Work around losing `awk'. Report from Harlan Stenn.
[automake.git] / automake.in
blob9c1b84af4d83070971c2a7b547a56a0b1406b56b
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, 1997, 1998, 1999 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@cygnus.com>.
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 $PACKAGE = "@PACKAGE@";
34 $prefix = "@prefix@";
35 $am_dir = "@datadir@/@PACKAGE@";
37 # String constants.
38 $IGNORE_PATTERN = "^##([^#].*)?\$";
39 $WHITE_PATTERN = "^[ \t]*\$";
40 $COMMENT_PATTERN = "^#";
41 $RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/\$]*) *:([^=].*|)\$";
42 $SUFFIX_RULE_PATTERN = "^\\.([a-zA-Z]+)\\.([a-zA-Z]+)\$";
43 $MACRO_PATTERN = "^([A-Za-z0-9_]+)[ \t]*([:+]?)=[ \t]*(.*)\$";
44 $BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*([:+]?)=[ \t]*(.*)\$";
45 $GNITS_VERSION_PATTERN = "[0-9]+\\.[0-9]+([a-z]|\\.[0-9]+)?";
46 $IF_PATTERN = "^if[ \t]+\([A-Za-z][A-Za-z0-9_]*\)[ \t]*\(#.*\)?\$";
47 $ELSE_PATTERN = "^else[ \t]*\(#.*\)?\$";
48 $ENDIF_PATTERN = "^endif[ \t]*\(#.*\)?\$";
49 $PATH_PATTERN='(\\w|/|\\.)+';
50 # This will pass through anything not of the prescribed form.
51 $INCLUDE_PATTERN = "^include[ \t]+((\\\$\\\(top_srcdir\\\)/${PATH_PATTERN})|(\\\$\\\(srcdir\\\)/${PATH_PATTERN})|([^/\\\$]${PATH_PATTERN}))[ \t]*(#.*)?\$";
53 # Some regular expressions.  One reason to put them here is that it
54 # makes indentation work better in Emacs.
55 $AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
56 $AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^,)]+)[,)]";
57 $AM_PACKAGE_VERSION_PATTERN = "^\\s*\\[?([^]\\s]+)\\]?\\s*\$";
58 # Note that there is no AC_PATH_TOOL.  But we don't really care.
59 $AC_CHECK_PATTERN = "AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\\(\\[?(\\w+)";
60 $AM_MISSING_PATTERN = "AM_MISSING_PROG\\(\\[?(\\w+)";
61 # Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
62 # then too bad.
63 $AC_SUBST_PATTERN = "AC_SUBST\\(\\[?(\\w+)";
64 $AM_CONDITIONAL_PATTERN = "AM_CONDITIONAL\\((\\w+)";
66 # Constants to define the "strictness" level.
67 $FOREIGN = 0;
68 $GNU = 1;
69 $GNITS = 2;
71 # These constants are returned by lang_*_rewrite functions.
72 # LANG_SUBDIR means that the resulting object file should be in a
73 # subdir if the source file is.  In this case the file name cannot
74 # have `..' components.
75 $LANG_IGNORE = 0;
76 $LANG_PROCESS = 1;
77 $LANG_SUBDIR = 2;
81 # Variables global to entire run.
83 # TRUE if we should always generate Makefile.in.
84 $force_generation = 1;
86 # Strictness level as set on command line.
87 $default_strictness = $GNU;
89 # Name of strictness level, as set on command line.
90 $default_strictness_name = 'gnu';
92 # This is TRUE if GNU make specific automatic dependency generation
93 # code should be included in generated Makefile.in.
94 $cmdline_use_dependencies = 1;
96 # This is the name of a dependency makefile bit (usually for inclusion in a
97 # SMakefile or similar); empty if not set.
98 $generate_deps = '';
100 # TRUE if in verbose mode.
101 $verbose = 0;
103 # This holds our (eventual) exit status.  We don't actually exit until
104 # we have processed all input files.
105 $exit_status = 0;
107 # From the Perl manual.
108 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
110 # TRUE if missing standard files should be installed.
111 $add_missing = 0;
113 # TRUE if we should copy missing files; otherwise symlink if possible.
114 $copy_missing = 0;
116 # Files found by scanning configure.in for LIBOBJS.
117 %libsources = ();
119 # True if AM_C_PROTOTYPES appears in configure.in.
120 $am_c_prototypes = 0;
122 # Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
123 # name which appears in AC_CONFIG_HEADER, colon and all.
124 # @config_names holds the file names.  @config_headers holds the '.in'
125 # files.  Ordinarily these are similar, but they can be different if
126 # the weird "NAME:FILE" syntax is used.
127 @config_fullnames = ();
128 @config_names = ();
129 @config_headers = ();
130 # Line number at which AC_CONFIG_HEADER appears in configure.in.
131 $config_header_line = 0;
133 # Directory where output files go.  Actually, output files are
134 # relative to this directory.
135 $output_directory = '.';
137 # Relative location of top build directory.
138 $top_builddir = '';
140 # Absolute location of top build directory.
141 $build_directory = '';
143 # Name of srcdir as given in build directory's Makefile.  For
144 # dependencies only.
145 $srcdir_name = '';
147 # List of Makefile.am's to process, and their corresponding outputs.
148 @input_files = ();
149 %output_files = ();
151 # Complete list of Makefile.am's that exist.
152 @configure_input_files = ();
154 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
155 @other_input_files = ();
156 # Line number at which AC_OUTPUT seen.
157 $ac_output_line = 0;
159 # List of directories to search for configure-required files.  This
160 # can be set by AC_CONFIG_AUX_DIR.
161 @config_aux_path = ('.', '..', '../..');
162 $config_aux_dir = '';
164 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
165 $seen_make_set = 0;
167 # Whether AM_GNU_GETTEXT has been seen in configure.in.
168 $seen_gettext = 0;
169 # Line number at which AM_GNU_GETTEXT seen.
170 $ac_gettext_line = 0;
172 # Whether ALL_LINGUAS has been seen.
173 $seen_linguas = '';
174 # The actual text.
175 $all_linguas = '';
176 # Line number at which it appears.
177 $all_linguas_line = 0;
179 # 1 if AC_PROG_INSTALL seen.
180 $seen_prog_install = 0;
182 # Whether AC_PATH_XTRA has been seen in configure.in.
183 $seen_path_xtra = 0;
185 # TRUE if AC_DECL_YYTEXT was seen.
186 $seen_decl_yytext = 0;
188 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
189 # AC_CHECK_TOOL also sets this.
190 $seen_canonical = 0;
192 # TRUE if we've seen AC_ARG_PROGRAM.
193 $seen_arg_prog = 0;
195 # TRUE if we've seen AC_PROG_LIBTOOL.
196 $seen_libtool = 0;
197 $libtool_line = 0;
199 # Files installed by libtoolize.
200 @libtoolize_files = ('ltconfig', 'ltmain.sh', 'config.guess', 'config.sub');
202 # TRUE if we've seen AM_MAINTAINER_MODE.
203 $seen_maint_mode = 0;
205 # TRUE if we've seen PACKAGE and VERSION.
206 $seen_package = 0;
207 $seen_version = 0;
209 # Actual version we've seen.
210 $package_version = '';
212 # Line number where we saw version definition.
213 $package_version_line = 0;
215 # TRUE if we've seen AM_PATH_LISPDIR.
216 $seen_lispdir = 0;
218 # TRUE if we've seen AC_EXEEXT.
219 $seen_exeext = 0;
221 # TRUE if we've seen AC_OBJEXT.
222 $seen_objext = 0;
224 # TRUE if we've seen AC_ENABLE_MULTILIB.
225 $seen_multilib = 0;
227 # TRUE if we've seen AM_PROG_CC_C_O
228 $seen_cc_c_o = 0;
230 # Hash table of discovered configure substitutions.  Keys are names,
231 # values are `FILE:LINE' strings which are used by error message
232 # generation.
233 %configure_vars = ();
235 # This is used to keep track of which variable definitions we are
236 # scanning.  It is only used in certain limited ways, but it has to be
237 # global.  It is declared just for documentation purposes.
238 %vars_scanned = ();
240 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
241 # handled in a funny way: if seen in the top-level Makefile.am, it is
242 # used for every directory which does not specify a different value.
243 # The rationale here is that some directories (eg gettext) might be
244 # distributions of other packages, and thus require their own charset
245 # info.  However, the DIST_CHARSET must be the same for the entire
246 # package; it can only be set at top-level.
247 # FIXME: this yields bugs when rebuilding.  What to do?  Always
248 # read (and sometimes discard) top-level Makefile.am?
249 $maint_charset = '';
250 $dist_charset = 'utf8';         # recode doesn't support this yet.
252 # Name of input file ("Makefile.in") and output file ("Makefile.am").
253 # These have no directory components.
254 $am_file_name = '';
255 $in_file_name = '';
257 # TRUE if --cygnus seen.
258 $cygnus_mode = 0;
260 # Keys of this hash are names of dependency files to ignore.
261 %omit_dependencies = ();
263 # Hash table of AM_CONDITIONAL variables seen in configure.
264 %configure_cond = ();
266 # Map from obsolete macros to hints for new macros.
267 # If you change this, change the corresponding list in aclocal.in.
268 # FIXME: should just put this into a single file.
269 %obsolete_macros =
270     (
271      'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
272      'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
273      'AC_FEATURE_EXIT', '',
274      'AC_SYSTEM_HEADER', '',
276      # Note that we do not handle this one, because it is still run
277      # from AM_CONFIG_HEADER.  So we deal with it specially in
278      # scan_configure.
279      # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",
281      'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
282      'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
283      'fp_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
284      'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
285      'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
286      'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
287      'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
288      'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
289      'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",
290      'ud_GNU_GETTEXT', "use \`AM_GNU_GETTEXT'",
292      # Now part of autoconf proper, under a different name.
293      'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
294      'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
295      'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",
296      'AM_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
297      'AM_EXEEXT', "use \`AC_EXEEXT'",
298      'AM_CYGWIN32', "use \`AC_CYGWIN32'",
299      'AM_MINGW32', "use \`AC_MINGW32'",
300      'AM_FUNC_MKTIME', "use \`AC_FUNC_MKTIME'",
302 # These aren't quite obsolete.
303 #      'md_PATH_PROG',
304      );
306 # Regexp to match the above macros.
307 $obsolete_rx = '(' . join ('|', keys %obsolete_macros) . ')';
309 # This maps extensions onto language names.
310 %extension_map = ();
312 # This maps languages names onto properties.
313 %language_map = ();
317 # Initialize global constants and our list of languages that are
318 # internally supported.
319 &initialize_global_constants;
321 &register_language ('c', 'ansi-p=1', 'autodep=', 'flags=CFLAGS',
322                     'compile=$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
323                     'compiler-name=COMPILE',
324                     'output-arg=-c',
325                     'c');
326 &register_language ('cxx', 'linker=CXXLINK', 'autodep=CXX', 'flags=CXXFLAGS',
327                     'compile=$(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
328                     'compiler-name=CXXCOMPILE',
329                     'output-arg=-c -o $@',
330                     'c++', 'cc', 'cpp', 'cxx', 'C');
331 &register_language ('objc', 'linker=OBJCLINK', 'autodep=OBJC',
332                     'flags=OBJCFLAGS',
333                     'compile=$(OBJC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
334                     'compiler-name=OBJCCOMPILE',
335                     'output-arg=-c -o $@',
336                     'm');
337 &register_language ('header',
338                     'h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc');
340 # For now, yacc and lex can't be handled on a per-exe basis.
341 &register_language ('yacc', 'ansi-p=1',
342                     'y');
343 &register_language ('yaccxx', 'linker=CXXLINK',
344                     'y++', 'yy', 'yxx', 'ypp');
345 &register_language ('lex', 'ansi-p=1',
346                     'l');
347 &register_language ('lexxx', 'linker=CXXLINK',
348                     'l++', 'll', 'lxx', 'lpp');
350 &register_language ('asm',
351                     'flags=CFLAGS', # FIXME: asmflags?
352                     'compile=$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)', # FIXME: a different compiler?
353                     'compiler-name=COMPILE',
354                     'output-arg=-c',
355                     's', 'S');
357 &register_language ('f77', 'linker=F77LINK', 'flags=FFLAGS',
358                     'compile=$(F77) $(AM_FFLAGS) $(FFLAGS)',
359                     'compiler-name=F77COMPILE',
360                     'output-arg=-c -o $@',
361                     'f', 'for', 'f90');
362 &register_language ('ppf77', 'linker=F77LINK', 'flags=FFLAGS',
363                     'compile=$(F77) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
364                     'compiler-name=PPF77COMPILE',
365                     'output-arg=-c -o $@',
366                     'F');
367 &register_language ('ratfor', 'linker=F77LINK',
368                     'flags=RFLAGS', # FIXME also FFLAGS.
369                     'compile=$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
370                     'compiler-name=RCOMPILE',
371                     'output-arg=-c -o $@',
372                     'r');
373 # FIXME: for now we can't do dependency tracking for Java.
374 # autodep=GCJ
375 &register_language ('java', 'linker=GCJLINK', 'flags=GCJFLAGS',
376                     'compile=$(GCJ) $(DEFS) $(INCLUDES) $(AM_GCJFLAGS) $(GCJFLAGS)',
377                     'compiler-name=GCJCOMPILE',
378                     'output-arg=-c -o $@',
379                     'java', 'class', 'zip', 'jar');
382 # Parse command line.
383 &parse_arguments (@ARGV);
385 # Do configure.in scan only once.
386 &scan_configure;
388 die "automake: no \`Makefile.am' found or specified\n"
389     if ! @input_files;
391 # If --generate-deps was given, we don't do anything else
393 if ($generate_deps)
395     die "automake: Must specify --include-deps (or -i) when generating\n"
396         if $use_dependencies;
397     die "automake: Must provide --build-dir when generating\n"
398         if ! $build_directory;
399     die "automake: Must provide --srcdir-name when generating\n"
400         if ! $srcdir_name;
402     open (GDEP, ">$output_directory/.dep_segment")
403         || die "automake: Could not open `$output_directory/.dep_segment': $!\n";
405     &handle_dependencies;
406     print GDEP $output_rules;
408     close(GDEP);
409     exit $exit_status;
412 # Now do all the work on each file.
413 foreach $am_file (@input_files)
415     if (! -f ($am_file . '.am'))
416     {
417         &am_error ("\`" . $am_file . ".am' does not exist");
418     }
419     else
420     {
421         &generate_makefile ($output_files{$am_file}, $am_file);
422     }
425 &am_conf_error ("AC_PROG_INSTALL must be used in configure.in")
426     if (! $seen_prog_install);
428 exit $exit_status;
431 ################################################################
433 # Parse command line.
434 sub parse_arguments
436     local (@arglist) = @_;
438     # Start off as gnu.
439     &set_strictness ('gnu');
441     while (@arglist)
442     {
443         if ($arglist[0] eq "--version")
444         {
445             print "automake (GNU $PACKAGE) $VERSION\n\n";
446             print "Copyright (C) 1999 Free Software Foundation, Inc.\n";
447             print "This is free software; see the source for copying conditions.  There is NO\n";
448             print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
449             print "Written by Tom Tromey <tromey\@cygnus.com>\n";
451             exit 0;
452         }
453         elsif ($arglist[0] eq "--help")
454         {
455             &usage;
456         }
457         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
458         {
459             $am_dir = $1;
460         }
461         elsif ($arglist[0] eq '--amdir')
462         {
463             &require_argument (@arglist);
464             shift (@arglist);
465             $am_dir = $arglist[0];
466         }
467         elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
468         {
469             # Must end in /.
470             $build_directory = $1 . '/';
471         }
472         elsif ($arglist[0] eq '--build-dir')
473         {
474             &require_argument (@arglist);
475             shift (@arglist);
476             # Must end in /.
477             $build_directory = $arglist[0] . '/';
478         }
479         elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
480         {
481             $srcdir_name = $1;
482         }
483         elsif ($arglist[0] eq '--srcdir-name')
484         {
485             &require_argument (@arglist);
486             shift (@arglist);
487             $srcdir_name = $arglist[0];
488         }
489         elsif ($arglist[0] eq '--gnu')
490         {
491             &set_strictness ('gnu');
492         }
493         elsif ($arglist[0] eq '--gnits')
494         {
495             &set_strictness ('gnits');
496         }
497         elsif ($arglist[0] eq '--cygnus')
498         {
499             $cygnus_mode = 1;
500         }
501         elsif ($arglist[0] eq '--foreign')
502         {
503             &set_strictness ('foreign');
504         }
505         elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
506         {
507             $cmdline_use_dependencies = 0;
508         }
509         elsif ($arglist[0] eq '--generate-deps')
510         {
511             $generate_deps = 1;
512         }
513         elsif ($arglist[0] eq '--no-force')
514         {
515             $force_generation = 0;
516         }
517         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
518         {
519             # Set output directory.
520             $output_directory = $1;
521         }
522         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
523         {
524             &require_argument (@arglist);
525             shift (@arglist);
526             $output_directory = $arglist[0];
527         }
528         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
529         {
530             $add_missing = 1;
531         }
532         elsif ($arglist[0] eq '--copy' || $arglist[0] eq '-c')
533         {
534             $copy_missing = 1;
535         }
536         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
537         {
538             $verbose = 1;
539         }
540         elsif ($arglist[0] eq '--')
541         {
542             # Stop option processing.
543             shift (@arglist);
544             push (@input_files, @arglist);
545             last;
546         }
547         elsif ($arglist[0] =~ /^-/)
548         {
549             die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
550         }
551         else
552         {
553             # Handle $local:$input syntax.  Note that we only examine
554             # the first ":" file to see if it is automake input; the
555             # rest are just taken verbatim.  We still keep all the
556             # files around for dependency checking, however.
557             local ($local, $input, @rest) = split (/:/, $arglist[0]);
558             if (! $input)
559             {
560                 $input = $local;
561             }
562             else
563             {
564                 # Strip .in; later on .am is tacked on.  That is how
565                 # the automake input file is found.  Maybe not the
566                 # best way, but it is easy to explain.  FIXME: should
567                 # be error if .in is missing.
568                 $input =~ s/\.in$//;
569             }
570             push (@input_files, $input);
571             $output_files{$input} = join (':', ($local, @rest));
572         }
574         shift (@arglist);
575     }
577     # Take global strictness from whatever we currently have set.
578     $default_strictness = $strictness;
579     $default_strictness_name = $strictness_name;
582 # Ensure argument exists, or die.
583 sub require_argument
585     local ($arg, @arglist) = @_;
586     die "automake: no argument given for option \`$arg'\n"
587         if ! @arglist;
590 ################################################################
592 # Generate a Makefile.in given the name of the corresponding Makefile and
593 # the name of the file output by config.status.
594 sub generate_makefile
596     local ($output, $makefile) = @_;
598     ($am_file_name = $makefile) =~ s/^.*\///;
599     $in_file_name = $am_file_name . '.in';
600     $am_file_name .= '.am';
602     # $OUTPUT is encoded.  If it contains a ":" then the first element
603     # is the real output file, and all remaining elements are input
604     # files.  We don't scan or otherwise deal with these input file,
605     # other than to mark them as dependencies.  See scan_configure for
606     # details.
607     local (@secondary_inputs);
608     ($output, @secondary_inputs) = split (/:/, $output);
610     &initialize_per_input;
611     $relative_dir = &dirname ($output);
612     $am_relative_dir = &dirname ($makefile);
614     # At the toplevel directory, we might need config.guess, config.sub
615     # or libtool scripts (ltconfig and ltmain.sh).
616     if ($relative_dir eq '.')
617     {
618         # libtool requires some files.
619         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
620                                            @libtoolize_files)
621             if $seen_libtool;
623         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
624         # config.sub.
625         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
626             if $seen_canonical;
627     }
629     # We still need Makefile.in here, because sometimes the `dist'
630     # target doesn't re-run automake.
631     if ($am_relative_dir eq $relative_dir)
632     {
633         # Only distribute the files if they are in the same subdir as
634         # the generated makefile.
635         &push_dist_common ($in_file_name, $am_file_name);
636     }
638     push (@sources, '$(SOURCES)')
639         if &variable_defined ('SOURCES');
640     push (@objects, '$(OBJECTS)')
641         if &variable_defined ('OBJECTS');
643     &read_main_am_file ($makefile . '.am');
644     if (&handle_options)
645     {
646         # Fatal error.  Just return, so we can continue with next file.
647         return;
648     }
650     # Must do this after reading .am file.  See read_main_am_file to
651     # understand weird tricks we play there with variables.
652     &define_variable ('subdir', $relative_dir);
654     # Check first, because we might modify some state.
655     &check_cygnus;
656     &check_gnu_standards;
657     &check_gnits_standards;
659     &handle_configure ($output, $makefile, @secondary_inputs);
660     &handle_gettext;
661     &handle_libraries;
662     &handle_ltlibraries;
663     &handle_programs;
664     &handle_scripts;
666     &handle_built_sources;
668     # This must be run after all the sources are scanned.
669     &finish_languages;
671     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
672     # on this (but currently does).
673     $contents{'SOURCES'} = join (' ', @sources);
674     $contents{'OBJECTS'} = join (' ', @objects);
675     &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
677     &handle_multilib;
678     &handle_texinfo;
679     &handle_emacs_lisp;
680     &handle_java;
681     &handle_man_pages;
682     &handle_data;
683     &handle_headers;
684     &handle_subdirs;
685     &handle_tags;
686     &handle_minor_options;
687     &handle_dist ($makefile);
688     &handle_dependencies;
689     &handle_tests;
690     &handle_footer;
691     &handle_merge_targets ($output);
692     &handle_installdirs;
693     &handle_clean;
694     &handle_phony;
696     &check_typos;
698     if (! -d ($output_directory . '/' . $am_relative_dir))
699     {
700         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
701     }
703     local ($out_file) = $output_directory . '/' . $makefile . ".in";
704     if (! $force_generation && -e $out_file)
705     {
706         local ($am_time) = (stat ($makefile . '.am'))[9];
707         local ($in_time) = (stat ($out_file))[9];
708         # FIXME: should cache these times.
709         local ($conf_time) = (stat ('configure.in'))[9];
710         # FIXME: how to do unsigned comparison?
711         if ($am_time < $in_time || $am_time < $conf_time)
712         {
713             # No need to update.
714             return;
715         }
716         if (-f 'aclocal.m4')
717         {
718             local ($acl_time) = (stat _)[9];
719             return if ($am_time < $acl_time);
720         }
721     }
723     if (! open (GM_FILE, "> " . $out_file))
724     {
725         warn "automake: ${am_file}.in: cannot write: $!\n";
726         $exit_status = 1;
727         return;
728     }
729     print "automake: creating ", $makefile, ".in\n" if $verbose;
731     print GM_FILE $output_vars;
732     # We make sure that `all:' is the first target.
733     print GM_FILE $output_all;
734     print GM_FILE $output_header;
735     print GM_FILE $output_rules;
736     print GM_FILE $output_trailer;
738     close (GM_FILE);
741 ################################################################
743 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
744 sub handle_options
746     if (&variable_defined ('AUTOMAKE_OPTIONS'))
747     {
748         foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
749         {
750             $options{$_} = 1;
751             if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
752             {
753                 &set_strictness ($_);
754             }
755             elsif ($_ eq 'cygnus')
756             {
757                 $cygnus_mode = 1;
758             }
759             elsif (/ansi2knr/)
760             {
761                 # An option like "../lib/ansi2knr" is allowed.  With
762                 # no path prefix, we assume the required programs are
763                 # in this directory.  We save the actual option for
764                 # later.
765                 $options{'ansi2knr'} = $_;
766             }
767             elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
768                    || $_ eq 'dist-shar' || $_ eq 'dist-zip'
769                    || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
770                    || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
771                    || $_ eq 'readme-alpha' || $_ eq 'check-news'
772                    || $_ eq 'subdir-objects')
773             {
774                 # Explicitly recognize these.
775             }
776             elsif ($_ eq 'no-dependencies')
777             {
778                 $use_dependencies = 0;
779             }
780             elsif (/([0-9]+)\.([0-9]+)([a-z])?/)
781             {
782                 # Got a version number.
784                 local ($rmajor, $rminor, $ralpha) = ($1, $2, $3);
786                 if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
787                 {
788                     print STDERR
789                         "automake: programming error: version is incorrect\n";
790                     exit 1;
791                 }
792                 local ($tmajor, $tminor, $talpha) = ($1, $2, $3);
794                 # 2.0 is better than 1.0.
795                 # 1.2 is better than 1.1.
796                 # 1.2a is better than 1.2.
797                 if ($rmajor > $tmajor
798                     || ($rmajor == $tmajor && $rminor > $tminor)
799                     || ($rminor == $tminor && $rminor == $tminor
800                         && $ralpha gt $talpha))
801                 {
802                     &am_line_error ('AUTOMAKE_OPTIONS',
803                                     "require version $_, only have $VERSION");
804                     return 1;
805                 }
806             }
807             else
808             {
809                 &am_line_error ('AUTOMAKE_OPTIONS',
810                                 "option \`" . $_ . "\' not recognized");
811             }
812         }
813     }
815     if ($strictness == $GNITS)
816     {
817         $options{'readme-alpha'} = 1;
818         $options{'check-news'} = 1;
819     }
821     return 0;
824 # Return object extension.  Just once, put some code into the output.
825 # Argument is the name of the output file
826 sub get_object_extension
828     local ($out) = @_;
830     # Maybe require libtool library object files.
831     local ($extension) = '.o';
832     $extension = '.$(OBJEXT)' if $seen_objext;
833     $extension = '.lo' if ($out =~ /\.la$/);
835     if (! $included_generic_compile)
836     {
837         # Boilerplate.
838         local ($xform) = '';
839         if (&variable_defined ('CONFIG_HEADER'))
840         {
841             local ($one_hdr);
842             foreach $one_hdr (split (' ', &variable_value ('CONFIG_HEADER')))
843             {
844                 local ($var);
845                 ($var = &dirname ($one_hdr)) =~ s/(\W)/\\$1/g;
846                 $xform .= ' ' if $xform;
847                 $xform .= '-I' . $var;
848             }
849         }
850         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go;';
851         $output_vars .= &file_contents_with_transform ($xform,
852                                                        'comp-vars');
854         $xform = $seen_objext ? 's/^OBJEXT//;' : 's/^OBJEXT.*$//;';
855         $output_rules .= &file_contents_with_transform ($xform, 'compile');
857         &push_phony_cleaners ('compile');
859         # If using X, include some extra variable definitions.  NOTE
860         # we don't want to force these into CFLAGS or anything,
861         # because not all programs will necessarily use X.
862         if ($seen_path_xtra)
863         {
864             local ($var);
865             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
866             {
867                 &define_configure_variable ($var);
868             }
869         }
871         push (@suffixes, '.c', '.o');
872         push (@suffixes, '.obj') if $seen_objext;
873         push (@clean, 'compile');
875         $included_generic_compile = 1;
876     }
878     if ($seen_libtool && ! $included_libtool_compile)
879     {
880         # Output the libtool compilation rules.
881         $output_rules .=
882             &file_contents_with_transform
883                 ($use_dependencies ? 's/^NOTDEPEND.*$//;' : 's/^NOTDEPEND//;',
884                  'libtool');
886         &push_phony_cleaners ('libtool');
888         push (@suffixes, '.lo');
889         push (@clean, 'libtool');
891         $included_libtool_compile = 1;
892     }
894     # Check for automatic de-ANSI-fication.
895     if (defined $options{'ansi2knr'})
896     {
897         $extension = '$U' . $extension;
898         if (! $included_knr_compile)
899         {
900             if (! $am_c_prototypes)
901             {
902                 &am_line_error ('AUTOMAKE_OPTIONS',
903                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
904                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
905                 # Only give this error once.
906                 $am_c_prototypes = 1;
907             }
909             # Only require ansi2knr files if they should appear in
910             # this directory.
911             if ($options{'ansi2knr'} eq 'ansi2knr')
912             {
913                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
914                                          'ansi2knr.c', 'ansi2knr.1');
915                 $output_rules .= &file_contents ('kr-extra');
916                 push (@clean, 'krextra');
917                 &push_phony_cleaners ('krextra');
918             }
920             # Generate rules to build ansi2knr.  If it is in some
921             # other directory, then generate dependencies but have the
922             # rule just run elsewhere.
923             $objext = $seen_objext ? ".$(OBJEXT)" : ".o";
924             $output_rules .= ($options{'ansi2knr'} . ': '
925                               . $options{'ansi2knr'} . $objext . "\n");
926             if ($options{'ansi2knr'} eq 'ansi2knr')
927             {
928                 $output_rules .= ("\t\$(LINK) ansi2knr" . $objext
929                                   . " \$(LIBS)\n"
930                                   . "ansi2knr" . $objext
931                                   . ": \$(CONFIG_HEADER)\n\n");
932             }
933             else
934             {
935                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
936                                   . " && \$(MAKE) \$(AM_MAKEFLAGS) "
937                                   . "ansi2knr\n\n");
938                 # This is required for non-GNU makes.
939                 $output_rules .= ($options{'ansi2knr'} . $objext . ":\n");
940                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
941                                   . " && \$(MAKE) \$(AM_MAKEFLAGS)"
942                                   . " ansi2knr" . $objext . "\n\n");
943             }
945             # Make sure ansi2knr can be found: if no path specified,
946             # specify "./".
947             if ($options{'ansi2knr'} eq 'ansi2knr')
948             {
949                 # Substitution from AM_C_PROTOTYPES.  This makes it be
950                 # built only when necessary.
951                 &define_configure_variable ('ANSI2KNR');
952                 # ansi2knr needs to be built before subdirs, so unshift it.
953                 unshift (@all, '$(ANSI2KNR)');
954             }
955             else
956             {
957                 # Found in another directory.
958                 &define_variable ("ANSI2KNR", $options{'ansi2knr'});
959             }
961             $output_rules .= &file_contents ('clean-kr');
963             push (@clean, 'kr');
964             &push_phony_cleaners ('kr');
966             $included_knr_compile = 1;
967         }
968     }
970     return $extension;
973 # Call finish function for each language that was used.
974 sub finish_languages
976     local ($ltcompile, $ltlink) = &libtool_compiler;
978     local ($ext, $name, $lang, %done);
979     local ($non_c) = 1;
980     foreach $ext (sort keys %extension_seen)
981     {
982         $lang = $extension_map{$ext};
984         # Generate the appropriate rules for this extension.
985         local ($comp) = '';
986         if (defined $language_map{$lang . '-compile'})
987         {
988             $comp = $language_map{$lang . '-compile'};
990             local ($outarg) = $language_map{$lang . '-output-arg'};
991             if ($language_map{$lang . '-flags'} eq 'CFLAGS')
992             {
993                 # C compilers don't always support -c -o.
994                 if (defined $options{'subdir-objects'})
995                 {
996                     $outarg .= ' -o $@';
997                 }
998             }
1000             local ($full) = ("\t\$("
1001                              . $language_map{$lang . '-compiler-name'}
1002                              . ") "
1003                              . $outarg);
1004             $output_rules .= (".$ext.o:\n"
1005                               . $full
1006                               . " \$<\n");
1007             # FIXME: Using cygpath should be somehow conditional.
1008             $output_rules .= (".$ext.obj:\n"
1009                               . $full
1010                               . " \`cygpath -w \$<\`\n")
1011                 if $seen_objext;
1012             $output_rules .= (".$ext.lo:\n"
1013                               . "\t\$(LT"
1014                               . $language_map{$lang . '-compiler-name'}
1015                               . ") "
1016                               . $language_map{$lang . '-output-arg'}
1017                               # We can always use -c -o with libtool.
1018                               . ($language_map{$lang . '-flags'} eq 'CFLAGS'
1019                                  ? ' -o $@' : '')
1020                               . " \$<\n")
1021                 if $seen_libtool;
1022         }
1024         push (@suffixes, '.' . $ext);
1026         # The rest of the loop is done once per language.
1027         next if defined $done{$lang};
1028         $done{$lang} = 1;
1030         $non_c = 0 if $lang !~ /(objc|cxx|f77|ratfor)$/;
1032         if ($comp ne '')
1033         {
1034             &define_compiler_variable ($language_map{$lang . '-compiler-name'},
1035                                        $ltcompile, $comp);
1036         }
1037         # The compiler's flag must be a configure variable.
1038         if (defined $language_map{$lang . '-flags'})
1039         {
1040             &define_configure_variable ($language_map{$lang . '-flags'});
1041         }
1043         # Compute the function name of the finisher and then call it.
1044         $name = 'lang_' . $lang . '_finish';
1045         & $name ();
1046     }
1048     # If the project is entirely C++ or entirely Fortran 77, don't
1049     # bother with the C stuff.  But if anything else creeps in, then use
1050     # it.
1051     if (! $non_c || scalar keys %suffix_rules > 0)
1052     {
1053         if (! defined $done{'c'})
1054         {
1055             &define_configure_variable ($language_map{'c-flags'});
1056             &define_compiler_variable ($language_map{'c-compiler-name'},
1057                                        $ltcompile,
1058                                        $language_map{'c-compile'});
1059         }
1060         &define_variable ('CCLD', '$(CC)');
1061         &define_variable ('LINK', $ltlink . '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
1062     }
1065 # Output a rule to build from a YACC source.  The output from YACC is
1066 # compiled with C or C++, depending on the extension of the YACC file.
1067 sub output_yacc_build_rule
1069     local ($yacc_suffix, $use_ylwrap, $c_suffix) = @_;
1071     local ($suffix);
1072     ($suffix = $yacc_suffix) =~ tr/y/c/;
1073     push (@suffixes, $yacc_suffix, $suffix);
1075     # Generate rule for c/c++.
1076     $output_rules .= "$yacc_suffix$suffix:\n\t";
1078     if ($use_ylwrap)
1079     {
1080         $output_rules .= ('$(SHELL) $(YLWRAP)'
1081                           . ' "$(YACC)" $< y.tab.c $*' . $suffix
1082                           . ' y.tab.h $*.h -- $(AM_YFLAGS) $(YFLAGS)');
1083     }
1084     else
1085     {
1086         $output_rules .= ('$(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*'
1087                           . $suffix . "\n"
1088                           . "\tif test -f y.tab.h; then \\\n"
1089                           . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
1090                           . "\telse :; fi");
1091     }
1092     $output_rules .= "\n";
1095 sub output_lex_build_rule
1097     local ($lex_suffix, $use_ylwrap) = @_;
1098     local ($c_suffix);
1100     ($c_suffix = $lex_suffix) =~ tr/l/c/;
1101     push (@suffixes, $lex_suffix);
1102     &define_configure_variable ('LEX_OUTPUT_ROOT');
1103     &define_configure_variable ('LEXLIB');
1104     $output_rules .= "$lex_suffix$c_suffix:\n\t";
1106     if ($use_ylwrap)
1107     {
1108         # Is the $@ correct here?  If so, why not use it in the ylwrap
1109         # build rule for yacc above?
1110         $output_rules .= '$(SHELL) $(YLWRAP)'
1111             . ' "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(AM_LFLAGS) $(LFLAGS)';
1112     }
1113     else
1114     {
1115         $output_rules .= '$(LEX) $(AM_LFLAGS) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
1116     }
1117     $output_rules .= "\n";
1121 # Check to make sure a source defined in LIBOBJS is not explicitly
1122 # mentioned.  This is a separate function (as opposed to being inlined
1123 # in handle_source_transform) because it isn't always appropriate to
1124 # do this check.
1125 sub check_libobjs_sources
1127     local ($one_file, $unxformed) = @_;
1129     local ($prefix, $file, @files);
1130     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1131                      'dist_EXTRA_', 'nodist_EXTRA_')
1132     {
1133         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1134         {
1135             @files = &variable_value_as_list (($prefix
1136                                                . $one_file . '_SOURCES'),
1137                                               'all');
1138         }
1139         elsif ($prefix eq '')
1140         {
1141             @files = ($unxformed . '.c');
1142         }
1143         else
1144         {
1145             next;
1146         }
1148         foreach $file (@files)
1149         {
1150             if (defined $libsources{$file})
1151             {
1152                 &am_line_error ($prefix . $one_file . '_SOURCES',
1153                                 "automatically discovered file \`$file' should not be explicitly mentioned");
1154             }
1155         }
1156     }
1159 # Does much of the actual work for handle_source_transform.
1160 # Arguments are:
1161 #   name of resulting executable or library ("derived")
1162 #   object extension (e.g., `$U.lo')
1163 #   list of source files to transform
1164 # Result is a list
1165 #   first element is name of linker to use (empty string for default linker)
1166 #   remaining elements are names of objects
1167 sub handle_single_transform_list
1169     local ($derived, $obj, @files) = @_;
1170     local (@result) = ();
1171     local ($nonansi_obj) = $obj;
1172     $nonansi_obj =~ s/_//g;
1173     local (%linkers_used) = ();
1174     if (@files > 0)
1175     {
1176         # Turn sources into objects.
1177         foreach (@files)
1178         {
1179             # Skip things that look like configure substitutions.
1180             next if /^\@.*\@$/;
1182             # If the source file is in a subdirectory then the `.o' is
1183             # put into the current directory.
1185             # Split file name into base and extension.
1186             local ($full, $directory, $base, $extension, $linker, $object);
1187             next if ! /^((.*)\/)?([^\/]*)\.(.*)$/;
1188             $full = $_;
1189             $directory = $2;
1190             $base = $3;
1191             $extension = $4;
1193             local ($xbase) = $base;
1195             # We must generate a rule for the object if it requires
1196             # its own flags.
1197             local ($rule) = '';
1198             local ($renamed) = 0;
1200             local ($lang) = $extension_map{$extension};
1201             if ($lang)
1202             {
1203                 &saw_extension ($extension);
1204                 # Found the language, so see what it says.
1205                 local ($subr) = 'lang_' . $lang . '_rewrite';
1206                 # Note: computed subr call.
1207                 local ($r) = & $subr ($directory, $base, $extension);
1208                 # Skip this entry if we were asked not to process it.
1209                 next if $r == $LANG_IGNORE;
1211                 # Now extract linker and other info.
1212                 $linker = $language_map{$lang . '-linker'};
1214                 local ($this_obj_ext);
1215                 if ($language_map{$lang . '-ansi-p'})
1216                 {
1217                     $object = $base . $obj;
1218                     $this_obj_ext = $obj;
1219                 }
1220                 else
1221                 {
1222                     $object = $base . $nonansi_obj;
1223                     $this_obj_ext = $nonansi_obj;
1224                 }
1226                 if ($language_map{$lang . '-flags'} ne ''
1227                     && &variable_defined ($derived . '_'
1228                                           . $language_map{$lang . '-flags'}))
1229                 {
1230                     # We have a per-executable flag in effect for this
1231                     # object.  In this case we rewrite the object's
1232                     # name to ensure it is unique.  We also require
1233                     # the `compile' program to deal with compilers
1234                     # where `-c -o' does not work.
1236                     # We choose the name `DERIVED-OBJECT' to ensure
1237                     # (1) uniqueness, and (2) continuity between
1238                     # invocations.  However, this will result in a
1239                     # name that is too long for losing systems, in
1240                     # some situations.  So we provide _SHORTNAME to
1241                     # override.
1243                     local ($dname) = $derived;
1244                     if (&variable_defined ($derived . '_SHORTNAME'))
1245                     {
1246                         # FIXME: should use the same conditional as
1247                         # the _SOURCES variable.  But this is really
1248                         # silly overkill -- nobody should have
1249                         # conditional shortnames.
1250                         $dname = &variable_value ($derived . '_SHORTNAME');
1251                     }
1252                     $object = $dname . '-' . $object;
1254                     &require_file ($FOREIGN, 'compile')
1255                         if $lang eq 'c';
1257                     if (! defined $language_map{$lang . '-compile'})
1258                     {
1259                         print STDERR "automake: programming error: $lang flags defined without compiler\n";
1260                         exit 1;
1261                     }
1262                     # Compute the rule to compile this object.
1263                     local ($flag) = $language_map{$lang . '-flags'};
1264                     local ($val) = "(${derived}_${flag}";
1265                     ($rule = $language_map{$lang . '-compile'}) =~    
1266                         s/\(AM_$flag/$val/;
1268                     $rule .= ' ' . $language_map{$lang . '-output-arg'};
1269                     # For C we have to add the -o, because the
1270                     # standard rule doesn't include it.
1271                     if ($language_map{$lang . '-flags'} eq 'CFLAGS')
1272                     {
1273                         $rule .= ' -o $@';
1274                     }
1276                     $renamed = 1;
1277                 }
1279                 # If rewrite said it was ok, put the object into a
1280                 # subdir.
1281                 if ($r == $LANG_SUBDIR && $directory ne '')
1282                 {
1283                     $object = $directory . '/' . $object;
1284                     $xbase = $directory . '/' . $base;
1285                 }
1287                 # If doing dependency tracking, then we can't print
1288                 # the rule.
1289                 if ($use_dependencies
1290                     && $rule ne ''
1291                     && $language_map{$lang . '-autodep'} ne 'no')
1292                 {
1293                     $rule = '';
1294                     local ($obj_sans_ext) = substr ($object, 0,
1295                                                     - length ($this_obj_ext));
1296                     $lang_specific_files{$lang} .= (' ' . $derived
1297                                                     . ' ' . $full
1298                                                     . ' ' . $obj_sans_ext);
1299                 }
1300             }
1301             elsif ($extension =~ /^$source_suffix_pattern$/) 
1302             {
1303                 # We just rewrite it.  Maybe we should do more.
1304                 # FIXME: what about subdir handling here?
1305                 $object = $base . '.' . $suffix_rules{$extension};
1306                 $linker = '';
1307             }
1308             else
1309             {
1310                 # No error message here.  Used to have one, but it was
1311                 # very unpopular.
1312                 next;
1313             }
1315             $linkers_used{$linker} = 1;
1317             push (@result, $object);
1319             if (defined $object_map{$object})
1320             {
1321                 if ($object_map{$object} ne $full)
1322                 {
1323                     &am_error ("object \`$object' created by \`$full' and \`$object_map{$object}'");
1324                 }
1325             }
1326             else
1327             {
1328                 local (@dep_list) = ();
1329                 $object_map{$object} = $full;
1331                 # If file is in subdirectory, we need explicit
1332                 # dependency.
1333                 if ($directory ne '' || $renamed)
1334                 {
1335                     push (@dep_list, $full);
1336                 }
1338                 # If resulting object is in subdir, we need to make
1339                 # sure the subdir exists at build time.
1340                 if ($object =~ /\//)
1341                 {
1342                     # FIXME: check that $DIRECTORY is somewhere in the
1343                     # project
1345                     # We don't allow `..' in object file names for
1346                     # *any* source, not just Java.  For Java it just
1347                     # doesn't make sense, but in general it is
1348                     # a problem because we can't pick a good name for
1349                     # the .deps entry.
1350                     if ($object =~ /(\/|^)\.\.\//)
1351                     {
1352                         &am_error ("\`$full' contains \`..' component but should not");
1353                     }
1355                     push (@dep_list, $directory . '/.dirstamp');
1357                     # If we're generating dependencies, we also want
1358                     # to make sure that the appropriate subdir of the
1359                     # .deps directory is created.
1360                     if ($use_dependencies)
1361                     {
1362                         push (@dep_list, '.deps/' . $directory . '/.dirstamp');
1363                     }
1365                     if (! defined $directory_map{$directory})
1366                     {
1367                         $directory_map{$directory} = 1;
1368                         $output_rules .= ($directory . "/.dirstamp:\n"
1369                                           . "\t\@\$(mkinstalldirs) $directory\n"
1370                                           . "\t\@: > $directory/.dirstamp\n");
1371                         if ($use_dependencies)
1372                         {
1373                             $output_rules .= ('.deps/' . $directory
1374                                               . "/.dirstamp:\n"
1375                                               . "\t\@\$(mkinstalldirs) .deps/$directory\n"
1376                                               . "\t\@: > .deps/$directory/.dirstamp\n");
1377                         }
1378                     }
1379                 }
1381                 &pretty_print_rule ($object . ':', "\t", @dep_list)
1382                     if scalar @dep_list > 0 || $rule ne '';
1384                 # Print the rule if we have one.
1385                 if ($rule ne '')
1386                 {
1387                     # Turn `$@' into name of our object file.
1388                     local ($xform);
1389                     ($xform = $object) =~ s,/,\\/,g;
1390                     $rule =~ s/\$\@/$xform/;
1391                     # FIXME: we use $< in an explicit rule here.
1392                     # We can't use $(srcdir)/<file> because we don't
1393                     # actually know it is in srcdir.
1394                     $rule .= ' $<';
1395                     # FIXME: handle .lo and .obj as well.
1396                     $output_rules .= "\t" . $rule . "\n";
1397                 }
1398             }
1400             # Transform .o or $o file into .P file (for automatic
1401             # dependency code).
1402             $dep_files{'.deps/' . $xbase . '.P'} = 1;
1403         }
1404     }
1406     return (&resolve_linker (%linkers_used), @result);
1409 # Handle SOURCE->OBJECT transform for one program or library.
1410 # Arguments are:
1411 #   canonical (transformed) name of object to build
1412 #   actual name of object to build
1413 #   object extension (ie either `.o' or `$o'.
1414 # Return result is name of linker variable that must be used.
1415 # Empty return means just use `LINK'.
1416 sub handle_source_transform
1418     # one_file is canonical name.  unxformed is given name.  obj is
1419     # object extension.
1420     local ($one_file, $unxformed, $obj) = @_;
1422     local ($linker) = '';
1424     if (&variable_defined ($one_file . "_OBJECTS"))
1425     {
1426         &am_line_error ($one_file . '_OBJECTS',
1427                         $one_file . '_OBJECTS', 'should not be defined');
1428         # No point in continuing.
1429         return;
1430     }
1432     local (@files, @result, $prefix, $temp, $xpfx);
1433     local (%used_pfx) = ();
1434     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1435                      'dist_EXTRA_', 'nodist_EXTRA_')
1436     {
1437         # We are going to define _OBJECTS variables using the prefix.
1438         # Then we glom them all together.  So we can't use the null
1439         # prefix here as we need it later.
1440         $xpfx = ($prefix eq '') ? 'am_' : $prefix;
1442         @files = ();
1443         local ($var) = $prefix . $one_file . "_SOURCES";
1444         if (&variable_defined ($var))
1445         {
1446             # Keep track of which prefixes we saw.
1447             $used_pfx{$xpfx} = 1
1448                 unless $prefix =~ /EXTRA_/;
1450             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1451             push (@objects, '$(' . $xpfx . $one_file . "_OBJECTS)")
1452                 unless $prefix =~ /EXTRA_/;
1453             push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
1454                 unless $prefix =~ /^nodist_/;
1455             local (@conds) = &variable_conditions ($var);
1456             if (! @conds)
1457             {
1458                 @files = &variable_value_as_list ($var, '');
1459             }
1460             else
1461             {
1462                 local ($cond);
1463                 foreach $cond (@conds)
1464                 {
1465                     @files = &variable_value_as_list ($var, $cond);
1466                     ($temp, @result) =
1467                         &handle_single_transform_list ($one_file, $obj,
1468                                                        @files);
1469                     $linker = $temp if $linker eq '';
1471                     # Define _OBJECTS conditionally.
1472                     &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
1473                                              $cond, @result)
1474                         unless $prefix =~ /EXTRA_/;
1475                 }
1477                 next;
1478             }
1479         }
1481         # Avoid defining needless variables.
1482         next if (scalar @files == 0);
1484         ($temp, @result) = &handle_single_transform_list ($one_file, $obj,
1485                                                           @files);
1486         $linker = $temp if $linker eq '';
1487         &define_pretty_variable ($xpfx . $one_file . "_OBJECTS", '', @result)
1488             unless $prefix =~ /EXTRA_/;
1489     }
1491     local (@keys) = sort keys %used_pfx;
1492     if (scalar @keys == 0)
1493     {
1494         &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1495         push (@sources, $unxformed . '.c');
1496         push (@dist_sources, $unxformed . '.c');
1497         push (@objects, $unxformed . $obj);
1498         push (@files, $unxformed . '.c');
1500         ($temp, @result) = &handle_single_transform_list ($one_file, $obj,
1501                                                           @files);
1502         $linker = $temp if $linker eq '';
1503         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
1504     }
1505     else
1506     {
1507         grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
1508         &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
1509     }
1511     return $linker;
1514 # Handle the BUILT_SOURCES variable.
1515 sub handle_built_sources
1517     return unless &variable_defined ('BUILT_SOURCES');
1519     local (@sources) = &variable_value_as_list ('BUILT_SOURCES', 'all');
1520     local ($s);
1521     foreach $s (@sources)
1522     {
1523         if (/^\@.*\@$/)
1524         {
1525             # FIXME: is this really the right thing to do?
1526             &am_line_error ('BUILT_SOURCES',
1527                             "\`BUILT_SOURCES' should not contain a configure substitution");
1528             last;
1529         }
1530     }
1533 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1534 # Also, generate _DEPENDENCIES variable if appropriate.
1535 # Arguments are:
1536 #   transformed name of object being built, or empty string if no object
1537 #   name of _LDADD/_LIBADD-type variable to examine
1538 #   boolean (lex_seen) which is true if a lex source file was seen in this
1539 #     object.  valid only for LDADDs, not LIBADDs.
1540 # Returns 1 if LIBOBJS seen, 0 otherwise.
1541 sub handle_lib_objects
1543     local ($xname, $var, $lex_seen) = @_;
1544     local ($ret);
1546     die "automake: programming error 1 in handle_lib_objects\n"
1547         if ! &variable_defined ($var);
1549     die "automake: programming error 2 in handle_lib_objects\n"
1550         if $lex_seen && $var =~ /LIBADD/;
1552     local (@conds) = &variable_conditions ($var);
1553     if (! @conds)
1554     {
1555         $ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
1556     }
1557     else
1558     {
1559         local ($cond);
1560         $ret = 0;
1561         foreach $cond (@conds)
1562         {
1563             if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
1564             {
1565                 $ret = 1;
1566             }
1567         }
1568     }
1570     return $ret;
1573 # Subroutine of handle_lib_objects: handle a particular condition.
1574 sub handle_lib_objects_cond
1576     local ($xname, $var, $lex_seen, $cond) = @_;
1578     # We recognize certain things that are commonly put in LIBADD or
1579     # LDADD.
1580     local ($lsearch);
1581     local (@dep_list) = ();
1583     local ($seen_libobjs) = 0;
1584     local ($flagvar) = 0;
1586     foreach $lsearch (&variable_value_as_list ($var, $cond))
1587     {
1588         # Skip -lfoo and -Ldir; these are explicitly allowed.
1589         next if $lsearch =~ /^-[lL]/;
1590         if (! $flagvar && $lsearch =~ /^-/)
1591         {
1592             if ($var =~ /^(.*)LDADD$/)
1593             {
1594                 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
1595                 next if $lsearch =~ /^-dl(pre)?open$/;
1596                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1597             }
1598             else
1599             {
1600                 # Only get this error once.
1601                 $flagvar = 1;
1602                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1603             }
1604         }
1606         # Assume we have a file of some sort, and push it onto the
1607         # dependency list.  Autoconf substitutions are not pushed;
1608         # rarely is a new dependency substituted into (eg) foo_LDADD
1609         # -- but "bad things (eg -lX11) are routinely substituted.
1610         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1611         # and handled specially below.
1612         push (@dep_list, $lsearch)
1613             unless $lsearch =~ /^\@.*\@$/;
1615         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1616         # means adding entries to dep_files.
1617         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1618         {
1619             push (@dep_list, $lsearch);
1620             $seen_libobjs = 1;
1621             if (! keys %libsources)
1622             {
1623                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
1624             }
1626             local ($iter, $rewrite);
1627             foreach $iter (keys %libsources)
1628             {
1629                 if ($iter =~ /\.([cly])$/)
1630                 {
1631                     &saw_extension ($1);
1632                     &saw_extension ('c');
1633                 }
1635                 if ($iter =~ /\.h$/)
1636                 {
1637                     &require_file_with_line ($var, $FOREIGN, $iter);
1638                 }
1639                 elsif ($iter ne 'alloca.c')
1640                 {
1641                     ($rewrite = $iter) =~ s/\.c$/.P/;
1642                     $dep_files{'.deps/' . $rewrite} = 1;
1643                     ($rewrite = $iter) =~ s/(\W)/\\$1/g;
1644                     $rewrite = "^" . $rewrite . "\$";
1645                     # Only require the file if it is not a built source.
1646                     if (! &variable_defined ('BUILT_SOURCES')
1647                         || ! grep (/$rewrite/,
1648                                    &variable_value_as_list ('BUILT_SOURCES',
1649                                                             'all')))
1650                     {
1651                         &require_file_with_line ($var, $FOREIGN, $iter);
1652                     }
1653                 }
1654             }
1655         }
1656         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1657         {
1658             push (@dep_list, $lsearch);
1659             &am_line_error ($var,
1660                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
1661                 if ! defined $libsources{'alloca.c'};
1662             $dep_files{'.deps/alloca.P'} = 1;
1663             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1664             &saw_extension ('c');
1665         }
1666     }
1668     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
1669     {
1670         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
1671     }
1673     return $seen_libobjs;
1676 # Canonicalize a name, and check to make sure the non-canonical name
1677 # is never used.  Returns canonical name.  Arguments are name and a
1678 # list of suffixes to check for.
1679 sub check_canonical_spelling
1681     local ($name, @suffixes) = @_;
1682     local ($xname, $xt);
1684     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
1685     if ($xname ne $name)
1686     {
1687         local ($xt);
1688         foreach $xt (@suffixes)
1689         {
1690             &am_line_error ($name . $xt,
1691                             "invalid variable \`" . $name . $xt
1692                             . "'; should be \`" . $xname . $xt . "'")
1693                 if &variable_defined ($name . $xt);
1694         }
1695     }
1697     return $xname;
1700 # Handle C programs.
1701 sub handle_programs
1703     local (@proglist) = &am_install_var ('-clean',
1704                                          'progs', 'PROGRAMS',
1705                                          'bin', 'sbin', 'libexec', 'pkglib',
1706                                          'noinst', 'check');
1707     return if ! @proglist;
1709     # If a program is installed, this is required.  We only want this
1710     # error to appear once.
1711     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1712         unless $seen_arg_prog;
1713     $seen_arg_prog = 1;
1715     local ($one_file, $xname, $munge);
1717     local ($seen_libobjs) = 0;
1718     foreach $one_file (@proglist)
1719     {
1720         local ($obj) = &get_object_extension ($one_file);
1722         # Canonicalize names and check for misspellings.
1723         $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
1724                                             '_SOURCES', '_OBJECTS',
1725                                             '_DEPENDENCIES');
1727         # FIXME: Using a trick to figure out if any lex sources appear
1728         # in our program; should use some cleaner method.
1729         local ($lex_num) = scalar (keys %lex_sources);
1730         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1731         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1733         local ($xt) = '';
1734         if (&variable_defined ($xname . "_LDADD"))
1735         {
1736             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1737                                      $lex_file_seen))
1738             {
1739                 $seen_libobjs = 1;
1740             }
1741             $lex_file_seen = 0;
1742             $xt = '_LDADD';
1743         }
1744         else
1745         {
1746             # User didn't define prog_LDADD override.  So do it.
1747             &define_variable ($xname . '_LDADD', '$(LDADD)');
1749             # This does a bit too much work.  But we need it to
1750             # generate _DEPENDENCIES when appropriate.
1751             if (&variable_defined ('LDADD'))
1752             {
1753                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1754                 {
1755                     $seen_libobjs = 1;
1756                 }
1757                 $lex_file_seen = 0;
1758             }
1759             elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
1760             {
1761                 &define_variable ($xname . '_DEPENDENCIES', '');
1762             }
1763             $xt = '_SOURCES'
1764         }
1766         if (&variable_defined ($xname . '_LIBADD'))
1767         {
1768             &am_line_error ($xname . '_LIBADD',
1769                             "use \`" . $xname . "_LDADD', not \`"
1770                             . $xname . "_LIBADD'");
1771         }
1773         if (! &variable_defined ($xname . '_LDFLAGS'))
1774         {
1775             # Define the prog_LDFLAGS variable.
1776             &define_variable ($xname . '_LDFLAGS', '');
1777         }
1779         # Determine program to use for link.
1780         local ($xlink);
1781         if (&variable_defined ($xname . '_LINK'))
1782         {
1783             $xlink = $xname . '_LINK';
1784         }
1785         else
1786         {
1787             $xlink = $linker ? $linker : 'LINK';
1788         }
1790         local ($xexe);
1791         if ($seen_exeext && $one_file !~ /\./)
1792         {
1793             $xexe = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
1794         }
1795         else
1796         {
1797             $xexe = 's/\@EXEEXT\@//g;';
1798         }
1800         $output_rules .=
1801             &file_contents_with_transform
1802                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1803                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1804                  . 's/\@XLINK\@/' . $xlink . '/go;'
1805                  . $xexe,
1806                  'program');
1807     }
1809     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1810     {
1811         $seen_libobjs = 1;
1812     }
1814     if ($seen_libobjs)
1815     {
1816         foreach $one_file (@proglist)
1817         {
1818             # Canonicalize names.
1819             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1821             if (&variable_defined ($xname . '_LDADD'))
1822             {
1823                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1824             }
1825             elsif (&variable_defined ('LDADD'))
1826             {
1827                 &check_libobjs_sources ($xname, 'LDADD');
1828             }
1829         }
1830     }
1834 # Handle libraries.
1835 sub handle_libraries
1837     local (@liblist) = &am_install_var ('-clean',
1838                                         'libs', 'LIBRARIES',
1839                                         'lib', 'pkglib', 'noinst', 'check');
1840     return if ! @liblist;
1842     local (%valid) = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
1843                                            'noinst', 'check');
1844     if (! defined $configure_vars{'RANLIB'})
1845     {
1846         local ($key);
1847         foreach $key (keys %valid)
1848         {
1849             if (&variable_defined ($key . '_LIBRARIES'))
1850             {
1851                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1852                 # Only get this error once.  If this is ever printed,
1853                 # we have a bug.
1854                 $configure_vars{'RANLIB'} = 'BUG';
1855                 last;
1856             }
1857         }
1858     }
1860     local ($onelib);
1861     local ($munge);
1862     local ($xlib);
1863     local ($seen_libobjs) = 0;
1864     foreach $onelib (@liblist)
1865     {
1866         # Check that the library fits the standard naming convention.
1867         if ($onelib !~ /^lib.*\.a$/)
1868         {
1869             # FIXME should put line number here.  That means mapping
1870             # from library name back to variable name.
1871             &am_error ("\`$onelib' is not a standard library name");
1872         }
1874         local ($obj) = &get_object_extension ($onelib);
1876         # Canonicalize names and check for misspellings.
1877         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
1878                                            '_OBJECTS', '_DEPENDENCIES', '_AR');
1880         if (! &variable_defined ($xlib . '_AR'))
1881         {
1882             &define_variable ($xlib . '_AR', '$(AR) cru');
1883         }
1885         if (&variable_defined ($xlib . '_LIBADD'))
1886         {
1887             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1888             {
1889                 $seen_libobjs = 1;
1890             }
1891         }
1892         else
1893         {
1894             # Generate support for conditional object inclusion in
1895             # libraries.
1896             &define_variable ($xlib . "_LIBADD", '');
1897         }
1899         if (&variable_defined ($xlib . '_LDADD'))
1900         {
1901             &am_line_error ($xlib . '_LDADD',
1902                             "use \`" . $xlib . "_LIBADD', not \`"
1903                             . $xlib . "_LDADD'");
1904         }
1906         # Make sure we at look at this.
1907         &examine_variable ($xlib . '_DEPENDENCIES');
1909         &handle_source_transform ($xlib, $onelib, $obj);
1911         $output_rules .=
1912             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1913                                            . 's/\@XLIBRARY\@/'
1914                                            . $xlib . '/go;',
1915                                            'library');
1916     }
1918     if ($seen_libobjs)
1919     {
1920         foreach $onelib (@liblist)
1921         {
1922             # Canonicalize names.
1923             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1924             if (&variable_defined ($xlib . '_LIBADD'))
1925             {
1926                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1927             }
1928         }
1929     }
1931     &define_variable ('AR', 'ar');
1932     &define_configure_variable ('RANLIB');
1935 # Handle shared libraries.
1936 sub handle_ltlibraries
1938     local (@liblist) = &am_install_var ('-clean',
1939                                         'ltlib', 'LTLIBRARIES',
1940                                         'noinst', 'lib', 'pkglib', 'check');
1941     return if ! @liblist;
1943     local (%instdirs);
1944     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
1945                                            'noinst', 'check');
1947     local ($key);
1948     foreach $key (keys %valid)
1949     {
1950         if (&variable_defined ($key . '_LTLIBRARIES'))
1951         {
1952             if (!$seen_libtool)
1953             {
1954                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
1955                 # Only get this error once.  If this is ever printed,
1956                 # we have a bug.
1957                 $configure_vars{'LIBTOOL'} = 'BUG';
1958                 $seen_libtool = 1;
1959             }
1961             # Get the installation directory of each library.
1962             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
1963             {
1964                 if ($instdirs{$_})
1965                 {
1966                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1967                 }
1968                 else
1969                 {
1970                     $instdirs{$_} = $key;
1971                 }
1972             }
1973         }
1974     }
1976     local ($onelib);
1977     local ($munge);
1978     local ($xlib);
1979     local ($seen_libobjs) = 0;
1980     foreach $onelib (@liblist)
1981     {
1982         local ($obj) = &get_object_extension ($onelib);
1984         # Canonicalize names and check for misspellings.
1985         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
1986                                            '_SOURCES', '_OBJECTS',
1987                                            '_DEPENDENCIES');
1989         if (! &variable_defined ($xlib . '_LDFLAGS'))
1990         {
1991             # Define the lib_LDFLAGS variable.
1992             &define_variable ($xlib . '_LDFLAGS', '');
1993         }
1995         # Check that the library fits the standard naming convention.
1996         $libname_rx = "^lib.*\.la";
1997         if (&variable_value ($xlib . '_LDFLAGS') =~ /-module/
1998             || &variable_value ('LDFLAGS') =~ /-module/) 
1999         {
2000                 # Relax name checking for libtool modules.
2001                 $libname_rx = "\.la";
2002         }
2003         if ($onelib !~ /$libname_rx$/)
2004         {
2005             # FIXME this should only be a warning for foreign packages
2006             # FIXME should put line number here.  That means mapping
2007             # from library name back to variable name.
2008             &am_error ("\`$onelib' is not a standard libtool library name");
2009         }
2011         if (&variable_defined ($xlib . '_LIBADD'))
2012         {
2013             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
2014             {
2015                 $seen_libobjs = 1;
2016             }
2017         }
2018         else
2019         {
2020             # Generate support for conditional object inclusion in
2021             # libraries.
2022             &define_variable ($xlib . "_LIBADD", '');
2023         }
2025         if (&variable_defined ($xlib . '_LDADD'))
2026         {
2027             &am_line_error ($xlib . '_LDADD',
2028                             "use \`" . $xlib . "_LIBADD', not \`"
2029                             . $xlib . "_LDADD'");
2030         }
2032         # Make sure we at look at this.
2033         &examine_variable ($xlib . '_DEPENDENCIES');
2035         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
2037         # Determine program to use for link.
2038         local ($xlink);
2039         if (&variable_defined ($xlib . '_LINK'))
2040         {
2041             $xlink = $xlib . '_LINK';
2042         }
2043         else
2044         {
2045             $xlink = $linker ? $linker : 'LINK';
2046         }
2048         local ($rpath);
2049         if ($instdirs{$onelib} eq 'EXTRA' || $instdirs{$onelib} eq 'noinst')
2050         {
2051             # It's an EXTRA_ library, so we can't specify -rpath,
2052             # because we don't know where the library will end up.
2053             # The user probably knows, but generally speaking automake
2054             # doesn't -- and in fact configure could decide
2055             # dynamically between two different locations.
2056             $rpath = 's/\@RPATH\@//go;';
2057         }
2058         else
2059         {
2060             $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
2061                       . 'dir)/go;');
2062         }
2064         $output_rules .=
2065             &file_contents_with_transform ('s/\@LTLIBRARY\@/'
2066                                            . $onelib . '/go;'
2067                                            . 's/\@XLTLIBRARY\@/'
2068                                            . $xlib . '/go;'
2069                                            . $rpath
2070                                            . 's/\@XLINK\@/' . $xlink . '/go;',
2071                                            'ltlibrary');
2072     }
2074     if ($seen_libobjs)
2075     {
2076         foreach $onelib (@liblist)
2077         {
2078             # Canonicalize names.
2079             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
2080             if (&variable_defined ($xlib . '_LIBADD'))
2081             {
2082                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2083             }
2084         }
2085     }
2088 # See if any _SOURCES variable were misspelled.  Also, make sure that
2089 # EXTRA_ variables don't contain configure substitutions.
2090 sub check_typos
2092     local ($varname, $primary);
2093     foreach $varname (keys %contents)
2094     {
2095         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
2096                           '_DEPENDENCIES')
2097         {
2098             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
2099             {
2100                 &am_line_error ($varname,
2101                                 "invalid unused variable name: \`$varname'");
2102             }
2103         }
2104     }
2107 # Handle scripts.
2108 sub handle_scripts
2110     # NOTE we no longer automatically clean SCRIPTS, because it is
2111     # useful to sometimes distribute scripts verbatim.  This happens
2112     # eg in Automake itself.
2113     &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2114                      'bin', 'sbin', 'libexec', 'pkgdata',
2115                      'noinst', 'check');
2117     local ($scripts_installed) = 0;
2118     # Set $scripts_installed if appropriate.  Make sure we only find
2119     # scripts which are actually installed -- this is why we can't
2120     # simply use the return value of am_install_var.
2121     local (%valid) = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
2122                                            'libexec', 'pkgdata',
2123                                            'noinst', 'check');
2124     local ($key);
2125     foreach $key (keys %valid)
2126     {
2127         if ($key ne 'noinst'
2128             && $key ne 'check'
2129             && &variable_defined ($key . '_SCRIPTS'))
2130         {
2131             $scripts_installed = 1;
2132             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
2133         }
2134     }
2136     if ($scripts_installed)
2137     {
2138         # If a program is installed, this is required.  We only want this
2139         # error to appear once.
2140         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
2141             unless $seen_arg_prog;
2142         $seen_arg_prog = 1;
2143     }
2146 # Search a file for a "version.texi" Texinfo include.  Return the name
2147 # of the include file if found, or the empty string if not.  A
2148 # "version.texi" file is actually any file whose name matches
2149 # "vers*.texi".
2150 sub scan_texinfo_file
2152     local ($filename) = @_;
2154     if (! open (TEXI, $filename))
2155     {
2156         &am_error ("couldn't open \`$filename': $!");
2157         return '';
2158     }
2159     print "automake: reading $filename\n" if $verbose;
2161     local ($vfile, $outfile);
2162     while (<TEXI>)
2163     {
2164         if (/^\@setfilename +(\S+)/)
2165         {
2166             $outfile = $1;
2167             last if ($vfile);
2168         }
2170         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2171         {
2172             # Found version.texi include.
2173             $vfile = $1;
2174             last if $outfile;
2175         }
2176     }
2178     close (TEXI);
2179     return ($outfile, $vfile);
2182 # Handle all Texinfo source.
2183 sub handle_texinfo
2185     &am_line_error ('TEXINFOS',
2186                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
2187         if &variable_defined ('TEXINFOS');
2188     return if (! &variable_defined ('info_TEXINFOS')
2189                && ! &variable_defined ('html_TEXINFOS'));
2191     if (&variable_defined ('html_TEXINFOS'))
2192     {
2193         &am_line_error ('html_TEXINFOS',
2194                         "HTML generation not yet supported");
2195         return;
2196     }
2198     local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');
2200     local (@info_deps_list, @dvis_list, @texi_deps);
2201     local ($infobase, $info_cursor);
2202     local (%versions);
2203     local ($done) = 0;
2204     local ($vti);
2205     local ($tc_cursor, @texi_cleans);
2206     local ($canonical);
2208     foreach $info_cursor (@texis)
2209     {
2210         # FIXME: This is mildly hacky, since it recognizes "txinfo".
2211         # I don't feel like making it right.
2212         ($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;
2214         # If 'version.texi' is referenced by input file, then include
2215         # automatic versioning capability.
2216         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
2217                                                         . "/" . $info_cursor);
2219         if ($out_file eq '')
2220         {
2221             &am_error ("\`$info_cursor' missing \@setfilename");
2222             next;
2223         }
2225         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
2226         {
2227             # FIXME should report line number in input file.
2228             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
2229             next;
2230         }
2232         if ($vtexi)
2233         {
2234             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
2235                 if (defined $versions{$vtexi});
2236             $versions{$vtexi} = $info_cursor;
2238             # We number the stamp-vti files.  This is doable since the
2239             # actual names don't matter much.  We only number starting
2240             # with the second one, so that the common case looks nice.
2241             $vti = ($done ? $done : 'vti');
2242             &push_dist_common ($vtexi, 'stamp-' . $vti);
2243             push (@clean, $vti);
2245             # Only require once.
2246             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2247                                           'mdate-sh')
2248                 if ! $done;
2249             ++$done;
2251             local ($conf_pat, $conf_dir);
2252             if ($config_aux_dir eq '.' || $config_aux_dir eq '')
2253             {
2254                 $conf_dir = '$(srcdir)/';
2255             }
2256             else
2257             {
2258                 $conf_dir = $config_aux_dir;
2259                 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
2260             }
2261             ($conf_pat = $conf_dir) =~ s/(\W)/\\$1/g;
2262             $output_rules .=
2263                 &file_contents_with_transform
2264                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
2265                      . 's/\@VTI\@/' . $vti . '/g; '
2266                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
2267                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
2268                      'texi-vers');
2270             &push_phony_cleaners ($vti);
2271         }
2273         # If user specified file_TEXINFOS, then use that as explicit
2274         # dependency list.
2275         @texi_deps = ();
2276         push (@texi_deps, $info_cursor);
2277         push (@texi_deps, $vtexi) if $vtexi;
2279         # Canonicalize name first.
2280         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
2281         if (&variable_defined ($canonical . "_TEXINFOS"))
2282         {
2283             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
2284             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
2285         }
2287         $output_rules .= ("\n" . $out_file . ": "
2288                           . join (' ', @texi_deps)
2289                           . "\n" . $infobase . ".dvi: "
2290                           . join (' ', @texi_deps)
2291                           . "\n\n");
2293         push (@info_deps_list, $out_file);
2294         push (@dvis_list, $infobase . '.dvi');
2296         # Generate list of things to clean for this target.  We do
2297         # this explicitly because otherwise too many things could be
2298         # removed.  In particular the ".log" extension might
2299         # reasonably be used in other contexts by the user.
2300         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns', 'pgs',
2301                             'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
2302                             'vr', 'vrs', 'op', 'tr', 'cv', 'cn')
2303         {
2304             push (@texi_cleans, $infobase . '.' . $tc_cursor);
2305         }
2306     }
2308     # Find these programs wherever they may lie.  Yes, this has
2309     # intimate knowledge of the structure of the texinfo distribution.
2310     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
2311                               'makeinfo',
2312                               # Circumlocution to avoid accidental
2313                               # configure substitution.
2314                               '@MAKE' . 'INFO@');
2315     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
2316                               'texi2dvi');
2318     # Set transform for including texinfos.am.  First, handle --cygnus
2319     # stuff.
2320     local ($xform);
2321     if ($cygnus_mode)
2322     {
2323         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
2324     }
2325     else
2326     {
2327         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
2328     }
2330     # Handle location of texinfo.tex.
2331     local ($need_texi_file) = 0;
2332     local ($texinfo_tex);
2333     if ($cygnus_mode)
2334     {
2335         $texinfo_tex = '$(top_srcdir)/../texinfo/texinfo.tex';
2336         &define_variable ('TEXINFO_TEX', $texinfo_tex);
2338     }
2339     elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
2340     {
2341         $texinfo_tex = $config_aux_dir . '/texinfo.tex';
2342         &define_variable ('TEXINFO_TEX', $texinfo_tex);
2343         $need_texi_file = 2; # so that we require_conf_file later
2344     }
2345     elsif (&variable_defined ('TEXINFO_TEX'))
2346     {
2347         # The user defined TEXINFO_TEX so assume he knows what he is
2348         # doing.
2349         $texinfo_tex = ('$(srcdir)/'
2350                         . &dirname (&variable_value ('TEXINFO_TEX')));
2351     }
2352     else
2353     {
2354         $texinfo_tex = '$(srcdir)/texinfo.tex';
2355         $need_texi_file = 1;
2356     }
2357     local ($xxform);
2358     ($xxform = $texinfo_tex) =~ s/\/texinfo\.tex$//;
2359     $xxform =~ s/(\W)/\\$1/g;
2360     $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';
2362     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
2363     push (@phony, 'install-info-am', 'uninstall-info');
2364     push (@dist_targets, 'dist-info');
2366     # How to clean.  The funny name is due to --cygnus influence; in
2367     # Cygnus mode, `clean-info' is a target that users can use.
2368     $output_rules .= "\nmostlyclean-aminfo:\n";
2369     &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
2370     $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
2371                       . "maintainer-clean-aminfo:\n\t"
2372                       # Eww.  But how else can we find all the output
2373                       # files from makeinfo?
2374                       . ($cygnus_mode ? '' : 'cd $(srcdir) && ')
2375                       . 'for i in $(INFO_DEPS); do' . " \\\n"
2376                       . "\t" . '  rm -f $$i;' . " \\\n"
2377                       . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
2378                       . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
2379                       . "\t" . '  fi;' . " \\\n"
2380                       . "\tdone\n");
2381     &push_phony_cleaners ('aminfo');
2382     if ($cygnus_mode)
2383     {
2384         $output_rules .= "clean-info: mostlyclean-aminfo\n";
2385     }
2387     push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');
2389     if (! defined $options{'no-installinfo'})
2390     {
2391         push (@uninstall, 'uninstall-info');
2392         push (@installdirs, '$(DESTDIR)$(infodir)');
2393         unshift (@install_data, 'install-info-am');
2395         # Make sure documentation is made and installed first.  Use
2396         # $(INFO_DEPS), not 'info', because otherwise recursive makes
2397         # get run twice during "make all".
2398         unshift (@all, '$(INFO_DEPS)');
2399     }
2400     push (@clean, 'aminfo');
2401     push (@info, '$(INFO_DEPS)');
2402     push (@dvi, '$(DVIS)');
2404     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2405     &define_variable ("DVIS", join (' ', @dvis_list));
2406     # This next isn't strictly needed now -- the places that look here
2407     # could easily be changed to look in info_TEXINFOS.  But this is
2408     # probably better, in case noinst_TEXINFOS is ever supported.
2409     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
2411     # Do some error checking.  Note that this file is not required
2412     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2413     # up above.
2414     if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
2415     {
2416         if ($need_texi_file > 1)
2417         {
2418             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2419                                           'texinfo.tex');
2420         }
2421         else
2422         {
2423             &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
2424         }
2425     }
2428 # Handle any man pages.
2429 sub handle_man_pages
2431     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
2432         if &variable_defined ('MANS');
2433     return if ! &variable_defined ('man_MANS');
2435     # Find all the sections in use.  We do this by first looking for
2436     # "standard" sections, and then looking for any additional
2437     # sections used in man_MANS.
2438     local ($sect, %sections, %vlist);
2439     # Add more sections as needed.
2440     foreach $sect ('0'..'9', 'n', 'l')
2441     {
2442         if (&variable_defined ('man' . $sect . '_MANS'))
2443         {
2444             $sections{$sect} = 1;
2445             $vlist{'$(man' . $sect . '_MANS)'} = 1;
2446         }
2447     }
2449     if (&variable_defined ('man_MANS'))
2450     {
2451         $vlist{'$(man_MANS)'} = 1;
2452         foreach (&variable_value_as_list ('man_MANS', 'all'))
2453         {
2454             # A page like `foo.1c' goes into man1dir.
2455             if (/\.([0-9a-z])([a-z]*)$/)
2456             {
2457                 $sections{$1} = 1;
2458             }
2459         }
2460     }
2463     # Now for each section, generate an install and unintall rule.
2464     # Sort sections so output is deterministic.
2465     local (@namelist);
2466     foreach $sect (sort keys %sections)
2467     {
2468         &define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
2469         push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
2470             unless defined $options{'no-installman'};
2471         $output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
2472                                                         . $sect . '/g;',
2473                                                         'mans');
2474         push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
2475         push (@namelist, 'install-man' . $sect);
2476     }
2478     # We don't really need this, but we use it in case we ever want to
2479     # support noinst_MANS.
2480     &define_variable ("MANS", join (' ', sort keys %vlist));
2482     # Generate list of install dirs.
2483     $output_rules .= ("install-man: \$(MANS)\n"
2484                       . "\t\@\$(NORMAL_INSTALL)\n");
2485     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2486     push (@phony, 'install-man');
2488     $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
2489     grep ($_ = 'un' . $_, @namelist);
2490     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2491     push (@phony, 'uninstall-man');
2493     $output_vars .= &file_contents ('mans-vars');
2495     if (! defined $options{'no-installman'})
2496     {
2497         push (@install_data, 'install-man');
2498         push (@uninstall, 'uninstall-man');
2499         push (@all, '$(MANS)');
2500     }
2503 # Handle DATA variables.
2504 sub handle_data
2506     &am_install_var ('-noextra', '-defaultdist', 'data', 'DATA',
2507                      'data', 'sysconf', 'sharedstate', 'localstate',
2508                      'pkgdata', 'noinst', 'check');
2511 # Handle TAGS.
2512 sub handle_tags
2514     push (@phony, 'tags');
2515     local (@tag_deps) = ();
2516     if (&variable_defined ('SUBDIRS'))
2517     {
2518         $output_rules .= ("tags-recursive:\n"
2519                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
2520                           # Never fail here if a subdir fails; it
2521                           # isn't important.
2522                           . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
2523                           . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
2524                           . "\tdone\n");
2525         push (@tag_deps, 'tags-recursive');
2526         push (@phony, 'tags-recursive');
2527     }
2529     if (&saw_sources_p (1)
2530         || &variable_defined ('ETAGS_ARGS')
2531         || @tag_deps)
2532     {
2533         local ($xform) = '';
2534         local ($one_hdr);
2535         foreach $one_hdr (@config_headers)
2536         {
2537             if ($relative_dir eq &dirname ($one_hdr))
2538             {
2539                 # The config header is in this directory.  So require it.
2540                 local ($var);
2541                 ($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
2542                 $xform .= ' ' if $xform;
2543                 $xform .= $var;
2544             }
2545         }
2546         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
2547                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
2549         if (&variable_defined ('SUBDIRS'))
2550         {
2551             $xform .= 's/^SUBDIRS//;';
2552         }
2553         else
2554         {
2555             $xform .= 's/^SUBDIRS.*$//;';
2556         }
2558         $output_rules .= &file_contents_with_transform ($xform, 'tags');
2559         $output_rules .= &file_contents ('tags-clean');
2560         push (@clean, 'tags');
2561         &push_phony_cleaners ('tags');
2562         &examine_variable ('TAGS_DEPENDENCIES');
2563     }
2564     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2565     {
2566         &am_line_error ('TAGS_DEPENDENCIES',
2567                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2568     }
2569     else
2570     {
2571         # Every Makefile must define some sort of TAGS rule.
2572         # Otherwise, it would be possible for a top-level "make TAGS"
2573         # to fail because some subdirectory failed.
2574         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2575     }
2578 # Handle multilib support.
2579 sub handle_multilib
2581     return unless $seen_multilib;
2583     $output_rules .= &file_contents ('multilib.am');
2584     &push_phony_cleaners ('multi');
2585     push (@phony, 'all-multi', 'install-multi');
2588 # Worker for handle_dist.
2589 sub handle_dist_worker
2591     local ($makefile) = @_;
2593     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
2595     # Initialization; only at top level.
2596     if ($relative_dir eq '.')
2597     {
2598         if (defined $options{'check-news'})
2599         {
2600             # For Gnits users, this is pretty handy.  Look at 15 lines
2601             # in case some explanatory text is desirable.
2602             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
2603           echo "NEWS not updated; not releasing" 1>&2; \\
2604           exit 1; \\
2605         fi
2607         }
2610         # Create dist directory.
2611         $output_rules .= ("\t-rm -rf \$(distdir)\n"
2612                           . "\tmkdir \$(distdir)\n");
2613     }
2615     # Only run automake in `dist' target if --include-deps and
2616     # `no-dependencies' not specified.  That way the recipient of a
2617     # distribution can run "make dist" and not need Automake.  You
2618     # might be wondering why we run automake once for each directory
2619     # we distribute, instead of running it once at the top level.  The
2620     # answer is that we want to run automake after the dependencies
2621     # have been generated.  This occurs when "make" is run in the
2622     # subdir.  So automake must be run after make has updated the
2623     # Makefile, which means that it must run once per directory.
2624     if ($use_dependencies)
2625     {
2626         $output_rules .=
2627             (
2628              # There are several directories we need to know about
2629              # when rebuilding the Makefile.ins.  They are:
2630              #   here - The absolute path to our topmost build directory.
2631              #   top_distdir - The absolute path to the top of our dist
2632              #                 hierarchy.
2633              #   distdir - The path to our sub-part of the dist hierarchy.
2634              # If this directory is the topmost directory, we set
2635              # top_distdir from distdir; that lets us pass in distdir
2636              # from an enclosing package.
2637              "\t" . 'here=`cd $(top_builddir) && pwd`; ' . "\\\n"
2638              . "\t" . 'top_distdir=`cd $('
2639              . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
2640              . ') && pwd`; ' . "\\\n"
2641              . "\t" . 'distdir=`cd $(distdir) && pwd`; ' . "\\\n"
2642              . "\tcd \$(top_srcdir) \\\n"
2643              . "\t  && \$(AUTOMAKE) --include-deps --build-dir=\$\$here --srcdir-name=\$(top_srcdir) --output-dir=\$\$top_distdir "
2644              # Set strictness of output.
2645              . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2646              . ($cmdline_use_dependencies ? '' : ' --include-deps')
2647              . " " . $makefile . "\n"
2648              );
2649     }
2651     # Scan EXTRA_DIST to see if we need to distribute anything from a
2652     # subdir.  If so, add it to the list.  I didn't want to do this
2653     # originally, but there were so many requests that I finally
2654     # relented.
2655     local (@dist_dirs);
2656     if (&variable_defined ('EXTRA_DIST'))
2657     {
2658         # FIXME: This should be fixed to work with conditionals.  That
2659         # will require only making the entries in @dist_dirs under the
2660         # appropriate condition.  This is meaningful if the nature of
2661         # the distribution should depend upon the configure options
2662         # used.
2663         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
2664         {
2665             next if /^\@.*\@$/;
2666             next unless s,/+[^/]+$,,;
2667             push (@dist_dirs, $_)
2668                 unless $_ eq '.';
2669         }
2670     }
2671     if (@dist_dirs)
2672     {
2673         # Prepend $(distdir) to each directory given.  Doing it via a
2674         # hash lets us ensure that each directory is used only once.
2675         local (%dhash);
2676         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
2677         $output_rules .= "\t";
2678         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
2679     }
2681     # In loop, test for file existence because sometimes a file gets
2682     # included in DISTFILES twice.  For example this happens when a
2683     # single source file is used in building more than one program.
2684     # Also, there are situations in which "ln" can fail.  For instance
2685     # a file to distribute could actually be a cross-filesystem
2686     # symlink -- this can easily happen if "gettextize" was run on the
2687     # distribution.
2688     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
2689     if ($cygnus_mode)
2690     {
2691         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
2692     }
2693     else
2694     {
2695         $output_rules .= "\t  d=\$(srcdir); \\\n";
2696     }
2697     $output_rules .= ("\t  if test -d \$\$d/\$\$file; then \\\n"
2698                       . "\t    cp -pr \$\$d/\$\$file \$(distdir)/\$\$file; \\\n"
2699                       . "\t  else \\\n"
2700                       . "\t    test -f \$(distdir)/\$\$file \\\n"
2701                       . "\t    || ln \$\$d/\$\$file \$(distdir)/\$\$file 2> /dev/null \\\n"
2702                       . "\t    || cp -p \$\$d/\$\$file \$(distdir)/\$\$file || :; \\\n"
2703                       . "\t  fi; \\\n"
2704                       . "\tdone\n");
2706     # If we have SUBDIRS, create all dist subdirectories and do
2707     # recursive build.
2708     if (&variable_defined ('SUBDIRS'))
2709     {
2710         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
2711         # to all possible directories, and use it.  If DIST_SUBDIRS is
2712         # defined, just use it.
2713         local ($dist_subdir_name);
2714         if (&variable_conditions ('SUBDIRS')
2715             || &variable_defined ('DIST_SUBDIRS'))
2716         {
2717             $dist_subdir_name = 'DIST_SUBDIRS';
2718             if (! &variable_defined ('DIST_SUBDIRS'))
2719             {
2720                 local (@full_list) = &variable_value_as_list ('SUBDIRS',
2721                                                               'all');
2722                 local (@ds_list, %uniq, $iter);
2723                 foreach $iter (@full_list)
2724                 {
2725                     if (! defined $uniq{$iter})
2726                     {
2727                         $uniq{$iter} = 1;
2728                         push (@ds_list, $iter);
2729                     }
2730                 }
2731                 &define_pretty_variable ('DIST_SUBDIRS', '', @ds_list);
2732             }
2733         }
2734         else
2735         {
2736             $dist_subdir_name = 'SUBDIRS';
2737         }
2739         # Test for directory existence here because previous automake
2740         # invocation might have created some directories.  Note that
2741         # we explicitly set distdir for the subdir make; that lets us
2742         # mix-n-match many automake-using packages into one large
2743         # package, and have "dist" at the top level do the right
2744         # thing.  If we're in the topmost directory, then we use
2745         # `distdir' instead of `top_distdir'; this lets us work
2746         # correctly with an enclosing package.
2747         $output_rules .= 
2748             ("\t" . 'for subdir in $(' . $dist_subdir_name . '); do ' . "\\\n"
2749              . "\t" . '  if test "$$subdir" = .; then :; else ' . "\\\n"
2750              . "\t" . '    test -d $(distdir)/$$subdir ' . "\\\n"
2751              . "\t" . '    || mkdir $(distdir)/$$subdir ' . "\\\n"
2752              . "\t" . '    || exit 1; ' . "\\\n"
2753              . "\t" . '    (cd $$subdir'
2754              . ' && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$('
2755              . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
2756              . ') distdir=../$(distdir)/$$subdir distdir) ' . "\\\n"
2757              . "\t" . '      || exit 1; ' . "\\\n"
2758              . "\t" . '  fi; ' . "\\\n"
2759              . "\tdone\n");
2760     }
2762     # If the target `dist-hook' exists, make sure it is run.  This
2763     # allows users to do random weird things to the distribution
2764     # before it is packaged up.
2765     push (@dist_targets, 'dist-hook') if &target_defined ('dist-hook');
2767     local ($targ);
2768     foreach $targ (@dist_targets)
2769     {
2770         # We must explicitly set distdir and top_distdir for these
2771         # sub-makes.
2772         $output_rules .= ("\t\$(MAKE) \$(AM_MAKEFLAGS)"
2773                           . " top_distdir=\"\$(top_distdir)\""
2774                           . " distdir=\"\$(distdir)\" $targ\n");
2775     }
2777     push (@phony, 'distdir');
2780 # Handle 'dist' target.
2781 sub handle_dist
2783     local ($makefile) = @_;
2785     # Set up maint_charset.
2786     $local_maint_charset = &variable_value ('MAINT_CHARSET')
2787         if &variable_defined ('MAINT_CHARSET');
2788     $maint_charset = $local_maint_charset
2789         if $relative_dir eq '.';
2791     if (&variable_defined ('DIST_CHARSET'))
2792     {
2793         &am_line_error ('DIST_CHARSET',
2794                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2795             if ! $local_maint_charset;
2796         if ($relative_dir eq '.')
2797         {
2798             $dist_charset = &variable_value ('DIST_CHARSET')
2799         }
2800         else
2801         {
2802             &am_line_error ('DIST_CHARSET',
2803                             "DIST_CHARSET can only be defined at top level");
2804         }
2805     }
2807     # Look for common files that should be included in distribution.
2808     local ($cfile);
2809     foreach $cfile (@common_files)
2810     {
2811         if (-f ($relative_dir . "/" . $cfile))
2812         {
2813             &push_dist_common ($cfile);
2814         }
2815     }
2817     # Always require configure.in and configure at top level, even if
2818     # they don't exist.  This is especially important for configure,
2819     # since it won't be created until autoconf is run -- which might
2820     # be after automake is run.
2821     &push_dist_common ('configure.in', 'configure')
2822         if $relative_dir eq '.';
2824     # Keys of %dist_common are names of files to distributed.  We put
2825     # README first because it then becomes easier to make a
2826     # Usenet-compliant shar file (in these, README must be first).
2827     # FIXME: do more ordering of files here.
2828     local (@coms);
2829     if (defined $dist_common{'README'})
2830     {
2831         push (@coms, 'README');
2832         delete $dist_common{'README'};
2833     }
2834     push (@coms, sort keys %dist_common);
2836     &define_pretty_variable ("DIST_COMMON", '', @coms);
2837     $output_vars .= "\n";
2839     # Some boilerplate.
2840     $output_vars .= &file_contents ('dist-vars') . "\n";
2841     &define_variable ('GZIP_ENV', '--best');
2843     # Put these things in rules section so it is easier for whoever
2844     # reads Makefile.in.
2845     if (! &variable_defined ('distdir'))
2846     {
2847         if ($relative_dir eq '.')
2848         {
2849             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2850         }
2851         else
2852         {
2853             $output_rules .= ("\n"
2854                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2855                               . "\n");
2856         }
2857     }
2858     if ($relative_dir eq '.')
2859     {
2860         $output_rules .= "top_distdir = \$(distdir)\n";
2861     }
2862     $output_rules .= "\n";
2864     # Generate 'dist' target, and maybe other dist targets.
2865     if ($relative_dir eq '.')
2866     {
2867         # Rule to check whether a distribution is viable.
2868         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
2869 # it guarantees that the distribution is self-contained by making another
2870 # tarfile.
2871 distcheck: dist
2872         -rm -rf $(distdir)
2873         GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(AMTAR) xf -
2874         mkdir $(distdir)/=build
2875         mkdir $(distdir)/=inst
2876         dc_install_base=`cd $(distdir)/=inst && pwd` \\'
2877                           . (&target_defined ('distcheck-hook')
2878                              ? ("\n\t  && \$(MAKE) \$(AM_MAKEFLAGS)"
2879                                 . " distcheck-hook \\")
2880                              : '')
2881                           . '
2882           && cd $(distdir)/=build \\
2883           && ../configure '
2885                           . ($seen_gettext ? '--with-included-gettext ' : '')
2886                           . '--srcdir=.. --prefix=$$dc_install_base \\
2887           && $(MAKE) $(AM_MAKEFLAGS) \\
2888           && $(MAKE) $(AM_MAKEFLAGS) dvi \\
2889           && $(MAKE) $(AM_MAKEFLAGS) check \\
2890           && $(MAKE) $(AM_MAKEFLAGS) install \\
2891           && $(MAKE) $(AM_MAKEFLAGS) installcheck \\
2892           && $(MAKE) $(AM_MAKEFLAGS) dist
2893         -rm -rf $(distdir)
2894         @banner="$(distdir).tar.gz is ready for distribution"; \\
2895         dashes=`echo "$$banner" | sed s/./=/g`; \\
2896         echo "$$dashes"; \\
2897         echo "$$banner"; \\
2898         echo "$$dashes"
2901         local ($dist_all) = ('dist-all: distdir' . "\n"
2902                              . $dist_header);
2903         local ($curs);
2904         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ',
2905                        'dist-bzip2')
2906         {
2907             if (defined $options{$curs} || $curs eq 'dist')
2908             {
2909                 $output_rules .= ($curs . ': distdir' . "\n"
2910                                   . $dist_header
2911                                   . $dist{$curs}
2912                                   . $dist_trailer);
2913                 $dist_all .= $dist{$curs};
2914             }
2915         }
2916         $output_rules .= $dist_all . $dist_trailer;
2917     }
2919     # Generate distdir target.
2920     &handle_dist_worker ($makefile);
2923 # Scan a single dependency file and rewrite the dependencies as
2924 # appropriate.  Essentially this means:
2925 # * Clean out absolute dependencies which are not desirable.
2926 # * Rewrite other dependencies to be relative to $(top_srcdir).
2927 sub scan_dependency_file
2929     local ($depfile) = @_;
2931     if (! open (DEP_FILE, $depfile))
2932     {
2933         &am_error ("couldn't open \`$depfile': $!");
2934         return;
2935     }
2936     print "automake: reading $depfile\n" if $verbose;
2938     # Sometimes it is necessary to omit some dependencies.
2939     local (%omit) = %omit_dependencies;
2940     if (&variable_defined ('OMIT_DEPENDENCIES'))
2941     {
2942         # FIXME: Doesn't work with conditionals.  I'm not sure if this
2943         # matters.
2944         grep ($omit{$_} = 1,
2945               &variable_value_as_list ('OMIT_DEPENDENCIES', ''));
2946     }
2948     local ($first_line) = 1;
2949     local ($last_line) = 0;
2950     local ($target, @dependencies);
2951     local ($one_dep, $xform);
2952     local ($just_file);
2954     local ($srcdir_rx, $fixup_rx);
2955     ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
2956         =~ s/(\W)/\\$1/g;
2957     ($srcdir_rx = $srcdir_name . '/') =~ s/(\W)/\\$1/g;
2959     local ($rewrite_builddir) = (($top_builddir eq '.')
2960                                  ? ''
2961                                  : $top_builddir . '/');
2963     while (<DEP_FILE>)
2964     {
2965         last if $last_line;
2966         next if (/$WHITE_PATTERN/o);
2967         chop;
2968         if (! s/\\$//)
2969         {
2970             # No trailing "\" means this should be the last line of
2971             # the first target.  We can have multiple targets due to
2972             # the "deleted header file" fix.  For the generated
2973             # Makefile we simply skip these fake targets.
2974             $last_line = 1;
2975         }
2977         if ($first_line)
2978         {
2979             if (! /^([^:]+:)(.+)$/)
2980             {
2981               bad_format:
2982                 &am_error ("\`$depfile' has incorrect format");
2983                 close (DEP_FILE);
2984                 return;
2985             }
2987             $_ = $2;
2988             # Make sure to strip the .P file from the target.
2989             ($target = $1) =~ s, *\.deps/[^.]+\.P,,;
2991             $first_line = 0;
2992         }
2994         foreach $one_dep (split (' ', $_))
2995         {
2996             ($just_file = $one_dep) =~ s,^.*/,,;
2997             next if defined $omit{$just_file};
2999             if ($one_dep =~ /^$fixup_rx/)
3000             {
3001                 # The dependency points to the current directory in
3002                 # some way.
3003                 ($xform = $one_dep) =~ s/^$fixup_rx//;
3004                 push (@dependencies, $xform);
3005             }
3006             elsif ($one_dep =~ /^$srcdir_rx/)
3007             {
3008                 # The dependency is in some other directory in the package.
3009                 ($xform = $one_dep) =~ s/^$srcdir_rx/$rewrite_builddir/;
3010                 push (@dependencies, $xform);
3011             }
3012             elsif ($one_dep =~ /^\// || $one_dep =~ /^[A-Za-z]:\\/)
3013             {
3014                 # Absolute path; ignore.
3015             }
3016             else
3017             {
3018                 # Anything else is assumed to be correct.
3019                 push (@dependencies, $one_dep);
3020             }
3021         }
3022     }
3024     &pretty_print_rule ($target, "\t", @dependencies);
3026     close (DEP_FILE);
3029 # A subroutine of handle_dependencies.  This function includes
3030 # `depend2' with appropriate transformations.
3031 sub add_depend2
3033     local ($lang) = @_;
3035     # First include code for ordinary objects.
3036     local ($key) = $lang . '-autodep';
3037     local ($xform, $ext);
3038     $xform = ('s/\@COMPILE\@/\$(' . $language_map{$key} . 'COMPILE)/g;'
3039               . 's/\@LTCOMPILE\@/\$(LT' . $language_map{$key} . 'COMPILE)/g;'
3040               . 's/\@OBJ\@/%.o/g;'
3041               . 's/\@LTOBJ\@/%.lo/g;');
3042     foreach $ext (&lang_extensions ($lang))
3043     {
3044         $output_rules .= &file_contents_with_transform ('s/\@SOURCE\@/%'
3045                                                         . $ext . '/g;'
3046                                                         . $xform,
3047                                                         'depend2');
3048     }
3050     # Now include code for each specially handled object with this
3051     # language.
3052     local (@list) = grep ($_ ne '', split (' ', $lang_specific_files{$lang}));
3053     local ($max) = scalar @list;
3054     local ($i) = 0;
3055     local ($derived, $source, $obj);
3056     while ($i < $max)
3057     {
3058         $derived = $list[$i];
3059         ($source = $list[$i + 1]) =~ s,([/\$]),\\$1,g;
3060         ($obj = $list[$i + 2]) =~ s,([/\$]),\\$1,g;
3061         $i += 3;
3063         local ($flag) = $language_map{$lang . '-flags'};
3064         local ($val) = "(${derived}_${flag}";
3065         ($rule = $language_map{$lang . '-compile'}) =~    
3066             s/\(AM_$flag/$val/;
3068         $rule =~ s,([/\$]),\\$1,g;
3070         $xform = ('s/\@COMPILE\@/' . $rule . '/g;'
3071                   . 's/\@LTCOMPILE\@/\$(LIBTOOL) --mode=compile ' . $rule
3072                   . '/g;'
3073                   . 's/\@OBJ\@/' . $obj . '.o/g;'
3074                   . 's/\@LTOBJ\@/' . $obj . '.lo/g;'
3075                   . 's/\@SOURCE\@/' . $source . '/g;');
3076         $output_rules .= &file_contents_with_transform ($xform, 'depend2');
3077     }
3080 # Handle auto-dependency code.
3081 sub handle_dependencies
3083     # Make sure this variable is always marked as used.
3084     &examine_variable ('OMIT_DEPENDENCIES');
3086     if ($use_dependencies)
3087     {
3088         # Include GNU-make-specific auto-dep code.  Don't include it
3089         # if DEP_FILES would be empty.
3090         if (&saw_sources_p (0) && keys %dep_files)
3091         {
3092             &define_pretty_variable ('DEP_FILES', '', sort keys %dep_files);
3093             $output_rules .= &file_contents ('depend');
3094             push (@clean, 'depend');
3095             &push_phony_cleaners ('depend');
3097             local ($key, $lang, $ext, $xform);
3098             foreach $key (sort keys %language_map)
3099             {
3100                 if ($key =~ /^(.*)-autodep$/
3101                     && $language_map{$key} ne 'no')
3102                 {
3103                     &add_depend2 ($1);
3104                 }
3105             }
3106         }
3107     }
3108     elsif ($build_directory ne '')
3109     {
3110         # Include any auto-generated deps that are present.  Note that
3111         # $build_directory ends in a "/".
3112         if (-d ($build_directory . $relative_dir . "/.deps"))
3113         {
3114             local ($depfile);
3116             foreach $depfile (&my_glob ($build_directory
3117                                         . $relative_dir . "/.deps/*.P"))
3118             {
3119                 &scan_dependency_file ($depfile);
3120             }
3122             $output_rules .= "\n";
3123         }
3124     }
3127 # Handle subdirectories.
3128 sub handle_subdirs
3130     return if ! &variable_defined ('SUBDIRS');
3132     # Make sure each directory mentioned in SUBDIRS actually exists.
3133     local ($dir);
3134     foreach $dir (&variable_value_as_list ('SUBDIRS', 'all'))
3135     {
3136         # Skip directories substituted by configure.
3137         next if $dir =~ /^\@.*\@$/;
3139         if (! -d $am_relative_dir . '/' . $dir)
3140         {
3141             &am_line_error ('SUBDIRS',
3142                             "required directory $am_relative_dir/$dir does not exist");
3143             next;
3144         }
3146         &am_line_error ('SUBDIRS', "directory should not contain \`/'")
3147             if $dir =~ /\//;
3148     }
3150     local ($xform) = ('s/\@INSTALLINFO\@/' .
3151                       (defined $options{'no-installinfo'}
3152                        ? 'install-info-recursive'
3153                        : '')
3154                       . '/;');
3155     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
3157     # Push a bunch of phony targets.
3158     local ($phonies);
3159     foreach $phonies ('', '-data', '-exec', 'dirs')
3160     {
3161         push (@phony, 'install' . $phonies . '-recursive');
3162         push (@phony, 'uninstall' . $phonies . '-recursive');
3163     }
3164     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
3165     {
3166         push (@phony, $phonies . '-recursive');
3167     }
3168     &push_phony_cleaners ('recursive');
3170     $recursive_install = 1;
3173 # Handle aclocal.m4.
3174 sub handle_aclocal_m4
3176     local ($regen_aclocal) = 0;
3177     if (-f 'aclocal.m4')
3178     {
3179         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3180         &push_dist_common ('aclocal.m4');
3182         if (open (ACLOCAL, '< aclocal.m4'))
3183         {
3184             local ($line);
3185             $line = <ACLOCAL>;
3186             close (ACLOCAL);
3188             if ($line =~ 'generated automatically by aclocal')
3189             {
3190                 $regen_aclocal = 1;
3191             }
3192         }
3193     }
3195     local ($acinclude) = 0;
3196     if (-f 'acinclude.m4')
3197     {
3198         $regen_aclocal = 1;
3199         $acinclude = 1;
3200     }
3202     # Note that it might be possible that aclocal.m4 doesn't exist but
3203     # should be auto-generated.  This case probably isn't very
3204     # important.
3205     if ($regen_aclocal)
3206     {
3207         local (@ac_deps) = (
3208                             ($seen_maint_mode
3209                              ? "\@MAINTAINER_MODE_TRUE\@"
3210                              : "") ,
3211                             "configure.in",
3212                             ($acinclude ? ' acinclude.m4' : '')
3213                             );
3215         # Scan all -I directories for m4 files.  These are our
3216         # dependencies.
3217         if (&variable_defined ('ACLOCAL_AMFLAGS'))
3218         {
3219             local ($examine_next, $amdir) = 0;
3220             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
3221             {
3222                 if ($examine_next)
3223                 {
3224                     $examine_next = 0;
3225                     if ($amdir !~ /^\// && -d $amdir)
3226                     {
3227                         push (@ac_deps, &my_glob ($amdir . '/*.m4'));
3228                     }
3229                 }
3230                 elsif ($amdir eq '-I')
3231                 {
3232                     $examine_next = 1;
3233                 }
3234             }
3235         }
3237         &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
3239         $output_rules .=  ("\t"
3240                            . 'cd $(srcdir) && $(ACLOCAL)'
3241                            . (&variable_defined ('ACLOCAL_AMFLAGS')
3242                               ? ' $(ACLOCAL_AMFLAGS)' : '')
3243                            . "\n");
3244     }
3247 # Rewrite a list of input files into a form suitable to put on a
3248 # dependency list.  The idea is that if an input file has a directory
3249 # part the same as the current directory, then the directory part is
3250 # simply removed.  But if the directory part is different, then
3251 # $(top_srcdir) is prepended.  Among other things, this is used to
3252 # generate the dependency list for the output files generated by
3253 # AC_OUTPUT.  Consider what the dependencies should look like in this
3254 # case:
3255 #   AC_OUTPUT(src/out:src/in1:lib/in2)
3256 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3257 # If 0 then files that require this addition will simply be ignored.
3258 sub rewrite_inputs_into_dependencies
3260     local ($add_srcdir, @inputs) = @_;
3261     local ($single, @newinputs);
3263     foreach $single (@inputs)
3264     {
3265         if (&dirname ($single) eq $relative_dir)
3266         {
3267             push (@newinputs, &basename ($single));
3268         }
3269         elsif ($add_srcdir)
3270         {
3271             push (@newinputs, '$(top_srcdir)/' . $single);
3272         }
3273     }
3275     return @newinputs;
3278 # Handle remaking and configure stuff.
3279 # We need the name of the input file, to do proper remaking rules.
3280 sub handle_configure
3282     local ($local, $input, @secondary_inputs) = @_;
3284     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
3285     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
3286         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
3288     local ($top_reldir);
3290     local ($input_base) = &basename ($input);
3291     local ($local_base) = &basename ($local);
3293     local ($amfile) = $input_base . '.am';
3294     # We know we can always add '.in' because it really should be an
3295     # error if the .in was missing originally.
3296     local ($infile) = '$(srcdir)/' . $input_base . '.in';
3297     local ($colon_infile);
3298     if ($local ne $input || @secondary_inputs)
3299     {
3300         $colon_infile = ':' . $input . '.in';
3301     }
3302     $colon_infile .= ':' . join (':', @secondary_inputs)
3303         if @secondary_inputs;
3305     local (@rewritten) = &rewrite_inputs_into_dependencies (1,
3306                                                             @secondary_inputs);
3308     # This rule remakes the Makefile.in.  Note use of
3309     # @MAINTAINER_MODE_TRUE@ forces us to abandon pretty-printing.
3310     # Sigh.
3311     $output_rules .= ($infile
3312                       # NOTE perl 5.003 (with -w) gives a
3313                       # uninitialized value error on the next line.
3314                       # Don't know why.
3315                       . ': '
3316                       . ($seen_maint_mode ? "\@MAINTAINER_MODE_TRUE\@ " : '')
3317                       . $amfile . ' '
3318                       . '$(top_srcdir)/configure.in $(ACLOCAL_M4)'
3319                       . ' ' . join (' ', @include_stack)
3320                       . "\n"
3321                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
3322                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
3323                       . ($cmdline_use_dependencies ? '' : ' --include-deps')
3324                       . ' ' . $input . $colon_infile . "\n\n");
3326     # This rule remakes the Makefile.
3327     $output_rules .= ($local_base
3328                       # NOTE: bogus uninit value error on next line;
3329                       # see comment above.
3330                       . ': '
3331                       . $infile . ' '
3332                       . join (' ', @rewritten)
3333                       . ' $(top_builddir)/config.status'
3334                       # NOTE: Makefile only depends on BUILT_SOURCES
3335                       # when dependencies are being computed.  This is
3336                       # a workaround for an obscure bug with
3337                       # AC_LINK_FILES.  Anyway, when dependencies are
3338                       # turned off, this shouldn't matter.
3339                       . ($use_dependencies ? ' $(BUILT_SOURCES)' : '')
3340                       . "\n"
3341                       . "\tcd \$(top_builddir) \\\n"
3342                       . "\t  && CONFIG_FILES="
3343                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3344                       . $colon_infile
3345                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
3346                       . "\n\n");
3348     if ($relative_dir ne '.')
3349     {
3350         # In subdirectory.
3351         $top_reldir = '../';
3352     }
3353     else
3354     {
3355         &handle_aclocal_m4;
3356         $output_rules .= &file_contents ('remake');
3357         &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3358         &examine_variable ('CONFIGURE_DEPENDENCIES');
3359         $top_reldir = '';
3361         &push_dist_common ('acconfig.h')
3362             if -f 'acconfig.h';
3363     }
3365     # Make it easy to see if there is a Makefile.am in a given
3366     # directory.
3367     local (%make_dirs, $iter);
3368     foreach $iter (@configure_input_files)
3369     {
3370         $make_dirs{&dirname ($iter)} = 1;
3371     }
3372     # We also want to notice Makefile.in's.
3373     foreach $iter (@other_input_files)
3374     {
3375         if ($iter =~ /Makefile\.in$/)
3376         {
3377             $make_dirs{&dirname ($iter)} = 1;
3378         }
3379     }
3381     # If we have a configure header, require it.
3382     local ($one_hdr);
3383     local (@local_fullnames) = @config_fullnames;
3384     local (@local_names) = @config_names;
3385     local ($hdr_index) = 0;
3386     local ($distclean_config) = '';
3387     foreach $one_hdr (@config_headers)
3388     {
3389         local ($one_fullname) = shift (@local_fullnames);
3390         local ($one_name) = shift (@local_names);
3391         $hdr_index += 1;
3392         local ($header_dir) = &dirname ($one_name);
3394         # If the header is in the current directory we want to build
3395         # the header here.  Otherwise, if we're at the topmost
3396         # directory and the header's directory doesn't have a
3397         # Makefile, then we also want to build the header.
3398         if ($relative_dir eq $header_dir
3399             || ($relative_dir eq '.' && ! defined $make_dirs{$header_dir}))
3400         {
3401             local ($ch_sans_dir, $cn_sans_dir, $stamp_dir);
3402             if ($relative_dir eq $header_dir)
3403             {
3404                 $cn_sans_dir = &basename ($one_name);
3405                 $stamp_dir = '';
3406             }
3407             else
3408             {
3409                 $cn_sans_dir = $one_name;
3410                 if ($header_dir eq '.')
3411                 {
3412                     $stamp_dir = '';
3413                 }
3414                 else
3415                 {
3416                     $stamp_dir = $header_dir . '/';
3417                 }
3418             }
3420             # Compute relative path from directory holding output
3421             # header to directory holding input header.  FIXME:
3422             # doesn't handle case where we have multiple inputs.
3423             if (&dirname ($one_hdr) eq $relative_dir)
3424             {
3425                 $ch_sans_dir = &basename ($one_hdr);
3426             }
3427             else
3428             {
3429                 local (@rel_out_path);
3430                 # FIXME this chunk of code should be its own sub.
3431                 # It is used elsewhere.
3432                 foreach (split (/\//, $relative_dir))
3433                 {
3434                     next if $_ eq '' || $_ eq '.';
3435                     if ($_ eq '..')
3436                     {
3437                         # FIXME: actually this is an error.
3438                         pop @rel_out_path;
3439                     }
3440                     else
3441                     {
3442                         push (@rel_out_path, '..');
3443                     }
3444                 }
3445                 if (@rel_out_path)
3446                 {
3447                     $ch_sans_dir = join ('/', @rel_out_path) . '/' . $one_hdr;
3448                 }
3449                 else
3450                 {
3451                     $ch_sans_dir = $one_hdr;
3452                 }
3453             }
3455             &require_file_with_conf_line ($config_header_line,
3456                                           $FOREIGN, $ch_sans_dir);
3458             # Header defined and in this directory.
3459             local (@files);
3460             if (-f $one_name . '.top')
3461             {
3462                 push (@files, "${cn_sans_dir}.top");
3463             }
3464             if (-f $one_name . '.bot')
3465             {
3466                 push (@files, "${cn_sans_dir}.bot");
3467             }
3469             &push_dist_common (@files);
3471             # For now, acconfig.h can only appear in the top srcdir.
3472             if (-f 'acconfig.h')
3473             {
3474                 if ($relative_dir eq '.')
3475                 {
3476                     push (@files, 'acconfig.h');
3477                 }
3478                 else
3479                 {
3480                     # Strange quoting because this gets fed through
3481                     # Perl.
3482                     push (@files, '\$(top_srcdir)/acconfig.h');
3483                 }
3484             }
3486             local ($stamp_name) = 'stamp-h';
3487             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3489             local ($xform) = '';
3491             $xform = 's,\@FILES\@,' . join (' ', @files) . ',;';
3492             $xform .= 's,\@CONFIG_HEADER\@,' . "${cn_sans_dir}" . ',;';
3493             $xform .= 's,\@CONFIG_HEADER_IN\@,' . "${ch_sans_dir}" . ',;';
3494             $xform .= 's,\@CONFIG_HEADER_FULL\@,' . "${one_fullname}" . ',;';
3495             $xform .= 's,\@STAMP\@,' . "${stamp_dir}${stamp_name}" . ',g;';
3497             local ($out_dir) = &dirname ($ch_sans_dir);
3498             $xform .= 's,\@SRC_STAMP\@,' . "${out_dir}/${stamp_name}" . ',g;';
3499             $output_rules .= &file_contents_with_transform ($xform,
3500                                                             'remake-hdr');
3502             &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3503             &require_file_with_conf_line ($config_header_line, $FOREIGN,
3504                                           "${out_dir}/${stamp_name}.in");
3506             $distclean_config .= ' ' if $distclean_config;
3507             $distclean_config .= $cn_sans_dir;
3508         }
3509     }
3511     if ($distclean_config)
3512     {
3513         $output_rules .= &file_contents_with_transform ('s,\@FILES\@,'
3514                                                         . $distclean_config
3515                                                         . ',;',
3516                                                         'clean-hdr');
3517         push (@clean, 'hdr');
3518         &push_phony_cleaners ('hdr');
3519     }
3521     # Set location of mkinstalldirs.
3522     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
3523     {
3524         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
3525                                             . '/mkinstalldirs'));
3526     }
3527     else
3528     {
3529         &define_variable ('mkinstalldirs',
3530                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
3531     }
3533     &am_line_error ('CONFIG_HEADER',
3534                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
3535         if &variable_defined ('CONFIG_HEADER');
3537     local ($one_name);
3538     local ($config_header) = '';
3539     foreach $one_name (@config_names)
3540     {
3541         # Generate CONFIG_HEADER define.
3542         local ($one_hdr);
3543         if ($relative_dir eq &dirname ($one_name))
3544         {
3545             $one_hdr = &basename ($one_name);
3546         }
3547         else
3548         {
3549             $one_hdr = "${top_builddir}/${one_name}";
3550         }
3552         $config_header .= ' ' if $config_header;
3553         $config_header .= $one_hdr;
3554     }
3555     if ($config_header)
3556     {
3557         &define_variable ("CONFIG_HEADER", $config_header);
3558     }
3560     # Now look for other files in this directory which must be remade
3561     # by config.status, and generate rules for them.
3562     local (@actual_other_files) = ();
3563     local ($file, $local);
3564     local (@inputs, @rewritten_inputs, $single);
3565     local ($need_rewritten);
3566     foreach $file (@other_input_files)
3567     {
3568         if ($file =~ /^([^:]*):(.*)$/)
3569         {
3570             # This is the ":" syntax of AC_OUTPUT.
3571             $file = $1;
3572             $local = &basename ($file);
3573             @inputs = split (':', $2);
3574             @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3575             $need_rewritten = 1;
3576         }
3577         else
3578         {
3579             # Normal usage.
3580             $local = &basename ($file);
3581             @inputs = ($local . '.in');
3582             @rewritten_inputs =
3583                 &rewrite_inputs_into_dependencies (1, $file . '.in');
3584             $need_rewritten = 0;
3585         }
3587         # Skip files not in this directory.
3588         next unless &dirname ($file) eq $relative_dir;
3590         # Skip any file that is an automake input.
3591         next if -f $file . '.am';
3593         # Some users have been tempted to put `stamp-h' in the
3594         # AC_OUTPUT line.  This won't do the right thing, so we
3595         # explicitly fail here.
3596         if ($local eq 'stamp-h')
3597         {
3598             # FIXME: allow real filename.
3599             &am_conf_error ('configure.in', $ac_output_line,
3600                             'stamp-h should not appear in AC_OUTPUT');
3601             next;
3602         }
3604         $output_rules .= ($local . ': '
3605                           . '$(top_builddir)/config.status '
3606                           . join (' ', @rewritten_inputs) . "\n"
3607                           . "\t"
3608                           . 'cd $(top_builddir) && CONFIG_FILES='
3609                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3610                           . '$@' . ($need_rewritten
3611                                     ? (':' . join (':', @inputs))
3612                                     : '')
3613                           . ' CONFIG_HEADERS= $(SHELL) ./config.status'
3614                           . "\n");
3615         &push_dist_common (@inputs);
3616         push (@actual_other_files, $local);
3618         # Require all input files.
3619         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3620                                       &rewrite_inputs_into_dependencies (0, @inputs));
3621     }
3623     # These files get removed by "make clean".
3624     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3627 # Handle C headers.
3628 sub handle_headers
3630     local (@r);
3631     @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3632                           'oldinclude', 'pkginclude',
3633                           'noinst', 'check');
3634     foreach (@r)
3635     {
3636         next unless /\.(.*)$/;
3637         &saw_extension ($1);
3638     }
3641 sub handle_gettext
3643     return if ! $seen_gettext || $relative_dir ne '.';
3645     if (! &variable_defined ('SUBDIRS'))
3646     {
3647         &am_conf_error
3648             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
3649         return;
3650     }
3652     &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3654     if (&variable_defined ('SUBDIRS'))
3655     {
3656         &am_line_error
3657             ('SUBDIRS',
3658              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
3659                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
3660         &am_line_error
3661             ('SUBDIRS',
3662              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
3663                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
3664     }
3666     # Ensure that each language in ALL_LINGUAS has a .po file, and
3667     # each po file is mentioned in ALL_LINGUAS.
3668     if ($seen_linguas)
3669     {
3670         local (%linguas) = ();
3671         grep ($linguas{$_} = 1, split (' ', $all_linguas));
3673         foreach (<po/*.po>)
3674         {
3675             s/^po\///;
3676             s/\.po$//;
3678             &am_line_error ($all_linguas_line,
3679                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
3680                 if ! $linguas{$_};
3681         }
3683         foreach (keys %linguas)
3684         {
3685             &am_line_error ($all_linguas_line,
3686                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
3687                 if ! -f "po/$_.po";
3688         }
3689     }
3690     else
3691     {
3692         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
3693     }
3696 # Handle footer elements.
3697 sub handle_footer
3699     if ($contents{'SOURCES'})
3700     {
3701         # NOTE don't use define_pretty_variable here, because
3702         # $contents{...} is already defined.
3703         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
3704     }
3705     if ($contents{'OBJECTS'})
3706     {
3707         # NOTE don't use define_pretty_variable here, because
3708         # $contents{...} is already defined.
3709         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
3710     }
3711     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
3712     {
3713         $output_vars .= "\n";
3714     }
3716     if (&variable_defined ('SUFFIXES'))
3717     {
3718         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
3719         # make do not like variable substitutions on the .SUFFIXES
3720         # line.
3721         push (@suffixes, &variable_value_as_list ('SUFFIXES', ''));
3722     }
3723     if (&target_defined ('.SUFFIXES'))
3724     {
3725         &am_line_error ('.SUFFIXES',
3726                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
3727     }
3729     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3730     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3731     # anything else, by sticking it right after the default: target.
3732     $output_header .= ".SUFFIXES:\n";
3733     if (@suffixes)
3734     {
3736         # Make sure suffixes has unique elements.  Sort them to ensure
3737         # the output remains consistent.
3738         local (%suffixes);
3740         grep ($suffixes{$_} = 1, @suffixes);
3742         $output_header .= (".SUFFIXES: "
3743                            . join (' ', sort keys %suffixes)
3744                            . "\n");
3745     }
3746     $output_trailer .= &file_contents ('footer');
3749 # Deal with installdirs target.
3750 sub handle_installdirs
3752     # GNU Makefile standards recommend this.
3753     if ($recursive_install)
3754     {
3755         # We create a separate `-am' target so that the -recursive
3756         # rule will work correctly.
3757         $output_rules .= ("installdirs: installdirs-recursive\n"
3758                           . "installdirs-am:\n");
3759         push (@phony, 'installdirs-am');
3760     }
3761     else
3762     {
3763         $output_rules .= "installdirs:\n";
3764     }
3765     push (@phony, 'installdirs');
3766     if (@installdirs)
3767     {
3768         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
3769                             @installdirs);
3770     }
3771     $output_rules .= "\n";
3774 # There are several targets which need to be merged.  This is because
3775 # their complete definition is compiled from many parts.  Note that we
3776 # avoid double colon rules, otherwise we'd use them instead.
3777 sub handle_merge_targets
3779     local ($makefile) = @_;
3781     # There are a few install-related variables that you should not define.
3782     local ($var);
3783     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
3784     {
3785         if (&variable_defined ($var))
3786         {
3787             &am_line_error ($var, "\`$var' should not be defined");
3788         }
3789     }
3791     # Put this at the beginning for the sake of non-GNU makes.  This
3792     # is still wrong if these makes can run parallel jobs.  But it is
3793     # right enough.
3794     unshift (@all, &basename ($makefile));
3796     local ($one_name);
3797     foreach $one_name (@config_names)
3798     {
3799         push (@all, &basename ($one_name))
3800             if &dirname ($one_name) eq $relative_dir;
3801     }
3803     &do_one_merge_target ('info', @info);
3804     &do_one_merge_target ('dvi', @dvi);
3805     &do_check_merge_target;
3806     &do_one_merge_target ('installcheck', @installcheck);
3808     if (defined $options{'no-installinfo'})
3809     {
3810         &do_one_merge_target ('install-info', '');
3811     }
3812     elsif (&target_defined ('install-info-local'))
3813     {
3814         &am_line_error ('install-info-local',
3815                         "\`install-info-local' target defined but \`no-installinfo' option not in use");
3816     }
3818     local ($utarg);
3819     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3820                     'uninstall-exec-local', 'uninstall-exec-hook')
3821     {
3822         if (&target_defined ($utarg))
3823         {
3824             local ($x);
3825             ($x = $utarg) =~ s/(data|exec)-//;
3826             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3827         }
3828     }
3830     if (&target_defined ('install-local'))
3831     {
3832         &am_line_error ('install-local',
3833                         "use \`install-data-local' or \`install-exec-local', not \`install-local'");
3834     }
3836     if (@all)
3837     {
3838         local ($one_name);
3839         local ($local_headers) = '';
3840         foreach $one_name (@config_names)
3841         {
3842             if (&dirname ($one_name) eq $relative_dir)
3843             {
3844                 $local_headers .= ' ' if $local_headers;
3845                 $local_headers .= &basename ($one_name);
3846             }
3847         }
3848         if ($local_headers)
3849         {
3850             # This is kind of a hack, but I couldn't see a better way
3851             # to handle it.  In this particular case, we need to make
3852             # sure config.h is built before we recurse.  We can't do
3853             # this by changing the order of dependencies to the "all"
3854             # because that breaks when using parallel makes.  Instead
3855             # we handle things explicitly.
3856             $output_rules .= ("all-recursive-am: ${local_headers}"
3857                                   . "\n\t"
3858                                   . '$(MAKE) $(AM_MAKEFLAGS)'
3859                                   . " all-recursive"
3860                                   . "\n\n");
3861             $all_target = 'all-recursive-am';
3862             push (@phony, 'all-recursive-am');
3863         }
3864     }
3866     # Print definitions users can use.
3867     &do_one_merge_target ('install-exec', @install_exec);
3868     $output_rules .= "\n";
3870     &do_one_merge_target ('install-data', @install_data);
3871     $output_rules .= "\n";
3873     &do_one_merge_target ('install', 'all-am');
3874     &do_one_merge_target ('uninstall', @uninstall);
3876     &do_one_merge_target ('all', @all);
3878     # Generate the new 'install-strip' target.  We can't just set
3879     # INSTALL_PROGRAM because that might be a relative path.
3880     $output_rules .= ("install-strip:\n\t"
3881                       . '$(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install'
3882                       . "\n");
3883     push (@phony, 'install-strip');
3886 # Helper for handle_merge_targets.  Note that handle_merge_targets
3887 # relies on the fact that this doesn't add an extra \n at the end.
3888 sub do_one_merge_target
3890     local ($name, @values) = @_;
3892     if (&target_defined ($name . '-local'))
3893     {
3894         # User defined local form of target.  So include it.
3895         push (@values, $name . '-local');
3896         push (@phony, $name . '-local');
3897     }
3899     &pretty_print_rule ($name . "-am:", "\t\t", @values);
3900     if ($name eq 'install')
3901     {
3902         # Special-case `install-am' to run install-exec-am and
3903         # install-data-am after all-am is built.
3904         &pretty_print_rule ("\t\@\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3905                             'install-exec-am', 'install-data-am');
3906     }
3907     elsif ($name eq 'install-exec' && &target_defined ('install-exec-hook'))
3908     {
3909         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3910                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-exec-hook'
3911                           . "\n");
3912     }
3913     elsif ($name eq 'install-data' && &target_defined ('install-data-hook'))
3914     {
3915         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3916                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-data-hook'
3917                           . "\n");
3918     }
3920     local ($lname) = $name . ($recursive_install ? '-recursive' : '-am');
3921     local ($tname) = $name;
3922     # To understand this special case, see handle_merge_targets.
3923     if ($name eq 'all')
3924     {
3925         $tname = 'all-redirect';
3926         $lname = $all_target if $recursive_install;
3927         push (@phony, 'all-redirect');
3928         $output_all = "all: all-redirect\n";
3929     }
3930     &pretty_print_rule ($tname . ":", "\t\t", $lname);
3931     push (@phony, $name . '-am', $name);
3934 # Handle check merge target specially.
3935 sub do_check_merge_target
3937     if (&target_defined ('check-local'))
3938     {
3939         # User defined local form of target.  So include it.
3940         push (@check_tests, 'check-local');
3941         push (@phony, 'check-local');
3942     }
3944     # In --cygnus mode, check doesn't depend on all.
3945     if ($cygnus_mode)
3946     {
3947         # Just run the local check rules.
3948         &pretty_print_rule ('check-am:', "\t\t", @check);
3949     }
3950     else
3951     {
3952         # The check target must depend on the local equivalent of
3953         # `all', to ensure all the primary targets are built.  Then it
3954         # must build the local check rules.
3955         $output_rules .= "check-am: all-am\n";
3956         &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3957                             @check)
3958             if @check;
3959     }
3960     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3961                         @check_tests)
3962         if @check_tests;
3964     push (@phony, 'check', 'check-am');
3965     $output_rules .= ("check: "
3966                       . ($recursive_install ? 'check-recursive' : 'check-am')
3967                       . "\n");
3970 # Handle all 'clean' targets.
3971 sub handle_clean
3973     local ($xform) = '';
3974     local ($name);
3976     # Don't include `MAINTAINER'; it is handled specially below.
3977     foreach $name ('MOSTLY', '', 'DIST')
3978     {
3979         if (! &variable_defined ($name . 'CLEANFILES'))
3980         {
3981             $xform .= 's/^' . $name . 'CLEAN.*$//;';
3982         }
3983         else
3984         {
3985             $xform .= 's/^' . $name . 'CLEAN//;';
3986         }
3987     }
3989     # Built sources are automatically removed by maintainer-clean.
3990     push (@maintainer_clean_files, '\$(BUILT_SOURCES)')
3991         if &variable_defined ('BUILT_SOURCES');
3992     push (@maintainer_clean_files, '\$(MAINTAINERCLEANFILES)')
3993         if &variable_defined ('MAINTAINERCLEANFILES');
3994     if (! @maintainer_clean_files)
3995     {
3996         $xform .= 's/^MAINTAINERCLEAN.*$//;';
3997     }
3998     else
3999     {
4000         $xform .= ('s/^MAINTAINERCLEAN//;'
4001                    # Join with no space to avoid spurious `test -z'
4002                    # success at runtime.
4003                    . 's,\@MCFILES\@,' . join ('', @maintainer_clean_files)
4004                    . ',;'
4005                    # A space is required in the join here.
4006                    . 's,\@MFILES\@,' . join (' ', @maintainer_clean_files)
4007                    . ',;');
4008     }
4010     $output_rules .= &file_contents_with_transform ($xform, 'clean');
4012     push (@clean, 'generic');
4013     &push_phony_cleaners ('generic');
4015     &do_one_clean_target ('clean', 'mostly', '', @clean);
4016     &do_one_clean_target ('clean', '', 'mostly', @clean);
4017     &do_one_clean_target ('clean', 'dist', '', @clean);
4018     &do_one_clean_target ('clean', 'maintainer-', 'dist', @clean);
4020     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
4023 # Helper for handle_clean.
4024 sub do_one_clean_target
4026     local ($target, $name, $last_name, @deps) = @_;
4028     # Change each dependency `BLARG' into `clean-BLARG'.
4029     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
4031     # Push the previous clean target.  There is no previous clean
4032     # target if we're doing mostlyclean.
4033     push (@deps, $last_name . $target . '-am')
4034         unless $name eq 'mostly';
4036     # If a -local version of the rule is given, add it to the list.
4037     if (&target_defined ($name . $target . '-local'))
4038     {
4039         push (@deps, $name . $target . '-local');
4040     }
4042     # Print the target and the dependencies.
4043     &pretty_print_rule ($name . $target . "-am: ", "\t\t", @deps);
4045     # FIXME: shouldn't we really print these messages before running
4046     # the dependencies?
4047     if ($name . $target eq 'maintainer-clean')
4048     {
4049         # Print a special warning.
4050         $output_rules .=
4051             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
4052              . "\t\@echo \"it deletes files that may require special "
4053              . "tools to rebuild.\"\n");
4054     }
4055     elsif ($name . $target eq 'distclean')
4056     {
4057         $output_rules .= "\t-rm -f libtool\n" if $seen_libtool;
4058     }
4059     $output_rules .= "\n";
4061     # Now generate the actual clean target.
4062     $output_rules .= ($name . $target . ": " . $name . $target
4063                       . ($recursive_install ? '-recursive' : '-am')
4064                       . "\n");
4066     # We special-case config.status here.  If we do it as part of the
4067     # normal clean processing for this directory, then it might be
4068     # removed before some subdir is cleaned.  However, that subdir's
4069     # Makefile depends on config.status.
4070     if (($name . $target eq 'maintainer-clean'
4071          || $name . $target eq 'distclean')
4072         && $relative_dir eq '.')
4073     {
4074         $output_rules .= "\t-rm -f config.status\n";
4075     }
4076     $output_rules .= "\n";
4079 # Handle .PHONY target.
4080 sub handle_phony
4082     &pretty_print_rule ('.PHONY:', "", @phony);
4083     $output_rules .= "\n";
4086 # Handle TESTS variable and other checks.
4087 sub handle_tests
4089     if (defined $options{'dejagnu'})
4090     {
4091         push (@check_tests, 'check-DEJAGNU');
4092         push (@phony, 'check-DEJAGNU');
4094         local ($xform);
4095         if ($cygnus_mode)
4096         {
4097             $xform = 's/^CYGNUS//;';
4098         }
4099         else
4100         {
4101             $xform = 's/^CYGNUS.*$//;';
4102         }
4103         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
4105         # In Cygnus mode, these are found in the build tree.
4106         # Otherwise they are looked for in $PATH.
4107         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
4108         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
4110         # Only create site.exp rule if user hasn't already written
4111         # one.
4112         if (! &target_defined ('site.exp'))
4113         {
4114             # Note that in the rule we don't directly generate
4115             # site.exp to avoid the possibility of a corrupted
4116             # site.exp if make is interrupted.  Jim Meyering has some
4117             # useful text on this topic.
4118             $output_rules .= ("site.exp: Makefile\n"
4119                               . "\t\@echo 'Making a new site.exp file...'\n"
4120                               . "\t\@test ! -f site.bak || rm -f site.bak\n"
4121                               . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
4122                               . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
4123                               . "\t\@echo '# edit the last section' >> \$\@-t\n"
4124                               . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
4125                               . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
4126                               . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
4128             # Extra stuff for AC_CANONICAL_*
4129             local (@whatlist) = ();
4130             if ($seen_canonical)
4131             {
4132                 push (@whatlist, 'host');
4133             }
4135             # Extra stuff only for AC_CANONICAL_SYSTEM.
4136             if ($seen_canonical == $AC_CANONICAL_SYSTEM)
4137             {
4138                 push (@whatlist, 'target', 'build');
4139             }
4141             local ($c1, $c2);
4142             foreach $c1 (@whatlist)
4143             {
4144                 foreach $c2 ('alias', 'triplet')
4145                 {
4146                     $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
4147                 }
4148             }
4150             $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
4151                               . "\t\@test ! -f site.exp || sed '1,/^## All variables above are.*##/ d' site.exp >> \$\@-t\n"
4152                               . "\t\@test ! -f site.exp || mv site.exp site.bak\n"
4153                               . "\t\@mv \$\@-t site.exp\n");
4154         }
4155     }
4156     else
4157     {
4158         local ($c);
4159         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4160         {
4161             if (&variable_defined ($c))
4162             {
4163                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
4164             }
4165         }
4166     }
4168     if (&variable_defined ('TESTS'))
4169     {
4170         push (@check_tests, 'check-TESTS');
4171         push (@phony, 'check-TESTS');
4173         # Note: Solaris 2.7 seems to expand TESTS using VPATH.  That's
4174         # why we also try `dir='
4175         $output_rules .= 'check-TESTS: $(TESTS)
4176         @failed=0; all=0; xfail=0; xpass=0; \\
4177         srcdir=$(srcdir); export srcdir; \\
4178         for tst in $(TESTS); do \\
4179           if test -f ./$$tst; then dir=./; \\
4180           elif test -f $$tst; then dir=; \\
4181           else dir="$(srcdir)/"; fi; \\
4182           if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \\
4183             all=`expr $$all + 1`; \\
4184             case " $(XFAIL_TESTS) " in \\
4185             *" $$tst "*) \\
4186               xpass=`expr $$xpass + 1`; \\
4187               failed=`expr $$failed + 1`; \\
4188               echo "XPASS: $$tst"; \\
4189             ;; \\
4190             *) \\
4191               echo "PASS: $$tst"; \\
4192             ;; \\
4193             esac; \\
4194           elif test $$? -ne 77; then \\
4195             all=`expr $$all + 1`; \\
4196             case " $(XFAIL_TESTS) " in \\
4197             *" $$tst "*) \\
4198               xfail=`expr $$xfail + 1`; \\
4199               echo "XFAIL: $$tst"; \\
4200             ;; \\
4201             *) \\
4202               failed=`expr $$failed + 1`; \\
4203               echo "FAIL: $$tst"; \\
4204             ;; \\
4205             esac; \\
4206           fi; \\
4207         done; \\
4208         if test "$$failed" -eq 0; then \\
4209           if test "$$xfail" -eq 0; then \\
4210             banner="All $$all tests passed"; \\
4211           else \\
4212             banner="All $$all tests behaved as expected ($$xfail expected failures)"; \\
4213           fi; \\
4214         else \\
4215           if test "$$xpass" -eq 0; then \\
4216             banner="$$failed of $$all tests failed"; \\
4217           else \\
4218             banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \\
4219           fi; \\
4220         fi; \\
4221         dashes=`echo "$$banner" | sed s/./=/g`; \\
4222         echo "$$dashes"; \\
4223         echo "$$banner"; \\
4224         echo "$$dashes"; \\
4225         test "$$failed" -eq 0
4227     }
4230 # Handle Emacs Lisp.
4231 sub handle_emacs_lisp
4233     local (@elfiles) = &am_install_var ('-candist', 'lisp', 'LISP',
4234                                         'lisp', 'noinst');
4236     if (@elfiles)
4237     {
4238         # Found some lisp.
4239         &define_configure_variable ('lispdir');
4240         &define_configure_variable ('EMACS');
4241         $output_rules .= (".el.elc:\n"
4242                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
4243                           . "\tif test \$(EMACS) != no; then \\\n"
4244                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
4245                           . "\tfi\n");
4246         push (@suffixes, '.el', '.elc');
4248         # Generate .elc files.
4249         grep ($_ .= 'c', @elfiles);
4250         &define_pretty_variable ('ELCFILES', '', @elfiles);
4252         $output_rules .= &file_contents ('lisp-clean');
4253         push (@clean, 'lisp');
4254         &push_phony_cleaners ('lisp');
4256         push (@all, '$(ELCFILES)');
4258         local ($varname);
4259         if (&variable_defined ('lisp_LISP'))
4260         {
4261             $varname = 'lisp_LISP';
4262             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
4263                 if ! $seen_lispdir;
4264         }
4265         else
4266         {
4267             $varname = 'noinst_LISP';
4268         }
4270         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
4271     }
4274 # Handle Java.
4275 sub handle_java
4277     local (@sourcelist) = &am_install_var ('-candist', '-clean',
4278                                            'java', 'JAVA',
4279                                            'java', 'noinst', 'check');
4280     return if ! @sourcelist;
4282     &define_variable ('JAVAC', 'javac');
4283     &define_variable ('JAVACFLAGS', '');
4284     &define_variable ('CLASSPATH_ENV',
4285                       'CLASSPATH=$(JAVAROOT):$(srcdir)/$(JAVAROOT):$$CLASSPATH');
4286     &define_variable ('JAVAROOT', '$(top_builddir)');
4288     local (%valid) = &am_primary_prefixes ('JAVA', 1,
4289                                            'java', 'noinst', 'check');
4291     local ($dir, $curs);
4292     foreach $curs (keys %valid)
4293     {
4294         if (! &variable_defined ($curs . '_JAVA') || $curs eq 'noinst'
4295             || $curs eq 'EXTRA')
4296         {
4297             next;
4298         }
4300         if (defined $dir)
4301         {
4302             &am_line_error ($curs . '_JAVA',
4303                             "multiple _JAVA primaries in use");
4304         }
4305         $dir = $curs;
4306     }
4308     $output_rules .= ('class' . $dir . '.stamp: $(' . $dir . '_JAVA)' . "\n"
4309                       . "\t" . '$(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) '
4310                       . '$(JAVACFLAGS) $?' . "\n"
4311                       . "\t" . 'echo timestamp > class' . $dir . '.stamp'
4312                       . "\n");
4313     push (@all, 'class' . $dir . '.stamp');
4314     &push_dist_common ('$(' . $dir . '_JAVA)');
4317 # Handle some of the minor options.
4318 sub handle_minor_options
4320     if (defined $options{'readme-alpha'})
4321     {
4322         if ($relative_dir eq '.')
4323         {
4324             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4325             {
4326                 # FIXME: allow real filename.
4327                 &am_conf_line_error ('configure.in',
4328                                      $package_version_line,
4329                                      "version \`$package_version' doesn't follow Gnits standards");
4330             }
4331             elsif (defined $1 && -f 'README-alpha')
4332             {
4333                 # This means we have an alpha release.  See
4334                 # GNITS_VERSION_PATTERN for details.
4335                 &require_file ($FOREIGN, 'README-alpha');
4336             }
4337         }
4338     }
4341 ################################################################
4343 # Scan one file for interesting things.  Subroutine of scan_configure.
4344 sub scan_one_configure_file
4346     local ($filename) = @_;
4347     local (*CONFIGURE);
4349     open (CONFIGURE, $filename)
4350         || die "automake: couldn't open \`$filename': $!\n";
4351     print "automake: reading $filename\n" if $verbose;
4353     while (<CONFIGURE>)
4354     {
4355         # Remove comments from current line.
4356         s/\bdnl\b.*$//;
4357         s/\#.*$//;
4359         # Skip macro definitions.  Otherwise we might be confused into
4360         # thinking that a macro that was only defined was actually
4361         # used.
4362         next if /AC_DEFUN/;
4364         # Follow includes.  This is a weirdness commonly in use at
4365         # Cygnus and hopefully nowhere else.
4366         if (/sinclude\((.*)\)/ && -f $1)
4367         {
4368             &scan_one_configure_file ($1);
4369         }
4371         # Populate libobjs array.
4372         if (/AC_FUNC_ALLOCA/)
4373         {
4374             $libsources{'alloca.c'} = 1;
4375         }
4376         elsif (/AC_FUNC_GETLOADAVG/)
4377         {
4378             $libsources{'getloadavg.c'} = 1;
4379         }
4380         elsif (/AC_FUNC_MEMCMP/)
4381         {
4382             $libsources{'memcmp.c'} = 1;
4383         }
4384         elsif (/AC_STRUCT_ST_BLOCKS/)
4385         {
4386             $libsources{'fileblocks.c'} = 1;
4387         }
4388         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4389         {
4390             $libsources{'getopt.c'} = 1;
4391             $libsources{'getopt1.c'} = 1;
4392         }
4393         elsif (/AM_FUNC_STRTOD/)
4394         {
4395             $libsources{'strtod.c'} = 1;
4396         }
4397         elsif (/AM_WITH_REGEX/)
4398         {
4399             $libsources{'rx.c'} = 1;
4400             $libsources{'rx.h'} = 1;
4401             $libsources{'regex.c'} = 1;
4402             $libsources{'regex.h'} = 1;
4403             $omit_dependencies{'rx.h'} = 1;
4404             $omit_dependencies{'regex.h'} = 1;
4405         }
4406         elsif (/AC_FUNC_MKTIME/)
4407         {
4408             $libsources{'mktime.c'} = 1;
4409         }
4410         elsif (/AM_FUNC_ERROR_AT_LINE/)
4411         {
4412             $libsources{'error.c'} = 1;
4413             $libsources{'error.h'} = 1;
4414         }
4415         elsif (/AM_FUNC_OBSTACK/)
4416         {
4417             $libsources{'obstack.c'} = 1;
4418             $libsources{'obstack.h'} = 1;
4419         }
4420         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4421                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4422         {
4423             foreach $libobj_iter (split (' ', $1))
4424             {
4425                 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4426                     || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4427                     || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4428                 {
4429                     $libsources{$1 . '.c'} = 1;
4430                 }
4431             }
4432         }
4434         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4435         {
4436             $in_ac_replace = 1;
4437         }
4438         if ($in_ac_replace)
4439         {
4440             $in_ac_replace = 0 if s/[\]\)].*$//;
4441             # Remove trailing backslash.
4442             s/\\$//;
4443             foreach (split)
4444             {
4445                 # Need to skip empty elements for Perl 4.
4446                 next if $_ eq '';
4447                 $libsources{$_ . '.c'} = 1;
4448             }
4449         }
4451         if (/$obsolete_rx/o)
4452         {
4453             local ($hint) = '';
4454             if ($obsolete_macros{$1} ne '')
4455             {
4456                 $hint = '; ' . $obsolete_macros{$1};
4457             }
4458             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
4459         }
4461         # Process the AC_OUTPUT macro.
4462         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
4463         {
4464             $in_ac_output = 1;
4465             $ac_output_line = $.;
4466         }
4467         if ($in_ac_output)
4468         {
4469             local ($closing) = 0;
4470             if (s/[\]\),].*$//)
4471             {
4472                 $in_ac_output = 0;
4473                 $closing = 1;
4474             }
4476             # Look at potential Makefile.am's.
4477             foreach (split)
4478             {
4479                 # Must skip empty string for Perl 4.
4480                 next if $_ eq "\\" || $_ eq '';
4482                 # Handle $local:$input syntax.  Note that we ignore
4483                 # every input file past the first, though we keep
4484                 # those around for later.
4485                 local ($local, $input, @rest) = split (/:/);
4486                 if (! $input)
4487                 {
4488                     $input = $local;
4489                 }
4490                 else
4491                 {
4492                     # FIXME: should be error if .in is missing.
4493                     $input =~ s/\.in$//;
4494                 }
4496                 if (-f $input . '.am')
4497                 {
4498                     # We have a file that automake should generate.
4499                     push (@make_input_list, $input);
4500                     $make_list{$input} = join (':', ($local, @rest));
4501                 }
4502                 else
4503                 {
4504                     # We have a file that automake should cause to be
4505                     # rebuilt, but shouldn't generate itself.
4506                     push (@other_input_files, $_);
4507                 }
4508             }
4510             if ($closing && @make_input_list == 0 && @other_input_files == 0)
4511             {
4512                 &am_conf_line_error ($filename, $ac_output_line,
4513                                      "No files mentioned in \`AC_OUTPUT'");
4514                 exit 1;
4515             }
4516         }
4518         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4519         {
4520             @config_aux_path = $1;
4521         }
4523         # Check for ansi2knr.
4524         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4526         # Check for exe extension stuff.
4527         if (/AC_EXEEXT/)
4528         {
4529             $seen_exeext = 1;
4530             $configure_vars{'EXEEXT'} = $filename . ':' . $.;
4531         }
4533         if (/AC_OBJEXT/)
4534         {
4535             $seen_objext = 1;
4536             $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4537         }
4539         # Check for `-c -o' code.
4540         $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4542         # Check for NLS support.
4543         if (/AM_GNU_GETTEXT/)
4544         {
4545             $seen_gettext = 1;
4546             $ac_gettext_line = $.;
4547             $omit_dependencies{'libintl.h'} = 1;
4548         }
4550         # Look for ALL_LINGUAS.
4551         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4552         {
4553             $seen_linguas = 1;
4554             $all_linguas = $1;
4555             $all_linguas_line = $.;
4556         }
4558         # Handle configuration headers.  A config header of `[$1]'
4559         # means we are actually scanning AM_CONFIG_HEADER from
4560         # aclocal.m4.
4561         if (/A([CM])_CONFIG_HEADER\s*\((.*)\)/
4562             && $2 ne '[$1]')
4563         {
4564             &am_conf_line_error
4565                 ($filename, $., "\`automake requires \`AM_CONFIG_HEADER', not \`AC_CONFIG_HEADER'")
4566                     if $1 eq 'C';
4568             $config_header_line = $.;
4569             local ($one_hdr);
4570             foreach $one_hdr (split (' ', $2))
4571             {
4572                 push (@config_fullnames, $one_hdr);
4573                 if ($one_hdr =~ /^([^:]+):(.+)$/)
4574                 {
4575                     push (@config_names, $1);
4576                     push (@config_headers, $2);
4577                 }
4578                 else
4579                 {
4580                     push (@config_names, $one_hdr);
4581                     push (@config_headers, $one_hdr . '.in');
4582                 }
4583             }
4584         }
4586         # Handle AC_CANONICAL_*.  Always allow upgrading to
4587         # AC_CANONICAL_SYSTEM, but never downgrading.
4588         $seen_canonical = $AC_CANONICAL_HOST
4589             if ! $seen_canonical
4590                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4591         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4593         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
4595         # This macro handles several different things.
4596         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4597         {
4598             $seen_make_set = 1;
4599             $seen_package = 1;
4600             $seen_version = 1;
4601             $seen_arg_prog = 1;
4602             $seen_prog_install = 1;
4603             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4604             $package_version_line = $.;
4605         }
4607         # This is like AM_INIT_AUTOMAKE, but doesn't actually set the
4608         # package and version number.  (This might change in the
4609         # future).  Yes, I'm not above hacking Automake so it works
4610         # well with other GNU tools -- that is actually the point.
4611         if (/AM_INIT_GUILE_MODULE/)
4612         {
4613             $seen_make_set = 1;
4614             $seen_package = 1;
4615             $seen_version = 1;
4616             $seen_arg_prog = 1;
4617             $seen_prog_install = 1;
4618             @config_aux_path = ('..');
4619         }
4621         # Some things required by Automake.
4622         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
4623         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
4625         if (/AM_PROG_LEX/)
4626         {
4627             $configure_vars{'LEX'} = $filename . ':' . $.;
4628             $seen_decl_yytext = 1;
4629         }
4630         if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.in$/)
4631         {
4632             &am_conf_line_warning ($filename, $., "\`AC_DECL_YYTEXT' is covered by \`AM_PROG_LEX'");
4633         }
4634         if (/AC_PROG_LEX/ && $filename =~ /configure\.in$/)
4635         {
4636             &am_conf_line_warning ($filename, $., "automake requires \`AM_PROG_LEX', not \`AC_PROG_LEX'");
4637         }
4639         if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4640         {
4641             $configure_vars{$1} = $filename . ':' . $.;
4642         }
4643         if (/$AC_CHECK_PATTERN/o)
4644         {
4645             $configure_vars{$3} = $filename . ':' . $.;
4646         }
4647         if (/$AM_MISSING_PATTERN/o
4648             && $1 ne 'ACLOCAL'
4649             && $1 ne 'AUTOCONF'
4650             && $1 ne 'AUTOMAKE'
4651             && $1 ne 'AUTOHEADER')
4652         {
4653             $configure_vars{$1} = $filename . ':' . $.;
4654         }
4656         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4657         # but later define it elsewhere.  This is pretty hacky.  We
4658         # also explicitly avoid INSTALL_SCRIPT and some other
4659         # variables because they are defined in header-vars.am.
4660         # FIXME.
4661         if (/$AC_SUBST_PATTERN/o
4662             && $1 ne 'ANSI2KNR'
4663             && $1 ne 'INSTALL_SCRIPT'
4664             && $1 ne 'INSTALL_DATA')
4665         {
4666             $configure_vars{$1} = $filename . ':' . $.;
4667         }
4669         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4670         if (/AM_MAINTAINER_MODE/)
4671         {
4672             $seen_maint_mode = 1;
4673             $configure_cond{'MAINTAINER_MODE'} = 1;
4674         }
4675         $seen_package = 1 if /PACKAGE=/;
4677         # Skip VERSION of [$2]; that is from AM_INIT_AUTOMAKE.
4678         if (/\bVERSION=(\S+)/ && $1 ne '[$2]')
4679         {
4680             $seen_version = 1;
4681             $package_version = $1;
4682             $package_version_line = $.;
4683         }
4684         elsif (/VERSION=/)
4685         {
4686             $seen_version = 1;
4687         }
4689         $seen_prog_install = 1 if /AC_PROG_INSTALL/;
4690         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4692         if (/A(C|M)_PROG_LIBTOOL/)
4693         {
4694             if (/AM_PROG_LIBTOOL/)
4695             {
4696                 &am_conf_line_warning ($filename, $., "\`AM_PROG_LIBTOOL' is obsolete, use \`AC_PROG_LIBTOOL' instead");
4697             }
4698             $seen_libtool = 1;
4699             $libtool_line = $.;
4700             $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4701             $configure_vars{'RANLIB'} = $filename . ':' . $.;
4702             $configure_vars{'CC'} = $filename . ':' . $.;
4703             # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
4704             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4705             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4706         }
4708         $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4710         if (/$AM_CONDITIONAL_PATTERN/o)
4711         {
4712             $configure_cond{$1} = 1;
4713         }
4715         # Check for Fortran 77 intrinsic and run-time libraries.
4716         if (/AC_F77_LIBRARY_LDFLAGS/)
4717         {
4718             $configure_vars{'FLIBS'} = $filename . ':' . $.;
4719         }
4720     }
4722     close (CONFIGURE);
4725 # Scan configure.in and aclocal.m4 for interesting things.  We must
4726 # scan aclocal.m4 because there might be AC_SUBSTs and such there.
4727 sub scan_configure
4729     # Reinitialize libsources here.  This isn't really necessary,
4730     # since we currently assume there is only one configure.in.  But
4731     # that won't always be the case.
4732     %libsources = ();
4734     local ($in_ac_output, $in_ac_replace) = (0, 0);
4735     local (%make_list, @make_input_list);
4736     local ($libobj_iter);
4738     &scan_one_configure_file ('configure.in');
4739     &scan_one_configure_file ('aclocal.m4')
4740         if -f 'aclocal.m4';
4742     # Set input and output files if not specified by user.
4743     if (! @input_files)
4744     {
4745         @input_files = @make_input_list;
4746         %output_files = %make_list;
4747     }
4749     @configure_input_files = @make_input_list;
4751     &am_conf_error ("\`PACKAGE' not defined in configure.in")
4752         if ! $seen_package;
4753     &am_conf_error ("\`VERSION' not defined in configure.in")
4754         if ! $seen_version;
4756     # Look for some files we need.  Always check for these.  This
4757     # check must be done for every run, even those where we are only
4758     # looking at a subdir Makefile.  We must set relative_dir so that
4759     # the file-finding machinery works.
4760     local ($relative_dir) = '.';
4761     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4762     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
4763         if -f $config_aux_path[0] . '/install.sh';
4766 ################################################################
4768 # Set up for Cygnus mode.
4769 sub check_cygnus
4771     return unless $cygnus_mode;
4773     &set_strictness ('foreign');
4774     $options{'no-installinfo'} = 1;
4775     $options{'no-dependencies'} = 1;
4776     $use_dependencies = 0;
4778     if (! $seen_maint_mode)
4779     {
4780         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
4781     }
4783     if (! $seen_exeext)
4784     {
4785         &am_conf_error ("\`AC_EXEEXT' required when --cygnus specified");
4786     }
4789 # Do any extra checking for GNU standards.
4790 sub check_gnu_standards
4792     if ($relative_dir eq '.')
4793     {
4794         # In top level (or only) directory.
4795         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4796                        'AUTHORS', 'ChangeLog');
4797     }
4799     if ($strictness >= $GNU)
4800     {
4801         if (defined $options{'no-installman'})
4802         {
4803             &am_line_error ('AUTOMAKE_OPTIONS',
4804                             "option \`no-installman' disallowed by GNU standards");
4805         }
4807         if (defined $options{'no-installinfo'})
4808         {
4809             &am_line_error ('AUTOMAKE_OPTIONS',
4810                             "option \`no-installinfo' disallowed by GNU standards");
4811         }
4812     }
4815 # Do any extra checking for GNITS standards.
4816 sub check_gnits_standards
4818     if ($strictness >= $GNITS)
4819     {
4820         if (-f $relative_dir . '/COPYING.LIB')
4821         {
4822             &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
4823         }
4824     }
4826     if ($relative_dir eq '.')
4827     {
4828         # In top level (or only) directory.
4829         &require_file ($GNITS, 'THANKS');
4830     }
4833 ################################################################
4835 # Functions to handle files of each language.
4837 # Each `lang_X_rewrite' function follows a simple formula:
4838 # * Args are the directory, base name and extension of the file.
4839 # * Return value is 1 if file is to be dealt with, 0 otherwise.
4840 # Much of the actual processing is handled in handle_single_transform_list.
4841 # These functions exist so that auxiliary information can be recorded
4842 # for a later cleanup pass.  Note that the calls to these functions
4843 # are computed, so don't bother searching for their precise names
4844 # in the source.
4846 # This is just a convenience function that can be used to determine
4847 # when a subdir object should be used.
4848 sub lang_sub_obj
4850     return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4853 # Rewrite a single C source file.
4854 sub lang_c_rewrite
4856     local ($directory, $base, $ext) = @_;
4858     if (defined $options{'ansi2knr'} && $base =~ /_$/)
4859     {
4860         # FIXME: include line number in error.
4861         &am_error ("C source file \`$base.c' would be deleted by ansi2knr rules");
4862     }
4864     local ($r) = $LANG_PROCESS;
4865     if (defined $options{'subdir-objects'})
4866     {
4867         $r = $LANG_SUBDIR;
4868         $base = $directory . '/' . $base;
4870         if (! $seen_cc_c_o)
4871         {
4872             # Only give error once.
4873             $seen_cc_c_o = 1;
4874             # FIXME: line number.
4875             &am_error ("C objects in subdir but \`AM_PROG_CC_C_O' not in \`configure.in'");
4876         }
4878         &require_file ($FOREIGN, 'compile')
4879             if $relative_dir eq '.';
4880     }
4882     $de_ansi_files{$base} = 1;
4883     return $r;
4886 # Rewrite a single C++ source file.
4887 sub lang_cxx_rewrite
4889     return &lang_sub_obj;
4892 # Rewrite a single header file.
4893 sub lang_header_rewrite
4895     # Header files are simply ignored.
4896     return $LANG_IGNORE;
4899 # Rewrite a single yacc file.
4900 sub lang_yacc_rewrite
4902     local ($directory, $base, $ext) = @_;
4904     local ($r) = &lang_c_rewrite ($directory, $base, $ext);
4905     local ($pfx) = '';
4906     if ($r == $LANG_SUBDIR)
4907     {
4908         $pfx = $directory . '/';
4909     }
4910     $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4911     $ext =~ tr/y/c/;
4912     &saw_extension ('c');
4913     # FIXME: nodist.
4914     &push_dist_common ($pfx . $base . '.' . $ext);
4915     return $r;
4918 # Rewrite a single yacc++ file.
4919 sub lang_yaccxx_rewrite
4921     local ($directory, $base, $ext) = @_;
4923     local ($r) = $LANG_PROCESS;
4924     local ($pfx) = '';
4925     if (defined $options{'subdir-objects'})
4926     {
4927         $pfx = $directory . '/';
4928         $r = $LANG_SUBDIR;
4929     }
4930     $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4931     $ext =~ tr/y/c/;
4932     &saw_extension ($ext);
4933     # FIXME: nodist.
4934     &push_dist_common ($pfx . $base . '.' . $ext);
4935     return $r;
4938 # Rewrite a single lex file.
4939 sub lang_lex_rewrite
4941     local ($directory, $base, $ext) = @_;
4943     local ($r) = &lang_c_rewrite ($directory, $base, $ext);
4944     local ($pfx) = '';
4945     if ($r == $LANG_SUBDIR)
4946     {
4947         $pfx = $directory . '/';
4948     }
4949     $lex_sources{$pfx . $base . '.' . $ext} = 1;
4950     $ext =~ tr/l/c/;
4951     &saw_extension ('c');
4952     # FIXME: nodist.
4953     &push_dist_common ($pfx . $base . '.' . $ext);
4954     return $r;
4957 # Rewrite a single lex++ file.
4958 sub lang_lexxx_rewrite
4960     local ($directory, $base, $ext) = @_;
4962     local ($r) = $LANG_PROCESS;
4963     local ($pfx) = '';
4964     if (defined $options{'subdir-objects'})
4965     {
4966         $pfx = $directory . '/';
4967         $r = $LANG_SUBDIR;
4968     }
4969     $lex_sources{$pfx . $base . '.' . $ext} = 1;
4970     $ext =~ tr/l/c/;
4971     &saw_extension ($ext);
4972     # FIXME: nodist.
4973     &push_dist_common ($pfx . $base . '.' . $ext);
4974     return $r;
4977 # Rewrite a single assembly file.
4978 sub lang_asm_rewrite
4980     return &lang_sub_obj;
4983 # Rewrite a single Fortran 77 file.
4984 sub lang_f77_rewrite
4986     return $LANG_PROCESS;
4989 # Rewrite a single preprocessed Fortran 77 file.
4990 sub lang_ppf77_rewrite
4992     return $LANG_PROCESS;
4995 # Rewrite a single ratfor file.
4996 sub lang_ratfor_rewrite
4998     return $LANG_PROCESS;
5001 # Rewrite a single Objective C file.
5002 sub lang_objc_rewrite
5004     return &lang_sub_obj;
5007 # Rewrite a single Java file.
5008 sub lang_java_rewrite
5010     return $LANG_SUBDIR;
5013 # The lang_X_finish functions are called after all source file
5014 # processing is done.  Each should handle defining rules for the
5015 # language, etc.  A finish function is only called if a source file of
5016 # the appropriate type has been seen.
5018 sub lang_c_finish
5020     # Push all libobjs files onto de_ansi_files.  We actually only
5021     # push files which exist in the current directory, and which are
5022     # genuine source files.
5023     local ($file);
5024     foreach $file (keys %libsources)
5025     {
5026         if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
5027         {
5028             $de_ansi_files{$1} = 1;
5029         }
5030     }
5032     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
5033     {
5034         # Make all _.c files depend on their corresponding .c files.
5035         local ($base, @objects);
5036         foreach $base (sort keys %de_ansi_files)
5037         {
5038             # Each _.c file must depend on ansi2knr; otherwise it
5039             # might be used in a parallel build before it is built.
5040             # We need to support files in the srcdir and in the build
5041             # dir (because these files might be auto-generated.  But
5042             # we can't use $< -- some makes only define $< during a
5043             # suffix rule.
5044             $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
5045                               . '$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5046                               . '`if test -f $(srcdir)/' . $base . '.c'
5047                               . '; then echo $(srcdir)/' . $base . '.c'
5048                               . '; else echo ' . $base . '.c; fi` '
5049                               . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5050                               . '| $(ANSI2KNR) > ' . $base . "_.c\n");
5051             push (@objects, $base . '_'
5052                   . ($seen_objext ? '.$(OBJEXT)' : '.o'));
5053             push (@objects, $base . '_.lo') if $seen_libtool;
5054         }
5056         # Make all _.o (and _.lo) files depend on ansi2knr.
5057         # Use a sneaky little hack to make it print nicely.
5058         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5059     }
5061     if (! defined $configure_vars{'CC'})
5062     {
5063         # FIXME: line number.
5064         &am_error ("C source seen but \`CC' not defined in \`configure.in'");
5065     }
5068 sub lang_cxx_finish
5070     local ($ltcompile, $ltlink) = &libtool_compiler;
5072     &define_variable ('CXXLD', '$(CXX)');
5073     &define_variable ('CXXLINK', $ltlink . '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5075     if (! defined $configure_vars{'CXX'})
5076     {
5077         &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
5078     }
5081 sub lang_header_finish
5083     # Nothing to do.
5086 # This is a helper for both lex and yacc.
5087 sub yacc_lex_finish_helper
5089     return if defined $language_scratch{'lex-yacc-done'};
5090     $language_scratch{'lex-yacc-done'} = 1;
5092     # If there is more than one distinct yacc (resp lex) source file
5093     # in a given directory, then the `ylwrap' program is required to
5094     # allow parallel builds to work correctly.  FIXME: for now, no
5095     # line number.
5096     &require_config_file ($FOREIGN, 'ylwrap');
5097     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
5098     {
5099         &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5100     }
5101     else
5102     {
5103         &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
5104     }
5107 sub lang_yacc_finish
5109     return if defined $language_scratch{'yacc-done'};
5110     $language_scratch{'yacc-done'} = 1;
5112     local ($file, $base, $hname, $cname);
5113     local (%seen_suffix) = ();
5114     local (@yacc_files) = sort keys %yacc_sources;
5115     local ($yacc_count) = scalar (@yacc_files);
5116     foreach $file (@yacc_files)
5117     {
5118         $file =~ /(\..*)$/;
5119         &output_yacc_build_rule ($1, $yacc_count > 1)
5120             if ! defined $seen_suffix{$1};
5121         $seen_suffix{$1} = 1;
5123         $file =~ /^(.*)\.(y|yy|y\+\+|yxx|ypp)$/;
5124         $base = $1;
5125         $hname = 'h';           # Always use `.h' for header file.
5126         ($cname = $2) =~ tr/y/c/;
5128         if ((&variable_defined ('AM_YFLAGS')
5129              && &variable_value ('AM_YFLAGS') =~ /(^|\s)-d(\s|$)/)
5130             || (&variable_defined ('YFLAGS')
5131                 && &variable_value ('YFLAGS') =~ /(^|\s)-d(\s|$)/)) {
5132             # Now generate rule to make the header file.  This should only
5133             # be generated if `yacc -d' specified.
5134             $output_rules .= "${base}.${hname}: ${base}.${cname}\n";
5136             # If the files are built in the build directory, then we want
5137             # to remove them with `make clean'.  If they are in srcdir
5138             # they shouldn't be touched.  However, we can't determine this
5139             # statically, and the GNU rules say that yacc/lex output files
5140             # should be removed by maintainer-clean.  So that's what we
5141             # do.
5142             push (@maintainer_clean_files, "${base}.${hname}");
5144             &push_dist_common ("${base}.${hname}");
5145         }
5146         push (@maintainer_clean_files, "${base}.${cname}");
5147     }
5148     $output_rules .= "\n";
5150     if (! defined $configure_vars{'YACC'})
5151     {
5152         &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
5153     }
5154     if (&variable_defined ('YACCFLAGS'))
5155     {
5156         &am_line_error ('YACCFLAGS',
5157                         "\`YACCFLAGS' obsolete; use \`YFLAGS' instead");
5158     }
5160     if ($yacc_count > 1)
5161     {
5162         &yacc_lex_finish_helper;
5163     }
5166 sub lang_yaccxx_finish
5168     &lang_yacc_finish;
5171 sub lang_lex_finish
5173     return if defined $language_scratch{'lex-done'};
5174     $language_scratch{'lex-done'} = 1;
5176     local (%seen_suffix) = ();
5177     local ($file, $cname);
5178     local ($lex_count) = scalar (keys %lex_sources);
5179     foreach $file (sort keys %lex_sources)
5180     {
5181         $file =~ /(\..*)$/;
5182         &output_lex_build_rule ($1, $lex_count > 1)
5183             if (! defined $seen_suffix{$1});
5184         $seen_suffix{$1} = 1;
5186         # If the files are built in the build directory, then we want
5187         # to remove them with `make clean'.  If they are in srcdir
5188         # they shouldn't be touched.  However, we can't determine this
5189         # statically, and the GNU rules say that yacc/lex output files
5190         # should be removed by maintainer-clean.  So that's what we
5191         # do.
5192         $file =~ /^(.*)\.(l|ll|l\+\+|lxx|lpp)$/;
5193         ($cname = $2) =~ tr/l/c/;
5194         push (@maintainer_clean_files, "${1}.${cname}");
5195     }
5197     if (! defined $configure_vars{'LEX'})
5198     {
5199         &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
5200     }
5201     if (! $seen_decl_yytext)
5202     {
5203         &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
5204     }
5206     if ($lex_count > 1)
5207     {
5208         &yacc_lex_finish_helper;
5209     }
5212 sub lang_lexxx_finish
5214     &lang_lex_finish;
5217 sub lang_asm_finish
5219     # We need the C code for assembly.
5220     &lang_c_finish;
5223 sub lang_f77_finish
5225     # FIXME: this function can be called more than once.  We should
5226     # arrange for it to only do anything the first time through.
5228     local ($ltcompile, $ltlink) = &libtool_compiler;
5230     &define_variable ('F77LD', '$(F77)');
5231     &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5233     if (! defined $configure_vars{'F77'})
5234     {
5235         &am_error ("Fortran 77 source seen but \`F77' not defined in \`configure.in'");
5236     }
5239 # Preprocessed Fortran 77
5241 # The current support for preprocessing Fortran 77 just involves passing
5242 # `$(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)' as additional flags
5243 # to the Fortran 77 compiler, since this is how GNU Make does it; see
5244 # the `GNU Make Manual, Edition 0.51 for `make' Version 3.76 Beta'
5245 # (specifically, from info file `(make)Catalogue of Rules').
5247 # A better approach would be to write an Autoconf test
5248 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
5249 # Fortran 77 compilers know how to do preprocessing.  The Autoconf macro
5250 # AC_PROG_FPP should test the Fortran 77 compiler first for
5251 # preprocessing capabilities, and then fall back on cpp (if cpp were
5252 # available).
5253 sub lang_ppf77_finish
5255     &lang_f77_finish;
5257     # We also handle the case of preprocessing `.F' files into `.f'
5258     # files.
5259     $output_rules .= (".F.f:\n"
5260                       . "\t\$(F77COMPILE) -F \$<\n");
5263 sub lang_ratfor_finish
5265     &lang_f77_finish;
5267     # We also handle the case of preprocessing `.r' files into `.f'
5268     # files.
5269     $output_rules .= (".r.f:\n"
5270                       . "\t\$(RCOMPILE) -F \$<\n");
5273 sub lang_objc_finish
5275     local ($ltcompile, $ltlink) = &libtool_compiler;
5277     &define_variable ('OBJCLD', '$(OBJC)');
5278     &define_variable ('OBJCLINK', $ltlink . '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5280     if (! defined $configure_vars{'OBJC'})
5281     {
5282         &am_error ("Objective C source seen but \`OBJC' not defined in \`configure.in'");
5283     }
5286 sub lang_java_finish
5288     local ($ltcompile, $ltlink) = &libtool_compiler;
5290     &define_variable ('GCJLD', '$(GCJ)');
5291     &define_variable ('GCJLINK', $ltlink . '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5293     if (! defined $configure_vars{'GCJ'})
5294     {
5295         &am_error ("Java source seen but \`GCJ' not defined in \`configure.in'");
5296     }
5299 # A helper which computes a sorted list of all extensions for LANG.
5300 sub lang_extensions
5302     local ($lang) = @_;
5303     local ($key, @r);
5304     foreach $key (sort keys %extension_seen)
5305     {
5306         push (@r, '.' . $key) if $extension_map{$key} eq $lang;
5307     }
5308     return @r;
5311 # A helper which decides whether libtool is needed.  Returns prefix
5312 # for compiler and linker.
5313 sub libtool_compiler
5315     local ($ltcompile, $ltlink) = ('', '');
5316     if ($seen_libtool)
5317     {
5318         &define_configure_variable ("LIBTOOL");
5319         $ltcompile = '$(LIBTOOL) --mode=compile ';
5320         $ltlink = '$(LIBTOOL) --mode=link ';
5321     }
5322     return ($ltcompile, $ltlink);
5325 # Given a hash table of linker names, pick the name that has the most
5326 # precedence.  This is lame, but something has to have global
5327 # knowledge in order to eliminate the conflict.  Add more linkers as
5328 # required.
5329 sub resolve_linker
5331     local (%linkers) = @_;
5333     return 'GCJLINK'
5334         if defined $linkers{'GCJLINK'};
5335     return 'CXXLINK'
5336         if defined $linkers{'CXXLINK'};
5337     return 'F77LINK'
5338         if defined $linkers{'F77LINK'};
5339     return 'OBJCLINK'
5340         if defined $linkers{'OBJCLINK'};
5341     return 'LINK';
5344 # Called to indicate that an extension was used.
5345 sub saw_extension
5347     local ($ext) = @_;
5348     $extension_seen{$ext} = 1;
5351 # Called to ask whether source files have been seen . If HEADERS is 1,
5352 # headers can be included.
5353 sub saw_sources_p
5355     local ($headers) = @_;
5357     if ($headers)
5358     {
5359         $headers = 0;
5360     }
5361     else
5362     {
5363         local (@exts) = &lang_extensions ('header');
5364         $headers = @exts;
5365     }
5367     return scalar keys %extension_seen > $headers;
5370 # Register a single language.  LANGUAGE is the name of the language.
5371 # Each OPTION is either of the form NAME=VALUE, or is a file extension
5372 # (sans `.').
5373 sub register_language
5375     local ($language, @options) = @_;
5377     # Set the defaults.
5378     $language_map{$language . '-ansi-p'} = 0;
5379     $language_map{$language . '-linker'} = '';
5380     $language_map{$language . '-autodep'} = 'no';
5382     local ($iter);
5383     foreach $iter (@options)
5384     {
5385         if ($iter =~ /^(.*)=(.*)$/)
5386         {
5387             $language_map{$language . '-' . $1} = $2;
5388         }
5389         elsif (defined $extension_map{$iter})
5390         {
5391             print STDERR
5392                 "automake: programming error: duplicate extension $iter\n";
5393             exit 1;
5394         }
5395         else
5396         {
5397             $extension_map{$iter} = $language;
5398         }
5399     }
5403 ################################################################
5405 # Pretty-print something.  HEAD is what should be printed at the
5406 # beginning of the first line, FILL is what should be printed at the
5407 # beginning of every subsequent line.
5408 sub pretty_print_internal
5410     local ($head, $fill, @values) = @_;
5412     local ($column) = length ($head);
5413     local ($result) = $head;
5415     # Fill length is number of characters.  However, each Tab
5416     # character counts for eight.  So we count the number of Tabs and
5417     # multiply by 7.
5418     local ($fill_length) = length ($fill);
5419     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5421     local ($bol) = ($head eq '');
5422     foreach (@values)
5423     {
5424         # "71" because we also print a space.
5425         if ($column + length ($_) > 71)
5426         {
5427             $result .= " \\\n" . $fill;
5428             $column = $fill_length;
5429             $bol = 1;
5430         }
5432         $result .= ' ' unless ($bol);
5433         $result .= $_;
5434         $column += length ($_) + 1;
5435         $bol = 0;
5436     }
5438     $result .= "\n";
5439     return $result;
5442 # Pretty-print something and append to output_vars.
5443 sub pretty_print
5445     $output_vars .= &pretty_print_internal (@_);
5448 # Pretty-print something and append to output_rules.
5449 sub pretty_print_rule
5451     $output_rules .= &pretty_print_internal (@_);
5455 ################################################################
5457 # See if a target exists.
5458 sub target_defined
5460     local ($target) = @_;
5461     return defined $targets{$target};
5464 # See if two conditionals are the same.
5465 sub conditional_same
5467     local ($cond1, $cond2) = @_;
5469     return (&conditional_true_when ($cond1, $cond2)
5470             && &conditional_true_when ($cond2, $cond1));
5473 # See if a conditional is true.  Both arguments are conditional
5474 # strings.  This returns true if the first conditional is true when
5475 # the second conditional is true.
5476 sub conditional_true_when
5478     local ($cond, $when) = @_;
5480     # Check the easy case first.
5481     if ($cond eq $when)
5482     {
5483         return 1;
5484     }
5486     # Check each component of $cond, which looks @COND1@@COND2@.
5487     foreach $comp (split ('@', $cond))
5488     {
5489         # The way we split will give null strings between each
5490         # condition.
5491         next if ! $comp;
5493         if (index ($when, '@' . $comp . '@') == -1)
5494         {
5495             return 0;
5496         }
5497     }
5499     return 1;
5502 # Check for an ambiguous conditional.  This is called when a variable
5503 # or target is being defined conditionally.  If we already know about
5504 # a definition that is true under the same conditions, then we have an
5505 # ambiguity.
5506 sub check_ambiguous_conditional
5508     local ($var_name, $cond) = @_;
5509     local (@cond_vals) = split (' ', $conditional{$var_name});
5510     while (@cond_vals)
5511     {
5512         local ($vcond) = shift (@cond_vals);
5513         shift (@cond_vals);
5514         if (&conditional_true_when ($vcond, $cond)
5515             || &conditional_true_when ($cond, $vcond))
5516         {
5517             &am_line_error ($var_name,
5518                             "$var_name multiply defined in condition");
5519         }
5520     }
5523 # See if a variable exists.  The first argument is the variable name,
5524 # and the optional second argument is the condition which we should
5525 # check.  If no condition is given, we currently return true if the
5526 # variable is defined under any condition.
5527 sub variable_defined
5529     local ($var, $cond) = @_;
5530     if (defined $targets{$var})
5531     {
5532         &am_line_error ($var, "\`$var' is target; expected variable");
5533         return 0;
5534     }
5535     elsif (defined $contents{$var})
5536     {
5537         if ($cond && $conditional{$var})
5538         {
5539             # We have been asked to check for a particular condition,
5540             # and the variable is defined conditionally.  We need to
5541             # look through the conditions under which the variable is
5542             # defined, and see if any of them match the conditional we
5543             # have been asked to check.
5544             local (@cond_vars) = split (' ', $conditional{$var});
5545             while (@cond_vars)
5546             {
5547                 if (&conditional_same ($cond, shift (@cond_vars)))
5548                 {
5549                     # Even a conditional examination is good enough
5550                     # for us.  FIXME: really should maintain examined
5551                     # status on a per-condition basis.
5552                     $content_seen{$var} = 1;
5553                     return 1;
5554                 }
5555                 shift (@cond_vars);
5556             }
5558             # The variable is not defined for the given condition.
5559             return 0;
5560         }
5562         $content_seen{$var} = 1;
5563         return 1;
5564     }
5565     return 0;
5568 # Mark a variable as examined.
5569 sub examine_variable
5571     local ($var) = @_;
5572     &variable_defined ($var);
5575 # Quote a value in order to put it in $conditional.  We need to quote
5576 # spaces, and we need to handle null strings, so that we can later
5577 # retrieve values by splitting on space.
5578 sub quote_cond_val
5580     local ($val) = @_;
5581     $val =~ tr/ \t\n/\001\003\004/;
5582     $val = "\002" if $val eq '';
5583     return $val;
5586 # Unquote a value in $conditional.
5587 sub unquote_cond_val
5589     local ($val) = @_;
5590     $val =~ tr/\001\003\004/ \t\n/;
5591     $val =~ s/\002//g;
5592     return $val;
5595 # Return the set of conditions for which a variable is defined.
5597 # If the variable is not defined conditionally, and is not defined in
5598 # terms of any variables which are defined conditionally, then this
5599 # returns the empty list.
5601 # If the variable is defined conditionally, but is not defined in
5602 # terms of any variables which are defined conditionally, then this
5603 # returns the list of conditions for which the variable is defined.
5605 # If the variable is defined in terms of any variables which are
5606 # defined conditionally, then this returns a full set of permutations
5607 # of the subvariable conditions.  For example, if the variable is
5608 # defined in terms of a variable which is defined for @COND_TRUE@,
5609 # then this returns both @COND_TRUE@ and @COND_FALSE@.  This is
5610 # because we will need to define the variable under both conditions.
5612 sub variable_conditions
5614     local ($var) = @_;
5615     local (%uniqify);
5616     local (@uniq_list);
5617     local ($cond);
5619     %vars_scanned = ();
5620     foreach $cond (&variable_conditions_sub ($var, '', ()))
5621     {
5622         $uniqify{$cond} = 1;
5623     }
5625     @uniq_list = sort keys %uniqify;
5626     # Note we cannot just do `return sort keys %uniqify', because this
5627     # function is sometimes used in a scalar context.
5628     return @uniq_list;
5631 # A subroutine of variable_conditions.  We only return conditions
5632 # which are true for all the conditions in @PARENT_CONDS.
5633 sub variable_conditions_sub
5635     local ($var, $parent, @parent_conds) = @_;
5636     local (@new_conds) = ();
5638     if (defined $vars_scanned{$var})
5639     {
5640         &am_line_error ($parent, "variable \`$var' recursively defined");
5641         return ();
5642     }
5643     $vars_scanned{$var} = 1;
5645     if (! $conditional{$var})
5646     {
5647         foreach (split (' ', $contents{$var}))
5648         {
5649             # If a comment seen, just leave.
5650             last if /^#/;
5652             # Handle variable substitutions.
5653             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5654             {
5655                 push (@new_conds,
5656                       &variable_conditions_sub ($1, $var, @parent_conds));
5657             }
5658         }
5660         # Now we want to return all permutations of the subvariable
5661         # conditions.
5662         local (%allconds, $item);
5663         foreach $item (@new_conds)
5664         {
5665             foreach (split ('@', $item))
5666             {
5667                 next if ! $_;
5668                 s/_(TRUE|FALSE)$//;
5669                 $allconds{$_ . '_TRUE'} = 1;
5670             }
5671         }
5673         # Unset our entry in vars_scanned.  We only care about recursive
5674         # definitions.
5675         delete $vars_scanned{$var};
5677         return &variable_conditions_permutations (sort keys %allconds);
5678     }
5680     local (@this_conds) = ();
5681     local (@condvals) = split (' ', $conditional{$var});
5682     while (@condvals)
5683     {
5684         local ($cond) = shift (@condvals);
5685         local ($val) = &unquote_cond_val (shift (@condvals));
5687         if (@parent_conds)
5688         {
5689             local ($ok) = 1;
5690             local ($parent_cond);
5691             foreach $parent_cond (@parent_conds)
5692             {
5693                 if (! &conditional_true_when ($parent_cond, $cond))
5694                 {
5695                     $ok = 0;
5696                     last;
5697                 }
5698             }
5700             next if ! $ok;
5701         }
5703         push (@this_conds, $cond);
5705         push (@parent_conds, $cond);
5706         local (@subvar_conds) = ();
5707         foreach (split (' ', $val))
5708         {
5709             # If a comment seen, just leave.
5710             last if /^#/;
5712             # Handle variable substitutions.
5713             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5714             {
5715                 push (@subvar_conds,
5716                       &variable_conditions_sub ($1, $var, @parent_conds));
5717             }
5718         }
5719         pop (@parent_conds);
5721         # If there are no conditional subvariables, then we want to
5722         # return this condition.  Otherwise, we want to return the
5723         # permutations of the subvariables.
5724         if (! @subvar_conds)
5725         {
5726             push (@new_conds, $cond);
5727         }
5728         else
5729         {
5730             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
5731         }
5732     }
5734     # Unset our entry in vars_scanned.  We only care about recursive
5735     # definitions.
5736     delete $vars_scanned{$var};
5738     return @new_conds
5739         if ! $parent;
5741     # If we are being called on behalf of another variable, we need to
5742     # return all possible permutations of the conditions.  We have
5743     # already handled everything in @this_conds along with their
5744     # subvariables.  We now need to add any permutations that are not
5745     # in @this_conds.
5746     local ($this_cond);
5747     foreach $this_cond (@this_conds)
5748     {
5749         local (@perms) =
5750             &variable_conditions_permutations (split('@', $this_cond));
5751         local ($perm);
5752         foreach $perm (@perms)
5753         {
5754             local ($scan);
5755             local ($ok) = 1;
5756             foreach $scan (@this_conds)
5757             {
5758                 if (&conditional_true_when ($perm, $scan)
5759                     || &conditional_true_when ($scan, $perm))
5760                 {
5761                     $ok = 0;
5762                     last;
5763                 }
5764             }
5765             next if ! $ok;
5767             if (@parent_conds)
5768             {
5769                 local ($ok) = 1;
5770                 local ($parent_cond);
5771                 foreach $parent_cond (@parent_conds)
5772                 {
5773                     if (! &conditional_true_when ($parent_cond, $perm))
5774                     {
5775                         $ok = 0;
5776                         last;
5777                     }
5778                 }
5780                 next if ! $ok;
5781             }
5783             # This permutation was not already handled, and is valid
5784             # for the parents.
5785             push (@new_conds, $perm);
5786         }
5787     }
5789     return @new_conds;
5792 # Subroutine for variable_conditions_sort
5793 sub variable_conditions_cmp
5795     local ($as) = $a;
5796     $as =~ s/[^@]//g;
5797     local ($bs) = $b;
5798     $bs =~ s/[^@]//g;
5799     return (length ($as) <=> length ($bs)
5800             || $a cmp $b);
5803 # Sort a list of conditionals so that only the exclusive ones are
5804 # retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
5805 # @COND1_TRUE@ are in the list, discard the latter.
5806 sub variable_conditions_reduce
5808     local (@conds) = @_;
5809     local (@ret) = ();
5810     local ($cond);
5811     foreach $cond (sort variable_conditions_cmp @conds)
5812     {
5813         local ($ok) = 1;
5814         local ($scan);
5815         foreach $scan (@ret)
5816         {
5817             if (&conditional_true_when ($cond, $scan))
5818             {
5819                 $ok = 0;
5820                 last;
5821             }
5822         }
5823         next if ! $ok;
5824         push (@ret, $cond);
5825     }
5827     return @ret;
5830 # Return a list of permutations of a conditional string.
5831 sub variable_conditions_permutations
5833     local (@comps) = @_;
5834     return ()
5835         if ! @comps;
5836     local ($comp) = shift (@comps);
5837     return &variable_conditions_permutations (@comps)
5838         if $comp eq '';
5839     local ($neg) = $comp;
5840     $neg =~ s/TRUE$/TRUEO/;
5841     $neg =~ s/FALSE$/TRUE/;
5842     $neg =~ s/TRUEO$/FALSE/;
5843     local (@ret);
5844     local ($sub);
5845     foreach $sub (&variable_conditions_permutations (@comps))
5846     {
5847         push (@ret, '@' . $comp . '@' . $sub);
5848         push (@ret, '@' . $neg . '@' . $sub);
5849     }
5850     if (! @ret)
5851     {
5852         push (@ret, '@' . $comp . '@');
5853         push (@ret, '@' . $neg . '@');
5854     }
5855     return @ret;
5858 # Warn if a variable is conditionally defined.  This is called if we
5859 # are using the value of a variable.
5860 sub variable_conditionally_defined
5862     local ($var, $parent) = @_;
5863     if ($conditional{$var})
5864     {
5865         if ($parent)
5866         {
5867             &am_line_error ($parent,
5868                             "warning: automake does not support conditional definition of $var in $parent");
5869         }
5870         else
5871         {
5872             &am_line_error ($parent,
5873                             "warning: automake does not support $var being defined conditionally")
5874         }
5875     }
5878 # Get the value of a variable.  This just returns $contents, but warns
5879 # if the variable is conditionally defined.
5880 sub variable_value
5882     local ($var) = @_;
5883     &variable_conditionally_defined ($var);
5884     return $contents{$var};
5887 # Convert a variable value to a list, split as whitespace.  This will
5888 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5889 # substitutions.  If COND is 'all', then all values under all
5890 # conditions should be returned; if COND is a particular condition
5891 # (all conditions are surrounded by @...@) then only the value for
5892 # that condition should be returned; otherwise, warn if VAR is
5893 # conditionally defined.  SCANNED is a global hash listing whose keys
5894 # are all the variables already scanned; it is an error to rescan a
5895 # variable.
5896 sub value_to_list
5898     local ($var, $val, $cond) = @_;
5899     local (@result);
5901     # Strip backslashes
5902     $val =~ s/\\(\n|$)/ /g;
5904     foreach (split (' ', $val))
5905     {
5906         # If a comment seen, just leave.
5907         last if /^#/;
5909         # Handle variable substitutions.
5910         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
5911         {
5912             local ($varname) = $1;
5914             # If the user uses a losing variable name, just ignore it.
5915             # This isn't ideal, but people have requested it.
5916             next if ($varname =~ /\@.*\@/);
5918             local ($from, $to);
5919             local (@temp_list);
5920             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
5921             {
5922                 $varname = $1;
5923                 $to = $3;
5924                 ($from = $2) =~ s/(\W)/\\$1/g;
5925             }
5927             # Find the value.
5928             @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
5930             # Now rewrite the value if appropriate.
5931             if ($from)
5932             {
5933                 grep (s/$from$/$to/, @temp_list);
5934             }
5936             push (@result, @temp_list);
5937         }
5938         else
5939         {
5940             push (@result, $_);
5941         }
5942     }
5944     return @result;
5947 # Return contents of variable as list, split as whitespace.  This will
5948 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5949 # substitutions.  If COND is 'all', then all values under all
5950 # conditions should be returned; if COND is a particular condition
5951 # (all conditions are surrounded by @...@) then only the value for
5952 # that condition should be returned; otherwise, warn if VAR is
5953 # conditionally defined.  If PARENT is specified, it is the name of
5954 # the including variable; this is only used for error reports.
5955 sub variable_value_as_list_worker
5957     local ($var, $cond, $parent) = @_;
5958     local (@result);
5960     if (defined $targets{$var})
5961     {
5962         &am_line_error ($var, "\`$var' is target; expected variable");
5963     }
5964     elsif (! defined $contents{$var})
5965     {
5966         &am_line_error ($parent, "variable \`$var' not defined");
5967     }
5968     elsif (defined $vars_scanned{$var})
5969     {
5970         # `vars_scanned' is a global we use to keep track of which
5971         # variables we've already examined.
5972         &am_line_error ($parent, "variable \`$var' recursively defined");
5973     }
5974     elsif ($cond eq 'all' && $conditional{$var})
5975     {
5976         $vars_scanned{$var} = 1;
5977         local (@condvals) = split (' ', $conditional{$var});
5978         while (@condvals)
5979         {
5980             shift (@condvals);
5981             local ($val) = &unquote_cond_val (shift (@condvals));
5982             push (@result, &value_to_list ($var, $val, $cond));
5983         }
5984     }
5985     elsif ($cond && $conditional{$var})
5986     {
5987         $vars_scanned{$var} = 1;
5988         local (@condvals) = split (' ', $conditional{$var});
5989         local ($onceflag);
5990         while (@condvals)
5991         {
5992             local ($vcond) = shift (@condvals);
5993             local ($val) = &unquote_cond_val (shift (@condvals));
5994             if (&conditional_true_when ($vcond, $cond))
5995             {
5996                 # Warn if we have an ambiguity.  It's hard to know how
5997                 # to handle this case correctly.
5998                 &variable_conditionally_defined ($var, $parent)
5999                     if $onceflag;
6000                 $onceflag = 1;
6001                 push (@result, &value_to_list ($var, $val, $cond));
6002             }
6003         }
6004     }
6005     else
6006     {
6007         $vars_scanned{$var} = 1;
6008         &variable_conditionally_defined ($var, $parent);
6009         $content_seen{$var} = 1;
6010         push (@result, &value_to_list ($var, $contents{$var}, $cond));
6011     }
6013     # Unset our entry in vars_scanned.  We only care about recursive
6014     # definitions.
6015     delete $vars_scanned{$var};
6017     return @result;
6020 # This is just a wrapper for variable_value_as_list_worker that
6021 # initializes the global hash `vars_scanned'.  This hash is used to
6022 # avoid infinite recursion.
6023 sub variable_value_as_list
6025     local ($var, $cond, $parent) = @_;
6026     %vars_scanned = ();
6027     return &variable_value_as_list_worker ($var, $cond, $parent);
6030 # Define a new variable, but only if not already defined.
6031 sub define_variable
6033     local ($var, $value) = @_;
6035     if (! defined $contents{$var})
6036     {
6037         $output_vars .= $var . ' = ' . $value . "\n";
6038         $contents{$var} = $value;
6039         $content_seen{$var} = 1;
6040     }
6041     elsif ($var_was_plus_eq{$var})
6042     {
6043         &am_line_error ($var, "internally generated variable \`$var' was set with \`+='");
6044     }
6047 # Like define_variable, but the value is a list, and the variable may
6048 # be defined conditionally.  The second argument is the conditional
6049 # under which the value should be defined; this should be the empty
6050 # string to define the variable unconditionally.  The third argument
6051 # is a list holding the values to use for the variable.  The value is
6052 # pretty printed in the output file.
6053 sub define_pretty_variable
6055     local ($var, $cond, @value) = @_;
6056     if (! defined $contents{$var}
6057         || ($cond && ! &variable_defined ($var, $cond)))
6058     {
6059         $contents{$var} = join (' ', @value);
6060         if ($cond)
6061         {
6062             if ($conditional{$var})
6063             {
6064                 $conditional{$var} .= ' ';
6065             }
6066             else
6067             {
6068                 $conditional{$var} = '';
6069             }
6070             $conditional{$var} .= ($cond
6071                                    . ' '
6072                                    . &quote_cond_val ($contents{$var}));
6073         }
6074         &pretty_print ($cond . $var . ' = ', $cond, @value);
6075         $content_seen{$var} = 1;
6076     }
6079 # Like define_variable, but define a variable to be the configure
6080 # substitution by the same name.
6081 sub define_configure_variable
6083     local ($var) = @_;
6084     local ($value) = '@' . $var . '@';
6085     &define_variable ($var, $value);
6088 # Define a compiler variable.  We also handle defining the `LT'
6089 # version of the command when using libtool.
6090 sub define_compiler_variable
6092     local ($var, $ltcompile, $value) = @_;
6093     local ($name) = $var;
6094     &define_variable ($name, $value);
6095     &define_variable ('LT' . $name, $ltcompile . $value)
6096         if $seen_libtool;
6099 # Define a variable that represents a program to run.  If in Cygnus
6100 # mode, the program is searched for in the build (or source) tree.
6101 # Otherwise no searching is done at all.  Arguments are:
6102 # * VAR      Name of variable to define
6103 # * WHATDIR  Either `src' or `build', depending on where program should
6104 #            be found.  (runtest is in srcdir!)
6105 # * SUBDIR   Subdir of top-level dir
6106 # * PROGRAM  Name of program
6107 # * OVERRIDE If specified, the name of the program to use when not in
6108 #            Cygnus mode.  Defaults to PROGRAM.
6109 sub define_program_variable
6111     local ($var, $whatdir, $subdir, $program, $override) = @_;
6113     if (! $override)
6114     {
6115         $override = $program;
6116     }
6118     if ($cygnus_mode)
6119     {
6120         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
6121                          . $subdir . '/' . $program);
6122         &define_variable ($var, ('`if test -f ' . $full
6123                                  . '; then echo ' . $full . '; else echo '
6124                                  . $program . '; fi`'));
6125     }
6126     else
6127     {
6128         &define_variable ($var, $override);
6129     }
6133 ################################################################
6135 # Read Makefile.am and set up %contents.  Simultaneously copy lines
6136 # from Makefile.am into $output_trailer or $output_vars as
6137 # appropriate.  NOTE we put rules in the trailer section.  We want
6138 # user rules to come after our generated stuff.
6139 sub read_am_file
6141     local ($amfile) = @_;
6142     local (*AM_FILE);
6144     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
6145     print "automake: reading $amfile\n" if $verbose;
6147     local ($saw_bk) = 0;
6148     local ($was_rule) = 0;
6149     local ($spacing) = '';
6150     local ($comment) = '';
6151     local ($last_var_name) = '';
6152     local ($blank) = 0;
6154     while (<AM_FILE>)
6155     {
6156         if (/$IGNORE_PATTERN/o)
6157         {
6158             # Merely delete comments beginning with two hashes.
6159         }
6160         elsif (/$WHITE_PATTERN/o)
6161         {
6162             # Stick a single white line before the incoming macro or rule.
6163             $spacing = "\n";
6164             $blank = 1;
6165         }
6166         elsif (/$COMMENT_PATTERN/o)
6167         {
6168             # Stick comments before the incoming macro or rule.  Make
6169             # sure a blank line preceeds first block of comments.
6170             $spacing = "\n" unless $blank;
6171             $blank = 1;
6172             $comment .= $spacing . $_;
6173             $spacing = '';
6174         }
6175         else
6176         {
6177             last;
6178         }
6179     }
6181     $output_vars .= $comment . "\n";
6182     $comment = '';
6183     $spacing = "\n";
6185     local ($is_ok_macro);
6186     while ($_)
6187     {
6188         $_ .= "\n"
6189             unless substr ($_, -1, 1) eq "\n";
6191         # Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
6192         # used by users.  @MAINT@ is an anachronism now.
6193         $_ =~ s/\@MAINT\@//g
6194             unless $seen_maint_mode;
6196         if (/$IGNORE_PATTERN/o)
6197         {
6198             # Merely delete comments beginning with two hashes.
6199         }
6200         elsif (/$WHITE_PATTERN/o)
6201         {
6202             # Stick a single white line before the incoming macro or rule.
6203             $spacing = "\n";
6204             &am_line_error ($., "blank line following trailing backslash")
6205                 if $saw_bk;
6206         }
6207         elsif (/$COMMENT_PATTERN/o)
6208         {
6209             # Stick comments before the incoming macro or rule.
6210             $comment .= $spacing . $_;
6211             $spacing = '';
6212             &am_line_error ($., "comment following trailing backslash")
6213                 if $saw_bk;
6214         }
6215         elsif ($saw_bk)
6216         {
6217             if ($was_rule)
6218             {
6219                 $output_trailer .= join ('', @conditional_stack) . $_;
6220                 $saw_bk = /\\$/;
6221             }
6222             else
6223             {
6224                 $saw_bk = /\\$/;
6225                 $contents{$last_var_name} .= ' '
6226                     unless $contents{$last_var_name} =~ /\s$/;
6227                 $contents{$last_var_name} .= $_;
6228                 if (@conditional_stack)
6229                 {
6230                     $conditional{$last_var_name} .= &quote_cond_val ($_);
6231                 }
6232             }
6233         }
6234         elsif (/$IF_PATTERN/o)
6235         {
6236             &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
6237                 if (! $configure_cond{$1});
6238             push (@conditional_stack, "\@" . $1 . "_TRUE\@");
6239         }
6240         elsif (/$ELSE_PATTERN/o)
6241         {
6242             if (! @conditional_stack)
6243             {
6244                 &am_line_error ($., "else without if");
6245             }
6246             elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
6247             {
6248                 &am_line_error ($., "else after else");
6249             }
6250             else
6251             {
6252                 $conditional_stack[$#conditional_stack]
6253                     =~ s/_TRUE\@$/_FALSE\@/;
6254             }
6255         }
6256         elsif (/$ENDIF_PATTERN/o)
6257         {
6258             if (! @conditional_stack)
6259             {
6260                 &am_line_error ($., "endif without if");
6261             }
6262             else
6263             {
6264                 pop @conditional_stack;
6265             }
6266         }
6267         elsif (/$RULE_PATTERN/o)
6268         {
6269             # Found a rule.
6270             $was_rule = 1;
6271             if (defined $contents{$1}
6272                 && (@conditional_stack
6273                     ? ! defined $conditional{$1}
6274                     : defined $conditional{$1}))
6275             {
6276                 &am_line_error ($1,
6277                                 "$1 defined both conditionally and unconditionally");
6278             }
6279             # Value here doesn't matter; for targets we only note
6280             # existence.
6281             $contents{$1} = 1;
6282             $targets{$1} = 1;
6283             local ($cond_string) = join ('', @conditional_stack);
6284             if (@conditional_stack)
6285             {
6286                 if ($conditional{$1})
6287                 {
6288                     &check_ambiguous_conditional ($1, $cond_string);
6289                     $conditional{$1} .= ' ';
6290                 }
6291                 else
6292                 {
6293                     $conditional{$1} = '';
6294                 }
6295                 $conditional{$1} .= $cond_string . ' 1';
6296             }
6297             $content_lines{$1} = $.;
6298             $output_trailer .= $comment . $spacing . $cond_string . $_;
6299             $comment = $spacing = '';
6300             $saw_bk = /\\$/;
6302             # Check the rule for being a suffix rule. If so, store in
6303             # a hash.
6305             local ($source_suffix);
6306             local ($object_suffix);
6308             if (($source_suffix, $object_suffix) = ($1 =~ $SUFFIX_RULE_PATTERN)) 
6309             {
6310               $suffix_rules{$source_suffix} = $object_suffix;
6311               print "Sources ending in .$source_suffix become .$object_suffix\n" if $verbose;
6312               $source_suffix_pattern = "(" . join('|', keys %suffix_rules) . ")";
6313             }
6315             # FIXME: make sure both suffixes are in SUFFIXES? Or set
6316             # SUFFIXES from suffix_rules?
6317         }
6318         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
6319                || /$BOGUS_MACRO_PATTERN/o)
6320         {
6321             # Found a macro definition.
6322             $was_rule = 0;
6323             $last_var_name = $1;
6324             if (defined $contents{$1}
6325                 && (@conditional_stack
6326                     ? ! defined $conditional{$1}
6327                     : defined $conditional{$1}))
6328             {
6329                 &am_line_error ($1,
6330                                 "$1 defined both conditionally and unconditionally");
6331             }
6332             local ($value);
6333             if ($3 ne '' && substr ($3, -1) eq "\\")
6334             {
6335                 # We preserve the `\' because otherwise the long lines
6336                 # that are generated will be truncated by broken
6337                 # `sed's.
6338                 $value = $3 . "\n";
6339             }
6340             else
6341             {
6342                 $value = $3;
6343             }
6344             local ($type) = $2;
6346             if (! defined $contents{$last_var_name})
6347             {
6348                 # The first assignment to a macro sets the line
6349                 # number.  Ideally I suppose we would associate line
6350                 # numbers with random bits of text.
6351                 $content_lines{$last_var_name} = $.;
6353                 # If first assignment, set `+=' indicator.
6354                 $var_was_plus_eq{$last_var_name} =
6355                     ($type eq '+'
6356                      && ! defined $am_var_defs{$last_var_name});
6357             }
6359             if ($type eq '+')
6360             {
6361                 if (! defined $contents{$last_var_name}
6362                     && defined $am_var_defs{$last_var_name})
6363                 {
6364                     $contents{$last_var_name} = $am_var_defs{$last_var_name};
6365                 }
6366                 if (substr ($contents{$last_var_name}, -1) eq "\n")
6367                 {
6368                     # Insert a backslash before a trailing newline.
6369                     $contents{$last_var_name}
6370                         = substr ($contents{$last_var_name}, 0, -1) . "\\\n";
6371                 }
6372                 $contents{$last_var_name} .= ' ' . $value;
6373             }
6374             else
6375             {
6376                 $contents{$last_var_name} = $value;
6377             }
6378             local ($cond_string) = join ('', @conditional_stack);
6379             if (@conditional_stack)
6380             {
6381                 local ($found) = 0;
6382                 local ($val);
6383                 if ($conditional{$last_var_name})
6384                 {
6385                     if ($type eq '+')
6386                     {
6387                         # If we're adding to the conditional, and it
6388                         # exists, then we might want to simply replace
6389                         # the old value with the new one.
6390                         local (@new_vals, @cond_vals);
6391                         @cond_vals = split (' ', $conditional{$last_var_name});
6392                         while (@cond_vals)
6393                         {
6394                             local ($vcond) = shift (@cond_vals);
6395                             push (@new_vals, $vcond);
6396                             if (&conditional_same ($vcond, $cond_string))
6397                             {
6398                                 $found = 1;
6399                                 $val = (&unquote_cond_val (shift (@cond_vals))
6400                                         . ' ' . $value);
6401                                 push (@new_vals, &quote_cond_val ($val));
6402                             }
6403                             else
6404                             {
6405                                 push (@new_vals, shift (@cond_vals));
6406                             }
6407                         }
6408                         if ($found)
6409                         {
6410                             $conditional{$last_var_name}
6411                                 = join (' ', @new_vals);
6412                         }
6413                     }
6415                     if (! $found)
6416                     {
6417                         &check_ambiguous_conditional ($last_var_name,
6418                                                       $cond_string);
6419                         $conditional{$last_var_name} .= ' ';
6420                         $val = $value;
6421                     }
6422                 }
6423                 else
6424                 {
6425                     $conditional{$last_var_name} = '';
6426                     $val = $contents{$last_var_name};
6427                 }
6428                 if (! $found)
6429                 {
6430                     $conditional{$last_var_name} .= ($cond_string
6431                                                      . ' '
6432                                                      . &quote_cond_val ($val));
6433                 }
6434             }
6436             # FIXME: this doesn't always work correctly; it will group
6437             # all comments for a given variable, no matter where
6438             # defined.
6439             $am_vars{$last_var_name} = $comment . $spacing;
6440             $def_type{$last_var_name} = ($type eq ':') ? ':' : '';
6441             push (@var_list, $last_var_name);
6442             $comment = $spacing = '';
6443             $saw_bk = /\\$/;
6445             # Error if bogus.
6446             &am_line_error ($., "bad macro name \`$last_var_name'")
6447                 if ! $is_ok_macro;
6448         }
6449         elsif (/$INCLUDE_PATTERN/o)
6450         {
6451             local ($path) = $1;
6453             if ($path =~ s/^\$\(top_srcdir\)\///)
6454             {
6455                 push (@include_stack, "\$\(top_srcdir\)/$path");
6456             }
6457             else
6458             {
6459                 $path =~ s/\$\(srcdir\)\///;
6460                 push (@include_stack, "\$\(srcdir\)/$path");
6461                 $path = $relative_dir . "/" . $path;
6462             }
6463             &read_am_file ($path);
6464         }
6465         else
6466         {
6467             # This isn't an error; it is probably a continued rule.
6468             # In fact, this is what we assume.
6469             $was_rule = 1;
6470             $output_trailer .= ($comment . $spacing
6471                                 . join ('', @conditional_stack) . $_);
6472             $comment = $spacing = '';
6473             $saw_bk = /\\$/;
6474         }
6476         $_ = <AM_FILE>;
6477     }
6479     $output_trailer .= $comment;
6481     &am_error ("unterminated conditionals: " . join (' ', @conditional_stack))
6482         if (@conditional_stack);
6485 # A helper for read_main_am_file which initializes configure variables
6486 # and variables from header-vars.am.  This is a subr so we can call it
6487 # twice.
6488 sub define_standard_variables
6490     # Compute relative location of the top object directory.
6491     local (@topdir) = ();
6492     foreach (split (/\//, $relative_dir))
6493     {
6494         next if $_ eq '.' || $_ eq '';
6495         if ($_ eq '..')
6496         {
6497             pop @topdir;
6498         }
6499         else
6500         {
6501             push (@topdir, '..');
6502         }
6503     }
6504     @topdir = ('.') if ! @topdir;
6506     $top_builddir = join ('/', @topdir);
6507     local ($build_rx);
6508     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
6509     $output_vars .= &file_contents_with_transform
6510                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
6511                          'header-vars');
6513     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
6514     # this should use generic %configure_vars method.
6515     if ($seen_canonical)
6516     {
6517         local ($curs, %vars);
6518         $vars{'host_alias'} = 'host_alias';
6519         $vars{'host_triplet'} = 'host';
6520         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
6521         {
6522             $vars{'build_alias'} = 'build_alias';
6523             $vars{'build_triplet'} = 'build';
6524             $vars{'target_alias'} = 'target_alias';
6525             $vars{'target_triplet'} = 'target';
6526         }
6527         foreach $curs (sort keys %vars)
6528         {
6529             $output_vars .= "$curs = \@$vars{$curs}\@\n";
6530             $contents{$curs} = "\@$vars{$curs}\@";
6531         }
6532     }
6534     local ($curs);
6535     foreach $curs (sort keys %configure_vars)
6536     {
6537         &define_configure_variable ($curs);
6538     }
6541 # Read main am file.
6542 sub read_main_am_file
6544     local ($amfile) = @_;
6546     # The keys here are variables we want to dump at the end of this
6547     # function.  The values are corresponding comments.
6548     local (%am_vars) = ();
6549     local (@var_list) = ();
6550     local (%def_type) = ();
6552     # This supports the strange variable tricks we are about to play.
6553     if (scalar keys %contents > 0)
6554     {
6555         print STDERR "automake: programming error: variable defined before read_main_am_file\n";
6556         exit 1;
6557     }
6559     # We want to predefine as many variables as possible.  This lets
6560     # the user set them with `+=' in Makefile.am.  However, we don't
6561     # want these initial definitions to end up in the output quite
6562     # yet.  So we adopt a hack: read the `.am' file twice, throwing
6563     # away the output the first time.  We also squirrel away a list of
6564     # all the variables defined by the .am file so that we know which
6565     # ones to remove from the content list.
6567     # First pass.
6568     &define_standard_variables;
6569     local (%saved_contents) = %contents;
6571     # Read user file, but discard text of variable assignments we just
6572     # made.
6573     $output_vars = '';
6574     &read_am_file ($amfile);
6576     # Now dump the variables that were defined.  We do it in the same
6577     # order in which they were defined (skipping duplicates).
6578     local (%done);
6579     foreach $curs (@var_list)
6580     {
6581         next if $done{$curs};
6582         $done{$curs} = 1;
6584         $output_vars .= $am_vars{$curs};
6585         if ($conditional{$curs})
6586         {
6587             local (@cond_vals) = split (' ', $conditional{$curs});
6588             while (@cond_vals)
6589             {
6590                 local ($vcond) = shift (@cond_vals);
6591                 local ($val) = &unquote_cond_val (shift (@cond_vals));
6592                 $output_vars .= ($vcond . $curs . ' '
6593                                  . $def_type{$curs} . "= ");
6594                 local ($line);
6595                 foreach $line (split ("\n", $val))
6596                 {
6597                     $output_vars .= $vcond . $line . "\n";
6598                 }
6599                 $output_vars .= "\n"
6600                     if $val eq '';
6601             }
6602         }
6603         else
6604         {
6605             $output_vars .= ($curs . ' ' . $def_type{$curs} . '= '
6606                              . $contents{$curs} . "\n");
6607         }
6608     }
6610     # Generate copyright header for generated Makefile.in.
6611     local ($ov) = $output_vars;
6612     $output_vars = ("# $in_file_name generated automatically by automake "
6613                    . $VERSION . " from $am_file_name\n");
6614     $output_vars .= $gen_copyright;
6616     # Now go through and delete all the variables that the user did
6617     # not change.
6618     local ($var);
6619     foreach $var (keys %saved_contents)
6620     {
6621         if ($contents{$var} eq $saved_contents{$var})
6622         {
6623             delete $contents{$var};
6624         }
6625     }
6627     # Re-read the standard variables, and this time keep their
6628     # contributions to the output.  Then add the user's output to the
6629     # end.
6630     &define_standard_variables;
6631     $output_vars .= $ov;
6635 ################################################################
6637 sub initialize_global_constants
6639     # Values for AC_CANONICAL_*
6640     $AC_CANONICAL_HOST = 1;
6641     $AC_CANONICAL_SYSTEM = 2;
6643     # Associative array of standard directory names.  Entry is TRUE if
6644     # corresponding directory should be installed during
6645     # 'install-exec' phase.
6646     %exec_dir_p =
6647         ('bin', 1,
6648          'sbin', 1,
6649          'libexec', 1,
6650          'data', 0,
6651          'sysconf', 1,
6652          'localstate', 1,
6653          'lib', 1,
6654          'info', 0,
6655          'man', 0,
6656          'include', 0,
6657          'oldinclude', 0,
6658          'pkgdata', 0,
6659          'pkglib', 1,
6660          'pkginclude', 0
6661          );
6663     # Commonly found files we look for and automatically include in
6664     # DISTFILES.
6665     @common_files =
6666         (
6667          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
6668          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
6669          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
6670          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
6671          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
6672          'ylwrap', 'acinclude.m4', @libtoolize_files,
6673          'missing', 'compile'
6674          );
6676     # Commonly used files we auto-include, but only sometimes.
6677     @common_sometimes =
6678         (
6679          "aclocal.m4", "acconfig.h", "config.h.top",
6680          "config.h.bot", "stamp-h.in", 'stamp-vti'
6681          );
6683     $USAGE = "\
6684   -a, --add-missing     add missing standard files to package
6685   --amdir=DIR           directory storing config files
6686   --build-dir=DIR       directory where build being done (for dependencies)
6687   -c, --copy            with -a, copy missing files (default is symlink)
6688   --cygnus              assume program is part of Cygnus-style tree
6689   --foreign             set strictness to foreign
6690   --gnits               set strictness to gnits
6691   --gnu                 set strictness to gnu
6692   --help                print this help, then exit
6693   -i, --include-deps    include generated dependencies in Makefile.in
6694   --no-force            only update Makefile.in's that are out of date
6695   -o DIR, --output-dir=DIR
6696                         put generated Makefile.in's into DIR
6697   --srcdir-name=DIR     name used for srcdir (for dependencies)
6698   -v, --verbose         verbosely list files processed
6699   --version             print version number, then exit\n";
6701     # Copyright on generated Makefile.ins.
6702     $gen_copyright = "\
6703 # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
6704 # This Makefile.in is free software; the Free Software Foundation
6705 # gives unlimited permission to copy and/or distribute it,
6706 # with or without modifications, as long as this notice is preserved.
6708 # This program is distributed in the hope that it will be useful,
6709 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
6710 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6711 # PARTICULAR PURPOSE.
6714     # This complex find command will try to avoid changing the modes of
6715     # links into the source tree, in case they're hard-linked.  It will
6716     # also make directories writable by everybody, because some
6717     # brain-dead tar implementations change ownership and permissions of
6718     # a directory before extracting the files, thus becoming unable to
6719     # extract them.
6720     # Ignore return result from chmod, because it might give an error
6721     # if we chmod a symlink.
6722     $dist_header = '    -find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \\
6723           ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \\
6724           ! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \\
6725         || chmod -R a+r $(distdir)
6727     $dist{'dist-bzip2'} = ("\t"
6728                            . '$(AMTAR) ch$(AMTARFLAGS)f - $(distdir) | bzip --best -c > $(distdir).bz2'
6729                            . "\n");
6730     $dist{'dist-tarZ'} = ("\t"
6731                      . '$(AMTAR) ch$(AMTARFLAGS)f - $(distdir) | compress -c > $(distdir).tar.Z'
6732                      . "\n");
6733     $dist{'dist-shar'} = ("\t"
6734                      . 'shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).shar.gz'
6735                      . "\n");
6736     $dist{'dist-zip'} = ("\t" . '-rm -f $(distdir).zip' . "\n" .
6737                          "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n");
6738     $dist{'dist'} = ("\t"
6739                      .  '$(AMTAR) ch$(AMTARFLAGS)f - $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).tar.gz'
6740                      . "\n");
6741     $dist_trailer = "\t" . '-rm -rf $(distdir)' . "\n";
6744 # (Re)-Initialize per-Makefile.am variables.
6745 sub initialize_per_input
6747     # These two variables are used when generating each Makefile.in.
6748     # They hold the Makefile.in until it is ready to be printed.
6749     $output_rules = '';
6750     $output_vars = '';
6751     $output_trailer = '';
6752     $output_all = '';
6753     $output_header = '';
6755     # Suffixes found during a run.
6756     @suffixes = ();
6758     # This holds the contents of a Makefile.am, as parsed by
6759     # read_am_file.
6760     %contents = ();
6762     # This holds the names which are targets.  These also appear in
6763     # %contents.
6764     %targets = ();
6766     # This maps a variable name onto a flag.  The flag is true iff the
6767     # variable was first defined with `+='.
6768     %var_was_plus_eq = ();
6770     # This holds definitions of all variables defined in .am files.
6771     # This is used during startup to determine which variables can be
6772     # assigned with `+='.
6773     %am_var_defs = ();
6775     # For a variable or target which is defined conditionally, this
6776     # holds an array of the conditional values.  The array is composed
6777     # of pairs of condition strings (the variables which configure
6778     # will substitute) and values (the value of a target is
6779     # meaningless).  For an unconditional variable, this is empty.
6780     %conditional = ();
6782     # This holds the line numbers at which various elements of
6783     # %contents are defined.
6784     %content_lines = ();
6786     # This holds a 1 if a particular variable was examined.
6787     %content_seen = ();
6789     # This is the conditional stack.
6790     @conditional_stack = ();
6792     # This holds the set of included files.
6793     @include_stack = ();
6795     # This holds the "relative directory" of the current Makefile.in.
6796     # Eg for src/Makefile.in, this is "src".
6797     $relative_dir = '';
6799     # This holds a list of files that are included in the
6800     # distribution.
6801     %dist_common = ();
6803     # List of dependencies for the obvious targets.
6804     @install_data = ();
6805     @install_exec = ();
6806     @uninstall = ();
6807     @installdirs = ();
6809     @info = ();
6810     @dvi = ();
6811     @all = ();
6812     @check = ();
6813     @check_tests = ();
6814     @installcheck = ();
6815     @clean = ();
6817     @phony = ();
6819     # A list of files deleted by `maintainer-clean'.
6820     @maintainer_clean_files = ();
6822     # These are pretty obvious, too.  They are used to define the
6823     # SOURCES and OBJECTS variables.
6824     @sources = ();
6825     @objects = ();
6826     # Sources which go in the distribution.
6827     @dist_sources = ();
6829     # This hash maps object file names onto their corresponding source
6830     # file names.  This is used to ensure that each object is created
6831     # by a single source file.
6832     %object_map = ();
6834     # This keeps track of the directories for which we've already
6835     # created `.dirstamp' code.
6836     %directory_map = ();
6838     # These variables track inclusion of various compile-related .am
6839     # files.  $included_generic_compile is TRUE if the basic code has
6840     # been included.  $included_knr_compile is TRUE if the ansi2knr
6841     # code has been included.  $included_libtool_compile is TRUE if
6842     # libtool support has been included.
6843     $included_generic_compile = 0;
6844     $included_knr_compile = 0;
6845     $included_libtool_compile = 0;
6847     # TRUE if install targets should work recursively.
6848     $recursive_install = 0;
6850     # All .P files.
6851     %dep_files = ();
6853     # Strictness levels.
6854     $strictness = $default_strictness;
6855     $strictness_name = $default_strictness_name;
6857     # Options from AUTOMAKE_OPTIONS.
6858     %options = ();
6860     # Whether or not dependencies are handled.  Can be further changed
6861     # in handle_options.
6862     $use_dependencies = $cmdline_use_dependencies;
6864     # Per Makefile.am.
6865     $local_maint_charset = $maint_charset;
6867     # All yacc and lex source filenames for this directory.  Use
6868     # filenames instead of raw count so that multiple instances are
6869     # counted correctly (eg one yacc file can appear in multiple
6870     # programs without harm).
6871     %yacc_sources = ();
6872     %lex_sources = ();
6874     # This is a list of all targets to run during "make dist".
6875     @dist_targets = ();
6877     # Keys in this hash are the basenames of files which must depend
6878     # on ansi2knr.
6879     %de_ansi_files = ();
6881     # This maps the source extension of a suffix rule to its
6882     # corresponding output extension.
6883     %suffix_rules = ();
6885     # This is the name of the recursive `all' target to use.
6886     $all_target = 'all-recursive';
6888     # This keeps track of which extensions we've seen (that we care
6889     # about).
6890     %extension_seen = ();
6892     # This is random scratch space for the language finish functions.
6893     # Don't randomly overwrite it; examine other uses of keys first.
6894     %language_scratch = ();
6896     # We keep track of which objects need special (per-executable)
6897     # handling on a per-language basis.
6898     %lang_specific_files = ();
6902 ################################################################
6904 # Return contents of a file from $am_dir, automatically skipping
6905 # macros or rules which are already known.  Runs command on each line
6906 # as it is read; this command can modify $_.
6907 sub file_contents_with_transform
6909     local ($command, $basename) = @_;
6910     local ($file) = $am_dir . '/' . $basename . '.am';
6912     if ($command ne '' && substr ($command, -1) ne ';')
6913     {
6914         die "automake: programming error in file_contents_with_transform: $command\n";
6915     }
6917     open (FC_FILE, $file)
6918         || die "automake: installation error: cannot open \`$file'\n";
6919     # Looks stupid?
6920     # print "automake: reading $file\n" if $verbose;
6922     local ($was_rule) = 0;
6923     local ($result_vars) = '';
6924     local ($result_rules) = '';
6925     local ($comment) = '';
6926     local ($spacing) = "\n";
6927     local ($skipping) = 0;
6928     local ($had_chars);
6930     while (<FC_FILE>)
6931     {
6932         $_ =~ s/\@MAINTAINER_MODE_TRUE\@//g
6933             unless $seen_maint_mode;
6935         $had_chars = length ($_) && $_ ne "\n";
6936         eval $command;
6937         # If the transform caused all the characters to go away, then
6938         # ignore the line.  Why do this?  Because in Perl 4, a "next"
6939         # inside of an eval doesn't affect a loop outside the eval.
6940         # So we can't pass in a "transform" that uses next.  We used
6941         # to do this.  "Empty" also means consisting of a single
6942         # newline.
6943         next if $had_chars && ($_ eq '' || $_ eq "\n");
6945         if (/$IGNORE_PATTERN/o)
6946         {
6947             # Merely delete comments beginning with two hashes.
6948         }
6949         elsif (/$WHITE_PATTERN/o)
6950         {
6951             # Stick a single white line before the incoming macro or rule.
6952             $spacing = "\n";
6953             &am_line_error ($., "blank line following trailing backslash")
6954                 if $saw_bk;
6955         }
6956         elsif (/$COMMENT_PATTERN/o)
6957         {
6958             # Stick comments before the incoming macro or rule.
6959             $comment .= $spacing . $_;
6960             $spacing = '';
6961             &am_line_error ($., "comment following trailing backslash")
6962                 if $saw_bk;
6963         }
6964         elsif ($saw_bk)
6965         {
6966             if ($was_rule)
6967             {
6968                 $result_rules .= $_ if ! $skipping;
6969             }
6970             else
6971             {
6972                 $result_vars .= $_ if ! $skipping;
6973             }
6974             $saw_bk = /\\$/;
6975         }
6976         elsif (/$RULE_PATTERN/o)
6977         {
6978             # Found a rule.
6979             $was_rule = 1;
6980             $skipping = defined $contents{$1};
6981             $result_rules .= $comment . $spacing . $_ if ! $skipping;
6982             $comment = $spacing = '';
6983             $saw_bk = /\\$/;
6984         }
6985         elsif (/$MACRO_PATTERN/o)
6986         {
6987             # Found a variable reference.
6988             $was_rule = 0;
6989             $skipping = defined $contents{$1};
6990             $result_vars .= $comment . $spacing . $_ if ! $skipping;
6991             $comment = $spacing = '';
6992             $saw_bk = /\\$/;
6993             print STDERR "automake: programming error: .am macro \`$1' with trailing backslash\n"
6994                 if $saw_bk;
6995             $am_var_defs{$1} = $3;
6996         }
6997         else
6998         {
6999             # This isn't an error; it is probably a continued rule.
7000             # In fact, this is what we assume.
7001             $was_rule = 1;
7002             $result_rules .= $comment . $spacing . $_ if ! $skipping;
7003             $comment = $spacing = '';
7004             $saw_bk = /\\$/;
7005         }
7006     }
7008     close (FC_FILE);
7009     return $result_vars . $result_rules . $comment;
7012 # Like file_contents_with_transform, but no transform.
7013 sub file_contents
7015     return &file_contents_with_transform ('', @_);
7018 # Find all variable prefixes that are used for install directories.  A
7019 # prefix `zar' qualifies iff:
7020 # * `zardir' is a variable.
7021 # * `zar_PRIMARY' is a variable.
7022 sub am_primary_prefixes
7024     local ($primary, $can_dist, @prefixes) = @_;
7026     local (%valid, $varname);
7027     grep ($valid{$_} = 0, @prefixes);
7028     $valid{'EXTRA'} = 0;
7029     foreach $varname (keys %contents)
7030     {
7031         if ($varname =~ /^(dist_|nodist_)?(.*)_$primary$/)
7032         {
7033             if (($1 ne '' && ! $can_dist)
7034                 || (! defined $valid{$2}
7035                     && ! &variable_defined ($2 . 'dir')
7036                     # Note that a configure variable is always
7037                     # legitimate.  It is natural to name such
7038                     # variables after the primary, so we explicitly
7039                     # allow it.
7040                     && ! defined $configure_vars{$varname}))
7041             {
7042                 &am_line_error ($varname, "invalid variable \`$varname'");
7043             }
7044             else
7045             {
7046                 # Ensure all extended prefixes are actually used.
7047                 $valid{$1 . $2} = 1;
7048             }
7049         }
7050     }
7052     return %valid;
7055 # Handle `where_HOW' variable magic.  Does all lookups, generates
7056 # install code, and possibly generates code to define the primary
7057 # variable.  The first argument is the name of the .am file to munge,
7058 # the second argument is the primary variable (eg HEADERS), and all
7059 # subsequent arguments are possible installation locations.  Returns
7060 # list of all values of all _HOW targets.
7062 # FIXME: this should be rewritten to be cleaner.  It should be broken
7063 # up into multiple functions.
7065 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7066 sub am_install_var
7068     local (@args) = @_;
7070     local ($do_clean) = 0;
7071     local ($do_require) = 1;
7072     local ($can_dist) = 0;
7073     local ($default_dist) = 0;
7075     local ($ltxform);
7076     if (defined $configure_vars{'LIBTOOL'})
7077     {
7078         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
7079         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
7080     }
7081     else
7082     {
7083         # Delete '@LIBTOOL ...@'
7084         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
7085     }
7087     local ($cygxform);
7088     if (! $seen_exeext)
7089     {
7090         $cygxform = 's/\@EXEEXT\@//g;';
7091     }
7092     else
7093     {
7094         $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
7095     }
7097     while (@args)
7098     {
7099         if ($args[0] eq '-clean')
7100         {
7101             $do_clean = 1;
7102         }
7103         elsif ($args[0] eq '-noextra')
7104         {
7105             $do_require = 0;
7106         }
7107         elsif ($args[0] eq '-candist')
7108         {
7109             $can_dist = 1;
7110         }
7111         elsif ($args[0] eq '-defaultdist')
7112         {
7113             $default_dist = 1;
7114             $can_dist = 1;
7115         }
7116         elsif ($args[0] !~ /^-/)
7117         {
7118             last;
7119         }
7120         shift (@args);
7121     }
7123     local ($file, $primary, @prefixes) = @args;
7125     local (@used) = ();
7126     local (@result) = ();
7128     # Now that configure substitutions are allowed in where_HOW
7129     # variables, it is an error to actually define the primary.  We
7130     # allow `JAVA', as it is customarily used to mean the Java
7131     # interpreter.  This is but one of several Java hacks.
7132     &am_line_error ($primary, "\`$primary' is an anachronism")
7133         if &variable_defined ($primary) && $primary ne 'JAVA';
7136     # Look for misspellings.  It is an error to have a variable ending
7137     # in a "reserved" suffix whose prefix is unknown, eg
7138     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
7139     # variable of the same name (with "dir" appended) exists.  For
7140     # instance, if the variable "zardir" is defined, then
7141     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
7142     # flexibility in those cases which need it.
7143     local (%valid) = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7145     # If a primary includes a configure substitution, then the EXTRA_
7146     # form is required.  Otherwise we can't properly do our job.
7147     local ($require_extra);
7148     local ($warned_about_extra) = 0;
7150     local ($clean_file) = $file . '-clean';
7151     local ($one_name);
7152     local ($X);
7153     local ($nodir_name);
7154     foreach $X (sort keys %valid)
7155     {
7156         $one_name = $X . '_' . $primary;
7157         if (&variable_defined ($one_name))
7158         {
7159             # If files should be distributed, do so.
7160             if ($can_dist)
7161             {
7162                 if (($default_dist && $one_name !~ /^nodist_/)
7163                     || (! $default_dist && $one_name =~ /^dist_/))
7164                 {
7165                     &push_dist_common ('$(' . $one_name . ')');
7166                 }
7167                 ($nodir_name = $X) =~ s/^(dist|nodist)_//;
7168             }
7169             else
7170             {
7171                 $nodir_name = $X;
7172             }
7174             # Append actual contents of where_PRIMARY variable to
7175             # result.
7176             local ($rcurs);
7177             foreach $rcurs (&variable_value_as_list ($one_name, 'all'))
7178             {
7179                 # Skip configure substitutions.  Possibly bogus.
7180                 if ($rcurs =~ /^\@.*\@$/)
7181                 {
7182                     if ($X eq 'EXTRA')
7183                     {
7184                         if (! $warned_about_extra)
7185                         {
7186                             $warned_about_extra = 1;
7187                             {
7188                                 &am_line_error ($one_name,
7189                                                 "\`$one_name' contains configure substitution, but shouldn't");
7190                             }
7191                         }
7192                     }
7193                     # Check here to make sure variables defined in
7194                     # configure.in do not imply that EXTRA_PRIMARY
7195                     # must be defined.
7196                     elsif (! defined $configure_vars{$one_name})
7197                     {
7198                         $require_extra = $one_name
7199                             if $do_require;
7200                     }
7202                     next;
7203                 }
7205                 push (@result, $rcurs);
7206             }
7208             # "EXTRA" shouldn't be used when generating clean targets,
7209             # all, or install targets.
7210             if ($X eq 'EXTRA')
7211             {
7212                 # We used to warn if EXTRA_FOO was defined uselessly,
7213                 # but this was annoying.
7214                 next;
7215             }
7217             # A blatant hack: we rewrite each _PROGRAMS primary to
7218             # include EXEEXT when in Cygwin32 mode.
7219             if ($seen_exeext && $primary eq 'PROGRAMS')
7220             {
7221                 local (@conds) = &variable_conditions ($one_name);
7222                 local (@one_binlist);
7224                 # FIXME: this definitely loses aesthetically; it
7225                 # redefines $ONE_NAME.  Instead we should arrange for
7226                 # variable definitions to be output later, instead of
7227                 # at scan time.
7229                 if (! @conds)
7230                 {
7231                     @one_binlist = ();
7232                     foreach $rcurs (&variable_value_as_list ($one_name, ''))
7233                     {
7234                         if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7235                         {
7236                             push (@one_binlist, $rcurs);
7237                         }
7238                         else
7239                         {
7240                             push (@one_binlist, $rcurs . '$(EXEEXT)');
7241                         }
7242                     }
7244                     delete $contents{$one_name};
7245                     &define_pretty_variable ($one_name, '', @one_binlist);
7246                 }
7247                 else
7248                 {
7249                     local ($cond);
7250                     local ($condvals) = '';
7251                     foreach $cond (@conds)
7252                     {
7253                         @one_binlist = ();
7254                         local (@condval) = &variable_value_as_list ($one_name,
7255                                                                     $cond);
7256                         foreach $rcurs (@condval)
7257                         {
7258                             if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7259                             {
7260                                 push (@one_binlist, $rcurs);
7261                             }
7262                             else
7263                             {
7264                                 push (@one_binlist, $rcurs . '$(EXEEXT)');
7265                             }
7266                         }
7268                         push (@condvals, $cond);
7269                         push (@condvals, join (' ', @one_binlist));
7270                     }
7272                     delete $contents{$one_name};
7274                     while (@condvals)
7275                     {
7276                         $cond = shift (@condvals);
7277                         local (@val) = split (' ', shift (@condvals));
7278                         &define_pretty_variable ($one_name, $cond, @val);
7279                     }
7280                 }
7281             }
7283             if ($do_clean)
7284             {
7285                 $output_rules .=
7286                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
7287                                                    . $cygxform,
7288                                                    $clean_file);
7290                 push (@clean, $X . $primary);
7291                 &push_phony_cleaners ($X . $primary);
7292             }
7294             if ($X eq 'check')
7295             {
7296                 push (@check, '$(' . $one_name . ')');
7297             }
7298             else
7299             {
7300                 push (@used, '$(' . $one_name . ')');
7301             }
7302             if ($X eq 'noinst' || $X eq 'check')
7303             {
7304                 # Objects which don't get installed by default.
7305                 next;
7306             }
7308             $output_rules .=
7309                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
7310                                                . 's/\@NDIR\@/' . $nodir_name . '/go;'
7311                                                . $ltxform . $cygxform,
7312                                                $file);
7314             push (@uninstall, 'uninstall-' . $X . $primary);
7315             push (@phony, 'uninstall-' . $X . $primary);
7316             push (@installdirs, '$(DESTDIR)$(' . $X . 'dir)');
7317             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
7318             {
7319                 push (@install_exec, 'install-' . $X . $primary);
7320                 push (@phony, 'install-' . $X . $primary);
7321             }
7322             else
7323             {
7324                 push (@install_data, 'install-' . $X . $primary);
7325                 push (@phony, 'install-' . $X . $primary);
7326             }
7327         }
7328     }
7330     # The JAVA variable is used as the name of the Java interpreter.
7331     if (@used && $primary ne 'JAVA')
7332     {
7333         # Define it.
7334         &define_pretty_variable ($primary, '', @used);
7335         $output_vars .= "\n";
7336     }
7338     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7339     {
7340         &am_line_error ($require_extra,
7341                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
7342     }
7344     # Push here because PRIMARY might be configure time determined.
7345     push (@all, '$(' . $primary . ')')
7346         if @used && $primary ne 'JAVA';
7348     # Make the result unique.  This lets the user use conditionals in
7349     # a natural way, but still lets us program lazily -- we don't have
7350     # to worry about handling a particular object more than once.
7351     local (%uniquify) = ();
7352     grep ($uniquify{$_} = 1, @result);
7353     return sort keys %uniquify;
7357 ################################################################
7359 # This variable is local to the "require file" set of functions.
7360 @require_file_paths = ();
7362 # Verify that the file must exist in the current directory.  Usage:
7363 # require_file (isconfigure, line_number, strictness, file) strictness
7364 # is the strictness level at which this file becomes required.  Must
7365 # set require_file_paths before calling this function.
7366 # require_file_paths is set to hold a single directory (the one in
7367 # which the first file was found) before return.
7368 sub require_file_internal
7370     local ($is_configure, $line, $mystrict, @files) = @_;
7371     local ($file, $fullfile);
7372     local ($found_it, $errfile, $errdir);
7373     local ($save_dir);
7375     foreach $file (@files)
7376     {
7377         $found_it = 0;
7378         foreach $dir (@require_file_paths)
7379         {
7380             if ($dir eq '.')
7381             {
7382                 $fullfile = $relative_dir . "/" . $file;
7383                 $errdir = $relative_dir unless $errdir;
7384             }
7385             else
7386             {
7387                 $fullfile = $dir . "/" . $file;
7388                 $errdir = $dir unless $errdir;
7389             }
7391             # Use different name for "error filename".  Otherwise on
7392             # an error the bad file will be reported as eg
7393             # `../../install-sh' when using the default
7394             # config_aux_path.
7395             $errfile = $errdir . '/' . $file;
7397             if (-f $fullfile)
7398             {
7399                 $found_it = 1;
7400                 # FIXME: Once again, special-case `.'.
7401                 &push_dist_common ($file)
7402                     if $dir eq $relative_dir || $dir eq '.';
7403                 $save_dir = $dir;
7404                 last;
7405             }
7406         }
7408         if ($found_it)
7409         {
7410             # Prune the path list.
7411             @require_file_paths = $save_dir;
7412         }
7413         else
7414         {
7415             if ($strictness >= $mystrict)
7416             {
7417                 local ($trailer) = '';
7418                 local ($suppress) = 0;
7420                 # Only install missing files according to our desired
7421                 # strictness level.
7422                 local ($message) = "required file \`$errfile' not found";
7423                 if ($add_missing)
7424                 {
7425                     $suppress = 1;
7427                     # Maybe run libtoolize.
7428                     if ($seen_libtool
7429                         && grep ($_ eq $file, @libtoolize_files)
7430                         && system ('libtoolize', '--automake'))
7431                     {
7432                         $message = "installing \`$errfile'";
7433                         $suppress = 0;
7434                         $trailer = "; cannot run \`libtoolize': $!";
7435                     }
7436                     elsif (-f ($am_dir . '/' . $file))
7437                     {
7438                         # Install the missing file.  Symlink if we
7439                         # can, copy if we must.  Note: delete the file
7440                         # first, in case it is a dangling symlink.
7441                         $message = "installing \`$errfile'";
7442                         # Windows Perl will hang if we try to delete a
7443                         # file that doesn't exist.
7444                         unlink ($errfile) if -f $errfile;
7445                         if ($symlink_exists && ! $copy_missing)
7446                         {
7447                             if (! symlink ($am_dir . '/' . $file, $errfile))
7448                             {
7449                                 $suppress = 0;
7450                                 $trailer = "; error while making link: $!\n";
7451                             }
7452                         }
7453                         elsif (system ('cp', $am_dir . '/' . $file, $errfile))
7454                         {
7455                             $suppress = 0;
7456                             $trailer = "\n    error while copying\n";
7457                         }
7458                     }
7459                 }
7461                 local ($save) = $exit_status;
7462                 if ($is_configure)
7463                 {
7464                     # FIXME: allow actual file to be specified.
7465                     &am_conf_line_error ('configure.in', $line,
7466                                          "$message$trailer");
7467                 }
7468                 else
7469                 {
7470                     &am_line_error ($line, "$message$trailer");
7471                 }
7472                 $exit_status = $save if $suppress;
7473             }
7474         }
7475     }
7478 # Like require_file_with_line, but error messages refer to
7479 # configure.in, not the current Makefile.am.
7480 sub require_file_with_conf_line
7482     @require_file_paths = '.';
7483     &require_file_internal (1, @_);
7486 sub require_file_with_line
7488     @require_file_paths = '.';
7489     &require_file_internal (0, @_);
7492 sub require_file
7494     @require_file_paths = '.';
7495     &require_file_internal (0, '', @_);
7498 # Require a file that is also required by Autoconf.  Looks in
7499 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7500 sub require_config_file
7502     @require_file_paths = @config_aux_path;
7503     &require_file_internal (1, '', @_);
7504     local ($dir) = $require_file_paths[0];
7505     @config_aux_path = @require_file_paths;
7506     if ($dir eq '.')
7507     {
7508         $config_aux_dir = '.';
7509     }
7510     else
7511     {
7512         $config_aux_dir = '$(top_srcdir)/' . $dir;
7513     }
7516 # Assumes that the line number is in Makefile.am.
7517 sub require_conf_file_with_line
7519     @require_file_paths = @config_aux_path;
7520     &require_file_internal (0, @_);
7521     local ($dir) = $require_file_paths[0];
7522     @config_aux_path = @require_file_paths;
7523     if ($dir eq '.')
7524     {
7525         $config_aux_dir = '.';
7526     }
7527     else
7528     {
7529         $config_aux_dir = '$(top_srcdir)/' . $dir;
7530     }
7533 # Assumes that the line number is in configure.in.
7534 sub require_conf_file_with_conf_line
7536     @require_file_paths = @config_aux_path;
7537     &require_file_internal (1, @_);
7538     local ($dir) = $require_file_paths[0];
7539     @config_aux_path = @require_file_paths;
7540     if ($dir eq '.')
7541     {
7542         $config_aux_dir = '.';
7543     }
7544     else
7545     {
7546         $config_aux_dir = '$(top_srcdir)/' . $dir;
7547     }
7550 ################################################################
7552 # Push a list of files onto dist_common.
7553 sub push_dist_common
7555     local (@files) = @_;
7556     local ($file);
7558     foreach $file (@files)
7559     {
7560         $dist_common{$file} = 1;
7561     }
7564 # Push a list of clean targets onto phony.
7565 sub push_phony_cleaners
7567     local ($base) = @_;
7568     local ($target);
7569     foreach $target ('mostly', 'dist', '', 'maintainer-')
7570     {
7571         push (@phony, $target . 'clean-' . $base);
7572     }
7575 # Set strictness.
7576 sub set_strictness
7578     $strictness_name = $_[0];
7579     if ($strictness_name eq 'gnu')
7580     {
7581         $strictness = $GNU;
7582     }
7583     elsif ($strictness_name eq 'gnits')
7584     {
7585         $strictness = $GNITS;
7586     }
7587     elsif ($strictness_name eq 'foreign')
7588     {
7589         $strictness = $FOREIGN;
7590     }
7591     else
7592     {
7593         die "automake: level \`$strictness_name' not recognized\n";
7594     }
7598 ################################################################
7600 # Return directory name of file.
7601 sub dirname
7603     local ($file) = @_;
7604     local ($sub);
7606     ($sub = $file) =~ s,/+[^/]+$,,g;
7607     $sub = '.' if $sub eq $file;
7608     return $sub;
7611 # Return file name of a file.
7612 sub basename
7614     local ($file) = @_;
7615     local ($sub);
7617     ($sub = $file) =~s,^.*/+,,g;
7618     return $sub;
7621 # Ensure a file exists.
7622 sub create
7624     local ($file) = @_;
7626     open (TOUCH, ">> $file");
7627     close (TOUCH);
7630 # Glob something.  Do this to avoid indentation screwups everywhere we
7631 # want to glob.  Gross!
7632 sub my_glob
7634     local ($pat) = @_;
7635     return <${pat}>;
7638 ################################################################
7640 # Print an error message and set exit status.
7641 sub am_error
7643     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
7644     $exit_status = 1;
7647 sub am_line_error
7649     local ($symbol, @args) = @_;
7651     if ($symbol && "$symbol" ne '-1')
7652     {
7653         local ($file) = "${am_file}.am";
7655         if ($symbol =~ /^\d+$/)
7656         {
7657             # SYMBOL is a line number, so just add the colon.
7658             $file .= ':' . $symbol;
7659         }
7660         elsif (defined $content_lines{$symbol})
7661         {
7662             # SYMBOL is a variable defined in Makefile.am, so add the
7663             # line number we saved from there.
7664             $file .= ':' . $content_lines{$symbol};
7665         }
7666         elsif (defined $configure_vars{$symbol})
7667         {
7668             # SYMBOL is a variable defined in configure.in, so add the
7669             # appropriate line number.
7670             $file = $configure_vars{$symbol};
7671         }
7672         else
7673         {
7674             # Couldn't find the line number.
7675         }
7676         warn $file, ": ", join (' ', @args), "\n";
7677         $exit_status = 1;
7678     }
7679     else
7680     {
7681         &am_error (@args);
7682     }
7685 # Like am_error, but while scanning configure.in.
7686 sub am_conf_error
7688     # FIXME: can run in subdirs.
7689     warn "automake: configure.in: ", join (' ', @_), "\n";
7690     $exit_status = 1;
7693 # Error message with line number referring to configure.in.
7694 sub am_conf_line_error
7696     local ($file, $line, @args) = @_;
7698     if ($line)
7699     {
7700         warn "$file: $line: ", join (' ', @args), "\n";
7701         $exit_status = 1;
7702     }
7703     else
7704     {
7705         &am_conf_error (@args);
7706     }
7709 # Warning message with line number referring to configure.in.
7710 # Does not affect exit_status
7711 sub am_conf_line_warning
7713     local ($saved_exit_status) = $exit_status;
7714     &am_conf_line_error (@_);
7715     $exit_status = $saved_exit_status;
7718 # Tell user where our aclocal.m4 is, but only once.
7719 sub keyed_aclocal_warning
7721     local ($key) = @_;
7722     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
7725 # Print usage information.
7726 sub usage
7728     print "Usage: automake [OPTION] ... [Makefile]...\n\n";
7729     print "Generate Makefile.in for autoconf from Makefile.am\n";
7730     print $USAGE;
7731     print "\nFiles which are automatically distributed, if found:\n";
7732     $~ = "USAGE_FORMAT";
7733     local ($last, $iter, @lcomm);
7734     $last = '';
7735     foreach $iter (sort ((@common_files, @common_sometimes)))
7736     {
7737         push (@lcomm, $iter) unless $iter eq $last;
7738         $last = $iter;
7739     }
7741     local ($one, $two, $three, $four, $i, $max);
7742     $max = int (($#lcomm + 1) / 4);
7744     for ($i = 0; $i < $max; ++$i)
7745     {
7746         $one = $lcomm[$i];
7747         $two = $lcomm[$max + $i];
7748         $three = $lcomm[2 * $max + $i];
7749         $four = $lcomm[3 * $max + $i];
7750         write;
7751     }
7753     local ($mod) = ($#lcomm + 1) % 4;
7754     if ($mod != 0)
7755     {
7756         $one = $lcomm[$max];
7757         $two = ($mod > 1) ? $lcomm[2 * $max] : '';
7758         $three = ($mod > 2) ? $lcomm[3 * $max] : '';
7759         $four = ($mod > 3) ? $lcomm[4 * $max] : '';
7760         write;
7761     }
7763     print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7765     exit 0;
7768 format USAGE_FORMAT =
7769   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
7770   $one,               $two,               $three,             $four