* automake.in (handle_configure): Replace multiple occurrences of
[automake.git] / automake.in
blobc29cfa0e35e0453e103d3ec123123127303076c6
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 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
152 @other_input_files = ();
153 # Line number at which AC_OUTPUT seen.
154 $ac_output_line = 0;
156 # List of directories to search for configure-required files.  This
157 # can be set by AC_CONFIG_AUX_DIR.
158 @config_aux_path = ('.', '..', '../..');
159 $config_aux_dir = '';
161 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
162 $seen_make_set = 0;
164 # Whether AM_GNU_GETTEXT has been seen in configure.in.
165 $seen_gettext = 0;
166 # Line number at which AM_GNU_GETTEXT seen.
167 $ac_gettext_line = 0;
169 # Whether ALL_LINGUAS has been seen.
170 $seen_linguas = '';
171 # The actual text.
172 $all_linguas = '';
173 # Line number at which it appears.
174 $all_linguas_line = 0;
176 # 1 if AC_PROG_INSTALL seen.
177 $seen_prog_install = 0;
179 # Whether AC_PATH_XTRA has been seen in configure.in.
180 $seen_path_xtra = 0;
182 # TRUE if AC_DECL_YYTEXT was seen.
183 $seen_decl_yytext = 0;
185 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
186 # AC_CHECK_TOOL also sets this.
187 $seen_canonical = 0;
189 # TRUE if we've seen AC_ARG_PROGRAM.
190 $seen_arg_prog = 0;
192 # TRUE if we've seen AC_PROG_LIBTOOL.
193 $seen_libtool = 0;
194 $libtool_line = 0;
196 # Files installed by libtoolize.
197 @libtoolize_files = ('ltconfig', 'ltmain.sh', 'config.guess', 'config.sub');
199 # TRUE if we've seen AM_MAINTAINER_MODE.
200 $seen_maint_mode = 0;
202 # TRUE if we've seen PACKAGE and VERSION.
203 $seen_package = 0;
204 $seen_version = 0;
206 # Actual version we've seen.
207 $package_version = '';
209 # Line number where we saw version definition.
210 $package_version_line = 0;
212 # TRUE if we've seen AM_PATH_LISPDIR.
213 $seen_lispdir = 0;
215 # TRUE if we've seen AC_EXEEXT.
216 $seen_exeext = 0;
218 # TRUE if we've seen AC_OBJEXT.
219 $seen_objext = 0;
221 # TRUE if we've seen AC_ENABLE_MULTILIB.
222 $seen_multilib = 0;
224 # Hash table of discovered configure substitutions.  Keys are names,
225 # values are `FILE:LINE' strings which are used by error message
226 # generation.
227 %configure_vars = ();
229 # This is used to keep track of which variable definitions we are
230 # scanning.  It is only used in certain limited ways, but it has to be
231 # global.  It is declared just for documentation purposes.
232 %vars_scanned = ();
234 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
235 # handled in a funny way: if seen in the top-level Makefile.am, it is
236 # used for every directory which does not specify a different value.
237 # The rationale here is that some directories (eg gettext) might be
238 # distributions of other packages, and thus require their own charset
239 # info.  However, the DIST_CHARSET must be the same for the entire
240 # package; it can only be set at top-level.
241 # FIXME: this yields bugs when rebuilding.  What to do?  Always
242 # read (and sometimes discard) top-level Makefile.am?
243 $maint_charset = '';
244 $dist_charset = 'utf8';         # recode doesn't support this yet.
246 # Name of input file ("Makefile.in") and output file ("Makefile.am").
247 # These have no directory components.
248 $am_file_name = '';
249 $in_file_name = '';
251 # TRUE if --cygnus seen.
252 $cygnus_mode = 0;
254 # Keys of this hash are names of dependency files to ignore.
255 %omit_dependencies = ();
257 # Hash table of AM_CONDITIONAL variables seen in configure.
258 %configure_cond = ();
260 # Map from obsolete macros to hints for new macros.
261 # If you change this, change the corresponding list in aclocal.in.
262 # FIXME: should just put this into a single file.
263 %obsolete_macros =
264     (
265      'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
266      'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
267      'AC_FEATURE_EXIT', '',
268      'AC_SYSTEM_HEADER', '',
270      # Note that we do not handle this one, because it is still run
271      # from AM_CONFIG_HEADER.  So we deal with it specially in
272      # scan_configure.
273      # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",
275      'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
276      'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
277      'fp_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
278      'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
279      'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
280      'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
281      'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
282      'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
283      'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",
284      'ud_GNU_GETTEXT', "use \`AM_GNU_GETTEXT'",
286      # Now part of autoconf proper, under a different name.
287      'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
288      'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
289      'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",
290      'AM_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
291      'AM_EXEEXT', "use \`AC_EXEEXT'",
292      'AM_CYGWIN32', "use \`AC_CYGWIN32'",
293      'AM_MINGW32', "use \`AC_MINGW32'",
295 # These aren't quite obsolete.
296 #      'md_PATH_PROG',
297      );
299 # Regexp to match the above macros.
300 $obsolete_rx = '(' . join ('|', keys %obsolete_macros) . ')';
302 # This maps extensions onto language names.
303 %extension_map = ();
305 # This maps languages names onto properties.
306 %language_map = ();
310 # Initialize global constants and our list of languages that are
311 # internally supported.
312 &initialize_global_constants;
314 &register_language ('c', 'ansi-p=1', 'autodep=',
315                     'c');
316 &register_language ('cxx', 'linker=CXXLINK', 'autodep=CXX',
317                     'c++', 'cc', 'cpp', 'cxx', 'C');
318 &register_language ('objc', 'linker=OBJCLINK', 'autodep=OBJC',
319                     'm');
320 &register_language ('header',
321                     'h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc');
322 &register_language ('yacc', 'ansi-p=1',
323                     'y');
324 &register_language ('yaccxx', 'linker=CXXLINK',
325                     'y++', 'yy', 'yxx', 'ypp');
326 &register_language ('lex', 'ansi-p=1',
327                     'l');
328 &register_language ('lexxx', 'linker=CXXLINK',
329                     'l++', 'll', 'lxx', 'lpp');
330 &register_language ('asm',
331                     's', 'S');
332 &register_language ('f77', 'linker=F77LINK',
333                     'f', 'for', 'f90');
334 &register_language ('ppf77', 'linker=F77LINK',
335                     'F');
336 &register_language ('ratfor', 'linker=F77LINK',
337                     'r');
338 &register_language ('java', 'linker=GCJLINK', 'autodep=GCJ',
339                     'java');
342 # Parse command line.
343 &parse_arguments (@ARGV);
345 # Do configure.in scan only once.
346 &scan_configure;
348 die "automake: no \`Makefile.am' found or specified\n"
349     if ! @input_files;
351 # If --generate-deps was given, we don't do anything else
353 if ($generate_deps)
355     die "automake: Must specify --include-deps (or -i) when generating\n"
356         if $use_dependencies;
357     die "automake: Must provide --build-dir when generating\n"
358         if ! $build_directory;
359     die "automake: Must provide --srcdir-name when generating\n"
360         if ! $srcdir_name;
362     open (GDEP, ">$output_directory/.dep_segment")
363         || die "automake: Could not open `$output_directory/.dep_segment': $!\n";
365     &handle_dependencies;
366     print GDEP $output_rules;
368     close(GDEP);
369     exit $exit_status;
372 # Now do all the work on each file.
373 foreach $am_file (@input_files)
375     if (! -f ($am_file . '.am'))
376     {
377         &am_error ("\`" . $am_file . ".am' does not exist");
378     }
379     else
380     {
381         &generate_makefile ($output_files{$am_file}, $am_file);
382     }
385 &am_conf_error ("AC_PROG_INSTALL must be used in configure.in")
386     if (! $seen_prog_install);
388 exit $exit_status;
391 ################################################################
393 # Parse command line.
394 sub parse_arguments
396     local (@arglist) = @_;
398     # Start off as gnu.
399     &set_strictness ('gnu');
401     while (@arglist)
402     {
403         if ($arglist[0] eq "--version")
404         {
405             print "automake (GNU $PACKAGE) $VERSION\n\n";
406             print "Copyright (C) 1999 Free Software Foundation, Inc.\n";
407             print "This is free software; see the source for copying conditions.  There is NO\n";
408             print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
409             print "Written by Tom Tromey <tromey\@cygnus.com>\n";
411             exit 0;
412         }
413         elsif ($arglist[0] eq "--help")
414         {
415             &usage;
416         }
417         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
418         {
419             $am_dir = $1;
420         }
421         elsif ($arglist[0] eq '--amdir')
422         {
423             &require_argument (@arglist);
424             shift (@arglist);
425             $am_dir = $arglist[0];
426         }
427         elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
428         {
429             # Must end in /.
430             $build_directory = $1 . '/';
431         }
432         elsif ($arglist[0] eq '--build-dir')
433         {
434             &require_argument (@arglist);
435             shift (@arglist);
436             # Must end in /.
437             $build_directory = $arglist[0] . '/';
438         }
439         elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
440         {
441             $srcdir_name = $1;
442         }
443         elsif ($arglist[0] eq '--srcdir-name')
444         {
445             &require_argument (@arglist);
446             shift (@arglist);
447             $srcdir_name = $arglist[0];
448         }
449         elsif ($arglist[0] eq '--gnu')
450         {
451             &set_strictness ('gnu');
452         }
453         elsif ($arglist[0] eq '--gnits')
454         {
455             &set_strictness ('gnits');
456         }
457         elsif ($arglist[0] eq '--cygnus')
458         {
459             $cygnus_mode = 1;
460         }
461         elsif ($arglist[0] eq '--foreign')
462         {
463             &set_strictness ('foreign');
464         }
465         elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
466         {
467             $cmdline_use_dependencies = 0;
468         }
469         elsif ($arglist[0] eq '--generate-deps')
470         {
471             $generate_deps = 1;
472         }
473         elsif ($arglist[0] eq '--no-force')
474         {
475             $force_generation = 0;
476         }
477         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
478         {
479             # Set output directory.
480             $output_directory = $1;
481         }
482         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
483         {
484             &require_argument (@arglist);
485             shift (@arglist);
486             $output_directory = $arglist[0];
487         }
488         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
489         {
490             $add_missing = 1;
491         }
492         elsif ($arglist[0] eq '--copy' || $arglist[0] eq '-c')
493         {
494             $copy_missing = 1;
495         }
496         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
497         {
498             $verbose = 1;
499         }
500         elsif ($arglist[0] eq '--')
501         {
502             # Stop option processing.
503             shift (@arglist);
504             push (@input_files, @arglist);
505             last;
506         }
507         elsif ($arglist[0] =~ /^-/)
508         {
509             die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
510         }
511         else
512         {
513             # Handle $local:$input syntax.  Note that we only examine
514             # the first ":" file to see if it is automake input; the
515             # rest are just taken verbatim.  We still keep all the
516             # files around for dependency checking, however.
517             local ($local, $input, @rest) = split (/:/, $arglist[0]);
518             if (! $input)
519             {
520                 $input = $local;
521             }
522             else
523             {
524                 # Strip .in; later on .am is tacked on.  That is how
525                 # the automake input file is found.  Maybe not the
526                 # best way, but it is easy to explain.  FIXME: should
527                 # be error if .in is missing.
528                 $input =~ s/\.in$//;
529             }
530             push (@input_files, $input);
531             $output_files{$input} = join (':', ($local, @rest));
532         }
534         shift (@arglist);
535     }
537     # Take global strictness from whatever we currently have set.
538     $default_strictness = $strictness;
539     $default_strictness_name = $strictness_name;
542 # Ensure argument exists, or die.
543 sub require_argument
545     local ($arg, @arglist) = @_;
546     die "automake: no argument given for option \`$arg'\n"
547         if ! @arglist;
550 ################################################################
552 # Generate a Makefile.in given the name of the corresponding Makefile and
553 # the name of the file output by config.status.
554 sub generate_makefile
556     local ($output, $makefile) = @_;
558     ($am_file_name = $makefile) =~ s/^.*\///;
559     $in_file_name = $am_file_name . '.in';
560     $am_file_name .= '.am';
562     # $OUTPUT is encoded.  If it contains a ":" then the first element
563     # is the real output file, and all remaining elements are input
564     # files.  We don't scan or otherwise deal with these input file,
565     # other than to mark them as dependencies.  See scan_configure for
566     # details.
567     local (@secondary_inputs);
568     ($output, @secondary_inputs) = split (/:/, $output);
570     &initialize_per_input;
571     $relative_dir = &dirname ($output);
572     $am_relative_dir = &dirname ($makefile);
574     # At the toplevel directory, we might need config.guess, config.sub
575     # or libtool scripts (ltconfig and ltmain.sh).
576     if ($relative_dir eq '.')
577     {
578         # libtool requires some files.
579         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
580                                            @libtoolize_files)
581             if $seen_libtool;
583         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
584         # config.sub.
585         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
586             if $seen_canonical;
587     }
589     # We still need Makefile.in here, because sometimes the `dist'
590     # target doesn't re-run automake.
591     if ($am_relative_dir eq $relative_dir)
592     {
593         # Only distribute the files if they are in the same subdir as
594         # the generated makefile.
595         &push_dist_common ($in_file_name, $am_file_name);
596     }
597     push (@sources, '$(SOURCES)')
598         if &variable_defined ('SOURCES');
599     push (@objects, '$(OBJECTS)')
600         if &variable_defined ('OBJECTS');
602     &read_main_am_file ($makefile . '.am');
603     if (&handle_options)
604     {
605         # Fatal error.  Just return, so we can continue with next file.
606         return;
607     }
609     # Check first, because we might modify some state.
610     &check_cygnus;
611     &check_gnu_standards;
612     &check_gnits_standards;
614     &handle_configure ($output, $makefile, @secondary_inputs);
615     &handle_gettext;
616     &handle_libraries;
617     &handle_ltlibraries;
618     &handle_programs;
619     &handle_scripts;
621     &handle_built_sources;
623     # This must be run after all the sources are scanned.
624     &finish_languages;
626     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
627     # on this (but currently does).
628     $contents{'SOURCES'} = join (' ', @sources);
629     $contents{'OBJECTS'} = join (' ', @objects);
630     &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
632     &handle_multilib;
633     &handle_texinfo;
634     &handle_emacs_lisp;
635     &handle_java;
636     &handle_man_pages;
637     &handle_data;
638     &handle_headers;
639     &handle_subdirs;
640     &handle_tags;
641     &handle_minor_options;
642     &handle_dist ($makefile);
643     &handle_dependencies;
644     &handle_tests;
645     &handle_footer;
646     &handle_merge_targets ($output);
647     &handle_installdirs;
648     &handle_clean;
649     &handle_phony;
651     &check_typos;
653     if (! -d ($output_directory . '/' . $am_relative_dir))
654     {
655         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
656     }
658     local ($out_file) = $output_directory . '/' . $makefile . ".in";
659     if (! $force_generation && -e $out_file)
660     {
661         local ($am_time) = (stat ($makefile . '.am'))[9];
662         local ($in_time) = (stat ($out_file))[9];
663         # FIXME: should cache these times.
664         local ($conf_time) = (stat ('configure.in'))[9];
665         # FIXME: how to do unsigned comparison?
666         if ($am_time < $in_time || $am_time < $conf_time)
667         {
668             # No need to update.
669             return;
670         }
671         if (-f 'aclocal.m4')
672         {
673             local ($acl_time) = (stat _)[9];
674             return if ($am_time < $acl_time);
675         }
676     }
678     if (! open (GM_FILE, "> " . $out_file))
679     {
680         warn "automake: ${am_file}.in: cannot write: $!\n";
681         $exit_status = 1;
682         return;
683     }
684     print "automake: creating ", $makefile, ".in\n" if $verbose;
686     print GM_FILE $output_vars;
687     # We make sure that `all:' is the first target.
688     print GM_FILE $output_all;
689     print GM_FILE $output_header;
690     print GM_FILE $output_rules;
691     print GM_FILE $output_trailer;
693     close (GM_FILE);
696 ################################################################
698 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
699 sub handle_options
701     if (&variable_defined ('AUTOMAKE_OPTIONS'))
702     {
703         foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
704         {
705             $options{$_} = 1;
706             if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
707             {
708                 &set_strictness ($_);
709             }
710             elsif ($_ eq 'cygnus')
711             {
712                 $cygnus_mode = 1;
713             }
714             elsif (/ansi2knr/)
715             {
716                 # An option like "../lib/ansi2knr" is allowed.  With
717                 # no path prefix, we assume the required programs are
718                 # in this directory.  We save the actual option for
719                 # later.
720                 $options{'ansi2knr'} = $_;
721             }
722             elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
723                    || $_ eq 'dist-shar' || $_ eq 'dist-zip'
724                    || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
725                    || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
726                    || $_ eq 'readme-alpha' || $_ eq 'check-news')
727             {
728                 # Explicitly recognize these.
729             }
730             elsif ($_ eq 'no-dependencies')
731             {
732                 $use_dependencies = 0;
733             }
734             elsif (/([0-9]+)\.([0-9]+)([a-z])?/)
735             {
736                 # Got a version number.
738                 local ($rmajor, $rminor, $ralpha) = ($1, $2, $3);
740                 if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
741                 {
742                     print STDERR
743                         "automake: programming error: version is incorrect\n";
744                     exit 1;
745                 }
746                 local ($tmajor, $tminor, $talpha) = ($1, $2, $3);
748                 # 2.0 is better than 1.0.
749                 # 1.2 is better than 1.1.
750                 # 1.2a is better than 1.2.
751                 if ($rmajor > $tmajor
752                     || ($rmajor == $tmajor && $rminor > $tminor)
753                     || ($rminor == $tminor && $rminor == $tminor
754                         && $ralpha gt $talpha))
755                 {
756                     &am_line_error ('AUTOMAKE_OPTIONS',
757                                     "require version $_, only have $VERSION");
758                     return 1;
759                 }
760             }
761             else
762             {
763                 &am_line_error ('AUTOMAKE_OPTIONS',
764                                 "option \`" . $_ . "\' not recognized");
765             }
766         }
767     }
769     if ($strictness == $GNITS)
770     {
771         $options{'readme-alpha'} = 1;
772         $options{'check-news'} = 1;
773     }
775     return 0;
778 # Return object extension.  Just once, put some code into the output.
779 # Argument is the name of the output file
780 sub get_object_extension
782     local ($out) = @_;
784     # Maybe require libtool library object files.
785     local ($extension) = '.o';
786     $extension = '.$(OBJEXT)' if $seen_objext;
787     $extension = '.lo' if ($out =~ /\.la$/);
789     if (! $included_generic_compile)
790     {
791         # Boilerplate.
792         local ($xform) = '';
793         if (&variable_defined ('CONFIG_HEADER'))
794         {
795             local ($one_hdr);
796             foreach $one_hdr (split (' ', &variable_value ('CONFIG_HEADER')))
797             {
798                 local ($var);
799                 ($var = &dirname ($one_hdr)) =~ s/(\W)/\\$1/g;
800                 $xform .= ' ' if $xform;
801                 $xform .= '-I' . $var;
802             }
803         }
804         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go;';
805         $output_vars .= &file_contents_with_transform ($xform,
806                                                        'comp-vars');
808         $xform = (($use_dependencies
809                    ? 's/^NOTDEPEND.*$//;'
810                    : 's/^NOTDEPEND//;')
811                   . ($seen_objext ? 's/^OBJEXT//;' : 's/^OBJEXT.*$//;'));
812         $output_rules .= &file_contents_with_transform ($xform, 'compile');
814         &push_phony_cleaners ('compile');
816         # If using X, include some extra variable definitions.  NOTE
817         # we don't want to force these into CFLAGS or anything,
818         # because not all programs will necessarily use X.
819         if ($seen_path_xtra)
820         {
821             local ($var);
822             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
823             {
824                 &define_configure_variable ($var);
825             }
826         }
828         push (@suffixes, '.c', '.o', '.S', '.s');
829         push (@suffixes, '.obj') if $seen_objext;
830         push (@clean, 'compile');
832         $included_generic_compile = 1;
833     }
835     if ($seen_libtool && ! $included_libtool_compile)
836     {
837         # Output the libtool compilation rules.
838         $output_rules .=
839             &file_contents_with_transform
840                 ($use_dependencies ? 's/^NOTDEPEND.*$//;' : 's/^NOTDEPEND//;',
841                  'libtool');
843         &push_phony_cleaners ('libtool');
845         push (@suffixes, '.lo');
846         push (@clean, 'libtool');
848         $included_libtool_compile = 1;
849     }
851     # Check for automatic de-ANSI-fication.
852     if (defined $options{'ansi2knr'})
853     {
854         $extension = '$U' . $extension;
855         if (! $included_knr_compile)
856         {
857             if (! $am_c_prototypes)
858             {
859                 &am_line_error ('AUTOMAKE_OPTIONS',
860                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
861                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
862                 # Only give this error once.
863                 $am_c_prototypes = 1;
864             }
866             # Only require ansi2knr files if they should appear in
867             # this directory.
868             if ($options{'ansi2knr'} eq 'ansi2knr')
869             {
870                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
871                                          'ansi2knr.c', 'ansi2knr.1');
872                 $output_rules .= &file_contents ('kr-extra');
873                 push (@clean, 'krextra');
874                 &push_phony_cleaners ('krextra');
875             }
877             # Generate rules to build ansi2knr.  If it is in some
878             # other directory, then generate dependencies but have the
879             # rule just run elsewhere.
880             $objext = $seen_objext ? ".$(OBJEXT)" : ".o";
881             $output_rules .= ($options{'ansi2knr'} . ': '
882                               . $options{'ansi2knr'} . $objext . "\n");
883             if ($options{'ansi2knr'} eq 'ansi2knr')
884             {
885                 $output_rules .= ("\t\$(LINK) ansi2knr" . $objext
886                                   . " \$(LIBS)\n"
887                                   . "ansi2knr" . $objext
888                                   . ": \$(CONFIG_HEADER)\n\n");
889             }
890             else
891             {
892                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
893                                   . " && \$(MAKE) \$(AM_MAKEFLAGS) "
894                                   . "ansi2knr\n\n");
895                 # This is required for non-GNU makes.
896                 $output_rules .= ($options{'ansi2knr'} . $objext . ":\n");
897                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
898                                   . " && \$(MAKE) \$(AM_MAKEFLAGS)"
899                                   . " ansi2knr" . $objext . "\n\n");
900             }
902             # Make sure ansi2knr can be found: if no path specified,
903             # specify "./".
904             if ($options{'ansi2knr'} eq 'ansi2knr')
905             {
906                 # Substitution from AM_C_PROTOTYPES.  This makes it be
907                 # built only when necessary.
908                 &define_configure_variable ('ANSI2KNR');
909                 # ansi2knr needs to be built before subdirs, so unshift it.
910                 unshift (@all, '$(ANSI2KNR)');
911             }
912             else
913             {
914                 # Found in another directory.
915                 &define_variable ("ANSI2KNR", $options{'ansi2knr'});
916             }
918             $output_rules .= &file_contents ('clean-kr');
920             push (@clean, 'kr');
921             &push_phony_cleaners ('kr');
923             $included_knr_compile = 1;
924         }
925     }
927     return $extension;
930 # Call finish function for each language that was used.
931 sub finish_languages
933     local ($ext, $name, $lang, %done);
934     local ($non_c) = 1;
935     foreach $ext (sort keys %extension_seen)
936     {
937         $lang = $extension_map{$ext};
938         next if defined $done{$lang};
939         $done{$lang} = 1;
940         $non_c = 0 if $lang !~ /(objc|cxx|f77|ratfor)$/;
942         # Compute the function name of the finisher and then call it.
943         $name = 'lang_' . $lang . '_finish';
944         & $name ();
945     }
947     # If the project is entirely C++ or entirely Fortran 77, don't
948     # bother with the C stuff.  But if anything else creeps in, then use
949     # it.
950     if (! $non_c || scalar keys %suffix_rules > 0)
951     {
952         local ($ltcompile, $ltlink) = &libtool_compiler;
954         &define_configure_variable ('CFLAGS');
955         &define_compiler_variable ('COMPILE', $ltcompile,
956                                    '$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)');
957         &define_variable ('CCLD', '$(CC)');
958         &define_variable ('LINK', $ltlink . '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
959     }
962 # Output a rule to build from a YACC source.  The output from YACC is
963 # compiled with C or C++, depending on the extension of the YACC file.
964 sub output_yacc_build_rule
966     local ($yacc_suffix, $use_ylwrap, $c_suffix) = @_;
968     local ($suffix);
969     ($suffix = $yacc_suffix) =~ tr/y/c/;
970     push (@suffixes, $yacc_suffix, $suffix);
972     # Generate rule for c/c++.
973     $output_rules .= "$yacc_suffix$suffix:\n\t";
975     if ($use_ylwrap)
976     {
977         $output_rules .= ('$(SHELL) $(YLWRAP)'
978                           . ' "$(YACC)" $< y.tab.c $*' . $suffix
979                           . ' y.tab.h $*.h -- $(AM_YFLAGS) $(YFLAGS)');
980     }
981     else
982     {
983         $output_rules .= ('$(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*'
984                           . $suffix . "\n"
985                           . "\tif test -f y.tab.h; then \\\n"
986                           . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
987                           . "\telse :; fi");
988     }
989     $output_rules .= "\n";
992 sub output_lex_build_rule
994     local ($lex_suffix, $use_ylwrap) = @_;
995     local ($c_suffix);
997     ($c_suffix = $lex_suffix) =~ tr/l/c/;
998     push (@suffixes, $lex_suffix);
999     &define_configure_variable ('LEX_OUTPUT_ROOT');
1000     &define_configure_variable ('LEXLIB');
1001     $output_rules .= "$lex_suffix$c_suffix:\n\t";
1003     if ($use_ylwrap)
1004     {
1005         # Is the $@ correct here?  If so, why not use it in the ylwrap
1006         # build rule for yacc above?
1007         $output_rules .= '$(SHELL) $(YLWRAP)'
1008             . ' "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(AM_LFLAGS) $(LFLAGS)';
1009     }
1010     else
1011     {
1012         $output_rules .= '$(LEX) $(AM_LFLAGS) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
1013     }
1014     $output_rules .= "\n";
1018 # Check to make sure a source defined in LIBOBJS is not explicitly
1019 # mentioned.  This is a separate function (as opposed to being inlined
1020 # in handle_source_transform) because it isn't always appropriate to
1021 # do this check.
1022 sub check_libobjs_sources
1024     local ($one_file, $unxformed) = @_;
1026     local ($prefix, $file, @files);
1027     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1028                      'dist_EXTRA_', 'nodist_EXTRA_')
1029     {
1030         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1031         {
1032             @files = &variable_value_as_list (($prefix
1033                                                . $one_file . '_SOURCES'),
1034                                               'all');
1035         }
1036         elsif ($prefix eq '')
1037         {
1038             @files = ($unxformed . '.c');
1039         }
1040         else
1041         {
1042             next;
1043         }
1045         foreach $file (@files)
1046         {
1047             if (defined $libsources{$file})
1048             {
1049                 &am_line_error ($prefix . $one_file . '_SOURCES',
1050                                 "automatically discovered file \`$file' should not be explicitly mentioned");
1051             }
1052         }
1053     }
1056 # Does much of the actual work for handle_source_transform.
1057 # Arguments are:
1058 #   object extension (e.g., `$U.lo')
1059 #   list of source files to transform
1060 # Result is a list
1061 #   first element is name of linker to use (empty string for default linker)
1062 #   remaining elements are names of objects
1063 sub handle_single_transform_list
1065     local ($obj, @files) = @_;
1066     local (@result) = ();
1067     local ($nonansi_obj) = $obj;
1068     $nonansi_obj =~ s/_//g;
1069     local (%linkers_used) = ();
1070     if (@files > 0)
1071     {
1072         # Turn sources into objects.
1073         foreach (@files)
1074         {
1075             # Skip things that look like configure substitutions.
1076             next if /^\@.*\@$/;
1078             # If the source file is in a subdirectory then the `.o' is
1079             # put into the current directory.
1081             # Split file name into base and extension.
1082             local ($full, $directory, $base, $extension, $linker, $object);
1083             next if ! /^((.*)\/)?([^\/]*)\.(.*)$/;
1084             $full = $_;
1085             $directory = $2;
1086             $base = $3;
1087             $extension = $4;
1089             local ($lang) = $extension_map{$extension};
1090             if ($lang)
1091             {
1092                 &saw_extension ($extension);
1093                 # Found the language, so see what it says.
1094                 local ($subr) = 'lang_' . $lang . '_rewrite';
1095                 # Note: computed subr call.
1096                 local ($r) = & $subr ($base, $extension);
1097                 # Skip this entry if we were asked not to process it.
1098                 next if $r == $LANG_IGNORE;
1100                 # Now extract linker and other info.
1101                 $linker = $language_map{$lang . '-linker'};
1103                 if ($language_map{$lang . '-ansi-p'})
1104                 {
1105                     $object = $base . $obj;
1106                 }
1107                 else
1108                 {
1109                     $object = $base . $nonansi_obj;
1110                 }
1112                 # If rewrite said it was ok, put the object into a
1113                 # subdir.
1114                 if ($r == $LANG_SUBDIR && $directory ne '')
1115                 {
1116                     $object = $directory . '/' . $object;
1117                 }
1118             }
1119             elsif ($extension =~ /^$source_suffix_pattern$/) 
1120             {
1121                 # We just rewrite it.  Maybe we should do more.
1122                 $object = $base . '.' . $suffix_rules{$extension};
1123                 $linker = '';
1124             }
1125             else
1126             {
1127                 # No error message here.  Used to have one, but it was
1128                 # very unpopular.
1129                 next;
1130             }
1132             $linkers_used{$linker} = 1;
1134             push (@result, $object);
1136             if (defined $object_map{$object})
1137             {
1138                 if ($object_map{$object} ne $full)
1139                 {
1140                     &am_error ("object \`$object' created by \`$full' and \`$object_map{$object}'");
1141                 }
1142             }
1143             else
1144             {
1145                 local (@dep_list) = ();
1146                 $object_map{$object} = $full;
1148                 # If file is in subdirectory, we need explicit
1149                 # dependency.
1150                 if ($directory ne '')
1151                 {
1152                     push (@dep_list, $full);
1153                 }
1155                 # If resulting object is in subdir, we need to make
1156                 # sure the subdir exists at build time.
1157                 if ($object =~ /\//)
1158                 {
1159                     push (@dep_list, $directory . '/.dirstamp');
1160                     $output_rules .= ($directory . "/.dirstamp:\n"
1161                                       . "\t\@\$(mkinstalldirs) $directory\n"
1162                                       . "\t\@: > $directory/.dirstamp\n");
1163                 }
1165                 &pretty_print_rule ($object . ':', "\t", @dep_list);
1166             }
1168             # Transform .o or $o file into .P file (for automatic
1169             # dependency code).
1170             # FIXME: LANG_SUBDIR.
1171             $dep_files{'.deps/' . $base . '.P'} = 1;
1172         }
1173     }
1175     return (&resolve_linker (%linkers_used), @result);
1178 # Handle SOURCE->OBJECT transform for one program or library.
1179 # Arguments are:
1180 #   canonical (transformed) name of object to build
1181 #   actual name of object to build
1182 #   object extension (ie either `.o' or `$o'.
1183 # Return result is name of linker variable that must be used.
1184 # Empty return means just use `LINK'.
1185 sub handle_source_transform
1187     # one_file is canonical name.  unxformed is given name.  obj is
1188     # object extension.
1189     local ($one_file, $unxformed, $obj) = @_;
1191     local ($linker) = '';
1193     if (&variable_defined ($one_file . "_OBJECTS"))
1194     {
1195         &am_line_error ($one_file . '_OBJECTS',
1196                         $one_file . '_OBJECTS', 'should not be defined');
1197         # No point in continuing.
1198         return;
1199     }
1201     local (@files, @result, $prefix, $temp, $xpfx);
1202     local (%used_pfx) = ();
1203     foreach $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1204                      'dist_EXTRA_', 'nodist_EXTRA_')
1205     {
1206         # We are going to define _OBJECTS variables using the prefix.
1207         # Then we glom them all together.  So we can't use the null
1208         # prefix here as we need it later.
1209         $xpfx = ($prefix eq '') ? 'am_' : $prefix;
1211         @files = ();
1212         local ($var) = $prefix . $one_file . "_SOURCES";
1213         if (&variable_defined ($var))
1214         {
1215             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1216             push (@objects, '$(' . $xpfx . $one_file . "_OBJECTS)")
1217                 unless $prefix =~ /EXTRA_/;
1218             push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
1219                 unless $prefix =~ /^nodist_/;
1220             local (@conds) = &variable_conditions ($var);
1221             if (! @conds)
1222             {
1223                 @files = &variable_value_as_list ($var, '');
1224             }
1225             else
1226             {
1227                 local ($cond);
1228                 foreach $cond (@conds)
1229                 {
1230                     @files = &variable_value_as_list ($var, $cond);
1231                     ($temp, @result) = &handle_single_transform_list ($obj,
1232                                                                       @files);
1233                     $linker = $temp if $linker eq '';
1235                     # Define _OBJECTS conditionally.
1236                     &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
1237                                              $cond, @result)
1238                         unless $prefix =~ /EXTRA_/;
1239                 }
1241                 # Keep track of which prefixes we saw.
1242                 $used_pfx{$xpfx} = 1
1243                     unless $prefix =~ /EXTRA_/;
1245                 next;
1246             }
1247         }
1249         # Avoid defining needless variables.
1250         next if (scalar @files == 0);
1252         # Keep track of which prefixes we saw.
1253         $used_pfx{$xpfx} = 1
1254             unless $prefix =~ /EXTRA_/;
1256         ($temp, @result) = &handle_single_transform_list ($obj, @files);
1257         $linker = $temp if $linker eq '';
1258         &define_pretty_variable ($xpfx . $one_file . "_OBJECTS", '', @result)
1259             unless $prefix =~ /EXTRA_/;
1260     }
1262     local (@keys) = sort keys %used_pfx;
1263     if (scalar @keys == 0)
1264     {
1265         &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1266         push (@sources, $unxformed . '.c');
1267         push (@dist_sources, $unxformed . '.c');
1268         push (@objects, $unxformed . $obj);
1269         push (@files, $unxformed . '.c');
1271         ($temp, @result) = &handle_single_transform_list ($obj, @files);
1272         $linker = $temp if $linker eq '';
1273         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
1274     }
1275     else
1276     {
1277         grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
1278         &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
1279     }
1281     return $linker;
1284 # Handle the BUILT_SOURCES variable.
1285 sub handle_built_sources
1287     return unless &variable_defined ('BUILT_SOURCES');
1289     local (@sources) = &variable_value_as_list ('BUILT_SOURCES', 'all');
1290     local ($s);
1291     foreach $s (@sources)
1292     {
1293         if (/^\@.*\@$/)
1294         {
1295             # FIXME: is this really the right thing to do?
1296             &am_line_error ('BUILT_SOURCES',
1297                             "\`BUILT_SOURCES' should not contain a configure substitution");
1298             last;
1299         }
1300     }
1302     # We don't care about the return value of this function.  We just
1303     # want to make sure to update %dep_files with the contents of
1304     # BUILT_SOURCES.
1305     &handle_single_transform_list (".o", @sources);
1308 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1309 # Also, generate _DEPENDENCIES variable if appropriate.
1310 # Arguments are:
1311 #   transformed name of object being built, or empty string if no object
1312 #   name of _LDADD/_LIBADD-type variable to examine
1313 #   boolean (lex_seen) which is true if a lex source file was seen in this
1314 #     object.  valid only for LDADDs, not LIBADDs.
1315 # Returns 1 if LIBOBJS seen, 0 otherwise.
1316 sub handle_lib_objects
1318     local ($xname, $var, $lex_seen) = @_;
1319     local ($ret);
1321     die "automake: programming error 1 in handle_lib_objects\n"
1322         if ! &variable_defined ($var);
1324     die "automake: programming error 2 in handle_lib_objects\n"
1325         if $lex_seen && $var =~ /LIBADD/;
1327     local (@conds) = &variable_conditions ($var);
1328     if (! @conds)
1329     {
1330         $ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
1331     }
1332     else
1333     {
1334         local ($cond);
1335         $ret = 0;
1336         foreach $cond (@conds)
1337         {
1338             if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
1339             {
1340                 $ret = 1;
1341             }
1342         }
1343     }
1345     return $ret;
1348 # Subroutine of handle_lib_objects: handle a particular condition.
1349 sub handle_lib_objects_cond
1351     local ($xname, $var, $lex_seen, $cond) = @_;
1353     # We recognize certain things that are commonly put in LIBADD or
1354     # LDADD.
1355     local ($lsearch);
1356     local (@dep_list) = ();
1358     local ($seen_libobjs) = 0;
1359     local ($flagvar) = 0;
1361     foreach $lsearch (&variable_value_as_list ($var, $cond))
1362     {
1363         # Skip -lfoo and -Ldir; these are explicitly allowed.
1364         next if $lsearch =~ /^-[lL]/;
1365         if (! $flagvar && $lsearch =~ /^-/)
1366         {
1367             if ($var =~ /^(.*)LDADD$/)
1368             {
1369                 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
1370                 next if $lsearch =~ /^-dl(pre)?open$/;
1371                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1372             }
1373             else
1374             {
1375                 # Only get this error once.
1376                 $flagvar = 1;
1377                 &am_line_error ($var, "you cannot use linker flags such as \`$lsearch' in \`$var'");
1378             }
1379         }
1381         # Assume we have a file of some sort, and push it onto the
1382         # dependency list.  Autoconf substitutions are not pushed;
1383         # rarely is a new dependency substituted into (eg) foo_LDADD
1384         # -- but "bad things (eg -lX11) are routinely substituted.
1385         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1386         # and handled specially below.
1387         push (@dep_list, $lsearch)
1388             unless $lsearch =~ /^\@.*\@$/;
1390         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1391         # means adding entries to dep_files.
1392         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1393         {
1394             push (@dep_list, $lsearch);
1395             $seen_libobjs = 1;
1396             if (! keys %libsources)
1397             {
1398                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
1399             }
1401             local ($iter, $rewrite);
1402             foreach $iter (keys %libsources)
1403             {
1404                 if ($iter =~ /\.([cly])$/)
1405                 {
1406                     &saw_extension ($1);
1407                     &saw_extension ('c');
1408                 }
1410                 if ($iter =~ /\.h$/)
1411                 {
1412                     &require_file_with_line ($var, $FOREIGN, $iter);
1413                 }
1414                 elsif ($iter ne 'alloca.c')
1415                 {
1416                     ($rewrite = $iter) =~ s/\.c$/.P/;
1417                     $dep_files{'.deps/' . $rewrite} = 1;
1418                     &require_file_with_line ($var, $FOREIGN, $iter);
1419                 }
1420             }
1421         }
1422         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1423         {
1424             push (@dep_list, $lsearch);
1425             &am_line_error ($var,
1426                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
1427                 if ! defined $libsources{'alloca.c'};
1428             $dep_files{'.deps/alloca.P'} = 1;
1429             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1430             &saw_extension ('c');
1431         }
1432     }
1434     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
1435     {
1436         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
1437     }
1439     return $seen_libobjs;
1442 # Canonicalize a name, and check to make sure the non-canonical name
1443 # is never used.  Returns canonical name.  Arguments are name and a
1444 # list of suffixes to check for.
1445 sub check_canonical_spelling
1447     local ($name, @suffixes) = @_;
1448     local ($xname, $xt);
1450     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
1451     if ($xname ne $name)
1452     {
1453         local ($xt);
1454         foreach $xt (@suffixes)
1455         {
1456             &am_line_error ($name . $xt,
1457                             "invalid variable \`" . $name . $xt
1458                             . "'; should be \`" . $xname . $xt . "'")
1459                 if &variable_defined ($name . $xt);
1460         }
1461     }
1463     return $xname;
1466 # Handle C programs.
1467 sub handle_programs
1469     local (@proglist) = &am_install_var ('-clean',
1470                                          'progs', 'PROGRAMS',
1471                                          'bin', 'sbin', 'libexec', 'pkglib',
1472                                          'noinst', 'check');
1473     return if ! @proglist;
1475     # If a program is installed, this is required.  We only want this
1476     # error to appear once.
1477     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1478         unless $seen_arg_prog;
1479     $seen_arg_prog = 1;
1481     local ($one_file, $xname, $munge);
1483     local ($seen_libobjs) = 0;
1484     foreach $one_file (@proglist)
1485     {
1486         local ($obj) = &get_object_extension ($one_file);
1488         # Canonicalize names and check for misspellings.
1489         $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
1490                                             '_SOURCES', '_OBJECTS',
1491                                             '_DEPENDENCIES');
1493         # FIXME: Using a trick to figure out if any lex sources appear
1494         # in our program; should use some cleaner method.
1495         local ($lex_num) = scalar (keys %lex_sources);
1496         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1497         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1499         local ($xt) = '';
1500         if (&variable_defined ($xname . "_LDADD"))
1501         {
1502             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1503                                      $lex_file_seen))
1504             {
1505                 $seen_libobjs = 1;
1506             }
1507             $lex_file_seen = 0;
1508             $xt = '_LDADD';
1509         }
1510         else
1511         {
1512             # User didn't define prog_LDADD override.  So do it.
1513             &define_variable ($xname . '_LDADD', '$(LDADD)');
1515             # This does a bit too much work.  But we need it to
1516             # generate _DEPENDENCIES when appropriate.
1517             if (&variable_defined ('LDADD'))
1518             {
1519                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1520                 {
1521                     $seen_libobjs = 1;
1522                 }
1523                 $lex_file_seen = 0;
1524             }
1525             elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
1526             {
1527                 &define_variable ($xname . '_DEPENDENCIES', '');
1528             }
1529             $xt = '_SOURCES'
1530         }
1532         if (&variable_defined ($xname . '_LIBADD'))
1533         {
1534             &am_line_error ($xname . '_LIBADD',
1535                             "use \`" . $xname . "_LDADD', not \`"
1536                             . $xname . "_LIBADD'");
1537         }
1539         if (! &variable_defined ($xname . '_LDFLAGS'))
1540         {
1541             # Define the prog_LDFLAGS variable.
1542             &define_variable ($xname . '_LDFLAGS', '');
1543         }
1545         # Determine program to use for link.
1546         local ($xlink);
1547         if (&variable_defined ($xname . '_LINK'))
1548         {
1549             $xlink = $xname . '_LINK';
1550         }
1551         else
1552         {
1553             $xlink = $linker ? $linker : 'LINK';
1554         }
1556         local ($xexe);
1557         if ($seen_exeext && $one_file !~ /\./)
1558         {
1559             $xexe = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
1560         }
1561         else
1562         {
1563             $xexe = 's/\@EXEEXT\@//g;';
1564         }
1566         $output_rules .=
1567             &file_contents_with_transform
1568                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1569                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1570                  . 's/\@XLINK\@/' . $xlink . '/go;'
1571                  . $xexe,
1572                  'program');
1573     }
1575     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1576     {
1577         $seen_libobjs = 1;
1578     }
1580     if ($seen_libobjs)
1581     {
1582         foreach $one_file (@proglist)
1583         {
1584             # Canonicalize names.
1585             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1587             if (&variable_defined ($xname . '_LDADD'))
1588             {
1589                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1590             }
1591             elsif (&variable_defined ('LDADD'))
1592             {
1593                 &check_libobjs_sources ($xname, 'LDADD');
1594             }
1595         }
1596     }
1600 # Handle libraries.
1601 sub handle_libraries
1603     local (@liblist) = &am_install_var ('-clean',
1604                                         'libs', 'LIBRARIES',
1605                                         'lib', 'pkglib', 'noinst', 'check');
1606     return if ! @liblist;
1608     local (%valid) = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
1609                                            'noinst', 'check');
1610     if (! defined $configure_vars{'RANLIB'})
1611     {
1612         local ($key);
1613         foreach $key (keys %valid)
1614         {
1615             if (&variable_defined ($key . '_LIBRARIES'))
1616             {
1617                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1618                 # Only get this error once.  If this is ever printed,
1619                 # we have a bug.
1620                 $configure_vars{'RANLIB'} = 'BUG';
1621                 last;
1622             }
1623         }
1624     }
1626     local ($onelib);
1627     local ($munge);
1628     local ($xlib);
1629     local ($seen_libobjs) = 0;
1630     foreach $onelib (@liblist)
1631     {
1632         # Check that the library fits the standard naming convention.
1633         if ($onelib !~ /^lib.*\.a$/)
1634         {
1635             # FIXME should put line number here.  That means mapping
1636             # from library name back to variable name.
1637             &am_error ("\`$onelib' is not a standard library name");
1638         }
1640         local ($obj) = &get_object_extension ($onelib);
1642         # Canonicalize names and check for misspellings.
1643         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
1644                                            '_OBJECTS', '_DEPENDENCIES');
1646         if (&variable_defined ($xlib . '_LIBADD'))
1647         {
1648             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1649             {
1650                 $seen_libobjs = 1;
1651             }
1652         }
1653         else
1654         {
1655             # Generate support for conditional object inclusion in
1656             # libraries.
1657             &define_variable ($xlib . "_LIBADD", '');
1658         }
1660         if (&variable_defined ($xlib . '_LDADD'))
1661         {
1662             &am_line_error ($xlib . '_LDADD',
1663                             "use \`" . $xlib . "_LIBADD', not \`"
1664                             . $xlib . "_LDADD'");
1665         }
1667         # Make sure we at look at this.
1668         &examine_variable ($xlib . '_DEPENDENCIES');
1670         &handle_source_transform ($xlib, $onelib, $obj);
1672         $output_rules .=
1673             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1674                                            . 's/\@XLIBRARY\@/'
1675                                            . $xlib . '/go;',
1676                                            'library');
1677     }
1679     if ($seen_libobjs)
1680     {
1681         foreach $onelib (@liblist)
1682         {
1683             # Canonicalize names.
1684             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1685             if (&variable_defined ($xlib . '_LIBADD'))
1686             {
1687                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1688             }
1689         }
1690     }
1692     &define_variable ('AR', 'ar');
1693     &define_configure_variable ('RANLIB');
1696 # Handle shared libraries.
1697 sub handle_ltlibraries
1699     local (@liblist) = &am_install_var ('-clean',
1700                                         'ltlib', 'LTLIBRARIES',
1701                                         'noinst', 'lib', 'pkglib');
1702     return if ! @liblist;
1704     local (%instdirs);
1705     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
1706                                            'noinst');
1708     local ($key);
1709     foreach $key (keys %valid)
1710     {
1711         if (&variable_defined ($key . '_LTLIBRARIES'))
1712         {
1713             if (!$seen_libtool)
1714             {
1715                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
1716                 # Only get this error once.  If this is ever printed,
1717                 # we have a bug.
1718                 $configure_vars{'LIBTOOL'} = 'BUG';
1719                 $seen_libtool = 1;
1720             }
1722             # Get the installation directory of each library.
1723             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
1724             {
1725                 if ($instdirs{$_})
1726                 {
1727                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1728                 }
1729                 else
1730                 {
1731                     $instdirs{$_} = $key;
1732                 }
1733             }
1734         }
1735     }
1737     local ($onelib);
1738     local ($munge);
1739     local ($xlib);
1740     local ($seen_libobjs) = 0;
1741     foreach $onelib (@liblist)
1742     {
1743         local ($obj) = &get_object_extension ($onelib);
1745         # Canonicalize names and check for misspellings.
1746         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
1747                                            '_SOURCES', '_OBJECTS',
1748                                            '_DEPENDENCIES');
1750         if (! &variable_defined ($xlib . '_LDFLAGS'))
1751         {
1752             # Define the lib_LDFLAGS variable.
1753             &define_variable ($xlib . '_LDFLAGS', '');
1754         }
1756         # Check that the library fits the standard naming convention.
1757         $libname_rx = "^lib.*\.la";
1758         if (&variable_value ($xlib . '_LDFLAGS') =~ /-module/) 
1759         {
1760                 # Relax name checking for libtool modules.
1761                 $libname_rx = "\.la";
1762         }
1763         if ($onelib !~ /$libname_rx$/)
1764         {
1765             # FIXME this should only be a warning for foreign packages
1766             # FIXME should put line number here.  That means mapping
1767             # from library name back to variable name.
1768             &am_error ("\`$onelib' is not a standard libtool library name");
1769         }
1771         if (&variable_defined ($xlib . '_LIBADD'))
1772         {
1773             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1774             {
1775                 $seen_libobjs = 1;
1776             }
1777         }
1778         else
1779         {
1780             # Generate support for conditional object inclusion in
1781             # libraries.
1782             &define_variable ($xlib . "_LIBADD", '');
1783         }
1785         if (&variable_defined ($xlib . '_LDADD'))
1786         {
1787             &am_line_error ($xlib . '_LDADD',
1788                             "use \`" . $xlib . "_LIBADD', not \`"
1789                             . $xlib . "_LDADD'");
1790         }
1792         # Make sure we at look at this.
1793         &examine_variable ($xlib . '_DEPENDENCIES');
1795         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
1797         # Determine program to use for link.
1798         local ($xlink);
1799         if (&variable_defined ($xlib . '_LINK'))
1800         {
1801             $xlink = $xlib . '_LINK';
1802         }
1803         else
1804         {
1805             $xlink = $linker ? $linker : 'LINK';
1806         }
1808         local ($rpath);
1809         if ($instdirs{$onelib} eq 'EXTRA' || $instdirs{$onelib} eq 'noinst')
1810         {
1811             # It's an EXTRA_ library, so we can't specify -rpath,
1812             # because we don't know where the library will end up.
1813             # The user probably knows, but generally speaking automake
1814             # doesn't -- and in fact configure could decide
1815             # dynamically between two different locations.
1816             $rpath = 's/\@RPATH\@//go;';
1817         }
1818         else
1819         {
1820             $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
1821                       . 'dir)/go;');
1822         }
1824         $output_rules .=
1825             &file_contents_with_transform ('s/\@LTLIBRARY\@/'
1826                                            . $onelib . '/go;'
1827                                            . 's/\@XLTLIBRARY\@/'
1828                                            . $xlib . '/go;'
1829                                            . $rpath
1830                                            . 's/\@XLINK\@/' . $xlink . '/go;',
1831                                            'ltlibrary');
1832     }
1834     if ($seen_libobjs)
1835     {
1836         foreach $onelib (@liblist)
1837         {
1838             # Canonicalize names.
1839             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1840             if (&variable_defined ($xlib . '_LIBADD'))
1841             {
1842                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1843             }
1844         }
1845     }
1848 # See if any _SOURCES variable were misspelled.  Also, make sure that
1849 # EXTRA_ variables don't contain configure substitutions.
1850 sub check_typos
1852     local ($varname, $primary);
1853     foreach $varname (keys %contents)
1854     {
1855         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
1856                           '_DEPENDENCIES')
1857         {
1858             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
1859             {
1860                 &am_line_error ($varname,
1861                                 "invalid unused variable name: \`$varname'");
1862             }
1863         }
1864     }
1867 # Handle scripts.
1868 sub handle_scripts
1870     # NOTE we no longer automatically clean SCRIPTS, because it is
1871     # useful to sometimes distribute scripts verbatim.  This happens
1872     # eg in Automake itself.
1873     &am_install_var ('-candist', 'scripts', 'SCRIPTS',
1874                      'bin', 'sbin', 'libexec', 'pkgdata',
1875                      'noinst', 'check');
1877     local ($scripts_installed) = 0;
1878     # Set $scripts_installed if appropriate.  Make sure we only find
1879     # scripts which are actually installed -- this is why we can't
1880     # simply use the return value of am_install_var.
1881     local (%valid) = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
1882                                            'libexec', 'pkgdata',
1883                                            'noinst', 'check');
1884     local ($key);
1885     foreach $key (keys %valid)
1886     {
1887         if ($key ne 'noinst'
1888             && $key ne 'check'
1889             && &variable_defined ($key . '_SCRIPTS'))
1890         {
1891             $scripts_installed = 1;
1892             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
1893         }
1894     }
1896     if ($scripts_installed)
1897     {
1898         # If a program is installed, this is required.  We only want this
1899         # error to appear once.
1900         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1901             unless $seen_arg_prog;
1902         $seen_arg_prog = 1;
1903     }
1906 # Search a file for a "version.texi" Texinfo include.  Return the name
1907 # of the include file if found, or the empty string if not.  A
1908 # "version.texi" file is actually any file whose name matches
1909 # "vers*.texi".
1910 sub scan_texinfo_file
1912     local ($filename) = @_;
1914     if (! open (TEXI, $filename))
1915     {
1916         &am_error ("couldn't open \`$filename': $!");
1917         return '';
1918     }
1919     print "automake: reading $filename\n" if $verbose;
1921     local ($vfile, $outfile);
1922     while (<TEXI>)
1923     {
1924         if (/^\@setfilename +(\S+)/)
1925         {
1926             $outfile = $1;
1927             last if ($vfile);
1928         }
1930         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
1931         {
1932             # Found version.texi include.
1933             $vfile = $1;
1934             last if $outfile;
1935         }
1936     }
1938     close (TEXI);
1939     return ($outfile, $vfile);
1942 # Handle all Texinfo source.
1943 sub handle_texinfo
1945     &am_line_error ('TEXINFOS',
1946                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
1947         if &variable_defined ('TEXINFOS');
1948     return if (! &variable_defined ('info_TEXINFOS')
1949                && ! &variable_defined ('html_TEXINFOS'));
1951     if (&variable_defined ('html_TEXINFOS'))
1952     {
1953         &am_line_error ('html_TEXINFOS',
1954                         "HTML generation not yet supported");
1955         return;
1956     }
1958     local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');
1960     local (@info_deps_list, @dvis_list, @texi_deps);
1961     local ($infobase, $info_cursor);
1962     local (%versions);
1963     local ($done) = 0;
1964     local ($vti);
1965     local ($tc_cursor, @texi_cleans);
1966     local ($canonical);
1968     foreach $info_cursor (@texis)
1969     {
1970         # FIXME: This is mildly hacky, since it recognizes "txinfo".
1971         # I don't feel like making it right.
1972         ($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;
1974         # If 'version.texi' is referenced by input file, then include
1975         # automatic versioning capability.
1976         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
1977                                                         . "/" . $info_cursor);
1979         if ($out_file eq '')
1980         {
1981             &am_error ("\`$info_cursor' missing \@setfilename");
1982             next;
1983         }
1985         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
1986         {
1987             # FIXME should report line number in input file.
1988             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
1989             next;
1990         }
1992         if ($vtexi)
1993         {
1994             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
1995                 if (defined $versions{$vtexi});
1996             $versions{$vtexi} = $info_cursor;
1998             # We number the stamp-vti files.  This is doable since the
1999             # actual names don't matter much.  We only number starting
2000             # with the second one, so that the common case looks nice.
2001             $vti = 'vti' . ($done ? $done : '');
2002             &push_dist_common ($vtexi, 'stamp-' . $vti);
2003             push (@clean, $vti);
2005             # Only require once.
2006             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2007                                           'mdate-sh')
2008                 if ! $done;
2009             ++$done;
2011             local ($conf_pat, $conf_dir);
2012             if ($config_aux_dir eq '.' || $config_aux_dir eq '')
2013             {
2014                 $conf_dir = '$(srcdir)/';
2015             }
2016             else
2017             {
2018                 $conf_dir = $config_aux_dir;
2019                 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
2020             }
2021             ($conf_pat = $conf_dir) =~ s/(\W)/\\$1/g;
2022             $output_rules .=
2023                 &file_contents_with_transform
2024                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
2025                      . 's/\@VTI\@/' . $vti . '/g; '
2026                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
2027                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
2028                      'texi-vers');
2030             &push_phony_cleaners ($vti);
2031         }
2033         # If user specified file_TEXINFOS, then use that as explicit
2034         # dependency list.
2035         @texi_deps = ();
2036         push (@texi_deps, $info_cursor);
2037         push (@texi_deps, $vtexi) if $vtexi;
2039         # Canonicalize name first.
2040         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
2041         if (&variable_defined ($canonical . "_TEXINFOS"))
2042         {
2043             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
2044             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
2045         }
2047         $output_rules .= ("\n" . $out_file . ": "
2048                           . join (' ', @texi_deps)
2049                           . "\n" . $infobase . ".dvi: "
2050                           . join (' ', @texi_deps)
2051                           . "\n\n");
2053         push (@info_deps_list, $out_file);
2054         push (@dvis_list, $infobase . '.dvi');
2056         # Generate list of things to clean for this target.  We do
2057         # this explicitly because otherwise too many things could be
2058         # removed.  In particular the ".log" extension might
2059         # reasonably be used in other contexts by the user.
2060         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns', 'pgs',
2061                             'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
2062                             'vr', 'vrs', 'op', 'tr', 'cv', 'cn')
2063         {
2064             push (@texi_cleans, $infobase . '.' . $tc_cursor);
2065         }
2066     }
2068     # Find these programs wherever they may lie.  Yes, this has
2069     # intimate knowledge of the structure of the texinfo distribution.
2070     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
2071                               'makeinfo',
2072                               # Circumlocution to avoid accidental
2073                               # configure substitution.
2074                               '@MAKE' . 'INFO@');
2075     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
2076                               'texi2dvi');
2078     # Set transform for including texinfos.am.  First, handle --cygnus
2079     # stuff.
2080     local ($xform);
2081     if ($cygnus_mode)
2082     {
2083         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
2084     }
2085     else
2086     {
2087         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
2088     }
2090     # Handle location of texinfo.tex.
2091     local ($need_texi_file) = 0;
2092     local ($texinfo_tex);
2093     if ($cygnus_mode)
2094     {
2095         $texinfo_tex = '$(top_srcdir)/../texinfo/texinfo.tex';
2096         &define_variable ('TEXINFO_TEX', $texinfo_tex);
2098     }
2099     elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
2100     {
2101         $texinfo_tex = $config_aux_dir . '/texinfo.tex';
2102         &define_variable ('TEXINFO_TEX', $texinfo_tex);
2103         $need_texi_file = 2; # so that we require_conf_file later
2104     }
2105     elsif (&variable_defined ('TEXINFO_TEX'))
2106     {
2107         # The user defined TEXINFO_TEX so assume he knows what he is
2108         # doing.
2109         $texinfo_tex = ('$(srcdir)/'
2110                         . &dirname (&variable_value ('TEXINFO_TEX')));
2111     }
2112     else
2113     {
2114         $texinfo_tex = '$(srcdir)/texinfo.tex';
2115         $need_texi_file = 1;
2116     }
2117     local ($xxform);
2118     ($xxform = $texinfo_tex) =~ s/\/texinfo\.tex$//;
2119     $xxform =~ s/(\W)/\\$1/g;
2120     $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';
2122     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
2123     push (@phony, 'install-info-am', 'uninstall-info');
2124     push (@dist_targets, 'dist-info');
2126     # How to clean.  The funny name is due to --cygnus influence; in
2127     # Cygnus mode, `clean-info' is a target that users can use.
2128     $output_rules .= "\nmostlyclean-aminfo:\n";
2129     &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
2130     $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
2131                       . "maintainer-clean-aminfo:\n\t"
2132                       # Eww.  But how else can we find all the output
2133                       # files from makeinfo?
2134                       . ($cygnus_mode ? '' : 'cd $(srcdir) && ')
2135                       . 'for i in $(INFO_DEPS); do' . " \\\n"
2136                       . "\t" . '  rm -f $$i;' . " \\\n"
2137                       . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
2138                       . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
2139                       . "\t" . '  fi;' . " \\\n"
2140                       . "\tdone\n");
2141     &push_phony_cleaners ('aminfo');
2142     if ($cygnus_mode)
2143     {
2144         $output_rules .= "clean-info: mostlyclean-aminfo\n";
2145     }
2147     push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');
2149     if (! defined $options{'no-installinfo'})
2150     {
2151         push (@uninstall, 'uninstall-info');
2152         push (@installdirs, '$(DESTDIR)$(infodir)');
2153         unshift (@install_data, 'install-info-am');
2155         # Make sure documentation is made and installed first.  Use
2156         # $(INFO_DEPS), not 'info', because otherwise recursive makes
2157         # get run twice during "make all".
2158         unshift (@all, '$(INFO_DEPS)');
2159     }
2160     push (@clean, 'aminfo');
2161     push (@info, '$(INFO_DEPS)');
2162     push (@dvi, '$(DVIS)');
2164     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2165     &define_variable ("DVIS", join (' ', @dvis_list));
2166     # This next isn't strictly needed now -- the places that look here
2167     # could easily be changed to look in info_TEXINFOS.  But this is
2168     # probably better, in case noinst_TEXINFOS is ever supported.
2169     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
2171     # Do some error checking.  Note that this file is not required
2172     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2173     # up above.
2174     if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
2175     {
2176         if ($need_texi_file > 1)
2177         {
2178             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2179                                           'texinfo.tex');
2180         }
2181         else
2182         {
2183             &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
2184         }
2185     }
2188 # Handle any man pages.
2189 sub handle_man_pages
2191     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
2192         if &variable_defined ('MANS');
2193     return if ! &variable_defined ('man_MANS');
2195     # Find all the sections in use.  We do this by first looking for
2196     # "standard" sections, and then looking for any additional
2197     # sections used in man_MANS.
2198     local ($sect, %sections, %vlist);
2199     # Add more sections as needed.
2200     foreach $sect ('0'..'9', 'n', 'l')
2201     {
2202         if (&variable_defined ('man' . $sect . '_MANS'))
2203         {
2204             $sections{$sect} = 1;
2205             $vlist{'$(man' . $sect . '_MANS)'} = 1;
2206         }
2207     }
2209     if (&variable_defined ('man_MANS'))
2210     {
2211         $vlist{'$(man_MANS)'} = 1;
2212         foreach (&variable_value_as_list ('man_MANS', 'all'))
2213         {
2214             # A page like `foo.1c' goes into man1dir.
2215             if (/\.([0-9a-z])([a-z]*)$/)
2216             {
2217                 $sections{$1} = 1;
2218             }
2219         }
2220     }
2223     # Now for each section, generate an install and unintall rule.
2224     # Sort sections so output is deterministic.
2225     local (@namelist);
2226     foreach $sect (sort keys %sections)
2227     {
2228         &define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
2229         push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
2230             unless defined $options{'no-installman'};
2231         $output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
2232                                                         . $sect . '/g;',
2233                                                         'mans');
2234         push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
2235         push (@namelist, 'install-man' . $sect);
2236     }
2238     # We don't really need this, but we use it in case we ever want to
2239     # support noinst_MANS.
2240     &define_variable ("MANS", join (' ', sort keys %vlist));
2242     # Generate list of install dirs.
2243     $output_rules .= ("install-man: \$(MANS)\n"
2244                       . "\t\@\$(NORMAL_INSTALL)\n");
2245     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2246     push (@phony, 'install-man');
2248     $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
2249     grep ($_ = 'un' . $_, @namelist);
2250     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
2251     push (@phony, 'uninstall-man');
2253     $output_vars .= &file_contents ('mans-vars');
2255     if (! defined $options{'no-installman'})
2256     {
2257         push (@install_data, 'install-man');
2258         push (@uninstall, 'uninstall-man');
2259         push (@all, '$(MANS)');
2260     }
2263 # Handle DATA variables.
2264 sub handle_data
2266     &am_install_var ('-noextra', '-defaultdist', 'data', 'DATA',
2267                      'data', 'sysconf', 'sharedstate', 'localstate',
2268                      'pkgdata', 'noinst', 'check');
2271 # Handle TAGS.
2272 sub handle_tags
2274     push (@phony, 'tags');
2275     local (@tag_deps) = ();
2276     if (&variable_defined ('SUBDIRS'))
2277     {
2278         $output_rules .= ("tags-recursive:\n"
2279                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
2280                           # Never fail here if a subdir fails; it
2281                           # isn't important.
2282                           . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
2283                           . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
2284                           . "\tdone\n");
2285         push (@tag_deps, 'tags-recursive');
2286         push (@phony, 'tags-recursive');
2287     }
2289     if (&saw_sources_p (1)
2290         || &variable_defined ('ETAGS_ARGS')
2291         || @tag_deps)
2292     {
2293         local ($xform) = '';
2294         local ($one_hdr);
2295         foreach $one_hdr (@config_headers)
2296         {
2297             if ($relative_dir eq &dirname ($one_hdr))
2298             {
2299                 # The config header is in this directory.  So require it.
2300                 local ($var);
2301                 ($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
2302                 $xform .= ' ' if $xform;
2303                 $xform .= $var;
2304             }
2305         }
2306         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
2307                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
2309         if (&variable_defined ('SUBDIRS'))
2310         {
2311             $xform .= 's/^SUBDIRS//;';
2312         }
2313         else
2314         {
2315             $xform .= 's/^SUBDIRS.*$//;';
2316         }
2318         $output_rules .= &file_contents_with_transform ($xform, 'tags');
2319         $output_rules .= &file_contents ('tags-clean');
2320         push (@clean, 'tags');
2321         &push_phony_cleaners ('tags');
2322         &examine_variable ('TAGS_DEPENDENCIES');
2323     }
2324     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2325     {
2326         &am_line_error ('TAGS_DEPENDENCIES',
2327                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2328     }
2329     else
2330     {
2331         # Every Makefile must define some sort of TAGS rule.
2332         # Otherwise, it would be possible for a top-level "make TAGS"
2333         # to fail because some subdirectory failed.
2334         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2335     }
2338 # Handle multilib support.
2339 sub handle_multilib
2341     return unless $seen_multilib;
2343     $output_rules .= &file_contents ('multilib.am');
2344     &push_phony_cleaners ('multi');
2345     push (@phony, 'all-multi', 'install-multi');
2348 # Worker for handle_dist.
2349 sub handle_dist_worker
2351     local ($makefile) = @_;
2353     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
2355     # Initialization; only at top level.
2356     if ($relative_dir eq '.')
2357     {
2358         if (defined $options{'check-news'})
2359         {
2360             # For Gnits users, this is pretty handy.  Look at 15 lines
2361             # in case some explanatory text is desirable.
2362             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
2363           echo "NEWS not updated; not releasing" 1>&2; \\
2364           exit 1; \\
2365         fi
2367         }
2370         # Create dist directory.
2371         $output_rules .= ("\t-rm -rf \$(distdir)\n"
2372                           . "\tmkdir \$(distdir)\n"
2373                           . "\t-chmod 777 \$(distdir)\n");
2374     }
2376     # Only run automake in `dist' target if --include-deps and
2377     # `no-dependencies' not specified.  That way the recipient of a
2378     # distribution can run "make dist" and not need Automake.  You
2379     # might be wondering why we run automake once for each directory
2380     # we distribute, instead of running it once at the top level.  The
2381     # answer is that we want to run automake after the dependencies
2382     # have been generated.  This occurs when "make" is run in the
2383     # subdir.  So automake must be run after make has updated the
2384     # Makefile, which means that it must run once per directory.
2385     if ($use_dependencies)
2386     {
2387         $output_rules .=
2388             (
2389              # There are several directories we need to know about
2390              # when rebuilding the Makefile.ins.  They are:
2391              #   here - The absolute path to our topmost build directory.
2392              #   top_distdir - The absolute path to the top of our dist
2393              #                 hierarchy.
2394              #   distdir - The path to our sub-part of the dist hierarchy.
2395              # If this directory is the topmost directory, we set
2396              # top_distdir from distdir; that lets us pass in distdir
2397              # from an enclosing package.
2398              "\t" . 'here=`cd $(top_builddir) && pwd`; ' . "\\\n"
2399              . "\t" . 'top_distdir=`cd $('
2400              . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
2401              . ') && pwd`; ' . "\\\n"
2402              . "\t" . 'distdir=`cd $(distdir) && pwd`; ' . "\\\n"
2403              . "\tcd \$(top_srcdir) \\\n"
2404              . "\t  && \$(AUTOMAKE) --include-deps --build-dir=\$\$here --srcdir-name=\$(top_srcdir) --output-dir=\$\$top_distdir "
2405              # Set strictness of output.
2406              . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2407              . ($cmdline_use_dependencies ? '' : ' --include-deps')
2408              . " " . $makefile . "\n"
2409              );
2410     }
2412     # Scan EXTRA_DIST to see if we need to distribute anything from a
2413     # subdir.  If so, add it to the list.  I didn't want to do this
2414     # originally, but there were so many requests that I finally
2415     # relented.
2416     local (@dist_dirs);
2417     if (&variable_defined ('EXTRA_DIST'))
2418     {
2419         # FIXME: This should be fixed to work with conditionals.  That
2420         # will require only making the entries in @dist_dirs under the
2421         # appropriate condition.  This is meaningful if the nature of
2422         # the distribution should depend upon the configure options
2423         # used.
2424         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
2425         {
2426             next if /^\@.*\@$/;
2427             next unless s,/+[^/]+$,,;
2428             push (@dist_dirs, $_)
2429                 unless $_ eq '.';
2430         }
2431     }
2432     if (@dist_dirs)
2433     {
2434         # Prepend $(distdir) to each directory given.  Doing it via a
2435         # hash lets us ensure that each directory is used only once.
2436         local (%dhash);
2437         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
2438         $output_rules .= "\t";
2439         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
2440     }
2442     # In loop, test for file existence because sometimes a file gets
2443     # included in DISTFILES twice.  For example this happens when a
2444     # single source file is used in building more than one program.
2445     # Also, there are situations in which "ln" can fail.  For instance
2446     # a file to distribute could actually be a cross-filesystem
2447     # symlink -- this can easily happen if "gettextize" was run on the
2448     # distribution.
2449     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
2450     if ($cygnus_mode)
2451     {
2452         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
2453     }
2454     else
2455     {
2456         $output_rules .= "\t  d=\$(srcdir); \\\n";
2457     }
2458     $output_rules .= ("\t  if test -d \$\$d/\$\$file; then \\\n"
2459                       . "\t    cp -pr \$\$d/\$\$file \$(distdir)/\$\$file; \\\n"
2460                       . "\t  else \\\n"
2461                       . "\t    test -f \$(distdir)/\$\$file \\\n"
2462                       . "\t    || ln \$\$d/\$\$file \$(distdir)/\$\$file 2> /dev/null \\\n"
2463                       . "\t    || cp -p \$\$d/\$\$file \$(distdir)/\$\$file || :; \\\n"
2464                       . "\t  fi; \\\n"
2465                       . "\tdone\n");
2467     # If we have SUBDIRS, create all dist subdirectories and do
2468     # recursive build.
2469     if (&variable_defined ('SUBDIRS'))
2470     {
2471         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
2472         # to all possible directories, and use it.  If DIST_SUBDIRS is
2473         # defined, just use it.
2474         local ($dist_subdir_name);
2475         if (&variable_conditions ('SUBDIRS')
2476             || &variable_defined ('DIST_SUBDIRS'))
2477         {
2478             $dist_subdir_name = 'DIST_SUBDIRS';
2479             if (! &variable_defined ('DIST_SUBDIRS'))
2480             {
2481                 &define_pretty_variable ('DIST_SUBDIRS', '',
2482                                          &variable_value_as_list ('SUBDIRS',
2483                                                                   'all'));
2484             }
2485         }
2486         else
2487         {
2488             $dist_subdir_name = 'SUBDIRS';
2489         }
2491         # Test for directory existence here because previous automake
2492         # invocation might have created some directories.  Note that
2493         # we explicitly set distdir for the subdir make; that lets us
2494         # mix-n-match many automake-using packages into one large
2495         # package, and have "dist" at the top level do the right
2496         # thing.  If we're in the topmost directory, then we use
2497         # `distdir' instead of `top_distdir'; this lets us work
2498         # correctly with an enclosing package.
2499         $output_rules .= 
2500             ("\t" . 'for subdir in $(' . $dist_subdir_name . '); do ' . "\\\n"
2501              . "\t" . '  if test "$$subdir" = .; then :; else ' . "\\\n"
2502              . "\t" . '    test -d $(distdir)/$$subdir ' . "\\\n"
2503              . "\t" . '    || mkdir $(distdir)/$$subdir ' . "\\\n"
2504              . "\t" . '    || exit 1; ' . "\\\n"
2505              . "\t" . '    chmod 777 $(distdir)/$$subdir; ' . "\\\n"
2506              . "\t" . '    (cd $$subdir'
2507              . ' && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$('
2508              . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
2509              . ') distdir=../$(distdir)/$$subdir distdir) ' . "\\\n"
2510              . "\t" . '      || exit 1; ' . "\\\n"
2511              . "\t" . '  fi; ' . "\\\n"
2512              . "\tdone\n");
2513     }
2515     # If the target `dist-hook' exists, make sure it is run.  This
2516     # allows users to do random weird things to the distribution
2517     # before it is packaged up.
2518     push (@dist_targets, 'dist-hook') if &target_defined ('dist-hook');
2520     local ($targ);
2521     foreach $targ (@dist_targets)
2522     {
2523         # We must explicitly set distdir and top_distdir for these
2524         # sub-makes.
2525         $output_rules .= ("\t\$(MAKE) \$(AM_MAKEFLAGS)"
2526                           . " top_distdir=\"\$(top_distdir)\""
2527                           . " distdir=\"\$(distdir)\" $targ\n");
2528     }
2530     push (@phony, 'distdir');
2533 # Handle 'dist' target.
2534 sub handle_dist
2536     local ($makefile) = @_;
2538     # Set up maint_charset.
2539     $local_maint_charset = &variable_value ('MAINT_CHARSET')
2540         if &variable_defined ('MAINT_CHARSET');
2541     $maint_charset = $local_maint_charset
2542         if $relative_dir eq '.';
2544     if (&variable_defined ('DIST_CHARSET'))
2545     {
2546         &am_line_error ('DIST_CHARSET',
2547                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2548             if ! $local_maint_charset;
2549         if ($relative_dir eq '.')
2550         {
2551             $dist_charset = &variable_value ('DIST_CHARSET')
2552         }
2553         else
2554         {
2555             &am_line_error ('DIST_CHARSET',
2556                             "DIST_CHARSET can only be defined at top level");
2557         }
2558     }
2560     # Look for common files that should be included in distribution.
2561     local ($cfile);
2562     foreach $cfile (@common_files)
2563     {
2564         if (-f ($relative_dir . "/" . $cfile))
2565         {
2566             &push_dist_common ($cfile);
2567         }
2568     }
2570     # Always require configure.in and configure at top level, even if
2571     # they don't exist.  This is especially important for configure,
2572     # since it won't be created until autoconf is run -- which might
2573     # be after automake is run.
2574     &push_dist_common ('configure.in', 'configure')
2575         if $relative_dir eq '.';
2577     # Keys of %dist_common are names of files to distributed.  We put
2578     # README first because it then becomes easier to make a
2579     # Usenet-compliant shar file (in these, README must be first).
2580     # FIXME: do more ordering of files here.
2581     local (@coms);
2582     if (defined $dist_common{'README'})
2583     {
2584         push (@coms, 'README');
2585         delete $dist_common{'README'};
2586     }
2587     push (@coms, sort keys %dist_common);
2589     &define_pretty_variable ("DIST_COMMON", '', @coms);
2590     $output_vars .= "\n";
2592     # Some boilerplate.
2593     $output_vars .= &file_contents ('dist-vars') . "\n";
2594     &define_variable ('GZIP_ENV', '--best');
2596     # Put these things in rules section so it is easier for whoever
2597     # reads Makefile.in.
2598     if (! &variable_defined ('distdir'))
2599     {
2600         if ($relative_dir eq '.')
2601         {
2602             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2603         }
2604         else
2605         {
2606             $output_rules .= ("\n"
2607                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2608                               . "\n");
2609         }
2610     }
2611     if ($relative_dir eq '.')
2612     {
2613         $output_rules .= "top_distdir = \$(distdir)\n\n";
2614     }
2615     else
2616     {
2617         $output_rules .= "\nsubdir = " . $relative_dir . "\n\n";
2618     }
2620     # Generate 'dist' target, and maybe other dist targets.
2621     if ($relative_dir eq '.')
2622     {
2623         # Rule to check whether a distribution is viable.
2624         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
2625 # it guarantees that the distribution is self-contained by making another
2626 # tarfile.
2627 distcheck: dist
2628         -rm -rf $(distdir)
2629         GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(TAR) xf -
2630         mkdir $(distdir)/=build
2631         mkdir $(distdir)/=inst
2632         dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
2633                           . (&target_defined ('distcheck-hook')
2634                              ? ("\n\t\$(MAKE) \$(AM_MAKEFLAGS)"
2635                                 . " distcheck-hook; \\")
2636                              : '')
2637                           . '
2638         cd $(distdir)/=build \\
2639           && ../configure '
2641                           . ($seen_gettext ? '--with-included-gettext ' : '')
2642                           . '--srcdir=.. --prefix=$$dc_install_base \\
2643           && $(MAKE) $(AM_MAKEFLAGS) \\
2644           && $(MAKE) $(AM_MAKEFLAGS) dvi \\
2645           && $(MAKE) $(AM_MAKEFLAGS) check \\
2646           && $(MAKE) $(AM_MAKEFLAGS) install \\
2647           && $(MAKE) $(AM_MAKEFLAGS) installcheck \\
2648           && $(MAKE) $(AM_MAKEFLAGS) dist
2649         -rm -rf $(distdir)
2650         @banner="$(distdir).tar.gz is ready for distribution"; \\
2651         dashes=`echo "$$banner" | sed s/./=/g`; \\
2652         echo "$$dashes"; \\
2653         echo "$$banner"; \\
2654         echo "$$dashes"
2657         local ($dist_all) = ('dist-all: distdir' . "\n"
2658                              . $dist_header);
2659         local ($curs);
2660         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ',
2661                        'dist-bzip2')
2662         {
2663             if (defined $options{$curs} || $curs eq 'dist')
2664             {
2665                 $output_rules .= ($curs . ': distdir' . "\n"
2666                                   . $dist_header
2667                                   . $dist{$curs}
2668                                   . $dist_trailer);
2669                 $dist_all .= $dist{$curs};
2670             }
2671         }
2672         $output_rules .= $dist_all . $dist_trailer;
2673     }
2675     # Generate distdir target.
2676     &handle_dist_worker ($makefile);
2679 # Scan a single dependency file and rewrite the dependencies as
2680 # appropriate.  Essentially this means:
2681 # * Clean out absolute dependencies which are not desirable.
2682 # * Rewrite other dependencies to be relative to $(top_srcdir).
2683 sub scan_dependency_file
2685     local ($depfile) = @_;
2687     if (! open (DEP_FILE, $depfile))
2688     {
2689         &am_error ("couldn't open \`$depfile': $!");
2690         return;
2691     }
2692     print "automake: reading $depfile\n" if $verbose;
2694     # Sometimes it is necessary to omit some dependencies.
2695     local (%omit) = %omit_dependencies;
2696     if (&variable_defined ('OMIT_DEPENDENCIES'))
2697     {
2698         # FIXME: Doesn't work with conditionals.  I'm not sure if this
2699         # matters.
2700         grep ($omit{$_} = 1,
2701               &variable_value_as_list ('OMIT_DEPENDENCIES', ''));
2702     }
2704     local ($first_line) = 1;
2705     local ($last_line) = 0;
2706     local ($target, @dependencies);
2707     local ($one_dep, $xform);
2708     local ($just_file);
2710     local ($srcdir_rx, $fixup_rx);
2711     ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
2712         =~ s/(\W)/\\$1/g;
2713     ($srcdir_rx = $srcdir_name . '/') =~ s/(\W)/\\$1/g;
2715     local ($rewrite_builddir) = (($top_builddir eq '.')
2716                                  ? ''
2717                                  : $top_builddir . '/');
2719     while (<DEP_FILE>)
2720     {
2721         last if $last_line;
2722         next if (/$WHITE_PATTERN/o);
2723         chop;
2724         if (! s/\\$//)
2725         {
2726             # No trailing "\" means this should be the last line of
2727             # the first target.  We can have multiple targets due to
2728             # the "deleted header file" fix.  For the generated
2729             # Makefile we simply skip these fake targets.
2730             $last_line = 1;
2731         }
2733         if ($first_line)
2734         {
2735             if (! /^([^:]+:)(.+)$/)
2736             {
2737               bad_format:
2738                 &am_error ("\`$depfile' has incorrect format");
2739                 close (DEP_FILE);
2740                 return;
2741             }
2743             $_ = $2;
2744             # Make sure to strip the .P file from the target.
2745             ($target = $1) =~ s, *\.deps/[^.]+\.P,,;
2747             $first_line = 0;
2748         }
2750         foreach $one_dep (split (' ', $_))
2751         {
2752             ($just_file = $one_dep) =~ s,^.*/,,;
2753             next if defined $omit{$just_file};
2755             if ($one_dep =~ /^$fixup_rx/)
2756             {
2757                 # The dependency points to the current directory in
2758                 # some way.
2759                 ($xform = $one_dep) =~ s/^$fixup_rx//;
2760                 push (@dependencies, $xform);
2761             }
2762             elsif ($one_dep =~ /^$srcdir_rx/)
2763             {
2764                 # The dependency is in some other directory in the package.
2765                 ($xform = $one_dep) =~ s/^$srcdir_rx/$rewrite_builddir/;
2766                 push (@dependencies, $xform);
2767             }
2768             elsif ($one_dep =~ /^\// || $one_dep =~ /^[A-Za-z]:\\/)
2769             {
2770                 # Absolute path; ignore.
2771             }
2772             else
2773             {
2774                 # Anything else is assumed to be correct.
2775                 push (@dependencies, $one_dep);
2776             }
2777         }
2778     }
2780     &pretty_print_rule ($target, "\t", @dependencies);
2782     close (DEP_FILE);
2785 # Handle auto-dependency code.
2786 sub handle_dependencies
2788     # Make sure this variable is always marked as used.
2789     &examine_variable ('OMIT_DEPENDENCIES');
2791     if ($use_dependencies)
2792     {
2793         # Include GNU-make-specific auto-dep code.  Don't include it
2794         # if DEP_FILES would be empty.
2795         if (&saw_sources_p (0) && keys %dep_files)
2796         {
2797             &define_pretty_variable ('DEP_FILES', '', sort keys %dep_files);
2798             $output_rules .= &file_contents ('depend');
2799             push (@clean, 'depend');
2800             &push_phony_cleaners ('depend');
2802             local ($key, $lang, $ext, $xform);
2803             foreach $key (sort keys %language_map)
2804             {
2805                 next unless $key =~ /^(.*)-autodep$/;
2806                 next if $language_map{$key} eq 'no';
2807                 $lang = $1;
2809                 $xform = 's/\@PFX\@/' . $language_map{$key} . '/g;';
2810                 foreach $ext (&lang_extensions ($lang))
2811                 {
2812                     $output_rules .=
2813                         &file_contents_with_transform ('s/\@EXT\@/'
2814                                                        . $ext . '/g;'
2815                                                        . $xform,
2816                                                        'depend2');
2817                 }
2818             }
2819         }
2820     }
2821     elsif ($build_directory ne '')
2822     {
2823         # Include any auto-generated deps that are present.  Note that
2824         # $build_directory ends in a "/".
2825         if (-d ($build_directory . $relative_dir . "/.deps"))
2826         {
2827             local ($depfile);
2829             foreach $depfile (&my_glob ($build_directory
2830                                         . $relative_dir . "/.deps/*.P"))
2831             {
2832                 &scan_dependency_file ($depfile);
2833             }
2835             $output_rules .= "\n";
2836         }
2837     }
2840 # Handle subdirectories.
2841 sub handle_subdirs
2843     return if ! &variable_defined ('SUBDIRS');
2845     # Make sure each directory mentioned in SUBDIRS actually exists.
2846     local ($dir);
2847     foreach $dir (&variable_value_as_list ('SUBDIRS', 'all'))
2848     {
2849         # Skip directories substituted by configure.
2850         next if $dir =~ /^\@.*\@$/;
2852         if (! -d $am_relative_dir . '/' . $dir)
2853         {
2854             &am_line_error ('SUBDIRS',
2855                             "required directory $am_relative_dir/$dir does not exist");
2856             next;
2857         }
2859         &am_line_error ('SUBDIRS', "directory should not contain \`/'")
2860             if $dir =~ /\//;
2861     }
2863     local ($xform) = ('s/\@INSTALLINFO\@/' .
2864                       (defined $options{'no-installinfo'}
2865                        ? 'install-info-recursive'
2866                        : '')
2867                       . '/;');
2868     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
2870     # Push a bunch of phony targets.
2871     local ($phonies);
2872     foreach $phonies ('-data', '-exec', 'dirs')
2873     {
2874         push (@phony, 'install' . $phonies . '-recursive');
2875         push (@phony, 'uninstall' . $phonies . '-recursive');
2876     }
2877     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
2878     {
2879         push (@phony, $phonies . '-recursive');
2880     }
2881     &push_phony_cleaners ('recursive');
2883     $recursive_install = 1;
2886 # Handle aclocal.m4.
2887 sub handle_aclocal_m4
2889     local ($regen_aclocal) = 0;
2890     if (-f 'aclocal.m4')
2891     {
2892         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
2893         &push_dist_common ('aclocal.m4');
2895         if (open (ACLOCAL, '< aclocal.m4'))
2896         {
2897             local ($line);
2898             $line = <ACLOCAL>;
2899             close (ACLOCAL);
2901             if ($line =~ 'generated automatically by aclocal')
2902             {
2903                 $regen_aclocal = 1;
2904             }
2905         }
2906     }
2908     local ($acinclude) = 0;
2909     if (-f 'acinclude.m4')
2910     {
2911         $regen_aclocal = 1;
2912         $acinclude = 1;
2913     }
2915     # Note that it might be possible that aclocal.m4 doesn't exist but
2916     # should be auto-generated.  This case probably isn't very
2917     # important.
2918     if ($regen_aclocal)
2919     {
2920         local (@ac_deps) = (
2921                             ($seen_maint_mode
2922                              ? "\@MAINTAINER_MODE_TRUE\@"
2923                              : "") ,
2924                             "configure.in",
2925                             ($acinclude ? ' acinclude.m4' : '')
2926                             );
2928         # Scan all -I directories for m4 files.  These are our
2929         # dependencies.
2930         if (&variable_defined ('ACLOCAL_AMFLAGS'))
2931         {
2932             local ($examine_next, $amdir) = 0;
2933             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
2934             {
2935                 if ($examine_next)
2936                 {
2937                     $examine_next = 0;
2938                     if ($amdir !~ /^\// && -d $amdir)
2939                     {
2940                         push (@ac_deps, &my_glob ($amdir . '/*.m4'));
2941                     }
2942                 }
2943                 elsif ($amdir eq '-I')
2944                 {
2945                     $examine_next = 1;
2946                 }
2947             }
2948         }
2950         &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
2952         $output_rules .=  ("\t"
2953                            . 'cd $(srcdir) && $(ACLOCAL)'
2954                            . (&variable_defined ('ACLOCAL_AMFLAGS')
2955                               ? ' $(ACLOCAL_AMFLAGS)' : '')
2956                            . "\n");
2957     }
2960 # Rewrite a list of input files into a form suitable to put on a
2961 # dependency list.  The idea is that if an input file has a directory
2962 # part the same as the current directory, then the directory part is
2963 # simply removed.  But if the directory part is different, then
2964 # $(top_srcdir) is prepended.  Among other things, this is used to
2965 # generate the dependency list for the output files generated by
2966 # AC_OUTPUT.  Consider what the dependencies should look like in this
2967 # case:
2968 #   AC_OUTPUT(src/out:src/in1:lib/in2)
2969 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
2970 # If 0 then files that require this addition will simply be ignored.
2971 sub rewrite_inputs_into_dependencies
2973     local ($add_srcdir, @inputs) = @_;
2974     local ($single, @newinputs);
2976     foreach $single (@inputs)
2977     {
2978         if (&dirname ($single) eq $relative_dir)
2979         {
2980             push (@newinputs, &basename ($single));
2981         }
2982         elsif ($add_srcdir)
2983         {
2984             push (@newinputs, '$(top_srcdir)/' . $single);
2985         }
2986     }
2988     return @newinputs;
2991 # Handle remaking and configure stuff.
2992 # We need the name of the input file, to do proper remaking rules.
2993 sub handle_configure
2995     local ($local, $input, @secondary_inputs) = @_;
2997     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
2998     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
2999         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
3001     local ($top_reldir);
3003     local ($input_base) = &basename ($input);
3004     local ($local_base) = &basename ($local);
3006     local ($amfile) = $input_base . '.am';
3007     # We know we can always add '.in' because it really should be an
3008     # error if the .in was missing originally.
3009     local ($infile) = '$(srcdir)/' . $input_base . '.in';
3010     local ($colon_infile);
3011     if ($local ne $input || @secondary_inputs)
3012     {
3013         $colon_infile = ':' . $input . '.in';
3014     }
3015     $colon_infile .= ':' . join (':', @secondary_inputs)
3016         if @secondary_inputs;
3018     local (@rewritten) = &rewrite_inputs_into_dependencies (1,
3019                                                             @secondary_inputs);
3021     # This rule remakes the Makefile.in.  Note use of
3022     # @MAINTAINER_MODE_TRUE@ forces us to abandon pretty-printing.
3023     # Sigh.
3024     $output_rules .= ($infile
3025                       # NOTE perl 5.003 (with -w) gives a
3026                       # uninitialized value error on the next line.
3027                       # Don't know why.
3028                       . ': '
3029                       . ($seen_maint_mode ? "\@MAINTAINER_MODE_TRUE\@ " : '')
3030                       . $amfile . ' '
3031                       . '$(top_srcdir)/configure.in $(ACLOCAL_M4)'
3032                       . ' ' . join (' ', @include_stack)
3033                       . "\n"
3034                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
3035                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
3036                       . ($cmdline_use_dependencies ? '' : ' --include-deps')
3037                       . ' ' . $input . $colon_infile . "\n\n");
3039     # This rule remakes the Makefile.
3040     $output_rules .= ($local_base
3041                       # NOTE: bogus uninit value error on next line;
3042                       # see comment above.
3043                       . ': '
3044                       . $infile . ' '
3045                       . join (' ', @rewritten)
3046                       . ' $(top_builddir)/config.status'
3047                       # NOTE: Makefile only depends on BUILT_SOURCES
3048                       # when dependencies are being computed.  This is
3049                       # a workaround for an obscure bug with
3050                       # AC_LINK_FILES.  Anyway, when dependencies are
3051                       # turned off, this shouldn't matter.
3052                       . ($use_dependencies ? ' $(BUILT_SOURCES)' : '')
3053                       . "\n"
3054                       . "\tcd \$(top_builddir) \\\n"
3055                       . "\t  && CONFIG_FILES="
3056                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3057                       . $colon_infile
3058                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
3059                       . "\n\n");
3061     if ($relative_dir ne '.')
3062     {
3063         # In subdirectory.
3064         $top_reldir = '../';
3065     }
3066     else
3067     {
3068         &handle_aclocal_m4;
3069         $output_rules .= &file_contents ('remake');
3070         &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3071         &examine_variable ('CONFIGURE_DEPENDENCIES');
3072         $top_reldir = '';
3073     }
3075     # Make it easy to see if there is a Makefile.am in a given
3076     # directory.
3077     local (%make_dirs, $iter);
3078     foreach $iter (@input_files)
3079     {
3080         $make_dirs{&dirname ($iter)} = 1;
3081     }
3082     # We also want to notice Makefile.in's.
3083     foreach $iter (@other_input_files)
3084     {
3085         if ($iter =~ /Makefile\.in$/)
3086         {
3087             $make_dirs{&dirname ($iter)} = 1;
3088         }
3089     }
3091     # If we have a configure header, require it.
3092     local ($one_hdr);
3093     local (@local_fullnames) = @config_fullnames;
3094     local (@local_names) = @config_names;
3095     local ($hdr_index) = 0;
3096     local ($distclean_config) = '';
3097     foreach $one_hdr (@config_headers)
3098     {
3099         local ($one_fullname) = shift (@local_fullnames);
3100         local ($one_name) = shift (@local_names);
3101         $hdr_index += 1;
3102         local ($header_dir) = &dirname ($one_name);
3104         # If the header is in the current directory we want to build
3105         # the header here.  Otherwise, if we're at the topmost
3106         # directory and the header's directory doesn't have a
3107         # Makefile, then we also want to build the header.
3108         if ($relative_dir eq $header_dir
3109             || ($relative_dir eq '.' && ! defined $make_dirs{$header_dir}))
3110         {
3111             local ($ch_sans_dir, $cn_sans_dir, $stamp_dir);
3112             if ($relative_dir eq $header_dir)
3113             {
3114                 $cn_sans_dir = &basename ($one_name);
3115                 $stamp_dir = '';
3116             }
3117             else
3118             {
3119                 $cn_sans_dir = $one_name;
3120                 if ($header_dir eq '.')
3121                 {
3122                     $stamp_dir = '';
3123                 }
3124                 else
3125                 {
3126                     $stamp_dir = $header_dir . '/';
3127                 }
3128             }
3130             # Compute relative path from directory holding output
3131             # header to directory holding input header.  FIXME:
3132             # doesn't handle case where we have multiple inputs.
3133             if (&dirname ($one_hdr) eq $relative_dir)
3134             {
3135                 $ch_sans_dir = &basename ($one_hdr);
3136             }
3137             else
3138             {
3139                 local (@rel_out_path);
3140                 # FIXME this chunk of code should be its own sub.
3141                 # It is used elsewhere.
3142                 foreach (split (/\//, $relative_dir))
3143                 {
3144                     next if $_ eq '' || $_ eq '.';
3145                     if ($_ eq '..')
3146                     {
3147                         # FIXME: actually this is an error.
3148                         pop @rel_out_path;
3149                     }
3150                     else
3151                     {
3152                         push (@rel_out_path, '..');
3153                     }
3154                 }
3155                 if (@rel_out_path)
3156                 {
3157                     $ch_sans_dir = join ('/', @rel_out_path) . '/' . $one_hdr;
3158                 }
3159                 else
3160                 {
3161                     $ch_sans_dir = $one_hdr;
3162                 }
3163             }
3165             &require_file_with_conf_line ($config_header_line,
3166                                           $FOREIGN, $ch_sans_dir);
3168             # Header defined and in this directory.
3169             local (@files);
3170             if (-f $relative_dir . '/acconfig.h')
3171             {
3172                 push (@files, 'acconfig.h');
3173             }
3174             if (-f $one_name . '.top')
3175             {
3176                 push (@files, "${cn_sans_dir}.top");
3177             }
3178             if (-f $one_name . '.bot')
3179             {
3180                 push (@files, "${cn_sans_dir}.bot");
3181             }
3183             &push_dist_common (@files);
3185             local ($stamp_name) = 'stamp-h';
3186             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3188             local ($xform) = '';
3190             $xform = 's,\@FILES\@,' . join (' ', @files) . ',;';
3191             $xform .= 's,\@CONFIG_HEADER\@,' . "${cn_sans_dir}" . ',;';
3192             $xform .= 's,\@CONFIG_HEADER_IN\@,' . "${ch_sans_dir}" . ',;';
3193             $xform .= 's,\@CONFIG_HEADER_FULL\@,' . "${one_fullname}" . ',;';
3194             $xform .= 's,\@STAMP\@,' . "${stamp_dir}${stamp_name}" . ',g;';
3196             $output_rules .= &file_contents_with_transform ($xform,
3197                                                             'remake-hdr');
3199             local ($out_dir) = &dirname ($ch_sans_dir);
3200             &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3201             &require_file_with_conf_line ($config_header_line, $FOREIGN,
3202                                           "${out_dir}/${stamp_name}.in");
3204             $distclean_config .= ' ' if $distclean_config;
3205             $distclean_config .= $cn_sans_dir;
3206         }
3207     }
3209     if ($distclean_config)
3210     {
3211         $output_rules .= &file_contents_with_transform ('s,\@FILES\@,'
3212                                                         . $distclean_config
3213                                                         . ',;',
3214                                                         'clean-hdr');
3215         push (@clean, 'hdr');
3216         &push_phony_cleaners ('hdr');
3217     }
3219     # Set location of mkinstalldirs.
3220     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
3221     {
3222         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
3223                                             . '/mkinstalldirs'));
3224     }
3225     else
3226     {
3227         &define_variable ('mkinstalldirs',
3228                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
3229     }
3231     &am_line_error ('CONFIG_HEADER',
3232                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
3233         if &variable_defined ('CONFIG_HEADER');
3235     local ($one_name);
3236     local ($config_header) = '';
3237     foreach $one_name (@config_names)
3238     {
3239         # Generate CONFIG_HEADER define.
3240         local ($one_hdr);
3241         if ($relative_dir eq &dirname ($one_name))
3242         {
3243             $one_hdr = &basename ($one_name);
3244         }
3245         else
3246         {
3247             $one_hdr = "${top_builddir}/${one_name}";
3248         }
3250         $config_header .= ' ' if $config_header;
3251         $config_header .= $one_hdr;
3252     }
3253     if ($config_header)
3254     {
3255         &define_variable ("CONFIG_HEADER", $config_header);
3256     }
3258     # Now look for other files in this directory which must be remade
3259     # by config.status, and generate rules for them.
3260     local (@actual_other_files) = ();
3261     local ($file, $local);
3262     local (@inputs, @rewritten_inputs, $single);
3263     local ($need_rewritten);
3264     foreach $file (@other_input_files)
3265     {
3266         if ($file =~ /^([^:]*):(.*)$/)
3267         {
3268             # This is the ":" syntax of AC_OUTPUT.
3269             $file = $1;
3270             $local = &basename ($file);
3271             @inputs = split (':', $2);
3272             @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3273             $need_rewritten = 1;
3274         }
3275         else
3276         {
3277             # Normal usage.
3278             $local = &basename ($file);
3279             @inputs = ($local . '.in');
3280             @rewritten_inputs =
3281                 &rewrite_inputs_into_dependencies (1, $file . '.in');
3282             $need_rewritten = 0;
3283         }
3285         # Skip files not in this directory.
3286         next unless &dirname ($file) eq $relative_dir;
3288         # Skip any file that is an automake input.
3289         next if -f $file . '.am';
3291         # Some users have been tempted to put `stamp-h' in the
3292         # AC_OUTPUT line.  This won't do the right thing, so we
3293         # explicitly fail here.
3294         if ($local eq 'stamp-h')
3295         {
3296             # FIXME: allow real filename.
3297             &am_conf_error ('configure.in', $ac_output_line,
3298                             'stamp-h should not appear in AC_OUTPUT');
3299             next;
3300         }
3302         $output_rules .= ($local . ': '
3303                           . '$(top_builddir)/config.status '
3304                           . join (' ', @rewritten_inputs) . "\n"
3305                           . "\t"
3306                           . 'cd $(top_builddir) && CONFIG_FILES='
3307                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3308                           . '$@' . ($need_rewritten
3309                                     ? (':' . join (':', @inputs))
3310                                     : '')
3311                           . ' CONFIG_HEADERS= $(SHELL) ./config.status'
3312                           . "\n");
3313         &push_dist_common (@inputs);
3314         push (@actual_other_files, $local);
3316         # Require all input files.
3317         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3318                                       &rewrite_inputs_into_dependencies (0, @inputs));
3319     }
3321     # These files get removed by "make clean".
3322     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3325 # Handle C headers.
3326 sub handle_headers
3328     local (@r);
3329     @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3330                           'oldinclude', 'pkginclude',
3331                           'noinst', 'check');
3332     foreach (@r)
3333     {
3334         next unless /\.(.*)$/;
3335         &saw_extension ($1);
3336     }
3339 sub handle_gettext
3341     return if ! $seen_gettext || $relative_dir ne '.';
3343     if (! &variable_defined ('SUBDIRS'))
3344     {
3345         &am_conf_error
3346             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
3347         return;
3348     }
3350     &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3352     if (&variable_defined ('SUBDIRS'))
3353     {
3354         &am_line_error
3355             ('SUBDIRS',
3356              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
3357                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
3358         &am_line_error
3359             ('SUBDIRS',
3360              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
3361                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
3362     }
3364     # Ensure that each language in ALL_LINGUAS has a .po file, and
3365     # each po file is mentioned in ALL_LINGUAS.
3366     if ($seen_linguas)
3367     {
3368         local (%linguas) = ();
3369         grep ($linguas{$_} = 1, split (' ', $all_linguas));
3371         foreach (<po/*.po>)
3372         {
3373             s/^po\///;
3374             s/\.po$//;
3376             &am_line_error ($all_linguas_line,
3377                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
3378                 if ! $linguas{$_};
3379         }
3381         foreach (keys %linguas)
3382         {
3383             &am_line_error ($all_linguas_line,
3384                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
3385                 if ! -f "po/$_.po";
3386         }
3387     }
3388     else
3389     {
3390         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
3391     }
3394 # Handle footer elements.
3395 sub handle_footer
3397     if ($contents{'SOURCES'})
3398     {
3399         # NOTE don't use define_pretty_variable here, because
3400         # $contents{...} is already defined.
3401         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
3402     }
3403     if ($contents{'OBJECTS'})
3404     {
3405         # NOTE don't use define_pretty_variable here, because
3406         # $contents{...} is already defined.
3407         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
3408     }
3409     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
3410     {
3411         $output_vars .= "\n";
3412     }
3414     if (&variable_defined ('SUFFIXES'))
3415     {
3416         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
3417         # make do not like variable substitutions on the .SUFFIXES
3418         # line.
3419         push (@suffixes, &variable_value_as_list ('SUFFIXES', ''));
3420     }
3421     if (&target_defined ('.SUFFIXES'))
3422     {
3423         &am_line_error ('.SUFFIXES',
3424                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
3425     }
3427     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3428     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3429     # anything else, by sticking it right after the default: target.
3430     $output_header .= ".SUFFIXES:\n";
3431     if (@suffixes)
3432     {
3434         # Make sure suffixes has unique elements.  Sort them to ensure
3435         # the output remains consistent.
3436         local (%suffixes);
3438         grep ($suffixes{$_} = 1, @suffixes);
3440         $output_header .= (".SUFFIXES: "
3441                            . join (' ', sort keys %suffixes)
3442                            . "\n");
3443     }
3444     $output_trailer .= &file_contents ('footer');
3447 # Deal with installdirs target.
3448 sub handle_installdirs
3450     # GNU Makefile standards recommend this.
3451     if ($recursive_install)
3452     {
3453         # We create a separate `-am' target so that the -recursive
3454         # rule will work correctly.
3455         $output_rules .= ("installdirs: installdirs-recursive\n"
3456                           . "installdirs-am:\n");
3457         push (@phony, 'installdirs-am');
3458     }
3459     else
3460     {
3461         $output_rules .= "installdirs:\n";
3462     }
3463     push (@phony, 'installdirs');
3464     if (@installdirs)
3465     {
3466         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
3467                             @installdirs);
3468     }
3469     $output_rules .= "\n";
3472 # There are several targets which need to be merged.  This is because
3473 # their complete definition is compiled from many parts.  Note that we
3474 # avoid double colon rules, otherwise we'd use them instead.
3475 sub handle_merge_targets
3477     local ($makefile) = @_;
3479     # There are a few install-related variables that you should not define.
3480     local ($var);
3481     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
3482     {
3483         if (&variable_defined ($var))
3484         {
3485             &am_line_error ($var, "\`$var' should not be defined");
3486         }
3487     }
3489     # Put this at the beginning for the sake of non-GNU makes.  This
3490     # is still wrong if these makes can run parallel jobs.  But it is
3491     # right enough.
3492     unshift (@all, &basename ($makefile));
3494     local ($one_name);
3495     foreach $one_name (@config_names)
3496     {
3497         push (@all, &basename ($one_name))
3498             if &dirname ($one_name) eq $relative_dir;
3499     }
3501     &do_one_merge_target ('info', @info);
3502     &do_one_merge_target ('dvi', @dvi);
3503     &do_check_merge_target;
3504     &do_one_merge_target ('installcheck', @installcheck);
3506     if (defined $options{'no-installinfo'})
3507     {
3508         &do_one_merge_target ('install-info', '');
3509     }
3510     elsif (&target_defined ('install-info-local'))
3511     {
3512         &am_line_error ('install-info-local',
3513                         "\`install-info-local' target defined but \`no-installinfo' option not in use");
3514     }
3516     local ($utarg);
3517     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3518                     'uninstall-exec-local', 'uninstall-exec-hook')
3519     {
3520         if (&target_defined ($utarg))
3521         {
3522             local ($x);
3523             ($x = $utarg) =~ s/(data|exec)-//;
3524             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3525         }
3526     }
3528     if (&target_defined ('install-local'))
3529     {
3530         &am_line_error ('install-local',
3531                         "use \`install-data-local' or \`install-exec-local', not \`install-local'");
3532     }
3534     if (@all)
3535     {
3536         local ($one_name);
3537         local ($local_headers) = '';
3538         foreach $one_name (@config_names)
3539         {
3540             if (&dirname ($one_name) eq $relative_dir)
3541             {
3542                 $local_headers .= ' ' if $local_headers;
3543                 $local_headers .= &basename ($one_name);
3544             }
3545         }
3546         if ($local_headers)
3547         {
3548             # This is kind of a hack, but I couldn't see a better way
3549             # to handle it.  In this particular case, we need to make
3550             # sure config.h is built before we recurse.  We can't do
3551             # this by changing the order of dependencies to the "all"
3552             # because that breaks when using parallel makes.  Instead
3553             # we handle things explicitly.
3554             $output_rules .= ("all-recursive-am: ${local_headers}"
3555                                   . "\n\t"
3556                                   . '$(MAKE) $(AM_MAKEFLAGS)'
3557                                   . " all-recursive"
3558                                   . "\n\n");
3559             $all_target = 'all-recursive-am';
3560             push (@phony, 'all-recursive-am');
3561         }
3562     }
3564     # Print definitions users can use.
3565     &do_one_merge_target ('install-exec', @install_exec);
3566     $output_rules .= "\n";
3568     &do_one_merge_target ('install-data', @install_data);
3569     $output_rules .= "\n";
3571     &do_one_merge_target ('install', 'all-am');
3572     &do_one_merge_target ('uninstall', @uninstall);
3574     &do_one_merge_target ('all', @all);
3576     # Generate the new 'install-strip' target.  We can't just set
3577     # INSTALL_PROGRAM because that might be a relative path.
3578     $output_rules .= ("install-strip:\n\t"
3579                       . '$(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install'
3580                       . "\n");
3581     push (@phony, 'install-strip');
3584 # Helper for handle_merge_targets.  Note that handle_merge_targets
3585 # relies on the fact that this doesn't add an extra \n at the end.
3586 sub do_one_merge_target
3588     local ($name, @values) = @_;
3590     if (&target_defined ($name . '-local'))
3591     {
3592         # User defined local form of target.  So include it.
3593         push (@values, $name . '-local');
3594         push (@phony, $name . '-local');
3595     }
3597     &pretty_print_rule ($name . "-am:", "\t\t", @values);
3598     if ($name eq 'install')
3599     {
3600         # Special-case `install-am' to run install-exec-am and
3601         # install-data-am after all-am is built.
3602         &pretty_print_rule ("\t\@\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3603                             'install-exec-am', 'install-data-am');
3604     }
3605     elsif ($name eq 'install-exec' && &target_defined ('install-exec-hook'))
3606     {
3607         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3608                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-exec-hook'
3609                           . "\n");
3610     }
3611     elsif ($name eq 'install-data' && &target_defined ('install-data-hook'))
3612     {
3613         $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
3614                           . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-data-hook'
3615                           . "\n");
3616     }
3618     local ($lname) = $name . ($recursive_install ? '-recursive' : '-am');
3619     local ($tname) = $name;
3620     # To understand this special case, see handle_merge_targets.
3621     if ($name eq 'all')
3622     {
3623         $tname = 'all-redirect';
3624         $lname = $all_target if $recursive_install;
3625         push (@phony, 'all-redirect');
3626         $output_all = "all: all-redirect\n";
3627     }
3628     &pretty_print_rule ($tname . ":", "\t\t", $lname);
3629     push (@phony, $name . '-am', $name);
3632 # Handle check merge target specially.
3633 sub do_check_merge_target
3635     if (&target_defined ('check-local'))
3636     {
3637         # User defined local form of target.  So include it.
3638         push (@check_tests, 'check-local');
3639         push (@phony, 'check-local');
3640     }
3642     # In --cygnus mode, check doesn't depend on all.
3643     if ($cygnus_mode)
3644     {
3645         # Just run the local check rules.
3646         &pretty_print_rule ('check-am:', "\t\t", @check);
3647     }
3648     else
3649     {
3650         # The check target must depend on the local equivalent of
3651         # `all', to ensure all the primary targets are built.  Then it
3652         # must build the local check rules.
3653         $output_rules .= "check-am: all-am\n";
3654         &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3655                             @check)
3656             if @check;
3657     }
3658     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
3659                         @check_tests)
3660         if @check_tests;
3662     push (@phony, 'check', 'check-am');
3663     $output_rules .= ("check: "
3664                       . ($recursive_install ? 'check-recursive' : 'check-am')
3665                       . "\n");
3668 # Handle all 'clean' targets.
3669 sub handle_clean
3671     local ($xform) = '';
3672     local ($name);
3674     # Don't include `MAINTAINER'; it is handled specially below.
3675     foreach $name ('MOSTLY', '', 'DIST')
3676     {
3677         if (! &variable_defined ($name . 'CLEANFILES'))
3678         {
3679             $xform .= 's/^' . $name . 'CLEAN.*$//;';
3680         }
3681         else
3682         {
3683             $xform .= 's/^' . $name . 'CLEAN//;';
3684         }
3685     }
3687     # Built sources are automatically removed by maintainer-clean.
3688     push (@maintainer_clean_files, '\$(BUILT_SOURCES)')
3689         if &variable_defined ('BUILT_SOURCES');
3690     push (@maintainer_clean_files, '\$(MAINTAINERCLEANFILES)')
3691         if &variable_defined ('MAINTAINERCLEANFILES');
3692     if (! @maintainer_clean_files)
3693     {
3694         $xform .= 's/^MAINTAINERCLEAN.*$//;';
3695     }
3696     else
3697     {
3698         $xform .= ('s/^MAINTAINERCLEAN//;'
3699                    # Join with no space to avoid spurious `test -z'
3700                    # success at runtime.
3701                    . 's,\@MCFILES\@,' . join ('', @maintainer_clean_files)
3702                    . ',;'
3703                    # A space is required in the join here.
3704                    . 's,\@MFILES\@,' . join (' ', @maintainer_clean_files)
3705                    . ',;');
3706     }
3708     $output_rules .= &file_contents_with_transform ($xform, 'clean');
3710     push (@clean, 'generic');
3711     &push_phony_cleaners ('generic');
3713     &do_one_clean_target ('clean', 'mostly', '', @clean);
3714     &do_one_clean_target ('clean', '', 'mostly', @clean);
3715     &do_one_clean_target ('clean', 'dist', '', @clean);
3716     &do_one_clean_target ('clean', 'maintainer-', 'dist', @clean);
3718     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
3721 # Helper for handle_clean.
3722 sub do_one_clean_target
3724     local ($target, $name, $last_name, @deps) = @_;
3726     # Change each dependency `BLARG' into `clean-BLARG'.
3727     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
3729     # Push the previous clean target.  There is no previous clean
3730     # target if we're doing mostlyclean.
3731     push (@deps, $last_name . $target . '-am')
3732         unless $name eq 'mostly';
3734     # If a -local version of the rule is given, add it to the list.
3735     if (&target_defined ($name . $target . '-local'))
3736     {
3737         push (@deps, $name . $target . '-local');
3738     }
3740     # Print the target and the dependencies.
3741     &pretty_print_rule ($name . $target . "-am: ", "\t\t", @deps);
3743     # FIXME: shouldn't we really print these messages before running
3744     # the dependencies?
3745     if ($name . $target eq 'maintainer-clean')
3746     {
3747         # Print a special warning.
3748         $output_rules .=
3749             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
3750              . "\t\@echo \"it deletes files that may require special "
3751              . "tools to rebuild.\"\n");
3752     }
3753     elsif ($name . $target eq 'distclean')
3754     {
3755         $output_rules .= "\t-rm -f libtool\n" if $seen_libtool;
3756     }
3757     $output_rules .= "\n";
3759     # Now generate the actual clean target.
3760     $output_rules .= ($name . $target . ": " . $name . $target
3761                       . ($recursive_install ? '-recursive' : '-am')
3762                       . "\n");
3764     # We special-case config.status here.  If we do it as part of the
3765     # normal clean processing for this directory, then it might be
3766     # removed before some subdir is cleaned.  However, that subdir's
3767     # Makefile depends on config.status.
3768     if (($name . $target eq 'maintainer-clean'
3769          || $name . $target eq 'distclean')
3770         && $relative_dir eq '.')
3771     {
3772         $output_rules .= "\t-rm -f config.status\n";
3773     }
3774     $output_rules .= "\n";
3777 # Handle .PHONY target.
3778 sub handle_phony
3780     &pretty_print_rule ('.PHONY:', "", @phony);
3781     $output_rules .= "\n";
3784 # Handle TESTS variable and other checks.
3785 sub handle_tests
3787     if (defined $options{'dejagnu'})
3788     {
3789         push (@check_tests, 'check-DEJAGNU');
3790         push (@phony, 'check-DEJAGNU');
3792         local ($xform);
3793         if ($cygnus_mode)
3794         {
3795             $xform = 's/^CYGNUS//;';
3796         }
3797         else
3798         {
3799             $xform = 's/^CYGNUS.*$//;';
3800         }
3801         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
3803         # In Cygnus mode, these are found in the build tree.
3804         # Otherwise they are looked for in $PATH.
3805         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
3806         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
3808         # Only create site.exp rule if user hasn't already written
3809         # one.
3810         if (! &target_defined ('site.exp'))
3811         {
3812             # Note that in the rule we don't directly generate
3813             # site.exp to avoid the possibility of a corrupted
3814             # site.exp if make is interrupted.  Jim Meyering has some
3815             # useful text on this topic.
3816             $output_rules .= ("site.exp: Makefile\n"
3817                               . "\t\@echo 'Making a new site.exp file...'\n"
3818                               . "\t\@test ! -f site.bak || rm -f site.bak\n"
3819                               . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
3820                               . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
3821                               . "\t\@echo '# edit the last section' >> \$\@-t\n"
3822                               . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
3823                               . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
3824                               . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
3826             # Extra stuff for AC_CANONICAL_*
3827             local (@whatlist) = ();
3828             if ($seen_canonical)
3829             {
3830                 push (@whatlist, 'host');
3831             }
3833             # Extra stuff only for AC_CANONICAL_SYSTEM.
3834             if ($seen_canonical == $AC_CANONICAL_SYSTEM)
3835             {
3836                 push (@whatlist, 'target', 'build');
3837             }
3839             local ($c1, $c2);
3840             foreach $c1 (@whatlist)
3841             {
3842                 foreach $c2 ('alias', 'triplet')
3843                 {
3844                     $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
3845                 }
3846             }
3848             $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
3849                               . "\t\@test ! -f site.exp || sed '1,/^## All variables above are.*##/ d' site.exp >> \$\@-t\n"
3850                               . "\t\@test ! -f site.exp || mv site.exp site.bak\n"
3851                               . "\t\@mv \$\@-t site.exp\n");
3852         }
3853     }
3854     else
3855     {
3856         local ($c);
3857         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
3858         {
3859             if (&variable_defined ($c))
3860             {
3861                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
3862             }
3863         }
3864     }
3866     if (&variable_defined ('TESTS'))
3867     {
3868         push (@check_tests, 'check-TESTS');
3869         push (@phony, 'check-TESTS');
3871         # Note: Solaris 2.7 seems to expand TESTS using VPATH.  That's
3872         # why we also try `dir='
3873         $output_rules .= 'check-TESTS: $(TESTS)
3874         @failed=0; all=0; xfail=0; xpass=0; \\
3875         srcdir=$(srcdir); export srcdir; \\
3876         for tst in $(TESTS); do \\
3877           if test -f ./$$tst; then dir=./; \\
3878           elif test -f $$tst; then dir=; \\
3879           else dir="$(srcdir)/"; fi; \\
3880           if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \\
3881             all=`expr $$all + 1`; \\
3882             case " $(XFAIL_TESTS) " in \\
3883             *" $$tst "*) \\
3884               xpass=`expr $$xpass + 1`; \\
3885               failed=`expr $$failed + 1`; \\
3886               echo "XPASS: $$tst"; \\
3887             ;; \\
3888             *) \\
3889               echo "PASS: $$tst"; \\
3890             ;; \\
3891             esac; \\
3892           elif test $$? -ne 77; then \\
3893             all=`expr $$all + 1`; \\
3894             case " $(XFAIL_TESTS) " in \\
3895             *" $$tst "*) \\
3896               xfail=`expr $$xfail + 1`; \\
3897               echo "XFAIL: $$tst"; \\
3898             ;; \\
3899             *) \\
3900               failed=`expr $$failed + 1`; \\
3901               echo "FAIL: $$tst"; \\
3902             ;; \\
3903             esac; \\
3904           fi; \\
3905         done; \\
3906         if test "$$failed" -eq 0; then \\
3907           if test "$$xfail" -eq 0; then \\
3908             banner="All $$all tests passed"; \\
3909           else \\
3910             banner="All $$all tests behaved as expected ($$xfail expected failures)"; \\
3911           fi; \\
3912         else \\
3913           if test "$$xpass" -eq 0; then \\
3914             banner="$$failed of $$all tests failed"; \\
3915           else \\
3916             banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \\
3917           fi; \\
3918         fi; \\
3919         dashes=`echo "$$banner" | sed s/./=/g`; \\
3920         echo "$$dashes"; \\
3921         echo "$$banner"; \\
3922         echo "$$dashes"; \\
3923         test "$$failed" -eq 0
3925     }
3928 # Handle Emacs Lisp.
3929 sub handle_emacs_lisp
3931     local (@elfiles) = &am_install_var ('-candist', 'lisp', 'LISP',
3932                                         'lisp', 'noinst');
3934     if (@elfiles)
3935     {
3936         # Found some lisp.
3937         &define_configure_variable ('lispdir');
3938         &define_configure_variable ('EMACS');
3939         $output_rules .= (".el.elc:\n"
3940                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
3941                           . "\tif test \$(EMACS) != no; then \\\n"
3942                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
3943                           . "\tfi\n");
3944         push (@suffixes, '.el', '.elc');
3946         # Generate .elc files.
3947         grep ($_ .= 'c', @elfiles);
3948         &define_pretty_variable ('ELCFILES', '', @elfiles);
3950         $output_rules .= &file_contents ('lisp-clean');
3951         push (@clean, 'lisp');
3952         &push_phony_cleaners ('lisp');
3954         push (@all, '$(ELCFILES)');
3956         local ($varname);
3957         if (&variable_defined ('lisp_LISP'))
3958         {
3959             $varname = 'lisp_LISP';
3960             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
3961                 if ! $seen_lispdir;
3962         }
3963         else
3964         {
3965             $varname = 'noinst_LISP';
3966         }
3968         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
3969     }
3972 # Handle Java.
3973 sub handle_java
3975     local (@sourcelist) = &am_install_var ('-candist', '-clean',
3976                                            'java', 'JAVA',
3977                                            'java', 'noinst', 'check');
3978     return if ! @sourcelist;
3980     &define_variable ('JAVAC', 'javac');
3981     &define_variable ('JAVACFLAGS', '');
3982     &define_variable ('CLASSPATH_ENV',
3983                       'CLASSPATH=$(JAVAROOT):$(srcdir)/$(JAVAROOT):$$CLASSPATH');
3984     &define_variable ('JAVAROOT', '$(top_builddir)');
3986     local (%valid) = &am_primary_prefixes ('JAVA', 1,
3987                                            'java', 'noinst', 'check');
3989     local ($dir, $curs);
3990     foreach $curs (keys %valid)
3991     {
3992         if (! &variable_defined ($curs . '_JAVA') || $curs eq 'noinst'
3993             || $curs eq 'EXTRA')
3994         {
3995             next;
3996         }
3998         if (defined $dir)
3999         {
4000             &am_line_error ($curs . '_JAVA',
4001                             "multiple _JAVA primaries in use");
4002         }
4003         $dir = $curs;
4004     }
4006     $output_rules .= ('class' . $dir . '.stamp: $(' . $dir . '_JAVA)' . "\n"
4007                       . "\t" . '$(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) '
4008                       . '$(JAVACFLAGS) $?' . "\n"
4009                       . "\t" . 'echo timestamp > class' . $dir . '.stamp'
4010                       . "\n");
4011     push (@all, 'class' . $dir . '.stamp');
4012     &push_dist_common ('$(' . $dir . '_JAVA)');
4015 # Handle some of the minor options.
4016 sub handle_minor_options
4018     if (defined $options{'readme-alpha'})
4019     {
4020         if ($relative_dir eq '.')
4021         {
4022             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4023             {
4024                 # FIXME: allow real filename.
4025                 &am_conf_line_error ('configure.in',
4026                                      $package_version_line,
4027                                      "version \`$package_version' doesn't follow Gnits standards");
4028             }
4029             elsif (defined $1 && -f 'README-alpha')
4030             {
4031                 # This means we have an alpha release.  See
4032                 # GNITS_VERSION_PATTERN for details.
4033                 &require_file ($FOREIGN, 'README-alpha');
4034             }
4035         }
4036     }
4039 ################################################################
4041 # Scan one file for interesting things.  Subroutine of scan_configure.
4042 sub scan_one_configure_file
4044     local ($filename) = @_;
4045     local (*CONFIGURE);
4047     open (CONFIGURE, $filename)
4048         || die "automake: couldn't open \`$filename': $!\n";
4049     print "automake: reading $filename\n" if $verbose;
4051     while (<CONFIGURE>)
4052     {
4053         # Remove comments from current line.
4054         s/\bdnl\b.*$//;
4055         s/\#.*$//;
4057         # Skip macro definitions.  Otherwise we might be confused into
4058         # thinking that a macro that was only defined was actually
4059         # used.
4060         next if /AC_DEFUN/;
4062         # Follow includes.  This is a weirdness commonly in use at
4063         # Cygnus and hopefully nowhere else.
4064         if (/sinclude\((.*)\)/ && -f $1)
4065         {
4066             &scan_one_configure_file ($1);
4067         }
4069         # Populate libobjs array.
4070         if (/AC_FUNC_ALLOCA/)
4071         {
4072             $libsources{'alloca.c'} = 1;
4073         }
4074         elsif (/AC_FUNC_GETLOADAVG/)
4075         {
4076             $libsources{'getloadavg.c'} = 1;
4077         }
4078         elsif (/AC_FUNC_MEMCMP/)
4079         {
4080             $libsources{'memcmp.c'} = 1;
4081         }
4082         elsif (/AC_STRUCT_ST_BLOCKS/)
4083         {
4084             $libsources{'fileblocks.c'} = 1;
4085         }
4086         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4087         {
4088             $libsources{'getopt.c'} = 1;
4089             $libsources{'getopt1.c'} = 1;
4090         }
4091         elsif (/AM_FUNC_STRTOD/)
4092         {
4093             $libsources{'strtod.c'} = 1;
4094         }
4095         elsif (/AM_WITH_REGEX/)
4096         {
4097             $libsources{'rx.c'} = 1;
4098             $libsources{'rx.h'} = 1;
4099             $libsources{'regex.c'} = 1;
4100             $libsources{'regex.h'} = 1;
4101             $omit_dependencies{'rx.h'} = 1;
4102             $omit_dependencies{'regex.h'} = 1;
4103         }
4104         elsif (/AM_FUNC_MKTIME/)
4105         {
4106             $libsources{'mktime.c'} = 1;
4107         }
4108         elsif (/AM_FUNC_ERROR_AT_LINE/)
4109         {
4110             $libsources{'error.c'} = 1;
4111             $libsources{'error.h'} = 1;
4112         }
4113         elsif (/AM_FUNC_OBSTACK/)
4114         {
4115             $libsources{'obstack.c'} = 1;
4116             $libsources{'obstack.h'} = 1;
4117         }
4118         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4119                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4120         {
4121             foreach $libobj_iter (split (' ', $1))
4122             {
4123                 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4124                     || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4125                     || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4126                 {
4127                     $libsources{$1 . '.c'} = 1;
4128                 }
4129             }
4130         }
4132         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4133         {
4134             $in_ac_replace = 1;
4135         }
4136         if ($in_ac_replace)
4137         {
4138             $in_ac_replace = 0 if s/[\]\)].*$//;
4139             # Remove trailing backslash.
4140             s/\\$//;
4141             foreach (split)
4142             {
4143                 # Need to skip empty elements for Perl 4.
4144                 next if $_ eq '';
4145                 $libsources{$_ . '.c'} = 1;
4146             }
4147         }
4149         if (/$obsolete_rx/o)
4150         {
4151             local ($hint) = '';
4152             if ($obsolete_macros{$1} ne '')
4153             {
4154                 $hint = '; ' . $obsolete_macros{$1};
4155             }
4156             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
4157         }
4159         # Process the AC_OUTPUT macro.
4160         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
4161         {
4162             $in_ac_output = 1;
4163             $ac_output_line = $.;
4164         }
4165         if ($in_ac_output)
4166         {
4167             local ($closing) = 0;
4168             if (s/[\]\),].*$//)
4169             {
4170                 $in_ac_output = 0;
4171                 $closing = 1;
4172             }
4174             # Look at potential Makefile.am's.
4175             foreach (split)
4176             {
4177                 # Must skip empty string for Perl 4.
4178                 next if $_ eq "\\" || $_ eq '';
4180                 # Handle $local:$input syntax.  Note that we ignore
4181                 # every input file past the first, though we keep
4182                 # those around for later.
4183                 local ($local, $input, @rest) = split (/:/);
4184                 if (! $input)
4185                 {
4186                     $input = $local;
4187                 }
4188                 else
4189                 {
4190                     # FIXME: should be error if .in is missing.
4191                     $input =~ s/\.in$//;
4192                 }
4194                 if (-f $input . '.am')
4195                 {
4196                     # We have a file that automake should generate.
4197                     push (@make_input_list, $input);
4198                     $make_list{$input} = join (':', ($local, @rest));
4199                 }
4200                 else
4201                 {
4202                     # We have a file that automake should cause to be
4203                     # rebuilt, but shouldn't generate itself.
4204                     push (@other_input_files, $_);
4205                 }
4206             }
4208             if ($closing && @make_input_list == 0 && @other_input_files == 0)
4209             {
4210                 &am_conf_line_error ($filename, $ac_output_line,
4211                                      "No files mentioned in \`AC_OUTPUT'");
4212                 exit 1;
4213             }
4214         }
4216         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4217         {
4218             @config_aux_path = $1;
4219         }
4221         # Check for ansi2knr.
4222         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4224         # Check for exe extension stuff.
4225         if (/AC_EXEEXT/)
4226         {
4227             $seen_exeext = 1;
4228             $configure_vars{'EXEEXT'} = $filename . ':' . $.;
4229         }
4231         if (/AC_OBJEXT/)
4232         {
4233             $seen_objext = 1;
4234             $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4235         }
4237         # Check for NLS support.
4238         if (/AM_GNU_GETTEXT/)
4239         {
4240             $seen_gettext = 1;
4241             $ac_gettext_line = $.;
4242             $omit_dependencies{'libintl.h'} = 1;
4243         }
4245         # Look for ALL_LINGUAS.
4246         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4247         {
4248             $seen_linguas = 1;
4249             $all_linguas = $1;
4250             $all_linguas_line = $.;
4251         }
4253         # Handle configuration headers.  A config header of `[$1]'
4254         # means we are actually scanning AM_CONFIG_HEADER from
4255         # aclocal.m4.
4256         if (/A([CM])_CONFIG_HEADER\s*\((.*)\)/
4257             && $2 ne '[$1]')
4258         {
4259             &am_conf_line_error
4260                 ($filename, $., "\`automake requires \`AM_CONFIG_HEADER', not \`AC_CONFIG_HEADER'")
4261                     if $1 eq 'C';
4263             $config_header_line = $.;
4264             local ($one_hdr);
4265             foreach $one_hdr (split (' ', $2))
4266             {
4267                 push (@config_fullnames, $one_hdr);
4268                 if ($one_hdr =~ /^([^:]+):(.+)$/)
4269                 {
4270                     push (@config_names, $1);
4271                     push (@config_headers, $2);
4272                 }
4273                 else
4274                 {
4275                     push (@config_names, $one_hdr);
4276                     push (@config_headers, $one_hdr . '.in');
4277                 }
4278             }
4279         }
4281         # Handle AC_CANONICAL_*.  Always allow upgrading to
4282         # AC_CANONICAL_SYSTEM, but never downgrading.
4283         $seen_canonical = $AC_CANONICAL_HOST
4284             if ! $seen_canonical
4285                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4286         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4288         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
4290         # This macro handles several different things.
4291         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4292         {
4293             $seen_make_set = 1;
4294             $seen_package = 1;
4295             $seen_version = 1;
4296             $seen_arg_prog = 1;
4297             $seen_prog_install = 1;
4298             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4299             $package_version_line = $.;
4300         }
4302         # This is like AM_INIT_AUTOMAKE, but doesn't actually set the
4303         # package and version number.  (This might change in the
4304         # future).  Yes, I'm not above hacking Automake so it works
4305         # well with other GNU tools -- that is actually the point.
4306         if (/AM_INIT_GUILE_MODULE/)
4307         {
4308             $seen_make_set = 1;
4309             $seen_package = 1;
4310             $seen_version = 1;
4311             $seen_arg_prog = 1;
4312             $seen_prog_install = 1;
4313             @config_aux_path = ('..');
4314         }
4316         # Some things required by Automake.
4317         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
4318         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
4320         if (/AM_PROG_LEX/)
4321         {
4322             $configure_vars{'LEX'} = $filename . ':' . $.;
4323             $seen_decl_yytext = 1;
4324         }
4325         if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.in$/)
4326         {
4327             &am_conf_line_warning ($filename, $., "\`AC_DECL_YYTEXT' is covered by \`AM_PROG_LEX'");
4328         }
4329         if (/AC_PROG_LEX/ && $filename =~ /configure\.in$/)
4330         {
4331             &am_conf_line_warning ($filename, $., "automake requires \`AM_PROG_LEX', not \`AC_PROG_LEX'");
4332         }
4334         if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4335         {
4336             $configure_vars{$1} = $filename . ':' . $.;
4337         }
4338         if (/$AC_CHECK_PATTERN/o)
4339         {
4340             $configure_vars{$3} = $filename . ':' . $.;
4341         }
4342         if (/$AM_MISSING_PATTERN/o
4343             && $1 ne 'ACLOCAL'
4344             && $1 ne 'AUTOCONF'
4345             && $1 ne 'AUTOMAKE'
4346             && $1 ne 'AUTOHEADER')
4347         {
4348             $configure_vars{$1} = $filename . ':' . $.;
4349         }
4351         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4352         # but later define it elsewhere.  This is pretty hacky.  We
4353         # also explicitly avoid INSTALL_SCRIPT and some other
4354         # variables because they are defined in header-vars.am.
4355         # FIXME.
4356         if (/$AC_SUBST_PATTERN/o
4357             && $1 ne 'ANSI2KNR'
4358             && $1 ne 'INSTALL_SCRIPT'
4359             && $1 ne 'INSTALL_DATA')
4360         {
4361             $configure_vars{$1} = $filename . ':' . $.;
4362         }
4364         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4365         if (/AM_MAINTAINER_MODE/)
4366         {
4367             $seen_maint_mode = 1;
4368             $configure_cond{'MAINTAINER_MODE'} = 1;
4369         }
4370         $seen_package = 1 if /PACKAGE=/;
4372         # Skip VERSION of [$2]; that is from AM_INIT_AUTOMAKE.
4373         if (/\bVERSION=(\S+)/ && $1 ne '[$2]')
4374         {
4375             $seen_version = 1;
4376             $package_version = $1;
4377             $package_version_line = $.;
4378         }
4379         elsif (/VERSION=/)
4380         {
4381             $seen_version = 1;
4382         }
4384         $seen_prog_install = 1 if /AC_PROG_INSTALL/;
4385         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4387         if (/A(C|M)_PROG_LIBTOOL/)
4388         {
4389             if (/AM_PROG_LIBTOOL/)
4390             {
4391                 &am_conf_line_warning ($filename, $., "\`AM_PROG_LIBTOOL' is obsolete, use \`AC_PROG_LIBTOOL' instead");
4392             }
4393             $seen_libtool = 1;
4394             $libtool_line = $.;
4395             $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4396             $configure_vars{'RANLIB'} = $filename . ':' . $.;
4397             $configure_vars{'CC'} = $filename . ':' . $.;
4398             # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
4399             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4400             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4401         }
4403         $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4405         if (/$AM_CONDITIONAL_PATTERN/o)
4406         {
4407             $configure_cond{$1} = 1;
4408         }
4410         # Check for Fortran 77 intrinsic and run-time libraries.
4411         if (/AC_F77_LIBRARY_LDFLAGS/)
4412         {
4413             $configure_vars{'FLIBS'} = $filename . ':' . $.;
4414         }
4415     }
4417     close (CONFIGURE);
4420 # Scan configure.in and aclocal.m4 for interesting things.  We must
4421 # scan aclocal.m4 because there might be AC_SUBSTs and such there.
4422 sub scan_configure
4424     # Reinitialize libsources here.  This isn't really necessary,
4425     # since we currently assume there is only one configure.in.  But
4426     # that won't always be the case.
4427     %libsources = ();
4429     local ($in_ac_output, $in_ac_replace) = (0, 0);
4430     local (%make_list, @make_input_list);
4431     local ($libobj_iter);
4433     &scan_one_configure_file ('configure.in');
4434     &scan_one_configure_file ('aclocal.m4')
4435         if -f 'aclocal.m4';
4437     # Set input and output files if not specified by user.
4438     if (! @input_files)
4439     {
4440         @input_files = @make_input_list;
4441         %output_files = %make_list;
4442     }
4444     &am_conf_error ("\`PACKAGE' not defined in configure.in")
4445         if ! $seen_package;
4446     &am_conf_error ("\`VERSION' not defined in configure.in")
4447         if ! $seen_version;
4449     # Look for some files we need.  Always check for these.  This
4450     # check must be done for every run, even those where we are only
4451     # looking at a subdir Makefile.  We must set relative_dir so that
4452     # the file-finding machinery works.
4453     local ($relative_dir) = '.';
4454     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4455     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
4456         if -f $config_aux_path[0] . '/install.sh';
4459 ################################################################
4461 # Set up for Cygnus mode.
4462 sub check_cygnus
4464     return unless $cygnus_mode;
4466     &set_strictness ('foreign');
4467     $options{'no-installinfo'} = 1;
4468     $options{'no-dependencies'} = 1;
4469     $use_dependencies = 0;
4471     if (! $seen_maint_mode)
4472     {
4473         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
4474     }
4476     if (! $seen_exeext)
4477     {
4478         &am_conf_error ("\`AC_EXEEXT' required when --cygnus specified");
4479     }
4482 # Do any extra checking for GNU standards.
4483 sub check_gnu_standards
4485     if ($relative_dir eq '.')
4486     {
4487         # In top level (or only) directory.
4488         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4489                        'AUTHORS', 'ChangeLog');
4490     }
4492     if ($strictness >= $GNU)
4493     {
4494         if (defined $options{'no-installman'})
4495         {
4496             &am_line_error ('AUTOMAKE_OPTIONS',
4497                             "option \`no-installman' disallowed by GNU standards");
4498         }
4500         if (defined $options{'no-installinfo'})
4501         {
4502             &am_line_error ('AUTOMAKE_OPTIONS',
4503                             "option \`no-installinfo' disallowed by GNU standards");
4504         }
4505     }
4508 # Do any extra checking for GNITS standards.
4509 sub check_gnits_standards
4511     if ($strictness >= $GNITS)
4512     {
4513         if (-f $relative_dir . '/COPYING.LIB')
4514         {
4515             &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
4516         }
4517     }
4519     if ($relative_dir eq '.')
4520     {
4521         # In top level (or only) directory.
4522         &require_file ($GNITS, 'THANKS');
4523     }
4526 ################################################################
4528 # Functions to handle files of each language.
4530 # Each `lang_X_rewrite' function follows a simple formula:
4531 # * Args are the base name and extension of the file.
4532 # * Return value is 1 if file is to be dealt with, 0 otherwise.
4533 # Much of the actual processing is handled in handle_single_transform_list.
4534 # These functions exist so that auxiliary information can be recorded
4535 # for a later cleanup pass.  Note that the calls to these functions
4536 # are computed, so don't bother searching for their precise names
4537 # in the source.
4539 # Rewrite a single C source file.
4540 sub lang_c_rewrite
4542     local ($base, $ext) = @_;
4544     if (defined $options{'ansi2knr'} && $base =~ /_$/)
4545     {
4546         # FIXME: include line number in error.
4547         &am_error ("C source file \`$base.c' would be deleted by ansi2knr rules");
4548     }
4550     $de_ansi_files{$base} = 1;
4551     return $LANG_PROCESS;
4554 # Rewrite a single C++ source file.
4555 sub lang_cxx_rewrite
4557     return $LANG_PROCESS;
4560 # Rewrite a single header file.
4561 sub lang_header_rewrite
4563     # Header files are simply ignored.
4564     return $LANG_IGNORE;
4567 # Rewrite a single yacc file.
4568 sub lang_yacc_rewrite
4570     local ($base, $ext) = @_;
4572     &lang_c_rewrite ($base, $ext);
4573     $yacc_sources{$base . '.' . $ext} = 1;
4574     $ext =~ tr/y/c/;
4575     &saw_extension ('c');
4576     &push_dist_common ($base . '.' . $ext);
4577     return $LANG_PROCESS;
4580 # Rewrite a single yacc++ file.
4581 sub lang_yaccxx_rewrite
4583     local ($base, $ext) = @_;
4585     $yacc_sources{$base . '.' . $ext} = 1;
4586     $ext =~ tr/y/c/;
4587     &saw_extension ($ext);
4588     &push_dist_common ($base . '.' . $ext);
4589     return $LANG_PROCESS;
4592 # Rewrite a single lex file.
4593 sub lang_lex_rewrite
4595     local ($base, $ext) = @_;
4597     &lang_c_rewrite ($base, $ext);
4598     $lex_sources{$base . '.' . $ext} = 1;
4599     $ext =~ tr/l/c/;
4600     &saw_extension ('c');
4601     &push_dist_common ($base . '.' . $ext);
4602     return $LANG_PROCESS;
4605 # Rewrite a single lex++ file.
4606 sub lang_lexxx_rewrite
4608     local ($base, $ext) = @_;
4610     $lex_sources{$base . '.' . $ext} = 1;
4611     $ext =~ tr/l/c/;
4612     &saw_extension ($ext);
4613     &push_dist_common ($base . '.' . $ext);
4614     return $LANG_PROCESS;
4617 # Rewrite a single assembly file.
4618 sub lang_asm_rewrite
4620     return $LANG_PROCESS;
4623 # Rewrite a single Fortran 77 file.
4624 sub lang_f77_rewrite
4626     return $LANG_PROCESS;
4629 # Rewrite a single preprocessed Fortran 77 file.
4630 sub lang_ppf77_rewrite
4632     return $LANG_PROCESS;
4635 # Rewrite a single ratfor file.
4636 sub lang_ratfor_rewrite
4638     return $LANG_PROCESS;
4641 # Rewrite a single Objective C file.
4642 sub lang_objc_rewrite
4644     return $LANG_PROCESS;
4647 # Rewrite a single Java file.
4648 sub lang_java_rewrite
4650     return $LANG_SUBDIR;
4653 # The lang_X_finish functions are called after all source file
4654 # processing is done.  Each should handle defining rules for the
4655 # language, etc.  A finish function is only called if a source file of
4656 # the appropriate type has been seen.
4658 sub lang_c_finish
4660     # Push all libobjs files onto de_ansi_files.  We actually only
4661     # push files which exist in the current directory, and which are
4662     # genuine source files.
4663     local ($file);
4664     foreach $file (keys %libsources)
4665     {
4666         if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
4667         {
4668             $de_ansi_files{$1} = 1;
4669         }
4670     }
4672     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
4673     {
4674         # Make all _.c files depend on their corresponding .c files.
4675         local ($base, @objects);
4676         foreach $base (sort keys %de_ansi_files)
4677         {
4678             # Each _.c file must depend on ansi2knr; otherwise it
4679             # might be used in a parallel build before it is built.
4680             # We need to support files in the srcdir and in the build
4681             # dir (because these files might be auto-generated.  But
4682             # we can't use $< -- some makes only define $< during a
4683             # suffix rule.
4684             $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
4685                               . '$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
4686                               . '`if test -f $(srcdir)/' . $base . '.c'
4687                               . '; then echo $(srcdir)/' . $base . '.c'
4688                               . '; else echo ' . $base . '.c; fi` '
4689                               . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
4690                               . '| $(ANSI2KNR) > ' . $base . "_.c\n");
4691             push (@objects, $base . '_'
4692                   . ($seen_objext ? '.$(OBJEXT)' : '.o'));
4693             push (@objects, $base . '_.lo') if $seen_libtool;
4694         }
4696         # Make all _.o (and _.lo) files depend on ansi2knr.
4697         # Use a sneaky little hack to make it print nicely.
4698         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
4699     }
4701     if (! defined $configure_vars{'CC'})
4702     {
4703         # FIXME: line number.
4704         &am_error ("C source seen but \`CC' not defined in \`configure.in'");
4705     }
4708 sub lang_cxx_finish
4710     local (@cxx_list) = &lang_extensions ('cxx');
4711     local ($cxx_count) = scalar @cxx_list;
4712     if ($cxx_count)
4713     {
4714         push (@suffixes, @cxx_list);
4716         local ($ltcompile, $ltlink) = &libtool_compiler;
4718         &define_configure_variable ("CXXFLAGS");
4719         &define_compiler_variable ('CXXCOMPILE', $ltcompile, '$(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)');
4721         &define_variable ('CXXLD', '$(CXX)');
4722         &define_variable ('CXXLINK', $ltlink . '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
4724         local ($ext);
4725         foreach $ext (@cxx_list)
4726         {
4727             $output_rules .= ("$ext.o:\n"
4728                               . "\t\$(CXXCOMPILE) -c \$<\n");
4729             # FIXME: Using cygpath should be somehow conditional.
4730             $output_rules .= ("$ext.obj:\n"
4731                               . "\t\$(CXXCOMPILE) -c `cygpath -w \$<`\n")
4732                 if ($seen_objext);
4733             $output_rules .= ("$ext.lo:\n"
4734                               . "\t\$(LTCXXCOMPILE) -c \$<\n")
4735                 if ($seen_libtool);
4736         }
4738         if (! defined $configure_vars{'CXX'})
4739         {
4740             &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
4741         }
4742     }
4745 sub lang_header_finish
4747     # Nothing to do.
4750 # This is a helper for both lex and yacc.
4751 sub yacc_lex_finish_helper
4753     return if defined $language_scratch{'lex-yacc-done'};
4754     $language_scratch{'lex-yacc-done'} = 1;
4756     # If there is more than one distinct yacc (resp lex) source file
4757     # in a given directory, then the `ylwrap' program is required to
4758     # allow parallel builds to work correctly.  FIXME: for now, no
4759     # line number.
4760     &require_config_file ($FOREIGN, 'ylwrap');
4761     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
4762     {
4763         &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
4764     }
4765     else
4766     {
4767         &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
4768     }
4771 sub lang_yacc_finish
4773     return if defined $language_scratch{'yacc-done'};
4774     $language_scratch{'yacc-done'} = 1;
4776     local ($file, $base, $hname, $cname);
4777     local (%seen_suffix) = ();
4778     local (@yacc_files) = sort keys %yacc_sources;
4779     local ($yacc_count) = scalar (@yacc_files);
4780     foreach $file (@yacc_files)
4781     {
4782         $file =~ /(\..*)$/;
4783         &output_yacc_build_rule ($1, $yacc_count > 1)
4784             if ! defined $seen_suffix{$1};
4785         $seen_suffix{$1} = 1;
4787         $file =~ /^(.*)\.(y|yy|y\+\+|yxx|ypp)$/;
4788         $base = $1;
4789         $hname = 'h';           # Always use `.h' for header file.
4790         ($cname = $2) =~ tr/y/c/;
4792         if ((&variable_defined ('AM_YFLAGS')
4793              && &variable_value ('AM_YFLAGS') =~ /(^|\s)-d(\s|$)/)
4794             || (&variable_defined ('YFLAGS')
4795                 && &variable_value ('YFLAGS') =~ /(^|\s)-d(\s|$)/)) {
4796             # Now generate rule to make the header file.  This should only
4797             # be generated if `yacc -d' specified.
4798             $output_rules .= "${base}.${hname}: ${base}.${cname}\n";
4800             # If the files are built in the build directory, then we want
4801             # to remove them with `make clean'.  If they are in srcdir
4802             # they shouldn't be touched.  However, we can't determine this
4803             # statically, and the GNU rules say that yacc/lex output files
4804             # should be removed by maintainer-clean.  So that's what we
4805             # do.
4806             push (@maintainer_clean_files, "${base}.${hname}");
4808             push_dist_common ("${base}.${hname}");
4809         }
4810         push (@maintainer_clean_files, "${base}.${cname}");
4811     }
4812     $output_rules .= "\n";
4814     if (! defined $configure_vars{'YACC'})
4815     {
4816         &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
4817     }
4818     if (&variable_defined ('YACCFLAGS'))
4819     {
4820         &am_line_error ('YACCFLAGS',
4821                         "\`YACCFLAGS' obsolete; use \`YFLAGS' instead");
4822     }
4824     if ($yacc_count > 1)
4825     {
4826         &yacc_lex_finish_helper;
4827     }
4830 sub lang_yaccxx_finish
4832     &lang_yacc_finish;
4835 sub lang_lex_finish
4837     return if defined $language_scratch{'lex-done'};
4838     $language_scratch{'lex-done'} = 1;
4840     local (%seen_suffix) = ();
4841     local ($file, $cname);
4842     local ($lex_count) = scalar (keys %lex_sources);
4843     foreach $file (sort keys %lex_sources)
4844     {
4845         $file =~ /(\..*)$/;
4846         &output_lex_build_rule ($1, $lex_count > 1)
4847             if (! defined $seen_suffix{$1});
4848         $seen_suffix{$1} = 1;
4850         # If the files are built in the build directory, then we want
4851         # to remove them with `make clean'.  If they are in srcdir
4852         # they shouldn't be touched.  However, we can't determine this
4853         # statically, and the GNU rules say that yacc/lex output files
4854         # should be removed by maintainer-clean.  So that's what we
4855         # do.
4856         $file =~ /^(.*)\.(l|ll|l\+\+|lxx|lpp)$/;
4857         ($cname = $2) =~ tr/l/c/;
4858         push (@maintainer_clean_files, "${1}.${cname}");
4859     }
4861     if (! defined $configure_vars{'LEX'})
4862     {
4863         &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
4864     }
4865     if (! $seen_decl_yytext)
4866     {
4867         &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
4868     }
4870     if ($lex_count > 1)
4871     {
4872         &yacc_lex_finish_helper;
4873     }
4876 sub lang_lexxx_finish
4878     &lang_lex_finish;
4881 sub lang_asm_finish
4883     # Pretend we're C.
4884     &lang_c_finish;
4887 sub lang_f77_finish
4889     local (@f77_list) = &lang_extensions ('f77');
4890     local ($f77_count) = scalar @f77_list;
4891     if ($f77_count)
4892     {
4893         push (@suffixes, @f77_list);
4895         local ($ltcompile, $ltlink) = &libtool_compiler;
4897         &define_configure_variable ('FFLAGS');
4898         &define_compiler_variable ('F77COMPILE', $ltcompile,
4899                                    '$(F77) $(AM_FFLAGS) $(FFLAGS)');
4901         &define_variable ('F77LD', '$(F77)');
4902         &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
4904         local ($ext);
4905         foreach $ext (@f77_list)
4906         {
4907             $output_rules .= ("$ext.o:\n"
4908                               . "\t\$(F77COMPILE) -c \$<\n");
4909             # FIXME: Using cygpath should be somehow conditional.
4910             $output_rules .= ("$ext.obj:\n"
4911                               . "\t\$(F77COMPILE) -c `cygpath -w \$<`\n")
4912                 if ($seen_objext);
4913             $output_rules .= ("$ext.lo:\n"
4914                               . "\t\$(LTF77COMPILE) -c \$<\n")
4915                 if ($seen_libtool);
4916         }
4918         if (! defined $configure_vars{'F77'})
4919         {
4920             &am_error ("Fortran 77 source seen but \`F77' not defined in \`configure.in'");
4921         }
4922     }
4925 # Preprocessed Fortran 77
4927 # The current support for preprocessing Fortran 77 just involves passing
4928 # `$(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)' as additional flags
4929 # to the Fortran 77 compiler, since this is how GNU Make does it; see
4930 # the `GNU Make Manual, Edition 0.51 for `make' Version 3.76 Beta'
4931 # (specifically, from info file `(make)Catalogue of Rules').
4933 # A better approach would be to write an Autoconf test
4934 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
4935 # Fortran 77 compilers know how to do preprocessing.  The Autoconf macro
4936 # AC_PROG_FPP should test the Fortran 77 compiler first for
4937 # preprocessing capabilities, and then fall back on cpp (if cpp were
4938 # available).
4939 sub lang_ppf77_finish
4941     local ($ext) = 'F';
4942     last unless $extension_seen{$ext};
4944     $ext = '.' . $ext;
4945     push (@suffixes, $ext);
4947     local ($ltcompile, $ltlink) = &libtool_compiler;
4949     &define_configure_variable ('FFLAGS');
4950     &define_compiler_variable ('F77COMPILE', $ltcompile,
4951                                '$(F77) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)');
4953     &define_variable ('F77LD', '$(F77)');
4954     &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
4956     $output_rules .= ("$ext.o:\n"
4957                       . "\t\$(F77COMPILE) -c \$<\n");
4958     # FIXME: Using cygpath should be somehow conditional.
4959     $output_rules .= ("$ext.obj:\n"
4960                       . "\t\$(F77COMPILE) -c `cygpath -w \$<`\n")
4961         if ($seen_objext);
4962     $output_rules .= ("$ext.lo:\n"
4963                       . "\t\$(LTF77COMPILE) -c \$<\n")
4964         if ($seen_libtool);
4966     # We also handle the case of preprocessing `.F' files into `.f'
4967     # files.
4968     $output_rules .= ("$ext.f:\n"
4969                       . "\t\$(F77COMPILE) -F \$<\n");
4971     if (! defined $configure_vars{'F77'})
4972     {
4973         &am_error ("Fortran 77 source seen but \`F77' not defined in \`configure.in'");
4974     }
4977 sub lang_ratfor_finish
4979     local ($ext) = 'r';
4980     last unless $extension_seen{$ext};
4981     $ext = '.' . $ext;
4982     push (@suffixes, $ext);
4984     local ($ltcompile, $ltlink) = &libtool_compiler;
4986     &define_configure_variable ('FFLAGS');
4987     &define_configure_variable ('RFLAGS');
4988     &define_variable ('RCOMPILE', $ltcompile,
4989                       '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)');
4991     &define_variable ('F77LD', '$(F77)');
4992     &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
4994     $output_rules .= ("$ext.o:\n"
4995                       . "\t\$(RCOMPILE) -c \$<\n");
4996     # FIXME: Using cygpath should be somehow conditional.
4997     $output_rules .= ("$ext.obj:\n"
4998                       . "\t\$(RCOMPILE) -c `cygpath -w \$<`\n")
4999         if ($seen_objext);
5000     $output_rules .= ("$ext.lo:\n"
5001                       . "\t\$(LTRCOMPILE) -c \$<\n")
5002         if ($seen_libtool);
5004     # We also handle the case of preprocessing `.r' files into `.f'
5005     # files.
5006     $output_rules .= ("$ext.f:\n"
5007                       . "\t\$(RCOMPILE) -F \$<\n");
5009     if (! defined $configure_vars{'F77'})
5010     {
5011         &am_error ("Ratfor source seen but \`F77' not defined in \`configure.in'");
5012     }
5015 sub lang_objc_finish
5017     push (@suffixes, '.m');
5019     local ($ltcompile, $ltlink) = &libtool_compiler;
5021     &define_configure_variable ("OBJCFLAGS");
5022     &define_compiler_variable ('OBJCCOMPILE', $ltcompile,
5023                                '$(OBJC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)');
5025     &define_variable ('OBJCLD', '$(OBJC)');
5026     &define_variable ('OBJCLINK', $ltlink . '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5028     $output_rules .= (".m.o:\n"
5029                       . "\t\$(OBJCCOMPILE) -c \$<\n");
5030     # FIXME: Using cygpath should be somehow conditional.
5031     $output_rules .= (".m.obj:\n"
5032                       . "\t\$(OBJCCOMPILE) -c `cygpath -w \$<`\n")
5033         if ($seen_objext);
5034     $output_rules .= (".m.lo:\n"
5035                       . "\t\$(LTOBJCCOMPILE) -c \$<\n")
5036         if ($seen_libtool);
5038     if (! defined $configure_vars{'OBJC'})
5039     {
5040         &am_error ("Objective C source seen but \`OBJC' not defined in \`configure.in'");
5041     }
5044 sub lang_java_finish
5046     push (@suffixes, '.java');
5048     local ($ltcompile, $ltlink) = &libtool_compiler;
5050     &define_configure_variable ("GCJFLAGS");
5051     &define_compiler_variable ('GCJCOMPILE', $ltcompile,
5052                                '$(GCJ) $(DEFS) $(INCLUDES) $(AM_GCJFLAGS) $(GCJFLAGS)');
5054     &define_variable ('GCJLD', '$(GCJ)');
5055     &define_variable ('GCJLINK', $ltlink . '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
5057     $output_rules .= (".java.o:\n"
5058                       . "\t\$(GCJCOMPILE) -c \$<\n");
5059     # FIXME: Using cygpath should be somehow conditional.
5060     $output_rules .= (".java.obj:\n"
5061                       . "\t\$(GCJCOMPILE) -c `cygpath -w \$<`\n")
5062         if ($seen_objext);
5063     $output_rules .= (".java.lo:\n"
5064                       . "\t\$(LTGCJCOMPILE) -c \$<\n")
5065         if ($seen_libtool);
5067     if (! defined $configure_vars{'GCJ'})
5068     {
5069         &am_error ("Java source seen but \`GCJ' not defined in \`configure.in'");
5070     }
5073 # A helper which computes a sorted list of all extensions for LANG.
5074 sub lang_extensions
5076     local ($lang) = @_;
5077     local ($key, @r);
5078     foreach $key (sort keys %extension_seen)
5079     {
5080         push (@r, '.' . $key) if $extension_map{$key} eq $lang;
5081     }
5082     return @r;
5085 # A helper which decides whether libtool is needed.  Returns prefix
5086 # for compiler and linker.
5087 sub libtool_compiler
5089     local ($ltcompile, $ltlink) = ('', '');
5090     if ($seen_libtool)
5091     {
5092         &define_configure_variable ("LIBTOOL");
5093         $ltcompile = '$(LIBTOOL) --mode=compile ';
5094         $ltlink = '$(LIBTOOL) --mode=link ';
5095     }
5096     return ($ltcompile, $ltlink);
5099 # Given a hash table of linker names, pick the name that has the most
5100 # precedence.  This is lame, but something has to have global
5101 # knowledge in order to eliminate the conflict.  Add more linkers as
5102 # required.
5103 sub resolve_linker
5105     local (%linkers) = @_;
5107     return 'GCJLINK'
5108         if defined $linkers{'GCJLINK'};
5109     return 'CXXLINK'
5110         if defined $linkers{'CXXLINK'};
5111     return 'F77LINK'
5112         if defined $linkers{'F77LINK'};
5113     return 'OBJCLINK'
5114         if defined $linkers{'OBJCLINK'};
5115     return 'LINK';
5118 # Called to indicate that an extension was used.
5119 sub saw_extension
5121     local ($ext) = @_;
5122     $extension_seen{$ext} = 1;
5125 # Called to ask whether source files have been seen . If HEADERS is 1,
5126 # headers can be included.
5127 sub saw_sources_p
5129     local ($headers) = @_;
5131     if ($headers)
5132     {
5133         $headers = 0;
5134     }
5135     else
5136     {
5137         local (@exts) = &lang_extensions ('header');
5138         $headers = @exts;
5139     }
5141     return scalar keys %extension_seen > $headers;
5144 # Register a single language.  LANGUAGE is the name of the language.
5145 # Each OPTION is either of the form NAME=VALUE, or is a file extension
5146 # (sans `.').
5147 sub register_language
5149     local ($language, @options) = @_;
5151     # Set the defaults.
5152     $language_map{$language . '-ansi-p'} = 0;
5153     $language_map{$language . '-linker'} = '';
5154     $language_map{$language . '-autodep'} = 'no';
5156     local ($iter);
5157     foreach $iter (@options)
5158     {
5159         if ($iter =~ /^(.*)=(.*)$/)
5160         {
5161             $language_map{$language . '-' . $1} = $2;
5162         }
5163         elsif (defined $extension_map{$iter})
5164         {
5165             print STDERR
5166                 "automake: programming error: duplicate extension $iter\n";
5167             exit 1;
5168         }
5169         else
5170         {
5171             $extension_map{$iter} = $language;
5172         }
5173     }
5177 ################################################################
5179 # Pretty-print something.  HEAD is what should be printed at the
5180 # beginning of the first line, FILL is what should be printed at the
5181 # beginning of every subsequent line.
5182 sub pretty_print_internal
5184     local ($head, $fill, @values) = @_;
5186     local ($column) = length ($head);
5187     local ($result) = $head;
5189     # Fill length is number of characters.  However, each Tab
5190     # character counts for eight.  So we count the number of Tabs and
5191     # multiply by 7.
5192     local ($fill_length) = length ($fill);
5193     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5195     local ($bol) = ($head eq '');
5196     foreach (@values)
5197     {
5198         # "71" because we also print a space.
5199         if ($column + length ($_) > 71)
5200         {
5201             $result .= " \\\n" . $fill;
5202             $column = $fill_length;
5203             $bol = 1;
5204         }
5206         $result .= ' ' unless ($bol);
5207         $result .= $_;
5208         $column += length ($_) + 1;
5209         $bol = 0;
5210     }
5212     $result .= "\n";
5213     return $result;
5216 # Pretty-print something and append to output_vars.
5217 sub pretty_print
5219     $output_vars .= &pretty_print_internal (@_);
5222 # Pretty-print something and append to output_rules.
5223 sub pretty_print_rule
5225     $output_rules .= &pretty_print_internal (@_);
5229 ################################################################
5231 # See if a target exists.
5232 sub target_defined
5234     local ($target) = @_;
5235     return defined $targets{$target};
5238 # See if two conditionals are the same.
5239 sub conditional_same
5241     local ($cond1, $cond2) = @_;
5243     return (&conditional_true_when ($cond1, $cond2)
5244             && &conditional_true_when ($cond2, $cond1));
5247 # See if a conditional is true.  Both arguments are conditional
5248 # strings.  This returns true if the first conditional is true when
5249 # the second conditional is true.
5250 sub conditional_true_when
5252     local ($cond, $when) = @_;
5254     # Check the easy case first.
5255     if ($cond eq $when)
5256     {
5257         return 1;
5258     }
5260     # Check each component of $cond, which looks @COND1@@COND2@.
5261     foreach $comp (split ('@', $cond))
5262     {
5263         # The way we split will give null strings between each
5264         # condition.
5265         next if ! $comp;
5267         if (index ($when, '@' . $comp . '@') == -1)
5268         {
5269             return 0;
5270         }
5271     }
5273     return 1;
5276 # Check for an ambiguous conditional.  This is called when a variable
5277 # or target is being defined conditionally.  If we already know about
5278 # a definition that is true under the same conditions, then we have an
5279 # ambiguity.
5280 sub check_ambiguous_conditional
5282     local ($var_name, $cond) = @_;
5283     local (@cond_vals) = split (' ', $conditional{$var_name});
5284     while (@cond_vals)
5285     {
5286         local ($vcond) = shift (@cond_vals);
5287         shift (@cond_vals);
5288         if (&conditional_true_when ($vcond, $cond)
5289             || &conditional_true_when ($cond, $vcond))
5290         {
5291             &am_line_error ($var_name,
5292                             "$var_name multiply defined in condition");
5293         }
5294     }
5297 # See if a variable exists.  The first argument is the variable name,
5298 # and the optional second argument is the condition which we should
5299 # check.  If no condition is given, we currently return true if the
5300 # variable is defined under any condition.
5301 sub variable_defined
5303     local ($var, $cond) = @_;
5304     if (defined $targets{$var})
5305     {
5306         &am_line_error ($var, "\`$var' is target; expected variable");
5307         return 0;
5308     }
5309     elsif (defined $contents{$var})
5310     {
5311         if ($cond && $conditional{$var})
5312         {
5313             # We have been asked to check for a particular condition,
5314             # and the variable is defined conditionally.  We need to
5315             # look through the conditions under which the variable is
5316             # defined, and see if any of them match the conditional we
5317             # have been asked to check.
5318             local (@cond_vars) = split (' ', $conditional{$var});
5319             while (@cond_vars)
5320             {
5321                 if (&conditional_same ($cond, shift (@cond_vars)))
5322                 {
5323                     # Even a conditional examination is good enough
5324                     # for us.  FIXME: really should maintain examined
5325                     # status on a per-condition basis.
5326                     $content_seen{$var} = 1;
5327                     return 1;
5328                 }
5329                 shift (@cond_vars);
5330             }
5332             # The variable is not defined for the given condition.
5333             return 0;
5334         }
5336         $content_seen{$var} = 1;
5337         return 1;
5338     }
5339     return 0;
5342 # Mark a variable as examined.
5343 sub examine_variable
5345     local ($var) = @_;
5346     &variable_defined ($var);
5349 # Quote a value in order to put it in $conditional.  We need to quote
5350 # spaces, and we need to handle null strings, so that we can later
5351 # retrieve values by splitting on space.
5352 sub quote_cond_val
5354     local ($val) = @_;
5355     $val =~ tr/ \t\n/\001\003\004/;
5356     $val = "\002" if $val eq '';
5357     return $val;
5360 # Unquote a value in $conditional.
5361 sub unquote_cond_val
5363     local ($val) = @_;
5364     $val =~ tr/\001\003\004/ \t\n/;
5365     $val =~ s/\002//g;
5366     return $val;
5369 # Return the set of conditions for which a variable is defined.
5371 # If the variable is not defined conditionally, and is not defined in
5372 # terms of any variables which are defined conditionally, then this
5373 # returns the empty list.
5375 # If the variable is defined conditionally, but is not defined in
5376 # terms of any variables which are defined conditionally, then this
5377 # returns the list of conditions for which the variable is defined.
5379 # If the variable is defined in terms of any variables which are
5380 # defined conditionally, then this returns a full set of permutations
5381 # of the subvariable conditions.  For example, if the variable is
5382 # defined in terms of a variable which is defined for @COND_TRUE@,
5383 # then this returns both @COND_TRUE@ and @COND_FALSE@.  This is
5384 # because we will need to define the variable under both conditions.
5386 sub variable_conditions
5388     local ($var) = @_;
5389     local (%uniqify);
5390     local (@uniq_list);
5391     local ($cond);
5393     %vars_scanned = ();
5394     foreach $cond (&variable_conditions_sub ($var, '', ()))
5395     {
5396         $uniqify{$cond} = 1;
5397     }
5399     @uniq_list = sort keys %uniqify;
5400     # Note we cannot just do `return sort keys %uniqify', because this
5401     # function is sometimes used in a scalar context.
5402     return @uniq_list;
5405 # A subroutine of variable_conditions.  We only return conditions
5406 # which are true for all the conditions in @PARENT_CONDS.
5407 sub variable_conditions_sub
5409     local ($var, $parent, @parent_conds) = @_;
5410     local (@new_conds) = ();
5412     if (defined $vars_scanned{$var})
5413     {
5414         &am_line_error ($parent, "variable \`$var' recursively defined");
5415         return ();
5416     }
5417     $vars_scanned{$var} = 1;
5419     if (! $conditional{$var})
5420     {
5421         foreach (split (' ', $contents{$var}))
5422         {
5423             # If a comment seen, just leave.
5424             last if /^#/;
5426             # Handle variable substitutions.
5427             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5428             {
5429                 push (@new_conds,
5430                       &variable_conditions_sub ($1, $var, @parent_conds));
5431             }
5432         }
5434         # Now we want to return all permutations of the subvariable
5435         # conditions.
5436         local (%allconds, $item);
5437         foreach $item (@new_conds)
5438         {
5439             foreach (split ('@', $item))
5440             {
5441                 next if ! $_;
5442                 s/_(TRUE|FALSE)$//;
5443                 $allconds{$_ . '_TRUE'} = 1;
5444             }
5445         }
5447         # Unset our entry in vars_scanned.  We only care about recursive
5448         # definitions.
5449         delete $vars_scanned{$var};
5451         return &variable_conditions_permutations (sort keys %allconds);
5452     }
5454     local (@this_conds) = ();
5455     local (@condvals) = split (' ', $conditional{$var});
5456     while (@condvals)
5457     {
5458         local ($cond) = shift (@condvals);
5459         local ($val) = &unquote_cond_val (shift (@condvals));
5461         if (@parent_conds)
5462         {
5463             local ($ok) = 1;
5464             local ($parent_cond);
5465             foreach $parent_cond (@parent_conds)
5466             {
5467                 if (! &conditional_true_when ($parent_cond, $cond))
5468                 {
5469                     $ok = 0;
5470                     last;
5471                 }
5472             }
5474             next if ! $ok;
5475         }
5477         push (@this_conds, $cond);
5479         push (@parent_conds, $cond);
5480         local (@subvar_conds) = ();
5481         foreach (split (' ', $val))
5482         {
5483             # If a comment seen, just leave.
5484             last if /^#/;
5486             # Handle variable substitutions.
5487             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5488             {
5489                 push (@subvar_conds,
5490                       &variable_conditions_sub ($1, $var, @parent_conds));
5491             }
5492         }
5493         pop (@parent_conds);
5495         # If there are no conditional subvariables, then we want to
5496         # return this condition.  Otherwise, we want to return the
5497         # permutations of the subvariables.
5498         if (! @subvar_conds)
5499         {
5500             push (@new_conds, $cond);
5501         }
5502         else
5503         {
5504             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
5505         }
5506     }
5508     # Unset our entry in vars_scanned.  We only care about recursive
5509     # definitions.
5510     delete $vars_scanned{$var};
5512     return @new_conds
5513         if ! $parent;
5515     # If we are being called on behalf of another variable, we need to
5516     # return all possible permutations of the conditions.  We have
5517     # already handled everything in @this_conds along with their
5518     # subvariables.  We now need to add any permutations that are not
5519     # in @this_conds.
5520     local ($this_cond);
5521     foreach $this_cond (@this_conds)
5522     {
5523         local (@perms) =
5524             &variable_conditions_permutations (split('@', $this_cond));
5525         local ($perm);
5526         foreach $perm (@perms)
5527         {
5528             local ($scan);
5529             local ($ok) = 1;
5530             foreach $scan (@this_conds)
5531             {
5532                 if (&conditional_true_when ($perm, $scan)
5533                     || &conditional_true_when ($scan, $perm))
5534                 {
5535                     $ok = 0;
5536                     last;
5537                 }
5538             }
5539             next if ! $ok;
5541             if (@parent_conds)
5542             {
5543                 local ($ok) = 1;
5544                 local ($parent_cond);
5545                 foreach $parent_cond (@parent_conds)
5546                 {
5547                     if (! &conditional_true_when ($parent_cond, $perm))
5548                     {
5549                         $ok = 0;
5550                         last;
5551                     }
5552                 }
5554                 next if ! $ok;
5555             }
5557             # This permutation was not already handled, and is valid
5558             # for the parents.
5559             push (@new_conds, $perm);
5560         }
5561     }
5563     return @new_conds;
5566 # Subroutine for variable_conditions_sort
5567 sub variable_conditions_cmp
5569     local ($as) = $a;
5570     $as =~ s/[^@]//g;
5571     local ($bs) = $b;
5572     $bs =~ s/[^@]//g;
5573     return (length ($as) <=> length ($bs)
5574             || $a cmp $b);
5577 # Sort a list of conditionals so that only the exclusive ones are
5578 # retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
5579 # @COND1_TRUE@ are in the list, discard the latter.
5580 sub variable_conditions_reduce
5582     local (@conds) = @_;
5583     local (@ret) = ();
5584     local ($cond);
5585     foreach $cond (sort variable_conditions_cmp @conds)
5586     {
5587         local ($ok) = 1;
5588         local ($scan);
5589         foreach $scan (@ret)
5590         {
5591             if (&conditional_true_when ($cond, $scan))
5592             {
5593                 $ok = 0;
5594                 last;
5595             }
5596         }
5597         next if ! $ok;
5598         push (@ret, $cond);
5599     }
5601     return @ret;
5604 # Return a list of permutations of a conditional string.
5605 sub variable_conditions_permutations
5607     local (@comps) = @_;
5608     return ()
5609         if ! @comps;
5610     local ($comp) = shift (@comps);
5611     return &variable_conditions_permutations (@comps)
5612         if $comp eq '';
5613     local ($neg) = $comp;
5614     $neg =~ s/TRUE$/TRUEO/;
5615     $neg =~ s/FALSE$/TRUE/;
5616     $neg =~ s/TRUEO$/FALSE/;
5617     local (@ret);
5618     local ($sub);
5619     foreach $sub (&variable_conditions_permutations (@comps))
5620     {
5621         push (@ret, '@' . $comp . '@' . $sub);
5622         push (@ret, '@' . $neg . '@' . $sub);
5623     }
5624     if (! @ret)
5625     {
5626         push (@ret, '@' . $comp . '@');
5627         push (@ret, '@' . $neg . '@');
5628     }
5629     return @ret;
5632 # Warn if a variable is conditionally defined.  This is called if we
5633 # are using the value of a variable.
5634 sub variable_conditionally_defined
5636     local ($var, $parent) = @_;
5637     if ($conditional{$var})
5638     {
5639         if ($parent)
5640         {
5641             &am_line_error ($parent,
5642                             "warning: automake does not support conditional definition of $var in $parent");
5643         }
5644         else
5645         {
5646             &am_line_error ($parent,
5647                             "warning: automake does not support $var being defined conditionally")
5648         }
5649     }
5652 # Get the value of a variable.  This just returns $contents, but warns
5653 # if the variable is conditionally defined.
5654 sub variable_value
5656     local ($var) = @_;
5657     &variable_conditionally_defined ($var);
5658     return $contents{$var};
5661 # Convert a variable value to a list, split as whitespace.  This will
5662 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5663 # substitutions.  If COND is 'all', then all values under all
5664 # conditions should be returned; if COND is a particular condition
5665 # (all conditions are surrounded by @...@) then only the value for
5666 # that condition should be returned; otherwise, warn if VAR is
5667 # conditionally defined.  SCANNED is a global hash listing whose keys
5668 # are all the variables already scanned; it is an error to rescan a
5669 # variable.
5670 sub value_to_list
5672     local ($var, $val, $cond) = @_;
5673     local (@result);
5675     # Strip backslashes
5676     $val =~ s/\\(\n|$)/ /g;
5678     foreach (split (' ', $val))
5679     {
5680         # If a comment seen, just leave.
5681         last if /^#/;
5683         # Handle variable substitutions.
5684         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
5685         {
5686             local ($varname) = $1;
5688             # If the user uses a losing variable name, just ignore it.
5689             # This isn't ideal, but people have requested it.
5690             next if ($varname =~ /\@.*\@/);
5692             local ($from, $to);
5693             local (@temp_list);
5694             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
5695             {
5696                 $varname = $1;
5697                 $to = $3;
5698                 ($from = $2) =~ s/(\W)/\\$1/g;
5699             }
5701             # Find the value.
5702             @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
5704             # Now rewrite the value if appropriate.
5705             if ($from)
5706             {
5707                 grep (s/$from$/$to/, @temp_list);
5708             }
5710             push (@result, @temp_list);
5711         }
5712         else
5713         {
5714             push (@result, $_);
5715         }
5716     }
5718     return @result;
5721 # Return contents of variable as list, split as whitespace.  This will
5722 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
5723 # substitutions.  If COND is 'all', then all values under all
5724 # conditions should be returned; if COND is a particular condition
5725 # (all conditions are surrounded by @...@) then only the value for
5726 # that condition should be returned; otherwise, warn if VAR is
5727 # conditionally defined.  If PARENT is specified, it is the name of
5728 # the including variable; this is only used for error reports.
5729 sub variable_value_as_list_worker
5731     local ($var, $cond, $parent) = @_;
5732     local (@result);
5734     if (defined $targets{$var})
5735     {
5736         &am_line_error ($var, "\`$var' is target; expected variable");
5737     }
5738     elsif (! defined $contents{$var})
5739     {
5740         &am_line_error ($parent, "variable \`$var' not defined");
5741     }
5742     elsif (defined $vars_scanned{$var})
5743     {
5744         # `vars_scanned' is a global we use to keep track of which
5745         # variables we've already examined.
5746         &am_line_error ($parent, "variable \`$var' recursively defined");
5747     }
5748     elsif ($cond eq 'all' && $conditional{$var})
5749     {
5750         $vars_scanned{$var} = 1;
5751         local (@condvals) = split (' ', $conditional{$var});
5752         while (@condvals)
5753         {
5754             shift (@condvals);
5755             local ($val) = &unquote_cond_val (shift (@condvals));
5756             push (@result, &value_to_list ($var, $val, $cond));
5757         }
5758     }
5759     elsif ($cond && $conditional{$var})
5760     {
5761         $vars_scanned{$var} = 1;
5762         local (@condvals) = split (' ', $conditional{$var});
5763         local ($onceflag);
5764         while (@condvals)
5765         {
5766             local ($vcond) = shift (@condvals);
5767             local ($val) = &unquote_cond_val (shift (@condvals));
5768             if (&conditional_true_when ($vcond, $cond))
5769             {
5770                 # Warn if we have an ambiguity.  It's hard to know how
5771                 # to handle this case correctly.
5772                 &variable_conditionally_defined ($var, $parent)
5773                     if $onceflag;
5774                 $onceflag = 1;
5775                 push (@result, &value_to_list ($var, $val, $cond));
5776             }
5777         }
5778     }
5779     else
5780     {
5781         $vars_scanned{$var} = 1;
5782         &variable_conditionally_defined ($var, $parent);
5783         $content_seen{$var} = 1;
5784         push (@result, &value_to_list ($var, $contents{$var}, $cond));
5785     }
5787     # Unset our entry in vars_scanned.  We only care about recursive
5788     # definitions.
5789     delete $vars_scanned{$var};
5791     return @result;
5794 # This is just a wrapper for variable_value_as_list_worker that
5795 # initializes the global hash `vars_scanned'.  This hash is used to
5796 # avoid infinite recursion.
5797 sub variable_value_as_list
5799     local ($var, $cond, $parent) = @_;
5800     %vars_scanned = ();
5801     return &variable_value_as_list_worker ($var, $cond, $parent);
5804 # Define a new variable, but only if not already defined.
5805 sub define_variable
5807     local ($var, $value) = @_;
5809     if (! defined $contents{$var})
5810     {
5811         $output_vars .= $var . ' = ' . $value . "\n";
5812         $contents{$var} = $value;
5813         $content_seen{$var} = 1;
5814     }
5815     elsif ($var_was_plus_eq{$var})
5816     {
5817         &am_line_error ($var, "internally generated variable \`$var' was set with \`+='");
5818     }
5821 # Like define_variable, but the value is a list, and the variable may
5822 # be defined conditionally.  The second argument is the conditional
5823 # under which the value should be defined; this should be the empty
5824 # string to define the variable unconditionally.  The third argument
5825 # is a list holding the values to use for the variable.  The value is
5826 # pretty printed in the output file.
5827 sub define_pretty_variable
5829     local ($var, $cond, @value) = @_;
5830     if (! defined $contents{$var}
5831         || ($cond && ! &variable_defined ($var, $cond)))
5832     {
5833         $contents{$var} = join (' ', @value);
5834         if ($cond)
5835         {
5836             if ($conditional{$var})
5837             {
5838                 $conditional{$var} .= ' ';
5839             }
5840             else
5841             {
5842                 $conditional{$var} = '';
5843             }
5844             $conditional{$var} .= ($cond
5845                                    . ' '
5846                                    . &quote_cond_val ($contents{$var}));
5847         }
5848         &pretty_print ($cond . $var . ' = ', $cond, @value);
5849         $content_seen{$var} = 1;
5850     }
5853 # Like define_variable, but define a variable to be the configure
5854 # substitution by the same name.
5855 sub define_configure_variable
5857     local ($var) = @_;
5858     local ($value) = '@' . $var . '@';
5859     &define_variable ($var, $value);
5862 # Define a compiler variable.  We also handle defining the `LT'
5863 # version of the command when using libtool.
5864 sub define_compiler_variable
5866     local ($var, $ltcompile, $value) = @_;
5867     local ($name) = $var;
5868     &define_variable ($name, $value);
5869     &define_variable ('LT' . $name, $ltcompile . $value)
5870         if $seen_libtool;
5873 # Define a variable that represents a program to run.  If in Cygnus
5874 # mode, the program is searched for in the build (or source) tree.
5875 # Otherwise no searching is done at all.  Arguments are:
5876 # * VAR      Name of variable to define
5877 # * WHATDIR  Either `src' or `build', depending on where program should
5878 #            be found.  (runtest is in srcdir!)
5879 # * SUBDIR   Subdir of top-level dir
5880 # * PROGRAM  Name of program
5881 # * OVERRIDE If specified, the name of the program to use when not in
5882 #            Cygnus mode.  Defaults to PROGRAM.
5883 sub define_program_variable
5885     local ($var, $whatdir, $subdir, $program, $override) = @_;
5887     if (! $override)
5888     {
5889         $override = $program;
5890     }
5892     if ($cygnus_mode)
5893     {
5894         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
5895                          . $subdir . '/' . $program);
5896         &define_variable ($var, ('`if test -f ' . $full
5897                                  . '; then echo ' . $full . '; else echo '
5898                                  . $program . '; fi`'));
5899     }
5900     else
5901     {
5902         &define_variable ($var, $override);
5903     }
5907 ################################################################
5909 # Read Makefile.am and set up %contents.  Simultaneously copy lines
5910 # from Makefile.am into $output_trailer or $output_vars as
5911 # appropriate.  NOTE we put rules in the trailer section.  We want
5912 # user rules to come after our generated stuff.
5913 sub read_am_file
5915     local ($amfile) = @_;
5916     local (*AM_FILE);
5918     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
5919     print "automake: reading $amfile\n" if $verbose;
5921     local ($saw_bk) = 0;
5922     local ($was_rule) = 0;
5923     local ($spacing) = '';
5924     local ($comment) = '';
5925     local ($last_var_name) = '';
5926     local ($blank) = 0;
5928     while (<AM_FILE>)
5929     {
5930         if (/$IGNORE_PATTERN/o)
5931         {
5932             # Merely delete comments beginning with two hashes.
5933         }
5934         elsif (/$WHITE_PATTERN/o)
5935         {
5936             # Stick a single white line before the incoming macro or rule.
5937             $spacing = "\n";
5938             $blank = 1;
5939         }
5940         elsif (/$COMMENT_PATTERN/o)
5941         {
5942             # Stick comments before the incoming macro or rule.  Make
5943             # sure a blank line preceeds first block of comments.
5944             $spacing = "\n" unless $blank;
5945             $blank = 1;
5946             $comment .= $spacing . $_;
5947             $spacing = '';
5948         }
5949         else
5950         {
5951             last;
5952         }
5953     }
5955     $output_vars .= $comment . "\n";
5956     $comment = '';
5957     $spacing = "\n";
5959     local ($is_ok_macro);
5960     while ($_)
5961     {
5962         $_ .= "\n"
5963             unless substr ($_, -1, 1) eq "\n";
5965         # Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
5966         # used by users.  @MAINT@ is an anachronism now.
5967         $_ =~ s/\@MAINT\@//g
5968             unless $seen_maint_mode;
5970         if (/$IGNORE_PATTERN/o)
5971         {
5972             # Merely delete comments beginning with two hashes.
5973         }
5974         elsif (/$WHITE_PATTERN/o)
5975         {
5976             # Stick a single white line before the incoming macro or rule.
5977             $spacing = "\n";
5978             &am_line_error ($., "blank line following trailing backslash")
5979                 if $saw_bk;
5980         }
5981         elsif (/$COMMENT_PATTERN/o)
5982         {
5983             # Stick comments before the incoming macro or rule.
5984             $comment .= $spacing . $_;
5985             $spacing = '';
5986             &am_line_error ($., "comment following trailing backslash")
5987                 if $saw_bk;
5988         }
5989         elsif ($saw_bk)
5990         {
5991             if ($was_rule)
5992             {
5993                 $output_trailer .= join ('', @conditional_stack) . $_;
5994                 $saw_bk = /\\$/;
5995             }
5996             else
5997             {
5998                 $saw_bk = /\\$/;
5999                 $contents{$last_var_name} .= ' '
6000                     unless $contents{$last_var_name} =~ /\s$/;
6001                 $contents{$last_var_name} .= $_;
6002                 if (@conditional_stack)
6003                 {
6004                     $conditional{$last_var_name} .= &quote_cond_val ($_);
6005                 }
6006             }
6007         }
6008         elsif (/$IF_PATTERN/o)
6009         {
6010             &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
6011                 if (! $configure_cond{$1});
6012             push (@conditional_stack, "\@" . $1 . "_TRUE\@");
6013         }
6014         elsif (/$ELSE_PATTERN/o)
6015         {
6016             if (! @conditional_stack)
6017             {
6018                 &am_line_error ($., "else without if");
6019             }
6020             elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
6021             {
6022                 &am_line_error ($., "else after else");
6023             }
6024             else
6025             {
6026                 $conditional_stack[$#conditional_stack]
6027                     =~ s/_TRUE\@$/_FALSE\@/;
6028             }
6029         }
6030         elsif (/$ENDIF_PATTERN/o)
6031         {
6032             if (! @conditional_stack)
6033             {
6034                 &am_line_error ($., "endif without if");
6035             }
6036             else
6037             {
6038                 pop @conditional_stack;
6039             }
6040         }
6041         elsif (/$RULE_PATTERN/o)
6042         {
6043             # Found a rule.
6044             $was_rule = 1;
6045             if (defined $contents{$1}
6046                 && (@conditional_stack
6047                     ? ! defined $conditional{$1}
6048                     : defined $conditional{$1}))
6049             {
6050                 &am_line_error ($1,
6051                                 "$1 defined both conditionally and unconditionally");
6052             }
6053             # Value here doesn't matter; for targets we only note
6054             # existence.
6055             $contents{$1} = 1;
6056             $targets{$1} = 1;
6057             local ($cond_string) = join ('', @conditional_stack);
6058             if (@conditional_stack)
6059             {
6060                 if ($conditional{$1})
6061                 {
6062                     &check_ambiguous_conditional ($1, $cond_string);
6063                     $conditional{$1} .= ' ';
6064                 }
6065                 else
6066                 {
6067                     $conditional{$1} = '';
6068                 }
6069                 $conditional{$1} .= $cond_string . ' 1';
6070             }
6071             $content_lines{$1} = $.;
6072             $output_trailer .= $comment . $spacing . $cond_string . $_;
6073             $comment = $spacing = '';
6074             $saw_bk = /\\$/;
6076             # Check the rule for being a suffix rule. If so, store in
6077             # a hash.
6079             local ($source_suffix);
6080             local ($object_suffix);
6082             if (($source_suffix, $object_suffix) = ($1 =~ $SUFFIX_RULE_PATTERN)) 
6083             {
6084               $suffix_rules{$source_suffix} = $object_suffix;
6085               print "Sources ending in .$source_suffix become .$object_suffix\n" if $verbose;
6086               $source_suffix_pattern = "(" . join('|', keys %suffix_rules) . ")";
6087             }
6089             # FIXME: make sure both suffixes are in SUFFIXES? Or set
6090             # SUFFIXES from suffix_rules?
6091         }
6092         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
6093                || /$BOGUS_MACRO_PATTERN/o)
6094         {
6095             # Found a macro definition.
6096             $was_rule = 0;
6097             $last_var_name = $1;
6098             if (defined $contents{$1}
6099                 && (@conditional_stack
6100                     ? ! defined $conditional{$1}
6101                     : defined $conditional{$1}))
6102             {
6103                 &am_line_error ($1,
6104                                 "$1 defined both conditionally and unconditionally");
6105             }
6106             local ($value);
6107             if ($3 ne '' && substr ($3, -1) eq "\\")
6108             {
6109                 # We preserve the `\' because otherwise the long lines
6110                 # that are generated will be truncated by broken
6111                 # `sed's.
6112                 $value = $3 . "\n";
6113             }
6114             else
6115             {
6116                 $value = $3;
6117             }
6118             local ($type) = $2;
6120             if (! defined $contents{$last_var_name})
6121             {
6122                 # The first assignment to a macro sets the line
6123                 # number.  Ideally I suppose we would associate line
6124                 # numbers with random bits of text.
6125                 $content_lines{$last_var_name} = $.;
6127                 # If first assignment, set `+=' indicator.
6128                 $var_was_plus_eq{$last_var_name} =
6129                     ($type eq '+'
6130                      && ! defined $am_var_defs{$last_var_name});
6131             }
6133             if ($type eq '+')
6134             {
6135                 if (! defined $contents{$last_var_name}
6136                     && defined $am_var_defs{$last_var_name})
6137                 {
6138                     $contents{$last_var_name} = $am_var_defs{$last_var_name};
6139                 }
6140                 $contents{$last_var_name} .= ' ' . $value;
6141             }
6142             else
6143             {
6144                 $contents{$last_var_name} = $value;
6145             }
6146             local ($cond_string) = join ('', @conditional_stack);
6147             if (@conditional_stack)
6148             {
6149                 local ($found) = 0;
6150                 local ($val);
6151                 if ($conditional{$last_var_name})
6152                 {
6153                     if ($type eq '+')
6154                     {
6155                         # If we're adding to the conditional, and it
6156                         # exists, then we might want to simply replace
6157                         # the old value with the new one.
6158                         local (@new_vals, @cond_vals);
6159                         @cond_vals = split (' ', $conditional{$last_var_name});
6160                         while (@cond_vals)
6161                         {
6162                             local ($vcond) = shift (@cond_vals);
6163                             push (@new_vals, $vcond);
6164                             if (&conditional_same ($vcond, $cond_string))
6165                             {
6166                                 $found = 1;
6167                                 $val = (&unquote_cond_val (shift (@cond_vals))
6168                                         . ' ' . $value);
6169                                 push (@new_vals, &quote_cond_val ($val));
6170                             }
6171                             else
6172                             {
6173                                 push (@new_vals, shift (@cond_vals));
6174                             }
6175                         }
6176                         if ($found)
6177                         {
6178                             $conditional{$last_var_name}
6179                                 = join (' ', @new_vals);
6180                         }
6181                     }
6183                     if (! $found)
6184                     {
6185                         &check_ambiguous_conditional ($last_var_name,
6186                                                       $cond_string);
6187                         $conditional{$last_var_name} .= ' ';
6188                         $val = $value;
6189                     }
6190                 }
6191                 else
6192                 {
6193                     $conditional{$last_var_name} = '';
6194                     $val = $contents{$last_var_name};
6195                 }
6196                 if (! $found)
6197                 {
6198                     $conditional{$last_var_name} .= ($cond_string
6199                                                      . ' '
6200                                                      . &quote_cond_val ($val));
6201                 }
6202             }
6204             # FIXME: this doesn't always work correctly; it will group
6205             # all comments for a given variable, no matter where
6206             # defined.
6207             $am_vars{$last_var_name} = $comment . $spacing;
6208             $def_type{$last_var_name} = ($type eq ':') ? ':' : '';
6209             push (@var_list, $last_var_name);
6210             $comment = $spacing = '';
6211             $saw_bk = /\\$/;
6213             # Error if bogus.
6214             &am_line_error ($., "bad macro name \`$last_var_name'")
6215                 if ! $is_ok_macro;
6216         }
6217         elsif (/$INCLUDE_PATTERN/o)
6218         {
6219             local ($path) = $1;
6221             if ($path =~ s/^\$\(top_srcdir\)\///)
6222             {
6223                 push (@include_stack, "\$\(top_srcdir\)/$path");
6224             }
6225             else
6226             {
6227                 $path =~ s/\$\(srcdir\)\///;
6228                 push (@include_stack, "\$\(srcdir\)/$path");
6229                 $path = $relative_dir . "/" . $path;
6230             }
6231             &read_am_file ($path);
6232         }
6233         else
6234         {
6235             # This isn't an error; it is probably a continued rule.
6236             # In fact, this is what we assume.
6237             $was_rule = 1;
6238             $output_trailer .= ($comment . $spacing
6239                                 . join ('', @conditional_stack) . $_);
6240             $comment = $spacing = '';
6241             $saw_bk = /\\$/;
6242         }
6244         $_ = <AM_FILE>;
6245     }
6247     $output_trailer .= $comment;
6249     &am_error ("unterminated conditionals: " . join (' ', @conditional_stack))
6250         if (@conditional_stack);
6253 # A helper for read_main_am_file which initializes configure variables
6254 # and variables from header-vars.am.  This is a subr so we can call it
6255 # twice.
6256 sub define_standard_variables
6258     # Compute relative location of the top object directory.
6259     local (@topdir) = ();
6260     foreach (split (/\//, $relative_dir))
6261     {
6262         next if $_ eq '.' || $_ eq '';
6263         if ($_ eq '..')
6264         {
6265             pop @topdir;
6266         }
6267         else
6268         {
6269             push (@topdir, '..');
6270         }
6271     }
6272     @topdir = ('.') if ! @topdir;
6274     $top_builddir = join ('/', @topdir);
6275     local ($build_rx);
6276     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
6277     $output_vars .= &file_contents_with_transform
6278                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
6279                          'header-vars');
6281     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
6282     # this should use generic %configure_vars method.
6283     if ($seen_canonical)
6284     {
6285         local ($curs, %vars);
6286         $vars{'host_alias'} = 'host_alias';
6287         $vars{'host_triplet'} = 'host';
6288         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
6289         {
6290             $vars{'build_alias'} = 'build_alias';
6291             $vars{'build_triplet'} = 'build';
6292             $vars{'target_alias'} = 'target_alias';
6293             $vars{'target_triplet'} = 'target';
6294         }
6295         foreach $curs (sort keys %vars)
6296         {
6297             $output_vars .= "$curs = \@$vars{$curs}\@\n";
6298             $contents{$curs} = "\@$vars{$curs}\@";
6299         }
6300     }
6302     local ($curs);
6303     foreach $curs (sort keys %configure_vars)
6304     {
6305         &define_configure_variable ($curs);
6306     }
6309 # Read main am file.
6310 sub read_main_am_file
6312     local ($amfile) = @_;
6314     # The keys here are variables we want to dump at the end of this
6315     # function.  The values are corresponding comments.
6316     local (%am_vars) = ();
6317     local (@var_list) = ();
6318     local (%def_type) = ();
6320     # We want to predefine as many variables as possible.  This lets
6321     # the user set them with `+=' in Makefile.am.  However, we don't
6322     # want these initial definitions to end up in the output quite
6323     # yet.  So we adopt a hack: read the `.am' file twice, throwing
6324     # away the output the first time.  We also squirrel away a list of
6325     # all the variables defined by the .am file so that we know which
6326     # ones to remove from the content list.
6328     # First pass.
6329     &define_standard_variables;
6330     local (%saved_contents) = %contents;
6332     # Read user file, but discard text of variable assignments we just
6333     # made.
6334     $output_vars = '';
6335     &read_am_file ($amfile);
6337     # Now dump the variables that were defined.  We do it in the same
6338     # order in which they were defined (skipping duplicates).
6339     local (%done);
6340     foreach $curs (@var_list)
6341     {
6342         next if $done{$curs};
6343         $done{$curs} = 1;
6345         $output_vars .= $am_vars{$curs};
6346         if ($conditional{$curs})
6347         {
6348             local (@cond_vals) = split (' ', $conditional{$curs});
6349             while (@cond_vals)
6350             {
6351                 local ($vcond) = shift (@cond_vals);
6352                 local ($val) = &unquote_cond_val (shift (@cond_vals));
6353                 $output_vars .= ($vcond . $curs . ' '
6354                                  . $def_type{$curs} . "= \\\n");
6355                 local ($line);
6356                 foreach $line (split ("\n", $val))
6357                 {
6358                     $output_vars .= $vcond . $line . "\n";
6359                 }
6360             }
6361         }
6362         else
6363         {
6364             $output_vars .= ($curs . ' ' . $def_type{$curs} . '= '
6365                              . $contents{$curs} . "\n");
6366         }
6367     }
6369     # Generate copyright header for generated Makefile.in.
6370     local ($ov) = $output_vars;
6371     $output_vars = ("# $in_file_name generated automatically by automake "
6372                    . $VERSION . " from $am_file_name\n");
6373     $output_vars .= $gen_copyright;
6375     # Now go through and delete all the variables that the user did
6376     # not change.
6377     local ($var);
6378     foreach $var (keys %saved_contents)
6379     {
6380         if ($contents{$var} eq $saved_contents{$var})
6381         {
6382             delete $contents{$var};
6383         }
6384     }
6386     # Re-read the standard variables, and this time keep their
6387     # contributions to the output.  Then add the user's output to the
6388     # end.
6389     &define_standard_variables;
6390     $output_vars .= $ov;
6394 ################################################################
6396 sub initialize_global_constants
6398     # Values for AC_CANONICAL_*
6399     $AC_CANONICAL_HOST = 1;
6400     $AC_CANONICAL_SYSTEM = 2;
6402     # Associative array of standard directory names.  Entry is TRUE if
6403     # corresponding directory should be installed during
6404     # 'install-exec' phase.
6405     %exec_dir_p =
6406         ('bin', 1,
6407          'sbin', 1,
6408          'libexec', 1,
6409          'data', 0,
6410          'sysconf', 1,
6411          'localstate', 1,
6412          'lib', 1,
6413          'info', 0,
6414          'man', 0,
6415          'include', 0,
6416          'oldinclude', 0,
6417          'pkgdata', 0,
6418          'pkglib', 1,
6419          'pkginclude', 0
6420          );
6422     # Commonly found files we look for and automatically include in
6423     # DISTFILES.
6424     @common_files =
6425         (
6426          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
6427          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
6428          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
6429          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
6430          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
6431          'ylwrap', 'acinclude.m4', @libtoolize_files,
6432          'missing'
6433          );
6435     # Commonly used files we auto-include, but only sometimes.
6436     @common_sometimes =
6437         (
6438          "aclocal.m4", "acconfig.h", "config.h.top",
6439          "config.h.bot", "stamp-h.in", 'stamp-vti'
6440          );
6442     $USAGE = "\
6443   -a, --add-missing     add missing standard files to package
6444   --amdir=DIR           directory storing config files
6445   --build-dir=DIR       directory where build being done (for dependencies)
6446   -c, --copy            with -a, copy missing files (default is symlink)
6447   --cygnus              assume program is part of Cygnus-style tree
6448   --foreign             set strictness to foreign
6449   --gnits               set strictness to gnits
6450   --gnu                 set strictness to gnu
6451   --help                print this help, then exit
6452   -i, --include-deps    include generated dependencies in Makefile.in
6453   --no-force            only update Makefile.in's that are out of date
6454   -o DIR, --output-dir=DIR
6455                         put generated Makefile.in's into DIR
6456   --srcdir-name=DIR     name used for srcdir (for dependencies)
6457   -v, --verbose         verbosely list files processed
6458   --version             print version number, then exit\n";
6460     # Copyright on generated Makefile.ins.
6461     $gen_copyright = "\
6462 # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
6463 # This Makefile.in is free software; the Free Software Foundation
6464 # gives unlimited permission to copy and/or distribute it,
6465 # with or without modifications, as long as this notice is preserved.
6467 # This program is distributed in the hope that it will be useful,
6468 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
6469 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6470 # PARTICULAR PURPOSE.
6473     # Ignore return result from chmod, because it might give an error
6474     # if we chmod a symlink.
6475     $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
6476     $dist{'dist-bzip2'} = ("\t"
6477                            . '$(TAR) ch$(AMTARFLAGS)f - $(distdir) | bzip --best -c > $(distdir).bz2'
6478                            . "\n");
6479     $dist{'dist-tarZ'} = ("\t"
6480                      . '$(TAR) ch$(AMTARFLAGS)f - $(distdir) | compress -c > $(distdir).tar.Z'
6481                      . "\n");
6482     $dist{'dist-shar'} = ("\t"
6483                      . 'shar $(distdir) | gzip > $(distdir).shar.gz'
6484                      . "\n");
6485     $dist{'dist-zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
6486     $dist{'dist'} = ("\t"
6487                      .  'tar ch$(AMTARFLAGS)f - $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).tar.gz'
6488                      . "\n");
6489     $dist_trailer = "\t" . '-rm -rf $(distdir)' . "\n";
6492 # (Re)-Initialize per-Makefile.am variables.
6493 sub initialize_per_input
6495     # These two variables are used when generating each Makefile.in.
6496     # They hold the Makefile.in until it is ready to be printed.
6497     $output_rules = '';
6498     $output_vars = '';
6499     $output_trailer = '';
6500     $output_all = '';
6501     $output_header = '';
6503     # Suffixes found during a run.
6504     @suffixes = ();
6506     # This holds the contents of a Makefile.am, as parsed by
6507     # read_am_file.
6508     %contents = ();
6510     # This holds the names which are targets.  These also appear in
6511     # %contents.
6512     %targets = ();
6514     # This maps a variable name onto a flag.  The flag is true iff the
6515     # variable was first defined with `+='.
6516     %var_was_plus_eq = ();
6518     # This holds definitions of all variables defined in .am files.
6519     # This is used during startup to determine which variables can be
6520     # assigned with `+='.
6521     %am_var_defs = ();
6523     # For a variable or target which is defined conditionally, this
6524     # holds an array of the conditional values.  The array is composed
6525     # of pairs of condition strings (the variables which configure
6526     # will substitute) and values (the value of a target is
6527     # meaningless).  For an unconditional variable, this is empty.
6528     %conditional = ();
6530     # This holds the line numbers at which various elements of
6531     # %contents are defined.
6532     %content_lines = ();
6534     # This holds a 1 if a particular variable was examined.
6535     %content_seen = ();
6537     # This is the conditional stack.
6538     @conditional_stack = ();
6540     # This holds the set of included files.
6541     @include_stack = ();
6543     # This holds the "relative directory" of the current Makefile.in.
6544     # Eg for src/Makefile.in, this is "src".
6545     $relative_dir = '';
6547     # This holds a list of files that are included in the
6548     # distribution.
6549     %dist_common = ();
6551     # List of dependencies for the obvious targets.
6552     @install_data = ();
6553     @install_exec = ();
6554     @uninstall = ();
6555     @installdirs = ();
6557     @info = ();
6558     @dvi = ();
6559     @all = ();
6560     @check = ();
6561     @check_tests = ();
6562     @installcheck = ();
6563     @clean = ();
6565     @phony = ();
6567     # A list of files deleted by `maintainer-clean'.
6568     @maintainer_clean_files = ();
6570     # These are pretty obvious, too.  They are used to define the
6571     # SOURCES and OBJECTS variables.
6572     @sources = ();
6573     @objects = ();
6574     # Sources which go in the distribution.
6575     @dist_sources = ();
6577     # This hash maps object file names onto their corresponding source
6578     # file names.  This is used to ensure that each object is created
6579     # by a single source file.
6580     %object_map = ();
6582     # These variables track inclusion of various compile-related .am
6583     # files.  $included_generic_compile is TRUE if the basic code has
6584     # been included.  $included_knr_compile is TRUE if the ansi2knr
6585     # code has been included.  $included_libtool_compile is TRUE if
6586     # libtool support has been included.
6587     $included_generic_compile = 0;
6588     $included_knr_compile = 0;
6589     $included_libtool_compile = 0;
6591     # TRUE if install targets should work recursively.
6592     $recursive_install = 0;
6594     # All .P files.
6595     %dep_files = ();
6597     # Strictness levels.
6598     $strictness = $default_strictness;
6599     $strictness_name = $default_strictness_name;
6601     # Options from AUTOMAKE_OPTIONS.
6602     %options = ();
6604     # Whether or not dependencies are handled.  Can be further changed
6605     # in handle_options.
6606     $use_dependencies = $cmdline_use_dependencies;
6608     # Per Makefile.am.
6609     $local_maint_charset = $maint_charset;
6611     # All yacc and lex source filenames for this directory.  Use
6612     # filenames instead of raw count so that multiple instances are
6613     # counted correctly (eg one yacc file can appear in multiple
6614     # programs without harm).
6615     %yacc_sources = ();
6616     %lex_sources = ();
6618     # This is a list of all targets to run during "make dist".
6619     @dist_targets = ();
6621     # Keys in this hash are the basenames of files which must depend
6622     # on ansi2knr.
6623     %de_ansi_files = ();
6625     # This maps the source extension of a suffix rule to its
6626     # corresponding output extension.
6627     %suffix_rules = ();
6629     # This is the name of the recursive `all' target to use.
6630     $all_target = 'all-recursive';
6632     # This keeps track of which extensions we've seen (that we care
6633     # about).
6634     %extension_seen = ();
6636     # This is random scratch space for the language finish functions.
6637     # Don't randomly overwrite it; examine other uses of keys first.
6638     %language_scratch = ();
6642 ################################################################
6644 # Return contents of a file from $am_dir, automatically skipping
6645 # macros or rules which are already known.  Runs command on each line
6646 # as it is read; this command can modify $_.
6647 sub file_contents_with_transform
6649     local ($command, $basename) = @_;
6650     local ($file) = $am_dir . '/' . $basename . '.am';
6652     if ($command ne '' && substr ($command, -1) ne ';')
6653     {
6654         die "automake: programming error in file_contents_with_transform: $command\n";
6655     }
6657     open (FC_FILE, $file)
6658         || die "automake: installation error: cannot open \`$file'\n";
6659     # Looks stupid?
6660     # print "automake: reading $file\n" if $verbose;
6662     local ($was_rule) = 0;
6663     local ($result_vars) = '';
6664     local ($result_rules) = '';
6665     local ($comment) = '';
6666     local ($spacing) = "\n";
6667     local ($skipping) = 0;
6668     local ($had_chars);
6670     while (<FC_FILE>)
6671     {
6672         $_ =~ s/\@MAINTAINER_MODE_TRUE\@//g
6673             unless $seen_maint_mode;
6675         $had_chars = length ($_) && $_ ne "\n";
6676         eval $command;
6677         # If the transform caused all the characters to go away, then
6678         # ignore the line.  Why do this?  Because in Perl 4, a "next"
6679         # inside of an eval doesn't affect a loop outside the eval.
6680         # So we can't pass in a "transform" that uses next.  We used
6681         # to do this.  "Empty" also means consisting of a single
6682         # newline.
6683         next if $had_chars && ($_ eq '' || $_ eq "\n");
6685         if (/$IGNORE_PATTERN/o)
6686         {
6687             # Merely delete comments beginning with two hashes.
6688         }
6689         elsif (/$WHITE_PATTERN/o)
6690         {
6691             # Stick a single white line before the incoming macro or rule.
6692             $spacing = "\n";
6693             &am_line_error ($., "blank line following trailing backslash")
6694                 if $saw_bk;
6695         }
6696         elsif (/$COMMENT_PATTERN/o)
6697         {
6698             # Stick comments before the incoming macro or rule.
6699             $comment .= $spacing . $_;
6700             $spacing = '';
6701             &am_line_error ($., "comment following trailing backslash")
6702                 if $saw_bk;
6703         }
6704         elsif ($saw_bk)
6705         {
6706             if ($was_rule)
6707             {
6708                 $result_rules .= $_ if ! $skipping;
6709             }
6710             else
6711             {
6712                 $result_vars .= $_ if ! $skipping;
6713             }
6714             $saw_bk = /\\$/;
6715         }
6716         elsif (/$RULE_PATTERN/o)
6717         {
6718             # Found a rule.
6719             $was_rule = 1;
6720             $skipping = defined $contents{$1};
6721             $result_rules .= $comment . $spacing . $_ if ! $skipping;
6722             $comment = $spacing = '';
6723             $saw_bk = /\\$/;
6724         }
6725         elsif (/$MACRO_PATTERN/o)
6726         {
6727             # Found a variable reference.
6728             $was_rule = 0;
6729             $skipping = defined $contents{$1};
6730             $result_vars .= $comment . $spacing . $_ if ! $skipping;
6731             $comment = $spacing = '';
6732             $saw_bk = /\\$/;
6733             print STDERR "automake: programming error: .am macro \`$1' with trailing backslash\n"
6734                 if $saw_bk;
6735             $am_var_defs{$1} = $3;
6736         }
6737         else
6738         {
6739             # This isn't an error; it is probably a continued rule.
6740             # In fact, this is what we assume.
6741             $was_rule = 1;
6742             $result_rules .= $comment . $spacing . $_ if ! $skipping;
6743             $comment = $spacing = '';
6744             $saw_bk = /\\$/;
6745         }
6746     }
6748     close (FC_FILE);
6749     return $result_vars . $result_rules . $comment;
6752 # Like file_contents_with_transform, but no transform.
6753 sub file_contents
6755     return &file_contents_with_transform ('', @_);
6758 # Find all variable prefixes that are used for install directories.  A
6759 # prefix `zar' qualifies iff:
6760 # * `zardir' is a variable.
6761 # * `zar_PRIMARY' is a variable.
6762 sub am_primary_prefixes
6764     local ($primary, $can_dist, @prefixes) = @_;
6766     local (%valid, $varname);
6767     grep ($valid{$_} = 0, @prefixes);
6768     $valid{'EXTRA'} = 0;
6769     foreach $varname (keys %contents)
6770     {
6771         if ($varname =~ /^(dist_|nodist_)?(.*)_$primary$/)
6772         {
6773             if (($1 ne '' && ! $can_dist)
6774                 || (! defined $valid{$2}
6775                     && ! &variable_defined ($2 . 'dir')
6776                     # Note that a configure variable is always
6777                     # legitimate.  It is natural to name such
6778                     # variables after the primary, so we explicitly
6779                     # allow it.
6780                     && ! defined $configure_vars{$varname}))
6781             {
6782                 &am_line_error ($varname, "invalid variable \`$varname'");
6783             }
6784             else
6785             {
6786                 # Ensure all extended prefixes are actually used.
6787                 $valid{$1 . $2} = 1;
6788             }
6789         }
6790     }
6792     return %valid;
6795 # Handle `where_HOW' variable magic.  Does all lookups, generates
6796 # install code, and possibly generates code to define the primary
6797 # variable.  The first argument is the name of the .am file to munge,
6798 # the second argument is the primary variable (eg HEADERS), and all
6799 # subsequent arguments are possible installation locations.  Returns
6800 # list of all values of all _HOW targets.
6802 # FIXME: this should be rewritten to be cleaner.  It should be broken
6803 # up into multiple functions.
6805 # Usage is: am_install_var (OPTION..., file, HOW, where...)
6806 sub am_install_var
6808     local (@args) = @_;
6810     local ($do_clean) = 0;
6811     local ($do_require) = 1;
6812     local ($can_dist) = 0;
6813     local ($default_dist) = 0;
6815     local ($ltxform);
6816     if (defined $configure_vars{'LIBTOOL'})
6817     {
6818         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
6819         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
6820     }
6821     else
6822     {
6823         # Delete '@LIBTOOL ...@'
6824         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
6825     }
6827     local ($cygxform);
6828     if (! $seen_exeext)
6829     {
6830         $cygxform = 's/\@EXEEXT\@//g;';
6831     }
6832     else
6833     {
6834         $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
6835     }
6837     while (@args)
6838     {
6839         if ($args[0] eq '-clean')
6840         {
6841             $do_clean = 1;
6842         }
6843         elsif ($args[0] eq '-noextra')
6844         {
6845             $do_require = 0;
6846         }
6847         elsif ($args[0] eq '-candist')
6848         {
6849             $can_dist = 1;
6850         }
6851         elsif ($args[0] eq '-defaultdist')
6852         {
6853             $default_dist = 1;
6854             $can_dist = 1;
6855         }
6856         elsif ($args[0] !~ /^-/)
6857         {
6858             last;
6859         }
6860         shift (@args);
6861     }
6863     local ($file, $primary, @prefixes) = @args;
6865     local (@used) = ();
6866     local (@result) = ();
6868     # Now that configure substitutions are allowed in where_HOW
6869     # variables, it is an error to actually define the primary.  We
6870     # allow `JAVA', as it is customarily used to mean the Java
6871     # interpreter.  This is but one of several Java hacks.
6872     &am_line_error ($primary, "\`$primary' is an anachronism")
6873         if &variable_defined ($primary) && $primary ne 'JAVA';
6876     # Look for misspellings.  It is an error to have a variable ending
6877     # in a "reserved" suffix whose prefix is unknown, eg
6878     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
6879     # variable of the same name (with "dir" appended) exists.  For
6880     # instance, if the variable "zardir" is defined, then
6881     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
6882     # flexibility in those cases which need it.
6883     local (%valid) = &am_primary_prefixes ($primary, $can_dist, @prefixes);
6885     # If a primary includes a configure substitution, then the EXTRA_
6886     # form is required.  Otherwise we can't properly do our job.
6887     local ($require_extra);
6888     local ($warned_about_extra) = 0;
6890     local ($clean_file) = $file . '-clean';
6891     local ($one_name);
6892     local ($X);
6893     local ($nodir_name);
6894     foreach $X (sort keys %valid)
6895     {
6896         $one_name = $X . '_' . $primary;
6897         if (&variable_defined ($one_name))
6898         {
6899             # If files should be distributed, do so.
6900             if ($can_dist)
6901             {
6902                 if (($default_dist && $one_name !~ /^nodist_/)
6903                     || (! $default_dist && $one_name =~ /^dist_/))
6904                 {
6905                     &push_dist_common ('$(' . $one_name . ')');
6906                 }
6907                 ($nodir_name = $X) =~ s/^(dist|nodist)_//;
6908             }
6909             else
6910             {
6911                 $nodir_name = $X;
6912             }
6914             # Append actual contents of where_PRIMARY variable to
6915             # result.
6916             local ($rcurs);
6917             foreach $rcurs (&variable_value_as_list ($one_name, 'all'))
6918             {
6919                 # Skip configure substitutions.  Possibly bogus.
6920                 if ($rcurs =~ /^\@.*\@$/)
6921                 {
6922                     if ($X eq 'EXTRA')
6923                     {
6924                         if (! $warned_about_extra)
6925                         {
6926                             $warned_about_extra = 1;
6927                             {
6928                                 &am_line_error ($one_name,
6929                                                 "\`$one_name' contains configure substitution, but shouldn't");
6930                             }
6931                         }
6932                     }
6933                     # Check here to make sure variables defined in
6934                     # configure.in do not imply that EXTRA_PRIMARY
6935                     # must be defined.
6936                     elsif (! defined $configure_vars{$one_name})
6937                     {
6938                         $require_extra = $one_name
6939                             if $do_require;
6940                     }
6942                     next;
6943                 }
6945                 push (@result, $rcurs);
6946             }
6948             # "EXTRA" shouldn't be used when generating clean targets,
6949             # all, or install targets.
6950             if ($X eq 'EXTRA')
6951             {
6952                 # We used to warn if EXTRA_FOO was defined uselessly,
6953                 # but this was annoying.
6954                 next;
6955             }
6957             # A blatant hack: we rewrite each _PROGRAMS primary to
6958             # include EXEEXT when in Cygwin32 mode.
6959             if ($seen_exeext && $primary eq 'PROGRAMS')
6960             {
6961                 local (@conds) = &variable_conditions ($one_name);
6962                 local (@one_binlist);
6964                 # FIXME: this definitely loses aesthetically; it
6965                 # redefines $ONE_NAME.  Instead we should arrange for
6966                 # variable definitions to be output later, instead of
6967                 # at scan time.
6969                 if (! @conds)
6970                 {
6971                     @one_binlist = ();
6972                     foreach $rcurs (&variable_value_as_list ($one_name, ''))
6973                     {
6974                         if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
6975                         {
6976                             push (@one_binlist, $rcurs);
6977                         }
6978                         else
6979                         {
6980                             push (@one_binlist, $rcurs . '$(EXEEXT)');
6981                         }
6982                     }
6984                     delete $contents{$one_name};
6985                     &define_pretty_variable ($one_name, '', @one_binlist);
6986                 }
6987                 else
6988                 {
6989                     local ($cond);
6990                     local ($condvals) = '';
6991                     foreach $cond (@conds)
6992                     {
6993                         @one_binlist = ();
6994                         local (@condval) = &variable_value_as_list ($one_name,
6995                                                                     $cond);
6996                         foreach $rcurs (@condval)
6997                         {
6998                             if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
6999                             {
7000                                 push (@one_binlist, $rcurs);
7001                             }
7002                             else
7003                             {
7004                                 push (@one_binlist, $rcurs . '$(EXEEXT)');
7005                             }
7006                         }
7008                         push (@condvals, $cond);
7009                         push (@condvals, join (' ', @one_binlist));
7010                     }
7012                     delete $contents{$one_name};
7014                     while (@condvals)
7015                     {
7016                         $cond = shift (@condvals);
7017                         local (@val) = split (' ', shift (@condvals));
7018                         &define_pretty_variable ($one_name, $cond, @val);
7019                     }
7020                 }
7021             }
7023             if ($do_clean)
7024             {
7025                 $output_rules .=
7026                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
7027                                                    . $cygxform,
7028                                                    $clean_file);
7030                 push (@clean, $X . $primary);
7031                 &push_phony_cleaners ($X . $primary);
7032             }
7034             if ($X eq 'check')
7035             {
7036                 push (@check, '$(' . $one_name . ')');
7037             }
7038             else
7039             {
7040                 push (@used, '$(' . $one_name . ')');
7041             }
7042             if ($X eq 'noinst' || $X eq 'check')
7043             {
7044                 # Objects which don't get installed by default.
7045                 next;
7046             }
7048             $output_rules .=
7049                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
7050                                                . 's/\@NDIR\@/' . $nodir_name . '/go;'
7051                                                . $ltxform . $cygxform,
7052                                                $file);
7054             push (@uninstall, 'uninstall-' . $X . $primary);
7055             push (@phony, 'uninstall-' . $X . $primary);
7056             push (@installdirs, '$(DESTDIR)$(' . $X . 'dir)');
7057             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
7058             {
7059                 push (@install_exec, 'install-' . $X . $primary);
7060                 push (@phony, 'install-' . $X . $primary);
7061             }
7062             else
7063             {
7064                 push (@install_data, 'install-' . $X . $primary);
7065                 push (@phony, 'install-' . $X . $primary);
7066             }
7067         }
7068     }
7070     # The JAVA variable is used as the name of the Java interpreter.
7071     if (@used && $primary ne 'JAVA')
7072     {
7073         # Define it.
7074         &define_pretty_variable ($primary, '', @used);
7075         $output_vars .= "\n";
7076     }
7078     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7079     {
7080         &am_line_error ($require_extra,
7081                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
7082     }
7084     # Push here because PRIMARY might be configure time determined.
7085     push (@all, '$(' . $primary . ')')
7086         if @used && $primary ne 'JAVA';
7088     return (@result);
7092 ################################################################
7094 # This variable is local to the "require file" set of functions.
7095 @require_file_paths = ();
7097 # Verify that the file must exist in the current directory.  Usage:
7098 # require_file (isconfigure, line_number, strictness, file) strictness
7099 # is the strictness level at which this file becomes required.  Must
7100 # set require_file_paths before calling this function.
7101 # require_file_paths is set to hold a single directory (the one in
7102 # which the first file was found) before return.
7103 sub require_file_internal
7105     local ($is_configure, $line, $mystrict, @files) = @_;
7106     local ($file, $fullfile);
7107     local ($found_it, $errfile, $errdir);
7108     local ($save_dir);
7110     foreach $file (@files)
7111     {
7112         $found_it = 0;
7113         foreach $dir (@require_file_paths)
7114         {
7115             if ($dir eq '.')
7116             {
7117                 $fullfile = $relative_dir . "/" . $file;
7118                 $errdir = $relative_dir unless $errdir;
7119             }
7120             else
7121             {
7122                 $fullfile = $dir . "/" . $file;
7123                 $errdir = $dir unless $errdir;
7124             }
7126             # Use different name for "error filename".  Otherwise on
7127             # an error the bad file will be reported as eg
7128             # `../../install-sh' when using the default
7129             # config_aux_path.
7130             $errfile = $errdir . '/' . $file;
7132             if (-f $fullfile)
7133             {
7134                 $found_it = 1;
7135                 # FIXME: Once again, special-case `.'.
7136                 &push_dist_common ($file)
7137                     if $dir eq $relative_dir || $dir eq '.';
7138                 $save_dir = $dir;
7139                 last;
7140             }
7141         }
7143         if ($found_it)
7144         {
7145             # Prune the path list.
7146             @require_file_paths = $save_dir;
7147         }
7148         else
7149         {
7150             if ($strictness >= $mystrict)
7151             {
7152                 local ($trailer) = '';
7153                 local ($suppress) = 0;
7155                 # Only install missing files according to our desired
7156                 # strictness level.
7157                 local ($message) = "required file \`$errfile' not found";
7158                 if ($add_missing)
7159                 {
7160                     $suppress = 1;
7162                     # Maybe run libtoolize.
7163                     if ($seen_libtool
7164                         && grep ($_ eq $file, @libtoolize_files)
7165                         && system ('libtoolize', '--automake'))
7166                     {
7167                         $message = "installing \`$errfile'";
7168                         $suppress = 0;
7169                         $trailer = "; cannot run \`libtoolize': $!";
7170                     }
7171                     elsif (-f ($am_dir . '/' . $file))
7172                     {
7173                         # Install the missing file.  Symlink if we
7174                         # can, copy if we must.  Note: delete the file
7175                         # first, in case it is a dangling symlink.
7176                         $message = "installing \`$errfile'";
7177                         # Windows Perl will hang if we try to delete a
7178                         # file that doesn't exist.
7179                         unlink ($errfile) if -f $errfile;
7180                         if ($symlink_exists && ! $copy_missing)
7181                         {
7182                             if (! symlink ($am_dir . '/' . $file, $errfile))
7183                             {
7184                                 $suppress = 0;
7185                                 $trailer = "; error while making link: $!\n";
7186                             }
7187                         }
7188                         elsif (system ('cp', $am_dir . '/' . $file, $errfile))
7189                         {
7190                             $suppress = 0;
7191                             $trailer = "\n    error while copying\n";
7192                         }
7193                     }
7194                 }
7196                 local ($save) = $exit_status;
7197                 if ($is_configure)
7198                 {
7199                     # FIXME: allow actual file to be specified.
7200                     &am_conf_line_error ('configure.in', $line,
7201                                          "$message$trailer");
7202                 }
7203                 else
7204                 {
7205                     &am_line_error ($line, "$message$trailer");
7206                 }
7207                 $exit_status = $save if $suppress;
7208             }
7209         }
7210     }
7213 # Like require_file_with_line, but error messages refer to
7214 # configure.in, not the current Makefile.am.
7215 sub require_file_with_conf_line
7217     @require_file_paths = '.';
7218     &require_file_internal (1, @_);
7221 sub require_file_with_line
7223     @require_file_paths = '.';
7224     &require_file_internal (0, @_);
7227 sub require_file
7229     @require_file_paths = '.';
7230     &require_file_internal (0, '', @_);
7233 # Require a file that is also required by Autoconf.  Looks in
7234 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7235 sub require_config_file
7237     @require_file_paths = @config_aux_path;
7238     &require_file_internal (1, '', @_);
7239     local ($dir) = $require_file_paths[0];
7240     @config_aux_path = @require_file_paths;
7241     if ($dir eq '.')
7242     {
7243         $config_aux_dir = '.';
7244     }
7245     else
7246     {
7247         $config_aux_dir = '$(top_srcdir)/' . $dir;
7248     }
7251 # Assumes that the line number is in Makefile.am.
7252 sub require_conf_file_with_line
7254     @require_file_paths = @config_aux_path;
7255     &require_file_internal (0, @_);
7256     local ($dir) = $require_file_paths[0];
7257     @config_aux_path = @require_file_paths;
7258     if ($dir eq '.')
7259     {
7260         $config_aux_dir = '.';
7261     }
7262     else
7263     {
7264         $config_aux_dir = '$(top_srcdir)/' . $dir;
7265     }
7268 # Assumes that the line number is in configure.in.
7269 sub require_conf_file_with_conf_line
7271     @require_file_paths = @config_aux_path;
7272     &require_file_internal (1, @_);
7273     local ($dir) = $require_file_paths[0];
7274     @config_aux_path = @require_file_paths;
7275     if ($dir eq '.')
7276     {
7277         $config_aux_dir = '.';
7278     }
7279     else
7280     {
7281         $config_aux_dir = '$(top_srcdir)/' . $dir;
7282     }
7285 ################################################################
7287 # Push a list of files onto dist_common.
7288 sub push_dist_common
7290     local (@files) = @_;
7291     local ($file);
7293     foreach $file (@files)
7294     {
7295         $dist_common{$file} = 1;
7296     }
7299 # Push a list of clean targets onto phony.
7300 sub push_phony_cleaners
7302     local ($base) = @_;
7303     local ($target);
7304     foreach $target ('mostly', 'dist', '', 'maintainer-')
7305     {
7306         push (@phony, $target . 'clean-' . $base);
7307     }
7310 # Set strictness.
7311 sub set_strictness
7313     $strictness_name = $_[0];
7314     if ($strictness_name eq 'gnu')
7315     {
7316         $strictness = $GNU;
7317     }
7318     elsif ($strictness_name eq 'gnits')
7319     {
7320         $strictness = $GNITS;
7321     }
7322     elsif ($strictness_name eq 'foreign')
7323     {
7324         $strictness = $FOREIGN;
7325     }
7326     else
7327     {
7328         die "automake: level \`$strictness_name' not recognized\n";
7329     }
7333 ################################################################
7335 # Return directory name of file.
7336 sub dirname
7338     local ($file) = @_;
7339     local ($sub);
7341     ($sub = $file) =~ s,/+[^/]+$,,g;
7342     $sub = '.' if $sub eq $file;
7343     return $sub;
7346 # Return file name of a file.
7347 sub basename
7349     local ($file) = @_;
7350     local ($sub);
7352     ($sub = $file) =~s,^.*/+,,g;
7353     return $sub;
7356 # Ensure a file exists.
7357 sub create
7359     local ($file) = @_;
7361     open (TOUCH, ">> $file");
7362     close (TOUCH);
7365 # Glob something.  Do this to avoid indentation screwups everywhere we
7366 # want to glob.  Gross!
7367 sub my_glob
7369     local ($pat) = @_;
7370     return <${pat}>;
7373 ################################################################
7375 # Print an error message and set exit status.
7376 sub am_error
7378     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
7379     $exit_status = 1;
7382 sub am_line_error
7384     local ($symbol, @args) = @_;
7386     if ($symbol && "$symbol" ne '-1')
7387     {
7388         local ($file) = "${am_file}.am";
7390         if ($symbol =~ /^\d+$/)
7391         {
7392             # SYMBOL is a line number, so just add the colon.
7393             $file .= ':' . $symbol;
7394         }
7395         elsif (defined $content_lines{$symbol})
7396         {
7397             # SYMBOL is a variable defined in Makefile.am, so add the
7398             # line number we saved from there.
7399             $file .= ':' . $content_lines{$symbol};
7400         }
7401         elsif (defined $configure_vars{$symbol})
7402         {
7403             # SYMBOL is a variable defined in configure.in, so add the
7404             # appropriate line number.
7405             $file = $configure_vars{$symbol};
7406         }
7407         else
7408         {
7409             # Couldn't find the line number.
7410         }
7411         warn $file, ": ", join (' ', @args), "\n";
7412         $exit_status = 1;
7413     }
7414     else
7415     {
7416         &am_error (@args);
7417     }
7420 # Like am_error, but while scanning configure.in.
7421 sub am_conf_error
7423     # FIXME: can run in subdirs.
7424     warn "automake: configure.in: ", join (' ', @_), "\n";
7425     $exit_status = 1;
7428 # Error message with line number referring to configure.in.
7429 sub am_conf_line_error
7431     local ($file, $line, @args) = @_;
7433     if ($line)
7434     {
7435         warn "$file: $line: ", join (' ', @args), "\n";
7436         $exit_status = 1;
7437     }
7438     else
7439     {
7440         &am_conf_error (@args);
7441     }
7444 # Warning message with line number referring to configure.in.
7445 # Does not affect exit_status
7446 sub am_conf_line_warning
7448     local ($saved_exit_status) = $exit_status;
7449     &am_conf_line_error (@_);
7450     $exit_status = $saved_exit_status;
7453 # Tell user where our aclocal.m4 is, but only once.
7454 sub keyed_aclocal_warning
7456     local ($key) = @_;
7457     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
7460 # Print usage information.
7461 sub usage
7463     print "Usage: automake [OPTION] ... [Makefile]...\n\n";
7464     print "Generate Makefile.in for autoconf from Makefile.am\n";
7465     print $USAGE;
7466     print "\nFiles which are automatically distributed, if found:\n";
7467     $~ = "USAGE_FORMAT";
7468     local ($last, $iter, @lcomm);
7469     $last = '';
7470     foreach $iter (sort ((@common_files, @common_sometimes)))
7471     {
7472         push (@lcomm, $iter) unless $iter eq $last;
7473         $last = $iter;
7474     }
7476     local ($one, $two, $three, $four, $i, $max);
7477     $max = int (($#lcomm + 1) / 4);
7479     for ($i = 0; $i < $max; ++$i)
7480     {
7481         $one = $lcomm[$i];
7482         $two = $lcomm[$max + $i];
7483         $three = $lcomm[2 * $max + $i];
7484         $four = $lcomm[3 * $max + $i];
7485         write;
7486     }
7488     local ($mod) = ($#lcomm + 1) % 4;
7489     if ($mod != 0)
7490     {
7491         $one = $lcomm[$max];
7492         $two = ($mod > 1) ? $lcomm[2 * $max] : '';
7493         $three = ($mod > 2) ? $lcomm[3 * $max] : '';
7494         $four = ($mod > 3) ? $lcomm[4 * $max] : '';
7495         write;
7496     }
7498     print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7500     exit 0;
7503 format USAGE_FORMAT =
7504   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
7505   $one,               $two,               $three,             $four