Bug fixes. More dejagnu support
[automake.git] / automake.in
blobda1b76543827eaa171abd33d8221bec54cf2ca07
1 #!@PERL@
2 # -*- perl -*-
3 # @configure_input@
5 eval 'exec @PERL@ -S $0 ${1+"$@"}'
6     if 0;
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 # Directory where output files go.  Actually, output files are
92 # relative to this directory.
93 $output_directory = '.';
95 # Relative location of top build directory.
96 $top_builddir = '';
98 # List of Makefile.am's to process.
99 @input_files = ();
101 # List of files in AC_OUTPUT without Makefile.am.
102 @other_input_files = ();
103 # Line number at which AC_OUTPUT seen.
104 $ac_output_line = 0;
106 # List of directories to search for configure-required files.  This
107 # can be set by AC_CONFIG_AUX_DIR.
108 @config_aux_path = ('.', '..', '../..');
109 $config_aux_dir = '';
111 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
112 $seen_make_set = 0;
114 # Whether ud_GNU_GETTEXT has been seen in configure.in.
115 $seen_gettext = 0;
116 # Line number at which ud_GNU_GETTEXT seen.
117 $ac_gettext_line = 0;
119 # Whether ALL_LINGUAS has been seen.
120 $seen_linguas = '';
121 # The actual text.
122 $all_linguas = '';
123 # Line number at which it appears.
124 $all_linguas_line = 0;
126 # 1 if AC_PROG_INSTALL seen, 2 if fp_PROG_INSTALL seen.
127 $seen_prog_install = 0;
129 # 1 if any scripts installed, 0 otherwise.
130 $scripts_installed = 0;
132 # Whether AC_PATH_XTRA has been seen in configure.in.
133 $seen_path_xtra = 0;
135 # Whether YACC variable has been seen in configure.in.
136 $seen_prog_yacc = 0;
138 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
139 # AC_CHECK_TOOL also sets this.
140 $seen_canonical = 0;
142 # TRUE if we've seen AC_PROG_RANLIB.
143 $seen_ranlib = 0;
145 # TRUE if we've seen AC_ARG_PROGRAM.
146 $seen_arg_prog = 0;
148 # TRUE if we've seen gm_PROG_LIBTOOL or AC_PROG_LIBTOOL.
149 $seen_libtool = 0;
150 $libtool_line = 0;
152 # TRUE if we've seen jm_MAINTAINER_MODE.
153 $seen_maint_mode = 0;
155 # TRUE if we've seen PACKAGE and VERSION.
156 $seen_package = 0;
157 $seen_version = 0;
160 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
161 # handled in a funny way: if seen in the top-level Makefile.am, it is
162 # used for every directory which does not specify a different value.
163 # The rationale here is that some directories (eg gettext) might be
164 # distributions of other packages, and thus require their own charset
165 # info.  However, the DIST_CHARSET must be the same for the entire
166 # package; it can only be set at top-level.
167 # FIXME this yields bugs when rebuilding.  What to do?  Always
168 # read (and sometimes discard) top-level Makefile.am?
169 $maint_charset = '';
170 $dist_charset = 'utf8';         # recode doesn't support this yet.
172 # Name of input file ("Makefile.in") and output file ("Makefile.am").
173 # These have no directory components.
174 $am_file_name = '';
175 $in_file_name = '';
179 &initialize_global_constants;
181 # Parse command line.
182 &parse_arguments (@ARGV);
184 # Do configure.in scan only once.
185 &scan_configure;
187 die "automake: no \`Makefile.am' found or specified\n"
188     if ! @input_files;
190 # Now do all the work on each file.
191 foreach $am_file (@input_files)
193     # FIXME should support the AC_OUTPUT ":" syntax here.
194     if (! -f ($am_file . '.am'))
195     {
196         &am_error ('no such file');
197     }
198     else
199     {
200         &generate_makefile ($am_file);
201     }
204 if ($seen_prog_install <= $scripts_installed)
206     &am_conf_error (($scripts_installed ? 'fp_PROG_INSTALL' : 'AC_PROG_INSTALL')
207                     . " must be used in configure.in");
208     &keyed_aclocal_warning ('fp_PROG_INSTALL')
209         if $scripts_installed;
212 exit $exit_status;
215 ################################################################
217 # Parse command line.
218 sub parse_arguments
220     local (@arglist) = @_;
222     # Start off as gnu.
223     &set_strictness ('gnu');
225     while (@arglist)
226     {
227         if ($arglist[0] eq "--version")
228         {
229             print "Automake version $VERSION\n";
230             exit 0;
231         }
232         elsif ($arglist[0] eq "--help")
233         {
234             &usage;
235         }
236         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
237         {
238             $am_dir = $1;
239         }
240         elsif ($arglist[0] eq '--amdir')
241         {
242             &require_argument (@arglist);
243             shift (@arglist);
244             $am_dir = $arglist[0];
245         }
246         elsif ($arglist[0] =~ /^--strictness=(.+)$/)
247         {
248             &set_strictness ($1);
249         }
250         elsif ($arglist[0] eq '--gnu')
251         {
252             &set_strictness ('gnu');
253         }
254         elsif ($arglist[0] eq '--gnits')
255         {
256             &set_strictness ('gnits');
257         }
258         elsif ($arglist[0] eq '--foreign')
259         {
260             &set_strictness ('foreign');
261         }
262         elsif ($arglist[0] eq '--strictness' || $arglist[0] eq '-s')
263         {
264             &require_argument (@arglist);
265             shift (@arglist);
266             &set_strictness ($arglist[0]);
267         }
268         elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
269         {
270             $cmdline_use_dependencies = 0;
271         }
272         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
273         {
274             # Set output directory.
275             $output_directory = $1;
276         }
277         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
278         {
279             &require_argument (@arglist);
280             shift (@arglist);
281             $output_directory = $arglist[0];
282         }
283         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
284         {
285             $add_missing = 1;
286         }
287         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
288         {
289             $verbose = 1;
290         }
291         elsif ($arglist[0] eq '--')
292         {
293             # Stop option processing.
294             shift (@arglist);
295             push (@input_files, @arglist);
296             last;
297         }
298         elsif ($arglist[0] =~ /^-/)
299         {
300             die "automake: unrecognized option -- \`$arglist[0]'\n";
301         }
302         else
303         {
304             push (@input_files, $arglist[0]);
305         }
307         shift (@arglist);
308     }
310     # Take global strictness from whatever we currently have set.
311     $default_strictness = $strictness;
312     $default_strictness_name = $strictness_name;
315 # Ensure argument exists, or die.
316 sub require_argument
318     local ($arg, @arglist) = @_;
319     die "automake: no argument given for option \`$arg'\n"
320         if ! @arglist;
323 ################################################################
325 # Generate a Makefile.in given the name of the corresponding Makefile.
326 sub generate_makefile
328     local ($makefile) = @_;
330     ($am_file_name = $makefile) =~ s/^.*\///;
331     $in_file_name = $am_file_name . '.in';
332     $am_file_name .= '.am';
334     print "automake: creating ", $makefile, ".in\n" if $verbose;
336     &initialize_per_input;
337     $relative_dir = &dirname ($makefile);
339     # At the toplevel directory, we might need config.guess, config.sub
340     # or libtool.
341     if ($relative_dir eq '.')
342     {
343         # libtool requires some files.
344         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
345                                            'config.sub', 'config.guess',
346                                            'libtool') if $seen_libtool;
348         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
349         # config.sub.
350         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
351             if $seen_canonical;
352     }
354     # We still need Makefile.in here, because sometimes the `dist'
355     # target doesn't re-run automake.
356     &push_dist_common ($in_file_name, $am_file_name);
357     push (@sources, '$(SOURCES)')
358         if &variable_defined ('SOURCES');
359     push (@objects, '$(OBJECTS)')
360         if &variable_defined ('OBJECTS');
362     # This is always the default target.  This gives us freedom to do
363     # things in whatever order is convenient.
364     $output_rules .= "default: all\n\n";
365     push (@phony, 'default');
367     &read_am_file ($makefile . '.am');
368     &handle_options;
370     # Check first, because we might modify some state.
371     &check_gnu_standards;
372     &check_gnits_standards;
374     &handle_configure;
375     &handle_gettext;
376     &handle_libraries;
377     &handle_programs;
378     &handle_scripts;
380     # Re-init SOURCES and OBJECTS.  FIXME other code shouldn't depend
381     # on this (but currently does).
382     $contents{'SOURCES'} = join (' ', @sources);
383     $contents{'OBJECTS'} = join (' ', @objects);
385     &handle_texinfo;
386     &handle_man_pages;
387     &handle_data;
388     &handle_headers;
389     &handle_subdirs;
390     &handle_tags;
391     &handle_dist;
392     &handle_dependencies;
393     &handle_tests;
394     &handle_footer;
395     &handle_merge_targets;
396     &handle_installdirs;
397     &handle_clean;
398     &handle_phony;
400     if (! -d ($output_directory . '/' . $relative_dir))
401     {
402         &mkdir ($output_directory . '/' . $relative_dir);
403     }
404     if (! open (GM_FILE, "> " . $output_directory . '/' . $makefile . ".in"))
405     {
406         warn "automake: ${am_file}.in: cannot open: $!\n";
407         $exit_status = 1;
408         return;
409     }
411     print GM_FILE $output_vars;
412     print GM_FILE $output_rules;
413     print GM_FILE $output_trailer;
415     close (GM_FILE);
418 ################################################################
420 # Handle AUTOMAKE_OPTIONS variable.
421 sub handle_options
423     return if ! &variable_defined ('AUTOMAKE_OPTIONS');
425     foreach (split (' ', $contents{'AUTOMAKE_OPTIONS'}))
426     {
427         $options{$_} = 1;
428         if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
429         {
430             &set_strictness ($_);
431         }
432         elsif ($_ eq 'no-installman' || $_ eq 'ansi2knr'
433                || $_ eq 'dist-shar' || $_ eq 'dist-zip'
434                || $_ eq 'dejagnu')
435         {
436             # Explicitly recognize these.
437         }
438         elsif ($_ eq 'no-dependencies')
439         {
440             $use_dependencies = 0;
441         }
442         elsif (/[0-9]+\.?[0-9]+/)
443         {
444             # Got a version number.  Is the syntax too strict?
445             local ($num_version);
446             ($num_version = $VERSION) =~ tr/0-9//d;
447             if ($VERSION < $_)
448             {
449                 &am_line_error ('AUTOMAKE_OPTIONS',
450                                 "require version $_, only have $VERSION");
451                 exit 1;
452             }
453         }
454         else
455         {
456             &am_line_error ('AUTOMAKE_OPTIONS',
457                             'option ', $_, 'not recognized');
458         }
459     }
462 # Return object extension.  Just once, put some code into the output.
463 sub get_object_extension
465     if (! $dir_holds_sources)
466     {
467         # Boilerplate.
468         local ($xform) = '';
469         if (&variable_defined ('CONFIG_HEADER'))
470         {
471             ($xform = &dirname ($contents{'CONFIG_HEADER'}))
472                 =~ s/(\W)/\\$1/g;
473             $xform = '-I' . $xform;
474         }
475         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go';
476         $output_vars .= &file_contents_with_transform ($xform,
477                                                        'compile-vars');
478         $output_rules .= &file_contents ('compile');
479         &push_phony_cleaners ('compile');
481         # If using X, include some extra variable definitions.  NOTE
482         # we don't want to force these into CFLAGS or anything,
483         # because not all programs will necessarily use X.
484         if ($seen_path_xtra)
485         {
486             $output_vars .= ("X_CFLAGS = \@X_CFLAGS\@\n"
487                              . "X_LIBS = \@X_LIBS\@\n"
488                              . "X_EXTRA_LIBS = \@X_EXTRA_LIBS\@\n"
489                              . "X_PRE_LIBS = \@X_PRE_LIBS\@\n");
490         }
492         # Check for automatic de-ANSI-fication.
493         $dir_holds_sources = '.o';
494         push (@suffixes, '.c', '.o');
495         push (@clean, 'compile');
497         if (defined $options{'ansi2knr'})
498         {
499             if (! $fp_c_prototypes)
500             {
501                 &am_line_error ('AUTOMAKE_OPTIONS',
502                                 "option \`ansi2knr' in use but \`fp_C_PROTOTYPES' not in configure.in");
503                 &keyed_aclocal_warning ('fp_C_PROTOTYPES');
504                 # Only give this error once.
505                 $fp_c_prototypes = 1;
506             }
508             $dir_holds_sources = '$o';
509             push (@suffixes, '._c', '._o');
511             &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
512                                      'ansi2knr.c', 'ansi2knr.1');
514             $output_vars .= &file_contents ('kr-vars');
515             $output_rules .= &file_contents ('compile-kr');
516             $output_rules .= &file_contents ('clean-kr');
518             push (@clean, 'kr');
519             &push_phony_cleaners ('kr');
520         }
521     }
522     return $dir_holds_sources;
525 # Handle SOURCE->OBJECT transform for one program or library.
526 sub handle_source_transform
528     # one_file is canonical name.  unxformed is given name.  obj is
529     # object extension.
530     local ($one_file, $unxformed, $obj) = @_;
531     local ($objpat) = $obj;
532     $objpat =~ s/(\W)/\\$1/g;
534     if (&variable_defined ($one_file . "_OBJECTS"))
535     {
536         &am_line_error ($one_file . '_OBJECTS',
537                         $one_file . '_OBJECTS', 'should not be defined');
538         # No point in continuing.
539         return;
540     }
542     local ($source_list);
543     local ($prefix);
544     foreach $prefix ('', 'EXTRA_')
545     {
546         $source_list = '';
547         if (&variable_defined ($prefix . $one_file . "_SOURCES"))
548         {
549             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
550             push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
551                 unless $prefix eq 'EXTRA_';
552             $source_list = $contents{$prefix . $one_file . "_SOURCES"};
553         }
554         elsif ($prefix eq '')
555         {
556             $output_vars .= $one_file . "_SOURCES = " . $unxformed . ".c\n";
557             push (@sources, $unxformed . '.c');
558             push (@objects, $unxformed . $obj);
559             $source_list = $unxformed . ".c ";
560         }
561         else
562         {
563             $output_vars .= "EXTRA_" . $one_file . "_SOURCES =\n";
564         }
566         if ($source_list)
567         {
568             # Turn sources into objects.
569             local (@files) = split (' ', $source_list);
570             local (@result) = ();
571             foreach (@files)
572             {
573                 # Skip header files, including C++-ish ones.
574                 next if /\.[hH]$/;
575                 next if /\.hxx$/;
576                 # Skip things that look like macro references.
577                 next if /^\$\(.*\)$/;
578                 next if /^\$\{.*\}$/;
579                 # Skip things that look like configure substitutions.
580                 next if /^\@.*\@$/;
582                 if (/^(.*)\.[yl]$/)
583                 {
584                     # Automatically include generated .c file in
585                     # distribution.
586                     &push_dist_common ($1 . '.c');
587                 }
589                 # Transform source files into .o files.
590                 s/\.cc$/$obj/g;
591                 s/\.cxx$/$obj/g;
592                 s/\.[cCmylfs]$/$obj/g;
593                 push (@result, $_)
594                     unless $prefix eq 'EXTRA_';
596                 # Transform .o or $o file into .P file (for automatic
597                 # dependency code).
598                 s/$objpat$/.P/g;
599                 $dep_files{'$(srcdir)/.deps/' . $_} = 1;
600             }
602             &pretty_print ($one_file . "_OBJECTS =", "", @result)
603                 unless $prefix eq 'EXTRA_';
604         }
605     }
607     if (&variable_defined ('CONFIG_HEADER'))
608     {
609         $output_rules .= ('$(' . $one_file . "_OBJECTS): "
610                           . $contents{'CONFIG_HEADER'} . "\n");
611     }
613     return @result;
616 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
617 sub handle_lib_objects
619     local ($var) = @_;
621     die "programming error in handle_lib_objects"
622         if ! &variable_defined ($var);
624     # We recognize certain things that are commonly put in LIBADD or
625     # LDADD.
626     local ($lsearch);
628     foreach $lsearch (split (' ', $contents{$var}))
629     {
630         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
631         # means adding entries to dep_files.
632         if ($lsearch eq '@LIBOBJS@')
633         {
634             local ($iter, $rewrite);
635             foreach $iter (keys %libsources)
636             {
637                 if ($iter ne 'alloca.c')
638                 {
639                     ($rewrite = $iter) =~ s/\.c$/.P/;
640                     $dep_files{'$(srcdir)/.deps/' . $rewrite} = 1;
641                     &require_file_with_line ($var, $FOREIGN, $iter);
642                 }
643             }
644         }
645         elsif ($lsearch eq '@ALLOCA@')
646         {
647             &am_line_error ($var,
648                             "\@ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
649                 if ! defined $libsources{'alloca.c'};
650             $dep_files{'$(srcdir)/.deps/alloca.P'} = 1;
651             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
652         }
653     }
656 # Handle C programs.
657 sub handle_programs
659     local (@proglist) = &am_install_var ('-clean',
660                                          'programs', 'PROGRAMS',
661                                          'bin', 'sbin', 'libexec', 'pkglib',
662                                          'noinst', 'check');
663     return if ! @proglist;
665     # If a program is installed, this is required.  We only want this
666     # error to appear once.
667     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
668         unless $seen_arg_prog;
669     $seen_arg_prog = 1;
671     local ($obj) = &get_object_extension;
672     local ($one_file, $xname, $munge);
674     foreach $one_file (@proglist)
675     {
676         # Canonicalize names.
677         ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
678         if ($xname ne $one_file)
679         {
680             local ($xt);
681             foreach $xt ('_LDADD', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
682             {
683                 &am_line_error ($one_file . $xt,
684                                 "invalid variable \`" . $one_file . $xt
685                                 . "'; should be \`" . $xname . $xt . "'")
686                     if &variable_defined ($one_file . $xt);
687             }
688         }
690         &handle_source_transform ($xname, $one_file, $obj);
692         if (&variable_defined ($xname . "_LDADD"))
693         {
694             &handle_lib_objects ($xname . '_LDADD');
695         }
696         else
697         {
698             # User didn't define prog_LDADD override.  So do it.
699             $output_vars .= $xname . '_LDADD = $(LDADD)' . "\n";
700         }
702         $output_rules .=
703             &file_contents_with_transform
704                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
705                  . 's/\@XPROGRAM\@/' . $xname . '/go;',
706                  'program');
707     }
709     &handle_lib_objects ('LDADD')
710         if &variable_defined ('LDADD');
713 # Handle libraries.
714 sub handle_libraries
716     local (@liblist) = &am_install_var ('-no-all', '-clean',
717                                         'libraries', 'LIBRARIES',
718                                         'lib', 'pkglib', 'noinst', 'check');
719     return if ! @liblist;
721     if (! $seen_ranlib)
722     {
723         # FIXME need am_line_error here.  But we don't know which
724         # variable exists.  Must add a loop...  No.  Must have
725         # am_install_var return a hash.  Otherwise the user could add
726         # install directories that we'd never find.
727         &am_error ("library requires either \`AC_PROG_RANLIB' or `gm_PROG_LIBTOOL' in configure.in");
728         # Only get this error once.
729         $seen_ranlib = 1;
730     }
732     # Generate _LIBFILES variables.  Too bad we can't do this in
733     # am_install_var.
734     local ($onedir, $onelib);
735     local (@outlist);
736     foreach $onedir ('lib', 'pkglib', 'noinst', 'check')
737     {
738         if (&variable_defined ($onedir . '_LIBRARIES'))
739         {
740             @outlist = ();
741             foreach $onelib (split (' ', $contents{$onedir . '_LIBRARIES'}))
742             {
743                 push (@outlist, 'lib' . $onelib . '.a');
744             }
745             &pretty_print ($onedir . '_LIBFILES =', "", @outlist);
746         }
747     }
748     push (@all, '$(LIBFILES)');
750     local ($obj) = &get_object_extension;
751     local ($munge);
752     foreach $onelib (@liblist)
753     {
754         if (&variable_defined ($onelib . '_LIBADD'))
755         {
756             &handle_lib_objects ($onelib . '_LIBADD');
757         }
758         else
759         {
760             # Generate support for conditional object inclusion in
761             # libraries.
762             $output_vars .= $onelib . "_LIBADD =\n";
763         }
765         &handle_source_transform ($onelib, $onelib, $obj);
767         $output_rules .=
768             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go',
769                                            'library');
770     }
772     # Turn "foo" into "libfoo.a" and include macro definition.
773     grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
775     if (! &variable_defined ('LIBFILES'))
776     {
777         &pretty_print ('LIBFILES = ', "", @liblist);
778     }
780     if ($seen_libtool)
781     {
782         $output_vars .= ('AR = $(LIBTOOL) archive' . "\n"
783                          . 'RANLIB = $(LIBTOOL) ranlib' . "\n"
784                          . 'LCOMPILE = $(LIBTOOL) compile $(DEFS) $(INCLUDES)'
785                          . ' $(CPPFLAGS) $(CFLAGS)' . "\n");
786     }
787     else
788     {
789         $output_vars .= ('AR = ar' . "\n"
790                          . 'RANLIB = @RANLIB@' . "\n");
791     }
794 # Handle scripts.
795 sub handle_scripts
797     # NOTE we no longer automatically clean SCRIPTS, because it is
798     # useful to sometimes distribute scripts verbatim.  This happens
799     # eg in Automake itself.
800     local ($msi);
801     $msi = &am_install_var ('scripts', 'SCRIPTS',
802                             'bin', 'sbin', 'libexec', 'pkgdata',
803                             'noinst', 'check');
805     # We really only want a boolean value.
806     $scripts_installed = 1 if $msi;
808     if ($scripts_installed)
809     {
810         # If a program is installed, this is required.  We only want this
811         # error to appear once.
812         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
813             unless $seen_arg_prog;
814         $seen_arg_prog = 1;
815     }
818 # Search a file for a "version.texi" Texinfo include.  Return the name
819 # of the include file if found, or the empty string if not.  A
820 # "version.texi" file is actually any file whose name matches
821 # "vers*.texi".
822 sub grep_for_vers_texi
824     local ($filename) = @_;
826     if (! open (TEXI, $filename))
827     {
828         &am_error ("couldn't open \`$filename': $!");
829         return '';
830     }
831     print "automake: reading $filename\n" if $verbose;
833     while (<TEXI>)
834     {
835         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
836         {
837             # Found it.
838             close (TEXI);
839             return $1;
840         }
841     }
843     close (TEXI);
844     return '';
847 # Handle all Texinfo source.
848 sub handle_texinfo
850     &am_line_error ('TEXINFOS',
851                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
852         if &variable_defined ('TEXINFOS');
853     return if (! &variable_defined ('info_TEXINFOS')
854                && ! &variable_defined ('html_TEXINFOS'));
856     local (@texis) = split (' ', $contents{'info_TEXINFOS'});
858     local (@infos_list, @info_deps_list, @dvis_list, @texi_deps);
859     local ($infobase, $info_cursor);
860     local (%versions);
861     local ($done) = 0;
862     local ($vti);
863     local ($tc_cursor, @texi_cleans);
864     local ($canonical);
866     foreach $info_cursor (@texis)
867     {
868         ($infobase = $info_cursor) =~ s/\.texi$//;
870         # If 'version.texi' is referenced by input file, then include
871         # automatic versioning capability.
872         local ($vtexi)
873             = &grep_for_vers_texi ($relative_dir . "/" . $info_cursor);
874         if ($vtexi)
875         {
876             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
877                 if (defined $versions{$vtexi});
878             $versions{$vtexi} = $info_cursor;
880             # We number the stamp-vti files.  This is doable since the
881             # actual names don't matter much.  We only number starting
882             # with the second one, so that the common case looks nice.
883             $vti = 'vti' . ($done ? $done : '');
884             &push_dist_common ($vtexi, 'stamp-' . $vti);
885             push (@clean, $vti);
887             # Only require once.
888             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
889                                           'mdate-sh')
890                 if ! $done;
891             ++$done;
893             local ($conf_pat);
894             ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
895             $output_rules .=
896                 &file_contents_with_transform
897                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
898                      . 's/\@VTI\@/' . $vti . '/g; '
899                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
900                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
901                      'texi-version');
903             &push_phony_cleaners ($vti);
904         }
906         # If user specified file_TEXINFOS, then use that as explicit
907         # dependency list.
908         @texi_deps = ();
909         push (@texi_deps, $info_cursor);
910         push (@texi_deps, $vtexi) if $vtexi;
912         # Canonicalize name first.
913         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
914         if (&variable_defined ($canonical . "_TEXINFOS"))
915         {
916             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
917             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
918         }
920         $output_rules .= ("\n" . $infobase . ".info: "
921                           . join (' ', @texi_deps) . "\n\n");
923         push (@infos_list, $infobase . '.info*');
924         push (@info_deps_list, $infobase . '.info');
925         push (@dvis_list, $infobase . '.dvi');
927         # Generate list of things to clean for this target.  We do
928         # this explicitly because otherwise too many things could be
929         # removed.  In particular the ".log" extension might
930         # reasonably be used in other contexts by the user.
931         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
932                             'ky', 'log', 'pg', 'toc', 'tp', 'vr', 'op')
933         {
934             push (@texi_cleans, $infobase . '.' . $tc_cursor);
935         }
936     }
938     # Some boilerplate.
939     $output_vars .= &file_contents ('texinfos-vars');
940     $output_rules .= &file_contents ('texinfos');
941     push (@phony, 'install-info', 'uninstall-info');
943     # How to clean.
944     $output_rules .= "\nmostlyclean-info:\n";
945     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
946     $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
947                       . "maintainer-clean-info:\n\t"
948                       . 'rm -f $(INFOS)' . "\n");
949     &push_phony_cleaners ('info');
951     push (@suffixes, '.texi', '.info', '.dvi');
952     push (@uninstall, 'uninstall-info');
953     push (@clean, 'info');
954     push (@info, '$(INFO_DEPS)');
955     push (@dvi, '$(DVIS)');
956     push (@installdirs, '$(infodir)');
957     unshift (@install_data, 'install-info');
959     # Make sure documentation is made and installed first.  Use
960     # $(INFO_DEPS), not 'info', because otherwise recursive makes get
961     # run twice during "make all".
962     unshift (@all, '$(INFO_DEPS)');
964     $output_vars .= ("INFOS = " . join (' ', @infos_list) . "\n"
965                      . "INFO_DEPS = " . join (' ', @info_deps_list)  . "\n"
966                      . "DVIS = " . join (' ', @dvis_list) . "\n"
967                      # This next isn't strictly needed now -- the
968                      # places that look here could easily be changed
969                      # to look in info_TEXINFOS.  But this is probably
970                      # better, in case noinst_TEXINFOS is ever
971                      # supported.
972                      . "TEXINFOS = " . $contents{'info_TEXINFOS'} . "\n\n");
974     # Do some error checking.
975     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
978 # Handle any man pages.
979 sub handle_man_pages
981     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
982         if &variable_defined ('MANS');
983     return if ! &variable_defined ('man_MANS');
985     # We generate the manpage install code by hand to avoid the use of
986     # basename in the generated Makefile.
987     local (@mans) = split (' ', $contents{'man_MANS'});
988     local (%sections, %inames, %secmap, %fullsecmap);
989     foreach (@mans)
990     {
991         # FIXME: statement without effect:
992         /^(.*)\.([0-9])([a-z]*)$/;
993         $sections{$2} = 1;
994         $inames{$1} = $_;
995         $secmap{$1} = $2;
996         $fullsecmap{$1} = $2 . $3;
997     }
999     # We don't really need this, but we use it in case we ever want to
1000     # support noinst_MANS.
1001     $output_vars .= "MANS = " . $contents{'man_MANS'} . "\n";
1003     # Generate list of install dirs.
1004     $output_rules .= "install-man: \$(MANS)\n";
1005     foreach (keys %sections)
1006     {
1007         push (@installdirs, '$(mandir)/man' . $_);
1008         $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
1009                           . $_ . "\n");
1010     }
1011     push (@phony, 'install-man');
1013     # Generate install target.
1014     local ($key);
1015     foreach $key (keys %inames)
1016     {
1017         $_ = $install_man_format;
1018         s/\@SECTION\@/$secmap{$key}/g;
1019         s/\@MAN\@/$inames{$key}/g;
1020         s/\@FULLSECT\@/$fullsecmap{$key}/g;
1021         s/\@MANBASE\@/$key/g;
1022         $output_rules .= $_;
1023     }
1024     $output_rules .= "\n";
1026     $output_rules .= "uninstall-man:\n";
1027     foreach $key (keys %inames)
1028     {
1029         $_ = $uninstall_man_format;
1030         s/\@SECTION\@/$secmap{$key}/g;
1031         s/\@MAN\@/$inames{$key}/g;
1032         s/\@FULLSECT\@/$fullsecmap{$key}/g;
1033         s/\@MANBASE\@/$key/g;
1034         $output_rules .= $_;
1035     }
1036     $output_rules .= "\n";
1037     push (@phony, 'uninstall-man');
1039     $output_vars .= &file_contents ('mans-vars');
1041     if (! defined $options{'no-installman'})
1042     {
1043         push (@install_data, 'install-man');
1044         push (@uninstall, 'uninstall-man');
1045         push (@all, '$(MANS)');
1046     }
1049 # Handle DATA variables.
1050 sub handle_data
1052     &am_install_var ('data', 'DATA', 'data', 'sysconf',
1053                      'sharedstate', 'localstate', 'pkgdata',
1054                      'noinst', 'check');
1057 # Handle TAGS.
1058 sub handle_tags
1060     local ($tagging) = 0;
1062     push (@phony, 'tags');
1063     if (&variable_defined ('SUBDIRS'))
1064     {
1065         $output_rules .= &file_contents ('tags');
1066         push (@phony, 'tags-recursive');
1067         $tagging = 1;
1068     }
1069     elsif ($dir_holds_sources || &variable_defined ('ETAGS_ARGS'))
1070     {
1071         $output_rules .= &file_contents ('tags-subd');
1072         $tagging = 1;
1073     }
1075     if ($tagging)
1076     {
1077         $output_rules .= &file_contents ('tags-clean');
1078         push (@clean, 'tags');
1079         &push_phony_cleaners ('tags');
1080     }
1081     else
1082     {
1083         # Every Makefile must define some sort of TAGS rule.
1084         # Otherwise, it would be possible for a top-level "make TAGS"
1085         # to fail because some subdirectory failed.
1086         $output_rules .= "tags: TAGS\nTAGS:\n\n";
1087     }
1090 # Worker for handle_dist.
1091 sub handle_dist_worker
1093     $output_rules .= 'distdir: $(DEP_DISTFILES)' . "\n";
1095     # Initialization; only at top level.
1096     if ($relative_dir eq '.')
1097     {
1098         if ($strictness >= $GNITS)
1099         {
1100             # For Gnits users, this is pretty handy.  Look at 15 lines
1101             # in case some explanatory text is desirable.
1102             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | grep -e "$(VERSION)" > /dev/null; then :; else \\
1103           echo "NEWS not updated; not releasing" 1>&2; \\
1104           exit 1;                               \\
1105         fi
1107         }
1110         $output_rules .=
1111             # Create dist directory.
1112             '   rm -rf $(distdir)
1113         mkdir $(distdir)
1114         chmod 777 $(distdir)
1117         # Only run automake in `dist' target if --include-deps not
1118         # specified.  That way the recipient of a distribution can run
1119         # "make dist" and not need Automake.
1120         if ($cmdline_use_dependencies)
1121         {
1122             $output_rules .=
1123                 (
1124                  # We need an absolute path for --output-dir.  Thus the
1125                  # weirdness.
1126                  '      distdir=`cd $(distdir) && pwd` \\
1127           && cd $(srcdir) \\
1128           && automake --include-deps --output-dir=$$distdir --strictness='
1129                  # Set strictness of output.
1130                  . $strictness_name . "\n"
1131                  );
1132         }
1133     }
1135     # In loop, test for file existence because sometimes a file gets
1136     # included in DISTFILES twice.  For example this happens when a
1137     # single source file is used in building more than one program.
1138     # Also, there are situations in which "ln" can fail.  For instance
1139     # a file to distribute could actually be a cross-filesystem
1140     # symlink -- this can easily happen if "gettextize" was run on the
1141     # distribution.  Note that DISTFILES can contain a wildcard (for
1142     # info files, sigh), so we must use the echo trick.
1143     $output_rules .= '  @for file in `cd $(srcdir) && echo $(DISTFILES)`; do \\
1144           test -f $(distdir)/$$file \\
1145           || ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \\
1146           || cp -p $(srcdir)/$$file $(distdir)/$$file; \\
1147         done
1150     # If we have SUBDIRS, create all dist subdirectories and do
1151     # recursive build.
1152     if (&variable_defined ('SUBDIRS'))
1153     {
1154         # Test for directory existence here because previous automake
1155         # invocation might have created some directories.  Note that
1156         # we explicitly set distdir for the subdir make; that lets us
1157         # mix-n-match many automake-using packages into one large
1158         # package, and have "dist" at the top level do the right
1159         # thing.
1160         $output_rules .= '      for subdir in $(SUBDIRS); do            \\
1161           test -d $(distdir)/$$subdir           \\
1162           || mkdir $(distdir)/$$subdir          \\
1163           || exit 1;                            \\
1164           chmod 777 $(distdir)/$$subdir;        \\
1165           (cd $$subdir && $(MAKE) distdir=../$(distdir)/$$subdir distdir) \\
1166             || exit 1; \\
1167         done
1169     }
1171     # If the target `dist-hook' exists, run it now.  This allows
1172     # users to do random weird things to the distribution before it is
1173     # packaged up.
1174     if (defined $contents{'dist-hook'})
1175     {
1176         $output_rules .= "\t\$(MAKE) dist-hook\n";
1177     }
1179     push (@phony, 'distdir');
1182 # Handle 'dist' target.
1183 sub handle_dist
1185     # Set up maint_charset.
1186     $local_maint_charset = $contents{'MAINT_CHARSET'}
1187         if &variable_defined ('MAINT_CHARSET');
1188     $maint_charset = $local_maint_charset
1189         if $relative_dir eq '.';
1191     if (&variable_defined ('DIST_CHARSET'))
1192     {
1193         &am_line_error ('DIST_CHARSET',
1194                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
1195             if ! $local_maint_charset;
1196         if ($relative_dir eq '.')
1197         {
1198             $dist_charset = $contents{'DIST_CHARSET'}
1199         }
1200         else
1201         {
1202             &am_line_error ('DIST_CHARSET',
1203                             "DIST_CHARSET can only be defined at top level");
1204         }
1205     }
1207     # Look for common files that should be included in distribution.
1208     local ($cfile);
1209     foreach $cfile (@common_files)
1210     {
1211         if (-f ($relative_dir . "/" . $cfile))
1212         {
1213             &push_dist_common ($cfile);
1214         }
1215     }
1217     # Keys of %dist_common are names of files to distributed.  We put
1218     # README first because it then becomes easier to make a
1219     # Usenet-compliant shar file (in these, README must be first).
1220     # FIXME do more ordering of files here.
1221     local (@coms);
1222     if (defined $dist_common{'README'})
1223     {
1224         push (@coms, 'README');
1225         undef $dist_common{'README'};
1226     }
1227     push (@coms, sort keys %dist_common);
1229     &pretty_print ("DIST_COMMON =", "", @coms);
1230     $output_vars .= "\n";
1232     # Some boilerplate.
1233     $output_vars .= &file_contents ('dist-vars');
1235     # Put these things in rules section so it is easier for whoever
1236     # reads Makefile.in.
1237     if ($relative_dir eq '.')
1238     {
1239         $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
1240     }
1241     else
1242     {
1243         $output_rules .= ("\nsubdir = " . $relative_dir . "\n"
1244                           . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
1245                           . "\n");
1246     }
1248     # Generate 'dist' target, and maybe dist-shar / dist-zip.
1249     if ($relative_dir eq '.')
1250     {
1251         # Rule to check whether a distribution is viable.
1252         $output_rules .= '# This target untars the dist file and tries a VPATH configuration.  Then
1253 # it guarantees that the distribution is self-contained by making another
1254 # tarfile.
1255 distcheck: dist
1256         rm -rf $(distdir)
1257         $(TAR) zxf $(distdir).tar.gz
1258         mkdir $(distdir)/=build
1259         mkdir $(distdir)/=inst
1260         dc_install_base=`cd $(distdir)/=inst && pwd`; \\
1261         cd $(distdir)/=build \\
1262           && ../configure --srcdir=.. --prefix=$$dc_install_base \\
1263           && $(MAKE) \\
1264           && $(MAKE) check \\
1265           && $(MAKE) install \\
1266           && $(MAKE) installcheck \\
1267           && $(MAKE) dist
1268         rm -rf $(distdir)
1269         @echo "========================"; \\
1270         echo "$(distdir).tar.gz is ready for distribution"; \\
1271         echo "========================"
1274         $output_rules .= 'dist: distdir' . "\n\t";
1275         $output_rules .= 'chmod -R a+r $(distdir)' . "\n\t";
1276         $output_rules .= '$(TAR) chozf $(distdir).tar.gz $(distdir)';
1277         $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
1279         if (defined $options{'dist-shar'})
1280         {
1281             $output_rules .= 'dist-shar: distdir' . "\n\t";
1282             $output_rules .= 'chmod -R a+r $(distdir)' . "\n\t";
1283             $output_rules .= 'shar $(distdir) | gzip > $(distdir).shar.gz';
1284             $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
1285         }
1287         if (defined $options{'dist-zip'})
1288         {
1289             $output_rules .= 'dist-zip: distdir' . "\n\t";
1290             $output_rules .= 'chmod -R a+r $(distdir)' . "\n\t";
1291             $output_rules .= 'zip -rq $(distdir).zip $(distdir)';
1292             $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
1293         }
1294     }
1296     # Generate distdir target.
1297     &handle_dist_worker;
1300 # Handle auto-dependency code.
1301 sub handle_dependencies
1303     if ($use_dependencies)
1304     {
1305         # Include GNU-make-specific auto-dep code.
1306         if ($dir_holds_sources)
1307         {
1308             &pretty_print ('DEP_FILES =', "", sort keys %dep_files);
1309             $output_rules .= &file_contents ('depend');
1310         }
1311     }
1312     else
1313     {
1314         # Include any auto-generated deps that are present.
1315         if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
1316         {
1317             local ($depfile);
1318             local ($gpat) = $relative_dir . "/.deps/*.P";
1320             foreach $depfile (<${gpat}>)
1321             {
1322                 if (! open (DEP_FILE, $depfile))
1323                 {
1324                     &am_error ("couldn't open \`$depfile': $!");
1325                     next;
1326                 }
1327                 print "automake: reading $depfile\n" if $verbose;
1329                 # Slurp entire file.
1330                 $output_rules .= join ('', <DEP_FILE>);
1332                 close (DEP_FILE);
1333             }
1335             $output_rules .= "\n";
1336         }
1337     }
1340 # Handle subdirectories.
1341 sub handle_subdirs
1343     if (! &variable_defined ('SUBDIRS'))
1344     {
1345         &am_conf_error
1346             ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined")
1347                 if $seen_gettext && $relative_dir eq '.';
1348         return;
1349     }
1351     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
1352         if $seen_gettext;
1354     return if ! &variable_defined ('SUBDIRS');
1356     # Make sure each directory mentioned in SUBDIRS actually exists.
1357     local ($dir);
1358     foreach $dir (split (' ', $contents{'SUBDIRS'}))
1359     {
1360         # Skip directories substituted by configure.
1361         next if $dir =~ /^\@.*\@$/;
1362         &am_line_error ('SUBDIRS',
1363                         "required directory $relative_dir/$dir does not exist")
1364             if ! -d $relative_dir . '/' . $dir;
1365     }
1367     $output_rules .= &file_contents ('subdirs');
1369     # Push a bunch of phony targets.
1370     local ($phonies);
1371     foreach $phonies ('-data', '-exec', 'dirs')
1372     {
1373         push (@phony, 'install' . $phonies . '-recursive');
1374         push (@phony, 'uninstall' . $phonies . '-recursive');
1375     }
1376     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
1377     {
1378         push (@phony, $phonies . '-recursive');
1379     }
1380     &push_phony_cleaners ('recursive');
1382     push (@check, "check-recursive");
1383     push (@installcheck, "installcheck-recursive");
1384     push (@info, "info-recursive");
1385     push (@dvi, "dvi-recursive");
1387     $recursive_install = 1;
1390 # Handle remaking and configure stuff.
1391 sub handle_configure
1393     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
1394     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
1395         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
1397     local ($top_reldir);
1398     if ($relative_dir ne '.')
1399     {
1400         # In subdirectory.
1401         $output_rules .= &file_contents ('remake-subd');
1402         $top_reldir = '../';
1403     }
1404     else
1405     {
1406         if (-f 'aclocal.m4')
1407         {
1408             $output_vars .= "ACLOCAL = aclocal.m4\n";
1409             &push_dist_common ('aclocal.m4');
1410         }
1411         $output_rules .= &file_contents ('remake');
1413         &am_error
1414             ("\`install.sh' is an anachronism; use \`install-sh' instead")
1415                 if -f $relative_dir . '/install.sh';
1417         # If we have a configure header, require it.
1418         if ($config_header)
1419         {
1420             # FIXME this restriction should be lifted.
1421             # FIXME first see if it is even needed as-is.
1422             &am_conf_line_error ($config_header_line,
1423                                  "argument to AC_CONFIG_HEADER contains \`/'\n")
1424                 if ($config_header =~ /\//);
1426             &require_file_with_conf_line ($config_header_line,
1427                                           $FOREIGN, $config_header);
1429             # Header defined and in this directory.
1430             if (-f 'acconfig.h')
1431             {
1432                 $output_vars .= "ACCONFIG = acconfig.h\n";
1433                 &push_dist_common ('acconfig.h');
1434             }
1435             if (-f $config_name . '.top')
1436             {
1437                 $output_vars .= "CONFIG_TOP = ${config_name}.top\n";
1438                 &push_dist_common ($config_name . '.top');
1439             }
1440             if (-f $config_name . '.bot')
1441             {
1442                 $output_vars .= "CONFIG_BOT = ${config_name}.bot\n";
1443                 &push_dist_common ($config_name . '.bot');
1444             }
1446             &require_file_with_conf_line ($config_header_line, $FOREIGN,
1447                                           'stamp-h.in');
1449             $output_rules .= &file_contents ('remake-hdr');
1450             $output_vars .= "CONFIG_HEADER_IN = ${config_header}\n";
1451         }
1453         $top_reldir = '';
1454     }
1456     # Set location of mkinstalldirs.
1457     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
1458     {
1459         $output_vars .= 'mkinstalldirs = ' . $config_aux_dir;
1460     }
1461     else
1462     {
1463         $output_vars .= 'mkinstalldirs = $(top_srcdir)';
1464     }
1465     $output_vars .= '/mkinstalldirs' . "\n";
1467     &am_line_error ('CONFIG_HEADER',
1468                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
1469         if &variable_defined ('CONFIG_HEADER');
1471     # Generate CONFIG_HEADER define, and define interally.
1472     $output_vars .= "CONFIG_HEADER = ${top_builddir}/${config_name}\n"
1473         if $config_name;
1474     $contents{'CONFIG_HEADER'} = "${top_builddir}/${config_name}"
1475         if $config_name;
1477     # Now look for other files in this directory which must be remade
1478     # by config.status, and generate rules for them.
1479     local ($file, $local, $input);
1480     foreach $file (@other_input_files)
1481     {
1482         # Skip files not in this directory, any Makefile, and the
1483         # config header.  These last two must be handled specially.
1484         next unless &dirname ($file) eq $relative_dir;
1485         next if $file eq $top_builddir . '/' . $config_name;
1486         ($local = $file) =~ s/^.*\///;
1487         next if $local eq 'Makefile';
1489         if ($local =~ /^(.*):(.*)$/)
1490         {
1491             # This is the ":" syntax of AC_OUTPUT.
1492             $input = $2;
1493             $local = $1;
1494         }
1495         else
1496         {
1497             # Normal usage.
1498             $input = $local . '.in';
1499         }
1500         # FIXME when using autoconf ":" syntax, should we set CONFIG_FILES
1501         # to $local:$input?
1502         $output_rules .= ($local . ': '
1503                           . '$(top_builddir)/config.status ' . $input . "\n"
1504                           . "\t"
1505                           . 'cd $(top_builddir) && CONFIG_FILES='
1506                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
1507                           . '$@ CONFIG_HEADERS= ./config.status'
1508                           . "\n");
1510         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
1511                                       $local . '.in');
1512     }
1515 # Handle C headers.
1516 sub handle_headers
1518     &am_install_var ('header', 'HEADERS', 'include',
1519                      'oldinclude', 'pkginclude',
1520                      'noinst', 'check');
1523 sub handle_gettext
1525     return if ! $seen_gettext || $relative_dir ne '.';
1527     # As of 0.10.6, gettext still wants @INTLSUB@ and @POSUB@ in
1528     # SUBDIRS.  This is going to change in a future version.  So for
1529     # now we simply do no checking.
1530     if (0 && &variable_defined ('SUBDIRS'))
1531     {
1532         &am_line_error
1533             ('SUBDIRS',
1534              "ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
1535                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
1536         &am_line_error
1537             ('SUBDIRS',
1538              "ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
1539                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
1540     }
1542     # Ensure that each language in ALL_LINGUAS has a .po file, and
1543     # each po file is mentioned in ALL_LINGUAS.
1544     if ($seen_linguas)
1545     {
1546         local (%linguas) = ();
1547         grep ($linguas{$_} = 1, split (' ', $all_linguas));
1549         foreach (<po/*.po>)
1550         {
1551             s/^po\///;
1552             s/\.po$//;
1554             &am_line_error ($all_linguas_line,
1555                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
1556                 if ! $linguas{$_};
1557         }
1559         foreach (keys %linguas)
1560         {
1561             &am_line_error ($all_linguas_line,
1562                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
1563                 if ! -f "po/$_.po";
1564         }
1565     }
1566     else
1567     {
1568         &am_error ("ud_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
1569     }
1572 # Handle footer elements.
1573 sub handle_footer
1575     if ($contents{'SOURCES'})
1576     {
1577         &pretty_print ('SOURCES =', "",
1578                        split (' ', $contents{'SOURCES'}));
1579     }
1580     if ($contents{'OBJECTS'})
1581     {
1582         &pretty_print ('OBJECTS =', "",
1583                        split (' ', $contents{'OBJECTS'}));
1584     }
1585     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
1586     {
1587         $output_vars .= "\n";
1588     }
1590     if (defined $contents{'SUFFIXES'})
1591     {
1592         push (@suffixes, '$(SUFFIXES)');
1593     }
1595     $output_trailer .= ".SUFFIXES:\n";
1596     if (@suffixes)
1597     {
1598         $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
1599     }
1600     $output_trailer .= &file_contents ('footer');
1603 # Deal with installdirs target.
1604 sub handle_installdirs
1606     # GNU Makefile standards recommend this.
1607     $output_rules .= ("installdirs:"
1608                       . ($recursive_install
1609                          ? " installdirs-recursive\n"
1610                          : "\n"));
1611     push (@phony, 'installdirs');
1612     if (@installdirs)
1613     {
1614         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
1615                             @installdirs);
1616     }
1617     $output_rules .= "\n";
1620 # There are several targets which need to be merged.  This is because
1621 # their complete definition is compiled from many parts.  Note that we
1622 # avoid double colon rules, otherwise we'd use them instead.
1623 sub handle_merge_targets
1625     push (@all, 'Makefile');
1626     push (@all, $config_name)
1627         if $config_name && &dirname ($config_name) eq $relative_dir;
1629     &do_one_merge_target ('info', @info);
1630     &do_one_merge_target ('dvi', @dvi);
1632     if (! &variable_defined ('SUBDIRS') || $relative_dir ne '.')
1633     {
1634         # 'check' must depend on 'all', but not at top level.
1635         # Ditto install.
1636         unshift (@check, 'all');
1637         unshift (@install, 'all');
1638     }
1639     &do_one_merge_target ('check', @check);
1640     &do_one_merge_target ('installcheck', @installcheck);
1642     # Handle the various install targets specially.  We do this so
1643     # that (eg) "make install-exec" will run "install-exec-recursive"
1644     # if required, but "make install" won't run it twice.  Step one is
1645     # to see if the user specified local versions of any of the
1646     # targets we handle.  "all" is treated as one of these since
1647     # "install" can run it.
1648     push (@install_exec, 'install-exec-local')
1649         if defined $contents{'install-exec-local'};
1650     push (@install_data, 'install-data-local')
1651         if defined $contents{'install-data-local'};
1652     push (@uninstall, 'uninstall-local')
1653         if defined $contents{'uninstall-local'};
1654     push (@all, 'all-local')
1655         if defined $contents{'all-local'};
1657     if (defined $contents{'install-local'})
1658     {
1659         &am_line_error ('install-local',
1660                         "use \`install-data' or \`install-exec', not \`install'");
1661     }
1663     # Step two: if we are doing recursive makes, write out the
1664     # appropriate rules.
1665     local (@install);
1666     if ($recursive_install)
1667     {
1668         push (@install, 'install-recursive');
1670         if (@all)
1671         {
1672             local (@hackall) = ();
1673             if ($config_name && &dirname ($config_name) eq $relative_dir)
1674             {
1676                 # This is kind of a hack, but I couldn't see a better
1677                 # way to handle it.  In this particular case, we need
1678                 # to make sure config.h is built before we recurse.
1679                 # We can't do this by changing the order of
1680                 # dependencies to the "all" because that breaks when
1681                 # using parallel makes.  Instead we handle things
1682                 # explicitly.
1683                 $output_rules .= ('all-recursive-hack: $(CONFIG_HEADER)'
1684                                   . "\n\t" . '$(MAKE) all-recursive'
1685                                   . "\n\n");
1686                 push (@hackall, 'all-recursive-hack');
1687                 push (@phony, 'all-recursive-hack');
1688             }
1689             else
1690             {
1691                 push (@hackall, 'all-recursive');
1692             }
1694             $output_rules .= ('all-am: '
1695                               . join (' ', @all)
1696                               . "\n\n");
1697             @all = @hackall;
1698             push (@all, 'all-am');
1699             push (@phony, 'all-am');
1700         }
1701         else
1702         {
1703             @all = ('all-recursive');
1704         }
1705         if (@install_exec)
1706         {
1707             $output_rules .= ('install-exec-am: '
1708                               . join (' ', @install_exec)
1709                               . "\n\n");
1710             @install_exec = ('install-exec-recursive', 'install-exec-am');
1711             push (@install, 'install-exec-am');
1712             push (@phony, 'install-exec-am');
1713         }
1714         else
1715         {
1716             @install_exec = ('install-exec-recursive');
1717         }
1718         if (@install_data)
1719         {
1720             $output_rules .= ('install-data-am: '
1721                               . join (' ', @install_data)
1722                               . "\n\n");
1723             @install_data = ('install-data-recursive', 'install-data-am');
1724             push (@install, 'install-data-am');
1725             push (@phony, 'install-data-am');
1726         }
1727         else
1728         {
1729             @install_data = ('install-data-recursive');
1730         }
1731         if (@uninstall)
1732         {
1733             $output_rules .= ('uninstall-am: '
1734                               . join (' ', @uninstall)
1735                               . "\n\n");
1736             @uninstall = ('uninstall-recursive', 'uninstall-am');
1737             push (@phony, 'uninstall-am');
1738         }
1739         else
1740         {
1741             @uninstall = ('uninstall-recursive');
1742         }
1743     }
1745     # Step three: print definitions users can use.  Code below knows
1746     # that install-exec is done before install-data, beware.
1747     $output_rules .= ("install-exec: "
1748                       . join (' ', @install_exec)
1749                       . "\n");
1750     if (defined $contents{'install-exec-hook'})
1751     {
1752         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
1753     }
1754     $output_rules .= "\n";
1755     push (@install, 'install-exec') if !$recursive_install;
1756     push (@phony, 'install-exec');
1758     $output_rules .= ("install-data: "
1759                       . join (' ', @install_data)
1760                       . "\n");
1761     if (defined $contents{'install-data-hook'})
1762     {
1763         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
1764     }
1765     $output_rules .= "\n";
1766     push (@install, 'install-data') if !$recursive_install;
1767     push (@phony, 'install-data');
1769     # If no dependencies for 'install', add 'all'.  Why?  That way
1770     # "make install" at top level of distclean'd distribution won't
1771     # fail because stuff in 'lib' fails to build.
1772     if (! @install || ($#install == 1
1773                        && $install[0] eq 'install-exec'
1774                        && $install[1] eq 'install-data'))
1775     {
1776         push (@install, 'all');
1777     }
1778     $output_rules .= ('install: '
1779                       . join (' ', @install)
1780                       # Use "@:" as empty command so nothing prints.
1781                       . "\n\t\@:"
1782                       . "\n\n"
1783                       . 'uninstall: '
1784                       . join (' ', @uninstall)
1785                       . "\n\n");
1786     push (@phony, 'install', 'uninstall');
1788     $output_rules .= ('all: '
1789                       . join (' ', @all)
1790                       . "\n\n");
1791     push (@phony, 'all');
1793     # Generate the new 'install-strip' target.
1794     $output_rules .= ("install-strip:\n\t"
1795                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
1796                       . "\n");
1799 # Helper for handle_merge_targets.
1800 sub do_one_merge_target
1802     local ($name, @values) = @_;
1804     if (defined $contents{$name . '-local'})
1805     {
1806         # User defined local form of target.  So include it.
1807         push (@values, $name . '-local');
1808         push (@phony, $name . '-local');
1809     }
1811     $output_rules .= $name . ":";
1812     if (@values)
1813     {
1814         $output_rules .= ' ' . join (' ', @values);
1815     }
1816     $output_rules .= "\n\n";
1817     push (@phony, $name);
1820 # Handle all 'clean' targets.
1821 sub handle_clean
1823     push (@clean, 'generic');
1824     $output_rules .= &file_contents ('clean');
1825     &push_phony_cleaners ('generic');
1827     local ($target) = $recursive_install ? 'clean-am' : 'clean';
1828     &do_one_clean_target ($target, 'mostly', '', @clean);
1829     &do_one_clean_target ($target, '', 'mostly', @clean);
1830     &do_one_clean_target ($target, 'dist', '', @clean);
1831     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
1833     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
1835     local (@deps);
1836     if ($recursive_install)
1837     {
1838         @deps = ('am', 'recursive');
1839         &do_one_clean_target ('', 'mostly', '', @deps);
1840         &do_one_clean_target ('', '', '', @deps);
1841         &do_one_clean_target ('', 'dist', '', @deps);
1842         &do_one_clean_target ('', 'maintainer-', '', @deps);
1843     }
1846 # Helper for handle_clean.
1847 sub do_one_clean_target
1849     local ($target, $name, $last_name, @deps) = @_;
1851     # Special case: if target not passed, then don't generate
1852     # dependency on next "lower" clean target (eg no
1853     # clean<-mostlyclean derivation).  In this case the target is
1854     # implicitly known to be 'clean'.
1855     local ($flag) = $target;
1856     $target = 'clean' if ! $flag;
1858     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
1859     if ($flag)
1860     {
1861         if ($last_name || $name ne 'mostly')
1862         {
1863             push (@deps, $last_name . $target . " ");
1864         }
1865     }
1866     # FIXME not sure if I like the tabs here.
1867     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
1869     # FIXME shouldn't we really print these messages before running
1870     # the dependencies?
1871     if ($name . $target eq 'maintainer-clean')
1872     {
1873         # Print a special warning.
1874         $output_rules .=
1875             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
1876              . "\t\@echo \"it deletes files that may require special "
1877              . "tools to rebuild.\"\n");
1879         $output_rules .= "\trm -f config.status\n"
1880             if $relative_dir eq '.';
1881     }
1882     elsif ($name . $target eq 'distclean')
1883     {
1884         $output_rules .= "\trm -f config.status\n";
1885     }
1886     $output_rules .= "\n";
1889 # Handle .PHONY target.
1890 sub handle_phony
1892     &pretty_print_rule ('.PHONY:', "", @phony);
1893     $output_rules .= "\n";
1896 # Handle TESTS variable and other checks.
1897 sub handle_tests
1899     if (&variable_defined ('DEJATOOL') && ! defined $options{'dejagnu'})
1900     {
1901         # Error.
1902         &am_line_error ('DEJATOOL',
1903                         "\`DEJATOOL' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
1904         return;
1905     }
1907     if (defined $options{'dejagnu'})
1908     {
1909         push (@check, 'check-DEJAGNU');
1910         push (@phony, 'check-DEJAGNU');
1911         $output_rules .= &file_contents ('dejagnu') . "\n";
1912         $output_rules .= ("site.exp: Makefile\n"
1913                           . "\t\@echo 'Making a new site.exp file...'\n"
1914                           . "\t-\@rm -f site.bak\n"
1915                           . "\t-\@mv site.exp site.bak\n"
1916                           . "\t\@echo '## these variables are automatically generated by make ##' > site.exp\n"
1917                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> site.exp\n"
1918                           . "\t\@echo '# edit the last section' >> site.exp\n"
1919                           . "\t\@echo 'set tool \$(DEJATOOL)' >> site.exp\n"
1920                           . "\t\@echo 'set srcdir \$(srcdir)' >> site.exp\n"
1921                           . "\t\@echo 'set objdir \`pwd\`' >> site.exp\n");
1923         # Extra stuff for AC_CANONICAL_*
1924         local (@whatlist) = ();
1925         if ($seen_canonical)
1926         {
1927             push (@whatlist, 'host')
1928         }
1930         # Extra stuff only for AC_CANONICAL_SYSTEM.
1931         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
1932         {
1933             push (@whatlist, 'target', 'build');
1934         }
1936         local ($c1, $c2);
1937         foreach $c1 (@whatlist)
1938         {
1939             foreach $c2 ('alias', 'triplet')
1940             {
1941                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> site.exp\n";
1942             }
1943         }
1945         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> site.exp\n"
1946                           . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> site.exp\n");
1947     }
1949     if (&variable_defined ('TESTS'))
1950     {
1951         push (@check, 'check-TESTS');
1952         push (@phony, 'check-TESTS');
1953         # FIXME use $(SHELL) here?  That is what Ulrich suggests.
1954         # Maybe a new macro, $(TEST_SHELL), a la $(CONFIG_SHELL)?  For
1955         # now we just execute the file directly; this allows test
1956         # files which are compiled -- a possibly useful feature.
1957         $output_rules .= 'check-TESTS: $(TESTS)
1958         @failed=0; all=0; \\
1959         srcdir=$(srcdir); export srcdir; \\
1960         for tst in $(TESTS); do \\
1961           all=`expr $$all + 1`; \\
1962           if test -f $$tst; then dir=.; \\
1963           else dir="$(srcdir)"; fi; \\
1964           if $$dir/$$tst; then \\
1965             echo "PASS: $$tst"; \\
1966           else \\
1967             failed=`expr $$failed + 1`; \\
1968             echo "FAIL: $$tst"; \\
1969           fi; \\
1970         done; \\
1971         if test "$$failed" -eq 0; then \\
1972           echo "========================"; \\
1973           echo "All $$all tests passed"; \\
1974           echo "========================"; \\
1975         else \\
1976           echo "$$failed of $$all tests failed"; \\
1977         fi
1979     }
1982 ################################################################
1984 # Scan configure.in for interesting things.
1985 # FIXME ensure VERSION, PACKAGE are set.
1986 sub scan_configure
1988     open (CONFIGURE, 'configure.in')
1989         || die "automake: couldn't open \`configure.in': $!\n";
1990     print "automake: reading configure.in\n" if $verbose;
1992     # Reinitialize libsources here.  This isn't really necessary,
1993     # since we currently assume there is only one configure.in.  But
1994     # that won't always be the case.
1995     %libsources = ();
1997     local ($in_ac_output, @make_list) = 0;
1998     local ($libobj_iter);
1999     while (<CONFIGURE>)
2000     {
2001         # Remove comments from current line.
2002         s/\bdnl\b.*$//;
2003         s/\#.*$//;
2005         # Populate libobjs array.
2006         if (/AC_FUNC_ALLOCA/)
2007         {
2008             $libsources{'alloca.c'} = 1;
2009         }
2010         elsif (/AC_FUNC_GETLOADAVG/)
2011         {
2012             $libsources{'getloadavg.c'} = 1;
2013         }
2014         elsif (/AC_FUNC_MEMCMP/)
2015         {
2016             $libsources{'memcmp.c'} = 1;
2017         }
2018         elsif (/AC_STRUCT_ST_BLOCKS/)
2019         {
2020             $libsources{'fileblocks.c'} = 1;
2021         }
2022         elsif (/(AC|fp)_FUNC_FNMATCH/)
2023         {
2024             # AC_FUNC_FNMATCH is just wishful thinking at this point.
2025             $libsources{'fnmatch.c'} = 1;
2026         }
2027         elsif (/AC_REPLACE_FUNCS\s*\((.*)\)/)
2028         {
2029             foreach (split (' ', $1))
2030             {
2031                 $libsources{$_ . '.c'} = 1;
2032             }
2033         }
2034         elsif (/AC_REPLACE_GNU_GETOPT/)
2035         {
2036             $libsources{'getopt.c'} = 1;
2037             $libsources{'getopt1.c'} = 1;
2038         }
2039         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
2040                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
2041         {
2042             foreach $libobj_iter (split (' ', $1))
2043             {
2044                 if ($libobj_iter =~ /^(.*)\.o$/)
2045                 {
2046                     $libsources{$1 . '.c'} = 1;
2047                 }
2048             }
2049         }
2051         # Process the AC_OUTPUT macro.
2052         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
2053         {
2054             $in_ac_output = 1;
2055             $ac_output_line = $.;
2056         }
2057         if ($in_ac_output)
2058         {
2059             $in_ac_output = 0 if s/[\]\),].*$//;
2061             # Look at potential Makefile.am's.
2062             foreach (split)
2063             {
2064                 next if $_ eq "\\";
2065                 if (-f $_ . '.am')
2066                 {
2067                     push (@make_list, $_);
2068                 }
2069                 else
2070                 {
2071                     push (@other_input_files, $_);
2072                 }
2073             }
2074         }
2076         if (/AC_CONFIG_AUX_DIR\(([^)]+)\)/)
2077         {
2078             @config_aux_path = $1;
2079         }
2081         # Check for ansi2knr.
2082         $fp_c_prototypes = 1 if /fp_C_PROTOTYPES/;
2084         # Check for NLS support.
2085         if (/ud_GNU_GETTEXT/)
2086         {
2087             $seen_gettext = 1;
2088             $ac_gettext_line = $.;
2089         }
2091         # Look for ALL_LINGUAS.
2092         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
2093         {
2094             $seen_linguas = 1;
2095             $all_linguas = $1;
2096             $all_linguas_line = $.;
2097         }
2099         # Handle configuration headers.
2100         if (/AC_CONFIG_HEADER\s*\((.*)\)/)
2101         {
2102             $config_header_line = $.;
2103             $config_name = $1;
2104             if ($config_name =~ /^([^:]+):(.+)$/)
2105             {
2106                 $config_name = $1;
2107                 $config_header = $2;
2108             }
2109             else
2110             {
2111                 $config_header = $config_name . '.in';
2112             }
2113         }
2115         # Handle AC_CANONICAL_*.  Always allow upgrading to
2116         # AC_CANONICAL_SYSTEM, but never downgrading.
2117         $seen_canonical = $AC_CANONICAL_HOST
2118             if ! $seen_canonical && /AC_CANONICAL_HOST/;
2119         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
2121         $seen_canonical = 1 if /AC_CHECK_TOOL/;
2122         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
2124         # Sometimes it is desirable to explicitly set YACC.  For
2125         # instance some people don't want to use bison.
2126         $seen_prog_yacc = 1 if (/AC_PROG_YACC/
2127                                 || /AC_SUBST\(YACC\)/
2128                                 || /AC_(PATH|CHECK)_PROGS?\(YACC/);
2130         # Some things required by Automake.
2131         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
2132         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
2133         $seen_ranlib = 1 if /AC_PROG_RANLIB/;
2134         $seen_maint_mode = 1 if /jm_MAINTAINER_MODE/;
2135         $seen_package = 1 if /PACKAGE=/;
2136         $seen_version = 1 if /VERSION=/;        
2138         # Weird conditionals here because it is always allowed to
2139         # upgrade to fp_PROG_INSTALL but never to downgrade to
2140         # AC_PROG_INSTALL.
2141         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
2142         $seen_prog_install = 2 if /fp_PROG_INSTALL/;
2144         if (/AC_PROG_LIBTOOL/ || /gm_PROG_LIBTOOL/)
2145         {
2146             $seen_libtool = 1;
2147             $seen_ranlib = 2;
2148             $libtool_line = $.;
2149         }
2150     }
2152     # Set input files if not specified by user.
2153     @input_files = @make_list if (! @input_files);
2155     close (CONFIGURE);
2157     &am_conf_error ("\`PACKAGE' not defined in configure.in")
2158         if ! $seen_package;
2159     &am_conf_error ("\`VERSION' not defined in configure.in")
2160         if ! $seen_version;
2162     # Look for some files we need.  Always check for these.  This
2163     # check must be done for every run, even those where we are only
2164     # looking at a subdir Makefile.  We must set relative_dir so that
2165     # the file-finding machinery works.
2166     local ($relative_dir) = '.';
2167     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs');
2170 ################################################################
2172 # Do any extra checking for GNU standards.
2173 sub check_gnu_standards
2175     if ($relative_dir eq '.')
2176     {
2177         # In top level (or only) directory.
2178         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
2179                        'AUTHORS', 'ChangeLog');
2180     }
2183 # Do any extra checking for GNITS standards.
2184 sub check_gnits_standards
2186     if ($strictness >= $GNITS && -f $relative_dir . '/COPYING.LIB')
2187     {
2188         &am_error
2189             ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
2190     }
2192     if ($relative_dir eq '.')
2193     {
2194         # In top level (or only) directory.
2195         &require_file ($GNITS, 'THANKS');
2196     }
2199 ################################################################
2201 # Pretty-print something.  HEAD is what should be printed at the
2202 # beginning of the first line, FILL is what should be printed at the
2203 # beginning of every subsequent line.
2204 sub pretty_print_internal
2206     local ($head, $fill, @values) = @_;
2208     local ($column) = length ($head);
2209     local ($result) = $head;
2211     # Fill length is number of characters.  However, each Tab
2212     # character counts for eight.  So we count the number of Tabs and
2213     # multiply by 7.
2214     local ($fill_length) = length ($fill);
2215     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
2217     local ($bol) = 0;
2218     foreach (@values)
2219     {
2220         # "71" because we also print a space.
2221         if ($column + length ($_) > 71)
2222         {
2223             $result .= " \\\n" . $fill;
2224             $column = $fill_length;
2225             $bol = 1;
2226         }
2228         $result .= ' ' unless ($bol);
2229         $result .= $_;
2230         $column += length ($_) + 1;
2231         $bol = 0;
2232     }
2234     $result .= "\n";
2235     return $result;
2238 # Pretty-print something and append to output_vars.
2239 sub pretty_print
2241     $output_vars .= &pretty_print_internal (@_);
2244 # Pretty-print something and append to output_rules.
2245 sub pretty_print_rule
2247     $output_rules .= &pretty_print_internal (@_);
2251 ################################################################
2253 # See if a variable exists.
2254 sub variable_defined
2256     local ($var) = @_;
2257     if (defined $targets{$var})
2258     {
2259         &am_line_error ($var, "\`$var' is target; expected variable");
2260     }
2261     return (defined $contents{$var} && ! defined $targets{$var});
2264 # Read Makefile.am and set up %contents.  Simultaneously copy lines
2265 # from Makefile.am into $output_trailer or $output_vars as
2266 # appropriate.  NOTE we put rules in the trailer section.  We want
2267 # user rules to come after our generated stuff.
2268 sub read_am_file
2270     local ($amfile) = @_;
2272     # Compute relative location of the top object directory.
2273     local (@topdir) = ();
2274     foreach (split (/\//, $relative_dir))
2275     {
2276         next if $_ eq '.' || $_ eq '';
2277         if ($_ eq '..')
2278         {
2279             pop @topdir;
2280         }
2281         else
2282         {
2283             push (@topdir, '..');
2284         }
2285     }
2286     @topdir = ('.') if ! @topdir;
2288     $top_builddir = join ('/', @topdir);
2289     local ($build_rx);
2290     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
2291     local ($header_vars) =
2292         &file_contents_with_transform
2293             ('s/\@top_builddir\@/' . $build_rx . '/g',
2294              'header-vars');
2296     # Generate some useful variables when AC_CANONICAL_* used.
2297     if ($seen_canonical)
2298     {
2299         $header_vars .= ('host_alias = @host_alias@' . "\n"
2300                          . 'host_triplet = @host@' . "\n");
2301         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
2302         {
2303             $header_vars .= ('build_alias = @build_alias@' . "\n"
2304                              . 'build_triplet = @build@' . "\n");
2305             $header_vars .= ('target_alias = @target_alias@' . "\n"
2306                              . 'target_triplet = @target@' . "\n");
2307         }
2308     }
2310     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
2311     print "automake: reading $amfile\n" if $verbose;
2313     $output_vars .= ("# $in_file_name generated automatically by automake "
2314                      . $VERSION . " from $am_file_name\n");
2316     # Generate copyright for generated Makefile.in.
2317     $output_vars .= $gen_copyright;
2319     local ($saw_bk) = 0;
2320     local ($was_rule) = 0;
2321     local ($spacing) = '';
2322     local ($comment) = '';
2323     local ($last_var_name) = '';
2324     local ($blank) = 0;
2326     while (<AM_FILE>)
2327     {
2328         if (/$IGNORE_PATTERN/o)
2329         {
2330             # Merely delete comments beginning with two hashes.
2331         }
2332         elsif (/$WHITE_PATTERN/o)
2333         {
2334             # Stick a single white line before the incoming macro or rule.
2335             $spacing = "\n";
2336             $blank = 1;
2337         }
2338         elsif (/$COMMENT_PATTERN/o)
2339         {
2340             # Stick comments before the incoming macro or rule.  Make
2341             # sure a blank line preceeds comments.
2342             $spacing = "\n" unless $blank;
2343             $comment .= $spacing . $_;
2344             $spacing = '';
2345         }
2346         else
2347         {
2348             last;
2349         }
2350     }
2352     $output_vars .= $comment . "\n" . $header_vars;
2353     $comment = '';
2354     $spacing = "\n";
2356     local ($is_ok_macro);
2357     while ($_)
2358     {
2359         $_ .= "\n"
2360             unless substr ($_, -1, 1) eq "\n";
2362         $_ =~ s/\@MAINT\@//g
2363             unless $seen_maint_mode;
2365         if (/$IGNORE_PATTERN/o)
2366         {
2367             # Merely delete comments beginning with two hashes.
2368         }
2369         elsif (/$WHITE_PATTERN/o)
2370         {
2371             # Stick a single white line before the incoming macro or rule.
2372             $spacing = "\n";
2373         }
2374         elsif (/$COMMENT_PATTERN/o)
2375         {
2376             # Stick comments before the incoming macro or rule.
2377             $comment .= $spacing . $_;
2378             $spacing = '';
2379         }
2380         elsif ($saw_bk)
2381         {
2382             if ($was_rule)
2383             {
2384                 $output_trailer .= $_;
2385                 $saw_bk = /\\$/;
2386             }
2387             else
2388             {
2389                 $output_vars .= $_;
2390                 $saw_bk = /\\$/;
2391                 # Chop newline and backslash if this line is
2392                 # continued.  FIXME maybe ensure trailing whitespace
2393                 # exists?
2394                 chop if $saw_bk;
2395                 chop if $saw_bk;
2396                 $contents{$last_var_name} .= $_;
2397             }
2398         }
2399         elsif (/$RULE_PATTERN/o)
2400         {
2401             # warn "** Saw rule .$1.\n";
2402             # Found a rule.
2403             $was_rule = 1;
2404             # Value here doesn't matter; for targets we only note
2405             # existence.
2406             $contents{$1} = 1;
2407             $targets{$1} = 1;
2408             $content_lines{$1} = $.;
2409             $output_trailer .= $comment . $spacing . $_;
2410             $comment = $spacing = '';
2411             $saw_bk = /\\$/;
2412         }
2413         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
2414                || /$BOGUS_MACRO_PATTERN/o)
2415         {
2416             # Found a macro definition.
2417             $was_rule = 0;
2418             $last_var_name = $1;
2419             if (substr ($2, -1) eq "\\")
2420             {
2421                 $contents{$1} = substr ($2, 0, length ($2) - 1);
2422             }
2423             else
2424             {
2425                 $contents{$1} = $2;
2426             }
2427             $content_lines{$1} = $.;
2428             $output_vars .= $comment . $spacing . $_;
2429             $comment = $spacing = '';
2430             $saw_bk = /\\$/;
2432             # Error if bogus.
2433             &am_line_error ($., "bad macro name \`$1'")
2434                 if ! $is_ok_macro;
2435         }
2436         else
2437         {
2438             # This isn't an error; it is probably a continued rule.
2439             # In fact, this is what we assume.
2440             $was_rule = 1;
2441             $output_trailer .= $comment . $spacing . $_;
2442             $comment = $spacing = '';
2443             $saw_bk = /\\$/;
2444         }
2446         $_ = <AM_FILE>;
2447     }
2449     $output_trailer .= $comment;
2452 ################################################################
2454 sub initialize_global_constants
2456     # Values for AC_CANONICAL_*
2457     $AC_CANONICAL_HOST = 1;
2458     $AC_CANONICAL_SYSTEM = 2;
2460     # Associative array of standard directory names.  Entry is TRUE if
2461     # corresponding directory should be installed during
2462     # 'install-exec' phase.
2463     %exec_dir_p =
2464         ('bin', 1,
2465          'sbin', 1,
2466          'libexec', 1,
2467          'data', 0,
2468          'sysconf', 1,
2469          'localstate', 1,
2470          'lib', 1,
2471          'info', 0,
2472          'man', 0,
2473          'include', 0,
2474          'oldinclude', 0,
2475          'pkgdata', 0,
2476          'pkglib', 1,
2477          'pkginclude', 0
2478          );
2480     # Helper text for dealing with man pages.
2481     $install_man_format =
2482     '   @sect=@SECTION@;                                \\
2483         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
2484         echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
2485         $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst
2488     $uninstall_man_format =
2489     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
2490         rm -f $(mandir)/man@SECTION@/$$inst
2493     # Commonly found files we look for and automatically include in
2494     # DISTFILES.
2495     @common_files =
2496         (
2497          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
2498          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
2499          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
2500          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
2501          'texinfo.tex'
2502          );
2504     # Commonly used files we auto-include, but only sometimes.
2505     @common_sometimes =
2506         (
2507          "aclocal.m4", "acconfig.h", "config.h.top",
2508          "config.h.bot", "stamp-h.in", "ansi2knr.c",
2509          "ansi2knr.1", 'stamp-vti'
2510          );
2512     $USAGE = "\
2513   --amdir=DIR           directory storing config files
2514   --foreign             same as --strictness=foreign
2515   --gnits               same as --strictness=gnits
2516   --gnu                 same as --strictness=gnu
2517   --help                print this help, then exit
2518   -i, --include-deps    include generated dependencies in Makefile.in
2519   -a, --add-missing     add missing standard files to package
2520   -o DIR, --output-dir=DIR
2521                         put generated Makefile.in's into DIR
2522   -s LEVEL, --strictness=LEVEL
2523                         set strictness level.  LEVEL is foreign, gnu, gnits
2524   -v, --verbose         verbosely list files processed
2525   --version             print version number, then exit\n";
2527     # Copyright on generated Makefile.ins.
2528     $gen_copyright = "\
2529 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
2530 # This Makefile.in is free software; the Free Software Foundation
2531 # gives unlimited permission to copy, distribute and modify it.
2535 # (Re)-Initialize per-Makefile.am variables.
2536 sub initialize_per_input
2538     # These two variables are used when generating each Makefile.in.
2539     # They hold the Makefile.in until it is ready to be printed.
2540     $output_rules = '';
2541     $output_vars = '';
2542     $output_trailer = '';
2544     # Suffixes found during a run.
2545     @suffixes = ();
2547     # This holds the contents of a Makefile.am, as parsed by
2548     # read_am_file.
2549     %contents = ();
2551     # This holds the names which are targets.  These also appear in
2552     # %contents.
2553     %targets = ();
2555     # This holds the line numbers at which various elements of
2556     # %contents are defined.
2557     %content_lines = ();
2559     # This holds the "relative directory" of the current Makefile.in.
2560     # Eg for src/Makefile.in, this is "src".
2561     $relative_dir = '';
2563     # This holds a list of files that are included in the
2564     # distribution.
2565     %dist_common = ();
2567     # List of dependencies for the obvious targets.
2568     @install_data = ();
2569     @install_exec = ();
2570     @uninstall = ();
2571     @installdirs = ();
2573     @info = ();
2574     @dvi = ();
2575     @all = ();
2576     @check = ();
2577     @installcheck = ();
2578     @clean = ();
2580     @phony = ();
2582     # These are pretty obvious, too.  They are used to define the
2583     # SOURCES and OBJECTS variables.
2584     @sources = ();
2585     @objects = ();
2587     # TRUE if current directory holds any C source files.  (Actually
2588     # holds object extension, but this information is encapsulated in
2589     # the function get_object_extension).
2590     $dir_holds_sources = '';
2592     # TRUE if install targets should work recursively.
2593     $recursive_install = 0;
2595     # All .P files.
2596     %dep_files = ();
2598     # Strictness levels.
2599     $strictness = $default_strictness;
2600     $strictness_name = $default_strictness_name;
2602     # Options from AUTOMAKE_OPTIONS.
2603     %options = ();
2605     # Whether or not dependencies are handled.  Can be further changed
2606     # in handle_options.
2607     $use_dependencies = $cmdline_use_dependencies;
2609     # Per Makefile.am.
2610     $local_maint_charset = $maint_charset;
2614 ################################################################
2616 # Return contents of a file from $am_dir, automatically skipping
2617 # macros or rules which are already known.  Runs command on each line
2618 # as it is read; this command can modify $_.
2619 sub file_contents_with_transform
2621     local ($command, $basename) = @_;
2622     local ($file) = $am_dir . '/' . $basename . '.am';
2624     open (FC_FILE, $file)
2625         || die "automake: installation error: cannot open \`$file'\n";
2626     # Looks stupid?
2627     # print "automake: reading $file\n" if $verbose;
2629     local ($was_rule) = 0;
2630     local ($result_vars) = '';
2631     local ($result_rules) = '';
2632     local ($comment) = '';
2633     local ($spacing) = "\n";
2634     local ($skipping) = 0;
2636     while (<FC_FILE>)
2637     {
2638         $_ =~ s/\@MAINT\@//g
2639             unless $seen_maint_mode;
2641         eval $command;
2643         if (/$IGNORE_PATTERN/o)
2644         {
2645             # Merely delete comments beginning with two hashes.
2646         }
2647         elsif (/$WHITE_PATTERN/o)
2648         {
2649             # Stick a single white line before the incoming macro or rule.
2650             $spacing = "\n";
2651         }
2652         elsif (/$COMMENT_PATTERN/o)
2653         {
2654             # Stick comments before the incoming macro or rule.
2655             $comment .= $spacing . $_;
2656             $spacing = '';
2657         }
2658         elsif ($saw_bk)
2659         {
2660             if ($was_rule)
2661             {
2662                 $result_rules .= $_ if ! $skipping;
2663             }
2664             else
2665             {
2666                 $result_vars .= $_ if ! $skipping;
2667             }
2668             $saw_bk = /\\$/;
2669         }
2670         elsif (/$RULE_PATTERN/o)
2671         {
2672             # warn "** Found rule .$1.\n";
2673             # Found a rule.
2674             $was_rule = 1;
2675             $skipping = defined $contents{$1};
2676             # warn "** Skip $skipping\n" if $skipping;
2677             $result_rules .= $comment . $spacing . $_ if ! $skipping;
2678             $comment = $spacing = '';
2679             $saw_bk = /\\$/;
2680         }
2681         elsif (/$MACRO_PATTERN/o)
2682         {
2683             # warn "** Found macro .$1.\n";
2684             # Found a variable reference.
2685             $was_rule = 0;
2686             $skipping = defined $contents{$1};
2687             # warn "** Skip $skipping\n" if $skipping;
2688             $result_vars .= $comment . $spacing . $_ if ! $skipping;
2689             $comment = $spacing = '';
2690             $saw_bk = /\\$/;
2691         }
2692         else
2693         {
2694             # This isn't an error; it is probably a continued rule.
2695             # In fact, this is what we assume.
2696             $was_rule = 1;
2697             $result_rules .= $comment . $spacing . $_ if ! $skipping;
2698             $comment = $spacing = '';
2699             $saw_bk = /\\$/;
2700         }
2701     }
2703     close (FC_FILE);
2704     return $result_vars . $result_rules . $comment;
2707 # Like file_contents_with_transform, but no transform.
2708 sub file_contents
2710     return &file_contents_with_transform ('', @_);
2713 # Handle `where_HOW' variable magic.  Does all lookups, generates
2714 # install code, and possibly generates code to define the primary
2715 # variable.  The first argument is the name of the .am file to munge,
2716 # the second argument is the primary variable (eg HEADERS), and all
2717 # subsequent arguments are possible installation locations.  Returns
2718 # list of all values of all _HOW targets.
2720 # FIXME this should be rewritten to be cleaner.  It should be broken
2721 # up into multiple functions.
2723 # Usage is: am_install_var (OPTION..., file, HOW, where...)
2724 sub am_install_var
2726     local (@args) = @_;
2728     local ($do_all, $do_clean) = (1, 0);
2729     while (@args)
2730     {
2731         if ($args[0] eq '-clean')
2732         {
2733             $do_clean = 1;
2734         }
2735         elsif ($args[0] eq '-no-all')
2736         {
2737             $do_all = 0;
2738         }
2739         elsif ($args[0] !~ /^-/)
2740         {
2741             last;
2742         }
2743         shift (@args);
2744     }
2745     local ($file, $primary, @prefixes) = @args;
2747     local (@used) = ();
2748     local (@result) = ();
2750     # Now that configure substitutions are allowed in where_HOW
2751     # variables, it is an error to actually define the primary.
2752     &am_line_error ($primary, "\`$primary' is an anachronism")
2753         if &variable_defined ($primary);
2756     # Look for misspellings.  It is an error to have a variable ending
2757     # in a "reserved" suffix whose prefix is unknown, eg
2758     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
2759     # variable of the same name (with "dir" appended) exists.  For
2760     # instance, if the variable "zardir" is defined, then
2761     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
2762     # flexibility in those cases which need it.  Perhaps it should be
2763     # disallowed in the Gnits case?  The problem is, sometimes it is
2764     # useful to put things in a subdir of eg pkgdatadir, perhaps even
2765     # for Gnitsoids.
2766     local (%valid, $varname);
2767     grep ($valid{$_} = 0, @prefixes);
2768     $valid{'EXTRA'} = 0;
2769     foreach $varname (keys %contents)
2770     {
2771         if ($varname =~ /^(.*)_$primary$/)
2772         {
2773             if (! defined $valid{$1} && ! &variable_defined ($1 . 'dir'))
2774             {
2775                 &am_line_error ($varname, "invalid variable \"$varname\"");
2776             }
2777             else
2778             {
2779                 # Ensure all extended prefixes are actually used.
2780                 $valid{$1} = 1;
2781             }
2782         }
2783     }
2785     local ($clean_file) = $file . '-clean';
2786     local ($one_name);
2787     local ($X);
2788     foreach $X (keys %valid)
2789     {
2790         $one_name = $X . '_' . $primary;
2791         if (&variable_defined ($one_name))
2792         {
2793             # Append actual contents of where_PRIMARY variable to
2794             # result.
2795             local ($rcurs);
2796             foreach $rcurs (split (' ', $contents{$one_name}))
2797             {
2798                 # Skip configure substitutions.  Possibly bogus.
2799                 next if $rcurs =~ /^\@.*\@$/;
2800                 push (@result, $rcurs);
2801             }
2803             # "EXTRA" shouldn't be used when generating clean targets,
2804             # @all, or install targets.
2805             next if $X eq 'EXTRA';
2807             if ($do_clean)
2808             {
2809                 $output_rules .=
2810                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2811                                                    $clean_file);
2813                 push (@clean, $X . $primary);
2814                 &push_phony_cleaners ($X . $primary);
2815             }
2817             if ($X eq 'check')
2818             {
2819                 push (@check, '$(' . $one_name . ')');
2820             }
2821             else
2822             {
2823                 push (@used, '$(' . $one_name . ')');
2824             }
2825             if ($X eq 'noinst' || $X eq 'check')
2826             {
2827                 # Objects which don't get installed by default.
2828                 next;
2829             }
2831             $output_rules .=
2832                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
2833                                                $file);
2835             push (@uninstall, 'uninstall-' . $X . $primary);
2836             push (@phony, 'uninstall-' . $X . $primary);
2837             push (@installdirs, '$(' . $X . 'dir)');
2838             if ($exec_dir_p{$X})
2839             {
2840                 push (@install_exec, 'install-' . $X . $primary);
2841                 push (@phony, 'install-' . $X . $primary);
2842             }
2843             else
2844             {
2845                 push (@install_data, 'install-' . $X . $primary);
2846                 push (@phony, 'install-' . $X . $primary);
2847             }
2848         }
2849     }
2851     if (@used)
2852     {
2853         # Define it.
2854         &pretty_print ($primary . ' =', '', @used);
2855         $output_vars .= "\n";
2856     }
2858     # Push here because PRIMARY might be configure time determined.
2859     push (@all, '$(' . $primary . ')')
2860         if $do_all && @used;
2862     return (@result);
2866 ################################################################
2868 # This variable is local to the "require file" set of functions.
2869 @require_file_paths = ();
2871 # Verify that the file must exist in the current directory.  Usage:
2872 # require_file (isconfigure, line_number, strictness, file) strictness
2873 # is the strictness level at which this file becomes required.  Must
2874 # set require_file_paths before calling this function.
2875 # require_file_paths is set to hold a single directory (the one in
2876 # which the first file was found) before return.
2877 sub require_file_internal
2879     local ($is_configure, $line, $mystrict, @files) = @_;
2880     local ($file, $fullfile);
2881     local ($found_it, $errfile, $errdir);
2882     local ($save_dir);
2884     foreach $file (@files)
2885     {
2886         $found_it = 0;
2887         foreach $dir (@require_file_paths)
2888         {
2889             if ($dir eq '.')
2890             {
2891                 $fullfile = $relative_dir . "/" . $file;
2892                 $errdir = $relative_dir unless $errdir;
2893             }
2894             else
2895             {
2896                 $fullfile = $dir . "/" . $file;
2897                 $errdir = $dir unless $errdir;
2898             }
2900             # Use different name for "error filename".  Otherwise on
2901             # an error the bad file will be reported as eg
2902             # `../../install-sh' when using the default
2903             # config_aux_path.
2904             $errfile = $errdir . '/' . $file;
2906             if (-f $fullfile)
2907             {
2908                 $found_it = 1;
2909                 &push_dist_common ($file) if $dir eq $relative_dir;
2910                 $save_dir = $dir;
2911                 last;
2912             }
2913         }
2915         if ($found_it)
2916         {
2917             # Prune the path list.
2918             @require_file_paths = $save_dir;
2919         }
2920         else
2921         {
2922             if ($strictness >= $mystrict)
2923             {
2924                 # Only install missing files according to our desired
2925                 # strictness level.
2926                 if ($add_missing && -f ($am_dir . '/' . $file))
2927                 {
2928                     # Install the missing file.  Symlink if we can, copy
2929                     # if we must.
2930                     if ($symlink_exists)
2931                     {
2932                         symlink ($am_dir . '/' . $file, $errfile);
2933                     }
2934                     else
2935                     {
2936                         system ('cp', $am_dir . '/' . $file, $errfile);
2937                     }
2939                     # FIXME this is a hack.  Should have am_warn.
2940                     local ($save) = $exit_status;
2941                     if ($is_configure)
2942                     {
2943                         &am_conf_line_error
2944                             ($line,
2945                              "required file \"$errfile\" not found; installing");
2946                     }
2947                     else
2948                     {
2949                         &am_line_error
2950                             ($line,
2951                              "required file \"$errfile\" not found; installing");
2952                     }
2953                     $exit_status = $save;
2954                 }
2955                 else
2956                 {
2957                     # Only an error if strictness constraint violated.
2958                     if ($is_configure)
2959                     {
2960                         &am_conf_line_error
2961                             ($line, "required file \"$errfile\" not found");
2962                     }
2963                     else
2964                     {
2965                         &am_line_error
2966                             ($line, "required file \"$errfile\" not found");
2967                     }
2968                 }
2969             }
2970         }
2971     }
2974 # Like require_file_with_line, but error messages refer to
2975 # configure.in, not the current Makefile.am.
2976 sub require_file_with_conf_line
2978     @require_file_paths = '.';
2979     &require_file_internal (1, @_);
2982 sub require_file_with_line
2984     @require_file_paths = '.';
2985     &require_file_internal (0, @_);
2988 sub require_file
2990     @require_file_paths = '.';
2991     &require_file_internal (0, '', @_);
2994 # Require a file that is also required by Autoconf.  Looks in
2995 # configuration path, as specified by AC_CONFIG_AUX_DIR.
2996 sub require_config_file
2998     @require_file_paths = @config_aux_path;
2999     &require_file_internal (0, '', @_);
3000     local ($dir) = $require_file_paths[0];
3001     @config_aux_path = @require_file_paths;
3002     if ($dir eq '.')
3003     {
3004         $config_aux_dir = '.';
3005     }
3006     else
3007     {
3008         $config_aux_dir = '$(top_srcdir)/' . $dir;
3009     }
3012 # Assumes that the line number is in Makefile.am.
3013 sub require_conf_file_with_line
3015     @require_file_paths = @config_aux_path;
3016     &require_file_internal (0, @_);
3017     local ($dir) = $require_file_paths[0];
3018     @config_aux_path = @require_file_paths;
3019     if ($dir eq '.')
3020     {
3021         $config_aux_dir = '.';
3022     }
3023     else
3024     {
3025         $config_aux_dir = '$(top_srcdir)/' . $dir;
3026     }
3029 # Assumes that the line number is in Makefile.am.
3030 sub require_conf_file_with_conf_line
3032     @require_file_paths = @config_aux_path;
3033     &require_file_internal (1, @_);
3034     local ($dir) = $require_file_paths[0];
3035     @config_aux_path = @require_file_paths;
3036     if ($dir eq '.')
3037     {
3038         $config_aux_dir = '.';
3039     }
3040     else
3041     {
3042         $config_aux_dir = '$(top_srcdir)/' . $dir;
3043     }
3046 ################################################################
3048 # Push a list of files onto dist_common.
3049 sub push_dist_common
3051     local (@files) = @_;
3052     local ($file);
3054     foreach $file (@files)
3055     {
3056         $dist_common{$file} = 1;
3057     }
3060 # Push a list of clean targets onto phony.
3061 sub push_phony_cleaners
3063     local ($base) = @_;
3064     local ($target);
3065     foreach $target ('mostly', 'dist', '', 'maintainer-')
3066     {
3067         push (@phony, $target . 'clean-' . $base);
3068     }
3071 # Set strictness.
3072 sub set_strictness
3074     $strictness_name = $_[0];
3075     if ($strictness_name eq 'gnu')
3076     {
3077         $strictness = $GNU;
3078     }
3079     elsif ($strictness_name eq 'gnits')
3080     {
3081         $strictness = $GNITS;
3082     }
3083     elsif ($strictness_name eq 'foreign')
3084     {
3085         $strictness = $FOREIGN;
3086     }
3087     else
3088     {
3089         die "automake: level \`$strictness_name' not recognized\n";
3090     }
3094 ################################################################
3096 # Return directory name of file.
3097 sub dirname
3099     local ($file) = @_;
3100     local ($sub);
3102     ($sub = $file) =~ s,/+[^/]+$,,g;
3103     $sub = '.' if $sub eq $file;
3104     return $sub;
3107 # Make a directory.
3108 sub mkdir
3110     local ($dirname) = @_;
3111     system ("mkdir", $dirname);
3114 ################################################################
3116 # Print an error message and set exit status.
3117 sub am_error
3119     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
3120     $exit_status = 1;
3123 sub am_line_error
3125     local ($symbol, @args) = @_;
3127     if ($symbol)
3128     {
3129         # If SYMBOL not already a line number, look it up in Makefile.am.
3130         $symbol = $content_lines{$symbol} unless $symbol =~ /^\d+$/;
3131         $symbol .= ': ' if $symbol;
3132         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
3133         $exit_status = 1;
3134     }
3135     else
3136     {
3137         &am_error (@args);
3138     }
3141 # Like am_error, but while scanning configure.in.
3142 sub am_conf_error
3144     # FIXME can run in subdirs.
3145     warn "automake: configure.in: ", join (' ', @_), "\n";
3146     $exit_status = 1;
3149 # Error message with line number referring to configure.in.
3150 sub am_conf_line_error
3152     local ($line, @args) = @_;
3154     if ($line)
3155     {
3156         warn "configure.in: $line: ", join (' ', @args), "\n";
3157         $exit_status = 1;
3158     }
3159     else
3160     {
3161         &am_conf_error (@args);
3162     }
3165 # Tell user where our aclocal.m4 is, but only once.
3166 sub keyed_aclocal_warning
3168     local ($key) = @_;
3169     warn "automake: macro \`$key' can be found in ${am_dir}/aclocal.m4\n";
3172 # Print usage information.
3173 sub usage
3175     print "Usage: automake [OPTION] ... [Makefile]...\n";
3176     print $USAGE;
3177     print "\nFiles which are automatically distributed, if found:\n";
3178     $~ = "USAGE_FORMAT";
3179     local (@lcomm) = sort ((@common_files, @common_sometimes));
3180     local ($one, $two, $three, $four);
3181     while (@lcomm > 0)
3182     {
3183         $one = shift @lcomm;
3184         $two = @lcomm ? shift @lcomm : '';
3185         $three = @lcomm ? shift @lcomm : '';
3186         $four = @lcomm ? shift @lcomm : '';
3187         write;
3188     }
3190     exit 0;
3193 format USAGE_FORMAT =
3194   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
3195   $one,               $two,               $three,             $four