Nothing
[automake.git] / automake.in
blob268962aeca4ec6d120d198967f644c3e236ea80a
1 #!@PERL@
2 # -*- perl -*-
3 # @configure_input@
5 eval 'exec @PERL@ -S $0 ${1+"$@"}'
6     if $running_under_some_shell;
8 # automake - create Makefile.in from Makefile.am
9 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
14 # any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 # 02111-1307, USA.
26 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
27 # Perl reimplementation by Tom Tromey <tromey@drip.colorado.edu>.
30 # Parameters set by configure.  Not to be changed.  NOTE: assign
31 # VERSION as string so that eg version 0.30 will print correctly.
32 $VERSION = "@VERSION@";
33 $prefix = "@prefix@";
34 $am_dir = "@datadir@/@PACKAGE@";
36 # String constants.
37 $IGNORE_PATTERN = "^##([^#].*)?\$";
38 $WHITE_PATTERN = "^[ \t]*\$";
39 $COMMENT_PATTERN = "^#";
40 $RULE_PATTERN = "^([a-zA-Z_.][-.a-zA-Z0-9_.]*) *:";
41 $MACRO_PATTERN = "^([A-Za-z][A-Za-z0-9_]*)[ \t]*=[ \t]*(.*)\$";
42 $BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*=[ \t]*(.*)\$";
44 # Constants to define the "strictness" level.
45 $FOREIGN = 0;
46 $GNU = 1;
47 $GNITS = 2;
51 # Variables global to entire run.
53 # Strictness level as set on command line.
54 $default_strictness = $GNU;
56 # Name of strictness level, as set on command line.
57 $default_strictness_name = 'gnu';
59 # This is TRUE if GNU make specific automatic dependency generation
60 # code should be included in generated Makefile.in.
61 $cmdline_use_dependencies = 1;
63 # TRUE if in verbose mode.
64 $verbose = 0;
66 # This holds our (eventual) exit status.  We don't actually exit until
67 # we have processed all input files.
68 $exit_status = 0;
70 # From the Perl manual.
71 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
73 # TRUE if missing standard files should be installed.
74 $add_missing = 0;
76 # Files found by scanning configure.in for LIBOBJS.
77 %libsources = ();
79 # True if fp_C_PROTOTYPES appears in configure.in.
80 $fp_c_prototypes = 0;
82 # Names used in AC_CONFIG_HEADER call.  $config_name is the actual
83 # (first) argument.  $config_header is the '.in' file.  Ordinarily the
84 # second is derived from the first, but they can be different if the
85 # weird "NAME:FILE" syntax is used.
86 $config_name = '';
87 $config_header = '';
88 # Line number at which AC_CONFIG_HEADER appears in configure.in.
89 $config_header_line = 0;
91 # Relative location of top build directory.
92 $top_builddir = '';
94 # List of Makefile.am's to process.
95 @input_files = ();
97 # List of files in AC_OUTPUT without Makefile.am.
98 @other_input_files = ();
99 # Line number at which AC_OUTPUT seen.
100 $ac_output_line = 0;
102 # List of directories to search for configure-required files.  This
103 # can be set by AC_CONFIG_AUX_DIR.
104 @config_aux_path = ('.', '..', '../..');
106 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
107 $seen_make_set = 0;
109 # Whether ud_GNU_GETTEXT has been seen in configure.in.
110 $seen_gettext = 0;
111 # Line number at which ud_GNU_GETTEXT seen.
112 $ac_gettext_line = 0;
114 # Whether ALL_LINGUAS has been seen.
115 $seen_linguas = '';
116 # The actual text.
117 $all_linguas = '';
118 # Line number at which it appears.
119 $all_linguas_line = 0;
121 # 1 if AC_PROG_INSTALL seen, 2 if fp_PROG_INSTALL seen.
122 $seen_prog_install = 0;
124 # 1 if any scripts installed, 0 otherwise.
125 $scripts_installed = 0;
127 # Whether AC_PATH_XTRA has been seen in configure.in.
128 $seen_path_xtra = 0;
130 # Whether YACC variable has been seen in configure.in.
131 $seen_prog_yacc = 0;
133 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
134 # AC_CHECK_TOOL also sets this.
135 $seen_canonical = 0;
137 # TRUE if we've seen AC_PROG_RANLIB.
138 $seen_ranlib = 0;
140 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
141 # handled in a funny way: if seen in the top-level Makefile.am, it is
142 # used for every directory which does not specify a different value.
143 # The rationale here is that some directories (eg gettext) might be
144 # distributions of other packages, and thus require their own charset
145 # info.  However, the DIST_CHARSET must be the same for the entire
146 # package; it can only be set at top-level.
147 # FIXME this yields bugs when rebuilding.  What to do?  Always
148 # read (and sometimes discard) top-level Makefile.am?
149 $maint_charset = '';
150 $dist_charset = 'utf8';         # recode doesn't support this yet.
154 &initialize_global_constants;
156 # Parse command line.
157 &parse_arguments (@ARGV);
159 # Do configure.in scan only once.
160 &scan_configure;
162 die "automake: no \`Makefile.am' found or specified\n"
163     if ! @input_files;
165 # Now do all the work on each file.
166 foreach $am_file (@input_files)
168     # FIXME should support the AC_OUTPUT ":" syntax here.
169     if (! -f ($am_file . '.am'))
170     {
171         &am_error ('no such file');
172     }
173     else
174     {
175         &generate_makefile ($am_file);
176     }
179 if ($seen_prog_install <= $scripts_installed)
181     &am_conf_error (($scripts_installed ? 'fp_PROG_INSTALL' : 'AC_PROG_INSTALL')
182                     . " must be used in configure.in");
183     &keyed_aclocal_warning ('fp_PROG_INSTALL')
184         if $scripts_installed;
187 exit $exit_status;
190 ################################################################
192 # Parse command line.
193 sub parse_arguments
195     local (@arglist) = @_;
197     # Start off as gnu.
198     &set_strictness ('gnu');
200     while (@arglist)
201     {
202         if ($arglist[0] eq "--version")
203         {
204             print "Automake version $VERSION\n";
205             exit 0;
206         }
207         elsif ($arglist[0] eq "--help")
208         {
209             &usage;
210         }
211         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
212         {
213             $am_dir = $1;
214         }
215         elsif ($arglist[0] eq '--amdir')
216         {
217             &require_argument (@arglist);
218             shift (@arglist);
219             $am_dir = $arglist[0];
220         }
221         elsif ($arglist[0] =~ /^--strictness=(.+)$/)
222         {
223             &set_strictness ($1);
224         }
225         elsif ($arglist[0] eq '--gnu')
226         {
227             &set_strictness ('gnu');
228         }
229         elsif ($arglist[0] eq '--gnits')
230         {
231             &set_strictness ('gnits');
232         }
233         elsif ($arglist[0] eq '--foreign')
234         {
235             &set_strictness ('foreign');
236         }
237         elsif ($arglist[0] eq '--strictness')
238         {
239             &require_argument (@arglist);
240             shift (@arglist);
241             &set_strictness ($arglist[0]);
242         }
243         elsif ($arglist[0] eq '--include-deps')
244         {
245             $cmdline_use_dependencies = 0;
246         }
247         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
248         {
249             # Set output directory.
250             $output_directory = $1;
251         }
252         elsif ($arglist[0] eq '--output-dir')
253         {
254             &require_argument (@arglist);
255             shift (@arglist);
256             $output_directory = $arglist[0];
257         }
258         elsif ($arglist[0] eq '--add-missing')
259         {
260             $add_missing = 1;
261         }
262         elsif ($arglist[0] eq '--verbose')
263         {
264             $verbose = 1;
265         }
266         elsif ($arglist[0] eq '--')
267         {
268             # Stop option processing.
269             shift (@arglist);
270             push (@input_files, @arglist);
271             last;
272         }
273         elsif ($arglist[0] =~ /^-/)
274         {
275             die "automake: unrecognized option -- \`$arglist[0]'\n";
276         }
277         else
278         {
279             push (@input_files, $arglist[0]);
280         }
282         shift (@arglist);
283     }
285     # Take global strictness from whatever we currently have set.
286     $default_strictness = $strictness;
287     $default_strictness_name = $strictness_name;
290 # Ensure argument exists, or die.
291 sub require_argument
293     local ($arg, @arglist) = @_;
294     die "automake: no argument given for option \`$arg'\n"
295         if ! @arglist;
298 ################################################################
300 # Generate a Makefile.in given the name of the corresponding Makefile.
301 sub generate_makefile
303     local ($makefile) = @_;
305     print "automake: creating ", $makefile, ".in\n" if $verbose;
307     &initialize_per_input;
308     $relative_dir = &dirname ($makefile);
310     # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
311     # config.sub.
312     &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
313         if $relative_dir eq '.' && $seen_canonical;
315     # We still need Makefile.in here, because sometimes the `dist'
316     # target doesn't re-run automake.
317     &push_dist_common ('Makefile.in', 'Makefile.am');
318     push (@sources, '$(SOURCES)') if defined $contents{'SOURCES'};
319     push (@objects, '$(OBJECTS)') if defined $contents{'OBJECTS'};
321     # This is always the default target.  This gives us freedom to do
322     # things in whatever order is convenient.
323     $output_rules .= "default: all\n\n";
324     push (@phony, 'default');
326     &read_am_file ($makefile . '.am');
327     &handle_options;
329     # Check first, because we might modify some state.
330     &check_gnu_standards;
331     &check_gnits_standards;
333     &handle_configure;
334     &handle_gettext;
335     &handle_libraries;
336     &handle_programs;
337     &handle_scripts;
339     # Re-init SOURCES and OBJECTS.  FIXME other code shouldn't depend
340     # on this (but currently does).
341     $contents{'SOURCES'} = join (' ', @sources);
342     $contents{'OBJECTS'} = join (' ', @objects);
344     &handle_texinfo;
345     &handle_man_pages;
346     &handle_data;
347     &handle_headers;
348     &handle_subdirs;
349     &handle_tags;
350     &handle_dist;
351     &handle_dependencies;
352     &handle_tests;
353     &handle_footer;
354     &handle_merge_targets;
355     &handle_installdirs;
356     &handle_clean;
357     &handle_phony;
359     if (! -d ($output_directory . '/' . $relative_dir))
360     {
361         &mkdir ($output_directory . '/' . $relative_dir);
362     }
363     if (! open (GM_FILE, "> " . $output_directory . '/' . $makefile . ".in"))
364     {
365         warn "automake: ${am_file}.in: cannot open: $!\n";
366         $exit_status = 1;
367         return;
368     }
370     print GM_FILE $output_vars;
371     print GM_FILE $output_rules;
372     print GM_FILE $output_trailer;
374     close (GM_FILE);
377 ################################################################
379 # Handle AUTOMAKE_OPTIONS variable.
380 sub handle_options
382     return if ! defined $contents{'AUTOMAKE_OPTIONS'};
384     foreach (split (/\s+/, $contents{'AUTOMAKE_OPTIONS'}))
385     {
386         $options{$_} = 1;
387         if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
388         {
389             &set_strictness ($_);
390         }
391         elsif ($_ eq 'no-installman' || $_ eq 'ansi2knr' || $_ eq 'dist-shar')
392         {
393             # Explicitly recognize these.
394         }
395         elsif ($_ eq 'no-dependencies')
396         {
397             $use_dependencies = 0;
398         }
399         elsif (/[0-9]+\.?[0-9]+/)
400         {
401             # Got a version number.  Is the syntax too strict?
402             if ($VERSION < $_)
403             {
404                 &am_line_error ('AUTOMAKE_OPTIONS',
405                                 "require version $_, only have $VERSION");
406                 exit 1;
407             }
408         }
409         else
410         {
411             &am_line_error ('AUTOMAKE_OPTIONS',
412                             'option ', $_, 'not recognized');
413         }
414     }
417 # Return object extension.  Just once, put some code into the output.
418 sub get_object_extension
420     if (! $dir_holds_sources)
421     {
422         # Boilerplate.
423         local ($xform) = '';
424         if (defined $contents{'CONFIG_HEADER'})
425         {
426             ($xform = &dirname ($contents{'CONFIG_HEADER'}))
427                 =~ s/(\W)/\\$1/g;
428             $xform = '-I' . $xform;
429         }
430         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go';
431         $output_vars .= &file_contents_with_transform ($xform,
432                                                        'compile-vars');
433         $output_rules .= &file_contents ('compile');
434         &push_phony_cleaners ('compile');
436         # If using X, include some extra variable definitions.  NOTE
437         # we don't want to force these into CFLAGS or anything,
438         # because not all programs will necessarily use X.
439         if ($seen_path_xtra)
440         {
441             $output_vars .= ("X_CFLAGS = \@X_CFLAGS\@\n"
442                              . "X_LIBS = \@X_LIBS\@\n"
443                              . "X_EXTRA_LIBS = \@X_EXTRA_LIBS\@\n"
444                              . "X_PRE_LIBS = \@X_PRE_LIBS\@\n");
445         }
447         # Check for automatic de-ANSI-fication.
448         $dir_holds_sources = '.o';
449         push (@suffixes, '.c', '.o');
450         push (@clean, 'compile');
452         if (defined $options{'ansi2knr'})
453         {
454             if (! $fp_c_prototypes)
455             {
456                 &am_line_error ('AUTOMAKE_OPTIONS',
457                                 "option \`ansi2knr' in use but \`fp_C_PROTOTYPES' not in configure.in");
458                 &keyed_aclocal_warning ('fp_C_PROTOTYPES');
459                 # Only give this error once.
460                 $fp_c_prototypes = 1;
461             }
463             $dir_holds_sources = '$o';
464             push (@suffixes, '._c', '._o');
466             &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
467                                      'ansi2knr.c', 'ansi2knr.1');
469             $output_vars .= &file_contents ('kr-vars');
470             $output_rules .= &file_contents ('compile-kr');
471             $output_rules .= &file_contents ('clean-kr');
473             push (@clean, 'kr');
474             &push_phony_cleaners ('kr');
475         }
476     }
477     return $dir_holds_sources;
480 # Handle SOURCE->OBJECT transform for one program or library.
481 sub handle_source_transform
483     local ($one_file, $obj) = @_;
484     local ($objpat) = $obj;
485     $objpat =~ s/(\W)/\\$1/g;
487     # Look for file_SOURCES and file_OBJECTS.
488     if (defined $contents{$one_file . "_SOURCES"})
489     {
490         if (! defined $contents{$one_file . "_OBJECTS"})
491         {
492             # Turn sources into objects.
493             local (@files) = split (/\s+/, $contents{$one_file . "_SOURCES"});
494             local (@result) = ();
495             foreach (@files)
496             {
497                 # Skip header files, including C++-ish ones.
498                 next if /\.[hH]$/;
499                 next if /\.hxx$/;
500                 # Skip things that look like macro references.
501                 next if /^\$\(.*\)$/;
502                 next if /^\$\{.*\}$/;
503                 # Skip things that look like configure substitutions.
504                 next if /^\@.*\@$/;
506                 # One wonders how this can happen.  But, apparently,
507                 # it can.  I believe it happens when nothing precedes
508                 # a backslash-newline on a line -- the \s+ regexp
509                 # doesn't match the newline.  Anyway, skip empty
510                 # strings.  See tests/depend.test for an example of
511                 # how to trigger this code.
512                 next if /^\s*$/;
514                 if (/^(.*)\.[yl]$/)
515                 {
516                     # Automatically include generated .c file in
517                     # distribution.
518                     &push_dist_common ($1 . '.c');
519                 }
521                 # Transform source files into .o files.
522                 s/\.cc$/$obj/g;
523                 s/\.cxx$/$obj/g;
524                 s/\.[cCmylfs]$/$obj/g;
525                 push (@result, $_);
527                 # Transform .o or $o file into .P file (for automatic
528                 # dependency code).
529                 s/$objpat$/.P/g;
530                 $dep_files{'$(srcdir)/.deps/' . $_} = 1;
531             }
533             &pretty_print ($one_file . "_OBJECTS =", "", @result);
534         }
535         else
536         {
537             &am_line_error ($one_file . '_OBJECTS',
538                             $one_file . '_OBJECTS', 'should not be defined');
539         }
541         push (@sources, '$(' . $one_file . "_SOURCES)");
542         push (@objects, '$(' . $one_file . "_OBJECTS)");
543     }
544     else
545     {
546         $output_vars .= ($one_file . "_SOURCES = " . $one_file . ".c\n"
547                          . $one_file . "_OBJECTS = ". $one_file
548                          . $obj . "\n");
549         push (@sources, $one_file . '.c');
550         push (@objects, $one_file . $obj);
551         $dep_files{'$(srcdir)/.deps/' . $one_file . '.P'} = 1;
552     }
554     if (defined $contents{'CONFIG_HEADER'})
555     {
556         $output_rules .= ('$(' . $one_file . "_OBJECTS): "
557                           . $contents{'CONFIG_HEADER'} . "\n");
558     }
560     return @result;
563 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
564 sub handle_lib_objects
566     local ($var) = @_;
568     die "programming error in handle_lib_objects"
569         if ! defined $contents{$var};
571     # We recognize certain things that are commonly put in LIBADD or
572     # LDADD.
573     local ($lsearch);
575     foreach $lsearch (split (/\s+/, $contents{$var}))
576     {
577         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
578         # means adding entries to dep_files.
579         if ($lsearch eq '@LIBOBJS@')
580         {
581             local ($iter, $rewrite);
582             foreach $iter (keys %libsources)
583             {
584                 if ($iter ne 'alloca.c')
585                 {
586                     ($rewrite = $iter) =~ s/\.c$/.P/;
587                     $dep_files{'$(srcdir)/.deps/' . $rewrite} = 1;
588                     &require_file_with_line ($var, $FOREIGN, $iter);
589                 }
590             }
591         }
592         elsif ($lsearch eq '@ALLOCA@')
593         {
594             &am_line_error ($var,
595                             "\@ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
596                 if ! defined $libsources{'alloca.c'};
597             $dep_files{'$(srcdir)/.deps/alloca.P'} = 1;
598             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
599         }
600     }
603 # Handle C programs.
604 sub handle_programs
606     local (@proglist) = &am_install_var ('-clean',
607                                          'programs', 'PROGRAMS',
608                                          'bin', 'sbin', 'libexec', 'pkglib',
609                                          'noinst', 'check');
610     return if ! @proglist;
612     local ($obj) = &get_object_extension;
613     local ($one_file, $xname, $munge);
615     foreach $one_file (@proglist)
616     {
617         # Canonicalize names.
618         ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
619         if ($xname ne $one_file)
620         {
621             local ($xt);
622             foreach $xt ('_LDADD', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
623             {
624                 &am_line_error ($one_file . $xt,
625                                 "invalid variable \`" . $one_file . $xt
626                                 . "'; should be \`" . $xname . $xt . "'")
627                     if defined $contents{$one_file . $xt};
628             }
629         }
631         &handle_source_transform ($xname, $obj);
633         if (defined $contents{$xname . "_LDADD"})
634         {
635             &handle_lib_objects ($xname . '_LDADD');
636         }
637         else
638         {
639             # User didn't define prog_LDADD override.  So do it.
640             $output_vars .= $xname . '_LDADD = $(LDADD)' . "\n";
641         }
643         $output_rules .=
644             &file_contents_with_transform
645                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
646                  . 's/\@XPROGRAM\@/' . $xname . '/go;',
647                  'program');
648     }
650     &handle_lib_objects ('LDADD')
651         if defined $contents{'LDADD'};
654 # Handle libraries.
655 sub handle_libraries
657     local (@liblist) = &am_install_var ('-no-all', '-clean',
658                                         'libraries', 'LIBRARIES',
659                                         'lib', 'pkglib', 'noinst', 'check');
660     return if ! @liblist;
662     if (! $seen_ranlib)
663     {
664         # FIXME need am_line_error here.  But we don't know which
665         # variable exists.  Must add a loop...  No.  Must have
666         # am_install_var return a hash.  Otherwise the user could add
667         # install directories that we'd never find.
668         &am_error ("building a library but \`AC_PROG_RANLIB' not in configure.in");
669         # Only get this error once.
670         $seen_ranlib = 1;
671     }
673     # Generate _LIBFILES variables.  Too bad we can't do this in
674     # am_install_var.
675     local ($onedir, $onelib);
676     local (@outlist);
677     foreach $onedir ('lib', 'pkglib', 'noinst')
678     {
679         if (defined $contents{$onedir . '_LIBRARIES'})
680         {
681             @outlist = ();
682             foreach $onelib (split (/\s+/, $contents{$onedir . '_LIBRARIES'}))
683             {
684                 push (@outlist, 'lib' . $onelib . '.a');
685             }
686             &pretty_print ($onedir . '_LIBFILES =', "", @outlist);
687         }
688     }
689     push (@all, '$(LIBFILES)');
691     local ($obj) = &get_object_extension;
692     local ($munge);
693     foreach $onelib (@liblist)
694     {
695         if (defined $contents{$onelib . '_LIBADD'})
696         {
697             &handle_lib_objects ($onelib . '_LIBADD');
698         }
699         else
700         {
701             # Generate support for conditional object inclusion in
702             # libraries.
703             $output_vars .= $onelib . "_LIBADD =\n";
704         }
706         &handle_source_transform ($onelib, $obj);
708         $output_rules .=
709             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go',
710                                            'library');
711     }
713     # Turn "foo" into "libfoo.a" and include macro definition.
714     grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
716     if (! defined $contents{'LIBFILES'})
717     {
718         &pretty_print ('LIBFILES = ', "", @liblist);
719     }
720     $output_vars .= &file_contents ('libraries-vars');
723 # Handle scripts.
724 sub handle_scripts
726     # NOTE we no longer automatically clean SCRIPTS, because it is
727     # useful to sometimes distribute scripts verbatim.  This happens
728     # eg in Automake itself.
729     $scripts_installed = &am_install_var ('scripts', 'SCRIPTS',
730                                           'bin', 'sbin', 'libexec', 'pkgdata',
731                                           'noinst', 'check');
733     # We really only want a boolean value.
734     $scripts_installed = 1 if $scripts_installed;
737 # Search a file for a "version.texi" Texinfo include.  Return the name
738 # of the include file if found, or the empty string if not.  A
739 # "version.texi" file is actually any file whose name matches
740 # "vers*.texi".
741 sub grep_for_vers_texi
743     local ($filename) = @_;
745     if (! open (TEXI, $filename))
746     {
747         &am_error ("couldn't open \`$filename': $!");
748         return '';
749     }
750     print "automake: reading $filename\n" if $verbose;
752     while (<TEXI>)
753     {
754         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
755         {
756             # Found it.
757             close (TEXI);
758             return $1;
759         }
760     }
762     close (TEXI);
763     return '';
766 # Handle all Texinfo source.
767 sub handle_texinfo
769     &am_line_error ('TEXINFOS',
770                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
771         if defined $contents{'TEXINFOS'};
772     return if (! defined $contents{'info_TEXINFOS'}
773                && ! defined $contents{'html_TEXINFOS'});
775     local (@texis) = split (/\s+/, $contents{'info_TEXINFOS'});
777     local (@infos_list, @info_deps_list, @dvis_list, @texi_deps);
778     local ($infobase, $info_cursor);
779     local (%versions);
780     local ($done) = 0;
781     local ($vti);
782     local ($tc_cursor, @texi_cleans);
784     foreach $info_cursor (@texis)
785     {
786         ($infobase = $info_cursor) =~ s/\.texi$//;
788         # If 'version.texi' is referenced by input file, then include
789         # automatic versioning capability.
790         local ($vtexi)
791             = &grep_for_vers_texi ($relative_dir . "/" . $info_cursor);
792         if ($vtexi)
793         {
794             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
795                 if (defined $versions{$vtexi});
796             $versions{$vtexi} = $info_cursor;
798             # We number the stamp-vti files.  This is doable since the
799             # actual names don't matter much.  We only number starting
800             # with the second one, so that the common case looks nice.
801             $vti = 'vti' . ($done ? $done : '');
802             &push_dist_common ($vtexi, 'stamp-' . $vti);
803             push (@clean, $vti);
805             $output_rules .=
806                 &file_contents_with_transform
807                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
808                      . 's/\@VTI\@/' . $vti . '/g; '
809                      . 's/\@VTEXI\@/' . $vtexi . '/g',
810                      'texi-version');
812             &push_phony_cleaners ($vti);
814             # Only require once.
815             &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'mdate-sh')
816                 if ! $done;
817             ++$done;
818         }
820         # If user specified file_TEXINFOS, then use that as explicit
821         # dependency list.
822         @texi_deps = ();
823         push (@texi_deps, $info_cursor);
824         push (@texi_deps, $vtexi) if $vtexi;
825         if (defined $contents{$infobase . "_TEXINFOS"})
826         {
827             push (@texi_deps, "\$" . $infobase . '_TEXINFOS');
828             &push_dist_common ("\$" . $infobase . '_TEXINFOS');
829         }
831         $output_rules .= ("\n" . $infobase . ".info: "
832                           . join (' ', @texi_deps) . "\n\n");
834         push (@infos_list, $infobase . '.info*');
835         push (@info_deps_list, $infobase . '.info');
836         push (@dvis_list, $infobase . '.dvi');
838         # Generate list of things to clean for this target.  We do
839         # this explicitly because otherwise too many things could be
840         # removed.  In particular the ".log" extension might
841         # reasonably be used in other contexts by the user.
842         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
843                             'ky', 'log', 'pg', 'toc', 'tp', 'vr', 'op')
844         {
845             push (@texi_cleans, $infobase . '.' . $tc_cursor);
846         }
847     }
849     # Some boilerplate.
850     $output_vars .= &file_contents ('texinfos-vars');
851     $output_rules .= &file_contents ('texinfos');
852     push (@phony, 'install-info', 'uninstall-info');
854     # How to clean.
855     $output_rules .= "\nmostlyclean-info:\n";
856     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
857     $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
858                       . "maintainer-clean-info:\n\t"
859                       . 'rm -f $(INFOS)' . "\n");
860     &push_phony_cleaners ('info');
862     push (@suffixes, '.texi', '.info', '.dvi');
863     push (@uninstall, 'uninstall-info');
864     push (@clean, 'info');
865     push (@info, '$(INFO_DEPS)');
866     push (@dvi, '$(DVIS)');
867     push (@installdirs, '$(infodir)');
868     unshift (@install_data, 'install-info');
870     # Make sure documentation is made and installed first.  Use
871     # $(INFO_DEPS), not 'info', because otherwise recursive makes get
872     # run twice during "make all".
873     unshift (@all, '$(INFO_DEPS)');
875     $output_vars .= ("INFOS = " . join (' ', @infos_list) . "\n"
876                      . "INFO_DEPS = " . join (' ', @info_deps_list)  . "\n"
877                      . "DVIS = " . join (' ', @dvis_list) . "\n"
878                      # This next isn't strictly needed now -- the
879                      # places that look here could easily be changed
880                      # to look in info_TEXINFOS.  But this is probably
881                      # better, in case noinst_TEXINFOS is ever
882                      # supported.
883                      . "TEXINFOS = " . $contents{'info_TEXINFOS'} . "\n\n");
885     # Do some error checking.
886     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
889 # Handle any man pages.
890 sub handle_man_pages
892     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
893         if defined $contents{'MANS'};
894     return if ! defined $contents{'man_MANS'};
896     # We generate the manpage install code by hand to avoid the use of
897     # basename in the generated Makefile.
898     local (@mans) = split (/\s+/, $contents{'man_MANS'});
899     local (%sections, %inames, %secmap, %fullsecmap);
900     foreach (@mans)
901     {
902         # FIXME: statement without effect:
903         /^(.*)\.([0-9])([a-z]*)$/;
904         $sections{$2} = 1;
905         $inames{$1} = $_;
906         $secmap{$1} = $2;
907         $fullsecmap{$1} = $2 . $3;
908     }
910     # We don't really need this, but we use it in case we ever want to
911     # support noinst_MANS.
912     $output_vars .= "MANS = " . $contents{'man_MANS'} . "\n";
914     # Generate list of install dirs.
915     $output_rules .= "install-man: \$(MANS)\n";
916     foreach (keys %sections)
917     {
918         push (@installdirs, '$(mandir)/man' . $_);
919         $output_rules .= ("\t" . '$(top_srcdir)/mkinstalldirs $(mandir)/man'
920                           . $_ . "\n");
921     }
922     push (@phony, 'install-man');
924     # Generate install target.
925     local ($key);
926     foreach $key (keys %inames)
927     {
928         $_ = $install_man_format;
929         s/\@SECTION\@/$secmap{$key}/g;
930         s/\@MAN\@/$inames{$key}/g;
931         s/\@FULLSECT\@/$fullsecmap{$key}/g;
932         s/\@MANBASE\@/$key/g;
933         $output_rules .= $_;
934     }
935     $output_rules .= "\n";
937     $output_rules .= "uninstall-man:\n";
938     foreach $key (keys %inames)
939     {
940         $_ = $uninstall_man_format;
941         s/\@SECTION\@/$secmap{$key}/g;
942         s/\@MAN\@/$inames{$key}/g;
943         s/\@FULLSECT\@/$fullsecmap{$key}/g;
944         s/\@MANBASE\@/$key/g;
945         $output_rules .= $_;
946     }
947     $output_rules .= "\n";
948     push (@phony, 'uninstall-man');
950     $output_vars .= &file_contents ('mans-vars');
952     if (! defined $options{'no-installman'})
953     {
954         push (@install_data, 'install-man');
955         push (@uninstall, 'uninstall-man');
956         push (@all, '$(MANS)');
957     }
960 # Handle DATA variables.
961 sub handle_data
963     &am_install_var ('data', 'DATA', 'data', 'sysconf',
964                      'sharedstate', 'localstate', 'pkgdata',
965                      'noinst', 'check');
968 # Handle TAGS.
969 sub handle_tags
971     local ($tagging) = 0;
973     push (@phony, 'tags');
974     if (defined $contents{'SUBDIRS'})
975     {
976         $output_rules .= &file_contents ('tags');
977         $tagging = 1;
978     }
979     elsif ($dir_holds_sources || defined $contents{'ETAGS_ARGS'})
980     {
981         $output_rules .= &file_contents ('tags-subd');
982         $tagging = 1;
983     }
985     if ($tagging)
986     {
987         $output_rules .= &file_contents ('tags-clean');
988         push (@clean, 'tags');
989         &push_phony_cleaners ('tags');
990     }
991     else
992     {
993         # Every Makefile must define some sort of TAGS rule.
994         # Otherwise, it would be possible for a top-level "make TAGS"
995         # to fail because some subdirectory failed.
996         $output_rules .= "tags: TAGS\nTAGS:\n\n";
997     }
1000 # Generate actual 'dist' (or dist-shar) rule.
1001 sub handle_dist_worker
1003     local ($distshar) = @_;
1004     local ($target) = $distshar ? 'dist-shar' : 'dist';
1006     $output_rules .= $target . ': $(DEP_DISTFILES)' . "\n";
1008     # Initialization; only at top level.
1009     if ($relative_dir eq '.')
1010     {
1011         if ($strictness >= $GNITS)
1012         {
1013             # For Gnits users, this is pretty handy.  Look at 15 lines
1014             # in case some explanatory text is desirable.
1015             $output_rules .= '  @if sed 15q NEWS | grep -e "$(VERSION)" > /dev/null; then :; else \\
1016           echo "NEWS not updated; not releasing" 1>&2; \\
1017           exit 1;                               \\
1018         fi
1020         }
1023         $output_rules .=
1024             # Create dist directory.
1025             '   rm -rf $(distdir)
1026         mkdir $(distdir)
1027         chmod 777 $(distdir)
1030         # Only run automake in `dist' target if --include-deps not
1031         # specified.  That way the recipient of a distribution can run
1032         # "make dist" and not need Automake.
1033         if ($cmdline_use_dependencies)
1034         {
1035             $output_rules .=
1036                 (
1037                  # We need an absolute path for --output-dir.  Thus the
1038                  # weirdness.
1039                  '      distdir=`cd $(distdir) && pwd` \\
1040           && cd $(srcdir) \\
1041           && automake --include-deps --output-dir=$$distdir --strictness='
1042                  # Set strictness of output.
1043                  . $strictness_name . "\n"
1044                  );
1045         }
1046     }
1048     # In loop, test for file existence because sometimes a file gets
1049     # included in DISTFILES twice.  For example this happens when a
1050     # single source file is used in building more than one program.
1051     # Also, there are situations in which "ln" can fail.  For instance
1052     # a file to distribute could actually be a cross-filesystem
1053     # symlink -- this can easily happen if "gettextize" was run on the
1054     # distribution.  Note that DISTFILES can contain a wildcard (for
1055     # info files, sigh), so we must use the echo trick.
1057     $output_rules .= '  @for file in `cd $(srcdir) && echo $(DISTFILES)`; do \\
1058           test -f $(distdir)/$$file \\
1059           || ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \\
1060           || cp -p $(srcdir)/$$file $(distdir)/$$file; \\
1061         done
1064     # If we have SUBDIRS, create all dist subdirectories and do
1065     # recursive build.
1066     if (defined $contents{'SUBDIRS'})
1067     {
1068         # Test for directory existence here because previous automake
1069         # invocation might have created some directories.
1070         $output_rules .= '      for subdir in $(SUBDIRS); do            \\
1071           test -d $(distdir)/$$subdir           \\
1072           || mkdir $(distdir)/$$subdir          \\
1073           || exit 1;                            \\
1074           chmod 777 $(distdir)/$$subdir;        \\
1075           (cd $$subdir && $(MAKE) dist) || exit 1; \\
1076         done
1078     }
1080     # Make verbatim copies of some subdirectories if required.  This
1081     # is a hack which might go away.
1082     if (defined $contents{'DIST_SUBDIRS'})
1083     {
1084         &am_line_error ('DIST_SUBDIRS',
1085                         "\`DIST_SUBDIRS' is deprecated; make a new \`Makefile.am' instead");
1087         $output_rules .= '      @for dir in $(DIST_SUBDIRS); do         \\
1088           echo copying directory $$dir;         \\
1089           tar chf - $$dir | (cd $(distdir) && tar xBpf -); \\
1090         done
1092     }
1094     # Finalize.
1095     if ($relative_dir eq '.')
1096     {
1097         $output_rules .= '      chmod -R a+r $(distdir)' . "\n\t";
1098         if ($distshar)
1099         {
1100             $output_rules .= 'shar $(distdir) | gzip > $(distdir).shar.gz';
1101         }
1102         else
1103         {
1104             $output_rules .= 'tar chozf $(distdir).tar.gz $(distdir)';
1105         }
1106         $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
1107     }
1109     push (@phony, $target);
1112 # Handle 'dist' target.
1113 sub handle_dist
1115     # Set up maint_charset.
1116     $local_maint_charset = $contents{'MAINT_CHARSET'}
1117         if defined $contents{'MAINT_CHARSET'};
1118     $maint_charset = $local_maint_charset
1119         if $relative_dir eq '.';
1121     &am_line_error
1122         ('DIST_OTHER',
1123          "\`DIST_OTHER' is an anachronism; use \`EXTRA_DIST' instead")
1124             if defined $contents{'DIST_OTHER'};
1126     if (defined $contents{'DIST_CHARSET'})
1127     {
1128         &am_line_error ('DIST_CHARSET',
1129                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
1130             if ! $local_maint_charset;
1131         if ($relative_dir eq '.')
1132         {
1133             $dist_charset = $contents{'DIST_CHARSET'}
1134         }
1135         else
1136         {
1137             &am_line_error ('DIST_CHARSET',
1138                             "DIST_CHARSET can only be defined at top level");
1139         }
1140     }
1142     # Look for common files that should be included in distribution.
1143     local ($cfile);
1144     foreach $cfile (@common_files)
1145     {
1146         if (-f ($relative_dir . "/" . $cfile))
1147         {
1148             &push_dist_common ($cfile);
1149         }
1150     }
1152     # Keys of %dist_common are names of files to distributed.  We put
1153     # README first because it then becomes easier to make a
1154     # Usenet-compliant shar file (in these, README must be first).
1155     # FIXME do more ordering of files here.
1156     local (@coms);
1157     if (defined $dist_common{'README'})
1158     {
1159         push (@coms, 'README');
1160         undef $dist_common{'README'};
1161     }
1162     push (@coms, sort keys %dist_common);
1164     &pretty_print ("DIST_COMMON =", "", @coms);
1165     $output_vars .= "\n";
1167     # Some boilerplate.
1168     $output_vars .= &file_contents ('dist-vars');
1170     # Put these things in rules section so it is easier for whoever
1171     # reads Makefile.in.
1172     if ($relative_dir eq '.')
1173     {
1174         $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
1175     }
1176     else
1177     {
1178         $output_rules .= ("\nsubdir = " . $relative_dir . "\n"
1179                           . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
1180                           . "\n");
1181     }
1183     # Generate 'dist' target, and maybe dist-shar.
1184     &handle_dist_worker (0);
1185     &handle_dist_worker (1) if defined $options{'dist-shar'};
1188 # Handle auto-dependency code.
1189 sub handle_dependencies
1191     if ($use_dependencies)
1192     {
1193         # Include GNU-make-specific auto-dep code.
1194         if ($dir_holds_sources)
1195         {
1196             &pretty_print ('DEP_FILES =', "", sort keys %dep_files);
1197             $output_rules .= &file_contents ('depend');
1198         }
1199     }
1200     else
1201     {
1202         # Include any auto-generated deps that are present.
1203         if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
1204         {
1205             local ($depfile);
1206             local ($gpat) = $relative_dir . "/.deps/*.P";
1208             foreach $depfile (<${gpat}>)
1209             {
1210                 if (! open (DEP_FILE, $depfile))
1211                 {
1212                     &am_error ("couldn't open \`$depfile': $!");
1213                     next;
1214                 }
1215                 print "automake: reading $depfile\n" if $verbose;
1217                 # Slurp entire file.
1218                 $output_rules .= join ('', <DEP_FILE>);
1220                 close (DEP_FILE);
1221             }
1223             $output_rules .= "\n";
1224         }
1225     }
1228 # Handle subdirectories.
1229 sub handle_subdirs
1231     if (! defined $contents{'SUBDIRS'})
1232     {
1233         &am_conf_error
1234             ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined")
1235                 if $seen_gettext && $relative_dir eq '.';
1236         return;
1237     }
1239     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
1240         if $seen_gettext;
1242     return if ! defined $contents{'SUBDIRS'};
1244     # Make sure each directory mentioned in SUBDIRS actually exists.
1245     local ($dir);
1246     foreach $dir (split (/\s+/, $contents{'SUBDIRS'}))
1247     {
1248         # Skip directories substituted by configure.
1249         next if $dir =~ /^\@.*\@$/;
1250         &am_line_error ('SUBDIRS',
1251                         "required directory $relative_dir/$dir does not exist")
1252             if ! -d $relative_dir . '/' . $dir;
1253     }
1255     $output_rules .= &file_contents ('subdirs');
1257     # Push a bunch of phony targets.
1258     local ($phonies);
1259     foreach $phonies ('-data', '-exec', 'dirs')
1260     {
1261         push (@phony, 'install' . $phonies . '-recursive');
1262         push (@phony, 'uninstall' . $phonies . '-recursive');
1263     }
1264     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
1265     {
1266         push (@phony, $phonies . '-recursive');
1267     }
1268     &push_phony_cleaners ('recursive');
1270     push (@check, "check-recursive");
1271     push (@installcheck, "installcheck-recursive");
1272     push (@info, "info-recursive");
1273     push (@dvi, "dvi-recursive");
1275     $recursive_install = 1;
1278 # Handle remaking and configure stuff.
1279 sub handle_configure
1281     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
1282     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
1283         if defined $contents{'SUBDIRS'} && ! $seen_make_set;
1285     local ($top_reldir);
1286     if ($relative_dir ne '.')
1287     {
1288         # In subdirectory.
1289         $output_rules .= &file_contents ('remake-subd');
1290         $top_reldir = '../';
1291     }
1292     else
1293     {
1294         if (-f 'aclocal.m4')
1295         {
1296             $output_vars .= "ACLOCAL = aclocal.m4\n";
1297             &push_dist_common ('aclocal.m4');
1298         }
1299         $output_rules .= &file_contents ('remake');
1301         # Look for some files we need.
1302         &require_config_file ($FOREIGN, 'install-sh');
1303         &require_file ($FOREIGN, 'mkinstalldirs');
1305         &am_error
1306             ("\`install.sh' is an anachronism; use \`install-sh' instead")
1307                 if -f $relative_dir . '/install.sh';
1309         # If we have a configure header, require it.
1310         if ($config_header)
1311         {
1312             # FIXME this restriction should be lifted.
1313             # FIXME first see if it is even needed as-is.
1314             &am_conf_line_error ($config_header_line,
1315                                  "argument to AC_CONFIG_HEADER contains \`/'\n")
1316                 if ($config_header =~ /\//);
1318             &require_file_with_conf_line ($config_header_line,
1319                                           $FOREIGN, $config_header);
1321             # Header defined and in this directory.
1322             if (-f 'acconfig.h')
1323             {
1324                 $output_vars .= "ACCONFIG = acconfig.h\n";
1325                 &push_dist_common ('acconfig.h');
1326             }
1327             if (-f $config_name . '.top')
1328             {
1329                 $output_vars .= "CONFIG_TOP = ${config_name}.top\n";
1330                 &push_dist_common ($config_name . '.top');
1331             }
1332             if (-f $config_name . '.bot')
1333             {
1334                 $output_vars .= "CONFIG_BOT = ${config_name}.bot\n";
1335                 &push_dist_common ($config_name . '.bot');
1336             }
1338             &push_dist_common ('stamp-h.in');
1340             $output_rules .= &file_contents ('remake-hdr');
1341             $output_vars .= "CONFIG_HEADER_IN = ${config_header}\n";
1342         }
1344         $top_reldir = '';
1345     }
1347     &am_line_error ('CONFIG_HEADER',
1348                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
1349         if defined $contents{'CONFIG_HEADER'};
1351     # Generate CONFIG_HEADER define, and define interally.
1352     $output_vars .= "CONFIG_HEADER = ${top_builddir}/${config_name}\n"
1353         if $config_name;
1354     $contents{'CONFIG_HEADER'} = "${top_builddir}/${config_name}"
1355         if $config_name;
1357     # Now look for other files in this directory which must be remade
1358     # by config.status, and generate rules for them.
1359     local ($file, $local, $input);
1360     foreach $file (@other_input_files)
1361     {
1362         # Skip files not in this directory, any Makefile, and the
1363         # config header.  These last two must be handled specially.
1364         next unless &dirname ($file) eq $relative_dir;
1365         next if $file eq $top_builddir . '/' . $config_name;
1366         ($local = $file) =~ s/^.*\///;
1367         next if $local eq 'Makefile';
1369         if ($local =~ /^(.*):(.*)$/)
1370         {
1371             # This is the ":" syntax of AC_OUTPUT.
1372             $input = $2;
1373             $local = $1;
1374         }
1375         else
1376         {
1377             # Normal usage.
1378             $input = $local . '.in';
1379         }
1380         # FIXME when using autoconf ":" syntax, should we set CONFIG_FILES
1381         # to $local:$input?
1382         $output_rules .= ($local . ': '
1383                           . '$(top_builddir)/config.status ' . $input . "\n"
1384                           . "\t"
1385                           . 'cd $(top_builddir) && CONFIG_FILES='
1386                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
1387                           . '$@ CONFIG_HEADERS= ./config.status'
1388                           . "\n");
1390         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
1391                                       $local . '.in');
1392     }
1395 # Handle C headers.
1396 sub handle_headers
1398     &am_install_var ('header', 'HEADERS', 'include',
1399                      'oldinclude', 'pkginclude',
1400                      'noinst', 'check');
1403 sub handle_gettext
1405     return if ! $seen_gettext || $relative_dir ne '.';
1407     # As of 0.10.6, gettext still wants @INTLSUB@ and @POSUB@ in
1408     # SUBDIRS.  This is going to change in a future version.  So for
1409     # now we simply do no checking.
1410     if (0 && defined $contents{'SUBDIRS'})
1411     {
1412         &am_line_error
1413             ('SUBDIRS',
1414              "ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
1415                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
1416         &am_line_error
1417             ('SUBDIRS',
1418              "ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
1419                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
1420     }
1422     # Ensure that each language in ALL_LINGUAS has a .po file, and
1423     # each po file is mentioned in ALL_LINGUAS.
1424     if ($seen_linguas)
1425     {
1426         local (%linguas) = ();
1427         grep ($linguas{$_} = 1, split (/\s+/, $all_linguas));
1429         foreach (<po/*.po>)
1430         {
1431             s/^po\///;
1432             s/\.po$//;
1434             &am_line_error ($all_linguas_line,
1435                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
1436                 if ! $linguas{$_};
1437         }
1439         foreach (keys %linguas)
1440         {
1441             &am_line_error ($all_linguas_line,
1442                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
1443                 if ! -f "po/$_.po";
1444         }
1445     }
1446     else
1447     {
1448         &am_error ("ud_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
1449     }
1452 # Handle footer elements.
1453 sub handle_footer
1455     if ($contents{'SOURCES'})
1456     {
1457         &pretty_print ('SOURCES =', "",
1458                        split (/\s+/, $contents{'SOURCES'}));
1459     }
1460     if ($contents{'OBJECTS'})
1461     {
1462         &pretty_print ('OBJECTS =', "",
1463                        split (/\s+/, $contents{'OBJECTS'}));
1464     }
1465     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
1466     {
1467         $output_vars .= "\n";
1468     }
1470     if (defined $contents{'SUFFIXES'})
1471     {
1472         push (@suffixes, '$(SUFFIXES)');
1473     }
1475     $output_trailer .= ".SUFFIXES:\n";
1476     if (@suffixes)
1477     {
1478         $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
1479     }
1480     $output_trailer .= &file_contents ('footer');
1483 # Deal with installdirs target.
1484 sub handle_installdirs
1486     # GNU Makefile standards recommend this.
1487     $output_rules .= ("installdirs:"
1488                       . ($recursive_install
1489                          ? " installdirs-recursive\n"
1490                          : "\n"));
1491     push (@phony, 'installdirs');
1492     if (@installdirs)
1493     {
1494         &pretty_print_rule ("\t\$(top_srcdir)/mkinstalldirs ", "\t\t",
1495                             @installdirs);
1496     }
1497     $output_rules .= "\n";
1500 # There are several targets which need to be merged.  This is because
1501 # their complete definition is compiled from many parts.  Note that we
1502 # avoid double colon rules, otherwise we'd use them instead.
1503 sub handle_merge_targets
1505     push (@all, 'Makefile');
1506     push (@all, $config_name)
1507         if $config_name && &dirname ($config_name) eq $relative_dir;
1509     &do_one_merge_target ('info', @info);
1510     &do_one_merge_target ('dvi', @dvi);
1512     if (! defined $contents{'SUBDIRS'} || $relative_dir ne '.')
1513     {
1514         # 'check' must depend on 'all', but not at top level.
1515         # Ditto install.
1516         unshift (@check, 'all');
1517         unshift (@install, 'all');
1518     }
1519     &do_one_merge_target ('check', @check);
1520     &do_one_merge_target ('installcheck', @installcheck);
1522     # Handle the various install targets specially.  We do this so
1523     # that (eg) "make install-exec" will run "install-exec-recursive"
1524     # if required, but "make install" won't run it twice.  Step one is
1525     # to see if the user specified local versions of any of the
1526     # targets we handle.  "all" is treated as one of these since
1527     # "install" can run it.
1528     push (@install_exec, 'install-exec-local')
1529         if defined $contents{'install-exec-local'};
1530     push (@install_data, 'install-data-local')
1531         if defined $contents{'install-data-local'};
1532     push (@uninstall, 'uninstall-local')
1533         if defined $contents{'uninstall-local'};
1534     push (@all, 'all-local')
1535         if defined $contents{'all-local'};
1537     if (defined $contents{'install-local'})
1538     {
1539         &am_line_error ('install-local',
1540                         "use \`install-data' or \`install-exec', not \`install'");
1541     }
1543     # Step two: if we are doing recursive makes, write out the
1544     # appropriate rules.
1545     local (@install);
1546     if ($recursive_install)
1547     {
1548         push (@install, 'install-recursive');
1550         if (@all)
1551         {
1552             $output_rules .= ('all-am: '
1553                               . join (' ', @all)
1554                               . "\n\n");
1555             @all = ('all-recursive', 'all-am');
1556             push (@phony, 'all-am');
1557         }
1558         else
1559         {
1560             @all = ('all-recursive');
1561         }
1562         if (@install_exec)
1563         {
1564             $output_rules .= ('install-exec-am: '
1565                               . join (' ', @install_exec)
1566                               . "\n\n");
1567             @install_exec = ('install-exec-recursive', 'install-exec-am');
1568             push (@install, 'install-exec-am');
1569             push (@phony, 'install-exec-am');
1570         }
1571         else
1572         {
1573             @install_exec = ('install-exec-recursive');
1574         }
1575         if (@install_data)
1576         {
1577             $output_rules .= ('install-data-am: '
1578                               . join (' ', @install_data)
1579                               . "\n\n");
1580             @install_data = ('install-data-recursive', 'install-data-am');
1581             push (@install, 'install-data-am');
1582             push (@phony, 'install-data-am');
1583         }
1584         else
1585         {
1586             @install_data = ('install-data-recursive');
1587         }
1588         if (@uninstall)
1589         {
1590             $output_rules .= ('uninstall-am: '
1591                               . join (' ', @uninstall)
1592                               . "\n\n");
1593             @uninstall = ('uninstall-recursive', 'uninstall-am');
1594             push (@phony, 'uninstall-am');
1595         }
1596         else
1597         {
1598             @uninstall = ('uninstall-recursive');
1599         }
1600     }
1602     # Step three: print definitions users can use.
1603     $output_rules .= ("install-exec: "
1604                       . join (' ', @install_exec)
1605                       . "\n\n");
1606     push (@install, 'install-exec') if !$recursive_install;
1607     push (@phony, 'install-exec');
1609     $output_rules .= ("install-data: "
1610                       . join (' ', @install_data)
1611                       . "\n\n");
1612     push (@install, 'install-data') if !$recursive_install;
1613     push (@phony, 'install-data');
1615     # If no dependencies for 'install', add 'all'.  Why?  That way
1616     # "make install" at top level of distclean'd distribution won't
1617     # fail because stuff in 'lib' fails to build.
1618     push (@install, 'all') if ! @install;
1619     $output_rules .= ('install: '
1620                       . join (' ', @install)
1621                       # Use "@:" as empty command so nothing prints.
1622                       . "\n\t\@:"
1623                       . "\n\n"
1624                       . 'uninstall: '
1625                       . join (' ', @uninstall)
1626                       . "\n\n");
1627     push (@phony, 'install', 'uninstall');
1629     $output_rules .= ('all: '
1630                       . join (' ', @all)
1631                       . "\n\n");
1632     push (@phony, 'all');
1634     # Generate the new 'install-strip' target.
1635     $output_rules .= ("install-strip:\n\t"
1636                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
1637                       . "\n");
1640 # Helper for handle_merge_targets.
1641 sub do_one_merge_target
1643     local ($name, @values) = @_;
1645     if (defined $contents{$name . '-local'})
1646     {
1647         # User defined local form of target.  So include it.
1648         push (@values, $name . '-local');
1649         push (@phony, $name . '-local');
1650     }
1652     $output_rules .= $name . ":";
1653     if (@values)
1654     {
1655         $output_rules .= ' ' . join (' ', @values);
1656     }
1657     $output_rules .= "\n\n";
1658     push (@phony, $name);
1661 # Handle all 'clean' targets.
1662 sub handle_clean
1664     push (@clean, 'generic');
1665     $output_rules .= &file_contents ('clean');
1666     &push_phony_cleaners ('generic');
1668     local ($target) = $recursive_install ? 'clean-am' : 'clean';
1669     &do_one_clean_target ($target, 'mostly', '', @clean);
1670     &do_one_clean_target ($target, '', 'mostly', @clean);
1671     &do_one_clean_target ($target, 'dist', '', @clean);
1672     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
1674     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
1676     local (@deps);
1677     if ($recursive_install)
1678     {
1679         @deps = ('am', 'recursive');
1680         &do_one_clean_target ('', 'mostly', '', @deps);
1681         &do_one_clean_target ('', '', '', @deps);
1682         &do_one_clean_target ('', 'dist', '', @deps);
1683         &do_one_clean_target ('', 'maintainer-', '', @deps);
1684     }
1687 # Helper for handle_clean.
1688 sub do_one_clean_target
1690     local ($target, $name, $last_name, @deps) = @_;
1692     # Special case: if target not passed, then don't generate
1693     # dependency on next "lower" clean target (eg no
1694     # clean<-mostlyclean derivation).  In this case the target is
1695     # implicitly known to be 'clean'.
1696     local ($flag) = $target;
1697     $target = 'clean' if ! $flag;
1699     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
1700     if ($flag)
1701     {
1702         if ($last_name || $name ne 'mostly')
1703         {
1704             push (@deps, $last_name . $target . " ");
1705         }
1706     }
1707     # FIXME not sure if I like the tabs here.
1708     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
1710     # FIXME shouldn't we really print these messages before running
1711     # the dependencies?
1712     if ($name . $target eq 'maintainer-clean')
1713     {
1714         # Print a special warning.
1715         $output_rules .=
1716             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
1717              . "\t\@echo \"it deletes files that may require special "
1718              . "tools to rebuild.\"\n");
1720         $output_rules .= "\trm -f config.status\n"
1721             if $relative_dir eq '.';
1722     }
1723     elsif ($name . $target eq 'distclean')
1724     {
1725         $output_rules .= "\trm -f config.status\n";
1726     }
1727     $output_rules .= "\n";
1730 # Handle .PHONY target.
1731 sub handle_phony
1733     &pretty_print_rule ('.PHONY:', "", @phony);
1734     $output_rules .= "\n";
1737 # Handle TESTS variable.
1738 sub handle_tests
1740     return if ! defined $contents{'TESTS'};
1742     &push_dist_common (split (/\s+/, $contents{'TESTS'}));
1743     push (@check, 'check-TESTS');
1744     push (@phony, 'check-TESTS');
1745     # FIXME use $(SHELL) here?  That is what Ulrich suggests.  Maybe a
1746     # new macro, $(TEST_SHELL), a la $(CONFIG_SHELL)?  For now we just
1747     # execute the file directly; this allows test files which are
1748     # compiled -- a possibly useful feature.
1749     $output_rules .= 'check-TESTS:
1750         @failed=0; all=0; \\
1751         srcdir=$(srcdir); export srcdir; \\
1752         for tst in $(TESTS); do \\
1753           all=`expr $$all + 1`; \\
1754           if test -f $$tst; then dir=.; \\
1755           else dir="$(srcdir)"; fi; \\
1756           if $$dir/$$tst; then \\
1757             echo "PASS: $$tst"; \\
1758           else \\
1759             failed=`expr $$failed + 1`; \\
1760             echo "FAIL: $$tst"; \\
1761           fi; \\
1762         done; \\
1763         if test "$$failed" -eq 0; then \\
1764           echo "========================"; \\
1765           echo "All $$all tests passed"; \\
1766           echo "========================"; \\
1767         else \\
1768           echo "$$failed of $$all tests failed"; \\
1769         fi
1773 ################################################################
1775 # Scan configure.in for interesting things.
1776 # FIXME ensure VERSION, PACKAGE are set.
1777 sub scan_configure
1779     open (CONFIGURE, 'configure.in')
1780         || die "automake: couldn't open \`configure.in': $!\n";
1781     print "automake: reading configure.in\n" if $verbose;
1783     # Reinitialize libsources here.  This isn't really necessary,
1784     # since we currently assume there is only one configure.in.  But
1785     # that won't always be the case.
1786     %libsources = ();
1788     local ($in_ac_output, @make_list) = 0;
1789     local ($seen_arg_prog) = 0;
1790     local ($libobj_iter);
1791     while (<CONFIGURE>)
1792     {
1793         # Remove comments from current line.
1794         s/\bdnl\b.*$//;
1795         s/\#.*$//;
1797         # Populate libobjs array.
1798         if (/AC_FUNC_ALLOCA/)
1799         {
1800             $libsources{'alloca.c'} = 1;
1801         }
1802         elsif (/AC_FUNC_GETLOADAVG/)
1803         {
1804             $libsources{'getloadavg.c'} = 1;
1805         }
1806         elsif (/AC_FUNC_MEMCMP/)
1807         {
1808             $libsources{'memcmp.c'} = 1;
1809         }
1810         elsif (/AC_STRUCT_ST_BLOCKS/)
1811         {
1812             $libsources{'fileblocks.c'} = 1;
1813         }
1814         elsif (/(AC|fp)_FUNC_FNMATCH/)
1815         {
1816             # AC_FUNC_FNMATCH is just wishful thinking at this point.
1817             $libsources{'fnmatch.c'} = 1;
1818         }
1819         elsif (/AC_REPLACE_FUNCS\s*\((.*)\)/)
1820         {
1821             foreach (split (/\s+/, $1))
1822             {
1823                 $libsources{$_ . '.c'} = 1;
1824             }
1825         }
1826         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
1827                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
1828         {
1829             foreach $libobj_iter (split (/\s+/, $1))
1830             {
1831                 if ($libobj_iter =~ /^(.*)\.o$/)
1832                 {
1833                     $libsources{$1 . '.c'} = 1;
1834                 }
1835             }
1836         }
1838         # Process the AC_OUTPUT macro.
1839         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
1840         {
1841             $in_ac_output = 1;
1842             $ac_output_line = $.;
1843         }
1844         if ($in_ac_output)
1845         {
1846             $in_ac_output = 0 if s/[\]\),].*$//;
1848             # Look at potential Makefile.am's.
1849             foreach (split)
1850             {
1851                 next if $_ eq "\\";
1852                 if (-f $_ . '.am')
1853                 {
1854                     push (@make_list, $_);
1855                 }
1856                 else
1857                 {
1858                     push (@other_input_files, $_);
1859                 }
1860             }
1861         }
1863         if (/AC_CONFIG_AUX_DIR\(([^)]+)\)/)
1864         {
1865             @config_aux_path = $1;
1866         }
1868         # Check for ansi2knr.
1869         $fp_c_prototypes = 1 if /fp_C_PROTOTYPES/;
1871         # Check for NLS support.
1872         if (/ud_GNU_GETTEXT/)
1873         {
1874             $seen_gettext = 1;
1875             $ac_gettext_line = $.;
1876         }
1878         # Look for ALL_LINGUAS.
1879         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
1880         {
1881             $seen_linguas = 1;
1882             $all_linguas = $1;
1883             $all_linguas_line = $.;
1884         }
1886         # Handle configuration headers.
1887         if (/AC_CONFIG_HEADER\s*\((.*)\)/)
1888         {
1889             $config_header_line = $.;
1890             $config_name = $1;
1891             if ($config_name =~ /^([^:]+):(.+)$/)
1892             {
1893                 $config_name = $1;
1894                 $config_header = $2;
1895             }
1896             else
1897             {
1898                 $config_header = $config_name . '.in';
1899             }
1900         }
1902         $seen_canonical = 1 if /AC_CANONICAL_(HOST|SYSTEM)/;
1903         $seen_canonical = 1 if /AC_CHECK_TOOL/;
1904         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
1906         # Sometimes it is desirable to explicitly set YACC.  For
1907         # instance some people don't want to use bison.
1908         $seen_prog_yacc = 1 if (/AC_PROG_YACC/
1909                                 || /AC_SUBST\(YACC\)/
1910                                 || /AC_(PATH|CHECK)_PROGS?\(YACC/);
1912         # Some things required by Automake.  FIXME We only really
1913         # require AC_ARG_PROGRAM if any program is installed.
1914         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
1915         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
1916         $seen_prog_install = 2 if ! $seen_prog_install && /fp_PROG_INSTALL/;
1917         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
1918         $seen_ranlib = 1 if /AC_PROG_RANLIB/;
1919     }
1921     # Set input files if not specified by user.
1922     @input_files = @make_list if (! @input_files);
1924     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1925         unless $seen_arg_prog;
1927     close (CONFIGURE);
1930 ################################################################
1932 # Do any extra checking for GNU standards.
1933 sub check_gnu_standards
1935     &require_file ($GNU, 'ChangeLog');
1937     if ($relative_dir eq '.')
1938     {
1939         # In top level (or only) directory.
1940         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
1941                        'AUTHORS');
1942     }
1945 # Do any extra checking for GNITS standards.
1946 sub check_gnits_standards
1948     if ($strictness >= $GNITS && -f $relative_dir . '/COPYING.LIB')
1949     {
1950         &am_error
1951             ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
1952     }
1954     if ($relative_dir eq '.')
1955     {
1956         # In top level (or only) directory.
1957         &require_file ($GNITS, 'THANKS');
1958     }
1961 ################################################################
1963 # Pretty-print something.  HEAD is what should be printed at the
1964 # beginning of the first line, FILL is what should be printed at the
1965 # beginning of every subsequent line.
1966 sub pretty_print_internal
1968     local ($head, $fill, @values) = @_;
1970     local ($column) = length ($head);
1971     local ($result) = $head;
1973     # Fill length is number of characters.  However, each Tab
1974     # character counts for eight.  So we count the number of Tabs and
1975     # multiply by 7.
1976     local ($fill_length) = length ($fill);
1977     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
1979     local ($bol) = 0;
1980     foreach (@values)
1981     {
1982         # "71" because we also print a space.
1983         if ($column + length ($_) > 71)
1984         {
1985             $result .= " \\\n" . $fill;
1986             $column = $fill_length;
1987             $bol = 1;
1988         }
1990         $result .= ' ' unless ($bol);
1991         $result .= $_;
1992         $column += length ($_) + 1;
1993         $bol = 0;
1994     }
1996     $result .= "\n";
1997     return $result;
2000 # Pretty-print something and append to output_vars.
2001 sub pretty_print
2003     $output_vars .= &pretty_print_internal (@_);
2006 # Pretty-print something and append to output_rules.
2007 sub pretty_print_rule
2009     $output_rules .= &pretty_print_internal (@_);
2013 ################################################################
2015 # Read Makefile.am and set up %contents.  Simultaneously copy lines
2016 # from Makefile.am into $output_trailer or $output_vars as
2017 # appropriate.  NOTE we put rules in the trailer section.  We want
2018 # user rules to come after our generated stuff.
2019 sub read_am_file
2021     local ($amfile) = @_;
2023     # Compute relative location of the top object directory.
2024     local (@topdir) = ();
2025     foreach (split (/\//, $relative_dir))
2026     {
2027         next if $_ eq '.' || $_ eq '';
2028         if ($_ eq '..')
2029         {
2030             pop @topdir;
2031         }
2032         else
2033         {
2034             push (@topdir, '..');
2035         }
2036     }
2037     @topdir = ('.') if ! @topdir;
2039     $top_builddir = join ('/', @topdir);
2040     local ($build_rx);
2041     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
2042     local ($header_vars) =
2043         &file_contents_with_transform
2044             ('s/\@top_builddir\@/' . $build_rx . '/g',
2045              'header-vars');
2047     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
2048     print "automake: reading $amfile\n" if $verbose;
2050     $output_vars .= ("# Makefile.in generated automatically by automake "
2051                      . $VERSION . " from Makefile.am\n");
2053     # Generate copyright for generated Makefile.in.
2054     $output_vars .= $gen_copyright;
2056     local ($saw_bk) = 0;
2057     local ($was_rule) = 0;
2058     local ($spacing) = '';
2059     local ($comment) = '';
2060     local ($last_var_name) = '';
2062     while (<AM_FILE>)
2063     {
2064         if (/$IGNORE_PATTERN/o)
2065         {
2066             # Merely delete comments beginning with two hashes.
2067         }
2068         elsif (/$WHITE_PATTERN/o)
2069         {
2070             # Stick a single white line before the incoming macro or rule.
2071             $spacing = "\n";
2072         }
2073         elsif (/$COMMENT_PATTERN/o)
2074         {
2075             # Stick comments before the incoming macro or rule.
2076             $comment .= $spacing . $_;
2077             $spacing = '';
2078         }
2079         else
2080         {
2081             last;
2082         }
2083     }
2085     $output_vars .= $comment . "\n" . $header_vars;
2086     $comment = '';
2087     $spacing = "\n";
2089     local ($is_ok_macro);
2090     while ($_)
2091     {
2092         if (/$IGNORE_PATTERN/o)
2093         {
2094             # Merely delete comments beginning with two hashes.
2095         }
2096         elsif (/$WHITE_PATTERN/o)
2097         {
2098             # Stick a single white line before the incoming macro or rule.
2099             $spacing = "\n";
2100         }
2101         elsif (/$COMMENT_PATTERN/o)
2102         {
2103             # Stick comments before the incoming macro or rule.
2104             $comment .= $spacing . $_;
2105             $spacing = '';
2106         }
2107         elsif ($saw_bk)
2108         {
2109             if ($was_rule)
2110             {
2111                 $output_trailer .= $_;
2112                 $saw_bk = /\\$/;
2113             }
2114             else
2115             {
2116                 $output_vars .= $_;
2117                 $saw_bk = /\\$/;
2118                 # Chop newline and backslash if this line is
2119                 # continued.  FIXME maybe ensure trailing whitespace
2120                 # exists?
2121                 chop if $saw_bk;
2122                 chop if $saw_bk;
2123                 $contents{$last_var_name} .= $_;
2124             }
2125         }
2126         elsif (/$RULE_PATTERN/o)
2127         {
2128             # warn "** Saw rule .$1.\n";
2129             # Found a rule.
2130             $was_rule = 1;
2131             # Value here doesn't matter; for targets we only note
2132             # existence.
2133             $contents{$1} = 1;
2134             $content_lines{$1} = $.;
2135             $output_trailer .= $comment . $spacing . $_;
2136             $comment = $spacing = '';
2137             $saw_bk = /\\$/;
2138         }
2139         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
2140                || /$BOGUS_MACRO_PATTERN/o)
2141         {
2142             # Found a macro definition.
2143             $was_rule = 0;
2144             $last_var_name = $1;
2145             if (substr ($2, -1) eq "\\")
2146             {
2147                 $contents{$1} = substr ($2, 0, length ($2) - 1);
2148             }
2149             else
2150             {
2151                 $contents{$1} = $2;
2152             }
2153             $content_lines{$1} = $.;
2154             $output_vars .= $comment . $spacing . $_;
2155             $comment = $spacing = '';
2156             $saw_bk = /\\$/;
2158             # Error if bogus.
2159             &am_line_error ($., "bad macro name \`$1'")
2160                 if ! $is_ok_macro;
2161         }
2162         else
2163         {
2164             # This isn't an error; it is probably a continued rule.
2165             # In fact, this is what we assume.
2166             $was_rule = 1;
2167             $output_trailer .= $comment . $spacing . $_;
2168             $comment = $spacing = '';
2169             $saw_bk = /\\$/;
2170         }
2172         $_ = <AM_FILE>;
2173     }
2175     $output_trailer .= $comment;
2178 ################################################################
2180 sub initialize_global_constants
2182     # Associative array of standard directory names.  Entry is TRUE if
2183     # corresponding directory should be installed during
2184     # 'install-exec' phase.
2185     %exec_dir_p =
2186         ('bin', 1,
2187          'sbin', 1,
2188          'libexec', 1,
2189          'data', 0,
2190          'sysconf', 1,
2191          'localstate', 1,
2192          'lib', 1,
2193          'info', 0,
2194          'man', 0,
2195          'include', 0,
2196          'oldinclude', 0,
2197          'pkgdata', 0,
2198          'pkglib', 1,
2199          'pkginclude', 0
2200          );
2202     # Helper text for dealing with man pages.
2203     $install_man_format =
2204     '   @sect=@SECTION@;                                \\
2205         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
2206         echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
2207         $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst
2210     $uninstall_man_format =
2211     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
2212         rm -f $(mandir)/man@SECTION@/$$inst
2215     # Commonly found files we look for and automatically include in
2216     # DISTFILES.
2217     @common_files =
2218         (
2219          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
2220          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
2221          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU"
2222          );
2224     # Commonly used files we auto-include, but only sometimes.
2225     @common_sometimes =
2226         (
2227          "version.texi", "aclocal.m4", "acconfig.h", "config.h.top",
2228          "config.h.bot", "stamp-h.in", "mdate-sh", "ansi2knr.c",
2229          "ansi2knr.1", 'stamp-vti', "mkinstalldirs", "install-sh"
2230          );
2232     $USAGE = "\
2233   --amdir=DIR           directory storing config files
2234   --foreign             same as --strictness=foreign
2235   --gnits               same as --strictness=gnits
2236   --gnu                 same as --strictness=gnu
2237   --help                print this help, then exit
2238   --include-deps        include generated dependencies in Makefile.in
2239   --add-missing         add missing standard files to package
2240   --output-dir=DIR      put generated Makefile.in's into DIR
2241   --strictness=LEVEL    set strictness level.  LEVEL is foreign, gnu, gnits
2242   --verbose             verbosely list files processed
2243   --version             print version number, then exit\n";
2245     # Copyright on generated Makefile.ins.
2246     $gen_copyright = "\
2247 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
2248 # This Makefile.in is free software; the Free Software Foundation
2249 # gives unlimited permission to copy, distribute and modify it.
2253 # (Re)-Initialize per-Makefile.am variables.
2254 sub initialize_per_input
2256     # These two variables are used when generating each Makefile.in.
2257     # They hold the Makefile.in until it is ready to be printed.
2258     $output_rules = '';
2259     $output_vars = '';
2260     $output_trailer = '';
2262     # Suffixes found during a run.
2263     @suffixes = ();
2265     # This holds the contents of a Makefile.am, as parsed by
2266     # read_am_file.
2267     %contents = ();
2269     # This holds the line numbers at which various elements of
2270     # %contents are defined.
2271     %content_lines = ();
2273     # This holds the "relative directory" of the current Makefile.in.
2274     # Eg for src/Makefile.in, this is "src".
2275     $relative_dir = '';
2277     # Directory where output files go.  Actually, output files are
2278     # relative to this directory.
2279     $output_directory = '.';
2281     # This holds a list of files that are included in the
2282     # distribution.
2283     %dist_common = ();
2285     # List of dependencies for the obvious targets.
2286     @install_data = ();
2287     @install_exec = ();
2288     @uninstall = ();
2289     @installdirs = ();
2291     @info = ();
2292     @dvi = ();
2293     @all = ();
2294     @check = ();
2295     @installcheck = ();
2296     @clean = ();
2298     @phony = ();
2300     # These are pretty obvious, too.  They are used to define the
2301     # SOURCES and OBJECTS variables.
2302     @sources = ();
2303     @objects = ();
2305     # TRUE if current directory holds any C source files.  (Actually
2306     # holds object extension, but this information is encapsulated in
2307     # the function get_object_extension).
2308     $dir_holds_sources = '';
2310     # TRUE if install targets should work recursively.
2311     $recursive_install = 0;
2313     # All .P files.
2314     %dep_files = ();
2316     # Strictness levels.
2317     $strictness = $default_strictness;
2318     $strictness_name = $default_strictness_name;
2320     # Options from AUTOMAKE_OPTIONS.
2321     %options = ();
2323     # Whether or not dependencies are handled.  Can be further changed
2324     # in handle_options.
2325     $use_dependencies = $cmdline_use_dependencies;
2327     # Per Makefile.am.
2328     $local_maint_charset = $maint_charset;
2332 ################################################################
2334 # Return contents of a file from $am_dir, automatically skipping
2335 # macros or rules which are already known.  Runs command on each line
2336 # as it is read; this command can modify $_.
2337 sub file_contents_with_transform
2339     local ($command, $basename) = @_;
2340     local ($file) = $am_dir . '/' . $basename . '.am';
2342     open (FC_FILE, $file)
2343         || die "automake: installation error: cannot open \`$file'\n";
2344     # Looks stupid?
2345     # print "automake: reading $file\n" if $verbose;
2347     local ($was_rule) = 0;
2348     local ($result_vars) = '';
2349     local ($result_rules) = '';
2350     local ($comment) = '';
2351     local ($spacing) = "\n";
2352     local ($skipping) = 0;
2354     while (<FC_FILE>)
2355     {
2356         eval $command;
2358         if (/$IGNORE_PATTERN/o)
2359         {
2360             # Merely delete comments beginning with two hashes.
2361         }
2362         elsif (/$WHITE_PATTERN/o)
2363         {
2364             # Stick a single white line before the incoming macro or rule.
2365             $spacing = "\n";
2366         }
2367         elsif (/$COMMENT_PATTERN/o)
2368         {
2369             # Stick comments before the incoming macro or rule.
2370             $comment .= $spacing . $_;
2371             $spacing = '';
2372         }
2373         elsif ($saw_bk)
2374         {
2375             if ($was_rule)
2376             {
2377                 $result_rules .= $_ if ! $skipping;
2378             }
2379             else
2380             {
2381                 $result_vars .= $_ if ! $skipping;
2382             }
2383             $saw_bk = /\\$/;
2384         }
2385         elsif (/$RULE_PATTERN/o)
2386         {
2387             # warn "** Found rule .$1.\n";
2388             # Found a rule.
2389             $was_rule = 1;
2390             $skipping = defined $contents{$1};
2391             # warn "** Skip $skipping\n" if $skipping;
2392             $result_rules .= $comment . $spacing . $_ if ! $skipping;
2393             $comment = $spacing = '';
2394             $saw_bk = /\\$/;
2395         }
2396         elsif (/$MACRO_PATTERN/o)
2397         {
2398             # warn "** Found macro .$1.\n";
2399             # Found a variable reference.
2400             $was_rule = 0;
2401             $skipping = defined $contents{$1};
2402             # warn "** Skip $skipping\n" if $skipping;
2403             $result_vars .= $comment . $spacing . $_ if ! $skipping;
2404             $comment = $spacing = '';
2405             $saw_bk = /\\$/;
2406         }
2407         else
2408         {
2409             # This isn't an error; it is probably a continued rule.
2410             # In fact, this is what we assume.
2411             $was_rule = 1;
2412             $result_rules .= $comment . $spacing . $_ if ! $skipping;
2413             $comment = $spacing = '';
2414             $saw_bk = /\\$/;
2415         }
2416     }
2418     close (FC_FILE);
2419     return $result_vars . $result_rules . $comment;
2422 # Like file_contents_with_transform, but no transform.
2423 sub file_contents
2425     return &file_contents_with_transform ('', @_);
2428 # Handle `where_HOW' variable magic.  Does all lookups, generates
2429 # install code,and possibly generates code to define the primary
2430 # variable.  The first argument is the name of the .am file to munge,
2431 # the second argument is the primary variable (eg HEADERS), and all
2432 # subsequent arguments are possible installation locations.  Returns
2433 # list of all values of all _HOW targets.
2435 # FIXME this should be rewritten to be cleaner.  It should be broken
2436 # up into multiple functions.
2438 # Usage is: am_install_var (OPTION..., file, HOW, where...)
2439 sub am_install_var
2441     local (@args) = @_;
2443     local ($do_all, $do_clean) = (1, 0);
2444     while (@args)
2445     {
2446         if ($args[0] eq '-clean')
2447         {
2448             $do_clean = 1;
2449         }
2450         elsif ($args[0] eq '-no-all')
2451         {
2452             $do_all = 0;
2453         }
2454         elsif ($args[0] !~ /^-/)
2455         {
2456             last;
2457         }
2458         shift (@args);
2459     }
2460     local ($file, $primary, @prefixes) = @args;
2462     local (@used) = ();
2463     local (@result) = ();
2465     # Now that configure substitutions are allowed in where_HOW
2466     # variables, it is an error to actually define the primary.
2467     &am_line_error ($primary, "\`$primary' is an anachronism")
2468         if defined $contents{$primary};
2471     # Look for misspellings.  It is an error to have a variable ending
2472     # in a "reserved" suffix whose prefix is unknown, eg
2473     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
2474     # variable of the same name (with "dir" appended) exists.  For
2475     # instance, if the variable "zardir" is defined, then
2476     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
2477     # flexibility in those cases which need it.  Perhaps it should be
2478     # disallowed in the Gnits case?  The problem is, sometimes it is
2479     # useful to put things in a subdir of eg pkgdatadir, perhaps even
2480     # for Gnitsoids.
2481     local (%valid, $varname);
2482     grep ($valid{$_} = 0, @prefixes);
2483     $valid{'EXTRA'} = 0;
2484     foreach $varname (keys %contents)
2485     {
2486         if ($varname =~ /^(.*)_$primary$/)
2487         {
2488             if (! defined $valid{$1} && ! defined $contents{$1 . 'dir'})
2489             {
2490                 &am_line_error ($varname, "invalid variable \"$varname\"");
2491             }
2492             else
2493             {
2494                 # Ensure all extended prefixes are actually used.
2495                 $valid{$1} = 1;
2496             }
2497         }
2498     }
2499     # We never want to examine EXTRA_blah.
2500     undef $valid{'EXTRA'};
2502     local ($clean_file) = $file . '-clean';
2503     local ($one_name);
2504     local ($X);
2505     foreach $X (keys %valid)
2506     {
2507         $one_name = $X . '_' . $primary;
2508         if (defined $contents{$one_name})
2509         {
2510             # Append actual contents of where_PRIMARY variable to
2511             # result.
2512             local ($rcurs);
2513             foreach $rcurs (split (/\s+/, $contents{$one_name}))
2514             {
2515                 # Skip configure substitutions.  Possibly bogus.
2516                 next if $rcurs =~ /^\@.*\@$/;
2517                 push (@result, $rcurs);
2518             }
2520             if ($do_clean)
2521             {
2522                 $output_rules .=
2523                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2524                                                    $clean_file);
2526                 push (@clean, $X . $primary);
2527                 &push_phony_cleaners ($X . $primary);
2528             }
2530             if ($X eq 'check')
2531             {
2532                 push (@check, '$(' . $one_name . ')');
2533             }
2534             else
2535             {
2536                 push (@used, '$(' . $one_name . ')');
2537             }
2538             if ($X eq 'noinst' || $X eq 'check')
2539             {
2540                 # Objects in noinst_FOO or check_FOO never get
2541                 # installed.
2542                 next;
2543             }
2545             $output_rules .=
2546                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2547                                                $file);
2549             push (@uninstall, 'uninstall-' . $X . $primary);
2550             push (@phony, 'uninstall-' . $X . $primary);
2551             push (@installdirs, '$(' . $X . 'dir)');
2552             if ($exec_dir_p{$X})
2553             {
2554                 push (@install_exec, 'install-' . $X . $primary);
2555                 push (@phony, 'install-' . $X . $primary);
2556             }
2557             else
2558             {
2559                 push (@install_data, 'install-' . $X . $primary);
2560                 push (@phony, 'install-' . $X . $primary);
2561             }
2562         }
2563     }
2565     if (@used)
2566     {
2567         # Define it.
2568         &pretty_print ($primary . ' =', '', @used);
2569         $output_vars .= "\n";
2570     }
2572     # Push here because PRIMARY might be configure time determined.
2573     push (@all, '$(' . $primary . ')')
2574         if $do_all && @used;
2576     push (@result, split (/\s+/, $contents{'EXTRA_' . $primary}))
2577         if defined $contents{'EXTRA_' . $primary};
2579     return (@result);
2583 ################################################################
2585 # Verify that the file must exist in the current directory.
2586 # Usage: require_file (isconfigure, line_number, strictness, file)
2587 # strictness is the strictness level at which this file becomes
2588 # required.
2589 sub require_file_internal
2591     local ($is_configure, $line, $mystrict, @files) = @_;
2592     local ($file, $fullfile);
2594     foreach $file (@files)
2595     {
2596         $fullfile = $relative_dir . "/" . $file;
2598         if (-f $fullfile)
2599         {
2600             &push_dist_common ($file);
2601         }
2602         elsif ($strictness >= $mystrict)
2603         {
2604             # Only install missing files according to our desired
2605             # strictness level.
2606             if ($add_missing && -f ($am_dir . '/' . $file))
2607             {
2608                 # Install the missing file.  Symlink if we can, copy
2609                 # if we must.
2610                 if ($symlink_exists)
2611                 {
2612                     symlink ($am_dir . '/' . $file, $fullfile);
2613                 }
2614                 else
2615                 {
2616                     system ('cp', $am_dir . '/' . $file, $fullfile);
2617                 }
2619                 # FIXME this is a hack.  Should have am_warn.
2620                 local ($save) = $exit_status;
2621                 if ($is_configure)
2622                 {
2623                     &am_conf_line_error
2624                         ($line,
2625                          "required file \"$fullfile\" not found; installing");
2626                 }
2627                 else
2628                 {
2629                     &am_line_error
2630                         ($line,
2631                          "required file \"$fullfile\" not found; installing");
2632                 }
2633                 $exit_status = $save;
2634             }
2635             else
2636             {
2637                 # Only an error if strictness constraint violated.
2638                 if ($is_configure)
2639                 {
2640                     &am_conf_line_error
2641                         ($line, "required file \"$fullfile\" not found");
2642                 }
2643                 else
2644                 {
2645                     &am_line_error
2646                         ($line, "required file \"$fullfile\" not found");
2647                 }
2648             }
2649         }
2650     }
2653 # Like require_file_with_line, but error messages refer to
2654 # configure.in, not the current Makefile.am.
2655 sub require_file_with_conf_line
2657     &require_file_internal (1, @_);
2660 sub require_file_with_line
2662     &require_file_internal (0, @_);
2665 sub require_file
2667     &require_file_internal (0, '', @_);
2670 # Require a file that is also required by Autoconf.  Looks in
2671 # configuration path, as specified by AC_CONFIG_AUX_DIR.
2672 sub require_config_file
2674     local ($mystrict, @files) = @_;
2675     local ($file, $dir);
2676     local ($found_it);
2678     foreach $file (@files)
2679     {
2680         $found_it = 0;
2681         foreach $dir (@config_aux_path)
2682         {
2683             $fullfile = $dir . "/" . $file;
2685             if (-f $fullfile)
2686             {
2687                 $found_it = 1;
2688                 &push_dist_common ($file) if $dir eq $relative_dir;
2689                 last;
2690             }
2691         }
2692         if (! $found_it)
2693         {
2694             if ($strictness >= $mystrict)
2695             {
2696                 # Only install missing files according to our desired
2697                 # strictness level.
2698                 if ($add_missing && -f ($am_dir . '/' . $file))
2699                 {
2700                     # Install the missing file.  Symlink if we can, copy
2701                     # if we must.
2702                     if ($symlink_exists)
2703                     {
2704                         symlink ($am_dir . '/' . $file, $fullfile);
2705                     }
2706                     else
2707                     {
2708                         system ('cp', $am_dir . '/' . $file, $fullfile);
2709                     }
2711                     # FIXME this is a hack.  Should have am_warn.
2712                     local ($save) = $exit_status;
2713                     &am_error
2714                         ("required file \"$fullfile\" not found; installing");
2715                     $exit_status = $save;
2716                 }
2717                 else
2718                 {
2719                     # Only an error if strictness constraint violated.
2720                     &am_error ("required file \"$fullfile\" not found");
2721                 }
2722             }
2723         }
2724     }
2727 ################################################################
2729 # Push a list of files onto dist_common.
2730 sub push_dist_common
2732     local (@files) = @_;
2733     local ($file);
2735     foreach $file (@files)
2736     {
2737         $dist_common{$file} = 1;
2738     }
2741 # Push a list of clean targets onto phony.
2742 sub push_phony_cleaners
2744     local ($base) = @_;
2745     local ($target);
2746     foreach $target ('mostly', 'dist', '', 'maintainer-')
2747     {
2748         push (@phony, $target . 'clean-' . $base);
2749     }
2752 # Set strictness.
2753 sub set_strictness
2755     $strictness_name = $_[0];
2756     if ($strictness_name eq 'gnu')
2757     {
2758         $strictness = $GNU;
2759     }
2760     elsif ($strictness_name eq 'gnits')
2761     {
2762         $strictness = $GNITS;
2763     }
2764     elsif ($strictness_name eq 'foreign')
2765     {
2766         $strictness = $FOREIGN;
2767     }
2768     else
2769     {
2770         die "automake: level \`$strictness_name' not recognized\n";
2771     }
2775 ################################################################
2777 # Return directory name of file.
2778 sub dirname
2780     local ($file) = @_;
2781     local ($sub);
2783     ($sub = $file) =~ s,/+[^/]+$,,g;
2784     $sub = '.' if $sub eq $file;
2785     return $sub;
2788 # Make a directory.
2789 sub mkdir
2791     local ($dirname) = @_;
2792     system ("mkdir", $dirname);
2795 ################################################################
2797 # Print an error message and set exit status.
2798 sub am_error
2800     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
2801     $exit_status = 1;
2804 sub am_line_error
2806     local ($symbol, @args) = @_;
2808     if ($symbol)
2809     {
2810         # If SYMBOL not already a line number, look it up in Makefile.am.
2811         $symbol = $content_lines{$symbol} unless $symbol =~ /^\d+$/;
2812         $symbol .= ': ' if $symbol;
2813         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
2814         $exit_status = 1;
2815     }
2816     else
2817     {
2818         &am_error (@args);
2819     }
2822 # Like am_error, but while scanning configure.in.
2823 sub am_conf_error
2825     # FIXME can run in subdirs.
2826     warn "automake: configure.in: ", join (' ', @_), "\n";
2827     $exit_status = 1;
2830 # Error message with line number referring to configure.in.
2831 sub am_conf_line_error
2833     local ($line, @args) = @_;
2835     if ($line)
2836     {
2837         warn "configure.in: $line: ", join (' ', @args), "\n";
2838         $exit_status = 1;
2839     }
2840     else
2841     {
2842         &am_conf_error (@args);
2843     }
2846 # Tell user where our aclocal.m4 is, but only once.
2847 sub keyed_aclocal_warning
2849     local ($key) = @_;
2850     warn "automake: macro \`$key' can be found in ${am_dir}/aclocal.m4\n";
2853 # Print usage information.
2854 sub usage
2856     print "Usage: automake [OPTION] ... [Makefile]...\n";
2857     print $USAGE;
2858     print "\nFiles which are automatically distributed, if found:\n";
2859     $~ = "USAGE_FORMAT";
2860     local (@lcomm) = sort ((@common_files, @common_sometimes));
2861     local ($one, $two, $three, $four);
2862     while (@lcomm > 0)
2863     {
2864         $one = shift @lcomm;
2865         $two = @lcomm ? shift @lcomm : '';
2866         $three = @lcomm ? shift @lcomm : '';
2867         $four = @lcomm ? shift @lcomm : '';
2868         write;
2869     }
2871     exit 0;
2874 format USAGE_FORMAT =
2875   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
2876   $one,               $two,               $three,             $four