changed copyright per RMS request
[automake.git] / automake.in
blob8ccd5a7c61286b45bb2d180ff22d4d2c71cbeb84
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 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@";
36 $TAR = "@TAR@";
38 # String constants.
39 $IGNORE_PATTERN = "^##([^#].*)?\$";
40 $WHITE_PATTERN = "^[ \t]*\$";
41 $COMMENT_PATTERN = "^#";
42 $RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/]*) *:([^=].*|)\$";
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]*\(#.*\)?\$";
50 # Some regular expressions.  One reason to put them here is that it
51 # makes indentation work better in Emacs.
52 $AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
53 $AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^,)]+)[,)]";
54 $AM_PACKAGE_VERSION_PATTERN = "^\\s*\\[?([^]\\s]+)\\]?\\s*\$";
55 # Note that there is no AC_PATH_TOOL.  But we don't really care.
56 $AC_CHECK_PATTERN = "AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\\(\\[?(\\w+)";
57 $AM_MISSING_PATTERN = "AM_MISSING_PROG\\(\\[?(\\w+)";
58 # Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
59 # then too bad.
60 $AC_SUBST_PATTERN = "AC_SUBST\\(\\[?(\\w+)";
61 $AM_CONDITIONAL_PATTERN = "AM_CONDITIONAL\\((\\w+)";
63 # Constants to define the "strictness" level.
64 $FOREIGN = 0;
65 $GNU = 1;
66 $GNITS = 2;
70 # Variables global to entire run.
72 # TRUE if we should always generate Makefile.in.
73 $force_generation = 1;
75 # Strictness level as set on command line.
76 $default_strictness = $GNU;
78 # Name of strictness level, as set on command line.
79 $default_strictness_name = 'gnu';
81 # This is TRUE if GNU make specific automatic dependency generation
82 # code should be included in generated Makefile.in.
83 $cmdline_use_dependencies = 1;
85 # TRUE if in verbose mode.
86 $verbose = 0;
88 # This holds our (eventual) exit status.  We don't actually exit until
89 # we have processed all input files.
90 $exit_status = 0;
92 # From the Perl manual.
93 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
95 # TRUE if missing standard files should be installed.
96 $add_missing = 0;
98 # Files found by scanning configure.in for LIBOBJS.
99 %libsources = ();
101 # True if AM_C_PROTOTYPES appears in configure.in.
102 $am_c_prototypes = 0;
104 # Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
105 # name which appears in AC_CONFIG_HEADER, colon and all.
106 # @config_names holds the file names.  @config_headers holds the '.in'
107 # files.  Ordinarily these are similar, but they can be different if
108 # the weird "NAME:FILE" syntax is used.
109 @config_fullnames = ();
110 @config_names = ();
111 @config_headers = ();
112 # Line number at which AC_CONFIG_HEADER appears in configure.in.
113 $config_header_line = 0;
115 # Directory where output files go.  Actually, output files are
116 # relative to this directory.
117 $output_directory = '.';
119 # Relative location of top build directory.
120 $top_builddir = '';
122 # Absolute location of top build directory.
123 $build_directory = '';
125 # Name of srcdir as given in build directory's Makefile.  For
126 # dependencies only.
127 $srcdir_name = '';
129 # List of Makefile.am's to process, and their corresponding outputs.
130 @input_files = ();
131 %output_files = ();
133 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
134 @other_input_files = ();
135 # Line number at which AC_OUTPUT seen.
136 $ac_output_line = 0;
138 # List of directories to search for configure-required files.  This
139 # can be set by AC_CONFIG_AUX_DIR.
140 @config_aux_path = ('.', '..', '../..');
141 $config_aux_dir = '';
143 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
144 $seen_make_set = 0;
146 # Whether AM_GNU_GETTEXT has been seen in configure.in.
147 $seen_gettext = 0;
148 # Line number at which AM_GNU_GETTEXT seen.
149 $ac_gettext_line = 0;
151 # Whether ALL_LINGUAS has been seen.
152 $seen_linguas = '';
153 # The actual text.
154 $all_linguas = '';
155 # Line number at which it appears.
156 $all_linguas_line = 0;
158 # 1 if AC_PROG_INSTALL seen, 2 if AM_PROG_INSTALL seen.
159 $seen_prog_install = 0;
161 # 1 if any scripts installed, 0 otherwise.
162 $scripts_installed = 0;
164 # Whether AC_PATH_XTRA has been seen in configure.in.
165 $seen_path_xtra = 0;
167 # TRUE if AC_DECL_YYTEXT was seen.
168 $seen_decl_yytext = 0;
170 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
171 # AC_CHECK_TOOL also sets this.
172 $seen_canonical = 0;
174 # TRUE if we've seen AC_ARG_PROGRAM.
175 $seen_arg_prog = 0;
177 # TRUE if we've seen AM_PROG_LIBTOOL.
178 $seen_libtool = 0;
179 $libtool_line = 0;
181 # Files installed by libtoolize.
182 @libtoolize_files = ('ltconfig', 'ltmain.sh', 'config.guess', 'config.sub');
184 # TRUE if we've seen AM_MAINTAINER_MODE.
185 $seen_maint_mode = 0;
187 # TRUE if we've seen PACKAGE and VERSION.
188 $seen_package = 0;
189 $seen_version = 0;
191 # Actual version we've seen.
192 $package_version = '';
194 # Line number where we saw version definition.
195 $package_version_line = 0;
197 # TRUE if we've seen AM_PATH_LISPDIR.
198 $seen_lispdir = 0;
200 # TRUE if we've seen AM_CYGWIN32.
201 $seen_cygwin32 = 0;
203 # Hash table of discovered configure substitutions.  Keys are names,
204 # values are meaningless.
205 %configure_vars = ();
207 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
208 # handled in a funny way: if seen in the top-level Makefile.am, it is
209 # used for every directory which does not specify a different value.
210 # The rationale here is that some directories (eg gettext) might be
211 # distributions of other packages, and thus require their own charset
212 # info.  However, the DIST_CHARSET must be the same for the entire
213 # package; it can only be set at top-level.
214 # FIXME: this yields bugs when rebuilding.  What to do?  Always
215 # read (and sometimes discard) top-level Makefile.am?
216 $maint_charset = '';
217 $dist_charset = 'utf8';         # recode doesn't support this yet.
219 # Name of input file ("Makefile.in") and output file ("Makefile.am").
220 # These have no directory components.
221 $am_file_name = '';
222 $in_file_name = '';
224 # TRUE if --cygnus seen.
225 $cygnus_mode = 0;
227 # Keys of this hash are names of dependency files to ignore.
228 %omit_dependencies = ();
230 # Hash table of AM_CONDITIONAL variables seen in configure.
231 %configure_cond = ();
233 # Map from obsolete macros to hints for new macros.
234 # FIXME complete the list so that there are no `0' hints.
235 %obsolete_macros =
236     (
237      'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
238      'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
239      'AC_FEATURE_EXIT', 0,
240      'AC_SYSTEM_HEADER', 0,
242      # Note that we do not handle this one, because it is still run
243      # from AM_CONFIG_HEADER.  So we deal with it specially in
244      # scan_configure.
245      # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",
247      'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
248      'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
249      'fp_PROG_INSTALL', "use \`AM_PROG_INSTALL'",
250      'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
251      'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
252      'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
253      'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
254      'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
255      'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",
257      # Now part of autoconf proper, under a different name.
258      'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
259      'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
260      'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",
262 # These aren't quite obsolete.
263 #      'md_PATH_PROG',
264      );
266 # Regexp to match the above macros.
267 $obsolete_rx = '(' . join ('|', keys %obsolete_macros) . ')';
271 &initialize_global_constants;
273 # Parse command line.
274 &parse_arguments (@ARGV);
276 # Do configure.in scan only once.
277 &scan_configure;
279 die "automake: no \`Makefile.am' found or specified\n"
280     if ! @input_files;
282 # Now do all the work on each file.
283 foreach $am_file (@input_files)
285     if (! -f ($am_file . '.am'))
286     {
287         &am_error ("\`" . $am_file . ".am' does not exist");
288     }
289     else
290     {
291         &generate_makefile ($output_files{$am_file}, $am_file);
292     }
295 if ($seen_prog_install <= $scripts_installed)
297     &am_conf_error (($scripts_installed ? 'AM_PROG_INSTALL' : 'AC_PROG_INSTALL')
298                     . " must be used in configure.in");
299     &keyed_aclocal_warning ('AM_PROG_INSTALL')
300         if $scripts_installed;
303 exit $exit_status;
306 ################################################################
308 # Parse command line.
309 sub parse_arguments
311     local (@arglist) = @_;
313     # Start off as gnu.
314     &set_strictness ('gnu');
316     while (@arglist)
317     {
318         if ($arglist[0] eq "--version")
319         {
320             print "automake (GNU $PACKAGE) $VERSION\n\n";
321             print "Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.\n";
322             print "This is free software; see the source for copying conditions.  There is NO\n";
323             print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
324             print "Written by Tom Tromey <tromey\@cygnus.com>\n";
326             exit 0;
327         }
328         elsif ($arglist[0] eq "--help")
329         {
330             &usage;
331         }
332         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
333         {
334             $am_dir = $1;
335         }
336         elsif ($arglist[0] eq '--amdir')
337         {
338             &require_argument (@arglist);
339             shift (@arglist);
340             $am_dir = $arglist[0];
341         }
342         elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
343         {
344             # Must end in /.
345             $build_directory = $1 . '/';
346         }
347         elsif ($arglist[0] eq '--build-dir')
348         {
349             &require_argument (@arglist);
350             shift (@arglist);
351             # Must end in /.
352             $build_directory = $arglist[0] . '/';
353         }
354         elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
355         {
356             $srcdir_name = $1;
357         }
358         elsif ($arglist[0] eq '--srcdir-name')
359         {
360             &require_argument (@arglist);
361             shift (@arglist);
362             $srcdir_name = $arglist[0];
363         }
364         elsif ($arglist[0] eq '--gnu')
365         {
366             &set_strictness ('gnu');
367         }
368         elsif ($arglist[0] eq '--gnits')
369         {
370             &set_strictness ('gnits');
371         }
372         elsif ($arglist[0] eq '--cygnus')
373         {
374             $cygnus_mode = 1;
375         }
376         elsif ($arglist[0] eq '--foreign')
377         {
378             &set_strictness ('foreign');
379         }
380         elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
381         {
382             $cmdline_use_dependencies = 0;
383         }
384         elsif ($arglist[0] eq '--no-force')
385         {
386             $force_generation = 0;
387         }
388         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
389         {
390             # Set output directory.
391             $output_directory = $1;
392         }
393         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
394         {
395             &require_argument (@arglist);
396             shift (@arglist);
397             $output_directory = $arglist[0];
398         }
399         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
400         {
401             $add_missing = 1;
402         }
403         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
404         {
405             $verbose = 1;
406         }
407         elsif ($arglist[0] eq '--')
408         {
409             # Stop option processing.
410             shift (@arglist);
411             push (@input_files, @arglist);
412             last;
413         }
414         elsif ($arglist[0] =~ /^-/)
415         {
416             die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
417         }
418         else
419         {
420             # Handle $local:$input syntax.  Note that we only examine
421             # the first ":" file to see if it is automake input; the
422             # rest are just taken verbatim.  We still keep all the
423             # files around for dependency checking, however.
424             local ($local, $input, @rest) = split (/:/, $arglist[0]);
425             if (! $input)
426             {
427                 $input = $local;
428             }
429             else
430             {
431                 # Strip .in; later on .am is tacked on.  That is how
432                 # the automake input file is found.  Maybe not the
433                 # best way, but it is easy to explain.  FIXME: should
434                 # be error if .in is missing.
435                 $input =~ s/\.in$//;
436             }
437             push (@input_files, $input);
438             $output_files{$input} = join (':', ($local, @rest));
439         }
441         shift (@arglist);
442     }
444     # Take global strictness from whatever we currently have set.
445     $default_strictness = $strictness;
446     $default_strictness_name = $strictness_name;
449 # Ensure argument exists, or die.
450 sub require_argument
452     local ($arg, @arglist) = @_;
453     die "automake: no argument given for option \`$arg'\n"
454         if ! @arglist;
457 ################################################################
459 # Generate a Makefile.in given the name of the corresponding Makefile and
460 # the name of the file output by config.status.
461 sub generate_makefile
463     local ($output, $makefile) = @_;
465     ($am_file_name = $makefile) =~ s/^.*\///;
466     $in_file_name = $am_file_name . '.in';
467     $am_file_name .= '.am';
469     # $OUTPUT is encoded.  If it contains a ":" then the first element
470     # is the real output file, and all remaining elements are input
471     # files.  We don't scan or otherwise deal with these input file,
472     # other than to mark them as dependencies.  See scan_configure for
473     # details.
474     local (@secondary_inputs);
475     ($output, @secondary_inputs) = split (/:/, $output);
477     &initialize_per_input;
478     $relative_dir = &dirname ($output);
479     $am_relative_dir = &dirname ($makefile);
481     # At the toplevel directory, we might need config.guess, config.sub
482     # or libtool scripts (ltconfig and ltmain.sh).
483     if ($relative_dir eq '.')
484     {
485         # libtool requires some files.
486         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
487                                            @libtoolize_files)
488             if $seen_libtool;
490         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
491         # config.sub.
492         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
493             if $seen_canonical;
494     }
496     # We still need Makefile.in here, because sometimes the `dist'
497     # target doesn't re-run automake.
498     if ($am_relative_dir eq $relative_dir)
499     {
500         # Only distribute the files if they are in the same subdir as
501         # the generated makefile.
502         &push_dist_common ($in_file_name, $am_file_name);
503     }
504     push (@sources, '$(SOURCES)')
505         if &variable_defined ('SOURCES');
506     push (@objects, '$(OBJECTS)')
507         if &variable_defined ('OBJECTS');
509     # This is always the default target.  This gives us freedom to do
510     # things in whatever order is convenient.  Note that we set up
511     # $output_header here so that we can insert some text just after
512     # the "default" target, but before any other targets.  In
513     # particular we want to support the .SUFFIX hack here; this is
514     # documented elsewhere.
515     $output_header = "default: all\n\n";
516     push (@phony, 'default');
518     &read_am_file ($makefile . '.am');
519     if (&handle_options)
520     {
521         # Fatal error.  Just return, so we can continue with next file.
522         return;
523     }
525     # Check first, because we might modify some state.
526     &check_cygnus;
527     &check_gnu_standards;
528     &check_gnits_standards;
530     &handle_configure ($output, $makefile, @secondary_inputs);
531     &handle_gettext;
532     &handle_libraries;
533     &handle_ltlibraries;
534     &handle_programs;
535     &handle_scripts;
537     &handle_built_sources;
539     # This must be run after all the sources are scanned.
540     &handle_yacc_lex_cxx;
542     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
543     # on this (but currently does).
544     $contents{'SOURCES'} = join (' ', @sources);
545     $contents{'OBJECTS'} = join (' ', @objects);
547     &handle_texinfo;
548     &handle_emacs_lisp;
549     &handle_man_pages;
550     &handle_data;
551     &handle_headers;
552     &handle_subdirs;
553     &handle_tags;
554     &handle_dist ($makefile);
555     &handle_dependencies;
556     &handle_tests;
557     &handle_footer;
558     &handle_merge_targets ($makefile);
559     &handle_installdirs;
560     &handle_clean;
561     &handle_phony;
563     &check_typos;
565     if (! -d ($output_directory . '/' . $am_relative_dir))
566     {
567         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
568     }
570     local ($out_file) = $output_directory . '/' . $makefile . ".in";
571     if (! $force_generation && -e $out_file)
572     {
573         local ($am_time) = (stat ($makefile . '.am'))[9];
574         local ($in_time) = (stat ($out_file))[9];
575         # FIXME: should cache these times.
576         local ($conf_time) = (stat ('configure.in'))[9];
577         # FIXME: how to do unsigned comparison?
578         if ($am_time < $in_time || $am_time < $conf_time)
579         {
580             # No need to update.
581             return;
582         }
583         if (-f 'aclocal.m4')
584         {
585             local ($acl_time) = (stat _)[9];
586             return if ($am_time < $acl_time);
587         }
588     }
590     if (! open (GM_FILE, "> " . $out_file))
591     {
592         warn "automake: ${am_file}.in: cannot write: $!\n";
593         $exit_status = 1;
594         return;
595     }
596     print "automake: creating ", $makefile, ".in\n" if $verbose;
598     print GM_FILE $output_vars;
599     print GM_FILE $output_header;
600     print GM_FILE $output_rules;
601     print GM_FILE $output_trailer;
603     close (GM_FILE);
606 ################################################################
608 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
609 sub handle_options
611     return 0 if ! &variable_defined ('AUTOMAKE_OPTIONS');
613     foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
614     {
615         $options{$_} = 1;
616         if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
617         {
618             &set_strictness ($_);
619         }
620         elsif (/ansi2knr/)
621         {
622             # An option like "../lib/ansi2knr" is allowed.  With no
623             # path prefix, we assume the required programs are in this
624             # directory.  We save the actual option for later.
625             $options{'ansi2knr'} = $_;
626         }
627         elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
628                || $_ eq 'dist-shar' || $_ eq 'dist-zip'
629                || $_ eq 'dist-tarZ' || $_ eq 'dejagnu'
630                || $_ eq 'no-texinfo.tex')
631         {
632             # Explicitly recognize these.
633         }
634         elsif ($_ eq 'no-dependencies')
635         {
636             $use_dependencies = 0;
637         }
638         elsif (/([0-9]+)\.([0-9]+)/)
639         {
640             # Got a version number.  Note that alpha releases count as
641             # the next higher release.  Note also that we assume there
642             # will be a maximum of 100 minor releases for any given
643             # major release.
644             local ($rmajor, $rminor) = ($1, $2);
645             if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
646             {
647                 print STDERR
648                     "automake: programming error: version is incorrect\n";
649                 exit 1;
650             }
651             local ($tmajor, $tminor) = ($1, $2);
652             # Handle alpha versions.
653             ++$tminor if defined $3;
655             if ($rmajor > $tmajor || ($rmajor == $tmajor && $rminor > $tminor))
656             {
657                 &am_line_error ('AUTOMAKE_OPTIONS',
658                                 "require version $_, only have $VERSION");
659                 return 1;
660             }
661         }
662         else
663         {
664             &am_line_error ('AUTOMAKE_OPTIONS',
665                             'option ', $_, 'not recognized');
666         }
667     }
669     return 0;
672 # Return object extension.  Just once, put some code into the output.
673 # Argument is the name of the output file
674 sub get_object_extension
676     local ($out) = @_;
678     # Always set this.
679     $dir_holds_sources = 1;
681     # Maybe require libtool library object files.
682     local ($extension) = '.o';
683     $extension = '.lo' if ($out =~ /\.la$/);
685     if (! $included_generic_compile)
686     {
687         # Boilerplate.
688         local ($xform) = '';
689         if (&variable_defined ('CONFIG_HEADER'))
690         {
691             local ($one_hdr);
692             foreach $one_hdr (split (' ', &variable_value ('CONFIG_HEADER')))
693             {
694                 local ($var);
695                 ($var = &dirname ($one_hdr)) =~ s/(\W)/\\$1/g;
696                 $xform .= ' ' if $xform;
697                 $xform .= '-I' . $var;
698             }
699         }
700         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go;';
701         $output_vars .= &file_contents_with_transform ($xform,
702                                                        'comp-vars');
703         $output_rules .= &file_contents ('compile');
704         &push_phony_cleaners ('compile');
706         # If using X, include some extra variable definitions.  NOTE
707         # we don't want to force these into CFLAGS or anything,
708         # because not all programs will necessarily use X.
709         if ($seen_path_xtra)
710         {
711             local ($var);
712             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
713             {
714                 &define_configure_variable ($var);
715             }
716         }
718         push (@suffixes, '.c', '.o');
719         push (@clean, 'compile');
721         $included_generic_compile = 1;
722     }
724     if ($seen_libtool && ! $included_libtool_compile)
725     {
726         # Output the libtool compilation rules.
727         $output_rules .= &file_contents ('libtool');
728         &push_phony_cleaners ('libtool');
730         push (@suffixes, '.lo');
731         push (@clean, 'libtool');
733         $included_libtool_compile = 1;
734     }
736     # Check for automatic de-ANSI-fication.
737     if (defined $options{'ansi2knr'})
738     {
739         $extension = '$U' . $extension;
740         if (! $included_knr_compile)
741         {
742             if (! $am_c_prototypes)
743             {
744                 &am_line_error ('AUTOMAKE_OPTIONS',
745                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
746                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
747                 # Only give this error once.
748                 $am_c_prototypes = 1;
749             }
751             # Only require ansi2knr files if they should appear in
752             # this directory.
753             if ($options{'ansi2knr'} eq 'ansi2knr')
754             {
755                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
756                                          'ansi2knr.c', 'ansi2knr.1');
757                 $output_rules .= &file_contents ('kr-extra');
758                 push (@clean, 'krextra');
759                 &push_phony_cleaners ('krextra');
760             }
762             # Generate rules to build ansi2knr.  If it is in some
763             # other directory, then generate dependencies but have the
764             # rule just run elsewhere.
765             $output_rules .= ($options{'ansi2knr'} . ': '
766                               . $options{'ansi2knr'} . ".o\n");
767             if ($options{'ansi2knr'} eq 'ansi2knr')
768             {
769                 $output_rules .= ("\t\$(LINK) ansi2knr.o \$(LIBS)\n"
770                                   . "ansi2knr.o: \$(CONFIG_HEADER)\n\n");
771             }
772             else
773             {
774                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
775                                   . " && \$(MAKE) ansi2knr\n\n");
776             }
778             # Make sure ansi2knr can be found: if no path specified,
779             # specify "./".
780             if ($options{'ansi2knr'} eq 'ansi2knr')
781             {
782                 # Substitution from AM_C_PROTOTYPES.  This makes it be
783                 # built only when necessary.
784                 &define_configure_variable ('ANSI2KNR');
785                 # ansi2knr needs to be built before subdirs, so unshift it.
786                 unshift (@all, '$(ANSI2KNR)');
787             }
788             else
789             {
790                 # Found in another directory.
791                 &define_variable ("ANSI2KNR", $options{'ansi2knr'});
792             }
794             $output_rules .= &file_contents ('clean-kr');
796             push (@clean, 'kr');
797             &push_phony_cleaners ('kr');
799             $included_knr_compile = 1;
800         }
801     }
803     return $extension;
806 # Handle yacc and lex.
807 sub handle_yacc_lex_cxx
809     #
810     # First do yacc and lex.
811     #
813     local ($yacc_count) = scalar (keys %yacc_sources);
814     local ($lex_count) = scalar (keys %lex_sources);
816     if ($yacc_count)
817     {
818         local (%seen_suffix) = ();
819         foreach (keys %yacc_sources)
820         {
821             /(\..*)$/;
822             &output_yacc_build_rule ($1, $yacc_count > 1)
823                 if (! defined $seen_suffix{$1});
824             $seen_suffix{$1} = 1;
825         }
827         if (! defined $configure_vars{'YACC'})
828         {
829             &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
830         }
831     }
832     if ($lex_count)
833     {
834         local (%seen_suffix) = ();
835         foreach (keys %lex_sources)
836         {
837             /(\..*)$/;
838             &output_lex_build_rule ($1, $lex_count > 1)
839                 if (! defined $seen_suffix{$1});
840             $seen_suffix{$1} = 1;
841         }
843         if (! defined $configure_vars{'LEX'})
844         {
845             &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
846         }
847         if (! $seen_decl_yytext)
848         {
849             &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
850         }
851     }
853     if ($yacc_count > 1 || $lex_count > 1)
854     {
855         # If there is more than one distinct yacc (resp lex) source
856         # file in a given directory, then the `ylwrap' program is
857         # required to allow parallel builds to work correctly.  FIXME:
858         # for now, no line number.
859         &require_config_file ($FOREIGN, 'ylwrap');
860         if ($config_aux_dir ne '.' && $config_aux_dir ne '')
861         {
862                 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
863         }
864         else
865         {
866                 &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
867         }
868     }
870     #
871     # Handle libtool.
872     #
873     local ($ltcompile, $ltlink) = ('', '');
874     if ($seen_libtool)
875     {
876         &define_configure_variable ("LIBTOOL");
877         $ltcompile = '$(LIBTOOL) --mode=compile ';
878         $ltlink = '$(LIBTOOL) --mode=link ';
879     }
881     #
882     # Now handle C++.
883     #
884     local (@cxx_list) = keys %cxx_extensions;
885     local ($cxx_count) = scalar @cxx_list;
886     if ($cxx_count)
887     {
888         push (@suffixes, @cxx_list);
890         &define_configure_variable ("CXXFLAGS");
891         &define_variable ('CXXCOMPILE', '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
892         &define_variable ('LTCXXCOMPILE',
893                           $ltcompile . '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)')
894             if ($seen_libtool);
896         &define_variable ('CXXLINK', $ltlink . '$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@');
898         local ($ext);
899         foreach $ext (@cxx_list)
900         {
901             $output_rules .= ("$ext.o:\n"
902                               . "\t\$(CXXCOMPILE) -c \$<\n");
903             $output_rules .= ("$ext.lo:\n"
904                               . "\t\$(LTCXXCOMPILE) -c \$<\n")
905                 if ($seen_libtool);
906         }
908         if (! defined $configure_vars{'CXX'})
909         {
910             &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
911         }
912     }
914     #
915     # Handle some ansi2knr cleanup.
916     #
917     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
918     {
919         # Make all _.c files depend on their corresponding .c files.
920         local ($base, @objects);
921         foreach $base (sort (keys %de_ansi_files))
922         {
923             $output_rules .= $base . "_.c: $base.c\n\t"
924                 . '$(ANSI2KNR) $< ' . $base . "_.c\n";
925             push (@objects, $base . '_.o');
926             push (@objects, $base . '_.lo') if $seen_libtool;
927         }
929         # Make all _.o (and _.lo) files depend on ansi2knr.
930         # Use a sneaky little hack to make it print nicely.
931         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
932     }
934     #
935     # Last, handle some C cleanup.
936     #
937     if ($seen_c_source)
938     {
939         &define_configure_variable ('CFLAGS');
940         &define_variable ('COMPILE',
941                           '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)');
942         &define_variable ('LTCOMPILE',
943                           $ltcompile .
944                           '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)')
945             if ($seen_libtool);
946         &define_variable ('LINK', $ltlink . '$(CC) $(CFLAGS) $(LDFLAGS) -o $@');
948         if (! defined $configure_vars{'CC'})
949         {
950             &am_line_error ($seen_c_source,
951                             "C source seen but \`CC' not defined in \`configure.in'");
952         }
953     }
957 # Output a rule to build from a YACC source.  The output from YACC is
958 # compiled with C or C++, depending on the extension of the YACC file.
959 sub output_yacc_build_rule
961     local ($yacc_suffix, $use_ylwrap, $c_suffix) = @_;
963     local ($c_suffix, $suffix);
964     ($c_suffix = $yacc_suffix) =~ tr/y/c/;
965     push (@suffixes, $yacc_suffix, $c_suffix, '.h');
967     # Generate rule for c/c++ and header file.  Probably should only
968     # do header if `yacc -d' is run.  But how can we determine that?
969     foreach $suffix ($c_suffix, '.h')
970     {
971         $output_rules .= "$yacc_suffix$suffix:\n\t";
973         if ($use_ylwrap)
974         {
975             $output_rules .= ('$(SHELL) $(YLWRAP)'
976                               . ' "$(YACC)" $< y.tab.c $*' . $c_suffix
977                               . ' y.tab.h $*.h -- $(YFLAGS)');
978         }
979         else
980         {
981             $output_rules .= ('$(YACC) $(YFLAGS) $< && mv y.tab.c $@' . "\n"
982                               . "\tif test -f y.tab.h; then \\\n"
983                               . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
984                           . "\telse :; fi");
985         }
986         $output_rules .= "\n";
987     }
990 sub output_lex_build_rule
992     local ($lex_suffix, $use_ylwrap) = @_;
993     local ($c_suffix);
995     ($c_suffix = $lex_suffix) =~ tr/l/c/;
996     push (@suffixes, $lex_suffix);
997     &define_configure_variable ('LEX_OUTPUT_ROOT');
998     &define_configure_variable ('LEXLIB');
999     $output_rules .= "$lex_suffix$c_suffix:\n\t";
1001     if ($use_ylwrap)
1002     {
1003         # Is the $@ correct here?  If so, why not use it in the ylwrap
1004         # build rule for yacc above?
1005         $output_rules .= '$(SHELL) $(YLWRAP)'
1006             . ' "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(LFLAGS)';
1007     }
1008     else
1009     {
1010         $output_rules .= '$(LEX) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
1011     }
1012     $output_rules .= "\n";
1016 # Check to make sure a source defined in LIBOBJS is not explicitly
1017 # mentioned.  This is a separate function (as opposed to being inlined
1018 # in handle_source_transform) because it isn't always appropriate to
1019 # do this check.
1020 sub check_libobjs_sources
1022     local ($one_file, $unxformed) = @_;
1024     local ($prefix, $file, @files);
1025     foreach $prefix ('', 'EXTRA_')
1026     {
1027         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1028         {
1029             @files = &variable_value_as_list (($prefix
1030                                                . $one_file . '_SOURCES'),
1031                                               'all');
1032         }
1033         elsif ($prefix eq '')
1034         {
1035             @files = ($unxformed . '.c');
1036         }
1037         else
1038         {
1039             next;
1040         }
1042         foreach $file (@files)
1043         {
1044             if (defined $libsources{$file})
1045             {
1046                 &am_line_error ($prefix . $one_file . '_SOURCES',
1047                                 "automatically discovered file \`$file' should not be explicitly mentioned");
1048             }
1049         }
1050     }
1053 # Does much of the actual work for handle_source_transform.
1054 # Arguments are:
1055 #   list of source files to transform
1056 # Result is a list
1057 #   first element is name of linker to use (empty string for default linker)
1058 #   remaining elements are names of `.o's
1059 sub handle_single_transform_list
1061     local (@files) = @_;
1062     local ($linker) = '';
1063     local (@result) = ();
1064     local ($nonansi_obj) = $obj;
1065     $nonansi_obj =~ s/_//g;
1066     if (length (@files))
1067     {
1068         # Turn sources into objects.
1069         foreach (@files)
1070         {
1071             # Skip header files, including C++-ish ones.  The list
1072             # of C++ header extensions comes from Emacs 19.32
1073             # etags.
1074             next if /\.[hH]$/;
1075             next if /\.hxx$/;
1076             next if /\.h\+\+$/;
1077             next if /\.hh$/;
1078             next if /\.hpp$/;
1079             # Skip things that look like configure substitutions.
1080             next if /^\@.*\@$/;
1082             # Include appropriate file for lex or yacc source in
1083             # distribution.  If the extension is the regular '.y' or
1084             # '.l', we assume C compilation, and the generated file
1085             # has exension .c.  Otherwise, we compile with C++, and
1086             # make the following association: (yy -> cc, y++ -> c++,
1087             # yxx -> cxx), similarly for .ll, etc.
1088             if (/^(.*)\.(y|yy|y\+\+|yxx)$/)
1089             {
1090                 # Yacc source.
1091                 local ($ext) = $2;
1092                 $ext =~ tr/y/c/;
1093                 &push_dist_common ("$1.$ext");
1094                 $yacc_sources{$_} = 1;
1095             }
1096             elsif (/^(.*)\.(l|ll|l\+\+|lxx)$/)
1097             {
1098                 # Lex source.
1099                 local ($ext) = $2;
1100                 $ext =~ tr/l/c/;
1101                 &push_dist_common ("$1.$ext");
1102                 $lex_sources{$_} = 1;
1103             }
1105             # Strip any directory prefix.
1106             $_ = &basename ($_);
1108             # Transform source files into .o files.  List of C++
1109             # extensions comes from Emacs 19.34 etags.
1110             if (s/\.(c\+\+|cc|cpp|cxx|C)$/$nonansi_obj/)
1111             {
1112                 $cxx_extensions{'.' . $1} = 1;
1113                 $linker = 'CXXLINK';
1114             }
1115             elsif (s/\.(yy|y\+\+|yxx|ll|l\+\+|lxx)$/$nonansi_obj/)
1116             {
1117                 # Compiling lex or yacc with C++
1118                 local ($ext) = $1;
1119                 $ext =~ tr/ly/cc/;
1120                 $cxx_extensions{".$ext"} = 1;
1121                 $linker = 'CXXLINK';
1122             }
1123             elsif (s/\.([Ff]\\|f90\\|for)$/$nonansi_obj/)
1124             {
1125                 # FORTRAN support.  FIXME: not finished.
1126             }
1127             elsif (s/\.[sS]$/$nonansi_obj/)
1128             {
1129                 # .s is assembly.  Just rewrite it.  FIXME: not finished.
1130             }
1131             elsif (defined ($options{'ansi2knr'}) && s/_\.[cly]$/_.c/)
1132             {
1133                 # FIXME include line number in error.
1134                 &am_error ("C source file \`$_' would be deleted by ansi2knr rules");
1135             }
1136             elsif (s/\.[cly]$//)
1137             {
1138                 # .c is C.  .l is lex.  .y is yacc.
1139   
1140                 # Note: first we rewrite (eg) foo.c to foo and push
1141                 # the file onto the list of deansified files.  Then we add
1142                 # $obj, which can either be `_.o', or simply `.o' if
1143                 # deansification is not required.
1144                 $de_ansi_files{$_} = 1;
1145                 $_ .= $obj;
1146                 $seen_c_source = 1;
1147             }
1148             else
1149             {
1150                 # No error message here.  Used to have one, but it was
1151                 # very unpopular.
1152                 next;
1153             }
1155             push (@result, $_);
1157             # Transform .o or $o file into .P file (for automatic
1158             # dependency code).
1159             s/$objpat$/.P/g;
1160             $dep_files{'.deps/' . $_} = 1;
1161         }
1162     }
1164     return ($linker, @result);
1167 # Handle SOURCE->OBJECT transform for one program or library.
1168 # Arguments are:
1169 #   canonical (transformed) name of object to build
1170 #   actual name of object to build
1171 #   object extension (ie either `.o' or `$o'.
1172 # Return result is name of linker variable that must be used.
1173 # Empty return means just use `LINK'.
1174 sub handle_source_transform
1176     # one_file is canonical name.  unxformed is given name.  obj is
1177     # object extension.
1178     local ($one_file, $unxformed, $obj) = @_;
1179     local ($objpat) = $obj;
1180     $objpat =~ s/(\W)/\\$1/g;
1181     # Handle explicit `.o' as well as whatever we're passed.
1182     $objpat = '(' . $objpat . "|\\.o)";
1184     local ($linker) = '';
1186     if (&variable_defined ($one_file . "_OBJECTS"))
1187     {
1188         &am_line_error ($one_file . '_OBJECTS',
1189                         $one_file . '_OBJECTS', 'should not be defined');
1190         # No point in continuing.
1191         return;
1192     }
1194     local (@files, @result, $prefix, $temp);
1195     foreach $prefix ('', 'EXTRA_')
1196     {
1197         @files = ();
1198         local ($var) = $prefix . $one_file . "_SOURCES";
1199         if (&variable_defined ($var))
1200         {
1201             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1202             push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
1203                 unless $prefix eq 'EXTRA_';
1204             local (@conds) = &variable_conditions ($var);
1205             if (! @conds)
1206             {
1207                 @files = &variable_value_as_list ($var, '');
1208             }
1209             else
1210             {
1211                 local ($cond);
1212                 foreach $cond (@conds)
1213                 {
1214                     @files = &variable_value_as_list ($var, $cond);
1215                     ($temp, @result) = &handle_single_transform_list (@files);
1216                     $linker = $temp if $linker eq '';
1217                     &define_pretty_variable ($one_file . "_OBJECTS", $cond,
1218                                              @result)
1219                         unless $prefix eq 'EXTRA_';
1220                 }
1222                 next;
1223             }
1224         }
1225         elsif ($prefix eq '')
1226         {
1227             &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1228             push (@sources, $unxformed . '.c');
1229             push (@objects, $unxformed . $obj);
1230             push (@files, $unxformed . '.c');
1231         }
1233         ($temp, @result) = &handle_single_transform_list (@files);
1234         $linker = $temp if $linker eq '';
1235         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
1236             unless $prefix eq 'EXTRA_';
1237     }
1239     return $linker;
1242 # Handle the BUILT_SOURCES variable.
1243 sub handle_built_sources
1245     return unless &variable_defined ('BUILT_SOURCES');
1247     local (@sources) = &variable_value_as_list ('BUILT_SOURCES', 'all');
1248     local ($s);
1249     foreach $s (@sources)
1250     {
1251         if (/^\@.*\@$/)
1252         {
1253             # FIXME: is this really the right thing to do?
1254             &am_line_error ('BUILT_SOURCES',
1255                             "\`BUILT_SOURCES' should not contain a configure substitution");
1256             last;
1257         }
1258     }
1260     # We don't care about the return value of this function.  We just
1261     # want to make sure to update %dep_files with the contents of
1262     # BUILT_SOURCES.
1263     &handle_single_transform_list (@sources);
1266 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1267 # Also, generate _DEPENDENCIES variable if appropriate.
1268 # Arguments are:
1269 #   transformed name of object being built, or empty string if no object
1270 #   name of _LDADD/_LIBADD-type variable to examine
1271 #   boolean (lex_seen) which is true if a lex source file was seen in this
1272 #     object.  valid only for LDADDs, not LIBADDs.  If set, LEXLIB
1273 #     must be in LDADD.
1274 # Returns 1 if LIBOBJS seen, 0 otherwise.
1275 sub handle_lib_objects
1277     local ($xname, $var, $lex_seen) = @_;
1278     local ($ret);
1280     die "automake: programming error 1 in handle_lib_objects\n"
1281         if ! &variable_defined ($var);
1283     die "automake: programming error 2 in handle_lib_objects\n"
1284         if $lex_seen && $var =~ /LIBADD/;
1286     local (@conds) = &variable_conditions ($var);
1287     if (! @conds)
1288     {
1289         $ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
1290     }
1291     else
1292     {
1293         local ($cond);
1294         $ret = 0;
1295         foreach $cond (@conds)
1296         {
1297             if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
1298             {
1299                 $ret = 1;
1300             }
1301         }
1302     }
1304     return $ret;
1307 # Subroutine of handle_lib_objects: handle a particular condition.
1308 sub handle_lib_objects_cond
1310     local ($xname, $var, $lex_seen, $cond) = @_;
1312     # We recognize certain things that are commonly put in LIBADD or
1313     # LDADD.
1314     local ($lsearch);
1315     local (@dep_list) = ();
1317     # If no lex source seen, just assume this is ok.
1318     local ($lex_ok) = $lex_seen ? 0 : 1;
1320     local ($seen_libobjs) = 0;
1321     local ($flagvar) = 0;
1323     foreach $lsearch (&variable_value_as_list ($var, $cond))
1324     {
1325         # Skip -lfoo and -Ldir; these are explicitly allowed.
1326         next if $lsearch =~ /^-[lL]/;
1327         if (! $flagvar && $lsearch =~ /^-/)
1328         {
1329             if ($var =~ /^(.*)LDADD$/)
1330             {
1331                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1332             }
1333             else
1334             {
1335                 # Only get this error once.
1336                 $flagvar = 1;
1337                 &am_line_error ($var, "you cannot use linker flags such as \`$lsearch' in \`$var'");
1338             }
1339         }
1341         # Assume we have a file of some sort, and push it onto the
1342         # dependency list.  Autoconf substitutions are not pushed;
1343         # rarely is a new dependency substituted into (eg) foo_LDADD
1344         # -- but "bad things (eg -lX11) are routinely substituted.
1345         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1346         # and handled specially below.
1347         push (@dep_list, $lsearch)
1348             unless $lsearch =~ /^\@.*\@$/;
1350         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1351         # means adding entries to dep_files.
1352         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1353         {
1354             push (@dep_list, $lsearch);
1355             $seen_libobjs = 1;
1356             if (! keys %libsources)
1357             {
1358                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
1359             }
1361             local ($iter, $rewrite);
1362             foreach $iter (keys %libsources)
1363             {
1364                 if ($iter =~ /\.[cly]$/)
1365                 {
1366                     $seen_c_source = $var;
1367                 }
1369                 if ($iter =~ /\.h$/)
1370                 {
1371                     &require_file_with_line ($var, $FOREIGN, $iter);
1372                 }
1373                 elsif ($iter ne 'alloca.c')
1374                 {
1375                     ($rewrite = $iter) =~ s/\.c$/.P/;
1376                     $dep_files{'.deps/' . $rewrite} = 1;
1377                     &require_file_with_line ($var, $FOREIGN, $iter);
1378                 }
1379             }
1380         }
1381         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1382         {
1383             push (@dep_list, $lsearch);
1384             &am_line_error ($var,
1385                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
1386                 if ! defined $libsources{'alloca.c'};
1387             $dep_files{'.deps/alloca.P'} = 1;
1388             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1389             $seen_c_source = $var;
1390         }
1391         elsif ($lsearch eq '@LEXLIB@')
1392         {
1393             # FIXME: variable_value_as_list requires us to force
1394             # @LEXLIB@ here, where we'd really prefer $(LEXLIB).
1395             # Nasty -- this will have to wait until many cleanups are
1396             # made, I think.
1397             $lex_ok = 1;
1398         }
1399     }
1401     if (! $lex_ok)
1402     {
1403         &am_line_error ($var, 'lex source file used without @LEXLIB@');
1404     }
1406     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
1407     {
1408         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
1409     }
1411     return $seen_libobjs;
1414 # Canonicalize a name, and check to make sure the non-canonical name
1415 # is never used.  Returns canonical name.  Arguments are name and a
1416 # list of suffixes to check for.
1417 sub check_canonical_spelling
1419     local ($name, @suffixes) = @_;
1420     local ($xname, $xt);
1422     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
1423     if ($xname ne $name)
1424     {
1425         local ($xt);
1426         foreach $xt (@suffixes)
1427         {
1428             &am_line_error ($name . $xt,
1429                             "invalid variable \`" . $name . $xt
1430                             . "'; should be \`" . $xname . $xt . "'")
1431                 if &variable_defined ($name . $xt);
1432         }
1433     }
1435     return $xname;
1438 # Handle C programs.
1439 sub handle_programs
1441     local (@proglist) = &am_install_var ('-clean',
1442                                          'progs', 'PROGRAMS',
1443                                          'bin', 'sbin', 'libexec', 'pkglib',
1444                                          'noinst', 'check');
1445     return if ! @proglist;
1447     # If a program is installed, this is required.  We only want this
1448     # error to appear once.
1449     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1450         unless $seen_arg_prog;
1451     $seen_arg_prog = 1;
1453     local ($one_file, $xname, $munge);
1455     local ($seen_libobjs) = 0;
1456     foreach $one_file (@proglist)
1457     {
1458         local ($obj) = &get_object_extension ($one_file);
1460         # Canonicalize names and check for misspellings.
1461         $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
1462                                             '_SOURCES', '_OBJECTS',
1463                                             '_DEPENDENCIES');
1465         # FIXME: Using a trick to figure out if any lex sources appear
1466         # in our program; should use some cleaner method.
1467         local ($lex_num) = scalar (keys %lex_sources);
1468         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1469         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1471         local ($xt) = '';
1472         if (&variable_defined ($xname . "_LDADD"))
1473         {
1474             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1475                                      $lex_file_seen))
1476             {
1477                 $seen_libobjs = 1;
1478             }
1479             $lex_file_seen = 0;
1480             $xt = '_LDADD';
1481         }
1482         else
1483         {
1484             # User didn't define prog_LDADD override.  So do it.
1485             &define_variable ($xname . '_LDADD', '$(LDADD)');
1487             # This does a bit too much work.  But we need it to
1488             # generate _DEPENDENCIES when appropriate.
1489             if (&variable_defined ('LDADD'))
1490             {
1491                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1492                 {
1493                     $seen_libobjs = 1;
1494                 }
1495                 $lex_file_seen = 0;
1496             }
1497             $xt = '_SOURCES'
1498         }
1500         if (&variable_defined ($xname . '_LIBADD'))
1501         {
1502             &am_line_error ($xname . '_LIBADD',
1503                             "use \`" . $xname . "_LDADD', not \`"
1504                             . $xname . "_LIBADD'");
1505         }
1507         if (! &variable_defined ($xname . '_LDFLAGS'))
1508         {
1509             # Define the prog_LDFLAGS variable.
1510             &define_variable ($xname . '_LDFLAGS', '');
1511         }
1513         if ($lex_file_seen)
1514         {
1515             &am_line_error ($xname . $xt,
1516                             'lex source file used without @LEXLIB@');
1517         }
1519         # Determine program to use for link.
1520         local ($xlink);
1521         if (&variable_defined ($xname . '_LINK'))
1522         {
1523             $xlink = $xname . '_LINK';
1524         }
1525         else
1526         {
1527             $xlink = $linker ? $linker : 'LINK';
1528         }
1530         local ($cygxform);
1531         if (! $seen_cygwin32)
1532         {
1533             $cygxform = 's/^CYGWIN.*$//; s/^NOTCYGWIN//;';
1534         }
1535         else
1536         {
1537             $cygxform = 's/^NOTCYGWIN.*$//; s/^CYGWIN//;';
1538         }
1540         $output_rules .=
1541             &file_contents_with_transform
1542                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1543                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1544                  . 's/\@XLINK\@/' . $xlink . '/go;'
1545                  . $cygxform,
1546                  'program');
1547     }
1549     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1550     {
1551         $seen_libobjs = 1;
1552     }
1554     if ($seen_libobjs)
1555     {
1556         foreach $one_file (@proglist)
1557         {
1558             # Canonicalize names.
1559             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1561             if (&variable_defined ($xname . '_LDADD'))
1562             {
1563                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1564             }
1565             elsif (&variable_defined ('LDADD'))
1566             {
1567                 &check_libobjs_sources ($xname, 'LDADD');
1568             }
1569         }
1570     }
1574 # Handle libraries.
1575 sub handle_libraries
1577     local (@liblist) = &am_install_var ('-clean',
1578                                         'libs', 'LIBRARIES',
1579                                         'lib', 'pkglib', 'noinst', 'check');
1580     return if ! @liblist;
1582     local (%valid) = &am_primary_prefixes ('LIBRARIES', 'lib', 'pkglib',
1583                                            'noinst', 'check');
1584     if (! defined $configure_vars{'RANLIB'})
1585     {
1586         local ($key);
1587         foreach $key (keys %valid)
1588         {
1589             if (&variable_defined ($key . '_LIBRARIES'))
1590             {
1591                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1592                 # Only get this error once.
1593                 $configure_vars{'RANLIB'} = 1;
1594                 last;
1595             }
1596         }
1597     }
1599     local ($onelib);
1600     local ($munge);
1601     local ($xlib);
1602     local ($seen_libobjs) = 0;
1603     foreach $onelib (@liblist)
1604     {
1605         # Check that the library fits the standard naming convention.
1606         if ($onelib !~ /^lib.*\.a$/)
1607         {
1608             # FIXME this should only be a warning for foreign packages
1609             # FIXME should put line number here.  That means mapping
1610             # from library name back to variable name.
1611             &am_error ("\`$onelib' is not a standard library name");
1612         }
1614         local ($obj) = &get_object_extension ($onelib);
1616         # Canonicalize names and check for misspellings.
1617         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
1618                                            '_OBJECTS', '_DEPENDENCIES');
1620         if (&variable_defined ($xlib . '_LIBADD'))
1621         {
1622             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1623             {
1624                 $seen_libobjs = 1;
1625             }
1626         }
1627         else
1628         {
1629             # Generate support for conditional object inclusion in
1630             # libraries.
1631             &define_variable ($xlib . "_LIBADD", '');
1632         }
1634         if (&variable_defined ($xlib . '_LDADD'))
1635         {
1636             &am_line_error ($xlib . '_LDADD',
1637                             "use \`" . $xlib . "_LIBADD', not \`"
1638                             . $xlib . "_LDADD'");
1639         }
1641         &handle_source_transform ($xlib, $onelib, $obj);
1643         $output_rules .=
1644             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1645                                            . 's/\@XLIBRARY\@/'
1646                                            . $xlib . '/go;',
1647                                            'library');
1648     }
1650     if ($seen_libobjs)
1651     {
1652         foreach $onelib (@liblist)
1653         {
1654             # Canonicalize names.
1655             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1656             if (&variable_defined ($xlib . '_LIBADD'))
1657             {
1658                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1659             }
1660         }
1661     }
1663     &define_variable ('AR', 'ar');
1664     &define_configure_variable ('RANLIB');
1667 # Handle shared libraries.
1668 sub handle_ltlibraries
1670     local (@liblist) = &am_install_var ('-clean',
1671                                         'ltlib', 'LTLIBRARIES',
1672                                         'lib', 'pkglib');
1673     return if ! @liblist;
1675     local (%instdirs);
1676     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 'lib', 'pkglib');
1678     local ($key);
1679     foreach $key (keys %valid)
1680     {
1681         if (&variable_defined ($key . '_LTLIBRARIES'))
1682         {
1683             if (!$seen_libtool)
1684             {
1685                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
1686                 # Only get this error once.
1687                 $configure_vars{'LIBTOOL'} = 1;
1688                 $seen_libtool = 1;
1689             }
1691             # Get the installation directory of each library.
1692             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
1693             {
1694                 if ($instdirs{$_})
1695                 {
1696                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1697                 }
1698                 else
1699                 {
1700                     $instdirs{$_} = $key;
1701                 }
1702             }
1703         }
1704     }
1706     local ($onelib);
1707     local ($munge);
1708     local ($xlib);
1709     local ($seen_libobjs) = 0;
1710     foreach $onelib (@liblist)
1711     {
1712         # Check that the library fits the standard naming convention.
1713         if ($onelib !~ /^lib.*\.la$/)
1714         {
1715             # FIXME this should only be a warning for foreign packages
1716             # FIXME should put line number here.  That means mapping
1717             # from library name back to variable name.
1718             &am_error ("\`$onelib' is not a standard libtool library name");
1719         }
1721         local ($obj) = &get_object_extension ($onelib);
1723         # Canonicalize names and check for misspellings.
1724         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
1725                                            '_SOURCES', '_OBJECTS',
1726                                            '_DEPENDENCIES');
1728         if (! &variable_defined ($xlib . '_LDFLAGS'))
1729         {
1730             # Define the lib_LDFLAGS variable.
1731             &define_variable ($xlib . '_LDFLAGS', '');
1732         }
1734         if (&variable_defined ($xlib . '_LIBADD'))
1735         {
1736             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1737             {
1738                 $seen_libobjs = 1;
1739             }
1740         }
1741         else
1742         {
1743             # Generate support for conditional object inclusion in
1744             # libraries.
1745             &define_variable ($xlib . "_LIBADD", '');
1746         }
1748         if (&variable_defined ($xlib . '_LDADD'))
1749         {
1750             &am_line_error ($xlib . '_LDADD',
1751                             "use \`" . $xlib . "_LIBADD', not \`"
1752                             . $xlib . "_LDADD'");
1753         }
1755         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
1757         # Determine program to use for link.
1758         local ($xlink);
1759         if (&variable_defined ($xlib . '_LINK'))
1760         {
1761             $xlink = $xlib . '_LINK';
1762         }
1763         else
1764         {
1765             $xlink = $linker ? $linker : 'LINK';
1766         }
1768         local ($rpath);
1769         if ($instdirs{$onelib} eq 'EXTRA')
1770         {
1771             # It's an EXTRA_ library, so we can't specify -rpath.
1772             # Yuck.
1773             $rpath = 's/\@RPATH\@//go;';
1774         }
1775         else
1776         {
1777             $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
1778                       . 'dir)/go;');
1779         }
1781         $output_rules .=
1782             &file_contents_with_transform ('s/\@LTLIBRARY\@/'
1783                                            . $onelib . '/go;'
1784                                            . 's/\@XLTLIBRARY\@/'
1785                                            . $xlib . '/go;'
1786                                            . $rpath
1787                                            . 's/\@XLINK\@/' . $xlink . '/go;',
1788                                            'ltlibrary');
1789     }
1791     if ($seen_libobjs)
1792     {
1793         foreach $onelib (@liblist)
1794         {
1795             # Canonicalize names.
1796             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1797             if (&variable_defined ($xlib . '_LIBADD'))
1798             {
1799                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1800             }
1801         }
1802     }
1805 # See if any _SOURCES variable were misspelled.  Also, make sure that
1806 # EXTRA_ variables don't contain configure substitutions.
1807 sub check_typos
1809     local ($varname, $primary);
1810     foreach $varname (keys %contents)
1811     {
1812         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS', '_DEPENDENCIES')
1813         {
1814             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
1815             {
1816                 &am_line_error ($varname,
1817                                 "invalid unused variable name: \`$varname'");
1818             }
1819         }
1820     }
1823 # Handle scripts.
1824 sub handle_scripts
1826     # NOTE we no longer automatically clean SCRIPTS, because it is
1827     # useful to sometimes distribute scripts verbatim.  This happens
1828     # eg in Automake itself.
1829     &am_install_var ('scripts', 'SCRIPTS',
1830                      'bin', 'sbin', 'libexec', 'pkgdata',
1831                      'noinst', 'check');
1833     # Set $scripts_installed if appropriate.  Make sure we only find
1834     # scripts which are actually installed -- this is why we can't
1835     # simply use the return value of am_install_var.
1836     local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
1837                                            'libexec', 'pkgdata',
1838                                            'noinst', 'check');
1839     local ($key);
1840     foreach $key (keys %valid)
1841     {
1842         if ($key ne 'noinst'
1843             && $key ne 'check'
1844             && &variable_defined ($key . '_SCRIPTS'))
1845         {
1846             $scripts_installed = 1;
1847             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
1848         }
1849     }
1851     if ($scripts_installed)
1852     {
1853         # If a program is installed, this is required.  We only want this
1854         # error to appear once.
1855         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1856             unless $seen_arg_prog;
1857         $seen_arg_prog = 1;
1858     }
1861 # Search a file for a "version.texi" Texinfo include.  Return the name
1862 # of the include file if found, or the empty string if not.  A
1863 # "version.texi" file is actually any file whose name matches
1864 # "vers*.texi".
1865 sub scan_texinfo_file
1867     local ($filename) = @_;
1869     if (! open (TEXI, $filename))
1870     {
1871         &am_error ("couldn't open \`$filename': $!");
1872         return '';
1873     }
1874     print "automake: reading $filename\n" if $verbose;
1876     local ($vfile, $outfile);
1877     while (<TEXI>)
1878     {
1879         if (/^\@setfilename +(\S+)/)
1880         {
1881             $outfile = $1;
1882             last if ($vfile);
1883         }
1885         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
1886         {
1887             # Found version.texi include.
1888             $vfile = $1;
1889             last if $outfile;
1890         }
1891     }
1893     close (TEXI);
1894     return ($outfile, $vfile);
1897 # Handle all Texinfo source.
1898 sub handle_texinfo
1900     &am_line_error ('TEXINFOS',
1901                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
1902         if &variable_defined ('TEXINFOS');
1903     return if (! &variable_defined ('info_TEXINFOS')
1904                && ! &variable_defined ('html_TEXINFOS'));
1906     local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');
1908     local (@info_deps_list, @dvis_list, @texi_deps);
1909     local ($infobase, $info_cursor);
1910     local (%versions);
1911     local ($done) = 0;
1912     local ($vti);
1913     local ($tc_cursor, @texi_cleans);
1914     local ($canonical);
1916     foreach $info_cursor (@texis)
1917     {
1918         ($infobase = $info_cursor) =~ s/\.texi(nfo)?$//;
1920         # If 'version.texi' is referenced by input file, then include
1921         # automatic versioning capability.
1922         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
1923                                                         . "/" . $info_cursor);
1925         if ($out_file eq '')
1926         {
1927             &am_error ("\`$info_cursor' missing \@setfilename");
1928             next;
1929         }
1931         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
1932         {
1933             # FIXME should report line number in input file.
1934             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
1935             next;
1936         }
1938         if ($vtexi)
1939         {
1940             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
1941                 if (defined $versions{$vtexi});
1942             $versions{$vtexi} = $info_cursor;
1944             # We number the stamp-vti files.  This is doable since the
1945             # actual names don't matter much.  We only number starting
1946             # with the second one, so that the common case looks nice.
1947             $vti = 'vti' . ($done ? $done : '');
1948             &push_dist_common ($vtexi, 'stamp-' . $vti);
1949             push (@clean, $vti);
1951             # Only require once.
1952             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
1953                                           'mdate-sh')
1954                 if ! $done;
1955             ++$done;
1957             local ($conf_pat);
1958             ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
1959             $output_rules .=
1960                 &file_contents_with_transform
1961                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
1962                      . 's/\@VTI\@/' . $vti . '/g; '
1963                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
1964                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
1965                      'texi-vers');
1967             &push_phony_cleaners ($vti);
1968         }
1970         # If user specified file_TEXINFOS, then use that as explicit
1971         # dependency list.
1972         @texi_deps = ();
1973         push (@texi_deps, $info_cursor);
1974         push (@texi_deps, $vtexi) if $vtexi;
1976         # Canonicalize name first.
1977         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
1978         if (&variable_defined ($canonical . "_TEXINFOS"))
1979         {
1980             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
1981             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
1982         }
1984         $output_rules .= ("\n" . $out_file . ": "
1985                           . join (' ', @texi_deps)
1986                           . "\n" . $infobase . ".dvi: "
1987                           . join (' ', @texi_deps)
1988                           . "\n\n");
1990         push (@info_deps_list, $out_file);
1991         push (@dvis_list, $infobase . '.dvi');
1993         # Generate list of things to clean for this target.  We do
1994         # this explicitly because otherwise too many things could be
1995         # removed.  In particular the ".log" extension might
1996         # reasonably be used in other contexts by the user.
1997         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
1998                             'ky', 'log', 'pg', 'toc', 'tp', 'tps',
1999                             'vr', 'vrs', 'op', 'tr', 'cv')
2000         {
2001             push (@texi_cleans, $infobase . '.' . $tc_cursor);
2002         }
2003     }
2005     # Find these programs wherever they may lie.  Yes, this has
2006     # intimate knowledge of the structure of the texinfo distribution.
2007     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
2008                               'makeinfo',
2009                               # Circumlocution to avoid accidental
2010                               # configure substitution.
2011                               '@MAKE' . 'INFO@');
2012     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
2013                               'texi2dvi');
2015     # Set transform for including texinfos.am.  First, handle --cygnus
2016     # stuff.
2017     local ($xform);
2018     if ($cygnus_mode)
2019     {
2020         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
2021     }
2022     else
2023     {
2024         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
2025     }
2027     # Handle location of texinfo.tex.
2028     if ($cygnus_mode)
2029     {
2030         &define_variable ('TEXINFO_TEX',
2031                           '$(top_srcdir)/../texinfo/texinfo.tex');
2032     }
2033     elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
2034     {
2035         &define_variable ('TEXINFO_TEX', $config_aux_dir . '/texinfo.tex');
2036     }
2037     elsif (! &variable_defined ('TEXINFO_TEX'))
2038     {
2039         &define_variable ('TEXINFO_TEX', '$(srcdir)/texinfo.tex');
2040     }
2041     local ($xxform) = &dirname (&variable_value ('TEXINFO_TEX'));
2042     $xxform =~ s/(\W)/\\$1/g;
2043     $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';
2045     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
2046     push (@phony, 'install-info-am', 'uninstall-info');
2047     push (@dist_targets, 'dist-info');
2049     # How to clean.  The funny name is due to --cygnus influence; in
2050     # Cygnus mode, `clean-info' is a target that users can use.
2051     $output_rules .= "\nmostlyclean-aminfo:\n";
2052     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
2053     $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
2054                       . "maintainer-clean-aminfo:\n\t"
2055                       . 'for i in $(INFO_DEPS); do rm -f `eval echo $$i*`; done'
2056                       . "\n");
2057     &push_phony_cleaners ('aminfo');
2058     if ($cygnus_mode)
2059     {
2060         $output_rules .= "clean-info: mostlyclean-aminfo\n";
2061     }
2063     push (@suffixes, '.texi', '.texinfo', '.info', '.dvi', '.ps');
2065     if (! defined $options{'no-installinfo'})
2066     {
2067         push (@uninstall, 'uninstall-info');
2068         push (@installdirs, '$(infodir)');
2069         unshift (@install_data, 'install-info-am');
2071         # Make sure documentation is made and installed first.  Use
2072         # $(INFO_DEPS), not 'info', because otherwise recursive makes
2073         # get run twice during "make all".
2074         unshift (@all, '$(INFO_DEPS)');
2075     }
2076     push (@clean, 'aminfo');
2077     push (@info, '$(INFO_DEPS)');
2078     push (@dvi, '$(DVIS)');
2080     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2081     &define_variable ("DVIS", join (' ', @dvis_list));
2082     # This next isn't strictly needed now -- the places that look here
2083     # could easily be changed to look in info_TEXINFOS.  But this is
2084     # probably better, in case noinst_TEXINFOS is ever supported.
2085     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
2087     # Do some error checking.  Note that this file is not required
2088     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2089     # up above.
2090     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
2091         unless (defined $options{'no-texinfo.tex'}
2092                 || &variable_defined ('TEXINFO_TEX'));
2095 # Handle any man pages.
2096 sub handle_man_pages
2098     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
2099         if &variable_defined ('MANS');
2100     return if ! &variable_defined ('man_MANS');
2102     # We generate the manpage install code by hand to avoid the use of
2103     # basename in the generated Makefile.
2104     local (@mans) = &variable_value_as_list ('man_MANS', 'all');
2105     local (%sections, %inames, %mbases, %secmap, %fullsecmap);
2106     local ($i) = 1;
2107     foreach (@mans)
2108     {
2109         # FIXME: statement without effect:
2110         /^(.*)\.([0-9])([a-z]*)$/;
2111         $sections{$2} = 1;
2112         $inames{$i} = $_;
2113         $mbases{$i} = $1;
2114         $secmap{$i} = $2;
2115         $fullsecmap{$i} = $2 . $3;
2116         $i++;
2117     }
2119     # We don't really need this, but we use it in case we ever want to
2120     # support noinst_MANS.
2121     &define_variable ("MANS", &variable_value ('man_MANS'));
2123     # Generate list of install dirs.
2124     $output_rules .= "install-man: \$(MANS)\n";
2125     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
2126     # Sort keys so that output is deterministic.
2127     foreach (sort keys %sections)
2128     {
2129         push (@installdirs, '$(mandir)/man' . $_)
2130             unless defined $options{'no-installman'};
2131         $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
2132                           . $_ . "\n");
2133     }
2134     push (@phony, 'install-man');
2136     # Generate install target.
2137     local ($key);
2138     foreach $key (sort keys %inames)
2139     {
2140         $_ = $install_man_format;
2141         s/\@SECTION\@/$secmap{$key}/g;
2142         s/\@MAN\@/$inames{$key}/g;
2143         s/\@FULLSECT\@/$fullsecmap{$key}/g;
2144         s/\@MANBASE\@/$mbases{$key}/g;
2145         $output_rules .= $_;
2146     }
2147     $output_rules .= "\n";
2149     $output_rules .= "uninstall-man:\n\t\$(NORMAL_UNINSTALL)\n";
2150     foreach $key (sort keys %inames)
2151     {
2152         $_ = $uninstall_man_format;
2153         s/\@SECTION\@/$secmap{$key}/g;
2154         s/\@MAN\@/$inames{$key}/g;
2155         s/\@FULLSECT\@/$fullsecmap{$key}/g;
2156         s/\@MANBASE\@/$mbases{$key}/g;
2157         $output_rules .= $_;
2158     }
2159     $output_rules .= "\n";
2160     push (@phony, 'uninstall-man');
2162     $output_vars .= &file_contents ('mans-vars');
2164     if (! defined $options{'no-installman'})
2165     {
2166         push (@install_data, 'install-man');
2167         push (@uninstall, 'uninstall-man');
2168         push (@all, '$(MANS)');
2169     }
2172 # Handle DATA variables.
2173 sub handle_data
2175     &am_install_var ('data', 'DATA', 'data', 'sysconf',
2176                      'sharedstate', 'localstate', 'pkgdata',
2177                      'noinst', 'check');
2180 # Handle TAGS.
2181 sub handle_tags
2183     push (@phony, 'tags');
2184     local (@tag_deps) = ();
2185     if (&variable_defined ('SUBDIRS'))
2186     {
2187         $output_rules .= ("tags-recursive:\n"
2188                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
2189                           # Never fail here if a subdir fails; it
2190                           # isn't important.
2191                           . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
2192                           . "\tdone\n");
2193         push (@tag_deps, 'tags-recursive');
2194         push (@phony, 'tags-recursive');
2195     }
2197     if ($dir_holds_sources
2198         || $dir_holds_headers
2199         || &variable_defined ('ETAGS_ARGS')
2200         || @tag_deps)
2201     {
2202         local ($xform) = '';
2203         local ($one_hdr);
2204         foreach $one_hdr (@config_headers)
2205         {
2206             if ($relative_dir eq &dirname ($one_hdr))
2207             {
2208                 # The config header is in this directory.  So require it.
2209                 local ($var);
2210                 ($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
2211                 $xform .= ' ' if $xform;
2212                 $xform .= $var;
2213             }
2214         }
2215         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
2216                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
2218         if (&variable_defined ('SUBDIRS'))
2219         {
2220             $xform .= 's/^SUBDIRS//;';
2221         }
2222         else
2223         {
2224             $xform .= 's/^SUBDIRS.*$//;';
2225         }
2227         $output_rules .= &file_contents_with_transform ($xform, 'tags');
2228         $output_rules .= &file_contents ('tags-clean');
2229         push (@clean, 'tags');
2230         &push_phony_cleaners ('tags');
2231         &examine_variable ('TAGS_DEPENDENCIES');
2232     }
2233     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2234     {
2235         &am_line_error ('TAGS_DEPENDENCIES',
2236                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2237     }
2238     else
2239     {
2240         # Every Makefile must define some sort of TAGS rule.
2241         # Otherwise, it would be possible for a top-level "make TAGS"
2242         # to fail because some subdirectory failed.
2243         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2244     }
2247 # Worker for handle_dist.
2248 sub handle_dist_worker
2250     local ($makefile) = @_;
2252     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
2254     # Initialization; only at top level.
2255     if ($relative_dir eq '.')
2256     {
2257         if ($strictness >= $GNITS)
2258         {
2259             # For Gnits users, this is pretty handy.  Look at 15 lines
2260             # in case some explanatory text is desirable.
2261             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
2262           echo "NEWS not updated; not releasing" 1>&2; \\
2263           exit 1; \\
2264         fi
2266         }
2269         # Create dist directory.
2270         $output_rules .= ("\trm -rf \$(distdir)\n"
2271                           . "\tmkdir \$(distdir)\n"
2272                           . "\t-chmod 777 \$(distdir)\n");
2273     }
2275     # Only run automake in `dist' target if --include-deps and
2276     # `no-dependencies' not specified.  That way the recipient of a
2277     # distribution can run "make dist" and not need Automake.  You
2278     # might be wondering why we run automake once for each directory
2279     # we distribute, instead of running it once at the top level.  The
2280     # answer is that we want to run automake after the dependencies
2281     # have been generated.  This occurs when "make" is run in the
2282     # subdir.  So automake must be run after make has updated the
2283     # Makefile, which means that it must run once per directory.
2284     if ($use_dependencies)
2285     {
2286         $output_rules .=
2287             (
2288              # We need an absolute path for --output-dir.  Thus the
2289              # weirdness.
2290              "\t" . 'here=`cd $(top_builddir) && pwd`; ' . "\\\n"
2291              . "\t" . 'top_distdir=`cd $(top_distdir) && pwd`; ' . "\\\n"
2292              . "\tcd \$(top_srcdir) \\\n"
2293              . "\t  && \$(AUTOMAKE) --include-deps --build-dir=\$\$here --srcdir-name=\$(top_srcdir) --output-dir=\$\$top_distdir "
2294              # Set strictness of output.
2295              . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2296              . ($cmdline_use_dependencies ? '' : ' --include-deps')
2297              . " " . $makefile . "\n"
2298              );
2299     }
2301     # Scan EXTRA_DIST to see if we need to distribute anything from a
2302     # subdir.  If so, add it to the list.  I didn't want to do this
2303     # originally, but there were so many requests that I finally
2304     # relented.
2305     local (@dist_dirs);
2306     if (&variable_defined ('EXTRA_DIST'))
2307     {
2308         # FIXME: This should be fixed to work with conditionals.  That
2309         # will require only making the entries in @dist_dirs under the
2310         # appropriate condition.  This is meaningful if the nature of
2311         # the distribution should depend upon the configure options
2312         # used.
2313         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
2314         {
2315             next if /^\@.*\@$/;
2316             next unless s,/+[^/]+$,,;
2317             push (@dist_dirs, $_)
2318                 unless $_ eq '.';
2319         }
2320     }
2321     if (@dist_dirs)
2322     {
2323         # Prepend $(distdir) to each directory given.  Doing it via a
2324         # hash lets us ensure that each directory is used only once.
2325         local (%dhash);
2326         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
2327         $output_rules .= "\t";
2328         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
2329     }
2331     # In loop, test for file existence because sometimes a file gets
2332     # included in DISTFILES twice.  For example this happens when a
2333     # single source file is used in building more than one program.
2334     # Also, there are situations in which "ln" can fail.  For instance
2335     # a file to distribute could actually be a cross-filesystem
2336     # symlink -- this can easily happen if "gettextize" was run on the
2337     # distribution.
2338     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
2339     if ($cygnus_mode)
2340     {
2341         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
2342     }
2343     else
2344     {
2345         $output_rules .= "\t  d=\$(srcdir); \\\n";
2346     }
2347     $output_rules .= '    test -f $(distdir)/$$file \\
2348           || ln $$d/$$file $(distdir)/$$file 2> /dev/null \\
2349           || cp -p $$d/$$file $(distdir)/$$file; \\
2350         done
2353     # If we have SUBDIRS, create all dist subdirectories and do
2354     # recursive build.
2355     if (&variable_defined ('SUBDIRS'))
2356     {
2357         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
2358         # to all possible directories, and use it.
2359         if (! &variable_conditions ('SUBDIRS'))
2360         {
2361             $dist_subdir_name = 'SUBDIRS';
2362         }
2363         else
2364         {
2365             $dist_subdir_name = 'DIST_SUBDIRS';
2366             if (! &variable_defined ('DIST_SUBDIRS'))
2367             {
2368                 &define_pretty_variable ('DIST_SUBDIRS', '',
2369                                          &variable_value_as_list ('SUBDIRS',
2370                                                                   'all'));
2371             }
2372         }
2374         # Test for directory existence here because previous automake
2375         # invocation might have created some directories.  Note that
2376         # we explicitly set distdir for the subdir make; that lets us
2377         # mix-n-match many automake-using packages into one large
2378         # package, and have "dist" at the top level do the right
2379         # thing.
2380         $output_rules .= '      for subdir in $(' . $dist_subdir_name . '); do          \\
2381           test -d $(distdir)/$$subdir           \\
2382           || mkdir $(distdir)/$$subdir          \\
2383           || exit 1;                            \\
2384           chmod 777 $(distdir)/$$subdir;        \\
2385           (cd $$subdir && $(MAKE) top_distdir=../$(top_distdir) distdir=../$(distdir)/$$subdir distdir) \\
2386             || exit 1; \\
2387         done
2389     }
2391     # If the target `dist-hook' exists, make sure it is run.  This
2392     # allows users to do random weird things to the distribution
2393     # before it is packaged up.
2394     push (@dist_targets, 'dist-hook') if defined $contents{'dist-hook'};
2396     local ($targ);
2397     foreach $targ (@dist_targets)
2398     {
2399         # We must explicitly set distdir and top_distdir for these
2400         # sub-makes.
2401         $output_rules .= "\t\$(MAKE) top_distdir=\"\$(top_distdir)\" distdir=\"\$(distdir)\" $targ\n";
2402     }
2404     push (@phony, 'distdir');
2407 # Handle 'dist' target.
2408 sub handle_dist
2410     local ($makefile) = @_;
2412     # Set up maint_charset.
2413     $local_maint_charset = &variable_value ('MAINT_CHARSET')
2414         if &variable_defined ('MAINT_CHARSET');
2415     $maint_charset = $local_maint_charset
2416         if $relative_dir eq '.';
2418     if (&variable_defined ('DIST_CHARSET'))
2419     {
2420         &am_line_error ('DIST_CHARSET',
2421                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2422             if ! $local_maint_charset;
2423         if ($relative_dir eq '.')
2424         {
2425             $dist_charset = &variable_value ('DIST_CHARSET')
2426         }
2427         else
2428         {
2429             &am_line_error ('DIST_CHARSET',
2430                             "DIST_CHARSET can only be defined at top level");
2431         }
2432     }
2434     # Look for common files that should be included in distribution.
2435     local ($cfile);
2436     foreach $cfile (@common_files)
2437     {
2438         if (-f ($relative_dir . "/" . $cfile))
2439         {
2440             &push_dist_common ($cfile);
2441         }
2442     }
2444     # Keys of %dist_common are names of files to distributed.  We put
2445     # README first because it then becomes easier to make a
2446     # Usenet-compliant shar file (in these, README must be first).
2447     # FIXME: do more ordering of files here.
2448     local (@coms);
2449     if (defined $dist_common{'README'})
2450     {
2451         push (@coms, 'README');
2452         delete $dist_common{'README'};
2453     }
2454     push (@coms, sort keys %dist_common);
2456     &define_pretty_variable ("DIST_COMMON", '', @coms);
2457     $output_vars .= "\n";
2459     # Some boilerplate.
2460     $output_vars .= &file_contents ('dist-vars') . "\n";
2461     &define_variable ('TAR', $TAR);
2462     &define_variable ('GZIP', '--best');
2464     # Put these things in rules section so it is easier for whoever
2465     # reads Makefile.in.
2466     if (! &variable_defined ('distdir'))
2467     {
2468         if ($relative_dir eq '.')
2469         {
2470             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2471         }
2472         else
2473         {
2474             $output_rules .= ("\n"
2475                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2476                               . "\n");
2477         }
2478     }
2479     if ($relative_dir eq '.')
2480     {
2481         $output_rules .= "top_distdir = \$(distdir)\n\n";
2482     }
2483     else
2484     {
2485         $output_rules .= "\nsubdir = " . $relative_dir . "\n\n";
2486     }
2488     # Generate 'dist' target, and maybe dist-shar / dist-zip / dist-tarZ.
2489     if ($relative_dir eq '.')
2490     {
2491         # Rule to check whether a distribution is viable.
2492         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
2493 # it guarantees that the distribution is self-contained by making another
2494 # tarfile.
2495 distcheck: dist
2496         rm -rf $(distdir)
2497         GZIP=$(GZIP) $(TAR) zxf $(distdir).tar.gz
2498         mkdir $(distdir)/=build
2499         mkdir $(distdir)/=inst
2500         dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
2501                           . (defined $contents{'distcheck-hook'}
2502                              ? "\t\$(MAKE) distcheck-hook"
2503                              : '')
2504                           . '
2505         cd $(distdir)/=build \\
2506           && ../configure '
2508                           . ($seen_gettext ? '--with-included-gettext ' : '')
2509                           . '--srcdir=.. --prefix=$$dc_install_base \\
2510           && $(MAKE) \\
2511           && $(MAKE) dvi \\
2512           && $(MAKE) check \\
2513           && $(MAKE) install \\
2514           && $(MAKE) installcheck \\
2515           && $(MAKE) dist
2516         rm -rf $(distdir)
2517         @echo "========================"; \\
2518         echo "$(distdir).tar.gz is ready for distribution"; \\
2519         echo "========================"
2522         local ($dist_all) = ('dist-all: distdir' . "\n"
2523                              . $dist_header);
2524         local ($curs);
2525         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ')
2526         {
2527             if (defined $options{$curs} || $curs eq 'dist')
2528             {
2529                 $output_rules .= ($curs . ': distdir' . "\n"
2530                                   . $dist_header
2531                                   . $dist{$curs}
2532                                   . $dist_trailer);
2533                 $dist_all .= $dist{$curs};
2534             }
2535         }
2536         $output_rules .= $dist_all . $dist_trailer;
2537     }
2539     # Generate distdir target.
2540     &handle_dist_worker ($makefile);
2543 # Scan a single dependency file and rewrite the dependencies as
2544 # appropriate.  Essentially this means:
2545 # * Clean out absolute dependencies which are not desirable.
2546 # * Rewrite other dependencies to be relative to $(top_srcdir).
2547 sub scan_dependency_file
2549     local ($depfile) = @_;
2551     if (! open (DEP_FILE, $depfile))
2552     {
2553         &am_error ("couldn't open \`$depfile': $!");
2554         return;
2555     }
2556     print "automake: reading $depfile\n" if $verbose;
2558     # Sometimes it is necessary to omit some dependencies.
2559     local (%omit) = %omit_dependencies;
2560     if (&variable_defined ('OMIT_DEPENDENCIES'))
2561     {
2562         # FIXME: Doesn't work with conditionals.  I'm not sure if this
2563         # matters.
2564         grep ($omit{$_} = 1,
2565               &variable_value_as_list ('OMIT_DEPENDENCIES', ''));
2566     }
2568     local ($first_line) = 1;
2569     local ($last_line) = 0;
2570     local ($target, @dependencies);
2571     local ($one_dep, $xform);
2572     local ($just_file);
2574     local ($srcdir_rx, $fixup_rx);
2575     ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
2576         =~ s/(\W)/\\$1/g;
2577     ($srcdir_rx = $srcdir_name . '/') =~ s/(\W)/\\$1/g;
2579     local ($rewrite_builddir) = (($top_builddir eq '.')
2580                                  ? ''
2581                                  : $top_builddir . '/');
2583     while (<DEP_FILE>)
2584     {
2585         if ($last_line)
2586         {
2587             # If LAST_LINE set then we've already seen what we thought
2588             # was the last line.
2589             goto bad_format;
2590         }
2591         next if (/$WHITE_PATTERN/o);
2592         chop;
2593         if (! s/\\$//)
2594         {
2595             # No trailing "\" means this should be the last line.
2596             $last_line = 1;
2597         }
2599         if ($first_line)
2600         {
2601             if (! /^([^:]+:)(.+)$/)
2602             {
2603               bad_format:
2604                 &am_error ("\`$depfile' has incorrect format");
2605                 close (DEP_FILE);
2606                 return;
2607             }
2609             $_ = $2;
2610             # Make sure to strip the .P file from the target.
2611             ($target = $1) =~ s, *\.deps/[^.]+\.P,,;
2613             $first_line = 0;
2614         }
2616         foreach $one_dep (split (' ', $_))
2617         {
2618             if ($one_dep =~ /^$fixup_rx/)
2619             {
2620                 # The dependency points to the current directory in
2621                 # some way.
2622                 ($xform = $one_dep) =~ s/^$fixup_rx//;
2623                 push (@dependencies, $xform);
2624             }
2625             elsif ($one_dep =~ /^$srcdir_rx/)
2626             {
2627                 # The dependency is in some other directory in the package.
2628                 ($xform = $one_dep) =~ s/^$srcdir_rx/$rewrite_builddir/;
2629                 push (@dependencies, $xform);
2630             }
2631             elsif ($one_dep =~ /^\//)
2632             {
2633                 # Absolute path; ignore.
2634             }
2635             else
2636             {
2637                 # Anything else is assumed to be correct.  But first
2638                 # make sure it is not on our list of dependencies to
2639                 # omit.
2640                 ($just_file = $one_dep) =~ s,^.*/,,;
2641                 push (@dependencies, $one_dep)
2642                     if ! defined $omit{$just_file};
2643             }
2644         }
2645     }
2647     &pretty_print_rule ($target, "\t", @dependencies);
2649     close (DEP_FILE);
2652 # Handle auto-dependency code.
2653 sub handle_dependencies
2655     if ($use_dependencies)
2656     {
2657         # Include GNU-make-specific auto-dep code.  Don't include it
2658         # if DEP_FILES would be empty.
2659         if ($dir_holds_sources && keys %dep_files)
2660         {
2661             &define_pretty_variable ('DEP_FILES', '', sort keys %dep_files);
2662             $output_rules .= &file_contents ('depend');
2663             push (@clean, 'depend');
2664             &push_phony_cleaners ('depend');
2665             $output_rules .=
2666                 &file_contents_with_transform ('s/\@EXT\@/.c/g;'
2667                                                . 's/\@MKDEP\@/MKDEP/g;'
2668                                                . 's/^ONLYC//g;',
2669                                                'depend2');
2670             local ($ext);
2671             local ($need_cxx) = 0;
2672             foreach $ext (sort keys %cxx_extensions)
2673             {
2674                 $output_rules .=
2675                     &file_contents_with_transform ('s/\@EXT\@/' . $ext .'/g;'
2676                                                    . 's/\@MKDEP\@/CXXMKDEP/g;'
2677                                                    . 's/^ONLYC.*$//;',
2678                                                    'depend2');
2679                 $need_cxx = 1;
2680             }
2681             if ($need_cxx)
2682             {
2683                 &define_variable ('CXXMKDEP', '$(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
2684             }
2685         }
2686     }
2687     elsif ($build_directory ne '')
2688     {
2689         # Include any auto-generated deps that are present.  Note that
2690         # $build_directory ends in a "/".
2691         if (-d ($build_directory . $relative_dir . "/.deps")
2692             && -f ($build_directory . $relative_dir . "/.deps/.P"))
2693         {
2694             local ($depfile);
2696             foreach $depfile (&my_glob ($build_directory
2697                                         . $relative_dir . "/.deps/*.P"))
2698             {
2699                 &scan_dependency_file ($depfile);
2700             }
2702             $output_rules .= "\n";
2703         }
2704     }
2707 # Handle subdirectories.
2708 sub handle_subdirs
2710     return if ! &variable_defined ('SUBDIRS');
2712     # Make sure each directory mentioned in SUBDIRS actually exists.
2713     local ($dir);
2714     foreach $dir (&variable_value_as_list ('SUBDIRS', 'all'))
2715     {
2716         # Skip directories substituted by configure.
2717         next if $dir =~ /^\@.*\@$/;
2719         if (! -d $am_relative_dir . '/' . $dir)
2720         {
2721             &am_line_error ('SUBDIRS',
2722                             "required directory $am_relative_dir/$dir does not exist");
2723             next;
2724         }
2726         &am_line_error ('SUBDIRS', "directory should not contain \`/'")
2727             if $dir =~ /\//;
2728     }
2730     local ($xform) = ('s/\@INSTALLINFO\@/' .
2731                       (defined $options{'no-installinfo'}
2732                        ? 'install-info-recursive'
2733                        : '')
2734                       . '/;');
2735     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
2737     # Push a bunch of phony targets.
2738     local ($phonies);
2739     foreach $phonies ('-data', '-exec', 'dirs')
2740     {
2741         push (@phony, 'install' . $phonies . '-recursive');
2742         push (@phony, 'uninstall' . $phonies . '-recursive');
2743     }
2744     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
2745     {
2746         push (@phony, $phonies . '-recursive');
2747     }
2748     &push_phony_cleaners ('recursive');
2750     push (@check_tests, "check-recursive");
2751     push (@installcheck, "installcheck-recursive");
2752     push (@info, "info-recursive");
2753     push (@dvi, "dvi-recursive");
2755     $recursive_install = 1;
2758 # Handle aclocal.m4.
2759 sub handle_aclocal_m4
2761     local ($regen_aclocal) = 0;
2762     if (-f 'aclocal.m4')
2763     {
2764         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
2765         &push_dist_common ('aclocal.m4');
2767         if (open (ACLOCAL, '< aclocal.m4'))
2768         {
2769             local ($line);
2770             $line = <ACLOCAL>;
2771             close (ACLOCAL);
2773             if ($line =~ 'generated automatically by aclocal')
2774             {
2775                 $regen_aclocal = 1;
2776             }
2777         }
2778     }
2780     local ($acinclude) = 0;
2781     if (-f 'acinclude.m4')
2782     {
2783         $regen_aclocal = 1;
2784         $acinclude = 1;
2785     }
2787     # Note that it might be possible that aclocal.m4 doesn't exist but
2788     # should be auto-generated.  This case probably isn't very
2789     # important.
2790     if ($regen_aclocal)
2791     {
2792         local (@ac_deps) = (
2793                             ($seen_maint_mode ? "\@MAINT\@" : "") ,
2794                             "configure.in",
2795                             ($acinclude ? ' acinclude.m4' : '')
2796                             );
2798         # Scan all -I directories for m4 files.  These are our
2799         # dependencies.
2800         if (&variable_defined ('ACLOCAL_AMFLAGS'))
2801         {
2802             local ($amdir);
2803             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
2804             {
2805                 if ($amdir =~ s/^-I//
2806                     && $amdir !~ /^\//
2807                     && -d $amdir)
2808                 {
2809                     push (@ac_deps, &my_glob ($am_dir . '/*.m4'));
2810                 }
2811             }
2812         }
2814         &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
2816         $output_rules .=  ("\t"
2817                            . 'cd $(srcdir) && $(ACLOCAL)'
2818                            . (&variable_defined ('ACLOCAL_AMFLAGS')
2819                               ? ' $(ACLOCAL_AMFLAGS)' : '')
2820                            . "\n");
2821     }
2824 # Rewrite a list of input files into a form suitable to put on a
2825 # dependency list.  The idea is that if an input file has a directory
2826 # part the same as the current directory, then the directory part is
2827 # simply removed.  But if the directory part is different, then
2828 # $(top_srcdir) is prepended.  Among other things, this is used to
2829 # generate the dependency list for the output files generated by
2830 # AC_OUTPUT.  Consider what the dependencies should look like in this
2831 # case:
2832 #   AC_OUTPUT(src/out:src/in1:lib/in2)
2833 sub rewrite_inputs_into_dependencies
2835     local (@inputs) = @_;
2836     local ($single, @newinputs);
2838     foreach $single (@inputs)
2839     {
2840         if (&dirname ($single) eq $relative_dir)
2841         {
2842             push (@newinputs, &basename ($single));
2843         }
2844         else
2845         {
2846             push (@newinputs, '$(top_srcdir)/' . $single);
2847         }
2848     }
2850     return @newinputs;
2853 # Handle remaking and configure stuff.
2854 # We need the name of the input file, to do proper remaking rules.
2855 sub handle_configure
2857     local ($local, $input, @secondary_inputs) = @_;
2859     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
2860     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
2861         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
2863     local ($top_reldir);
2865     local ($input_base) = &basename ($input);
2866     local ($local_base) = &basename ($local);
2868     local ($amfile) = $input_base . '.am';
2869     # We know we can always add '.in' because it really should be an
2870     # error if the .in was missing originally.
2871     local ($infile) = '$(srcdir)/' . $input_base . '.in';
2872     local ($colon_infile);
2873     if ($local ne $input)
2874     {
2875         $colon_infile = ':' . $input . '.in';
2876     }
2877     $colon_infile .= ':' . join (':', @secondary_inputs)
2878         if @secondary_inputs;
2880     local (@rewritten) = &rewrite_inputs_into_dependencies (@secondary_inputs);
2881     # This rule remakes the Makefile.in.  Note use of @MAINT@ forces
2882     # us to abandon pretty-printing.  Sigh.
2883     $output_rules .= ($infile
2884                       # NOTE perl 5.003 (with -w) gives a
2885                       # uninitialized value error on the next line.
2886                       # Don't know why.
2887                       . ': '
2888                       . ($seen_maint_mode ? '@MAINT@ ' : '')
2889                       . $amfile . ' '
2890                       . '$(top_srcdir)/configure.in $(ACLOCAL_M4) '
2891                       . join (' ', @rewritten) . "\n"
2892                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
2893                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2894                       . ($cmdline_use_dependencies ? '' : ' --include-deps')
2895                       . ' ' . $input . $colon_infile . "\n\n");
2897     # This rule remakes the Makefile.
2898     $output_rules .= ($local_base
2899                       # NOTE: bogus uninit value error on next line;
2900                       # see comment above.
2901                       . ': '
2902                       . $infile . ' '
2903                       . '$(top_builddir)/config.status'
2904                       # NOTE: Makefile only depends on BUILT_SOURCES
2905                       # when dependencies are being computed.  This is
2906                       # a workaround for an obscure bug with
2907                       # AC_LINK_FILES.  Anyway, when dependencies are
2908                       # turned off, this shouldn't matter.
2909                       . ($use_dependencies ? ' $(BUILT_SOURCES)' : '')
2910                       . "\n"
2911                       . "\tcd \$(top_builddir) \\\n"
2912                       . "\t  && CONFIG_FILES="
2913                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
2914                       . $colon_infile
2915                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
2916                       . "\n\n");
2918     if ($relative_dir ne '.')
2919     {
2920         # In subdirectory.
2921         $top_reldir = '../';
2922     }
2923     else
2924     {
2925         &handle_aclocal_m4;
2926         $output_rules .= &file_contents ('remake');
2927         &examine_variable ('CONFIGURE_DEPENDENCIES');
2928         $top_reldir = '';
2929     }
2931     # If we have a configure header, require it.
2932     local ($one_hdr);
2933     local (@local_fullnames) = @config_fullnames;
2934     local (@local_names) = @config_names;
2935     local ($hdr_index) = 0;
2936     local ($distclean_config) = '';
2937     foreach $one_hdr (@config_headers)
2938     {
2939         local ($one_fullname) = shift (@local_fullnames);
2940         local ($one_name) = shift (@local_names);
2941         $hdr_index += 1;
2942         if ($relative_dir eq &dirname ($one_hdr))
2943         {
2944             local ($ch_sans_dir) = &basename ($one_hdr);
2945             local ($cn_sans_dir) = &basename ($one_name);
2947             &require_file_with_conf_line ($config_header_line,
2948                                           $FOREIGN, $ch_sans_dir);
2950             # Header defined and in this directory.
2951             local (@files);
2952             if (-f $relative_dir . '/acconfig.h')
2953             {
2954                 push (@files, 'acconfig.h');
2955             }
2956             if (-f $one_name . '.top')
2957             {
2958                 push (@files, "${cn_sans_dir}.top");
2959             }
2960             if (-f $one_name . '.bot')
2961             {
2962                 push (@files, "${cn_sans_dir}.bot");
2963             }
2965             &push_dist_common (@files);
2967             local ($stamp_name) = 'stamp-h';
2968             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
2970             local ($xform) = '';
2972             $xform = 's,\@FILES\@,' . join (' ', @files) . ',;';
2973             $xform .= 's,\@CONFIG_HEADER\@,' . "${cn_sans_dir}" . ',;';
2974             $xform .= 's,\@CONFIG_HEADER_IN\@,' . "${ch_sans_dir}" . ',;';
2975             $xform .= 's,\@CONFIG_HEADER_FULL\@,' . "${one_fullname}" . ',;';
2976             $xform .= 's,\@STAMP\@,' . "${stamp_name}" . ',;';
2978             $output_rules .= &file_contents_with_transform ($xform,
2979                                                             'remake-hdr');
2981             &touch ($relative_dir . "/${stamp_name}.in");
2982             &require_file_with_conf_line ($config_header_line, $FOREIGN,
2983                                           "${stamp_name}.in");
2985             $distclean_config .= ' ' if $distclean_config;
2986             $distclean_config .= $cn_sans_dir;
2987         }
2988     }
2990     if ($distclean_config)
2991     {
2992         $output_rules .= &file_contents_with_transform ('s,\@FILES\@,'
2993                                                         . $distclean_config
2994                                                         . ',;',
2995                                                         'clean-hdr');
2996         push (@clean, 'hdr');
2997         &push_phony_cleaners ('hdr');
2998     }
3000     # Set location of mkinstalldirs.
3001     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
3002     {
3003         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
3004                                             . '/mkinstalldirs'));
3005     }
3006     else
3007     {
3008         &define_variable ('mkinstalldirs',
3009                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
3010     }
3012     &am_line_error ('CONFIG_HEADER',
3013                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
3014         if &variable_defined ('CONFIG_HEADER');
3016     local ($one_name);
3017     local ($config_header) = '';
3018     foreach $one_name (@config_names)
3019     {
3020         # Generate CONFIG_HEADER define.
3021         local ($one_hdr);
3022         if ($relative_dir eq &dirname ($one_name))
3023         {
3024             $one_hdr = &basename ($one_name);
3025         }
3026         else
3027         {
3028             $one_hdr = "${top_builddir}/${one_name}";
3029         }
3031         $config_header .= ' ' if $config_header;
3032         $config_header .= $one_hdr;
3033     }
3034     if ($config_header)
3035     {
3036         &define_variable ("CONFIG_HEADER", $config_header);
3037     }
3039     # Now look for other files in this directory which must be remade
3040     # by config.status, and generate rules for them.
3041     local (@actual_other_files) = ();
3042     local ($file, $local);
3043     local (@inputs, @rewritten_inputs, $single);
3044     foreach $file (@other_input_files)
3045     {
3046         if ($file =~ /^(.*):(.*)$/)
3047         {
3048             # This is the ":" syntax of AC_OUTPUT.
3049             $file = $1;
3050             $local = &basename ($file);
3051             @inputs = split (':', $2);
3052             @rewritten_inputs = &rewrite_inputs_into_dependencies (@inputs);
3053         }
3054         else
3055         {
3056             # Normal usage.
3057             $local = &basename ($file);
3058             @inputs = ($local . '.in');
3059             @rewritten_inputs =
3060                 &rewrite_inputs_into_dependencies ($file . '.in');
3061         }
3063         # Skip files not in this directory.
3064         next unless &dirname ($file) eq $relative_dir;
3066         # Skip any file that is an automake input.
3067         next if -f $file . '.am';
3069         # Some users have been tempted to put `stamp-h' in the
3070         # AC_OUTPUT line.  This won't do the right thing, so we
3071         # explicitly fail here.
3072         if ($local eq 'stamp-h')
3073         {
3074             # FIXME: allow real filename.
3075             &am_conf_error ('configure.in', $ac_output_line,
3076                             'stamp-h should not appear in AC_OUTPUT');
3077             next;
3078         }
3080         $output_rules .= ($local . ': '
3081                           . '$(top_builddir)/config.status '
3082                           . join (' ', @rewritten_inputs) . "\n"
3083                           . "\t"
3084                           . 'cd $(top_builddir) && CONFIG_FILES='
3085                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3086                           . '$@' . (length (@rewritten_inputs) > 0
3087                                     ? (':' . join (':', @rewritten_inputs))
3088                                     : '')
3089                           . ' CONFIG_HEADERS= ./config.status'
3090                           . "\n");
3091         push (@actual_other_files, $local);
3093         # Require all input files.
3094         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3095                                       @inputs);
3096     }
3098     # These files get removed by "make clean".
3099     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3102 # Handle C headers.
3103 sub handle_headers
3105     $dir_holds_headers = &am_install_var ('header', 'HEADERS', 'include',
3106                                           'oldinclude', 'pkginclude',
3107                                           'noinst', 'check');
3110 sub handle_gettext
3112     return if ! $seen_gettext || $relative_dir ne '.';
3114     if (! &variable_defined ('SUBDIRS'))
3115     {
3116         &am_conf_error
3117             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
3118         return;
3119     }
3121     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
3122         if $seen_gettext;
3124     if (&variable_defined ('SUBDIRS'))
3125     {
3126         &am_line_error
3127             ('SUBDIRS',
3128              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
3129                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
3130         &am_line_error
3131             ('SUBDIRS',
3132              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
3133                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
3134     }
3136     # Ensure that each language in ALL_LINGUAS has a .po file, and
3137     # each po file is mentioned in ALL_LINGUAS.
3138     if ($seen_linguas)
3139     {
3140         local (%linguas) = ();
3141         grep ($linguas{$_} = 1, split (' ', $all_linguas));
3143         foreach (<po/*.po>)
3144         {
3145             s/^po\///;
3146             s/\.po$//;
3148             &am_line_error ($all_linguas_line,
3149                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
3150                 if ! $linguas{$_};
3151         }
3153         foreach (keys %linguas)
3154         {
3155             &am_line_error ($all_linguas_line,
3156                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
3157                 if ! -f "po/$_.po";
3158         }
3159     }
3160     else
3161     {
3162         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
3163     }
3166 # Handle footer elements.
3167 sub handle_footer
3169     if ($contents{'SOURCES'})
3170     {
3171         # NOTE don't use define_pretty_variable here, because
3172         # $contents{...} is already defined.
3173         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
3174     }
3175     if ($contents{'OBJECTS'})
3176     {
3177         # NOTE don't use define_pretty_variable here, because
3178         # $contents{...} is already defined.
3179         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
3180     }
3181     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
3182     {
3183         $output_vars .= "\n";
3184     }
3186     if (&variable_defined ('SUFFIXES'))
3187     {
3188         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
3189         # make do not like variable substitutions on the .SUFFIXES
3190         # line.
3191         push (@suffixes, &variable_value_as_list ('SUFFIXES', ''));
3192     }
3193     if (&target_defined ('.SUFFIXES'))
3194     {
3195         &am_line_error ('.SUFFIXES',
3196                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
3197     }
3199     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3200     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3201     # anything else, by sticking it right after the default: target.
3202     $output_header .= ".SUFFIXES:\n";
3203     if (@suffixes)
3204     {
3206         # Make sure suffixes has unique elements.  Sort them to ensure
3207         # the output remains consistent.
3208         local (%suffixes);
3210         grep ($suffixes{$_} = 1, @suffixes);
3212         $output_header .= (".SUFFIXES: "
3213                            . join (' ', sort keys %suffixes)
3214                            . "\n");
3215     }
3216     $output_trailer .= &file_contents ('footer');
3219 # Deal with installdirs target.
3220 sub handle_installdirs
3222     # GNU Makefile standards recommend this.
3223     $output_rules .= ("installdirs:"
3224                       . ($recursive_install
3225                          ? " installdirs-recursive\n"
3226                          : "\n"));
3227     push (@phony, 'installdirs');
3228     if (@installdirs)
3229     {
3230         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
3231                             @installdirs);
3232     }
3233     $output_rules .= "\n";
3236 # There are several targets which need to be merged.  This is because
3237 # their complete definition is compiled from many parts.  Note that we
3238 # avoid double colon rules, otherwise we'd use them instead.
3239 sub handle_merge_targets
3241     local ($makefile) = @_;
3243     # There are a few install-related variables that you should not define.
3244     local ($var);
3245     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
3246     {
3247         if (&variable_defined ($var))
3248         {
3249             &am_line_error ($var, "\`$var' should not be defined");
3250         }
3251     }
3253     # Put this at the beginning for the sake of non-GNU makes.  This
3254     # is still wrong if these makes can run parallel jobs.  But it is
3255     # right enough.
3256     unshift (@all, &basename ($makefile));
3258     local ($one_name);
3259     foreach $one_name (@config_names)
3260     {
3261         push (@all, &basename ($one_name))
3262             if &dirname ($one_name) eq $relative_dir;
3263     }
3265     &do_one_merge_target ('info', @info);
3266     &do_one_merge_target ('dvi', @dvi);
3267     &do_check_merge_target;
3268     &do_one_merge_target ('installcheck', @installcheck);
3270     if (defined $options{'no-installinfo'})
3271     {
3272         # FIXME: this is kind of a hack; should find another way to
3273         # know that this is required.
3274         local (@dirs);
3275         if (grep ($_ eq 'install-info-am', @phony))
3276         {
3277             push (@dirs, 'install-info-am');
3278         }
3279         if (&variable_defined ('SUBDIRS'))
3280         {
3281             push (@dirs, 'install-info-recursive');
3282         }
3283         &do_one_merge_target ('install-info', @dirs);
3284     }
3286     # Handle the various install targets specially.  We do this so
3287     # that (eg) "make install-exec" will run "install-exec-recursive"
3288     # if required, but "make install" won't run it twice.  Step one is
3289     # to see if the user specified local versions of any of the
3290     # targets we handle.  "all" is treated as one of these since
3291     # "install" can run it.
3292     push (@install_exec, 'install-exec-local')
3293         if defined $contents{'install-exec-local'};
3294     push (@install_data, 'install-data-local')
3295         if defined $contents{'install-data-local'};
3296     push (@uninstall, 'uninstall-local')
3297         if defined $contents{'uninstall-local'};
3298     local ($utarg);
3299     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3300                     'uninstall-exec-local', 'uninstall-exec-hook')
3301     {
3302         if (defined $contents{$utarg})
3303         {
3304             local ($x);
3305             ($x = $utarg) =~ s/(data|exec)-//;
3306             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3307         }
3308     }
3309     push (@all, 'all-local')
3310         if defined $contents{'all-local'};
3312     if (defined $contents{'install-local'})
3313     {
3314         &am_line_error ('install-local',
3315                         "use \`install-data' or \`install-exec', not \`install'");
3316     }
3318     # Step two: if we are doing recursive makes, write out the
3319     # appropriate rules.
3320     local (@install);
3321     if ($recursive_install)
3322     {
3323         push (@install, 'install-recursive');
3325         if (@all)
3326         {
3327             local (@hackall) = ();
3328             local ($one_name);
3329             local ($local_headers) = '';
3330             foreach $one_name (@config_names)
3331             {
3332                 if (&dirname ($one_name) eq $relative_dir)
3333                 {
3334                     $local_headers .= ' ' if $local_headers;
3335                     $local_headers .= &basename ($one_name);
3336                 }
3337             }
3338             if ($local_headers)
3339             {
3341                 # This is kind of a hack, but I couldn't see a better
3342                 # way to handle it.  In this particular case, we need
3343                 # to make sure config.h is built before we recurse.
3344                 # We can't do this by changing the order of
3345                 # dependencies to the "all" because that breaks when
3346                 # using parallel makes.  Instead we handle things
3347                 # explicitly.
3348                 $output_rules .= ("all-recursive-am: ${local_headers}"
3349                                   . "\n\t" . '$(MAKE) all-recursive'
3350                                   . "\n\n");
3351                 push (@hackall, 'all-recursive-am');
3352                 push (@phony, 'all-recursive-am');
3353             }
3354             else
3355             {
3356                 push (@hackall, 'all-recursive');
3357             }
3359             $output_rules .= ('all-am: '
3360                               . join (' ', @all)
3361                               . "\n\n");
3362             @all = @hackall;
3363             push (@all, 'all-am');
3364             push (@phony, 'all-am');
3365         }
3366         else
3367         {
3368             @all = ('all-recursive');
3370             # Must always generate `all-am' target, so it can be
3371             # referred to elsewhere.
3372             $output_rules .= "all-am:\n";
3373         }
3374         if (@install_exec)
3375         {
3376             $output_rules .= ('install-exec-am: '
3377                               . join (' ', @install_exec)
3378                               . "\n\n");
3379             @install_exec = ('install-exec-recursive', 'install-exec-am');
3380             push (@install, 'install-exec-am');
3381             push (@phony, 'install-exec-am');
3382         }
3383         else
3384         {
3385             @install_exec = ('install-exec-recursive');
3386         }
3387         if (@install_data)
3388         {
3389             $output_rules .= ('install-data-am: '
3390                               . join (' ', @install_data)
3391                               . "\n\n");
3392             @install_data = ('install-data-recursive', 'install-data-am');
3393             push (@install, 'install-data-am');
3394             push (@phony, 'install-data-am');
3395         }
3396         else
3397         {
3398             @install_data = ('install-data-recursive');
3399         }
3400         if (@uninstall)
3401         {
3402             $output_rules .= ('uninstall-am: '
3403                               . join (' ', @uninstall)
3404                               . "\n\n");
3405             @uninstall = ('uninstall-recursive', 'uninstall-am');
3406             push (@phony, 'uninstall-am');
3407         }
3408         else
3409         {
3410             @uninstall = ('uninstall-recursive');
3411         }
3412     }
3414     # Step three: print definitions users can use.  Code below knows
3415     # that install-exec is done before install-data, beware.
3416     $output_rules .= ("install-exec: "
3417                       . join (' ', @install_exec)
3418                       . "\n");
3419     $output_rules .= "\t\@\$(NORMAL_INSTALL)\n";
3420     if (defined $contents{'install-exec-hook'})
3421     {
3422         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
3423     }
3424     $output_rules .= "\n";
3425     push (@install, 'install-exec') if !$recursive_install;
3426     push (@phony, 'install-exec');
3428     $output_rules .= ("install-data: "
3429                       . join (' ', @install_data)
3430                       . "\n");
3431     $output_rules .= "\t\@\$(NORMAL_INSTALL)\n";
3432     if (defined $contents{'install-data-hook'})
3433     {
3434         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
3435     }
3436     $output_rules .= "\n";
3437     push (@install, 'install-data') if !$recursive_install;
3438     push (@phony, 'install-data');
3440     # If no dependencies for 'install', add 'all'.  Why?  That way
3441     # "make install" at top level of distclean'd distribution won't
3442     # fail because stuff in 'lib' fails to build.
3443     if (! @install || (scalar (@install) == 2
3444                        && $install[0] eq 'install-exec'
3445                        && $install[1] eq 'install-data'))
3446     {
3447         push (@install, 'all');
3448     }
3449     $output_rules .= ('install: '
3450                       . join (' ', @install)
3451                       # Use "@:" as empty command so nothing prints.
3452                       . "\n\t\@:"
3453                       . "\n\n"
3454                       . 'uninstall: '
3455                       . join (' ', @uninstall)
3456                       . "\n\n");
3457     push (@phony, 'install', 'uninstall');
3459     $output_rules .= ('all: '
3460                       . join (' ', @all)
3461                       . "\n\n");
3462     push (@phony, 'all');
3464     # Generate the new 'install-strip' target.  Must set
3465     # INSTALL_SCRIPT to avoid stripping scripts.
3466     $output_rules .= ("install-strip:\n\t"
3467                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' INSTALL_SCRIPT=\'$(INSTALL_PROGRAM)\' install'
3468                       . "\n");
3471 # Helper for handle_merge_targets.
3472 sub do_one_merge_target
3474     local ($name, @values) = @_;
3476     if (defined $contents{$name . '-local'})
3477     {
3478         # User defined local form of target.  So include it.
3479         push (@values, $name . '-local');
3480         push (@phony, $name . '-local');
3481     }
3483     &pretty_print_rule ($name . ":", "\t\t", @values);
3484     push (@phony, $name);
3487 # Handle check merge target specially.
3488 sub do_check_merge_target
3490     if (defined $contents{'check-local'})
3491     {
3492         # User defined local form of target.  So include it.
3493         push (@check_tests, 'check-local');
3494         push (@phony, 'check-local');
3495     }
3497     if (! &variable_defined ('SUBDIRS'))
3498     {
3499         # 'check' must depend on `all', but not when doing recursive
3500         # build.
3501         unshift (@check, 'all');
3502     }
3503     else
3504     {
3505         # When subdirs are used, do the `all' build and then do all
3506         # the recursive stuff.  Actually use `all-am' because it
3507         # doesn't recurse; we rely on the check target in the subdirs
3508         # to do the required builds there.
3509         unshift (@check, 'all-am');
3510     }
3512     # The check target must depend on the local equivalent of `all',
3513     # to ensure all the primary targets are built.  Also it must
3514     # depend on the test code named in @check.
3515     &pretty_print_rule ('check:', "\t\t", @check);
3517     # Now the check rules must explicitly run anything named in
3518     # @check_tests.  This is done via a separate make invocation to
3519     # avoid problems with parallel makes.  Every time I write code
3520     # like this I wonder: how could you invent a parallel make and not
3521     # provide any real synchronization facilities?
3522     &pretty_print_rule ("\t\$(MAKE)", "\t  ", @check_tests);
3525 # Handle all 'clean' targets.
3526 sub handle_clean
3528     push (@clean, 'generic');
3529     $output_rules .= &file_contents ('clean');
3530     &push_phony_cleaners ('generic');
3532     local ($target) = $recursive_install ? 'clean-am' : 'clean';
3533     &do_one_clean_target ($target, 'mostly', '', @clean);
3534     &do_one_clean_target ($target, '', 'mostly', @clean);
3535     &do_one_clean_target ($target, 'dist', '', @clean);
3536     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
3538     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
3540     local (@deps);
3541     if ($recursive_install)
3542     {
3543         # Do -recursive before -am.  If you aren't doing a parallel
3544         # make, this can be nicer.
3545         @deps = ('recursive', 'am');
3546         &do_one_clean_target ('', 'mostly', '', @deps);
3547         &do_one_clean_target ('', '', '', @deps);
3548         &do_one_clean_target ('', 'dist', '', @deps);
3549         &do_one_clean_target ('', 'maintainer-', '', @deps);
3550     }
3553 # Helper for handle_clean.
3554 sub do_one_clean_target
3556     local ($target, $name, $last_name, @deps) = @_;
3558     # Special case: if target not passed, then don't generate
3559     # dependency on next "lower" clean target (eg no
3560     # clean<-mostlyclean derivation).  In this case the target is
3561     # implicitly known to be 'clean'.
3562     local ($flag) = $target;
3563     $target = 'clean' if ! $flag;
3565     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
3566     if ($flag)
3567     {
3568         if ($last_name || $name ne 'mostly')
3569         {
3570             push (@deps, $last_name . $target);
3571         }
3572     }
3574     # If a -local version of the rule is given, add it to the list.
3575     if (defined $contents{$name . $target . '-local'})
3576     {
3577         push (@deps, $name . $target . '-local');
3578     }
3580     # Print the target and the dependencies.
3581     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
3583     # FIXME: shouldn't we really print these messages before running
3584     # the dependencies?
3585     if ($name . $target eq 'maintainer-clean')
3586     {
3587         # Print a special warning.
3588         $output_rules .=
3589             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
3590              . "\t\@echo \"it deletes files that may require special "
3591              . "tools to rebuild.\"\n");
3593         $output_rules .= "\trm -f config.status\n"
3594             if $relative_dir eq '.';
3595     }
3596     elsif ($name . $target eq 'distclean')
3597     {
3598         $output_rules .= "\trm -f config.status\n";
3599         $output_rules .= "\trm -f libtool\n" if $seen_libtool;
3600     }
3601     $output_rules .= "\n";
3604 # Handle .PHONY target.
3605 sub handle_phony
3607     &pretty_print_rule ('.PHONY:', "", @phony);
3608     $output_rules .= "\n";
3611 # Handle TESTS variable and other checks.
3612 sub handle_tests
3614     if (defined $options{'dejagnu'})
3615     {
3616         push (@check_tests, 'check-DEJAGNU');
3617         push (@phony, 'check-DEJAGNU');
3619         local ($xform);
3620         if ($cygnus_mode)
3621         {
3622             $xform = 's/^CYGNUS//;';
3623         }
3624         else
3625         {
3626             $xform = 's/^CYGNUS.*$//;';
3627         }
3628         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
3630         # In Cygnus mode, these are found in the build tree.
3631         # Otherwise they are looked for in $PATH.
3632         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
3633         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
3635         # Note that in the rule we don't directly generate site.exp to
3636         # avoid the possibility of a corrupted site.exp if make is
3637         # interrupted.  Jim Meyering has some useful text on this
3638         # topic.
3639         $output_rules .= ("site.exp: Makefile\n"
3640                           . "\t\@echo 'Making a new site.exp file...'\n"
3641                           . "\t-\@rm -f site.bak\n"
3642                           . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
3643                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
3644                           . "\t\@echo '# edit the last section' >> \$\@-t\n"
3645                           . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
3646                           . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
3647                           . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
3649         # Extra stuff for AC_CANONICAL_*
3650         local (@whatlist) = ();
3651         if ($seen_canonical)
3652         {
3653             push (@whatlist, 'host')
3654         }
3656         # Extra stuff only for AC_CANONICAL_SYSTEM.
3657         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
3658         {
3659             push (@whatlist, 'target', 'build');
3660         }
3662         local ($c1, $c2);
3663         foreach $c1 (@whatlist)
3664         {
3665             foreach $c2 ('alias', 'triplet')
3666             {
3667                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
3668             }
3669         }
3671         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
3672                           . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
3673                           . "\t-\@mv site.exp site.bak\n"
3674                           . "\t\@mv \$\@-t site.exp\n");
3675     }
3676     else
3677     {
3678         local ($c);
3679         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
3680         {
3681             if (&variable_defined ($c))
3682             {
3683                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
3684             }
3685         }
3686     }
3688     if (&variable_defined ('TESTS'))
3689     {
3690         push (@check_tests, 'check-TESTS');
3691         push (@phony, 'check-TESTS');
3693         $output_rules .= 'check-TESTS: $(TESTS)
3694         @failed=0; all=0; \\
3695         srcdir=$(srcdir); export srcdir; \\
3696         for tst in $(TESTS); do \\
3697           if test -f $$tst; then dir=.; \\
3698           else dir="$(srcdir)"; fi; \\
3699           if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
3700             all=`expr $$all + 1`; \\
3701             echo "PASS: $$tst"; \\
3702           elif test $$? -ne 77; then \\
3703             all=`expr $$all + 1`; \\
3704             failed=`expr $$failed + 1`; \\
3705             echo "FAIL: $$tst"; \\
3706           fi; \\
3707         done; \\
3708         if test "$$failed" -eq 0; then \\
3709           banner="All $$all tests passed"; \\
3710         else \\
3711           banner="$$failed of $$all tests failed"; \\
3712         fi; \\
3713         dashes=`echo "$$banner" | sed s/./=/g`; \\
3714         echo "$$dashes"; \\
3715         echo "$$banner"; \\
3716         echo "$$dashes"; \\
3717         test "$$failed" -eq 0
3719     }
3722 # Handle Emacs Lisp.
3723 sub handle_emacs_lisp
3725     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
3727     if (@elfiles)
3728     {
3729         # Found some lisp.
3730         &define_configure_variable ('lispdir');
3731         &define_configure_variable ('EMACS');
3732         $output_rules .= (".el.elc:\n"
3733                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
3734                           . "\tif test \$(EMACS) != no; then \\\n"
3735                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
3736                           . "\tfi\n");
3737         push (@suffixes, '.el', '.elc');
3739         # Generate .elc files.
3740         grep ($_ .= 'c', @elfiles);
3741         &define_pretty_variable ('ELCFILES', '', @elfiles);
3743         $output_rules .= &file_contents ('lisp-clean');
3744         push (@clean, 'lisp');
3745         &push_phony_cleaners ('lisp');
3747         push (@all, '$(ELCFILES)');
3749         local ($varname);
3750         if (&variable_defined ('lisp_LISP'))
3751         {
3752             $varname = 'lisp_LISP';
3753             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
3754                 if ! $seen_lispdir;
3755         }
3756         else
3757         {
3758             $varname = 'noinst_LISP';
3759         }
3761         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
3762     }
3765 ################################################################
3767 # Scan one file for interesting things.  Subroutine of scan_configure.
3768 sub scan_one_configure_file
3770     local ($filename) = @_;
3772     open (CONFIGURE, $filename)
3773         || die "automake: couldn't open \`$filename': $!\n";
3774     print "automake: reading $filename\n" if $verbose;
3776     while (<CONFIGURE>)
3777     {
3778         # Remove comments from current line.
3779         s/\bdnl\b.*$//;
3780         s/\#.*$//;
3782         # Skip macro definitions.  Otherwise we might be confused into
3783         # thinking that a macro that was only defined was actually
3784         # used.
3785         next if /AC_DEFUN/;
3787         # Populate libobjs array.
3788         if (/AC_FUNC_ALLOCA/)
3789         {
3790             $libsources{'alloca.c'} = 1;
3791         }
3792         elsif (/AC_FUNC_GETLOADAVG/)
3793         {
3794             $libsources{'getloadavg.c'} = 1;
3795         }
3796         elsif (/AC_FUNC_MEMCMP/)
3797         {
3798             $libsources{'memcmp.c'} = 1;
3799         }
3800         elsif (/AC_STRUCT_ST_BLOCKS/)
3801         {
3802             $libsources{'fileblocks.c'} = 1;
3803         }
3804         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
3805         {
3806             $libsources{'getopt.c'} = 1;
3807             $libsources{'getopt1.c'} = 1;
3808         }
3809         elsif (/AM_FUNC_STRTOD/)
3810         {
3811             $libsources{'strtod.c'} = 1;
3812         }
3813         elsif (/AM_WITH_REGEX/)
3814         {
3815             $libsources{'rx.c'} = 1;
3816             $libsources{'rx.h'} = 1;
3817             $libsources{'regex.c'} = 1;
3818             $libsources{'regex.h'} = 1;
3819             $omit_dependencies{'rx.h'} = 1;
3820             $omit_dependencies{'regex.h'} = 1;
3821         }
3822         elsif (/AM_FUNC_MKTIME/)
3823         {
3824             $libsources{'mktime.c'} = 1;
3825         }
3826         elsif (/AM_FUNC_ERROR_AT_LINE/)
3827         {
3828             $libsources{'error.c'} = 1;
3829             $libsources{'error.h'} = 1;
3830         }
3831         elsif (/AM_FUNC_OBSTACK/)
3832         {
3833             $libsources{'obstack.c'} = 1;
3834             $libsources{'obstack.h'} = 1;
3835         }
3836         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
3837                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
3838         {
3839             foreach $libobj_iter (split (' ', $1))
3840             {
3841                 if ($libobj_iter =~ /^(.*)\.o$/)
3842                 {
3843                     $libsources{$1 . '.c'} = 1;
3844                 }
3845             }
3846         }
3848         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
3849         {
3850             $in_ac_replace = 1;
3851         }
3852         if ($in_ac_replace)
3853         {
3854             $in_ac_replace = 0 if s/[\]\)].*$//;
3855             # Remove trailing backslash.
3856             s/\\$//;
3857             foreach (split)
3858             {
3859                 # Need to skip empty elements for Perl 4.
3860                 next if $_ eq '';
3861                 $libsources{$_ . '.c'} = 1;
3862             }
3863         }
3865         if (/$obsolete_rx/o)
3866         {
3867             local ($hint) = '';
3868             if ($obsolete_macros{$1})
3869             {
3870                 $hint = '; ' . $obsolete_macros{$1};
3871             }
3872             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
3873         }
3875         # Process the AC_OUTPUT macro.
3876         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
3877         {
3878             $in_ac_output = 1;
3879             $ac_output_line = $.;
3880         }
3881         if ($in_ac_output)
3882         {
3883             $in_ac_output = 0 if s/[\]\),].*$//;
3885             # Look at potential Makefile.am's.
3886             foreach (split)
3887             {
3888                 next if $_ eq "\\";
3890                 # Handle $local:$input syntax.  Note that we ignore
3891                 # every input file past the first, though we keep
3892                 # those around for later.
3893                 local ($local, $input, @rest) = split (/:/);
3894                 if (! $input)
3895                 {
3896                     $input = $local;
3897                 }
3898                 else
3899                 {
3900                     # FIXME: should be error if .in is missing.
3901                     $input =~ s/\.in$//;
3902                 }
3904                 if (-f $input . '.am')
3905                 {
3906                     # We have a file that automake should generate.
3907                     push (@make_input_list, $input);
3908                     $make_list{$input} = join (':', ($local, @rest));
3909                 }
3910                 else
3911                 {
3912                     # We have a file that automake should cause to be
3913                     # rebuilt, but shouldn't generate itself.
3914                     push (@other_input_files, $_);
3915                 }
3916             }
3917         }
3919         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
3920         {
3921             @config_aux_path = $1;
3922         }
3924         # Check for ansi2knr.
3925         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
3927         # Check for Cygwin32.
3928         if (/AM_CYGWIN32/)
3929         {
3930             $seen_cygwin32 = 1;
3931             $configure_vars{'EXEEXT'} = 1;
3932         }
3934         # Check for NLS support.
3935         if (/AM_GNU_GETTEXT/)
3936         {
3937             $seen_gettext = 1;
3938             $ac_gettext_line = $.;
3939             $omit_dependencies{'libintl.h'} = 1;
3940         }
3942         # Look for ALL_LINGUAS.
3943         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
3944         {
3945             $seen_linguas = 1;
3946             $all_linguas = $1;
3947             $all_linguas_line = $.;
3948         }
3950         # Handle configuration headers.  A config header of `[$1]'
3951         # means we are actually scanning AM_CONFIG_HEADER from
3952         # aclocal.m4.
3953         if (/A([CM])_CONFIG_HEADER\s*\((.*)\)/
3954             && $2 ne '[$1]')
3955         {
3956             &am_conf_line_error
3957                 ($filename, $.,
3958                  "\`AC_CONFIG_HEADER' is obsolete; use \`AM_CONFIG_HEADER'")
3959                     if $1 eq 'C';
3961             $config_header_line = $.;
3962             local ($one_hdr);
3963             foreach $one_hdr (split (' ', $2))
3964             {
3965                 push (@config_fullnames, $one_hdr);
3966                 if ($one_hdr =~ /^([^:]+):(.+)$/)
3967                 {
3968                     push (@config_names, $1);
3969                     push (@config_headers, $2);
3970                 }
3971                 else
3972                 {
3973                     push (@config_names, $one_hdr);
3974                     push (@config_headers, $one_hdr . '.in');
3975                 }
3976             }
3977         }
3979         # Handle AC_CANONICAL_*.  Always allow upgrading to
3980         # AC_CANONICAL_SYSTEM, but never downgrading.
3981         $seen_canonical = $AC_CANONICAL_HOST
3982             if ! $seen_canonical
3983                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
3984         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
3986         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
3988         # This macro handles several different things.
3989         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
3990         {
3991             $seen_make_set = 1;
3992             $seen_package = 1;
3993             $seen_version = 1;
3994             $seen_arg_prog = 1;
3995             $seen_prog_install = 2;
3996             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
3997             $package_version_line = $.;
3998         }
4000         # This is like AM_INIT_AUTOMAKE, but doesn't actually set the
4001         # package and version number.  (This might change in the
4002         # future).  Yes, I'm not above hacking Automake so it works
4003         # well with other GNU tools -- that is actually the point.
4004         if (/AM_INIT_GUILE_MODULE/)
4005         {
4006             $seen_make_set = 1;
4007             $seen_package = 1;
4008             $seen_version = 1;
4009             $seen_arg_prog = 1;
4010             $seen_prog_install = 2;
4011             @config_aux_path = ('..');
4012         }
4014         # Some things required by Automake.
4015         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
4016         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
4018         if (/AC_PROG_(YACC|RANLIB|CC|CXX|LEX|AWK|CPP|CXXCPP|LN_S)/)
4019         {
4020             $configure_vars{$1} = 1;
4021         }
4022         if (/$AC_CHECK_PATTERN/o)
4023         {
4024             $configure_vars{$3} = 1;
4025         }
4026         if (/$AM_MISSING_PATTERN/o
4027             && $1 ne 'ACLOCAL'
4028             && $1 ne 'AUTOCONF'
4029             && $1 ne 'AUTOMAKE'
4030             && $1 ne 'AUTOHEADER')
4031         {
4032             $configure_vars{$1} = 1;
4033         }
4035         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4036         # but later define it elsewhere.  This is pretty hacky.  We
4037         # also explicitly avoid INSTALL_SCRIPT and some other
4038         # variables because they are defined in header-vars.am.
4039         # FIXME.
4040         if (/$AC_SUBST_PATTERN/o
4041             && $1 ne 'ANSI2KNR'
4042             && $1 ne 'INSTALL_SCRIPT')
4043         {
4044             $configure_vars{$1} = 1;
4045         }
4047         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4048         $seen_maint_mode = 1 if /AM_MAINTAINER_MODE/;
4049         $seen_package = 1 if /PACKAGE=/;
4051         # Skip VERSION of [$2]; that is from AM_INIT_AUTOMAKE.
4052         if (/\bVERSION=(\S+)/ && $1 ne '[$2]')
4053         {
4054             $seen_version = 1;
4055             $package_version = $1;
4056             $package_version_line = $.;
4057         }
4058         elsif (/VERSION=/)
4059         {
4060             $seen_version = 1;
4061         }
4063         # Weird conditionals here because it is always allowed to
4064         # upgrade to AM_PROG_INSTALL but never to downgrade to
4065         # AC_PROG_INSTALL.
4066         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
4067         $seen_prog_install = 2 if /AM_PROG_INSTALL/;
4069         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4071         if (/AM_PROG_LIBTOOL/)
4072         {
4073             $seen_libtool = 1;
4074             $libtool_line = $.;
4075             $configure_vars{'LIBTOOL'} = 1;
4076             $configure_vars{'RANLIB'} = 1;
4077             $configure_vars{'CC'} = 1;
4078             # AM_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
4079             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4080             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4081         }
4083         if (/$AM_CONDITIONAL_PATTERN/o)
4084         {
4085             $configure_cond{$1} = 1;
4086         }
4087     }
4089     close (CONFIGURE);
4092 # Scan configure.in and aclocal.m4 for interesting things.  We must
4093 # scan aclocal.m4 because there might be AC_SUBSTs and such there.
4094 sub scan_configure
4096     # Reinitialize libsources here.  This isn't really necessary,
4097     # since we currently assume there is only one configure.in.  But
4098     # that won't always be the case.
4099     %libsources = ();
4101     local ($in_ac_output, $in_ac_replace) = (0, 0);
4102     local (%make_list, @make_input_list);
4103     local ($libobj_iter);
4105     &scan_one_configure_file ('configure.in');
4106     &scan_one_configure_file ('aclocal.m4')
4107         if -f 'aclocal.m4';
4109     # Set input and output files if not specified by user.
4110     if (! @input_files)
4111     {
4112         @input_files = @make_input_list;
4113         %output_files = %make_list;
4114     }
4116     &am_conf_error ("\`PACKAGE' not defined in configure.in")
4117         if ! $seen_package;
4118     &am_conf_error ("\`VERSION' not defined in configure.in")
4119         if ! $seen_version;
4121     # Look for some files we need.  Always check for these.  This
4122     # check must be done for every run, even those where we are only
4123     # looking at a subdir Makefile.  We must set relative_dir so that
4124     # the file-finding machinery works.
4125     local ($relative_dir) = '.';
4126     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4127     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
4128         if -f $config_aux_path[0] . '/install.sh';
4131 ################################################################
4133 # Set up for Cygnus mode.
4134 sub check_cygnus
4136     return unless $cygnus_mode;
4138     &set_strictness ('foreign');
4139     $options{'no-installinfo'} = 1;
4140     $options{'no-dependencies'} = 1;
4141     $use_dependencies = 0;
4143     if (! $seen_maint_mode)
4144     {
4145         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
4146     }
4148     if (! $seen_cygwin32)
4149     {
4150         &am_conf_error ("\`AM_CYGWIN32' required when --cygnus specified");
4151     }
4154 # Do any extra checking for GNU standards.
4155 sub check_gnu_standards
4157     if ($relative_dir eq '.')
4158     {
4159         # In top level (or only) directory.
4160         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4161                        'AUTHORS', 'ChangeLog');
4162     }
4164     if ($strictness >= $GNU)
4165     {
4166         if (defined $options{'no-installman'})
4167         {
4168             &am_line_error ('AUTOMAKE_OPTIONS',
4169                             "option \`no-installman' disallowed by GNU standards");
4170         }
4172         if (defined $options{'no-installinfo'})
4173         {
4174             &am_line_error ('AUTOMAKE_OPTIONS',
4175                             "option \`no-installinfo' disallowed by GNU standards");
4176         }
4177     }
4180 # Do any extra checking for GNITS standards.
4181 sub check_gnits_standards
4183     if ($strictness >= $GNITS)
4184     {
4185         if (-f $relative_dir . '/COPYING.LIB')
4186         {
4187             &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
4188         }
4190         if ($relative_dir eq '.')
4191         {
4192             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4193             {
4194                 # FIXME: allow real filename.
4195                 &am_conf_line_error ('configure.in',
4196                                      $package_version_line,
4197                                      "version \`$package_version' doesn't follow Gnits standards");
4198             }
4199             elsif (defined $1 && -f 'README-alpha')
4200             {
4201                 # This means we have an alpha release.  See
4202                 # GNITS_VERSION_PATTERN for details.
4203                 &require_file ($GNITS, 'README-alpha');
4204             }
4205         }
4206     }
4208     if ($relative_dir eq '.')
4209     {
4210         # In top level (or only) directory.
4211         &require_file ($GNITS, 'THANKS');
4212     }
4215 ################################################################
4217 # Pretty-print something.  HEAD is what should be printed at the
4218 # beginning of the first line, FILL is what should be printed at the
4219 # beginning of every subsequent line.
4220 sub pretty_print_internal
4222     local ($head, $fill, @values) = @_;
4224     local ($column) = length ($head);
4225     local ($result) = $head;
4227     # Fill length is number of characters.  However, each Tab
4228     # character counts for eight.  So we count the number of Tabs and
4229     # multiply by 7.
4230     local ($fill_length) = length ($fill);
4231     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
4233     local ($bol) = ($head eq '');
4234     foreach (@values)
4235     {
4236         # "71" because we also print a space.
4237         if ($column + length ($_) > 71)
4238         {
4239             $result .= " \\\n" . $fill;
4240             $column = $fill_length;
4241             $bol = 1;
4242         }
4244         $result .= ' ' unless ($bol);
4245         $result .= $_;
4246         $column += length ($_) + 1;
4247         $bol = 0;
4248     }
4250     $result .= "\n";
4251     return $result;
4254 # Pretty-print something and append to output_vars.
4255 sub pretty_print
4257     $output_vars .= &pretty_print_internal (@_);
4260 # Pretty-print something and append to output_rules.
4261 sub pretty_print_rule
4263     $output_rules .= &pretty_print_internal (@_);
4267 ################################################################
4269 # See if a target exists.
4270 sub target_defined
4272     local ($target) = @_;
4273     return defined $targets{$target};
4276 # See if two conditionals are the same.
4277 sub conditional_same
4279     local ($cond1, $cond2) = @_;
4281     return (&conditional_true_when ($cond1, $cond2)
4282             && &conditional_true_when ($cond2, $cond1));
4285 # See if a conditional is true.  Both arguments are conditional
4286 # strings.  This returns true if the first conditional is true when
4287 # the second conditional is true.
4288 sub conditional_true_when
4290     local ($cond, $when) = @_;
4292     # Check the easy case first.
4293     if ($cond eq $when)
4294     {
4295         return 1;
4296     }
4298     # Check each component of $cond, which looks @COND1@@COND2@.
4299     foreach $comp (split ('@', $cond))
4300     {
4301         # The way we split will give null strings between each
4302         # condition.
4303         next if ! $comp;
4305         if (index ($when, '@' . $comp . '@') == -1)
4306         {
4307             return 0;
4308         }
4309     }
4311     return 1;
4314 # Check for an ambiguous conditional.  This is called when a variable
4315 # or target is being defined conditionally.  If we already know about
4316 # a definition that is true under the same conditions, then we have an
4317 # ambiguity.
4318 sub check_ambiguous_conditional
4320     local ($var_name, $cond) = @_;
4321     local (@cond_vals) = split (/ /, $conditional{$var_name});
4322     while (@cond_vals)
4323     {
4324         local ($vcond) = shift (@cond_vals);
4325         shift (@cond_vals);
4326         if (&conditional_true_when ($vcond, $cond)
4327             || &conditional_true_when ($cond, $vcond))
4328         {
4329             &am_line_error ($var_name,
4330                             "$var_name multiply defined in condition");
4331         }
4332     }
4335 # See if a variable exists.  The first argument is the variable name,
4336 # and the optional second argument is the condition which we should
4337 # check.  If no condition is given, we currently return true if the
4338 # variable is defined under any condition.
4339 sub variable_defined
4341     local ($var, $cond) = @_;
4342     if (defined $targets{$var})
4343     {
4344         &am_line_error ($var, "\`$var' is target; expected variable");
4345         return 0;
4346     }
4347     elsif (defined $contents{$var})
4348     {
4349         if ($cond && $conditional{$var})
4350         {
4351             # We have been asked to check for a particular condition,
4352             # and the variable is defined conditionally.  We need to
4353             # look through the conditions under which the variable is
4354             # defined, and see if any of them match the conditional we
4355             # have been asked to check.
4356             local (@cond_vars) = split (/ /, $conditional{$var});
4357             while (@cond_vars)
4358             {
4359                 if (&conditional_same ($cond, shift (@cond_vars)))
4360                 {
4361                     return 1;
4362                 }
4363                 shift (@cond_vars);
4364             }
4366             # The variable is not defined for the given condition.
4367             return 0;
4368         }
4370         $content_seen{$var} = 1;
4371         return 1;
4372     }
4373     return 0;
4376 # Mark a variable as examined.
4377 sub examine_variable
4379     local ($var) = @_;
4380     &variable_defined ($var);
4383 # Quote a value in order to put it in $conditional.  We need to quote
4384 # spaces, and we need to handle null strings, so that we can later
4385 # retrieve values by splitting on space.
4386 sub quote_cond_val
4388     local ($val) = @_;
4389     $val =~ s/ /\001/g;
4390     $val = '\002' if $val eq '';
4391     return $val;
4394 # Unquote a value in $conditional.
4395 sub unquote_cond_val
4397     local ($val) = @_;
4398     $val =~ s/\001/ /g;
4399     $val = '' if $val eq '\002';
4400     return $val;
4403 # Return the set of conditions for which a variable is defined.
4405 # If the variable is not defined conditionally, and is not defined in
4406 # terms of any variables which are defined conditionally, then this
4407 # returns the empty list.
4409 # If the variable is defined conditionally, but is not defined in
4410 # terms of any variables which are defined conditionally, then this
4411 # returns the list of conditions for which the variable is defined.
4413 # If the variable is defined in terms of any variables which are
4414 # defined conditionally, then this returns a full set of permutations
4415 # of the subvariable conditions.  For example, if the variable is
4416 # defined in terms of a variable which is defined for @COND_TRUE@,
4417 # then this returns both @COND_TRUE@ and @COND_FALSE@.  This is
4418 # because we will need to define the variable under both conditions.
4420 sub variable_conditions
4422     local ($var) = @_;
4423     local (%uniqify);
4424     local ($cond);
4426     foreach $cond (&variable_conditions_sub ($var, '', ()))
4427     {
4428         $uniqify{$cond} = 1;
4429     }
4431     return keys %uniqify;
4434 # A subroutine of variable_conditions.  We only return conditions
4435 # which are true for all the conditions in @PARENT_CONDS.
4436 sub variable_conditions_sub
4438     local ($var, $parent, @parent_conds) = @_;
4439     local (@new_conds) = ();
4441     if (! $conditional{$var})
4442     {
4443         foreach (split (' ', $contents{$var}))
4444         {
4445             # If a comment seen, just leave.
4446             last if /^#/;
4448             # Handle variable substitutions.
4449             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
4450             {
4451                 push (@new_conds,
4452                       &variable_conditions_sub ($1, $var, @parent_conds));
4453             }
4454         }
4456         return &variable_conditions_reduce (@new_conds);
4457     }
4459     local (@this_conds) = ();
4460     local (@condvals) = split (/ /, $conditional{$var});
4461     while (@condvals)
4462     {
4463         local ($cond) = shift (@condvals);
4464         local ($val) = &unquote_cond_val (shift (@condvals));
4466         if (@parent_conds)
4467         {
4468             local ($ok) = 1;
4469             local ($parent_cond);
4470             foreach $parent_cond (@parent_conds)
4471             {
4472                 if (! &conditional_true_when ($parent_cond, $cond))
4473                 {
4474                     $ok = 0;
4475                     last;
4476                 }
4477             }
4479             next if ! $ok;
4480         }
4482         push (@this_conds, $cond);
4484         push (@parent_conds, $cond);
4485         local (@subvar_conds) = ();
4486         foreach (split (' ', $val))
4487         {
4488             # If a comment seen, just leave.
4489             last if /^#/;
4491             # Handle variable substitutions.
4492             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
4493             {
4494                 push (@subvar_conds,
4495                       &variable_conditions_sub ($1, $var, @parent_conds));
4496             }
4497         }
4498         pop (@parent_conds);
4500         # If there are no conditional subvariables, then we want to
4501         # return this condition.  Otherwise, we want to return the
4502         # permutations of the subvariables.
4503         if (! @subvar_conds)
4504         {
4505             push (@new_conds, $cond);
4506         }
4507         else
4508         {
4509             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
4510         }
4511     }
4513     return @new_conds
4514         if ! $parent;
4516     # If we are being called on behalf of another variable, we need to
4517     # return all possible permutations of the conditions.  We have
4518     # already handled everything in @this_conds along with their
4519     # subvariables.  We now need to add any permutations that are not
4520     # in @this_conds.
4521     local ($this_cond);
4522     foreach $this_cond (@this_conds)
4523     {
4524         local (@perms) =
4525             &variable_conditions_permutations (split('@', $this_cond));
4526         local ($perm);
4527         foreach $perm (@perms)
4528         {
4529             local ($scan);
4530             local ($ok) = 1;
4531             foreach $scan (@this_conds)
4532             {
4533                 if (&conditional_true_when ($perm, $scan)
4534                     || &conditional_true_when ($scan, $perm))
4535                 {
4536                     $ok = 0;
4537                     last;
4538                 }
4539             }
4540             next if ! $ok;
4542             if (@parent_conds)
4543             {
4544                 local ($ok) = 1;
4545                 local ($parent_cond);
4546                 foreach $parent_cond (@parent_conds)
4547                 {
4548                     if (! &conditional_true_when ($parent_cond, $perm))
4549                     {
4550                         $ok = 0;
4551                         last;
4552                     }
4553                 }
4555                 next if ! $ok;
4556             }
4558             # This permutation was not already handled, and is valid
4559             # for the parents.
4560             push (@new_conds, $perm);
4561         }
4562     }
4564     return @new_conds;
4567 # Subroutine for variable_conditions_sort
4568 sub variable_conditions_cmp
4570     local ($as) = $a;
4571     $as =~ s/[^@]//g;
4572     local ($bs) = $b;
4573     $bs =~ s/[^@]//g;
4574     return (length ($as) <=> length ($bs)
4575             || $a cmp $b);
4578 # Sort a list of conditionals so that only the exclusive ones are
4579 # retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
4580 # @COND1_TRUE@ are in the list, discard the latter.
4581 sub variable_conditions_reduce
4583     local (@conds) = @_;
4584     local (@ret) = ();
4585     local ($cond);
4586     foreach $cond (sort variable_conditions_cmp @conds)
4587     {
4588         local ($ok) = 1;
4589         local ($scan);
4590         foreach $scan (@ret)
4591         {
4592             if (&conditional_true_when ($cond, $scan))
4593             {
4594                 $ok = 0;
4595                 last;
4596             }
4597         }
4598         next if ! $ok;
4599         push (@ret, $cond);
4600     }
4602     return @ret;
4605 # Return a list of permutations of a conditional string.
4606 sub variable_conditions_permutations
4608     local (@comps) = @_;
4609     return ()
4610         if ! @comps;
4611     local ($comp) = shift (@comps);
4612     return &variable_conditions_permutations (@comps)
4613         if $comp eq '';
4614     local ($neg) = $comp;
4615     $neg =~ s/TRUE$/TRUEO/;
4616     $neg =~ s/FALSE$/TRUE/;
4617     $neg =~ s/TRUEO$/FALSE/;
4618     local (@ret);
4619     local ($sub);
4620     foreach $sub (&variable_conditions_permutations (@comps))
4621     {
4622         push (@ret, '@' . $comp . '@' . $sub);
4623         push (@ret, '@' . $neg . '@' . $sub);
4624     }
4625     if (! @ret)
4626     {
4627         push (@ret, '@' . $comp . '@');
4628         push (@ret, '@' . $neg . '@');
4629     }
4630     return @ret;
4633 # Warn if a variable is conditionally defined.  This is called if we
4634 # are using the value of a variable.
4635 sub variable_conditionally_defined
4637     local ($var, $parent) = @_;
4638     if ($conditional{$var})
4639     {
4640         if ($parent)
4641         {
4642             &am_line_error ($parent,
4643                             "warning: automake does not support conditional definition of $var in $parent");
4644         }
4645         else
4646         {
4647             &am_line_error ($parent,
4648                             "warning: automake does not support $var being defined conditionally")
4649         }
4650     }
4653 # Get the value of a variable.  This just returns $contents, but warns
4654 # if the variable is conditionally defined.
4655 sub variable_value
4657     local ($var) = @_;
4658     &variable_conditionally_defined ($var);
4659     return $contents{$var};
4662 # Convert a variable value to a list, split as whitespace.  This will
4663 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
4664 # substitutions.  If COND is 'all', then all values under all
4665 # conditions should be returned; if COND is a particular condition
4666 # (all conditions are surrounded by @...@) then only the value for
4667 # that condition should be returned; otherwise, warn if VAR is
4668 # conditionally defined.
4669 sub value_to_list
4671     local ($var, $val, $cond) = @_;
4672     local (@result);
4674     foreach (split (' ', $val))
4675     {
4676         # If a comment seen, just leave.
4677         last if /^#/;
4679         # Handle variable substitutions.
4680         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
4681         {
4682             local ($varname) = $1;
4683             local ($from, $to);
4684             local (@temp_list);
4685             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
4686             {
4687                 $varname = $1;
4688                 $to = $3;
4689                 ($from = $2) =~ s/(\W)/\\$1/g;
4690             }
4692             # Find the value.
4693             @temp_list = &variable_value_as_list ($1, $cond, $var);
4695             # Now rewrite the value if appropriate.
4696             if ($from)
4697             {
4698                 grep (s/$from$/$to/, @temp_list);
4699             }
4701             push (@result, @temp_list);
4702         }
4703         else
4704         {
4705             push (@result, $_);
4706         }
4707     }
4709     return @result;
4712 # Return contents of variable as list, split as whitespace.  This will
4713 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
4714 # substitutions.  If COND is 'all', then all values under all
4715 # conditions should be returned; if COND is a particular condition
4716 # (all conditions are surrounded by @...@) then only the value for
4717 # that condition should be returned; otherwise, warn if VAR is
4718 # conditionally defined.  If PARENT is specified, it is the name of
4719 # the including variable; this is only used for error reports.
4720 sub variable_value_as_list
4722     local ($var, $cond, $parent) = @_;
4723     local (@result);
4725     if (defined $targets{$var})
4726     {
4727         &am_line_error ($var, "\`$var' is target; expected variable");
4728     }
4729     elsif (! defined $contents{$var})
4730     {
4731         &am_line_error ($parent, "variable \`$var' not defined");
4732     }
4733     elsif ($cond eq 'all' && $conditional{$var})
4734     {
4735         local (@condvals) = split (/ /, $conditional{$var});
4736         while (@condvals)
4737         {
4738             shift (@condvals);
4739             local ($val) = &unquote_cond_val (shift (@condvals));
4740             push (@result, &value_to_list ($var, $val, $cond));
4741         }
4742     }
4743     elsif ($cond && $conditional{$var})
4744     {
4745         local (@condvals) = split (/ /, $conditional{$var});
4746         local ($onceflag);
4747         while (@condvals)
4748         {
4749             local ($vcond) = shift (@condvals);
4750             local ($val) = &unquote_cond_val (shift (@condvals));
4751             if (&conditional_true_when ($vcond, $cond))
4752             {
4753                 # Warn if we have an ambiguity.  It's hard to know how
4754                 # to handle this case correctly.
4755                 &variable_conditionally_defined ($var, $parent)
4756                     if $onceflag;
4757                 $onceflag = 1;
4758                 push (@result, &value_to_list ($var, $val, $cond));
4759             }
4760         }
4761     }
4762     else
4763     {
4764         &variable_conditionally_defined ($var, $parent);
4765         $content_seen{$var} = 1;
4766         push (@result, &value_to_list ($var, $contents{$var}, $cond));
4767     }
4769     return @result;
4772 # Define a new variable, but only if not already defined.
4773 sub define_variable
4775     local ($var, $value) = @_;
4777     if (! defined $contents{$var})
4778     {
4779         $output_vars .= $var . ' = ' . $value . "\n";
4780         $contents{$var} = $value;
4781         $content_seen{$var} = 1;
4782     }
4785 # Like define_variable, but the value is a list, and the variable may
4786 # be defined conditionally.  The second argument is the conditional
4787 # under which the value should be defined; this should be the empty
4788 # string to define the variable unconditionally.  The third argument
4789 # is a list holding the values to use for the variable.  The value is
4790 # pretty printed in the output file.
4791 sub define_pretty_variable
4793     local ($var, $cond, @value) = @_;
4794     if (! defined $contents{$var}
4795         || ($cond && ! &variable_defined ($var, $cond)))
4796     {
4797         $contents{$var} = join (' ', @value);
4798         if ($cond)
4799         {
4800             if ($conditional{$var})
4801             {
4802                 $conditional{$var} .= ' ';
4803             }
4804             else
4805             {
4806                 $conditional{$var} = '';
4807             }
4808             $conditional{$var} .= ($cond
4809                                    . ' '
4810                                    . &quote_cond_val ($contents{$var}));
4811         }
4812         &pretty_print ($cond . $var . ' = ', $cond, @value);
4813         $content_seen{$var} = 1;
4814     }
4817 # Like define_variable, but define a variable to be the configure
4818 # substitution by the same name.
4819 sub define_configure_variable
4821     local ($var) = @_;
4822     local ($value) = '@' . $var . '@';
4823     &define_variable ($var, $value);
4826 # Define a variable that represents a program to run.  If in Cygnus
4827 # mode, the program is searched for in the build (or source) tree.
4828 # Otherwise no searching is done at all.  Arguments are:
4829 # * VAR      Name of variable to define
4830 # * WHATDIR  Either `src' or `build', depending on where program should
4831 #            be found.  (runtest is in srcdir!)
4832 # * SUBDIR   Subdir of top-level dir
4833 # * PROGRAM  Name of program
4834 # * OVERRIDE If specified, the name of the program to use when not in
4835 #            Cygnus mode.  Defaults to PROGRAM.
4836 sub define_program_variable
4838     local ($var, $whatdir, $subdir, $program, $override) = @_;
4840     if (! $override)
4841     {
4842         $override = $program;
4843     }
4845     if ($cygnus_mode)
4846     {
4847         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
4848                          . $subdir . '/' . $program);
4849         &define_variable ($var, ('`if test -f ' . $full
4850                                  . '; then echo ' . $full . '; else echo '
4851                                  . $program . '; fi`'));
4852     }
4853     else
4854     {
4855         &define_variable ($var, $override);
4856     }
4860 ################################################################
4862 # Read Makefile.am and set up %contents.  Simultaneously copy lines
4863 # from Makefile.am into $output_trailer or $output_vars as
4864 # appropriate.  NOTE we put rules in the trailer section.  We want
4865 # user rules to come after our generated stuff.
4866 sub read_am_file
4868     local ($amfile) = @_;
4870     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
4871     print "automake: reading $amfile\n" if $verbose;
4873     $output_vars = ("# $in_file_name generated automatically by automake "
4874                     . $VERSION . " from $am_file_name\n");
4876     # Generate copyright for generated Makefile.in.
4877     $output_vars .= $gen_copyright;
4879     local ($saw_bk) = 0;
4880     local ($was_rule) = 0;
4881     local ($spacing) = '';
4882     local ($comment) = '';
4883     local ($last_var_name) = '';
4884     local ($blank) = 0;
4886     while (<AM_FILE>)
4887     {
4888         if (/$IGNORE_PATTERN/o)
4889         {
4890             # Merely delete comments beginning with two hashes.
4891         }
4892         elsif (/$WHITE_PATTERN/o)
4893         {
4894             # Stick a single white line before the incoming macro or rule.
4895             $spacing = "\n";
4896             $blank = 1;
4897         }
4898         elsif (/$COMMENT_PATTERN/o)
4899         {
4900             # Stick comments before the incoming macro or rule.  Make
4901             # sure a blank line preceeds first block of comments.
4902             $spacing = "\n" unless $blank;
4903             $blank = 1;
4904             $comment .= $spacing . $_;
4905             $spacing = '';
4906         }
4907         else
4908         {
4909             last;
4910         }
4911     }
4913     $output_vars .= $comment . "\n";
4914     $comment = '';
4915     $spacing = "\n";
4916     local ($am_vars) = '';
4918     local ($is_ok_macro);
4919     while ($_)
4920     {
4921         $_ .= "\n"
4922             unless substr ($_, -1, 1) eq "\n";
4924         $_ =~ s/\@MAINT\@//g
4925             unless $seen_maint_mode;
4927         if (/$IGNORE_PATTERN/o)
4928         {
4929             # Merely delete comments beginning with two hashes.
4930         }
4931         elsif (/$WHITE_PATTERN/o)
4932         {
4933             # Stick a single white line before the incoming macro or rule.
4934             $spacing = "\n";
4935         }
4936         elsif (/$COMMENT_PATTERN/o)
4937         {
4938             # Stick comments before the incoming macro or rule.
4939             $comment .= $spacing . $_;
4940             $spacing = '';
4941         }
4942         elsif ($saw_bk)
4943         {
4944             if ($was_rule)
4945             {
4946                 $output_trailer .= join ('', @conditional_stack) . $_;
4947                 $saw_bk = /\\$/;
4948             }
4949             else
4950             {
4951                 $am_vars .= join ('', @conditional_stack) . $_;
4952                 $saw_bk = /\\$/;
4953                 # Chop newline and backslash if this line is
4954                 # continued.  FIXME: maybe ensure trailing whitespace
4955                 # exists?
4956                 chop if $saw_bk;
4957                 chop if $saw_bk;
4958                 $contents{$last_var_name} .= $_;
4959                 if (@conditional_stack)
4960                 {
4961                     $conditional{$last_var_name} .= &quote_cond_val ($_);
4962                 }
4963             }
4964         }
4965         elsif (/$IF_PATTERN/o)
4966         {
4967             &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
4968                 if (! $configure_cond{$1});
4969             push (@conditional_stack, "\@" . $1 . "_TRUE\@");
4970         }
4971         elsif (/$ELSE_PATTERN/o)
4972         {
4973             if (! @conditional_stack)
4974             {
4975                 &am_line_error ($., "else without if");
4976             }
4977             elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
4978             {
4979                 &am_line_error ($., "else after else");
4980             }
4981             else
4982             {
4983                 $conditional_stack[$#conditional_stack]
4984                     =~ s/_TRUE\@$/_FALSE\@/;
4985             }
4986         }
4987         elsif (/$ENDIF_PATTERN/o)
4988         {
4989             if (! @conditional_stack)
4990             {
4991                 &am_line_error ($., "endif without if");
4992             }
4993             else
4994             {
4995                 pop @conditional_stack;
4996             }
4997         }
4998         elsif (/$RULE_PATTERN/o)
4999         {
5000             # Found a rule.
5001             $was_rule = 1;
5002             if (defined $contents{$1}
5003                 && (@conditional_stack
5004                     ? ! defined $conditional{$1}
5005                     : defined $conditional{$1}))
5006             {
5007                 &am_line_error ($1,
5008                                 "$1 defined both conditionally and unconditionally");
5009             }
5010             # Value here doesn't matter; for targets we only note
5011             # existence.
5012             $contents{$1} = 1;
5013             $targets{$1} = 1;
5014             local ($cond_string) = join ('', @conditional_stack);
5015             if (@conditional_stack)
5016             {
5017                 if ($conditional{$1})
5018                 {
5019                     &check_ambiguous_conditional ($1, $cond_string);
5020                     $conditional{$1} .= ' ';
5021                 }
5022                 else
5023                 {
5024                     $conditional{$1} = '';
5025                 }
5026                 $conditional{$1} .= $cond_string . ' 1';
5027             }
5028             $content_lines{$1} = $.;
5029             $output_trailer .= $comment . $spacing . $cond_string . $_;
5030             $comment = $spacing = '';
5031             $saw_bk = /\\$/;
5032         }
5033         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
5034                || /$BOGUS_MACRO_PATTERN/o)
5035         {
5036             # Found a macro definition.
5037             $was_rule = 0;
5038             $last_var_name = $1;
5039             if (defined $contents{$1}
5040                 && (@conditional_stack
5041                     ? ! defined $conditional{$1}
5042                     : defined $conditional{$1}))
5043             {
5044                 &am_line_error ($1,
5045                                 "$1 defined both conditionally and unconditionally");
5046             }
5047             if ($2 ne '' && substr ($2, -1) eq "\\")
5048             {
5049                 $contents{$last_var_name} = substr ($2, 0, length ($2) - 1);
5050             }
5051             else
5052             {
5053                 $contents{$last_var_name} = $2;
5054             }
5055             local ($cond_string) = join ('', @conditional_stack);
5056             if (@conditional_stack)
5057             {
5058                 if ($conditional{$last_var_name})
5059                 {
5060                     &check_ambiguous_conditional ($last_var_name,
5061                                                   $cond_string);
5062                     $conditional{$last_var_name} .= ' ';
5063                 }
5064                 else
5065                 {
5066                     $conditional{$last_var_name} = '';
5067                 }
5068                 local ($val) = $contents{$last_var_name};
5069                 $conditional{$last_var_name} .= ($cond_string
5070                                                  . ' '
5071                                                  . &quote_cond_val ($val));
5072             }
5073             $content_lines{$last_var_name} = $.;
5074             $am_vars .= $comment . $spacing . $cond_string . $_;
5075             $comment = $spacing = '';
5076             $saw_bk = /\\$/;
5078             # Error if bogus.
5079             &am_line_error ($., "bad macro name \`$last_var_name'")
5080                 if ! $is_ok_macro;
5081         }
5082         else
5083         {
5084             # This isn't an error; it is probably a continued rule.
5085             # In fact, this is what we assume.
5086             $was_rule = 1;
5087             $output_trailer .= ($comment . $spacing
5088                                 . join ('', @conditional_stack) . $_);
5089             $comment = $spacing = '';
5090             $saw_bk = /\\$/;
5091         }
5093         $_ = <AM_FILE>;
5094     }
5096     $output_trailer .= $comment;
5098     &am_error ("unterminated conditionals: " . join (' ', @conditional_stack))
5099         if (@conditional_stack);
5101     # Compute relative location of the top object directory.
5102     local (@topdir) = ();
5103     foreach (split (/\//, $relative_dir))
5104     {
5105         next if $_ eq '.' || $_ eq '';
5106         if ($_ eq '..')
5107         {
5108             pop @topdir;
5109         }
5110         else
5111         {
5112             push (@topdir, '..');
5113         }
5114     }
5115     @topdir = ('.') if ! @topdir;
5117     $top_builddir = join ('/', @topdir);
5118     local ($build_rx);
5119     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
5120     $output_vars .= &file_contents_with_transform
5121                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
5122                          'header-vars');
5124     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
5125     # this should use generic %configure_vars method.
5126     if ($seen_canonical)
5127     {
5128         local ($curs, %vars);
5129         $vars{'host_alias'} = 'host_alias';
5130         $vars{'host_triplet'} = 'host';
5131         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
5132         {
5133             $vars{'build_alias'} = 'build_alias';
5134             $vars{'build_triplet'} = 'build';
5135             $vars{'target_alias'} = 'target_alias';
5136             $vars{'target_triplet'} = 'target';
5137         }
5138         foreach $curs (sort keys %vars)
5139         {
5140             $output_vars .= "$curs = \@$vars{$curs}\@\n";
5141             $contents{$curs} = "\@$vars{$curs}\@";
5142         }
5143     }
5145     local ($curs);
5146     foreach $curs (sort keys %configure_vars)
5147     {
5148         &define_configure_variable ($curs);
5149     }
5151     $output_vars .= $am_vars;
5154 ################################################################
5156 sub initialize_global_constants
5158     # Values for AC_CANONICAL_*
5159     $AC_CANONICAL_HOST = 1;
5160     $AC_CANONICAL_SYSTEM = 2;
5162     # Associative array of standard directory names.  Entry is TRUE if
5163     # corresponding directory should be installed during
5164     # 'install-exec' phase.
5165     %exec_dir_p =
5166         ('bin', 1,
5167          'sbin', 1,
5168          'libexec', 1,
5169          'data', 0,
5170          'sysconf', 1,
5171          'localstate', 1,
5172          'lib', 1,
5173          'info', 0,
5174          'man', 0,
5175          'include', 0,
5176          'oldinclude', 0,
5177          'pkgdata', 0,
5178          'pkglib', 1,
5179          'pkginclude', 0
5180          );
5182     # Helper text for dealing with man pages.
5183     $install_man_format =
5184     '   @sect=@SECTION@;                                \\
5185         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
5186         if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
5187         else file=@MAN@; fi; \\
5188         echo " $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst"; \\
5189         $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst
5192     $uninstall_man_format =
5193     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
5194         rm -f $(mandir)/man@SECTION@/$$inst
5197     # Commonly found files we look for and automatically include in
5198     # DISTFILES.
5199     @common_files =
5200         (
5201          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
5202          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
5203          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
5204          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
5205          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
5206          'ylwrap', 'acinclude.m4', @libtoolize_files,
5207          'missing'
5208          );
5210     # Commonly used files we auto-include, but only sometimes.
5211     @common_sometimes =
5212         (
5213          "aclocal.m4", "acconfig.h", "config.h.top",
5214          "config.h.bot", "stamp-h.in", 'stamp-vti'
5215          );
5217     $USAGE = "\
5218   -a, --add-missing     add missing standard files to package
5219   --amdir=DIR           directory storing config files
5220   --build-dir=DIR       directory where build being done (for dependencies)
5221   --cygnus              assume program is part of Cygnus-style tree
5222   --foreign             set strictness to foreign
5223   --gnits               set strictness to gnits
5224   --gnu                 set strictness to gnu
5225   --help                print this help, then exit
5226   -i, --include-deps    include generated dependencies in Makefile.in
5227   --no-force            only update Makefile.in's that are out of date
5228   -o DIR, --output-dir=DIR
5229                         put generated Makefile.in's into DIR
5230   --srcdir-name=DIR     name used for srcdir (for dependencies)
5231   -v, --verbose         verbosely list files processed
5232   --version             print version number, then exit\n";
5234     # Copyright on generated Makefile.ins.
5235     $gen_copyright = "\
5236 # Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
5237 # This Makefile.in is free software; the Free Software Foundation
5238 # gives unlimited permission to copy and/or distribute it,
5239 # with or without modifications, as long as this notice is preserved.
5242     # Ignore return result from chmod, because it might give an error
5243     # if we chmod a symlink.
5244     $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
5245     $dist{'dist-tarZ'} = ("\t"
5246                      . '$(TAR) chf - $(distdir) | compress -c > $(distdir).tar.Z'
5247                      . "\n");
5248     $dist{'dist-shar'} = ("\t"
5249                      . 'shar $(distdir) | gzip > $(distdir).shar.gz'
5250                      . "\n");
5251     $dist{'dist-zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
5252     $dist{'dist'} = "\t" .  'GZIP=$(GZIP) $(TAR) chozf $(distdir).tar.gz $(distdir)' . "\n";
5253     $dist_trailer = "\t" . 'rm -rf $(distdir)' . "\n";
5256 # (Re)-Initialize per-Makefile.am variables.
5257 sub initialize_per_input
5259     # These two variables are used when generating each Makefile.in.
5260     # They hold the Makefile.in until it is ready to be printed.
5261     $output_rules = '';
5262     $output_vars = '';
5263     $output_trailer = '';
5264     $output_header = '';
5266     # Suffixes found during a run.
5267     @suffixes = ();
5269     # This holds the contents of a Makefile.am, as parsed by
5270     # read_am_file.
5271     %contents = ();
5273     # This holds the names which are targets.  These also appear in
5274     # %contents.
5275     %targets = ();
5277     # For a variable or target which is defined conditionally, this
5278     # holds an array of the conditional values.  The array is composed
5279     # of pairs of condition strings (the variables which configure
5280     # will substitute) and values (the value of a target is
5281     # meaningless).  For an unconditional variable, this is empty.
5282     %conditional = ();
5284     # This holds the line numbers at which various elements of
5285     # %contents are defined.
5286     %content_lines = ();
5288     # This holds a 1 if a particular variable was examined.
5289     %content_seen = ();
5291     # This is the conditional stack.
5292     @conditional_stack = ();
5294     # This holds the "relative directory" of the current Makefile.in.
5295     # Eg for src/Makefile.in, this is "src".
5296     $relative_dir = '';
5298     # This holds a list of files that are included in the
5299     # distribution.
5300     %dist_common = ();
5302     # List of dependencies for the obvious targets.
5303     @install_data = ();
5304     @install_exec = ();
5305     @uninstall = ();
5306     @installdirs = ();
5308     @info = ();
5309     @dvi = ();
5310     @all = ();
5311     @check = ();
5312     @check_tests = ();
5313     @installcheck = ();
5314     @clean = ();
5316     @phony = ();
5318     # These are pretty obvious, too.  They are used to define the
5319     # SOURCES and OBJECTS variables.
5320     @sources = ();
5321     @objects = ();
5323     # TRUE if current directory holds any C source files.
5324     $dir_holds_sources = 0;
5326     # These variables track inclusion of various compile-related .am
5327     # files.  $included_generic_compile is TRUE if the basic code has
5328     # been included.  $included_knr_compile is TRUE if the ansi2knr
5329     # code has been included.  $included_libtool_compile is TRUE if
5330     # libtool support has been included.
5331     $included_generic_compile = 0;
5332     $included_knr_compile = 0;
5333     $included_libtool_compile = 0;
5335     # TRUE if current directory holds any headers.
5336     $dir_holds_headers = 0;
5338     # TRUE if install targets should work recursively.
5339     $recursive_install = 0;
5341     # All .P files.
5342     %dep_files = ();
5344     # Strictness levels.
5345     $strictness = $default_strictness;
5346     $strictness_name = $default_strictness_name;
5348     # Options from AUTOMAKE_OPTIONS.
5349     %options = ();
5351     # Whether or not dependencies are handled.  Can be further changed
5352     # in handle_options.
5353     $use_dependencies = $cmdline_use_dependencies;
5355     # Per Makefile.am.
5356     $local_maint_charset = $maint_charset;
5358     # All yacc and lex source filenames for this directory.  Use
5359     # filenames instead of raw count so that multiple instances are
5360     # counted correctly (eg one yacc file can appear in multiple
5361     # programs without harm).
5362     %yacc_sources = ();
5363     %lex_sources = ();
5365     # C++ source extensions we've seen.
5366     %cxx_extensions = ();
5368     # TRUE if we've seen any non-C++ sources.  This actually holds a
5369     # line number or the name of a symbol corresponding to a line
5370     # number where the C sources were seen.  If it is -1 then it means
5371     # we couldn't (easily) figure out which line of the Makefile.am
5372     # mentioned the sources.
5373     $seen_c_source = 0;
5375     # This is a list of all targets to run during "make dist".
5376     @dist_targets = ();
5378     # Keys in this hash are the basenames of files which must depend
5379     # on ansi2knr.
5380     %de_ansi_files = ();
5384 ################################################################
5386 # Return contents of a file from $am_dir, automatically skipping
5387 # macros or rules which are already known.  Runs command on each line
5388 # as it is read; this command can modify $_.
5389 sub file_contents_with_transform
5391     local ($command, $basename) = @_;
5392     local ($file) = $am_dir . '/' . $basename . '.am';
5394     if ($command ne '' && substr ($command, -1) ne ';')
5395     {
5396         die "automake: programming error in file_contents_with_transform\n";
5397     }
5399     open (FC_FILE, $file)
5400         || die "automake: installation error: cannot open \`$file'\n";
5401     # Looks stupid?
5402     # print "automake: reading $file\n" if $verbose;
5404     local ($was_rule) = 0;
5405     local ($result_vars) = '';
5406     local ($result_rules) = '';
5407     local ($comment) = '';
5408     local ($spacing) = "\n";
5409     local ($skipping) = 0;
5410     local ($had_chars);
5412     while (<FC_FILE>)
5413     {
5414         $_ =~ s/\@MAINT\@//g
5415             unless $seen_maint_mode;
5417         $had_chars = length ($_) && $_ ne "\n";
5418         eval $command;
5419         # If the transform caused all the characters to go away, then
5420         # ignore the line.  Why do this?  Because in Perl 4, a "next"
5421         # inside of an eval doesn't affect a loop outside the eval.
5422         # So we can't pass in a "transform" that uses next.  We used
5423         # to do this.  "Empty" also means consisting of a single
5424         # newline.
5425         next if $had_chars && ($_ eq '' || $_ eq "\n");
5427         if (/$IGNORE_PATTERN/o)
5428         {
5429             # Merely delete comments beginning with two hashes.
5430         }
5431         elsif (/$WHITE_PATTERN/o)
5432         {
5433             # Stick a single white line before the incoming macro or rule.
5434             $spacing = "\n";
5435         }
5436         elsif (/$COMMENT_PATTERN/o)
5437         {
5438             # Stick comments before the incoming macro or rule.
5439             $comment .= $spacing . $_;
5440             $spacing = '';
5441         }
5442         elsif ($saw_bk)
5443         {
5444             if ($was_rule)
5445             {
5446                 $result_rules .= $_ if ! $skipping;
5447             }
5448             else
5449             {
5450                 $result_vars .= $_ if ! $skipping;
5451             }
5452             $saw_bk = /\\$/;
5453         }
5454         elsif (/$RULE_PATTERN/o)
5455         {
5456             # Found a rule.
5457             $was_rule = 1;
5458             $skipping = defined $contents{$1};
5459             $result_rules .= $comment . $spacing . $_ if ! $skipping;
5460             $comment = $spacing = '';
5461             $saw_bk = /\\$/;
5462         }
5463         elsif (/$MACRO_PATTERN/o)
5464         {
5465             # Found a variable reference.
5466             $was_rule = 0;
5467             $skipping = defined $contents{$1};
5468             $result_vars .= $comment . $spacing . $_ if ! $skipping;
5469             $comment = $spacing = '';
5470             $saw_bk = /\\$/;
5471         }
5472         else
5473         {
5474             # This isn't an error; it is probably a continued rule.
5475             # In fact, this is what we assume.
5476             $was_rule = 1;
5477             $result_rules .= $comment . $spacing . $_ if ! $skipping;
5478             $comment = $spacing = '';
5479             $saw_bk = /\\$/;
5480         }
5481     }
5483     close (FC_FILE);
5484     return $result_vars . $result_rules . $comment;
5487 # Like file_contents_with_transform, but no transform.
5488 sub file_contents
5490     return &file_contents_with_transform ('', @_);
5493 # Find all variable prefixes that are used for install directories.  A
5494 # prefix `zar' qualifies iff:
5495 # * `zardir' is a variable.
5496 # * `zar_PRIMARY' is a variable.
5497 sub am_primary_prefixes
5499     local ($primary, @prefixes) = @_;
5501     local (%valid, $varname);
5502     grep ($valid{$_} = 0, @prefixes);
5503     $valid{'EXTRA'} = 0;
5504     foreach $varname (keys %contents)
5505     {
5506         if ($varname =~ /^(.*)_$primary$/)
5507         {
5508             if (! defined $valid{$1}
5509                 && ! &variable_defined ($1 . 'dir')
5510                 # Note that a configure variable is always legitimate.
5511                 # It is natural to name such variables after the
5512                 # primary, so we explicitly allow it.
5513                 && ! defined $configure_vars{$varname})
5514             {
5515                 &am_line_error ($varname, "invalid variable \"$varname\"");
5516             }
5517             else
5518             {
5519                 # Ensure all extended prefixes are actually used.
5520                 $valid{$1} = 1;
5521             }
5522         }
5523     }
5525     return %valid;
5528 # Handle `where_HOW' variable magic.  Does all lookups, generates
5529 # install code, and possibly generates code to define the primary
5530 # variable.  The first argument is the name of the .am file to munge,
5531 # the second argument is the primary variable (eg HEADERS), and all
5532 # subsequent arguments are possible installation locations.  Returns
5533 # list of all values of all _HOW targets.
5535 # FIXME: this should be rewritten to be cleaner.  It should be broken
5536 # up into multiple functions.
5538 # Usage is: am_install_var (OPTION..., file, HOW, where...)
5539 sub am_install_var
5541     local (@args) = @_;
5543     local ($do_clean) = 0;
5545     local ($ltxform);
5546     if (defined $configure_vars{'LIBTOOL'})
5547     {
5548         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
5549         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
5550     }
5551     else
5552     {
5553         # Delete '@LIBTOOL ...@'
5554         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
5555     }
5557     local ($cygxform);
5558     if (! $seen_cygwin32)
5559     {
5560         $cygxform = 's/\@EXEEXT\@//g; s/^NOTCYGWIN//; s/^CYGWIN.*$//;';
5561     }
5562     else
5563     {
5564         $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g; s/^CYGWIN//; s/^NOTCYGWIN.*$//;';
5565     }
5567     while (@args)
5568     {
5569         if ($args[0] eq '-clean')
5570         {
5571             $do_clean = 1;
5572         }
5573         elsif ($args[0] !~ /^-/)
5574         {
5575             last;
5576         }
5577         shift (@args);
5578     }
5579     local ($file, $primary, @prefixes) = @args;
5581     local (@used) = ();
5582     local (@result) = ();
5584     # Now that configure substitutions are allowed in where_HOW
5585     # variables, it is an error to actually define the primary.
5586     &am_line_error ($primary, "\`$primary' is an anachronism")
5587         if &variable_defined ($primary);
5590     # Look for misspellings.  It is an error to have a variable ending
5591     # in a "reserved" suffix whose prefix is unknown, eg
5592     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
5593     # variable of the same name (with "dir" appended) exists.  For
5594     # instance, if the variable "zardir" is defined, then
5595     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
5596     # flexibility in those cases which need it.  Perhaps it should be
5597     # disallowed in the Gnits case?  The problem is, sometimes it is
5598     # useful to put things in a subdir of eg pkgdatadir, perhaps even
5599     # for Gnitsoids.
5600     local (%valid) = &am_primary_prefixes ($primary, @prefixes);
5602     # If a primary includes a configure substitution, then the EXTRA_
5603     # form is required.  Otherwise we can't properly do our job.
5604     local ($require_extra);
5605     local ($warned_about_extra) = 0;
5607     local ($clean_file) = $file . '-clean';
5608     local ($one_name);
5609     local ($X);
5610     foreach $X (sort keys %valid)
5611     {
5612         $one_name = $X . '_' . $primary;
5613         if (&variable_defined ($one_name))
5614         {
5615             # Append actual contents of where_PRIMARY variable to
5616             # result.
5617             local ($rcurs);
5618             foreach $rcurs (&variable_value_as_list ($one_name, 'all'))
5619             {
5620                 # Skip configure substitutions.  Possibly bogus.
5621                 if ($rcurs =~ /^\@.*\@$/)
5622                 {
5623                     if ($X eq 'EXTRA')
5624                     {
5625                         if (! $warned_about_extra)
5626                         {
5627                             $warned_about_extra = 1;
5628                             &am_line_error ($one_name,
5629                                             "\`$one_name' contains configure substitution, but shouldn't");
5630                         }
5631                     }
5632                     # Check here to make sure variables defined in
5633                     # configure.in do not imply that EXTRA_PRIMARY
5634                     # must be defined.
5635                     elsif (! defined $configure_vars{$one_name})
5636                     {
5637                         $require_extra = $one_name;
5638                     }
5639                     next;
5640                 }
5641                 push (@result, $rcurs);
5642             }
5644             # "EXTRA" shouldn't be used when generating clean targets,
5645             # @all, or install targets.
5646             next if $X eq 'EXTRA';
5648             if ($do_clean)
5649             {
5650                 $output_rules .=
5651                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
5652                                                    . $cygxform,
5653                                                    $clean_file);
5655                 push (@clean, $X . $primary);
5656                 &push_phony_cleaners ($X . $primary);
5657             }
5659             if ($X eq 'check')
5660             {
5661                 push (@check, '$(' . $one_name . ')');
5662             }
5663             else
5664             {
5665                 push (@used, '$(' . $one_name . ')');
5666             }
5667             if ($X eq 'noinst' || $X eq 'check')
5668             {
5669                 # Objects which don't get installed by default.
5670                 next;
5671             }
5673             $output_rules .=
5674                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
5675                                                . $ltxform . $cygxform,
5676                                                $file);
5678             push (@uninstall, 'uninstall-' . $X . $primary);
5679             push (@phony, 'uninstall-' . $X . $primary);
5680             push (@installdirs, '$(' . $X . 'dir)');
5681             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
5682             {
5683                 push (@install_exec, 'install-' . $X . $primary);
5684                 push (@phony, 'install-' . $X . $primary);
5685             }
5686             else
5687             {
5688                 push (@install_data, 'install-' . $X . $primary);
5689                 push (@phony, 'install-' . $X . $primary);
5690             }
5691         }
5692     }
5694     if (@used)
5695     {
5696         # Define it.
5697         &define_pretty_variable ($primary, '', @used);
5698         $output_vars .= "\n";
5699     }
5701     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
5702     {
5703         &am_line_error ($require_extra,
5704                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
5705     }
5707     # Push here because PRIMARY might be configure time determined.
5708     push (@all, '$(' . $primary . ')')
5709         if @used;
5711     return (@result);
5715 ################################################################
5717 # This variable is local to the "require file" set of functions.
5718 @require_file_paths = ();
5720 # Verify that the file must exist in the current directory.  Usage:
5721 # require_file (isconfigure, line_number, strictness, file) strictness
5722 # is the strictness level at which this file becomes required.  Must
5723 # set require_file_paths before calling this function.
5724 # require_file_paths is set to hold a single directory (the one in
5725 # which the first file was found) before return.
5726 sub require_file_internal
5728     local ($is_configure, $line, $mystrict, @files) = @_;
5729     local ($file, $fullfile);
5730     local ($found_it, $errfile, $errdir);
5731     local ($save_dir);
5733     foreach $file (@files)
5734     {
5735         $found_it = 0;
5736         foreach $dir (@require_file_paths)
5737         {
5738             if ($dir eq '.')
5739             {
5740                 $fullfile = $relative_dir . "/" . $file;
5741                 $errdir = $relative_dir unless $errdir;
5742             }
5743             else
5744             {
5745                 $fullfile = $dir . "/" . $file;
5746                 $errdir = $dir unless $errdir;
5747             }
5749             # Use different name for "error filename".  Otherwise on
5750             # an error the bad file will be reported as eg
5751             # `../../install-sh' when using the default
5752             # config_aux_path.
5753             $errfile = $errdir . '/' . $file;
5755             if (-f $fullfile)
5756             {
5757                 $found_it = 1;
5758                 # FIXME: Once again, special-case `.'.
5759                 &push_dist_common ($file)
5760                     if $dir eq $relative_dir || $dir eq '.';
5761                 $save_dir = $dir;
5762                 last;
5763             }
5764         }
5766         if ($found_it)
5767         {
5768             # Prune the path list.
5769             @require_file_paths = $save_dir;
5770         }
5771         else
5772         {
5773             if ($strictness >= $mystrict)
5774             {
5775                 local ($trailer) = '';
5776                 local ($suppress) = 0;
5778                 # Only install missing files according to our desired
5779                 # strictness level.
5780                 if ($add_missing)
5781                 {
5782                     $suppress = 1;
5784                     # Maybe run libtoolize.
5785                     if ($seen_libtool
5786                         && grep ($_ eq $file, @libtoolize_files)
5787                         && system ('libtoolize', '--automake'))
5788                     {
5789                         $trailer = "; installing";
5790                         $suppress = 0;
5791                         $trailer .= "; cannot run \`libtoolize': $!";
5792                     }
5793                     elsif (-f ($am_dir . '/' . $file))
5794                     {
5795                         # Install the missing file.  Symlink if we
5796                         # can, copy if we must.  Note: delete the file
5797                         # first, in case it is a dangling symlink.
5798                         $trailer = "; installing";
5799                         unlink ($errfile);
5800                         if ($symlink_exists)
5801                         {
5802                             if (! symlink ($am_dir . '/' . $file, $errfile))
5803                             {
5804                                 $suppress = 0;
5805                                 $trailer .= "; error while making link: $!\n";
5806                             }
5807                         }
5808                         elsif (! system ('cp', $am_dir . '/' . $file, $errfile))
5809                         {
5810                             $suppress = 0;
5811                             $trailer .= "\n    error while making link\n";
5812                         }
5813                     }
5814                 }
5816                 local ($save) = $exit_status;
5817                 if ($is_configure)
5818                 {
5819                     # FIXME: allow actual file to be specified.
5820                     &am_conf_line_error
5821                         ('configure.in', $line,
5822                          "required file \"$errfile\" not found$trailer");
5823                 }
5824                 else
5825                 {
5826                     &am_line_error
5827                         ($line,
5828                          "required file \"$errfile\" not found$trailer");
5829                 }
5830                 $exit_status = $save if $suppress;
5831             }
5832         }
5833     }
5836 # Like require_file_with_line, but error messages refer to
5837 # configure.in, not the current Makefile.am.
5838 sub require_file_with_conf_line
5840     @require_file_paths = '.';
5841     &require_file_internal (1, @_);
5844 sub require_file_with_line
5846     @require_file_paths = '.';
5847     &require_file_internal (0, @_);
5850 sub require_file
5852     @require_file_paths = '.';
5853     &require_file_internal (0, '', @_);
5856 # Require a file that is also required by Autoconf.  Looks in
5857 # configuration path, as specified by AC_CONFIG_AUX_DIR.
5858 sub require_config_file
5860     @require_file_paths = @config_aux_path;
5861     &require_file_internal (1, '', @_);
5862     local ($dir) = $require_file_paths[0];
5863     @config_aux_path = @require_file_paths;
5864     if ($dir eq '.')
5865     {
5866         $config_aux_dir = '.';
5867     }
5868     else
5869     {
5870         $config_aux_dir = '$(top_srcdir)/' . $dir;
5871     }
5874 # Assumes that the line number is in Makefile.am.
5875 sub require_conf_file_with_line
5877     @require_file_paths = @config_aux_path;
5878     &require_file_internal (0, @_);
5879     local ($dir) = $require_file_paths[0];
5880     @config_aux_path = @require_file_paths;
5881     if ($dir eq '.')
5882     {
5883         $config_aux_dir = '.';
5884     }
5885     else
5886     {
5887         $config_aux_dir = '$(top_srcdir)/' . $dir;
5888     }
5891 # Assumes that the line number is in Makefile.am.
5892 sub require_conf_file_with_conf_line
5894     @require_file_paths = @config_aux_path;
5895     &require_file_internal (1, @_);
5896     local ($dir) = $require_file_paths[0];
5897     @config_aux_path = @require_file_paths;
5898     if ($dir eq '.')
5899     {
5900         $config_aux_dir = '.';
5901     }
5902     else
5903     {
5904         $config_aux_dir = '$(top_srcdir)/' . $dir;
5905     }
5908 ################################################################
5910 # Push a list of files onto dist_common.
5911 sub push_dist_common
5913     local (@files) = @_;
5914     local ($file);
5916     foreach $file (@files)
5917     {
5918         $dist_common{$file} = 1;
5919     }
5922 # Push a list of clean targets onto phony.
5923 sub push_phony_cleaners
5925     local ($base) = @_;
5926     local ($target);
5927     foreach $target ('mostly', 'dist', '', 'maintainer-')
5928     {
5929         push (@phony, $target . 'clean-' . $base);
5930     }
5933 # Set strictness.
5934 sub set_strictness
5936     $strictness_name = $_[0];
5937     if ($strictness_name eq 'gnu')
5938     {
5939         $strictness = $GNU;
5940     }
5941     elsif ($strictness_name eq 'gnits')
5942     {
5943         $strictness = $GNITS;
5944     }
5945     elsif ($strictness_name eq 'foreign')
5946     {
5947         $strictness = $FOREIGN;
5948     }
5949     else
5950     {
5951         die "automake: level \`$strictness_name' not recognized\n";
5952     }
5956 ################################################################
5958 # Return directory name of file.
5959 sub dirname
5961     local ($file) = @_;
5962     local ($sub);
5964     ($sub = $file) =~ s,/+[^/]+$,,g;
5965     $sub = '.' if $sub eq $file;
5966     return $sub;
5969 # Return file name of a file.
5970 sub basename
5972     local ($file) = @_;
5973     local ($sub);
5975     ($sub = $file) =~s,^.*/+,,g;
5976     return $sub;
5979 # Touch a file.
5980 sub touch
5982     local ($file) = @_;
5984     open (TOUCH, ">> $file");
5985     close (TOUCH);
5988 # Glob something.  Do this to avoid indentation screwups everywhere we
5989 # want to glob.  Gross!
5990 sub my_glob
5992     local ($pat) = @_;
5993     return <${pat}>;
5996 ################################################################
5998 # Print an error message and set exit status.
5999 sub am_error
6001     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
6002     $exit_status = 1;
6005 sub am_line_error
6007     local ($symbol, @args) = @_;
6009     if ($symbol && "$symbol" ne '-1')
6010     {
6011         # If SYMBOL not already a line number, look it up in Makefile.am.
6012         if ($symbol =~ /^\d+$/)
6013         {
6014             $symbol .= ': ';
6015         }
6016         elsif (defined $content_lines{$symbol})
6017         {
6018             $symbol = $content_lines{$symbol} . ': ';
6019         }
6020         else
6021         {
6022             # A single space, to provide nice separation.
6023             $symbol = ' ';
6024         }
6025         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
6026         $exit_status = 1;
6027     }
6028     else
6029     {
6030         &am_error (@args);
6031     }
6034 # Like am_error, but while scanning configure.in.
6035 sub am_conf_error
6037     # FIXME: can run in subdirs.
6038     warn "automake: configure.in: ", join (' ', @_), "\n";
6039     $exit_status = 1;
6042 # Error message with line number referring to configure.in.
6043 sub am_conf_line_error
6045     local ($file, $line, @args) = @_;
6047     if ($line)
6048     {
6049         warn "$file: $line: ", join (' ', @args), "\n";
6050         $exit_status = 1;
6051     }
6052     else
6053     {
6054         &am_conf_error (@args);
6055     }
6058 # Tell user where our aclocal.m4 is, but only once.
6059 sub keyed_aclocal_warning
6061     local ($key) = @_;
6062     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
6065 # Print usage information.
6066 sub usage
6068     print "Usage: automake [OPTION] ... [Makefile]...\n\n";
6069     print "Generate Makefile.in for autoconf from Makefile.am\n";
6070     print $USAGE;
6071     print "\nFiles which are automatically distributed, if found:\n";
6072     $~ = "USAGE_FORMAT";
6073     local (@lcomm) = sort ((@common_files, @common_sometimes));
6074     local ($one, $two, $three, $four);
6075     while (@lcomm > 0)
6076     {
6077         $one = shift @lcomm;
6078         $two = @lcomm ? shift @lcomm : '';
6079         $three = @lcomm ? shift @lcomm : '';
6080         $four = @lcomm ? shift @lcomm : '';
6081         write;
6082     }
6084     print "\nReport bugs to <automake-bugs\@gnu.ai.mit.edu>.\n";
6086     exit 0;
6089 format USAGE_FORMAT =
6090   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
6091   $one,               $two,               $three,             $four