* Makefile.am (XFAIL_TESTS): Removed remake3.test,
[automake.git] / automake.in
blob19f94d9b35da39865f5b6e037e975ee323d2a59a
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 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
10 # Free Software Foundation, Inc.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2, or (at your option)
15 # any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 # 02111-1307, USA.
27 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
28 # Perl reimplementation by Tom Tromey <tromey@cygnus.com>.
30 require 5;
32 # Parameters set by configure.  Not to be changed.  NOTE: assign
33 # VERSION as string so that eg version 0.30 will print correctly.
34 $VERSION = "@VERSION@";
35 $PACKAGE = "@PACKAGE@";
36 $prefix = "@prefix@";
37 $am_dir = "@datadir@/@PACKAGE@";
39 # String constants.
40 $IGNORE_PATTERN = "^##([^#].*)?\$";
41 $WHITE_PATTERN = "^[ \t]*\$";
42 $COMMENT_PATTERN = "^#";
43 $TARGET_PATTERN="[\$a-zA-Z_.][-.a-zA-Z0-9_(){}/\$]*";
44 $RULE_PATTERN = "^($TARGET_PATTERN) *:([^=].*|)\$";
45 $SUFFIX_RULE_PATTERN = "^\\.([a-zA-Z0-9]+)\\.([a-zA-Z0-9]+)\$";
46 # Only recognize leading spaces, not leading tabs.  If we recognize
47 # leading tabs here then we need to make the reader smarter, because
48 # otherwise it will think rules like `foo=bar; \' are errors.
49 $MACRO_PATTERN = "^ *([A-Za-z0-9_]+)[ \t]*([:+]?)=[ \t]*(.*)\$";
50 $BOGUS_MACRO_PATTERN = "^ *([^ \t]*)[ \t]*([:+]?)=[ \t]*(.*)\$";
51 $GNITS_VERSION_PATTERN = "[0-9]+\\.[0-9]+([a-z]|\\.[0-9]+)?";
52 $IF_PATTERN = "^if[ \t]+\([A-Za-z][A-Za-z0-9_]*\)[ \t]*\(#.*\)?\$";
53 $ELSE_PATTERN = "^else[ \t]*\(#.*\)?\$";
54 $ENDIF_PATTERN = "^endif[ \t]*\(#.*\)?\$";
55 $PATH_PATTERN='(\\w|[/.-])+';
56 # This will pass through anything not of the prescribed form.
57 $INCLUDE_PATTERN = "^include[ \t]+((\\\$\\\(top_srcdir\\\)/${PATH_PATTERN})|(\\\$\\\(srcdir\\\)/${PATH_PATTERN})|([^/\\\$]${PATH_PATTERN}))[ \t]*(#.*)?\$";
59 # Some regular expressions.  One reason to put them here is that it
60 # makes indentation work better in Emacs.
61 $AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
62 $AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^,)]+)[,)]";
63 $AM_PACKAGE_VERSION_PATTERN = "^\\s*\\[?([^]\\s]+)\\]?\\s*\$";
64 # Note that there is no AC_PATH_TOOL.  But we don't really care.
65 $AC_CHECK_PATTERN = "AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\\(\\[?(\\w+)";
66 $AM_MISSING_PATTERN = "AM_MISSING_PROG\\(\\[?(\\w+)";
67 # Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
68 # then too bad.
69 $AC_SUBST_PATTERN = "AC_SUBST\\(\\[?(\\w+)";
70 $AM_CONDITIONAL_PATTERN = "AM_CONDITIONAL\\((\\w+)";
72 # Constants to define the "strictness" level.
73 $FOREIGN = 0;
74 $GNU = 1;
75 $GNITS = 2;
77 # These constants are returned by lang_*_rewrite functions.
78 # LANG_SUBDIR means that the resulting object file should be in a
79 # subdir if the source file is.  In this case the file name cannot
80 # have `..' components.
81 $LANG_IGNORE = 0;
82 $LANG_PROCESS = 1;
83 $LANG_SUBDIR = 2;
87 # Variables global to entire run.
89 # Variables related to the options.
91 # TRUE if we should always generate Makefile.in.
92 $force_generation = 1;
94 # Strictness level as set on command line.
95 $default_strictness = $GNU;
97 # Name of strictness level, as set on command line.
98 $default_strictness_name = 'gnu';
100 # This is TRUE if automatic dependency generation code should be
101 # included in generated Makefile.in.
102 $cmdline_use_dependencies = 1;
104 # TRUE if in verbose mode.
105 $verbose = 0;
107 # This holds our (eventual) exit status.  We don't actually exit until
108 # we have processed all input files.
109 $exit_status = 0;
111 # From the Perl manual.
112 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
114 # TRUE if missing standard files should be installed.
115 $add_missing = 0;
117 # TRUE if we should copy missing files; otherwise symlink if possible.
118 $copy_missing = 0;
120 # TRUE if we should always update files that we know about.
121 $force_missing = 0;
124 # Variables filled during files scanning.
126 # Name of the top autoconf input: `configure.ac' or `configure.in'.
127 $configure_ac = '';
129 # Files found by scanning configure.ac for LIBOBJS.
130 %libsources = ();
132 # True if AM_C_PROTOTYPES appears in configure.ac.
133 $am_c_prototypes = 0;
135 # Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
136 # name which appears in AC_CONFIG_HEADER, colon and all.
137 # @config_names holds the file names.  @config_headers holds the '.in'
138 # files.  Ordinarily these are similar, but they can be different if
139 # the weird "NAME:FILE" syntax is used.
140 @config_fullnames = ();
141 @config_names = ();
142 @config_headers = ();
143 # Line number at which AC_CONFIG_HEADER appears in configure.ac.
144 $config_header_line = 0;
146 # Directory where output files go.  Actually, output files are
147 # relative to this directory.
148 $output_directory = '.';
150 # Relative location of top build directory.
151 $top_builddir = '';
153 # List of Makefile.am's to process, and their corresponding outputs.
154 @input_files = ();
155 %output_files = ();
157 # Complete list of Makefile.am's that exist.
158 @configure_input_files = ();
160 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
161 @other_input_files = ();
162 # Line number at which AC_OUTPUT seen.
163 $ac_output_line = 0;
165 # List of directories to search for configure-required files.  This
166 # can be set by AC_CONFIG_AUX_DIR.
167 @config_aux_path = ('.', '..', '../..');
168 $config_aux_dir = '';
170 # Whether AC_PROG_MAKE_SET has been seen in configure.ac.
171 $seen_make_set = 0;
173 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
174 $seen_gettext = 0;
175 # Line number at which AM_GNU_GETTEXT seen.
176 $ac_gettext_line = 0;
178 # Whether ALL_LINGUAS has been seen.
179 $seen_linguas = '';
180 # The actual text.
181 $all_linguas = '';
182 # Line number at which it appears.
183 $all_linguas_line = 0;
185 # 1 if AC_PROG_INSTALL seen.
186 $seen_prog_install = 0;
188 # Whether AC_PATH_XTRA has been seen in configure.ac.
189 $seen_path_xtra = 0;
191 # TRUE if AC_DECL_YYTEXT was seen.
192 $seen_decl_yytext = 0;
194 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
195 # AC_CHECK_TOOL also sets this.
196 $seen_canonical = 0;
198 # TRUE if we've seen AC_ARG_PROGRAM.
199 $seen_arg_prog = 0;
201 # TRUE if we've seen AC_PROG_LIBTOOL.
202 $seen_libtool = 0;
203 $libtool_line = 0;
205 # Files installed by libtoolize.
206 @libtoolize_files = ('ltmain.sh', 'config.guess', 'config.sub');
207 # ltconfig appears here for compatibility with old versions of libtool.
208 @libtoolize_sometimes = ('ltconfig', 'ltcf-c.sh', 'ltcf-cxx.sh',
209                          'ltcf-gcj.sh');
211 # TRUE if we've seen AM_MAINTAINER_MODE.
212 $seen_maint_mode = 0;
214 # Actual version we've seen.
215 $package_version = '';
217 # Line number where we saw version definition.
218 $package_version_line = 0;
220 # TRUE if we've seen AM_PATH_LISPDIR.
221 $seen_lispdir = 0;
223 # TRUE if we've seen AM_CHECK_PYTHON.
224 $seen_pythondir = 0;
226 # TRUE if we've seen AC_EXEEXT.
227 $seen_exeext = 0;
229 # TRUE if we've seen AC_OBJEXT.
230 $seen_objext = 0;
232 # TRUE if we've seen AC_ENABLE_MULTILIB.
233 $seen_multilib = 0;
235 # TRUE if we've seen AM_PROG_CC_C_O
236 $seen_cc_c_o = 0;
238 # TRUE if we've seen AM_INIT_AUTOMAKE.
239 $seen_init_automake = 0;
241 # Hash table of discovered configure substitutions.  Keys are names,
242 # values are `FILE:LINE' strings which are used by error message
243 # generation.
244 %configure_vars = ();
246 # This is used to keep track of which variable definitions we are
247 # scanning.  It is only used in certain limited ways, but it has to be
248 # global.  It is declared just for documentation purposes.
249 %vars_scanned = ();
251 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
252 # handled in a funny way: if seen in the top-level Makefile.am, it is
253 # used for every directory which does not specify a different value.
254 # The rationale here is that some directories (eg gettext) might be
255 # distributions of other packages, and thus require their own charset
256 # info.  However, the DIST_CHARSET must be the same for the entire
257 # package; it can only be set at top-level.
258 # FIXME: this yields bugs when rebuilding.  What to do?  Always
259 # read (and sometimes discard) top-level Makefile.am?
260 $maint_charset = '';
261 $dist_charset = 'utf8';         # recode doesn't support this yet.
263 # Name of input file ("Makefile.in") and output file ("Makefile.am").
264 # These have no directory components.
265 $am_file_name = '';
266 $in_file_name = '';
268 # TRUE if --cygnus seen.
269 $cygnus_mode = 0;
271 # Hash table of AM_CONDITIONAL variables seen in configure.
272 %configure_cond = ();
274 # Map from obsolete macros to hints for new macros.
275 # If you change this, change the corresponding list in aclocal.in.
276 # FIXME: should just put this into a single file.
277 %obsolete_macros =
278     (
279      'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
280      'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
281      'AC_FEATURE_EXIT', '',
282      'AC_SYSTEM_HEADER', '',
284      # Note that we do not handle this one, because it is still run
285      # from AM_CONFIG_HEADER.  So we deal with it specially in
286      # &scan_autoconf_files.
287      # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",
289      'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
290      'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
291      'fp_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
292      'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
293      'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
294      'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
295      'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
296      'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
297      'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",
298      'ud_GNU_GETTEXT', "use \`AM_GNU_GETTEXT'",
300      # Now part of autoconf proper, under a different name.
301      'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
302      'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
303      'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",
304      'AM_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
305      'AM_EXEEXT', "use \`AC_EXEEXT'",
306      'AM_CYGWIN32', "use \`AC_CYGWIN'",
307      'AM_MINGW32', "use \`AC_MINGW32'",
308      'AM_FUNC_MKTIME', "use \`AC_FUNC_MKTIME'",
310 # These aren't quite obsolete.
311 #      'md_PATH_PROG',
312      );
314 # Regexp to match the above macros.
315 $obsolete_rx = '(\b' . join ('\b|\b', keys %obsolete_macros) . '\b)';
317 # This maps extensions onto language names.
318 %extension_map = ();
320 # This maps languages names onto properties.
321 %language_map = ();
323 # This holds all the files that would go in `dist_common' which we
324 # discovered while scanning configure.ac.  We might distribute these
325 # in the top-level Makefile.in.
326 %configure_dist_common = ();
329 # Initialize global constants and our list of languages that are
330 # internally supported.
331 &initialize_global_constants;
333 &register_language ('c', 'ansi-p=1', 'autodep=', 'flags=CFLAGS',
334                     'compile=$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
335                     'compiler-name=COMPILE',
336                     'output-arg=-c',
337                     'c');
338 &register_language ('cxx', 'linker=CXXLINK', 'autodep=CXX', 'flags=CXXFLAGS',
339                     'compile=$(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
340                     'compiler-name=CXXCOMPILE',
341                     'output-arg=-c -o $@',
342                     'c++', 'cc', 'cpp', 'cxx', 'C');
343 &register_language ('objc', 'linker=OBJCLINK', 'autodep=OBJC',
344                     'flags=OBJCFLAGS',
345                     'compile=$(OBJC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
346                     'compiler-name=OBJCCOMPILE',
347                     'output-arg=-c -o $@',
348                     'm');
349 &register_language ('header',
350                     'h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc');
352 # For now, yacc and lex can't be handled on a per-exe basis.
353 &register_language ('yacc', 'ansi-p=1', 'derived-autodep=yes',
354                     'y');
355 &register_language ('yaccxx', 'linker=CXXLINK', 'derived-autodep=yes',
356                     'y++', 'yy', 'yxx', 'ypp');
357 &register_language ('lex', 'ansi-p=1', 'derived-autodep=yes',
358                     'l');
359 &register_language ('lexxx', 'linker=CXXLINK', 'derived-autodep=yes',
360                     'l++', 'll', 'lxx', 'lpp');
362 &register_language ('asm',
363                     'flags=CFLAGS', # FIXME: asmflags?
364                     'compile=$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)', # FIXME: a different compiler?
365                     'compiler-name=COMPILE',
366                     'output-arg=-c',
367                     's', 'S');
369 &register_language ('f77', 'linker=F77LINK', 'flags=FFLAGS',
370                     'compile=$(F77) $(AM_FFLAGS) $(FFLAGS)',
371                     'compiler-name=F77COMPILE',
372                     'output-arg=-c -o $@',
373                     'f', 'for', 'f90');
374 &register_language ('ppf77', 'linker=F77LINK', 'flags=FFLAGS',
375                     'compile=$(F77) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
376                     'compiler-name=PPF77COMPILE',
377                     'output-arg=-c -o $@',
378                     'F');
379 &register_language ('ratfor', 'linker=F77LINK',
380                     'flags=RFLAGS', # FIXME also FFLAGS.
381                     'compile=$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
382                     'compiler-name=RCOMPILE',
383                     'output-arg=-c -o $@',
384                     'r');
385 # FIXME: for now we can't do dependency tracking for Java.
386 # autodep=GCJ
387 &register_language ('java', 'linker=GCJLINK', 'flags=GCJFLAGS',
388                     'compile=$(GCJ) $(DEFS) $(INCLUDES) $(AM_GCJFLAGS) $(GCJFLAGS)',
389                     'compiler-name=GCJCOMPILE',
390                     'output-arg=-c -o $@',
391                     'java', 'class', 'zip', 'jar');
394 # Parse command line.
395 &parse_arguments (@ARGV);
397 # Do configure.ac scan only once.
398 &scan_autoconf_files;
400 die "automake: no \`Makefile.am' found or specified\n"
401     if ! @input_files;
403 # Now do all the work on each file.
404 foreach $am_file (@input_files)
406     if (! -f ($am_file . '.am'))
407     {
408         &am_error ("\`" . $am_file . ".am' does not exist");
409     }
410     else
411     {
412         &generate_makefile ($output_files{$am_file}, $am_file);
413     }
416 &am_conf_error ("AC_PROG_INSTALL must be used")
417     if (! $seen_prog_install);
419 exit $exit_status;
422 ################################################################
425 # prog_error (@PRINT-ME)
426 # ----------------------
427 # Signal a programming error, display PRINT-ME, and exit 1.
428 sub prog_error
430     print STDERR "automake: programming error: @_\n";
431     exit 1;
435 ################################################################
437 # Parse command line.
438 sub parse_arguments
440     local (@arglist) = @_;
442     # Start off as gnu.
443     &set_strictness ('gnu');
445     while (@arglist)
446     {
447         if ($arglist[0] eq "--version")
448         {
449             print "automake (GNU $PACKAGE) $VERSION\n\n";
450             print "Copyright 2000 Free Software Foundation, Inc.\n";
451             print "This is free software; see the source for copying conditions.  There is NO\n";
452             print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
453             print "Written by Tom Tromey <tromey\@cygnus.com>\n";
455             exit 0;
456         }
457         elsif ($arglist[0] eq "--help")
458         {
459             &usage;
460         }
461         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
462         {
463             $am_dir = $1;
464         }
465         elsif ($arglist[0] eq '--amdir')
466         {
467             &require_argument (@arglist);
468             shift (@arglist);
469             $am_dir = $arglist[0];
470         }
471         elsif ($arglist[0] eq '--gnu')
472         {
473             &set_strictness ('gnu');
474         }
475         elsif ($arglist[0] eq '--gnits')
476         {
477             &set_strictness ('gnits');
478         }
479         elsif ($arglist[0] eq '--cygnus')
480         {
481             $cygnus_mode = 1;
482         }
483         elsif ($arglist[0] eq '--foreign')
484         {
485             &set_strictness ('foreign');
486         }
487         elsif ($arglist[0] eq '--include-deps')
488         {
489             $cmdline_use_dependencies = 1;
490         }
491         elsif ($arglist[0] eq '--ignore-deps' || $arglist[0] eq '-i')
492         {
493             $cmdline_use_dependencies = 0;
494         }
495         elsif ($arglist[0] eq '--no-force')
496         {
497             $force_generation = 0;
498         }
499         elsif ($arglist[0] eq '--force-missing')
500         {
501             $force_missing = 1;
502         }
503         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
504         {
505             # Set output directory.
506             $output_directory = $1;
507         }
508         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
509         {
510             &require_argument (@arglist);
511             shift (@arglist);
512             $output_directory = $arglist[0];
513         }
514         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
515         {
516             $add_missing = 1;
517         }
518         elsif ($arglist[0] eq '--copy' || $arglist[0] eq '-c')
519         {
520             $copy_missing = 1;
521         }
522         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
523         {
524             $verbose = 1;
525         }
526         elsif ($arglist[0] eq '--')
527         {
528             # Stop option processing.
529             shift (@arglist);
530             push (@input_files, @arglist);
531             last;
532         }
533         elsif ($arglist[0] =~ /^-/)
534         {
535             die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
536         }
537         else
538         {
539             # Handle $local:$input syntax.  Note that we only examine
540             # the first ":" file to see if it is automake input; the
541             # rest are just taken verbatim.  We still keep all the
542             # files around for dependency checking, however.
543             local ($local, $input, @rest) = split (/:/, $arglist[0]);
544             if (! $input)
545             {
546                 $input = $local;
547             }
548             else
549             {
550                 # Strip .in; later on .am is tacked on.  That is how
551                 # the automake input file is found.  Maybe not the
552                 # best way, but it is easy to explain.  FIXME: should
553                 # be error if .in is missing.
554                 $input =~ s/\.in$//;
555             }
556             push (@input_files, $input);
557             $output_files{$input} = join (':', ($local, @rest));
558         }
560         shift (@arglist);
561     }
563     # Take global strictness from whatever we currently have set.
564     $default_strictness = $strictness;
565     $default_strictness_name = $strictness_name;
568 # Ensure argument exists, or die.
569 sub require_argument
571     local ($arg, @arglist) = @_;
572     die "automake: no argument given for option \`$arg'\n"
573         if ! @arglist;
576 ################################################################
578 # Generate a Makefile.in given the name of the corresponding Makefile and
579 # the name of the file output by config.status.
580 sub generate_makefile
582     local ($output, $makefile) = @_;
584     ($am_file_name = $makefile) =~ s/^.*\///;
585     $in_file_name = $am_file_name . '.in';
586     $am_file_name .= '.am';
588     # $OUTPUT is encoded.  If it contains a ":" then the first element
589     # is the real output file, and all remaining elements are input
590     # files.  We don't scan or otherwise deal with these input file,
591     # other than to mark them as dependencies.  See
592     # &scan_autoconf_files for details.
593     local (@secondary_inputs);
594     ($output, @secondary_inputs) = split (/:/, $output);
596     &initialize_per_input;
597     $relative_dir = &dirname ($output);
598     $am_relative_dir = &dirname ($makefile);
600     # At the toplevel directory, we might need config.guess, config.sub
601     # or libtool scripts (ltconfig and ltmain.sh).
602     if ($relative_dir eq '.')
603     {
604         # libtool requires some files.
605         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
606                                            @libtoolize_files)
607             if $seen_libtool;
609         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
610         # config.sub.
611         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
612             if $seen_canonical;
613     }
615     # We still need Makefile.in here, because sometimes the `dist'
616     # target doesn't re-run automake.
617     if ($am_relative_dir eq $relative_dir)
618     {
619         # Only distribute the files if they are in the same subdir as
620         # the generated makefile.
621         &push_dist_common ($in_file_name, $am_file_name);
622     }
624     push (@sources, '$(SOURCES)')
625         if &variable_defined ('SOURCES');
626     push (@objects, '$(OBJECTS)')
627         if &variable_defined ('OBJECTS');
629     &read_main_am_file ($makefile . '.am');
630     if (&handle_options)
631     {
632         # Fatal error.  Just return, so we can continue with next file.
633         return;
634     }
636     # Must do this after reading .am file.  See read_main_am_file to
637     # understand weird tricks we play there with variables.
638     &define_variable ('subdir', $relative_dir);
640     # Check first, because we might modify some state.
641     &check_cygnus;
642     &check_gnu_standards;
643     &check_gnits_standards;
645     &handle_configure ($output, $makefile, @secondary_inputs);
646     &handle_gettext;
647     &handle_libraries;
648     &handle_ltlibraries;
649     &handle_programs;
650     &handle_scripts;
652     # This must be run after all the sources are scanned.
653     &finish_languages;
655     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
656     # on this (but currently does).
657     $contents{'SOURCES'} = join (' ', @sources);
658     $contents{'OBJECTS'} = join (' ', @objects);
659     &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
661     &handle_multilib;
662     &handle_texinfo;
663     &handle_emacs_lisp;
664     &handle_python;
665     &handle_java;
666     &handle_man_pages;
667     &handle_data;
668     &handle_headers;
669     &handle_subdirs;
670     &handle_tags;
671     &handle_minor_options;
672     &handle_dependencies;
673     &handle_tests;
675     # This must come after most other rules.
676     &handle_dist ($makefile);
678     &handle_footer;
679     &handle_merge_targets ($output);
680     &handle_installdirs;
681     &handle_clean;
682     &handle_factored_dependencies;
684     &check_typos;
686     if (! -d ($output_directory . '/' . $am_relative_dir))
687     {
688         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
689     }
691     local ($out_file) = $output_directory . '/' . $makefile . ".in";
692     if (! $force_generation && -e $out_file)
693     {
694         local ($am_time) = (stat ($makefile . '.am'))[9];
695         local ($in_time) = (stat ($out_file))[9];
696         # FIXME: should cache these times.
697         local ($conf_time) = (stat ($configure_ac))[9];
698         # FIXME: how to do unsigned comparison?
699         if ($am_time < $in_time || $am_time < $conf_time)
700         {
701             # No need to update.
702             return;
703         }
704         if (-f 'aclocal.m4')
705         {
706             local ($acl_time) = (stat _)[9];
707             return if ($am_time < $acl_time);
708         }
709     }
711     if (! open (GM_FILE, "> " . $out_file))
712     {
713         warn "automake: ${am_file}.in: cannot write: $!\n";
714         $exit_status = 1;
715         return;
716     }
717     print "automake: creating ", $makefile, ".in\n" if $verbose;
719     # In case we're running under MSWindows, don't write with CRLF
720     # (as it causes problems for the dependency-file extraction in
721     # AM_OUTPUT_DEPENDENCY_COMMANDS).
722     binmode GM_FILE;
724     print GM_FILE $output_vars;
725     # We make sure that `all:' is the first target.
726     print GM_FILE $output_all;
727     print GM_FILE $output_header;
728     print GM_FILE $output_rules;
729     print GM_FILE $output_trailer;
731     if (! close (GM_FILE))
732       {
733         warn "automake: $am_file.in: cannot close: $!\n";
734         $exit_status = 1;
735         return;
736       }
739 ################################################################
741 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
742 sub handle_options
744     if (&variable_defined ('AUTOMAKE_OPTIONS'))
745     {
746         foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
747         {
748             $options{$_} = 1;
749             if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
750             {
751                 &set_strictness ($_);
752             }
753             elsif ($_ eq 'cygnus')
754             {
755                 $cygnus_mode = 1;
756             }
757             elsif (/ansi2knr/)
758             {
759                 # An option like "../lib/ansi2knr" is allowed.  With
760                 # no path prefix, we assume the required programs are
761                 # in this directory.  We save the actual option for
762                 # later.
763                 $options{'ansi2knr'} = $_;
764             }
765             elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
766                    || $_ eq 'dist-shar' || $_ eq 'dist-zip'
767                    || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
768                    || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
769                    || $_ eq 'readme-alpha' || $_ eq 'check-news'
770                    || $_ eq 'subdir-objects' || $_ eq 'nostdinc')
771             {
772                 # Explicitly recognize these.
773             }
774             elsif ($_ eq 'no-dependencies')
775             {
776                 $use_dependencies = 0;
777             }
778             elsif (/([0-9]+)\.([0-9]+)([a-z])?/)
779             {
780                 # Got a version number.
782                 local ($rmajor, $rminor, $ralpha) = ($1, $2, $3);
784                 &prog_error ("version is incorrect: $VERSION")
785                     if $VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/;
787                 local ($tmajor, $tminor, $talpha) = ($1, $2, $3);
789                 # 2.0 is better than 1.0.
790                 # 1.2 is better than 1.1.
791                 # 1.2a is better than 1.2.
792                 if ($rmajor > $tmajor
793                     || ($rmajor == $tmajor && $rminor > $tminor)
794                     || ($rminor == $tminor && $rminor == $tminor
795                         && $ralpha gt $talpha))
796                 {
797                     &am_line_error ('AUTOMAKE_OPTIONS',
798                                     "require version $_, only have $VERSION");
799                     return 1;
800                 }
801             }
802             else
803             {
804                 &am_line_error ('AUTOMAKE_OPTIONS',
805                                 "option \`" . $_ . "\' not recognized");
806             }
807         }
808     }
810     if ($strictness == $GNITS)
811     {
812         $options{'readme-alpha'} = 1;
813         $options{'check-news'} = 1;
814     }
816     return 0;
820 # get_object_extension ($OUT)
821 # ---------------------------
822 # Return object extension.  Just once, put some code into the output.
823 # OUT is the name of the output file
824 sub get_object_extension
826     local ($out) = @_;
828     # Maybe require libtool library object files.
829     local ($extension) = '.o';
830     $extension = '.$(OBJEXT)' if $seen_objext;
831     $extension = '.lo' if ($out =~ /\.la$/);
833     if (! $included_generic_compile)
834     {
835         # Boilerplate.
836         local ($default_include) = '';
837         if (! defined $options{'nostdinc'})
838         {
839             $default_include = ' -I. -I$(srcdir)';
841             if (&variable_defined ('CONFIG_HEADER'))
842             {
843                 local ($one_hdr);
844                 foreach $one_hdr (split (' ',
845                                          &variable_value ('CONFIG_HEADER')))
846                 {
847                     $default_include .= ' -I' . &dirname ($one_hdr);
848                 }
849             }
850         }
851         local ($xform) = &transform ('DEFAULT_INCLUDES' => $default_include);
852         $output_vars .= &file_contents ('comp-vars', $xform);
854         $xform = $seen_objext ? 's/^OBJEXT//;' : 's/^OBJEXT.*$//;';
855         $output_rules .= &file_contents ('compile', $xform);
857         # If using X, include some extra variable definitions.  NOTE
858         # we don't want to force these into CFLAGS or anything,
859         # because not all programs will necessarily use X.
860         if ($seen_path_xtra)
861         {
862             local ($var);
863             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
864             {
865                 &define_configure_variable ($var);
866             }
867         }
869         push (@suffixes, '.c', '.o');
870         push (@suffixes, '.obj') if $seen_objext;
872         $included_generic_compile = 1;
873     }
875     if ($seen_libtool && ! $included_libtool_compile)
876     {
877         # Output the libtool compilation rules.
878         $output_rules .= &file_contents ('libtool');
880         push (@suffixes, '.lo');
882         $included_libtool_compile = 1;
883     }
885     # Check for automatic de-ANSI-fication.
886     if (defined $options{'ansi2knr'})
887     {
888         $extension = '$U' . $extension;
889         if (! $included_knr_compile)
890         {
891             if (! $am_c_prototypes)
892             {
893                 &am_line_error ('AUTOMAKE_OPTIONS',
894                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in \`$configure_ac'");
895                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
896                 # Only give this error once.
897                 $am_c_prototypes = 1;
898             }
900             # Only require ansi2knr files if they should appear in
901             # this directory.
902             if ($options{'ansi2knr'} eq 'ansi2knr')
903             {
904                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
905                                          'ansi2knr.c', 'ansi2knr.1');
906                 $output_rules .= &file_contents ('kr-extra');
907             }
909             # Generate rules to build ansi2knr.  If it is in some
910             # other directory, then generate dependencies but have the
911             # rule just run elsewhere.
912             $objext = $seen_objext ? ".\$(OBJEXT)" : ".o";
913             $output_rules .= ($options{'ansi2knr'} . ': '
914                               . $options{'ansi2knr'} . $objext . "\n");
915             if ($options{'ansi2knr'} eq 'ansi2knr')
916             {
917                 $output_rules .= ("\t\$(LINK) ansi2knr" . $objext
918                                   . " \$(LIBS)\n"
919                                   . "ansi2knr" . $objext
920                                   . ": \$(CONFIG_HEADER)\n\n");
921             }
922             else
923             {
924                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
925                                   . " && \$(MAKE) \$(AM_MAKEFLAGS) "
926                                   . "ansi2knr\n\n");
927                 # This is required for non-GNU makes.
928                 $output_rules .= ($options{'ansi2knr'} . $objext . ":\n");
929                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
930                                   . " && \$(MAKE) \$(AM_MAKEFLAGS)"
931                                   . " ansi2knr" . $objext . "\n\n");
932             }
934             # Make sure ansi2knr can be found: if no path specified,
935             # specify "./".
936             if ($options{'ansi2knr'} eq 'ansi2knr')
937             {
938                 # Substitution from AM_C_PROTOTYPES.  This makes it be
939                 # built only when necessary.
940                 &define_configure_variable ('ANSI2KNR');
941                 # ansi2knr needs to be built before subdirs, so unshift it.
942                 unshift (@all, '$(ANSI2KNR)');
943             }
944             else
945             {
946                 # Found in another directory.
947                 &define_variable ("ANSI2KNR", $options{'ansi2knr'});
948             }
950             $output_rules .= &file_contents ('clean-kr');
952             $included_knr_compile = 1;
953         }
954     }
956     return $extension;
959 # Call finish function for each language that was used.
960 sub finish_languages
962     local ($ltcompile, $ltlink) = &libtool_compiler;
964     local ($ext, $name, $lang, %done);
965     local ($non_c) = 1;
966     foreach $ext (sort keys %extension_seen)
967     {
968         $lang = $extension_map{$ext};
970         # Generate the appropriate rules for this extension.  If
971         # dependency tracking was requested, and this extension
972         # supports it, then we don't generate the rule here.
973         local ($comp) = '';
975         if ($use_dependencies && $language_map{$lang . '-autodep'} ne 'no')
976         {
977             # Don't generate the rule, but still generate the variables.
978             if (defined $language_map{$lang . '-compile'})
979             {
980                 $comp = $language_map{$lang . '-compile'};
981             }
982         }
983         elsif (defined $language_map{$lang . '-compile'})
984         {
985             $comp = $language_map{$lang . '-compile'};
987             local ($outarg) = $language_map{$lang . '-output-arg'};
988             if ($language_map{$lang . '-flags'} eq 'CFLAGS')
989             {
990                 # C compilers don't always support -c -o.
991                 if (defined $options{'subdir-objects'})
992                 {
993                     $outarg .= ' -o $@';
994                 }
995             }
997             local ($full) = ("\t\$("
998                              . $language_map{$lang . '-compiler-name'}
999                              . ") "
1000                              . $outarg);
1001             $output_rules .= (".$ext.o:\n"
1002                               . $full
1003                               . " \$<\n");
1004             # FIXME: Using cygpath should be somehow conditional.
1005             $output_rules .= (".$ext.obj:\n"
1006                               . $full
1007                               . " \`cygpath -w \$<\`\n")
1008                 if $seen_objext;
1009             $output_rules .= (".$ext.lo:\n"
1010                               . "\t\$(LT"
1011                               . $language_map{$lang . '-compiler-name'}
1012                               . ") "
1013                               . $language_map{$lang . '-output-arg'}
1014                               # We can always use -c -o with libtool.
1015                               . ($language_map{$lang . '-flags'} eq 'CFLAGS'
1016                                  ? ' -o $@' : '')
1017                               . " \$<\n")
1018                 if $seen_libtool;
1019         }
1021         push (@suffixes, '.' . $ext);
1023         # The rest of the loop is done once per language.
1024         next if defined $done{$lang};
1025         $done{$lang} = 1;
1027         $non_c = 0 if $lang !~ /(objc|cxx|f77|ratfor)$/;
1029         if ($comp ne '')
1030         {
1031             &define_compiler_variable ($language_map{$lang . '-compiler-name'},
1032                                        $ltcompile, $comp);
1033         }
1034         # The compiler's flag must be a configure variable.
1035         if (defined $language_map{$lang . '-flags'})
1036         {
1037             &define_configure_variable ($language_map{$lang . '-flags'});
1038         }
1040         # Compute the function name of the finisher and then call it.
1041         $name = 'lang_' . $lang . '_finish';
1042         & $name ();
1043     }
1045     # If the project is entirely C++ or entirely Fortran 77, don't
1046     # bother with the C stuff.  But if anything else creeps in, then use
1047     # it.
1048     if ($need_link || ! $non_c || scalar keys %suffix_rules > 0)
1049     {
1050         if (! defined $done{'c'})
1051         {
1052             &define_configure_variable ($language_map{'c-flags'});
1053             &define_compiler_variable ($language_map{'c-compiler-name'},
1054                                        $ltcompile,
1055                                        $language_map{'c-compile'});
1056         }
1057         &define_variable ('CCLD', '$(CC)');
1058         &define_variable ('LINK', $ltlink . '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
1059     }
1062 # Output a rule to build from a YACC source.  The output from YACC is
1063 # compiled with C or C++, depending on the extension of the YACC file.
1064 sub output_yacc_build_rule
1066     local ($yacc_suffix, $use_ylwrap, $c_suffix) = @_;
1068     local ($suffix);
1069     ($suffix = $yacc_suffix) =~ tr/y/c/;
1070     push (@suffixes, $yacc_suffix, $suffix);
1072     # Generate rule for c/c++.
1073     $output_rules .= "$yacc_suffix$suffix:\n\t";
1075     if ($use_ylwrap)
1076     {
1077         $output_rules .= ('$(SHELL) $(YLWRAP)'
1078                           . ' "$(YACC)" $< y.tab.c $*' . $suffix
1079                           . ' y.tab.h $*.h -- $(AM_YFLAGS) $(YFLAGS)');
1080     }
1081     else
1082     {
1083         $output_rules .= ('$(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*'
1084                           . $suffix . "\n"
1085                           . "\tif test -f y.tab.h; then \\\n"
1086                           . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
1087                           . "\telse :; fi");
1088     }
1089     $output_rules .= "\n";
1092 sub output_lex_build_rule
1094     local ($lex_suffix, $use_ylwrap) = @_;
1095     local ($c_suffix);
1097     ($c_suffix = $lex_suffix) =~ tr/l/c/;
1098     push (@suffixes, $lex_suffix);
1099     &define_configure_variable ('LEX_OUTPUT_ROOT');
1100     &define_configure_variable ('LEXLIB');
1101     $output_rules .= "$lex_suffix$c_suffix:\n\t";
1103     if ($use_ylwrap)
1104     {
1105         # Is the $@ correct here?  If so, why not use it in the ylwrap
1106         # build rule for yacc above?
1107         $output_rules .= '$(SHELL) $(YLWRAP)'
1108             . ' "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(AM_LFLAGS) $(LFLAGS)';
1109     }
1110     else
1111     {
1112         $output_rules .= '$(LEX) $(AM_LFLAGS) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
1113     }
1114     $output_rules .= "\n";
1118 # Check to make sure a source defined in LIBOBJS is not explicitly
1119 # mentioned.  This is a separate function (as opposed to being inlined
1120 # in handle_source_transform) because it isn't always appropriate to
1121 # do this check.
1122 sub check_libobjs_sources
1124     local ($one_file, $unxformed) = @_;
1126     local ($prefix, $file, @files);
1127     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1128                      'dist_EXTRA_', 'nodist_EXTRA_')
1129     {
1130         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1131         {
1132             @files = &variable_value_as_list (($prefix
1133                                                . $one_file . '_SOURCES'),
1134                                               'all');
1135         }
1136         elsif ($prefix eq '')
1137         {
1138             @files = ($unxformed . '.c');
1139         }
1140         else
1141         {
1142             next;
1143         }
1145         foreach $file (@files)
1146         {
1147             if (defined $libsources{$file})
1148             {
1149                 &am_line_error ($prefix . $one_file . '_SOURCES',
1150                                 "automatically discovered file \`$file' should not be explicitly mentioned");
1151             }
1152         }
1153     }
1157 # ($LINKER, @OBJECTS)
1158 # handle_single_transform_list ($VAR, $DERIVED, $OBJ, @FILES)
1159 # -----------------------------------------------------------
1160 # Does much of the actual work for handle_source_transform.
1161 # Arguments are:
1162 #   $DERIVED is the name of resulting executable or library
1163 #   $OBJ is the object extension (e.g., `$U.lo')
1164 #   @FILES is the list of source files to transform
1165 # Result is a list
1166 #   $LINKER is name of linker to use (empty string for default linker)
1167 #   @OBJECTS are names of objects
1168 sub handle_single_transform_list
1170     local ($var, $derived, $obj, @files) = @_;
1171     local (@result) = ();
1172     local ($nonansi_obj) = $obj;
1173     $nonansi_obj =~ s/\$U//g;
1174     local (%linkers_used) = ();
1176     # Turn sources into objects.
1177     foreach (@files)
1178     {
1179         # Configure substitutions in _SOURCES variables are errors.
1180         if (/^\@.*\@$/)
1181         {
1182             &am_line_error ($var, "$var includes configure substitution \`$_'");
1183             next;
1184         }
1186         # If the source file is in a subdirectory then the `.o' is
1187         # put into the current directory.
1189         # Split file name into base and extension.
1190         local ($full, $directory, $base, $extension, $linker, $object);
1191         next if ! /^((.*)\/)?([^\/]*)\.(.*)$/;
1192         $full = $_;
1193         $directory = $2;
1194         $base = $3;
1195         $extension = $4;
1197         local ($xbase) = $base;
1199         # We must generate a rule for the object if it requires
1200         # its own flags.
1201         local ($rule) = '';
1202         local ($renamed) = 0;
1204         $extension = &derive_suffix ($extension);
1205         local ($lang) = $extension_map{$extension};
1206         if ($lang)
1207         {
1208             &saw_extension ($extension);
1209             # Found the language, so see what it says.
1210             local ($subr) = 'lang_' . $lang . '_rewrite';
1211             # Note: computed subr call.
1212             local ($r) = & $subr ($directory, $base, $extension);
1213             # Skip this entry if we were asked not to process it.
1214             next if $r == $LANG_IGNORE;
1216             # Now extract linker and other info.
1217             $linker = $language_map{$lang . '-linker'};
1219             local ($this_obj_ext);
1220             if ($language_map{$lang . '-ansi-p'})
1221             {
1222                 $object = $base . $obj;
1223                 $this_obj_ext = $obj;
1224             }
1225             else
1226             {
1227                 $object = $base . $nonansi_obj;
1228                 $this_obj_ext = $nonansi_obj;
1229             }
1231             if ($language_map{$lang . '-flags'} ne ''
1232                 && &variable_defined ($derived . '_'
1233                                       . $language_map{$lang . '-flags'}))
1234             {
1235                 # We have a per-executable flag in effect for this
1236                 # object.  In this case we rewrite the object's
1237                 # name to ensure it is unique.  We also require
1238                 # the `compile' program to deal with compilers
1239                 # where `-c -o' does not work.
1241                 # We choose the name `DERIVED-OBJECT' to ensure
1242                 # (1) uniqueness, and (2) continuity between
1243                 # invocations.  However, this will result in a
1244                 # name that is too long for losing systems, in
1245                 # some situations.  So we provide _SHORTNAME to
1246                 # override.
1248                 local ($dname) = $derived;
1249                 if (&variable_defined ($derived . '_SHORTNAME'))
1250                 {
1251                     # FIXME: should use the same conditional as
1252                     # the _SOURCES variable.  But this is really
1253                     # silly overkill -- nobody should have
1254                     # conditional shortnames.
1255                     $dname = &variable_value ($derived . '_SHORTNAME');
1256                 }
1257                 $object = $dname . '-' . $object;
1259                 &require_file ($FOREIGN, 'compile')
1260                     if $lang eq 'c';
1262                 &prog_error ("$lang flags defined without compiler")
1263                     if ! defined $language_map{$lang . '-compile'};
1265                 # Compute the rule to compile this object.
1266                 local ($flag) = $language_map{$lang . '-flags'};
1267                 local ($val) = "(${derived}_${flag}";
1268                 ($rule = $language_map{$lang . '-compile'}) =~
1269                     s/\(AM_$flag/$val/;
1271                 $rule .= ' ' . $language_map{$lang . '-output-arg'};
1272                 # For C we have to add the -o, because the
1273                 # standard rule doesn't include it.
1274                 if ($language_map{$lang . '-flags'} eq 'CFLAGS')
1275                 {
1276                     $rule .= ' -o $@';
1277                 }
1279                 $renamed = 1;
1280             }
1282             # If rewrite said it was ok, put the object into a
1283             # subdir.
1284             if ($r == $LANG_SUBDIR && $directory ne '')
1285             {
1286                 $object = $directory . '/' . $object;
1287                 $xbase = $directory . '/' . $base;
1288             }
1290             # If doing dependency tracking, then we can't print
1291             # the rule.  If we have a subdir object, we need to
1292             # generate an explicit rule.  Actually, in any case
1293             # where the object is not in `.' we need a special
1294             # rule.  The per-object rules in this case are
1295             # generated later, by add_depend2.
1296             if (($use_dependencies
1297                  && $rule ne ''
1298                  && $language_map{$lang . '-autodep'} ne 'no')
1299                 || $directory ne '')
1300             {
1301                 $rule = '';
1302                 local ($obj_sans_ext) = substr ($object, 0,
1303                                                 - length ($this_obj_ext));
1304                 $lang_specific_files{$lang} .= (' ' . $derived
1305                                                 . ' ' . $full
1306                                                 . ' ' . $obj_sans_ext);
1307             }
1308         }
1309         elsif ($extension eq 'o')
1310         {
1311             # This is probably the result of a direct suffix rule.
1312             # In this case we just accept the rewrite.  FIXME:
1313             # this fails if we want libtool objects.
1314             $object = $base . '.' . $extension;
1315             $linker = '';
1316         }
1317         else
1318         {
1319             # No error message here.  Used to have one, but it was
1320             # very unpopular.
1321             next;
1322         }
1324         $linkers_used{$linker} = 1;
1326         push (@result, $object);
1328         if (defined $object_map{$object})
1329         {
1330             if ($object_map{$object} ne $full)
1331             {
1332                 &am_error ("object \`$object' created by \`$full' and \`$object_map{$object}'");
1333             }
1334         }
1335         else
1336         {
1337             local (@dep_list) = ();
1338             $object_map{$object} = $full;
1340             # If file is in subdirectory, we need explicit
1341             # dependency.
1342             if ($directory ne '' || $renamed)
1343             {
1344                 push (@dep_list, $full);
1345             }
1347             # If resulting object is in subdir, we need to make
1348             # sure the subdir exists at build time.
1349             if ($object =~ /\//)
1350             {
1351                 # FIXME: check that $DIRECTORY is somewhere in the
1352                 # project
1354                 # We don't allow `..' in object file names for
1355                 # *any* source, not just Java.  For Java it just
1356                 # doesn't make sense, but in general it is
1357                 # a problem because we can't pick a good name for
1358                 # the .deps entry.
1359                 if ($object =~ /(\/|^)\.\.\//)
1360                 {
1361                     &am_error ("\`$full' contains \`..' component but should not");
1362                 }
1364                 push (@dep_list, $directory . '/.dirstamp');
1366                 # If we're generating dependencies, we also want
1367                 # to make sure that the appropriate subdir of the
1368                 # .deps directory is created.
1369                 if ($use_dependencies)
1370                 {
1371                     push (@dep_list, '.deps/' . $directory . '/.dirstamp');
1372                 }
1374                 if (! defined $directory_map{$directory})
1375                 {
1376                     $directory_map{$directory} = 1;
1377                     $output_rules .= ($directory . "/.dirstamp:\n"
1378                                       . "\t\@\$(mkinstalldirs) $directory\n"
1379                                       . "\t\@: > $directory/.dirstamp\n");
1380                     if ($use_dependencies)
1381                     {
1382                         $output_rules .= ('.deps/' . $directory
1383                                           . "/.dirstamp:\n"
1384                                           . "\t\@\$(mkinstalldirs) .deps/$directory\n"
1385                                           . "\t\@: > .deps/$directory/.dirstamp\n");
1386                     }
1387                 }
1388             }
1390             &pretty_print_rule ($object . ':', "\t", @dep_list)
1391                 if scalar @dep_list > 0 || $rule ne '';
1393             # Print the rule if we have one.
1394             if ($rule ne '')
1395             {
1396                 # Turn `$@' into name of our object file.
1397                 local ($xform);
1398                 ($xform = $object) =~ s,/,\\/,g;
1399                 $rule =~ s/\$\@/$xform/;
1401                 # We cannot use $< here since this is an explicit
1402                 # rule and not all makes handle that.
1403                 $rule .= " \`test -f $full || echo '\$(srcdir)/'\`$full";
1405                 # FIXME: handle .lo and .obj as well.
1406                 $output_rules .= "\t" . $rule . "\n";
1407             }
1408         }
1410         # Transform .o or $o file into .P file (for automatic
1411         # dependency code).
1412         if ($lang
1413             && ($language_map{$lang . '-autodep'} ne 'no'
1414                 || $language_map{$lang . '-derived-autodep'} eq 'yes'))
1415         {
1416             local ($depfile) = $object;
1417             $depfile =~ s/\.([^.]*)$/.P$1/;
1418             $depfile =~ s/\$\(OBJEXT\)$/o/ if $seen_objext;
1419             $dep_files{'$(DEPDIR)/' . $depfile} = 1;
1420         }
1421     }
1423     return (&resolve_linker (%linkers_used), @result);
1428 # Handle SOURCE->OBJECT transform for one program or library.
1429 # Arguments are:
1430 #   canonical (transformed) name of object to build
1431 #   actual name of object to build
1432 #   object extension (ie either `.o' or `$o'.
1433 # Return result is name of linker variable that must be used.
1434 # Empty return means just use `LINK'.
1435 sub handle_source_transform
1437     # one_file is canonical name.  unxformed is given name.  obj is
1438     # object extension.
1439     local ($one_file, $unxformed, $obj) = @_;
1441     local ($linker) = '';
1443     if (&variable_defined ($one_file . "_OBJECTS"))
1444     {
1445         &am_line_error ($one_file . '_OBJECTS',
1446                         $one_file . '_OBJECTS', 'should not be defined');
1447         # No point in continuing.
1448         return;
1449     }
1451     local (@files, @result, $prefix, $temp, $xpfx);
1452     local (%used_pfx) = ();
1453     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1454                      'dist_EXTRA_', 'nodist_EXTRA_')
1455     {
1456         # We are going to define _OBJECTS variables using the prefix.
1457         # Then we glom them all together.  So we can't use the null
1458         # prefix here as we need it later.
1459         $xpfx = ($prefix eq '') ? 'am_' : $prefix;
1461         @files = ();
1462         local ($var) = $prefix . $one_file . "_SOURCES";
1463         if (&variable_defined ($var))
1464         {
1465             # Keep track of which prefixes we saw.
1466             $used_pfx{$xpfx} = 1
1467                 unless $prefix =~ /EXTRA_/;
1469             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1470             push (@objects, '$(' . $xpfx . $one_file . "_OBJECTS)")
1471                 unless $prefix =~ /EXTRA_/;
1472             push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
1473                 unless $prefix =~ /^nodist_/;
1474             local (@conds) = &variable_conditions ($var);
1475             if (! @conds)
1476             {
1477                 @files = &variable_value_as_list ($var, '');
1478             }
1479             else
1480             {
1481                 local ($cond);
1482                 foreach $cond (@conds)
1483                 {
1484                     @files = &variable_value_as_list ($var, $cond);
1485                     ($temp, @result) =
1486                         &handle_single_transform_list ($var, $one_file, $obj,
1487                                                        @files);
1488                     $linker = $temp if $linker eq '';
1490                     # Define _OBJECTS conditionally.
1491                     &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
1492                                              $cond, @result)
1493                         unless $prefix =~ /EXTRA_/;
1494                 }
1496                 next;
1497             }
1498         }
1500         # Avoid defining needless variables.
1501         next if (scalar @files == 0);
1503         ($temp, @result) = &handle_single_transform_list ($var, $one_file,
1504                                                           $obj, @files);
1505         $linker = $temp if $linker eq '';
1506         &define_pretty_variable ($xpfx . $one_file . "_OBJECTS", '', @result)
1507             unless $prefix =~ /EXTRA_/;
1508     }
1510     local (@keys) = sort keys %used_pfx;
1511     if (scalar @keys == 0)
1512     {
1513         &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1514         push (@sources, $unxformed . '.c');
1515         push (@dist_sources, $unxformed . '.c');
1516         push (@objects, $unxformed . $obj);
1517         push (@files, $unxformed . '.c');
1519         ($temp, @result) = &handle_single_transform_list ($one_file . '_SOURCES',
1520                                                           $one_file, $obj,
1521                                                           @files);
1522         $linker = $temp if $linker eq '';
1523         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
1524     }
1525     else
1526     {
1527         grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
1528         &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
1529     }
1531     # If we want to use `LINK' we must make sure it is defined.
1532     if ($linker eq '')
1533     {
1534         $need_link = 1;
1535     }
1537     return $linker;
1541 # handle_lib_objects ()
1542 # ---------------------
1543 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1544 # Also, generate _DEPENDENCIES variable if appropriate.
1545 # Arguments are:
1546 #   transformed name of object being built, or empty string if no object
1547 #   name of _LDADD/_LIBADD-type variable to examine
1548 #   boolean (lex_seen) which is true if a lex source file was seen in this
1549 #     object.  valid only for LDADDs, not LIBADDs.
1550 # Returns 1 if LIBOBJS seen, 0 otherwise.
1551 sub handle_lib_objects
1553     local ($xname, $var, $lex_seen) = @_;
1554     local ($ret);
1556     &prog_error ("handle_lib_objects: $var undefined")
1557         if ! &variable_defined ($var);
1559     &prog_error ("handle_lib_objects: lex_seen and $var =~ /LIBADD/")
1560         if $lex_seen && $var =~ /LIBADD/;
1562     local (@conds) = &variable_conditions ($var);
1563     if (! @conds)
1564     {
1565         $ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
1566     }
1567     else
1568     {
1569         local ($cond);
1570         $ret = 0;
1571         foreach $cond (@conds)
1572         {
1573             if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
1574             {
1575                 $ret = 1;
1576             }
1577         }
1578     }
1580     return $ret;
1583 # Subroutine of handle_lib_objects: handle a particular condition.
1584 sub handle_lib_objects_cond
1586     local ($xname, $var, $lex_seen, $cond) = @_;
1588     # We recognize certain things that are commonly put in LIBADD or
1589     # LDADD.
1590     local ($lsearch);
1591     local (@dep_list) = ();
1593     local ($seen_libobjs) = 0;
1594     local ($flagvar) = 0;
1596     foreach $lsearch (&variable_value_as_list ($var, $cond))
1597     {
1598         # Skip -lfoo and -Ldir; these are explicitly allowed.
1599         next if $lsearch =~ /^-[lL]/;
1600         if (! $flagvar && $lsearch =~ /^-/)
1601         {
1602             if ($var =~ /^(.*)LDADD$/)
1603             {
1604                 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
1605                 next if $lsearch =~ /^-dl(pre)?open$/;
1606                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1607             }
1608             else
1609             {
1610                 # Only get this error once.
1611                 $flagvar = 1;
1612                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1613             }
1614         }
1616         # Assume we have a file of some sort, and push it onto the
1617         # dependency list.  Autoconf substitutions are not pushed;
1618         # rarely is a new dependency substituted into (eg) foo_LDADD
1619         # -- but "bad things (eg -lX11) are routinely substituted.
1620         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1621         # and handled specially below.
1622         push (@dep_list, $lsearch)
1623             unless $lsearch =~ /^\@.*\@$/;
1625         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1626         # means adding entries to dep_files.
1627         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1628         {
1629             local ($myobjext) = ($1 ? 'l' : '') . 'o';
1631             push (@dep_list, $lsearch);
1632             $seen_libobjs = 1;
1633             if (! keys %libsources
1634                 && ! &variable_defined ($1 . 'LIBOBJS'))
1635             {
1636                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`$configure_ac'");
1637             }
1639             local ($iter, $rewrite);
1640             foreach $iter (keys %libsources)
1641             {
1642                 if ($iter =~ /\.([cly])$/)
1643                 {
1644                     &saw_extension ($1);
1645                     &saw_extension ('c');
1646                 }
1648                 if ($iter =~ /\.h$/)
1649                 {
1650                     &require_file_with_line ($var, $FOREIGN, $iter);
1651                 }
1652                 elsif ($iter ne 'alloca.c')
1653                 {
1654                     ($rewrite = $iter) =~ s/\.c$/.P$myobjext/;
1655                     $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
1656                     ($rewrite = $iter) =~ s/(\W)/\\$1/g;
1657                     $rewrite = "^" . $rewrite . "\$";
1658                     # Only require the file if it is not a built source.
1659                     if (! &variable_defined ('BUILT_SOURCES')
1660                         || ! grep (/$rewrite/,
1661                                    &variable_value_as_list ('BUILT_SOURCES',
1662                                                             'all')))
1663                     {
1664                         &require_file_with_line ($var, $FOREIGN, $iter);
1665                     }
1666                 }
1667             }
1668         }
1669         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1670         {
1671             local ($myobjext) = ($1 ? 'l' : '') . 'o';
1673             push (@dep_list, $lsearch);
1674             &am_line_error ($var,
1675                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`$configure_ac'")
1676                 if ! defined $libsources{'alloca.c'};
1677             $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
1678             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1679             &saw_extension ('c');
1680         }
1681     }
1683     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
1684     {
1685         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
1686     }
1688     return $seen_libobjs;
1691 # Canonicalize a name, and check to make sure the non-canonical name
1692 # is never used.  Returns canonical name.  Arguments are name and a
1693 # list of suffixes to check for.
1694 sub check_canonical_spelling
1696     local ($name, @suffixes) = @_;
1697     local ($xname, $xt);
1699     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
1700     if ($xname ne $name)
1701     {
1702         local ($xt);
1703         foreach $xt (@suffixes)
1704         {
1705             &am_line_error ($name . $xt,
1706                             "invalid variable \`" . $name . $xt
1707                             . "'; should be \`" . $xname . $xt . "'")
1708                 if &variable_defined ($name . $xt);
1709         }
1710     }
1712     return $xname;
1716 # handle_programs ()
1717 # ------------------
1718 # Handle C programs.
1719 sub handle_programs
1721     local (@proglist) = &am_install_var ('-clean',
1722                                          'progs', 'PROGRAMS',
1723                                          'bin', 'sbin', 'libexec', 'pkglib',
1724                                          'noinst', 'check');
1725     return if ! @proglist;
1727     # If a program is installed, this is required.  We only want this
1728     # error to appear once.
1729     &am_conf_error ("AC_ARG_PROGRAM must be used")
1730         unless $seen_arg_prog;
1731     $seen_arg_prog = 1;
1733     local ($one_file, $xname, $munge);
1735     local ($seen_libobjs) = 0;
1736     foreach $one_file (@proglist)
1737     {
1738         local ($obj) = &get_object_extension ($one_file);
1740         # Canonicalize names and check for misspellings.
1741         $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
1742                                             '_SOURCES', '_OBJECTS',
1743                                             '_DEPENDENCIES');
1745         # FIXME: Using a trick to figure out if any lex sources appear
1746         # in our program; should use some cleaner method.
1747         local ($lex_num) = scalar (keys %lex_sources);
1748         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1749         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1751         local ($xt) = '';
1752         if (&variable_defined ($xname . "_LDADD"))
1753         {
1754             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1755                                      $lex_file_seen))
1756             {
1757                 $seen_libobjs = 1;
1758             }
1759             $lex_file_seen = 0;
1760             $xt = '_LDADD';
1761         }
1762         else
1763         {
1764             # User didn't define prog_LDADD override.  So do it.
1765             &define_variable ($xname . '_LDADD', '$(LDADD)');
1767             # This does a bit too much work.  But we need it to
1768             # generate _DEPENDENCIES when appropriate.
1769             if (&variable_defined ('LDADD'))
1770             {
1771                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1772                 {
1773                     $seen_libobjs = 1;
1774                 }
1775                 $lex_file_seen = 0;
1776             }
1777             elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
1778             {
1779                 &define_variable ($xname . '_DEPENDENCIES', '');
1780             }
1781             $xt = '_SOURCES'
1782         }
1784         if (&variable_defined ($xname . '_LIBADD'))
1785         {
1786             &am_line_error ($xname . '_LIBADD',
1787                             "use \`" . $xname . "_LDADD', not \`"
1788                             . $xname . "_LIBADD'");
1789         }
1791         if (! &variable_defined ($xname . '_LDFLAGS'))
1792         {
1793             # Define the prog_LDFLAGS variable.
1794             &define_variable ($xname . '_LDFLAGS', '');
1795         }
1797         # Determine program to use for link.
1798         local ($xlink);
1799         if (&variable_defined ($xname . '_LINK'))
1800         {
1801             $xlink = $xname . '_LINK';
1802         }
1803         else
1804         {
1805             $xlink = $linker ? $linker : 'LINK';
1806         }
1808         local ($exeext) = '';
1809         if ($seen_exeext && $one_file !~ /\./)
1810         {
1811             $exeext = '$(EXEEXT)';
1812         }
1814         $output_rules .= &file_contents ('program',
1815                                          &transform ('EXEEXT'   => $exeext,
1816                                                      'PROGRAM'  => $one_file,
1817                                                      'XPROGRAM' => $xname,
1818                                                      'XLINK'    => $xlink));
1819     }
1821     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1822     {
1823         $seen_libobjs = 1;
1824     }
1826     if ($seen_libobjs)
1827     {
1828         foreach $one_file (@proglist)
1829         {
1830             # Canonicalize names.
1831             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1833             if (&variable_defined ($xname . '_LDADD'))
1834             {
1835                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1836             }
1837             elsif (&variable_defined ('LDADD'))
1838             {
1839                 &check_libobjs_sources ($xname, 'LDADD');
1840             }
1841         }
1842     }
1846 # handle_libraries ()
1847 # -------------------
1848 # Handle libraries.
1849 sub handle_libraries
1851     local (@liblist) = &am_install_var ('-clean',
1852                                         'libs', 'LIBRARIES',
1853                                         'lib', 'pkglib', 'noinst', 'check');
1854     return if ! @liblist;
1856     local (%valid) = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
1857                                            'noinst', 'check');
1858     if (! defined $configure_vars{'RANLIB'})
1859     {
1860         local ($key);
1861         foreach $key (keys %valid)
1862         {
1863             if (&variable_defined ($key . '_LIBRARIES'))
1864             {
1865                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`$configure_ac'");
1866                 # Only get this error once.  If this is ever printed,
1867                 # we have a bug.
1868                 $configure_vars{'RANLIB'} = 'BUG';
1869                 last;
1870             }
1871         }
1872     }
1874     local ($onelib);
1875     local ($munge);
1876     local ($xlib);
1877     local ($seen_libobjs) = 0;
1878     foreach $onelib (@liblist)
1879     {
1880         # Check that the library fits the standard naming convention.
1881         if ($onelib !~ /^lib.*\.a$/)
1882         {
1883             # FIXME should put line number here.  That means mapping
1884             # from library name back to variable name.
1885             &am_error ("\`$onelib' is not a standard library name");
1886         }
1888         local ($obj) = &get_object_extension ($onelib);
1890         # Canonicalize names and check for misspellings.
1891         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
1892                                            '_OBJECTS', '_DEPENDENCIES', '_AR');
1894         if (! &variable_defined ($xlib . '_AR'))
1895         {
1896             &define_variable ($xlib . '_AR', '$(AR) cru');
1897         }
1899         if (&variable_defined ($xlib . '_LIBADD'))
1900         {
1901             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1902             {
1903                 $seen_libobjs = 1;
1904             }
1905         }
1906         else
1907         {
1908             # Generate support for conditional object inclusion in
1909             # libraries.
1910             &define_variable ($xlib . "_LIBADD", '');
1911         }
1913         if (&variable_defined ($xlib . '_LDADD'))
1914         {
1915             &am_line_error ($xlib . '_LDADD',
1916                             "use \`" . $xlib . "_LIBADD', not \`"
1917                             . $xlib . "_LDADD'");
1918         }
1920         # Make sure we at look at this.
1921         &examine_variable ($xlib . '_DEPENDENCIES');
1923         &handle_source_transform ($xlib, $onelib, $obj);
1925         $output_rules .= &file_contents ('library',
1926                                          &transform ('LIBRARY'  => $onelib,
1927                                                      'XLIBRARY' => $xlib));
1928     }
1930     if ($seen_libobjs)
1931     {
1932         foreach $onelib (@liblist)
1933         {
1934             # Canonicalize names.
1935             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1936             if (&variable_defined ($xlib . '_LIBADD'))
1937             {
1938                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1939             }
1940         }
1941     }
1943     &define_variable ('AR', 'ar');
1944     &define_configure_variable ('RANLIB');
1948 # handle_ltlibraries ()
1949 # ---------------------
1950 # Handle shared libraries.
1951 sub handle_ltlibraries
1953     local (@liblist) = &am_install_var ('-clean',
1954                                         'ltlib', 'LTLIBRARIES',
1955                                         'noinst', 'lib', 'pkglib', 'check');
1956     return if ! @liblist;
1958     local (%instdirs);
1959     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
1960                                            'noinst', 'check');
1962     local ($key);
1963     foreach $key (keys %valid)
1964     {
1965         if (&variable_defined ($key . '_LTLIBRARIES'))
1966         {
1967             if (!$seen_libtool)
1968             {
1969                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`$configure_ac'");
1970                 # Only get this error once.  If this is ever printed,
1971                 # we have a bug.
1972                 $configure_vars{'LIBTOOL'} = 'BUG';
1973                 $seen_libtool = 1;
1974             }
1976             # Get the installation directory of each library.
1977             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
1978             {
1979                 if ($instdirs{$_})
1980                 {
1981                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1982                 }
1983                 else
1984                 {
1985                     $instdirs{$_} = $key;
1986                 }
1987             }
1988         }
1989     }
1991     local ($onelib);
1992     local ($munge);
1993     local ($xlib);
1994     local ($seen_libobjs) = 0;
1995     foreach $onelib (@liblist)
1996     {
1997         local ($obj) = &get_object_extension ($onelib);
1999         # Canonicalize names and check for misspellings.
2000         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2001                                            '_SOURCES', '_OBJECTS',
2002                                            '_DEPENDENCIES');
2004         if (! &variable_defined ($xlib . '_LDFLAGS'))
2005         {
2006             # Define the lib_LDFLAGS variable.
2007             &define_variable ($xlib . '_LDFLAGS', '');
2008         }
2010         # Check that the library fits the standard naming convention.
2011         $libname_rx = "^lib.*\.la";
2012         if ((&variable_defined ($xlib . '_LDFLAGS')
2013              && grep (/-module/, &variable_value_as_list ($xlib . '_LDFLAGS',
2014                                                           'all')))
2015             || (&variable_defined ('LDFLAGS')
2016                 && grep (/-module/, &variable_value_as_list ('LDFLAGS',
2017                                                              'all'))))
2018         {
2019                 # Relax name checking for libtool modules.
2020                 $libname_rx = "\.la";
2021         }
2022         if ($onelib !~ /$libname_rx$/)
2023         {
2024             # FIXME this should only be a warning for foreign packages
2025             # FIXME should put line number here.  That means mapping
2026             # from library name back to variable name.
2027             &am_error ("\`$onelib' is not a standard libtool library name");
2028         }
2030         if (&variable_defined ($xlib . '_LIBADD'))
2031         {
2032             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
2033             {
2034                 $seen_libobjs = 1;
2035             }
2036         }
2037         else
2038         {
2039             # Generate support for conditional object inclusion in
2040             # libraries.
2041             &define_variable ($xlib . "_LIBADD", '');
2042         }
2044         if (&variable_defined ($xlib . '_LDADD'))
2045         {
2046             &am_line_error ($xlib . '_LDADD',
2047                             "use \`" . $xlib . "_LIBADD', not \`"
2048                             . $xlib . "_LDADD'");
2049         }
2051         # Make sure we at look at this.
2052         &examine_variable ($xlib . '_DEPENDENCIES');
2054         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
2056         # Determine program to use for link.
2057         local ($xlink);
2058         if (&variable_defined ($xlib . '_LINK'))
2059         {
2060             $xlink = $xlib . '_LINK';
2061         }
2062         else
2063         {
2064             $xlink = $linker ? $linker : 'LINK';
2065         }
2067         local ($rpath);
2068         if ($instdirs{$onelib} eq 'EXTRA'
2069             || $instdirs{$onelib} eq 'noinst'
2070             || $instdirs{$onelib} eq 'check')
2071         {
2072             # It's an EXTRA_ library, so we can't specify -rpath,
2073             # because we don't know where the library will end up.
2074             # The user probably knows, but generally speaking automake
2075             # doesn't -- and in fact configure could decide
2076             # dynamically between two different locations.
2077             $rpath = '';
2078         }
2079         else
2080         {
2081             $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
2082         }
2084         $output_rules .= &file_contents ('ltlibrary',
2085                                          &transform ('LTLIBRARY'  => $onelib,
2086                                                      'XLTLIBRARY' => $xlib,
2087                                                      'RPATH'      => $rpath,
2088                                                      'XLINK'      => $xlink));
2089     }
2091     if ($seen_libobjs)
2092     {
2093         foreach $onelib (@liblist)
2094         {
2095             # Canonicalize names.
2096             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
2097             if (&variable_defined ($xlib . '_LIBADD'))
2098             {
2099                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2100             }
2101         }
2102     }
2105 # See if any _SOURCES variable were misspelled.  Also, make sure that
2106 # EXTRA_ variables don't contain configure substitutions.
2107 sub check_typos
2109     local ($varname, $primary);
2110     foreach $varname (keys %contents)
2111     {
2112         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
2113                           '_DEPENDENCIES')
2114         {
2115             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
2116             {
2117                 &am_line_error ($varname,
2118                                 "invalid unused variable name: \`$varname'");
2119             }
2120         }
2121     }
2124 # Handle scripts.
2125 sub handle_scripts
2127     # NOTE we no longer automatically clean SCRIPTS, because it is
2128     # useful to sometimes distribute scripts verbatim.  This happens
2129     # eg in Automake itself.
2130     &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2131                      'bin', 'sbin', 'libexec', 'pkgdata',
2132                      'noinst', 'check');
2134     local ($scripts_installed) = 0;
2135     # Set $scripts_installed if appropriate.  Make sure we only find
2136     # scripts which are actually installed -- this is why we can't
2137     # simply use the return value of am_install_var.
2138     local (%valid) = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
2139                                            'libexec', 'pkgdata',
2140                                            'noinst', 'check');
2141     local ($key);
2142     foreach $key (keys %valid)
2143     {
2144         if ($key ne 'noinst'
2145             && $key ne 'check'
2146             && &variable_defined ($key . '_SCRIPTS'))
2147         {
2148             $scripts_installed = 1;
2149             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
2150         }
2151     }
2153     if ($scripts_installed)
2154     {
2155         # If a program is installed, this is required.  We only want this
2156         # error to appear once.
2157         &am_conf_error ("AC_ARG_PROGRAM must be used")
2158             unless $seen_arg_prog;
2159         $seen_arg_prog = 1;
2160     }
2163 # Search a file for a "version.texi" Texinfo include.  Return the name
2164 # of the include file if found, or the empty string if not.  A
2165 # "version.texi" file is actually any file whose name matches
2166 # "vers*.texi".
2167 sub scan_texinfo_file
2169     local ($filename) = @_;
2171     if (! open (TEXI, $filename))
2172     {
2173         &am_error ("couldn't open \`$filename': $!");
2174         return '';
2175     }
2176     print "automake: reading $filename\n" if $verbose;
2178     local ($vfile, $outfile);
2179     while (<TEXI>)
2180     {
2181         if (/^\@setfilename +(\S+)/)
2182         {
2183             $outfile = $1;
2184             last if ($vfile);
2185         }
2187         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2188         {
2189             # Found version.texi include.
2190             $vfile = $1;
2191             last if $outfile;
2192         }
2193     }
2195     close (TEXI);
2196     return ($outfile, $vfile);
2200 # handle_texinfo ()
2201 # -----------------
2202 # Handle all Texinfo source.
2203 sub handle_texinfo
2205     &am_line_error ('TEXINFOS',
2206                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
2207         if &variable_defined ('TEXINFOS');
2208     return if (! &variable_defined ('info_TEXINFOS')
2209                && ! &variable_defined ('html_TEXINFOS'));
2211     if (&variable_defined ('html_TEXINFOS'))
2212     {
2213         &am_line_error ('html_TEXINFOS',
2214                         "HTML generation not yet supported");
2215         return;
2216     }
2218     local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');
2220     local (@info_deps_list, @dvis_list, @texi_deps);
2221     local ($infobase, $info_cursor);
2222     local (%versions);
2223     local ($done) = 0;
2224     local ($vti);
2225     local ($tc_cursor, @texi_cleans);
2226     local ($canonical);
2228     foreach $info_cursor (@texis)
2229     {
2230         # FIXME: This is mildly hacky, since it recognizes "txinfo".
2231         # I don't feel like making it right.
2232         ($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;
2234         # If 'version.texi' is referenced by input file, then include
2235         # automatic versioning capability.
2236         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
2237                                                         . "/" . $info_cursor);
2239         if ($out_file eq '')
2240         {
2241             &am_error ("\`$info_cursor' missing \@setfilename");
2242             next;
2243         }
2245         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
2246         {
2247             # FIXME should report line number in input file.
2248             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
2249             next;
2250         }
2252         if ($vtexi)
2253         {
2254             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
2255                 if (defined $versions{$vtexi});
2256             $versions{$vtexi} = $info_cursor;
2258             # We number the stamp-vti files.  This is doable since the
2259             # actual names don't matter much.  We only number starting
2260             # with the second one, so that the common case looks nice.
2261             $vti = ($done ? $done : 'vti');
2262             ++$done;
2264             &push_dist_common ($vtexi, 'stamp-' . $vti);
2266             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2267                                           'mdate-sh');
2269             local ($conf_dir);
2270             if ($config_aux_dir eq '.' || $config_aux_dir eq '')
2271             {
2272                 $conf_dir = '$(srcdir)/';
2273             }
2274             else
2275             {
2276                 $conf_dir = $config_aux_dir;
2277                 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
2278             }
2279             $output_rules .=
2280                 &file_contents ('texi-vers',
2281                                 &transform ('TEXI'         => $info_cursor,
2282                                             'VTI'          => $vti,
2283                                             'VTEXI'        => $vtexi,
2284                                             'MDDIR'        => $conf_dir,
2285                                             'CONFIGURE_AC' => $configure_ac));
2286         }
2288         # If user specified file_TEXINFOS, then use that as explicit
2289         # dependency list.
2290         @texi_deps = ();
2291         push (@texi_deps, $info_cursor);
2292         # Prefix with $(srcdir) because some version of make won't
2293         # work if the target has it and the dependency doesn't.
2294         push (@texi_deps, '$(srcdir)/' . $vtexi) if $vtexi;
2296         # Canonicalize name first.
2297         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
2298         if (&variable_defined ($canonical . "_TEXINFOS"))
2299         {
2300             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
2301             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
2302         }
2304         $output_rules .= ("\n" . $out_file . ": "
2305                           . join (' ', @texi_deps)
2306                           . "\n" . $infobase . ".dvi: "
2307                           . join (' ', @texi_deps)
2308                           . "\n\n");
2310         push (@info_deps_list, $out_file);
2311         push (@dvis_list, $infobase . '.dvi');
2313         # Generate list of things to clean for this target.  We do
2314         # this explicitly because otherwise too many things could be
2315         # removed.  In particular the ".log" extension might
2316         # reasonably be used in other contexts by the user.
2317         # FIXME: this is really out of control.
2318         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns', 'pgs',
2319                             'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
2320                             'vr', 'vrs', 'op', 'tr', 'cv', 'cn', 'cm', 'ov')
2321         {
2322             push (@texi_cleans, $infobase . '.' . $tc_cursor);
2323         }
2324     }
2326     # Find these programs wherever they may lie.  Yes, this has
2327     # intimate knowledge of the structure of the texinfo distribution.
2328     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
2329                               'makeinfo',
2330                               # Circumlocution to avoid accidental
2331                               # configure substitution.
2332                               '@MAKE' . 'INFO@');
2333     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
2334                               'texi2dvi');
2336     # Set transform for including texinfos.am.  First, handle --cygnus
2337     # stuff.
2338     local ($xform);
2339     if ($cygnus_mode)
2340     {
2341         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
2342     }
2343     else
2344     {
2345         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
2346     }
2348     # Handle location of texinfo.tex.
2349     local ($need_texi_file) = 0;
2350     local ($texinfodir);
2351     if ($cygnus_mode)
2352     {
2353         $texinfodir = '$(top_srcdir)/../texinfo';
2354         &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
2356     }
2357     elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
2358     {
2359         $texinfodir = $config_aux_dir;
2360         &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
2361         $need_texi_file = 2; # so that we require_conf_file later
2362     }
2363     elsif (&variable_defined ('TEXINFO_TEX'))
2364     {
2365         # The user defined TEXINFO_TEX so assume he knows what he is
2366         # doing.
2367         $texinfodir = ('$(srcdir)/'
2368                        . &dirname (&variable_value ('TEXINFO_TEX')));
2369     }
2370     else
2371     {
2372         $texinfodir = '$(srcdir)';
2373         $need_texi_file = 1;
2374     }
2375     $xform .= &transform ('TEXINFODIR' => $texinfodir,
2376                           'TEXICLEAN' => &pretty_print_internal ("\t-rm -f",
2377                                                                  "\t  ",
2378                                                                  @texi_cleans));
2380     $output_rules .= &file_contents ('texinfos', $xform);
2381     push (@dist_targets, 'dist-info');
2383     if ($cygnus_mode)
2384     {
2385         $output_rules .= "clean-info: mostlyclean-aminfo\n";
2386     }
2388     push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');
2390     if (! defined $options{'no-installinfo'})
2391     {
2392         push (@uninstall, 'uninstall-info');
2393         push (@installdirs, '$(DESTDIR)$(infodir)');
2394         unshift (@install_data, 'install-info-am');
2396         # Make sure documentation is made and installed first.  Use
2397         # $(INFO_DEPS), not 'info', because otherwise recursive makes
2398         # get run twice during "make all".
2399         unshift (@all, '$(INFO_DEPS)');
2400     }
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');
2434     # Find all the sections in use.  We do this by first looking for
2435     # "standard" sections, and then looking for any additional
2436     # sections used in man_MANS.
2437     local ($sect, %sections, %vlist);
2438     local ($found) = 0;
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             $found = 1;
2447         }
2448     }
2450     if (&variable_defined ('man_MANS'))
2451     {
2452         $vlist{'$(man_MANS)'} = 1;
2453         foreach (&variable_value_as_list ('man_MANS', 'all'))
2454         {
2455             # A page like `foo.1c' goes into man1dir.
2456             if (/\.([0-9a-z])([a-z]*)$/)
2457             {
2458                 $sections{$1} = 1;
2459                 $found = 1;
2460             }
2461         }
2462     }
2464     return unless $found;
2466     # Now for each section, generate an install and unintall rule.
2467     # Sort sections so output is deterministic.
2468     local (@namelist);
2469     foreach $sect (sort keys %sections)
2470     {
2471         &define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
2472         push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
2473             unless defined $options{'no-installman'};
2474         $output_rules .= &file_contents ('mans',
2475                                          &transform ('SECTION', $sect));
2476         push (@namelist, 'install-man' . $sect);
2477     }
2479     # We don't really need this, but we use it in case we ever want to
2480     # support noinst_MANS.
2481     &define_variable ("MANS", join (' ', sort keys %vlist));
2483     # Generate list of install dirs.
2484     $output_rules .= ("install-man: \$(MANS)\n"
2485                       . "\t\@\$(NORMAL_INSTALL)\n");
2486     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2487     &depend ('.PHONY', 'install-man');
2489     $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
2490     grep ($_ = 'un' . $_, @namelist);
2491     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2492     &depend ('.PHONY', 'uninstall-man');
2494     $output_vars .= &file_contents ('mans-vars');
2496     if (! defined $options{'no-installman'})
2497     {
2498         push (@install_data, 'install-man');
2499         push (@uninstall, 'uninstall-man');
2500         push (@all, '$(MANS)');
2501     }
2504 # Handle DATA variables.
2505 sub handle_data
2507     &am_install_var ('-noextra', '-candist', 'data', 'DATA',
2508                      'data', 'sysconf', 'sharedstate', 'localstate',
2509                      'pkgdata', 'noinst', 'check');
2512 # Handle TAGS.
2513 sub handle_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         &depend ('.PHONY', 'tags-recursive');
2527     }
2529     if (&saw_sources_p (1)
2530         || &variable_defined ('ETAGS_ARGS')
2531         || @tag_deps)
2532     {
2533         local ($config) = '';
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                 $config .= ' ' if $config;
2541                 $config .= &basename ($one_hdr);
2542             }
2543         }
2544         local $xform = &transform ('CONFIG' => $xform,
2545                                    'DIRS'   => join (' ', @tag_deps));
2547         if (&variable_defined ('SUBDIRS'))
2548         {
2549             $xform .= 's/^SUBDIRS//;';
2550         }
2551         else
2552         {
2553             $xform .= 's/^SUBDIRS.*$//;';
2554         }
2556         $output_rules .= &file_contents ('tags', $xform);
2557         $output_rules .= &file_contents ('tags-clean');
2558         &examine_variable ('TAGS_DEPENDENCIES');
2559     }
2560     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2561     {
2562         &am_line_error ('TAGS_DEPENDENCIES',
2563                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2564     }
2565     else
2566     {
2567         # Every Makefile must define some sort of TAGS rule.
2568         # Otherwise, it would be possible for a top-level "make TAGS"
2569         # to fail because some subdirectory failed.
2570         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2571     }
2574 # Handle multilib support.
2575 sub handle_multilib
2577     return unless $seen_multilib;
2579     $output_rules .= &file_contents ('multilib');
2582 # Worker for handle_dist.
2583 sub handle_dist_worker
2585     my ($makefile) = @_;
2586     my $xform = '';
2588     # Initialization; only at top level.
2589     if ($relative_dir eq '.')
2590     {
2591         $xform .= 's/\@TOPDIR\@//g;';
2592     }
2593     else
2594     {
2595         $xform .= 's/\@TOPDIR\@.*//g;';
2596     }
2598     if (defined $options{'check-news'})
2599     {
2600         $xform .= 's/\@CK-NEWS\@//g;';
2601     }
2602     else
2603     {
2604         $xform .= 's/\@CK-NEWS\@.*//g;';
2605     }
2607     # Scan EXTRA_DIST to see if we need to distribute anything from a
2608     # subdir.  If so, add it to the list.  I didn't want to do this
2609     # originally, but there were so many requests that I finally
2610     # relented.
2611     if (&variable_defined ('EXTRA_DIST'))
2612     {
2613         # FIXME: This should be fixed to work with conditionals.  That
2614         # will require only making the entries in @dist_dirs under the
2615         # appropriate condition.  This is meaningful if the nature of
2616         # the distribution should depend upon the configure options
2617         # used.
2618         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
2619         {
2620             next if /^\@.*\@$/;
2621             next unless s,/+[^/]+$,,;
2622             $dist_dirs{$_} = 1
2623                 unless $_ eq '.';
2624         }
2625     }
2627     # We have to check DIST_COMMON for extra directories in case the
2628     # user put a source used in AC_OUTPUT into a subdir.
2629     foreach (&variable_value_as_list ('DIST_COMMON', 'all'))
2630     {
2631         next if /^\@.*\@$/;
2632         next unless s,/+[^/]+$,,;
2633         $dist_dirs{$_} = 1
2634             unless $_ eq '.';
2635     }
2637     if (scalar keys %dist_dirs)
2638     {
2639         # Prepend $(distdir) to each directory given.  Doing it via a
2640         # hash lets us ensure that each directory is used only once.
2641         grep ($dist_dirs{'$(distdir)/' . $_} = 1, keys %dist_dirs);
2642         $xform .= &transform ('DISTDIRS', join (' ', sort keys %dist_dirs));
2643     }
2644     else
2645     {
2646         $xform .= 's/.*\@DISTDIRS\@.*//g;';
2647     }
2649     if ($cygnus_mode)
2650     {
2651         $xform .= 's/\@CYGNUS\@\t*/\t/g;';
2652         $xform .= 's/.*\@NCYGNUS\@.*//g;';
2653     }
2654     else
2655     {
2656         $xform .= 's/\@NCYGNUS\@\t*/\t/g;';
2657         $xform .= 's/.*\@CYGNUS\@.*//g;';
2658     }
2660     # If we have SUBDIRS, create all dist subdirectories and do
2661     # recursive build.
2662     if (&variable_defined ('SUBDIRS'))
2663     {
2664         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
2665         # to all possible directories, and use it.  If DIST_SUBDIRS is
2666         # defined, just use it.
2667         local ($dist_subdir_name);
2668         if (&variable_conditions ('SUBDIRS')
2669             || &variable_defined ('DIST_SUBDIRS'))
2670         {
2671             $dist_subdir_name = 'DIST_SUBDIRS';
2672             if (! &variable_defined ('DIST_SUBDIRS'))
2673             {
2674                 local (@full_list) = &variable_value_as_list ('SUBDIRS',
2675                                                               'all');
2676                 local (@ds_list, %uniq, $iter);
2677                 foreach $iter (@full_list)
2678                 {
2679                     if (! defined $uniq{$iter})
2680                     {
2681                         $uniq{$iter} = 1;
2682                         push (@ds_list, $iter);
2683                     }
2684                 }
2685                 &define_pretty_variable ('DIST_SUBDIRS', '', @ds_list);
2686             }
2687         }
2688         else
2689         {
2690             $dist_subdir_name = 'SUBDIRS';
2691             # We always define this because that is what `distclean'
2692             # wants.
2693             &define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
2694         }
2696         $xform .= ('s/\@SUBDIRS\@//g;'
2697                    . &transform ('DIST_SUBDIR_NAME'
2698                                  => $dist_subdir_name,
2699                                  'TOP_DISTDIR'
2700                                  => (($relative_dir eq '.')
2701                                      ? 'distdir' : 'top_distdir')));
2702     }
2703     else
2704     {
2705         $xform .= 's/\@SUBDIRS\@.*//g;';
2706     }
2708     $output_rules .= &file_contents ('distdir', $xform);
2710     # If the target `dist-hook' exists, make sure it is run.  This
2711     # allows users to do random weird things to the distribution
2712     # before it is packaged up.
2713     push (@dist_targets, 'dist-hook') if &target_defined ('dist-hook');
2715     local ($targ);
2716     foreach $targ (@dist_targets)
2717     {
2718         # We must explicitly set distdir and top_distdir for these
2719         # sub-makes.
2720         $output_rules .= ("\t\$(MAKE) \$(AM_MAKEFLAGS)"
2721                           . " top_distdir=\"\$(top_distdir)\""
2722                           . " distdir=\"\$(distdir)\" $targ\n");
2723     }
2726 # Handle 'dist' target.
2727 sub handle_dist
2729     local ($makefile) = @_;
2731     # Set up maint_charset.
2732     $local_maint_charset = &variable_value ('MAINT_CHARSET')
2733         if &variable_defined ('MAINT_CHARSET');
2734     $maint_charset = $local_maint_charset
2735         if $relative_dir eq '.';
2737     if (&variable_defined ('DIST_CHARSET'))
2738     {
2739         &am_line_error ('DIST_CHARSET',
2740                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2741             if ! $local_maint_charset;
2742         if ($relative_dir eq '.')
2743         {
2744             $dist_charset = &variable_value ('DIST_CHARSET')
2745         }
2746         else
2747         {
2748             &am_line_error ('DIST_CHARSET',
2749                             "DIST_CHARSET can only be defined at top level");
2750         }
2751     }
2753     # Look for common files that should be included in distribution.
2754     local ($cfile);
2755     foreach $cfile (@common_files)
2756     {
2757         if (-f ($relative_dir . "/" . $cfile))
2758         {
2759             &push_dist_common ($cfile);
2760         }
2761     }
2763     # Always require configure.ac and configure at top level, even if
2764     # they don't exist.  This is especially important for configure,
2765     # since it won't be created until autoconf is run -- which might
2766     # be after automake is run.
2767     &push_dist_common ($configure_ac, 'configure')
2768         if $relative_dir eq '.';
2770     # We might copy elements from %configure_dist_common to
2771     # %dist_common if we think we need to.  If the file appears in our
2772     # directory, we would have discovered it already, so we don't
2773     # check that.  But if the file is in a subdir without a Makefile,
2774     # we want to distribute it here if we are doing `.'.  Ugly!
2775     if ($relative_dir eq '.')
2776     {
2777         local ($iter);
2778         foreach $iter (keys %configure_dist_common)
2779         {
2780             if (! &is_make_dir (&dirname ($iter)))
2781             {
2782                 &push_dist_common ($iter);
2783             }
2784         }
2785     }
2787     # Keys of %dist_common are names of files to distributed.  We put
2788     # README first because it then becomes easier to make a
2789     # Usenet-compliant shar file (in these, README must be first).
2790     # FIXME: do more ordering of files here.
2791     local (@coms);
2792     if (defined $dist_common{'README'})
2793     {
2794         push (@coms, 'README');
2795         delete $dist_common{'README'};
2796     }
2797     push (@coms, sort keys %dist_common);
2799     # Now that we've processed %dist_common, disallow further attempts
2800     # to set it.
2801     $handle_dist_run = 1;
2803     &define_pretty_variable ("DIST_COMMON", '', @coms);
2804     $output_vars .= "\n";
2806     # Some boilerplate.
2807     $output_vars .= &file_contents ('dist-vars') . "\n";
2808     &define_variable ('GZIP_ENV', '--best');
2810     # Put these things in rules section so it is easier for whoever
2811     # reads Makefile.in.
2812     if (! &variable_defined ('distdir'))
2813     {
2814         if ($relative_dir eq '.')
2815         {
2816             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2817         }
2818         else
2819         {
2820             $output_rules .= ("\n"
2821                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2822                               . "\n");
2823         }
2824     }
2825     if ($relative_dir eq '.')
2826     {
2827         $output_rules .= "top_distdir = \$(distdir)\n";
2828     }
2829     $output_rules .= "\n";
2831     # Generate 'dist' target, and maybe other dist targets.
2832     if ($relative_dir eq '.')
2833     {
2834         # Rule to check whether a distribution is viable.
2835         local ($xform) = '';
2837         if (&target_defined ('distcheck-hook'))
2838         {
2839             $xform .= 's/^DISTHOOK//;';
2840         }
2841         else
2842         {
2843             $xform .= 's/^DISTHOOK.*$//;';
2844         }
2845         if ($seen_gettext)
2846         {
2847             $xform .= 's/^GETTEXT//;';
2848         }
2849         else
2850         {
2851             $xform .= 's/^GETTEXT.*$//;';
2852         }
2854         # Arg, this file should have been named `distcheck'.
2855         $output_rules .= &file_contents ('dist', $xform);
2857         local ($dist_all) = ('dist-all: distdir' . "\n"
2858                              . $dist_header);
2859         local ($curs);
2860         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ',
2861                        'dist-bzip2')
2862         {
2863             if (defined $options{$curs} || $curs eq 'dist')
2864             {
2865                 $output_rules .= ($curs . ': distdir' . "\n"
2866                                   . $dist_header
2867                                   . $dist{$curs}
2868                                   . $dist_trailer);
2869                 $dist_all .= $dist{$curs};
2870             }
2871         }
2872         $output_rules .= $dist_all . $dist_trailer;
2873     }
2875     # Generate distdir target.
2876     &handle_dist_worker ($makefile);
2880 # add_depend2 ($LANG)
2881 # -------------------
2882 # A subroutine of handle_dependencies.  This function includes
2883 # `depend2' with appropriate transformations.
2884 sub add_depend2
2886     local ($lang) = @_;
2888     # Get information on $LANG.
2889     my $pfx = $language_map{"$lang-autodep"};
2890     my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
2891     my $flag = $language_map{"$lang-flags"};
2893     # First include code for ordinary objects.
2894     local ($xform, $ext);
2895     $xform = &transform ('PFX'  => $pfx,
2896                          'FPFX' => $fpfx);
2897     $xform .= $seen_objext  ? 's/^OBJEXT//;'  : 's/^OBJEXT.*$//;';
2898     $xform .= $seen_libtool ? 's/^LIBTOOL//;' : 's/^LIBTOOL.*$//;';
2900     # This function can be called even when we don't want dependency
2901     # tracking.  This happens when we need an explicit rule for some
2902     # target.  In this case we don't want to include the generic code.
2903     if ($use_dependencies)
2904     {
2905         my $compile = '$(' . $pfx . 'COMPILE)';
2906         my $ltcompile = '$(LT' . $pfx . 'COMPILE)';
2907         my $xform1 = ($xform
2908                       . &transform ('BASE'      => '$*',
2909                                     'SOURCE'    => '$<',
2910                                     'OBJ'       => '$@',
2911                                     'LTOBJ'     => '$@',
2912                                     'OBJOBJ'    => '$@',
2913                                     'COMPILE'   => $compile,
2914                                     'LTCOMPILE' => $ltcompile));
2916         foreach $ext (&lang_extensions ($lang))
2917         {
2918             $output_rules .= (&file_contents ('depend2',
2919                                               &transform ('EXT' => $ext)
2920                                               . $xform1)
2921                               . "\n");
2922         }
2923     }
2925     # Now include code for each specially handled object with this
2926     # language.
2927     local (@list) = grep ($_ ne '', split (' ', $lang_specific_files{$lang}));
2928     local ($max) = scalar @list;
2929     local ($i) = 0;
2930     local ($derived, $source, $obj);
2932     # If dependency tracking is disabled, we just elide the code.
2933     if (! $use_dependencies)
2934     {
2935         $xform .= 's/\@AMDEP\@.*$//;';
2936     }
2938     while ($i < $max)
2939     {
2940         $derived = $list[$i];
2941         $source = $list[$i + 1];
2942         $obj = $list[$i + 2];
2943         $i += 3;
2945         my $val = "${derived}_${flag}";
2947         my $obj_compile = $language_map{"$lang-compile"};
2948         $obj_compile =~ s/\(AM_$flag/\($val/;
2949         my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
2951         # Generate a transform which will turn suffix targets in
2952         # depend2.am into real targets for the particular objects we
2953         # are building.
2954         $output_rules .=
2955             &file_contents
2956                 ('depend2',
2957                  $xform
2958                  . &transform ('COMPILE'   => $obj_compile,
2959                                'LTCOMPILE' => $obj_ltcompile,
2960                                # Handle source and obj transforms.
2961                                'OBJ'       => $obj . '.o',
2962                                'OBJOBJ'    => $obj . '.obj',
2963                                'LTOBJ'     => $obj . '.lo',
2964                                'BASE'      => $obj,
2965                                'SOURCE'    => $source)
2966                  # Generate rule for `.o'.
2967                  . 's/^\@EXT\@\.o:/' . "\Q$obj.o: $source\E" . '/g;'
2968                  # Maybe generate rule for `.lo'.  Might be eliminated
2969                  # by $XFORM.
2970                  . 's/^\@EXT\@\.lo:/' . "\Q$obj.lo: $source\E" . '/g;'
2971                  # Maybe generate rule for `.obj'.  Might be
2972                  # eliminated by $XFORM.
2973                  . 's/^\@EXT\@\.obj:/' . "\Q$obj.obj: $source\E" . '/g;');
2974     }
2977 # Handle auto-dependency code.
2978 sub handle_dependencies
2980     if ($use_dependencies)
2981     {
2982         # Include auto-dep code.  Don't include it if DEP_FILES would
2983         # be empty.
2984         if (&saw_sources_p (0) && keys %dep_files)
2985         {
2986             local ($config_aux_dir_specified) = ($config_aux_dir ne '.'
2987                                                  && $config_aux_dir ne '');
2989             # Set $require_file_found{'depcomp'} if the depcomp file exists,
2990             # before calling require_config_file on `depcomp'.  This makes
2991             # require_file_internal skip its buggy existence test that would
2992             # make automake fail (with `required file `lib/depcomp' not found')
2993             # when AC_CONFIG_AUX_DIR is not set.  See tests/subdir4.test.
2994             local ($depcomp_dir) = ($config_aux_dir_specified ? $config_aux_dir
2995                                     : '.');
2996             $require_file_found{'depcomp'} = 1 if -f "$depcomp_dir/depcomp";
2998             # Set location of depcomp.
2999             local ($prefix) = ($config_aux_dir_specified ? $config_aux_dir
3000                                : '$(top_srcdir)');
3002             &define_variable ('depcomp', "\$(SHELL) $prefix/depcomp");
3004             &require_config_file ($FOREIGN, 'depcomp');
3006             local ($iter);
3007             local (@deplist) = sort keys %dep_files;
3009             # We define this as a conditional variable because BSD
3010             # make can't handle backslashes for continuing comments on
3011             # the following line.
3012             &define_pretty_variable ('DEP_FILES', "\@AMDEP\@", @deplist);
3014             # Generate each `include' individually.  Irix 6 make will
3015             # not properly include several files resulting from a
3016             # variable expansion; generating many separate includes
3017             # seems safest.
3018             $output_rules .= "\n";
3019             foreach $iter (@deplist)
3020             {
3021                 $output_rules .= "\@AMDEP\@\@AMINCLUDE\@ " . $iter . "\n";
3022             }
3024             $output_rules .= &file_contents ('depend');
3025         }
3026     }
3027     else
3028     {
3029         &define_variable ('depcomp', '');
3030     }
3032     local ($key, $lang, $ext, $xform);
3033     foreach $key (sort keys %language_map)
3034     {
3035         next unless $key =~ /^(.*)-autodep$/;
3036         next if $language_map{$key} eq 'no';
3037         &add_depend2 ($1);
3038     }
3041 # Handle subdirectories.
3042 sub handle_subdirs
3044     return if ! &variable_defined ('SUBDIRS');
3046     # Make sure each directory mentioned in SUBDIRS actually exists.
3047     local ($dir);
3048     foreach $dir (&variable_value_as_list ('SUBDIRS', 'all'))
3049     {
3050         # Skip directories substituted by configure.
3051         next if $dir =~ /^\@.*\@$/;
3053         if (! -d $am_relative_dir . '/' . $dir)
3054         {
3055             &am_line_error ('SUBDIRS',
3056                             "required directory $am_relative_dir/$dir does not exist");
3057             next;
3058         }
3060         &am_line_error ('SUBDIRS', "directory should not contain \`/'")
3061             if $dir =~ /\//;
3062     }
3064     local ($xform) = ('s/\@INSTALLINFO\@/' .
3065                       (defined $options{'no-installinfo'}
3066                        ? 'install-info-recursive'
3067                        : '')
3068                       . '/;');
3069     $output_rules .= &file_contents ('subdirs', $xform);
3071     $recursive_install = 1;
3074 # Handle aclocal.m4.
3075 sub handle_aclocal_m4
3077     local ($regen_aclocal) = 0;
3078     if (-f 'aclocal.m4')
3079     {
3080         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3081         &push_dist_common ('aclocal.m4');
3083         if (open (ACLOCAL, '< aclocal.m4'))
3084         {
3085             local ($line);
3086             $line = <ACLOCAL>;
3087             close (ACLOCAL);
3089             if ($line =~ 'generated automatically by aclocal')
3090             {
3091                 $regen_aclocal = 1;
3092             }
3093         }
3094     }
3096     local ($acinclude) = 0;
3097     if (-f 'acinclude.m4')
3098     {
3099         $regen_aclocal = 1;
3100         $acinclude = 1;
3101     }
3103     # Note that it might be possible that aclocal.m4 doesn't exist but
3104     # should be auto-generated.  This case probably isn't very
3105     # important.
3106     if ($regen_aclocal)
3107     {
3108         local (@ac_deps) = (
3109                             ($seen_maint_mode
3110                              ? "\@MAINTAINER_MODE_TRUE\@"
3111                              : "") ,
3112                             $configure_ac,
3113                             ($acinclude ? ' acinclude.m4' : '')
3114                             );
3116         if (&variable_defined ('ACLOCAL_M4_SOURCES'))
3117         {
3118             push (@ac_deps, "\$(ACLOCAL_M4_SOURCES)");
3119         }
3120         elsif (&variable_defined ('ACLOCAL_AMFLAGS'))
3121         {
3122             # Scan all -I directories for m4 files.  These are our
3123             # dependencies.
3124             local ($examine_next, $amdir) = 0;
3125             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
3126             {
3127                 if ($examine_next)
3128                 {
3129                     $examine_next = 0;
3130                     if ($amdir !~ /^\// && -d $amdir)
3131                     {
3132                         foreach $ac_dep (&my_glob ($amdir . '/*.m4'))
3133                         {
3134                             $ac_dep =~ s/^\.\/+//;
3135                             push (@ac_deps, $ac_dep)
3136                                 unless $ac_dep eq "aclocal.m4"
3137                                     || $ac_dep eq "acinclude.m4";
3138                         }
3139                     }
3140                 }
3141                 elsif ($amdir eq '-I')
3142                 {
3143                     $examine_next = 1;
3144                 }
3145             }
3146         }
3148         &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
3150         $output_rules .=  ("\t"
3151                            . 'cd $(srcdir) && $(ACLOCAL)'
3152                            . (&variable_defined ('ACLOCAL_AMFLAGS')
3153                               ? ' $(ACLOCAL_AMFLAGS)' : '')
3154                            . "\n");
3155     }
3158 # Rewrite a list of input files into a form suitable to put on a
3159 # dependency list.  The idea is that if an input file has a directory
3160 # part the same as the current directory, then the directory part is
3161 # simply removed.  But if the directory part is different, then
3162 # $(top_srcdir) is prepended.  Among other things, this is used to
3163 # generate the dependency list for the output files generated by
3164 # AC_OUTPUT.  Consider what the dependencies should look like in this
3165 # case:
3166 #   AC_OUTPUT(src/out:src/in1:lib/in2)
3167 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3168 # If 0 then files that require this addition will simply be ignored.
3169 sub rewrite_inputs_into_dependencies
3171     local ($add_srcdir, @inputs) = @_;
3172     local ($single, @newinputs);
3174     foreach $single (@inputs)
3175     {
3176         if (&dirname ($single) eq $relative_dir)
3177         {
3178             push (@newinputs, &basename ($single));
3179         }
3180         elsif ($add_srcdir)
3181         {
3182             push (@newinputs, '$(top_srcdir)/' . $single);
3183         }
3184     }
3186     return @newinputs;
3189 # Handle remaking and configure stuff.
3190 # We need the name of the input file, to do proper remaking rules.
3191 sub handle_configure
3193     local ($local, $input, @secondary_inputs) = @_;
3195     local ($top_reldir);
3197     local ($input_base) = &basename ($input);
3198     local ($local_base) = &basename ($local);
3200     local ($amfile) = $input_base . '.am';
3201     # We know we can always add '.in' because it really should be an
3202     # error if the .in was missing originally.
3203     local ($infile) = '$(srcdir)/' . $input_base . '.in';
3204     local ($colon_infile);
3205     if ($local ne $input || @secondary_inputs)
3206     {
3207         $colon_infile = ':' . $input . '.in';
3208     }
3209     $colon_infile .= ':' . join (':', @secondary_inputs)
3210         if @secondary_inputs;
3212     local (@rewritten) = &rewrite_inputs_into_dependencies (1,
3213                                                             @secondary_inputs);
3215     # This rule remakes the Makefile.in.  Note use of
3216     # @MAINTAINER_MODE_TRUE@ forces us to abandon pretty-printing.
3217     # Sigh.
3218     $output_rules .= ($infile
3219                       # NOTE perl 5.003 (with -w) gives a
3220                       # uninitialized value error on the next line.
3221                       # Don't know why.
3222                       . ': '
3223                       . ($seen_maint_mode ? "\@MAINTAINER_MODE_TRUE\@ " : '')
3224                       . $amfile . ' '
3225                       . '$(top_srcdir)/' . $configure_ac .' $(ACLOCAL_M4)'
3226                       . ' ' . join (' ', @include_stack)
3227                       . "\n"
3228                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
3229                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
3230                       . ($cmdline_use_dependencies ? '' : ' --ignore-deps')
3231                       . ' ' . $input . $colon_infile . "\n\n");
3233     # This rule remakes the Makefile.
3234     $output_rules .= ($local_base
3235                       # NOTE: bogus uninit value error on next line;
3236                       # see comment above.
3237                       . ': '
3238                       . $infile . ' '
3239                       . join (' ', @rewritten)
3240                       . ' $(top_builddir)/config.status'
3241                       . "\n"
3242                       . "\tcd \$(top_builddir) \\\n"
3243                       . "\t  && CONFIG_FILES="
3244                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3245                       . $colon_infile
3246                       . ' CONFIG_HEADERS= CONFIG_LINKS= CONFIG_COMMANDS= $(SHELL) ./config.status'
3247                       . "\n\n");
3249     if ($relative_dir ne '.')
3250     {
3251         # In subdirectory.
3252         $top_reldir = '../';
3253     }
3254     else
3255     {
3256         local ($xform) = &transform ('CONFIGURE_AC' => $configure_ac);
3257         &handle_aclocal_m4;
3258         $output_rules .= &file_contents ('remake', $xform);
3259         &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3260         &examine_variable ('CONFIGURE_DEPENDENCIES');
3261         $top_reldir = '';
3263         &push_dist_common ('acconfig.h')
3264             if -f 'acconfig.h';
3265     }
3267     # If we have a configure header, require it.
3268     local ($one_hdr);
3269     local (@local_fullnames) = @config_fullnames;
3270     local (@local_names) = @config_names;
3271     local ($hdr_index) = 0;
3272     local ($distclean_config) = '';
3273     foreach $one_hdr (@config_headers)
3274     {
3275         local ($one_fullname) = shift (@local_fullnames);
3276         local ($one_name) = shift (@local_names);
3277         $hdr_index += 1;
3278         local ($header_dir) = &dirname ($one_name);
3280         # If the header is in the current directory we want to build
3281         # the header here.  Otherwise, if we're at the topmost
3282         # directory and the header's directory doesn't have a
3283         # Makefile, then we also want to build the header.
3284         if ($relative_dir eq $header_dir
3285             || ($relative_dir eq '.' && ! &is_make_dir ($header_dir)))
3286         {
3287             local ($ch_sans_dir, $cn_sans_dir, $stamp_dir);
3288             if ($relative_dir eq $header_dir)
3289             {
3290                 $cn_sans_dir = &basename ($one_name);
3291                 $stamp_dir = '';
3292             }
3293             else
3294             {
3295                 $cn_sans_dir = $one_name;
3296                 if ($header_dir eq '.')
3297                 {
3298                     $stamp_dir = '';
3299                 }
3300                 else
3301                 {
3302                     $stamp_dir = $header_dir . '/';
3303                 }
3304             }
3306             # Compute relative path from directory holding output
3307             # header to directory holding input header.  FIXME:
3308             # doesn't handle case where we have multiple inputs.
3309             if (&dirname ($one_hdr) eq $relative_dir)
3310             {
3311                 $ch_sans_dir = &basename ($one_hdr);
3312             }
3313             else
3314             {
3315                 local (@rel_out_path);
3316                 # FIXME this chunk of code should be its own sub.
3317                 # It is used elsewhere.
3318                 foreach (split (/\//, $relative_dir))
3319                 {
3320                     next if $_ eq '' || $_ eq '.';
3321                     if ($_ eq '..')
3322                     {
3323                         # FIXME: actually this is an error.
3324                         pop @rel_out_path;
3325                     }
3326                     else
3327                     {
3328                         push (@rel_out_path, '..');
3329                     }
3330                 }
3331                 if (@rel_out_path)
3332                 {
3333                     $ch_sans_dir = join ('/', @rel_out_path) . '/' . $one_hdr;
3334                 }
3335                 else
3336                 {
3337                     $ch_sans_dir = $one_hdr;
3338                 }
3339             }
3341             &require_file_with_conf_line ($config_header_line,
3342                                           $FOREIGN, $ch_sans_dir);
3344             # Header defined and in this directory.
3345             local (@files);
3346             if (-f $one_name . '.top')
3347             {
3348                 push (@files, "${cn_sans_dir}.top");
3349             }
3350             if (-f $one_name . '.bot')
3351             {
3352                 push (@files, "${cn_sans_dir}.bot");
3353             }
3355             &push_dist_common (@files);
3357             # For now, acconfig.h can only appear in the top srcdir.
3358             if (-f 'acconfig.h')
3359             {
3360                 if ($relative_dir eq '.')
3361                 {
3362                     push (@files, 'acconfig.h');
3363                 }
3364                 else
3365                 {
3366                     # Strange quoting because this gets fed through
3367                     # Perl.
3368                     push (@files, '$(top_srcdir)/acconfig.h');
3369                 }
3370             }
3372             local ($stamp_name) = 'stamp-h';
3373             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3375             local ($xform) = '';
3377             $xform = &transform ('CONFIGURE_AC'       => $configure_ac,
3378                                  'FILES'              => join (' ', @files),
3379                                  'CONFIG_HEADER'      => $cn_sans_dir,
3380                                  'CONFIG_HEADER_IN'   => $ch_sans_dir,
3381                                  'CONFIG_HEADER_FULL' => $one_fullname,
3382                                  'STAMP'          => "$stamp_dir$stamp_name");
3384             local ($out_dir) = &dirname ($ch_sans_dir);
3385             $xform .= &transform ('SRC_STAMP' => "${out_dir}/${stamp_name}");
3386             $output_rules .= &file_contents ('remake-hdr', $xform);
3388             &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3389             &require_file_with_conf_line ($config_header_line, $FOREIGN,
3390                                           "${out_dir}/${stamp_name}.in");
3392             $distclean_config .= ' ' if $distclean_config;
3393             $distclean_config .= $cn_sans_dir;
3394         }
3395     }
3397     if ($distclean_config)
3398     {
3399         $output_rules .=
3400             &file_contents ('clean-hdr',
3401                             &transform ('FILES' => $distclean_config));
3402     }
3404     # Set location of mkinstalldirs.
3405     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
3406     {
3407         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
3408                                             . '/mkinstalldirs'));
3409     }
3410     else
3411     {
3412         &define_variable ('mkinstalldirs',
3413                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
3414     }
3416     &am_line_error ('CONFIG_HEADER',
3417                     "\`CONFIG_HEADER' is an anachronism; now determined from \`$configure_ac'")
3418         if &variable_defined ('CONFIG_HEADER');
3420     local ($one_name);
3421     local ($config_header) = '';
3422     foreach $one_name (@config_names)
3423     {
3424         # Generate CONFIG_HEADER define.
3425         local ($one_hdr);
3426         if ($relative_dir eq &dirname ($one_name))
3427         {
3428             $one_hdr = &basename ($one_name);
3429         }
3430         else
3431         {
3432             $one_hdr = "${top_builddir}/${one_name}";
3433         }
3435         $config_header .= ' ' if $config_header;
3436         $config_header .= $one_hdr;
3437     }
3438     if ($config_header)
3439     {
3440         &define_variable ("CONFIG_HEADER", $config_header);
3441     }
3443     # Now look for other files in this directory which must be remade
3444     # by config.status, and generate rules for them.
3445     local (@actual_other_files) = ();
3446     local ($file, $local);
3447     local (@inputs, @rewritten_inputs, $single);
3448     local ($need_rewritten, $lfile);
3449     foreach $lfile (@other_input_files)
3450     {
3451         if ($lfile =~ /^([^:]*):(.*)$/)
3452         {
3453             # This is the ":" syntax of AC_OUTPUT.
3454             $file = $1;
3455             $local = &basename ($file);
3456             @inputs = split (':', $2);
3457             @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3458             $need_rewritten = 1;
3459         }
3460         else
3461         {
3462             # Normal usage.
3463             $file = $lfile;
3464             $local = &basename ($file);
3465             @inputs = ($local . '.in');
3466             @rewritten_inputs =
3467                 &rewrite_inputs_into_dependencies (1, $file . '.in');
3468             $need_rewritten = 0;
3469         }
3471         # Make sure the dist directory for each input file is created.
3472         # We only have to do this at the topmost level though.  This
3473         # is a bit ugly but it easier than spreading out the logic,
3474         # especially in cases like AC_OUTPUT(foo/out:bar/in), where
3475         # there is no Makefile in bar/.
3476         if ($relative_dir eq '.')
3477         {
3478             foreach (@inputs)
3479             {
3480                 $dist_dirs{&dirname ($_)} = 1;
3481             }
3482         }
3484         # Skip files not in this directory.
3485         next unless &dirname ($file) eq $relative_dir;
3487         # Skip any file that is an automake input.
3488         next if -f $file . '.am';
3490         # Some users have been tempted to put `stamp-h' in the
3491         # AC_OUTPUT line.  This won't do the right thing, so we
3492         # explicitly fail here.
3493         if ($local eq 'stamp-h')
3494         {
3495             # FIXME: allow real filename.
3496             &am_conf_error ($configure_ac, $ac_output_line,
3497                             'stamp-h should not appear in AC_OUTPUT');
3498             next;
3499         }
3501         $output_rules .= ($local . ': '
3502                           . '$(top_builddir)/config.status '
3503                           . join (' ', @rewritten_inputs) . "\n"
3504                           . "\t"
3505                           . 'cd $(top_builddir) && CONFIG_FILES='
3506                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3507                           . '$@' . ($need_rewritten
3508                                     ? (':' . join (':', @inputs))
3509                                     : '')
3510                           . ' CONFIG_HEADERS= CONFIG_LINKS= CONFIG_COMMANDS= $(SHELL) ./config.status'
3511                           . "\n");
3512         push (@actual_other_files, $local);
3514         # Require all input files.
3515         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3516                                       &rewrite_inputs_into_dependencies (0, @inputs));
3517     }
3519     # These files get removed by "make clean".
3520     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3523 # Handle C headers.
3524 sub handle_headers
3526     local (@r);
3527     @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3528                           'oldinclude', 'pkginclude',
3529                           'noinst', 'check');
3530     foreach (@r)
3531     {
3532         next unless /\.(.*)$/;
3533         &saw_extension ($1);
3534     }
3537 sub handle_gettext
3539     return if ! $seen_gettext || $relative_dir ne '.';
3541     if (! &variable_defined ('SUBDIRS'))
3542     {
3543         &am_conf_error
3544             ("AM_GNU_GETTEXT used but SUBDIRS not defined");
3545         return;
3546     }
3548     &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3550     if (&variable_defined ('SUBDIRS'))
3551     {
3552         &am_line_error
3553             ('SUBDIRS',
3554              "AM_GNU_GETTEXT in \`$configure_ac' but \`po' not in SUBDIRS")
3555                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
3556         &am_line_error
3557             ('SUBDIRS',
3558              "AM_GNU_GETTEXT in \`$configure_ac' but \`intl' not in SUBDIRS")
3559                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
3560     }
3562     # Ensure that each language in ALL_LINGUAS has a .po file, and
3563     # each po file is mentioned in ALL_LINGUAS.
3564     if ($seen_linguas)
3565     {
3566         local (%linguas) = ();
3567         grep ($linguas{$_} = 1, split (' ', $all_linguas));
3569         foreach (<po/*.po>)
3570         {
3571             s/^po\///;
3572             s/\.po$//;
3574             &am_line_error ($all_linguas_line,
3575                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
3576                 if ! $linguas{$_};
3577         }
3579         foreach (keys %linguas)
3580         {
3581             &am_line_error ($all_linguas_line,
3582                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
3583                 if ! -f "po/$_.po";
3584         }
3585     }
3586     else
3587     {
3588         &am_error ("AM_GNU_GETTEXT in \`$configure_ac' but \`ALL_LINGUAS' not defined");
3589     }
3592 # Handle footer elements.
3593 sub handle_footer
3595     if ($contents{'SOURCES'})
3596     {
3597         # NOTE don't use define_pretty_variable here, because
3598         # $contents{...} is already defined.
3599         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
3600     }
3601     if ($contents{'OBJECTS'})
3602     {
3603         # NOTE don't use define_pretty_variable here, because
3604         # $contents{...} is already defined.
3605         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
3606     }
3607     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
3608     {
3609         $output_vars .= "\n";
3610     }
3612     if (&target_defined ('.SUFFIXES'))
3613     {
3614         &am_line_error ('.SUFFIXES',
3615                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
3616     }
3618     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3619     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3620     # anything else, by sticking it right after the default: target.
3621     $output_header .= ".SUFFIXES:\n";
3622     if (@suffixes || &variable_defined ('SUFFIXES'))
3623     {
3624         # Make sure suffixes has unique elements.  Sort them to ensure
3625         # the output remains consistent.  However, $(SUFFIXES) is
3626         # always at the start of the list, unsorted.  This is done
3627         # because make will choose rules depending on the ordering of
3628         # suffixes, and this lets the user have some control.  Push
3629         # actual suffixes, and not $(SUFFIXES).  Some versions of make
3630         # do not like variable substitutions on the .SUFFIXES line.
3631         local (%suffixes);
3632         local (@user_suffixes) = (&variable_defined ('SUFFIXES')
3633                                   ? &variable_value_as_list ('SUFFIXES', '')
3634                                   : ());
3636         grep ($suffixes{$_} = 1, @suffixes);
3637         delete @suffixes{@user_suffixes};
3639         $output_header .= (".SUFFIXES: "
3640                            . join (' ', @user_suffixes, sort keys %suffixes)
3641                            . "\n");
3642     }
3643     $output_trailer .= &file_contents ('footer');
3646 # Deal with installdirs target.
3647 sub handle_installdirs
3649     # GNU Makefile standards recommend this.
3650     if ($recursive_install)
3651     {
3652         # We create a separate `-am' target so that the -recursive
3653         # rule will work correctly.
3654         $output_rules .= ("installdirs: installdirs-recursive\n"
3655                           . "installdirs-am:\n");
3656         &depend ('.PHONY', 'installdirs-am');
3657     }
3658     else
3659     {
3660         $output_rules .= "installdirs:\n";
3661     }
3662     &depend ('.PHONY', 'installdirs');
3663     if (@installdirs)
3664     {
3665         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
3666                             @installdirs);
3667     }
3668     $output_rules .= "\n";
3671 # There are several targets which need to be merged.  This is because
3672 # their complete definition is compiled from many parts.  Note that we
3673 # avoid double colon rules, otherwise we'd use them instead.
3674 sub handle_merge_targets
3676     local ($makefile) = @_;
3678     # There are a few install-related variables that you should not define.
3679     local ($var);
3680     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
3681     {
3682         if (&variable_defined ($var))
3683         {
3684             &am_line_error ($var, "\`$var' should not be defined");
3685         }
3686     }
3688     # Put this at the beginning for the sake of non-GNU makes.  This
3689     # is still wrong if these makes can run parallel jobs.  But it is
3690     # right enough.
3691     unshift (@all, &basename ($makefile));
3693     local ($one_name);
3694     foreach $one_name (@config_names)
3695     {
3696         push (@all, &basename ($one_name))
3697             if &dirname ($one_name) eq $relative_dir;
3698     }
3700     &do_one_merge_target ('info', @info);
3701     &do_one_merge_target ('dvi', @dvi);
3702     &do_check_merge_target;
3703     &do_one_merge_target ('installcheck', @installcheck);
3705     if (defined $options{'no-installinfo'})
3706     {
3707         &do_one_merge_target ('install-info', '');
3708     }
3709     elsif (&target_defined ('install-info-local'))
3710     {
3711         &am_line_error ('install-info-local',
3712                         "\`install-info-local' target defined but \`no-installinfo' option not in use");
3713     }
3715     local ($utarg);
3716     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3717                     'uninstall-exec-local', 'uninstall-exec-hook')
3718     {
3719         if (&target_defined ($utarg))
3720         {
3721             local ($x);
3722             ($x = $utarg) =~ s/(data|exec)-//;
3723             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3724         }
3725     }
3727     if (&target_defined ('install-local'))
3728     {
3729         &am_line_error ('install-local',
3730                         "use \`install-data-local' or \`install-exec-local', not \`install-local'");
3731     }
3733     if (@all || &variable_defined ('BUILT_SOURCES'))
3734     {
3735         local ($one_name);
3736         local ($local_headers) = '';
3737         $local_headers = '$(BUILT_SOURCES)'
3738             if &variable_defined ('BUILT_SOURCES');
3739         foreach $one_name (@config_names)
3740         {
3741             if (&dirname ($one_name) eq $relative_dir)
3742             {
3743                 $local_headers .= ' ' if $local_headers;
3744                 $local_headers .= &basename ($one_name);
3745             }
3746         }
3747         if ($local_headers)
3748         {
3749             # This is kind of a hack, but I couldn't see a better way
3750             # to handle it.  In this particular case, we need to make
3751             # sure config.h is built before we recurse.  We can't do
3752             # this by changing the order of dependencies to the "all"
3753             # because that breaks when using parallel makes.  Instead
3754             # we handle things explicitly.
3755             $output_rules .= ("all-recursive-am: ${local_headers}"
3756                                   . "\n\t"
3757                                   . '$(MAKE) $(AM_MAKEFLAGS)'
3758                                   . " all-recursive"
3759                                   . "\n\n");
3760             $all_target = 'all-recursive-am';
3761             &depend ('.PHONY', 'all-recursive-am');
3762         }
3763     }
3765     if (&variable_defined('lib_LTLIBRARIES') &&
3766         &variable_defined('bin_PROGRAMS'))
3767     {
3768         $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
3769     }
3770     # Print definitions users can use.
3771     &do_one_merge_target ('install-exec', @install_exec);
3772     $output_rules .= "\n";
3774     &do_one_merge_target ('install-data', @install_data);
3775     $output_rules .= "\n";
3777     &do_one_merge_target ('install', 'all-am');
3778     &do_one_merge_target ('uninstall', @uninstall);
3780     &do_one_merge_target ('all', @all);
3782     # Generate the new 'install-strip' target.  We can't just set
3783     # INSTALL_PROGRAM because that might be a relative path.
3784     $output_rules .= ("install-strip:\n\t"
3785                       . '$(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install'
3786                       . "\n");
3787     &depend ('.PHONY', 'install-strip');
3790 # Helper for handle_merge_targets.  Note that handle_merge_targets
3791 # relies on the fact that this doesn't add an extra \n at the end.
3792 sub do_one_merge_target
3794     local ($name, @values) = @_;
3796     if (&target_defined ($name . '-local'))
3797     {
3798         # User defined local form of target.  So include it.
3799         push (@values, $name . '-local');
3800         &depend ('.PHONY', $name . '-local');
3801     }
3803     &pretty_print_rule ($name . "-am:", "\t\t", @values);
3804     if ($name eq 'install')
3805     {
3806         # Special-case `install-am' to run install-exec-am and
3807         # install-data-am after all-am is built.
3808         &pretty_print_rule ("\t\@\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3809                             'install-exec-am', 'install-data-am');
3810     }
3811     elsif ($name eq 'install-exec' && &target_defined ('install-exec-hook'))
3812     {
3813         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3814                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-exec-hook'
3815                           . "\n");
3816     }
3817     elsif ($name eq 'install-data' && &target_defined ('install-data-hook'))
3818     {
3819         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3820                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-data-hook'
3821                           . "\n");
3822     }
3824     local ($lname) = $name . ($recursive_install ? '-recursive' : '-am');
3825     local ($tname) = $name;
3826     # To understand this special case, see handle_merge_targets.
3827     if ($name eq 'all')
3828     {
3829         $tname = 'all-redirect';
3830         $lname = $all_target if $recursive_install;
3831         &depend ('.PHONY', 'all-redirect');
3832         $output_all = "all: all-redirect\n";
3833     }
3834     &pretty_print_rule ($tname . ":", "\t\t", $lname);
3835     &depend ('.PHONY', $name . '-am', $name);
3838 # Handle check merge target specially.
3839 sub do_check_merge_target
3841     if (&target_defined ('check-local'))
3842     {
3843         # User defined local form of target.  So include it.
3844         push (@check_tests, 'check-local');
3845         &depend ('.PHONY', 'check-local');
3846     }
3848     # In --cygnus mode, check doesn't depend on all.
3849     if ($cygnus_mode)
3850     {
3851         # Just run the local check rules.
3852         &pretty_print_rule ('check-am:', "\t\t", @check);
3853     }
3854     else
3855     {
3856         # The check target must depend on the local equivalent of
3857         # `all', to ensure all the primary targets are built.  Then it
3858         # must build the local check rules.
3859         $output_rules .= "check-am: all-am\n";
3860         &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3861                             @check)
3862             if @check;
3863     }
3864     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3865                         @check_tests)
3866         if @check_tests;
3868     &depend ('.PHONY', 'check', 'check-am');
3869     $output_rules .= ("check: "
3870                       . ($recursive_install ? 'check-recursive' : 'check-am')
3871                       . "\n");
3874 # Handle all 'clean' targets.
3875 sub handle_clean
3877     my ($xform) = '';
3878     my ($name);
3880     # Don't include `MAINTAINER'; it is handled specially below.
3881     foreach $name ('MOSTLY', '', 'DIST')
3882     {
3883         if (! &variable_defined ($name . 'CLEANFILES'))
3884         {
3885             $xform .= 's/^' . $name . 'CLEAN.*$//;';
3886         }
3887         else
3888         {
3889             $xform .= 's/^' . $name . 'CLEAN//;';
3890         }
3891     }
3893     # Built sources are automatically removed by maintainer-clean.
3894     push (@maintainer_clean_files, '\$(BUILT_SOURCES)')
3895         if &variable_defined ('BUILT_SOURCES');
3896     push (@maintainer_clean_files, '\$(MAINTAINERCLEANFILES)')
3897         if &variable_defined ('MAINTAINERCLEANFILES');
3898     if (! @maintainer_clean_files)
3899     {
3900         $xform .= 's/^MAINTAINERCLEAN.*$//;';
3901     }
3902     else
3903     {
3904         $xform .= ('s/^MAINTAINERCLEAN//;'
3905                    # Join with no space to avoid spurious `test -z'
3906                    # success at runtime.
3907                    . 's,\@MCFILES\@,' . join ('', @maintainer_clean_files)
3908                    . ',;'
3909                    # A space is required in the join here.
3910                    . 's,\@MFILES\@,' . join (' ', @maintainer_clean_files)
3911                    . ',;');
3912     }
3913     if ($recursive_install)
3914     {
3915         $xform .= 's/^NSUBDIRS.*$//;';
3916     }
3917     else
3918     {
3919         $xform .= 's/^NSUBDIRS//;';
3920     }
3922     $output_rules .= &file_contents ('clean', $xform);
3924     foreach ('clean', 'distclean', 'mostlyclean', 'maintainer-clean')
3925       {
3926         &depend ("$_-am", "$_-local")
3927           if &target_defined ("$_-local");
3928       }
3930     # We special-case config.status here.  If we do it as part of the
3931     # normal clean processing for this directory, then it might be
3932     # removed before some subdir is cleaned.  However, that subdir's
3933     # Makefile depends on config.status.
3934     if ($relative_dir eq '.')
3935     {
3936         $actions{'distclean'} .= "\t-rm -f config.status\n";
3937         $actions{'maintainer-clean'} .= "\t-rm -f config.status\n";
3938     }
3942 # &depend ($CATEGORY, @DEPENDENDEES)
3943 # ----------------------------------
3944 # The target $CATEGORY depends on @DEPENDENDEES.
3945 sub depend
3947     my ($category, @dependendees) = @_;
3948     {
3949       push (@{$dependencies{$category}}, @dependendees);
3950     }
3954 # &target_cmp ($A, $B)
3955 # --------------------
3956 # Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
3957 sub target_cmp
3959     return
3960         if $a eq $b;
3961     return -1
3962         if $b eq '.PHONY';
3963     return 1
3964         if $a eq '.PHONY';
3965     return $a cmp $b;
3969 # &handle_factored_dependencies ()
3970 # --------------------------------
3971 # Handle .PHONY target.
3972 sub handle_factored_dependencies
3974     foreach (sort target_cmp keys %dependencies)
3975     {
3976         &pretty_print_rule ("$_:", "\t",
3977                             sort @{$dependencies{$_}});
3978         $output_rules .= $actions{$_};
3979         $output_rules .= "\n";
3980     }
3984 # &handle_tests_dejagnu ()
3985 # ------------------------
3986 sub handle_tests_dejagnu
3988     push (@check_tests, 'check-DEJAGNU');
3990     local ($xform);
3991     if ($cygnus_mode)
3992     {
3993         $xform = 's/^CYGNUS//;';
3994     }
3995     else
3996     {
3997         $xform = 's/^CYGNUS.*$//;';
3998     }
3999     $output_rules .= &file_contents ('dejagnu', $xform);
4001     # In Cygnus mode, these are found in the build tree.
4002     # Otherwise they are looked for in $PATH.
4003     &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
4004     &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
4006     # Only create site.exp rule if user hasn't already written
4007     # one.
4008     if (! &target_defined ('site.exp'))
4009     {
4010         # Note that in the rule we don't directly generate
4011         # site.exp to avoid the possibility of a corrupted
4012         # site.exp if make is interrupted.  Jim Meyering has some
4013         # useful text on this topic.
4014         $output_rules .= ("site.exp: Makefile\n"
4015                           . "\t\@echo 'Making a new site.exp file...'\n"
4016                           . "\t\@test ! -f site.bak || rm -f site.bak\n"
4017                           . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
4018                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
4019                           . "\t\@echo '# edit the last section' >> \$\@-t\n"
4020                           . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
4021                           . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
4022                           . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
4024         # Extra stuff for AC_CANONICAL_*
4025         local (@whatlist) = ();
4026         if ($seen_canonical)
4027         {
4028             push (@whatlist, 'host');
4029         }
4031         # Extra stuff only for AC_CANONICAL_SYSTEM.
4032         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
4033         {
4034             push (@whatlist, 'target', 'build');
4035         }
4037         local ($c1, $c2);
4038         foreach $c1 (@whatlist)
4039         {
4040             foreach $c2 ('alias', 'triplet')
4041             {
4042                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
4043             }
4044         }
4046         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
4047                           . "\t\@test ! -f site.exp || sed '1,/^## All variables above are.*##/ d' site.exp >> \$\@-t\n"
4048                           . "\t\@test ! -f site.exp || mv site.exp site.bak\n"
4049                           . "\t\@mv \$\@-t site.exp\n");
4050     }
4054 # Handle TESTS variable and other checks.
4055 sub handle_tests
4057     if (defined $options{'dejagnu'})
4058     {
4059         &handle_tests_dejagnu;
4060     }
4061     else
4062     {
4063         local ($c);
4064         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4065         {
4066             if (&variable_defined ($c))
4067             {
4068                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
4069             }
4070         }
4071     }
4073     if (&variable_defined ('TESTS'))
4074     {
4075         push (@check_tests, 'check-TESTS');
4077         # Note: Solaris 2.7 seems to expand TESTS using VPATH.  That's
4078         # why we also try `dir='
4079         $output_rules .= &file_contents ('check');
4080     }
4083 # Handle Emacs Lisp.
4084 sub handle_emacs_lisp
4086     local (@elfiles) = &am_install_var ('-candist', 'lisp', 'LISP',
4087                                         'lisp', 'noinst');
4089     if (@elfiles)
4090     {
4091         # Found some lisp.
4092         &define_configure_variable ('lispdir');
4093         &define_configure_variable ('EMACS');
4094         $output_rules .= (".el.elc:\n"
4095                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
4096                           . "\tif test \$(EMACS) != no; then \\\n"
4097                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
4098                           . "\tfi\n");
4099         push (@suffixes, '.el', '.elc');
4101         # Generate .elc files.
4102         grep ($_ .= 'c', @elfiles);
4103         &define_pretty_variable ('ELCFILES', '', @elfiles);
4105         $output_rules .= &file_contents ('lisp-clean');
4107         push (@all, '$(ELCFILES)');
4109         local ($varname);
4110         if (&variable_defined ('lisp_LISP'))
4111         {
4112             $varname = 'lisp_LISP';
4113             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`$configure_ac'")
4114                 if ! $seen_lispdir;
4115         }
4116         else
4117         {
4118             $varname = 'noinst_LISP';
4119         }
4121         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
4122     }
4125 # Handle Python
4126 sub handle_python
4128     local (@pyfiles) = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4129                                         'python', 'noinst');
4130     return if ! @pyfiles;
4132     # Found some python.
4133     &define_configure_variable ('pythondir');
4134     &define_configure_variable ('PYTHON');
4136     $output_rules .= &file_contents ('python-clean');
4138     &am_error ("\`python_PYTHON' defined but \`AM_CHECK_PYTHON' not in \`$configure_ac'")
4139         if ! $seen_pythondir && &variable_defined ('python_PYTHON');
4141     if ($config_aux_dir eq '.' || $config_aux_dir eq '')
4142     {
4143         &define_variable ('py_compile', '$(top_srcdir)/py-compile');
4144     }
4145     else
4146     {
4147         &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4148     }
4151 # Handle Java.
4152 sub handle_java
4154     local (@sourcelist) = &am_install_var ('-candist', '-clean',
4155                                            'java', 'JAVA',
4156                                            'java', 'noinst', 'check');
4157     return if ! @sourcelist;
4159     &define_variable ('JAVAC', 'javac');
4160     &define_variable ('JAVACFLAGS', '');
4161     &define_variable ('CLASSPATH_ENV',
4162                       'CLASSPATH=$(JAVAROOT):$(srcdir)/$(JAVAROOT):$$CLASSPATH');
4163     &define_variable ('JAVAROOT', '$(top_builddir)');
4165     local (%valid) = &am_primary_prefixes ('JAVA', 1,
4166                                            'java', 'noinst', 'check');
4168     local ($dir, $curs);
4169     foreach $curs (keys %valid)
4170     {
4171         if (! &variable_defined ($curs . '_JAVA') || $curs eq 'EXTRA')
4172         {
4173             next;
4174         }
4176         if (defined $dir)
4177         {
4178             &am_line_error ($curs . '_JAVA',
4179                             "multiple _JAVA primaries in use");
4180         }
4181         $dir = $curs;
4182     }
4184     $output_rules .= ('class' . $dir . '.stamp: $(' . $dir . '_JAVA)' . "\n"
4185                       . "\t" . '$(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) '
4186                       . '$(JAVACFLAGS) $?' . "\n"
4187                       . "\t" . 'echo timestamp > class' . $dir . '.stamp'
4188                       . "\n");
4189     push (@all, 'class' . $dir . '.stamp');
4190     &push_dist_common ('$(' . $dir . '_JAVA)');
4193 # Handle some of the minor options.
4194 sub handle_minor_options
4196     if (defined $options{'readme-alpha'})
4197     {
4198         if ($relative_dir eq '.')
4199         {
4200             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4201             {
4202                 # FIXME: allow real filename.
4203                 &am_conf_line_error ($configure_ac,
4204                                      $package_version_line,
4205                                      "version \`$package_version' doesn't follow Gnits standards");
4206             }
4207             elsif (defined $1 && -f 'README-alpha')
4208             {
4209                 # This means we have an alpha release.  See
4210                 # GNITS_VERSION_PATTERN for details.
4211                 &require_file ($FOREIGN, 'README-alpha');
4212             }
4213         }
4214     }
4217 ################################################################
4219 # &scan_autoconf_config_files ($CONFIG-FILES)
4220 # -------------------------------------------
4221 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4222 # (or AC_OUTPUT).
4223 sub scan_autoconf_config_files
4225     # Look at potential Makefile.am's.
4226     foreach (split)
4227     {
4228         # Must skip empty string for Perl 4.
4229         next if $_ eq "\\" || $_ eq '';
4231         # Handle $local:$input syntax.  Note that we ignore
4232         # every input file past the first, though we keep
4233         # those around for later.
4234         local ($local, $input, @rest) = split (/:/);
4235         if (! $input)
4236         {
4237             $input = $local;
4238         }
4239         else
4240         {
4241             # FIXME: should be error if .in is missing.
4242             $input =~ s/\.in$//;
4243         }
4245         if (-f $input . '.am')
4246         {
4247             # We have a file that automake should generate.
4248             push (@make_input_list, $input);
4249             $make_list{$input} = join (':', ($local, @rest));
4250         }
4251         else
4252         {
4253             # We have a file that automake should cause to be
4254             # rebuilt, but shouldn't generate itself.
4255             push (@other_input_files, $_);
4256         }
4257     }
4261 # &scan_autoconf_traces ($FILENAME)
4262 # ---------------------------------
4263 # FIXME: For the time being, we don't care about the FILENAME.
4264 sub scan_autoconf_traces
4266     local ($filename) = @_;
4267     local (*TRACES);
4269     local ($traces) = "$ENV{amtraces} ";
4271     $traces .= ' -t AC_CONFIG_FILES';
4272     $traces .= ' -t AC_LIBSOURCE';
4273     $traces .= ' -t AC_SUBST';
4275     open (TRACES, "$traces |")
4276         || die "automake: couldn't open \`$traces': $!\n";
4277     print "automake: reading $traces\n" if $verbose;
4279     while (<TRACES>)
4280     {
4281         chomp;
4282         local ($file, $line, $macro, @args) = split /:/;
4283         local ($here) = "$file:$line";
4285         # Alphabetical ordering please.
4286         if ($macro eq 'AC_CONFIG_FILES')
4287         {
4288             # Look at potential Makefile.am's.
4289             &scan_autoconf_config_files ($args[0]);
4290         }
4291         elsif ($macro eq 'AC_LIBSOURCE')
4292         {
4293             local ($source) = "$args[0].c";
4294             # We should actually also `close' the sources: getopt.c
4295             # wants getopt.h etc.  But actually it should be done in the
4296             # macro itself, i.e., we have to first fix Autoconf to extend
4297             # _AC_LIBOBJ_DECL and use it the in various macros.
4298             if (!defined $libsources{$source})
4299                 {
4300                     print STDERR "traces: discovered $source\n";
4301                     $libsources{$source} = $here;
4302                 }
4303         }
4304         elsif ($macro eq 'AC_SUBST')
4305         {
4306             if (!defined $configure_vars{$args[0]})
4307                 {
4308                     print STDERR "traces: discovered AC_SUBST($args[0])\n";
4309                     $configure_vars{$args[0]} = $here;
4310                 }
4311         }
4312     }
4314     close (TRACES)
4315       || die "automake: close: $traces: $!\n";
4319 # &scan_one_autoconf_file ($FILENAME)
4320 # -----------------------------------
4321 # Scan one file for interesting things.  Subroutine of
4322 # &scan_autoconf_files.
4323 sub scan_one_autoconf_file
4325     local ($filename) = @_;
4326     local (*CONFIGURE);
4328     open (CONFIGURE, $filename)
4329         || die "automake: couldn't open \`$filename': $!\n";
4330     print "automake: reading $filename\n" if $verbose;
4332     while (<CONFIGURE>)
4333     {
4334         # Remove comments from current line.
4335         s/\bdnl\b.*$//;
4336         s/\#.*$//;
4338         # Skip macro definitions.  Otherwise we might be confused into
4339         # thinking that a macro that was only defined was actually
4340         # used.
4341         next if /AC_DEFUN/;
4343         # Follow includes.  This is a weirdness commonly in use at
4344         # Cygnus and hopefully nowhere else.
4345         if (/sinclude\((.*)\)/ && -f $1)
4346         {
4347             &scan_one_autoconf_file ($1);
4348         }
4350         # Populate libobjs array.
4351         if (/AC_FUNC_ALLOCA/)
4352         {
4353             $libsources{'alloca.c'} = 1;
4354         }
4355         elsif (/AC_FUNC_GETLOADAVG/)
4356         {
4357             $libsources{'getloadavg.c'} = 1;
4358         }
4359         elsif (/AC_FUNC_MEMCMP/)
4360         {
4361             $libsources{'memcmp.c'} = 1;
4362         }
4363         elsif (/AC_STRUCT_ST_BLOCKS/)
4364         {
4365             $libsources{'fileblocks.c'} = 1;
4366         }
4367         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4368         {
4369             $libsources{'getopt.c'} = 1;
4370             $libsources{'getopt1.c'} = 1;
4371         }
4372         elsif (/AM_FUNC_STRTOD/)
4373         {
4374             $libsources{'strtod.c'} = 1;
4375         }
4376         elsif (/AM_WITH_REGEX/)
4377         {
4378             $libsources{'rx.c'} = 1;
4379             $libsources{'rx.h'} = 1;
4380             $libsources{'regex.c'} = 1;
4381             $libsources{'regex.h'} = 1;
4382         }
4383         elsif (/AC_FUNC_MKTIME/)
4384         {
4385             $libsources{'mktime.c'} = 1;
4386         }
4387         elsif (/AM_FUNC_ERROR_AT_LINE/)
4388         {
4389             $libsources{'error.c'} = 1;
4390             $libsources{'error.h'} = 1;
4391         }
4392         elsif (/AM_FUNC_OBSTACK/)
4393         {
4394             $libsources{'obstack.c'} = 1;
4395             $libsources{'obstack.h'} = 1;
4396         }
4397         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4398                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4399         {
4400             foreach $libobj_iter (split (' ', $1))
4401             {
4402                 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4403                     || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4404                     || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4405                 {
4406                     $libsources{$1 . '.c'} = 1;
4407                 }
4408             }
4409         }
4410         elsif (/AC_LIBOBJ\(([^)]+)\)/)
4411         {
4412             $libsources{"$1.c"} = 1;
4413         }
4415         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4416         {
4417             $in_ac_replace = 1;
4418         }
4419         if ($in_ac_replace)
4420         {
4421             $in_ac_replace = 0 if s/[\]\)].*$//;
4422             # Remove trailing backslash.
4423             s/\\$//;
4424             foreach (split)
4425             {
4426                 # Need to skip empty elements for Perl 4.
4427                 next if $_ eq '';
4428                 $libsources{$_ . '.c'} = 1;
4429             }
4430         }
4432         if (/$obsolete_rx/o)
4433         {
4434             local ($hint) = '';
4435             if ($obsolete_macros{$1} ne '')
4436             {
4437                 $hint = '; ' . $obsolete_macros{$1};
4438             }
4439             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
4440         }
4442         # Process the AC_OUTPUT and AC_CONFIG_FILES macros.
4443         if (! $in_ac_output && s/AC_(OUTPUT|CONFIG_FILES)\s*\(\[?//)
4444         {
4445             $in_ac_output = 1;
4446             $ac_output_line = $.;
4447         }
4448         if ($in_ac_output)
4449         {
4450             local ($closing) = 0;
4451             if (s/[\]\),].*$//)
4452             {
4453                 $in_ac_output = 0;
4454                 $closing = 1;
4455             }
4457             # Look at potential Makefile.am's.
4458             &scan_autoconf_config_files ($_);
4460             if ($closing && @make_input_list == 0 && @other_input_files == 0)
4461             {
4462                 &am_conf_line_error ($filename, $ac_output_line,
4463                                      "No files mentioned in \`AC_OUTPUT'");
4464                 exit 1;
4465             }
4466         }
4468         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4469         {
4470             @config_aux_path = $1;
4471         }
4473         # Check for ansi2knr.
4474         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4476         # Check for exe extension stuff.
4477         if (/AC_EXEEXT/)
4478         {
4479             $seen_exeext = 1;
4480             $configure_vars{'EXEEXT'} = $filename . ':' . $.;
4481         }
4483         if (/AC_OBJEXT/)
4484         {
4485             $seen_objext = 1;
4486             $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4487         }
4489         # Check for `-c -o' code.
4490         $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4492         # Check for NLS support.
4493         if (/AM_GNU_GETTEXT/)
4494         {
4495             $seen_gettext = 1;
4496             $ac_gettext_line = $.;
4497         }
4499         # Look for ALL_LINGUAS.
4500         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4501         {
4502             $seen_linguas = 1;
4503             $all_linguas = $1;
4504             $all_linguas_line = $.;
4505         }
4507         # Handle configuration headers.  A config header of `[$1]'
4508         # means we are actually scanning AM_CONFIG_HEADER from
4509         # aclocal.m4.
4510         if (/A([CM])_CONFIG_HEADERS?\s*\((.*)\)/
4511             && $2 ne '[$1]')
4512         {
4513             &am_conf_line_error
4514                 ($filename, $., "\`automake requires \`AM_CONFIG_HEADER', not \`AC_CONFIG_HEADER'")
4515                     if $1 eq 'C';
4517             $config_header_line = $.;
4518             local ($one_hdr);
4519             foreach $one_hdr (split (' ', $2))
4520             {
4521                 push (@config_fullnames, $one_hdr);
4522                 if ($one_hdr =~ /^([^:]+):(.+)$/)
4523                 {
4524                     push (@config_names, $1);
4525                     push (@config_headers, $2);
4526                 }
4527                 else
4528                 {
4529                     push (@config_names, $one_hdr);
4530                     push (@config_headers, $one_hdr . '.in');
4531                 }
4532             }
4533         }
4535         # Handle AC_CANONICAL_*.  Always allow upgrading to
4536         # AC_CANONICAL_SYSTEM, but never downgrading.
4537         $seen_canonical = $AC_CANONICAL_HOST
4538             if ! $seen_canonical
4539                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4540         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4542         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
4544         # This macro handles several different things.
4545         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4546         {
4547             $seen_make_set = 1;
4548             $seen_arg_prog = 1;
4549             $seen_prog_install = 1;
4550             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4551             $package_version_line = $.;
4552             $seen_init_automake = 1;
4553         }
4555         # Some things required by Automake.
4556         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
4557         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
4559         if (/AM_PROG_LEX/)
4560         {
4561             $configure_vars{'LEX'} = $filename . ':' . $.;
4562             $seen_decl_yytext = 1;
4563         }
4564         if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.(ac|in)$/)
4565         {
4566             &am_conf_line_warning ($filename, $., "\`AC_DECL_YYTEXT' is covered by \`AM_PROG_LEX'");
4567         }
4568         if (/AC_PROG_LEX/ && $filename =~ /configure\.(ac|in)$/)
4569         {
4570             &am_conf_line_warning ($filename, $., "automake requires \`AM_PROG_LEX', not \`AC_PROG_LEX'");
4571         }
4573         if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4574         {
4575             $configure_vars{$1} = $filename . ':' . $.;
4576         }
4577         if (/$AC_CHECK_PATTERN/o)
4578         {
4579             $configure_vars{$3} = $filename . ':' . $.;
4580         }
4581         if (/$AM_MISSING_PATTERN/o
4582             && $1 ne 'ACLOCAL'
4583             && $1 ne 'AUTOCONF'
4584             && $1 ne 'AUTOMAKE'
4585             && $1 ne 'AUTOHEADER')
4586         {
4587             $configure_vars{$1} = $filename . ':' . $.;
4588         }
4590         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4591         # but later define it elsewhere.  This is pretty hacky.  We
4592         # also explicitly avoid INSTALL_SCRIPT and some other
4593         # variables because they are defined in header-vars.am.
4594         # FIXME.
4595         if (/$AC_SUBST_PATTERN/o
4596             && $1 ne 'ANSI2KNR'
4597             && $1 ne 'INSTALL_SCRIPT'
4598             && $1 ne 'INSTALL_DATA')
4599         {
4600             $configure_vars{$1} = $filename . ':' . $.;
4601         }
4603         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4604         if (/AM_MAINTAINER_MODE/)
4605         {
4606             $seen_maint_mode = 1;
4607             $configure_cond{'MAINTAINER_MODE'} = 1;
4608         }
4610         $seen_prog_install = 1 if /AC_PROG_INSTALL/;
4611         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4612         $seen_pythondir = 1 if /AM_PATH_PYTHON/;
4614         if (/A(C|M)_PROG_LIBTOOL/)
4615         {
4616             # We're not ready for this yet.  People still use a
4617             # libtool with no AC_PROG_LIBTOOL.  Once that is the
4618             # dominant version we can reenable this code -- but next
4619             # time by mentioning the macro in %obsolete_macros, both
4620             # here and in aclocal.in.
4622             # if (/AM_PROG_LIBTOOL/)
4623             # {
4624             #   &am_conf_line_warning ($filename, $., "\`AM_PROG_LIBTOOL' is obsolete, use \`AC_PROG_LIBTOOL' instead");
4625             # }
4626             $seen_libtool = 1;
4627             $libtool_line = $.;
4628             $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4629             $configure_vars{'RANLIB'} = $filename . ':' . $.;
4630             $configure_vars{'CC'} = $filename . ':' . $.;
4631             # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
4632             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4633             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4634         }
4636         $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4638         if (/$AM_CONDITIONAL_PATTERN/o)
4639         {
4640             $configure_cond{$1} = 1;
4641         }
4643         # Check for Fortran 77 intrinsic and run-time libraries.
4644         if (/AC_F77_LIBRARY_LDFLAGS/)
4645         {
4646             $configure_vars{'FLIBS'} = $filename . ':' . $.;
4647         }
4648     }
4650     close (CONFIGURE);
4654 # &scan_autoconf_files ()
4655 # -----------------------
4656 # Check whether we use `configure.ac' or `configure.in'.
4657 # Scan it (and possibly `aclocal.m4') for interesting things.
4658 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
4659 sub scan_autoconf_files
4661     # Reinitialize libsources here.  This isn't really necessary,
4662     # since we currently assume there is only one configure.ac.  But
4663     # that won't always be the case.
4664     %libsources = ();
4666     local ($in_ac_output, $in_ac_replace) = (0, 0);
4667     local (%make_list, @make_input_list);
4668     local ($libobj_iter);
4670     warn "automake: both \`configure.ac' and \`configure.in' present:"
4671          . " ignoring \`configure.in'\n"
4672         if -f 'configure.ac' && -f 'configure.in';
4673     $configure_ac = 'configure.in'
4674         if -f 'configure.in';
4675     $configure_ac = 'configure.ac'
4676         if -f 'configure.ac';
4677     die "automake: \`configure.ac' or \`configure.in' is required\n"
4678         if !$configure_ac;
4680     &scan_one_autoconf_file ($configure_ac);
4681     &scan_one_autoconf_file ('aclocal.m4')
4682         if -f 'aclocal.m4';
4684     if (defined $ENV{'amtraces'})
4685     {
4686         warn 'automake: Autoconf traces is an experimental feature';
4687         warn 'automake: use at your own risks';
4689         &scan_autoconf_traces ($configure_ac);
4690     }
4692     # Set input and output files if not specified by user.
4693     if (! @input_files)
4694     {
4695         @input_files = @make_input_list;
4696         %output_files = %make_list;
4697     }
4699     @configure_input_files = @make_input_list;
4701     &am_conf_error ("\`AM_INIT_AUTOMAKE' must be used")
4702         if ! $seen_init_automake;
4704     # Always require AC_PROG_MAKE_SET.  We might randomly use $(MAKE)
4705     # for our own reasons.
4706     &am_conf_error ("\`AC_PROG_MAKE_SET' must be used")
4707         if ! $seen_make_set;
4709     # Look for some files we need.  Always check for these.  This
4710     # check must be done for every run, even those where we are only
4711     # looking at a subdir Makefile.  We must set relative_dir so that
4712     # the file-finding machinery works.
4713     local ($relative_dir) = '.';
4714     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4715     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
4716         if -f $config_aux_path[0] . '/install.sh';
4718     &require_config_file ($FOREIGN, 'py-compile')
4719         if $seen_pythondir;
4721     # Preserve dist_common for later.
4722     %configure_dist_common = %dist_common;
4725 ################################################################
4727 # Set up for Cygnus mode.
4728 sub check_cygnus
4730     return unless $cygnus_mode;
4732     &set_strictness ('foreign');
4733     $options{'no-installinfo'} = 1;
4734     $options{'no-dependencies'} = 1;
4735     $use_dependencies = 0;
4737     if (! $seen_maint_mode)
4738     {
4739         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
4740     }
4742     if (! $seen_exeext)
4743     {
4744         &am_conf_error ("\`AC_EXEEXT' required when --cygnus specified");
4745     }
4748 # Do any extra checking for GNU standards.
4749 sub check_gnu_standards
4751     if ($relative_dir eq '.')
4752     {
4753         # In top level (or only) directory.
4754         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4755                        'AUTHORS', 'ChangeLog');
4756     }
4758     if ($strictness >= $GNU)
4759     {
4760         if (defined $options{'no-installman'})
4761         {
4762             &am_line_error ('AUTOMAKE_OPTIONS',
4763                             "option \`no-installman' disallowed by GNU standards");
4764         }
4766         if (defined $options{'no-installinfo'})
4767         {
4768             &am_line_error ('AUTOMAKE_OPTIONS',
4769                             "option \`no-installinfo' disallowed by GNU standards");
4770         }
4771     }
4774 # Do any extra checking for GNITS standards.
4775 sub check_gnits_standards
4777     if ($relative_dir eq '.')
4778     {
4779         # In top level (or only) directory.
4780         &require_file ($GNITS, 'THANKS');
4781     }
4784 ################################################################
4786 # Functions to handle files of each language.
4788 # Each `lang_X_rewrite' function follows a simple formula:
4789 # * Args are the directory, base name and extension of the file.
4790 # * Return value is 1 if file is to be dealt with, 0 otherwise.
4791 # Much of the actual processing is handled in handle_single_transform_list.
4792 # These functions exist so that auxiliary information can be recorded
4793 # for a later cleanup pass.  Note that the calls to these functions
4794 # are computed, so don't bother searching for their precise names
4795 # in the source.
4797 # This is just a convenience function that can be used to determine
4798 # when a subdir object should be used.
4799 sub lang_sub_obj
4801     return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4804 # Rewrite a single C source file.
4805 sub lang_c_rewrite
4807     local ($directory, $base, $ext) = @_;
4809     if (defined $options{'ansi2knr'} && $base =~ /_$/)
4810     {
4811         # FIXME: include line number in error.
4812         &am_error ("C source file \`$base.c' would be deleted by ansi2knr rules");
4813     }
4815     local ($r) = $LANG_PROCESS;
4816     if (defined $options{'subdir-objects'})
4817     {
4818         $r = $LANG_SUBDIR;
4819         $base = $directory . '/' . $base;
4821         if (! $seen_cc_c_o)
4822         {
4823             # Only give error once.
4824             $seen_cc_c_o = 1;
4825             # FIXME: line number.
4826             &am_error ("C objects in subdir but \`AM_PROG_CC_C_O' not in \`$configure_ac'");
4827         }
4829         &require_file ($FOREIGN, 'compile')
4830             if $relative_dir eq '.';
4831     }
4833     $de_ansi_files{$base} = 1;
4834     return $r;
4837 # Rewrite a single C++ source file.
4838 sub lang_cxx_rewrite
4840     return &lang_sub_obj;
4843 # Rewrite a single header file.
4844 sub lang_header_rewrite
4846     # Header files are simply ignored.
4847     return $LANG_IGNORE;
4850 # Rewrite a single yacc file.
4851 sub lang_yacc_rewrite
4853     local ($directory, $base, $ext) = @_;
4855     local ($r) = &lang_c_rewrite ($directory, $base, $ext);
4856     local ($pfx) = '';
4857     if ($r == $LANG_SUBDIR)
4858     {
4859         $pfx = $directory . '/';
4860     }
4861     $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4862     $ext =~ tr/y/c/;
4863     &saw_extension ('c');
4864     # FIXME: nodist.
4865     &push_dist_common ($pfx . $base . '.' . $ext);
4866     return $r;
4869 # Rewrite a single yacc++ file.
4870 sub lang_yaccxx_rewrite
4872     local ($directory, $base, $ext) = @_;
4874     local ($r) = $LANG_PROCESS;
4875     local ($pfx) = '';
4876     if (defined $options{'subdir-objects'})
4877     {
4878         $pfx = $directory . '/';
4879         $r = $LANG_SUBDIR;
4880     }
4881     $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4882     $ext =~ tr/y/c/;
4883     &saw_extension ($ext);
4884     # FIXME: nodist.
4885     &push_dist_common ($pfx . $base . '.' . $ext);
4886     return $r;
4889 # Rewrite a single lex file.
4890 sub lang_lex_rewrite
4892     local ($directory, $base, $ext) = @_;
4894     local ($r) = &lang_c_rewrite ($directory, $base, $ext);
4895     local ($pfx) = '';
4896     if ($r == $LANG_SUBDIR)
4897     {
4898         $pfx = $directory . '/';
4899     }
4900     $lex_sources{$pfx . $base . '.' . $ext} = 1;
4901     $ext =~ tr/l/c/;
4902     &saw_extension ('c');
4903     # FIXME: nodist.
4904     &push_dist_common ($pfx . $base . '.' . $ext);
4905     return $r;
4908 # Rewrite a single lex++ file.
4909 sub lang_lexxx_rewrite
4911     local ($directory, $base, $ext) = @_;
4913     local ($r) = $LANG_PROCESS;
4914     local ($pfx) = '';
4915     if (defined $options{'subdir-objects'})
4916     {
4917         $pfx = $directory . '/';
4918         $r = $LANG_SUBDIR;
4919     }
4920     $lex_sources{$pfx . $base . '.' . $ext} = 1;
4921     $ext =~ tr/l/c/;
4922     &saw_extension ($ext);
4923     # FIXME: nodist.
4924     &push_dist_common ($pfx . $base . '.' . $ext);
4925     return $r;
4928 # Rewrite a single assembly file.
4929 sub lang_asm_rewrite
4931     return &lang_sub_obj;
4934 # Rewrite a single Fortran 77 file.
4935 sub lang_f77_rewrite
4937     return $LANG_PROCESS;
4940 # Rewrite a single preprocessed Fortran 77 file.
4941 sub lang_ppf77_rewrite
4943     return $LANG_PROCESS;
4946 # Rewrite a single ratfor file.
4947 sub lang_ratfor_rewrite
4949     return $LANG_PROCESS;
4952 # Rewrite a single Objective C file.
4953 sub lang_objc_rewrite
4955     return &lang_sub_obj;
4958 # Rewrite a single Java file.
4959 sub lang_java_rewrite
4961     return $LANG_SUBDIR;
4964 # The lang_X_finish functions are called after all source file
4965 # processing is done.  Each should handle defining rules for the
4966 # language, etc.  A finish function is only called if a source file of
4967 # the appropriate type has been seen.
4969 sub lang_c_finish
4971     # Push all libobjs files onto de_ansi_files.  We actually only
4972     # push files which exist in the current directory, and which are
4973     # genuine source files.
4974     local ($file);
4975     foreach $file (keys %libsources)
4976     {
4977         if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
4978         {
4979             $de_ansi_files{$1} = 1;
4980         }
4981     }
4983     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
4984     {
4985         # Make all _.c files depend on their corresponding .c files.
4986         local ($base, @objects);
4987         foreach $base (sort keys %de_ansi_files)
4988         {
4989             # Each _.c file must depend on ansi2knr; otherwise it
4990             # might be used in a parallel build before it is built.
4991             # We need to support files in the srcdir and in the build
4992             # dir (because these files might be auto-generated.  But
4993             # we can't use $< -- some makes only define $< during a
4994             # suffix rule.
4995             $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
4996                               . '$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
4997                               . '`if test -f $(srcdir)/' . $base . '.c'
4998                               . '; then echo $(srcdir)/' . $base . '.c'
4999                               . '; else echo ' . $base . '.c; fi` '
5000                               . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5001                               . '| $(ANSI2KNR) > ' . $base . "_.c\n");
5002             push (@objects, $base . '_'
5003                   . ($seen_objext ? '.$(OBJEXT)' : '.o'));
5004             push (@objects, $base . '_.lo') if $seen_libtool;
5005         }
5007         # Make all _.o (and _.lo) files depend on ansi2knr.
5008         # Use a sneaky little hack to make it print nicely.
5009         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5010     }
5012     if (! defined $configure_vars{'CC'})
5013     {
5014         # FIXME: line number.
5015         &am_error ("C source seen but \`CC' not defined in \`$configure_ac'");
5016     }
5019 sub lang_cxx_finish
5021     local ($ltcompile, $ltlink) = &libtool_compiler;
5023     &define_variable ('CXXLD', '$(CXX)');
5024     &define_variable ('CXXLINK', $ltlink . '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5026     if (! defined $configure_vars{'CXX'})
5027     {
5028         &am_error ("C++ source seen but \`CXX' not defined in \`$configure_ac'");
5029     }
5032 sub lang_header_finish
5034     # Nothing to do.
5037 # This is a helper for both lex and yacc.
5038 sub yacc_lex_finish_helper
5040     return if defined $language_scratch{'lex-yacc-done'};
5041     $language_scratch{'lex-yacc-done'} = 1;
5043     # If there is more than one distinct yacc (resp lex) source file
5044     # in a given directory, then the `ylwrap' program is required to
5045     # allow parallel builds to work correctly.  FIXME: for now, no
5046     # line number.
5047     &require_config_file ($FOREIGN, 'ylwrap');
5048     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
5049     {
5050         &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5051     }
5052     else
5053     {
5054         &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
5055     }
5058 sub lang_yacc_finish
5060     return if defined $language_scratch{'yacc-done'};
5061     $language_scratch{'yacc-done'} = 1;
5063     local ($file, $base, $hname, $cname);
5064     local (%seen_suffix) = ();
5065     local (@yacc_files) = sort keys %yacc_sources;
5066     local ($yacc_count) = scalar (@yacc_files);
5067     foreach $file (@yacc_files)
5068     {
5069         $file =~ /(\..*)$/;
5070         &output_yacc_build_rule ($1, $yacc_count > 1)
5071             if ! defined $seen_suffix{$1};
5072         $seen_suffix{$1} = 1;
5074         $file =~ /^(.*)\.(y|yy|y\+\+|yxx|ypp)$/;
5075         $base = $1;
5076         $hname = 'h';           # Always use `.h' for header file.
5077         ($cname = $2) =~ tr/y/c/;
5079         if ((&variable_defined ('AM_YFLAGS')
5080              && &variable_value ('AM_YFLAGS') =~ /(^|\s)-d(\s|$)/)
5081             || (&variable_defined ('YFLAGS')
5082                 && &variable_value ('YFLAGS') =~ /(^|\s)-d(\s|$)/)) {
5083             # Now generate rule to make the header file.  This should only
5084             # be generated if `yacc -d' specified.
5085             $output_rules .= "${base}.${hname}: ${base}.${cname}\n";
5087             # If the files are built in the build directory, then we want
5088             # to remove them with `make clean'.  If they are in srcdir
5089             # they shouldn't be touched.  However, we can't determine this
5090             # statically, and the GNU rules say that yacc/lex output files
5091             # should be removed by maintainer-clean.  So that's what we
5092             # do.
5093             push (@maintainer_clean_files, "${base}.${hname}");
5095             &push_dist_common ("${base}.${hname}");
5096         }
5097         push (@maintainer_clean_files, "${base}.${cname}");
5098     }
5099     $output_rules .= "\n";
5101     if (! defined $configure_vars{'YACC'})
5102     {
5103         &am_error ("yacc source seen but \`YACC' not defined in \`$configure_ac'");
5104     }
5105     if (&variable_defined ('YACCFLAGS'))
5106     {
5107         &am_line_error ('YACCFLAGS',
5108                         "\`YACCFLAGS' obsolete; use \`YFLAGS' instead");
5109     }
5111     if ($yacc_count > 1)
5112     {
5113         &yacc_lex_finish_helper;
5114     }
5117 sub lang_yaccxx_finish
5119     &lang_yacc_finish;
5122 sub lang_lex_finish
5124     return if defined $language_scratch{'lex-done'};
5125     $language_scratch{'lex-done'} = 1;
5127     local (%seen_suffix) = ();
5128     local ($file, $cname);
5129     local ($lex_count) = scalar (keys %lex_sources);
5130     foreach $file (sort keys %lex_sources)
5131     {
5132         $file =~ /(\..*)$/;
5133         &output_lex_build_rule ($1, $lex_count > 1)
5134             if (! defined $seen_suffix{$1});
5135         $seen_suffix{$1} = 1;
5137         # If the files are built in the build directory, then we want
5138         # to remove them with `make clean'.  If they are in srcdir
5139         # they shouldn't be touched.  However, we can't determine this
5140         # statically, and the GNU rules say that yacc/lex output files
5141         # should be removed by maintainer-clean.  So that's what we
5142         # do.
5143         $file =~ /^(.*)\.(l|ll|l\+\+|lxx|lpp)$/;
5144         ($cname = $2) =~ tr/l/c/;
5145         push (@maintainer_clean_files, "${1}.${cname}");
5146     }
5148     if (! defined $configure_vars{'LEX'})
5149     {
5150         &am_error ("lex source seen but \`LEX' not defined in \`$configure_ac'");
5151     }
5152     if (! $seen_decl_yytext)
5153     {
5154         &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`$configure_ac'");
5155     }
5157     if ($lex_count > 1)
5158     {
5159         &yacc_lex_finish_helper;
5160     }
5163 sub lang_lexxx_finish
5165     &lang_lex_finish;
5168 sub lang_asm_finish
5170     # We need the C code for assembly.
5171     &lang_c_finish;
5174 sub lang_f77_finish
5176     # FIXME: this function can be called more than once.  We should
5177     # arrange for it to only do anything the first time through.
5179     local ($ltcompile, $ltlink) = &libtool_compiler;
5181     &define_variable ('F77LD', '$(F77)');
5182     &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5184     if (! defined $configure_vars{'F77'})
5185     {
5186         &am_error ("Fortran 77 source seen but \`F77' not defined in \`$configure_ac'");
5187     }
5190 # Preprocessed Fortran 77
5192 # The current support for preprocessing Fortran 77 just involves passing
5193 # `$(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)' as additional flags
5194 # to the Fortran 77 compiler, since this is how GNU Make does it; see
5195 # the `GNU Make Manual, Edition 0.51 for `make' Version 3.76 Beta'
5196 # (specifically, from info file `(make)Catalogue of Rules').
5198 # A better approach would be to write an Autoconf test
5199 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
5200 # Fortran 77 compilers know how to do preprocessing.  The Autoconf macro
5201 # AC_PROG_FPP should test the Fortran 77 compiler first for
5202 # preprocessing capabilities, and then fall back on cpp (if cpp were
5203 # available).
5204 sub lang_ppf77_finish
5206     &lang_f77_finish;
5208     # We also handle the case of preprocessing `.F' files into `.f'
5209     # files.
5210     $output_rules .= (".F.f:\n"
5211                       . "\t\$(F77COMPILE) -F \$<\n");
5214 sub lang_ratfor_finish
5216     &lang_f77_finish;
5218     # We also handle the case of preprocessing `.r' files into `.f'
5219     # files.
5220     $output_rules .= (".r.f:\n"
5221                       . "\t\$(RCOMPILE) -F \$<\n");
5224 sub lang_objc_finish
5226     local ($ltcompile, $ltlink) = &libtool_compiler;
5228     &define_variable ('OBJCLD', '$(OBJC)');
5229     &define_variable ('OBJCLINK', $ltlink . '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5231     if (! defined $configure_vars{'OBJC'})
5232     {
5233         &am_error ("Objective C source seen but \`OBJC' not defined in \`$configure_ac'");
5234     }
5237 sub lang_java_finish
5239     local ($ltcompile, $ltlink) = &libtool_compiler;
5241     &define_variable ('GCJLD', '$(GCJ)');
5242     &define_variable ('GCJLINK', $ltlink . '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5244     if (! defined $configure_vars{'GCJ'})
5245     {
5246         &am_error ("Java source seen but \`GCJ' not defined in \`$configure_ac'");
5247     }
5250 # A helper which computes a sorted list of all extensions for LANG.
5251 sub lang_extensions
5253     local ($lang) = @_;
5254     local ($key, @r);
5255     foreach $key (sort keys %extension_seen)
5256     {
5257         push (@r, '.' . $key) if $extension_map{$key} eq $lang;
5258     }
5259     return @r;
5262 # A helper which decides whether libtool is needed.  Returns prefix
5263 # for compiler and linker.
5264 sub libtool_compiler
5266     local ($ltcompile, $ltlink) = ('', '');
5267     if ($seen_libtool)
5268     {
5269         &define_configure_variable ("LIBTOOL");
5270         $ltcompile = '$(LIBTOOL) --mode=compile ';
5271         $ltlink = '$(LIBTOOL) --mode=link ';
5272     }
5273     return ($ltcompile, $ltlink);
5276 # Given a hash table of linker names, pick the name that has the most
5277 # precedence.  This is lame, but something has to have global
5278 # knowledge in order to eliminate the conflict.  Add more linkers as
5279 # required.
5280 sub resolve_linker
5282     local (%linkers) = @_;
5284     return 'GCJLINK'
5285         if defined $linkers{'GCJLINK'};
5286     return 'CXXLINK'
5287         if defined $linkers{'CXXLINK'};
5288     return 'F77LINK'
5289         if defined $linkers{'F77LINK'};
5290     return 'OBJCLINK'
5291         if defined $linkers{'OBJCLINK'};
5292     return 'LINK';
5295 # Called to indicate that an extension was used.
5296 sub saw_extension
5298     local ($ext) = @_;
5299     $extension_seen{$ext} = 1;
5302 # Called to ask whether source files have been seen . If HEADERS is 1,
5303 # headers can be included.
5304 sub saw_sources_p
5306     local ($headers) = @_;
5308     if ($headers)
5309     {
5310         $headers = 0;
5311     }
5312     else
5313     {
5314         local (@exts) = &lang_extensions ('header');
5315         $headers = @exts;
5316     }
5318     return scalar keys %extension_seen > $headers;
5321 # Register a single language.  LANGUAGE is the name of the language.
5322 # Each OPTION is either of the form NAME=VALUE, or is a file extension
5323 # (sans `.').
5324 sub register_language
5326     local ($language, @options) = @_;
5328     # Set the defaults.
5329     $language_map{$language . '-ansi-p'} = 0;
5330     $language_map{$language . '-linker'} = '';
5331     $language_map{$language . '-autodep'} = 'no';
5332     $language_map{$language . '-derived-autodep'} = 'no';
5334     local ($iter);
5335     foreach $iter (@options)
5336     {
5337         if ($iter =~ /^(.*)=(.*)$/)
5338         {
5339             $language_map{$language . '-' . $1} = $2;
5340         }
5341         elsif (defined $extension_map{$iter})
5342         {
5343             &prog_error ("duplicate extension $iter");
5344         }
5345         else
5346         {
5347             $extension_map{$iter} = $language;
5348         }
5349     }
5352 # This function is used to find a path from a user-specified suffix to
5353 # `o' or to some other suffix we recognize internally, eg `cc'.
5354 sub derive_suffix
5356     local ($source_ext) = @_;
5358     # FIXME: hard-coding `o' is a mistake.  Doing something
5359     # intelligent is harder.
5360     while ($extension_map{$source_ext} eq ''
5361            && $source_ext ne 'o'
5362            && defined $suffix_rules{$source_ext})
5363     {
5364         $source_ext = $suffix_rules{$source_ext};
5365     }
5367     return $source_ext;
5371 ################################################################
5373 # Pretty-print something.  HEAD is what should be printed at the
5374 # beginning of the first line, FILL is what should be printed at the
5375 # beginning of every subsequent line.
5376 sub pretty_print_internal
5378     local ($head, $fill, @values) = @_;
5380     local ($column) = length ($head);
5381     local ($result) = $head;
5383     # Fill length is number of characters.  However, each Tab
5384     # character counts for eight.  So we count the number of Tabs and
5385     # multiply by 7.
5386     local ($fill_length) = length ($fill);
5387     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5389     local ($bol) = ($head eq '');
5390     foreach (@values)
5391     {
5392         # "71" because we also print a space.
5393         if ($column + length ($_) > 71)
5394         {
5395             $result .= " \\\n" . $fill;
5396             $column = $fill_length;
5397             $bol = 1;
5398         }
5400         $result .= ' ' unless $bol;
5401         $result .= $_;
5402         $column += length ($_) + 1;
5403         $bol = 0;
5404     }
5406     $result .= "\n";
5407     return $result;
5410 # Pretty-print something and append to output_vars.
5411 sub pretty_print
5413     $output_vars .= &pretty_print_internal (@_);
5416 # Pretty-print something and append to output_rules.
5417 sub pretty_print_rule
5419     $output_rules .= &pretty_print_internal (@_);
5423 ################################################################
5425 # See if a target exists.
5426 sub target_defined
5428     local ($target) = @_;
5429     return defined $targets{$target};
5432 # See if two conditionals are the same.
5433 sub conditional_same
5435     local ($cond1, $cond2) = @_;
5437     return (&conditional_true_when ($cond1, $cond2)
5438             && &conditional_true_when ($cond2, $cond1));
5441 # See if a conditional is true.  Both arguments are conditional
5442 # strings.  This returns true if the first conditional is true when
5443 # the second conditional is true.
5444 sub conditional_true_when
5446     local ($cond, $when) = @_;
5448     # Check the easy case first.
5449     if ($cond eq $when)
5450     {
5451         return 1;
5452     }
5454     # Check each component of $cond, which looks @COND1@@COND2@.
5455     foreach $comp (split ('@', $cond))
5456     {
5457         # The way we split will give null strings between each
5458         # condition.
5459         next if ! $comp;
5461         if (index ($when, '@' . $comp . '@') == -1)
5462         {
5463             return 0;
5464         }
5465     }
5467     return 1;
5470 # Check for an ambiguous conditional.  This is called when a variable
5471 # or target is being defined conditionally.  If we already know about
5472 # a definition that is true under the same conditions, then we have an
5473 # ambiguity.
5474 sub check_ambiguous_conditional
5476     local ($var_name, $cond) = @_;
5477     local (@cond_vals) = split (' ', $conditional{$var_name});
5478     while (@cond_vals)
5479     {
5480         local ($vcond) = shift (@cond_vals);
5481         shift (@cond_vals);
5482         if (&conditional_true_when ($vcond, $cond)
5483             || &conditional_true_when ($cond, $vcond))
5484         {
5485             &am_line_error ($var_name,
5486                             "$var_name multiply defined in condition");
5487         }
5488     }
5491 # See if a variable exists.  The first argument is the variable name,
5492 # and the optional second argument is the condition which we should
5493 # check.  If no condition is given, we currently return true if the
5494 # variable is defined under any condition.
5495 sub variable_defined
5497     local ($var, $cond) = @_;
5498     if (defined $targets{$var})
5499     {
5500         &am_line_error ($var, "\`$var' is target; expected variable");
5501         return 0;
5502     }
5503     elsif (defined $contents{$var})
5504     {
5505         if ($cond && $conditional{$var})
5506         {
5507             # We have been asked to check for a particular condition,
5508             # and the variable is defined conditionally.  We need to
5509             # look through the conditions under which the variable is
5510             # defined, and see if any of them match the conditional we
5511             # have been asked to check.
5512             local (@cond_vars) = split (' ', $conditional{$var});
5513             while (@cond_vars)
5514             {
5515                 if (&conditional_same ($cond, shift (@cond_vars)))
5516                 {
5517                     # Even a conditional examination is good enough
5518                     # for us.  FIXME: really should maintain examined
5519                     # status on a per-condition basis.
5520                     $content_seen{$var} = 1;
5521                     return 1;
5522                 }
5523                 shift (@cond_vars);
5524             }
5526             # The variable is not defined for the given condition.
5527             return 0;
5528         }
5530         $content_seen{$var} = 1;
5531         return 1;
5532     }
5533     return 0;
5536 # Mark a variable as examined.
5537 sub examine_variable
5539     local ($var) = @_;
5540     &variable_defined ($var);
5543 # Quote a value in order to put it in $conditional.  We need to quote
5544 # spaces, and we need to handle null strings, so that we can later
5545 # retrieve values by splitting on space.
5546 sub quote_cond_val
5548     local ($val) = @_;
5549     $val =~ tr/ \t\n/\001\003\004/;
5550     $val = "\002" if $val eq '';
5551     return $val;
5554 # Unquote a value in $conditional.
5555 sub unquote_cond_val
5557     local ($val) = @_;
5558     $val =~ tr/\001\003\004/ \t\n/;
5559     $val =~ s/\002//g;
5560     return $val;
5563 # Return the set of conditions for which a variable is defined.
5565 # If the variable is not defined conditionally, and is not defined in
5566 # terms of any variables which are defined conditionally, then this
5567 # returns the empty list.
5569 # If the variable is defined conditionally, but is not defined in
5570 # terms of any variables which are defined conditionally, then this
5571 # returns the list of conditions for which the variable is defined.
5573 # If the variable is defined in terms of any variables which are
5574 # defined conditionally, then this returns a full set of permutations
5575 # of the subvariable conditions.  For example, if the variable is
5576 # defined in terms of a variable which is defined for @COND_TRUE@,
5577 # then this returns both @COND_TRUE@ and @COND_FALSE@.  This is
5578 # because we will need to define the variable under both conditions.
5580 sub variable_conditions
5582     local ($var) = @_;
5583     local (%uniqify);
5584     local (@uniq_list);
5585     local ($cond);
5587     %vars_scanned = ();
5588     foreach $cond (&variable_conditions_sub ($var, '', ()))
5589     {
5590         $uniqify{$cond} = 1;
5591     }
5593     @uniq_list = sort keys %uniqify;
5594     # Note we cannot just do `return sort keys %uniqify', because this
5595     # function is sometimes used in a scalar context.
5596     return @uniq_list;
5599 # A subroutine of variable_conditions.  We only return conditions
5600 # which are true for all the conditions in @PARENT_CONDS.
5601 sub variable_conditions_sub
5603     local ($var, $parent, @parent_conds) = @_;
5604     local (@new_conds) = ();
5606     if (defined $vars_scanned{$var})
5607     {
5608         &am_line_error ($parent, "variable \`$var' recursively defined");
5609         return ();
5610     }
5611     $vars_scanned{$var} = 1;
5613     if (! $conditional{$var})
5614     {
5615         foreach (split (' ', $contents{$var}))
5616         {
5617             # If a comment seen, just leave.
5618             last if /^#/;
5620             # Handle variable substitutions.
5621             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5622             {
5623                 push (@new_conds,
5624                       &variable_conditions_sub ($1, $var, @parent_conds));
5625             }
5626         }
5628         # Now we want to return all permutations of the subvariable
5629         # conditions.
5630         local (%allconds, $item);
5631         foreach $item (@new_conds)
5632         {
5633             foreach (split ('@', $item))
5634             {
5635                 next if ! $_;
5636                 s/_(TRUE|FALSE)$//;
5637                 $allconds{$_ . '_TRUE'} = 1;
5638             }
5639         }
5641         # Unset our entry in vars_scanned.  We only care about recursive
5642         # definitions.
5643         delete $vars_scanned{$var};
5645         return &variable_conditions_permutations (sort keys %allconds);
5646     }
5648     local (@this_conds) = ();
5649     local (@condvals) = split (' ', $conditional{$var});
5650     while (@condvals)
5651     {
5652         local ($cond) = shift (@condvals);
5653         local ($val) = &unquote_cond_val (shift (@condvals));
5655         if (@parent_conds)
5656         {
5657             local ($ok) = 1;
5658             local ($parent_cond);
5659             foreach $parent_cond (@parent_conds)
5660             {
5661                 if (! &conditional_true_when ($parent_cond, $cond))
5662                 {
5663                     $ok = 0;
5664                     last;
5665                 }
5666             }
5668             next if ! $ok;
5669         }
5671         push (@this_conds, $cond);
5673         push (@parent_conds, $cond);
5674         local (@subvar_conds) = ();
5675         foreach (split (' ', $val))
5676         {
5677             # If a comment seen, just leave.
5678             last if /^#/;
5680             # Handle variable substitutions.
5681             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5682             {
5683                 push (@subvar_conds,
5684                       &variable_conditions_sub ($1, $var, @parent_conds));
5685             }
5686         }
5687         pop (@parent_conds);
5689         # If there are no conditional subvariables, then we want to
5690         # return this condition.  Otherwise, we want to return the
5691         # permutations of the subvariables.
5692         if (! @subvar_conds)
5693         {
5694             push (@new_conds, $cond);
5695         }
5696         else
5697         {
5698             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
5699         }
5700     }
5702     # Unset our entry in vars_scanned.  We only care about recursive
5703     # definitions.
5704     delete $vars_scanned{$var};
5706     return @new_conds
5707         if ! $parent;
5709     # If we are being called on behalf of another variable, we need to
5710     # return all possible permutations of the conditions.  We have
5711     # already handled everything in @this_conds along with their
5712     # subvariables.  We now need to add any permutations that are not
5713     # in @this_conds.
5714     local ($this_cond);
5715     foreach $this_cond (@this_conds)
5716     {
5717         local (@perms) =
5718             &variable_conditions_permutations (split('@', $this_cond));
5719         local ($perm);
5720         foreach $perm (@perms)
5721         {
5722             local ($scan);
5723             local ($ok) = 1;
5724             foreach $scan (@this_conds)
5725             {
5726                 if (&conditional_true_when ($perm, $scan)
5727                     || &conditional_true_when ($scan, $perm))
5728                 {
5729                     $ok = 0;
5730                     last;
5731                 }
5732             }
5733             next if ! $ok;
5735             if (@parent_conds)
5736             {
5737                 local ($ok) = 1;
5738                 local ($parent_cond);
5739                 foreach $parent_cond (@parent_conds)
5740                 {
5741                     if (! &conditional_true_when ($parent_cond, $perm))
5742                     {
5743                         $ok = 0;
5744                         last;
5745                     }
5746                 }
5748                 next if ! $ok;
5749             }
5751             # This permutation was not already handled, and is valid
5752             # for the parents.
5753             push (@new_conds, $perm);
5754         }
5755     }
5757     return @new_conds;
5760 # Subroutine for variable_conditions_sort
5761 sub variable_conditions_cmp
5763     local ($as) = $a;
5764     $as =~ s/[^@]//g;
5765     local ($bs) = $b;
5766     $bs =~ s/[^@]//g;
5767     return (length ($as) <=> length ($bs)
5768             || $a cmp $b);
5771 # Sort a list of conditionals so that only the exclusive ones are
5772 # retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
5773 # @COND1_TRUE@ are in the list, discard the latter.
5774 sub variable_conditions_reduce
5776     local (@conds) = @_;
5777     local (@ret) = ();
5778     local ($cond);
5779     foreach $cond (sort variable_conditions_cmp @conds)
5780     {
5781         local ($ok) = 1;
5782         local ($scan);
5783         foreach $scan (@ret)
5784         {
5785             if (&conditional_true_when ($cond, $scan))
5786             {
5787                 $ok = 0;
5788                 last;
5789             }
5790         }
5791         next if ! $ok;
5792         push (@ret, $cond);
5793     }
5795     return @ret;
5798 # Return a list of permutations of a conditional string.
5799 sub variable_conditions_permutations
5801     local (@comps) = @_;
5802     return ()
5803         if ! @comps;
5804     local ($comp) = shift (@comps);
5805     return &variable_conditions_permutations (@comps)
5806         if $comp eq '';
5807     local ($neg) = $comp;
5808     $neg =~ s/TRUE$/TRUEO/;
5809     $neg =~ s/FALSE$/TRUE/;
5810     $neg =~ s/TRUEO$/FALSE/;
5811     local (@ret);
5812     local ($sub);
5813     foreach $sub (&variable_conditions_permutations (@comps))
5814     {
5815         push (@ret, '@' . $comp . '@' . $sub);
5816         push (@ret, '@' . $neg . '@' . $sub);
5817     }
5818     if (! @ret)
5819     {
5820         push (@ret, '@' . $comp . '@');
5821         push (@ret, '@' . $neg . '@');
5822     }
5823     return @ret;
5826 # Warn if a variable is conditionally defined.  This is called if we
5827 # are using the value of a variable.
5828 sub variable_conditionally_defined
5830     local ($var, $parent) = @_;
5831     if ($conditional{$var})
5832     {
5833         if ($parent)
5834         {
5835             &am_line_error ($parent,
5836                             "warning: automake does not support conditional definition of $var in $parent");
5837         }
5838         else
5839         {
5840             &am_line_error ($parent,
5841                             "warning: automake does not support $var being defined conditionally")
5842         }
5843     }
5846 # Get the value of a variable.  This just returns $contents, but warns
5847 # if the variable is conditionally defined.
5848 sub variable_value
5850     local ($var) = @_;
5851     &variable_conditionally_defined ($var);
5852     return $contents{$var};
5855 # Convert a variable value to a list, split as whitespace.  This will
5856 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5857 # substitutions.  If COND is 'all', then all values under all
5858 # conditions should be returned; if COND is a particular condition
5859 # (all conditions are surrounded by @...@) then only the value for
5860 # that condition should be returned; otherwise, warn if VAR is
5861 # conditionally defined.  SCANNED is a global hash listing whose keys
5862 # are all the variables already scanned; it is an error to rescan a
5863 # variable.
5864 sub value_to_list
5866     local ($var, $val, $cond) = @_;
5867     local (@result);
5869     # Strip backslashes
5870     $val =~ s/\\(\n|$)/ /g;
5872     foreach (split (' ', $val))
5873     {
5874         # If a comment seen, just leave.
5875         last if /^#/;
5877         # Handle variable substitutions.
5878         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
5879         {
5880             local ($varname) = $1;
5882             # If the user uses a losing variable name, just ignore it.
5883             # This isn't ideal, but people have requested it.
5884             next if ($varname =~ /\@.*\@/);
5886             local ($from, $to);
5887             local (@temp_list);
5888             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
5889             {
5890                 $varname = $1;
5891                 $to = $3;
5892                 ($from = $2) =~ s/(\W)/\\$1/g;
5893             }
5895             # Find the value.
5896             @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
5898             # Now rewrite the value if appropriate.
5899             if ($from)
5900             {
5901                 grep (s/$from$/$to/, @temp_list);
5902             }
5904             push (@result, @temp_list);
5905         }
5906         else
5907         {
5908             push (@result, $_);
5909         }
5910     }
5912     return @result;
5915 # Return contents of variable as list, split as whitespace.  This will
5916 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5917 # substitutions.  If COND is 'all', then all values under all
5918 # conditions should be returned; if COND is a particular condition
5919 # (all conditions are surrounded by @...@) then only the value for
5920 # that condition should be returned; otherwise, warn if VAR is
5921 # conditionally defined.  If PARENT is specified, it is the name of
5922 # the including variable; this is only used for error reports.
5923 sub variable_value_as_list_worker
5925     local ($var, $cond, $parent) = @_;
5926     local (@result);
5928     if (defined $targets{$var})
5929     {
5930         &am_line_error ($var, "\`$var' is target; expected variable");
5931     }
5932     elsif (! defined $contents{$var} && ! defined $am_var_defs{$var})
5933     {
5934         &am_line_error ($parent, "variable \`$var' not defined");
5935     }
5936     elsif (defined $vars_scanned{$var})
5937     {
5938         # `vars_scanned' is a global we use to keep track of which
5939         # variables we've already examined.
5940         &am_line_error ($parent, "variable \`$var' recursively defined");
5941     }
5942     elsif ($cond eq 'all' && $conditional{$var})
5943     {
5944         $vars_scanned{$var} = 1;
5945         local (@condvals) = split (' ', $conditional{$var});
5946         while (@condvals)
5947         {
5948             shift (@condvals);
5949             local ($val) = &unquote_cond_val (shift (@condvals));
5950             push (@result, &value_to_list ($var, $val, $cond));
5951         }
5952     }
5953     elsif ($cond && $conditional{$var})
5954     {
5955         $vars_scanned{$var} = 1;
5956         local (@condvals) = split (' ', $conditional{$var});
5957         local ($onceflag);
5958         while (@condvals)
5959         {
5960             local ($vcond) = shift (@condvals);
5961             local ($val) = &unquote_cond_val (shift (@condvals));
5962             if (&conditional_true_when ($vcond, $cond))
5963             {
5964                 # Warn if we have an ambiguity.  It's hard to know how
5965                 # to handle this case correctly.
5966                 &variable_conditionally_defined ($var, $parent)
5967                     if $onceflag;
5968                 $onceflag = 1;
5969                 push (@result, &value_to_list ($var, $val, $cond));
5970             }
5971         }
5972     }
5973     elsif (defined $am_var_defs{$var})
5974     {
5975         $vars_scanned{$var} = 1;
5976         &variable_conditionally_defined ($var, $parent);
5977         $content_seen{$var} = 1;
5978         push (@result, &value_to_list ($var, $am_var_defs{$var}, $cond));
5979     }
5980     else
5981     {
5982         $vars_scanned{$var} = 1;
5983         &variable_conditionally_defined ($var, $parent);
5984         $content_seen{$var} = 1;
5985         push (@result, &value_to_list ($var, $contents{$var}, $cond));
5986     }
5988     # Unset our entry in vars_scanned.  We only care about recursive
5989     # definitions.
5990     delete $vars_scanned{$var};
5992     return @result;
5995 # This is just a wrapper for variable_value_as_list_worker that
5996 # initializes the global hash `vars_scanned'.  This hash is used to
5997 # avoid infinite recursion.
5998 sub variable_value_as_list
6000     local ($var, $cond, $parent) = @_;
6001     %vars_scanned = ();
6002     return &variable_value_as_list_worker ($var, $cond, $parent);
6006 # define_variable ($VAR, $VALUE)
6007 # ------------------------------
6008 # Define a new variable VAR to VALUE, but only if not already defined.
6009 sub define_variable
6011     local ($var, $value) = @_;
6013     if (! defined $contents{$var})
6014     {
6015         $output_vars .= $var . ' = ' . $value . "\n";
6016         $contents{$var} = $value;
6017         $content_seen{$var} = 1;
6018     }
6019     elsif ($var_was_plus_eq{$var})
6020     {
6021         &am_line_error ($var, "internally generated variable \`$var' was set with \`+='");
6022     }
6025 # Like define_variable, but the value is a list, and the variable may
6026 # be defined conditionally.  The second argument is the conditional
6027 # under which the value should be defined; this should be the empty
6028 # string to define the variable unconditionally.  The third argument
6029 # is a list holding the values to use for the variable.  The value is
6030 # pretty printed in the output file.
6031 sub define_pretty_variable
6033     local ($var, $cond, @value) = @_;
6034     if (! defined $contents{$var}
6035         || ($cond && ! &variable_defined ($var, $cond)))
6036     {
6037         $contents{$var} = join (' ', @value);
6038         if ($cond)
6039         {
6040             if ($conditional{$var})
6041             {
6042                 $conditional{$var} .= ' ';
6043             }
6044             else
6045             {
6046                 $conditional{$var} = '';
6047             }
6048             $conditional{$var} .= ($cond
6049                                    . ' '
6050                                    . &quote_cond_val ($contents{$var}));
6051         }
6052         &pretty_print ($cond . $var . ' = ', $cond, @value);
6053         $content_seen{$var} = 1;
6054     }
6057 # Like define_variable, but define a variable to be the configure
6058 # substitution by the same name.
6059 sub define_configure_variable
6061     local ($var) = @_;
6062     local ($value) = '@' . $var . '@';
6063     &define_variable ($var, $value);
6066 # Define a compiler variable.  We also handle defining the `LT'
6067 # version of the command when using libtool.
6068 sub define_compiler_variable
6070     local ($var, $ltcompile, $value) = @_;
6071     local ($name) = $var;
6072     &define_variable ($name, $value);
6073     &define_variable ('LT' . $name, $ltcompile . $value)
6074         if $seen_libtool;
6077 # Define a variable that represents a program to run.  If in Cygnus
6078 # mode, the program is searched for in the build (or source) tree.
6079 # Otherwise no searching is done at all.  Arguments are:
6080 # * VAR      Name of variable to define
6081 # * WHATDIR  Either `src' or `build', depending on where program should
6082 #            be found.  (runtest is in srcdir!)
6083 # * SUBDIR   Subdir of top-level dir
6084 # * PROGRAM  Name of program
6085 # * OVERRIDE If specified, the name of the program to use when not in
6086 #            Cygnus mode.  Defaults to PROGRAM.
6087 sub define_program_variable
6089     local ($var, $whatdir, $subdir, $program, $override) = @_;
6091     if (! $override)
6092     {
6093         $override = $program;
6094     }
6096     if ($cygnus_mode)
6097     {
6098         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
6099                          . $subdir . '/' . $program);
6100         &define_variable ($var, ('`if test -f ' . $full
6101                                  . '; then echo ' . $full . '; else echo '
6102                                  . $program . '; fi`'));
6103     }
6104     else
6105     {
6106         &define_variable ($var, $override);
6107     }
6111 ################################################################
6113 # Read Makefile.am and set up %contents.  Simultaneously copy lines
6114 # from Makefile.am into $output_trailer or $output_vars as
6115 # appropriate.  NOTE we put rules in the trailer section.  We want
6116 # user rules to come after our generated stuff.
6117 sub read_am_file
6119     local ($amfile) = @_;
6120     local (*AM_FILE);
6122     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
6123     print "automake: reading $amfile\n" if $verbose;
6125     local ($saw_bk) = 0;
6126     local ($was_rule) = 0;
6127     local ($spacing) = '';
6128     local ($comment) = '';
6129     local ($last_var_name) = '';
6130     local ($blank) = 0;
6132     # We save the conditional stack on entry, and then check to make
6133     # sure it is the same on exit.  This lets us conditonally include
6134     # other files.
6135     local (@saved_cond_stack) = @conditional_stack;
6137     while (<AM_FILE>)
6138     {
6139         if (/$IGNORE_PATTERN/o)
6140         {
6141             # Merely delete comments beginning with two hashes.
6142         }
6143         elsif (/$WHITE_PATTERN/o)
6144         {
6145             # Stick a single white line before the incoming macro or rule.
6146             $spacing = "\n";
6147             $blank = 1;
6148         }
6149         elsif (/$COMMENT_PATTERN/o)
6150         {
6151             # Stick comments before the incoming macro or rule.  Make
6152             # sure a blank line preceeds first block of comments.
6153             $spacing = "\n" unless $blank;
6154             $blank = 1;
6155             $comment .= $spacing . $_;
6156             $spacing = '';
6157         }
6158         else
6159         {
6160             last;
6161         }
6162     }
6164     $output_vars .= $comment . "\n";
6165     $comment = '';
6166     $spacing = "\n";
6168     local ($is_ok_macro);
6169     while ($_)
6170     {
6171         $_ .= "\n"
6172             unless substr ($_, -1, 1) eq "\n";
6174         # Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
6175         # used by users.  @MAINT@ is an anachronism now.
6176         $_ =~ s/\@MAINT\@//g
6177             unless $seen_maint_mode;
6179         if (/$IGNORE_PATTERN/o)
6180         {
6181             # Merely delete comments beginning with two hashes.
6182         }
6183         elsif (/$WHITE_PATTERN/o)
6184         {
6185             # Stick a single white line before the incoming macro or rule.
6186             $spacing = "\n";
6187             &am_line_error ($., "blank line following trailing backslash")
6188                 if $saw_bk;
6189         }
6190         elsif (/$COMMENT_PATTERN/o)
6191         {
6192             # Stick comments before the incoming macro or rule.
6193             $comment .= $spacing . $_;
6194             $spacing = '';
6195             &am_line_error ($., "comment following trailing backslash")
6196                 if $saw_bk;
6197         }
6198         elsif ($saw_bk)
6199         {
6200             if ($was_rule)
6201             {
6202                 $output_trailer .= join ('', @conditional_stack) . $_;
6203                 $saw_bk = /\\$/;
6204             }
6205             else
6206             {
6207                 $saw_bk = /\\$/;
6208                 $contents{$last_var_name} .= ' '
6209                     unless $contents{$last_var_name} =~ /\s$/;
6210                 $contents{$last_var_name} .= $_;
6211                 if (@conditional_stack)
6212                 {
6213                     $conditional{$last_var_name} .= &quote_cond_val ($_);
6214                 }
6215             }
6216         }
6217         elsif (/$IF_PATTERN/o)
6218         {
6219             &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
6220                 if (! $configure_cond{$1});
6221             push (@conditional_stack, "\@" . $1 . "_TRUE\@");
6222         }
6223         elsif (/$ELSE_PATTERN/o)
6224         {
6225             if (! @conditional_stack)
6226             {
6227                 &am_line_error ($., "else without if");
6228             }
6229             elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
6230             {
6231                 &am_line_error ($., "else after else");
6232             }
6233             else
6234             {
6235                 $conditional_stack[$#conditional_stack]
6236                     =~ s/_TRUE\@$/_FALSE\@/;
6237             }
6238         }
6239         elsif (/$ENDIF_PATTERN/o)
6240         {
6241             if (! @conditional_stack)
6242             {
6243                 &am_line_error ($., "endif without if");
6244             }
6245             else
6246             {
6247                 pop @conditional_stack;
6248             }
6249         }
6250         elsif (/$RULE_PATTERN/o)
6251         {
6252             # Found a rule.
6253             $was_rule = 1;
6254             if (defined $contents{$1}
6255                 && (@conditional_stack
6256                     ? ! defined $conditional{$1}
6257                     : defined $conditional{$1}))
6258             {
6259                 &am_line_error ($1,
6260                                 "$1 defined both conditionally and unconditionally");
6261             }
6262             # Value here doesn't matter; for targets we only note
6263             # existence.
6264             $contents{$1} = 1;
6265             $targets{$1} = 1;
6266             local ($cond_string) = join ('', @conditional_stack);
6267             if (@conditional_stack)
6268             {
6269                 if ($conditional{$1})
6270                 {
6271                     &check_ambiguous_conditional ($1, $cond_string);
6272                     $conditional{$1} .= ' ';
6273                 }
6274                 else
6275                 {
6276                     $conditional{$1} = '';
6277                 }
6278                 $conditional{$1} .= $cond_string . ' 1';
6279             }
6280             $content_lines{$1} = $.;
6281             $output_trailer .= $comment . $spacing . $cond_string . $_;
6282             $comment = $spacing = '';
6283             $saw_bk = /\\$/;
6285             # Check the rule for being a suffix rule. If so, store in
6286             # a hash.
6288             local ($source_suffix);
6289             local ($object_suffix);
6291             if (($source_suffix, $object_suffix) = ($1 =~ $SUFFIX_RULE_PATTERN))
6292             {
6293               $suffix_rules{$source_suffix} = $object_suffix;
6294               print "Sources ending in .$source_suffix become .$object_suffix\n" if $verbose;
6295               $source_suffix_pattern = "(" . join ('|', keys %suffix_rules) . ")";
6296             }
6298             # FIXME: make sure both suffixes are in SUFFIXES? Or set
6299             # SUFFIXES from suffix_rules?
6300         }
6301         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
6302                || /$BOGUS_MACRO_PATTERN/o)
6303         {
6304             # Found a macro definition.
6305             $was_rule = 0;
6306             $last_var_name = $1;
6307             if (defined $contents{$1}
6308                 && (@conditional_stack
6309                     ? ! defined $conditional{$1}
6310                     : defined $conditional{$1}))
6311             {
6312                 &am_line_error ($1,
6313                                 "$1 defined both conditionally and unconditionally");
6314             }
6315             local ($value);
6316             if ($3 ne '' && substr ($3, -1) eq "\\")
6317             {
6318                 # We preserve the `\' because otherwise the long lines
6319                 # that are generated will be truncated by broken
6320                 # `sed's.
6321                 $value = $3 . "\n";
6322             }
6323             else
6324             {
6325                 $value = $3;
6326             }
6327             local ($type) = $2;
6329             if (! defined $contents{$last_var_name})
6330             {
6331                 # The first assignment to a macro sets the line
6332                 # number.  Ideally I suppose we would associate line
6333                 # numbers with random bits of text.
6334                 $content_lines{$last_var_name} = $.;
6336                 # If first assignment, set `+=' indicator.
6337                 $var_was_plus_eq{$last_var_name} =
6338                     ($type eq '+'
6339                      && ! defined $am_var_defs{$last_var_name});
6340             }
6342             if ($type eq '+')
6343             {
6344                 if (! defined $contents{$last_var_name}
6345                     && defined $am_var_defs{$last_var_name})
6346                 {
6347                     $contents{$last_var_name} = $am_var_defs{$last_var_name};
6348                 }
6349                 if (substr ($contents{$last_var_name}, -1) eq "\n")
6350                 {
6351                     # Insert a backslash before a trailing newline.
6352                     $contents{$last_var_name}
6353                         = substr ($contents{$last_var_name}, 0, -1) . "\\\n";
6354                 }
6355                 $contents{$last_var_name} .= ' ' . $value;
6356             }
6357             else
6358             {
6359                 $contents{$last_var_name} = $value;
6360             }
6361             local ($cond_string) = join ('', @conditional_stack);
6362             if (@conditional_stack)
6363             {
6364                 local ($found) = 0;
6365                 local ($val);
6366                 if ($conditional{$last_var_name})
6367                 {
6368                     if ($type eq '+')
6369                     {
6370                         # If we're adding to the conditional, and it
6371                         # exists, then we might want to simply replace
6372                         # the old value with the new one.
6373                         local (@new_vals, @cond_vals);
6374                         @cond_vals = split (' ', $conditional{$last_var_name});
6375                         while (@cond_vals)
6376                         {
6377                             local ($vcond) = shift (@cond_vals);
6378                             push (@new_vals, $vcond);
6379                             if (&conditional_same ($vcond, $cond_string))
6380                             {
6381                                 $found = 1;
6382                                 $val = (&unquote_cond_val (shift (@cond_vals))
6383                                         . ' ' . $value);
6384                                 push (@new_vals, &quote_cond_val ($val));
6385                             }
6386                             else
6387                             {
6388                                 push (@new_vals, shift (@cond_vals));
6389                             }
6390                         }
6391                         if ($found)
6392                         {
6393                             $conditional{$last_var_name}
6394                                 = join (' ', @new_vals);
6395                         }
6396                     }
6398                     if (! $found)
6399                     {
6400                         &check_ambiguous_conditional ($last_var_name,
6401                                                       $cond_string);
6402                         $conditional{$last_var_name} .= ' ';
6403                         $val = $value;
6404                     }
6405                 }
6406                 else
6407                 {
6408                     $conditional{$last_var_name} = '';
6409                     $val = $contents{$last_var_name};
6410                 }
6411                 if (! $found)
6412                 {
6413                     $conditional{$last_var_name} .= ($cond_string
6414                                                      . ' '
6415                                                      . &quote_cond_val ($val));
6416                 }
6417             }
6419             # FIXME: this doesn't always work correctly; it will group
6420             # all comments for a given variable, no matter where
6421             # defined.
6422             $am_vars{$last_var_name} = $comment . $spacing;
6423             $def_type{$last_var_name} = ($type eq ':') ? ':' : '';
6424             push (@var_list, $last_var_name);
6425             $comment = $spacing = '';
6426             $saw_bk = /\\$/;
6428             # Error if bogus.
6429             &am_line_error ($., "bad macro name \`$last_var_name'")
6430                 if ! $is_ok_macro;
6431         }
6432         elsif (/$INCLUDE_PATTERN/o)
6433         {
6434             local ($path) = $1;
6436             if ($path =~ s/^\$\(top_srcdir\)\///)
6437             {
6438                 push (@include_stack, "\$\(top_srcdir\)/$path");
6439             }
6440             else
6441             {
6442                 $path =~ s/\$\(srcdir\)\///;
6443                 push (@include_stack, "\$\(srcdir\)/$path");
6444                 $path = $relative_dir . "/" . $path;
6445             }
6446             &read_am_file ($path);
6447         }
6448         else
6449         {
6450             # This isn't an error; it is probably a continued rule.
6451             # In fact, this is what we assume.
6452             $was_rule = 1;
6453             $output_trailer .= ($comment . $spacing
6454                                 . join ('', @conditional_stack) . $_);
6455             $comment = $spacing = '';
6456             $saw_bk = /\\$/;
6457         }
6459         $_ = <AM_FILE>;
6460     }
6462     $output_trailer .= $comment;
6464     if (join (' ', @saved_cond_stack) ne join (' ', @conditional_stack))
6465     {
6466         if (@conditional_stack)
6467         {
6468             &am_error ("unterminated conditionals: @conditional_stack");
6469         }
6470         else
6471         {
6472             # FIXME: better error message here.
6473             &am_error ("conditionals not nested in include file");
6474         }
6475     }
6479 # define_standard_variables ()
6480 # ----------------------------
6481 # A helper for read_main_am_file which initializes configure variables
6482 # and variables from header-vars.am.  This is a subr so we can call it
6483 # twice.
6484 sub define_standard_variables
6486     # Compute relative location of the top object directory.
6487     local (@topdir) = ();
6488     foreach (split (/\//, $relative_dir))
6489     {
6490         next if $_ eq '.' || $_ eq '';
6491         if ($_ eq '..')
6492         {
6493             pop @topdir;
6494         }
6495         else
6496         {
6497             push (@topdir, '..');
6498         }
6499     }
6500     @topdir = ('.') if ! @topdir;
6502     $top_builddir = join ('/', @topdir);
6503     $output_vars .=
6504         &file_contents ('header-vars',
6505                         &transform ('top_builddir' => $top_builddir));
6507     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
6508     # this should use generic %configure_vars method.
6509     if ($seen_canonical)
6510     {
6511         local ($curs, %vars);
6512         $vars{'host_alias'} = 'host_alias';
6513         $vars{'host_triplet'} = 'host';
6514         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
6515         {
6516             $vars{'build_alias'} = 'build_alias';
6517             $vars{'build_triplet'} = 'build';
6518             $vars{'target_alias'} = 'target_alias';
6519             $vars{'target_triplet'} = 'target';
6520         }
6521         foreach $curs (sort keys %vars)
6522         {
6523             $output_vars .= "$curs = \@$vars{$curs}\@\n";
6524             $contents{$curs} = "\@$vars{$curs}\@";
6525         }
6526     }
6528     local ($curs);
6529     foreach $curs (sort keys %configure_vars)
6530     {
6531         &define_configure_variable ($curs);
6532     }
6535 # Read main am file.
6536 sub read_main_am_file
6538     local ($amfile) = @_;
6540     # The keys here are variables we want to dump at the end of this
6541     # function.  The values are corresponding comments.
6542     local (%am_vars) = ();
6543     local (@var_list) = ();
6544     local (%def_type) = ();
6546     # This supports the strange variable tricks we are about to play.
6547     &prog_error ("variable defined before read_main_am_file")
6548         if scalar keys %contents > 0;
6550     # We want to predefine as many variables as possible.  This lets
6551     # the user set them with `+=' in Makefile.am.  However, we don't
6552     # want these initial definitions to end up in the output quite
6553     # yet.  So we adopt a hack: read the `.am' file twice, throwing
6554     # away the output the first time.  We also squirrel away a list of
6555     # all the variables defined by the .am file so that we know which
6556     # ones to remove from the content list.
6558     # First pass.
6559     &define_standard_variables;
6560     local (%saved_contents) = %contents;
6562     # Read user file, but discard text of variable assignments we just
6563     # made.
6564     $output_vars = '';
6565     &read_am_file ($amfile);
6567     # Now dump the variables that were defined.  We do it in the same
6568     # order in which they were defined (skipping duplicates).
6569     local (%done);
6570     foreach $curs (@var_list)
6571     {
6572         next if $done{$curs};
6573         $done{$curs} = 1;
6575         $output_vars .= $am_vars{$curs};
6576         if ($conditional{$curs})
6577         {
6578             local (@cond_vals) = split (' ', $conditional{$curs});
6579             while (@cond_vals)
6580             {
6581                 local ($vcond) = shift (@cond_vals);
6582                 local ($val) = &unquote_cond_val (shift (@cond_vals));
6583                 $output_vars .= ($vcond . $curs . ' '
6584                                  . $def_type{$curs} . "= ");
6585                 local ($line);
6586                 foreach $line (split ("\n", $val))
6587                 {
6588                     $output_vars .= $vcond . $line . "\n";
6589                 }
6590                 $output_vars .= "\n"
6591                     if $val eq '';
6592             }
6593         }
6594         else
6595         {
6596             $output_vars .= ($curs . ' ' . $def_type{$curs} . '= '
6597                              . $contents{$curs} . "\n");
6598         }
6599     }
6601     # Generate copyright header for generated Makefile.in.
6602     local ($ov) = $output_vars;
6603     $output_vars = ("# $in_file_name generated automatically by automake "
6604                    . $VERSION . " from $am_file_name\n");
6605     $output_vars .= $gen_copyright;
6607     # Now go through and delete all the variables that the user did
6608     # not change.
6609     local ($var);
6610     foreach $var (keys %saved_contents)
6611     {
6612         if ($contents{$var} eq $saved_contents{$var})
6613         {
6614             delete $contents{$var};
6615         }
6616     }
6618     # Re-read the standard variables, and this time keep their
6619     # contributions to the output.  Then add the user's output to the
6620     # end.
6621     &define_standard_variables;
6622     $output_vars .= $ov;
6626 ################################################################
6628 sub initialize_global_constants
6630     # Values for AC_CANONICAL_*
6631     $AC_CANONICAL_HOST = 1;
6632     $AC_CANONICAL_SYSTEM = 2;
6634     # Associative array of standard directory names.  Entry is TRUE if
6635     # corresponding directory should be installed during
6636     # 'install-exec' phase.
6637     %exec_dir_p =
6638         ('bin', 1,
6639          'sbin', 1,
6640          'libexec', 1,
6641          'data', 0,
6642          'sysconf', 1,
6643          'localstate', 1,
6644          'lib', 1,
6645          'info', 0,
6646          'man', 0,
6647          'include', 0,
6648          'oldinclude', 0,
6649          'pkgdata', 0,
6650          'pkglib', 1,
6651          'pkginclude', 0
6652          );
6654     # Commonly found files we look for and automatically include in
6655     # DISTFILES.
6656     @common_files =
6657         (
6658          'README', 'THANKS', 'TODO', 'NEWS', 'COPYING', 'COPYING.LIB',
6659          'INSTALL', 'ABOUT-NLS', 'ChangeLog', 'configure.ac',
6660          'configure.in', 'configure', 'config.guess', 'config.sub',
6661          'AUTHORS', 'BACKLOG', 'ABOUT-GNU', 'libversion.in',
6662          'mdate-sh', 'mkinstalldirs', 'install-sh', 'texinfo.tex',
6663          'ansi2knr.c', 'ansi2knr.1', 'elisp-comp',
6664          # ltconfig appears here for compatibility with old versions
6665          # of libtool.
6666          'ylwrap', 'acinclude.m4', @libtoolize_files, @libtoolize_sometimes,
6667          'missing', 'depcomp', 'compile', 'py-compile'
6668          );
6670     # Commonly used files we auto-include, but only sometimes.
6671     @common_sometimes =
6672         (
6673          'aclocal.m4', 'acconfig.h', 'config.h.top',
6674          'config.h.bot', 'stamp-h.in', 'stamp-vti'
6675          );
6677     $USAGE = "\
6678   -a, --add-missing     add missing standard files to package
6679   --amdir=DIR           directory storing config files
6680   -c, --copy            with -a, copy missing files (default is symlink)
6681   --cygnus              assume program is part of Cygnus-style tree
6682   --force-missing       force update of standard files
6683   --foreign             set strictness to foreign
6684   --gnits               set strictness to gnits
6685   --gnu                 set strictness to gnu
6686   --help                print this help, then exit
6687   -i, --ignore-deps     disable dependency tracking code
6688   --include-deps        enable dependency tracking code
6689   --no-force            only update Makefile.in's that are out of date
6690   -o DIR, --output-dir=DIR
6691                         put generated Makefile.in's into DIR
6692   -v, --verbose         verbosely list files processed
6693   --version             print version number, then exit\n";
6695     # Copyright on generated Makefile.ins.
6696     $gen_copyright = "\
6697 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000
6698 # Free Software Foundation, Inc.
6699 # This Makefile.in is free software; the Free Software Foundation
6700 # gives unlimited permission to copy and/or distribute it,
6701 # with or without modifications, as long as this notice is preserved.
6703 # This program is distributed in the hope that it will be useful,
6704 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
6705 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6706 # PARTICULAR PURPOSE.
6709     # This complex find command will try to avoid changing the modes of
6710     # links into the source tree, in case they're hard-linked.  It will
6711     # also make directories writable by everybody, because some
6712     # brain-dead tar implementations change ownership and permissions of
6713     # a directory before extracting the files, thus becoming unable to
6714     # extract them.
6715     # Ignore return result from chmod, because it might give an error
6716     # if we chmod a symlink.
6717     # Another nastiness: if the file is unreadable by us, we make it
6718     # readable regardless of the number of links to it.  This only
6719     # happens in perverse cases.
6720     # We use $(install_sh) because that is a known-portable way to
6721     # modify the file in place in the source tree.
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 -400 -exec chmod a+r {} \; -o \\
6725           ! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \\
6726         || chmod -R a+r $(distdir)
6728     $dist{'dist-bzip2'} = ("\t"
6729                            . '$(AMTAR) chof - $(distdir) | bzip2 -9 -c > $(distdir).tar.bz2'
6730                            . "\n");
6731     $dist{'dist-tarZ'} = ("\t"
6732                      . '$(AMTAR) chof - $(distdir) | compress -c > $(distdir).tar.Z'
6733                      . "\n");
6734     $dist{'dist-shar'} = ("\t"
6735                      . 'shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).shar.gz'
6736                      . "\n");
6737     $dist{'dist-zip'} = ("\t" . '-rm -f $(distdir).zip' . "\n" .
6738                          "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n");
6740     # Note that we don't use GNU tar's `-z' option.  One reason (but
6741     # not the only reason) is that some versions of tar (e.g., OSF1)
6742     # interpret `-z' differently.
6743     $dist{'dist'} = ("\t"
6744                      .  '$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).tar.gz'
6745                      . "\n");
6746     $dist_trailer = "\t" . '-chmod -R a+w $(distdir) > /dev/null 2>&1; rm -rf $(distdir)' . "\n";
6749 # (Re)-Initialize per-Makefile.am variables.
6750 sub initialize_per_input
6752     # These two variables are used when generating each Makefile.in.
6753     # They hold the Makefile.in until it is ready to be printed.
6754     $output_rules = '';
6755     $output_vars = '';
6756     $output_trailer = '';
6757     $output_all = '';
6758     $output_header = '';
6760     # Suffixes found during a run.
6761     @suffixes = ();
6763     # This holds the contents of a Makefile.am, as parsed by
6764     # read_am_file.
6765     %contents = ();
6767     # This holds the names which are targets.  These also appear in
6768     # %contents.
6769     %targets = ();
6771     # This maps a variable name onto a flag.  The flag is true iff the
6772     # variable was first defined with `+='.
6773     %var_was_plus_eq = ();
6775     # This holds definitions of all variables defined in .am files.
6776     # This is used during startup to determine which variables can be
6777     # assigned with `+='.
6778     %am_var_defs = ();
6780     # For a variable or target which is defined conditionally, this
6781     # holds an array of the conditional values.  The array is composed
6782     # of pairs of condition strings (the variables which configure
6783     # will substitute) and values (the value of a target is
6784     # meaningless).  For an unconditional variable, this is empty.
6785     %conditional = ();
6787     # This holds the line numbers at which various elements of
6788     # %contents are defined.
6789     %content_lines = ();
6791     # This holds a 1 if a particular variable was examined.
6792     %content_seen = ();
6794     # This is the conditional stack.
6795     @conditional_stack = ();
6797     # This holds the set of included files.
6798     @include_stack = ();
6800     # This holds the "relative directory" of the current Makefile.in.
6801     # Eg for src/Makefile.in, this is "src".
6802     $relative_dir = '';
6804     # This holds a list of files that are included in the
6805     # distribution.
6806     %dist_common = ();
6808     # This holds a list of directories which we must create at `dist'
6809     # time.  This is used in some strange scenarios involving weird
6810     # AC_OUTPUT commands.
6811     %dist_dirs = ();
6813     # List of dependencies for the obvious targets.
6814     @install_data = ();
6815     @install_exec = ();
6816     @uninstall = ();
6817     @installdirs = ();
6819     @info = ();
6820     @dvi = ();
6821     @all = ();
6822     @check = ();
6823     @check_tests = ();
6824     @installcheck = ();
6826     # Holds the dependencies of targets which dependencies are factored.
6827     # Typically, `.PHONY' will appear in plenty of *.am files, but must
6828     # be output once.  Arguably all pure dependencies could be subject
6829     # to this factorization, but it is not unpleasant to have paragraphs
6830     # in Makefile: keeping related stuff altogether.
6831     %dependencies =
6832       (
6833        'clean-am'             => [],
6834        'mostlyclean-am'       => [],
6835        'maintainer-clean-am'  => [],
6836        'distclean-am'         => [],
6837        'clean'                => [],
6838        'mostlyclean'          => [],
6839        'maintainer-clean'     => [],
6840        'distclean'            => [],
6841        '.PHONY'               => []
6842       );
6843     # Holds the factored actions.  Tied to %DEPENDENCIES, i.e., filled
6844     # only when keys exists in %DEPENDENCIES.
6845     %actions = ();
6847     # A list of files deleted by `maintainer-clean'.
6848     @maintainer_clean_files = ();
6850     # These are pretty obvious, too.  They are used to define the
6851     # SOURCES and OBJECTS variables.
6852     @sources = ();
6853     @objects = ();
6854     # Sources which go in the distribution.
6855     @dist_sources = ();
6857     # This hash maps object file names onto their corresponding source
6858     # file names.  This is used to ensure that each object is created
6859     # by a single source file.
6860     %object_map = ();
6862     # This keeps track of the directories for which we've already
6863     # created `.dirstamp' code.
6864     %directory_map = ();
6866     # These variables track inclusion of various compile-related .am
6867     # files.  $included_generic_compile is TRUE if the basic code has
6868     # been included.  $included_knr_compile is TRUE if the ansi2knr
6869     # code has been included.  $included_libtool_compile is TRUE if
6870     # libtool support has been included.
6871     $included_generic_compile = 0;
6872     $included_knr_compile = 0;
6873     $included_libtool_compile = 0;
6875     # TRUE if install targets should work recursively.
6876     $recursive_install = 0;
6878     # All .P files.
6879     %dep_files = ();
6881     # Strictness levels.
6882     $strictness = $default_strictness;
6883     $strictness_name = $default_strictness_name;
6885     # Options from AUTOMAKE_OPTIONS.
6886     %options = ();
6888     # Whether or not dependencies are handled.  Can be further changed
6889     # in handle_options.
6890     $use_dependencies = $cmdline_use_dependencies;
6892     # Per Makefile.am.
6893     $local_maint_charset = $maint_charset;
6895     # All yacc and lex source filenames for this directory.  Use
6896     # filenames instead of raw count so that multiple instances are
6897     # counted correctly (eg one yacc file can appear in multiple
6898     # programs without harm).
6899     %yacc_sources = ();
6900     %lex_sources = ();
6902     # This is a list of all targets to run during "make dist".
6903     @dist_targets = ();
6905     # Keys in this hash are the basenames of files which must depend
6906     # on ansi2knr.
6907     %de_ansi_files = ();
6909     # This maps the source extension of a suffix rule to its
6910     # corresponding output extension.
6911     %suffix_rules = ();
6913     # This is a regular expression which matches all the known source
6914     # suffix.  A source suffix is one that appears in the first
6915     # position of a suffix rule.
6916     $source_suffix_pattern = '';
6918     # This is the name of the recursive `all' target to use.
6919     $all_target = 'all-recursive';
6921     # This keeps track of which extensions we've seen (that we care
6922     # about).
6923     %extension_seen = ();
6925     # This is random scratch space for the language finish functions.
6926     # Don't randomly overwrite it; examine other uses of keys first.
6927     %language_scratch = ();
6929     # We keep track of which objects need special (per-executable)
6930     # handling on a per-language basis.
6931     %lang_specific_files = ();
6933     # This is set when `handle_dist' has finished.  Once this happens,
6934     # we should no longer push on dist_common.
6935     $handle_dist_run = 0;
6937     # True if we need `LINK' defined.  This is a hack.
6938     $need_link = 0;
6942 ################################################################
6944 # $FLATTENED
6945 # &flatten ($STRING)
6946 # ------------------
6947 # Flatten the $STRING and return the result.
6948 sub flatten
6950   $_ = shift;
6952   s/\\\n//somg;
6953   s/\s+/ /g;
6954   s/^ //;
6955   s/ $//;
6957   return $_;
6961 # $CONTENTS
6962 # &file_contents ($BASENAME, [$COMMAND])
6963 # --------------------------------------
6964 # Return contents of a file from $am_dir, automatically skipping
6965 # macros or rules which are already known.  Runs command on each line
6966 # as it is read; this command can modify $_.
6967 sub file_contents
6969     local ($basename, $command) = @_;
6970     local ($file) = $am_dir . '/' . $basename . '.am';
6972     &prog_error ("file_contents: $command")
6973         if $command ne '' && substr ($command, -1) ne ';';
6975     open (FC_FILE, $file)
6976         || die "automake: installation error: cannot open \`$file'\n";
6977     # Looks stupid?
6978     # print "automake: reading $file\n" if $verbose;
6980     # Swallow into $CONTENTS the whole content of the file, after
6981     # having performed the $COMMAND, and removed Automake comments.
6982     local ($contents) = '';
6984     while (<FC_FILE>)
6985     {
6986         $_ =~ s/\@MAINTAINER_MODE_TRUE\@//g
6987             unless $seen_maint_mode;
6989         $had_chars = length ($_) && $_ ne "\n";
6990         eval $command;
6991         # If the transform caused all the characters to go away, then
6992         # ignore the line.  Why do this?  Because in Perl 4, a "next"
6993         # inside of an eval doesn't affect a loop outside the eval.
6994         # So we can't pass in a "transform" that uses next.  We used
6995         # to do this.  "Empty" also means consisting of a single
6996         # newline.
6997         next if $had_chars && ($_ eq '' || $_ eq "\n");
6999         # Merely delete comments beginning with two hashes.
7000         next if /$IGNORE_PATTERN/o;
7002         $contents .= $_;
7003     }
7005     close (FC_FILE);
7007     # We don't need more than two consecutive new-lines.
7008     $contents =~ s/\n{3,}/\n\n/g;
7010     # A rule has three parts: a list of targets, a list of dependencies,
7011     # and optionally actions.
7012     my $RULE_PATTERN =
7013       "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
7016     # Process each Make `paragraph'.
7017     #
7018     # A Make `paragraph' is delimited by a new line which is not
7019     # escaped, and not followed by a tab or a comment.
7020     #
7021     # Frankly, unless you like fighting with Perl (you're a freak!),
7022     # if I were you I would not try some other implementation, it's
7023     # very easy falling either into extremely low RE matching
7024     # (backtracking...), or worse yet: infloop...  For instance, (my)
7025     # perl goes loopy if you try to
7026     #
7027     #  $result_rules =~ /^($TARGET_PATTERN *)+: ($TARGET_PATTERN *)+\n\n/sm
7028     local ($result_vars) = '';
7029     local ($result_rules) = '';
7030     local ($comment) = '';
7031     foreach (split (/(?<!\\)\n(?![\t#])/, $contents))
7032     {
7033         &am_file_error ("$basename.am",
7034                         "blank line following trailing backslash:\n$_")
7035           if /\\$/;
7036         &am_file_error ("$basename.am",
7037                         "comment following trailing backslash:\n$_")
7038           if /\\#/;
7040         if (/^$/)
7041         {
7042             # Stick empty line before the incoming macro or rule.
7043             $separator = "\n";
7044         }
7045         elsif (/$COMMENT_PATTERN/mso)
7046         {
7047             # Stick comments before the incoming macro or rule.
7048             $comment = $_;
7049         }
7050         elsif (/$RULE_PATTERN/mso)
7051         {
7052           # Separate relationship from optional actions: the first
7053           # `new-line tab" not preceded by backslash (continuation
7054           # line).
7055           # I'm quite shoked!  It seems that (\\\n|[^\n]) is not the
7056           # same as `([^\n]|\\\n)!!!  Don't swap it, it breaks.
7057           my ($relationship, $actions) =
7058             /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
7060           # Separate targets from dependencies: the first colon.
7061           $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
7062           my ($targets, $dependencies) = ($1, $2);
7063           # Remove the escaped new lines.
7064           # I don't know why, but I have to use a tmp $flat_deps.
7065           my $flat_deps = &flatten ($dependencies);
7066           my @deps = split (' ', $flat_deps);
7068           foreach (split (' ' , $targets))
7069             {
7070               if (defined $dependencies{$_})
7071                 {
7072                   &depend ($_, @deps);
7073                   $actions{$_} .= $actions;
7074                 }
7075               else
7076                 {
7077                   # Free lance dependency.  Output the rule for all the
7078                   # targets instead of one by one.
7079                   if (!defined $contents{$targets})
7080                     {
7081                       # Some hair to avoid spurious trailing blank
7082                       # when there are no dependencies.
7083                       $result_rules .= "$comment$separator";
7084                       $result_rules .= "$targets:";
7085                       $result_rules .= " $dependencies"
7086                         if $dependencies;
7087                       $result_rules .= "\n$actions\n";
7088                     }
7089                   $comment = $separator = '';
7090                   last;
7091                 }
7092             }
7093         }
7094         elsif (/$RULE_PATTERN/mso)
7095         {
7096             $result_rules .= "$comment$separator$_\n"
7097               unless defined $contents{$1};
7098             $comment = $separator = '';
7099         }
7100         elsif (/$MACRO_PATTERN/mso)
7101         {
7102             $result_vars .= "$comment$separator$_\n"
7103               unless defined $contents{$1};
7104             $comment = $separator = '';
7105             &prog_error (".am macro \`$1' with trailing backslash at $file:$.")
7106               if /\\$/;;
7107             $am_var_defs{$1} = $3;
7108         }
7109         else
7110         {
7111             # This isn't an error; it is probably some tokens which
7112             # configure is supposed to replace, such as `@SET-MAKE@'.
7113             $result_rules .= "$comment$separator$_\n";
7114             $comment = $separator = '';
7115         }
7116     }
7118     return $result_vars . $result_rules . $comment;
7122 # &transform (%PAIRS)
7123 # -------------------
7124 # Create a replacement expression suitable for file_contents
7125 # to replace each key of %PAIRS by its value.
7126 sub transform
7128     local (%pairs) = @_;
7129     local ($result) = '';
7131     local ($quoted);
7132     foreach $pattern (sort keys %pairs)
7133     {
7134         ($quoted = $pairs{$pattern}) =~ s/(\W)/\\$1/g;
7135         $result .= 's,\@' . $pattern . '\@,' . $quoted . ',g;';
7136     }
7137     return $result;
7140 # Find all variable prefixes that are used for install directories.  A
7141 # prefix `zar' qualifies iff:
7142 # * `zardir' is a variable.
7143 # * `zar_PRIMARY' is a variable.
7144 sub am_primary_prefixes
7146     local ($primary, $can_dist, @prefixes) = @_;
7148     local (%valid, $varname);
7149     grep ($valid{$_} = 0, @prefixes);
7150     $valid{'EXTRA'} = 0;
7151     foreach $varname (keys %contents)
7152     {
7153         if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
7154         {
7155             if (($2 ne '' && ! $can_dist)
7156                 || (! defined $valid{$3} && ! &variable_defined ($3 . 'dir')))
7157             {
7158                 # Note that a configure variable is always legitimate.
7159                 # It is natural to name such variables after the
7160                 # primary, so we explicitly allow it.
7161                 if (! defined $configure_vars{$varname})
7162                 {
7163                     &am_line_error ($varname, "invalid variable \`$varname'");
7164                 }
7165             }
7166             else
7167             {
7168                 # Ensure all extended prefixes are actually used.
7169                 $valid{$1 . $2 . $3} = 1;
7170             }
7171         }
7172     }
7174     return %valid;
7177 # Handle `where_HOW' variable magic.  Does all lookups, generates
7178 # install code, and possibly generates code to define the primary
7179 # variable.  The first argument is the name of the .am file to munge,
7180 # the second argument is the primary variable (eg HEADERS), and all
7181 # subsequent arguments are possible installation locations.  Returns
7182 # list of all values of all _HOW targets.
7184 # FIXME: this should be rewritten to be cleaner.  It should be broken
7185 # up into multiple functions.
7187 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7188 sub am_install_var
7190     local (@args) = @_;
7192     local ($do_clean) = 0;
7193     local ($do_require) = 1;
7194     local ($can_dist) = 0;
7195     local ($default_dist) = 0;
7197     local ($ltxform);
7198     if (defined $configure_vars{'LIBTOOL'})
7199     {
7200         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
7201         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
7202     }
7203     else
7204     {
7205         # Delete '@LIBTOOL ...@'
7206         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
7207     }
7209     local ($cygxform);
7210     if (! $seen_exeext)
7211     {
7212         $cygxform = 's/\@EXEEXT\@//g;';
7213     }
7214     else
7215     {
7216         $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
7217     }
7219     while (@args)
7220     {
7221         if ($args[0] eq '-clean')
7222         {
7223             $do_clean = 1;
7224         }
7225         elsif ($args[0] eq '-noextra')
7226         {
7227             $do_require = 0;
7228         }
7229         elsif ($args[0] eq '-candist')
7230         {
7231             $can_dist = 1;
7232         }
7233         elsif ($args[0] eq '-defaultdist')
7234         {
7235             $default_dist = 1;
7236             $can_dist = 1;
7237         }
7238         elsif ($args[0] !~ /^-/)
7239         {
7240             last;
7241         }
7242         shift (@args);
7243     }
7245     local ($file, $primary, @prefixes) = @args;
7247     local (@used) = ();
7248     local (@result) = ();
7250     # Now that configure substitutions are allowed in where_HOW
7251     # variables, it is an error to actually define the primary.  We
7252     # allow `JAVA', as it is customarily used to mean the Java
7253     # interpreter.  This is but one of several Java hacks.  Similarly,
7254     # `PYTHON' is customarily used to mean the Python interpreter.
7255     &am_line_error ($primary, "\`$primary' is an anachronism")
7256         if &variable_defined ($primary)
7257             && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7260     # Look for misspellings.  It is an error to have a variable ending
7261     # in a "reserved" suffix whose prefix is unknown, eg
7262     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
7263     # variable of the same name (with "dir" appended) exists.  For
7264     # instance, if the variable "zardir" is defined, then
7265     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
7266     # flexibility in those cases which need it.
7267     local (%valid) = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7269     # If a primary includes a configure substitution, then the EXTRA_
7270     # form is required.  Otherwise we can't properly do our job.
7271     local ($require_extra);
7272     local ($warned_about_extra) = 0;
7274     local ($clean_file) = $file . '-clean';
7275     local ($one_name);
7276     local ($X);
7277     local ($nodir_name);
7278     local ($strip_subdir) = 1;
7279     foreach $X (sort keys %valid)
7280     {
7281         $one_name = $X . '_' . $primary;
7282         if (&variable_defined ($one_name))
7283         {
7284             # If subdir prefix should be preserved, do so.
7285             if ($X =~ /^nobase_/)
7286             {
7287                 $strip_subdir = 0;
7288                 $X =~ s/^nobase_//;
7289             }
7291             # If files should be distributed, do so.
7292             if ($can_dist)
7293             {
7294                 if (($default_dist && $one_name !~ /^nodist_/)
7295                     || (! $default_dist && $one_name =~ /^dist_/))
7296                 {
7297                     &push_dist_common ('$(' . $one_name . ')');
7298                 }
7299                 ($nodir_name = $X) =~ s/^(dist|nodist)_//;
7300             }
7301             else
7302             {
7303                 $nodir_name = $X;
7304             }
7306             # Append actual contents of where_PRIMARY variable to
7307             # result.
7308             local ($rcurs);
7309             foreach $rcurs (&variable_value_as_list ($one_name, 'all'))
7310             {
7311                 # Skip configure substitutions.  Possibly bogus.
7312                 if ($rcurs =~ /^\@.*\@$/)
7313                 {
7314                     if ($X eq 'EXTRA')
7315                     {
7316                         if (! $warned_about_extra)
7317                         {
7318                             $warned_about_extra = 1;
7319                             {
7320                                 &am_line_error ($one_name,
7321                                                 "\`$one_name' contains configure substitution, but shouldn't");
7322                             }
7323                         }
7324                     }
7325                     # Check here to make sure variables defined in
7326                     # configure.ac do not imply that EXTRA_PRIMARY
7327                     # must be defined.
7328                     elsif (! defined $configure_vars{$one_name})
7329                     {
7330                         $require_extra = $one_name
7331                             if $do_require;
7332                     }
7334                     next;
7335                 }
7337                 push (@result, $rcurs);
7338             }
7340             # A blatant hack: we rewrite each _PROGRAMS primary to
7341             # include EXEEXT when in Cygwin32 mode.
7342             if ($seen_exeext && $primary eq 'PROGRAMS')
7343             {
7344                 local (@conds) = &variable_conditions ($one_name);
7345                 local (@one_binlist);
7347                 # FIXME: this definitely loses aesthetically; it
7348                 # redefines $ONE_NAME.  Instead we should arrange for
7349                 # variable definitions to be output later, instead of
7350                 # at scan time.
7352                 if (! @conds)
7353                 {
7354                     @one_binlist = ();
7355                     foreach $rcurs (&variable_value_as_list ($one_name, ''))
7356                     {
7357                         if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7358                         {
7359                             push (@one_binlist, $rcurs);
7360                         }
7361                         else
7362                         {
7363                             push (@one_binlist, $rcurs . '$(EXEEXT)');
7364                         }
7365                     }
7367                     delete $contents{$one_name};
7368                     &define_pretty_variable ($one_name, '', @one_binlist);
7369                 }
7370                 else
7371                 {
7372                     local ($cond);
7373                     local ($condvals) = '';
7374                     foreach $cond (@conds)
7375                     {
7376                         @one_binlist = ();
7377                         local (@condval) = &variable_value_as_list ($one_name,
7378                                                                     $cond);
7379                         foreach $rcurs (@condval)
7380                         {
7381                             if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7382                             {
7383                                 push (@one_binlist, $rcurs);
7384                             }
7385                             else
7386                             {
7387                                 push (@one_binlist, $rcurs . '$(EXEEXT)');
7388                             }
7389                         }
7391                         push (@condvals, $cond);
7392                         push (@condvals, join (' ', @one_binlist));
7393                     }
7395                     delete $contents{$one_name};
7397                     while (@condvals)
7398                     {
7399                         $cond = shift (@condvals);
7400                         local (@val) = split (' ', shift (@condvals));
7401                         &define_pretty_variable ($one_name, $cond, @val);
7402                     }
7403                 }
7404             }
7406             # "EXTRA" shouldn't be used when generating clean targets,
7407             # all, or install targets.
7408             if ($X eq 'EXTRA')
7409             {
7410                 # We used to warn if EXTRA_FOO was defined uselessly,
7411                 # but this was annoying.
7412                 next;
7413             }
7415             if ($do_clean)
7416             {
7417                 $output_rules .=
7418                   &file_contents ($clean_file,
7419                                   &transform ('DIR' => $X)
7420                                   . $cygxform);
7422                 &depend ('mostlyclean-am', 'mostlyclean-' . $X . $primary);
7423                 &depend ('.PHONY', 'mostlyclean-' . $X . $primary);
7424                 &depend ('clean-am', 'clean-' . $X . $primary);
7425                 &depend ('.PHONY', 'clean-' . $X . $primary);
7426                 &depend ('distclean-am', 'distclean-' . $X . $primary);
7427                 &depend ('.PHONY', 'distclean-' . $X . $primary);
7428                 &depend ('maintainer-clean-am', 'maintainer-clean-' . $X . $primary);
7429                 &depend ('.PHONY', 'maintainer-clean-' . $X . $primary);
7430             }
7432             if ($X eq 'check')
7433             {
7434                 push (@check, '$(' . $one_name . ')');
7435             }
7436             else
7437             {
7438                 push (@used, '$(' . $one_name . ')');
7439             }
7440             if ($X eq 'noinst' || $X eq 'check')
7441             {
7442                 # Objects which don't get installed by default.
7443                 next;
7444             }
7446             local ($subdir_xform);
7447             if ($strip_subdir)
7448             {
7449                 $subdir_xform = 's/^NOBASE.*$//; s/^BASE//;';
7450             }
7451             else
7452             {
7453                 $subdir_xform = 's/^BASE.*$//; s/^NOBASE//;';
7454             }
7456             $output_rules .=
7457               &file_contents ($file,
7458                               &transform ('DIR'  => $X,
7459                                           'NDIR' => $nodir_name)
7460                               . $ltxform
7461                               . $cygxform
7462                               . $subdir_xform);
7464             push (@uninstall, 'uninstall-' . $X . $primary);
7465             &depend ('.PHONY', 'uninstall-' . $X . $primary);
7466             push (@installdirs, '$(DESTDIR)$(' . $X . 'dir)');
7467             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
7468             {
7469                 push (@install_exec, 'install-' . $X . $primary);
7470                 &depend ('.PHONY', 'install-' . $X . $primary);
7471             }
7472             else
7473             {
7474                 push (@install_data, 'install-' . $X . $primary);
7475                 &depend ('.PHONY', 'install-' . $X . $primary);
7476             }
7477         }
7478     }
7480     # The JAVA variable is used as the name of the Java interpreter.
7481     # The PYTHON variable is used as the name of the Python interpreter.
7482     if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7483     {
7484         # Define it.
7485         &define_pretty_variable ($primary, '', @used);
7486         $output_vars .= "\n";
7487     }
7489     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7490     {
7491         &am_line_error ($require_extra,
7492                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
7493     }
7495     # Push here because PRIMARY might be configure time determined.
7496     push (@all, '$(' . $primary . ')')
7497         if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7499     # Make the result unique.  This lets the user use conditionals in
7500     # a natural way, but still lets us program lazily -- we don't have
7501     # to worry about handling a particular object more than once.
7502     local (%uniquify) = ();
7503     grep ($uniquify{$_} = 1, @result);
7504     return sort keys %uniquify;
7508 ################################################################
7510 # Each key in this hash is the name of a directory holding a
7511 # Makefile.in.  These variables are local to `is_make_dir'.
7512 %make_dirs = ();
7513 $make_dirs_set = 0;
7515 sub is_make_dir
7517     local ($dir) = @_;
7518     if (! $make_dirs_set)
7519     {
7520         foreach $iter (@configure_input_files)
7521         {
7522             $make_dirs{&dirname ($iter)} = 1;
7523         }
7524         # We also want to notice Makefile.in's.
7525         foreach $iter (@other_input_files)
7526         {
7527             if ($iter =~ /Makefile\.in$/)
7528             {
7529                 $make_dirs{&dirname ($iter)} = 1;
7530             }
7531         }
7532         $make_dirs_set = 1;
7533     }
7534     return defined $make_dirs{$dir};
7537 ################################################################
7539 # This variable is local to the "require file" set of functions.
7540 @require_file_paths = ();
7542 # If a file name appears as a key in this hash, then it has already
7543 # been checked for.  This variable is local to the "require file"
7544 # functions.
7545 %require_file_found = ();
7547 # See if we want to push this file onto dist_common.  This function
7548 # encodes the rules for deciding when to do so.
7549 sub maybe_push_required_file
7551     local ($dir, $file, $fullfile) = @_;
7553     # FIXME: Once again, special-case `.'.
7554     if ($dir eq $relative_dir || $dir eq '.')
7555     {
7556         &push_dist_common ($file);
7557     }
7558     elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7559     {
7560         # If we are doing the topmost directory, and the file is in a
7561         # subdir which does not have a Makefile, then we distribute it
7562         # here.
7563         &push_dist_common ($fullfile);
7564     }
7567 # Verify that the file must exist in the current directory.  Usage:
7568 # require_file (isconfigure, line_number, strictness, file) strictness
7569 # is the strictness level at which this file becomes required.  Must
7570 # set require_file_paths before calling this function.
7571 # require_file_paths is set to hold a single directory (the one in
7572 # which the first file was found) before return.
7573 sub require_file_internal
7575     local ($is_configure, $line, $mystrict, @files) = @_;
7576     local ($file, $fullfile);
7577     local ($found_it, $dangling_sym, $errfile, $errdir);
7578     local ($save_dir);
7580     foreach $file (@files)
7581     {
7582         # If we've already looked for it, we're done.
7583         next if defined $require_file_found{$file};
7584         $require_file_found{$file} = 1;
7586         $found_it = 0;
7587         $dangling_sym = 0;
7588         foreach $dir (@require_file_paths)
7589         {
7590             if ($dir eq '.')
7591             {
7592                 $fullfile = $relative_dir . "/" . $file;
7593                 $errdir = $relative_dir unless $errdir;
7594             }
7595             else
7596             {
7597                 $fullfile = $dir . "/" . $file;
7598                 $errdir = $dir unless $errdir;
7599             }
7601             # Use different name for "error filename".  Otherwise on
7602             # an error the bad file will be reported as eg
7603             # `../../install-sh' when using the default
7604             # config_aux_path.
7605             $errfile = $errdir . '/' . $file;
7607             if (-l $fullfile && ! -f readlink ($fullfile))
7608             {
7609                 $dangling_sym = 1;
7610                 last;
7611             }
7612             elsif (-f $fullfile)
7613             {
7614                 $found_it = 1;
7615                 &maybe_push_required_file ($dir, $file, $fullfile);
7616                 $save_dir = $dir;
7617                 last;
7618             }
7619         }
7621         if ($found_it && ! $force_missing)
7622         {
7623             # Prune the path list.
7624             @require_file_paths = $save_dir;
7625         }
7626         else
7627         {
7628             if ($strictness >= $mystrict)
7629             {
7630                 if ($dangling_sym && ($force_missing || $add_missing))
7631                 {
7632                     unlink ($fullfile);
7633                 }
7635                 local ($trailer) = '';
7636                 local ($suppress) = 0;
7638                 # Only install missing files according to our desired
7639                 # strictness level.
7640                 local ($message) = "required file \`$errfile' not found";
7641                 if ($add_missing)
7642                 {
7643                     $suppress = 1;
7645                     # Maybe run libtoolize.
7646                     local @syslist = ('libtoolize', '--automake');
7647                     push @syslist, '--copy'
7648                         if $copy_missing;
7649                     if ($seen_libtool
7650                         && grep ($_ eq $file, @libtoolize_files)
7651                         && system (@syslist))
7652                     {
7653                         $message = "installing \`$errfile'";
7654                         $suppress = 0;
7655                         $trailer = "; cannot run \`libtoolize': $!";
7656                     }
7657                     elsif (-f ($am_dir . '/' . $file))
7658                     {
7659                         # Install the missing file.  Symlink if we
7660                         # can, copy if we must.  Note: delete the file
7661                         # first, in case it is a dangling symlink.
7662                         $message = "installing \`$errfile'";
7663                         # Windows Perl will hang if we try to delete a
7664                         # file that doesn't exist.
7665                         unlink ($errfile) if -f $errfile;
7666                         if ($symlink_exists && ! $copy_missing)
7667                         {
7668                             if (! symlink ($am_dir . '/' . $file, $errfile))
7669                             {
7670                                 $suppress = 0;
7671                                 $trailer = "; error while making link: $!";
7672                             }
7673                         }
7674                         elsif (system ('cp', $am_dir . '/' . $file, $errfile))
7675                         {
7676                             $suppress = 0;
7677                             $trailer = "\n    error while copying";
7678                         }
7679                     }
7681                     &maybe_push_required_file (&dirname ($errfile),
7682                                                $file, $errfile);
7683                 }
7685                 local ($save) = $exit_status;
7686                 if ($is_configure)
7687                 {
7688                     # FIXME: allow actual file to be specified.
7689                     &am_conf_line_error ($configure_ac, $line,
7690                                          "$message$trailer");
7691                 }
7692                 else
7693                 {
7694                     &am_line_error ($line, "$message$trailer");
7695                 }
7696                 $exit_status = $save if $suppress;
7697             }
7698         }
7699     }
7702 # Like require_file_with_line, but error messages refer to
7703 # configure.ac, not the current Makefile.am.
7704 sub require_file_with_conf_line
7706     @require_file_paths = '.';
7707     &require_file_internal (1, @_);
7710 sub require_file_with_line
7712     @require_file_paths = '.';
7713     &require_file_internal (0, @_);
7716 sub require_file
7718     @require_file_paths = '.';
7719     &require_file_internal (0, '', @_);
7722 # Require a file that is also required by Autoconf.  Looks in
7723 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7724 sub require_config_file
7726     @require_file_paths = @config_aux_path;
7727     &require_file_internal (1, '', @_);
7728     local ($dir) = $require_file_paths[0];
7729     @config_aux_path = @require_file_paths;
7730     if ($dir eq '.')
7731     {
7732         $config_aux_dir = '.';
7733     }
7734     else
7735     {
7736         $config_aux_dir = '$(top_srcdir)/' . $dir;
7737     }
7740 # Assumes that the line number is in Makefile.am.
7741 sub require_conf_file_with_line
7743     @require_file_paths = @config_aux_path;
7744     &require_file_internal (0, @_);
7745     local ($dir) = $require_file_paths[0];
7746     @config_aux_path = @require_file_paths;
7747     if ($dir eq '.')
7748     {
7749         $config_aux_dir = '.';
7750     }
7751     else
7752     {
7753         $config_aux_dir = '$(top_srcdir)/' . $dir;
7754     }
7757 # Assumes that the line number is in configure.ac.
7758 sub require_conf_file_with_conf_line
7760     @require_file_paths = @config_aux_path;
7761     &require_file_internal (1, @_);
7762     local ($dir) = $require_file_paths[0];
7763     @config_aux_path = @require_file_paths;
7764     if ($dir eq '.')
7765     {
7766         $config_aux_dir = '.';
7767     }
7768     else
7769     {
7770         $config_aux_dir = '$(top_srcdir)/' . $dir;
7771     }
7774 ################################################################
7776 # Push a list of files onto dist_common.
7777 sub push_dist_common
7779     local (@files) = @_;
7780     local ($file);
7782     foreach $file (@files)
7783     {
7784         if (! defined $dist_common{$file})
7785         {
7786             &prog_error ("push_dist_common run after handle_dist")
7787                 if $handle_dist_run;
7788             $dist_common{$file} = 1;
7789         }
7790     }
7794 # Set strictness.
7795 sub set_strictness
7797     $strictness_name = $_[0];
7798     if ($strictness_name eq 'gnu')
7799     {
7800         $strictness = $GNU;
7801     }
7802     elsif ($strictness_name eq 'gnits')
7803     {
7804         $strictness = $GNITS;
7805     }
7806     elsif ($strictness_name eq 'foreign')
7807     {
7808         $strictness = $FOREIGN;
7809     }
7810     else
7811     {
7812         die "automake: level \`$strictness_name' not recognized\n";
7813     }
7817 ################################################################
7819 # Return directory name of file.
7820 sub dirname
7822     local ($file) = @_;
7823     local ($sub);
7825     ($sub = $file) =~ s,/+[^/]+$,,g;
7826     $sub = '.' if $sub eq $file;
7827     return $sub;
7830 # Return file name of a file.
7831 sub basename
7833     local ($file) = @_;
7834     local ($sub);
7836     ($sub = $file) =~s,^.*/+,,g;
7837     return $sub;
7840 # Ensure a file exists.
7841 sub create
7843     local ($file) = @_;
7845     open (TOUCH, ">> $file");
7846     close (TOUCH);
7849 # Glob something.  Do this to avoid indentation screwups everywhere we
7850 # want to glob.  Gross!
7851 sub my_glob
7853     local ($pat) = @_;
7854     return <${pat}>;
7857 ################################################################
7859 # Print an error message and set exit status.
7860 sub am_error
7862     warn "automake: ${am_file}.am: @_\n";
7863     $exit_status = 1;
7867 # am_file_error ($FILE, @ARGS)
7868 # ----------------------------
7869 sub am_file_error
7871     my ($file, @args) = @_;
7873     warn "$file: @args\n";
7874     $exit_status = 1;
7877 sub am_line_error
7879     local ($symbol, @args) = @_;
7881     if ($symbol && "$symbol" ne '-1')
7882     {
7883         local ($file) = "${am_file}.am";
7885         if ($symbol =~ /^\d+$/)
7886         {
7887             # SYMBOL is a line number, so just add the colon.
7888             $file .= ':' . $symbol;
7889         }
7890         elsif (defined $content_lines{$symbol})
7891         {
7892             # SYMBOL is a variable defined in Makefile.am, so add the
7893             # line number we saved from there.
7894             $file .= ':' . $content_lines{$symbol};
7895         }
7896         elsif (defined $configure_vars{$symbol})
7897         {
7898             # SYMBOL is a variable defined in configure.ac, so add the
7899             # appropriate line number.
7900             $file = $configure_vars{$symbol};
7901         }
7902         else
7903         {
7904             # Couldn't find the line number.
7905         }
7906         warn $file, ": @args\n";
7907         $exit_status = 1;
7908     }
7909     else
7910     {
7911         &am_error (@args);
7912     }
7915 # Like am_error, but while scanning configure.ac.
7916 sub am_conf_error
7918     # FIXME: can run in subdirs.
7919     warn "automake: $configure_ac: @_\n";
7920     $exit_status = 1;
7923 # Error message with line number referring to configure.ac.
7924 sub am_conf_line_error
7926     local ($file, $line, @args) = @_;
7928     if ($line)
7929     {
7930         warn "$file: $line: @args\n";
7931         $exit_status = 1;
7932     }
7933     else
7934     {
7935         &am_conf_error (@args);
7936     }
7939 # Warning message with line number referring to configure.ac.
7940 # Does not affect exit_status
7941 sub am_conf_line_warning
7943     local ($saved_exit_status) = $exit_status;
7944     &am_conf_line_error (@_);
7945     $exit_status = $saved_exit_status;
7948 # Tell user where our aclocal.m4 is, but only once.
7949 sub keyed_aclocal_warning
7951     local ($key) = @_;
7952     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
7955 # Print usage information.
7956 sub usage
7958     print "Usage: automake [OPTION] ... [Makefile]...\n\n";
7959     print "Generate Makefile.in for autoconf from Makefile.am\n";
7960     print $USAGE;
7961     print "\nFiles which are automatically distributed, if found:\n";
7962     $~ = "USAGE_FORMAT";
7963     local ($last, $iter, @lcomm);
7964     $last = '';
7965     foreach $iter (sort ((@common_files, @common_sometimes)))
7966     {
7967         push (@lcomm, $iter) unless $iter eq $last;
7968         $last = $iter;
7969     }
7971     local ($one, $two, $three, $four, $i, $max);
7972     $max = int (($#lcomm + 1) / 4);
7974     for ($i = 0; $i < $max; ++$i)
7975     {
7976         $one = $lcomm[$i];
7977         $two = $lcomm[$max + $i];
7978         $three = $lcomm[2 * $max + $i];
7979         $four = $lcomm[3 * $max + $i];
7980         write;
7981     }
7983     local ($mod) = ($#lcomm + 1) % 4;
7984     if ($mod != 0)
7985     {
7986         $one = $lcomm[$max];
7987         $two = ($mod > 1) ? $lcomm[2 * $max] : '';
7988         $three = ($mod > 2) ? $lcomm[3 * $max] : '';
7989         $four = ($mod > 3) ? $lcomm[4 * $max] : '';
7990         write;
7991     }
7993     print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7995     exit 0;
7998 format USAGE_FORMAT =
7999   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
8000   $one,               $two,               $three,             $four