* automake.in (libtoolize_files): Removed ltconfig.
[automake.git] / automake.in
blobdd6be09d31848d5f4fb3988de444231132f690ac
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
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>.
31 # Parameters set by configure.  Not to be changed.  NOTE: assign
32 # VERSION as string so that eg version 0.30 will print correctly.
33 $VERSION = "@VERSION@";
34 $PACKAGE = "@PACKAGE@";
35 $prefix = "@prefix@";
36 $am_dir = "@datadir@/@PACKAGE@";
38 # String constants.
39 $IGNORE_PATTERN = "^##([^#].*)?\$";
40 $WHITE_PATTERN = "^[ \t]*\$";
41 $COMMENT_PATTERN = "^#";
42 $RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/\$]*) *:([^=].*|)\$";
43 $SUFFIX_RULE_PATTERN = "^\\.([a-zA-Z0-9]+)\\.([a-zA-Z0-9]+)\$";
44 # Only recognize leading spaces, not leading tabs.  If we recognize
45 # leading tabs here then we need to make the reader smarter, because
46 # otherwise it will think rules like `foo=bar; \' are errors.
47 $MACRO_PATTERN = "^ *([A-Za-z0-9_]+)[ \t]*([:+]?)=[ \t]*(.*)\$";
48 $BOGUS_MACRO_PATTERN = "^ *([^ \t]*)[ \t]*([:+]?)=[ \t]*(.*)\$";
49 $GNITS_VERSION_PATTERN = "[0-9]+\\.[0-9]+([a-z]|\\.[0-9]+)?";
50 $IF_PATTERN = "^if[ \t]+\([A-Za-z][A-Za-z0-9_]*\)[ \t]*\(#.*\)?\$";
51 $ELSE_PATTERN = "^else[ \t]*\(#.*\)?\$";
52 $ENDIF_PATTERN = "^endif[ \t]*\(#.*\)?\$";
53 $PATH_PATTERN='(\\w|[/.-])+';
54 # This will pass through anything not of the prescribed form.
55 $INCLUDE_PATTERN = "^include[ \t]+((\\\$\\\(top_srcdir\\\)/${PATH_PATTERN})|(\\\$\\\(srcdir\\\)/${PATH_PATTERN})|([^/\\\$]${PATH_PATTERN}))[ \t]*(#.*)?\$";
57 # Some regular expressions.  One reason to put them here is that it
58 # makes indentation work better in Emacs.
59 $AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
60 $AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^,)]+)[,)]";
61 $AM_PACKAGE_VERSION_PATTERN = "^\\s*\\[?([^]\\s]+)\\]?\\s*\$";
62 # Note that there is no AC_PATH_TOOL.  But we don't really care.
63 $AC_CHECK_PATTERN = "AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\\(\\[?(\\w+)";
64 $AM_MISSING_PATTERN = "AM_MISSING_PROG\\(\\[?(\\w+)";
65 # Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
66 # then too bad.
67 $AC_SUBST_PATTERN = "AC_SUBST\\(\\[?(\\w+)";
68 $AM_CONDITIONAL_PATTERN = "AM_CONDITIONAL\\((\\w+)";
70 # Constants to define the "strictness" level.
71 $FOREIGN = 0;
72 $GNU = 1;
73 $GNITS = 2;
75 # These constants are returned by lang_*_rewrite functions.
76 # LANG_SUBDIR means that the resulting object file should be in a
77 # subdir if the source file is.  In this case the file name cannot
78 # have `..' components.
79 $LANG_IGNORE = 0;
80 $LANG_PROCESS = 1;
81 $LANG_SUBDIR = 2;
85 # Variables global to entire run.
87 # TRUE if we should always generate Makefile.in.
88 $force_generation = 1;
90 # Strictness level as set on command line.
91 $default_strictness = $GNU;
93 # Name of strictness level, as set on command line.
94 $default_strictness_name = 'gnu';
96 # This is TRUE if automatic dependency generation code should be
97 # included in generated Makefile.in.
98 $cmdline_use_dependencies = 1;
100 # TRUE if in verbose mode.
101 $verbose = 0;
103 # This holds our (eventual) exit status.  We don't actually exit until
104 # we have processed all input files.
105 $exit_status = 0;
107 # From the Perl manual.
108 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
110 # TRUE if missing standard files should be installed.
111 $add_missing = 0;
113 # TRUE if we should copy missing files; otherwise symlink if possible.
114 $copy_missing = 0;
116 # TRUE if we should always update files that we know about.
117 $force_missing = 0;
119 # Files found by scanning configure.in for LIBOBJS.
120 %libsources = ();
122 # True if AM_C_PROTOTYPES appears in configure.in.
123 $am_c_prototypes = 0;
125 # Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
126 # name which appears in AC_CONFIG_HEADER, colon and all.
127 # @config_names holds the file names.  @config_headers holds the '.in'
128 # files.  Ordinarily these are similar, but they can be different if
129 # the weird "NAME:FILE" syntax is used.
130 @config_fullnames = ();
131 @config_names = ();
132 @config_headers = ();
133 # Line number at which AC_CONFIG_HEADER appears in configure.in.
134 $config_header_line = 0;
136 # Directory where output files go.  Actually, output files are
137 # relative to this directory.
138 $output_directory = '.';
140 # Relative location of top build directory.
141 $top_builddir = '';
143 # List of Makefile.am's to process, and their corresponding outputs.
144 @input_files = ();
145 %output_files = ();
147 # Complete list of Makefile.am's that exist.
148 @configure_input_files = ();
150 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
151 @other_input_files = ();
152 # Line number at which AC_OUTPUT seen.
153 $ac_output_line = 0;
155 # List of directories to search for configure-required files.  This
156 # can be set by AC_CONFIG_AUX_DIR.
157 @config_aux_path = ('.', '..', '../..');
158 $config_aux_dir = '';
160 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
161 $seen_make_set = 0;
163 # Whether AM_GNU_GETTEXT has been seen in configure.in.
164 $seen_gettext = 0;
165 # Line number at which AM_GNU_GETTEXT seen.
166 $ac_gettext_line = 0;
168 # Whether ALL_LINGUAS has been seen.
169 $seen_linguas = '';
170 # The actual text.
171 $all_linguas = '';
172 # Line number at which it appears.
173 $all_linguas_line = 0;
175 # 1 if AC_PROG_INSTALL seen.
176 $seen_prog_install = 0;
178 # Whether AC_PATH_XTRA has been seen in configure.in.
179 $seen_path_xtra = 0;
181 # TRUE if AC_DECL_YYTEXT was seen.
182 $seen_decl_yytext = 0;
184 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
185 # AC_CHECK_TOOL also sets this.
186 $seen_canonical = 0;
188 # TRUE if we've seen AC_ARG_PROGRAM.
189 $seen_arg_prog = 0;
191 # TRUE if we've seen AC_PROG_LIBTOOL.
192 $seen_libtool = 0;
193 $libtool_line = 0;
195 # Files installed by libtoolize.
196 @libtoolize_files = ('ltmain.sh', 'config.guess', 'config.sub');
198 # TRUE if we've seen AM_MAINTAINER_MODE.
199 $seen_maint_mode = 0;
201 # Actual version we've seen.
202 $package_version = '';
204 # Line number where we saw version definition.
205 $package_version_line = 0;
207 # TRUE if we've seen AM_PATH_LISPDIR.
208 $seen_lispdir = 0;
210 # TRUE if we've seen AM_CHECK_PYTHON.
211 $seen_pythondir = 0;
213 # TRUE if we've seen AC_EXEEXT.
214 $seen_exeext = 0;
216 # TRUE if we've seen AC_OBJEXT.
217 $seen_objext = 0;
219 # TRUE if we've seen AC_ENABLE_MULTILIB.
220 $seen_multilib = 0;
222 # TRUE if we've seen AM_PROG_CC_C_O
223 $seen_cc_c_o = 0;
225 # TRUE if we've seen AM_INIT_AUTOMAKE.
226 $seen_init_automake = 0;
228 # Hash table of discovered configure substitutions.  Keys are names,
229 # values are `FILE:LINE' strings which are used by error message
230 # generation.
231 %configure_vars = ();
233 # This is used to keep track of which variable definitions we are
234 # scanning.  It is only used in certain limited ways, but it has to be
235 # global.  It is declared just for documentation purposes.
236 %vars_scanned = ();
238 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
239 # handled in a funny way: if seen in the top-level Makefile.am, it is
240 # used for every directory which does not specify a different value.
241 # The rationale here is that some directories (eg gettext) might be
242 # distributions of other packages, and thus require their own charset
243 # info.  However, the DIST_CHARSET must be the same for the entire
244 # package; it can only be set at top-level.
245 # FIXME: this yields bugs when rebuilding.  What to do?  Always
246 # read (and sometimes discard) top-level Makefile.am?
247 $maint_charset = '';
248 $dist_charset = 'utf8';         # recode doesn't support this yet.
250 # Name of input file ("Makefile.in") and output file ("Makefile.am").
251 # These have no directory components.
252 $am_file_name = '';
253 $in_file_name = '';
255 # TRUE if --cygnus seen.
256 $cygnus_mode = 0;
258 # Hash table of AM_CONDITIONAL variables seen in configure.
259 %configure_cond = ();
261 # Map from obsolete macros to hints for new macros.
262 # If you change this, change the corresponding list in aclocal.in.
263 # FIXME: should just put this into a single file.
264 %obsolete_macros =
265     (
266      'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
267      'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
268      'AC_FEATURE_EXIT', '',
269      'AC_SYSTEM_HEADER', '',
271      # Note that we do not handle this one, because it is still run
272      # from AM_CONFIG_HEADER.  So we deal with it specially in
273      # scan_configure.
274      # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",
276      'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
277      'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
278      'fp_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
279      'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
280      'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
281      'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
282      'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
283      'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
284      'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",
285      'ud_GNU_GETTEXT', "use \`AM_GNU_GETTEXT'",
287      # Now part of autoconf proper, under a different name.
288      'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
289      'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
290      'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",
291      'AM_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
292      'AM_EXEEXT', "use \`AC_EXEEXT'",
293      'AM_CYGWIN32', "use \`AC_CYGWIN'",
294      'AM_MINGW32', "use \`AC_MINGW32'",
295      'AM_FUNC_MKTIME', "use \`AC_FUNC_MKTIME'",
297 # These aren't quite obsolete.
298 #      'md_PATH_PROG',
299      );
301 # Regexp to match the above macros.
302 $obsolete_rx = '(' . join ('|', keys %obsolete_macros) . ')';
304 # This maps extensions onto language names.
305 %extension_map = ();
307 # This maps languages names onto properties.
308 %language_map = ();
310 # This holds all the files that would go in `dist_common' which we
311 # discovered while scanning configure.in.  We might distribute these
312 # in the top-level Makefile.in.
313 %configure_dist_common = ();
317 # Initialize global constants and our list of languages that are
318 # internally supported.
319 &initialize_global_constants;
321 &register_language ('c', 'ansi-p=1', 'autodep=', 'flags=CFLAGS',
322                     'compile=$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
323                     'compiler-name=COMPILE',
324                     'output-arg=-c',
325                     'c');
326 &register_language ('cxx', 'linker=CXXLINK', 'autodep=CXX', 'flags=CXXFLAGS',
327                     'compile=$(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
328                     'compiler-name=CXXCOMPILE',
329                     'output-arg=-c -o $@',
330                     'c++', 'cc', 'cpp', 'cxx', 'C');
331 &register_language ('objc', 'linker=OBJCLINK', 'autodep=OBJC',
332                     'flags=OBJCFLAGS',
333                     'compile=$(OBJC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
334                     'compiler-name=OBJCCOMPILE',
335                     'output-arg=-c -o $@',
336                     'm');
337 &register_language ('header',
338                     'h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc');
340 # For now, yacc and lex can't be handled on a per-exe basis.
341 &register_language ('yacc', 'ansi-p=1', 'derived-autodep=yes',
342                     'y');
343 &register_language ('yaccxx', 'linker=CXXLINK', 'derived-autodep=yes',
344                     'y++', 'yy', 'yxx', 'ypp');
345 &register_language ('lex', 'ansi-p=1', 'derived-autodep=yes',
346                     'l');
347 &register_language ('lexxx', 'linker=CXXLINK', 'derived-autodep=yes',
348                     'l++', 'll', 'lxx', 'lpp');
350 &register_language ('asm',
351                     'flags=CFLAGS', # FIXME: asmflags?
352                     'compile=$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)', # FIXME: a different compiler?
353                     'compiler-name=COMPILE',
354                     'output-arg=-c',
355                     's', 'S');
357 &register_language ('f77', 'linker=F77LINK', 'flags=FFLAGS',
358                     'compile=$(F77) $(AM_FFLAGS) $(FFLAGS)',
359                     'compiler-name=F77COMPILE',
360                     'output-arg=-c -o $@',
361                     'f', 'for', 'f90');
362 &register_language ('ppf77', 'linker=F77LINK', 'flags=FFLAGS',
363                     'compile=$(F77) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
364                     'compiler-name=PPF77COMPILE',
365                     'output-arg=-c -o $@',
366                     'F');
367 &register_language ('ratfor', 'linker=F77LINK',
368                     'flags=RFLAGS', # FIXME also FFLAGS.
369                     'compile=$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
370                     'compiler-name=RCOMPILE',
371                     'output-arg=-c -o $@',
372                     'r');
373 # FIXME: for now we can't do dependency tracking for Java.
374 # autodep=GCJ
375 &register_language ('java', 'linker=GCJLINK', 'flags=GCJFLAGS',
376                     'compile=$(GCJ) $(DEFS) $(INCLUDES) $(AM_GCJFLAGS) $(GCJFLAGS)',
377                     'compiler-name=GCJCOMPILE',
378                     'output-arg=-c -o $@',
379                     'java', 'class', 'zip', 'jar');
382 # Parse command line.
383 &parse_arguments (@ARGV);
385 # Do configure.in scan only once.
386 &scan_configure;
388 die "automake: no \`Makefile.am' found or specified\n"
389     if ! @input_files;
391 # Now do all the work on each file.
392 foreach $am_file (@input_files)
394     if (! -f ($am_file . '.am'))
395     {
396         &am_error ("\`" . $am_file . ".am' does not exist");
397     }
398     else
399     {
400         &generate_makefile ($output_files{$am_file}, $am_file);
401     }
404 &am_conf_error ("AC_PROG_INSTALL must be used in configure.in")
405     if (! $seen_prog_install);
407 exit $exit_status;
410 ################################################################
412 # Parse command line.
413 sub parse_arguments
415     local (@arglist) = @_;
417     # Start off as gnu.
418     &set_strictness ('gnu');
420     while (@arglist)
421     {
422         if ($arglist[0] eq "--version")
423         {
424             print "automake (GNU $PACKAGE) $VERSION\n\n";
425             print "Copyright 2000 Free Software Foundation, Inc.\n";
426             print "This is free software; see the source for copying conditions.  There is NO\n";
427             print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
428             print "Written by Tom Tromey <tromey\@cygnus.com>\n";
430             exit 0;
431         }
432         elsif ($arglist[0] eq "--help")
433         {
434             &usage;
435         }
436         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
437         {
438             $am_dir = $1;
439         }
440         elsif ($arglist[0] eq '--amdir')
441         {
442             &require_argument (@arglist);
443             shift (@arglist);
444             $am_dir = $arglist[0];
445         }
446         elsif ($arglist[0] eq '--gnu')
447         {
448             &set_strictness ('gnu');
449         }
450         elsif ($arglist[0] eq '--gnits')
451         {
452             &set_strictness ('gnits');
453         }
454         elsif ($arglist[0] eq '--cygnus')
455         {
456             $cygnus_mode = 1;
457         }
458         elsif ($arglist[0] eq '--foreign')
459         {
460             &set_strictness ('foreign');
461         }
462         elsif ($arglist[0] eq '--include-deps')
463         {
464             $cmdline_use_dependencies = 1;
465         }
466         elsif ($arglist[0] eq '--ignore-deps' || $arglist[0] eq '-i')
467         {
468             $cmdline_use_dependencies = 0;
469         }
470         elsif ($arglist[0] eq '--no-force')
471         {
472             $force_generation = 0;
473         }
474         elsif ($arglist[0] eq '--force-missing')
475         {
476             $force_missing = 1;
477         }
478         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
479         {
480             # Set output directory.
481             $output_directory = $1;
482         }
483         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
484         {
485             &require_argument (@arglist);
486             shift (@arglist);
487             $output_directory = $arglist[0];
488         }
489         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
490         {
491             $add_missing = 1;
492         }
493         elsif ($arglist[0] eq '--copy' || $arglist[0] eq '-c')
494         {
495             $copy_missing = 1;
496         }
497         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
498         {
499             $verbose = 1;
500         }
501         elsif ($arglist[0] eq '--')
502         {
503             # Stop option processing.
504             shift (@arglist);
505             push (@input_files, @arglist);
506             last;
507         }
508         elsif ($arglist[0] =~ /^-/)
509         {
510             die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
511         }
512         else
513         {
514             # Handle $local:$input syntax.  Note that we only examine
515             # the first ":" file to see if it is automake input; the
516             # rest are just taken verbatim.  We still keep all the
517             # files around for dependency checking, however.
518             local ($local, $input, @rest) = split (/:/, $arglist[0]);
519             if (! $input)
520             {
521                 $input = $local;
522             }
523             else
524             {
525                 # Strip .in; later on .am is tacked on.  That is how
526                 # the automake input file is found.  Maybe not the
527                 # best way, but it is easy to explain.  FIXME: should
528                 # be error if .in is missing.
529                 $input =~ s/\.in$//;
530             }
531             push (@input_files, $input);
532             $output_files{$input} = join (':', ($local, @rest));
533         }
535         shift (@arglist);
536     }
538     # Take global strictness from whatever we currently have set.
539     $default_strictness = $strictness;
540     $default_strictness_name = $strictness_name;
543 # Ensure argument exists, or die.
544 sub require_argument
546     local ($arg, @arglist) = @_;
547     die "automake: no argument given for option \`$arg'\n"
548         if ! @arglist;
551 ################################################################
553 # Generate a Makefile.in given the name of the corresponding Makefile and
554 # the name of the file output by config.status.
555 sub generate_makefile
557     local ($output, $makefile) = @_;
559     ($am_file_name = $makefile) =~ s/^.*\///;
560     $in_file_name = $am_file_name . '.in';
561     $am_file_name .= '.am';
563     # $OUTPUT is encoded.  If it contains a ":" then the first element
564     # is the real output file, and all remaining elements are input
565     # files.  We don't scan or otherwise deal with these input file,
566     # other than to mark them as dependencies.  See scan_configure for
567     # details.
568     local (@secondary_inputs);
569     ($output, @secondary_inputs) = split (/:/, $output);
571     &initialize_per_input;
572     $relative_dir = &dirname ($output);
573     $am_relative_dir = &dirname ($makefile);
575     # At the toplevel directory, we might need config.guess, config.sub
576     # or libtool scripts (ltconfig and ltmain.sh).
577     if ($relative_dir eq '.')
578     {
579         # libtool requires some files.
580         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
581                                            @libtoolize_files)
582             if $seen_libtool;
584         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
585         # config.sub.
586         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
587             if $seen_canonical;
588     }
590     # We still need Makefile.in here, because sometimes the `dist'
591     # target doesn't re-run automake.
592     if ($am_relative_dir eq $relative_dir)
593     {
594         # Only distribute the files if they are in the same subdir as
595         # the generated makefile.
596         &push_dist_common ($in_file_name, $am_file_name);
597     }
599     push (@sources, '$(SOURCES)')
600         if &variable_defined ('SOURCES');
601     push (@objects, '$(OBJECTS)')
602         if &variable_defined ('OBJECTS');
604     &read_main_am_file ($makefile . '.am');
605     if (&handle_options)
606     {
607         # Fatal error.  Just return, so we can continue with next file.
608         return;
609     }
611     # Must do this after reading .am file.  See read_main_am_file to
612     # understand weird tricks we play there with variables.
613     &define_variable ('subdir', $relative_dir);
615     # Check first, because we might modify some state.
616     &check_cygnus;
617     &check_gnu_standards;
618     &check_gnits_standards;
620     &handle_configure ($output, $makefile, @secondary_inputs);
621     &handle_gettext;
622     &handle_libraries;
623     &handle_ltlibraries;
624     &handle_programs;
625     &handle_scripts;
627     # This must be run after all the sources are scanned.
628     &finish_languages;
630     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
631     # on this (but currently does).
632     $contents{'SOURCES'} = join (' ', @sources);
633     $contents{'OBJECTS'} = join (' ', @objects);
634     &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
636     &handle_multilib;
637     &handle_texinfo;
638     &handle_emacs_lisp;
639     &handle_python;
640     &handle_java;
641     &handle_man_pages;
642     &handle_data;
643     &handle_headers;
644     &handle_subdirs;
645     &handle_tags;
646     &handle_minor_options;
647     &handle_dependencies;
648     &handle_tests;
650     # This must come after most other rules.
651     &handle_dist ($makefile);
653     &handle_footer;
654     &handle_merge_targets ($output);
655     &handle_installdirs;
656     &handle_clean;
657     &handle_phony;
659     &check_typos;
661     if (! -d ($output_directory . '/' . $am_relative_dir))
662     {
663         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
664     }
666     local ($out_file) = $output_directory . '/' . $makefile . ".in";
667     if (! $force_generation && -e $out_file)
668     {
669         local ($am_time) = (stat ($makefile . '.am'))[9];
670         local ($in_time) = (stat ($out_file))[9];
671         # FIXME: should cache these times.
672         local ($conf_time) = (stat ('configure.in'))[9];
673         # FIXME: how to do unsigned comparison?
674         if ($am_time < $in_time || $am_time < $conf_time)
675         {
676             # No need to update.
677             return;
678         }
679         if (-f 'aclocal.m4')
680         {
681             local ($acl_time) = (stat _)[9];
682             return if ($am_time < $acl_time);
683         }
684     }
686     if (! open (GM_FILE, "> " . $out_file))
687     {
688         warn "automake: ${am_file}.in: cannot write: $!\n";
689         $exit_status = 1;
690         return;
691     }
692     print "automake: creating ", $makefile, ".in\n" if $verbose;
694     # In case we're running under MSWindows, don't write with CRLF
695     # (as it causes problems for the dependency-file extraction in
696     # AM_OUTPUT_DEPENDENCY_COMMANDS).
697     binmode GM_FILE;
699     print GM_FILE $output_vars;
700     # We make sure that `all:' is the first target.
701     print GM_FILE $output_all;
702     print GM_FILE $output_header;
703     print GM_FILE $output_rules;
704     print GM_FILE $output_trailer;
706     if (! close (GM_FILE))
707       {
708         warn "automake: $am_file.in: cannot close: $!\n";
709         $exit_status = 1;
710         return;
711       }
714 ################################################################
716 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
717 sub handle_options
719     if (&variable_defined ('AUTOMAKE_OPTIONS'))
720     {
721         foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
722         {
723             $options{$_} = 1;
724             if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
725             {
726                 &set_strictness ($_);
727             }
728             elsif ($_ eq 'cygnus')
729             {
730                 $cygnus_mode = 1;
731             }
732             elsif (/ansi2knr/)
733             {
734                 # An option like "../lib/ansi2knr" is allowed.  With
735                 # no path prefix, we assume the required programs are
736                 # in this directory.  We save the actual option for
737                 # later.
738                 $options{'ansi2knr'} = $_;
739             }
740             elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
741                    || $_ eq 'dist-shar' || $_ eq 'dist-zip'
742                    || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
743                    || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
744                    || $_ eq 'readme-alpha' || $_ eq 'check-news'
745                    || $_ eq 'subdir-objects' || $_ eq 'nostdinc')
746             {
747                 # Explicitly recognize these.
748             }
749             elsif ($_ eq 'no-dependencies')
750             {
751                 $use_dependencies = 0;
752             }
753             elsif (/([0-9]+)\.([0-9]+)([a-z])?/)
754             {
755                 # Got a version number.
757                 local ($rmajor, $rminor, $ralpha) = ($1, $2, $3);
759                 if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
760                 {
761                     print STDERR
762                         "automake: programming error: version is incorrect\n";
763                     exit 1;
764                 }
765                 local ($tmajor, $tminor, $talpha) = ($1, $2, $3);
767                 # 2.0 is better than 1.0.
768                 # 1.2 is better than 1.1.
769                 # 1.2a is better than 1.2.
770                 if ($rmajor > $tmajor
771                     || ($rmajor == $tmajor && $rminor > $tminor)
772                     || ($rminor == $tminor && $rminor == $tminor
773                         && $ralpha gt $talpha))
774                 {
775                     &am_line_error ('AUTOMAKE_OPTIONS',
776                                     "require version $_, only have $VERSION");
777                     return 1;
778                 }
779             }
780             else
781             {
782                 &am_line_error ('AUTOMAKE_OPTIONS',
783                                 "option \`" . $_ . "\' not recognized");
784             }
785         }
786     }
788     if ($strictness == $GNITS)
789     {
790         $options{'readme-alpha'} = 1;
791         $options{'check-news'} = 1;
792     }
794     return 0;
797 # Return object extension.  Just once, put some code into the output.
798 # Argument is the name of the output file
799 sub get_object_extension
801     local ($out) = @_;
803     # Maybe require libtool library object files.
804     local ($extension) = '.o';
805     $extension = '.$(OBJEXT)' if $seen_objext;
806     $extension = '.lo' if ($out =~ /\.la$/);
808     if (! $included_generic_compile)
809     {
810         # Boilerplate.
811         local ($xform) = '';
812         if (! defined $options{'nostdinc'})
813         {
814             $xform = ' -I. -I\$(srcdir)';
816             if (&variable_defined ('CONFIG_HEADER'))
817             {
818                 local ($one_hdr);
819                 foreach $one_hdr (split (' ',
820                                          &variable_value ('CONFIG_HEADER')))
821                 {
822                     local ($var);
823                     ($var = &dirname ($one_hdr)) =~ s/(\W)/\\$1/g;
824                     $xform .= ' -I' . $var;
825                 }
826             }
827         }
828         $xform = 's/\@DEFAULT_INCLUDES\@/' . $xform . '/go;';
829         $output_vars .= &file_contents_with_transform ($xform,
830                                                        'comp-vars');
832         $xform = $seen_objext ? 's/^OBJEXT//;' : 's/^OBJEXT.*$//;';
833         $output_rules .= &file_contents_with_transform ($xform, 'compile');
835         &push_phony_cleaners ('compile');
837         # If using X, include some extra variable definitions.  NOTE
838         # we don't want to force these into CFLAGS or anything,
839         # because not all programs will necessarily use X.
840         if ($seen_path_xtra)
841         {
842             local ($var);
843             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
844             {
845                 &define_configure_variable ($var);
846             }
847         }
849         push (@suffixes, '.c', '.o');
850         push (@suffixes, '.obj') if $seen_objext;
851         push (@clean, 'compile');
853         $included_generic_compile = 1;
854     }
856     if ($seen_libtool && ! $included_libtool_compile)
857     {
858         # Output the libtool compilation rules.
859         $output_rules .= &file_contents ('libtool');
861         &push_phony_cleaners ('libtool');
863         push (@suffixes, '.lo');
864         push (@clean, 'libtool');
866         $included_libtool_compile = 1;
867     }
869     # Check for automatic de-ANSI-fication.
870     if (defined $options{'ansi2knr'})
871     {
872         $extension = '$U' . $extension;
873         if (! $included_knr_compile)
874         {
875             if (! $am_c_prototypes)
876             {
877                 &am_line_error ('AUTOMAKE_OPTIONS',
878                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
879                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
880                 # Only give this error once.
881                 $am_c_prototypes = 1;
882             }
884             # Only require ansi2knr files if they should appear in
885             # this directory.
886             if ($options{'ansi2knr'} eq 'ansi2knr')
887             {
888                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
889                                          'ansi2knr.c', 'ansi2knr.1');
890                 $output_rules .= &file_contents ('kr-extra');
891                 push (@clean, 'krextra');
892                 &push_phony_cleaners ('krextra');
893             }
895             # Generate rules to build ansi2knr.  If it is in some
896             # other directory, then generate dependencies but have the
897             # rule just run elsewhere.
898             $objext = $seen_objext ? ".\$(OBJEXT)" : ".o";
899             $output_rules .= ($options{'ansi2knr'} . ': '
900                               . $options{'ansi2knr'} . $objext . "\n");
901             if ($options{'ansi2knr'} eq 'ansi2knr')
902             {
903                 $output_rules .= ("\t\$(LINK) ansi2knr" . $objext
904                                   . " \$(LIBS)\n"
905                                   . "ansi2knr" . $objext
906                                   . ": \$(CONFIG_HEADER)\n\n");
907             }
908             else
909             {
910                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
911                                   . " && \$(MAKE) \$(AM_MAKEFLAGS) "
912                                   . "ansi2knr\n\n");
913                 # This is required for non-GNU makes.
914                 $output_rules .= ($options{'ansi2knr'} . $objext . ":\n");
915                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
916                                   . " && \$(MAKE) \$(AM_MAKEFLAGS)"
917                                   . " ansi2knr" . $objext . "\n\n");
918             }
920             # Make sure ansi2knr can be found: if no path specified,
921             # specify "./".
922             if ($options{'ansi2knr'} eq 'ansi2knr')
923             {
924                 # Substitution from AM_C_PROTOTYPES.  This makes it be
925                 # built only when necessary.
926                 &define_configure_variable ('ANSI2KNR');
927                 # ansi2knr needs to be built before subdirs, so unshift it.
928                 unshift (@all, '$(ANSI2KNR)');
929             }
930             else
931             {
932                 # Found in another directory.
933                 &define_variable ("ANSI2KNR", $options{'ansi2knr'});
934             }
936             $output_rules .= &file_contents ('clean-kr');
938             push (@clean, 'kr');
939             &push_phony_cleaners ('kr');
941             $included_knr_compile = 1;
942         }
943     }
945     return $extension;
948 # Call finish function for each language that was used.
949 sub finish_languages
951     local ($ltcompile, $ltlink) = &libtool_compiler;
953     local ($ext, $name, $lang, %done);
954     local ($non_c) = 1;
955     foreach $ext (sort keys %extension_seen)
956     {
957         $lang = $extension_map{$ext};
959         # Generate the appropriate rules for this extension.  If
960         # dependency tracking was requested, and this extension
961         # supports it, then we don't generate the rule here.
962         local ($comp) = '';
964         if ($use_dependencies && $language_map{$lang . '-autodep'} ne 'no')
965         {
966             # Don't generate the rule, but still generate the variables.
967             if (defined $language_map{$lang . '-compile'})
968             {
969                 $comp = $language_map{$lang . '-compile'};
970             }
971         }
972         elsif (defined $language_map{$lang . '-compile'})
973         {
974             $comp = $language_map{$lang . '-compile'};
976             local ($outarg) = $language_map{$lang . '-output-arg'};
977             if ($language_map{$lang . '-flags'} eq 'CFLAGS')
978             {
979                 # C compilers don't always support -c -o.
980                 if (defined $options{'subdir-objects'})
981                 {
982                     $outarg .= ' -o $@';
983                 }
984             }
986             local ($full) = ("\t\$("
987                              . $language_map{$lang . '-compiler-name'}
988                              . ") "
989                              . $outarg);
990             $output_rules .= (".$ext.o:\n"
991                               . $full
992                               . " \$<\n");
993             # FIXME: Using cygpath should be somehow conditional.
994             $output_rules .= (".$ext.obj:\n"
995                               . $full
996                               . " \`cygpath -w \$<\`\n")
997                 if $seen_objext;
998             $output_rules .= (".$ext.lo:\n"
999                               . "\t\$(LT"
1000                               . $language_map{$lang . '-compiler-name'}
1001                               . ") "
1002                               . $language_map{$lang . '-output-arg'}
1003                               # We can always use -c -o with libtool.
1004                               . ($language_map{$lang . '-flags'} eq 'CFLAGS'
1005                                  ? ' -o $@' : '')
1006                               . " \$<\n")
1007                 if $seen_libtool;
1008         }
1010         push (@suffixes, '.' . $ext);
1012         # The rest of the loop is done once per language.
1013         next if defined $done{$lang};
1014         $done{$lang} = 1;
1016         $non_c = 0 if $lang !~ /(objc|cxx|f77|ratfor)$/;
1018         if ($comp ne '')
1019         {
1020             &define_compiler_variable ($language_map{$lang . '-compiler-name'},
1021                                        $ltcompile, $comp);
1022         }
1023         # The compiler's flag must be a configure variable.
1024         if (defined $language_map{$lang . '-flags'})
1025         {
1026             &define_configure_variable ($language_map{$lang . '-flags'});
1027         }
1029         # Compute the function name of the finisher and then call it.
1030         $name = 'lang_' . $lang . '_finish';
1031         & $name ();
1032     }
1034     # If the project is entirely C++ or entirely Fortran 77, don't
1035     # bother with the C stuff.  But if anything else creeps in, then use
1036     # it.
1037     if ($need_link || ! $non_c || scalar keys %suffix_rules > 0)
1038     {
1039         if (! defined $done{'c'})
1040         {
1041             &define_configure_variable ($language_map{'c-flags'});
1042             &define_compiler_variable ($language_map{'c-compiler-name'},
1043                                        $ltcompile,
1044                                        $language_map{'c-compile'});
1045         }
1046         &define_variable ('CCLD', '$(CC)');
1047         &define_variable ('LINK', $ltlink . '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
1048     }
1051 # Output a rule to build from a YACC source.  The output from YACC is
1052 # compiled with C or C++, depending on the extension of the YACC file.
1053 sub output_yacc_build_rule
1055     local ($yacc_suffix, $use_ylwrap, $c_suffix) = @_;
1057     local ($suffix);
1058     ($suffix = $yacc_suffix) =~ tr/y/c/;
1059     push (@suffixes, $yacc_suffix, $suffix);
1061     # Generate rule for c/c++.
1062     $output_rules .= "$yacc_suffix$suffix:\n\t";
1064     if ($use_ylwrap)
1065     {
1066         $output_rules .= ('$(SHELL) $(YLWRAP)'
1067                           . ' "$(YACC)" $< y.tab.c $*' . $suffix
1068                           . ' y.tab.h $*.h -- $(AM_YFLAGS) $(YFLAGS)');
1069     }
1070     else
1071     {
1072         $output_rules .= ('$(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*'
1073                           . $suffix . "\n"
1074                           . "\tif test -f y.tab.h; then \\\n"
1075                           . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
1076                           . "\telse :; fi");
1077     }
1078     $output_rules .= "\n";
1081 sub output_lex_build_rule
1083     local ($lex_suffix, $use_ylwrap) = @_;
1084     local ($c_suffix);
1086     ($c_suffix = $lex_suffix) =~ tr/l/c/;
1087     push (@suffixes, $lex_suffix);
1088     &define_configure_variable ('LEX_OUTPUT_ROOT');
1089     &define_configure_variable ('LEXLIB');
1090     $output_rules .= "$lex_suffix$c_suffix:\n\t";
1092     if ($use_ylwrap)
1093     {
1094         # Is the $@ correct here?  If so, why not use it in the ylwrap
1095         # build rule for yacc above?
1096         $output_rules .= '$(SHELL) $(YLWRAP)'
1097             . ' "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(AM_LFLAGS) $(LFLAGS)';
1098     }
1099     else
1100     {
1101         $output_rules .= '$(LEX) $(AM_LFLAGS) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
1102     }
1103     $output_rules .= "\n";
1107 # Check to make sure a source defined in LIBOBJS is not explicitly
1108 # mentioned.  This is a separate function (as opposed to being inlined
1109 # in handle_source_transform) because it isn't always appropriate to
1110 # do this check.
1111 sub check_libobjs_sources
1113     local ($one_file, $unxformed) = @_;
1115     local ($prefix, $file, @files);
1116     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1117                      'dist_EXTRA_', 'nodist_EXTRA_')
1118     {
1119         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1120         {
1121             @files = &variable_value_as_list (($prefix
1122                                                . $one_file . '_SOURCES'),
1123                                               'all');
1124         }
1125         elsif ($prefix eq '')
1126         {
1127             @files = ($unxformed . '.c');
1128         }
1129         else
1130         {
1131             next;
1132         }
1134         foreach $file (@files)
1135         {
1136             if (defined $libsources{$file})
1137             {
1138                 &am_line_error ($prefix . $one_file . '_SOURCES',
1139                                 "automatically discovered file \`$file' should not be explicitly mentioned");
1140             }
1141         }
1142     }
1145 # Does much of the actual work for handle_source_transform.
1146 # Arguments are:
1147 #   name of resulting executable or library ("derived")
1148 #   object extension (e.g., `$U.lo')
1149 #   list of source files to transform
1150 # Result is a list
1151 #   first element is name of linker to use (empty string for default linker)
1152 #   remaining elements are names of objects
1153 sub handle_single_transform_list
1155     local ($var, $derived, $obj, @files) = @_;
1156     local (@result) = ();
1157     local ($nonansi_obj) = $obj;
1158     $nonansi_obj =~ s/_//g;
1159     local (%linkers_used) = ();
1160     if (@files > 0)
1161     {
1162         # Turn sources into objects.
1163         foreach (@files)
1164         {
1165             # Configure substitutions in _SOURCES variables are errors.
1166             if (/^\@.*\@$/)
1167             {
1168                 &am_line_error ($var, "$var includes configure substitution \`$_'");
1169                 next;
1170             }
1172             # If the source file is in a subdirectory then the `.o' is
1173             # put into the current directory.
1175             # Split file name into base and extension.
1176             local ($full, $directory, $base, $extension, $linker, $object);
1177             next if ! /^((.*)\/)?([^\/]*)\.(.*)$/;
1178             $full = $_;
1179             $directory = $2;
1180             $base = $3;
1181             $extension = $4;
1183             local ($xbase) = $base;
1185             # We must generate a rule for the object if it requires
1186             # its own flags.
1187             local ($rule) = '';
1188             local ($renamed) = 0;
1190             $extension = &derive_suffix ($extension);
1191             local ($lang) = $extension_map{$extension};
1192             if ($lang)
1193             {
1194                 &saw_extension ($extension);
1195                 # Found the language, so see what it says.
1196                 local ($subr) = 'lang_' . $lang . '_rewrite';
1197                 # Note: computed subr call.
1198                 local ($r) = & $subr ($directory, $base, $extension);
1199                 # Skip this entry if we were asked not to process it.
1200                 next if $r == $LANG_IGNORE;
1202                 # Now extract linker and other info.
1203                 $linker = $language_map{$lang . '-linker'};
1205                 local ($this_obj_ext);
1206                 if ($language_map{$lang . '-ansi-p'})
1207                 {
1208                     $object = $base . $obj;
1209                     $this_obj_ext = $obj;
1210                 }
1211                 else
1212                 {
1213                     $object = $base . $nonansi_obj;
1214                     $this_obj_ext = $nonansi_obj;
1215                 }
1217                 if ($language_map{$lang . '-flags'} ne ''
1218                     && &variable_defined ($derived . '_'
1219                                           . $language_map{$lang . '-flags'}))
1220                 {
1221                     # We have a per-executable flag in effect for this
1222                     # object.  In this case we rewrite the object's
1223                     # name to ensure it is unique.  We also require
1224                     # the `compile' program to deal with compilers
1225                     # where `-c -o' does not work.
1227                     # We choose the name `DERIVED-OBJECT' to ensure
1228                     # (1) uniqueness, and (2) continuity between
1229                     # invocations.  However, this will result in a
1230                     # name that is too long for losing systems, in
1231                     # some situations.  So we provide _SHORTNAME to
1232                     # override.
1234                     local ($dname) = $derived;
1235                     if (&variable_defined ($derived . '_SHORTNAME'))
1236                     {
1237                         # FIXME: should use the same conditional as
1238                         # the _SOURCES variable.  But this is really
1239                         # silly overkill -- nobody should have
1240                         # conditional shortnames.
1241                         $dname = &variable_value ($derived . '_SHORTNAME');
1242                     }
1243                     $object = $dname . '-' . $object;
1245                     &require_file ($FOREIGN, 'compile')
1246                         if $lang eq 'c';
1248                     if (! defined $language_map{$lang . '-compile'})
1249                     {
1250                         print STDERR "automake: programming error: $lang flags defined without compiler\n";
1251                         exit 1;
1252                     }
1253                     # Compute the rule to compile this object.
1254                     local ($flag) = $language_map{$lang . '-flags'};
1255                     local ($val) = "(${derived}_${flag}";
1256                     ($rule = $language_map{$lang . '-compile'}) =~
1257                         s/\(AM_$flag/$val/;
1259                     $rule .= ' ' . $language_map{$lang . '-output-arg'};
1260                     # For C we have to add the -o, because the
1261                     # standard rule doesn't include it.
1262                     if ($language_map{$lang . '-flags'} eq 'CFLAGS')
1263                     {
1264                         $rule .= ' -o $@';
1265                     }
1267                     $renamed = 1;
1268                 }
1270                 # If rewrite said it was ok, put the object into a
1271                 # subdir.
1272                 if ($r == $LANG_SUBDIR && $directory ne '')
1273                 {
1274                     $object = $directory . '/' . $object;
1275                     $xbase = $directory . '/' . $base;
1276                 }
1278                 # If doing dependency tracking, then we can't print
1279                 # the rule.  Also, if we have a subdir object, we need
1280                 # to generate an explicit rule.
1281                 if (($use_dependencies
1282                      && $rule ne ''
1283                      && $language_map{$lang . '-autodep'} ne 'no')
1284                     || ($r == $LANG_SUBDIR && $directory ne ''))
1285                 {
1286                     $rule = '';
1287                     local ($obj_sans_ext) = substr ($object, 0,
1288                                                     - length ($this_obj_ext));
1289                     $lang_specific_files{$lang} .= (' ' . $derived
1290                                                     . ' ' . $full
1291                                                     . ' ' . $obj_sans_ext);
1292                 }
1293             }
1294             elsif ($extension eq 'o')
1295             {
1296                 # This is probably the result of a direct suffix rule.
1297                 # In this case we just accept the rewrite.  FIXME:
1298                 # this fails if we want libtool objects.
1299                 $object = $base . '.' . $extension;
1300                 $linker = '';
1301             }
1302             else
1303             {
1304                 # No error message here.  Used to have one, but it was
1305                 # very unpopular.
1306                 next;
1307             }
1309             $linkers_used{$linker} = 1;
1311             push (@result, $object);
1313             if (defined $object_map{$object})
1314             {
1315                 if ($object_map{$object} ne $full)
1316                 {
1317                     &am_error ("object \`$object' created by \`$full' and \`$object_map{$object}'");
1318                 }
1319             }
1320             else
1321             {
1322                 local (@dep_list) = ();
1323                 $object_map{$object} = $full;
1325                 # If file is in subdirectory, we need explicit
1326                 # dependency.
1327                 if ($directory ne '' || $renamed)
1328                 {
1329                     push (@dep_list, $full);
1330                 }
1332                 # If resulting object is in subdir, we need to make
1333                 # sure the subdir exists at build time.
1334                 if ($object =~ /\//)
1335                 {
1336                     # FIXME: check that $DIRECTORY is somewhere in the
1337                     # project
1339                     # We don't allow `..' in object file names for
1340                     # *any* source, not just Java.  For Java it just
1341                     # doesn't make sense, but in general it is
1342                     # a problem because we can't pick a good name for
1343                     # the .deps entry.
1344                     if ($object =~ /(\/|^)\.\.\//)
1345                     {
1346                         &am_error ("\`$full' contains \`..' component but should not");
1347                     }
1349                     push (@dep_list, $directory . '/.dirstamp');
1351                     # If we're generating dependencies, we also want
1352                     # to make sure that the appropriate subdir of the
1353                     # .deps directory is created.
1354                     if ($use_dependencies)
1355                     {
1356                         push (@dep_list, '.deps/' . $directory . '/.dirstamp');
1357                     }
1359                     if (! defined $directory_map{$directory})
1360                     {
1361                         $directory_map{$directory} = 1;
1362                         $output_rules .= ($directory . "/.dirstamp:\n"
1363                                           . "\t\@\$(mkinstalldirs) $directory\n"
1364                                           . "\t\@: > $directory/.dirstamp\n");
1365                         if ($use_dependencies)
1366                         {
1367                             $output_rules .= ('.deps/' . $directory
1368                                               . "/.dirstamp:\n"
1369                                               . "\t\@\$(mkinstalldirs) .deps/$directory\n"
1370                                               . "\t\@: > .deps/$directory/.dirstamp\n");
1371                         }
1372                     }
1373                 }
1375                 &pretty_print_rule ($object . ':', "\t", @dep_list)
1376                     if scalar @dep_list > 0 || $rule ne '';
1378                 # Print the rule if we have one.
1379                 if ($rule ne '')
1380                 {
1381                     # Turn `$@' into name of our object file.
1382                     local ($xform);
1383                     ($xform = $object) =~ s,/,\\/,g;
1384                     $rule =~ s/\$\@/$xform/;
1386                     # We cannot use $< here since this is an explicit
1387                     # rule and not all makes handle that.
1388                     $rule .= " \`test -f $full || echo '\$(srcdir)/'\`$full";
1390                     # FIXME: handle .lo and .obj as well.
1391                     $output_rules .= "\t" . $rule . "\n";
1392                 }
1393             }
1395             # Transform .o or $o file into .P file (for automatic
1396             # dependency code).
1397             if ($lang
1398                 && ($language_map{$lang . '-autodep'} ne 'no'
1399                     || $language_map{$lang . '-derived-autodep'} eq 'yes'))
1400             {
1401                 local ($depfile) = $object;
1402                 $depfile =~ s/\.([^.]*)$/.P$1/;
1403                 $depfile =~ s/\$\(OBJEXT\)$/o/ if $seen_objext;
1404                 $dep_files{'$(DEPDIR)/' . $depfile} = 1;
1405             }
1406         }
1407     }
1409     return (&resolve_linker (%linkers_used), @result);
1412 # Handle SOURCE->OBJECT transform for one program or library.
1413 # Arguments are:
1414 #   canonical (transformed) name of object to build
1415 #   actual name of object to build
1416 #   object extension (ie either `.o' or `$o'.
1417 # Return result is name of linker variable that must be used.
1418 # Empty return means just use `LINK'.
1419 sub handle_source_transform
1421     # one_file is canonical name.  unxformed is given name.  obj is
1422     # object extension.
1423     local ($one_file, $unxformed, $obj) = @_;
1425     local ($linker) = '';
1427     if (&variable_defined ($one_file . "_OBJECTS"))
1428     {
1429         &am_line_error ($one_file . '_OBJECTS',
1430                         $one_file . '_OBJECTS', 'should not be defined');
1431         # No point in continuing.
1432         return;
1433     }
1435     local (@files, @result, $prefix, $temp, $xpfx);
1436     local (%used_pfx) = ();
1437     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1438                      'dist_EXTRA_', 'nodist_EXTRA_')
1439     {
1440         # We are going to define _OBJECTS variables using the prefix.
1441         # Then we glom them all together.  So we can't use the null
1442         # prefix here as we need it later.
1443         $xpfx = ($prefix eq '') ? 'am_' : $prefix;
1445         @files = ();
1446         local ($var) = $prefix . $one_file . "_SOURCES";
1447         if (&variable_defined ($var))
1448         {
1449             # Keep track of which prefixes we saw.
1450             $used_pfx{$xpfx} = 1
1451                 unless $prefix =~ /EXTRA_/;
1453             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1454             push (@objects, '$(' . $xpfx . $one_file . "_OBJECTS)")
1455                 unless $prefix =~ /EXTRA_/;
1456             push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
1457                 unless $prefix =~ /^nodist_/;
1458             local (@conds) = &variable_conditions ($var);
1459             if (! @conds)
1460             {
1461                 @files = &variable_value_as_list ($var, '');
1462             }
1463             else
1464             {
1465                 local ($cond);
1466                 foreach $cond (@conds)
1467                 {
1468                     @files = &variable_value_as_list ($var, $cond);
1469                     ($temp, @result) =
1470                         &handle_single_transform_list ($var, $one_file, $obj,
1471                                                        @files);
1472                     $linker = $temp if $linker eq '';
1474                     # Define _OBJECTS conditionally.
1475                     &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
1476                                              $cond, @result)
1477                         unless $prefix =~ /EXTRA_/;
1478                 }
1480                 next;
1481             }
1482         }
1484         # Avoid defining needless variables.
1485         next if (scalar @files == 0);
1487         ($temp, @result) = &handle_single_transform_list ($var, $one_file,
1488                                                           $obj, @files);
1489         $linker = $temp if $linker eq '';
1490         &define_pretty_variable ($xpfx . $one_file . "_OBJECTS", '', @result)
1491             unless $prefix =~ /EXTRA_/;
1492     }
1494     local (@keys) = sort keys %used_pfx;
1495     if (scalar @keys == 0)
1496     {
1497         &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1498         push (@sources, $unxformed . '.c');
1499         push (@dist_sources, $unxformed . '.c');
1500         push (@objects, $unxformed . $obj);
1501         push (@files, $unxformed . '.c');
1503         ($temp, @result) = &handle_single_transform_list ($one_file . '_SOURCES',
1504                                                           $one_file, $obj,
1505                                                           @files);
1506         $linker = $temp if $linker eq '';
1507         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
1508     }
1509     else
1510     {
1511         grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
1512         &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
1513     }
1515     # If we want to use `LINK' we must make sure it is defined.
1516     if ($linker eq '')
1517     {
1518         $need_link = 1;
1519     }
1521     return $linker;
1524 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1525 # Also, generate _DEPENDENCIES variable if appropriate.
1526 # Arguments are:
1527 #   transformed name of object being built, or empty string if no object
1528 #   name of _LDADD/_LIBADD-type variable to examine
1529 #   boolean (lex_seen) which is true if a lex source file was seen in this
1530 #     object.  valid only for LDADDs, not LIBADDs.
1531 # Returns 1 if LIBOBJS seen, 0 otherwise.
1532 sub handle_lib_objects
1534     local ($xname, $var, $lex_seen) = @_;
1535     local ($ret);
1537     die "automake: programming error 1 in handle_lib_objects\n"
1538         if ! &variable_defined ($var);
1540     die "automake: programming error 2 in handle_lib_objects\n"
1541         if $lex_seen && $var =~ /LIBADD/;
1543     local (@conds) = &variable_conditions ($var);
1544     if (! @conds)
1545     {
1546         $ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
1547     }
1548     else
1549     {
1550         local ($cond);
1551         $ret = 0;
1552         foreach $cond (@conds)
1553         {
1554             if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
1555             {
1556                 $ret = 1;
1557             }
1558         }
1559     }
1561     return $ret;
1564 # Subroutine of handle_lib_objects: handle a particular condition.
1565 sub handle_lib_objects_cond
1567     local ($xname, $var, $lex_seen, $cond) = @_;
1569     # We recognize certain things that are commonly put in LIBADD or
1570     # LDADD.
1571     local ($lsearch);
1572     local (@dep_list) = ();
1574     local ($seen_libobjs) = 0;
1575     local ($flagvar) = 0;
1577     foreach $lsearch (&variable_value_as_list ($var, $cond))
1578     {
1579         # Skip -lfoo and -Ldir; these are explicitly allowed.
1580         next if $lsearch =~ /^-[lL]/;
1581         if (! $flagvar && $lsearch =~ /^-/)
1582         {
1583             if ($var =~ /^(.*)LDADD$/)
1584             {
1585                 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
1586                 next if $lsearch =~ /^-dl(pre)?open$/;
1587                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1588             }
1589             else
1590             {
1591                 # Only get this error once.
1592                 $flagvar = 1;
1593                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1594             }
1595         }
1597         # Assume we have a file of some sort, and push it onto the
1598         # dependency list.  Autoconf substitutions are not pushed;
1599         # rarely is a new dependency substituted into (eg) foo_LDADD
1600         # -- but "bad things (eg -lX11) are routinely substituted.
1601         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1602         # and handled specially below.
1603         push (@dep_list, $lsearch)
1604             unless $lsearch =~ /^\@.*\@$/;
1606         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1607         # means adding entries to dep_files.
1608         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1609         {
1610             local ($myobjext) = ($1 ? 'l' : '') . 'o';
1612             push (@dep_list, $lsearch);
1613             $seen_libobjs = 1;
1614             if (! keys %libsources
1615                 && ! &variable_defined ($1 . 'LIBOBJS'))
1616             {
1617                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
1618             }
1620             local ($iter, $rewrite);
1621             foreach $iter (keys %libsources)
1622             {
1623                 if ($iter =~ /\.([cly])$/)
1624                 {
1625                     &saw_extension ($1);
1626                     &saw_extension ('c');
1627                 }
1629                 if ($iter =~ /\.h$/)
1630                 {
1631                     &require_file_with_line ($var, $FOREIGN, $iter);
1632                 }
1633                 elsif ($iter ne 'alloca.c')
1634                 {
1635                     ($rewrite = $iter) =~ s/\.c$/.P$myobjext/;
1636                     $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
1637                     ($rewrite = $iter) =~ s/(\W)/\\$1/g;
1638                     $rewrite = "^" . $rewrite . "\$";
1639                     # Only require the file if it is not a built source.
1640                     if (! &variable_defined ('BUILT_SOURCES')
1641                         || ! grep (/$rewrite/,
1642                                    &variable_value_as_list ('BUILT_SOURCES',
1643                                                             'all')))
1644                     {
1645                         &require_file_with_line ($var, $FOREIGN, $iter);
1646                     }
1647                 }
1648             }
1649         }
1650         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1651         {
1652             local ($myobjext) = ($1 ? 'l' : '') . 'o';
1654             push (@dep_list, $lsearch);
1655             &am_line_error ($var,
1656                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
1657                 if ! defined $libsources{'alloca.c'};
1658             $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
1659             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1660             &saw_extension ('c');
1661         }
1662     }
1664     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
1665     {
1666         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
1667     }
1669     return $seen_libobjs;
1672 # Canonicalize a name, and check to make sure the non-canonical name
1673 # is never used.  Returns canonical name.  Arguments are name and a
1674 # list of suffixes to check for.
1675 sub check_canonical_spelling
1677     local ($name, @suffixes) = @_;
1678     local ($xname, $xt);
1680     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
1681     if ($xname ne $name)
1682     {
1683         local ($xt);
1684         foreach $xt (@suffixes)
1685         {
1686             &am_line_error ($name . $xt,
1687                             "invalid variable \`" . $name . $xt
1688                             . "'; should be \`" . $xname . $xt . "'")
1689                 if &variable_defined ($name . $xt);
1690         }
1691     }
1693     return $xname;
1696 # Handle C programs.
1697 sub handle_programs
1699     local (@proglist) = &am_install_var ('-clean',
1700                                          'progs', 'PROGRAMS',
1701                                          'bin', 'sbin', 'libexec', 'pkglib',
1702                                          'noinst', 'check');
1703     return if ! @proglist;
1705     # If a program is installed, this is required.  We only want this
1706     # error to appear once.
1707     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1708         unless $seen_arg_prog;
1709     $seen_arg_prog = 1;
1711     local ($one_file, $xname, $munge);
1713     local ($seen_libobjs) = 0;
1714     foreach $one_file (@proglist)
1715     {
1716         local ($obj) = &get_object_extension ($one_file);
1718         # Canonicalize names and check for misspellings.
1719         $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
1720                                             '_SOURCES', '_OBJECTS',
1721                                             '_DEPENDENCIES');
1723         # FIXME: Using a trick to figure out if any lex sources appear
1724         # in our program; should use some cleaner method.
1725         local ($lex_num) = scalar (keys %lex_sources);
1726         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1727         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1729         local ($xt) = '';
1730         if (&variable_defined ($xname . "_LDADD"))
1731         {
1732             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1733                                      $lex_file_seen))
1734             {
1735                 $seen_libobjs = 1;
1736             }
1737             $lex_file_seen = 0;
1738             $xt = '_LDADD';
1739         }
1740         else
1741         {
1742             # User didn't define prog_LDADD override.  So do it.
1743             &define_variable ($xname . '_LDADD', '$(LDADD)');
1745             # This does a bit too much work.  But we need it to
1746             # generate _DEPENDENCIES when appropriate.
1747             if (&variable_defined ('LDADD'))
1748             {
1749                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1750                 {
1751                     $seen_libobjs = 1;
1752                 }
1753                 $lex_file_seen = 0;
1754             }
1755             elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
1756             {
1757                 &define_variable ($xname . '_DEPENDENCIES', '');
1758             }
1759             $xt = '_SOURCES'
1760         }
1762         if (&variable_defined ($xname . '_LIBADD'))
1763         {
1764             &am_line_error ($xname . '_LIBADD',
1765                             "use \`" . $xname . "_LDADD', not \`"
1766                             . $xname . "_LIBADD'");
1767         }
1769         if (! &variable_defined ($xname . '_LDFLAGS'))
1770         {
1771             # Define the prog_LDFLAGS variable.
1772             &define_variable ($xname . '_LDFLAGS', '');
1773         }
1775         # Determine program to use for link.
1776         local ($xlink);
1777         if (&variable_defined ($xname . '_LINK'))
1778         {
1779             $xlink = $xname . '_LINK';
1780         }
1781         else
1782         {
1783             $xlink = $linker ? $linker : 'LINK';
1784         }
1786         local ($xexe);
1787         if ($seen_exeext && $one_file !~ /\./)
1788         {
1789             $xexe = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
1790         }
1791         else
1792         {
1793             $xexe = 's/\@EXEEXT\@//g;';
1794         }
1796         $output_rules .=
1797             &file_contents_with_transform
1798                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1799                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1800                  . 's/\@XLINK\@/' . $xlink . '/go;'
1801                  . $xexe,
1802                  'program');
1803     }
1805     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1806     {
1807         $seen_libobjs = 1;
1808     }
1810     if ($seen_libobjs)
1811     {
1812         foreach $one_file (@proglist)
1813         {
1814             # Canonicalize names.
1815             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1817             if (&variable_defined ($xname . '_LDADD'))
1818             {
1819                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1820             }
1821             elsif (&variable_defined ('LDADD'))
1822             {
1823                 &check_libobjs_sources ($xname, 'LDADD');
1824             }
1825         }
1826     }
1830 # Handle libraries.
1831 sub handle_libraries
1833     local (@liblist) = &am_install_var ('-clean',
1834                                         'libs', 'LIBRARIES',
1835                                         'lib', 'pkglib', 'noinst', 'check');
1836     return if ! @liblist;
1838     local (%valid) = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
1839                                            'noinst', 'check');
1840     if (! defined $configure_vars{'RANLIB'})
1841     {
1842         local ($key);
1843         foreach $key (keys %valid)
1844         {
1845             if (&variable_defined ($key . '_LIBRARIES'))
1846             {
1847                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1848                 # Only get this error once.  If this is ever printed,
1849                 # we have a bug.
1850                 $configure_vars{'RANLIB'} = 'BUG';
1851                 last;
1852             }
1853         }
1854     }
1856     local ($onelib);
1857     local ($munge);
1858     local ($xlib);
1859     local ($seen_libobjs) = 0;
1860     foreach $onelib (@liblist)
1861     {
1862         # Check that the library fits the standard naming convention.
1863         if ($onelib !~ /^lib.*\.a$/)
1864         {
1865             # FIXME should put line number here.  That means mapping
1866             # from library name back to variable name.
1867             &am_error ("\`$onelib' is not a standard library name");
1868         }
1870         local ($obj) = &get_object_extension ($onelib);
1872         # Canonicalize names and check for misspellings.
1873         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
1874                                            '_OBJECTS', '_DEPENDENCIES', '_AR');
1876         if (! &variable_defined ($xlib . '_AR'))
1877         {
1878             &define_variable ($xlib . '_AR', '$(AR) cru');
1879         }
1881         if (&variable_defined ($xlib . '_LIBADD'))
1882         {
1883             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1884             {
1885                 $seen_libobjs = 1;
1886             }
1887         }
1888         else
1889         {
1890             # Generate support for conditional object inclusion in
1891             # libraries.
1892             &define_variable ($xlib . "_LIBADD", '');
1893         }
1895         if (&variable_defined ($xlib . '_LDADD'))
1896         {
1897             &am_line_error ($xlib . '_LDADD',
1898                             "use \`" . $xlib . "_LIBADD', not \`"
1899                             . $xlib . "_LDADD'");
1900         }
1902         # Make sure we at look at this.
1903         &examine_variable ($xlib . '_DEPENDENCIES');
1905         &handle_source_transform ($xlib, $onelib, $obj);
1907         $output_rules .=
1908             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1909                                            . 's/\@XLIBRARY\@/'
1910                                            . $xlib . '/go;',
1911                                            'library');
1912     }
1914     if ($seen_libobjs)
1915     {
1916         foreach $onelib (@liblist)
1917         {
1918             # Canonicalize names.
1919             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1920             if (&variable_defined ($xlib . '_LIBADD'))
1921             {
1922                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1923             }
1924         }
1925     }
1927     &define_variable ('AR', 'ar');
1928     &define_configure_variable ('RANLIB');
1931 # Handle shared libraries.
1932 sub handle_ltlibraries
1934     local (@liblist) = &am_install_var ('-clean',
1935                                         'ltlib', 'LTLIBRARIES',
1936                                         'noinst', 'lib', 'pkglib', 'check');
1937     return if ! @liblist;
1939     local (%instdirs);
1940     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
1941                                            'noinst', 'check');
1943     local ($key);
1944     foreach $key (keys %valid)
1945     {
1946         if (&variable_defined ($key . '_LTLIBRARIES'))
1947         {
1948             if (!$seen_libtool)
1949             {
1950                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
1951                 # Only get this error once.  If this is ever printed,
1952                 # we have a bug.
1953                 $configure_vars{'LIBTOOL'} = 'BUG';
1954                 $seen_libtool = 1;
1955             }
1957             # Get the installation directory of each library.
1958             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
1959             {
1960                 if ($instdirs{$_})
1961                 {
1962                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1963                 }
1964                 else
1965                 {
1966                     $instdirs{$_} = $key;
1967                 }
1968             }
1969         }
1970     }
1972     local ($onelib);
1973     local ($munge);
1974     local ($xlib);
1975     local ($seen_libobjs) = 0;
1976     foreach $onelib (@liblist)
1977     {
1978         local ($obj) = &get_object_extension ($onelib);
1980         # Canonicalize names and check for misspellings.
1981         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
1982                                            '_SOURCES', '_OBJECTS',
1983                                            '_DEPENDENCIES');
1985         if (! &variable_defined ($xlib . '_LDFLAGS'))
1986         {
1987             # Define the lib_LDFLAGS variable.
1988             &define_variable ($xlib . '_LDFLAGS', '');
1989         }
1991         # Check that the library fits the standard naming convention.
1992         $libname_rx = "^lib.*\.la";
1993         if ((&variable_defined ($xlib . '_LDFLAGS')
1994              && grep (/-module/, &variable_value_as_list ($xlib . '_LDFLAGS',
1995                                                           'all')))
1996             || (&variable_defined ('LDFLAGS')
1997                 && grep (/-module/, &variable_value_as_list ('LDFLAGS',
1998                                                              'all'))))
1999         {
2000                 # Relax name checking for libtool modules.
2001                 $libname_rx = "\.la";
2002         }
2003         if ($onelib !~ /$libname_rx$/)
2004         {
2005             # FIXME this should only be a warning for foreign packages
2006             # FIXME should put line number here.  That means mapping
2007             # from library name back to variable name.
2008             &am_error ("\`$onelib' is not a standard libtool library name");
2009         }
2011         if (&variable_defined ($xlib . '_LIBADD'))
2012         {
2013             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
2014             {
2015                 $seen_libobjs = 1;
2016             }
2017         }
2018         else
2019         {
2020             # Generate support for conditional object inclusion in
2021             # libraries.
2022             &define_variable ($xlib . "_LIBADD", '');
2023         }
2025         if (&variable_defined ($xlib . '_LDADD'))
2026         {
2027             &am_line_error ($xlib . '_LDADD',
2028                             "use \`" . $xlib . "_LIBADD', not \`"
2029                             . $xlib . "_LDADD'");
2030         }
2032         # Make sure we at look at this.
2033         &examine_variable ($xlib . '_DEPENDENCIES');
2035         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
2037         # Determine program to use for link.
2038         local ($xlink);
2039         if (&variable_defined ($xlib . '_LINK'))
2040         {
2041             $xlink = $xlib . '_LINK';
2042         }
2043         else
2044         {
2045             $xlink = $linker ? $linker : 'LINK';
2046         }
2048         local ($rpath);
2049         if ($instdirs{$onelib} eq 'EXTRA' || $instdirs{$onelib} eq 'noinst')
2050         {
2051             # It's an EXTRA_ library, so we can't specify -rpath,
2052             # because we don't know where the library will end up.
2053             # The user probably knows, but generally speaking automake
2054             # doesn't -- and in fact configure could decide
2055             # dynamically between two different locations.
2056             $rpath = 's/\@RPATH\@//go;';
2057         }
2058         else
2059         {
2060             $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
2061                       . 'dir)/go;');
2062         }
2064         $output_rules .=
2065             &file_contents_with_transform ('s/\@LTLIBRARY\@/'
2066                                            . $onelib . '/go;'
2067                                            . 's/\@XLTLIBRARY\@/'
2068                                            . $xlib . '/go;'
2069                                            . $rpath
2070                                            . 's/\@XLINK\@/' . $xlink . '/go;',
2071                                            'ltlibrary');
2072     }
2074     if ($seen_libobjs)
2075     {
2076         foreach $onelib (@liblist)
2077         {
2078             # Canonicalize names.
2079             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
2080             if (&variable_defined ($xlib . '_LIBADD'))
2081             {
2082                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2083             }
2084         }
2085     }
2088 # See if any _SOURCES variable were misspelled.  Also, make sure that
2089 # EXTRA_ variables don't contain configure substitutions.
2090 sub check_typos
2092     local ($varname, $primary);
2093     foreach $varname (keys %contents)
2094     {
2095         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
2096                           '_DEPENDENCIES')
2097         {
2098             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
2099             {
2100                 &am_line_error ($varname,
2101                                 "invalid unused variable name: \`$varname'");
2102             }
2103         }
2104     }
2107 # Handle scripts.
2108 sub handle_scripts
2110     # NOTE we no longer automatically clean SCRIPTS, because it is
2111     # useful to sometimes distribute scripts verbatim.  This happens
2112     # eg in Automake itself.
2113     &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2114                      'bin', 'sbin', 'libexec', 'pkgdata',
2115                      'noinst', 'check');
2117     local ($scripts_installed) = 0;
2118     # Set $scripts_installed if appropriate.  Make sure we only find
2119     # scripts which are actually installed -- this is why we can't
2120     # simply use the return value of am_install_var.
2121     local (%valid) = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
2122                                            'libexec', 'pkgdata',
2123                                            'noinst', 'check');
2124     local ($key);
2125     foreach $key (keys %valid)
2126     {
2127         if ($key ne 'noinst'
2128             && $key ne 'check'
2129             && &variable_defined ($key . '_SCRIPTS'))
2130         {
2131             $scripts_installed = 1;
2132             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
2133         }
2134     }
2136     if ($scripts_installed)
2137     {
2138         # If a program is installed, this is required.  We only want this
2139         # error to appear once.
2140         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
2141             unless $seen_arg_prog;
2142         $seen_arg_prog = 1;
2143     }
2146 # Search a file for a "version.texi" Texinfo include.  Return the name
2147 # of the include file if found, or the empty string if not.  A
2148 # "version.texi" file is actually any file whose name matches
2149 # "vers*.texi".
2150 sub scan_texinfo_file
2152     local ($filename) = @_;
2154     if (! open (TEXI, $filename))
2155     {
2156         &am_error ("couldn't open \`$filename': $!");
2157         return '';
2158     }
2159     print "automake: reading $filename\n" if $verbose;
2161     local ($vfile, $outfile);
2162     while (<TEXI>)
2163     {
2164         if (/^\@setfilename +(\S+)/)
2165         {
2166             $outfile = $1;
2167             last if ($vfile);
2168         }
2170         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2171         {
2172             # Found version.texi include.
2173             $vfile = $1;
2174             last if $outfile;
2175         }
2176     }
2178     close (TEXI);
2179     return ($outfile, $vfile);
2182 # Handle all Texinfo source.
2183 sub handle_texinfo
2185     &am_line_error ('TEXINFOS',
2186                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
2187         if &variable_defined ('TEXINFOS');
2188     return if (! &variable_defined ('info_TEXINFOS')
2189                && ! &variable_defined ('html_TEXINFOS'));
2191     if (&variable_defined ('html_TEXINFOS'))
2192     {
2193         &am_line_error ('html_TEXINFOS',
2194                         "HTML generation not yet supported");
2195         return;
2196     }
2198     local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');
2200     local (@info_deps_list, @dvis_list, @texi_deps);
2201     local ($infobase, $info_cursor);
2202     local (%versions);
2203     local ($done) = 0;
2204     local ($vti);
2205     local ($tc_cursor, @texi_cleans);
2206     local ($canonical);
2208     foreach $info_cursor (@texis)
2209     {
2210         # FIXME: This is mildly hacky, since it recognizes "txinfo".
2211         # I don't feel like making it right.
2212         ($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;
2214         # If 'version.texi' is referenced by input file, then include
2215         # automatic versioning capability.
2216         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
2217                                                         . "/" . $info_cursor);
2219         if ($out_file eq '')
2220         {
2221             &am_error ("\`$info_cursor' missing \@setfilename");
2222             next;
2223         }
2225         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
2226         {
2227             # FIXME should report line number in input file.
2228             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
2229             next;
2230         }
2232         if ($vtexi)
2233         {
2234             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
2235                 if (defined $versions{$vtexi});
2236             $versions{$vtexi} = $info_cursor;
2238             # We number the stamp-vti files.  This is doable since the
2239             # actual names don't matter much.  We only number starting
2240             # with the second one, so that the common case looks nice.
2241             $vti = ($done ? $done : 'vti');
2242             ++$done;
2244             &push_dist_common ($vtexi, 'stamp-' . $vti);
2245             push (@clean, $vti);
2247             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2248                                           'mdate-sh');
2250             local ($conf_pat, $conf_dir);
2251             if ($config_aux_dir eq '.' || $config_aux_dir eq '')
2252             {
2253                 $conf_dir = '$(srcdir)/';
2254             }
2255             else
2256             {
2257                 $conf_dir = $config_aux_dir;
2258                 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
2259             }
2260             ($conf_pat = $conf_dir) =~ s/(\W)/\\$1/g;
2261             $output_rules .=
2262                 &file_contents_with_transform
2263                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
2264                      . 's/\@VTI\@/' . $vti . '/g; '
2265                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
2266                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
2267                      'texi-vers');
2269             &push_phony_cleaners ($vti);
2270         }
2272         # If user specified file_TEXINFOS, then use that as explicit
2273         # dependency list.
2274         @texi_deps = ();
2275         push (@texi_deps, $info_cursor);
2276         # Prefix with $(srcdir) because some version of make won't
2277         # work if the target has it and the dependency doesn't.
2278         push (@texi_deps, '$(srcdir)/' . $vtexi) if $vtexi;
2280         # Canonicalize name first.
2281         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
2282         if (&variable_defined ($canonical . "_TEXINFOS"))
2283         {
2284             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
2285             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
2286         }
2288         $output_rules .= ("\n" . $out_file . ": "
2289                           . join (' ', @texi_deps)
2290                           . "\n" . $infobase . ".dvi: "
2291                           . join (' ', @texi_deps)
2292                           . "\n\n");
2294         push (@info_deps_list, $out_file);
2295         push (@dvis_list, $infobase . '.dvi');
2297         # Generate list of things to clean for this target.  We do
2298         # this explicitly because otherwise too many things could be
2299         # removed.  In particular the ".log" extension might
2300         # reasonably be used in other contexts by the user.
2301         # FIXME: this is really out of control.
2302         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns', 'pgs',
2303                             'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
2304                             'vr', 'vrs', 'op', 'tr', 'cv', 'cn', 'cm', 'ov')
2305         {
2306             push (@texi_cleans, $infobase . '.' . $tc_cursor);
2307         }
2308     }
2310     # Find these programs wherever they may lie.  Yes, this has
2311     # intimate knowledge of the structure of the texinfo distribution.
2312     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
2313                               'makeinfo',
2314                               # Circumlocution to avoid accidental
2315                               # configure substitution.
2316                               '@MAKE' . 'INFO@');
2317     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
2318                               'texi2dvi');
2320     # Set transform for including texinfos.am.  First, handle --cygnus
2321     # stuff.
2322     local ($xform);
2323     if ($cygnus_mode)
2324     {
2325         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
2326     }
2327     else
2328     {
2329         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
2330     }
2332     # Handle location of texinfo.tex.
2333     local ($need_texi_file) = 0;
2334     local ($texinfo_tex);
2335     if ($cygnus_mode)
2336     {
2337         $texinfo_tex = '$(top_srcdir)/../texinfo/texinfo.tex';
2338         &define_variable ('TEXINFO_TEX', $texinfo_tex);
2340     }
2341     elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
2342     {
2343         $texinfo_tex = $config_aux_dir . '/texinfo.tex';
2344         &define_variable ('TEXINFO_TEX', $texinfo_tex);
2345         $need_texi_file = 2; # so that we require_conf_file later
2346     }
2347     elsif (&variable_defined ('TEXINFO_TEX'))
2348     {
2349         # The user defined TEXINFO_TEX so assume he knows what he is
2350         # doing.
2351         $texinfo_tex = ('$(srcdir)/'
2352                         . &dirname (&variable_value ('TEXINFO_TEX')));
2353     }
2354     else
2355     {
2356         $texinfo_tex = '$(srcdir)/texinfo.tex';
2357         $need_texi_file = 1;
2358     }
2359     local ($xxform);
2360     ($xxform = $texinfo_tex) =~ s/\/texinfo\.tex$//;
2361     $xxform =~ s/(\W)/\\$1/g;
2362     $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';
2364     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
2365     push (@phony, 'install-info-am', 'uninstall-info');
2366     push (@dist_targets, 'dist-info');
2368     # How to clean.  The funny name is due to --cygnus influence; in
2369     # Cygnus mode, `clean-info' is a target that users can use.
2370     $output_rules .= "\nmostlyclean-aminfo:\n";
2371     &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
2372     $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
2373                       . "maintainer-clean-aminfo:\n\t"
2374                       # Eww.  But how else can we find all the output
2375                       # files from makeinfo?
2376                       . ($cygnus_mode ? '' : 'cd $(srcdir) && ')
2377                       . 'for i in $(INFO_DEPS); do' . " \\\n"
2378                       . "\t" . '  rm -f $$i;' . " \\\n"
2379                       . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
2380                       . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
2381                       . "\t" . '  fi;' . " \\\n"
2382                       . "\tdone\n");
2383     &push_phony_cleaners ('aminfo');
2384     if ($cygnus_mode)
2385     {
2386         $output_rules .= "clean-info: mostlyclean-aminfo\n";
2387     }
2389     push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');
2391     if (! defined $options{'no-installinfo'})
2392     {
2393         push (@uninstall, 'uninstall-info');
2394         push (@installdirs, '$(DESTDIR)$(infodir)');
2395         unshift (@install_data, 'install-info-am');
2397         # Make sure documentation is made and installed first.  Use
2398         # $(INFO_DEPS), not 'info', because otherwise recursive makes
2399         # get run twice during "make all".
2400         unshift (@all, '$(INFO_DEPS)');
2401     }
2402     push (@clean, 'aminfo');
2403     push (@info, '$(INFO_DEPS)');
2404     push (@dvi, '$(DVIS)');
2406     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2407     &define_variable ("DVIS", join (' ', @dvis_list));
2408     # This next isn't strictly needed now -- the places that look here
2409     # could easily be changed to look in info_TEXINFOS.  But this is
2410     # probably better, in case noinst_TEXINFOS is ever supported.
2411     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
2413     # Do some error checking.  Note that this file is not required
2414     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2415     # up above.
2416     if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
2417     {
2418         if ($need_texi_file > 1)
2419         {
2420             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2421                                           'texinfo.tex');
2422         }
2423         else
2424         {
2425             &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
2426         }
2427     }
2430 # Handle any man pages.
2431 sub handle_man_pages
2433     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
2434         if &variable_defined ('MANS');
2436     # Find all the sections in use.  We do this by first looking for
2437     # "standard" sections, and then looking for any additional
2438     # sections used in man_MANS.
2439     local ($sect, %sections, %vlist);
2440     local ($found) = 0;
2441     # Add more sections as needed.
2442     foreach $sect ('0'..'9', 'n', 'l')
2443     {
2444         if (&variable_defined ('man' . $sect . '_MANS'))
2445         {
2446             $sections{$sect} = 1;
2447             $vlist{'$(man' . $sect . '_MANS)'} = 1;
2448             $found = 1;
2449         }
2450     }
2452     if (&variable_defined ('man_MANS'))
2453     {
2454         $vlist{'$(man_MANS)'} = 1;
2455         foreach (&variable_value_as_list ('man_MANS', 'all'))
2456         {
2457             # A page like `foo.1c' goes into man1dir.
2458             if (/\.([0-9a-z])([a-z]*)$/)
2459             {
2460                 $sections{$1} = 1;
2461                 $found = 1;
2462             }
2463         }
2464     }
2466     return unless $found;
2468     # Now for each section, generate an install and unintall rule.
2469     # Sort sections so output is deterministic.
2470     local (@namelist);
2471     foreach $sect (sort keys %sections)
2472     {
2473         &define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
2474         push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
2475             unless defined $options{'no-installman'};
2476         $output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
2477                                                         . $sect . '/g;',
2478                                                         'mans');
2479         push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
2480         push (@namelist, 'install-man' . $sect);
2481     }
2483     # We don't really need this, but we use it in case we ever want to
2484     # support noinst_MANS.
2485     &define_variable ("MANS", join (' ', sort keys %vlist));
2487     # Generate list of install dirs.
2488     $output_rules .= ("install-man: \$(MANS)\n"
2489                       . "\t\@\$(NORMAL_INSTALL)\n");
2490     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2491     push (@phony, 'install-man');
2493     $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
2494     grep ($_ = 'un' . $_, @namelist);
2495     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2496     push (@phony, 'uninstall-man');
2498     $output_vars .= &file_contents ('mans-vars');
2500     if (! defined $options{'no-installman'})
2501     {
2502         push (@install_data, 'install-man');
2503         push (@uninstall, 'uninstall-man');
2504         push (@all, '$(MANS)');
2505     }
2508 # Handle DATA variables.
2509 sub handle_data
2511     &am_install_var ('-noextra', '-candist', 'data', 'DATA',
2512                      'data', 'sysconf', 'sharedstate', 'localstate',
2513                      'pkgdata', 'noinst', 'check');
2516 # Handle TAGS.
2517 sub handle_tags
2519     push (@phony, 'tags');
2520     local (@tag_deps) = ();
2521     if (&variable_defined ('SUBDIRS'))
2522     {
2523         $output_rules .= ("tags-recursive:\n"
2524                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
2525                           # Never fail here if a subdir fails; it
2526                           # isn't important.
2527                           . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
2528                           . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
2529                           . "\tdone\n");
2530         push (@tag_deps, 'tags-recursive');
2531         push (@phony, 'tags-recursive');
2532     }
2534     if (&saw_sources_p (1)
2535         || &variable_defined ('ETAGS_ARGS')
2536         || @tag_deps)
2537     {
2538         local ($xform) = '';
2539         local ($one_hdr);
2540         foreach $one_hdr (@config_headers)
2541         {
2542             if ($relative_dir eq &dirname ($one_hdr))
2543             {
2544                 # The config header is in this directory.  So require it.
2545                 local ($var);
2546                 ($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
2547                 $xform .= ' ' if $xform;
2548                 $xform .= $var;
2549             }
2550         }
2551         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
2552                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
2554         if (&variable_defined ('SUBDIRS'))
2555         {
2556             $xform .= 's/^SUBDIRS//;';
2557         }
2558         else
2559         {
2560             $xform .= 's/^SUBDIRS.*$//;';
2561         }
2563         $output_rules .= &file_contents_with_transform ($xform, 'tags');
2564         $output_rules .= &file_contents ('tags-clean');
2565         push (@clean, 'tags');
2566         &push_phony_cleaners ('tags');
2567         &examine_variable ('TAGS_DEPENDENCIES');
2568     }
2569     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2570     {
2571         &am_line_error ('TAGS_DEPENDENCIES',
2572                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2573     }
2574     else
2575     {
2576         # Every Makefile must define some sort of TAGS rule.
2577         # Otherwise, it would be possible for a top-level "make TAGS"
2578         # to fail because some subdirectory failed.
2579         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2580     }
2583 # Handle multilib support.
2584 sub handle_multilib
2586     return unless $seen_multilib;
2588     $output_rules .= &file_contents ('multilib');
2589     &push_phony_cleaners ('multi');
2590     push (@phony, 'all-multi', 'install-multi');
2593 # Worker for handle_dist.
2594 sub handle_dist_worker
2596     local ($makefile) = @_;
2598     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
2600     # Initialization; only at top level.
2601     if ($relative_dir eq '.')
2602     {
2603         if (defined $options{'check-news'})
2604         {
2605             # For Gnits users, this is pretty handy.  Look at 15 lines
2606             # in case some explanatory text is desirable.
2607             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
2608           echo "NEWS not updated; not releasing" 1>&2; \\
2609           exit 1; \\
2610         fi
2612         }
2615         # Create dist directory.
2616         $output_rules .= ("\t-chmod -R a+w \$(distdir) > /dev/null 2>&1; rm -rf \$(distdir)\n"
2617                           . "\tmkdir \$(distdir)\n");
2618     }
2620     # Scan EXTRA_DIST to see if we need to distribute anything from a
2621     # subdir.  If so, add it to the list.  I didn't want to do this
2622     # originally, but there were so many requests that I finally
2623     # relented.
2624     local (@dist_dirs);
2625     if (&variable_defined ('EXTRA_DIST'))
2626     {
2627         # FIXME: This should be fixed to work with conditionals.  That
2628         # will require only making the entries in @dist_dirs under the
2629         # appropriate condition.  This is meaningful if the nature of
2630         # the distribution should depend upon the configure options
2631         # used.
2632         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
2633         {
2634             next if /^\@.*\@$/;
2635             next unless s,/+[^/]+$,,;
2636             push (@dist_dirs, $_)
2637                 unless $_ eq '.';
2638         }
2639     }
2641     # We have to check DIST_COMMON for extra directories in case the
2642     # user put a source used in AC_OUTPUT into a subdir.
2643     foreach (&variable_value_as_list ('DIST_COMMON', 'all'))
2644     {
2645         next if /^\@.*\@$/;
2646         next unless s,/+[^/]+$,,;
2647         push (@dist_dirs, $_)
2648             unless $_ eq '.';
2649     }
2651     if (@dist_dirs)
2652     {
2653         # Prepend $(distdir) to each directory given.  Doing it via a
2654         # hash lets us ensure that each directory is used only once.
2655         local (%dhash);
2656         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
2657         $output_rules .= "\t";
2658         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
2659     }
2661     # In loop, test for file existence because sometimes a file gets
2662     # included in DISTFILES twice.  For example this happens when a
2663     # single source file is used in building more than one program.
2664     # Also, there are situations in which "ln" can fail.  For instance
2665     # a file to distribute could actually be a cross-filesystem
2666     # symlink -- this can easily happen if "gettextize" was run on the
2667     # distribution.
2668     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
2669     if ($cygnus_mode)
2670     {
2671         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
2672     }
2673     else
2674     {
2675         $output_rules .= "\t  d=\$(srcdir); \\\n";
2676     }
2677     $output_rules .= ("\t  if test -d \$\$d/\$\$file; then \\\n"
2678                       # Don't mention $$file in destination argument,
2679                       # since this fails if destination directory
2680                       # already exists.  Also, use `-R' and not `-r'.
2681                       # `-r' is almost always incorrect.
2682                       . "\t    cp -pR \$\$d/\$\$file \$(distdir) \\\n"
2683                       . "\t    || exit 1; \\\n"
2684                       . "\t  else \\\n"
2685                       . "\t    test -f \$(distdir)/\$\$file \\\n"
2686                       . "\t    || cp -p \$\$d/\$\$file \$(distdir)/\$\$file \\\n"
2687                       . "\t    || exit 1; \\\n"
2688                       . "\t  fi; \\\n"
2689                       . "\tdone\n");
2691     # If we have SUBDIRS, create all dist subdirectories and do
2692     # recursive build.
2693     if (&variable_defined ('SUBDIRS'))
2694     {
2695         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
2696         # to all possible directories, and use it.  If DIST_SUBDIRS is
2697         # defined, just use it.
2698         local ($dist_subdir_name);
2699         if (&variable_conditions ('SUBDIRS')
2700             || &variable_defined ('DIST_SUBDIRS'))
2701         {
2702             $dist_subdir_name = 'DIST_SUBDIRS';
2703             if (! &variable_defined ('DIST_SUBDIRS'))
2704             {
2705                 local (@full_list) = &variable_value_as_list ('SUBDIRS',
2706                                                               'all');
2707                 local (@ds_list, %uniq, $iter);
2708                 foreach $iter (@full_list)
2709                 {
2710                     if (! defined $uniq{$iter})
2711                     {
2712                         $uniq{$iter} = 1;
2713                         push (@ds_list, $iter);
2714                     }
2715                 }
2716                 &define_pretty_variable ('DIST_SUBDIRS', '', @ds_list);
2717             }
2718         }
2719         else
2720         {
2721             $dist_subdir_name = 'SUBDIRS';
2722         }
2724         # Test for directory existence here because previous automake
2725         # invocation might have created some directories.  Note that
2726         # we explicitly set distdir for the subdir make; that lets us
2727         # mix-n-match many automake-using packages into one large
2728         # package, and have "dist" at the top level do the right
2729         # thing.  If we're in the topmost directory, then we use
2730         # `distdir' instead of `top_distdir'; this lets us work
2731         # correctly with an enclosing package.
2732         $output_rules .=
2733             ("\t" . 'for subdir in $(' . $dist_subdir_name . '); do ' . "\\\n"
2734              . "\t" . '  if test "$$subdir" = .; then :; else ' . "\\\n"
2735              . "\t" . '    test -d $(distdir)/$$subdir ' . "\\\n"
2736              . "\t" . '    || mkdir $(distdir)/$$subdir ' . "\\\n"
2737              . "\t" . '    || exit 1; ' . "\\\n"
2738              . "\t" . '    (cd $$subdir'
2739              . ' && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$('
2740              . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
2741              . ') distdir=../$(distdir)/$$subdir distdir) ' . "\\\n"
2742              . "\t" . '      || exit 1; ' . "\\\n"
2743              . "\t" . '  fi; ' . "\\\n"
2744              . "\tdone\n");
2745     }
2747     # If the target `dist-hook' exists, make sure it is run.  This
2748     # allows users to do random weird things to the distribution
2749     # before it is packaged up.
2750     push (@dist_targets, 'dist-hook') if &target_defined ('dist-hook');
2752     local ($targ);
2753     foreach $targ (@dist_targets)
2754     {
2755         # We must explicitly set distdir and top_distdir for these
2756         # sub-makes.
2757         $output_rules .= ("\t\$(MAKE) \$(AM_MAKEFLAGS)"
2758                           . " top_distdir=\"\$(top_distdir)\""
2759                           . " distdir=\"\$(distdir)\" $targ\n");
2760     }
2762     push (@phony, 'distdir');
2765 # Handle 'dist' target.
2766 sub handle_dist
2768     local ($makefile) = @_;
2770     # Set up maint_charset.
2771     $local_maint_charset = &variable_value ('MAINT_CHARSET')
2772         if &variable_defined ('MAINT_CHARSET');
2773     $maint_charset = $local_maint_charset
2774         if $relative_dir eq '.';
2776     if (&variable_defined ('DIST_CHARSET'))
2777     {
2778         &am_line_error ('DIST_CHARSET',
2779                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2780             if ! $local_maint_charset;
2781         if ($relative_dir eq '.')
2782         {
2783             $dist_charset = &variable_value ('DIST_CHARSET')
2784         }
2785         else
2786         {
2787             &am_line_error ('DIST_CHARSET',
2788                             "DIST_CHARSET can only be defined at top level");
2789         }
2790     }
2792     # Look for common files that should be included in distribution.
2793     local ($cfile);
2794     foreach $cfile (@common_files)
2795     {
2796         if (-f ($relative_dir . "/" . $cfile))
2797         {
2798             &push_dist_common ($cfile);
2799         }
2800     }
2802     # Always require configure.in and configure at top level, even if
2803     # they don't exist.  This is especially important for configure,
2804     # since it won't be created until autoconf is run -- which might
2805     # be after automake is run.
2806     &push_dist_common ('configure.in', 'configure')
2807         if $relative_dir eq '.';
2809     # We might copy elements from %configure_dist_common to
2810     # %dist_common if we think we need to.  If the file appears in our
2811     # directory, we would have discovered it already, so we don't
2812     # check that.  But if the file is in a subdir without a Makefile,
2813     # we want to distribute it here if we are doing `.'.  Ugly!
2814     if ($relative_dir eq '.')
2815     {
2816         local ($iter);
2817         foreach $iter (keys %configure_dist_common)
2818         {
2819             if (! &is_make_dir (&dirname ($iter)))
2820             {
2821                 &push_dist_common ($iter);
2822             }
2823         }
2824     }
2826     # Keys of %dist_common are names of files to distributed.  We put
2827     # README first because it then becomes easier to make a
2828     # Usenet-compliant shar file (in these, README must be first).
2829     # FIXME: do more ordering of files here.
2830     local (@coms);
2831     if (defined $dist_common{'README'})
2832     {
2833         push (@coms, 'README');
2834         delete $dist_common{'README'};
2835     }
2836     push (@coms, sort keys %dist_common);
2838     # Now that we've processed %dist_common, disallow further attempts
2839     # to set it.
2840     $handle_dist_run = 1;
2842     &define_pretty_variable ("DIST_COMMON", '', @coms);
2843     $output_vars .= "\n";
2845     # Some boilerplate.
2846     $output_vars .= &file_contents ('dist-vars') . "\n";
2847     &define_variable ('GZIP_ENV', '--best');
2849     # Put these things in rules section so it is easier for whoever
2850     # reads Makefile.in.
2851     if (! &variable_defined ('distdir'))
2852     {
2853         if ($relative_dir eq '.')
2854         {
2855             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2856         }
2857         else
2858         {
2859             $output_rules .= ("\n"
2860                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2861                               . "\n");
2862         }
2863     }
2864     if ($relative_dir eq '.')
2865     {
2866         $output_rules .= "top_distdir = \$(distdir)\n";
2867     }
2868     $output_rules .= "\n";
2870     # Generate 'dist' target, and maybe other dist targets.
2871     if ($relative_dir eq '.')
2872     {
2873         # Rule to check whether a distribution is viable.
2874         local ($xform) = '';
2876         if (&target_defined ('distcheck-hook'))
2877         {
2878             $xform .= 's/^DISTHOOK//;';
2879         }
2880         else
2881         {
2882             $xform .= 's/^DISTHOOK.*$//;';
2883         }
2884         if ($seen_gettext)
2885         {
2886             $xform .= 's/^GETTEXT//;';
2887         }
2888         else
2889         {
2890             $xform .= 's/^GETTEXT.*$//;';
2891         }
2893         $output_rules .= &file_contents_with_transform ($xform, 'dist');
2895         local ($dist_all) = ('dist-all: distdir' . "\n"
2896                              . $dist_header);
2897         local ($curs);
2898         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ',
2899                        'dist-bzip2')
2900         {
2901             if (defined $options{$curs} || $curs eq 'dist')
2902             {
2903                 $output_rules .= ($curs . ': distdir' . "\n"
2904                                   . $dist_header
2905                                   . $dist{$curs}
2906                                   . $dist_trailer);
2907                 $dist_all .= $dist{$curs};
2908             }
2909         }
2910         $output_rules .= $dist_all . $dist_trailer;
2911     }
2913     # Generate distdir target.
2914     &handle_dist_worker ($makefile);
2917 # A subroutine of handle_dependencies.  This function includes
2918 # `depend2' with appropriate transformations.
2919 sub add_depend2
2921     local ($lang) = @_;
2923     # First include code for ordinary objects.
2924     local ($key) = $lang . '-autodep';
2925     local ($xform, $ext);
2927     local ($pfx) = $language_map{$key};
2928     local ($fpfx) = ($pfx eq '') ? 'CC' : $pfx;
2929     $xform = ('s/\@PFX\@/' . $pfx . '/g;'
2930               . 's/\@FPFX\@/' . $fpfx . '/g;'
2931               . ($seen_objext ? 's/^OBJEXT//;' : 's/^OBJEXT.*$//;')
2932               . ($seen_libtool ? 's/^LIBTOOL//;' : 's/^LIBTOOL.*$//;'));
2934     # This function can be called even when we don't want dependency
2935     # tracking.  This happens when we need an explicit rule for some
2936     # target.  In this case we don't want to include the generic code.
2937     if ($use_dependencies)
2938     {
2939         local ($xform1) = ($xform
2940                            . 's/\@BASE\@/\$\*/g;'
2941                            . 's/\@SOURCE\@/\$\</g;'
2942                            . 's/\@(LT|OBJ)?OBJ\@/\$\@/g;');
2944         foreach $ext (&lang_extensions ($lang))
2945         {
2946             $output_rules .= (&file_contents_with_transform ('s/\@EXT\@/'
2947                                                              . $ext . '/g;'
2948                                                              . $xform1,
2949                                                              'depend2')
2950                               . "\n");
2951         }
2952     }
2954     # Now include code for each specially handled object with this
2955     # language.
2956     local (@list) = grep ($_ ne '', split (' ', $lang_specific_files{$lang}));
2957     local ($max) = scalar @list;
2958     local ($i) = 0;
2959     local ($derived, $source, $obj);
2961     # If dependency tracking is disabled, we just elide the code.
2962     if (! $use_dependencies)
2963     {
2964         $xform .= 's/\@AMDEP\@.*$//;';
2965     }
2967     while ($i < $max)
2968     {
2969         $derived = $list[$i];
2970         ($source = $list[$i + 1]) =~ s,([/\$]),\\$1,g;
2971         ($obj = $list[$i + 2]) =~ s,([/\$]),\\$1,g;
2972         $i += 3;
2974         local ($flag) = $language_map{$lang . '-flags'};
2975         local ($val) = "(${derived}_${flag}";
2976         ($rule = $language_map{$lang . '-compile'}) =~
2977             s/\(AM_$flag/$val/;
2979         $rule =~ s,([/\$]),\\$1,g;
2981         # Generate a transform which will turn suffix targets in
2982         # depend2.am into real targets for the particular objects we
2983         # are building.
2984         $output_rules .=
2985             &file_contents_with_transform ($xform
2986                                            . 's/\$\(' . $pfx . 'COMPILE\)/'
2987                                            . $rule . '/g;'
2988                                            . 's/\$\(LT' . $pfx . 'COMPILE\)/'
2989                                            . '\$(LIBTOOL) --mode=compile '
2990                                            . $rule . '/g;'
2991                                            # Generate rule for `.o'.
2992                                            . 's/^\@EXT\@\.o:/'
2993                                            . $obj . '.o: ' . $source
2994                                            . '/g;'
2995                                            # Maybe generate rule for `.lo'.
2996                                            # Might be eliminated by
2997                                            # $XFORM.
2998                                            . 's/^\@EXT\@\.lo:/'
2999                                            . $obj . '.lo: ' . $source
3000                                            . '/g;'
3001                                            # Maybe generate rule for `.obj'.
3002                                            # Might be eliminated by
3003                                            # $XFORM.
3004                                            . 's/^\@EXT\@\.obj:/'
3005                                            . $obj . '.obj: ' . $source
3006                                            . '/g;'
3007                                            # Handle source and obj
3008                                            # transforms.
3009                                            . 's/\@OBJ\@/' . $obj . '.o/g;'
3010                                            . 's/\@OBJOBJ\@/' . $obj . '.obj/g;'
3011                                            . 's/\@LTOBJ\@/' . $obj . '.lo/g;'
3012                                            . 's/\@BASE\@/' . $obj . '/g;'
3013                                            . 's/\@SOURCE\@/' . $source . '/g;',
3014                                            'depend2');
3015     }
3018 # Handle auto-dependency code.
3019 sub handle_dependencies
3021     if ($use_dependencies)
3022     {
3023         # Include auto-dep code.  Don't include it if DEP_FILES would
3024         # be empty.
3025         if (&saw_sources_p (0) && keys %dep_files)
3026         {
3027             local ($config_aux_dir_specified) = ($config_aux_dir ne '.'
3028                                                  && $config_aux_dir ne '');
3030             # Set $require_file_found{'depcomp'} if the depcomp file exists,
3031             # before calling require_config_file on `depcomp'.  This makes
3032             # require_file_internal skip its buggy existence test that would
3033             # make automake fail (with `required file `lib/depcomp' not found')
3034             # when AC_CONFIG_AUX_DIR is not set.  See tests/subdir4.test.
3035             local ($depcomp_dir) = ($config_aux_dir_specified ? $config_aux_dir
3036                                     : '.');
3037             $require_file_found{'depcomp'} = 1 if -f "$depcomp_dir/depcomp";
3039             # Set location of depcomp.
3040             local ($prefix) = ($config_aux_dir_specified ? $config_aux_dir
3041                                : '$(top_srcdir)');
3043             &define_variable ('depcomp', "\$(SHELL) $prefix/depcomp");
3045             &require_config_file ($FOREIGN, 'depcomp');
3047             local ($iter);
3048             local (@deplist) = sort keys %dep_files;
3050             &define_pretty_variable ('DEP_FILES', '', ("\@AMDEP\@", @deplist));
3052             # Generate each `include' individually.  Irix 6 make will
3053             # not properly include several files resulting from a
3054             # variable expansion; generating many separate includes
3055             # seems safest.
3056             $output_rules .= "\n";
3057             foreach $iter (@deplist)
3058             {
3059                 $output_rules .= "\@AMDEP\@" . 'include ' . $iter . "\n";
3060             }
3062             $output_rules .= &file_contents ('depend');
3063             push (@clean, 'depend');
3064             &push_phony_cleaners ('depend');
3065         }
3066     }
3067     else
3068     {
3069         &define_variable ('depcomp', '');
3070     }
3072     local ($key, $lang, $ext, $xform);
3073     foreach $key (sort keys %language_map)
3074     {
3075         next unless $key =~ /^(.*)-autodep$/;
3076         next if $language_map{$key} eq 'no';
3077         &add_depend2 ($1);
3078     }
3081 # Handle subdirectories.
3082 sub handle_subdirs
3084     return if ! &variable_defined ('SUBDIRS');
3086     # Make sure each directory mentioned in SUBDIRS actually exists.
3087     local ($dir);
3088     foreach $dir (&variable_value_as_list ('SUBDIRS', 'all'))
3089     {
3090         # Skip directories substituted by configure.
3091         next if $dir =~ /^\@.*\@$/;
3093         if (! -d $am_relative_dir . '/' . $dir)
3094         {
3095             &am_line_error ('SUBDIRS',
3096                             "required directory $am_relative_dir/$dir does not exist");
3097             next;
3098         }
3100         &am_line_error ('SUBDIRS', "directory should not contain \`/'")
3101             if $dir =~ /\//;
3102     }
3104     local ($xform) = ('s/\@INSTALLINFO\@/' .
3105                       (defined $options{'no-installinfo'}
3106                        ? 'install-info-recursive'
3107                        : '')
3108                       . '/;');
3109     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
3111     # Push a bunch of phony targets.
3112     local ($phonies);
3113     foreach $phonies ('', '-data', '-exec', 'dirs')
3114     {
3115         push (@phony, 'install' . $phonies . '-recursive');
3116         push (@phony, 'uninstall' . $phonies . '-recursive');
3117     }
3118     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
3119     {
3120         push (@phony, $phonies . '-recursive');
3121     }
3122     &push_phony_cleaners ('recursive');
3124     $recursive_install = 1;
3127 # Handle aclocal.m4.
3128 sub handle_aclocal_m4
3130     local ($regen_aclocal) = 0;
3131     if (-f 'aclocal.m4')
3132     {
3133         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3134         &push_dist_common ('aclocal.m4');
3136         if (open (ACLOCAL, '< aclocal.m4'))
3137         {
3138             local ($line);
3139             $line = <ACLOCAL>;
3140             close (ACLOCAL);
3142             if ($line =~ 'generated automatically by aclocal')
3143             {
3144                 $regen_aclocal = 1;
3145             }
3146         }
3147     }
3149     local ($acinclude) = 0;
3150     if (-f 'acinclude.m4')
3151     {
3152         $regen_aclocal = 1;
3153         $acinclude = 1;
3154     }
3156     # Note that it might be possible that aclocal.m4 doesn't exist but
3157     # should be auto-generated.  This case probably isn't very
3158     # important.
3159     if ($regen_aclocal)
3160     {
3161         local (@ac_deps) = (
3162                             ($seen_maint_mode
3163                              ? "\@MAINTAINER_MODE_TRUE\@"
3164                              : "") ,
3165                             "configure.in",
3166                             ($acinclude ? ' acinclude.m4' : '')
3167                             );
3169         if (&variable_defined ('ACLOCAL_M4_SOURCES'))
3170         {
3171             push (@ac_deps, "\$(ACLOCAL_M4_SOURCES)");
3172         }
3173         elsif (&variable_defined ('ACLOCAL_AMFLAGS'))
3174         {
3175             # Scan all -I directories for m4 files.  These are our
3176             # dependencies.
3177             local ($examine_next, $amdir) = 0;
3178             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
3179             {
3180                 if ($examine_next)
3181                 {
3182                     $examine_next = 0;
3183                     if ($amdir !~ /^\// && -d $amdir)
3184                     {
3185                         foreach $ac_dep (&my_glob ($amdir . '/*.m4'))
3186                         {
3187                             $ac_dep =~ s/^\.\/*//;
3188                             push (@ac_deps, $ac_dep)
3189                                 unless $ac_dep eq "aclocal.m4"
3190                                     || $ac_dep eq "acinclude.m4";
3191                         }
3192                     }
3193                 }
3194                 elsif ($amdir eq '-I')
3195                 {
3196                     $examine_next = 1;
3197                 }
3198             }
3199         }
3201         &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
3203         $output_rules .=  ("\t"
3204                            . 'cd $(srcdir) && $(ACLOCAL)'
3205                            . (&variable_defined ('ACLOCAL_AMFLAGS')
3206                               ? ' $(ACLOCAL_AMFLAGS)' : '')
3207                            . "\n");
3208     }
3211 # Rewrite a list of input files into a form suitable to put on a
3212 # dependency list.  The idea is that if an input file has a directory
3213 # part the same as the current directory, then the directory part is
3214 # simply removed.  But if the directory part is different, then
3215 # $(top_srcdir) is prepended.  Among other things, this is used to
3216 # generate the dependency list for the output files generated by
3217 # AC_OUTPUT.  Consider what the dependencies should look like in this
3218 # case:
3219 #   AC_OUTPUT(src/out:src/in1:lib/in2)
3220 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3221 # If 0 then files that require this addition will simply be ignored.
3222 sub rewrite_inputs_into_dependencies
3224     local ($add_srcdir, @inputs) = @_;
3225     local ($single, @newinputs);
3227     foreach $single (@inputs)
3228     {
3229         if (&dirname ($single) eq $relative_dir)
3230         {
3231             push (@newinputs, &basename ($single));
3232         }
3233         elsif ($add_srcdir)
3234         {
3235             push (@newinputs, '$(top_srcdir)/' . $single);
3236         }
3237     }
3239     return @newinputs;
3242 # Handle remaking and configure stuff.
3243 # We need the name of the input file, to do proper remaking rules.
3244 sub handle_configure
3246     local ($local, $input, @secondary_inputs) = @_;
3248     local ($top_reldir);
3250     local ($input_base) = &basename ($input);
3251     local ($local_base) = &basename ($local);
3253     local ($amfile) = $input_base . '.am';
3254     # We know we can always add '.in' because it really should be an
3255     # error if the .in was missing originally.
3256     local ($infile) = '$(srcdir)/' . $input_base . '.in';
3257     local ($colon_infile);
3258     if ($local ne $input || @secondary_inputs)
3259     {
3260         $colon_infile = ':' . $input . '.in';
3261     }
3262     $colon_infile .= ':' . join (':', @secondary_inputs)
3263         if @secondary_inputs;
3265     local (@rewritten) = &rewrite_inputs_into_dependencies (1,
3266                                                             @secondary_inputs);
3268     # This rule remakes the Makefile.in.  Note use of
3269     # @MAINTAINER_MODE_TRUE@ forces us to abandon pretty-printing.
3270     # Sigh.
3271     $output_rules .= ($infile
3272                       # NOTE perl 5.003 (with -w) gives a
3273                       # uninitialized value error on the next line.
3274                       # Don't know why.
3275                       . ': '
3276                       . ($seen_maint_mode ? "\@MAINTAINER_MODE_TRUE\@ " : '')
3277                       . $amfile . ' '
3278                       . '$(top_srcdir)/configure.in $(ACLOCAL_M4)'
3279                       . ' ' . join (' ', @include_stack)
3280                       . "\n"
3281                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
3282                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
3283                       . ($cmdline_use_dependencies ? '' : ' --ignore-deps')
3284                       . ' ' . $input . $colon_infile . "\n\n");
3286     # This rule remakes the Makefile.
3287     $output_rules .= ($local_base
3288                       # NOTE: bogus uninit value error on next line;
3289                       # see comment above.
3290                       . ': '
3291                       . $infile . ' '
3292                       . join (' ', @rewritten)
3293                       . ' $(top_builddir)/config.status'
3294                       . "\n"
3295                       . "\tcd \$(top_builddir) \\\n"
3296                       . "\t  && CONFIG_FILES="
3297                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3298                       . $colon_infile
3299                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
3300                       . "\n\n");
3302     if ($relative_dir ne '.')
3303     {
3304         # In subdirectory.
3305         $top_reldir = '../';
3306     }
3307     else
3308     {
3309         &handle_aclocal_m4;
3310         $output_rules .= &file_contents ('remake');
3311         &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3312         &examine_variable ('CONFIGURE_DEPENDENCIES');
3313         $top_reldir = '';
3315         &push_dist_common ('acconfig.h')
3316             if -f 'acconfig.h';
3317     }
3319     # If we have a configure header, require it.
3320     local ($one_hdr);
3321     local (@local_fullnames) = @config_fullnames;
3322     local (@local_names) = @config_names;
3323     local ($hdr_index) = 0;
3324     local ($distclean_config) = '';
3325     foreach $one_hdr (@config_headers)
3326     {
3327         local ($one_fullname) = shift (@local_fullnames);
3328         local ($one_name) = shift (@local_names);
3329         $hdr_index += 1;
3330         local ($header_dir) = &dirname ($one_name);
3332         # If the header is in the current directory we want to build
3333         # the header here.  Otherwise, if we're at the topmost
3334         # directory and the header's directory doesn't have a
3335         # Makefile, then we also want to build the header.
3336         if ($relative_dir eq $header_dir
3337             || ($relative_dir eq '.' && ! &is_make_dir ($header_dir)))
3338         {
3339             local ($ch_sans_dir, $cn_sans_dir, $stamp_dir);
3340             if ($relative_dir eq $header_dir)
3341             {
3342                 $cn_sans_dir = &basename ($one_name);
3343                 $stamp_dir = '';
3344             }
3345             else
3346             {
3347                 $cn_sans_dir = $one_name;
3348                 if ($header_dir eq '.')
3349                 {
3350                     $stamp_dir = '';
3351                 }
3352                 else
3353                 {
3354                     $stamp_dir = $header_dir . '/';
3355                 }
3356             }
3358             # Compute relative path from directory holding output
3359             # header to directory holding input header.  FIXME:
3360             # doesn't handle case where we have multiple inputs.
3361             if (&dirname ($one_hdr) eq $relative_dir)
3362             {
3363                 $ch_sans_dir = &basename ($one_hdr);
3364             }
3365             else
3366             {
3367                 local (@rel_out_path);
3368                 # FIXME this chunk of code should be its own sub.
3369                 # It is used elsewhere.
3370                 foreach (split (/\//, $relative_dir))
3371                 {
3372                     next if $_ eq '' || $_ eq '.';
3373                     if ($_ eq '..')
3374                     {
3375                         # FIXME: actually this is an error.
3376                         pop @rel_out_path;
3377                     }
3378                     else
3379                     {
3380                         push (@rel_out_path, '..');
3381                     }
3382                 }
3383                 if (@rel_out_path)
3384                 {
3385                     $ch_sans_dir = join ('/', @rel_out_path) . '/' . $one_hdr;
3386                 }
3387                 else
3388                 {
3389                     $ch_sans_dir = $one_hdr;
3390                 }
3391             }
3393             &require_file_with_conf_line ($config_header_line,
3394                                           $FOREIGN, $ch_sans_dir);
3396             # Header defined and in this directory.
3397             local (@files);
3398             if (-f $one_name . '.top')
3399             {
3400                 push (@files, "${cn_sans_dir}.top");
3401             }
3402             if (-f $one_name . '.bot')
3403             {
3404                 push (@files, "${cn_sans_dir}.bot");
3405             }
3407             &push_dist_common (@files);
3409             # For now, acconfig.h can only appear in the top srcdir.
3410             if (-f 'acconfig.h')
3411             {
3412                 if ($relative_dir eq '.')
3413                 {
3414                     push (@files, 'acconfig.h');
3415                 }
3416                 else
3417                 {
3418                     # Strange quoting because this gets fed through
3419                     # Perl.
3420                     push (@files, '\$(top_srcdir)/acconfig.h');
3421                 }
3422             }
3424             local ($stamp_name) = 'stamp-h';
3425             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3427             local ($xform) = '';
3429             $xform = 's,\@FILES\@,' . join (' ', @files) . ',;';
3430             $xform .= 's,\@CONFIG_HEADER\@,' . "${cn_sans_dir}" . ',;';
3431             $xform .= 's,\@CONFIG_HEADER_IN\@,' . "${ch_sans_dir}" . ',;';
3432             $xform .= 's,\@CONFIG_HEADER_FULL\@,' . "${one_fullname}" . ',;';
3433             $xform .= 's,\@STAMP\@,' . "${stamp_dir}${stamp_name}" . ',g;';
3435             local ($out_dir) = &dirname ($ch_sans_dir);
3436             $xform .= 's,\@SRC_STAMP\@,' . "${out_dir}/${stamp_name}" . ',g;';
3437             $output_rules .= &file_contents_with_transform ($xform,
3438                                                             'remake-hdr');
3440             &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3441             &require_file_with_conf_line ($config_header_line, $FOREIGN,
3442                                           "${out_dir}/${stamp_name}.in");
3444             $distclean_config .= ' ' if $distclean_config;
3445             $distclean_config .= $cn_sans_dir;
3446         }
3447     }
3449     if ($distclean_config)
3450     {
3451         $output_rules .= &file_contents_with_transform ('s,\@FILES\@,'
3452                                                         . $distclean_config
3453                                                         . ',;',
3454                                                         'clean-hdr');
3455         push (@clean, 'hdr');
3456         &push_phony_cleaners ('hdr');
3457     }
3459     # Set location of mkinstalldirs.
3460     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
3461     {
3462         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
3463                                             . '/mkinstalldirs'));
3464     }
3465     else
3466     {
3467         &define_variable ('mkinstalldirs',
3468                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
3469     }
3471     &am_line_error ('CONFIG_HEADER',
3472                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
3473         if &variable_defined ('CONFIG_HEADER');
3475     local ($one_name);
3476     local ($config_header) = '';
3477     foreach $one_name (@config_names)
3478     {
3479         # Generate CONFIG_HEADER define.
3480         local ($one_hdr);
3481         if ($relative_dir eq &dirname ($one_name))
3482         {
3483             $one_hdr = &basename ($one_name);
3484         }
3485         else
3486         {
3487             $one_hdr = "${top_builddir}/${one_name}";
3488         }
3490         $config_header .= ' ' if $config_header;
3491         $config_header .= $one_hdr;
3492     }
3493     if ($config_header)
3494     {
3495         &define_variable ("CONFIG_HEADER", $config_header);
3496     }
3498     # Now look for other files in this directory which must be remade
3499     # by config.status, and generate rules for them.
3500     local (@actual_other_files) = ();
3501     local ($file, $local);
3502     local (@inputs, @rewritten_inputs, $single);
3503     local ($need_rewritten);
3504     foreach $file (@other_input_files)
3505     {
3506         if ($file =~ /^([^:]*):(.*)$/)
3507         {
3508             # This is the ":" syntax of AC_OUTPUT.
3509             $file = $1;
3510             $local = &basename ($file);
3511             @inputs = split (':', $2);
3512             @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3513             $need_rewritten = 1;
3514         }
3515         else
3516         {
3517             # Normal usage.
3518             $local = &basename ($file);
3519             @inputs = ($local . '.in');
3520             @rewritten_inputs =
3521                 &rewrite_inputs_into_dependencies (1, $file . '.in');
3522             $need_rewritten = 0;
3523         }
3525         # Skip files not in this directory.
3526         next unless &dirname ($file) eq $relative_dir;
3528         # Skip any file that is an automake input.
3529         next if -f $file . '.am';
3531         # Some users have been tempted to put `stamp-h' in the
3532         # AC_OUTPUT line.  This won't do the right thing, so we
3533         # explicitly fail here.
3534         if ($local eq 'stamp-h')
3535         {
3536             # FIXME: allow real filename.
3537             &am_conf_error ('configure.in', $ac_output_line,
3538                             'stamp-h should not appear in AC_OUTPUT');
3539             next;
3540         }
3542         $output_rules .= ($local . ': '
3543                           . '$(top_builddir)/config.status '
3544                           . join (' ', @rewritten_inputs) . "\n"
3545                           . "\t"
3546                           . 'cd $(top_builddir) && CONFIG_FILES='
3547                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3548                           . '$@' . ($need_rewritten
3549                                     ? (':' . join (':', @inputs))
3550                                     : '')
3551                           . ' CONFIG_HEADERS= $(SHELL) ./config.status'
3552                           . "\n");
3553         &push_dist_common (@inputs);
3554         push (@actual_other_files, $local);
3556         # Require all input files.
3557         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3558                                       &rewrite_inputs_into_dependencies (0, @inputs));
3559     }
3561     # These files get removed by "make clean".
3562     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3565 # Handle C headers.
3566 sub handle_headers
3568     local (@r);
3569     @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3570                           'oldinclude', 'pkginclude',
3571                           'noinst', 'check');
3572     foreach (@r)
3573     {
3574         next unless /\.(.*)$/;
3575         &saw_extension ($1);
3576     }
3579 sub handle_gettext
3581     return if ! $seen_gettext || $relative_dir ne '.';
3583     if (! &variable_defined ('SUBDIRS'))
3584     {
3585         &am_conf_error
3586             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
3587         return;
3588     }
3590     &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3592     if (&variable_defined ('SUBDIRS'))
3593     {
3594         &am_line_error
3595             ('SUBDIRS',
3596              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
3597                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
3598         &am_line_error
3599             ('SUBDIRS',
3600              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
3601                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
3602     }
3604     # Ensure that each language in ALL_LINGUAS has a .po file, and
3605     # each po file is mentioned in ALL_LINGUAS.
3606     if ($seen_linguas)
3607     {
3608         local (%linguas) = ();
3609         grep ($linguas{$_} = 1, split (' ', $all_linguas));
3611         foreach (<po/*.po>)
3612         {
3613             s/^po\///;
3614             s/\.po$//;
3616             &am_line_error ($all_linguas_line,
3617                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
3618                 if ! $linguas{$_};
3619         }
3621         foreach (keys %linguas)
3622         {
3623             &am_line_error ($all_linguas_line,
3624                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
3625                 if ! -f "po/$_.po";
3626         }
3627     }
3628     else
3629     {
3630         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
3631     }
3634 # Handle footer elements.
3635 sub handle_footer
3637     if ($contents{'SOURCES'})
3638     {
3639         # NOTE don't use define_pretty_variable here, because
3640         # $contents{...} is already defined.
3641         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
3642     }
3643     if ($contents{'OBJECTS'})
3644     {
3645         # NOTE don't use define_pretty_variable here, because
3646         # $contents{...} is already defined.
3647         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
3648     }
3649     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
3650     {
3651         $output_vars .= "\n";
3652     }
3654     if (&target_defined ('.SUFFIXES'))
3655     {
3656         &am_line_error ('.SUFFIXES',
3657                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
3658     }
3660     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3661     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3662     # anything else, by sticking it right after the default: target.
3663     $output_header .= ".SUFFIXES:\n";
3664     if (@suffixes || &variable_defined ('SUFFIXES'))
3665     {
3666         # Make sure suffixes has unique elements.  Sort them to ensure
3667         # the output remains consistent.  However, $(SUFFIXES) is
3668         # always at the start of the list, unsorted.  This is done
3669         # because make will choose rules depending on the ordering of
3670         # suffixes, and this lets the user have some control.  Push
3671         # actual suffixes, and not $(SUFFIXES).  Some versions of make
3672         # do not like variable substitutions on the .SUFFIXES line.
3673         local (%suffixes);
3674         local (@user_suffixes) = (&variable_defined ('SUFFIXES')
3675                                   ? &variable_value_as_list ('SUFFIXES', '')
3676                                   : ());
3678         grep ($suffixes{$_} = 1, @suffixes);
3679         delete @suffixes{@user_suffixes};
3681         $output_header .= (".SUFFIXES: "
3682                            . join (' ', @user_suffixes, sort keys %suffixes)
3683                            . "\n");
3684     }
3685     $output_trailer .= &file_contents ('footer');
3688 # Deal with installdirs target.
3689 sub handle_installdirs
3691     # GNU Makefile standards recommend this.
3692     if ($recursive_install)
3693     {
3694         # We create a separate `-am' target so that the -recursive
3695         # rule will work correctly.
3696         $output_rules .= ("installdirs: installdirs-recursive\n"
3697                           . "installdirs-am:\n");
3698         push (@phony, 'installdirs-am');
3699     }
3700     else
3701     {
3702         $output_rules .= "installdirs:\n";
3703     }
3704     push (@phony, 'installdirs');
3705     if (@installdirs)
3706     {
3707         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
3708                             @installdirs);
3709     }
3710     $output_rules .= "\n";
3713 # There are several targets which need to be merged.  This is because
3714 # their complete definition is compiled from many parts.  Note that we
3715 # avoid double colon rules, otherwise we'd use them instead.
3716 sub handle_merge_targets
3718     local ($makefile) = @_;
3720     # There are a few install-related variables that you should not define.
3721     local ($var);
3722     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
3723     {
3724         if (&variable_defined ($var))
3725         {
3726             &am_line_error ($var, "\`$var' should not be defined");
3727         }
3728     }
3730     # Put this at the beginning for the sake of non-GNU makes.  This
3731     # is still wrong if these makes can run parallel jobs.  But it is
3732     # right enough.
3733     unshift (@all, &basename ($makefile));
3735     local ($one_name);
3736     foreach $one_name (@config_names)
3737     {
3738         push (@all, &basename ($one_name))
3739             if &dirname ($one_name) eq $relative_dir;
3740     }
3742     &do_one_merge_target ('info', @info);
3743     &do_one_merge_target ('dvi', @dvi);
3744     &do_check_merge_target;
3745     &do_one_merge_target ('installcheck', @installcheck);
3747     if (defined $options{'no-installinfo'})
3748     {
3749         &do_one_merge_target ('install-info', '');
3750     }
3751     elsif (&target_defined ('install-info-local'))
3752     {
3753         &am_line_error ('install-info-local',
3754                         "\`install-info-local' target defined but \`no-installinfo' option not in use");
3755     }
3757     local ($utarg);
3758     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3759                     'uninstall-exec-local', 'uninstall-exec-hook')
3760     {
3761         if (&target_defined ($utarg))
3762         {
3763             local ($x);
3764             ($x = $utarg) =~ s/(data|exec)-//;
3765             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3766         }
3767     }
3769     if (&target_defined ('install-local'))
3770     {
3771         &am_line_error ('install-local',
3772                         "use \`install-data-local' or \`install-exec-local', not \`install-local'");
3773     }
3775     if (@all || &variable_defined ('BUILT_SOURCES'))
3776     {
3777         local ($one_name);
3778         local ($local_headers) = '';
3779         $local_headers = '$(BUILT_SOURCES)'
3780             if &variable_defined ('BUILT_SOURCES');
3781         foreach $one_name (@config_names)
3782         {
3783             if (&dirname ($one_name) eq $relative_dir)
3784             {
3785                 $local_headers .= ' ' if $local_headers;
3786                 $local_headers .= &basename ($one_name);
3787             }
3788         }
3789         if ($local_headers)
3790         {
3791             # This is kind of a hack, but I couldn't see a better way
3792             # to handle it.  In this particular case, we need to make
3793             # sure config.h is built before we recurse.  We can't do
3794             # this by changing the order of dependencies to the "all"
3795             # because that breaks when using parallel makes.  Instead
3796             # we handle things explicitly.
3797             $output_rules .= ("all-recursive-am: ${local_headers}"
3798                                   . "\n\t"
3799                                   . '$(MAKE) $(AM_MAKEFLAGS)'
3800                                   . " all-recursive"
3801                                   . "\n\n");
3802             $all_target = 'all-recursive-am';
3803             push (@phony, 'all-recursive-am');
3804         }
3805     }
3807     if (&variable_defined('lib_LTLIBRARIES') && 
3808         &variable_defined('bin_PROGRAMS'))
3809     {
3810         $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
3811     }
3812     # Print definitions users can use.
3813     &do_one_merge_target ('install-exec', @install_exec);
3814     $output_rules .= "\n";
3816     &do_one_merge_target ('install-data', @install_data);
3817     $output_rules .= "\n";
3819     &do_one_merge_target ('install', 'all-am');
3820     &do_one_merge_target ('uninstall', @uninstall);
3822     &do_one_merge_target ('all', @all);
3824     # Generate the new 'install-strip' target.  We can't just set
3825     # INSTALL_PROGRAM because that might be a relative path.
3826     $output_rules .= ("install-strip:\n\t"
3827                       . '$(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install'
3828                       . "\n");
3829     push (@phony, 'install-strip');
3832 # Helper for handle_merge_targets.  Note that handle_merge_targets
3833 # relies on the fact that this doesn't add an extra \n at the end.
3834 sub do_one_merge_target
3836     local ($name, @values) = @_;
3838     if (&target_defined ($name . '-local'))
3839     {
3840         # User defined local form of target.  So include it.
3841         push (@values, $name . '-local');
3842         push (@phony, $name . '-local');
3843     }
3845     &pretty_print_rule ($name . "-am:", "\t\t", @values);
3846     if ($name eq 'install')
3847     {
3848         # Special-case `install-am' to run install-exec-am and
3849         # install-data-am after all-am is built.
3850         &pretty_print_rule ("\t\@\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3851                             'install-exec-am', 'install-data-am');
3852     }
3853     elsif ($name eq 'install-exec' && &target_defined ('install-exec-hook'))
3854     {
3855         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3856                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-exec-hook'
3857                           . "\n");
3858     }
3859     elsif ($name eq 'install-data' && &target_defined ('install-data-hook'))
3860     {
3861         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3862                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-data-hook'
3863                           . "\n");
3864     }
3866     local ($lname) = $name . ($recursive_install ? '-recursive' : '-am');
3867     local ($tname) = $name;
3868     # To understand this special case, see handle_merge_targets.
3869     if ($name eq 'all')
3870     {
3871         $tname = 'all-redirect';
3872         $lname = $all_target if $recursive_install;
3873         push (@phony, 'all-redirect');
3874         $output_all = "all: all-redirect\n";
3875     }
3876     &pretty_print_rule ($tname . ":", "\t\t", $lname);
3877     push (@phony, $name . '-am', $name);
3880 # Handle check merge target specially.
3881 sub do_check_merge_target
3883     if (&target_defined ('check-local'))
3884     {
3885         # User defined local form of target.  So include it.
3886         push (@check_tests, 'check-local');
3887         push (@phony, 'check-local');
3888     }
3890     # In --cygnus mode, check doesn't depend on all.
3891     if ($cygnus_mode)
3892     {
3893         # Just run the local check rules.
3894         &pretty_print_rule ('check-am:', "\t\t", @check);
3895     }
3896     else
3897     {
3898         # The check target must depend on the local equivalent of
3899         # `all', to ensure all the primary targets are built.  Then it
3900         # must build the local check rules.
3901         $output_rules .= "check-am: all-am\n";
3902         &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3903                             @check)
3904             if @check;
3905     }
3906     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3907                         @check_tests)
3908         if @check_tests;
3910     push (@phony, 'check', 'check-am');
3911     $output_rules .= ("check: "
3912                       . ($recursive_install ? 'check-recursive' : 'check-am')
3913                       . "\n");
3916 # Handle all 'clean' targets.
3917 sub handle_clean
3919     local ($xform) = '';
3920     local ($name);
3922     # Don't include `MAINTAINER'; it is handled specially below.
3923     foreach $name ('MOSTLY', '', 'DIST')
3924     {
3925         if (! &variable_defined ($name . 'CLEANFILES'))
3926         {
3927             $xform .= 's/^' . $name . 'CLEAN.*$//;';
3928         }
3929         else
3930         {
3931             $xform .= 's/^' . $name . 'CLEAN//;';
3932         }
3933     }
3935     # Built sources are automatically removed by maintainer-clean.
3936     push (@maintainer_clean_files, '\$(BUILT_SOURCES)')
3937         if &variable_defined ('BUILT_SOURCES');
3938     push (@maintainer_clean_files, '\$(MAINTAINERCLEANFILES)')
3939         if &variable_defined ('MAINTAINERCLEANFILES');
3940     if (! @maintainer_clean_files)
3941     {
3942         $xform .= 's/^MAINTAINERCLEAN.*$//;';
3943     }
3944     else
3945     {
3946         $xform .= ('s/^MAINTAINERCLEAN//;'
3947                    # Join with no space to avoid spurious `test -z'
3948                    # success at runtime.
3949                    . 's,\@MCFILES\@,' . join ('', @maintainer_clean_files)
3950                    . ',;'
3951                    # A space is required in the join here.
3952                    . 's,\@MFILES\@,' . join (' ', @maintainer_clean_files)
3953                    . ',;');
3954     }
3956     $output_rules .= &file_contents_with_transform ($xform, 'clean');
3958     push (@clean, 'generic');
3959     &push_phony_cleaners ('generic');
3961     &do_one_clean_target ('clean', 'mostly', '', @clean);
3962     &do_one_clean_target ('clean', '', 'mostly', @clean);
3963     &do_one_clean_target ('clean', 'dist', '', @clean);
3964     &do_one_clean_target ('clean', 'maintainer-', 'dist', @clean);
3966     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
3969 # Helper for handle_clean.
3970 sub do_one_clean_target
3972     local ($target, $name, $last_name, @deps) = @_;
3974     # Change each dependency `BLARG' into `clean-BLARG'.
3975     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
3977     # Push the previous clean target.  There is no previous clean
3978     # target if we're doing mostlyclean.
3979     push (@deps, $last_name . $target . '-am')
3980         unless $name eq 'mostly';
3982     # If a -local version of the rule is given, add it to the list.
3983     if (&target_defined ($name . $target . '-local'))
3984     {
3985         push (@deps, $name . $target . '-local');
3986     }
3988     # Print the target and the dependencies.
3989     &pretty_print_rule ($name . $target . "-am: ", "\t\t", @deps);
3991     # FIXME: shouldn't we really print these messages before running
3992     # the dependencies?
3993     if ($name . $target eq 'maintainer-clean')
3994     {
3995         # Print a special warning.
3996         $output_rules .=
3997             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
3998              . "\t\@echo \"it deletes files that may require special "
3999              . "tools to rebuild.\"\n");
4000     }
4001     elsif ($name . $target eq 'distclean')
4002     {
4003         $output_rules .= "\t-rm -f libtool\n" if $seen_libtool;
4004     }
4005     $output_rules .= "\n";
4007     # Now generate the actual clean target.
4008     $output_rules .= ($name . $target . ": " . $name . $target
4009                       . ($recursive_install ? '-recursive' : '-am')
4010                       . "\n");
4012     # We special-case config.status here.  If we do it as part of the
4013     # normal clean processing for this directory, then it might be
4014     # removed before some subdir is cleaned.  However, that subdir's
4015     # Makefile depends on config.status.
4016     if (($name . $target eq 'maintainer-clean'
4017          || $name . $target eq 'distclean')
4018         && $relative_dir eq '.')
4019     {
4020         $output_rules .= "\t-rm -f config.status\n";
4021     }
4022     $output_rules .= "\n";
4025 # Handle .PHONY target.
4026 sub handle_phony
4028     &pretty_print_rule ('.PHONY:', "", @phony);
4029     $output_rules .= "\n";
4032 # Handle TESTS variable and other checks.
4033 sub handle_tests
4035     if (defined $options{'dejagnu'})
4036     {
4037         push (@check_tests, 'check-DEJAGNU');
4038         push (@phony, 'check-DEJAGNU');
4040         local ($xform);
4041         if ($cygnus_mode)
4042         {
4043             $xform = 's/^CYGNUS//;';
4044         }
4045         else
4046         {
4047             $xform = 's/^CYGNUS.*$//;';
4048         }
4049         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
4051         # In Cygnus mode, these are found in the build tree.
4052         # Otherwise they are looked for in $PATH.
4053         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
4054         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
4056         # Only create site.exp rule if user hasn't already written
4057         # one.
4058         if (! &target_defined ('site.exp'))
4059         {
4060             # Note that in the rule we don't directly generate
4061             # site.exp to avoid the possibility of a corrupted
4062             # site.exp if make is interrupted.  Jim Meyering has some
4063             # useful text on this topic.
4064             $output_rules .= ("site.exp: Makefile\n"
4065                               . "\t\@echo 'Making a new site.exp file...'\n"
4066                               . "\t\@test ! -f site.bak || rm -f site.bak\n"
4067                               . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
4068                               . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
4069                               . "\t\@echo '# edit the last section' >> \$\@-t\n"
4070                               . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
4071                               . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
4072                               . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
4074             # Extra stuff for AC_CANONICAL_*
4075             local (@whatlist) = ();
4076             if ($seen_canonical)
4077             {
4078                 push (@whatlist, 'host');
4079             }
4081             # Extra stuff only for AC_CANONICAL_SYSTEM.
4082             if ($seen_canonical == $AC_CANONICAL_SYSTEM)
4083             {
4084                 push (@whatlist, 'target', 'build');
4085             }
4087             local ($c1, $c2);
4088             foreach $c1 (@whatlist)
4089             {
4090                 foreach $c2 ('alias', 'triplet')
4091                 {
4092                     $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
4093                 }
4094             }
4096             $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
4097                               . "\t\@test ! -f site.exp || sed '1,/^## All variables above are.*##/ d' site.exp >> \$\@-t\n"
4098                               . "\t\@test ! -f site.exp || mv site.exp site.bak\n"
4099                               . "\t\@mv \$\@-t site.exp\n");
4100         }
4101     }
4102     else
4103     {
4104         local ($c);
4105         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4106         {
4107             if (&variable_defined ($c))
4108             {
4109                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
4110             }
4111         }
4112     }
4114     if (&variable_defined ('TESTS'))
4115     {
4116         push (@check_tests, 'check-TESTS');
4117         push (@phony, 'check-TESTS');
4119         # Note: Solaris 2.7 seems to expand TESTS using VPATH.  That's
4120         # why we also try `dir='
4121         $output_rules .= 'check-TESTS: $(TESTS)
4122         @failed=0; all=0; xfail=0; xpass=0; \\
4123         srcdir=$(srcdir); export srcdir; \\
4124         list=' . "'\$(TESTS)'; \\" . '
4125         if test -n "$$list"; then \\
4126           for tst in $$list; do \\
4127             if test -f ./$$tst; then dir=./; \\
4128             elif test -f $$tst; then dir=; \\
4129             else dir="$(srcdir)/"; fi; \\
4130             if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \\
4131               all=`expr $$all + 1`; \\
4132               case " $(XFAIL_TESTS) " in \\
4133               *" $$tst "*) \\
4134                 xpass=`expr $$xpass + 1`; \\
4135                 failed=`expr $$failed + 1`; \\
4136                 echo "XPASS: $$tst"; \\
4137               ;; \\
4138               *) \\
4139                 echo "PASS: $$tst"; \\
4140               ;; \\
4141               esac; \\
4142             elif test $$? -ne 77; then \\
4143               all=`expr $$all + 1`; \\
4144               case " $(XFAIL_TESTS) " in \\
4145               *" $$tst "*) \\
4146                 xfail=`expr $$xfail + 1`; \\
4147                 echo "XFAIL: $$tst"; \\
4148               ;; \\
4149               *) \\
4150                 failed=`expr $$failed + 1`; \\
4151                 echo "FAIL: $$tst"; \\
4152               ;; \\
4153               esac; \\
4154             fi; \\
4155           done; \\
4156           if test "$$failed" -eq 0; then \\
4157             if test "$$xfail" -eq 0; then \\
4158               banner="All $$all tests passed"; \\
4159             else \\
4160               banner="All $$all tests behaved as expected ($$xfail expected failures)"; \\
4161             fi; \\
4162           else \\
4163             if test "$$xpass" -eq 0; then \\
4164               banner="$$failed of $$all tests failed"; \\
4165             else \\
4166               banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \\
4167             fi; \\
4168           fi; \\
4169           dashes=`echo "$$banner" | sed s/./=/g`; \\
4170           echo "$$dashes"; \\
4171           echo "$$banner"; \\
4172           echo "$$dashes"; \\
4173           test "$$failed" -eq 0; \\
4174         fi
4176     }
4179 # Handle Emacs Lisp.
4180 sub handle_emacs_lisp
4182     local (@elfiles) = &am_install_var ('-candist', 'lisp', 'LISP',
4183                                         'lisp', 'noinst');
4185     if (@elfiles)
4186     {
4187         # Found some lisp.
4188         &define_configure_variable ('lispdir');
4189         &define_configure_variable ('EMACS');
4190         $output_rules .= (".el.elc:\n"
4191                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
4192                           . "\tif test \$(EMACS) != no; then \\\n"
4193                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
4194                           . "\tfi\n");
4195         push (@suffixes, '.el', '.elc');
4197         # Generate .elc files.
4198         grep ($_ .= 'c', @elfiles);
4199         &define_pretty_variable ('ELCFILES', '', @elfiles);
4201         $output_rules .= &file_contents ('lisp-clean');
4202         push (@clean, 'lisp');
4203         &push_phony_cleaners ('lisp');
4205         push (@all, '$(ELCFILES)');
4207         local ($varname);
4208         if (&variable_defined ('lisp_LISP'))
4209         {
4210             $varname = 'lisp_LISP';
4211             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
4212                 if ! $seen_lispdir;
4213         }
4214         else
4215         {
4216             $varname = 'noinst_LISP';
4217         }
4219         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
4220     }
4223 # Handle Python
4224 sub handle_python
4226     local (@pyfiles) = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4227                                         'python', 'noinst');
4228     return if ! @pyfiles;
4230     # Found some python.
4231     &define_configure_variable ('pythondir');
4232     &define_configure_variable ('PYTHON');
4234     $output_rules .= &file_contents ('python-clean');
4235     push (@clean, 'python');
4237     &am_error ("\`python_PYTHON' defined but \`AM_CHECK_PYTHON' not in \`configure.in'")
4238         if ! $seen_pythondir && &variable_defined ('python_PYTHON');
4240     if ($config_aux_dir eq '.' || $config_aux_dir eq '')
4241     {
4242         &define_variable ('py_compile', '$(top_srcdir)/py-compile');
4243     }
4244     else
4245     {
4246         &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4247     }
4250 # Handle Java.
4251 sub handle_java
4253     local (@sourcelist) = &am_install_var ('-candist', '-clean',
4254                                            'java', 'JAVA',
4255                                            'java', 'noinst', 'check');
4256     return if ! @sourcelist;
4258     &define_variable ('JAVAC', 'javac');
4259     &define_variable ('JAVACFLAGS', '');
4260     &define_variable ('CLASSPATH_ENV',
4261                       'CLASSPATH=$(JAVAROOT):$(srcdir)/$(JAVAROOT):$$CLASSPATH');
4262     &define_variable ('JAVAROOT', '$(top_builddir)');
4264     local (%valid) = &am_primary_prefixes ('JAVA', 1,
4265                                            'java', 'noinst', 'check');
4267     local ($dir, $curs);
4268     foreach $curs (keys %valid)
4269     {
4270         if (! &variable_defined ($curs . '_JAVA') || $curs eq 'noinst'
4271             || $curs eq 'EXTRA')
4272         {
4273             next;
4274         }
4276         if (defined $dir)
4277         {
4278             &am_line_error ($curs . '_JAVA',
4279                             "multiple _JAVA primaries in use");
4280         }
4281         $dir = $curs;
4282     }
4284     $output_rules .= ('class' . $dir . '.stamp: $(' . $dir . '_JAVA)' . "\n"
4285                       . "\t" . '$(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) '
4286                       . '$(JAVACFLAGS) $?' . "\n"
4287                       . "\t" . 'echo timestamp > class' . $dir . '.stamp'
4288                       . "\n");
4289     push (@all, 'class' . $dir . '.stamp');
4290     &push_dist_common ('$(' . $dir . '_JAVA)');
4293 # Handle some of the minor options.
4294 sub handle_minor_options
4296     if (defined $options{'readme-alpha'})
4297     {
4298         if ($relative_dir eq '.')
4299         {
4300             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4301             {
4302                 # FIXME: allow real filename.
4303                 &am_conf_line_error ('configure.in',
4304                                      $package_version_line,
4305                                      "version \`$package_version' doesn't follow Gnits standards");
4306             }
4307             elsif (defined $1 && -f 'README-alpha')
4308             {
4309                 # This means we have an alpha release.  See
4310                 # GNITS_VERSION_PATTERN for details.
4311                 &require_file ($FOREIGN, 'README-alpha');
4312             }
4313         }
4314     }
4317 ################################################################
4319 # Scan one file for interesting things.  Subroutine of scan_configure.
4320 sub scan_one_configure_file
4322     local ($filename) = @_;
4323     local (*CONFIGURE);
4325     open (CONFIGURE, $filename)
4326         || die "automake: couldn't open \`$filename': $!\n";
4327     print "automake: reading $filename\n" if $verbose;
4329     while (<CONFIGURE>)
4330     {
4331         # Remove comments from current line.
4332         s/\bdnl\b.*$//;
4333         s/\#.*$//;
4335         # Skip macro definitions.  Otherwise we might be confused into
4336         # thinking that a macro that was only defined was actually
4337         # used.
4338         next if /AC_DEFUN/;
4340         # Follow includes.  This is a weirdness commonly in use at
4341         # Cygnus and hopefully nowhere else.
4342         if (/sinclude\((.*)\)/ && -f $1)
4343         {
4344             &scan_one_configure_file ($1);
4345         }
4347         # Populate libobjs array.
4348         if (/AC_FUNC_ALLOCA/)
4349         {
4350             $libsources{'alloca.c'} = 1;
4351         }
4352         elsif (/AC_FUNC_GETLOADAVG/)
4353         {
4354             $libsources{'getloadavg.c'} = 1;
4355         }
4356         elsif (/AC_FUNC_MEMCMP/)
4357         {
4358             $libsources{'memcmp.c'} = 1;
4359         }
4360         elsif (/AC_STRUCT_ST_BLOCKS/)
4361         {
4362             $libsources{'fileblocks.c'} = 1;
4363         }
4364         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4365         {
4366             $libsources{'getopt.c'} = 1;
4367             $libsources{'getopt1.c'} = 1;
4368         }
4369         elsif (/AM_FUNC_STRTOD/)
4370         {
4371             $libsources{'strtod.c'} = 1;
4372         }
4373         elsif (/AM_WITH_REGEX/)
4374         {
4375             $libsources{'rx.c'} = 1;
4376             $libsources{'rx.h'} = 1;
4377             $libsources{'regex.c'} = 1;
4378             $libsources{'regex.h'} = 1;
4379             $omit_dependencies{'rx.h'} = 1;
4380             $omit_dependencies{'regex.h'} = 1;
4381         }
4382         elsif (/AC_FUNC_MKTIME/)
4383         {
4384             $libsources{'mktime.c'} = 1;
4385         }
4386         elsif (/AM_FUNC_ERROR_AT_LINE/)
4387         {
4388             $libsources{'error.c'} = 1;
4389             $libsources{'error.h'} = 1;
4390         }
4391         elsif (/AM_FUNC_OBSTACK/)
4392         {
4393             $libsources{'obstack.c'} = 1;
4394             $libsources{'obstack.h'} = 1;
4395         }
4396         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4397                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4398         {
4399             foreach $libobj_iter (split (' ', $1))
4400             {
4401                 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4402                     || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4403                     || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4404                 {
4405                     $libsources{$1 . '.c'} = 1;
4406                 }
4407             }
4408         }
4409         elsif (/AC_LIBOBJ\(([^)]+)\)/)
4410         {
4411             $libsources{"$1.c"} = 1;
4412         }
4414         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4415         {
4416             $in_ac_replace = 1;
4417         }
4418         if ($in_ac_replace)
4419         {
4420             $in_ac_replace = 0 if s/[\]\)].*$//;
4421             # Remove trailing backslash.
4422             s/\\$//;
4423             foreach (split)
4424             {
4425                 # Need to skip empty elements for Perl 4.
4426                 next if $_ eq '';
4427                 $libsources{$_ . '.c'} = 1;
4428             }
4429         }
4431         if (/$obsolete_rx/o)
4432         {
4433             local ($hint) = '';
4434             if ($obsolete_macros{$1} ne '')
4435             {
4436                 $hint = '; ' . $obsolete_macros{$1};
4437             }
4438             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
4439         }
4441         # Process the AC_OUTPUT and AC_CONFIG_FILES macros.
4442         if (! $in_ac_output && s/AC_(OUTPUT|CONFIG_FILES)\s*\(\[?//)
4443         {
4444             $in_ac_output = 1;
4445             $ac_output_line = $.;
4446         }
4447         if ($in_ac_output)
4448         {
4449             local ($closing) = 0;
4450             if (s/[\]\),].*$//)
4451             {
4452                 $in_ac_output = 0;
4453                 $closing = 1;
4454             }
4456             # Look at potential Makefile.am's.
4457             foreach (split)
4458             {
4459                 # Must skip empty string for Perl 4.
4460                 next if $_ eq "\\" || $_ eq '';
4462                 # Handle $local:$input syntax.  Note that we ignore
4463                 # every input file past the first, though we keep
4464                 # those around for later.
4465                 local ($local, $input, @rest) = split (/:/);
4466                 if (! $input)
4467                 {
4468                     $input = $local;
4469                 }
4470                 else
4471                 {
4472                     # FIXME: should be error if .in is missing.
4473                     $input =~ s/\.in$//;
4474                 }
4476                 if (-f $input . '.am')
4477                 {
4478                     # We have a file that automake should generate.
4479                     push (@make_input_list, $input);
4480                     $make_list{$input} = join (':', ($local, @rest));
4481                 }
4482                 else
4483                 {
4484                     # We have a file that automake should cause to be
4485                     # rebuilt, but shouldn't generate itself.
4486                     push (@other_input_files, $_);
4487                 }
4488             }
4490             if ($closing && @make_input_list == 0 && @other_input_files == 0)
4491             {
4492                 &am_conf_line_error ($filename, $ac_output_line,
4493                                      "No files mentioned in \`AC_OUTPUT'");
4494                 exit 1;
4495             }
4496         }
4498         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4499         {
4500             @config_aux_path = $1;
4501         }
4503         # Check for ansi2knr.
4504         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4506         # Check for exe extension stuff.
4507         if (/AC_EXEEXT/)
4508         {
4509             $seen_exeext = 1;
4510             $configure_vars{'EXEEXT'} = $filename . ':' . $.;
4511         }
4513         if (/AC_OBJEXT/)
4514         {
4515             $seen_objext = 1;
4516             $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4517         }
4519         # Check for `-c -o' code.
4520         $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4522         # Check for NLS support.
4523         if (/AM_GNU_GETTEXT/)
4524         {
4525             $seen_gettext = 1;
4526             $ac_gettext_line = $.;
4527             $omit_dependencies{'libintl.h'} = 1;
4528         }
4530         # Look for ALL_LINGUAS.
4531         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4532         {
4533             $seen_linguas = 1;
4534             $all_linguas = $1;
4535             $all_linguas_line = $.;
4536         }
4538         # Handle configuration headers.  A config header of `[$1]'
4539         # means we are actually scanning AM_CONFIG_HEADER from
4540         # aclocal.m4.
4541         if (/A([CM])_CONFIG_HEADERS?\s*\((.*)\)/
4542             && $2 ne '[$1]')
4543         {
4544             &am_conf_line_error
4545                 ($filename, $., "\`automake requires \`AM_CONFIG_HEADER', not \`AC_CONFIG_HEADER'")
4546                     if $1 eq 'C';
4548             $config_header_line = $.;
4549             local ($one_hdr);
4550             foreach $one_hdr (split (' ', $2))
4551             {
4552                 push (@config_fullnames, $one_hdr);
4553                 if ($one_hdr =~ /^([^:]+):(.+)$/)
4554                 {
4555                     push (@config_names, $1);
4556                     push (@config_headers, $2);
4557                 }
4558                 else
4559                 {
4560                     push (@config_names, $one_hdr);
4561                     push (@config_headers, $one_hdr . '.in');
4562                 }
4563             }
4564         }
4566         # Handle AC_CANONICAL_*.  Always allow upgrading to
4567         # AC_CANONICAL_SYSTEM, but never downgrading.
4568         $seen_canonical = $AC_CANONICAL_HOST
4569             if ! $seen_canonical
4570                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4571         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4573         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
4575         # This macro handles several different things.
4576         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4577         {
4578             $seen_make_set = 1;
4579             $seen_arg_prog = 1;
4580             $seen_prog_install = 1;
4581             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4582             $package_version_line = $.;
4583             $seen_init_automake = 1;
4584         }
4586         # Some things required by Automake.
4587         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
4588         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
4590         if (/AM_PROG_LEX/)
4591         {
4592             $configure_vars{'LEX'} = $filename . ':' . $.;
4593             $seen_decl_yytext = 1;
4594         }
4595         if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.in$/)
4596         {
4597             &am_conf_line_warning ($filename, $., "\`AC_DECL_YYTEXT' is covered by \`AM_PROG_LEX'");
4598         }
4599         if (/AC_PROG_LEX/ && $filename =~ /configure\.in$/)
4600         {
4601             &am_conf_line_warning ($filename, $., "automake requires \`AM_PROG_LEX', not \`AC_PROG_LEX'");
4602         }
4604         if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4605         {
4606             $configure_vars{$1} = $filename . ':' . $.;
4607         }
4608         if (/$AC_CHECK_PATTERN/o)
4609         {
4610             $configure_vars{$3} = $filename . ':' . $.;
4611         }
4612         if (/$AM_MISSING_PATTERN/o
4613             && $1 ne 'ACLOCAL'
4614             && $1 ne 'AUTOCONF'
4615             && $1 ne 'AUTOMAKE'
4616             && $1 ne 'AUTOHEADER')
4617         {
4618             $configure_vars{$1} = $filename . ':' . $.;
4619         }
4621         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4622         # but later define it elsewhere.  This is pretty hacky.  We
4623         # also explicitly avoid INSTALL_SCRIPT and some other
4624         # variables because they are defined in header-vars.am.
4625         # FIXME.
4626         if (/$AC_SUBST_PATTERN/o
4627             && $1 ne 'ANSI2KNR'
4628             && $1 ne 'INSTALL_SCRIPT'
4629             && $1 ne 'INSTALL_DATA')
4630         {
4631             $configure_vars{$1} = $filename . ':' . $.;
4632         }
4634         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4635         if (/AM_MAINTAINER_MODE/)
4636         {
4637             $seen_maint_mode = 1;
4638             $configure_cond{'MAINTAINER_MODE'} = 1;
4639         }
4641         $seen_prog_install = 1 if /AC_PROG_INSTALL/;
4642         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4643         $seen_pythondir = 1 if /AM_PATH_PYTHON/;
4645         if (/A(C|M)_PROG_LIBTOOL/)
4646         {
4647             if (/AM_PROG_LIBTOOL/)
4648             {
4649                 &am_conf_line_warning ($filename, $., "\`AM_PROG_LIBTOOL' is obsolete, use \`AC_PROG_LIBTOOL' instead");
4650             }
4651             $seen_libtool = 1;
4652             $libtool_line = $.;
4653             $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4654             $configure_vars{'RANLIB'} = $filename . ':' . $.;
4655             $configure_vars{'CC'} = $filename . ':' . $.;
4656             # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
4657             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4658             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4659         }
4661         $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4663         if (/$AM_CONDITIONAL_PATTERN/o)
4664         {
4665             $configure_cond{$1} = 1;
4666         }
4668         # Check for Fortran 77 intrinsic and run-time libraries.
4669         if (/AC_F77_LIBRARY_LDFLAGS/)
4670         {
4671             $configure_vars{'FLIBS'} = $filename . ':' . $.;
4672         }
4673     }
4675     close (CONFIGURE);
4678 # Scan configure.in and aclocal.m4 for interesting things.  We must
4679 # scan aclocal.m4 because there might be AC_SUBSTs and such there.
4680 sub scan_configure
4682     # Reinitialize libsources here.  This isn't really necessary,
4683     # since we currently assume there is only one configure.in.  But
4684     # that won't always be the case.
4685     %libsources = ();
4687     local ($in_ac_output, $in_ac_replace) = (0, 0);
4688     local (%make_list, @make_input_list);
4689     local ($libobj_iter);
4691     &scan_one_configure_file ('configure.in');
4692     &scan_one_configure_file ('aclocal.m4')
4693         if -f 'aclocal.m4';
4695     # Set input and output files if not specified by user.
4696     if (! @input_files)
4697     {
4698         @input_files = @make_input_list;
4699         %output_files = %make_list;
4700     }
4702     @configure_input_files = @make_input_list;
4704     &am_conf_error ("\`AM_INIT_AUTOMAKE' must be used in configure.in")
4705         if ! $seen_init_automake;
4707     # Always require AC_PROG_MAKE_SET.  We might randomly use $(MAKE)
4708     # for our own reasons.
4709     &am_conf_error ("\`AC_PROG_MAKE_SET' must be used in configure.in")
4710         if ! $seen_make_set;
4712     # Look for some files we need.  Always check for these.  This
4713     # check must be done for every run, even those where we are only
4714     # looking at a subdir Makefile.  We must set relative_dir so that
4715     # the file-finding machinery works.
4716     local ($relative_dir) = '.';
4717     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4718     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
4719         if -f $config_aux_path[0] . '/install.sh';
4721     &require_config_file ($FOREIGN, 'py-compile')
4722         if $seen_pythondir;
4724     # Preserve dist_common for later.
4725     %configure_dist_common = %dist_common;
4728 ################################################################
4730 # Set up for Cygnus mode.
4731 sub check_cygnus
4733     return unless $cygnus_mode;
4735     &set_strictness ('foreign');
4736     $options{'no-installinfo'} = 1;
4737     $options{'no-dependencies'} = 1;
4738     $use_dependencies = 0;
4740     if (! $seen_maint_mode)
4741     {
4742         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
4743     }
4745     if (! $seen_exeext)
4746     {
4747         &am_conf_error ("\`AC_EXEEXT' required when --cygnus specified");
4748     }
4751 # Do any extra checking for GNU standards.
4752 sub check_gnu_standards
4754     if ($relative_dir eq '.')
4755     {
4756         # In top level (or only) directory.
4757         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4758                        'AUTHORS', 'ChangeLog');
4759     }
4761     if ($strictness >= $GNU)
4762     {
4763         if (defined $options{'no-installman'})
4764         {
4765             &am_line_error ('AUTOMAKE_OPTIONS',
4766                             "option \`no-installman' disallowed by GNU standards");
4767         }
4769         if (defined $options{'no-installinfo'})
4770         {
4771             &am_line_error ('AUTOMAKE_OPTIONS',
4772                             "option \`no-installinfo' disallowed by GNU standards");
4773         }
4774     }
4777 # Do any extra checking for GNITS standards.
4778 sub check_gnits_standards
4780     if ($relative_dir eq '.')
4781     {
4782         # In top level (or only) directory.
4783         &require_file ($GNITS, 'THANKS');
4784     }
4787 ################################################################
4789 # Functions to handle files of each language.
4791 # Each `lang_X_rewrite' function follows a simple formula:
4792 # * Args are the directory, base name and extension of the file.
4793 # * Return value is 1 if file is to be dealt with, 0 otherwise.
4794 # Much of the actual processing is handled in handle_single_transform_list.
4795 # These functions exist so that auxiliary information can be recorded
4796 # for a later cleanup pass.  Note that the calls to these functions
4797 # are computed, so don't bother searching for their precise names
4798 # in the source.
4800 # This is just a convenience function that can be used to determine
4801 # when a subdir object should be used.
4802 sub lang_sub_obj
4804     return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4807 # Rewrite a single C source file.
4808 sub lang_c_rewrite
4810     local ($directory, $base, $ext) = @_;
4812     if (defined $options{'ansi2knr'} && $base =~ /_$/)
4813     {
4814         # FIXME: include line number in error.
4815         &am_error ("C source file \`$base.c' would be deleted by ansi2knr rules");
4816     }
4818     local ($r) = $LANG_PROCESS;
4819     if (defined $options{'subdir-objects'})
4820     {
4821         $r = $LANG_SUBDIR;
4822         $base = $directory . '/' . $base;
4824         if (! $seen_cc_c_o)
4825         {
4826             # Only give error once.
4827             $seen_cc_c_o = 1;
4828             # FIXME: line number.
4829             &am_error ("C objects in subdir but \`AM_PROG_CC_C_O' not in \`configure.in'");
4830         }
4832         &require_file ($FOREIGN, 'compile')
4833             if $relative_dir eq '.';
4834     }
4836     $de_ansi_files{$base} = 1;
4837     return $r;
4840 # Rewrite a single C++ source file.
4841 sub lang_cxx_rewrite
4843     return &lang_sub_obj;
4846 # Rewrite a single header file.
4847 sub lang_header_rewrite
4849     # Header files are simply ignored.
4850     return $LANG_IGNORE;
4853 # Rewrite a single yacc file.
4854 sub lang_yacc_rewrite
4856     local ($directory, $base, $ext) = @_;
4858     local ($r) = &lang_c_rewrite ($directory, $base, $ext);
4859     local ($pfx) = '';
4860     if ($r == $LANG_SUBDIR)
4861     {
4862         $pfx = $directory . '/';
4863     }
4864     $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4865     $ext =~ tr/y/c/;
4866     &saw_extension ('c');
4867     # FIXME: nodist.
4868     &push_dist_common ($pfx . $base . '.' . $ext);
4869     return $r;
4872 # Rewrite a single yacc++ file.
4873 sub lang_yaccxx_rewrite
4875     local ($directory, $base, $ext) = @_;
4877     local ($r) = $LANG_PROCESS;
4878     local ($pfx) = '';
4879     if (defined $options{'subdir-objects'})
4880     {
4881         $pfx = $directory . '/';
4882         $r = $LANG_SUBDIR;
4883     }
4884     $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4885     $ext =~ tr/y/c/;
4886     &saw_extension ($ext);
4887     # FIXME: nodist.
4888     &push_dist_common ($pfx . $base . '.' . $ext);
4889     return $r;
4892 # Rewrite a single lex file.
4893 sub lang_lex_rewrite
4895     local ($directory, $base, $ext) = @_;
4897     local ($r) = &lang_c_rewrite ($directory, $base, $ext);
4898     local ($pfx) = '';
4899     if ($r == $LANG_SUBDIR)
4900     {
4901         $pfx = $directory . '/';
4902     }
4903     $lex_sources{$pfx . $base . '.' . $ext} = 1;
4904     $ext =~ tr/l/c/;
4905     &saw_extension ('c');
4906     # FIXME: nodist.
4907     &push_dist_common ($pfx . $base . '.' . $ext);
4908     return $r;
4911 # Rewrite a single lex++ file.
4912 sub lang_lexxx_rewrite
4914     local ($directory, $base, $ext) = @_;
4916     local ($r) = $LANG_PROCESS;
4917     local ($pfx) = '';
4918     if (defined $options{'subdir-objects'})
4919     {
4920         $pfx = $directory . '/';
4921         $r = $LANG_SUBDIR;
4922     }
4923     $lex_sources{$pfx . $base . '.' . $ext} = 1;
4924     $ext =~ tr/l/c/;
4925     &saw_extension ($ext);
4926     # FIXME: nodist.
4927     &push_dist_common ($pfx . $base . '.' . $ext);
4928     return $r;
4931 # Rewrite a single assembly file.
4932 sub lang_asm_rewrite
4934     return &lang_sub_obj;
4937 # Rewrite a single Fortran 77 file.
4938 sub lang_f77_rewrite
4940     return $LANG_PROCESS;
4943 # Rewrite a single preprocessed Fortran 77 file.
4944 sub lang_ppf77_rewrite
4946     return $LANG_PROCESS;
4949 # Rewrite a single ratfor file.
4950 sub lang_ratfor_rewrite
4952     return $LANG_PROCESS;
4955 # Rewrite a single Objective C file.
4956 sub lang_objc_rewrite
4958     return &lang_sub_obj;
4961 # Rewrite a single Java file.
4962 sub lang_java_rewrite
4964     return $LANG_SUBDIR;
4967 # The lang_X_finish functions are called after all source file
4968 # processing is done.  Each should handle defining rules for the
4969 # language, etc.  A finish function is only called if a source file of
4970 # the appropriate type has been seen.
4972 sub lang_c_finish
4974     # Push all libobjs files onto de_ansi_files.  We actually only
4975     # push files which exist in the current directory, and which are
4976     # genuine source files.
4977     local ($file);
4978     foreach $file (keys %libsources)
4979     {
4980         if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
4981         {
4982             $de_ansi_files{$1} = 1;
4983         }
4984     }
4986     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
4987     {
4988         # Make all _.c files depend on their corresponding .c files.
4989         local ($base, @objects);
4990         foreach $base (sort keys %de_ansi_files)
4991         {
4992             # Each _.c file must depend on ansi2knr; otherwise it
4993             # might be used in a parallel build before it is built.
4994             # We need to support files in the srcdir and in the build
4995             # dir (because these files might be auto-generated.  But
4996             # we can't use $< -- some makes only define $< during a
4997             # suffix rule.
4998             $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
4999                               . '$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5000                               . '`if test -f $(srcdir)/' . $base . '.c'
5001                               . '; then echo $(srcdir)/' . $base . '.c'
5002                               . '; else echo ' . $base . '.c; fi` '
5003                               . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5004                               . '| $(ANSI2KNR) > ' . $base . "_.c\n");
5005             push (@objects, $base . '_'
5006                   . ($seen_objext ? '.$(OBJEXT)' : '.o'));
5007             push (@objects, $base . '_.lo') if $seen_libtool;
5008         }
5010         # Make all _.o (and _.lo) files depend on ansi2knr.
5011         # Use a sneaky little hack to make it print nicely.
5012         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5013     }
5015     if (! defined $configure_vars{'CC'})
5016     {
5017         # FIXME: line number.
5018         &am_error ("C source seen but \`CC' not defined in \`configure.in'");
5019     }
5022 sub lang_cxx_finish
5024     local ($ltcompile, $ltlink) = &libtool_compiler;
5026     &define_variable ('CXXLD', '$(CXX)');
5027     &define_variable ('CXXLINK', $ltlink . '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5029     if (! defined $configure_vars{'CXX'})
5030     {
5031         &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
5032     }
5035 sub lang_header_finish
5037     # Nothing to do.
5040 # This is a helper for both lex and yacc.
5041 sub yacc_lex_finish_helper
5043     return if defined $language_scratch{'lex-yacc-done'};
5044     $language_scratch{'lex-yacc-done'} = 1;
5046     # If there is more than one distinct yacc (resp lex) source file
5047     # in a given directory, then the `ylwrap' program is required to
5048     # allow parallel builds to work correctly.  FIXME: for now, no
5049     # line number.
5050     &require_config_file ($FOREIGN, 'ylwrap');
5051     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
5052     {
5053         &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5054     }
5055     else
5056     {
5057         &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
5058     }
5061 sub lang_yacc_finish
5063     return if defined $language_scratch{'yacc-done'};
5064     $language_scratch{'yacc-done'} = 1;
5066     local ($file, $base, $hname, $cname);
5067     local (%seen_suffix) = ();
5068     local (@yacc_files) = sort keys %yacc_sources;
5069     local ($yacc_count) = scalar (@yacc_files);
5070     foreach $file (@yacc_files)
5071     {
5072         $file =~ /(\..*)$/;
5073         &output_yacc_build_rule ($1, $yacc_count > 1)
5074             if ! defined $seen_suffix{$1};
5075         $seen_suffix{$1} = 1;
5077         $file =~ /^(.*)\.(y|yy|y\+\+|yxx|ypp)$/;
5078         $base = $1;
5079         $hname = 'h';           # Always use `.h' for header file.
5080         ($cname = $2) =~ tr/y/c/;
5082         if ((&variable_defined ('AM_YFLAGS')
5083              && &variable_value ('AM_YFLAGS') =~ /(^|\s)-d(\s|$)/)
5084             || (&variable_defined ('YFLAGS')
5085                 && &variable_value ('YFLAGS') =~ /(^|\s)-d(\s|$)/)) {
5086             # Now generate rule to make the header file.  This should only
5087             # be generated if `yacc -d' specified.
5088             $output_rules .= "${base}.${hname}: ${base}.${cname}\n";
5090             # If the files are built in the build directory, then we want
5091             # to remove them with `make clean'.  If they are in srcdir
5092             # they shouldn't be touched.  However, we can't determine this
5093             # statically, and the GNU rules say that yacc/lex output files
5094             # should be removed by maintainer-clean.  So that's what we
5095             # do.
5096             push (@maintainer_clean_files, "${base}.${hname}");
5098             &push_dist_common ("${base}.${hname}");
5099         }
5100         push (@maintainer_clean_files, "${base}.${cname}");
5101     }
5102     $output_rules .= "\n";
5104     if (! defined $configure_vars{'YACC'})
5105     {
5106         &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
5107     }
5108     if (&variable_defined ('YACCFLAGS'))
5109     {
5110         &am_line_error ('YACCFLAGS',
5111                         "\`YACCFLAGS' obsolete; use \`YFLAGS' instead");
5112     }
5114     if ($yacc_count > 1)
5115     {
5116         &yacc_lex_finish_helper;
5117     }
5120 sub lang_yaccxx_finish
5122     &lang_yacc_finish;
5125 sub lang_lex_finish
5127     return if defined $language_scratch{'lex-done'};
5128     $language_scratch{'lex-done'} = 1;
5130     local (%seen_suffix) = ();
5131     local ($file, $cname);
5132     local ($lex_count) = scalar (keys %lex_sources);
5133     foreach $file (sort keys %lex_sources)
5134     {
5135         $file =~ /(\..*)$/;
5136         &output_lex_build_rule ($1, $lex_count > 1)
5137             if (! defined $seen_suffix{$1});
5138         $seen_suffix{$1} = 1;
5140         # If the files are built in the build directory, then we want
5141         # to remove them with `make clean'.  If they are in srcdir
5142         # they shouldn't be touched.  However, we can't determine this
5143         # statically, and the GNU rules say that yacc/lex output files
5144         # should be removed by maintainer-clean.  So that's what we
5145         # do.
5146         $file =~ /^(.*)\.(l|ll|l\+\+|lxx|lpp)$/;
5147         ($cname = $2) =~ tr/l/c/;
5148         push (@maintainer_clean_files, "${1}.${cname}");
5149     }
5151     if (! defined $configure_vars{'LEX'})
5152     {
5153         &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
5154     }
5155     if (! $seen_decl_yytext)
5156     {
5157         &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
5158     }
5160     if ($lex_count > 1)
5161     {
5162         &yacc_lex_finish_helper;
5163     }
5166 sub lang_lexxx_finish
5168     &lang_lex_finish;
5171 sub lang_asm_finish
5173     # We need the C code for assembly.
5174     &lang_c_finish;
5177 sub lang_f77_finish
5179     # FIXME: this function can be called more than once.  We should
5180     # arrange for it to only do anything the first time through.
5182     local ($ltcompile, $ltlink) = &libtool_compiler;
5184     &define_variable ('F77LD', '$(F77)');
5185     &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5187     if (! defined $configure_vars{'F77'})
5188     {
5189         &am_error ("Fortran 77 source seen but \`F77' not defined in \`configure.in'");
5190     }
5193 # Preprocessed Fortran 77
5195 # The current support for preprocessing Fortran 77 just involves passing
5196 # `$(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)' as additional flags
5197 # to the Fortran 77 compiler, since this is how GNU Make does it; see
5198 # the `GNU Make Manual, Edition 0.51 for `make' Version 3.76 Beta'
5199 # (specifically, from info file `(make)Catalogue of Rules').
5201 # A better approach would be to write an Autoconf test
5202 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
5203 # Fortran 77 compilers know how to do preprocessing.  The Autoconf macro
5204 # AC_PROG_FPP should test the Fortran 77 compiler first for
5205 # preprocessing capabilities, and then fall back on cpp (if cpp were
5206 # available).
5207 sub lang_ppf77_finish
5209     &lang_f77_finish;
5211     # We also handle the case of preprocessing `.F' files into `.f'
5212     # files.
5213     $output_rules .= (".F.f:\n"
5214                       . "\t\$(F77COMPILE) -F \$<\n");
5217 sub lang_ratfor_finish
5219     &lang_f77_finish;
5221     # We also handle the case of preprocessing `.r' files into `.f'
5222     # files.
5223     $output_rules .= (".r.f:\n"
5224                       . "\t\$(RCOMPILE) -F \$<\n");
5227 sub lang_objc_finish
5229     local ($ltcompile, $ltlink) = &libtool_compiler;
5231     &define_variable ('OBJCLD', '$(OBJC)');
5232     &define_variable ('OBJCLINK', $ltlink . '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5234     if (! defined $configure_vars{'OBJC'})
5235     {
5236         &am_error ("Objective C source seen but \`OBJC' not defined in \`configure.in'");
5237     }
5240 sub lang_java_finish
5242     local ($ltcompile, $ltlink) = &libtool_compiler;
5244     &define_variable ('GCJLD', '$(GCJ)');
5245     &define_variable ('GCJLINK', $ltlink . '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5247     if (! defined $configure_vars{'GCJ'})
5248     {
5249         &am_error ("Java source seen but \`GCJ' not defined in \`configure.in'");
5250     }
5253 # A helper which computes a sorted list of all extensions for LANG.
5254 sub lang_extensions
5256     local ($lang) = @_;
5257     local ($key, @r);
5258     foreach $key (sort keys %extension_seen)
5259     {
5260         push (@r, '.' . $key) if $extension_map{$key} eq $lang;
5261     }
5262     return @r;
5265 # A helper which decides whether libtool is needed.  Returns prefix
5266 # for compiler and linker.
5267 sub libtool_compiler
5269     local ($ltcompile, $ltlink) = ('', '');
5270     if ($seen_libtool)
5271     {
5272         &define_configure_variable ("LIBTOOL");
5273         $ltcompile = '$(LIBTOOL) --mode=compile ';
5274         $ltlink = '$(LIBTOOL) --mode=link ';
5275     }
5276     return ($ltcompile, $ltlink);
5279 # Given a hash table of linker names, pick the name that has the most
5280 # precedence.  This is lame, but something has to have global
5281 # knowledge in order to eliminate the conflict.  Add more linkers as
5282 # required.
5283 sub resolve_linker
5285     local (%linkers) = @_;
5287     return 'GCJLINK'
5288         if defined $linkers{'GCJLINK'};
5289     return 'CXXLINK'
5290         if defined $linkers{'CXXLINK'};
5291     return 'F77LINK'
5292         if defined $linkers{'F77LINK'};
5293     return 'OBJCLINK'
5294         if defined $linkers{'OBJCLINK'};
5295     return 'LINK';
5298 # Called to indicate that an extension was used.
5299 sub saw_extension
5301     local ($ext) = @_;
5302     $extension_seen{$ext} = 1;
5305 # Called to ask whether source files have been seen . If HEADERS is 1,
5306 # headers can be included.
5307 sub saw_sources_p
5309     local ($headers) = @_;
5311     if ($headers)
5312     {
5313         $headers = 0;
5314     }
5315     else
5316     {
5317         local (@exts) = &lang_extensions ('header');
5318         $headers = @exts;
5319     }
5321     return scalar keys %extension_seen > $headers;
5324 # Register a single language.  LANGUAGE is the name of the language.
5325 # Each OPTION is either of the form NAME=VALUE, or is a file extension
5326 # (sans `.').
5327 sub register_language
5329     local ($language, @options) = @_;
5331     # Set the defaults.
5332     $language_map{$language . '-ansi-p'} = 0;
5333     $language_map{$language . '-linker'} = '';
5334     $language_map{$language . '-autodep'} = 'no';
5335     $language_map{$language . '-derived-autodep'} = 'no';
5337     local ($iter);
5338     foreach $iter (@options)
5339     {
5340         if ($iter =~ /^(.*)=(.*)$/)
5341         {
5342             $language_map{$language . '-' . $1} = $2;
5343         }
5344         elsif (defined $extension_map{$iter})
5345         {
5346             print STDERR
5347                 "automake: programming error: duplicate extension $iter\n";
5348             exit 1;
5349         }
5350         else
5351         {
5352             $extension_map{$iter} = $language;
5353         }
5354     }
5357 # This function is used to find a path from a user-specified suffix to
5358 # `o' or to some other suffix we recognize internally, eg `cc'.
5359 sub derive_suffix
5361     local ($source_ext) = @_;
5363     # FIXME: hard-coding `o' is a mistake.  Doing something
5364     # intelligent is harder.
5365     while ($extension_map{$source_ext} eq ''
5366            && $source_ext ne 'o'
5367            && defined $suffix_rules{$source_ext})
5368     {
5369         $source_ext = $suffix_rules{$source_ext};
5370     }
5372     return $source_ext;
5376 ################################################################
5378 # Pretty-print something.  HEAD is what should be printed at the
5379 # beginning of the first line, FILL is what should be printed at the
5380 # beginning of every subsequent line.
5381 sub pretty_print_internal
5383     local ($head, $fill, @values) = @_;
5385     local ($column) = length ($head);
5386     local ($result) = $head;
5388     # Fill length is number of characters.  However, each Tab
5389     # character counts for eight.  So we count the number of Tabs and
5390     # multiply by 7.
5391     local ($fill_length) = length ($fill);
5392     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5394     local ($bol) = ($head eq '');
5395     foreach (@values)
5396     {
5397         # "71" because we also print a space.
5398         if ($column + length ($_) > 71)
5399         {
5400             $result .= " \\\n" . $fill;
5401             $column = $fill_length;
5402             $bol = 1;
5403         }
5405         $result .= ' ' unless ($bol);
5406         $result .= $_;
5407         $column += length ($_) + 1;
5408         $bol = 0;
5409     }
5411     $result .= "\n";
5412     return $result;
5415 # Pretty-print something and append to output_vars.
5416 sub pretty_print
5418     $output_vars .= &pretty_print_internal (@_);
5421 # Pretty-print something and append to output_rules.
5422 sub pretty_print_rule
5424     $output_rules .= &pretty_print_internal (@_);
5428 ################################################################
5430 # See if a target exists.
5431 sub target_defined
5433     local ($target) = @_;
5434     return defined $targets{$target};
5437 # See if two conditionals are the same.
5438 sub conditional_same
5440     local ($cond1, $cond2) = @_;
5442     return (&conditional_true_when ($cond1, $cond2)
5443             && &conditional_true_when ($cond2, $cond1));
5446 # See if a conditional is true.  Both arguments are conditional
5447 # strings.  This returns true if the first conditional is true when
5448 # the second conditional is true.
5449 sub conditional_true_when
5451     local ($cond, $when) = @_;
5453     # Check the easy case first.
5454     if ($cond eq $when)
5455     {
5456         return 1;
5457     }
5459     # Check each component of $cond, which looks @COND1@@COND2@.
5460     foreach $comp (split ('@', $cond))
5461     {
5462         # The way we split will give null strings between each
5463         # condition.
5464         next if ! $comp;
5466         if (index ($when, '@' . $comp . '@') == -1)
5467         {
5468             return 0;
5469         }
5470     }
5472     return 1;
5475 # Check for an ambiguous conditional.  This is called when a variable
5476 # or target is being defined conditionally.  If we already know about
5477 # a definition that is true under the same conditions, then we have an
5478 # ambiguity.
5479 sub check_ambiguous_conditional
5481     local ($var_name, $cond) = @_;
5482     local (@cond_vals) = split (' ', $conditional{$var_name});
5483     while (@cond_vals)
5484     {
5485         local ($vcond) = shift (@cond_vals);
5486         shift (@cond_vals);
5487         if (&conditional_true_when ($vcond, $cond)
5488             || &conditional_true_when ($cond, $vcond))
5489         {
5490             &am_line_error ($var_name,
5491                             "$var_name multiply defined in condition");
5492         }
5493     }
5496 # See if a variable exists.  The first argument is the variable name,
5497 # and the optional second argument is the condition which we should
5498 # check.  If no condition is given, we currently return true if the
5499 # variable is defined under any condition.
5500 sub variable_defined
5502     local ($var, $cond) = @_;
5503     if (defined $targets{$var})
5504     {
5505         &am_line_error ($var, "\`$var' is target; expected variable");
5506         return 0;
5507     }
5508     elsif (defined $contents{$var})
5509     {
5510         if ($cond && $conditional{$var})
5511         {
5512             # We have been asked to check for a particular condition,
5513             # and the variable is defined conditionally.  We need to
5514             # look through the conditions under which the variable is
5515             # defined, and see if any of them match the conditional we
5516             # have been asked to check.
5517             local (@cond_vars) = split (' ', $conditional{$var});
5518             while (@cond_vars)
5519             {
5520                 if (&conditional_same ($cond, shift (@cond_vars)))
5521                 {
5522                     # Even a conditional examination is good enough
5523                     # for us.  FIXME: really should maintain examined
5524                     # status on a per-condition basis.
5525                     $content_seen{$var} = 1;
5526                     return 1;
5527                 }
5528                 shift (@cond_vars);
5529             }
5531             # The variable is not defined for the given condition.
5532             return 0;
5533         }
5535         $content_seen{$var} = 1;
5536         return 1;
5537     }
5538     return 0;
5541 # Mark a variable as examined.
5542 sub examine_variable
5544     local ($var) = @_;
5545     &variable_defined ($var);
5548 # Quote a value in order to put it in $conditional.  We need to quote
5549 # spaces, and we need to handle null strings, so that we can later
5550 # retrieve values by splitting on space.
5551 sub quote_cond_val
5553     local ($val) = @_;
5554     $val =~ tr/ \t\n/\001\003\004/;
5555     $val = "\002" if $val eq '';
5556     return $val;
5559 # Unquote a value in $conditional.
5560 sub unquote_cond_val
5562     local ($val) = @_;
5563     $val =~ tr/\001\003\004/ \t\n/;
5564     $val =~ s/\002//g;
5565     return $val;
5568 # Return the set of conditions for which a variable is defined.
5570 # If the variable is not defined conditionally, and is not defined in
5571 # terms of any variables which are defined conditionally, then this
5572 # returns the empty list.
5574 # If the variable is defined conditionally, but is not defined in
5575 # terms of any variables which are defined conditionally, then this
5576 # returns the list of conditions for which the variable is defined.
5578 # If the variable is defined in terms of any variables which are
5579 # defined conditionally, then this returns a full set of permutations
5580 # of the subvariable conditions.  For example, if the variable is
5581 # defined in terms of a variable which is defined for @COND_TRUE@,
5582 # then this returns both @COND_TRUE@ and @COND_FALSE@.  This is
5583 # because we will need to define the variable under both conditions.
5585 sub variable_conditions
5587     local ($var) = @_;
5588     local (%uniqify);
5589     local (@uniq_list);
5590     local ($cond);
5592     %vars_scanned = ();
5593     foreach $cond (&variable_conditions_sub ($var, '', ()))
5594     {
5595         $uniqify{$cond} = 1;
5596     }
5598     @uniq_list = sort keys %uniqify;
5599     # Note we cannot just do `return sort keys %uniqify', because this
5600     # function is sometimes used in a scalar context.
5601     return @uniq_list;
5604 # A subroutine of variable_conditions.  We only return conditions
5605 # which are true for all the conditions in @PARENT_CONDS.
5606 sub variable_conditions_sub
5608     local ($var, $parent, @parent_conds) = @_;
5609     local (@new_conds) = ();
5611     if (defined $vars_scanned{$var})
5612     {
5613         &am_line_error ($parent, "variable \`$var' recursively defined");
5614         return ();
5615     }
5616     $vars_scanned{$var} = 1;
5618     if (! $conditional{$var})
5619     {
5620         foreach (split (' ', $contents{$var}))
5621         {
5622             # If a comment seen, just leave.
5623             last if /^#/;
5625             # Handle variable substitutions.
5626             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5627             {
5628                 push (@new_conds,
5629                       &variable_conditions_sub ($1, $var, @parent_conds));
5630             }
5631         }
5633         # Now we want to return all permutations of the subvariable
5634         # conditions.
5635         local (%allconds, $item);
5636         foreach $item (@new_conds)
5637         {
5638             foreach (split ('@', $item))
5639             {
5640                 next if ! $_;
5641                 s/_(TRUE|FALSE)$//;
5642                 $allconds{$_ . '_TRUE'} = 1;
5643             }
5644         }
5646         # Unset our entry in vars_scanned.  We only care about recursive
5647         # definitions.
5648         delete $vars_scanned{$var};
5650         return &variable_conditions_permutations (sort keys %allconds);
5651     }
5653     local (@this_conds) = ();
5654     local (@condvals) = split (' ', $conditional{$var});
5655     while (@condvals)
5656     {
5657         local ($cond) = shift (@condvals);
5658         local ($val) = &unquote_cond_val (shift (@condvals));
5660         if (@parent_conds)
5661         {
5662             local ($ok) = 1;
5663             local ($parent_cond);
5664             foreach $parent_cond (@parent_conds)
5665             {
5666                 if (! &conditional_true_when ($parent_cond, $cond))
5667                 {
5668                     $ok = 0;
5669                     last;
5670                 }
5671             }
5673             next if ! $ok;
5674         }
5676         push (@this_conds, $cond);
5678         push (@parent_conds, $cond);
5679         local (@subvar_conds) = ();
5680         foreach (split (' ', $val))
5681         {
5682             # If a comment seen, just leave.
5683             last if /^#/;
5685             # Handle variable substitutions.
5686             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5687             {
5688                 push (@subvar_conds,
5689                       &variable_conditions_sub ($1, $var, @parent_conds));
5690             }
5691         }
5692         pop (@parent_conds);
5694         # If there are no conditional subvariables, then we want to
5695         # return this condition.  Otherwise, we want to return the
5696         # permutations of the subvariables.
5697         if (! @subvar_conds)
5698         {
5699             push (@new_conds, $cond);
5700         }
5701         else
5702         {
5703             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
5704         }
5705     }
5707     # Unset our entry in vars_scanned.  We only care about recursive
5708     # definitions.
5709     delete $vars_scanned{$var};
5711     return @new_conds
5712         if ! $parent;
5714     # If we are being called on behalf of another variable, we need to
5715     # return all possible permutations of the conditions.  We have
5716     # already handled everything in @this_conds along with their
5717     # subvariables.  We now need to add any permutations that are not
5718     # in @this_conds.
5719     local ($this_cond);
5720     foreach $this_cond (@this_conds)
5721     {
5722         local (@perms) =
5723             &variable_conditions_permutations (split('@', $this_cond));
5724         local ($perm);
5725         foreach $perm (@perms)
5726         {
5727             local ($scan);
5728             local ($ok) = 1;
5729             foreach $scan (@this_conds)
5730             {
5731                 if (&conditional_true_when ($perm, $scan)
5732                     || &conditional_true_when ($scan, $perm))
5733                 {
5734                     $ok = 0;
5735                     last;
5736                 }
5737             }
5738             next if ! $ok;
5740             if (@parent_conds)
5741             {
5742                 local ($ok) = 1;
5743                 local ($parent_cond);
5744                 foreach $parent_cond (@parent_conds)
5745                 {
5746                     if (! &conditional_true_when ($parent_cond, $perm))
5747                     {
5748                         $ok = 0;
5749                         last;
5750                     }
5751                 }
5753                 next if ! $ok;
5754             }
5756             # This permutation was not already handled, and is valid
5757             # for the parents.
5758             push (@new_conds, $perm);
5759         }
5760     }
5762     return @new_conds;
5765 # Subroutine for variable_conditions_sort
5766 sub variable_conditions_cmp
5768     local ($as) = $a;
5769     $as =~ s/[^@]//g;
5770     local ($bs) = $b;
5771     $bs =~ s/[^@]//g;
5772     return (length ($as) <=> length ($bs)
5773             || $a cmp $b);
5776 # Sort a list of conditionals so that only the exclusive ones are
5777 # retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
5778 # @COND1_TRUE@ are in the list, discard the latter.
5779 sub variable_conditions_reduce
5781     local (@conds) = @_;
5782     local (@ret) = ();
5783     local ($cond);
5784     foreach $cond (sort variable_conditions_cmp @conds)
5785     {
5786         local ($ok) = 1;
5787         local ($scan);
5788         foreach $scan (@ret)
5789         {
5790             if (&conditional_true_when ($cond, $scan))
5791             {
5792                 $ok = 0;
5793                 last;
5794             }
5795         }
5796         next if ! $ok;
5797         push (@ret, $cond);
5798     }
5800     return @ret;
5803 # Return a list of permutations of a conditional string.
5804 sub variable_conditions_permutations
5806     local (@comps) = @_;
5807     return ()
5808         if ! @comps;
5809     local ($comp) = shift (@comps);
5810     return &variable_conditions_permutations (@comps)
5811         if $comp eq '';
5812     local ($neg) = $comp;
5813     $neg =~ s/TRUE$/TRUEO/;
5814     $neg =~ s/FALSE$/TRUE/;
5815     $neg =~ s/TRUEO$/FALSE/;
5816     local (@ret);
5817     local ($sub);
5818     foreach $sub (&variable_conditions_permutations (@comps))
5819     {
5820         push (@ret, '@' . $comp . '@' . $sub);
5821         push (@ret, '@' . $neg . '@' . $sub);
5822     }
5823     if (! @ret)
5824     {
5825         push (@ret, '@' . $comp . '@');
5826         push (@ret, '@' . $neg . '@');
5827     }
5828     return @ret;
5831 # Warn if a variable is conditionally defined.  This is called if we
5832 # are using the value of a variable.
5833 sub variable_conditionally_defined
5835     local ($var, $parent) = @_;
5836     if ($conditional{$var})
5837     {
5838         if ($parent)
5839         {
5840             &am_line_error ($parent,
5841                             "warning: automake does not support conditional definition of $var in $parent");
5842         }
5843         else
5844         {
5845             &am_line_error ($parent,
5846                             "warning: automake does not support $var being defined conditionally")
5847         }
5848     }
5851 # Get the value of a variable.  This just returns $contents, but warns
5852 # if the variable is conditionally defined.
5853 sub variable_value
5855     local ($var) = @_;
5856     &variable_conditionally_defined ($var);
5857     return $contents{$var};
5860 # Convert a variable value to a list, split as whitespace.  This will
5861 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5862 # substitutions.  If COND is 'all', then all values under all
5863 # conditions should be returned; if COND is a particular condition
5864 # (all conditions are surrounded by @...@) then only the value for
5865 # that condition should be returned; otherwise, warn if VAR is
5866 # conditionally defined.  SCANNED is a global hash listing whose keys
5867 # are all the variables already scanned; it is an error to rescan a
5868 # variable.
5869 sub value_to_list
5871     local ($var, $val, $cond) = @_;
5872     local (@result);
5874     # Strip backslashes
5875     $val =~ s/\\(\n|$)/ /g;
5877     foreach (split (' ', $val))
5878     {
5879         # If a comment seen, just leave.
5880         last if /^#/;
5882         # Handle variable substitutions.
5883         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
5884         {
5885             local ($varname) = $1;
5887             # If the user uses a losing variable name, just ignore it.
5888             # This isn't ideal, but people have requested it.
5889             next if ($varname =~ /\@.*\@/);
5891             local ($from, $to);
5892             local (@temp_list);
5893             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
5894             {
5895                 $varname = $1;
5896                 $to = $3;
5897                 ($from = $2) =~ s/(\W)/\\$1/g;
5898             }
5900             # Find the value.
5901             @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
5903             # Now rewrite the value if appropriate.
5904             if ($from)
5905             {
5906                 grep (s/$from$/$to/, @temp_list);
5907             }
5909             push (@result, @temp_list);
5910         }
5911         else
5912         {
5913             push (@result, $_);
5914         }
5915     }
5917     return @result;
5920 # Return contents of variable as list, split as whitespace.  This will
5921 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5922 # substitutions.  If COND is 'all', then all values under all
5923 # conditions should be returned; if COND is a particular condition
5924 # (all conditions are surrounded by @...@) then only the value for
5925 # that condition should be returned; otherwise, warn if VAR is
5926 # conditionally defined.  If PARENT is specified, it is the name of
5927 # the including variable; this is only used for error reports.
5928 sub variable_value_as_list_worker
5930     local ($var, $cond, $parent) = @_;
5931     local (@result);
5933     if (defined $targets{$var})
5934     {
5935         &am_line_error ($var, "\`$var' is target; expected variable");
5936     }
5937     elsif (! defined $contents{$var})
5938     {
5939         &am_line_error ($parent, "variable \`$var' not defined");
5940     }
5941     elsif (defined $vars_scanned{$var})
5942     {
5943         # `vars_scanned' is a global we use to keep track of which
5944         # variables we've already examined.
5945         &am_line_error ($parent, "variable \`$var' recursively defined");
5946     }
5947     elsif ($cond eq 'all' && $conditional{$var})
5948     {
5949         $vars_scanned{$var} = 1;
5950         local (@condvals) = split (' ', $conditional{$var});
5951         while (@condvals)
5952         {
5953             shift (@condvals);
5954             local ($val) = &unquote_cond_val (shift (@condvals));
5955             push (@result, &value_to_list ($var, $val, $cond));
5956         }
5957     }
5958     elsif ($cond && $conditional{$var})
5959     {
5960         $vars_scanned{$var} = 1;
5961         local (@condvals) = split (' ', $conditional{$var});
5962         local ($onceflag);
5963         while (@condvals)
5964         {
5965             local ($vcond) = shift (@condvals);
5966             local ($val) = &unquote_cond_val (shift (@condvals));
5967             if (&conditional_true_when ($vcond, $cond))
5968             {
5969                 # Warn if we have an ambiguity.  It's hard to know how
5970                 # to handle this case correctly.
5971                 &variable_conditionally_defined ($var, $parent)
5972                     if $onceflag;
5973                 $onceflag = 1;
5974                 push (@result, &value_to_list ($var, $val, $cond));
5975             }
5976         }
5977     }
5978     else
5979     {
5980         $vars_scanned{$var} = 1;
5981         &variable_conditionally_defined ($var, $parent);
5982         $content_seen{$var} = 1;
5983         push (@result, &value_to_list ($var, $contents{$var}, $cond));
5984     }
5986     # Unset our entry in vars_scanned.  We only care about recursive
5987     # definitions.
5988     delete $vars_scanned{$var};
5990     return @result;
5993 # This is just a wrapper for variable_value_as_list_worker that
5994 # initializes the global hash `vars_scanned'.  This hash is used to
5995 # avoid infinite recursion.
5996 sub variable_value_as_list
5998     local ($var, $cond, $parent) = @_;
5999     %vars_scanned = ();
6000     return &variable_value_as_list_worker ($var, $cond, $parent);
6003 # Define a new variable, but only if not already defined.
6004 sub define_variable
6006     local ($var, $value) = @_;
6008     if (! defined $contents{$var})
6009     {
6010         $output_vars .= $var . ' = ' . $value . "\n";
6011         $contents{$var} = $value;
6012         $content_seen{$var} = 1;
6013     }
6014     elsif ($var_was_plus_eq{$var})
6015     {
6016         &am_line_error ($var, "internally generated variable \`$var' was set with \`+='");
6017     }
6020 # Like define_variable, but the value is a list, and the variable may
6021 # be defined conditionally.  The second argument is the conditional
6022 # under which the value should be defined; this should be the empty
6023 # string to define the variable unconditionally.  The third argument
6024 # is a list holding the values to use for the variable.  The value is
6025 # pretty printed in the output file.
6026 sub define_pretty_variable
6028     local ($var, $cond, @value) = @_;
6029     if (! defined $contents{$var}
6030         || ($cond && ! &variable_defined ($var, $cond)))
6031     {
6032         $contents{$var} = join (' ', @value);
6033         if ($cond)
6034         {
6035             if ($conditional{$var})
6036             {
6037                 $conditional{$var} .= ' ';
6038             }
6039             else
6040             {
6041                 $conditional{$var} = '';
6042             }
6043             $conditional{$var} .= ($cond
6044                                    . ' '
6045                                    . &quote_cond_val ($contents{$var}));
6046         }
6047         &pretty_print ($cond . $var . ' = ', $cond, @value);
6048         $content_seen{$var} = 1;
6049     }
6052 # Like define_variable, but define a variable to be the configure
6053 # substitution by the same name.
6054 sub define_configure_variable
6056     local ($var) = @_;
6057     local ($value) = '@' . $var . '@';
6058     &define_variable ($var, $value);
6061 # Define a compiler variable.  We also handle defining the `LT'
6062 # version of the command when using libtool.
6063 sub define_compiler_variable
6065     local ($var, $ltcompile, $value) = @_;
6066     local ($name) = $var;
6067     &define_variable ($name, $value);
6068     &define_variable ('LT' . $name, $ltcompile . $value)
6069         if $seen_libtool;
6072 # Define a variable that represents a program to run.  If in Cygnus
6073 # mode, the program is searched for in the build (or source) tree.
6074 # Otherwise no searching is done at all.  Arguments are:
6075 # * VAR      Name of variable to define
6076 # * WHATDIR  Either `src' or `build', depending on where program should
6077 #            be found.  (runtest is in srcdir!)
6078 # * SUBDIR   Subdir of top-level dir
6079 # * PROGRAM  Name of program
6080 # * OVERRIDE If specified, the name of the program to use when not in
6081 #            Cygnus mode.  Defaults to PROGRAM.
6082 sub define_program_variable
6084     local ($var, $whatdir, $subdir, $program, $override) = @_;
6086     if (! $override)
6087     {
6088         $override = $program;
6089     }
6091     if ($cygnus_mode)
6092     {
6093         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
6094                          . $subdir . '/' . $program);
6095         &define_variable ($var, ('`if test -f ' . $full
6096                                  . '; then echo ' . $full . '; else echo '
6097                                  . $program . '; fi`'));
6098     }
6099     else
6100     {
6101         &define_variable ($var, $override);
6102     }
6106 ################################################################
6108 # Read Makefile.am and set up %contents.  Simultaneously copy lines
6109 # from Makefile.am into $output_trailer or $output_vars as
6110 # appropriate.  NOTE we put rules in the trailer section.  We want
6111 # user rules to come after our generated stuff.
6112 sub read_am_file
6114     local ($amfile) = @_;
6115     local (*AM_FILE);
6117     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
6118     print "automake: reading $amfile\n" if $verbose;
6120     local ($saw_bk) = 0;
6121     local ($was_rule) = 0;
6122     local ($spacing) = '';
6123     local ($comment) = '';
6124     local ($last_var_name) = '';
6125     local ($blank) = 0;
6127     # We save the conditional stack on entry, and then check to make
6128     # sure it is the same on exit.  This lets us conditonally include
6129     # other files.
6130     local (@saved_cond_stack) = @conditional_stack;
6132     while (<AM_FILE>)
6133     {
6134         if (/$IGNORE_PATTERN/o)
6135         {
6136             # Merely delete comments beginning with two hashes.
6137         }
6138         elsif (/$WHITE_PATTERN/o)
6139         {
6140             # Stick a single white line before the incoming macro or rule.
6141             $spacing = "\n";
6142             $blank = 1;
6143         }
6144         elsif (/$COMMENT_PATTERN/o)
6145         {
6146             # Stick comments before the incoming macro or rule.  Make
6147             # sure a blank line preceeds first block of comments.
6148             $spacing = "\n" unless $blank;
6149             $blank = 1;
6150             $comment .= $spacing . $_;
6151             $spacing = '';
6152         }
6153         else
6154         {
6155             last;
6156         }
6157     }
6159     $output_vars .= $comment . "\n";
6160     $comment = '';
6161     $spacing = "\n";
6163     local ($is_ok_macro);
6164     while ($_)
6165     {
6166         $_ .= "\n"
6167             unless substr ($_, -1, 1) eq "\n";
6169         # Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
6170         # used by users.  @MAINT@ is an anachronism now.
6171         $_ =~ s/\@MAINT\@//g
6172             unless $seen_maint_mode;
6174         if (/$IGNORE_PATTERN/o)
6175         {
6176             # Merely delete comments beginning with two hashes.
6177         }
6178         elsif (/$WHITE_PATTERN/o)
6179         {
6180             # Stick a single white line before the incoming macro or rule.
6181             $spacing = "\n";
6182             &am_line_error ($., "blank line following trailing backslash")
6183                 if $saw_bk;
6184         }
6185         elsif (/$COMMENT_PATTERN/o)
6186         {
6187             # Stick comments before the incoming macro or rule.
6188             $comment .= $spacing . $_;
6189             $spacing = '';
6190             &am_line_error ($., "comment following trailing backslash")
6191                 if $saw_bk;
6192         }
6193         elsif ($saw_bk)
6194         {
6195             if ($was_rule)
6196             {
6197                 $output_trailer .= join ('', @conditional_stack) . $_;
6198                 $saw_bk = /\\$/;
6199             }
6200             else
6201             {
6202                 $saw_bk = /\\$/;
6203                 $contents{$last_var_name} .= ' '
6204                     unless $contents{$last_var_name} =~ /\s$/;
6205                 $contents{$last_var_name} .= $_;
6206                 if (@conditional_stack)
6207                 {
6208                     $conditional{$last_var_name} .= &quote_cond_val ($_);
6209                 }
6210             }
6211         }
6212         elsif (/$IF_PATTERN/o)
6213         {
6214             &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
6215                 if (! $configure_cond{$1});
6216             push (@conditional_stack, "\@" . $1 . "_TRUE\@");
6217         }
6218         elsif (/$ELSE_PATTERN/o)
6219         {
6220             if (! @conditional_stack)
6221             {
6222                 &am_line_error ($., "else without if");
6223             }
6224             elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
6225             {
6226                 &am_line_error ($., "else after else");
6227             }
6228             else
6229             {
6230                 $conditional_stack[$#conditional_stack]
6231                     =~ s/_TRUE\@$/_FALSE\@/;
6232             }
6233         }
6234         elsif (/$ENDIF_PATTERN/o)
6235         {
6236             if (! @conditional_stack)
6237             {
6238                 &am_line_error ($., "endif without if");
6239             }
6240             else
6241             {
6242                 pop @conditional_stack;
6243             }
6244         }
6245         elsif (/$RULE_PATTERN/o)
6246         {
6247             # Found a rule.
6248             $was_rule = 1;
6249             if (defined $contents{$1}
6250                 && (@conditional_stack
6251                     ? ! defined $conditional{$1}
6252                     : defined $conditional{$1}))
6253             {
6254                 &am_line_error ($1,
6255                                 "$1 defined both conditionally and unconditionally");
6256             }
6257             # Value here doesn't matter; for targets we only note
6258             # existence.
6259             $contents{$1} = 1;
6260             $targets{$1} = 1;
6261             local ($cond_string) = join ('', @conditional_stack);
6262             if (@conditional_stack)
6263             {
6264                 if ($conditional{$1})
6265                 {
6266                     &check_ambiguous_conditional ($1, $cond_string);
6267                     $conditional{$1} .= ' ';
6268                 }
6269                 else
6270                 {
6271                     $conditional{$1} = '';
6272                 }
6273                 $conditional{$1} .= $cond_string . ' 1';
6274             }
6275             $content_lines{$1} = $.;
6276             $output_trailer .= $comment . $spacing . $cond_string . $_;
6277             $comment = $spacing = '';
6278             $saw_bk = /\\$/;
6280             # Check the rule for being a suffix rule. If so, store in
6281             # a hash.
6283             local ($source_suffix);
6284             local ($object_suffix);
6286             if (($source_suffix, $object_suffix) = ($1 =~ $SUFFIX_RULE_PATTERN))
6287             {
6288               $suffix_rules{$source_suffix} = $object_suffix;
6289               print "Sources ending in .$source_suffix become .$object_suffix\n" if $verbose;
6290               $source_suffix_pattern = "(" . join ('|', keys %suffix_rules) . ")";
6291             }
6293             # FIXME: make sure both suffixes are in SUFFIXES? Or set
6294             # SUFFIXES from suffix_rules?
6295         }
6296         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
6297                || /$BOGUS_MACRO_PATTERN/o)
6298         {
6299             # Found a macro definition.
6300             $was_rule = 0;
6301             $last_var_name = $1;
6302             if (defined $contents{$1}
6303                 && (@conditional_stack
6304                     ? ! defined $conditional{$1}
6305                     : defined $conditional{$1}))
6306             {
6307                 &am_line_error ($1,
6308                                 "$1 defined both conditionally and unconditionally");
6309             }
6310             local ($value);
6311             if ($3 ne '' && substr ($3, -1) eq "\\")
6312             {
6313                 # We preserve the `\' because otherwise the long lines
6314                 # that are generated will be truncated by broken
6315                 # `sed's.
6316                 $value = $3 . "\n";
6317             }
6318             else
6319             {
6320                 $value = $3;
6321             }
6322             local ($type) = $2;
6324             if (! defined $contents{$last_var_name})
6325             {
6326                 # The first assignment to a macro sets the line
6327                 # number.  Ideally I suppose we would associate line
6328                 # numbers with random bits of text.
6329                 $content_lines{$last_var_name} = $.;
6331                 # If first assignment, set `+=' indicator.
6332                 $var_was_plus_eq{$last_var_name} =
6333                     ($type eq '+'
6334                      && ! defined $am_var_defs{$last_var_name});
6335             }
6337             if ($type eq '+')
6338             {
6339                 if (! defined $contents{$last_var_name}
6340                     && defined $am_var_defs{$last_var_name})
6341                 {
6342                     $contents{$last_var_name} = $am_var_defs{$last_var_name};
6343                 }
6344                 if (substr ($contents{$last_var_name}, -1) eq "\n")
6345                 {
6346                     # Insert a backslash before a trailing newline.
6347                     $contents{$last_var_name}
6348                         = substr ($contents{$last_var_name}, 0, -1) . "\\\n";
6349                 }
6350                 $contents{$last_var_name} .= ' ' . $value;
6351             }
6352             else
6353             {
6354                 $contents{$last_var_name} = $value;
6355             }
6356             local ($cond_string) = join ('', @conditional_stack);
6357             if (@conditional_stack)
6358             {
6359                 local ($found) = 0;
6360                 local ($val);
6361                 if ($conditional{$last_var_name})
6362                 {
6363                     if ($type eq '+')
6364                     {
6365                         # If we're adding to the conditional, and it
6366                         # exists, then we might want to simply replace
6367                         # the old value with the new one.
6368                         local (@new_vals, @cond_vals);
6369                         @cond_vals = split (' ', $conditional{$last_var_name});
6370                         while (@cond_vals)
6371                         {
6372                             local ($vcond) = shift (@cond_vals);
6373                             push (@new_vals, $vcond);
6374                             if (&conditional_same ($vcond, $cond_string))
6375                             {
6376                                 $found = 1;
6377                                 $val = (&unquote_cond_val (shift (@cond_vals))
6378                                         . ' ' . $value);
6379                                 push (@new_vals, &quote_cond_val ($val));
6380                             }
6381                             else
6382                             {
6383                                 push (@new_vals, shift (@cond_vals));
6384                             }
6385                         }
6386                         if ($found)
6387                         {
6388                             $conditional{$last_var_name}
6389                                 = join (' ', @new_vals);
6390                         }
6391                     }
6393                     if (! $found)
6394                     {
6395                         &check_ambiguous_conditional ($last_var_name,
6396                                                       $cond_string);
6397                         $conditional{$last_var_name} .= ' ';
6398                         $val = $value;
6399                     }
6400                 }
6401                 else
6402                 {
6403                     $conditional{$last_var_name} = '';
6404                     $val = $contents{$last_var_name};
6405                 }
6406                 if (! $found)
6407                 {
6408                     $conditional{$last_var_name} .= ($cond_string
6409                                                      . ' '
6410                                                      . &quote_cond_val ($val));
6411                 }
6412             }
6414             # FIXME: this doesn't always work correctly; it will group
6415             # all comments for a given variable, no matter where
6416             # defined.
6417             $am_vars{$last_var_name} = $comment . $spacing;
6418             $def_type{$last_var_name} = ($type eq ':') ? ':' : '';
6419             push (@var_list, $last_var_name);
6420             $comment = $spacing = '';
6421             $saw_bk = /\\$/;
6423             # Error if bogus.
6424             &am_line_error ($., "bad macro name \`$last_var_name'")
6425                 if ! $is_ok_macro;
6426         }
6427         elsif (/$INCLUDE_PATTERN/o)
6428         {
6429             local ($path) = $1;
6431             if ($path =~ s/^\$\(top_srcdir\)\///)
6432             {
6433                 push (@include_stack, "\$\(top_srcdir\)/$path");
6434             }
6435             else
6436             {
6437                 $path =~ s/\$\(srcdir\)\///;
6438                 push (@include_stack, "\$\(srcdir\)/$path");
6439                 $path = $relative_dir . "/" . $path;
6440             }
6441             &read_am_file ($path);
6442         }
6443         else
6444         {
6445             # This isn't an error; it is probably a continued rule.
6446             # In fact, this is what we assume.
6447             $was_rule = 1;
6448             $output_trailer .= ($comment . $spacing
6449                                 . join ('', @conditional_stack) . $_);
6450             $comment = $spacing = '';
6451             $saw_bk = /\\$/;
6452         }
6454         $_ = <AM_FILE>;
6455     }
6457     $output_trailer .= $comment;
6459     if (join (' ', @saved_cond_stack) ne join (' ', @conditional_stack))
6460     {
6461         if (@conditional_stack)
6462         {
6463             &am_error ("unterminated conditionals: " . join (' ', @conditional_stack));
6464         }
6465         else
6466         {
6467             # FIXME: better error message here.
6468             &am_error ("conditionals not nested in include file");
6469         }
6470     }
6473 # A helper for read_main_am_file which initializes configure variables
6474 # and variables from header-vars.am.  This is a subr so we can call it
6475 # twice.
6476 sub define_standard_variables
6478     # Compute relative location of the top object directory.
6479     local (@topdir) = ();
6480     foreach (split (/\//, $relative_dir))
6481     {
6482         next if $_ eq '.' || $_ eq '';
6483         if ($_ eq '..')
6484         {
6485             pop @topdir;
6486         }
6487         else
6488         {
6489             push (@topdir, '..');
6490         }
6491     }
6492     @topdir = ('.') if ! @topdir;
6494     $top_builddir = join ('/', @topdir);
6495     local ($build_rx);
6496     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
6497     $output_vars .= &file_contents_with_transform
6498                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
6499                          'header-vars');
6501     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
6502     # this should use generic %configure_vars method.
6503     if ($seen_canonical)
6504     {
6505         local ($curs, %vars);
6506         $vars{'host_alias'} = 'host_alias';
6507         $vars{'host_triplet'} = 'host';
6508         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
6509         {
6510             $vars{'build_alias'} = 'build_alias';
6511             $vars{'build_triplet'} = 'build';
6512             $vars{'target_alias'} = 'target_alias';
6513             $vars{'target_triplet'} = 'target';
6514         }
6515         foreach $curs (sort keys %vars)
6516         {
6517             $output_vars .= "$curs = \@$vars{$curs}\@\n";
6518             $contents{$curs} = "\@$vars{$curs}\@";
6519         }
6520     }
6522     local ($curs);
6523     foreach $curs (sort keys %configure_vars)
6524     {
6525         &define_configure_variable ($curs);
6526     }
6529 # Read main am file.
6530 sub read_main_am_file
6532     local ($amfile) = @_;
6534     # The keys here are variables we want to dump at the end of this
6535     # function.  The values are corresponding comments.
6536     local (%am_vars) = ();
6537     local (@var_list) = ();
6538     local (%def_type) = ();
6540     # This supports the strange variable tricks we are about to play.
6541     if (scalar keys %contents > 0)
6542     {
6543         print STDERR "automake: programming error: variable defined before read_main_am_file\n";
6544         exit 1;
6545     }
6547     # We want to predefine as many variables as possible.  This lets
6548     # the user set them with `+=' in Makefile.am.  However, we don't
6549     # want these initial definitions to end up in the output quite
6550     # yet.  So we adopt a hack: read the `.am' file twice, throwing
6551     # away the output the first time.  We also squirrel away a list of
6552     # all the variables defined by the .am file so that we know which
6553     # ones to remove from the content list.
6555     # First pass.
6556     &define_standard_variables;
6557     local (%saved_contents) = %contents;
6559     # Read user file, but discard text of variable assignments we just
6560     # made.
6561     $output_vars = '';
6562     &read_am_file ($amfile);
6564     # Now dump the variables that were defined.  We do it in the same
6565     # order in which they were defined (skipping duplicates).
6566     local (%done);
6567     foreach $curs (@var_list)
6568     {
6569         next if $done{$curs};
6570         $done{$curs} = 1;
6572         $output_vars .= $am_vars{$curs};
6573         if ($conditional{$curs})
6574         {
6575             local (@cond_vals) = split (' ', $conditional{$curs});
6576             while (@cond_vals)
6577             {
6578                 local ($vcond) = shift (@cond_vals);
6579                 local ($val) = &unquote_cond_val (shift (@cond_vals));
6580                 $output_vars .= ($vcond . $curs . ' '
6581                                  . $def_type{$curs} . "= ");
6582                 local ($line);
6583                 foreach $line (split ("\n", $val))
6584                 {
6585                     $output_vars .= $vcond . $line . "\n";
6586                 }
6587                 $output_vars .= "\n"
6588                     if $val eq '';
6589             }
6590         }
6591         else
6592         {
6593             $output_vars .= ($curs . ' ' . $def_type{$curs} . '= '
6594                              . $contents{$curs} . "\n");
6595         }
6596     }
6598     # Generate copyright header for generated Makefile.in.
6599     local ($ov) = $output_vars;
6600     $output_vars = ("# $in_file_name generated automatically by automake "
6601                    . $VERSION . " from $am_file_name\n");
6602     $output_vars .= $gen_copyright;
6604     # Now go through and delete all the variables that the user did
6605     # not change.
6606     local ($var);
6607     foreach $var (keys %saved_contents)
6608     {
6609         if ($contents{$var} eq $saved_contents{$var})
6610         {
6611             delete $contents{$var};
6612         }
6613     }
6615     # Re-read the standard variables, and this time keep their
6616     # contributions to the output.  Then add the user's output to the
6617     # end.
6618     &define_standard_variables;
6619     $output_vars .= $ov;
6623 ################################################################
6625 sub initialize_global_constants
6627     # Values for AC_CANONICAL_*
6628     $AC_CANONICAL_HOST = 1;
6629     $AC_CANONICAL_SYSTEM = 2;
6631     # Associative array of standard directory names.  Entry is TRUE if
6632     # corresponding directory should be installed during
6633     # 'install-exec' phase.
6634     %exec_dir_p =
6635         ('bin', 1,
6636          'sbin', 1,
6637          'libexec', 1,
6638          'data', 0,
6639          'sysconf', 1,
6640          'localstate', 1,
6641          'lib', 1,
6642          'info', 0,
6643          'man', 0,
6644          'include', 0,
6645          'oldinclude', 0,
6646          'pkgdata', 0,
6647          'pkglib', 1,
6648          'pkginclude', 0
6649          );
6651     # Commonly found files we look for and automatically include in
6652     # DISTFILES.
6653     @common_files =
6654         (
6655          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
6656          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
6657          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
6658          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
6659          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
6660          # ltconfig appears here for compatibility with old versions
6661          # of libtool.
6662          'ylwrap', 'acinclude.m4', @libtoolize_files, 'ltconfig',
6663          'missing', 'depcomp', 'compile', 'py-compile'
6664          );
6666     # Commonly used files we auto-include, but only sometimes.
6667     @common_sometimes =
6668         (
6669          "aclocal.m4", "acconfig.h", "config.h.top",
6670          "config.h.bot", "stamp-h.in", 'stamp-vti'
6671          );
6673     $USAGE = "\
6674   -a, --add-missing     add missing standard files to package
6675   --amdir=DIR           directory storing config files
6676   -c, --copy            with -a, copy missing files (default is symlink)
6677   --cygnus              assume program is part of Cygnus-style tree
6678   --force-missing       force update of standard files
6679   --foreign             set strictness to foreign
6680   --gnits               set strictness to gnits
6681   --gnu                 set strictness to gnu
6682   --help                print this help, then exit
6683   -i, --ignore-deps     disable dependency tracking code
6684   --include-deps        enable dependency tracking code
6685   --no-force            only update Makefile.in's that are out of date
6686   -o DIR, --output-dir=DIR
6687                         put generated Makefile.in's into DIR
6688   -v, --verbose         verbosely list files processed
6689   --version             print version number, then exit\n";
6691     # Copyright on generated Makefile.ins.
6692     $gen_copyright = "\
6693 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000
6694 # Free Software Foundation, Inc.
6695 # This Makefile.in is free software; the Free Software Foundation
6696 # gives unlimited permission to copy and/or distribute it,
6697 # with or without modifications, as long as this notice is preserved.
6699 # This program is distributed in the hope that it will be useful,
6700 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
6701 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6702 # PARTICULAR PURPOSE.
6705     # This complex find command will try to avoid changing the modes of
6706     # links into the source tree, in case they're hard-linked.  It will
6707     # also make directories writable by everybody, because some
6708     # brain-dead tar implementations change ownership and permissions of
6709     # a directory before extracting the files, thus becoming unable to
6710     # extract them.
6711     # Ignore return result from chmod, because it might give an error
6712     # if we chmod a symlink.
6713     # Another nastiness: if the file is unreadable by us, we make it
6714     # readable regardless of the number of links to it.  This only
6715     # happens in perverse cases.
6716     # We use $(install_sh) because that is a known-portable way to
6717     # modify the file in place in the source tree.
6718     $dist_header = '    -find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \\
6719           ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \\
6720           ! -type d ! -perm -400 -exec chmod a+r {} \; -o \\
6721           ! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \\
6722         || chmod -R a+r $(distdir)
6724     $dist{'dist-bzip2'} = ("\t"
6725                            . '$(AMTAR) chof - $(distdir) | bzip2 -9 -c > $(distdir).tar.bz2'
6726                            . "\n");
6727     $dist{'dist-tarZ'} = ("\t"
6728                      . '$(AMTAR) chof - $(distdir) | compress -c > $(distdir).tar.Z'
6729                      . "\n");
6730     $dist{'dist-shar'} = ("\t"
6731                      . 'shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).shar.gz'
6732                      . "\n");
6733     $dist{'dist-zip'} = ("\t" . '-rm -f $(distdir).zip' . "\n" .
6734                          "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n");
6736     # Note that we don't use GNU tar's `-z' option.  One reason (but
6737     # not the only reason) is that some versions of tar (e.g., OSF1)
6738     # interpret `-z' differently.
6739     $dist{'dist'} = ("\t"
6740                      .  '$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).tar.gz'
6741                      . "\n");
6742     $dist_trailer = "\t" . '-chmod -R a+w $(distdir) > /dev/null 2>&1; rm -rf $(distdir)' . "\n";
6745 # (Re)-Initialize per-Makefile.am variables.
6746 sub initialize_per_input
6748     # These two variables are used when generating each Makefile.in.
6749     # They hold the Makefile.in until it is ready to be printed.
6750     $output_rules = '';
6751     $output_vars = '';
6752     $output_trailer = '';
6753     $output_all = '';
6754     $output_header = '';
6756     # Suffixes found during a run.
6757     @suffixes = ();
6759     # This holds the contents of a Makefile.am, as parsed by
6760     # read_am_file.
6761     %contents = ();
6763     # This holds the names which are targets.  These also appear in
6764     # %contents.
6765     %targets = ();
6767     # This maps a variable name onto a flag.  The flag is true iff the
6768     # variable was first defined with `+='.
6769     %var_was_plus_eq = ();
6771     # This holds definitions of all variables defined in .am files.
6772     # This is used during startup to determine which variables can be
6773     # assigned with `+='.
6774     %am_var_defs = ();
6776     # For a variable or target which is defined conditionally, this
6777     # holds an array of the conditional values.  The array is composed
6778     # of pairs of condition strings (the variables which configure
6779     # will substitute) and values (the value of a target is
6780     # meaningless).  For an unconditional variable, this is empty.
6781     %conditional = ();
6783     # This holds the line numbers at which various elements of
6784     # %contents are defined.
6785     %content_lines = ();
6787     # This holds a 1 if a particular variable was examined.
6788     %content_seen = ();
6790     # This is the conditional stack.
6791     @conditional_stack = ();
6793     # This holds the set of included files.
6794     @include_stack = ();
6796     # This holds the "relative directory" of the current Makefile.in.
6797     # Eg for src/Makefile.in, this is "src".
6798     $relative_dir = '';
6800     # This holds a list of files that are included in the
6801     # distribution.
6802     %dist_common = ();
6804     # List of dependencies for the obvious targets.
6805     @install_data = ();
6806     @install_exec = ();
6807     @uninstall = ();
6808     @installdirs = ();
6810     @info = ();
6811     @dvi = ();
6812     @all = ();
6813     @check = ();
6814     @check_tests = ();
6815     @installcheck = ();
6816     @clean = ();
6818     @phony = ();
6820     # A list of files deleted by `maintainer-clean'.
6821     @maintainer_clean_files = ();
6823     # These are pretty obvious, too.  They are used to define the
6824     # SOURCES and OBJECTS variables.
6825     @sources = ();
6826     @objects = ();
6827     # Sources which go in the distribution.
6828     @dist_sources = ();
6830     # This hash maps object file names onto their corresponding source
6831     # file names.  This is used to ensure that each object is created
6832     # by a single source file.
6833     %object_map = ();
6835     # This keeps track of the directories for which we've already
6836     # created `.dirstamp' code.
6837     %directory_map = ();
6839     # These variables track inclusion of various compile-related .am
6840     # files.  $included_generic_compile is TRUE if the basic code has
6841     # been included.  $included_knr_compile is TRUE if the ansi2knr
6842     # code has been included.  $included_libtool_compile is TRUE if
6843     # libtool support has been included.
6844     $included_generic_compile = 0;
6845     $included_knr_compile = 0;
6846     $included_libtool_compile = 0;
6848     # TRUE if install targets should work recursively.
6849     $recursive_install = 0;
6851     # All .P files.
6852     %dep_files = ();
6854     # Strictness levels.
6855     $strictness = $default_strictness;
6856     $strictness_name = $default_strictness_name;
6858     # Options from AUTOMAKE_OPTIONS.
6859     %options = ();
6861     # Whether or not dependencies are handled.  Can be further changed
6862     # in handle_options.
6863     $use_dependencies = $cmdline_use_dependencies;
6865     # Per Makefile.am.
6866     $local_maint_charset = $maint_charset;
6868     # All yacc and lex source filenames for this directory.  Use
6869     # filenames instead of raw count so that multiple instances are
6870     # counted correctly (eg one yacc file can appear in multiple
6871     # programs without harm).
6872     %yacc_sources = ();
6873     %lex_sources = ();
6875     # This is a list of all targets to run during "make dist".
6876     @dist_targets = ();
6878     # Keys in this hash are the basenames of files which must depend
6879     # on ansi2knr.
6880     %de_ansi_files = ();
6882     # This maps the source extension of a suffix rule to its
6883     # corresponding output extension.
6884     %suffix_rules = ();
6886     # This is a regular expression which matches all the known source
6887     # suffix.  A source suffix is one that appears in the first
6888     # position of a suffix rule.
6889     $source_suffix_pattern = '';
6891     # This is the name of the recursive `all' target to use.
6892     $all_target = 'all-recursive';
6894     # This keeps track of which extensions we've seen (that we care
6895     # about).
6896     %extension_seen = ();
6898     # This is random scratch space for the language finish functions.
6899     # Don't randomly overwrite it; examine other uses of keys first.
6900     %language_scratch = ();
6902     # We keep track of which objects need special (per-executable)
6903     # handling on a per-language basis.
6904     %lang_specific_files = ();
6906     # This is set when `handle_dist' has finished.  Once this happens,
6907     # we should no longer push on dist_common.
6908     $handle_dist_run = 0;
6910     # True if we need `LINK' defined.  This is a hack.
6911     $need_link = 0;
6915 ################################################################
6917 # Return contents of a file from $am_dir, automatically skipping
6918 # macros or rules which are already known.  Runs command on each line
6919 # as it is read; this command can modify $_.
6920 sub file_contents_with_transform
6922     local ($command, $basename) = @_;
6923     local ($file) = $am_dir . '/' . $basename . '.am';
6925     if ($command ne '' && substr ($command, -1) ne ';')
6926     {
6927         die "automake: programming error in file_contents_with_transform: $command\n";
6928     }
6930     open (FC_FILE, $file)
6931         || die "automake: installation error: cannot open \`$file'\n";
6932     # Looks stupid?
6933     # print "automake: reading $file\n" if $verbose;
6935     local ($was_rule) = 0;
6936     local ($result_vars) = '';
6937     local ($result_rules) = '';
6938     local ($comment) = '';
6939     local ($spacing) = "\n";
6940     local ($skipping) = 0;
6941     local ($had_chars);
6943     while (<FC_FILE>)
6944     {
6945         $_ =~ s/\@MAINTAINER_MODE_TRUE\@//g
6946             unless $seen_maint_mode;
6948         $had_chars = length ($_) && $_ ne "\n";
6949         eval $command;
6950         # If the transform caused all the characters to go away, then
6951         # ignore the line.  Why do this?  Because in Perl 4, a "next"
6952         # inside of an eval doesn't affect a loop outside the eval.
6953         # So we can't pass in a "transform" that uses next.  We used
6954         # to do this.  "Empty" also means consisting of a single
6955         # newline.
6956         next if $had_chars && ($_ eq '' || $_ eq "\n");
6958         if (/$IGNORE_PATTERN/o)
6959         {
6960             # Merely delete comments beginning with two hashes.
6961         }
6962         elsif (/$WHITE_PATTERN/o)
6963         {
6964             # Stick a single white line before the incoming macro or rule.
6965             $spacing = "\n";
6966             &am_line_error ($., "blank line following trailing backslash")
6967                 if $saw_bk;
6968         }
6969         elsif (/$COMMENT_PATTERN/o)
6970         {
6971             # Stick comments before the incoming macro or rule.
6972             $comment .= $spacing . $_;
6973             $spacing = '';
6974             &am_line_error ($., "comment following trailing backslash")
6975                 if $saw_bk;
6976         }
6977         elsif ($saw_bk)
6978         {
6979             if ($was_rule)
6980             {
6981                 $result_rules .= $_ if ! $skipping;
6982             }
6983             else
6984             {
6985                 $result_vars .= $_ if ! $skipping;
6986             }
6987             $saw_bk = /\\$/;
6988         }
6989         elsif (/$RULE_PATTERN/o)
6990         {
6991             # Found a rule.
6992             $was_rule = 1;
6993             $skipping = defined $contents{$1};
6994             $result_rules .= $comment . $spacing . $_ if ! $skipping;
6995             $comment = $spacing = '';
6996             $saw_bk = /\\$/;
6997         }
6998         elsif (/$MACRO_PATTERN/o)
6999         {
7000             # Found a variable reference.
7001             $was_rule = 0;
7002             $skipping = defined $contents{$1};
7003             $result_vars .= $comment . $spacing . $_ if ! $skipping;
7004             $comment = $spacing = '';
7005             $saw_bk = /\\$/;
7006             print STDERR "automake: programming error: .am macro \`$1' with trailing backslash at $file:$.\n"
7007                 if $saw_bk;
7008             $am_var_defs{$1} = $3;
7009         }
7010         else
7011         {
7012             # This isn't an error; it is probably a continued rule.
7013             # In fact, this is what we assume.
7014             $was_rule = 1;
7015             $result_rules .= $comment . $spacing . $_ if ! $skipping;
7016             $comment = $spacing = '';
7017             $saw_bk = /\\$/;
7018         }
7019     }
7021     close (FC_FILE);
7022     return $result_vars . $result_rules . $comment;
7025 # Like file_contents_with_transform, but no transform.
7026 sub file_contents
7028     return &file_contents_with_transform ('', @_);
7031 # Find all variable prefixes that are used for install directories.  A
7032 # prefix `zar' qualifies iff:
7033 # * `zardir' is a variable.
7034 # * `zar_PRIMARY' is a variable.
7035 sub am_primary_prefixes
7037     local ($primary, $can_dist, @prefixes) = @_;
7039     local (%valid, $varname);
7040     grep ($valid{$_} = 0, @prefixes);
7041     $valid{'EXTRA'} = 0;
7042     foreach $varname (keys %contents)
7043     {
7044         if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
7045         {
7046             if (($2 ne '' && ! $can_dist)
7047                 || (! defined $valid{$3} && ! &variable_defined ($3 . 'dir')))
7048             {
7049                 # Note that a configure variable is always legitimate.
7050                 # It is natural to name such variables after the
7051                 # primary, so we explicitly allow it.
7052                 if (! defined $configure_vars{$varname})
7053                 {
7054                     &am_line_error ($varname, "invalid variable \`$varname'");
7055                 }
7056             }
7057             else
7058             {
7059                 # Ensure all extended prefixes are actually used.
7060                 $valid{$1 . $2 . $3} = 1;
7061             }
7062         }
7063     }
7065     return %valid;
7068 # Handle `where_HOW' variable magic.  Does all lookups, generates
7069 # install code, and possibly generates code to define the primary
7070 # variable.  The first argument is the name of the .am file to munge,
7071 # the second argument is the primary variable (eg HEADERS), and all
7072 # subsequent arguments are possible installation locations.  Returns
7073 # list of all values of all _HOW targets.
7075 # FIXME: this should be rewritten to be cleaner.  It should be broken
7076 # up into multiple functions.
7078 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7079 sub am_install_var
7081     local (@args) = @_;
7083     local ($do_clean) = 0;
7084     local ($do_require) = 1;
7085     local ($can_dist) = 0;
7086     local ($default_dist) = 0;
7088     local ($ltxform);
7089     if (defined $configure_vars{'LIBTOOL'})
7090     {
7091         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
7092         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
7093     }
7094     else
7095     {
7096         # Delete '@LIBTOOL ...@'
7097         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
7098     }
7100     local ($cygxform);
7101     if (! $seen_exeext)
7102     {
7103         $cygxform = 's/\@EXEEXT\@//g;';
7104     }
7105     else
7106     {
7107         $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
7108     }
7110     while (@args)
7111     {
7112         if ($args[0] eq '-clean')
7113         {
7114             $do_clean = 1;
7115         }
7116         elsif ($args[0] eq '-noextra')
7117         {
7118             $do_require = 0;
7119         }
7120         elsif ($args[0] eq '-candist')
7121         {
7122             $can_dist = 1;
7123         }
7124         elsif ($args[0] eq '-defaultdist')
7125         {
7126             $default_dist = 1;
7127             $can_dist = 1;
7128         }
7129         elsif ($args[0] !~ /^-/)
7130         {
7131             last;
7132         }
7133         shift (@args);
7134     }
7136     local ($file, $primary, @prefixes) = @args;
7138     local (@used) = ();
7139     local (@result) = ();
7141     # Now that configure substitutions are allowed in where_HOW
7142     # variables, it is an error to actually define the primary.  We
7143     # allow `JAVA', as it is customarily used to mean the Java
7144     # interpreter.  This is but one of several Java hacks.  Similarly,
7145     # `PYTHON' is customarily used to mean the Python interpreter.
7146     &am_line_error ($primary, "\`$primary' is an anachronism")
7147         if &variable_defined ($primary)
7148             && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7151     # Look for misspellings.  It is an error to have a variable ending
7152     # in a "reserved" suffix whose prefix is unknown, eg
7153     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
7154     # variable of the same name (with "dir" appended) exists.  For
7155     # instance, if the variable "zardir" is defined, then
7156     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
7157     # flexibility in those cases which need it.
7158     local (%valid) = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7160     # If a primary includes a configure substitution, then the EXTRA_
7161     # form is required.  Otherwise we can't properly do our job.
7162     local ($require_extra);
7163     local ($warned_about_extra) = 0;
7165     local ($clean_file) = $file . '-clean';
7166     local ($one_name);
7167     local ($X);
7168     local ($nodir_name);
7169     local ($strip_subdir) = 1;
7170     foreach $X (sort keys %valid)
7171     {
7172         $one_name = $X . '_' . $primary;
7173         if (&variable_defined ($one_name))
7174         {
7175             # If subdir prefix should be preserved, do so.
7176             if ($X =~ /^nobase_/)
7177             {
7178                 $strip_subdir = 0;
7179                 $X =~ s/^nobase_//;
7180             }
7182             # If files should be distributed, do so.
7183             if ($can_dist)
7184             {
7185                 if (($default_dist && $one_name !~ /^nodist_/)
7186                     || (! $default_dist && $one_name =~ /^dist_/))
7187                 {
7188                     &push_dist_common ('$(' . $one_name . ')');
7189                 }
7190                 ($nodir_name = $X) =~ s/^(dist|nodist)_//;
7191             }
7192             else
7193             {
7194                 $nodir_name = $X;
7195             }
7197             # Append actual contents of where_PRIMARY variable to
7198             # result.
7199             local ($rcurs);
7200             foreach $rcurs (&variable_value_as_list ($one_name, 'all'))
7201             {
7202                 # Skip configure substitutions.  Possibly bogus.
7203                 if ($rcurs =~ /^\@.*\@$/)
7204                 {
7205                     if ($X eq 'EXTRA')
7206                     {
7207                         if (! $warned_about_extra)
7208                         {
7209                             $warned_about_extra = 1;
7210                             {
7211                                 &am_line_error ($one_name,
7212                                                 "\`$one_name' contains configure substitution, but shouldn't");
7213                             }
7214                         }
7215                     }
7216                     # Check here to make sure variables defined in
7217                     # configure.in do not imply that EXTRA_PRIMARY
7218                     # must be defined.
7219                     elsif (! defined $configure_vars{$one_name})
7220                     {
7221                         $require_extra = $one_name
7222                             if $do_require;
7223                     }
7225                     next;
7226                 }
7228                 push (@result, $rcurs);
7229             }
7231             # A blatant hack: we rewrite each _PROGRAMS primary to
7232             # include EXEEXT when in Cygwin32 mode.
7233             if ($seen_exeext && $primary eq 'PROGRAMS')
7234             {
7235                 local (@conds) = &variable_conditions ($one_name);
7236                 local (@one_binlist);
7238                 # FIXME: this definitely loses aesthetically; it
7239                 # redefines $ONE_NAME.  Instead we should arrange for
7240                 # variable definitions to be output later, instead of
7241                 # at scan time.
7243                 if (! @conds)
7244                 {
7245                     @one_binlist = ();
7246                     foreach $rcurs (&variable_value_as_list ($one_name, ''))
7247                     {
7248                         if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7249                         {
7250                             push (@one_binlist, $rcurs);
7251                         }
7252                         else
7253                         {
7254                             push (@one_binlist, $rcurs . '$(EXEEXT)');
7255                         }
7256                     }
7258                     delete $contents{$one_name};
7259                     &define_pretty_variable ($one_name, '', @one_binlist);
7260                 }
7261                 else
7262                 {
7263                     local ($cond);
7264                     local ($condvals) = '';
7265                     foreach $cond (@conds)
7266                     {
7267                         @one_binlist = ();
7268                         local (@condval) = &variable_value_as_list ($one_name,
7269                                                                     $cond);
7270                         foreach $rcurs (@condval)
7271                         {
7272                             if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7273                             {
7274                                 push (@one_binlist, $rcurs);
7275                             }
7276                             else
7277                             {
7278                                 push (@one_binlist, $rcurs . '$(EXEEXT)');
7279                             }
7280                         }
7282                         push (@condvals, $cond);
7283                         push (@condvals, join (' ', @one_binlist));
7284                     }
7286                     delete $contents{$one_name};
7288                     while (@condvals)
7289                     {
7290                         $cond = shift (@condvals);
7291                         local (@val) = split (' ', shift (@condvals));
7292                         &define_pretty_variable ($one_name, $cond, @val);
7293                     }
7294                 }
7295             }
7297             # "EXTRA" shouldn't be used when generating clean targets,
7298             # all, or install targets.
7299             if ($X eq 'EXTRA')
7300             {
7301                 # We used to warn if EXTRA_FOO was defined uselessly,
7302                 # but this was annoying.
7303                 next;
7304             }
7306             if ($do_clean)
7307             {
7308                 $output_rules .=
7309                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
7310                                                    . $cygxform,
7311                                                    $clean_file);
7313                 push (@clean, $X . $primary);
7314                 &push_phony_cleaners ($X . $primary);
7315             }
7317             if ($X eq 'check')
7318             {
7319                 push (@check, '$(' . $one_name . ')');
7320             }
7321             else
7322             {
7323                 push (@used, '$(' . $one_name . ')');
7324             }
7325             if ($X eq 'noinst' || $X eq 'check')
7326             {
7327                 # Objects which don't get installed by default.
7328                 next;
7329             }
7331             local ($subdir_xform);
7332             if ($strip_subdir)
7333             {
7334                 $subdir_xform = 's/^NOBASE.*$//; s/^BASE//;';
7335             }
7336             else
7337             {
7338                 $subdir_xform = 's/^BASE.*$//; s/^NOBASE//;';
7339             }
7341             $output_rules .=
7342                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
7343                                                . 's/\@NDIR\@/' . $nodir_name . '/go;'
7344                                                . $ltxform . $cygxform
7345                                                . $subdir_xform,
7346                                                $file);
7348             push (@uninstall, 'uninstall-' . $X . $primary);
7349             push (@phony, 'uninstall-' . $X . $primary);
7350             push (@installdirs, '$(DESTDIR)$(' . $X . 'dir)');
7351             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
7352             {
7353                 push (@install_exec, 'install-' . $X . $primary);
7354                 push (@phony, 'install-' . $X . $primary);
7355             }
7356             else
7357             {
7358                 push (@install_data, 'install-' . $X . $primary);
7359                 push (@phony, 'install-' . $X . $primary);
7360             }
7361         }
7362     }
7364     # The JAVA variable is used as the name of the Java interpreter.
7365     # The PYTHON variable is used as the name of the Python interpreter.
7366     if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7367     {
7368         # Define it.
7369         &define_pretty_variable ($primary, '', @used);
7370         $output_vars .= "\n";
7371     }
7373     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7374     {
7375         &am_line_error ($require_extra,
7376                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
7377     }
7379     # Push here because PRIMARY might be configure time determined.
7380     push (@all, '$(' . $primary . ')')
7381         if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7383     # Make the result unique.  This lets the user use conditionals in
7384     # a natural way, but still lets us program lazily -- we don't have
7385     # to worry about handling a particular object more than once.
7386     local (%uniquify) = ();
7387     grep ($uniquify{$_} = 1, @result);
7388     return sort keys %uniquify;
7392 ################################################################
7394 # Each key in this hash is the name of a directory holding a
7395 # Makefile.in.  These variables are local to `is_make_dir'.
7396 %make_dirs = ();
7397 $make_dirs_set = 0;
7399 sub is_make_dir
7401     local ($dir) = @_;
7402     if (! $make_dirs_set)
7403     {
7404         foreach $iter (@configure_input_files)
7405         {
7406             $make_dirs{&dirname ($iter)} = 1;
7407         }
7408         # We also want to notice Makefile.in's.
7409         foreach $iter (@other_input_files)
7410         {
7411             if ($iter =~ /Makefile\.in$/)
7412             {
7413                 $make_dirs{&dirname ($iter)} = 1;
7414             }
7415         }
7416         $make_dirs_set = 1;
7417     }
7418     return defined $make_dirs{$dir};
7421 ################################################################
7423 # This variable is local to the "require file" set of functions.
7424 @require_file_paths = ();
7426 # If a file name appears as a key in this hash, then it has already
7427 # been checked for.  This variable is local to the "require file"
7428 # functions.
7429 %require_file_found = ();
7431 # See if we want to push this file onto dist_common.  This function
7432 # encodes the rules for deciding when to do so.
7433 sub maybe_push_required_file
7435     local ($dir, $file, $fullfile) = @_;
7437     # FIXME: Once again, special-case `.'.
7438     if ($dir eq $relative_dir || $dir eq '.')
7439     {
7440         &push_dist_common ($file);
7441     }
7442     elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7443     {
7444         # If we are doing the topmost directory, and the file is in a
7445         # subdir which does not have a Makefile, then we distribute it
7446         # here.
7447         &push_dist_common ($fullfile);
7448     }
7451 # Verify that the file must exist in the current directory.  Usage:
7452 # require_file (isconfigure, line_number, strictness, file) strictness
7453 # is the strictness level at which this file becomes required.  Must
7454 # set require_file_paths before calling this function.
7455 # require_file_paths is set to hold a single directory (the one in
7456 # which the first file was found) before return.
7457 sub require_file_internal
7459     local ($is_configure, $line, $mystrict, @files) = @_;
7460     local ($file, $fullfile);
7461     local ($found_it, $dangling_sym, $errfile, $errdir);
7462     local ($save_dir);
7464     foreach $file (@files)
7465     {
7466         # If we've already looked for it, we're done.
7467         next if defined $require_file_found{$file};
7468         $require_file_found{$file} = 1;
7470         $found_it = 0;
7471         $dangling_sym = 0;
7472         foreach $dir (@require_file_paths)
7473         {
7474             if ($dir eq '.')
7475             {
7476                 $fullfile = $relative_dir . "/" . $file;
7477                 $errdir = $relative_dir unless $errdir;
7478             }
7479             else
7480             {
7481                 $fullfile = $dir . "/" . $file;
7482                 $errdir = $dir unless $errdir;
7483             }
7485             # Use different name for "error filename".  Otherwise on
7486             # an error the bad file will be reported as eg
7487             # `../../install-sh' when using the default
7488             # config_aux_path.
7489             $errfile = $errdir . '/' . $file;
7491             if (-l $fullfile && ! -f readlink ($fullfile))
7492             {
7493                 $dangling_sym = 1;
7494                 last;
7495             }
7496             elsif (-f $fullfile)
7497             {
7498                 $found_it = 1;
7499                 &maybe_push_required_file ($dir, $file, $fullfile);
7500                 $save_dir = $dir;
7501                 last;
7502             }
7503         }
7505         if ($found_it && ! $force_missing)
7506         {
7507             # Prune the path list.
7508             @require_file_paths = $save_dir;
7509         }
7510         else
7511         {
7512             if ($strictness >= $mystrict)
7513             {
7514                 if ($dangling_sym && ($force_missing || $add_missing))
7515                 {
7516                     unlink ($fullfile);
7517                 }
7519                 local ($trailer) = '';
7520                 local ($suppress) = 0;
7522                 # Only install missing files according to our desired
7523                 # strictness level.
7524                 local ($message) = "required file \`$errfile' not found";
7525                 if ($add_missing)
7526                 {
7527                     $suppress = 1;
7529                     # Maybe run libtoolize.
7530                     local @syslist = ('libtoolize', '--automake');
7531                     push @syslist, '--copy'
7532                         if $copy_missing;
7533                     if ($seen_libtool
7534                         && grep ($_ eq $file, @libtoolize_files)
7535                         && system (@syslist))
7536                     {
7537                         $message = "installing \`$errfile'";
7538                         $suppress = 0;
7539                         $trailer = "; cannot run \`libtoolize': $!";
7540                     }
7541                     elsif (-f ($am_dir . '/' . $file))
7542                     {
7543                         # Install the missing file.  Symlink if we
7544                         # can, copy if we must.  Note: delete the file
7545                         # first, in case it is a dangling symlink.
7546                         $message = "installing \`$errfile'";
7547                         # Windows Perl will hang if we try to delete a
7548                         # file that doesn't exist.
7549                         unlink ($errfile) if -f $errfile;
7550                         if ($symlink_exists && ! $copy_missing)
7551                         {
7552                             if (! symlink ($am_dir . '/' . $file, $errfile))
7553                             {
7554                                 $suppress = 0;
7555                                 $trailer = "; error while making link: $!";
7556                             }
7557                         }
7558                         elsif (system ('cp', $am_dir . '/' . $file, $errfile))
7559                         {
7560                             $suppress = 0;
7561                             $trailer = "\n    error while copying";
7562                         }
7563                     }
7565                     &maybe_push_required_file (&dirname ($errfile),
7566                                                $file, $errfile);
7567                 }
7569                 local ($save) = $exit_status;
7570                 if ($is_configure)
7571                 {
7572                     # FIXME: allow actual file to be specified.
7573                     &am_conf_line_error ('configure.in', $line,
7574                                          "$message$trailer");
7575                 }
7576                 else
7577                 {
7578                     &am_line_error ($line, "$message$trailer");
7579                 }
7580                 $exit_status = $save if $suppress;
7581             }
7582         }
7583     }
7586 # Like require_file_with_line, but error messages refer to
7587 # configure.in, not the current Makefile.am.
7588 sub require_file_with_conf_line
7590     @require_file_paths = '.';
7591     &require_file_internal (1, @_);
7594 sub require_file_with_line
7596     @require_file_paths = '.';
7597     &require_file_internal (0, @_);
7600 sub require_file
7602     @require_file_paths = '.';
7603     &require_file_internal (0, '', @_);
7606 # Require a file that is also required by Autoconf.  Looks in
7607 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7608 sub require_config_file
7610     @require_file_paths = @config_aux_path;
7611     &require_file_internal (1, '', @_);
7612     local ($dir) = $require_file_paths[0];
7613     @config_aux_path = @require_file_paths;
7614     if ($dir eq '.')
7615     {
7616         $config_aux_dir = '.';
7617     }
7618     else
7619     {
7620         $config_aux_dir = '$(top_srcdir)/' . $dir;
7621     }
7624 # Assumes that the line number is in Makefile.am.
7625 sub require_conf_file_with_line
7627     @require_file_paths = @config_aux_path;
7628     &require_file_internal (0, @_);
7629     local ($dir) = $require_file_paths[0];
7630     @config_aux_path = @require_file_paths;
7631     if ($dir eq '.')
7632     {
7633         $config_aux_dir = '.';
7634     }
7635     else
7636     {
7637         $config_aux_dir = '$(top_srcdir)/' . $dir;
7638     }
7641 # Assumes that the line number is in configure.in.
7642 sub require_conf_file_with_conf_line
7644     @require_file_paths = @config_aux_path;
7645     &require_file_internal (1, @_);
7646     local ($dir) = $require_file_paths[0];
7647     @config_aux_path = @require_file_paths;
7648     if ($dir eq '.')
7649     {
7650         $config_aux_dir = '.';
7651     }
7652     else
7653     {
7654         $config_aux_dir = '$(top_srcdir)/' . $dir;
7655     }
7658 ################################################################
7660 # Push a list of files onto dist_common.
7661 sub push_dist_common
7663     local (@files) = @_;
7664     local ($file);
7666     foreach $file (@files)
7667     {
7668         if (! defined $dist_common{$file})
7669         {
7670             if ($handle_dist_run)
7671             {
7672                 print STDERR
7673                     "automake: programming error: push_dist_common run after handle_dist\n";
7674                 exit 1;
7675             }
7676             $dist_common{$file} = 1;
7677         }
7678     }
7681 # Push a list of clean targets onto phony.
7682 sub push_phony_cleaners
7684     local ($base) = @_;
7685     local ($target);
7686     foreach $target ('mostly', 'dist', '', 'maintainer-')
7687     {
7688         push (@phony, $target . 'clean-' . $base);
7689     }
7692 # Set strictness.
7693 sub set_strictness
7695     $strictness_name = $_[0];
7696     if ($strictness_name eq 'gnu')
7697     {
7698         $strictness = $GNU;
7699     }
7700     elsif ($strictness_name eq 'gnits')
7701     {
7702         $strictness = $GNITS;
7703     }
7704     elsif ($strictness_name eq 'foreign')
7705     {
7706         $strictness = $FOREIGN;
7707     }
7708     else
7709     {
7710         die "automake: level \`$strictness_name' not recognized\n";
7711     }
7715 ################################################################
7717 # Return directory name of file.
7718 sub dirname
7720     local ($file) = @_;
7721     local ($sub);
7723     ($sub = $file) =~ s,/+[^/]+$,,g;
7724     $sub = '.' if $sub eq $file;
7725     return $sub;
7728 # Return file name of a file.
7729 sub basename
7731     local ($file) = @_;
7732     local ($sub);
7734     ($sub = $file) =~s,^.*/+,,g;
7735     return $sub;
7738 # Ensure a file exists.
7739 sub create
7741     local ($file) = @_;
7743     open (TOUCH, ">> $file");
7744     close (TOUCH);
7747 # Glob something.  Do this to avoid indentation screwups everywhere we
7748 # want to glob.  Gross!
7749 sub my_glob
7751     local ($pat) = @_;
7752     return <${pat}>;
7755 ################################################################
7757 # Print an error message and set exit status.
7758 sub am_error
7760     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
7761     $exit_status = 1;
7764 sub am_line_error
7766     local ($symbol, @args) = @_;
7768     if ($symbol && "$symbol" ne '-1')
7769     {
7770         local ($file) = "${am_file}.am";
7772         if ($symbol =~ /^\d+$/)
7773         {
7774             # SYMBOL is a line number, so just add the colon.
7775             $file .= ':' . $symbol;
7776         }
7777         elsif (defined $content_lines{$symbol})
7778         {
7779             # SYMBOL is a variable defined in Makefile.am, so add the
7780             # line number we saved from there.
7781             $file .= ':' . $content_lines{$symbol};
7782         }
7783         elsif (defined $configure_vars{$symbol})
7784         {
7785             # SYMBOL is a variable defined in configure.in, so add the
7786             # appropriate line number.
7787             $file = $configure_vars{$symbol};
7788         }
7789         else
7790         {
7791             # Couldn't find the line number.
7792         }
7793         warn $file, ": ", join (' ', @args), "\n";
7794         $exit_status = 1;
7795     }
7796     else
7797     {
7798         &am_error (@args);
7799     }
7802 # Like am_error, but while scanning configure.in.
7803 sub am_conf_error
7805     # FIXME: can run in subdirs.
7806     warn "automake: configure.in: ", join (' ', @_), "\n";
7807     $exit_status = 1;
7810 # Error message with line number referring to configure.in.
7811 sub am_conf_line_error
7813     local ($file, $line, @args) = @_;
7815     if ($line)
7816     {
7817         warn "$file: $line: ", join (' ', @args), "\n";
7818         $exit_status = 1;
7819     }
7820     else
7821     {
7822         &am_conf_error (@args);
7823     }
7826 # Warning message with line number referring to configure.in.
7827 # Does not affect exit_status
7828 sub am_conf_line_warning
7830     local ($saved_exit_status) = $exit_status;
7831     &am_conf_line_error (@_);
7832     $exit_status = $saved_exit_status;
7835 # Tell user where our aclocal.m4 is, but only once.
7836 sub keyed_aclocal_warning
7838     local ($key) = @_;
7839     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
7842 # Print usage information.
7843 sub usage
7845     print "Usage: automake [OPTION] ... [Makefile]...\n\n";
7846     print "Generate Makefile.in for autoconf from Makefile.am\n";
7847     print $USAGE;
7848     print "\nFiles which are automatically distributed, if found:\n";
7849     $~ = "USAGE_FORMAT";
7850     local ($last, $iter, @lcomm);
7851     $last = '';
7852     foreach $iter (sort ((@common_files, @common_sometimes)))
7853     {
7854         push (@lcomm, $iter) unless $iter eq $last;
7855         $last = $iter;
7856     }
7858     local ($one, $two, $three, $four, $i, $max);
7859     $max = int (($#lcomm + 1) / 4);
7861     for ($i = 0; $i < $max; ++$i)
7862     {
7863         $one = $lcomm[$i];
7864         $two = $lcomm[$max + $i];
7865         $three = $lcomm[2 * $max + $i];
7866         $four = $lcomm[3 * $max + $i];
7867         write;
7868     }
7870     local ($mod) = ($#lcomm + 1) % 4;
7871     if ($mod != 0)
7872     {
7873         $one = $lcomm[$max];
7874         $two = ($mod > 1) ? $lcomm[2 * $max] : '';
7875         $three = ($mod > 2) ? $lcomm[3 * $max] : '';
7876         $four = ($mod > 3) ? $lcomm[4 * $max] : '';
7877         write;
7878     }
7880     print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7882     exit 0;
7885 format USAGE_FORMAT =
7886   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
7887   $one,               $two,               $three,             $four