* automake.in (handle_dist): Use AMTAR.
[automake.git] / automake.in
bloba047d67e8de74651617667f35bebf8655cd52fe7
1 #!@PERL@
2 # -*- perl -*-
3 # @configure_input@
5 eval 'exec @PERL@ -S $0 ${1+"$@"}'
6     if 0;
8 # automake - create Makefile.in from Makefile.am
9 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
14 # any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 # 02111-1307, USA.
26 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
27 # Perl reimplementation by Tom Tromey <tromey@cygnus.com>.
30 # Parameters set by configure.  Not to be changed.  NOTE: assign
31 # VERSION as string so that eg version 0.30 will print correctly.
32 $VERSION = "@VERSION@";
33 $PACKAGE = "@PACKAGE@";
34 $prefix = "@prefix@";
35 $am_dir = "@datadir@/@PACKAGE@";
37 # String constants.
38 $IGNORE_PATTERN = "^##([^#].*)?\$";
39 $WHITE_PATTERN = "^[ \t]*\$";
40 $COMMENT_PATTERN = "^#";
41 $RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/\$]*) *:([^=].*|)\$";
42 $SUFFIX_RULE_PATTERN = "^\\.([a-zA-Z]+)\\.([a-zA-Z]+)\$";
43 $MACRO_PATTERN = "^([A-Za-z][A-Za-z0-9_]*)[ \t]*([:+]?)=[ \t]*(.*)\$";
44 $BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*([:+]?)=[ \t]*(.*)\$";
45 $GNITS_VERSION_PATTERN = "[0-9]+\\.[0-9]+([a-z]|\\.[0-9]+)?";
46 $IF_PATTERN = "^if[ \t]+\([A-Za-z][A-Za-z0-9_]*\)[ \t]*\(#.*\)?\$";
47 $ELSE_PATTERN = "^else[ \t]*\(#.*\)?\$";
48 $ENDIF_PATTERN = "^endif[ \t]*\(#.*\)?\$";
49 $PATH_PATTERN='(\\w|/|\\.)+';
50 # This will pass through anything not of the prescribed form.
51 $INCLUDE_PATTERN = "^include[ \t]+((\\\$\\\(top_srcdir\\\)/${PATH_PATTERN})|(\\\$\\\(srcdir\\\)/${PATH_PATTERN})|([^/\\\$]${PATH_PATTERN}))[ \t]*(#.*)?\$";
53 # Some regular expressions.  One reason to put them here is that it
54 # makes indentation work better in Emacs.
55 $AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
56 $AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^,)]+)[,)]";
57 $AM_PACKAGE_VERSION_PATTERN = "^\\s*\\[?([^]\\s]+)\\]?\\s*\$";
58 # Note that there is no AC_PATH_TOOL.  But we don't really care.
59 $AC_CHECK_PATTERN = "AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\\(\\[?(\\w+)";
60 $AM_MISSING_PATTERN = "AM_MISSING_PROG\\(\\[?(\\w+)";
61 # Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
62 # then too bad.
63 $AC_SUBST_PATTERN = "AC_SUBST\\(\\[?(\\w+)";
64 $AM_CONDITIONAL_PATTERN = "AM_CONDITIONAL\\((\\w+)";
66 # Constants to define the "strictness" level.
67 $FOREIGN = 0;
68 $GNU = 1;
69 $GNITS = 2;
71 # These constants are returned by lang_*_rewrite functions.
72 # LANG_SUBDIR means that the resulting object file should be in a
73 # subdir if the source file is.  In this case the file name cannot
74 # have `..' components.
75 $LANG_IGNORE = 0;
76 $LANG_PROCESS = 1;
77 $LANG_SUBDIR = 2;
81 # Variables global to entire run.
83 # TRUE if we should always generate Makefile.in.
84 $force_generation = 1;
86 # Strictness level as set on command line.
87 $default_strictness = $GNU;
89 # Name of strictness level, as set on command line.
90 $default_strictness_name = 'gnu';
92 # This is TRUE if GNU make specific automatic dependency generation
93 # code should be included in generated Makefile.in.
94 $cmdline_use_dependencies = 1;
96 # This is the name of a dependency makefile bit (usually for inclusion in a
97 # SMakefile or similar); empty if not set.
98 $generate_deps = '';
100 # TRUE if in verbose mode.
101 $verbose = 0;
103 # This holds our (eventual) exit status.  We don't actually exit until
104 # we have processed all input files.
105 $exit_status = 0;
107 # From the Perl manual.
108 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
110 # TRUE if missing standard files should be installed.
111 $add_missing = 0;
113 # TRUE if we should copy missing files; otherwise symlink if possible.
114 $copy_missing = 0;
116 # Files found by scanning configure.in for LIBOBJS.
117 %libsources = ();
119 # True if AM_C_PROTOTYPES appears in configure.in.
120 $am_c_prototypes = 0;
122 # Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
123 # name which appears in AC_CONFIG_HEADER, colon and all.
124 # @config_names holds the file names.  @config_headers holds the '.in'
125 # files.  Ordinarily these are similar, but they can be different if
126 # the weird "NAME:FILE" syntax is used.
127 @config_fullnames = ();
128 @config_names = ();
129 @config_headers = ();
130 # Line number at which AC_CONFIG_HEADER appears in configure.in.
131 $config_header_line = 0;
133 # Directory where output files go.  Actually, output files are
134 # relative to this directory.
135 $output_directory = '.';
137 # Relative location of top build directory.
138 $top_builddir = '';
140 # Absolute location of top build directory.
141 $build_directory = '';
143 # Name of srcdir as given in build directory's Makefile.  For
144 # dependencies only.
145 $srcdir_name = '';
147 # List of Makefile.am's to process, and their corresponding outputs.
148 @input_files = ();
149 %output_files = ();
151 # Complete list of Makefile.am's that exist.
152 @configure_input_files = ();
154 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
155 @other_input_files = ();
156 # Line number at which AC_OUTPUT seen.
157 $ac_output_line = 0;
159 # List of directories to search for configure-required files.  This
160 # can be set by AC_CONFIG_AUX_DIR.
161 @config_aux_path = ('.', '..', '../..');
162 $config_aux_dir = '';
164 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
165 $seen_make_set = 0;
167 # Whether AM_GNU_GETTEXT has been seen in configure.in.
168 $seen_gettext = 0;
169 # Line number at which AM_GNU_GETTEXT seen.
170 $ac_gettext_line = 0;
172 # Whether ALL_LINGUAS has been seen.
173 $seen_linguas = '';
174 # The actual text.
175 $all_linguas = '';
176 # Line number at which it appears.
177 $all_linguas_line = 0;
179 # 1 if AC_PROG_INSTALL seen.
180 $seen_prog_install = 0;
182 # Whether AC_PATH_XTRA has been seen in configure.in.
183 $seen_path_xtra = 0;
185 # TRUE if AC_DECL_YYTEXT was seen.
186 $seen_decl_yytext = 0;
188 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
189 # AC_CHECK_TOOL also sets this.
190 $seen_canonical = 0;
192 # TRUE if we've seen AC_ARG_PROGRAM.
193 $seen_arg_prog = 0;
195 # TRUE if we've seen AC_PROG_LIBTOOL.
196 $seen_libtool = 0;
197 $libtool_line = 0;
199 # Files installed by libtoolize.
200 @libtoolize_files = ('ltconfig', 'ltmain.sh', 'config.guess', 'config.sub');
202 # TRUE if we've seen AM_MAINTAINER_MODE.
203 $seen_maint_mode = 0;
205 # TRUE if we've seen PACKAGE and VERSION.
206 $seen_package = 0;
207 $seen_version = 0;
209 # Actual version we've seen.
210 $package_version = '';
212 # Line number where we saw version definition.
213 $package_version_line = 0;
215 # TRUE if we've seen AM_PATH_LISPDIR.
216 $seen_lispdir = 0;
218 # TRUE if we've seen AC_EXEEXT.
219 $seen_exeext = 0;
221 # TRUE if we've seen AC_OBJEXT.
222 $seen_objext = 0;
224 # TRUE if we've seen AC_ENABLE_MULTILIB.
225 $seen_multilib = 0;
227 # TRUE if we've seen AM_PROG_CC_C_O
228 $seen_cc_c_o = 0;
230 # Hash table of discovered configure substitutions.  Keys are names,
231 # values are `FILE:LINE' strings which are used by error message
232 # generation.
233 %configure_vars = ();
235 # This is used to keep track of which variable definitions we are
236 # scanning.  It is only used in certain limited ways, but it has to be
237 # global.  It is declared just for documentation purposes.
238 %vars_scanned = ();
240 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
241 # handled in a funny way: if seen in the top-level Makefile.am, it is
242 # used for every directory which does not specify a different value.
243 # The rationale here is that some directories (eg gettext) might be
244 # distributions of other packages, and thus require their own charset
245 # info.  However, the DIST_CHARSET must be the same for the entire
246 # package; it can only be set at top-level.
247 # FIXME: this yields bugs when rebuilding.  What to do?  Always
248 # read (and sometimes discard) top-level Makefile.am?
249 $maint_charset = '';
250 $dist_charset = 'utf8';         # recode doesn't support this yet.
252 # Name of input file ("Makefile.in") and output file ("Makefile.am").
253 # These have no directory components.
254 $am_file_name = '';
255 $in_file_name = '';
257 # TRUE if --cygnus seen.
258 $cygnus_mode = 0;
260 # Keys of this hash are names of dependency files to ignore.
261 %omit_dependencies = ();
263 # Hash table of AM_CONDITIONAL variables seen in configure.
264 %configure_cond = ();
266 # Map from obsolete macros to hints for new macros.
267 # If you change this, change the corresponding list in aclocal.in.
268 # FIXME: should just put this into a single file.
269 %obsolete_macros =
270     (
271      'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
272      'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
273      'AC_FEATURE_EXIT', '',
274      'AC_SYSTEM_HEADER', '',
276      # Note that we do not handle this one, because it is still run
277      # from AM_CONFIG_HEADER.  So we deal with it specially in
278      # scan_configure.
279      # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",
281      'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
282      'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
283      'fp_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
284      'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
285      'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
286      'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
287      'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
288      'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
289      'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",
290      'ud_GNU_GETTEXT', "use \`AM_GNU_GETTEXT'",
292      # Now part of autoconf proper, under a different name.
293      'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
294      'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
295      'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",
296      'AM_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
297      'AM_EXEEXT', "use \`AC_EXEEXT'",
298      'AM_CYGWIN32', "use \`AC_CYGWIN32'",
299      'AM_MINGW32', "use \`AC_MINGW32'",
301 # These aren't quite obsolete.
302 #      'md_PATH_PROG',
303      );
305 # Regexp to match the above macros.
306 $obsolete_rx = '(' . join ('|', keys %obsolete_macros) . ')';
308 # This maps extensions onto language names.
309 %extension_map = ();
311 # This maps languages names onto properties.
312 %language_map = ();
316 # Initialize global constants and our list of languages that are
317 # internally supported.
318 &initialize_global_constants;
320 &register_language ('c', 'ansi-p=1', 'autodep=',
321                     'c');
322 &register_language ('cxx', 'linker=CXXLINK', 'autodep=CXX',
323                     'c++', 'cc', 'cpp', 'cxx', 'C');
324 &register_language ('objc', 'linker=OBJCLINK', 'autodep=OBJC',
325                     'm');
326 &register_language ('header',
327                     'h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc');
328 &register_language ('yacc', 'ansi-p=1',
329                     'y');
330 &register_language ('yaccxx', 'linker=CXXLINK',
331                     'y++', 'yy', 'yxx', 'ypp');
332 &register_language ('lex', 'ansi-p=1',
333                     'l');
334 &register_language ('lexxx', 'linker=CXXLINK',
335                     'l++', 'll', 'lxx', 'lpp');
336 &register_language ('asm',
337                     's', 'S');
338 &register_language ('f77', 'linker=F77LINK',
339                     'f', 'for', 'f90');
340 &register_language ('ppf77', 'linker=F77LINK',
341                     'F');
342 &register_language ('ratfor', 'linker=F77LINK',
343                     'r');
344 &register_language ('java', 'linker=GCJLINK', 'autodep=GCJ',
345                     'java');
348 # Parse command line.
349 &parse_arguments (@ARGV);
351 # Do configure.in scan only once.
352 &scan_configure;
354 die "automake: no \`Makefile.am' found or specified\n"
355     if ! @input_files;
357 # If --generate-deps was given, we don't do anything else
359 if ($generate_deps)
361     die "automake: Must specify --include-deps (or -i) when generating\n"
362         if $use_dependencies;
363     die "automake: Must provide --build-dir when generating\n"
364         if ! $build_directory;
365     die "automake: Must provide --srcdir-name when generating\n"
366         if ! $srcdir_name;
368     open (GDEP, ">$output_directory/.dep_segment")
369         || die "automake: Could not open `$output_directory/.dep_segment': $!\n";
371     &handle_dependencies;
372     print GDEP $output_rules;
374     close(GDEP);
375     exit $exit_status;
378 # Now do all the work on each file.
379 foreach $am_file (@input_files)
381     if (! -f ($am_file . '.am'))
382     {
383         &am_error ("\`" . $am_file . ".am' does not exist");
384     }
385     else
386     {
387         &generate_makefile ($output_files{$am_file}, $am_file);
388     }
391 &am_conf_error ("AC_PROG_INSTALL must be used in configure.in")
392     if (! $seen_prog_install);
394 exit $exit_status;
397 ################################################################
399 # Parse command line.
400 sub parse_arguments
402     local (@arglist) = @_;
404     # Start off as gnu.
405     &set_strictness ('gnu');
407     while (@arglist)
408     {
409         if ($arglist[0] eq "--version")
410         {
411             print "automake (GNU $PACKAGE) $VERSION\n\n";
412             print "Copyright (C) 1999 Free Software Foundation, Inc.\n";
413             print "This is free software; see the source for copying conditions.  There is NO\n";
414             print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
415             print "Written by Tom Tromey <tromey\@cygnus.com>\n";
417             exit 0;
418         }
419         elsif ($arglist[0] eq "--help")
420         {
421             &usage;
422         }
423         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
424         {
425             $am_dir = $1;
426         }
427         elsif ($arglist[0] eq '--amdir')
428         {
429             &require_argument (@arglist);
430             shift (@arglist);
431             $am_dir = $arglist[0];
432         }
433         elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
434         {
435             # Must end in /.
436             $build_directory = $1 . '/';
437         }
438         elsif ($arglist[0] eq '--build-dir')
439         {
440             &require_argument (@arglist);
441             shift (@arglist);
442             # Must end in /.
443             $build_directory = $arglist[0] . '/';
444         }
445         elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
446         {
447             $srcdir_name = $1;
448         }
449         elsif ($arglist[0] eq '--srcdir-name')
450         {
451             &require_argument (@arglist);
452             shift (@arglist);
453             $srcdir_name = $arglist[0];
454         }
455         elsif ($arglist[0] eq '--gnu')
456         {
457             &set_strictness ('gnu');
458         }
459         elsif ($arglist[0] eq '--gnits')
460         {
461             &set_strictness ('gnits');
462         }
463         elsif ($arglist[0] eq '--cygnus')
464         {
465             $cygnus_mode = 1;
466         }
467         elsif ($arglist[0] eq '--foreign')
468         {
469             &set_strictness ('foreign');
470         }
471         elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
472         {
473             $cmdline_use_dependencies = 0;
474         }
475         elsif ($arglist[0] eq '--generate-deps')
476         {
477             $generate_deps = 1;
478         }
479         elsif ($arglist[0] eq '--no-force')
480         {
481             $force_generation = 0;
482         }
483         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
484         {
485             # Set output directory.
486             $output_directory = $1;
487         }
488         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
489         {
490             &require_argument (@arglist);
491             shift (@arglist);
492             $output_directory = $arglist[0];
493         }
494         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
495         {
496             $add_missing = 1;
497         }
498         elsif ($arglist[0] eq '--copy' || $arglist[0] eq '-c')
499         {
500             $copy_missing = 1;
501         }
502         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
503         {
504             $verbose = 1;
505         }
506         elsif ($arglist[0] eq '--')
507         {
508             # Stop option processing.
509             shift (@arglist);
510             push (@input_files, @arglist);
511             last;
512         }
513         elsif ($arglist[0] =~ /^-/)
514         {
515             die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
516         }
517         else
518         {
519             # Handle $local:$input syntax.  Note that we only examine
520             # the first ":" file to see if it is automake input; the
521             # rest are just taken verbatim.  We still keep all the
522             # files around for dependency checking, however.
523             local ($local, $input, @rest) = split (/:/, $arglist[0]);
524             if (! $input)
525             {
526                 $input = $local;
527             }
528             else
529             {
530                 # Strip .in; later on .am is tacked on.  That is how
531                 # the automake input file is found.  Maybe not the
532                 # best way, but it is easy to explain.  FIXME: should
533                 # be error if .in is missing.
534                 $input =~ s/\.in$//;
535             }
536             push (@input_files, $input);
537             $output_files{$input} = join (':', ($local, @rest));
538         }
540         shift (@arglist);
541     }
543     # Take global strictness from whatever we currently have set.
544     $default_strictness = $strictness;
545     $default_strictness_name = $strictness_name;
548 # Ensure argument exists, or die.
549 sub require_argument
551     local ($arg, @arglist) = @_;
552     die "automake: no argument given for option \`$arg'\n"
553         if ! @arglist;
556 ################################################################
558 # Generate a Makefile.in given the name of the corresponding Makefile and
559 # the name of the file output by config.status.
560 sub generate_makefile
562     local ($output, $makefile) = @_;
564     ($am_file_name = $makefile) =~ s/^.*\///;
565     $in_file_name = $am_file_name . '.in';
566     $am_file_name .= '.am';
568     # $OUTPUT is encoded.  If it contains a ":" then the first element
569     # is the real output file, and all remaining elements are input
570     # files.  We don't scan or otherwise deal with these input file,
571     # other than to mark them as dependencies.  See scan_configure for
572     # details.
573     local (@secondary_inputs);
574     ($output, @secondary_inputs) = split (/:/, $output);
576     &initialize_per_input;
577     $relative_dir = &dirname ($output);
578     $am_relative_dir = &dirname ($makefile);
580     # At the toplevel directory, we might need config.guess, config.sub
581     # or libtool scripts (ltconfig and ltmain.sh).
582     if ($relative_dir eq '.')
583     {
584         # libtool requires some files.
585         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
586                                            @libtoolize_files)
587             if $seen_libtool;
589         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
590         # config.sub.
591         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
592             if $seen_canonical;
593     }
595     # We still need Makefile.in here, because sometimes the `dist'
596     # target doesn't re-run automake.
597     if ($am_relative_dir eq $relative_dir)
598     {
599         # Only distribute the files if they are in the same subdir as
600         # the generated makefile.
601         &push_dist_common ($in_file_name, $am_file_name);
602     }
603     push (@sources, '$(SOURCES)')
604         if &variable_defined ('SOURCES');
605     push (@objects, '$(OBJECTS)')
606         if &variable_defined ('OBJECTS');
608     &read_main_am_file ($makefile . '.am');
609     if (&handle_options)
610     {
611         # Fatal error.  Just return, so we can continue with next file.
612         return;
613     }
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     &handle_built_sources;
629     # This must be run after all the sources are scanned.
630     &finish_languages;
632     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
633     # on this (but currently does).
634     $contents{'SOURCES'} = join (' ', @sources);
635     $contents{'OBJECTS'} = join (' ', @objects);
636     &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
638     &handle_multilib;
639     &handle_texinfo;
640     &handle_emacs_lisp;
641     &handle_java;
642     &handle_man_pages;
643     &handle_data;
644     &handle_headers;
645     &handle_subdirs;
646     &handle_tags;
647     &handle_minor_options;
648     &handle_dist ($makefile);
649     &handle_dependencies;
650     &handle_tests;
651     &handle_footer;
652     &handle_merge_targets ($output);
653     &handle_installdirs;
654     &handle_clean;
655     &handle_phony;
657     &check_typos;
659     if (! -d ($output_directory . '/' . $am_relative_dir))
660     {
661         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
662     }
664     local ($out_file) = $output_directory . '/' . $makefile . ".in";
665     if (! $force_generation && -e $out_file)
666     {
667         local ($am_time) = (stat ($makefile . '.am'))[9];
668         local ($in_time) = (stat ($out_file))[9];
669         # FIXME: should cache these times.
670         local ($conf_time) = (stat ('configure.in'))[9];
671         # FIXME: how to do unsigned comparison?
672         if ($am_time < $in_time || $am_time < $conf_time)
673         {
674             # No need to update.
675             return;
676         }
677         if (-f 'aclocal.m4')
678         {
679             local ($acl_time) = (stat _)[9];
680             return if ($am_time < $acl_time);
681         }
682     }
684     if (! open (GM_FILE, "> " . $out_file))
685     {
686         warn "automake: ${am_file}.in: cannot write: $!\n";
687         $exit_status = 1;
688         return;
689     }
690     print "automake: creating ", $makefile, ".in\n" if $verbose;
692     print GM_FILE $output_vars;
693     # We make sure that `all:' is the first target.
694     print GM_FILE $output_all;
695     print GM_FILE $output_header;
696     print GM_FILE $output_rules;
697     print GM_FILE $output_trailer;
699     close (GM_FILE);
702 ################################################################
704 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
705 sub handle_options
707     if (&variable_defined ('AUTOMAKE_OPTIONS'))
708     {
709         foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
710         {
711             $options{$_} = 1;
712             if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
713             {
714                 &set_strictness ($_);
715             }
716             elsif ($_ eq 'cygnus')
717             {
718                 $cygnus_mode = 1;
719             }
720             elsif (/ansi2knr/)
721             {
722                 # An option like "../lib/ansi2knr" is allowed.  With
723                 # no path prefix, we assume the required programs are
724                 # in this directory.  We save the actual option for
725                 # later.
726                 $options{'ansi2knr'} = $_;
727             }
728             elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
729                    || $_ eq 'dist-shar' || $_ eq 'dist-zip'
730                    || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
731                    || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
732                    || $_ eq 'readme-alpha' || $_ eq 'check-news'
733                    || $_ eq 'subdir-objects')
734             {
735                 # Explicitly recognize these.
736             }
737             elsif ($_ eq 'no-dependencies')
738             {
739                 $use_dependencies = 0;
740             }
741             elsif (/([0-9]+)\.([0-9]+)([a-z])?/)
742             {
743                 # Got a version number.
745                 local ($rmajor, $rminor, $ralpha) = ($1, $2, $3);
747                 if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
748                 {
749                     print STDERR
750                         "automake: programming error: version is incorrect\n";
751                     exit 1;
752                 }
753                 local ($tmajor, $tminor, $talpha) = ($1, $2, $3);
755                 # 2.0 is better than 1.0.
756                 # 1.2 is better than 1.1.
757                 # 1.2a is better than 1.2.
758                 if ($rmajor > $tmajor
759                     || ($rmajor == $tmajor && $rminor > $tminor)
760                     || ($rminor == $tminor && $rminor == $tminor
761                         && $ralpha gt $talpha))
762                 {
763                     &am_line_error ('AUTOMAKE_OPTIONS',
764                                     "require version $_, only have $VERSION");
765                     return 1;
766                 }
767             }
768             else
769             {
770                 &am_line_error ('AUTOMAKE_OPTIONS',
771                                 "option \`" . $_ . "\' not recognized");
772             }
773         }
774     }
776     if ($strictness == $GNITS)
777     {
778         $options{'readme-alpha'} = 1;
779         $options{'check-news'} = 1;
780     }
782     return 0;
785 # Return object extension.  Just once, put some code into the output.
786 # Argument is the name of the output file
787 sub get_object_extension
789     local ($out) = @_;
791     # Maybe require libtool library object files.
792     local ($extension) = '.o';
793     $extension = '.$(OBJEXT)' if $seen_objext;
794     $extension = '.lo' if ($out =~ /\.la$/);
796     if (! $included_generic_compile)
797     {
798         # Boilerplate.
799         local ($xform) = '';
800         if (&variable_defined ('CONFIG_HEADER'))
801         {
802             local ($one_hdr);
803             foreach $one_hdr (split (' ', &variable_value ('CONFIG_HEADER')))
804             {
805                 local ($var);
806                 ($var = &dirname ($one_hdr)) =~ s/(\W)/\\$1/g;
807                 $xform .= ' ' if $xform;
808                 $xform .= '-I' . $var;
809             }
810         }
811         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go;';
812         $output_vars .= &file_contents_with_transform ($xform,
813                                                        'comp-vars');
815         $xform = (($use_dependencies
816                    ? 's/^NOTDEPEND.*$//;'
817                    : 's/^NOTDEPEND//;')
818                   . ($seen_objext ? 's/^OBJEXT//;' : 's/^OBJEXT.*$//;')
819                   . 's/\@MINUSO\@/'
820                   . (defined $options{'subdir-objects'} ? '-o \$\@' : '')
821                   . '/;');
822         $output_rules .= &file_contents_with_transform ($xform, 'compile');
824         &push_phony_cleaners ('compile');
826         # If using X, include some extra variable definitions.  NOTE
827         # we don't want to force these into CFLAGS or anything,
828         # because not all programs will necessarily use X.
829         if ($seen_path_xtra)
830         {
831             local ($var);
832             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
833             {
834                 &define_configure_variable ($var);
835             }
836         }
838         push (@suffixes, '.c', '.o');
839         push (@suffixes, '.obj') if $seen_objext;
840         push (@clean, 'compile');
842         $included_generic_compile = 1;
843     }
845     if ($seen_libtool && ! $included_libtool_compile)
846     {
847         # Output the libtool compilation rules.
848         $output_rules .=
849             &file_contents_with_transform
850                 ($use_dependencies ? 's/^NOTDEPEND.*$//;' : 's/^NOTDEPEND//;',
851                  'libtool');
853         &push_phony_cleaners ('libtool');
855         push (@suffixes, '.lo');
856         push (@clean, 'libtool');
858         $included_libtool_compile = 1;
859     }
861     # Check for automatic de-ANSI-fication.
862     if (defined $options{'ansi2knr'})
863     {
864         $extension = '$U' . $extension;
865         if (! $included_knr_compile)
866         {
867             if (! $am_c_prototypes)
868             {
869                 &am_line_error ('AUTOMAKE_OPTIONS',
870                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
871                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
872                 # Only give this error once.
873                 $am_c_prototypes = 1;
874             }
876             # Only require ansi2knr files if they should appear in
877             # this directory.
878             if ($options{'ansi2knr'} eq 'ansi2knr')
879             {
880                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
881                                          'ansi2knr.c', 'ansi2knr.1');
882                 $output_rules .= &file_contents ('kr-extra');
883                 push (@clean, 'krextra');
884                 &push_phony_cleaners ('krextra');
885             }
887             # Generate rules to build ansi2knr.  If it is in some
888             # other directory, then generate dependencies but have the
889             # rule just run elsewhere.
890             $objext = $seen_objext ? ".$(OBJEXT)" : ".o";
891             $output_rules .= ($options{'ansi2knr'} . ': '
892                               . $options{'ansi2knr'} . $objext . "\n");
893             if ($options{'ansi2knr'} eq 'ansi2knr')
894             {
895                 $output_rules .= ("\t\$(LINK) ansi2knr" . $objext
896                                   . " \$(LIBS)\n"
897                                   . "ansi2knr" . $objext
898                                   . ": \$(CONFIG_HEADER)\n\n");
899             }
900             else
901             {
902                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
903                                   . " && \$(MAKE) \$(AM_MAKEFLAGS) "
904                                   . "ansi2knr\n\n");
905                 # This is required for non-GNU makes.
906                 $output_rules .= ($options{'ansi2knr'} . $objext . ":\n");
907                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
908                                   . " && \$(MAKE) \$(AM_MAKEFLAGS)"
909                                   . " ansi2knr" . $objext . "\n\n");
910             }
912             # Make sure ansi2knr can be found: if no path specified,
913             # specify "./".
914             if ($options{'ansi2knr'} eq 'ansi2knr')
915             {
916                 # Substitution from AM_C_PROTOTYPES.  This makes it be
917                 # built only when necessary.
918                 &define_configure_variable ('ANSI2KNR');
919                 # ansi2knr needs to be built before subdirs, so unshift it.
920                 unshift (@all, '$(ANSI2KNR)');
921             }
922             else
923             {
924                 # Found in another directory.
925                 &define_variable ("ANSI2KNR", $options{'ansi2knr'});
926             }
928             $output_rules .= &file_contents ('clean-kr');
930             push (@clean, 'kr');
931             &push_phony_cleaners ('kr');
933             $included_knr_compile = 1;
934         }
935     }
937     return $extension;
940 # Call finish function for each language that was used.
941 sub finish_languages
943     local ($ext, $name, $lang, %done);
944     local ($non_c) = 1;
945     foreach $ext (sort keys %extension_seen)
946     {
947         $lang = $extension_map{$ext};
948         next if defined $done{$lang};
949         $done{$lang} = 1;
950         $non_c = 0 if $lang !~ /(objc|cxx|f77|ratfor)$/;
952         # Compute the function name of the finisher and then call it.
953         $name = 'lang_' . $lang . '_finish';
954         & $name ();
955     }
957     # If the project is entirely C++ or entirely Fortran 77, don't
958     # bother with the C stuff.  But if anything else creeps in, then use
959     # it.
960     if (! $non_c || scalar keys %suffix_rules > 0)
961     {
962         local ($ltcompile, $ltlink) = &libtool_compiler;
964         &define_configure_variable ('CFLAGS');
965         &define_compiler_variable ('COMPILE', $ltcompile,
966                                    '$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)');
967         &define_variable ('CCLD', '$(CC)');
968         &define_variable ('LINK', $ltlink . '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
969     }
972 # Output a rule to build from a YACC source.  The output from YACC is
973 # compiled with C or C++, depending on the extension of the YACC file.
974 sub output_yacc_build_rule
976     local ($yacc_suffix, $use_ylwrap, $c_suffix) = @_;
978     local ($suffix);
979     ($suffix = $yacc_suffix) =~ tr/y/c/;
980     push (@suffixes, $yacc_suffix, $suffix);
982     # Generate rule for c/c++.
983     $output_rules .= "$yacc_suffix$suffix:\n\t";
985     if ($use_ylwrap)
986     {
987         $output_rules .= ('$(SHELL) $(YLWRAP)'
988                           . ' "$(YACC)" $< y.tab.c $*' . $suffix
989                           . ' y.tab.h $*.h -- $(AM_YFLAGS) $(YFLAGS)');
990     }
991     else
992     {
993         $output_rules .= ('$(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*'
994                           . $suffix . "\n"
995                           . "\tif test -f y.tab.h; then \\\n"
996                           . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
997                           . "\telse :; fi");
998     }
999     $output_rules .= "\n";
1002 sub output_lex_build_rule
1004     local ($lex_suffix, $use_ylwrap) = @_;
1005     local ($c_suffix);
1007     ($c_suffix = $lex_suffix) =~ tr/l/c/;
1008     push (@suffixes, $lex_suffix);
1009     &define_configure_variable ('LEX_OUTPUT_ROOT');
1010     &define_configure_variable ('LEXLIB');
1011     $output_rules .= "$lex_suffix$c_suffix:\n\t";
1013     if ($use_ylwrap)
1014     {
1015         # Is the $@ correct here?  If so, why not use it in the ylwrap
1016         # build rule for yacc above?
1017         $output_rules .= '$(SHELL) $(YLWRAP)'
1018             . ' "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(AM_LFLAGS) $(LFLAGS)';
1019     }
1020     else
1021     {
1022         $output_rules .= '$(LEX) $(AM_LFLAGS) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
1023     }
1024     $output_rules .= "\n";
1028 # Check to make sure a source defined in LIBOBJS is not explicitly
1029 # mentioned.  This is a separate function (as opposed to being inlined
1030 # in handle_source_transform) because it isn't always appropriate to
1031 # do this check.
1032 sub check_libobjs_sources
1034     local ($one_file, $unxformed) = @_;
1036     local ($prefix, $file, @files);
1037     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1038                      'dist_EXTRA_', 'nodist_EXTRA_')
1039     {
1040         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1041         {
1042             @files = &variable_value_as_list (($prefix
1043                                                . $one_file . '_SOURCES'),
1044                                               'all');
1045         }
1046         elsif ($prefix eq '')
1047         {
1048             @files = ($unxformed . '.c');
1049         }
1050         else
1051         {
1052             next;
1053         }
1055         foreach $file (@files)
1056         {
1057             if (defined $libsources{$file})
1058             {
1059                 &am_line_error ($prefix . $one_file . '_SOURCES',
1060                                 "automatically discovered file \`$file' should not be explicitly mentioned");
1061             }
1062         }
1063     }
1066 # Does much of the actual work for handle_source_transform.
1067 # Arguments are:
1068 #   object extension (e.g., `$U.lo')
1069 #   list of source files to transform
1070 # Result is a list
1071 #   first element is name of linker to use (empty string for default linker)
1072 #   remaining elements are names of objects
1073 sub handle_single_transform_list
1075     local ($obj, @files) = @_;
1076     local (@result) = ();
1077     local ($nonansi_obj) = $obj;
1078     $nonansi_obj =~ s/_//g;
1079     local (%linkers_used) = ();
1080     if (@files > 0)
1081     {
1082         # Turn sources into objects.
1083         foreach (@files)
1084         {
1085             # Skip things that look like configure substitutions.
1086             next if /^\@.*\@$/;
1088             # If the source file is in a subdirectory then the `.o' is
1089             # put into the current directory.
1091             # Split file name into base and extension.
1092             local ($full, $directory, $base, $extension, $linker, $object);
1093             next if ! /^((.*)\/)?([^\/]*)\.(.*)$/;
1094             $full = $_;
1095             $directory = $2;
1096             $base = $3;
1097             $extension = $4;
1099             local ($xbase) = $base;
1101             local ($lang) = $extension_map{$extension};
1102             if ($lang)
1103             {
1104                 &saw_extension ($extension);
1105                 # Found the language, so see what it says.
1106                 local ($subr) = 'lang_' . $lang . '_rewrite';
1107                 # Note: computed subr call.
1108                 local ($r) = & $subr ($directory, $base, $extension);
1109                 # Skip this entry if we were asked not to process it.
1110                 next if $r == $LANG_IGNORE;
1112                 # Now extract linker and other info.
1113                 $linker = $language_map{$lang . '-linker'};
1115                 if ($language_map{$lang . '-ansi-p'})
1116                 {
1117                     $object = $base . $obj;
1118                 }
1119                 else
1120                 {
1121                     $object = $base . $nonansi_obj;
1122                 }
1124                 # If rewrite said it was ok, put the object into a
1125                 # subdir.
1126                 if ($r == $LANG_SUBDIR && $directory ne '')
1127                 {
1128                     $object = $directory . '/' . $object;
1129                     $xbase = $directory . '/' . $base;
1130                 }
1131             }
1132             elsif ($extension =~ /^$source_suffix_pattern$/) 
1133             {
1134                 # We just rewrite it.  Maybe we should do more.
1135                 # FIXME: what about subdir handling here?
1136                 $object = $base . '.' . $suffix_rules{$extension};
1137                 $linker = '';
1138             }
1139             else
1140             {
1141                 # No error message here.  Used to have one, but it was
1142                 # very unpopular.
1143                 next;
1144             }
1146             $linkers_used{$linker} = 1;
1148             push (@result, $object);
1150             if (defined $object_map{$object})
1151             {
1152                 if ($object_map{$object} ne $full)
1153                 {
1154                     &am_error ("object \`$object' created by \`$full' and \`$object_map{$object}'");
1155                 }
1156             }
1157             else
1158             {
1159                 local (@dep_list) = ();
1160                 $object_map{$object} = $full;
1162                 # If file is in subdirectory, we need explicit
1163                 # dependency.
1164                 if ($directory ne '')
1165                 {
1166                     push (@dep_list, $full);
1167                 }
1169                 # If resulting object is in subdir, we need to make
1170                 # sure the subdir exists at build time.
1171                 if ($object =~ /\//)
1172                 {
1173                     # FIXME: check that $DIRECTORY is somewhere in the
1174                     # project
1176                     # We don't allow `..' in object file names for
1177                     # *any* source, not just Java.  For Java it just
1178                     # doesn't make sense, but in general it is
1179                     # a problem because we can't pick a good name for
1180                     # the .deps entry.
1181                     if ($object =~ /(\/|^)\.\.\//)
1182                     {
1183                         &am_error ("\`$full' contains \`..' component but should not");
1184                     }
1186                     push (@dep_list, $directory . '/.dirstamp');
1188                     # If we're generating dependencies, we also want
1189                     # to make sure that the appropriate subdir of the
1190                     # .deps directory is created.
1191                     if ($use_dependencies)
1192                     {
1193                         push (@dep_list, '.deps/' . $directory . '/.dirstamp');
1194                     }
1196                     if (! defined $directory_map{$directory})
1197                     {
1198                         $directory_map{$directory} = 1;
1199                         $output_rules .= ($directory . "/.dirstamp:\n"
1200                                           . "\t\@\$(mkinstalldirs) $directory\n"
1201                                           . "\t\@: > $directory/.dirstamp\n");
1202                         if ($use_dependencies)
1203                         {
1204                             $output_rules .= ('.deps/' . $directory
1205                                               . "/.dirstamp:\n"
1206                                               . "\t\@\$(mkinstalldirs) .deps/$directory\n"
1207                                               . "\t\@: > .deps/$directory/.dirstamp\n");
1208                         }
1209                     }
1210                 }
1212                 &pretty_print_rule ($object . ':', "\t", @dep_list);
1213             }
1215             # Transform .o or $o file into .P file (for automatic
1216             # dependency code).
1217             $dep_files{'.deps/' . $xbase . '.P'} = 1;
1218         }
1219     }
1221     return (&resolve_linker (%linkers_used), @result);
1224 # Handle SOURCE->OBJECT transform for one program or library.
1225 # Arguments are:
1226 #   canonical (transformed) name of object to build
1227 #   actual name of object to build
1228 #   object extension (ie either `.o' or `$o'.
1229 # Return result is name of linker variable that must be used.
1230 # Empty return means just use `LINK'.
1231 sub handle_source_transform
1233     # one_file is canonical name.  unxformed is given name.  obj is
1234     # object extension.
1235     local ($one_file, $unxformed, $obj) = @_;
1237     local ($linker) = '';
1239     if (&variable_defined ($one_file . "_OBJECTS"))
1240     {
1241         &am_line_error ($one_file . '_OBJECTS',
1242                         $one_file . '_OBJECTS', 'should not be defined');
1243         # No point in continuing.
1244         return;
1245     }
1247     local (@files, @result, $prefix, $temp, $xpfx);
1248     local (%used_pfx) = ();
1249     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1250                      'dist_EXTRA_', 'nodist_EXTRA_')
1251     {
1252         # We are going to define _OBJECTS variables using the prefix.
1253         # Then we glom them all together.  So we can't use the null
1254         # prefix here as we need it later.
1255         $xpfx = ($prefix eq '') ? 'am_' : $prefix;
1257         @files = ();
1258         local ($var) = $prefix . $one_file . "_SOURCES";
1259         if (&variable_defined ($var))
1260         {
1261             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1262             push (@objects, '$(' . $xpfx . $one_file . "_OBJECTS)")
1263                 unless $prefix =~ /EXTRA_/;
1264             push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
1265                 unless $prefix =~ /^nodist_/;
1266             local (@conds) = &variable_conditions ($var);
1267             if (! @conds)
1268             {
1269                 @files = &variable_value_as_list ($var, '');
1270             }
1271             else
1272             {
1273                 local ($cond);
1274                 foreach $cond (@conds)
1275                 {
1276                     @files = &variable_value_as_list ($var, $cond);
1277                     ($temp, @result) = &handle_single_transform_list ($obj,
1278                                                                       @files);
1279                     $linker = $temp if $linker eq '';
1281                     # Define _OBJECTS conditionally.
1282                     &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
1283                                              $cond, @result)
1284                         unless $prefix =~ /EXTRA_/;
1285                 }
1287                 # Keep track of which prefixes we saw.
1288                 $used_pfx{$xpfx} = 1
1289                     unless $prefix =~ /EXTRA_/;
1291                 next;
1292             }
1293         }
1295         # Avoid defining needless variables.
1296         next if (scalar @files == 0);
1298         # Keep track of which prefixes we saw.
1299         $used_pfx{$xpfx} = 1
1300             unless $prefix =~ /EXTRA_/;
1302         ($temp, @result) = &handle_single_transform_list ($obj, @files);
1303         $linker = $temp if $linker eq '';
1304         &define_pretty_variable ($xpfx . $one_file . "_OBJECTS", '', @result)
1305             unless $prefix =~ /EXTRA_/;
1306     }
1308     local (@keys) = sort keys %used_pfx;
1309     if (scalar @keys == 0)
1310     {
1311         &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1312         push (@sources, $unxformed . '.c');
1313         push (@dist_sources, $unxformed . '.c');
1314         push (@objects, $unxformed . $obj);
1315         push (@files, $unxformed . '.c');
1317         ($temp, @result) = &handle_single_transform_list ($obj, @files);
1318         $linker = $temp if $linker eq '';
1319         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
1320     }
1321     else
1322     {
1323         grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
1324         &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
1325     }
1327     return $linker;
1330 # Handle the BUILT_SOURCES variable.
1331 sub handle_built_sources
1333     return unless &variable_defined ('BUILT_SOURCES');
1335     local (@sources) = &variable_value_as_list ('BUILT_SOURCES', 'all');
1336     local ($s);
1337     foreach $s (@sources)
1338     {
1339         if (/^\@.*\@$/)
1340         {
1341             # FIXME: is this really the right thing to do?
1342             &am_line_error ('BUILT_SOURCES',
1343                             "\`BUILT_SOURCES' should not contain a configure substitution");
1344             last;
1345         }
1346     }
1348     # We don't care about the return value of this function.  We just
1349     # want to make sure to update %dep_files with the contents of
1350     # BUILT_SOURCES.
1351     &handle_single_transform_list (".o", @sources);
1354 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1355 # Also, generate _DEPENDENCIES variable if appropriate.
1356 # Arguments are:
1357 #   transformed name of object being built, or empty string if no object
1358 #   name of _LDADD/_LIBADD-type variable to examine
1359 #   boolean (lex_seen) which is true if a lex source file was seen in this
1360 #     object.  valid only for LDADDs, not LIBADDs.
1361 # Returns 1 if LIBOBJS seen, 0 otherwise.
1362 sub handle_lib_objects
1364     local ($xname, $var, $lex_seen) = @_;
1365     local ($ret);
1367     die "automake: programming error 1 in handle_lib_objects\n"
1368         if ! &variable_defined ($var);
1370     die "automake: programming error 2 in handle_lib_objects\n"
1371         if $lex_seen && $var =~ /LIBADD/;
1373     local (@conds) = &variable_conditions ($var);
1374     if (! @conds)
1375     {
1376         $ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
1377     }
1378     else
1379     {
1380         local ($cond);
1381         $ret = 0;
1382         foreach $cond (@conds)
1383         {
1384             if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
1385             {
1386                 $ret = 1;
1387             }
1388         }
1389     }
1391     return $ret;
1394 # Subroutine of handle_lib_objects: handle a particular condition.
1395 sub handle_lib_objects_cond
1397     local ($xname, $var, $lex_seen, $cond) = @_;
1399     # We recognize certain things that are commonly put in LIBADD or
1400     # LDADD.
1401     local ($lsearch);
1402     local (@dep_list) = ();
1404     local ($seen_libobjs) = 0;
1405     local ($flagvar) = 0;
1407     foreach $lsearch (&variable_value_as_list ($var, $cond))
1408     {
1409         # Skip -lfoo and -Ldir; these are explicitly allowed.
1410         next if $lsearch =~ /^-[lL]/;
1411         if (! $flagvar && $lsearch =~ /^-/)
1412         {
1413             if ($var =~ /^(.*)LDADD$/)
1414             {
1415                 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
1416                 next if $lsearch =~ /^-dl(pre)?open$/;
1417                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1418             }
1419             else
1420             {
1421                 # Only get this error once.
1422                 $flagvar = 1;
1423                 &am_line_error ($var, "you cannot use linker flags such as \`$lsearch' in \`$var'");
1424             }
1425         }
1427         # Assume we have a file of some sort, and push it onto the
1428         # dependency list.  Autoconf substitutions are not pushed;
1429         # rarely is a new dependency substituted into (eg) foo_LDADD
1430         # -- but "bad things (eg -lX11) are routinely substituted.
1431         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1432         # and handled specially below.
1433         push (@dep_list, $lsearch)
1434             unless $lsearch =~ /^\@.*\@$/;
1436         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1437         # means adding entries to dep_files.
1438         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1439         {
1440             push (@dep_list, $lsearch);
1441             $seen_libobjs = 1;
1442             if (! keys %libsources)
1443             {
1444                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
1445             }
1447             local ($iter, $rewrite);
1448             foreach $iter (keys %libsources)
1449             {
1450                 if ($iter =~ /\.([cly])$/)
1451                 {
1452                     &saw_extension ($1);
1453                     &saw_extension ('c');
1454                 }
1456                 if ($iter =~ /\.h$/)
1457                 {
1458                     &require_file_with_line ($var, $FOREIGN, $iter);
1459                 }
1460                 elsif ($iter ne 'alloca.c')
1461                 {
1462                     ($rewrite = $iter) =~ s/\.c$/.P/;
1463                     $dep_files{'.deps/' . $rewrite} = 1;
1464                     &require_file_with_line ($var, $FOREIGN, $iter);
1465                 }
1466             }
1467         }
1468         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1469         {
1470             push (@dep_list, $lsearch);
1471             &am_line_error ($var,
1472                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
1473                 if ! defined $libsources{'alloca.c'};
1474             $dep_files{'.deps/alloca.P'} = 1;
1475             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1476             &saw_extension ('c');
1477         }
1478     }
1480     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
1481     {
1482         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
1483     }
1485     return $seen_libobjs;
1488 # Canonicalize a name, and check to make sure the non-canonical name
1489 # is never used.  Returns canonical name.  Arguments are name and a
1490 # list of suffixes to check for.
1491 sub check_canonical_spelling
1493     local ($name, @suffixes) = @_;
1494     local ($xname, $xt);
1496     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
1497     if ($xname ne $name)
1498     {
1499         local ($xt);
1500         foreach $xt (@suffixes)
1501         {
1502             &am_line_error ($name . $xt,
1503                             "invalid variable \`" . $name . $xt
1504                             . "'; should be \`" . $xname . $xt . "'")
1505                 if &variable_defined ($name . $xt);
1506         }
1507     }
1509     return $xname;
1512 # Handle C programs.
1513 sub handle_programs
1515     local (@proglist) = &am_install_var ('-clean',
1516                                          'progs', 'PROGRAMS',
1517                                          'bin', 'sbin', 'libexec', 'pkglib',
1518                                          'noinst', 'check');
1519     return if ! @proglist;
1521     # If a program is installed, this is required.  We only want this
1522     # error to appear once.
1523     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1524         unless $seen_arg_prog;
1525     $seen_arg_prog = 1;
1527     local ($one_file, $xname, $munge);
1529     local ($seen_libobjs) = 0;
1530     foreach $one_file (@proglist)
1531     {
1532         local ($obj) = &get_object_extension ($one_file);
1534         # Canonicalize names and check for misspellings.
1535         $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
1536                                             '_SOURCES', '_OBJECTS',
1537                                             '_DEPENDENCIES');
1539         # FIXME: Using a trick to figure out if any lex sources appear
1540         # in our program; should use some cleaner method.
1541         local ($lex_num) = scalar (keys %lex_sources);
1542         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1543         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1545         local ($xt) = '';
1546         if (&variable_defined ($xname . "_LDADD"))
1547         {
1548             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1549                                      $lex_file_seen))
1550             {
1551                 $seen_libobjs = 1;
1552             }
1553             $lex_file_seen = 0;
1554             $xt = '_LDADD';
1555         }
1556         else
1557         {
1558             # User didn't define prog_LDADD override.  So do it.
1559             &define_variable ($xname . '_LDADD', '$(LDADD)');
1561             # This does a bit too much work.  But we need it to
1562             # generate _DEPENDENCIES when appropriate.
1563             if (&variable_defined ('LDADD'))
1564             {
1565                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1566                 {
1567                     $seen_libobjs = 1;
1568                 }
1569                 $lex_file_seen = 0;
1570             }
1571             elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
1572             {
1573                 &define_variable ($xname . '_DEPENDENCIES', '');
1574             }
1575             $xt = '_SOURCES'
1576         }
1578         if (&variable_defined ($xname . '_LIBADD'))
1579         {
1580             &am_line_error ($xname . '_LIBADD',
1581                             "use \`" . $xname . "_LDADD', not \`"
1582                             . $xname . "_LIBADD'");
1583         }
1585         if (! &variable_defined ($xname . '_LDFLAGS'))
1586         {
1587             # Define the prog_LDFLAGS variable.
1588             &define_variable ($xname . '_LDFLAGS', '');
1589         }
1591         # Determine program to use for link.
1592         local ($xlink);
1593         if (&variable_defined ($xname . '_LINK'))
1594         {
1595             $xlink = $xname . '_LINK';
1596         }
1597         else
1598         {
1599             $xlink = $linker ? $linker : 'LINK';
1600         }
1602         local ($xexe);
1603         if ($seen_exeext && $one_file !~ /\./)
1604         {
1605             $xexe = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
1606         }
1607         else
1608         {
1609             $xexe = 's/\@EXEEXT\@//g;';
1610         }
1612         $output_rules .=
1613             &file_contents_with_transform
1614                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1615                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1616                  . 's/\@XLINK\@/' . $xlink . '/go;'
1617                  . $xexe,
1618                  'program');
1619     }
1621     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1622     {
1623         $seen_libobjs = 1;
1624     }
1626     if ($seen_libobjs)
1627     {
1628         foreach $one_file (@proglist)
1629         {
1630             # Canonicalize names.
1631             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1633             if (&variable_defined ($xname . '_LDADD'))
1634             {
1635                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1636             }
1637             elsif (&variable_defined ('LDADD'))
1638             {
1639                 &check_libobjs_sources ($xname, 'LDADD');
1640             }
1641         }
1642     }
1646 # Handle libraries.
1647 sub handle_libraries
1649     local (@liblist) = &am_install_var ('-clean',
1650                                         'libs', 'LIBRARIES',
1651                                         'lib', 'pkglib', 'noinst', 'check');
1652     return if ! @liblist;
1654     local (%valid) = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
1655                                            'noinst', 'check');
1656     if (! defined $configure_vars{'RANLIB'})
1657     {
1658         local ($key);
1659         foreach $key (keys %valid)
1660         {
1661             if (&variable_defined ($key . '_LIBRARIES'))
1662             {
1663                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1664                 # Only get this error once.  If this is ever printed,
1665                 # we have a bug.
1666                 $configure_vars{'RANLIB'} = 'BUG';
1667                 last;
1668             }
1669         }
1670     }
1672     local ($onelib);
1673     local ($munge);
1674     local ($xlib);
1675     local ($seen_libobjs) = 0;
1676     foreach $onelib (@liblist)
1677     {
1678         # Check that the library fits the standard naming convention.
1679         if ($onelib !~ /^lib.*\.a$/)
1680         {
1681             # FIXME should put line number here.  That means mapping
1682             # from library name back to variable name.
1683             &am_error ("\`$onelib' is not a standard library name");
1684         }
1686         local ($obj) = &get_object_extension ($onelib);
1688         # Canonicalize names and check for misspellings.
1689         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
1690                                            '_OBJECTS', '_DEPENDENCIES');
1692         if (&variable_defined ($xlib . '_LIBADD'))
1693         {
1694             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1695             {
1696                 $seen_libobjs = 1;
1697             }
1698         }
1699         else
1700         {
1701             # Generate support for conditional object inclusion in
1702             # libraries.
1703             &define_variable ($xlib . "_LIBADD", '');
1704         }
1706         if (&variable_defined ($xlib . '_LDADD'))
1707         {
1708             &am_line_error ($xlib . '_LDADD',
1709                             "use \`" . $xlib . "_LIBADD', not \`"
1710                             . $xlib . "_LDADD'");
1711         }
1713         # Make sure we at look at this.
1714         &examine_variable ($xlib . '_DEPENDENCIES');
1716         &handle_source_transform ($xlib, $onelib, $obj);
1718         $output_rules .=
1719             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1720                                            . 's/\@XLIBRARY\@/'
1721                                            . $xlib . '/go;',
1722                                            'library');
1723     }
1725     if ($seen_libobjs)
1726     {
1727         foreach $onelib (@liblist)
1728         {
1729             # Canonicalize names.
1730             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1731             if (&variable_defined ($xlib . '_LIBADD'))
1732             {
1733                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1734             }
1735         }
1736     }
1738     &define_variable ('AR', 'ar');
1739     &define_configure_variable ('RANLIB');
1742 # Handle shared libraries.
1743 sub handle_ltlibraries
1745     local (@liblist) = &am_install_var ('-clean',
1746                                         'ltlib', 'LTLIBRARIES',
1747                                         'noinst', 'lib', 'pkglib', 'check');
1748     return if ! @liblist;
1750     local (%instdirs);
1751     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
1752                                            'noinst');
1754     local ($key);
1755     foreach $key (keys %valid)
1756     {
1757         if (&variable_defined ($key . '_LTLIBRARIES'))
1758         {
1759             if (!$seen_libtool)
1760             {
1761                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
1762                 # Only get this error once.  If this is ever printed,
1763                 # we have a bug.
1764                 $configure_vars{'LIBTOOL'} = 'BUG';
1765                 $seen_libtool = 1;
1766             }
1768             # Get the installation directory of each library.
1769             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
1770             {
1771                 if ($instdirs{$_})
1772                 {
1773                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1774                 }
1775                 else
1776                 {
1777                     $instdirs{$_} = $key;
1778                 }
1779             }
1780         }
1781     }
1783     local ($onelib);
1784     local ($munge);
1785     local ($xlib);
1786     local ($seen_libobjs) = 0;
1787     foreach $onelib (@liblist)
1788     {
1789         local ($obj) = &get_object_extension ($onelib);
1791         # Canonicalize names and check for misspellings.
1792         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
1793                                            '_SOURCES', '_OBJECTS',
1794                                            '_DEPENDENCIES');
1796         if (! &variable_defined ($xlib . '_LDFLAGS'))
1797         {
1798             # Define the lib_LDFLAGS variable.
1799             &define_variable ($xlib . '_LDFLAGS', '');
1800         }
1802         # Check that the library fits the standard naming convention.
1803         $libname_rx = "^lib.*\.la";
1804         if (&variable_value ($xlib . '_LDFLAGS') =~ /-module/) 
1805         {
1806                 # Relax name checking for libtool modules.
1807                 $libname_rx = "\.la";
1808         }
1809         if ($onelib !~ /$libname_rx$/)
1810         {
1811             # FIXME this should only be a warning for foreign packages
1812             # FIXME should put line number here.  That means mapping
1813             # from library name back to variable name.
1814             &am_error ("\`$onelib' is not a standard libtool library name");
1815         }
1817         if (&variable_defined ($xlib . '_LIBADD'))
1818         {
1819             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1820             {
1821                 $seen_libobjs = 1;
1822             }
1823         }
1824         else
1825         {
1826             # Generate support for conditional object inclusion in
1827             # libraries.
1828             &define_variable ($xlib . "_LIBADD", '');
1829         }
1831         if (&variable_defined ($xlib . '_LDADD'))
1832         {
1833             &am_line_error ($xlib . '_LDADD',
1834                             "use \`" . $xlib . "_LIBADD', not \`"
1835                             . $xlib . "_LDADD'");
1836         }
1838         # Make sure we at look at this.
1839         &examine_variable ($xlib . '_DEPENDENCIES');
1841         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
1843         # Determine program to use for link.
1844         local ($xlink);
1845         if (&variable_defined ($xlib . '_LINK'))
1846         {
1847             $xlink = $xlib . '_LINK';
1848         }
1849         else
1850         {
1851             $xlink = $linker ? $linker : 'LINK';
1852         }
1854         local ($rpath);
1855         if ($instdirs{$onelib} eq 'EXTRA' || $instdirs{$onelib} eq 'noinst')
1856         {
1857             # It's an EXTRA_ library, so we can't specify -rpath,
1858             # because we don't know where the library will end up.
1859             # The user probably knows, but generally speaking automake
1860             # doesn't -- and in fact configure could decide
1861             # dynamically between two different locations.
1862             $rpath = 's/\@RPATH\@//go;';
1863         }
1864         else
1865         {
1866             $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
1867                       . 'dir)/go;');
1868         }
1870         $output_rules .=
1871             &file_contents_with_transform ('s/\@LTLIBRARY\@/'
1872                                            . $onelib . '/go;'
1873                                            . 's/\@XLTLIBRARY\@/'
1874                                            . $xlib . '/go;'
1875                                            . $rpath
1876                                            . 's/\@XLINK\@/' . $xlink . '/go;',
1877                                            'ltlibrary');
1878     }
1880     if ($seen_libobjs)
1881     {
1882         foreach $onelib (@liblist)
1883         {
1884             # Canonicalize names.
1885             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1886             if (&variable_defined ($xlib . '_LIBADD'))
1887             {
1888                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1889             }
1890         }
1891     }
1894 # See if any _SOURCES variable were misspelled.  Also, make sure that
1895 # EXTRA_ variables don't contain configure substitutions.
1896 sub check_typos
1898     local ($varname, $primary);
1899     foreach $varname (keys %contents)
1900     {
1901         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
1902                           '_DEPENDENCIES')
1903         {
1904             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
1905             {
1906                 &am_line_error ($varname,
1907                                 "invalid unused variable name: \`$varname'");
1908             }
1909         }
1910     }
1913 # Handle scripts.
1914 sub handle_scripts
1916     # NOTE we no longer automatically clean SCRIPTS, because it is
1917     # useful to sometimes distribute scripts verbatim.  This happens
1918     # eg in Automake itself.
1919     &am_install_var ('-candist', 'scripts', 'SCRIPTS',
1920                      'bin', 'sbin', 'libexec', 'pkgdata',
1921                      'noinst', 'check');
1923     local ($scripts_installed) = 0;
1924     # Set $scripts_installed if appropriate.  Make sure we only find
1925     # scripts which are actually installed -- this is why we can't
1926     # simply use the return value of am_install_var.
1927     local (%valid) = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
1928                                            'libexec', 'pkgdata',
1929                                            'noinst', 'check');
1930     local ($key);
1931     foreach $key (keys %valid)
1932     {
1933         if ($key ne 'noinst'
1934             && $key ne 'check'
1935             && &variable_defined ($key . '_SCRIPTS'))
1936         {
1937             $scripts_installed = 1;
1938             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
1939         }
1940     }
1942     if ($scripts_installed)
1943     {
1944         # If a program is installed, this is required.  We only want this
1945         # error to appear once.
1946         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1947             unless $seen_arg_prog;
1948         $seen_arg_prog = 1;
1949     }
1952 # Search a file for a "version.texi" Texinfo include.  Return the name
1953 # of the include file if found, or the empty string if not.  A
1954 # "version.texi" file is actually any file whose name matches
1955 # "vers*.texi".
1956 sub scan_texinfo_file
1958     local ($filename) = @_;
1960     if (! open (TEXI, $filename))
1961     {
1962         &am_error ("couldn't open \`$filename': $!");
1963         return '';
1964     }
1965     print "automake: reading $filename\n" if $verbose;
1967     local ($vfile, $outfile);
1968     while (<TEXI>)
1969     {
1970         if (/^\@setfilename +(\S+)/)
1971         {
1972             $outfile = $1;
1973             last if ($vfile);
1974         }
1976         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
1977         {
1978             # Found version.texi include.
1979             $vfile = $1;
1980             last if $outfile;
1981         }
1982     }
1984     close (TEXI);
1985     return ($outfile, $vfile);
1988 # Handle all Texinfo source.
1989 sub handle_texinfo
1991     &am_line_error ('TEXINFOS',
1992                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
1993         if &variable_defined ('TEXINFOS');
1994     return if (! &variable_defined ('info_TEXINFOS')
1995                && ! &variable_defined ('html_TEXINFOS'));
1997     if (&variable_defined ('html_TEXINFOS'))
1998     {
1999         &am_line_error ('html_TEXINFOS',
2000                         "HTML generation not yet supported");
2001         return;
2002     }
2004     local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');
2006     local (@info_deps_list, @dvis_list, @texi_deps);
2007     local ($infobase, $info_cursor);
2008     local (%versions);
2009     local ($done) = 0;
2010     local ($vti);
2011     local ($tc_cursor, @texi_cleans);
2012     local ($canonical);
2014     foreach $info_cursor (@texis)
2015     {
2016         # FIXME: This is mildly hacky, since it recognizes "txinfo".
2017         # I don't feel like making it right.
2018         ($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;
2020         # If 'version.texi' is referenced by input file, then include
2021         # automatic versioning capability.
2022         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
2023                                                         . "/" . $info_cursor);
2025         if ($out_file eq '')
2026         {
2027             &am_error ("\`$info_cursor' missing \@setfilename");
2028             next;
2029         }
2031         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
2032         {
2033             # FIXME should report line number in input file.
2034             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
2035             next;
2036         }
2038         if ($vtexi)
2039         {
2040             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
2041                 if (defined $versions{$vtexi});
2042             $versions{$vtexi} = $info_cursor;
2044             # We number the stamp-vti files.  This is doable since the
2045             # actual names don't matter much.  We only number starting
2046             # with the second one, so that the common case looks nice.
2047             $vti = 'vti' . ($done ? $done : '');
2048             &push_dist_common ($vtexi, 'stamp-' . $vti);
2049             push (@clean, $vti);
2051             # Only require once.
2052             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2053                                           'mdate-sh')
2054                 if ! $done;
2055             ++$done;
2057             local ($conf_pat, $conf_dir);
2058             if ($config_aux_dir eq '.' || $config_aux_dir eq '')
2059             {
2060                 $conf_dir = '$(srcdir)/';
2061             }
2062             else
2063             {
2064                 $conf_dir = $config_aux_dir;
2065                 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
2066             }
2067             ($conf_pat = $conf_dir) =~ s/(\W)/\\$1/g;
2068             $output_rules .=
2069                 &file_contents_with_transform
2070                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
2071                      . 's/\@VTI\@/' . $vti . '/g; '
2072                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
2073                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
2074                      'texi-vers');
2076             &push_phony_cleaners ($vti);
2077         }
2079         # If user specified file_TEXINFOS, then use that as explicit
2080         # dependency list.
2081         @texi_deps = ();
2082         push (@texi_deps, $info_cursor);
2083         push (@texi_deps, $vtexi) if $vtexi;
2085         # Canonicalize name first.
2086         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
2087         if (&variable_defined ($canonical . "_TEXINFOS"))
2088         {
2089             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
2090             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
2091         }
2093         $output_rules .= ("\n" . $out_file . ": "
2094                           . join (' ', @texi_deps)
2095                           . "\n" . $infobase . ".dvi: "
2096                           . join (' ', @texi_deps)
2097                           . "\n\n");
2099         push (@info_deps_list, $out_file);
2100         push (@dvis_list, $infobase . '.dvi');
2102         # Generate list of things to clean for this target.  We do
2103         # this explicitly because otherwise too many things could be
2104         # removed.  In particular the ".log" extension might
2105         # reasonably be used in other contexts by the user.
2106         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns', 'pgs',
2107                             'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
2108                             'vr', 'vrs', 'op', 'tr', 'cv', 'cn')
2109         {
2110             push (@texi_cleans, $infobase . '.' . $tc_cursor);
2111         }
2112     }
2114     # Find these programs wherever they may lie.  Yes, this has
2115     # intimate knowledge of the structure of the texinfo distribution.
2116     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
2117                               'makeinfo',
2118                               # Circumlocution to avoid accidental
2119                               # configure substitution.
2120                               '@MAKE' . 'INFO@');
2121     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
2122                               'texi2dvi');
2124     # Set transform for including texinfos.am.  First, handle --cygnus
2125     # stuff.
2126     local ($xform);
2127     if ($cygnus_mode)
2128     {
2129         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
2130     }
2131     else
2132     {
2133         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
2134     }
2136     # Handle location of texinfo.tex.
2137     local ($need_texi_file) = 0;
2138     local ($texinfo_tex);
2139     if ($cygnus_mode)
2140     {
2141         $texinfo_tex = '$(top_srcdir)/../texinfo/texinfo.tex';
2142         &define_variable ('TEXINFO_TEX', $texinfo_tex);
2144     }
2145     elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
2146     {
2147         $texinfo_tex = $config_aux_dir . '/texinfo.tex';
2148         &define_variable ('TEXINFO_TEX', $texinfo_tex);
2149         $need_texi_file = 2; # so that we require_conf_file later
2150     }
2151     elsif (&variable_defined ('TEXINFO_TEX'))
2152     {
2153         # The user defined TEXINFO_TEX so assume he knows what he is
2154         # doing.
2155         $texinfo_tex = ('$(srcdir)/'
2156                         . &dirname (&variable_value ('TEXINFO_TEX')));
2157     }
2158     else
2159     {
2160         $texinfo_tex = '$(srcdir)/texinfo.tex';
2161         $need_texi_file = 1;
2162     }
2163     local ($xxform);
2164     ($xxform = $texinfo_tex) =~ s/\/texinfo\.tex$//;
2165     $xxform =~ s/(\W)/\\$1/g;
2166     $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';
2168     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
2169     push (@phony, 'install-info-am', 'uninstall-info');
2170     push (@dist_targets, 'dist-info');
2172     # How to clean.  The funny name is due to --cygnus influence; in
2173     # Cygnus mode, `clean-info' is a target that users can use.
2174     $output_rules .= "\nmostlyclean-aminfo:\n";
2175     &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
2176     $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
2177                       . "maintainer-clean-aminfo:\n\t"
2178                       # Eww.  But how else can we find all the output
2179                       # files from makeinfo?
2180                       . ($cygnus_mode ? '' : 'cd $(srcdir) && ')
2181                       . 'for i in $(INFO_DEPS); do' . " \\\n"
2182                       . "\t" . '  rm -f $$i;' . " \\\n"
2183                       . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
2184                       . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
2185                       . "\t" . '  fi;' . " \\\n"
2186                       . "\tdone\n");
2187     &push_phony_cleaners ('aminfo');
2188     if ($cygnus_mode)
2189     {
2190         $output_rules .= "clean-info: mostlyclean-aminfo\n";
2191     }
2193     push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');
2195     if (! defined $options{'no-installinfo'})
2196     {
2197         push (@uninstall, 'uninstall-info');
2198         push (@installdirs, '$(DESTDIR)$(infodir)');
2199         unshift (@install_data, 'install-info-am');
2201         # Make sure documentation is made and installed first.  Use
2202         # $(INFO_DEPS), not 'info', because otherwise recursive makes
2203         # get run twice during "make all".
2204         unshift (@all, '$(INFO_DEPS)');
2205     }
2206     push (@clean, 'aminfo');
2207     push (@info, '$(INFO_DEPS)');
2208     push (@dvi, '$(DVIS)');
2210     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2211     &define_variable ("DVIS", join (' ', @dvis_list));
2212     # This next isn't strictly needed now -- the places that look here
2213     # could easily be changed to look in info_TEXINFOS.  But this is
2214     # probably better, in case noinst_TEXINFOS is ever supported.
2215     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
2217     # Do some error checking.  Note that this file is not required
2218     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2219     # up above.
2220     if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
2221     {
2222         if ($need_texi_file > 1)
2223         {
2224             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2225                                           'texinfo.tex');
2226         }
2227         else
2228         {
2229             &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
2230         }
2231     }
2234 # Handle any man pages.
2235 sub handle_man_pages
2237     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
2238         if &variable_defined ('MANS');
2239     return if ! &variable_defined ('man_MANS');
2241     # Find all the sections in use.  We do this by first looking for
2242     # "standard" sections, and then looking for any additional
2243     # sections used in man_MANS.
2244     local ($sect, %sections, %vlist);
2245     # Add more sections as needed.
2246     foreach $sect ('0'..'9', 'n', 'l')
2247     {
2248         if (&variable_defined ('man' . $sect . '_MANS'))
2249         {
2250             $sections{$sect} = 1;
2251             $vlist{'$(man' . $sect . '_MANS)'} = 1;
2252         }
2253     }
2255     if (&variable_defined ('man_MANS'))
2256     {
2257         $vlist{'$(man_MANS)'} = 1;
2258         foreach (&variable_value_as_list ('man_MANS', 'all'))
2259         {
2260             # A page like `foo.1c' goes into man1dir.
2261             if (/\.([0-9a-z])([a-z]*)$/)
2262             {
2263                 $sections{$1} = 1;
2264             }
2265         }
2266     }
2269     # Now for each section, generate an install and unintall rule.
2270     # Sort sections so output is deterministic.
2271     local (@namelist);
2272     foreach $sect (sort keys %sections)
2273     {
2274         &define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
2275         push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
2276             unless defined $options{'no-installman'};
2277         $output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
2278                                                         . $sect . '/g;',
2279                                                         'mans');
2280         push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
2281         push (@namelist, 'install-man' . $sect);
2282     }
2284     # We don't really need this, but we use it in case we ever want to
2285     # support noinst_MANS.
2286     &define_variable ("MANS", join (' ', sort keys %vlist));
2288     # Generate list of install dirs.
2289     $output_rules .= ("install-man: \$(MANS)\n"
2290                       . "\t\@\$(NORMAL_INSTALL)\n");
2291     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2292     push (@phony, 'install-man');
2294     $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
2295     grep ($_ = 'un' . $_, @namelist);
2296     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2297     push (@phony, 'uninstall-man');
2299     $output_vars .= &file_contents ('mans-vars');
2301     if (! defined $options{'no-installman'})
2302     {
2303         push (@install_data, 'install-man');
2304         push (@uninstall, 'uninstall-man');
2305         push (@all, '$(MANS)');
2306     }
2309 # Handle DATA variables.
2310 sub handle_data
2312     &am_install_var ('-noextra', '-defaultdist', 'data', 'DATA',
2313                      'data', 'sysconf', 'sharedstate', 'localstate',
2314                      'pkgdata', 'noinst', 'check');
2317 # Handle TAGS.
2318 sub handle_tags
2320     push (@phony, 'tags');
2321     local (@tag_deps) = ();
2322     if (&variable_defined ('SUBDIRS'))
2323     {
2324         $output_rules .= ("tags-recursive:\n"
2325                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
2326                           # Never fail here if a subdir fails; it
2327                           # isn't important.
2328                           . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
2329                           . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
2330                           . "\tdone\n");
2331         push (@tag_deps, 'tags-recursive');
2332         push (@phony, 'tags-recursive');
2333     }
2335     if (&saw_sources_p (1)
2336         || &variable_defined ('ETAGS_ARGS')
2337         || @tag_deps)
2338     {
2339         local ($xform) = '';
2340         local ($one_hdr);
2341         foreach $one_hdr (@config_headers)
2342         {
2343             if ($relative_dir eq &dirname ($one_hdr))
2344             {
2345                 # The config header is in this directory.  So require it.
2346                 local ($var);
2347                 ($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
2348                 $xform .= ' ' if $xform;
2349                 $xform .= $var;
2350             }
2351         }
2352         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
2353                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
2355         if (&variable_defined ('SUBDIRS'))
2356         {
2357             $xform .= 's/^SUBDIRS//;';
2358         }
2359         else
2360         {
2361             $xform .= 's/^SUBDIRS.*$//;';
2362         }
2364         $output_rules .= &file_contents_with_transform ($xform, 'tags');
2365         $output_rules .= &file_contents ('tags-clean');
2366         push (@clean, 'tags');
2367         &push_phony_cleaners ('tags');
2368         &examine_variable ('TAGS_DEPENDENCIES');
2369     }
2370     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2371     {
2372         &am_line_error ('TAGS_DEPENDENCIES',
2373                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2374     }
2375     else
2376     {
2377         # Every Makefile must define some sort of TAGS rule.
2378         # Otherwise, it would be possible for a top-level "make TAGS"
2379         # to fail because some subdirectory failed.
2380         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2381     }
2384 # Handle multilib support.
2385 sub handle_multilib
2387     return unless $seen_multilib;
2389     $output_rules .= &file_contents ('multilib.am');
2390     &push_phony_cleaners ('multi');
2391     push (@phony, 'all-multi', 'install-multi');
2394 # Worker for handle_dist.
2395 sub handle_dist_worker
2397     local ($makefile) = @_;
2399     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
2401     # Initialization; only at top level.
2402     if ($relative_dir eq '.')
2403     {
2404         if (defined $options{'check-news'})
2405         {
2406             # For Gnits users, this is pretty handy.  Look at 15 lines
2407             # in case some explanatory text is desirable.
2408             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
2409           echo "NEWS not updated; not releasing" 1>&2; \\
2410           exit 1; \\
2411         fi
2413         }
2416         # Create dist directory.
2417         $output_rules .= ("\t-rm -rf \$(distdir)\n"
2418                           . "\tmkdir \$(distdir)\n"
2419                           . "\t-chmod 777 \$(distdir)\n");
2420     }
2422     # Only run automake in `dist' target if --include-deps and
2423     # `no-dependencies' not specified.  That way the recipient of a
2424     # distribution can run "make dist" and not need Automake.  You
2425     # might be wondering why we run automake once for each directory
2426     # we distribute, instead of running it once at the top level.  The
2427     # answer is that we want to run automake after the dependencies
2428     # have been generated.  This occurs when "make" is run in the
2429     # subdir.  So automake must be run after make has updated the
2430     # Makefile, which means that it must run once per directory.
2431     if ($use_dependencies)
2432     {
2433         $output_rules .=
2434             (
2435              # There are several directories we need to know about
2436              # when rebuilding the Makefile.ins.  They are:
2437              #   here - The absolute path to our topmost build directory.
2438              #   top_distdir - The absolute path to the top of our dist
2439              #                 hierarchy.
2440              #   distdir - The path to our sub-part of the dist hierarchy.
2441              # If this directory is the topmost directory, we set
2442              # top_distdir from distdir; that lets us pass in distdir
2443              # from an enclosing package.
2444              "\t" . 'here=`cd $(top_builddir) && pwd`; ' . "\\\n"
2445              . "\t" . 'top_distdir=`cd $('
2446              . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
2447              . ') && pwd`; ' . "\\\n"
2448              . "\t" . 'distdir=`cd $(distdir) && pwd`; ' . "\\\n"
2449              . "\tcd \$(top_srcdir) \\\n"
2450              . "\t  && \$(AUTOMAKE) --include-deps --build-dir=\$\$here --srcdir-name=\$(top_srcdir) --output-dir=\$\$top_distdir "
2451              # Set strictness of output.
2452              . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2453              . ($cmdline_use_dependencies ? '' : ' --include-deps')
2454              . " " . $makefile . "\n"
2455              );
2456     }
2458     # Scan EXTRA_DIST to see if we need to distribute anything from a
2459     # subdir.  If so, add it to the list.  I didn't want to do this
2460     # originally, but there were so many requests that I finally
2461     # relented.
2462     local (@dist_dirs);
2463     if (&variable_defined ('EXTRA_DIST'))
2464     {
2465         # FIXME: This should be fixed to work with conditionals.  That
2466         # will require only making the entries in @dist_dirs under the
2467         # appropriate condition.  This is meaningful if the nature of
2468         # the distribution should depend upon the configure options
2469         # used.
2470         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
2471         {
2472             next if /^\@.*\@$/;
2473             next unless s,/+[^/]+$,,;
2474             push (@dist_dirs, $_)
2475                 unless $_ eq '.';
2476         }
2477     }
2478     if (@dist_dirs)
2479     {
2480         # Prepend $(distdir) to each directory given.  Doing it via a
2481         # hash lets us ensure that each directory is used only once.
2482         local (%dhash);
2483         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
2484         $output_rules .= "\t";
2485         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
2486     }
2488     # In loop, test for file existence because sometimes a file gets
2489     # included in DISTFILES twice.  For example this happens when a
2490     # single source file is used in building more than one program.
2491     # Also, there are situations in which "ln" can fail.  For instance
2492     # a file to distribute could actually be a cross-filesystem
2493     # symlink -- this can easily happen if "gettextize" was run on the
2494     # distribution.
2495     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
2496     if ($cygnus_mode)
2497     {
2498         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
2499     }
2500     else
2501     {
2502         $output_rules .= "\t  d=\$(srcdir); \\\n";
2503     }
2504     $output_rules .= ("\t  if test -d \$\$d/\$\$file; then \\\n"
2505                       . "\t    cp -pr \$\$d/\$\$file \$(distdir)/\$\$file; \\\n"
2506                       . "\t  else \\\n"
2507                       . "\t    test -f \$(distdir)/\$\$file \\\n"
2508                       . "\t    || ln \$\$d/\$\$file \$(distdir)/\$\$file 2> /dev/null \\\n"
2509                       . "\t    || cp -p \$\$d/\$\$file \$(distdir)/\$\$file || :; \\\n"
2510                       . "\t  fi; \\\n"
2511                       . "\tdone\n");
2513     # If we have SUBDIRS, create all dist subdirectories and do
2514     # recursive build.
2515     if (&variable_defined ('SUBDIRS'))
2516     {
2517         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
2518         # to all possible directories, and use it.  If DIST_SUBDIRS is
2519         # defined, just use it.
2520         local ($dist_subdir_name);
2521         if (&variable_conditions ('SUBDIRS')
2522             || &variable_defined ('DIST_SUBDIRS'))
2523         {
2524             $dist_subdir_name = 'DIST_SUBDIRS';
2525             if (! &variable_defined ('DIST_SUBDIRS'))
2526             {
2527                 &define_pretty_variable ('DIST_SUBDIRS', '',
2528                                          &variable_value_as_list ('SUBDIRS',
2529                                                                   'all'));
2530             }
2531         }
2532         else
2533         {
2534             $dist_subdir_name = 'SUBDIRS';
2535         }
2537         # Test for directory existence here because previous automake
2538         # invocation might have created some directories.  Note that
2539         # we explicitly set distdir for the subdir make; that lets us
2540         # mix-n-match many automake-using packages into one large
2541         # package, and have "dist" at the top level do the right
2542         # thing.  If we're in the topmost directory, then we use
2543         # `distdir' instead of `top_distdir'; this lets us work
2544         # correctly with an enclosing package.
2545         $output_rules .= 
2546             ("\t" . 'for subdir in $(' . $dist_subdir_name . '); do ' . "\\\n"
2547              . "\t" . '  if test "$$subdir" = .; then :; else ' . "\\\n"
2548              . "\t" . '    test -d $(distdir)/$$subdir ' . "\\\n"
2549              . "\t" . '    || mkdir $(distdir)/$$subdir ' . "\\\n"
2550              . "\t" . '    || exit 1; ' . "\\\n"
2551              . "\t" . '    chmod 777 $(distdir)/$$subdir; ' . "\\\n"
2552              . "\t" . '    (cd $$subdir'
2553              . ' && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$('
2554              . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
2555              . ') distdir=../$(distdir)/$$subdir distdir) ' . "\\\n"
2556              . "\t" . '      || exit 1; ' . "\\\n"
2557              . "\t" . '  fi; ' . "\\\n"
2558              . "\tdone\n");
2559     }
2561     # If the target `dist-hook' exists, make sure it is run.  This
2562     # allows users to do random weird things to the distribution
2563     # before it is packaged up.
2564     push (@dist_targets, 'dist-hook') if &target_defined ('dist-hook');
2566     local ($targ);
2567     foreach $targ (@dist_targets)
2568     {
2569         # We must explicitly set distdir and top_distdir for these
2570         # sub-makes.
2571         $output_rules .= ("\t\$(MAKE) \$(AM_MAKEFLAGS)"
2572                           . " top_distdir=\"\$(top_distdir)\""
2573                           . " distdir=\"\$(distdir)\" $targ\n");
2574     }
2576     push (@phony, 'distdir');
2579 # Handle 'dist' target.
2580 sub handle_dist
2582     local ($makefile) = @_;
2584     # Set up maint_charset.
2585     $local_maint_charset = &variable_value ('MAINT_CHARSET')
2586         if &variable_defined ('MAINT_CHARSET');
2587     $maint_charset = $local_maint_charset
2588         if $relative_dir eq '.';
2590     if (&variable_defined ('DIST_CHARSET'))
2591     {
2592         &am_line_error ('DIST_CHARSET',
2593                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2594             if ! $local_maint_charset;
2595         if ($relative_dir eq '.')
2596         {
2597             $dist_charset = &variable_value ('DIST_CHARSET')
2598         }
2599         else
2600         {
2601             &am_line_error ('DIST_CHARSET',
2602                             "DIST_CHARSET can only be defined at top level");
2603         }
2604     }
2606     # Look for common files that should be included in distribution.
2607     local ($cfile);
2608     foreach $cfile (@common_files)
2609     {
2610         if (-f ($relative_dir . "/" . $cfile))
2611         {
2612             &push_dist_common ($cfile);
2613         }
2614     }
2616     # Always require configure.in and configure at top level, even if
2617     # they don't exist.  This is especially important for configure,
2618     # since it won't be created until autoconf is run -- which might
2619     # be after automake is run.
2620     &push_dist_common ('configure.in', 'configure')
2621         if $relative_dir eq '.';
2623     # Keys of %dist_common are names of files to distributed.  We put
2624     # README first because it then becomes easier to make a
2625     # Usenet-compliant shar file (in these, README must be first).
2626     # FIXME: do more ordering of files here.
2627     local (@coms);
2628     if (defined $dist_common{'README'})
2629     {
2630         push (@coms, 'README');
2631         delete $dist_common{'README'};
2632     }
2633     push (@coms, sort keys %dist_common);
2635     &define_pretty_variable ("DIST_COMMON", '', @coms);
2636     $output_vars .= "\n";
2638     # Some boilerplate.
2639     $output_vars .= &file_contents ('dist-vars') . "\n";
2640     &define_variable ('GZIP_ENV', '--best');
2642     # Put these things in rules section so it is easier for whoever
2643     # reads Makefile.in.
2644     if (! &variable_defined ('distdir'))
2645     {
2646         if ($relative_dir eq '.')
2647         {
2648             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2649         }
2650         else
2651         {
2652             $output_rules .= ("\n"
2653                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2654                               . "\n");
2655         }
2656     }
2657     if ($relative_dir eq '.')
2658     {
2659         $output_rules .= "top_distdir = \$(distdir)\n\n";
2660     }
2661     else
2662     {
2663         $output_rules .= "\nsubdir = " . $relative_dir . "\n\n";
2664     }
2666     # Generate 'dist' target, and maybe other dist targets.
2667     if ($relative_dir eq '.')
2668     {
2669         # Rule to check whether a distribution is viable.
2670         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
2671 # it guarantees that the distribution is self-contained by making another
2672 # tarfile.
2673 distcheck: dist
2674         -rm -rf $(distdir)
2675         GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(AMTAR) xf -
2676         mkdir $(distdir)/=build
2677         mkdir $(distdir)/=inst
2678         dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
2679                           . (&target_defined ('distcheck-hook')
2680                              ? ("\n\t\$(MAKE) \$(AM_MAKEFLAGS)"
2681                                 . " distcheck-hook; \\")
2682                              : '')
2683                           . '
2684         cd $(distdir)/=build \\
2685           && ../configure '
2687                           . ($seen_gettext ? '--with-included-gettext ' : '')
2688                           . '--srcdir=.. --prefix=$$dc_install_base \\
2689           && $(MAKE) $(AM_MAKEFLAGS) \\
2690           && $(MAKE) $(AM_MAKEFLAGS) dvi \\
2691           && $(MAKE) $(AM_MAKEFLAGS) check \\
2692           && $(MAKE) $(AM_MAKEFLAGS) install \\
2693           && $(MAKE) $(AM_MAKEFLAGS) installcheck \\
2694           && $(MAKE) $(AM_MAKEFLAGS) dist
2695         -rm -rf $(distdir)
2696         @banner="$(distdir).tar.gz is ready for distribution"; \\
2697         dashes=`echo "$$banner" | sed s/./=/g`; \\
2698         echo "$$dashes"; \\
2699         echo "$$banner"; \\
2700         echo "$$dashes"
2703         local ($dist_all) = ('dist-all: distdir' . "\n"
2704                              . $dist_header);
2705         local ($curs);
2706         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ',
2707                        'dist-bzip2')
2708         {
2709             if (defined $options{$curs} || $curs eq 'dist')
2710             {
2711                 $output_rules .= ($curs . ': distdir' . "\n"
2712                                   . $dist_header
2713                                   . $dist{$curs}
2714                                   . $dist_trailer);
2715                 $dist_all .= $dist{$curs};
2716             }
2717         }
2718         $output_rules .= $dist_all . $dist_trailer;
2719     }
2721     # Generate distdir target.
2722     &handle_dist_worker ($makefile);
2725 # Scan a single dependency file and rewrite the dependencies as
2726 # appropriate.  Essentially this means:
2727 # * Clean out absolute dependencies which are not desirable.
2728 # * Rewrite other dependencies to be relative to $(top_srcdir).
2729 sub scan_dependency_file
2731     local ($depfile) = @_;
2733     if (! open (DEP_FILE, $depfile))
2734     {
2735         &am_error ("couldn't open \`$depfile': $!");
2736         return;
2737     }
2738     print "automake: reading $depfile\n" if $verbose;
2740     # Sometimes it is necessary to omit some dependencies.
2741     local (%omit) = %omit_dependencies;
2742     if (&variable_defined ('OMIT_DEPENDENCIES'))
2743     {
2744         # FIXME: Doesn't work with conditionals.  I'm not sure if this
2745         # matters.
2746         grep ($omit{$_} = 1,
2747               &variable_value_as_list ('OMIT_DEPENDENCIES', ''));
2748     }
2750     local ($first_line) = 1;
2751     local ($last_line) = 0;
2752     local ($target, @dependencies);
2753     local ($one_dep, $xform);
2754     local ($just_file);
2756     local ($srcdir_rx, $fixup_rx);
2757     ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
2758         =~ s/(\W)/\\$1/g;
2759     ($srcdir_rx = $srcdir_name . '/') =~ s/(\W)/\\$1/g;
2761     local ($rewrite_builddir) = (($top_builddir eq '.')
2762                                  ? ''
2763                                  : $top_builddir . '/');
2765     while (<DEP_FILE>)
2766     {
2767         last if $last_line;
2768         next if (/$WHITE_PATTERN/o);
2769         chop;
2770         if (! s/\\$//)
2771         {
2772             # No trailing "\" means this should be the last line of
2773             # the first target.  We can have multiple targets due to
2774             # the "deleted header file" fix.  For the generated
2775             # Makefile we simply skip these fake targets.
2776             $last_line = 1;
2777         }
2779         if ($first_line)
2780         {
2781             if (! /^([^:]+:)(.+)$/)
2782             {
2783               bad_format:
2784                 &am_error ("\`$depfile' has incorrect format");
2785                 close (DEP_FILE);
2786                 return;
2787             }
2789             $_ = $2;
2790             # Make sure to strip the .P file from the target.
2791             ($target = $1) =~ s, *\.deps/[^.]+\.P,,;
2793             $first_line = 0;
2794         }
2796         foreach $one_dep (split (' ', $_))
2797         {
2798             ($just_file = $one_dep) =~ s,^.*/,,;
2799             next if defined $omit{$just_file};
2801             if ($one_dep =~ /^$fixup_rx/)
2802             {
2803                 # The dependency points to the current directory in
2804                 # some way.
2805                 ($xform = $one_dep) =~ s/^$fixup_rx//;
2806                 push (@dependencies, $xform);
2807             }
2808             elsif ($one_dep =~ /^$srcdir_rx/)
2809             {
2810                 # The dependency is in some other directory in the package.
2811                 ($xform = $one_dep) =~ s/^$srcdir_rx/$rewrite_builddir/;
2812                 push (@dependencies, $xform);
2813             }
2814             elsif ($one_dep =~ /^\// || $one_dep =~ /^[A-Za-z]:\\/)
2815             {
2816                 # Absolute path; ignore.
2817             }
2818             else
2819             {
2820                 # Anything else is assumed to be correct.
2821                 push (@dependencies, $one_dep);
2822             }
2823         }
2824     }
2826     &pretty_print_rule ($target, "\t", @dependencies);
2828     close (DEP_FILE);
2831 # Handle auto-dependency code.
2832 sub handle_dependencies
2834     # Make sure this variable is always marked as used.
2835     &examine_variable ('OMIT_DEPENDENCIES');
2837     if ($use_dependencies)
2838     {
2839         # Include GNU-make-specific auto-dep code.  Don't include it
2840         # if DEP_FILES would be empty.
2841         if (&saw_sources_p (0) && keys %dep_files)
2842         {
2843             &define_pretty_variable ('DEP_FILES', '', sort keys %dep_files);
2844             $output_rules .= &file_contents ('depend');
2845             push (@clean, 'depend');
2846             &push_phony_cleaners ('depend');
2848             local ($key, $lang, $ext, $xform);
2849             foreach $key (sort keys %language_map)
2850             {
2851                 next unless $key =~ /^(.*)-autodep$/;
2852                 next if $language_map{$key} eq 'no';
2853                 $lang = $1;
2855                 $xform = 's/\@PFX\@/' . $language_map{$key} . '/g;';
2856                 foreach $ext (&lang_extensions ($lang))
2857                 {
2858                     $output_rules .=
2859                         &file_contents_with_transform ('s/\@EXT\@/'
2860                                                        . $ext . '/g;'
2861                                                        . $xform,
2862                                                        'depend2');
2863                 }
2864             }
2865         }
2866     }
2867     elsif ($build_directory ne '')
2868     {
2869         # Include any auto-generated deps that are present.  Note that
2870         # $build_directory ends in a "/".
2871         if (-d ($build_directory . $relative_dir . "/.deps"))
2872         {
2873             local ($depfile);
2875             foreach $depfile (&my_glob ($build_directory
2876                                         . $relative_dir . "/.deps/*.P"))
2877             {
2878                 &scan_dependency_file ($depfile);
2879             }
2881             $output_rules .= "\n";
2882         }
2883     }
2886 # Handle subdirectories.
2887 sub handle_subdirs
2889     return if ! &variable_defined ('SUBDIRS');
2891     # Make sure each directory mentioned in SUBDIRS actually exists.
2892     local ($dir);
2893     foreach $dir (&variable_value_as_list ('SUBDIRS', 'all'))
2894     {
2895         # Skip directories substituted by configure.
2896         next if $dir =~ /^\@.*\@$/;
2898         if (! -d $am_relative_dir . '/' . $dir)
2899         {
2900             &am_line_error ('SUBDIRS',
2901                             "required directory $am_relative_dir/$dir does not exist");
2902             next;
2903         }
2905         &am_line_error ('SUBDIRS', "directory should not contain \`/'")
2906             if $dir =~ /\//;
2907     }
2909     local ($xform) = ('s/\@INSTALLINFO\@/' .
2910                       (defined $options{'no-installinfo'}
2911                        ? 'install-info-recursive'
2912                        : '')
2913                       . '/;');
2914     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
2916     # Push a bunch of phony targets.
2917     local ($phonies);
2918     foreach $phonies ('-data', '-exec', 'dirs')
2919     {
2920         push (@phony, 'install' . $phonies . '-recursive');
2921         push (@phony, 'uninstall' . $phonies . '-recursive');
2922     }
2923     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
2924     {
2925         push (@phony, $phonies . '-recursive');
2926     }
2927     &push_phony_cleaners ('recursive');
2929     $recursive_install = 1;
2932 # Handle aclocal.m4.
2933 sub handle_aclocal_m4
2935     local ($regen_aclocal) = 0;
2936     if (-f 'aclocal.m4')
2937     {
2938         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
2939         &push_dist_common ('aclocal.m4');
2941         if (open (ACLOCAL, '< aclocal.m4'))
2942         {
2943             local ($line);
2944             $line = <ACLOCAL>;
2945             close (ACLOCAL);
2947             if ($line =~ 'generated automatically by aclocal')
2948             {
2949                 $regen_aclocal = 1;
2950             }
2951         }
2952     }
2954     local ($acinclude) = 0;
2955     if (-f 'acinclude.m4')
2956     {
2957         $regen_aclocal = 1;
2958         $acinclude = 1;
2959     }
2961     # Note that it might be possible that aclocal.m4 doesn't exist but
2962     # should be auto-generated.  This case probably isn't very
2963     # important.
2964     if ($regen_aclocal)
2965     {
2966         local (@ac_deps) = (
2967                             ($seen_maint_mode
2968                              ? "\@MAINTAINER_MODE_TRUE\@"
2969                              : "") ,
2970                             "configure.in",
2971                             ($acinclude ? ' acinclude.m4' : '')
2972                             );
2974         # Scan all -I directories for m4 files.  These are our
2975         # dependencies.
2976         if (&variable_defined ('ACLOCAL_AMFLAGS'))
2977         {
2978             local ($examine_next, $amdir) = 0;
2979             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
2980             {
2981                 if ($examine_next)
2982                 {
2983                     $examine_next = 0;
2984                     if ($amdir !~ /^\// && -d $amdir)
2985                     {
2986                         push (@ac_deps, &my_glob ($amdir . '/*.m4'));
2987                     }
2988                 }
2989                 elsif ($amdir eq '-I')
2990                 {
2991                     $examine_next = 1;
2992                 }
2993             }
2994         }
2996         &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
2998         $output_rules .=  ("\t"
2999                            . 'cd $(srcdir) && $(ACLOCAL)'
3000                            . (&variable_defined ('ACLOCAL_AMFLAGS')
3001                               ? ' $(ACLOCAL_AMFLAGS)' : '')
3002                            . "\n");
3003     }
3006 # Rewrite a list of input files into a form suitable to put on a
3007 # dependency list.  The idea is that if an input file has a directory
3008 # part the same as the current directory, then the directory part is
3009 # simply removed.  But if the directory part is different, then
3010 # $(top_srcdir) is prepended.  Among other things, this is used to
3011 # generate the dependency list for the output files generated by
3012 # AC_OUTPUT.  Consider what the dependencies should look like in this
3013 # case:
3014 #   AC_OUTPUT(src/out:src/in1:lib/in2)
3015 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3016 # If 0 then files that require this addition will simply be ignored.
3017 sub rewrite_inputs_into_dependencies
3019     local ($add_srcdir, @inputs) = @_;
3020     local ($single, @newinputs);
3022     foreach $single (@inputs)
3023     {
3024         if (&dirname ($single) eq $relative_dir)
3025         {
3026             push (@newinputs, &basename ($single));
3027         }
3028         elsif ($add_srcdir)
3029         {
3030             push (@newinputs, '$(top_srcdir)/' . $single);
3031         }
3032     }
3034     return @newinputs;
3037 # Handle remaking and configure stuff.
3038 # We need the name of the input file, to do proper remaking rules.
3039 sub handle_configure
3041     local ($local, $input, @secondary_inputs) = @_;
3043     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
3044     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
3045         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
3047     local ($top_reldir);
3049     local ($input_base) = &basename ($input);
3050     local ($local_base) = &basename ($local);
3052     local ($amfile) = $input_base . '.am';
3053     # We know we can always add '.in' because it really should be an
3054     # error if the .in was missing originally.
3055     local ($infile) = '$(srcdir)/' . $input_base . '.in';
3056     local ($colon_infile);
3057     if ($local ne $input || @secondary_inputs)
3058     {
3059         $colon_infile = ':' . $input . '.in';
3060     }
3061     $colon_infile .= ':' . join (':', @secondary_inputs)
3062         if @secondary_inputs;
3064     local (@rewritten) = &rewrite_inputs_into_dependencies (1,
3065                                                             @secondary_inputs);
3067     # This rule remakes the Makefile.in.  Note use of
3068     # @MAINTAINER_MODE_TRUE@ forces us to abandon pretty-printing.
3069     # Sigh.
3070     $output_rules .= ($infile
3071                       # NOTE perl 5.003 (with -w) gives a
3072                       # uninitialized value error on the next line.
3073                       # Don't know why.
3074                       . ': '
3075                       . ($seen_maint_mode ? "\@MAINTAINER_MODE_TRUE\@ " : '')
3076                       . $amfile . ' '
3077                       . '$(top_srcdir)/configure.in $(ACLOCAL_M4)'
3078                       . ' ' . join (' ', @include_stack)
3079                       . "\n"
3080                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
3081                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
3082                       . ($cmdline_use_dependencies ? '' : ' --include-deps')
3083                       . ' ' . $input . $colon_infile . "\n\n");
3085     # This rule remakes the Makefile.
3086     $output_rules .= ($local_base
3087                       # NOTE: bogus uninit value error on next line;
3088                       # see comment above.
3089                       . ': '
3090                       . $infile . ' '
3091                       . join (' ', @rewritten)
3092                       . ' $(top_builddir)/config.status'
3093                       # NOTE: Makefile only depends on BUILT_SOURCES
3094                       # when dependencies are being computed.  This is
3095                       # a workaround for an obscure bug with
3096                       # AC_LINK_FILES.  Anyway, when dependencies are
3097                       # turned off, this shouldn't matter.
3098                       . ($use_dependencies ? ' $(BUILT_SOURCES)' : '')
3099                       . "\n"
3100                       . "\tcd \$(top_builddir) \\\n"
3101                       . "\t  && CONFIG_FILES="
3102                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3103                       . $colon_infile
3104                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
3105                       . "\n\n");
3107     if ($relative_dir ne '.')
3108     {
3109         # In subdirectory.
3110         $top_reldir = '../';
3111     }
3112     else
3113     {
3114         &handle_aclocal_m4;
3115         $output_rules .= &file_contents ('remake');
3116         &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3117         &examine_variable ('CONFIGURE_DEPENDENCIES');
3118         $top_reldir = '';
3120         &push_dist_common ('acconfig.h')
3121             if -f 'acconfig.h';
3122     }
3124     # Make it easy to see if there is a Makefile.am in a given
3125     # directory.
3126     local (%make_dirs, $iter);
3127     foreach $iter (@configure_input_files)
3128     {
3129         $make_dirs{&dirname ($iter)} = 1;
3130     }
3131     # We also want to notice Makefile.in's.
3132     foreach $iter (@other_input_files)
3133     {
3134         if ($iter =~ /Makefile\.in$/)
3135         {
3136             $make_dirs{&dirname ($iter)} = 1;
3137         }
3138     }
3140     # If we have a configure header, require it.
3141     local ($one_hdr);
3142     local (@local_fullnames) = @config_fullnames;
3143     local (@local_names) = @config_names;
3144     local ($hdr_index) = 0;
3145     local ($distclean_config) = '';
3146     foreach $one_hdr (@config_headers)
3147     {
3148         local ($one_fullname) = shift (@local_fullnames);
3149         local ($one_name) = shift (@local_names);
3150         $hdr_index += 1;
3151         local ($header_dir) = &dirname ($one_name);
3153         # If the header is in the current directory we want to build
3154         # the header here.  Otherwise, if we're at the topmost
3155         # directory and the header's directory doesn't have a
3156         # Makefile, then we also want to build the header.
3157         if ($relative_dir eq $header_dir
3158             || ($relative_dir eq '.' && ! defined $make_dirs{$header_dir}))
3159         {
3160             local ($ch_sans_dir, $cn_sans_dir, $stamp_dir);
3161             if ($relative_dir eq $header_dir)
3162             {
3163                 $cn_sans_dir = &basename ($one_name);
3164                 $stamp_dir = '';
3165             }
3166             else
3167             {
3168                 $cn_sans_dir = $one_name;
3169                 if ($header_dir eq '.')
3170                 {
3171                     $stamp_dir = '';
3172                 }
3173                 else
3174                 {
3175                     $stamp_dir = $header_dir . '/';
3176                 }
3177             }
3179             # Compute relative path from directory holding output
3180             # header to directory holding input header.  FIXME:
3181             # doesn't handle case where we have multiple inputs.
3182             if (&dirname ($one_hdr) eq $relative_dir)
3183             {
3184                 $ch_sans_dir = &basename ($one_hdr);
3185             }
3186             else
3187             {
3188                 local (@rel_out_path);
3189                 # FIXME this chunk of code should be its own sub.
3190                 # It is used elsewhere.
3191                 foreach (split (/\//, $relative_dir))
3192                 {
3193                     next if $_ eq '' || $_ eq '.';
3194                     if ($_ eq '..')
3195                     {
3196                         # FIXME: actually this is an error.
3197                         pop @rel_out_path;
3198                     }
3199                     else
3200                     {
3201                         push (@rel_out_path, '..');
3202                     }
3203                 }
3204                 if (@rel_out_path)
3205                 {
3206                     $ch_sans_dir = join ('/', @rel_out_path) . '/' . $one_hdr;
3207                 }
3208                 else
3209                 {
3210                     $ch_sans_dir = $one_hdr;
3211                 }
3212             }
3214             &require_file_with_conf_line ($config_header_line,
3215                                           $FOREIGN, $ch_sans_dir);
3217             # Header defined and in this directory.
3218             local (@files);
3219             if (-f $one_name . '.top')
3220             {
3221                 push (@files, "${cn_sans_dir}.top");
3222             }
3223             if (-f $one_name . '.bot')
3224             {
3225                 push (@files, "${cn_sans_dir}.bot");
3226             }
3228             &push_dist_common (@files);
3230             # For now, acconfig.h can only appear in the top srcdir.
3231             if (-f 'acconfig.h')
3232             {
3233                 if ($relative_dir eq '.')
3234                 {
3235                     push (@files, 'acconfig.h');
3236                 }
3237                 else
3238                 {
3239                     # Strange quoting because this gets fed through
3240                     # Perl.
3241                     push (@files, '\$(top_srcdir)/acconfig.h');
3242                 }
3243             }
3245             local ($stamp_name) = 'stamp-h';
3246             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3248             local ($xform) = '';
3250             $xform = 's,\@FILES\@,' . join (' ', @files) . ',;';
3251             $xform .= 's,\@CONFIG_HEADER\@,' . "${cn_sans_dir}" . ',;';
3252             $xform .= 's,\@CONFIG_HEADER_IN\@,' . "${ch_sans_dir}" . ',;';
3253             $xform .= 's,\@CONFIG_HEADER_FULL\@,' . "${one_fullname}" . ',;';
3254             $xform .= 's,\@STAMP\@,' . "${stamp_dir}${stamp_name}" . ',g;';
3256             $output_rules .= &file_contents_with_transform ($xform,
3257                                                             'remake-hdr');
3259             local ($out_dir) = &dirname ($ch_sans_dir);
3260             &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3261             &require_file_with_conf_line ($config_header_line, $FOREIGN,
3262                                           "${out_dir}/${stamp_name}.in");
3264             $distclean_config .= ' ' if $distclean_config;
3265             $distclean_config .= $cn_sans_dir;
3266         }
3267     }
3269     if ($distclean_config)
3270     {
3271         $output_rules .= &file_contents_with_transform ('s,\@FILES\@,'
3272                                                         . $distclean_config
3273                                                         . ',;',
3274                                                         'clean-hdr');
3275         push (@clean, 'hdr');
3276         &push_phony_cleaners ('hdr');
3277     }
3279     # Set location of mkinstalldirs.
3280     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
3281     {
3282         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
3283                                             . '/mkinstalldirs'));
3284     }
3285     else
3286     {
3287         &define_variable ('mkinstalldirs',
3288                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
3289     }
3291     &am_line_error ('CONFIG_HEADER',
3292                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
3293         if &variable_defined ('CONFIG_HEADER');
3295     local ($one_name);
3296     local ($config_header) = '';
3297     foreach $one_name (@config_names)
3298     {
3299         # Generate CONFIG_HEADER define.
3300         local ($one_hdr);
3301         if ($relative_dir eq &dirname ($one_name))
3302         {
3303             $one_hdr = &basename ($one_name);
3304         }
3305         else
3306         {
3307             $one_hdr = "${top_builddir}/${one_name}";
3308         }
3310         $config_header .= ' ' if $config_header;
3311         $config_header .= $one_hdr;
3312     }
3313     if ($config_header)
3314     {
3315         &define_variable ("CONFIG_HEADER", $config_header);
3316     }
3318     # Now look for other files in this directory which must be remade
3319     # by config.status, and generate rules for them.
3320     local (@actual_other_files) = ();
3321     local ($file, $local);
3322     local (@inputs, @rewritten_inputs, $single);
3323     local ($need_rewritten);
3324     foreach $file (@other_input_files)
3325     {
3326         if ($file =~ /^([^:]*):(.*)$/)
3327         {
3328             # This is the ":" syntax of AC_OUTPUT.
3329             $file = $1;
3330             $local = &basename ($file);
3331             @inputs = split (':', $2);
3332             @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3333             $need_rewritten = 1;
3334         }
3335         else
3336         {
3337             # Normal usage.
3338             $local = &basename ($file);
3339             @inputs = ($local . '.in');
3340             @rewritten_inputs =
3341                 &rewrite_inputs_into_dependencies (1, $file . '.in');
3342             $need_rewritten = 0;
3343         }
3345         # Skip files not in this directory.
3346         next unless &dirname ($file) eq $relative_dir;
3348         # Skip any file that is an automake input.
3349         next if -f $file . '.am';
3351         # Some users have been tempted to put `stamp-h' in the
3352         # AC_OUTPUT line.  This won't do the right thing, so we
3353         # explicitly fail here.
3354         if ($local eq 'stamp-h')
3355         {
3356             # FIXME: allow real filename.
3357             &am_conf_error ('configure.in', $ac_output_line,
3358                             'stamp-h should not appear in AC_OUTPUT');
3359             next;
3360         }
3362         $output_rules .= ($local . ': '
3363                           . '$(top_builddir)/config.status '
3364                           . join (' ', @rewritten_inputs) . "\n"
3365                           . "\t"
3366                           . 'cd $(top_builddir) && CONFIG_FILES='
3367                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3368                           . '$@' . ($need_rewritten
3369                                     ? (':' . join (':', @inputs))
3370                                     : '')
3371                           . ' CONFIG_HEADERS= $(SHELL) ./config.status'
3372                           . "\n");
3373         &push_dist_common (@inputs);
3374         push (@actual_other_files, $local);
3376         # Require all input files.
3377         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3378                                       &rewrite_inputs_into_dependencies (0, @inputs));
3379     }
3381     # These files get removed by "make clean".
3382     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3385 # Handle C headers.
3386 sub handle_headers
3388     local (@r);
3389     @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3390                           'oldinclude', 'pkginclude',
3391                           'noinst', 'check');
3392     foreach (@r)
3393     {
3394         next unless /\.(.*)$/;
3395         &saw_extension ($1);
3396     }
3399 sub handle_gettext
3401     return if ! $seen_gettext || $relative_dir ne '.';
3403     if (! &variable_defined ('SUBDIRS'))
3404     {
3405         &am_conf_error
3406             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
3407         return;
3408     }
3410     &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3412     if (&variable_defined ('SUBDIRS'))
3413     {
3414         &am_line_error
3415             ('SUBDIRS',
3416              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
3417                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
3418         &am_line_error
3419             ('SUBDIRS',
3420              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
3421                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
3422     }
3424     # Ensure that each language in ALL_LINGUAS has a .po file, and
3425     # each po file is mentioned in ALL_LINGUAS.
3426     if ($seen_linguas)
3427     {
3428         local (%linguas) = ();
3429         grep ($linguas{$_} = 1, split (' ', $all_linguas));
3431         foreach (<po/*.po>)
3432         {
3433             s/^po\///;
3434             s/\.po$//;
3436             &am_line_error ($all_linguas_line,
3437                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
3438                 if ! $linguas{$_};
3439         }
3441         foreach (keys %linguas)
3442         {
3443             &am_line_error ($all_linguas_line,
3444                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
3445                 if ! -f "po/$_.po";
3446         }
3447     }
3448     else
3449     {
3450         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
3451     }
3454 # Handle footer elements.
3455 sub handle_footer
3457     if ($contents{'SOURCES'})
3458     {
3459         # NOTE don't use define_pretty_variable here, because
3460         # $contents{...} is already defined.
3461         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
3462     }
3463     if ($contents{'OBJECTS'})
3464     {
3465         # NOTE don't use define_pretty_variable here, because
3466         # $contents{...} is already defined.
3467         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
3468     }
3469     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
3470     {
3471         $output_vars .= "\n";
3472     }
3474     if (&variable_defined ('SUFFIXES'))
3475     {
3476         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
3477         # make do not like variable substitutions on the .SUFFIXES
3478         # line.
3479         push (@suffixes, &variable_value_as_list ('SUFFIXES', ''));
3480     }
3481     if (&target_defined ('.SUFFIXES'))
3482     {
3483         &am_line_error ('.SUFFIXES',
3484                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
3485     }
3487     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3488     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3489     # anything else, by sticking it right after the default: target.
3490     $output_header .= ".SUFFIXES:\n";
3491     if (@suffixes)
3492     {
3494         # Make sure suffixes has unique elements.  Sort them to ensure
3495         # the output remains consistent.
3496         local (%suffixes);
3498         grep ($suffixes{$_} = 1, @suffixes);
3500         $output_header .= (".SUFFIXES: "
3501                            . join (' ', sort keys %suffixes)
3502                            . "\n");
3503     }
3504     $output_trailer .= &file_contents ('footer');
3507 # Deal with installdirs target.
3508 sub handle_installdirs
3510     # GNU Makefile standards recommend this.
3511     if ($recursive_install)
3512     {
3513         # We create a separate `-am' target so that the -recursive
3514         # rule will work correctly.
3515         $output_rules .= ("installdirs: installdirs-recursive\n"
3516                           . "installdirs-am:\n");
3517         push (@phony, 'installdirs-am');
3518     }
3519     else
3520     {
3521         $output_rules .= "installdirs:\n";
3522     }
3523     push (@phony, 'installdirs');
3524     if (@installdirs)
3525     {
3526         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
3527                             @installdirs);
3528     }
3529     $output_rules .= "\n";
3532 # There are several targets which need to be merged.  This is because
3533 # their complete definition is compiled from many parts.  Note that we
3534 # avoid double colon rules, otherwise we'd use them instead.
3535 sub handle_merge_targets
3537     local ($makefile) = @_;
3539     # There are a few install-related variables that you should not define.
3540     local ($var);
3541     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
3542     {
3543         if (&variable_defined ($var))
3544         {
3545             &am_line_error ($var, "\`$var' should not be defined");
3546         }
3547     }
3549     # Put this at the beginning for the sake of non-GNU makes.  This
3550     # is still wrong if these makes can run parallel jobs.  But it is
3551     # right enough.
3552     unshift (@all, &basename ($makefile));
3554     local ($one_name);
3555     foreach $one_name (@config_names)
3556     {
3557         push (@all, &basename ($one_name))
3558             if &dirname ($one_name) eq $relative_dir;
3559     }
3561     &do_one_merge_target ('info', @info);
3562     &do_one_merge_target ('dvi', @dvi);
3563     &do_check_merge_target;
3564     &do_one_merge_target ('installcheck', @installcheck);
3566     if (defined $options{'no-installinfo'})
3567     {
3568         &do_one_merge_target ('install-info', '');
3569     }
3570     elsif (&target_defined ('install-info-local'))
3571     {
3572         &am_line_error ('install-info-local',
3573                         "\`install-info-local' target defined but \`no-installinfo' option not in use");
3574     }
3576     local ($utarg);
3577     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3578                     'uninstall-exec-local', 'uninstall-exec-hook')
3579     {
3580         if (&target_defined ($utarg))
3581         {
3582             local ($x);
3583             ($x = $utarg) =~ s/(data|exec)-//;
3584             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3585         }
3586     }
3588     if (&target_defined ('install-local'))
3589     {
3590         &am_line_error ('install-local',
3591                         "use \`install-data-local' or \`install-exec-local', not \`install-local'");
3592     }
3594     if (@all)
3595     {
3596         local ($one_name);
3597         local ($local_headers) = '';
3598         foreach $one_name (@config_names)
3599         {
3600             if (&dirname ($one_name) eq $relative_dir)
3601             {
3602                 $local_headers .= ' ' if $local_headers;
3603                 $local_headers .= &basename ($one_name);
3604             }
3605         }
3606         if ($local_headers)
3607         {
3608             # This is kind of a hack, but I couldn't see a better way
3609             # to handle it.  In this particular case, we need to make
3610             # sure config.h is built before we recurse.  We can't do
3611             # this by changing the order of dependencies to the "all"
3612             # because that breaks when using parallel makes.  Instead
3613             # we handle things explicitly.
3614             $output_rules .= ("all-recursive-am: ${local_headers}"
3615                                   . "\n\t"
3616                                   . '$(MAKE) $(AM_MAKEFLAGS)'
3617                                   . " all-recursive"
3618                                   . "\n\n");
3619             $all_target = 'all-recursive-am';
3620             push (@phony, 'all-recursive-am');
3621         }
3622     }
3624     # Print definitions users can use.
3625     &do_one_merge_target ('install-exec', @install_exec);
3626     $output_rules .= "\n";
3628     &do_one_merge_target ('install-data', @install_data);
3629     $output_rules .= "\n";
3631     &do_one_merge_target ('install', 'all-am');
3632     &do_one_merge_target ('uninstall', @uninstall);
3634     &do_one_merge_target ('all', @all);
3636     # Generate the new 'install-strip' target.  We can't just set
3637     # INSTALL_PROGRAM because that might be a relative path.
3638     $output_rules .= ("install-strip:\n\t"
3639                       . '$(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install'
3640                       . "\n");
3641     push (@phony, 'install-strip');
3644 # Helper for handle_merge_targets.  Note that handle_merge_targets
3645 # relies on the fact that this doesn't add an extra \n at the end.
3646 sub do_one_merge_target
3648     local ($name, @values) = @_;
3650     if (&target_defined ($name . '-local'))
3651     {
3652         # User defined local form of target.  So include it.
3653         push (@values, $name . '-local');
3654         push (@phony, $name . '-local');
3655     }
3657     &pretty_print_rule ($name . "-am:", "\t\t", @values);
3658     if ($name eq 'install')
3659     {
3660         # Special-case `install-am' to run install-exec-am and
3661         # install-data-am after all-am is built.
3662         &pretty_print_rule ("\t\@\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3663                             'install-exec-am', 'install-data-am');
3664     }
3665     elsif ($name eq 'install-exec' && &target_defined ('install-exec-hook'))
3666     {
3667         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3668                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-exec-hook'
3669                           . "\n");
3670     }
3671     elsif ($name eq 'install-data' && &target_defined ('install-data-hook'))
3672     {
3673         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3674                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-data-hook'
3675                           . "\n");
3676     }
3678     local ($lname) = $name . ($recursive_install ? '-recursive' : '-am');
3679     local ($tname) = $name;
3680     # To understand this special case, see handle_merge_targets.
3681     if ($name eq 'all')
3682     {
3683         $tname = 'all-redirect';
3684         $lname = $all_target if $recursive_install;
3685         push (@phony, 'all-redirect');
3686         $output_all = "all: all-redirect\n";
3687     }
3688     &pretty_print_rule ($tname . ":", "\t\t", $lname);
3689     push (@phony, $name . '-am', $name);
3692 # Handle check merge target specially.
3693 sub do_check_merge_target
3695     if (&target_defined ('check-local'))
3696     {
3697         # User defined local form of target.  So include it.
3698         push (@check_tests, 'check-local');
3699         push (@phony, 'check-local');
3700     }
3702     # In --cygnus mode, check doesn't depend on all.
3703     if ($cygnus_mode)
3704     {
3705         # Just run the local check rules.
3706         &pretty_print_rule ('check-am:', "\t\t", @check);
3707     }
3708     else
3709     {
3710         # The check target must depend on the local equivalent of
3711         # `all', to ensure all the primary targets are built.  Then it
3712         # must build the local check rules.
3713         $output_rules .= "check-am: all-am\n";
3714         &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3715                             @check)
3716             if @check;
3717     }
3718     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3719                         @check_tests)
3720         if @check_tests;
3722     push (@phony, 'check', 'check-am');
3723     $output_rules .= ("check: "
3724                       . ($recursive_install ? 'check-recursive' : 'check-am')
3725                       . "\n");
3728 # Handle all 'clean' targets.
3729 sub handle_clean
3731     local ($xform) = '';
3732     local ($name);
3734     # Don't include `MAINTAINER'; it is handled specially below.
3735     foreach $name ('MOSTLY', '', 'DIST')
3736     {
3737         if (! &variable_defined ($name . 'CLEANFILES'))
3738         {
3739             $xform .= 's/^' . $name . 'CLEAN.*$//;';
3740         }
3741         else
3742         {
3743             $xform .= 's/^' . $name . 'CLEAN//;';
3744         }
3745     }
3747     # Built sources are automatically removed by maintainer-clean.
3748     push (@maintainer_clean_files, '\$(BUILT_SOURCES)')
3749         if &variable_defined ('BUILT_SOURCES');
3750     push (@maintainer_clean_files, '\$(MAINTAINERCLEANFILES)')
3751         if &variable_defined ('MAINTAINERCLEANFILES');
3752     if (! @maintainer_clean_files)
3753     {
3754         $xform .= 's/^MAINTAINERCLEAN.*$//;';
3755     }
3756     else
3757     {
3758         $xform .= ('s/^MAINTAINERCLEAN//;'
3759                    # Join with no space to avoid spurious `test -z'
3760                    # success at runtime.
3761                    . 's,\@MCFILES\@,' . join ('', @maintainer_clean_files)
3762                    . ',;'
3763                    # A space is required in the join here.
3764                    . 's,\@MFILES\@,' . join (' ', @maintainer_clean_files)
3765                    . ',;');
3766     }
3768     $output_rules .= &file_contents_with_transform ($xform, 'clean');
3770     push (@clean, 'generic');
3771     &push_phony_cleaners ('generic');
3773     &do_one_clean_target ('clean', 'mostly', '', @clean);
3774     &do_one_clean_target ('clean', '', 'mostly', @clean);
3775     &do_one_clean_target ('clean', 'dist', '', @clean);
3776     &do_one_clean_target ('clean', 'maintainer-', 'dist', @clean);
3778     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
3781 # Helper for handle_clean.
3782 sub do_one_clean_target
3784     local ($target, $name, $last_name, @deps) = @_;
3786     # Change each dependency `BLARG' into `clean-BLARG'.
3787     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
3789     # Push the previous clean target.  There is no previous clean
3790     # target if we're doing mostlyclean.
3791     push (@deps, $last_name . $target . '-am')
3792         unless $name eq 'mostly';
3794     # If a -local version of the rule is given, add it to the list.
3795     if (&target_defined ($name . $target . '-local'))
3796     {
3797         push (@deps, $name . $target . '-local');
3798     }
3800     # Print the target and the dependencies.
3801     &pretty_print_rule ($name . $target . "-am: ", "\t\t", @deps);
3803     # FIXME: shouldn't we really print these messages before running
3804     # the dependencies?
3805     if ($name . $target eq 'maintainer-clean')
3806     {
3807         # Print a special warning.
3808         $output_rules .=
3809             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
3810              . "\t\@echo \"it deletes files that may require special "
3811              . "tools to rebuild.\"\n");
3812     }
3813     elsif ($name . $target eq 'distclean')
3814     {
3815         $output_rules .= "\t-rm -f libtool\n" if $seen_libtool;
3816     }
3817     $output_rules .= "\n";
3819     # Now generate the actual clean target.
3820     $output_rules .= ($name . $target . ": " . $name . $target
3821                       . ($recursive_install ? '-recursive' : '-am')
3822                       . "\n");
3824     # We special-case config.status here.  If we do it as part of the
3825     # normal clean processing for this directory, then it might be
3826     # removed before some subdir is cleaned.  However, that subdir's
3827     # Makefile depends on config.status.
3828     if (($name . $target eq 'maintainer-clean'
3829          || $name . $target eq 'distclean')
3830         && $relative_dir eq '.')
3831     {
3832         $output_rules .= "\t-rm -f config.status\n";
3833     }
3834     $output_rules .= "\n";
3837 # Handle .PHONY target.
3838 sub handle_phony
3840     &pretty_print_rule ('.PHONY:', "", @phony);
3841     $output_rules .= "\n";
3844 # Handle TESTS variable and other checks.
3845 sub handle_tests
3847     if (defined $options{'dejagnu'})
3848     {
3849         push (@check_tests, 'check-DEJAGNU');
3850         push (@phony, 'check-DEJAGNU');
3852         local ($xform);
3853         if ($cygnus_mode)
3854         {
3855             $xform = 's/^CYGNUS//;';
3856         }
3857         else
3858         {
3859             $xform = 's/^CYGNUS.*$//;';
3860         }
3861         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
3863         # In Cygnus mode, these are found in the build tree.
3864         # Otherwise they are looked for in $PATH.
3865         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
3866         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
3868         # Only create site.exp rule if user hasn't already written
3869         # one.
3870         if (! &target_defined ('site.exp'))
3871         {
3872             # Note that in the rule we don't directly generate
3873             # site.exp to avoid the possibility of a corrupted
3874             # site.exp if make is interrupted.  Jim Meyering has some
3875             # useful text on this topic.
3876             $output_rules .= ("site.exp: Makefile\n"
3877                               . "\t\@echo 'Making a new site.exp file...'\n"
3878                               . "\t\@test ! -f site.bak || rm -f site.bak\n"
3879                               . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
3880                               . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
3881                               . "\t\@echo '# edit the last section' >> \$\@-t\n"
3882                               . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
3883                               . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
3884                               . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
3886             # Extra stuff for AC_CANONICAL_*
3887             local (@whatlist) = ();
3888             if ($seen_canonical)
3889             {
3890                 push (@whatlist, 'host');
3891             }
3893             # Extra stuff only for AC_CANONICAL_SYSTEM.
3894             if ($seen_canonical == $AC_CANONICAL_SYSTEM)
3895             {
3896                 push (@whatlist, 'target', 'build');
3897             }
3899             local ($c1, $c2);
3900             foreach $c1 (@whatlist)
3901             {
3902                 foreach $c2 ('alias', 'triplet')
3903                 {
3904                     $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
3905                 }
3906             }
3908             $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
3909                               . "\t\@test ! -f site.exp || sed '1,/^## All variables above are.*##/ d' site.exp >> \$\@-t\n"
3910                               . "\t\@test ! -f site.exp || mv site.exp site.bak\n"
3911                               . "\t\@mv \$\@-t site.exp\n");
3912         }
3913     }
3914     else
3915     {
3916         local ($c);
3917         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
3918         {
3919             if (&variable_defined ($c))
3920             {
3921                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
3922             }
3923         }
3924     }
3926     if (&variable_defined ('TESTS'))
3927     {
3928         push (@check_tests, 'check-TESTS');
3929         push (@phony, 'check-TESTS');
3931         # Note: Solaris 2.7 seems to expand TESTS using VPATH.  That's
3932         # why we also try `dir='
3933         $output_rules .= 'check-TESTS: $(TESTS)
3934         @failed=0; all=0; xfail=0; xpass=0; \\
3935         srcdir=$(srcdir); export srcdir; \\
3936         for tst in $(TESTS); do \\
3937           if test -f ./$$tst; then dir=./; \\
3938           elif test -f $$tst; then dir=; \\
3939           else dir="$(srcdir)/"; fi; \\
3940           if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \\
3941             all=`expr $$all + 1`; \\
3942             case " $(XFAIL_TESTS) " in \\
3943             *" $$tst "*) \\
3944               xpass=`expr $$xpass + 1`; \\
3945               failed=`expr $$failed + 1`; \\
3946               echo "XPASS: $$tst"; \\
3947             ;; \\
3948             *) \\
3949               echo "PASS: $$tst"; \\
3950             ;; \\
3951             esac; \\
3952           elif test $$? -ne 77; then \\
3953             all=`expr $$all + 1`; \\
3954             case " $(XFAIL_TESTS) " in \\
3955             *" $$tst "*) \\
3956               xfail=`expr $$xfail + 1`; \\
3957               echo "XFAIL: $$tst"; \\
3958             ;; \\
3959             *) \\
3960               failed=`expr $$failed + 1`; \\
3961               echo "FAIL: $$tst"; \\
3962             ;; \\
3963             esac; \\
3964           fi; \\
3965         done; \\
3966         if test "$$failed" -eq 0; then \\
3967           if test "$$xfail" -eq 0; then \\
3968             banner="All $$all tests passed"; \\
3969           else \\
3970             banner="All $$all tests behaved as expected ($$xfail expected failures)"; \\
3971           fi; \\
3972         else \\
3973           if test "$$xpass" -eq 0; then \\
3974             banner="$$failed of $$all tests failed"; \\
3975           else \\
3976             banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \\
3977           fi; \\
3978         fi; \\
3979         dashes=`echo "$$banner" | sed s/./=/g`; \\
3980         echo "$$dashes"; \\
3981         echo "$$banner"; \\
3982         echo "$$dashes"; \\
3983         test "$$failed" -eq 0
3985     }
3988 # Handle Emacs Lisp.
3989 sub handle_emacs_lisp
3991     local (@elfiles) = &am_install_var ('-candist', 'lisp', 'LISP',
3992                                         'lisp', 'noinst');
3994     if (@elfiles)
3995     {
3996         # Found some lisp.
3997         &define_configure_variable ('lispdir');
3998         &define_configure_variable ('EMACS');
3999         $output_rules .= (".el.elc:\n"
4000                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
4001                           . "\tif test \$(EMACS) != no; then \\\n"
4002                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
4003                           . "\tfi\n");
4004         push (@suffixes, '.el', '.elc');
4006         # Generate .elc files.
4007         grep ($_ .= 'c', @elfiles);
4008         &define_pretty_variable ('ELCFILES', '', @elfiles);
4010         $output_rules .= &file_contents ('lisp-clean');
4011         push (@clean, 'lisp');
4012         &push_phony_cleaners ('lisp');
4014         push (@all, '$(ELCFILES)');
4016         local ($varname);
4017         if (&variable_defined ('lisp_LISP'))
4018         {
4019             $varname = 'lisp_LISP';
4020             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
4021                 if ! $seen_lispdir;
4022         }
4023         else
4024         {
4025             $varname = 'noinst_LISP';
4026         }
4028         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
4029     }
4032 # Handle Java.
4033 sub handle_java
4035     local (@sourcelist) = &am_install_var ('-candist', '-clean',
4036                                            'java', 'JAVA',
4037                                            'java', 'noinst', 'check');
4038     return if ! @sourcelist;
4040     &define_variable ('JAVAC', 'javac');
4041     &define_variable ('JAVACFLAGS', '');
4042     &define_variable ('CLASSPATH_ENV',
4043                       'CLASSPATH=$(JAVAROOT):$(srcdir)/$(JAVAROOT):$$CLASSPATH');
4044     &define_variable ('JAVAROOT', '$(top_builddir)');
4046     local (%valid) = &am_primary_prefixes ('JAVA', 1,
4047                                            'java', 'noinst', 'check');
4049     local ($dir, $curs);
4050     foreach $curs (keys %valid)
4051     {
4052         if (! &variable_defined ($curs . '_JAVA') || $curs eq 'noinst'
4053             || $curs eq 'EXTRA')
4054         {
4055             next;
4056         }
4058         if (defined $dir)
4059         {
4060             &am_line_error ($curs . '_JAVA',
4061                             "multiple _JAVA primaries in use");
4062         }
4063         $dir = $curs;
4064     }
4066     $output_rules .= ('class' . $dir . '.stamp: $(' . $dir . '_JAVA)' . "\n"
4067                       . "\t" . '$(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) '
4068                       . '$(JAVACFLAGS) $?' . "\n"
4069                       . "\t" . 'echo timestamp > class' . $dir . '.stamp'
4070                       . "\n");
4071     push (@all, 'class' . $dir . '.stamp');
4072     &push_dist_common ('$(' . $dir . '_JAVA)');
4075 # Handle some of the minor options.
4076 sub handle_minor_options
4078     if (defined $options{'readme-alpha'})
4079     {
4080         if ($relative_dir eq '.')
4081         {
4082             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4083             {
4084                 # FIXME: allow real filename.
4085                 &am_conf_line_error ('configure.in',
4086                                      $package_version_line,
4087                                      "version \`$package_version' doesn't follow Gnits standards");
4088             }
4089             elsif (defined $1 && -f 'README-alpha')
4090             {
4091                 # This means we have an alpha release.  See
4092                 # GNITS_VERSION_PATTERN for details.
4093                 &require_file ($FOREIGN, 'README-alpha');
4094             }
4095         }
4096     }
4099 ################################################################
4101 # Scan one file for interesting things.  Subroutine of scan_configure.
4102 sub scan_one_configure_file
4104     local ($filename) = @_;
4105     local (*CONFIGURE);
4107     open (CONFIGURE, $filename)
4108         || die "automake: couldn't open \`$filename': $!\n";
4109     print "automake: reading $filename\n" if $verbose;
4111     while (<CONFIGURE>)
4112     {
4113         # Remove comments from current line.
4114         s/\bdnl\b.*$//;
4115         s/\#.*$//;
4117         # Skip macro definitions.  Otherwise we might be confused into
4118         # thinking that a macro that was only defined was actually
4119         # used.
4120         next if /AC_DEFUN/;
4122         # Follow includes.  This is a weirdness commonly in use at
4123         # Cygnus and hopefully nowhere else.
4124         if (/sinclude\((.*)\)/ && -f $1)
4125         {
4126             &scan_one_configure_file ($1);
4127         }
4129         # Populate libobjs array.
4130         if (/AC_FUNC_ALLOCA/)
4131         {
4132             $libsources{'alloca.c'} = 1;
4133         }
4134         elsif (/AC_FUNC_GETLOADAVG/)
4135         {
4136             $libsources{'getloadavg.c'} = 1;
4137         }
4138         elsif (/AC_FUNC_MEMCMP/)
4139         {
4140             $libsources{'memcmp.c'} = 1;
4141         }
4142         elsif (/AC_STRUCT_ST_BLOCKS/)
4143         {
4144             $libsources{'fileblocks.c'} = 1;
4145         }
4146         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4147         {
4148             $libsources{'getopt.c'} = 1;
4149             $libsources{'getopt1.c'} = 1;
4150         }
4151         elsif (/AM_FUNC_STRTOD/)
4152         {
4153             $libsources{'strtod.c'} = 1;
4154         }
4155         elsif (/AM_WITH_REGEX/)
4156         {
4157             $libsources{'rx.c'} = 1;
4158             $libsources{'rx.h'} = 1;
4159             $libsources{'regex.c'} = 1;
4160             $libsources{'regex.h'} = 1;
4161             $omit_dependencies{'rx.h'} = 1;
4162             $omit_dependencies{'regex.h'} = 1;
4163         }
4164         elsif (/AM_FUNC_MKTIME/)
4165         {
4166             $libsources{'mktime.c'} = 1;
4167         }
4168         elsif (/AM_FUNC_ERROR_AT_LINE/)
4169         {
4170             $libsources{'error.c'} = 1;
4171             $libsources{'error.h'} = 1;
4172         }
4173         elsif (/AM_FUNC_OBSTACK/)
4174         {
4175             $libsources{'obstack.c'} = 1;
4176             $libsources{'obstack.h'} = 1;
4177         }
4178         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4179                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4180         {
4181             foreach $libobj_iter (split (' ', $1))
4182             {
4183                 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4184                     || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4185                     || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4186                 {
4187                     $libsources{$1 . '.c'} = 1;
4188                 }
4189             }
4190         }
4192         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4193         {
4194             $in_ac_replace = 1;
4195         }
4196         if ($in_ac_replace)
4197         {
4198             $in_ac_replace = 0 if s/[\]\)].*$//;
4199             # Remove trailing backslash.
4200             s/\\$//;
4201             foreach (split)
4202             {
4203                 # Need to skip empty elements for Perl 4.
4204                 next if $_ eq '';
4205                 $libsources{$_ . '.c'} = 1;
4206             }
4207         }
4209         if (/$obsolete_rx/o)
4210         {
4211             local ($hint) = '';
4212             if ($obsolete_macros{$1} ne '')
4213             {
4214                 $hint = '; ' . $obsolete_macros{$1};
4215             }
4216             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
4217         }
4219         # Process the AC_OUTPUT macro.
4220         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
4221         {
4222             $in_ac_output = 1;
4223             $ac_output_line = $.;
4224         }
4225         if ($in_ac_output)
4226         {
4227             local ($closing) = 0;
4228             if (s/[\]\),].*$//)
4229             {
4230                 $in_ac_output = 0;
4231                 $closing = 1;
4232             }
4234             # Look at potential Makefile.am's.
4235             foreach (split)
4236             {
4237                 # Must skip empty string for Perl 4.
4238                 next if $_ eq "\\" || $_ eq '';
4240                 # Handle $local:$input syntax.  Note that we ignore
4241                 # every input file past the first, though we keep
4242                 # those around for later.
4243                 local ($local, $input, @rest) = split (/:/);
4244                 if (! $input)
4245                 {
4246                     $input = $local;
4247                 }
4248                 else
4249                 {
4250                     # FIXME: should be error if .in is missing.
4251                     $input =~ s/\.in$//;
4252                 }
4254                 if (-f $input . '.am')
4255                 {
4256                     # We have a file that automake should generate.
4257                     push (@make_input_list, $input);
4258                     $make_list{$input} = join (':', ($local, @rest));
4259                 }
4260                 else
4261                 {
4262                     # We have a file that automake should cause to be
4263                     # rebuilt, but shouldn't generate itself.
4264                     push (@other_input_files, $_);
4265                 }
4266             }
4268             if ($closing && @make_input_list == 0 && @other_input_files == 0)
4269             {
4270                 &am_conf_line_error ($filename, $ac_output_line,
4271                                      "No files mentioned in \`AC_OUTPUT'");
4272                 exit 1;
4273             }
4274         }
4276         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4277         {
4278             @config_aux_path = $1;
4279         }
4281         # Check for ansi2knr.
4282         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4284         # Check for exe extension stuff.
4285         if (/AC_EXEEXT/)
4286         {
4287             $seen_exeext = 1;
4288             $configure_vars{'EXEEXT'} = $filename . ':' . $.;
4289         }
4291         if (/AC_OBJEXT/)
4292         {
4293             $seen_objext = 1;
4294             $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4295         }
4297         # Check for `-c -o' code.
4298         $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4300         # Check for NLS support.
4301         if (/AM_GNU_GETTEXT/)
4302         {
4303             $seen_gettext = 1;
4304             $ac_gettext_line = $.;
4305             $omit_dependencies{'libintl.h'} = 1;
4306         }
4308         # Look for ALL_LINGUAS.
4309         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4310         {
4311             $seen_linguas = 1;
4312             $all_linguas = $1;
4313             $all_linguas_line = $.;
4314         }
4316         # Handle configuration headers.  A config header of `[$1]'
4317         # means we are actually scanning AM_CONFIG_HEADER from
4318         # aclocal.m4.
4319         if (/A([CM])_CONFIG_HEADER\s*\((.*)\)/
4320             && $2 ne '[$1]')
4321         {
4322             &am_conf_line_error
4323                 ($filename, $., "\`automake requires \`AM_CONFIG_HEADER', not \`AC_CONFIG_HEADER'")
4324                     if $1 eq 'C';
4326             $config_header_line = $.;
4327             local ($one_hdr);
4328             foreach $one_hdr (split (' ', $2))
4329             {
4330                 push (@config_fullnames, $one_hdr);
4331                 if ($one_hdr =~ /^([^:]+):(.+)$/)
4332                 {
4333                     push (@config_names, $1);
4334                     push (@config_headers, $2);
4335                 }
4336                 else
4337                 {
4338                     push (@config_names, $one_hdr);
4339                     push (@config_headers, $one_hdr . '.in');
4340                 }
4341             }
4342         }
4344         # Handle AC_CANONICAL_*.  Always allow upgrading to
4345         # AC_CANONICAL_SYSTEM, but never downgrading.
4346         $seen_canonical = $AC_CANONICAL_HOST
4347             if ! $seen_canonical
4348                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4349         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4351         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
4353         # This macro handles several different things.
4354         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4355         {
4356             $seen_make_set = 1;
4357             $seen_package = 1;
4358             $seen_version = 1;
4359             $seen_arg_prog = 1;
4360             $seen_prog_install = 1;
4361             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4362             $package_version_line = $.;
4363         }
4365         # This is like AM_INIT_AUTOMAKE, but doesn't actually set the
4366         # package and version number.  (This might change in the
4367         # future).  Yes, I'm not above hacking Automake so it works
4368         # well with other GNU tools -- that is actually the point.
4369         if (/AM_INIT_GUILE_MODULE/)
4370         {
4371             $seen_make_set = 1;
4372             $seen_package = 1;
4373             $seen_version = 1;
4374             $seen_arg_prog = 1;
4375             $seen_prog_install = 1;
4376             @config_aux_path = ('..');
4377         }
4379         # Some things required by Automake.
4380         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
4381         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
4383         if (/AM_PROG_LEX/)
4384         {
4385             $configure_vars{'LEX'} = $filename . ':' . $.;
4386             $seen_decl_yytext = 1;
4387         }
4388         if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.in$/)
4389         {
4390             &am_conf_line_warning ($filename, $., "\`AC_DECL_YYTEXT' is covered by \`AM_PROG_LEX'");
4391         }
4392         if (/AC_PROG_LEX/ && $filename =~ /configure\.in$/)
4393         {
4394             &am_conf_line_warning ($filename, $., "automake requires \`AM_PROG_LEX', not \`AC_PROG_LEX'");
4395         }
4397         if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4398         {
4399             $configure_vars{$1} = $filename . ':' . $.;
4400         }
4401         if (/$AC_CHECK_PATTERN/o)
4402         {
4403             $configure_vars{$3} = $filename . ':' . $.;
4404         }
4405         if (/$AM_MISSING_PATTERN/o
4406             && $1 ne 'ACLOCAL'
4407             && $1 ne 'AUTOCONF'
4408             && $1 ne 'AUTOMAKE'
4409             && $1 ne 'AUTOHEADER')
4410         {
4411             $configure_vars{$1} = $filename . ':' . $.;
4412         }
4414         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4415         # but later define it elsewhere.  This is pretty hacky.  We
4416         # also explicitly avoid INSTALL_SCRIPT and some other
4417         # variables because they are defined in header-vars.am.
4418         # FIXME.
4419         if (/$AC_SUBST_PATTERN/o
4420             && $1 ne 'ANSI2KNR'
4421             && $1 ne 'INSTALL_SCRIPT'
4422             && $1 ne 'INSTALL_DATA')
4423         {
4424             $configure_vars{$1} = $filename . ':' . $.;
4425         }
4427         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4428         if (/AM_MAINTAINER_MODE/)
4429         {
4430             $seen_maint_mode = 1;
4431             $configure_cond{'MAINTAINER_MODE'} = 1;
4432         }
4433         $seen_package = 1 if /PACKAGE=/;
4435         # Skip VERSION of [$2]; that is from AM_INIT_AUTOMAKE.
4436         if (/\bVERSION=(\S+)/ && $1 ne '[$2]')
4437         {
4438             $seen_version = 1;
4439             $package_version = $1;
4440             $package_version_line = $.;
4441         }
4442         elsif (/VERSION=/)
4443         {
4444             $seen_version = 1;
4445         }
4447         $seen_prog_install = 1 if /AC_PROG_INSTALL/;
4448         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4450         if (/A(C|M)_PROG_LIBTOOL/)
4451         {
4452             if (/AM_PROG_LIBTOOL/)
4453             {
4454                 &am_conf_line_warning ($filename, $., "\`AM_PROG_LIBTOOL' is obsolete, use \`AC_PROG_LIBTOOL' instead");
4455             }
4456             $seen_libtool = 1;
4457             $libtool_line = $.;
4458             $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4459             $configure_vars{'RANLIB'} = $filename . ':' . $.;
4460             $configure_vars{'CC'} = $filename . ':' . $.;
4461             # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
4462             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4463             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4464         }
4466         $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4468         if (/$AM_CONDITIONAL_PATTERN/o)
4469         {
4470             $configure_cond{$1} = 1;
4471         }
4473         # Check for Fortran 77 intrinsic and run-time libraries.
4474         if (/AC_F77_LIBRARY_LDFLAGS/)
4475         {
4476             $configure_vars{'FLIBS'} = $filename . ':' . $.;
4477         }
4478     }
4480     close (CONFIGURE);
4483 # Scan configure.in and aclocal.m4 for interesting things.  We must
4484 # scan aclocal.m4 because there might be AC_SUBSTs and such there.
4485 sub scan_configure
4487     # Reinitialize libsources here.  This isn't really necessary,
4488     # since we currently assume there is only one configure.in.  But
4489     # that won't always be the case.
4490     %libsources = ();
4492     local ($in_ac_output, $in_ac_replace) = (0, 0);
4493     local (%make_list, @make_input_list);
4494     local ($libobj_iter);
4496     &scan_one_configure_file ('configure.in');
4497     &scan_one_configure_file ('aclocal.m4')
4498         if -f 'aclocal.m4';
4500     # Set input and output files if not specified by user.
4501     if (! @input_files)
4502     {
4503         @input_files = @make_input_list;
4504         %output_files = %make_list;
4505     }
4507     @configure_input_files = @make_input_list;
4509     &am_conf_error ("\`PACKAGE' not defined in configure.in")
4510         if ! $seen_package;
4511     &am_conf_error ("\`VERSION' not defined in configure.in")
4512         if ! $seen_version;
4514     # Look for some files we need.  Always check for these.  This
4515     # check must be done for every run, even those where we are only
4516     # looking at a subdir Makefile.  We must set relative_dir so that
4517     # the file-finding machinery works.
4518     local ($relative_dir) = '.';
4519     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4520     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
4521         if -f $config_aux_path[0] . '/install.sh';
4524 ################################################################
4526 # Set up for Cygnus mode.
4527 sub check_cygnus
4529     return unless $cygnus_mode;
4531     &set_strictness ('foreign');
4532     $options{'no-installinfo'} = 1;
4533     $options{'no-dependencies'} = 1;
4534     $use_dependencies = 0;
4536     if (! $seen_maint_mode)
4537     {
4538         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
4539     }
4541     if (! $seen_exeext)
4542     {
4543         &am_conf_error ("\`AC_EXEEXT' required when --cygnus specified");
4544     }
4547 # Do any extra checking for GNU standards.
4548 sub check_gnu_standards
4550     if ($relative_dir eq '.')
4551     {
4552         # In top level (or only) directory.
4553         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4554                        'AUTHORS', 'ChangeLog');
4555     }
4557     if ($strictness >= $GNU)
4558     {
4559         if (defined $options{'no-installman'})
4560         {
4561             &am_line_error ('AUTOMAKE_OPTIONS',
4562                             "option \`no-installman' disallowed by GNU standards");
4563         }
4565         if (defined $options{'no-installinfo'})
4566         {
4567             &am_line_error ('AUTOMAKE_OPTIONS',
4568                             "option \`no-installinfo' disallowed by GNU standards");
4569         }
4570     }
4573 # Do any extra checking for GNITS standards.
4574 sub check_gnits_standards
4576     if ($strictness >= $GNITS)
4577     {
4578         if (-f $relative_dir . '/COPYING.LIB')
4579         {
4580             &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
4581         }
4582     }
4584     if ($relative_dir eq '.')
4585     {
4586         # In top level (or only) directory.
4587         &require_file ($GNITS, 'THANKS');
4588     }
4591 ################################################################
4593 # Functions to handle files of each language.
4595 # Each `lang_X_rewrite' function follows a simple formula:
4596 # * Args are the directory, base name and extension of the file.
4597 # * Return value is 1 if file is to be dealt with, 0 otherwise.
4598 # Much of the actual processing is handled in handle_single_transform_list.
4599 # These functions exist so that auxiliary information can be recorded
4600 # for a later cleanup pass.  Note that the calls to these functions
4601 # are computed, so don't bother searching for their precise names
4602 # in the source.
4604 # This is just a convenience function that can be used to determine
4605 # when a subdir object should be used.
4606 sub lang_sub_obj
4608     return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4611 # Rewrite a single C source file.
4612 sub lang_c_rewrite
4614     local ($directory, $base, $ext) = @_;
4616     if (defined $options{'ansi2knr'} && $base =~ /_$/)
4617     {
4618         # FIXME: include line number in error.
4619         &am_error ("C source file \`$base.c' would be deleted by ansi2knr rules");
4620     }
4622     local ($r) = $LANG_PROCESS;
4623     if (defined $options{'subdir-objects'})
4624     {
4625         $r = $LANG_SUBDIR;
4626         $base = $directory . '/' . $base;
4628         if (! $seen_cc_c_o)
4629         {
4630             # Only give error once.
4631             $seen_cc_c_o = 1;
4632             # FIXME: line number.
4633             &am_error ("C objects in subdir but \`AM_PROG_CC_C_O' not in \`configure.in'");
4634         }
4636         &require_file ($FOREIGN, 'compile')
4637             if $relative_dir eq '.';
4638     }
4640     $de_ansi_files{$base} = 1;
4641     return $r;
4644 # Rewrite a single C++ source file.
4645 sub lang_cxx_rewrite
4647     return &lang_sub_obj;
4650 # Rewrite a single header file.
4651 sub lang_header_rewrite
4653     # Header files are simply ignored.
4654     return $LANG_IGNORE;
4657 # Rewrite a single yacc file.
4658 sub lang_yacc_rewrite
4660     local ($directory, $base, $ext) = @_;
4662     local ($r) = &lang_c_rewrite ($directory, $base, $ext);
4663     local ($pfx) = '';
4664     if ($r == $LANG_SUBDIR)
4665     {
4666         $pfx = $directory . '/';
4667     }
4668     $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4669     $ext =~ tr/y/c/;
4670     &saw_extension ('c');
4671     # FIXME: nodist.
4672     &push_dist_common ($pfx . $base . '.' . $ext);
4673     return $r;
4676 # Rewrite a single yacc++ file.
4677 sub lang_yaccxx_rewrite
4679     local ($directory, $base, $ext) = @_;
4681     local ($r) = $LANG_PROCESS;
4682     local ($pfx) = '';
4683     if (defined $options{'subdir-objects'})
4684     {
4685         $pfx = $directory . '/';
4686         $r = $LANG_SUBDIR;
4687     }
4688     $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4689     $ext =~ tr/y/c/;
4690     &saw_extension ($ext);
4691     # FIXME: nodist.
4692     &push_dist_common ($pfx . $base . '.' . $ext);
4693     return $r;
4696 # Rewrite a single lex file.
4697 sub lang_lex_rewrite
4699     local ($directory, $base, $ext) = @_;
4701     local ($r) = &lang_c_rewrite ($directory, $base, $ext);
4702     local ($pfx) = '';
4703     if ($r == $LANG_SUBDIR)
4704     {
4705         $pfx = $directory . '/';
4706     }
4707     $lex_sources{$pfx . $base . '.' . $ext} = 1;
4708     $ext =~ tr/l/c/;
4709     &saw_extension ('c');
4710     # FIXME: nodist.
4711     &push_dist_common ($pfx . $base . '.' . $ext);
4712     return $r;
4715 # Rewrite a single lex++ file.
4716 sub lang_lexxx_rewrite
4718     local ($directory, $base, $ext) = @_;
4720     local ($r) = $LANG_PROCESS;
4721     local ($pfx) = '';
4722     if (defined $options{'subdir-objects'})
4723     {
4724         $pfx = $directory . '/';
4725         $r = $LANG_SUBDIR;
4726     }
4727     $lex_sources{$pfx . $base . '.' . $ext} = 1;
4728     $ext =~ tr/l/c/;
4729     &saw_extension ($ext);
4730     # FIXME: nodist.
4731     &push_dist_common ($pfx . $base . '.' . $ext);
4732     return $r;
4735 # Rewrite a single assembly file.
4736 sub lang_asm_rewrite
4738     return &lang_sub_obj;
4741 # Rewrite a single Fortran 77 file.
4742 sub lang_f77_rewrite
4744     return $LANG_PROCESS;
4747 # Rewrite a single preprocessed Fortran 77 file.
4748 sub lang_ppf77_rewrite
4750     return $LANG_PROCESS;
4753 # Rewrite a single ratfor file.
4754 sub lang_ratfor_rewrite
4756     return $LANG_PROCESS;
4759 # Rewrite a single Objective C file.
4760 sub lang_objc_rewrite
4762     return &lang_sub_obj;
4765 # Rewrite a single Java file.
4766 sub lang_java_rewrite
4768     return $LANG_SUBDIR;
4771 # The lang_X_finish functions are called after all source file
4772 # processing is done.  Each should handle defining rules for the
4773 # language, etc.  A finish function is only called if a source file of
4774 # the appropriate type has been seen.
4776 sub lang_c_finish
4778     # Push all libobjs files onto de_ansi_files.  We actually only
4779     # push files which exist in the current directory, and which are
4780     # genuine source files.
4781     local ($file);
4782     foreach $file (keys %libsources)
4783     {
4784         if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
4785         {
4786             $de_ansi_files{$1} = 1;
4787         }
4788     }
4790     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
4791     {
4792         # Make all _.c files depend on their corresponding .c files.
4793         local ($base, @objects);
4794         foreach $base (sort keys %de_ansi_files)
4795         {
4796             # Each _.c file must depend on ansi2knr; otherwise it
4797             # might be used in a parallel build before it is built.
4798             # We need to support files in the srcdir and in the build
4799             # dir (because these files might be auto-generated.  But
4800             # we can't use $< -- some makes only define $< during a
4801             # suffix rule.
4802             $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
4803                               . '$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
4804                               . '`if test -f $(srcdir)/' . $base . '.c'
4805                               . '; then echo $(srcdir)/' . $base . '.c'
4806                               . '; else echo ' . $base . '.c; fi` '
4807                               . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
4808                               . '| $(ANSI2KNR) > ' . $base . "_.c\n");
4809             push (@objects, $base . '_'
4810                   . ($seen_objext ? '.$(OBJEXT)' : '.o'));
4811             push (@objects, $base . '_.lo') if $seen_libtool;
4812         }
4814         # Make all _.o (and _.lo) files depend on ansi2knr.
4815         # Use a sneaky little hack to make it print nicely.
4816         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
4817     }
4819     if (! defined $configure_vars{'CC'})
4820     {
4821         # FIXME: line number.
4822         &am_error ("C source seen but \`CC' not defined in \`configure.in'");
4823     }
4826 sub lang_cxx_finish
4828     local (@cxx_list) = &lang_extensions ('cxx');
4829     local ($cxx_count) = scalar @cxx_list;
4830     if ($cxx_count)
4831     {
4832         push (@suffixes, @cxx_list);
4834         local ($ltcompile, $ltlink) = &libtool_compiler;
4836         &define_configure_variable ("CXXFLAGS");
4837         &define_compiler_variable ('CXXCOMPILE', $ltcompile, '$(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)');
4839         &define_variable ('CXXLD', '$(CXX)');
4840         &define_variable ('CXXLINK', $ltlink . '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
4842         local ($ext);
4843         foreach $ext (@cxx_list)
4844         {
4845             # Every known C++ compiler supports both -c and -o.
4846             $output_rules .= ("$ext.o:\n"
4847                               . "\t\$(CXXCOMPILE) -c -o \$\@ \$<\n");
4848             # FIXME: Using cygpath should be somehow conditional.
4849             $output_rules .= ("$ext.obj:\n"
4850                               . "\t\$(CXXCOMPILE) -c -o \$\@ `cygpath -w \$<`\n")
4851                 if ($seen_objext);
4852             $output_rules .= ("$ext.lo:\n"
4853                               . "\t\$(LTCXXCOMPILE) -c -o \$\@ \$<\n")
4854                 if ($seen_libtool);
4855         }
4857         if (! defined $configure_vars{'CXX'})
4858         {
4859             &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
4860         }
4861     }
4864 sub lang_header_finish
4866     # Nothing to do.
4869 # This is a helper for both lex and yacc.
4870 sub yacc_lex_finish_helper
4872     return if defined $language_scratch{'lex-yacc-done'};
4873     $language_scratch{'lex-yacc-done'} = 1;
4875     # If there is more than one distinct yacc (resp lex) source file
4876     # in a given directory, then the `ylwrap' program is required to
4877     # allow parallel builds to work correctly.  FIXME: for now, no
4878     # line number.
4879     &require_config_file ($FOREIGN, 'ylwrap');
4880     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
4881     {
4882         &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
4883     }
4884     else
4885     {
4886         &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
4887     }
4890 sub lang_yacc_finish
4892     return if defined $language_scratch{'yacc-done'};
4893     $language_scratch{'yacc-done'} = 1;
4895     local ($file, $base, $hname, $cname);
4896     local (%seen_suffix) = ();
4897     local (@yacc_files) = sort keys %yacc_sources;
4898     local ($yacc_count) = scalar (@yacc_files);
4899     foreach $file (@yacc_files)
4900     {
4901         $file =~ /(\..*)$/;
4902         &output_yacc_build_rule ($1, $yacc_count > 1)
4903             if ! defined $seen_suffix{$1};
4904         $seen_suffix{$1} = 1;
4906         $file =~ /^(.*)\.(y|yy|y\+\+|yxx|ypp)$/;
4907         $base = $1;
4908         $hname = 'h';           # Always use `.h' for header file.
4909         ($cname = $2) =~ tr/y/c/;
4911         if ((&variable_defined ('AM_YFLAGS')
4912              && &variable_value ('AM_YFLAGS') =~ /(^|\s)-d(\s|$)/)
4913             || (&variable_defined ('YFLAGS')
4914                 && &variable_value ('YFLAGS') =~ /(^|\s)-d(\s|$)/)) {
4915             # Now generate rule to make the header file.  This should only
4916             # be generated if `yacc -d' specified.
4917             $output_rules .= "${base}.${hname}: ${base}.${cname}\n";
4919             # If the files are built in the build directory, then we want
4920             # to remove them with `make clean'.  If they are in srcdir
4921             # they shouldn't be touched.  However, we can't determine this
4922             # statically, and the GNU rules say that yacc/lex output files
4923             # should be removed by maintainer-clean.  So that's what we
4924             # do.
4925             push (@maintainer_clean_files, "${base}.${hname}");
4927             &push_dist_common ("${base}.${hname}");
4928         }
4929         push (@maintainer_clean_files, "${base}.${cname}");
4930     }
4931     $output_rules .= "\n";
4933     if (! defined $configure_vars{'YACC'})
4934     {
4935         &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
4936     }
4937     if (&variable_defined ('YACCFLAGS'))
4938     {
4939         &am_line_error ('YACCFLAGS',
4940                         "\`YACCFLAGS' obsolete; use \`YFLAGS' instead");
4941     }
4943     if ($yacc_count > 1)
4944     {
4945         &yacc_lex_finish_helper;
4946     }
4949 sub lang_yaccxx_finish
4951     &lang_yacc_finish;
4954 sub lang_lex_finish
4956     return if defined $language_scratch{'lex-done'};
4957     $language_scratch{'lex-done'} = 1;
4959     local (%seen_suffix) = ();
4960     local ($file, $cname);
4961     local ($lex_count) = scalar (keys %lex_sources);
4962     foreach $file (sort keys %lex_sources)
4963     {
4964         $file =~ /(\..*)$/;
4965         &output_lex_build_rule ($1, $lex_count > 1)
4966             if (! defined $seen_suffix{$1});
4967         $seen_suffix{$1} = 1;
4969         # If the files are built in the build directory, then we want
4970         # to remove them with `make clean'.  If they are in srcdir
4971         # they shouldn't be touched.  However, we can't determine this
4972         # statically, and the GNU rules say that yacc/lex output files
4973         # should be removed by maintainer-clean.  So that's what we
4974         # do.
4975         $file =~ /^(.*)\.(l|ll|l\+\+|lxx|lpp)$/;
4976         ($cname = $2) =~ tr/l/c/;
4977         push (@maintainer_clean_files, "${1}.${cname}");
4978     }
4980     if (! defined $configure_vars{'LEX'})
4981     {
4982         &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
4983     }
4984     if (! $seen_decl_yytext)
4985     {
4986         &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
4987     }
4989     if ($lex_count > 1)
4990     {
4991         &yacc_lex_finish_helper;
4992     }
4995 sub lang_lexxx_finish
4997     &lang_lex_finish;
5000 sub lang_asm_finish
5002     # We need the C code for assembly.
5003     &lang_c_finish;
5005     # We also need our own rules.
5006     local ($minuso) = '';
5007     if (defined $options{'subdir-objects'})
5008     {
5009         $minuso = '-o $@ ';
5010     }
5011     local (@asm_list) = &lang_extensions ('am');
5012     local ($ext);
5013     foreach $ext (@asm_list)
5014     {
5015         $output_rules .= ("$ext.o:\n"
5016                           . "\t\$(COMPILE) -c " . $minuso . "\$<\n");
5017         # FIXME: Using cygpath should be somehow conditional.
5018         $output_rules .= ("$ext.obj:\n"
5019                           . "\t\$(COMPILE) -c " . $minuso
5020                           . "`cygpath -w \$<`\n")
5021             if $seen_objext;
5022         $output_rules .= ("$ext.lo:\n"
5023                           . "\t\$(LTCOMPILE) -c -o \$\@ \$<\n")
5024             if $seen_libtool;
5025     }
5027     push (@suffixes, @asm_list);
5030 sub lang_f77_finish
5032     local (@f77_list) = &lang_extensions ('f77');
5033     local ($f77_count) = scalar @f77_list;
5034     if ($f77_count)
5035     {
5036         push (@suffixes, @f77_list);
5038         local ($ltcompile, $ltlink) = &libtool_compiler;
5040         &define_configure_variable ('FFLAGS');
5041         &define_compiler_variable ('F77COMPILE', $ltcompile,
5042                                    '$(F77) $(AM_FFLAGS) $(FFLAGS)');
5044         &define_variable ('F77LD', '$(F77)');
5045         &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5047         local ($ext);
5048         foreach $ext (@f77_list)
5049         {
5050             $output_rules .= ("$ext.o:\n"
5051                               . "\t\$(F77COMPILE) -c \$<\n");
5052             # FIXME: Using cygpath should be somehow conditional.
5053             $output_rules .= ("$ext.obj:\n"
5054                               . "\t\$(F77COMPILE) -c `cygpath -w \$<`\n")
5055                 if ($seen_objext);
5056             $output_rules .= ("$ext.lo:\n"
5057                               . "\t\$(LTF77COMPILE) -c \$<\n")
5058                 if ($seen_libtool);
5059         }
5061         if (! defined $configure_vars{'F77'})
5062         {
5063             &am_error ("Fortran 77 source seen but \`F77' not defined in \`configure.in'");
5064         }
5065     }
5068 # Preprocessed Fortran 77
5070 # The current support for preprocessing Fortran 77 just involves passing
5071 # `$(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)' as additional flags
5072 # to the Fortran 77 compiler, since this is how GNU Make does it; see
5073 # the `GNU Make Manual, Edition 0.51 for `make' Version 3.76 Beta'
5074 # (specifically, from info file `(make)Catalogue of Rules').
5076 # A better approach would be to write an Autoconf test
5077 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
5078 # Fortran 77 compilers know how to do preprocessing.  The Autoconf macro
5079 # AC_PROG_FPP should test the Fortran 77 compiler first for
5080 # preprocessing capabilities, and then fall back on cpp (if cpp were
5081 # available).
5082 sub lang_ppf77_finish
5084     local ($ext) = 'F';
5085     last unless $extension_seen{$ext};
5087     $ext = '.' . $ext;
5088     push (@suffixes, $ext);
5090     local ($ltcompile, $ltlink) = &libtool_compiler;
5092     &define_configure_variable ('FFLAGS');
5093     &define_compiler_variable ('F77COMPILE', $ltcompile,
5094                                '$(F77) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)');
5096     &define_variable ('F77LD', '$(F77)');
5097     &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5099     $output_rules .= ("$ext.o:\n"
5100                       . "\t\$(F77COMPILE) -c \$<\n");
5101     # FIXME: Using cygpath should be somehow conditional.
5102     $output_rules .= ("$ext.obj:\n"
5103                       . "\t\$(F77COMPILE) -c `cygpath -w \$<`\n")
5104         if ($seen_objext);
5105     $output_rules .= ("$ext.lo:\n"
5106                       . "\t\$(LTF77COMPILE) -c \$<\n")
5107         if ($seen_libtool);
5109     # We also handle the case of preprocessing `.F' files into `.f'
5110     # files.
5111     $output_rules .= ("$ext.f:\n"
5112                       . "\t\$(F77COMPILE) -F \$<\n");
5114     if (! defined $configure_vars{'F77'})
5115     {
5116         &am_error ("Fortran 77 source seen but \`F77' not defined in \`configure.in'");
5117     }
5120 sub lang_ratfor_finish
5122     local ($ext) = 'r';
5123     last unless $extension_seen{$ext};
5124     $ext = '.' . $ext;
5125     push (@suffixes, $ext);
5127     local ($ltcompile, $ltlink) = &libtool_compiler;
5129     &define_configure_variable ('FFLAGS');
5130     &define_configure_variable ('RFLAGS');
5131     &define_variable ('RCOMPILE', $ltcompile,
5132                       '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)');
5134     &define_variable ('F77LD', '$(F77)');
5135     &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5137     $output_rules .= ("$ext.o:\n"
5138                       . "\t\$(RCOMPILE) -c \$<\n");
5139     # FIXME: Using cygpath should be somehow conditional.
5140     $output_rules .= ("$ext.obj:\n"
5141                       . "\t\$(RCOMPILE) -c `cygpath -w \$<`\n")
5142         if ($seen_objext);
5143     $output_rules .= ("$ext.lo:\n"
5144                       . "\t\$(LTRCOMPILE) -c \$<\n")
5145         if ($seen_libtool);
5147     # We also handle the case of preprocessing `.r' files into `.f'
5148     # files.
5149     $output_rules .= ("$ext.f:\n"
5150                       . "\t\$(RCOMPILE) -F \$<\n");
5152     if (! defined $configure_vars{'F77'})
5153     {
5154         &am_error ("Ratfor source seen but \`F77' not defined in \`configure.in'");
5155     }
5158 sub lang_objc_finish
5160     push (@suffixes, '.m');
5162     local ($ltcompile, $ltlink) = &libtool_compiler;
5164     &define_configure_variable ("OBJCFLAGS");
5165     &define_compiler_variable ('OBJCCOMPILE', $ltcompile,
5166                                '$(OBJC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)');
5168     &define_variable ('OBJCLD', '$(OBJC)');
5169     &define_variable ('OBJCLINK', $ltlink . '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5171     # All known ObjC compilers support -c and -o together.
5172     $output_rules .= (".m.o:\n"
5173                       . "\t\$(OBJCCOMPILE) -c -o \$\@ \$<\n");
5174     # FIXME: Using cygpath should be somehow conditional.
5175     $output_rules .= (".m.obj:\n"
5176                       . "\t\$(OBJCCOMPILE) -c -o \$\@ `cygpath -w \$<`\n")
5177         if ($seen_objext);
5178     $output_rules .= (".m.lo:\n"
5179                       . "\t\$(LTOBJCCOMPILE) -c -o \$\@ \$<\n")
5180         if ($seen_libtool);
5182     if (! defined $configure_vars{'OBJC'})
5183     {
5184         &am_error ("Objective C source seen but \`OBJC' not defined in \`configure.in'");
5185     }
5188 sub lang_java_finish
5190     push (@suffixes, '.java');
5192     local ($ltcompile, $ltlink) = &libtool_compiler;
5194     &define_configure_variable ("GCJFLAGS");
5195     &define_compiler_variable ('GCJCOMPILE', $ltcompile,
5196                                '$(GCJ) $(DEFS) $(INCLUDES) $(AM_GCJFLAGS) $(GCJFLAGS)');
5198     &define_variable ('GCJLD', '$(GCJ)');
5199     &define_variable ('GCJLINK', $ltlink . '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5201     # All known Java compilers support -c and -o together.
5202     $output_rules .= (".java.o:\n"
5203                       . "\t\$(GCJCOMPILE) -c -o \$\@ \$<\n");
5204     # FIXME: Using cygpath should be somehow conditional.
5205     $output_rules .= (".java.obj:\n"
5206                       . "\t\$(GCJCOMPILE) -c -o \$\@ `cygpath -w \$<`\n")
5207         if ($seen_objext);
5208     $output_rules .= (".java.lo:\n"
5209                       . "\t\$(LTGCJCOMPILE) -c -o \$\@ \$<\n")
5210         if ($seen_libtool);
5212     if (! defined $configure_vars{'GCJ'})
5213     {
5214         &am_error ("Java source seen but \`GCJ' not defined in \`configure.in'");
5215     }
5218 # A helper which computes a sorted list of all extensions for LANG.
5219 sub lang_extensions
5221     local ($lang) = @_;
5222     local ($key, @r);
5223     foreach $key (sort keys %extension_seen)
5224     {
5225         push (@r, '.' . $key) if $extension_map{$key} eq $lang;
5226     }
5227     return @r;
5230 # A helper which decides whether libtool is needed.  Returns prefix
5231 # for compiler and linker.
5232 sub libtool_compiler
5234     local ($ltcompile, $ltlink) = ('', '');
5235     if ($seen_libtool)
5236     {
5237         &define_configure_variable ("LIBTOOL");
5238         $ltcompile = '$(LIBTOOL) --mode=compile ';
5239         $ltlink = '$(LIBTOOL) --mode=link ';
5240     }
5241     return ($ltcompile, $ltlink);
5244 # Given a hash table of linker names, pick the name that has the most
5245 # precedence.  This is lame, but something has to have global
5246 # knowledge in order to eliminate the conflict.  Add more linkers as
5247 # required.
5248 sub resolve_linker
5250     local (%linkers) = @_;
5252     return 'GCJLINK'
5253         if defined $linkers{'GCJLINK'};
5254     return 'CXXLINK'
5255         if defined $linkers{'CXXLINK'};
5256     return 'F77LINK'
5257         if defined $linkers{'F77LINK'};
5258     return 'OBJCLINK'
5259         if defined $linkers{'OBJCLINK'};
5260     return 'LINK';
5263 # Called to indicate that an extension was used.
5264 sub saw_extension
5266     local ($ext) = @_;
5267     $extension_seen{$ext} = 1;
5270 # Called to ask whether source files have been seen . If HEADERS is 1,
5271 # headers can be included.
5272 sub saw_sources_p
5274     local ($headers) = @_;
5276     if ($headers)
5277     {
5278         $headers = 0;
5279     }
5280     else
5281     {
5282         local (@exts) = &lang_extensions ('header');
5283         $headers = @exts;
5284     }
5286     return scalar keys %extension_seen > $headers;
5289 # Register a single language.  LANGUAGE is the name of the language.
5290 # Each OPTION is either of the form NAME=VALUE, or is a file extension
5291 # (sans `.').
5292 sub register_language
5294     local ($language, @options) = @_;
5296     # Set the defaults.
5297     $language_map{$language . '-ansi-p'} = 0;
5298     $language_map{$language . '-linker'} = '';
5299     $language_map{$language . '-autodep'} = 'no';
5301     local ($iter);
5302     foreach $iter (@options)
5303     {
5304         if ($iter =~ /^(.*)=(.*)$/)
5305         {
5306             $language_map{$language . '-' . $1} = $2;
5307         }
5308         elsif (defined $extension_map{$iter})
5309         {
5310             print STDERR
5311                 "automake: programming error: duplicate extension $iter\n";
5312             exit 1;
5313         }
5314         else
5315         {
5316             $extension_map{$iter} = $language;
5317         }
5318     }
5322 ################################################################
5324 # Pretty-print something.  HEAD is what should be printed at the
5325 # beginning of the first line, FILL is what should be printed at the
5326 # beginning of every subsequent line.
5327 sub pretty_print_internal
5329     local ($head, $fill, @values) = @_;
5331     local ($column) = length ($head);
5332     local ($result) = $head;
5334     # Fill length is number of characters.  However, each Tab
5335     # character counts for eight.  So we count the number of Tabs and
5336     # multiply by 7.
5337     local ($fill_length) = length ($fill);
5338     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5340     local ($bol) = ($head eq '');
5341     foreach (@values)
5342     {
5343         # "71" because we also print a space.
5344         if ($column + length ($_) > 71)
5345         {
5346             $result .= " \\\n" . $fill;
5347             $column = $fill_length;
5348             $bol = 1;
5349         }
5351         $result .= ' ' unless ($bol);
5352         $result .= $_;
5353         $column += length ($_) + 1;
5354         $bol = 0;
5355     }
5357     $result .= "\n";
5358     return $result;
5361 # Pretty-print something and append to output_vars.
5362 sub pretty_print
5364     $output_vars .= &pretty_print_internal (@_);
5367 # Pretty-print something and append to output_rules.
5368 sub pretty_print_rule
5370     $output_rules .= &pretty_print_internal (@_);
5374 ################################################################
5376 # See if a target exists.
5377 sub target_defined
5379     local ($target) = @_;
5380     return defined $targets{$target};
5383 # See if two conditionals are the same.
5384 sub conditional_same
5386     local ($cond1, $cond2) = @_;
5388     return (&conditional_true_when ($cond1, $cond2)
5389             && &conditional_true_when ($cond2, $cond1));
5392 # See if a conditional is true.  Both arguments are conditional
5393 # strings.  This returns true if the first conditional is true when
5394 # the second conditional is true.
5395 sub conditional_true_when
5397     local ($cond, $when) = @_;
5399     # Check the easy case first.
5400     if ($cond eq $when)
5401     {
5402         return 1;
5403     }
5405     # Check each component of $cond, which looks @COND1@@COND2@.
5406     foreach $comp (split ('@', $cond))
5407     {
5408         # The way we split will give null strings between each
5409         # condition.
5410         next if ! $comp;
5412         if (index ($when, '@' . $comp . '@') == -1)
5413         {
5414             return 0;
5415         }
5416     }
5418     return 1;
5421 # Check for an ambiguous conditional.  This is called when a variable
5422 # or target is being defined conditionally.  If we already know about
5423 # a definition that is true under the same conditions, then we have an
5424 # ambiguity.
5425 sub check_ambiguous_conditional
5427     local ($var_name, $cond) = @_;
5428     local (@cond_vals) = split (' ', $conditional{$var_name});
5429     while (@cond_vals)
5430     {
5431         local ($vcond) = shift (@cond_vals);
5432         shift (@cond_vals);
5433         if (&conditional_true_when ($vcond, $cond)
5434             || &conditional_true_when ($cond, $vcond))
5435         {
5436             &am_line_error ($var_name,
5437                             "$var_name multiply defined in condition");
5438         }
5439     }
5442 # See if a variable exists.  The first argument is the variable name,
5443 # and the optional second argument is the condition which we should
5444 # check.  If no condition is given, we currently return true if the
5445 # variable is defined under any condition.
5446 sub variable_defined
5448     local ($var, $cond) = @_;
5449     if (defined $targets{$var})
5450     {
5451         &am_line_error ($var, "\`$var' is target; expected variable");
5452         return 0;
5453     }
5454     elsif (defined $contents{$var})
5455     {
5456         if ($cond && $conditional{$var})
5457         {
5458             # We have been asked to check for a particular condition,
5459             # and the variable is defined conditionally.  We need to
5460             # look through the conditions under which the variable is
5461             # defined, and see if any of them match the conditional we
5462             # have been asked to check.
5463             local (@cond_vars) = split (' ', $conditional{$var});
5464             while (@cond_vars)
5465             {
5466                 if (&conditional_same ($cond, shift (@cond_vars)))
5467                 {
5468                     # Even a conditional examination is good enough
5469                     # for us.  FIXME: really should maintain examined
5470                     # status on a per-condition basis.
5471                     $content_seen{$var} = 1;
5472                     return 1;
5473                 }
5474                 shift (@cond_vars);
5475             }
5477             # The variable is not defined for the given condition.
5478             return 0;
5479         }
5481         $content_seen{$var} = 1;
5482         return 1;
5483     }
5484     return 0;
5487 # Mark a variable as examined.
5488 sub examine_variable
5490     local ($var) = @_;
5491     &variable_defined ($var);
5494 # Quote a value in order to put it in $conditional.  We need to quote
5495 # spaces, and we need to handle null strings, so that we can later
5496 # retrieve values by splitting on space.
5497 sub quote_cond_val
5499     local ($val) = @_;
5500     $val =~ tr/ \t\n/\001\003\004/;
5501     $val = "\002" if $val eq '';
5502     return $val;
5505 # Unquote a value in $conditional.
5506 sub unquote_cond_val
5508     local ($val) = @_;
5509     $val =~ tr/\001\003\004/ \t\n/;
5510     $val =~ s/\002//g;
5511     return $val;
5514 # Return the set of conditions for which a variable is defined.
5516 # If the variable is not defined conditionally, and is not defined in
5517 # terms of any variables which are defined conditionally, then this
5518 # returns the empty list.
5520 # If the variable is defined conditionally, but is not defined in
5521 # terms of any variables which are defined conditionally, then this
5522 # returns the list of conditions for which the variable is defined.
5524 # If the variable is defined in terms of any variables which are
5525 # defined conditionally, then this returns a full set of permutations
5526 # of the subvariable conditions.  For example, if the variable is
5527 # defined in terms of a variable which is defined for @COND_TRUE@,
5528 # then this returns both @COND_TRUE@ and @COND_FALSE@.  This is
5529 # because we will need to define the variable under both conditions.
5531 sub variable_conditions
5533     local ($var) = @_;
5534     local (%uniqify);
5535     local (@uniq_list);
5536     local ($cond);
5538     %vars_scanned = ();
5539     foreach $cond (&variable_conditions_sub ($var, '', ()))
5540     {
5541         $uniqify{$cond} = 1;
5542     }
5544     @uniq_list = sort keys %uniqify;
5545     # Note we cannot just do `return sort keys %uniqify', because this
5546     # function is sometimes used in a scalar context.
5547     return @uniq_list;
5550 # A subroutine of variable_conditions.  We only return conditions
5551 # which are true for all the conditions in @PARENT_CONDS.
5552 sub variable_conditions_sub
5554     local ($var, $parent, @parent_conds) = @_;
5555     local (@new_conds) = ();
5557     if (defined $vars_scanned{$var})
5558     {
5559         &am_line_error ($parent, "variable \`$var' recursively defined");
5560         return ();
5561     }
5562     $vars_scanned{$var} = 1;
5564     if (! $conditional{$var})
5565     {
5566         foreach (split (' ', $contents{$var}))
5567         {
5568             # If a comment seen, just leave.
5569             last if /^#/;
5571             # Handle variable substitutions.
5572             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5573             {
5574                 push (@new_conds,
5575                       &variable_conditions_sub ($1, $var, @parent_conds));
5576             }
5577         }
5579         # Now we want to return all permutations of the subvariable
5580         # conditions.
5581         local (%allconds, $item);
5582         foreach $item (@new_conds)
5583         {
5584             foreach (split ('@', $item))
5585             {
5586                 next if ! $_;
5587                 s/_(TRUE|FALSE)$//;
5588                 $allconds{$_ . '_TRUE'} = 1;
5589             }
5590         }
5592         # Unset our entry in vars_scanned.  We only care about recursive
5593         # definitions.
5594         delete $vars_scanned{$var};
5596         return &variable_conditions_permutations (sort keys %allconds);
5597     }
5599     local (@this_conds) = ();
5600     local (@condvals) = split (' ', $conditional{$var});
5601     while (@condvals)
5602     {
5603         local ($cond) = shift (@condvals);
5604         local ($val) = &unquote_cond_val (shift (@condvals));
5606         if (@parent_conds)
5607         {
5608             local ($ok) = 1;
5609             local ($parent_cond);
5610             foreach $parent_cond (@parent_conds)
5611             {
5612                 if (! &conditional_true_when ($parent_cond, $cond))
5613                 {
5614                     $ok = 0;
5615                     last;
5616                 }
5617             }
5619             next if ! $ok;
5620         }
5622         push (@this_conds, $cond);
5624         push (@parent_conds, $cond);
5625         local (@subvar_conds) = ();
5626         foreach (split (' ', $val))
5627         {
5628             # If a comment seen, just leave.
5629             last if /^#/;
5631             # Handle variable substitutions.
5632             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5633             {
5634                 push (@subvar_conds,
5635                       &variable_conditions_sub ($1, $var, @parent_conds));
5636             }
5637         }
5638         pop (@parent_conds);
5640         # If there are no conditional subvariables, then we want to
5641         # return this condition.  Otherwise, we want to return the
5642         # permutations of the subvariables.
5643         if (! @subvar_conds)
5644         {
5645             push (@new_conds, $cond);
5646         }
5647         else
5648         {
5649             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
5650         }
5651     }
5653     # Unset our entry in vars_scanned.  We only care about recursive
5654     # definitions.
5655     delete $vars_scanned{$var};
5657     return @new_conds
5658         if ! $parent;
5660     # If we are being called on behalf of another variable, we need to
5661     # return all possible permutations of the conditions.  We have
5662     # already handled everything in @this_conds along with their
5663     # subvariables.  We now need to add any permutations that are not
5664     # in @this_conds.
5665     local ($this_cond);
5666     foreach $this_cond (@this_conds)
5667     {
5668         local (@perms) =
5669             &variable_conditions_permutations (split('@', $this_cond));
5670         local ($perm);
5671         foreach $perm (@perms)
5672         {
5673             local ($scan);
5674             local ($ok) = 1;
5675             foreach $scan (@this_conds)
5676             {
5677                 if (&conditional_true_when ($perm, $scan)
5678                     || &conditional_true_when ($scan, $perm))
5679                 {
5680                     $ok = 0;
5681                     last;
5682                 }
5683             }
5684             next if ! $ok;
5686             if (@parent_conds)
5687             {
5688                 local ($ok) = 1;
5689                 local ($parent_cond);
5690                 foreach $parent_cond (@parent_conds)
5691                 {
5692                     if (! &conditional_true_when ($parent_cond, $perm))
5693                     {
5694                         $ok = 0;
5695                         last;
5696                     }
5697                 }
5699                 next if ! $ok;
5700             }
5702             # This permutation was not already handled, and is valid
5703             # for the parents.
5704             push (@new_conds, $perm);
5705         }
5706     }
5708     return @new_conds;
5711 # Subroutine for variable_conditions_sort
5712 sub variable_conditions_cmp
5714     local ($as) = $a;
5715     $as =~ s/[^@]//g;
5716     local ($bs) = $b;
5717     $bs =~ s/[^@]//g;
5718     return (length ($as) <=> length ($bs)
5719             || $a cmp $b);
5722 # Sort a list of conditionals so that only the exclusive ones are
5723 # retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
5724 # @COND1_TRUE@ are in the list, discard the latter.
5725 sub variable_conditions_reduce
5727     local (@conds) = @_;
5728     local (@ret) = ();
5729     local ($cond);
5730     foreach $cond (sort variable_conditions_cmp @conds)
5731     {
5732         local ($ok) = 1;
5733         local ($scan);
5734         foreach $scan (@ret)
5735         {
5736             if (&conditional_true_when ($cond, $scan))
5737             {
5738                 $ok = 0;
5739                 last;
5740             }
5741         }
5742         next if ! $ok;
5743         push (@ret, $cond);
5744     }
5746     return @ret;
5749 # Return a list of permutations of a conditional string.
5750 sub variable_conditions_permutations
5752     local (@comps) = @_;
5753     return ()
5754         if ! @comps;
5755     local ($comp) = shift (@comps);
5756     return &variable_conditions_permutations (@comps)
5757         if $comp eq '';
5758     local ($neg) = $comp;
5759     $neg =~ s/TRUE$/TRUEO/;
5760     $neg =~ s/FALSE$/TRUE/;
5761     $neg =~ s/TRUEO$/FALSE/;
5762     local (@ret);
5763     local ($sub);
5764     foreach $sub (&variable_conditions_permutations (@comps))
5765     {
5766         push (@ret, '@' . $comp . '@' . $sub);
5767         push (@ret, '@' . $neg . '@' . $sub);
5768     }
5769     if (! @ret)
5770     {
5771         push (@ret, '@' . $comp . '@');
5772         push (@ret, '@' . $neg . '@');
5773     }
5774     return @ret;
5777 # Warn if a variable is conditionally defined.  This is called if we
5778 # are using the value of a variable.
5779 sub variable_conditionally_defined
5781     local ($var, $parent) = @_;
5782     if ($conditional{$var})
5783     {
5784         if ($parent)
5785         {
5786             &am_line_error ($parent,
5787                             "warning: automake does not support conditional definition of $var in $parent");
5788         }
5789         else
5790         {
5791             &am_line_error ($parent,
5792                             "warning: automake does not support $var being defined conditionally")
5793         }
5794     }
5797 # Get the value of a variable.  This just returns $contents, but warns
5798 # if the variable is conditionally defined.
5799 sub variable_value
5801     local ($var) = @_;
5802     &variable_conditionally_defined ($var);
5803     return $contents{$var};
5806 # Convert a variable value to a list, split as whitespace.  This will
5807 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5808 # substitutions.  If COND is 'all', then all values under all
5809 # conditions should be returned; if COND is a particular condition
5810 # (all conditions are surrounded by @...@) then only the value for
5811 # that condition should be returned; otherwise, warn if VAR is
5812 # conditionally defined.  SCANNED is a global hash listing whose keys
5813 # are all the variables already scanned; it is an error to rescan a
5814 # variable.
5815 sub value_to_list
5817     local ($var, $val, $cond) = @_;
5818     local (@result);
5820     # Strip backslashes
5821     $val =~ s/\\(\n|$)/ /g;
5823     foreach (split (' ', $val))
5824     {
5825         # If a comment seen, just leave.
5826         last if /^#/;
5828         # Handle variable substitutions.
5829         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
5830         {
5831             local ($varname) = $1;
5833             # If the user uses a losing variable name, just ignore it.
5834             # This isn't ideal, but people have requested it.
5835             next if ($varname =~ /\@.*\@/);
5837             local ($from, $to);
5838             local (@temp_list);
5839             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
5840             {
5841                 $varname = $1;
5842                 $to = $3;
5843                 ($from = $2) =~ s/(\W)/\\$1/g;
5844             }
5846             # Find the value.
5847             @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
5849             # Now rewrite the value if appropriate.
5850             if ($from)
5851             {
5852                 grep (s/$from$/$to/, @temp_list);
5853             }
5855             push (@result, @temp_list);
5856         }
5857         else
5858         {
5859             push (@result, $_);
5860         }
5861     }
5863     return @result;
5866 # Return contents of variable as list, split as whitespace.  This will
5867 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5868 # substitutions.  If COND is 'all', then all values under all
5869 # conditions should be returned; if COND is a particular condition
5870 # (all conditions are surrounded by @...@) then only the value for
5871 # that condition should be returned; otherwise, warn if VAR is
5872 # conditionally defined.  If PARENT is specified, it is the name of
5873 # the including variable; this is only used for error reports.
5874 sub variable_value_as_list_worker
5876     local ($var, $cond, $parent) = @_;
5877     local (@result);
5879     if (defined $targets{$var})
5880     {
5881         &am_line_error ($var, "\`$var' is target; expected variable");
5882     }
5883     elsif (! defined $contents{$var})
5884     {
5885         &am_line_error ($parent, "variable \`$var' not defined");
5886     }
5887     elsif (defined $vars_scanned{$var})
5888     {
5889         # `vars_scanned' is a global we use to keep track of which
5890         # variables we've already examined.
5891         &am_line_error ($parent, "variable \`$var' recursively defined");
5892     }
5893     elsif ($cond eq 'all' && $conditional{$var})
5894     {
5895         $vars_scanned{$var} = 1;
5896         local (@condvals) = split (' ', $conditional{$var});
5897         while (@condvals)
5898         {
5899             shift (@condvals);
5900             local ($val) = &unquote_cond_val (shift (@condvals));
5901             push (@result, &value_to_list ($var, $val, $cond));
5902         }
5903     }
5904     elsif ($cond && $conditional{$var})
5905     {
5906         $vars_scanned{$var} = 1;
5907         local (@condvals) = split (' ', $conditional{$var});
5908         local ($onceflag);
5909         while (@condvals)
5910         {
5911             local ($vcond) = shift (@condvals);
5912             local ($val) = &unquote_cond_val (shift (@condvals));
5913             if (&conditional_true_when ($vcond, $cond))
5914             {
5915                 # Warn if we have an ambiguity.  It's hard to know how
5916                 # to handle this case correctly.
5917                 &variable_conditionally_defined ($var, $parent)
5918                     if $onceflag;
5919                 $onceflag = 1;
5920                 push (@result, &value_to_list ($var, $val, $cond));
5921             }
5922         }
5923     }
5924     else
5925     {
5926         $vars_scanned{$var} = 1;
5927         &variable_conditionally_defined ($var, $parent);
5928         $content_seen{$var} = 1;
5929         push (@result, &value_to_list ($var, $contents{$var}, $cond));
5930     }
5932     # Unset our entry in vars_scanned.  We only care about recursive
5933     # definitions.
5934     delete $vars_scanned{$var};
5936     return @result;
5939 # This is just a wrapper for variable_value_as_list_worker that
5940 # initializes the global hash `vars_scanned'.  This hash is used to
5941 # avoid infinite recursion.
5942 sub variable_value_as_list
5944     local ($var, $cond, $parent) = @_;
5945     %vars_scanned = ();
5946     return &variable_value_as_list_worker ($var, $cond, $parent);
5949 # Define a new variable, but only if not already defined.
5950 sub define_variable
5952     local ($var, $value) = @_;
5954     if (! defined $contents{$var})
5955     {
5956         $output_vars .= $var . ' = ' . $value . "\n";
5957         $contents{$var} = $value;
5958         $content_seen{$var} = 1;
5959     }
5960     elsif ($var_was_plus_eq{$var})
5961     {
5962         &am_line_error ($var, "internally generated variable \`$var' was set with \`+='");
5963     }
5966 # Like define_variable, but the value is a list, and the variable may
5967 # be defined conditionally.  The second argument is the conditional
5968 # under which the value should be defined; this should be the empty
5969 # string to define the variable unconditionally.  The third argument
5970 # is a list holding the values to use for the variable.  The value is
5971 # pretty printed in the output file.
5972 sub define_pretty_variable
5974     local ($var, $cond, @value) = @_;
5975     if (! defined $contents{$var}
5976         || ($cond && ! &variable_defined ($var, $cond)))
5977     {
5978         $contents{$var} = join (' ', @value);
5979         if ($cond)
5980         {
5981             if ($conditional{$var})
5982             {
5983                 $conditional{$var} .= ' ';
5984             }
5985             else
5986             {
5987                 $conditional{$var} = '';
5988             }
5989             $conditional{$var} .= ($cond
5990                                    . ' '
5991                                    . &quote_cond_val ($contents{$var}));
5992         }
5993         &pretty_print ($cond . $var . ' = ', $cond, @value);
5994         $content_seen{$var} = 1;
5995     }
5998 # Like define_variable, but define a variable to be the configure
5999 # substitution by the same name.
6000 sub define_configure_variable
6002     local ($var) = @_;
6003     local ($value) = '@' . $var . '@';
6004     &define_variable ($var, $value);
6007 # Define a compiler variable.  We also handle defining the `LT'
6008 # version of the command when using libtool.
6009 sub define_compiler_variable
6011     local ($var, $ltcompile, $value) = @_;
6012     local ($name) = $var;
6013     &define_variable ($name, $value);
6014     &define_variable ('LT' . $name, $ltcompile . $value)
6015         if $seen_libtool;
6018 # Define a variable that represents a program to run.  If in Cygnus
6019 # mode, the program is searched for in the build (or source) tree.
6020 # Otherwise no searching is done at all.  Arguments are:
6021 # * VAR      Name of variable to define
6022 # * WHATDIR  Either `src' or `build', depending on where program should
6023 #            be found.  (runtest is in srcdir!)
6024 # * SUBDIR   Subdir of top-level dir
6025 # * PROGRAM  Name of program
6026 # * OVERRIDE If specified, the name of the program to use when not in
6027 #            Cygnus mode.  Defaults to PROGRAM.
6028 sub define_program_variable
6030     local ($var, $whatdir, $subdir, $program, $override) = @_;
6032     if (! $override)
6033     {
6034         $override = $program;
6035     }
6037     if ($cygnus_mode)
6038     {
6039         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
6040                          . $subdir . '/' . $program);
6041         &define_variable ($var, ('`if test -f ' . $full
6042                                  . '; then echo ' . $full . '; else echo '
6043                                  . $program . '; fi`'));
6044     }
6045     else
6046     {
6047         &define_variable ($var, $override);
6048     }
6052 ################################################################
6054 # Read Makefile.am and set up %contents.  Simultaneously copy lines
6055 # from Makefile.am into $output_trailer or $output_vars as
6056 # appropriate.  NOTE we put rules in the trailer section.  We want
6057 # user rules to come after our generated stuff.
6058 sub read_am_file
6060     local ($amfile) = @_;
6061     local (*AM_FILE);
6063     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
6064     print "automake: reading $amfile\n" if $verbose;
6066     local ($saw_bk) = 0;
6067     local ($was_rule) = 0;
6068     local ($spacing) = '';
6069     local ($comment) = '';
6070     local ($last_var_name) = '';
6071     local ($blank) = 0;
6073     while (<AM_FILE>)
6074     {
6075         if (/$IGNORE_PATTERN/o)
6076         {
6077             # Merely delete comments beginning with two hashes.
6078         }
6079         elsif (/$WHITE_PATTERN/o)
6080         {
6081             # Stick a single white line before the incoming macro or rule.
6082             $spacing = "\n";
6083             $blank = 1;
6084         }
6085         elsif (/$COMMENT_PATTERN/o)
6086         {
6087             # Stick comments before the incoming macro or rule.  Make
6088             # sure a blank line preceeds first block of comments.
6089             $spacing = "\n" unless $blank;
6090             $blank = 1;
6091             $comment .= $spacing . $_;
6092             $spacing = '';
6093         }
6094         else
6095         {
6096             last;
6097         }
6098     }
6100     $output_vars .= $comment . "\n";
6101     $comment = '';
6102     $spacing = "\n";
6104     local ($is_ok_macro);
6105     while ($_)
6106     {
6107         $_ .= "\n"
6108             unless substr ($_, -1, 1) eq "\n";
6110         # Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
6111         # used by users.  @MAINT@ is an anachronism now.
6112         $_ =~ s/\@MAINT\@//g
6113             unless $seen_maint_mode;
6115         if (/$IGNORE_PATTERN/o)
6116         {
6117             # Merely delete comments beginning with two hashes.
6118         }
6119         elsif (/$WHITE_PATTERN/o)
6120         {
6121             # Stick a single white line before the incoming macro or rule.
6122             $spacing = "\n";
6123             &am_line_error ($., "blank line following trailing backslash")
6124                 if $saw_bk;
6125         }
6126         elsif (/$COMMENT_PATTERN/o)
6127         {
6128             # Stick comments before the incoming macro or rule.
6129             $comment .= $spacing . $_;
6130             $spacing = '';
6131             &am_line_error ($., "comment following trailing backslash")
6132                 if $saw_bk;
6133         }
6134         elsif ($saw_bk)
6135         {
6136             if ($was_rule)
6137             {
6138                 $output_trailer .= join ('', @conditional_stack) . $_;
6139                 $saw_bk = /\\$/;
6140             }
6141             else
6142             {
6143                 $saw_bk = /\\$/;
6144                 $contents{$last_var_name} .= ' '
6145                     unless $contents{$last_var_name} =~ /\s$/;
6146                 $contents{$last_var_name} .= $_;
6147                 if (@conditional_stack)
6148                 {
6149                     $conditional{$last_var_name} .= &quote_cond_val ($_);
6150                 }
6151             }
6152         }
6153         elsif (/$IF_PATTERN/o)
6154         {
6155             &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
6156                 if (! $configure_cond{$1});
6157             push (@conditional_stack, "\@" . $1 . "_TRUE\@");
6158         }
6159         elsif (/$ELSE_PATTERN/o)
6160         {
6161             if (! @conditional_stack)
6162             {
6163                 &am_line_error ($., "else without if");
6164             }
6165             elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
6166             {
6167                 &am_line_error ($., "else after else");
6168             }
6169             else
6170             {
6171                 $conditional_stack[$#conditional_stack]
6172                     =~ s/_TRUE\@$/_FALSE\@/;
6173             }
6174         }
6175         elsif (/$ENDIF_PATTERN/o)
6176         {
6177             if (! @conditional_stack)
6178             {
6179                 &am_line_error ($., "endif without if");
6180             }
6181             else
6182             {
6183                 pop @conditional_stack;
6184             }
6185         }
6186         elsif (/$RULE_PATTERN/o)
6187         {
6188             # Found a rule.
6189             $was_rule = 1;
6190             if (defined $contents{$1}
6191                 && (@conditional_stack
6192                     ? ! defined $conditional{$1}
6193                     : defined $conditional{$1}))
6194             {
6195                 &am_line_error ($1,
6196                                 "$1 defined both conditionally and unconditionally");
6197             }
6198             # Value here doesn't matter; for targets we only note
6199             # existence.
6200             $contents{$1} = 1;
6201             $targets{$1} = 1;
6202             local ($cond_string) = join ('', @conditional_stack);
6203             if (@conditional_stack)
6204             {
6205                 if ($conditional{$1})
6206                 {
6207                     &check_ambiguous_conditional ($1, $cond_string);
6208                     $conditional{$1} .= ' ';
6209                 }
6210                 else
6211                 {
6212                     $conditional{$1} = '';
6213                 }
6214                 $conditional{$1} .= $cond_string . ' 1';
6215             }
6216             $content_lines{$1} = $.;
6217             $output_trailer .= $comment . $spacing . $cond_string . $_;
6218             $comment = $spacing = '';
6219             $saw_bk = /\\$/;
6221             # Check the rule for being a suffix rule. If so, store in
6222             # a hash.
6224             local ($source_suffix);
6225             local ($object_suffix);
6227             if (($source_suffix, $object_suffix) = ($1 =~ $SUFFIX_RULE_PATTERN)) 
6228             {
6229               $suffix_rules{$source_suffix} = $object_suffix;
6230               print "Sources ending in .$source_suffix become .$object_suffix\n" if $verbose;
6231               $source_suffix_pattern = "(" . join('|', keys %suffix_rules) . ")";
6232             }
6234             # FIXME: make sure both suffixes are in SUFFIXES? Or set
6235             # SUFFIXES from suffix_rules?
6236         }
6237         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
6238                || /$BOGUS_MACRO_PATTERN/o)
6239         {
6240             # Found a macro definition.
6241             $was_rule = 0;
6242             $last_var_name = $1;
6243             if (defined $contents{$1}
6244                 && (@conditional_stack
6245                     ? ! defined $conditional{$1}
6246                     : defined $conditional{$1}))
6247             {
6248                 &am_line_error ($1,
6249                                 "$1 defined both conditionally and unconditionally");
6250             }
6251             local ($value);
6252             if ($3 ne '' && substr ($3, -1) eq "\\")
6253             {
6254                 # We preserve the `\' because otherwise the long lines
6255                 # that are generated will be truncated by broken
6256                 # `sed's.
6257                 $value = $3 . "\n";
6258             }
6259             else
6260             {
6261                 $value = $3;
6262             }
6263             local ($type) = $2;
6265             if (! defined $contents{$last_var_name})
6266             {
6267                 # The first assignment to a macro sets the line
6268                 # number.  Ideally I suppose we would associate line
6269                 # numbers with random bits of text.
6270                 $content_lines{$last_var_name} = $.;
6272                 # If first assignment, set `+=' indicator.
6273                 $var_was_plus_eq{$last_var_name} =
6274                     ($type eq '+'
6275                      && ! defined $am_var_defs{$last_var_name});
6276             }
6278             if ($type eq '+')
6279             {
6280                 if (! defined $contents{$last_var_name}
6281                     && defined $am_var_defs{$last_var_name})
6282                 {
6283                     $contents{$last_var_name} = $am_var_defs{$last_var_name};
6284                 }
6285                 $contents{$last_var_name} .= ' ' . $value;
6286             }
6287             else
6288             {
6289                 $contents{$last_var_name} = $value;
6290             }
6291             local ($cond_string) = join ('', @conditional_stack);
6292             if (@conditional_stack)
6293             {
6294                 local ($found) = 0;
6295                 local ($val);
6296                 if ($conditional{$last_var_name})
6297                 {
6298                     if ($type eq '+')
6299                     {
6300                         # If we're adding to the conditional, and it
6301                         # exists, then we might want to simply replace
6302                         # the old value with the new one.
6303                         local (@new_vals, @cond_vals);
6304                         @cond_vals = split (' ', $conditional{$last_var_name});
6305                         while (@cond_vals)
6306                         {
6307                             local ($vcond) = shift (@cond_vals);
6308                             push (@new_vals, $vcond);
6309                             if (&conditional_same ($vcond, $cond_string))
6310                             {
6311                                 $found = 1;
6312                                 $val = (&unquote_cond_val (shift (@cond_vals))
6313                                         . ' ' . $value);
6314                                 push (@new_vals, &quote_cond_val ($val));
6315                             }
6316                             else
6317                             {
6318                                 push (@new_vals, shift (@cond_vals));
6319                             }
6320                         }
6321                         if ($found)
6322                         {
6323                             $conditional{$last_var_name}
6324                                 = join (' ', @new_vals);
6325                         }
6326                     }
6328                     if (! $found)
6329                     {
6330                         &check_ambiguous_conditional ($last_var_name,
6331                                                       $cond_string);
6332                         $conditional{$last_var_name} .= ' ';
6333                         $val = $value;
6334                     }
6335                 }
6336                 else
6337                 {
6338                     $conditional{$last_var_name} = '';
6339                     $val = $contents{$last_var_name};
6340                 }
6341                 if (! $found)
6342                 {
6343                     $conditional{$last_var_name} .= ($cond_string
6344                                                      . ' '
6345                                                      . &quote_cond_val ($val));
6346                 }
6347             }
6349             # FIXME: this doesn't always work correctly; it will group
6350             # all comments for a given variable, no matter where
6351             # defined.
6352             $am_vars{$last_var_name} = $comment . $spacing;
6353             $def_type{$last_var_name} = ($type eq ':') ? ':' : '';
6354             push (@var_list, $last_var_name);
6355             $comment = $spacing = '';
6356             $saw_bk = /\\$/;
6358             # Error if bogus.
6359             &am_line_error ($., "bad macro name \`$last_var_name'")
6360                 if ! $is_ok_macro;
6361         }
6362         elsif (/$INCLUDE_PATTERN/o)
6363         {
6364             local ($path) = $1;
6366             if ($path =~ s/^\$\(top_srcdir\)\///)
6367             {
6368                 push (@include_stack, "\$\(top_srcdir\)/$path");
6369             }
6370             else
6371             {
6372                 $path =~ s/\$\(srcdir\)\///;
6373                 push (@include_stack, "\$\(srcdir\)/$path");
6374                 $path = $relative_dir . "/" . $path;
6375             }
6376             &read_am_file ($path);
6377         }
6378         else
6379         {
6380             # This isn't an error; it is probably a continued rule.
6381             # In fact, this is what we assume.
6382             $was_rule = 1;
6383             $output_trailer .= ($comment . $spacing
6384                                 . join ('', @conditional_stack) . $_);
6385             $comment = $spacing = '';
6386             $saw_bk = /\\$/;
6387         }
6389         $_ = <AM_FILE>;
6390     }
6392     $output_trailer .= $comment;
6394     &am_error ("unterminated conditionals: " . join (' ', @conditional_stack))
6395         if (@conditional_stack);
6398 # A helper for read_main_am_file which initializes configure variables
6399 # and variables from header-vars.am.  This is a subr so we can call it
6400 # twice.
6401 sub define_standard_variables
6403     # Compute relative location of the top object directory.
6404     local (@topdir) = ();
6405     foreach (split (/\//, $relative_dir))
6406     {
6407         next if $_ eq '.' || $_ eq '';
6408         if ($_ eq '..')
6409         {
6410             pop @topdir;
6411         }
6412         else
6413         {
6414             push (@topdir, '..');
6415         }
6416     }
6417     @topdir = ('.') if ! @topdir;
6419     $top_builddir = join ('/', @topdir);
6420     local ($build_rx);
6421     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
6422     $output_vars .= &file_contents_with_transform
6423                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
6424                          'header-vars');
6426     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
6427     # this should use generic %configure_vars method.
6428     if ($seen_canonical)
6429     {
6430         local ($curs, %vars);
6431         $vars{'host_alias'} = 'host_alias';
6432         $vars{'host_triplet'} = 'host';
6433         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
6434         {
6435             $vars{'build_alias'} = 'build_alias';
6436             $vars{'build_triplet'} = 'build';
6437             $vars{'target_alias'} = 'target_alias';
6438             $vars{'target_triplet'} = 'target';
6439         }
6440         foreach $curs (sort keys %vars)
6441         {
6442             $output_vars .= "$curs = \@$vars{$curs}\@\n";
6443             $contents{$curs} = "\@$vars{$curs}\@";
6444         }
6445     }
6447     local ($curs);
6448     foreach $curs (sort keys %configure_vars)
6449     {
6450         &define_configure_variable ($curs);
6451     }
6454 # Read main am file.
6455 sub read_main_am_file
6457     local ($amfile) = @_;
6459     # The keys here are variables we want to dump at the end of this
6460     # function.  The values are corresponding comments.
6461     local (%am_vars) = ();
6462     local (@var_list) = ();
6463     local (%def_type) = ();
6465     # We want to predefine as many variables as possible.  This lets
6466     # the user set them with `+=' in Makefile.am.  However, we don't
6467     # want these initial definitions to end up in the output quite
6468     # yet.  So we adopt a hack: read the `.am' file twice, throwing
6469     # away the output the first time.  We also squirrel away a list of
6470     # all the variables defined by the .am file so that we know which
6471     # ones to remove from the content list.
6473     # First pass.
6474     &define_standard_variables;
6475     local (%saved_contents) = %contents;
6477     # Read user file, but discard text of variable assignments we just
6478     # made.
6479     $output_vars = '';
6480     &read_am_file ($amfile);
6482     # Now dump the variables that were defined.  We do it in the same
6483     # order in which they were defined (skipping duplicates).
6484     local (%done);
6485     foreach $curs (@var_list)
6486     {
6487         next if $done{$curs};
6488         $done{$curs} = 1;
6490         $output_vars .= $am_vars{$curs};
6491         if ($conditional{$curs})
6492         {
6493             local (@cond_vals) = split (' ', $conditional{$curs});
6494             while (@cond_vals)
6495             {
6496                 local ($vcond) = shift (@cond_vals);
6497                 local ($val) = &unquote_cond_val (shift (@cond_vals));
6498                 $output_vars .= ($vcond . $curs . ' '
6499                                  . $def_type{$curs} . "= \\\n");
6500                 local ($line);
6501                 foreach $line (split ("\n", $val))
6502                 {
6503                     $output_vars .= $vcond . $line . "\n";
6504                 }
6505             }
6506         }
6507         else
6508         {
6509             $output_vars .= ($curs . ' ' . $def_type{$curs} . '= '
6510                              . $contents{$curs} . "\n");
6511         }
6512     }
6514     # Generate copyright header for generated Makefile.in.
6515     local ($ov) = $output_vars;
6516     $output_vars = ("# $in_file_name generated automatically by automake "
6517                    . $VERSION . " from $am_file_name\n");
6518     $output_vars .= $gen_copyright;
6520     # Now go through and delete all the variables that the user did
6521     # not change.
6522     local ($var);
6523     foreach $var (keys %saved_contents)
6524     {
6525         if ($contents{$var} eq $saved_contents{$var})
6526         {
6527             delete $contents{$var};
6528         }
6529     }
6531     # Re-read the standard variables, and this time keep their
6532     # contributions to the output.  Then add the user's output to the
6533     # end.
6534     &define_standard_variables;
6535     $output_vars .= $ov;
6539 ################################################################
6541 sub initialize_global_constants
6543     # Values for AC_CANONICAL_*
6544     $AC_CANONICAL_HOST = 1;
6545     $AC_CANONICAL_SYSTEM = 2;
6547     # Associative array of standard directory names.  Entry is TRUE if
6548     # corresponding directory should be installed during
6549     # 'install-exec' phase.
6550     %exec_dir_p =
6551         ('bin', 1,
6552          'sbin', 1,
6553          'libexec', 1,
6554          'data', 0,
6555          'sysconf', 1,
6556          'localstate', 1,
6557          'lib', 1,
6558          'info', 0,
6559          'man', 0,
6560          'include', 0,
6561          'oldinclude', 0,
6562          'pkgdata', 0,
6563          'pkglib', 1,
6564          'pkginclude', 0
6565          );
6567     # Commonly found files we look for and automatically include in
6568     # DISTFILES.
6569     @common_files =
6570         (
6571          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
6572          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
6573          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
6574          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
6575          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
6576          'ylwrap', 'acinclude.m4', @libtoolize_files,
6577          'missing', 'compile'
6578          );
6580     # Commonly used files we auto-include, but only sometimes.
6581     @common_sometimes =
6582         (
6583          "aclocal.m4", "acconfig.h", "config.h.top",
6584          "config.h.bot", "stamp-h.in", 'stamp-vti'
6585          );
6587     $USAGE = "\
6588   -a, --add-missing     add missing standard files to package
6589   --amdir=DIR           directory storing config files
6590   --build-dir=DIR       directory where build being done (for dependencies)
6591   -c, --copy            with -a, copy missing files (default is symlink)
6592   --cygnus              assume program is part of Cygnus-style tree
6593   --foreign             set strictness to foreign
6594   --gnits               set strictness to gnits
6595   --gnu                 set strictness to gnu
6596   --help                print this help, then exit
6597   -i, --include-deps    include generated dependencies in Makefile.in
6598   --no-force            only update Makefile.in's that are out of date
6599   -o DIR, --output-dir=DIR
6600                         put generated Makefile.in's into DIR
6601   --srcdir-name=DIR     name used for srcdir (for dependencies)
6602   -v, --verbose         verbosely list files processed
6603   --version             print version number, then exit\n";
6605     # Copyright on generated Makefile.ins.
6606     $gen_copyright = "\
6607 # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
6608 # This Makefile.in is free software; the Free Software Foundation
6609 # gives unlimited permission to copy and/or distribute it,
6610 # with or without modifications, as long as this notice is preserved.
6612 # This program is distributed in the hope that it will be useful,
6613 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
6614 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6615 # PARTICULAR PURPOSE.
6618     # Ignore return result from chmod, because it might give an error
6619     # if we chmod a symlink.
6620     $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
6621     $dist{'dist-bzip2'} = ("\t"
6622                            . '$(AMTAR) ch$(AMTARFLAGS)f - $(distdir) | bzip --best -c > $(distdir).bz2'
6623                            . "\n");
6624     $dist{'dist-tarZ'} = ("\t"
6625                      . '$(AMTAR) ch$(AMTARFLAGS)f - $(distdir) | compress -c > $(distdir).tar.Z'
6626                      . "\n");
6627     $dist{'dist-shar'} = ("\t"
6628                      . 'shar $(distdir) | gzip > $(distdir).shar.gz'
6629                      . "\n");
6630     $dist{'dist-zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
6631     $dist{'dist'} = ("\t"
6632                      .  '$(AMTAR) ch$(AMTARFLAGS)f - $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).tar.gz'
6633                      . "\n");
6634     $dist_trailer = "\t" . '-rm -rf $(distdir)' . "\n";
6637 # (Re)-Initialize per-Makefile.am variables.
6638 sub initialize_per_input
6640     # These two variables are used when generating each Makefile.in.
6641     # They hold the Makefile.in until it is ready to be printed.
6642     $output_rules = '';
6643     $output_vars = '';
6644     $output_trailer = '';
6645     $output_all = '';
6646     $output_header = '';
6648     # Suffixes found during a run.
6649     @suffixes = ();
6651     # This holds the contents of a Makefile.am, as parsed by
6652     # read_am_file.
6653     %contents = ();
6655     # This holds the names which are targets.  These also appear in
6656     # %contents.
6657     %targets = ();
6659     # This maps a variable name onto a flag.  The flag is true iff the
6660     # variable was first defined with `+='.
6661     %var_was_plus_eq = ();
6663     # This holds definitions of all variables defined in .am files.
6664     # This is used during startup to determine which variables can be
6665     # assigned with `+='.
6666     %am_var_defs = ();
6668     # For a variable or target which is defined conditionally, this
6669     # holds an array of the conditional values.  The array is composed
6670     # of pairs of condition strings (the variables which configure
6671     # will substitute) and values (the value of a target is
6672     # meaningless).  For an unconditional variable, this is empty.
6673     %conditional = ();
6675     # This holds the line numbers at which various elements of
6676     # %contents are defined.
6677     %content_lines = ();
6679     # This holds a 1 if a particular variable was examined.
6680     %content_seen = ();
6682     # This is the conditional stack.
6683     @conditional_stack = ();
6685     # This holds the set of included files.
6686     @include_stack = ();
6688     # This holds the "relative directory" of the current Makefile.in.
6689     # Eg for src/Makefile.in, this is "src".
6690     $relative_dir = '';
6692     # This holds a list of files that are included in the
6693     # distribution.
6694     %dist_common = ();
6696     # List of dependencies for the obvious targets.
6697     @install_data = ();
6698     @install_exec = ();
6699     @uninstall = ();
6700     @installdirs = ();
6702     @info = ();
6703     @dvi = ();
6704     @all = ();
6705     @check = ();
6706     @check_tests = ();
6707     @installcheck = ();
6708     @clean = ();
6710     @phony = ();
6712     # A list of files deleted by `maintainer-clean'.
6713     @maintainer_clean_files = ();
6715     # These are pretty obvious, too.  They are used to define the
6716     # SOURCES and OBJECTS variables.
6717     @sources = ();
6718     @objects = ();
6719     # Sources which go in the distribution.
6720     @dist_sources = ();
6722     # This hash maps object file names onto their corresponding source
6723     # file names.  This is used to ensure that each object is created
6724     # by a single source file.
6725     %object_map = ();
6727     # This keeps track of the directories for which we've already
6728     # created `.dirstamp' code.
6729     %directory_map = ();
6731     # These variables track inclusion of various compile-related .am
6732     # files.  $included_generic_compile is TRUE if the basic code has
6733     # been included.  $included_knr_compile is TRUE if the ansi2knr
6734     # code has been included.  $included_libtool_compile is TRUE if
6735     # libtool support has been included.
6736     $included_generic_compile = 0;
6737     $included_knr_compile = 0;
6738     $included_libtool_compile = 0;
6740     # TRUE if install targets should work recursively.
6741     $recursive_install = 0;
6743     # All .P files.
6744     %dep_files = ();
6746     # Strictness levels.
6747     $strictness = $default_strictness;
6748     $strictness_name = $default_strictness_name;
6750     # Options from AUTOMAKE_OPTIONS.
6751     %options = ();
6753     # Whether or not dependencies are handled.  Can be further changed
6754     # in handle_options.
6755     $use_dependencies = $cmdline_use_dependencies;
6757     # Per Makefile.am.
6758     $local_maint_charset = $maint_charset;
6760     # All yacc and lex source filenames for this directory.  Use
6761     # filenames instead of raw count so that multiple instances are
6762     # counted correctly (eg one yacc file can appear in multiple
6763     # programs without harm).
6764     %yacc_sources = ();
6765     %lex_sources = ();
6767     # This is a list of all targets to run during "make dist".
6768     @dist_targets = ();
6770     # Keys in this hash are the basenames of files which must depend
6771     # on ansi2knr.
6772     %de_ansi_files = ();
6774     # This maps the source extension of a suffix rule to its
6775     # corresponding output extension.
6776     %suffix_rules = ();
6778     # This is the name of the recursive `all' target to use.
6779     $all_target = 'all-recursive';
6781     # This keeps track of which extensions we've seen (that we care
6782     # about).
6783     %extension_seen = ();
6785     # This is random scratch space for the language finish functions.
6786     # Don't randomly overwrite it; examine other uses of keys first.
6787     %language_scratch = ();
6791 ################################################################
6793 # Return contents of a file from $am_dir, automatically skipping
6794 # macros or rules which are already known.  Runs command on each line
6795 # as it is read; this command can modify $_.
6796 sub file_contents_with_transform
6798     local ($command, $basename) = @_;
6799     local ($file) = $am_dir . '/' . $basename . '.am';
6801     if ($command ne '' && substr ($command, -1) ne ';')
6802     {
6803         die "automake: programming error in file_contents_with_transform: $command\n";
6804     }
6806     open (FC_FILE, $file)
6807         || die "automake: installation error: cannot open \`$file'\n";
6808     # Looks stupid?
6809     # print "automake: reading $file\n" if $verbose;
6811     local ($was_rule) = 0;
6812     local ($result_vars) = '';
6813     local ($result_rules) = '';
6814     local ($comment) = '';
6815     local ($spacing) = "\n";
6816     local ($skipping) = 0;
6817     local ($had_chars);
6819     while (<FC_FILE>)
6820     {
6821         $_ =~ s/\@MAINTAINER_MODE_TRUE\@//g
6822             unless $seen_maint_mode;
6824         $had_chars = length ($_) && $_ ne "\n";
6825         eval $command;
6826         # If the transform caused all the characters to go away, then
6827         # ignore the line.  Why do this?  Because in Perl 4, a "next"
6828         # inside of an eval doesn't affect a loop outside the eval.
6829         # So we can't pass in a "transform" that uses next.  We used
6830         # to do this.  "Empty" also means consisting of a single
6831         # newline.
6832         next if $had_chars && ($_ eq '' || $_ eq "\n");
6834         if (/$IGNORE_PATTERN/o)
6835         {
6836             # Merely delete comments beginning with two hashes.
6837         }
6838         elsif (/$WHITE_PATTERN/o)
6839         {
6840             # Stick a single white line before the incoming macro or rule.
6841             $spacing = "\n";
6842             &am_line_error ($., "blank line following trailing backslash")
6843                 if $saw_bk;
6844         }
6845         elsif (/$COMMENT_PATTERN/o)
6846         {
6847             # Stick comments before the incoming macro or rule.
6848             $comment .= $spacing . $_;
6849             $spacing = '';
6850             &am_line_error ($., "comment following trailing backslash")
6851                 if $saw_bk;
6852         }
6853         elsif ($saw_bk)
6854         {
6855             if ($was_rule)
6856             {
6857                 $result_rules .= $_ if ! $skipping;
6858             }
6859             else
6860             {
6861                 $result_vars .= $_ if ! $skipping;
6862             }
6863             $saw_bk = /\\$/;
6864         }
6865         elsif (/$RULE_PATTERN/o)
6866         {
6867             # Found a rule.
6868             $was_rule = 1;
6869             $skipping = defined $contents{$1};
6870             $result_rules .= $comment . $spacing . $_ if ! $skipping;
6871             $comment = $spacing = '';
6872             $saw_bk = /\\$/;
6873         }
6874         elsif (/$MACRO_PATTERN/o)
6875         {
6876             # Found a variable reference.
6877             $was_rule = 0;
6878             $skipping = defined $contents{$1};
6879             $result_vars .= $comment . $spacing . $_ if ! $skipping;
6880             $comment = $spacing = '';
6881             $saw_bk = /\\$/;
6882             print STDERR "automake: programming error: .am macro \`$1' with trailing backslash\n"
6883                 if $saw_bk;
6884             $am_var_defs{$1} = $3;
6885         }
6886         else
6887         {
6888             # This isn't an error; it is probably a continued rule.
6889             # In fact, this is what we assume.
6890             $was_rule = 1;
6891             $result_rules .= $comment . $spacing . $_ if ! $skipping;
6892             $comment = $spacing = '';
6893             $saw_bk = /\\$/;
6894         }
6895     }
6897     close (FC_FILE);
6898     return $result_vars . $result_rules . $comment;
6901 # Like file_contents_with_transform, but no transform.
6902 sub file_contents
6904     return &file_contents_with_transform ('', @_);
6907 # Find all variable prefixes that are used for install directories.  A
6908 # prefix `zar' qualifies iff:
6909 # * `zardir' is a variable.
6910 # * `zar_PRIMARY' is a variable.
6911 sub am_primary_prefixes
6913     local ($primary, $can_dist, @prefixes) = @_;
6915     local (%valid, $varname);
6916     grep ($valid{$_} = 0, @prefixes);
6917     $valid{'EXTRA'} = 0;
6918     foreach $varname (keys %contents)
6919     {
6920         if ($varname =~ /^(dist_|nodist_)?(.*)_$primary$/)
6921         {
6922             if (($1 ne '' && ! $can_dist)
6923                 || (! defined $valid{$2}
6924                     && ! &variable_defined ($2 . 'dir')
6925                     # Note that a configure variable is always
6926                     # legitimate.  It is natural to name such
6927                     # variables after the primary, so we explicitly
6928                     # allow it.
6929                     && ! defined $configure_vars{$varname}))
6930             {
6931                 &am_line_error ($varname, "invalid variable \`$varname'");
6932             }
6933             else
6934             {
6935                 # Ensure all extended prefixes are actually used.
6936                 $valid{$1 . $2} = 1;
6937             }
6938         }
6939     }
6941     return %valid;
6944 # Handle `where_HOW' variable magic.  Does all lookups, generates
6945 # install code, and possibly generates code to define the primary
6946 # variable.  The first argument is the name of the .am file to munge,
6947 # the second argument is the primary variable (eg HEADERS), and all
6948 # subsequent arguments are possible installation locations.  Returns
6949 # list of all values of all _HOW targets.
6951 # FIXME: this should be rewritten to be cleaner.  It should be broken
6952 # up into multiple functions.
6954 # Usage is: am_install_var (OPTION..., file, HOW, where...)
6955 sub am_install_var
6957     local (@args) = @_;
6959     local ($do_clean) = 0;
6960     local ($do_require) = 1;
6961     local ($can_dist) = 0;
6962     local ($default_dist) = 0;
6964     local ($ltxform);
6965     if (defined $configure_vars{'LIBTOOL'})
6966     {
6967         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
6968         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
6969     }
6970     else
6971     {
6972         # Delete '@LIBTOOL ...@'
6973         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
6974     }
6976     local ($cygxform);
6977     if (! $seen_exeext)
6978     {
6979         $cygxform = 's/\@EXEEXT\@//g;';
6980     }
6981     else
6982     {
6983         $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
6984     }
6986     while (@args)
6987     {
6988         if ($args[0] eq '-clean')
6989         {
6990             $do_clean = 1;
6991         }
6992         elsif ($args[0] eq '-noextra')
6993         {
6994             $do_require = 0;
6995         }
6996         elsif ($args[0] eq '-candist')
6997         {
6998             $can_dist = 1;
6999         }
7000         elsif ($args[0] eq '-defaultdist')
7001         {
7002             $default_dist = 1;
7003             $can_dist = 1;
7004         }
7005         elsif ($args[0] !~ /^-/)
7006         {
7007             last;
7008         }
7009         shift (@args);
7010     }
7012     local ($file, $primary, @prefixes) = @args;
7014     local (@used) = ();
7015     local (@result) = ();
7017     # Now that configure substitutions are allowed in where_HOW
7018     # variables, it is an error to actually define the primary.  We
7019     # allow `JAVA', as it is customarily used to mean the Java
7020     # interpreter.  This is but one of several Java hacks.
7021     &am_line_error ($primary, "\`$primary' is an anachronism")
7022         if &variable_defined ($primary) && $primary ne 'JAVA';
7025     # Look for misspellings.  It is an error to have a variable ending
7026     # in a "reserved" suffix whose prefix is unknown, eg
7027     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
7028     # variable of the same name (with "dir" appended) exists.  For
7029     # instance, if the variable "zardir" is defined, then
7030     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
7031     # flexibility in those cases which need it.
7032     local (%valid) = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7034     # If a primary includes a configure substitution, then the EXTRA_
7035     # form is required.  Otherwise we can't properly do our job.
7036     local ($require_extra);
7037     local ($warned_about_extra) = 0;
7039     local ($clean_file) = $file . '-clean';
7040     local ($one_name);
7041     local ($X);
7042     local ($nodir_name);
7043     foreach $X (sort keys %valid)
7044     {
7045         $one_name = $X . '_' . $primary;
7046         if (&variable_defined ($one_name))
7047         {
7048             # If files should be distributed, do so.
7049             if ($can_dist)
7050             {
7051                 if (($default_dist && $one_name !~ /^nodist_/)
7052                     || (! $default_dist && $one_name =~ /^dist_/))
7053                 {
7054                     &push_dist_common ('$(' . $one_name . ')');
7055                 }
7056                 ($nodir_name = $X) =~ s/^(dist|nodist)_//;
7057             }
7058             else
7059             {
7060                 $nodir_name = $X;
7061             }
7063             # Append actual contents of where_PRIMARY variable to
7064             # result.
7065             local ($rcurs);
7066             foreach $rcurs (&variable_value_as_list ($one_name, 'all'))
7067             {
7068                 # Skip configure substitutions.  Possibly bogus.
7069                 if ($rcurs =~ /^\@.*\@$/)
7070                 {
7071                     if ($X eq 'EXTRA')
7072                     {
7073                         if (! $warned_about_extra)
7074                         {
7075                             $warned_about_extra = 1;
7076                             {
7077                                 &am_line_error ($one_name,
7078                                                 "\`$one_name' contains configure substitution, but shouldn't");
7079                             }
7080                         }
7081                     }
7082                     # Check here to make sure variables defined in
7083                     # configure.in do not imply that EXTRA_PRIMARY
7084                     # must be defined.
7085                     elsif (! defined $configure_vars{$one_name})
7086                     {
7087                         $require_extra = $one_name
7088                             if $do_require;
7089                     }
7091                     next;
7092                 }
7094                 push (@result, $rcurs);
7095             }
7097             # "EXTRA" shouldn't be used when generating clean targets,
7098             # all, or install targets.
7099             if ($X eq 'EXTRA')
7100             {
7101                 # We used to warn if EXTRA_FOO was defined uselessly,
7102                 # but this was annoying.
7103                 next;
7104             }
7106             # A blatant hack: we rewrite each _PROGRAMS primary to
7107             # include EXEEXT when in Cygwin32 mode.
7108             if ($seen_exeext && $primary eq 'PROGRAMS')
7109             {
7110                 local (@conds) = &variable_conditions ($one_name);
7111                 local (@one_binlist);
7113                 # FIXME: this definitely loses aesthetically; it
7114                 # redefines $ONE_NAME.  Instead we should arrange for
7115                 # variable definitions to be output later, instead of
7116                 # at scan time.
7118                 if (! @conds)
7119                 {
7120                     @one_binlist = ();
7121                     foreach $rcurs (&variable_value_as_list ($one_name, ''))
7122                     {
7123                         if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7124                         {
7125                             push (@one_binlist, $rcurs);
7126                         }
7127                         else
7128                         {
7129                             push (@one_binlist, $rcurs . '$(EXEEXT)');
7130                         }
7131                     }
7133                     delete $contents{$one_name};
7134                     &define_pretty_variable ($one_name, '', @one_binlist);
7135                 }
7136                 else
7137                 {
7138                     local ($cond);
7139                     local ($condvals) = '';
7140                     foreach $cond (@conds)
7141                     {
7142                         @one_binlist = ();
7143                         local (@condval) = &variable_value_as_list ($one_name,
7144                                                                     $cond);
7145                         foreach $rcurs (@condval)
7146                         {
7147                             if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7148                             {
7149                                 push (@one_binlist, $rcurs);
7150                             }
7151                             else
7152                             {
7153                                 push (@one_binlist, $rcurs . '$(EXEEXT)');
7154                             }
7155                         }
7157                         push (@condvals, $cond);
7158                         push (@condvals, join (' ', @one_binlist));
7159                     }
7161                     delete $contents{$one_name};
7163                     while (@condvals)
7164                     {
7165                         $cond = shift (@condvals);
7166                         local (@val) = split (' ', shift (@condvals));
7167                         &define_pretty_variable ($one_name, $cond, @val);
7168                     }
7169                 }
7170             }
7172             if ($do_clean)
7173             {
7174                 $output_rules .=
7175                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
7176                                                    . $cygxform,
7177                                                    $clean_file);
7179                 push (@clean, $X . $primary);
7180                 &push_phony_cleaners ($X . $primary);
7181             }
7183             if ($X eq 'check')
7184             {
7185                 push (@check, '$(' . $one_name . ')');
7186             }
7187             else
7188             {
7189                 push (@used, '$(' . $one_name . ')');
7190             }
7191             if ($X eq 'noinst' || $X eq 'check')
7192             {
7193                 # Objects which don't get installed by default.
7194                 next;
7195             }
7197             $output_rules .=
7198                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
7199                                                . 's/\@NDIR\@/' . $nodir_name . '/go;'
7200                                                . $ltxform . $cygxform,
7201                                                $file);
7203             push (@uninstall, 'uninstall-' . $X . $primary);
7204             push (@phony, 'uninstall-' . $X . $primary);
7205             push (@installdirs, '$(DESTDIR)$(' . $X . 'dir)');
7206             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
7207             {
7208                 push (@install_exec, 'install-' . $X . $primary);
7209                 push (@phony, 'install-' . $X . $primary);
7210             }
7211             else
7212             {
7213                 push (@install_data, 'install-' . $X . $primary);
7214                 push (@phony, 'install-' . $X . $primary);
7215             }
7216         }
7217     }
7219     # The JAVA variable is used as the name of the Java interpreter.
7220     if (@used && $primary ne 'JAVA')
7221     {
7222         # Define it.
7223         &define_pretty_variable ($primary, '', @used);
7224         $output_vars .= "\n";
7225     }
7227     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7228     {
7229         &am_line_error ($require_extra,
7230                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
7231     }
7233     # Push here because PRIMARY might be configure time determined.
7234     push (@all, '$(' . $primary . ')')
7235         if @used && $primary ne 'JAVA';
7237     # Make the result unique.  This lets the user use conditionals in
7238     # a natural way, but still lets us program lazily -- we don't have
7239     # to worry about handling a particular object more than once.
7240     local (%uniquify) = ();
7241     grep ($uniquify{$_} = 1, @result);
7242     return sort keys %uniquify;
7246 ################################################################
7248 # This variable is local to the "require file" set of functions.
7249 @require_file_paths = ();
7251 # Verify that the file must exist in the current directory.  Usage:
7252 # require_file (isconfigure, line_number, strictness, file) strictness
7253 # is the strictness level at which this file becomes required.  Must
7254 # set require_file_paths before calling this function.
7255 # require_file_paths is set to hold a single directory (the one in
7256 # which the first file was found) before return.
7257 sub require_file_internal
7259     local ($is_configure, $line, $mystrict, @files) = @_;
7260     local ($file, $fullfile);
7261     local ($found_it, $errfile, $errdir);
7262     local ($save_dir);
7264     foreach $file (@files)
7265     {
7266         $found_it = 0;
7267         foreach $dir (@require_file_paths)
7268         {
7269             if ($dir eq '.')
7270             {
7271                 $fullfile = $relative_dir . "/" . $file;
7272                 $errdir = $relative_dir unless $errdir;
7273             }
7274             else
7275             {
7276                 $fullfile = $dir . "/" . $file;
7277                 $errdir = $dir unless $errdir;
7278             }
7280             # Use different name for "error filename".  Otherwise on
7281             # an error the bad file will be reported as eg
7282             # `../../install-sh' when using the default
7283             # config_aux_path.
7284             $errfile = $errdir . '/' . $file;
7286             if (-f $fullfile)
7287             {
7288                 $found_it = 1;
7289                 # FIXME: Once again, special-case `.'.
7290                 &push_dist_common ($file)
7291                     if $dir eq $relative_dir || $dir eq '.';
7292                 $save_dir = $dir;
7293                 last;
7294             }
7295         }
7297         if ($found_it)
7298         {
7299             # Prune the path list.
7300             @require_file_paths = $save_dir;
7301         }
7302         else
7303         {
7304             if ($strictness >= $mystrict)
7305             {
7306                 local ($trailer) = '';
7307                 local ($suppress) = 0;
7309                 # Only install missing files according to our desired
7310                 # strictness level.
7311                 local ($message) = "required file \`$errfile' not found";
7312                 if ($add_missing)
7313                 {
7314                     $suppress = 1;
7316                     # Maybe run libtoolize.
7317                     if ($seen_libtool
7318                         && grep ($_ eq $file, @libtoolize_files)
7319                         && system ('libtoolize', '--automake'))
7320                     {
7321                         $message = "installing \`$errfile'";
7322                         $suppress = 0;
7323                         $trailer = "; cannot run \`libtoolize': $!";
7324                     }
7325                     elsif (-f ($am_dir . '/' . $file))
7326                     {
7327                         # Install the missing file.  Symlink if we
7328                         # can, copy if we must.  Note: delete the file
7329                         # first, in case it is a dangling symlink.
7330                         $message = "installing \`$errfile'";
7331                         # Windows Perl will hang if we try to delete a
7332                         # file that doesn't exist.
7333                         unlink ($errfile) if -f $errfile;
7334                         if ($symlink_exists && ! $copy_missing)
7335                         {
7336                             if (! symlink ($am_dir . '/' . $file, $errfile))
7337                             {
7338                                 $suppress = 0;
7339                                 $trailer = "; error while making link: $!\n";
7340                             }
7341                         }
7342                         elsif (system ('cp', $am_dir . '/' . $file, $errfile))
7343                         {
7344                             $suppress = 0;
7345                             $trailer = "\n    error while copying\n";
7346                         }
7347                     }
7348                 }
7350                 local ($save) = $exit_status;
7351                 if ($is_configure)
7352                 {
7353                     # FIXME: allow actual file to be specified.
7354                     &am_conf_line_error ('configure.in', $line,
7355                                          "$message$trailer");
7356                 }
7357                 else
7358                 {
7359                     &am_line_error ($line, "$message$trailer");
7360                 }
7361                 $exit_status = $save if $suppress;
7362             }
7363         }
7364     }
7367 # Like require_file_with_line, but error messages refer to
7368 # configure.in, not the current Makefile.am.
7369 sub require_file_with_conf_line
7371     @require_file_paths = '.';
7372     &require_file_internal (1, @_);
7375 sub require_file_with_line
7377     @require_file_paths = '.';
7378     &require_file_internal (0, @_);
7381 sub require_file
7383     @require_file_paths = '.';
7384     &require_file_internal (0, '', @_);
7387 # Require a file that is also required by Autoconf.  Looks in
7388 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7389 sub require_config_file
7391     @require_file_paths = @config_aux_path;
7392     &require_file_internal (1, '', @_);
7393     local ($dir) = $require_file_paths[0];
7394     @config_aux_path = @require_file_paths;
7395     if ($dir eq '.')
7396     {
7397         $config_aux_dir = '.';
7398     }
7399     else
7400     {
7401         $config_aux_dir = '$(top_srcdir)/' . $dir;
7402     }
7405 # Assumes that the line number is in Makefile.am.
7406 sub require_conf_file_with_line
7408     @require_file_paths = @config_aux_path;
7409     &require_file_internal (0, @_);
7410     local ($dir) = $require_file_paths[0];
7411     @config_aux_path = @require_file_paths;
7412     if ($dir eq '.')
7413     {
7414         $config_aux_dir = '.';
7415     }
7416     else
7417     {
7418         $config_aux_dir = '$(top_srcdir)/' . $dir;
7419     }
7422 # Assumes that the line number is in configure.in.
7423 sub require_conf_file_with_conf_line
7425     @require_file_paths = @config_aux_path;
7426     &require_file_internal (1, @_);
7427     local ($dir) = $require_file_paths[0];
7428     @config_aux_path = @require_file_paths;
7429     if ($dir eq '.')
7430     {
7431         $config_aux_dir = '.';
7432     }
7433     else
7434     {
7435         $config_aux_dir = '$(top_srcdir)/' . $dir;
7436     }
7439 ################################################################
7441 # Push a list of files onto dist_common.
7442 sub push_dist_common
7444     local (@files) = @_;
7445     local ($file);
7447     foreach $file (@files)
7448     {
7449         $dist_common{$file} = 1;
7450     }
7453 # Push a list of clean targets onto phony.
7454 sub push_phony_cleaners
7456     local ($base) = @_;
7457     local ($target);
7458     foreach $target ('mostly', 'dist', '', 'maintainer-')
7459     {
7460         push (@phony, $target . 'clean-' . $base);
7461     }
7464 # Set strictness.
7465 sub set_strictness
7467     $strictness_name = $_[0];
7468     if ($strictness_name eq 'gnu')
7469     {
7470         $strictness = $GNU;
7471     }
7472     elsif ($strictness_name eq 'gnits')
7473     {
7474         $strictness = $GNITS;
7475     }
7476     elsif ($strictness_name eq 'foreign')
7477     {
7478         $strictness = $FOREIGN;
7479     }
7480     else
7481     {
7482         die "automake: level \`$strictness_name' not recognized\n";
7483     }
7487 ################################################################
7489 # Return directory name of file.
7490 sub dirname
7492     local ($file) = @_;
7493     local ($sub);
7495     ($sub = $file) =~ s,/+[^/]+$,,g;
7496     $sub = '.' if $sub eq $file;
7497     return $sub;
7500 # Return file name of a file.
7501 sub basename
7503     local ($file) = @_;
7504     local ($sub);
7506     ($sub = $file) =~s,^.*/+,,g;
7507     return $sub;
7510 # Ensure a file exists.
7511 sub create
7513     local ($file) = @_;
7515     open (TOUCH, ">> $file");
7516     close (TOUCH);
7519 # Glob something.  Do this to avoid indentation screwups everywhere we
7520 # want to glob.  Gross!
7521 sub my_glob
7523     local ($pat) = @_;
7524     return <${pat}>;
7527 ################################################################
7529 # Print an error message and set exit status.
7530 sub am_error
7532     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
7533     $exit_status = 1;
7536 sub am_line_error
7538     local ($symbol, @args) = @_;
7540     if ($symbol && "$symbol" ne '-1')
7541     {
7542         local ($file) = "${am_file}.am";
7544         if ($symbol =~ /^\d+$/)
7545         {
7546             # SYMBOL is a line number, so just add the colon.
7547             $file .= ':' . $symbol;
7548         }
7549         elsif (defined $content_lines{$symbol})
7550         {
7551             # SYMBOL is a variable defined in Makefile.am, so add the
7552             # line number we saved from there.
7553             $file .= ':' . $content_lines{$symbol};
7554         }
7555         elsif (defined $configure_vars{$symbol})
7556         {
7557             # SYMBOL is a variable defined in configure.in, so add the
7558             # appropriate line number.
7559             $file = $configure_vars{$symbol};
7560         }
7561         else
7562         {
7563             # Couldn't find the line number.
7564         }
7565         warn $file, ": ", join (' ', @args), "\n";
7566         $exit_status = 1;
7567     }
7568     else
7569     {
7570         &am_error (@args);
7571     }
7574 # Like am_error, but while scanning configure.in.
7575 sub am_conf_error
7577     # FIXME: can run in subdirs.
7578     warn "automake: configure.in: ", join (' ', @_), "\n";
7579     $exit_status = 1;
7582 # Error message with line number referring to configure.in.
7583 sub am_conf_line_error
7585     local ($file, $line, @args) = @_;
7587     if ($line)
7588     {
7589         warn "$file: $line: ", join (' ', @args), "\n";
7590         $exit_status = 1;
7591     }
7592     else
7593     {
7594         &am_conf_error (@args);
7595     }
7598 # Warning message with line number referring to configure.in.
7599 # Does not affect exit_status
7600 sub am_conf_line_warning
7602     local ($saved_exit_status) = $exit_status;
7603     &am_conf_line_error (@_);
7604     $exit_status = $saved_exit_status;
7607 # Tell user where our aclocal.m4 is, but only once.
7608 sub keyed_aclocal_warning
7610     local ($key) = @_;
7611     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
7614 # Print usage information.
7615 sub usage
7617     print "Usage: automake [OPTION] ... [Makefile]...\n\n";
7618     print "Generate Makefile.in for autoconf from Makefile.am\n";
7619     print $USAGE;
7620     print "\nFiles which are automatically distributed, if found:\n";
7621     $~ = "USAGE_FORMAT";
7622     local ($last, $iter, @lcomm);
7623     $last = '';
7624     foreach $iter (sort ((@common_files, @common_sometimes)))
7625     {
7626         push (@lcomm, $iter) unless $iter eq $last;
7627         $last = $iter;
7628     }
7630     local ($one, $two, $three, $four, $i, $max);
7631     $max = int (($#lcomm + 1) / 4);
7633     for ($i = 0; $i < $max; ++$i)
7634     {
7635         $one = $lcomm[$i];
7636         $two = $lcomm[$max + $i];
7637         $three = $lcomm[2 * $max + $i];
7638         $four = $lcomm[3 * $max + $i];
7639         write;
7640     }
7642     local ($mod) = ($#lcomm + 1) % 4;
7643     if ($mod != 0)
7644     {
7645         $one = $lcomm[$max];
7646         $two = ($mod > 1) ? $lcomm[2 * $max] : '';
7647         $three = ($mod > 2) ? $lcomm[3 * $max] : '';
7648         $four = ($mod > 3) ? $lcomm[4 * $max] : '';
7649         write;
7650     }
7652     print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7654     exit 0;
7657 format USAGE_FORMAT =
7658   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
7659   $one,               $two,               $three,             $four