new files from elsewhere
[automake.git] / automake.in
blob07f79493539b9dcf7ca5ddaa2f5e9cdf99545b85
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 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]+)?";
47 # Some regular expressions.  One reason to put them here is that it
48 # makes indentation work better in Emacs.
49 $AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
50 $AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^)]+)\\)";
51 $AM_PACKAGE_VERSION_PATTERN = "^\\s*\\[?([^]\\s]+)\\]?\\s*\$";
52 # Note that there is no AC_PATH_TOOL.  But we don't really care.
53 $AC_CHECK_PATTERN = "AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\\(\\[?(\\w+)";
54 # Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
55 # then too bad.
56 $AC_SUBST_PATTERN = "AC_SUBST\\(\\[?(\\w+)";
58 # Constants to define the "strictness" level.
59 $FOREIGN = 0;
60 $GNU = 1;
61 $GNITS = 2;
65 # Variables global to entire run.
67 # TRUE if we should always generate Makefile.in.
68 $force_generation = 1;
70 # Strictness level as set on command line.
71 $default_strictness = $GNU;
73 # Name of strictness level, as set on command line.
74 $default_strictness_name = 'gnu';
76 # This is TRUE if GNU make specific automatic dependency generation
77 # code should be included in generated Makefile.in.
78 $cmdline_use_dependencies = 1;
80 # TRUE if in verbose mode.
81 $verbose = 0;
83 # This holds our (eventual) exit status.  We don't actually exit until
84 # we have processed all input files.
85 $exit_status = 0;
87 # From the Perl manual.
88 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
90 # TRUE if missing standard files should be installed.
91 $add_missing = 0;
93 # Files found by scanning configure.in for LIBOBJS.
94 %libsources = ();
96 # True if AM_C_PROTOTYPES appears in configure.in.
97 $am_c_prototypes = 0;
99 # Names used in AC_CONFIG_HEADER call.  $config_name is the actual
100 # (first) argument.  $config_header is the '.in' file.  Ordinarily the
101 # second is derived from the first, but they can be different if the
102 # weird "NAME:FILE" syntax is used.
103 $config_name = '';
104 $config_header = '';
105 # Line number at which AC_CONFIG_HEADER appears in configure.in.
106 $config_header_line = 0;
108 # Directory where output files go.  Actually, output files are
109 # relative to this directory.
110 $output_directory = '.';
112 # Relative location of top build directory.
113 $top_builddir = '';
115 # Absolute location of top build directory.
116 $build_directory = '';
118 # Name of srcdir as given in build directory's Makefile.  For
119 # dependencies only.
120 $srcdir_name = '';
122 # List of Makefile.am's to process, and their corresponding outputs.
123 @input_files = ();
124 %output_files = ();
126 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
127 @other_input_files = ();
128 # Line number at which AC_OUTPUT seen.
129 $ac_output_line = 0;
131 # List of directories to search for configure-required files.  This
132 # can be set by AC_CONFIG_AUX_DIR.
133 @config_aux_path = ('.', '..', '../..');
134 $config_aux_dir = '';
136 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
137 $seen_make_set = 0;
139 # Whether AM_GNU_GETTEXT has been seen in configure.in.
140 $seen_gettext = 0;
141 # Line number at which AM_GNU_GETTEXT seen.
142 $ac_gettext_line = 0;
144 # Whether ALL_LINGUAS has been seen.
145 $seen_linguas = '';
146 # The actual text.
147 $all_linguas = '';
148 # Line number at which it appears.
149 $all_linguas_line = 0;
151 # 1 if AC_PROG_INSTALL seen, 2 if AM_PROG_INSTALL seen.
152 $seen_prog_install = 0;
154 # 1 if any scripts installed, 0 otherwise.
155 $scripts_installed = 0;
157 # Whether AC_PATH_XTRA has been seen in configure.in.
158 $seen_path_xtra = 0;
160 # TRUE if AC_DECL_YYTEXT was seen.
161 $seen_decl_yytext = 0;
163 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
164 # AC_CHECK_TOOL also sets this.
165 $seen_canonical = 0;
167 # TRUE if we've seen AC_ARG_PROGRAM.
168 $seen_arg_prog = 0;
170 # TRUE if we've seen AM_PROG_LIBTOOL.
171 $seen_libtool = 0;
172 $libtool_line = 0;
174 # Files installed by libtoolize.
175 @libtoolize_files = ('ltconfig', 'ltmain.sh', 'config.guess', 'config.sub');
177 # TRUE if we've seen AM_MAINTAINER_MODE.
178 $seen_maint_mode = 0;
180 # TRUE if we've seen PACKAGE and VERSION.
181 $seen_package = 0;
182 $seen_version = 0;
184 # Actual version we've seen.
185 $package_version = '';
187 # Line number where we saw version definition.
188 $package_version_line = 0;
190 # TRUE if we've seen AM_PATH_LISPDIR.
191 $seen_lispdir = 0;
193 # TRUE if we've seen AM_CYGWIN32.
194 $seen_cygwin32 = 0;
196 # Hash table of discovered configure substitutions.  Keys are names,
197 # values are meaningless.
198 %configure_vars = ();
200 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
201 # handled in a funny way: if seen in the top-level Makefile.am, it is
202 # used for every directory which does not specify a different value.
203 # The rationale here is that some directories (eg gettext) might be
204 # distributions of other packages, and thus require their own charset
205 # info.  However, the DIST_CHARSET must be the same for the entire
206 # package; it can only be set at top-level.
207 # FIXME: this yields bugs when rebuilding.  What to do?  Always
208 # read (and sometimes discard) top-level Makefile.am?
209 $maint_charset = '';
210 $dist_charset = 'utf8';         # recode doesn't support this yet.
212 # Name of input file ("Makefile.in") and output file ("Makefile.am").
213 # These have no directory components.
214 $am_file_name = '';
215 $in_file_name = '';
217 # TRUE if --cygnus seen.
218 $cygnus_mode = 0;
220 # Keys of this hash are names of dependency files to ignore.
221 %omit_dependencies = ();
223 # Map from obsolete macros to hints for new macros.
224 # FIXME complete the list so that there are no `0' hints.
225 %obsolete_macros =
226     (
227      'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
228      'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
229      'AC_FEATURE_EXIT', 0,
230      'AC_SYSTEM_HEADER', 0,
232      # Note that we do not handle this one, because it is still run
233      # from AM_CONFIG_HEADER.  So we deal with it specially in
234      # scan_configure.
235      # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",
237      'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
238      'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
239      'fp_PROG_INSTALL', "use \`AM_PROG_INSTALL'",
240      'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
241      'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
242      'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
243      'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
244      'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
245      'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",
247      # Now part of autoconf proper, under a different name.
248      'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
249      'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
250      'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",
252 # These aren't quite obsolete.
253 #      'md_PATH_PROG',
254      );
256 # Regexp to match the above macros.
257 $obsolete_rx = '(' . join ('|', keys %obsolete_macros) . ')';
261 &initialize_global_constants;
263 # Parse command line.
264 &parse_arguments (@ARGV);
266 # Do configure.in scan only once.
267 &scan_configure;
269 die "automake: no \`Makefile.am' found or specified\n"
270     if ! @input_files;
272 # Now do all the work on each file.
273 foreach $am_file (@input_files)
275     if (! -f ($am_file . '.am'))
276     {
277         &am_error ("\`" . $am_file . ".am' does not exist");
278     }
279     else
280     {
281         &generate_makefile ($output_files{$am_file}, $am_file);
282     }
285 if ($seen_prog_install <= $scripts_installed)
287     &am_conf_error (($scripts_installed ? 'AM_PROG_INSTALL' : 'AC_PROG_INSTALL')
288                     . " must be used in configure.in");
289     &keyed_aclocal_warning ('AM_PROG_INSTALL')
290         if $scripts_installed;
293 exit $exit_status;
296 ################################################################
298 # Parse command line.
299 sub parse_arguments
301     local (@arglist) = @_;
303     # Start off as gnu.
304     &set_strictness ('gnu');
306     while (@arglist)
307     {
308         if ($arglist[0] eq "--version")
309         {
310             print "automake (GNU $PACKAGE) $VERSION\n\n";
311             print "Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.\n";
312             print "This is free software; see the source for copying conditions.  There is NO\n";
313             print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
314             print "Written by Tom Tromey <tromey\@cygnus.com>\n";
316             exit 0;
317         }
318         elsif ($arglist[0] eq "--help")
319         {
320             &usage;
321         }
322         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
323         {
324             $am_dir = $1;
325         }
326         elsif ($arglist[0] eq '--amdir')
327         {
328             &require_argument (@arglist);
329             shift (@arglist);
330             $am_dir = $arglist[0];
331         }
332         elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
333         {
334             # Must end in /.
335             $build_directory = $1 . '/';
336         }
337         elsif ($arglist[0] eq '--build-dir')
338         {
339             &require_argument (@arglist);
340             shift (@arglist);
341             # Must end in /.
342             $build_directory = $arglist[0] . '/';
343         }
344         elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
345         {
346             $srcdir_name = $1;
347         }
348         elsif ($arglist[0] eq '--srcdir-name')
349         {
350             &require_argument (@arglist);
351             shift (@arglist);
352             $srcdir_name = $arglist[0];
353         }
354         elsif ($arglist[0] eq '--gnu')
355         {
356             &set_strictness ('gnu');
357         }
358         elsif ($arglist[0] eq '--gnits')
359         {
360             &set_strictness ('gnits');
361         }
362         elsif ($arglist[0] eq '--cygnus')
363         {
364             $cygnus_mode = 1;
365         }
366         elsif ($arglist[0] eq '--foreign')
367         {
368             &set_strictness ('foreign');
369         }
370         elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
371         {
372             $cmdline_use_dependencies = 0;
373         }
374         elsif ($arglist[0] eq '--no-force')
375         {
376             $force_generation = 0;
377         }
378         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
379         {
380             # Set output directory.
381             $output_directory = $1;
382         }
383         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
384         {
385             &require_argument (@arglist);
386             shift (@arglist);
387             $output_directory = $arglist[0];
388         }
389         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
390         {
391             $add_missing = 1;
392         }
393         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
394         {
395             $verbose = 1;
396         }
397         elsif ($arglist[0] eq '--')
398         {
399             # Stop option processing.
400             shift (@arglist);
401             push (@input_files, @arglist);
402             last;
403         }
404         elsif ($arglist[0] =~ /^-/)
405         {
406             die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
407         }
408         else
409         {
410             # Handle $local:$input syntax.  Note that we only examine
411             # the first ":" file to see if it is automake input; the
412             # rest are just taken verbatim.  We still keep all the
413             # files around for dependency checking, however.
414             local ($local, $input, @rest) = split (/:/, $arglist[0]);
415             if (! $input)
416             {
417                 $input = $local;
418             }
419             else
420             {
421                 # Strip .in; later on .am is tacked on.  That is how
422                 # the automake input file is found.  Maybe not the
423                 # best way, but it is easy to explain.  FIXME: should
424                 # be error if .in is missing.
425                 $input =~ s/\.in$//;
426             }
427             push (@input_files, $input);
428             $output_files{$input} = join (':', ($local, @rest));
429         }
431         shift (@arglist);
432     }
434     # Take global strictness from whatever we currently have set.
435     $default_strictness = $strictness;
436     $default_strictness_name = $strictness_name;
439 # Ensure argument exists, or die.
440 sub require_argument
442     local ($arg, @arglist) = @_;
443     die "automake: no argument given for option \`$arg'\n"
444         if ! @arglist;
447 ################################################################
449 # Generate a Makefile.in given the name of the corresponding Makefile and
450 # the name of the file output by config.status.
451 sub generate_makefile
453     local ($output, $makefile) = @_;
455     ($am_file_name = $makefile) =~ s/^.*\///;
456     $in_file_name = $am_file_name . '.in';
457     $am_file_name .= '.am';
459     # $OUTPUT is encoded.  If it contains a ":" then the first element
460     # is the real output file, and all remaining elements are input
461     # files.  We don't scan or otherwise deal with these input file,
462     # other than to mark them as dependencies.  See scan_configure for
463     # details.
464     local (@secondary_inputs);
465     ($output, @secondary_inputs) = split (/:/, $output);
467     &initialize_per_input;
468     $relative_dir = &dirname ($output);
469     $am_relative_dir = &dirname ($makefile);
471     # At the toplevel directory, we might need config.guess, config.sub
472     # or libtool scripts (ltconfig and ltmain.sh).
473     if ($relative_dir eq '.')
474     {
475         # libtool requires some files.
476         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
477                                            @libtoolize_files)
478             if $seen_libtool;
480         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
481         # config.sub.
482         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
483             if $seen_canonical;
484     }
486     # We still need Makefile.in here, because sometimes the `dist'
487     # target doesn't re-run automake.
488     if ($am_relative_dir eq $relative_dir)
489     {
490         # Only distribute the files if they are in the same subdir as
491         # the generated makefile.
492         &push_dist_common ($in_file_name, $am_file_name);
493     }
494     push (@sources, '$(SOURCES)')
495         if &variable_defined ('SOURCES');
496     push (@objects, '$(OBJECTS)')
497         if &variable_defined ('OBJECTS');
499     # This is always the default target.  This gives us freedom to do
500     # things in whatever order is convenient.  Note that we set up
501     # $output_header here so that we can insert some text just after
502     # the "default" target, but before any other targets.  In
503     # particular we want to support the .SUFFIX hack here; this is
504     # documented elsewhere.
505     $output_header = "default: all\n\n";
506     push (@phony, 'default');
508     &read_am_file ($makefile . '.am');
509     if (&handle_options)
510     {
511         # Fatal error.  Just return, so we can continue with next file.
512         return;
513     }
515     # Check first, because we might modify some state.
516     &check_cygnus;
517     &check_gnu_standards;
518     &check_gnits_standards;
520     &handle_configure ($output, $makefile, @secondary_inputs);
521     &handle_gettext;
522     &handle_libraries;
523     &handle_ltlibraries;
524     &handle_programs;
525     &handle_scripts;
527     &handle_built_sources;
529     # This must be run after all the sources are scanned.
530     &handle_yacc_lex_cxx;
532     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
533     # on this (but currently does).
534     $contents{'SOURCES'} = join (' ', @sources);
535     $contents{'OBJECTS'} = join (' ', @objects);
537     &handle_texinfo;
538     &handle_emacs_lisp;
539     &handle_man_pages;
540     &handle_data;
541     &handle_headers;
542     &handle_subdirs;
543     &handle_tags;
544     &handle_dist;
545     &handle_dependencies;
546     &handle_tests;
547     &handle_footer;
548     &handle_merge_targets;
549     &handle_installdirs;
550     &handle_clean;
551     &handle_phony;
553     &check_typos;
555     if (! -d ($output_directory . '/' . $am_relative_dir))
556     {
557         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
558     }
560     local ($out_file) = $output_directory . '/' . $makefile . ".in";
561     if (! $force_generation && -e $out_file)
562     {
563         local ($am_time) = (stat ($makefile . '.am'))[9];
564         local ($in_time) = (stat ($out_file))[9];
565         # FIXME: how to do unsigned comparison?
566         if ($am_time < $in_time)
567         {
568             # No need to update.
569             return;
570         }
571     }
573     if (! open (GM_FILE, "> " . $out_file))
574     {
575         warn "automake: ${am_file}.in: cannot open: $!\n";
576         $exit_status = 1;
577         return;
578     }
579     print "automake: creating ", $makefile, ".in\n" if $verbose;
581     print GM_FILE $output_vars;
582     print GM_FILE $output_header;
583     print GM_FILE $output_rules;
584     print GM_FILE $output_trailer;
586     close (GM_FILE);
589 ################################################################
591 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
592 sub handle_options
594     return 0 if ! &variable_defined ('AUTOMAKE_OPTIONS');
596     foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS'))
597     {
598         $options{$_} = 1;
599         if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
600         {
601             &set_strictness ($_);
602         }
603         elsif (/ansi2knr/)
604         {
605             # An option like "../lib/ansi2knr" is allowed.  With no
606             # path prefix, we assume the required programs are in this
607             # directory.  We save the actual option for later.
608             $options{'ansi2knr'} = $_;
609         }
610         elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
611                || $_ eq 'dist-shar' || $_ eq 'dist-zip'
612                || $_ eq 'dist-tarZ' || $_ eq 'dejagnu'
613                || $_ eq 'no-texinfo.tex')
614         {
615             # Explicitly recognize these.
616         }
617         elsif ($_ eq 'no-dependencies')
618         {
619             $use_dependencies = 0;
620         }
621         elsif (/([0-9]+)\.([0-9]+)/)
622         {
623             # Got a version number.  Note that alpha releases count as
624             # the next higher release.  Note also that we assume there
625             # will be a maximum of 100 minor releases for any given
626             # major release.
627             local ($rmajor, $rminor) = ($1, $2);
628             if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
629             {
630                 print STDERR
631                     "automake: programming error: version is incorrect\n";
632                 exit 1;
633             }
634             local ($tmajor, $tminor) = ($1, $2);
635             # Handle alpha versions.
636             ++$tminor if defined $3;
638             if ($rmajor > $tmajor || ($rmajor == $tmajor && $rminor > $tminor))
639             {
640                 &am_line_error ('AUTOMAKE_OPTIONS',
641                                 "require version $_, only have $VERSION");
642                 return 1;
643             }
644         }
645         else
646         {
647             &am_line_error ('AUTOMAKE_OPTIONS',
648                             'option ', $_, 'not recognized');
649         }
650     }
652     return 0;
655 # Return object extension.  Just once, put some code into the output.
656 # Argument is the name of the output file
657 sub get_object_extension
659     local ($out) = @_;
661     # Always set this.
662     $dir_holds_sources = 1;
664     # Maybe require libtool library object files.
665     local ($l, $extension) = ('', 'o');
666     $l = 'l' if ($out =~ /^lib.*\.la$/);
668     if (! $included_generic_compile)
669     {
670         # Boilerplate.
671         local ($xform) = '';
672         if (&variable_defined ('CONFIG_HEADER'))
673         {
674             ($xform = &dirname ($contents{'CONFIG_HEADER'}))
675                 =~ s/(\W)/\\$1/g;
676             $xform = '-I' . $xform;
677         }
678         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go;';
679         $output_vars .= &file_contents_with_transform ($xform,
680                                                        'comp-vars');
681         $output_rules .= &file_contents ('compile');
682         &push_phony_cleaners ('compile');
684         # If using X, include some extra variable definitions.  NOTE
685         # we don't want to force these into CFLAGS or anything,
686         # because not all programs will necessarily use X.
687         if ($seen_path_xtra)
688         {
689             local ($var);
690             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
691             {
692                 &define_configure_variable ($var);
693             }
694         }
696         push (@suffixes, '.c', '.o');
697         push (@clean, 'compile');
699         $included_generic_compile = 1;
700     }
702     if ($seen_libtool && ! $included_libtool_compile)
703     {
704         # Output the libtool compilation rules.
705         $output_rules .= &file_contents ('libtool');
706         &push_phony_cleaners ('libtool');
708         push (@suffixes, '.lo');
709         push (@clean, 'libtool');
711         $included_libtool_compile = 1;
712     }
714     # Check for automatic de-ANSI-fication.
715     if (defined $options{'ansi2knr'})
716     {
717         $extension = '$o';
718         if (! $included_knr_compile)
719         {
720             if (! $am_c_prototypes)
721             {
722                 &am_line_error ('AUTOMAKE_OPTIONS',
723                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
724                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
725                 # Only give this error once.
726                 $am_c_prototypes = 1;
727             }
729             push (@suffixes, '._c', '._o');
730             push (@suffixes, '.l_o') if $seen_libtool;
732             # Only require ansi2knr files if they should appear in
733             # this directory.
734             if ($options{'ansi2knr'} eq 'ansi2knr')
735             {
736                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
737                                          'ansi2knr.c', 'ansi2knr.1');
738                 $output_rules .= &file_contents ('kr-extra');
739                 push (@clean, 'krextra');
740                 &push_phony_cleaners ('krextra');
741             }
743             &define_variable ('o', "\@U\@o");
745             # Make sure ansi2knr can be found: if no path specified,
746             # specify "./".
747             local ($apath) = $options{'ansi2knr'};
748             if ($apath =~ /\//)
749             {
750                 # Found in another directory.
751                 &define_variable ("ANSI2KNR", $apath);
752             }
753             else
754             {
755                 # Substitution from AM_C_PROTOTYPES.  This makes it be
756                 # built only when necessary.
757                 &define_configure_variable ('ANSI2KNR');
758                 # ansi2knr needs to be built before subdirs, so unshift it.
759                 unshift (@all, '$(ANSI2KNR)');
760             }
762             $output_rules .= &file_contents ('compile-kr');
763             $output_rules .= &file_contents ('clean-kr');
765             push (@clean, 'kr');
766             &push_phony_cleaners ('kr');
768             $included_knr_compile = 1;
769         }
770     }
772     return '.' . $l . $extension;
775 # Handle yacc and lex.
776 sub handle_yacc_lex_cxx
778     #
779     # First do yacc and lex.
780     #
782     local ($yacc_count) = scalar (keys %yacc_sources);
783     local ($lex_count) = scalar (keys %lex_sources);
785     if ($yacc_count)
786     {
787         local (%seen_suffix) = ();
788         foreach (keys %yacc_sources)
789         {
790             /(\..*)$/;
791             &output_yacc_build_rule ($1, $yacc_count > 1)
792                 if (! defined $seen_suffix{$1});
793             $seen_suffix{$1} = 1;
794         }
796         if (! defined $configure_vars{'YACC'})
797         {
798             &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
799         }
800     }
801     if ($lex_count)
802     {
803         local (%seen_suffix) = ();
804         foreach (keys %lex_sources)
805         {
806             /(\..*)$/;
807             &output_lex_build_rule ($1, $lex_count > 1)
808                 if (! defined $seen_suffix{$1});
809             $seen_suffix{$1} = 1;
810         }
812         if (! defined $configure_vars{'LEX'})
813         {
814             &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
815         }
816         if (! $seen_decl_yytext)
817         {
818             &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
819         }
820     }
822     if ($yacc_count > 1 || $lex_count > 1)
823     {
824         # If there is more than one distinct yacc (resp lex) source
825         # file in a given directory, then the `interlock' program is
826         # required to allow parallel builds to work correctly.  FIXME:
827         # for now, no line number.
828         &require_config_file ($FOREIGN, 'interlock', 'ylwrap');
829         if ($config_aux_dir ne '.' && $config_aux_dir ne '')
830         {
831                 &define_variable ('INTERLOCK', $config_aux_dir . "/interlock");
832                 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
833         }
834         else
835         {
836                 &define_variable ('INTERLOCK', '$(srcdir)/interlock');
837                 &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
838         }
839     }
841     #
842     # Handle libtool.
843     #
844     local ($ltcompile, $ltlink) = ('', '');
845     if ($seen_libtool)
846     {
847         &define_configure_variable ("LIBTOOL");
848         $ltcompile = '$(LIBTOOL) --mode=compile ';
849         $ltlink = '$(LIBTOOL) --mode=link ';
850     }
852     #
853     # Now handle C++.
854     #
855     local (@cxx_list) = keys %cxx_extensions;
856     local ($cxx_count) = scalar @cxx_list;
857     if ($cxx_count)
858     {
859         push (@suffixes, @cxx_list);
861         &define_configure_variable ("CXXFLAGS");
862         &define_variable ('CXXCOMPILE', '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
863         &define_variable ('LTCXXCOMPILE',
864                           $ltcompile . '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)')
865             if ($seen_libtool);
867         &define_variable ('CXXLINK', $ltlink . '$(CXX) $(LDFLAGS) -o $@');
869         local ($ext);
870         foreach $ext (@cxx_list)
871         {
872             $output_rules .= ("$ext.o:\n"
873                               . "\t\$(CXXCOMPILE) -c \$<\n");
874             $output_rules .= ("$ext.lo:\n"
875                               . "\t\$(LTCXXCOMPILE) -c \$<\n")
876                 if ($seen_libtool);
877         }
879         if (! defined $configure_vars{'CXX'})
880         {
881             &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
882         }
883     }
885     #
886     # Handle some ansi2knr cleanup.
887     #
888     if (defined $options{'ansi2knr'} && keys %de_ansi_objects)
889     {
890         # Make all ._o files depend on ansi2knr.  Use a sneaky little
891         # hack to make it print nicely.
892         &pretty_print_rule ('', '', (sort keys %de_ansi_objects,
893                                      ':', '$(ANSI2KNR)'));
894     }
896     #
897     # Last, handle some C cleanup.
898     #
899     if ($seen_c_source)
900     {
901         &define_configure_variable ('CFLAGS');
902         &define_variable ('COMPILE',
903                           '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)');
904         &define_variable ('LTCOMPILE',
905                           $ltcompile .
906                           '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)')
907             if ($seen_libtool);
908         &define_variable ('LINK', $ltlink . '$(CC) $(LDFLAGS) -o $@');
910         if (! defined $configure_vars{'CC'})
911         {
912             &am_line_error ($seen_c_source,
913                             "C source seen but \`CC' not defined in \`configure.in'");
914         }
915     }
919 # Output a rule to build from a YACC source.  The output from YACC is
920 # compiled with C or C++, depending on the extension of the YACC file.
921 sub output_yacc_build_rule
923     local ($yacc_suffix, $use_interlock) = @_;
924     local ($c_suffix);
926     ($c_suffix = $yacc_suffix) =~ tr/y/c/;
927     push (@suffixes, $yacc_suffix);
928     $output_rules .= "$yacc_suffix$c_suffix:\n\t";
930     if ($use_interlock)
931     {
932         $output_rules .= '$(SHELL) $(INTERLOCK) =yacclockdir $(YLWRAP)'
933             . ' "$(YACC)" y.tab.c $*' . $c_suffix 
934             . ' y.tab.h $*.h -- $(YFLAGS) $<';
935     }
936     else
937     {
938         $output_rules .= ('$(YACC) $(YFLAGS) $< && mv y.tab.c $@' . "\n"
939                           . "\tif test -f y.tab.h; then \\\n"
940                           . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
941                           . "\telse :; fi");
942     }
943     $output_rules .= "\n";
946 sub output_lex_build_rule
948     local ($lex_suffix, $use_interlock) = @_;
949     local ($c_suffix);
951     ($c_suffix = $lex_suffix) =~ tr/l/c/;
952     push (@suffixes, $lex_suffix);
953     &define_configure_variable ('LEX_OUTPUT_ROOT');
954     &define_configure_variable ('LEXLIB');
955     $output_rules .= "$lex_suffix$c_suffix:\n\t";
956     
957     if ($use_interlock)
958     { 
959         # is the $@ correct here?  If so, why not use it in the
960         # interlock build rule for yacc above?
961         $output_rules .= '$(SHELL) $(INTERLOCK) =lexlockdir $(YLWRAP)'
962             . ' "$(LEX)" $(LEX_OUTPUT_ROOT).c $@ -- $(LFLAGS) $<';
963     }
964     else
965     {
966         $output_rules .= '$(LEX) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
967     }
968     $output_rules .= "\n";
972 # Check to make sure a source defined in LIBOBJS is not explicitly
973 # mentioned.  This is a separate function (as opposed to being inlined
974 # in handle_source_transform) because it isn't always appropriate to
975 # do this check.
976 sub check_libobjs_sources
978     local ($one_file, $unxformed) = @_;
980     local ($prefix, $file, @files);
981     foreach $prefix ('', 'EXTRA_')
982     {
983         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
984         {
985             @files = &variable_value_as_list ($prefix
986                                               . $one_file . '_SOURCES');
987         }
988         elsif ($prefix eq '')
989         {
990             @files = ($unxformed . '.c');
991         }
992         else
993         {
994             next;
995         }
997         foreach $file (@files)
998         {
999             if (defined $libsources{$file})
1000             {
1001                 &am_line_error ($prefix . $one_file . '_SOURCES',
1002                                 "automatically discovered file \`$file' should not be explicitly mentioned");
1003             }
1004         }
1005     }
1008 # Does much of the actual work for handle_source_transform.
1009 # Arguments are:
1010 #   list of source files to transform
1011 # Result is a list
1012 #   first element is name of linker to use (empty string for default linker)
1013 #   remaining elements are names of `.o's
1014 sub handle_single_transform_list
1016     local (@files) = @_;
1017     local ($linker) = '';
1018     local (@result) = ();
1019     local ($nonansi_obj) = $obj;
1020     $nonansi_obj =~ s/_//g;
1021     if (length (@files))
1022     {
1023         # Turn sources into objects.
1024         foreach (@files)
1025         {
1026             # Skip header files, including C++-ish ones.  The list
1027             # of C++ header extensions comes from Emacs 19.32
1028             # etags.
1029             next if /\.[hH]$/;
1030             next if /\.hxx$/;
1031             next if /\.h\+\+$/;
1032             next if /\.hh$/;
1033             next if /\.hpp$/;
1034             # Skip things that look like configure substitutions.
1035             next if /^\@.*\@$/;
1037             # Include appropriate file for lex or yacc source in
1038             # distribution.  If the extension is the regular '.y' or
1039             # '.l', we assume C compilation, and the generated file
1040             # has exension .c.  Otherwise, we compile with C++, and
1041             # make the following association: (yy -> cc, y++ -> c++, 
1042             # yxx -> cxx), similarly for .ll, etc.
1043             if (/^(.*)\.(y|yy|y\+\+|yxx)$/)
1044             {
1045                 # Yacc source.
1046                 local ($ext) = $2;
1047                 $ext =~ tr/y/c/;
1048                 &push_dist_common ("$1.$ext");
1049                 $yacc_sources{$_} = 1;
1050             }
1051             elsif (/^(.*)\.(l|ll|l\+\+|lxx)$/)
1052             {
1053                 # Lex source.
1054                 local ($ext) = $2;
1055                 $ext =~ tr/l/c/;
1056                 &push_dist_common ("$1.$ext");
1057                 $lex_sources{$_} = 1;
1058             }
1060             # Transform source files into .o files.  List of C++
1061             # extensions comes from Emacs 19.34 etags.
1062             if (s/\.(c\+\+|cc|cpp|cxx|C)$/$nonansi_obj/)
1063             {
1064                 $cxx_extensions{'.' . $1} = 1;
1065                 $linker = 'CXXLINK';
1066             }
1067             elsif (s/\.(yy|y\+\+|yxx|ll|l\+\+|lxx)$/$nonansi_obj/)
1068             {
1069                 # Compiling lex or yacc with C++
1070                 local ($ext) = $1;
1071                 $ext =~ tr/ly/cc/;
1072                 $cxx_extensions{".$ext"} = 1;
1073                 $linker = 'CXXLINK';
1074             }
1075             elsif (s/\.([Ff]\\|f90\\|for)$/$nonansi_obj/)
1076             {
1077                 # FORTRAN support.  FIXME: not finished.
1078             }
1079             elsif (s/\.[sS]$/$nonansi_obj/)
1080             {
1081                 # .s is assembly.  Just rewrite it.  FIXME: not finished.
1082             }
1083             elsif (s/\.[cly]$/._o/)
1084             {
1085                 # .c is C.  .l is lex.  .y is yacc.
1087                 # Note: first we rewrite (eg) foo.c to foo._o and push
1088                 # the file onto the list of objects that require
1089                 # ansi2knr.  Then we rewrite ._o to $obj; $obj can be
1090                 # simply `.o' if deansification is not really
1091                 # required.
1092                 $de_ansi_objects{$_} = 1;
1093                 s/\._o$/$obj/;
1094                 $seen_c_source = -1 unless $seen_c_source;
1095             }
1096             else
1097             {
1098                 # No error message here.  Used to have one, but it was
1099                 # very unpopular.
1100                 next;
1101             }
1103             push (@result, $_);
1105             # Transform .o or $o file into .P file (for automatic
1106             # dependency code).
1107             s/$objpat$/.P/g;
1108             $dep_files{'.deps/' . $_} = 1;
1109         }
1110     }
1112     return ($linker, @result);
1115 # Handle SOURCE->OBJECT transform for one program or library.
1116 # Arguments are:
1117 #   canonical (transformed) name of object to build
1118 #   actual name of object to build
1119 #   object extension (ie either `.o' or `$o'.
1120 # Return result is name of linker variable that must be used.
1121 # Empty return means just use `LINK'.
1122 sub handle_source_transform
1124     # one_file is canonical name.  unxformed is given name.  obj is
1125     # object extension.
1126     local ($one_file, $unxformed, $obj) = @_;
1127     local ($objpat) = $obj;
1128     $objpat =~ s/(\W)/\\$1/g;
1129     # Handle explicit `.o' as well as whatever we're passed.
1130     $objpat = '(' . $objpat . "|\\.o)";
1132     local ($linker) = '';
1134     if (&variable_defined ($one_file . "_OBJECTS"))
1135     {
1136         &am_line_error ($one_file . '_OBJECTS',
1137                         $one_file . '_OBJECTS', 'should not be defined');
1138         # No point in continuing.
1139         return;
1140     }
1142     local (@files, @result, $prefix, $temp);
1143     foreach $prefix ('', 'EXTRA_')
1144     {
1145         @files = ();
1146         if (&variable_defined ($prefix . $one_file . "_SOURCES"))
1147         {
1148             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1149             push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
1150                 unless $prefix eq 'EXTRA_';
1151             @files = &variable_value_as_list ($prefix
1152                                               . $one_file . "_SOURCES");
1153         }
1154         elsif ($prefix eq '')
1155         {
1156             &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1157             push (@sources, $unxformed . '.c');
1158             push (@objects, $unxformed . $obj);
1159             push (@files, $unxformed . '.c');
1160         }
1162         ($temp, @result) = &handle_single_transform_list (@files);
1163         $linker = $temp if $linker eq '';
1164         &define_pretty_variable ($one_file . "_OBJECTS", @result)
1165             unless $prefix eq 'EXTRA_';
1166     }
1168     if (&variable_defined ('CONFIG_HEADER'))
1169     {
1170         $output_rules .= ('$(' . $one_file . "_OBJECTS): "
1171                           . $contents{'CONFIG_HEADER'} . "\n");
1172     }
1174     return $linker;
1177 # Handle the BUILT_SOURCES variable.
1178 sub handle_built_sources
1180     return unless &variable_defined ('BUILT_SOURCES');
1181     push (@all, '$(BUILT_SOURCES)');
1183     local (@sources) = &variable_value_as_list ('BUILT_SOURCES');
1184     local ($s);
1185     foreach $s (@sources)
1186     {
1187         if (/^\@.*\@$/)
1188         {
1189             # FIXME: is this really the right thing to do?
1190             &am_line_error ('BUILT_SOURCES', "\`BUILT_SOURCES' should not contain a configure substitution");
1191             last;
1192         }
1193     }
1195     # We don't care about the return value of this function.  We just
1196     # want to make sure to update %dep_files with the contents of
1197     # BUILT_SOURCES.
1198     &handle_single_transform_list (@sources);
1201 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1202 # Also, generate _DEPENDENCIES variable if appropriate.
1203 # Arguments are:
1204 #   transformed name of object being built, or empty string if no object
1205 #   name of _LDADD/_LIBADD-type variable to examine
1206 #   boolean (lex_seen) which is true if a lex source file was seen in this
1207 #     object.  valid only for LDADDs, not LIBADDs.  If set, LEXLIB
1208 #     must be in LDADD.
1209 # Returns 1 if LIBOBJS seen, 0 otherwise.
1210 sub handle_lib_objects
1212     local ($xname, $var, $lex_seen) = @_;
1214     die "automake: programming error 1 in handle_lib_objects\n"
1215         if ! &variable_defined ($var);
1217     die "automake: programming error 2 in handle_lib_objects\n"
1218         if $lex_seen && $var =~ /LIBADD/;
1220     # We recognize certain things that are commonly put in LIBADD or
1221     # LDADD.
1222     local ($lsearch);
1223     local (@dep_list) = ();
1225     # If no lex source seen, just assume this is ok.
1226     local ($lex_ok) = $lex_seen ? 0 : 1;
1228     local ($seen_libobjs) = 0;
1229     local ($flagvar) = 0;
1231     foreach $lsearch (&variable_value_as_list ($var))
1232     {
1233         # Skip -lfoo and -Ldir; these are explicitly allowed.
1234         next if $lsearch =~ /^-[lL]/;
1235         if (! $flagvar && $lsearch =~ /^-/)
1236         {
1237             if ($var =~ /^(.*)LDADD$/)
1238             {
1239                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1240             }
1241             else
1242             {
1243                 # Only get this error once.
1244                 $flagvar = 1;
1245                 &am_line_error ($var, "you cannot use linker flags such as \`$lsearch' in \`$var'");
1246             }
1247         }
1249         # Assume we have a file of some sort, and push it onto the
1250         # dependency list.  Autoconf substitutions are not pushed;
1251         # rarely is a new dependency substituted into (eg) foo_LDADD
1252         # -- but "bad things (eg -lX11) are routinely substituted.
1253         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1254         # and handled specially below.
1255         push (@dep_list, $lsearch)
1256             unless $lsearch =~ /^\@.*\@$/;
1258         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1259         # means adding entries to dep_files.
1260         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1261         {
1262             push (@dep_list, $lsearch);
1263             $seen_libobjs = 1;
1264             if (! keys %libsources)
1265             {
1266                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
1267             }
1269             local ($iter, $rewrite);
1270             foreach $iter (keys %libsources)
1271             {
1272                 if ($iter =~ /\.[cly]$/)
1273                 {
1274                     $seen_c_source = $var;
1275                 }
1277                 if ($iter =~ /\.h$/)
1278                 {
1279                     &require_file_with_line ($var, $FOREIGN, $iter);
1280                 }
1281                 elsif ($iter ne 'alloca.c')
1282                 {
1283                     ($rewrite = $iter) =~ s/\.c$/.P/;
1284                     $dep_files{'.deps/' . $rewrite} = 1;
1285                     &require_file_with_line ($var, $FOREIGN, $iter);
1286                 }
1287             }
1288         }
1289         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1290         {
1291             push (@dep_list, $lsearch);
1292             &am_line_error ($var,
1293                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
1294                 if ! defined $libsources{'alloca.c'};
1295             $dep_files{'.deps/alloca.P'} = 1;
1296             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1297             $seen_c_source = $var;
1298         }
1299         elsif ($lsearch eq '@LEXLIB@')
1300         {
1301             # FIXME: variable_value_as_list requires us to force
1302             # @LEXLIB@ here, where we'd really prefer $(LEXLIB).
1303             # Nasty -- this will have to wait until many cleanups are
1304             # made, I think.
1305             $lex_ok = 1;
1306         }
1307     }
1309     if (! $lex_ok)
1310     {
1311         &am_line_error ($var, 'lex source file used without @LEXLIB@');
1312     }
1314     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES'))
1315     {
1316         &define_pretty_variable ($xname . '_DEPENDENCIES', @dep_list);
1317     }
1319     return $seen_libobjs;
1322 # Handle C programs.
1323 sub handle_programs
1325     local (@proglist) = &am_install_var ('-clean',
1326                                          'progs', 'PROGRAMS',
1327                                          'bin', 'sbin', 'libexec', 'pkglib',
1328                                          'noinst', 'check');
1329     return if ! @proglist;
1331     # If a program is installed, this is required.  We only want this
1332     # error to appear once.
1333     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1334         unless $seen_arg_prog;
1335     $seen_arg_prog = 1;
1337     local ($one_file, $xname, $munge);
1339     local ($seen_libobjs) = 0;
1340     foreach $one_file (@proglist)
1341     {
1342         local ($obj) = &get_object_extension ($one_file);
1344         # Canonicalize names.
1345         ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1346         if ($xname ne $one_file)
1347         {
1348             local ($xt);
1349             foreach $xt ('_LDADD', '_LDFLAGS', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
1350             {
1351                 &am_line_error ($one_file . $xt,
1352                                 "invalid variable \`" . $one_file . $xt
1353                                 . "'; should be \`" . $xname . $xt . "'")
1354                     if &variable_defined ($one_file . $xt);
1355             }
1356         }
1358         # FIXME: Using a trick to figure out if any lex sources appear
1359         # in our program; should use some cleaner method.
1360         local ($lex_num) = scalar (keys %lex_sources);
1361         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1362         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1364         local ($xt) = '';
1365         if (&variable_defined ($xname . "_LDADD"))
1366         {
1367             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1368                                      $lex_file_seen))
1369             {
1370                 $seen_libobjs = 1;
1371             }
1372             $lex_file_seen = 0;
1373             $xt = '_LDADD';
1374         }
1375         else
1376         {
1377             # User didn't define prog_LDADD override.  So do it.
1378             &define_variable ($xname . '_LDADD', '$(LDADD)');
1380             # This does a bit too much work.  But we need it to
1381             # generate _DEPENDENCIES when appropriate.
1382             if (&variable_defined ('LDADD'))
1383             {
1384                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1385                 {
1386                     $seen_libobjs = 1;
1387                 }
1388                 $lex_file_seen = 0;
1389             }
1390             $xt = '_SOURCES'
1391         }
1393         if (! &variable_defined ($xname . '_LDFLAGS'))
1394         {
1395             # Define the prog_LDFLAGS variable.
1396             &define_variable ($xname . '_LDFLAGS', '');
1397         }
1399         if ($lex_file_seen)
1400         {
1401             &am_line_error ($xname . $xt,
1402                             'lex source file used without @LEXLIB@');
1403         }
1405         # Determine program to use for link.
1406         local ($xlink);
1407         if (&variable_defined ($xname . '_LINK'))
1408         {
1409             $xlink = $xname . '_LINK';
1410         }
1411         else
1412         {
1413             $xlink = $linker ? $linker : 'LINK';
1414         }
1416         local ($cygxform) = '';
1417         if (! $seen_cygwin32)
1418         {
1419             $cygxform .= 's/^CYGWIN.*$//;';
1420         }
1422         $output_rules .=
1423             &file_contents_with_transform
1424                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1425                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1426                  . 's/\@XLINK\@/' . $xlink . '/go;'
1427                  . $cygxform,
1428                  'program');
1429     }
1431     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1432     {
1433         $seen_libobjs = 1;
1434     }
1436     if ($seen_libobjs)
1437     {
1438         foreach $one_file (@proglist)
1439         {
1440             # Canonicalize names.
1441             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1443             if (&variable_defined ($xname . '_LDADD'))
1444             {
1445                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1446             }
1447             elsif (&variable_defined ('LDADD'))
1448             {
1449                 &check_libobjs_sources ($xname, 'LDADD');
1450             }
1451         }
1452     }
1456 # Handle libraries.
1457 sub handle_libraries
1459     local (@liblist) = &am_install_var ('-clean',
1460                                         'libs', 'LIBRARIES',
1461                                         'lib', 'pkglib', 'noinst', 'check');
1462     return if ! @liblist;
1464     local (%valid) = &am_primary_prefixes ('LIBRARIES', 'lib', 'pkglib',
1465                                            'noinst', 'check');
1466     if (! defined $configure_vars{'RANLIB'})
1467     {
1468         local ($key);
1469         foreach $key (keys %valid)
1470         {
1471             if (&variable_defined ($key . '_LIBRARIES'))
1472             {
1473                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1474                 # Only get this error once.
1475                 $configure_vars{'RANLIB'} = 1;
1476                 last;
1477             }
1478         }
1479     }
1481     local ($onelib);
1482     local ($munge);
1483     local ($xlib);
1484     local ($seen_libobjs) = 0;
1485     foreach $onelib (@liblist)
1486     {
1487         # Check that the library fits the standard naming convention.
1488         if ($onelib !~ /^lib.*\.a$/)
1489         {
1490             # FIXME this should only be a warning for foreign packages
1491             # FIXME should put line number here.  That means mapping
1492             # from library name back to variable name.
1493             &am_error ("\`$onelib' is not a standard library name");
1494         }
1496         local ($obj) = &get_object_extension ($onelib);
1498         # Canonicalize names.
1499         ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1500         if ($xlib ne $onelib)
1501         {
1502             local ($xt);
1503             foreach $xt ('_LIBADD', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
1504             {
1505                 &am_line_error ($onelib . $xt,
1506                                 "invalid variable \`" . $onelib . $xt
1507                                 . "'; should be \`" . $xlib . $xt . "'")
1508                     if &variable_defined ($onelib . $xt);
1509             }
1510         }
1512         if (&variable_defined ($xlib . '_LIBADD'))
1513         {
1514             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1515             {
1516                 $seen_libobjs = 1;
1517             }
1518         }
1519         else
1520         {
1521             # Generate support for conditional object inclusion in
1522             # libraries.
1523             &define_variable ($xlib . "_LIBADD", '');
1524         }
1526         &handle_source_transform ($xlib, $onelib, $obj);
1528         $output_rules .=
1529             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1530                                            . 's/\@XLIBRARY\@/'
1531                                            . $xlib . '/go;',
1532                                            'library');
1533     }
1535     if ($seen_libobjs)
1536     {
1537         foreach $onelib (@liblist)
1538         {
1539             # Canonicalize names.
1540             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1541             if (&variable_defined ($xlib . '_LIBADD'))
1542             {
1543                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1544             }
1545         }
1546     }
1548     &define_variable ('AR', 'ar');
1549     &define_configure_variable ('RANLIB');
1552 # Handle shared libraries.
1553 sub handle_ltlibraries
1555     local (@liblist) = &am_install_var ('-clean',
1556                                         'ltlib', 'LTLIBRARIES',
1557                                         'lib', 'pkglib');
1558     return if ! @liblist;
1560     local (%instdirs);
1561     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 'lib', 'pkglib');
1563     local ($key);
1564     foreach $key (keys %valid)
1565     {
1566         if (&variable_defined ($key . '_LTLIBRARIES'))
1567         {
1568             if (!$seen_libtool)
1569             {
1570                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
1571                 # Only get this error once.
1572                 $configure_vars{'LIBTOOL'} = 1;
1573                 $seen_libtool = 1;
1574             }
1576             # Get the installation directory of each library.
1577             next if ($key eq 'EXTRA');
1578             for (&variable_value_as_list ($key . '_LTLIBRARIES'))
1579             {
1580                 if ($instdirs{$_})
1581                 {
1582                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1583                 }
1584                 else
1585                 {
1586                     $instdirs{$_} = $key;
1587                 }
1588             }
1589         }
1590     }
1592     local ($onelib);
1593     local ($munge);
1594     local ($xlib);
1595     local ($seen_libobjs) = 0;
1596     foreach $onelib (@liblist)
1597     {
1598         # Check that the library fits the standard naming convention.
1599         if ($onelib !~ /^lib.*\.la$/)
1600         {
1601             # FIXME this should only be a warning for foreign packages
1602             # FIXME should put line number here.  That means mapping
1603             # from library name back to variable name.
1604             &am_error ("\`$onelib' is not a standard libtool library name");
1605         }
1607         local ($obj) = &get_object_extension ($onelib);
1609         # Canonicalize names.
1610         ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1611         if ($xlib ne $onelib)
1612         {
1613             local ($xt);
1614             foreach $xt ('_LIBADD', '_LDFLAGS', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
1615             {
1616                 &am_line_error ($onelib . $xt,
1617                                 "invalid variable \`" . $onelib . $xt
1618                                 . "'; should be \`" . $xlib . $xt . "'")
1619                     if &variable_defined ($onelib . $xt);
1620             }
1621         }
1623         if (! &variable_defined ($xlib . '_LDFLAGS'))
1624         {
1625             # Define the lib_LDFLAGS variable.
1626             &define_variable ($xlib . '_LDFLAGS', '');
1627         }
1629         if (&variable_defined ($xlib . '_LIBADD'))
1630         {
1631             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1632             {
1633                 $seen_libobjs = 1;
1634             }
1635         }
1636         else
1637         {
1638             # Generate support for conditional object inclusion in
1639             # libraries.
1640             &define_variable ($xlib . "_LIBADD", '');
1641         }
1643         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
1645         # Determine program to use for link.
1646         local ($xlink);
1647         if (&variable_defined ($xlib . '_LINK'))
1648         {
1649             $xlink = $xlib . '_LINK';
1650         }
1651         else
1652         {
1653             $xlink = $linker ? $linker : 'LINK';
1654         }
1657         $output_rules .=
1658             &file_contents_with_transform ('s/\@LTLIBRARY\@/'
1659                                            . $onelib . '/go;'
1660                                            . 's/\@XLTLIBRARY\@/'
1661                                            . $xlib . '/go;'
1662                                            . 's/\@DIR\@/'
1663                                            . $instdirs{$onelib} . '/go;'
1664                                            . 's/\@XLINK\@/' . $xlink . '/go;',
1665                                            'ltlibrary');
1666     }
1668     if ($seen_libobjs)
1669     {
1670         foreach $onelib (@liblist)
1671         {
1672             # Canonicalize names.
1673             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1674             if (&variable_defined ($xlib . '_LIBADD'))
1675             {
1676                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1677             }
1678         }
1679     }
1682 # See if any _SOURCES variable were misspelled.  Also, make sure that
1683 # EXTRA_ variables don't contain configure substitutions.
1684 sub check_typos
1686     local ($varname, $primary);
1687     foreach $varname (keys %contents)
1688     {
1689         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS', '_DEPENDENCIES')
1690         {
1691             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
1692             {
1693                 &am_line_error ($varname,
1694                                 "invalid unused variable name: \`$varname'");
1695             }
1696         }
1697     }
1700 # Handle scripts.
1701 sub handle_scripts
1703     # NOTE we no longer automatically clean SCRIPTS, because it is
1704     # useful to sometimes distribute scripts verbatim.  This happens
1705     # eg in Automake itself.
1706     &am_install_var ('scripts', 'SCRIPTS',
1707                      'bin', 'sbin', 'libexec', 'pkgdata',
1708                      'noinst', 'check');
1710     # Set $scripts_installed if appropriate.  Make sure we only find
1711     # scripts which are actually installed -- this is why we can't
1712     # simply use the return value of am_install_var.
1713     local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
1714                                            'libexec', 'pkgdata',
1715                                            'noinst', 'check');
1716     local ($key);
1717     foreach $key (keys %valid)
1718     {
1719         if ($key ne 'noinst'
1720             && $key ne 'check'
1721             && &variable_defined ($key . '_SCRIPTS'))
1722         {
1723             $scripts_installed = 1;
1724             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
1725         }
1726     }
1728     if ($scripts_installed)
1729     {
1730         # If a program is installed, this is required.  We only want this
1731         # error to appear once.
1732         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1733             unless $seen_arg_prog;
1734         $seen_arg_prog = 1;
1735     }
1738 # Search a file for a "version.texi" Texinfo include.  Return the name
1739 # of the include file if found, or the empty string if not.  A
1740 # "version.texi" file is actually any file whose name matches
1741 # "vers*.texi".
1742 sub scan_texinfo_file
1744     local ($filename) = @_;
1746     if (! open (TEXI, $filename))
1747     {
1748         &am_error ("couldn't open \`$filename': $!");
1749         return '';
1750     }
1751     print "automake: reading $filename\n" if $verbose;
1753     local ($vfile, $outfile);
1754     while (<TEXI>)
1755     {
1756         if (/^\@setfilename +(\S+)/)
1757         {
1758             $outfile = $1;
1759             last if ($vfile);
1760         }
1762         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
1763         {
1764             # Found version.texi include.
1765             $vfile = $1;
1766             last if $outfile;
1767         }
1768     }
1770     close (TEXI);
1771     return ($outfile, $vfile);
1774 # Handle all Texinfo source.
1775 sub handle_texinfo
1777     &am_line_error ('TEXINFOS',
1778                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
1779         if &variable_defined ('TEXINFOS');
1780     return if (! &variable_defined ('info_TEXINFOS')
1781                && ! &variable_defined ('html_TEXINFOS'));
1783     local (@texis) = &variable_value_as_list ('info_TEXINFOS');
1785     local (@info_deps_list, @dvis_list, @texi_deps);
1786     local ($infobase, $info_cursor);
1787     local (%versions);
1788     local ($done) = 0;
1789     local ($vti);
1790     local ($tc_cursor, @texi_cleans);
1791     local ($canonical);
1793     foreach $info_cursor (@texis)
1794     {
1795         ($infobase = $info_cursor) =~ s/\.texi(nfo)?$//;
1797         # If 'version.texi' is referenced by input file, then include
1798         # automatic versioning capability.
1799         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
1800                                                         . "/" . $info_cursor);
1802         if ($out_file eq '')
1803         {
1804             &am_error ("\`$info_cursor' missing \@setfilename");
1805             next;
1806         }
1808         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
1809         {
1810             # FIXME should report line number in input file.
1811             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
1812             next;
1813         }
1815         if ($vtexi)
1816         {
1817             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
1818                 if (defined $versions{$vtexi});
1819             $versions{$vtexi} = $info_cursor;
1821             # We number the stamp-vti files.  This is doable since the
1822             # actual names don't matter much.  We only number starting
1823             # with the second one, so that the common case looks nice.
1824             $vti = 'vti' . ($done ? $done : '');
1825             &push_dist_common ($vtexi, 'stamp-' . $vti);
1826             push (@clean, $vti);
1828             # Only require once.
1829             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
1830                                           'mdate-sh')
1831                 if ! $done;
1832             ++$done;
1834             local ($conf_pat);
1835             ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
1836             $output_rules .=
1837                 &file_contents_with_transform
1838                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
1839                      . 's/\@VTI\@/' . $vti . '/g; '
1840                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
1841                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
1842                      'texi-vers');
1844             &push_phony_cleaners ($vti);
1845         }
1847         # If user specified file_TEXINFOS, then use that as explicit
1848         # dependency list.
1849         @texi_deps = ();
1850         push (@texi_deps, $info_cursor);
1851         push (@texi_deps, $vtexi) if $vtexi;
1853         # Canonicalize name first.
1854         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
1855         if (&variable_defined ($canonical . "_TEXINFOS"))
1856         {
1857             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
1858             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
1859         }
1861         $output_rules .= ("\n" . $out_file . ": "
1862                           . join (' ', @texi_deps)
1863                           . "\n" . $infobase . ".dvi: "
1864                           . join (' ', @texi_deps)
1865                           . "\n\n");
1867         push (@info_deps_list, $out_file);
1868         push (@dvis_list, $infobase . '.dvi');
1870         # Generate list of things to clean for this target.  We do
1871         # this explicitly because otherwise too many things could be
1872         # removed.  In particular the ".log" extension might
1873         # reasonably be used in other contexts by the user.
1874         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
1875                             'ky', 'log', 'pg', 'toc', 'tp', 'tps',
1876                             'vr', 'vrs', 'op', 'tr', 'cv')
1877         {
1878             push (@texi_cleans, $infobase . '.' . $tc_cursor);
1879         }
1880     }
1882     # Find these programs wherever they may lie.  Yes, this has
1883     # intimate knowledge of the structure of the texinfo distribution.
1884     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
1885                               '@MAKEINFO@');
1886     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
1887                               'texi2dvi');
1889     local ($xform);
1890     if ($cygnus_mode)
1891     {
1892         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
1893     }
1894     else
1895     {
1896         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
1897     }
1898     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
1899     push (@phony, 'install-info-am', 'uninstall-info');
1900     push (@dist_targets, 'dist-info');
1902     # How to clean.
1903     $output_rules .= "\nmostlyclean-info:\n";
1904     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
1905     $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
1906                       . "maintainer-clean-info:\n\t"
1907                       . 'for i in $(INFO_DEPS); do rm -f `eval echo $$i*`; done'
1908                       . "\n");
1909     &push_phony_cleaners ('info');
1911     push (@suffixes, '.texi', '.texinfo', '.info', '.dvi', '.ps');
1913     if (! defined $options{'no-installinfo'})
1914     {
1915         push (@uninstall, 'uninstall-info');
1916         push (@installdirs, '$(infodir)');
1917         unshift (@install_data, 'install-info-am');
1919         # Make sure documentation is made and installed first.  Use
1920         # $(INFO_DEPS), not 'info', because otherwise recursive makes
1921         # get run twice during "make all".
1922         unshift (@all, '$(INFO_DEPS)');
1923     }
1924     push (@clean, 'info');
1925     push (@info, '$(INFO_DEPS)');
1926     push (@dvi, '$(DVIS)');
1928     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
1929     &define_variable ("DVIS", join (' ', @dvis_list));
1930     # This next isn't strictly needed now -- the places that look here
1931     # could easily be changed to look in info_TEXINFOS.  But this is
1932     # probably better, in case noinst_TEXINFOS is ever supported.
1933     &define_variable ("TEXINFOS", $contents{'info_TEXINFOS'});
1935     # Do some error checking.  Note that this file is not required
1936     # when in Cygnus mode -- a bletcherous hack.
1937     &require_file_with_line ('info_TEXINFOS',
1938                              $cygnus_mode ? $GNU : $FOREIGN,
1939                              'texinfo.tex')
1940         unless defined $options{'no-texinfo.tex'};
1943 # Handle any man pages.
1944 sub handle_man_pages
1946     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
1947         if &variable_defined ('MANS');
1948     return if ! &variable_defined ('man_MANS');
1950     # We generate the manpage install code by hand to avoid the use of
1951     # basename in the generated Makefile.
1952     local (@mans) = &variable_value_as_list ('man_MANS');
1953     local (%sections, %inames, %mbases, %secmap, %fullsecmap);
1954     local ($i) = 1;
1955     foreach (@mans)
1956     {
1957         # FIXME: statement without effect:
1958         /^(.*)\.([0-9])([a-z]*)$/;
1959         $sections{$2} = 1;
1960         $inames{$i} = $_;
1961         $mbases{$i} = $1;
1962         $secmap{$i} = $2;
1963         $fullsecmap{$i} = $2 . $3;
1964         $i++;
1965     }
1967     # We don't really need this, but we use it in case we ever want to
1968     # support noinst_MANS.
1969     &define_variable ("MANS", $contents{'man_MANS'});
1971     # Generate list of install dirs.
1972     $output_rules .= "install-man: \$(MANS)\n";
1973     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
1974     # Sort keys so that output is deterministic.
1975     foreach (sort keys %sections)
1976     {
1977         push (@installdirs, '$(mandir)/man' . $_)
1978             unless defined $options{'no-installman'};
1979         $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
1980                           . $_ . "\n");
1981     }
1982     push (@phony, 'install-man');
1984     # Generate install target.
1985     local ($key);
1986     foreach $key (sort keys %inames)
1987     {
1988         $_ = $install_man_format;
1989         s/\@SECTION\@/$secmap{$key}/g;
1990         s/\@MAN\@/$inames{$key}/g;
1991         s/\@FULLSECT\@/$fullsecmap{$key}/g;
1992         s/\@MANBASE\@/$mbases{$key}/g;
1993         $output_rules .= $_;
1994     }
1995     $output_rules .= "\n";
1997     $output_rules .= "uninstall-man:\n";
1998     foreach $key (sort keys %inames)
1999     {
2000         $_ = $uninstall_man_format;
2001         s/\@SECTION\@/$secmap{$key}/g;
2002         s/\@MAN\@/$inames{$key}/g;
2003         s/\@FULLSECT\@/$fullsecmap{$key}/g;
2004         s/\@MANBASE\@/$mbases{$key}/g;
2005         $output_rules .= $_;
2006     }
2007     $output_rules .= "\n";
2008     push (@phony, 'uninstall-man');
2010     $output_vars .= &file_contents ('mans-vars');
2012     if (! defined $options{'no-installman'})
2013     {
2014         push (@install_data, 'install-man');
2015         push (@uninstall, 'uninstall-man');
2016         push (@all, '$(MANS)');
2017     }
2020 # Handle DATA variables.
2021 sub handle_data
2023     &am_install_var ('data', 'DATA', 'data', 'sysconf',
2024                      'sharedstate', 'localstate', 'pkgdata',
2025                      'noinst', 'check');
2028 # Handle TAGS.
2029 sub handle_tags
2031     push (@phony, 'tags');
2032     local (@tag_deps) = ();
2033     if (&variable_defined ('SUBDIRS'))
2034     {
2035         $output_rules .= ("tags-recursive:\n"
2036                           . "\tlist=\"\$(SUBDIRS)\"; for subdir in \$\$list; do \\\n"
2037                           # Never fail here if a subdir fails; it
2038                           # isn't important.
2039                           . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
2040                           . "\tdone\n");
2041         push (@tag_deps, 'tags-recursive');
2042         push (@phony, 'tags-recursive');
2043     }
2045     if ($dir_holds_sources
2046         || $dir_holds_headers
2047         || &variable_defined ('ETAGS_ARGS')
2048         || @tag_deps)
2049     {
2050         local ($xform) = '';
2051         if ($config_header && $relative_dir eq &dirname ($config_header))
2052         {
2053             # The config header is in this directory.  So require it.
2054             ($xform = &basename ($config_header)) =~ s/(\W)/\\$1/g;
2055         }
2056         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
2057                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
2059         $output_rules .= &file_contents_with_transform ($xform, 'tags');
2060         $output_rules .= &file_contents ('tags-clean');
2061         push (@clean, 'tags');
2062         &push_phony_cleaners ('tags');
2063         &examine_variable ('TAGS_DEPENDENCIES');
2064     }
2065     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2066     {
2067         &am_line_error ('TAGS_DEPENDENCIES',
2068                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2069     }
2070     else
2071     {
2072         # Every Makefile must define some sort of TAGS rule.
2073         # Otherwise, it would be possible for a top-level "make TAGS"
2074         # to fail because some subdirectory failed.
2075         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2076     }
2079 # Worker for handle_dist.
2080 sub handle_dist_worker
2082     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
2084     # Initialization; only at top level.
2085     if ($relative_dir eq '.')
2086     {
2087         if ($strictness >= $GNITS)
2088         {
2089             # For Gnits users, this is pretty handy.  Look at 15 lines
2090             # in case some explanatory text is desirable.
2091             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
2092           echo "NEWS not updated; not releasing" 1>&2; \\
2093           exit 1; \\
2094         fi
2096         }
2099         $output_rules .=
2100             # Create dist directory.
2101             '   rm -rf $(distdir)
2102         mkdir $(distdir)
2103         -chmod 755 $(distdir)
2106         # Only run automake in `dist' target if --include-deps not
2107         # specified.  That way the recipient of a distribution can run
2108         # "make dist" and not need Automake.
2109         if ($cmdline_use_dependencies)
2110         {
2111             $output_rules .=
2112                 (
2113                  # We need an absolute path for --output-dir.  Thus the
2114                  # weirdness.
2115                  '      here=`pwd`; distdir=`cd $(distdir) && pwd` \\
2116           && cd $(srcdir) \\
2117           && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(srcdir) --output-dir=$$distdir '
2118                  # Set strictness of output.
2119                  . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2120                  . "\n"
2121                  );
2122         }
2123     }
2125     # Scan EXTRA_DIST to see if we need to distribute anything from a
2126     # subdir.  If so, add it to the list.  I didn't want to do this
2127     # originally, but there were so many requests that I finally
2128     # relented.
2129     local (@dist_dirs);
2130     if (&variable_defined ('EXTRA_DIST'))
2131     {
2132         foreach (&variable_value_as_list ('EXTRA_DIST'))
2133         {
2134             next if /^\@.*\@$/;
2135             next unless s,/+[^/]+$,,;
2136             push (@dist_dirs, $_)
2137                 unless $_ eq '.';
2138         }
2139     }
2140     if (@dist_dirs)
2141     {
2142         # Prepend $(distdir) to each directory given.  Doing it via a
2143         # hash lets us ensure that each directory is used only once.
2144         local (%dhash);
2145         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
2146         $output_rules .= "\t";
2147         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
2148     }
2150     # In loop, test for file existence because sometimes a file gets
2151     # included in DISTFILES twice.  For example this happens when a
2152     # single source file is used in building more than one program.
2153     # Also, there are situations in which "ln" can fail.  For instance
2154     # a file to distribute could actually be a cross-filesystem
2155     # symlink -- this can easily happen if "gettextize" was run on the
2156     # distribution.
2157     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
2158     if ($cygnus_mode)
2159     {
2160         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
2161     }
2162     else
2163     {
2164         $output_rules .= "\t  d=\$(srcdir); \\\n";
2165     }
2166     $output_rules .= '    test -f $(distdir)/$$file \\
2167           || ln $$d/$$file $(distdir)/$$file 2> /dev/null \\
2168           || cp -p $$d/$$file $(distdir)/$$file; \\
2169         done
2172     # If we have SUBDIRS, create all dist subdirectories and do
2173     # recursive build.
2174     if (&variable_defined ('SUBDIRS'))
2175     {
2176         # Test for directory existence here because previous automake
2177         # invocation might have created some directories.  Note that
2178         # we explicitly set distdir for the subdir make; that lets us
2179         # mix-n-match many automake-using packages into one large
2180         # package, and have "dist" at the top level do the right
2181         # thing.
2182         $output_rules .= '      for subdir in $(SUBDIRS); do            \\
2183           test -d $(distdir)/$$subdir           \\
2184           || mkdir $(distdir)/$$subdir          \\
2185           || exit 1;                            \\
2186           chmod 755 $(distdir)/$$subdir;        \\
2187           (cd $$subdir && $(MAKE) distdir=../$(distdir)/$$subdir distdir) \\
2188             || exit 1; \\
2189         done
2191     }
2193     # If the target `dist-hook' exists, make sure it is run.  This
2194     # allows users to do random weird things to the distribution
2195     # before it is packaged up.
2196     push (@dist_targets, 'dist-hook') if defined $contents{'dist-hook'};
2198     local ($targ);
2199     foreach $targ (@dist_targets)
2200     {
2201         # We must explicitly set distdir for these sub-makes.
2202         $output_rules .= "\t\$(MAKE) distdir=\"\$(distdir)\" $targ\n";
2203     }
2205     push (@phony, 'distdir');
2208 # Handle 'dist' target.
2209 sub handle_dist
2211     # Set up maint_charset.
2212     $local_maint_charset = $contents{'MAINT_CHARSET'}
2213         if &variable_defined ('MAINT_CHARSET');
2214     $maint_charset = $local_maint_charset
2215         if $relative_dir eq '.';
2217     if (&variable_defined ('DIST_CHARSET'))
2218     {
2219         &am_line_error ('DIST_CHARSET',
2220                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2221             if ! $local_maint_charset;
2222         if ($relative_dir eq '.')
2223         {
2224             $dist_charset = $contents{'DIST_CHARSET'}
2225         }
2226         else
2227         {
2228             &am_line_error ('DIST_CHARSET',
2229                             "DIST_CHARSET can only be defined at top level");
2230         }
2231     }
2233     # Look for common files that should be included in distribution.
2234     local ($cfile);
2235     foreach $cfile (@common_files)
2236     {
2237         if (-f ($relative_dir . "/" . $cfile))
2238         {
2239             &push_dist_common ($cfile);
2240         }
2241     }
2243     # Keys of %dist_common are names of files to distributed.  We put
2244     # README first because it then becomes easier to make a
2245     # Usenet-compliant shar file (in these, README must be first).
2246     # FIXME: do more ordering of files here.
2247     local (@coms);
2248     if (defined $dist_common{'README'})
2249     {
2250         push (@coms, 'README');
2251         delete $dist_common{'README'};
2252     }
2253     push (@coms, sort keys %dist_common);
2255     &define_pretty_variable ("DIST_COMMON", @coms);
2256     $output_vars .= "\n";
2258     # Some boilerplate.
2259     $output_vars .= &file_contents ('dist-vars') . "\n";
2260     &define_variable ('TAR', $TAR);
2261     &define_variable ('GZIP', '--best');
2263     # Put these things in rules section so it is easier for whoever
2264     # reads Makefile.in.
2265     if (! &variable_defined ('distdir'))
2266     {
2267         if ($relative_dir eq '.')
2268         {
2269             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2270         }
2271         else
2272         {
2273             $output_rules .= ("\n"
2274                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2275                               . "\n");
2276         }
2277     }
2278     if ($relative_dir ne '.')
2279     {
2280         $output_rules .= "\nsubdir = " . $relative_dir . "\n";
2281     }
2283     # Generate 'dist' target, and maybe dist-shar / dist-zip / dist-tarZ.
2284     if ($relative_dir eq '.')
2285     {
2286         # Rule to check whether a distribution is viable.
2287         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
2288 # it guarantees that the distribution is self-contained by making another
2289 # tarfile.
2290 distcheck: dist
2291         rm -rf $(distdir)
2292         GZIP=$(GZIP) $(TAR) zxf $(distdir).tar.gz
2293         mkdir $(distdir)/=build
2294         mkdir $(distdir)/=inst
2295         dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
2296                           . (defined $contents{'distcheck-hook'}
2297                              ? "\t\$(MAKE) distcheck-hook"
2298                              : '')
2299                           . '
2300         cd $(distdir)/=build \\
2301           && ../configure '
2303                           . ($seen_gettext ? '--with-included-gettext ' : '')
2304                           . '--srcdir=.. --prefix=$$dc_install_base \\
2305           && $(MAKE) \\
2306           && $(MAKE) dvi \\
2307           && $(MAKE) check \\
2308           && $(MAKE) install \\
2309           && $(MAKE) installcheck \\
2310           && $(MAKE) dist
2311         rm -rf $(distdir)
2312         @echo "========================"; \\
2313         echo "$(distdir).tar.gz is ready for distribution"; \\
2314         echo "========================"
2317         local ($dist_all) = ('dist-all: distdir' . "\n"
2318                              . $dist_header);
2319         local ($curs);
2320         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ')
2321         {
2322             if (defined $options{$curs} || $curs eq 'dist')
2323             {
2324                 $output_rules .= ($curs . ': distdir' . "\n"
2325                                   . $dist_header
2326                                   . $dist{$curs}
2327                                   . $dist_trailer);
2328                 $dist_all .= $dist{$curs};
2329             }
2330         }
2331         $output_rules .= $dist_all . $dist_trailer;
2332     }
2334     # Generate distdir target.
2335     &handle_dist_worker;
2338 # Scan a single dependency file and rewrite the dependencies as
2339 # appropriate.  Essentially this means:
2340 # * Clean out absolute dependencies which are not desirable.
2341 # * Rewrite other dependencies to be relative to $(top_srcdir).
2342 sub scan_dependency_file
2344     local ($depfile) = @_;
2346     if (! open (DEP_FILE, $depfile))
2347     {
2348         &am_error ("couldn't open \`$depfile': $!");
2349         return;
2350     }
2351     print "automake: reading $depfile\n" if $verbose;
2353     # Sometimes it is necessary to omit some dependencies.
2354     local (%omit) = %omit_dependencies;
2355     if (&variable_defined ('OMIT_DEPENDENCIES'))
2356     {
2357         grep ($omit{$_} = 1, &variable_value_as_list ('OMIT_DEPENDENCIES'));
2358     }
2360     local ($first_line) = 1;
2361     local ($last_line) = 0;
2362     local ($target, @dependencies);
2363     local ($one_dep, $xform);
2364     local ($just_file);
2366     local ($srcdir_rx, $fixup_rx);
2367     # If the top srcdir is absolute, then the current directory is
2368     # just relative_dir.  But if the top srcdir is relative, then we
2369     # need to add some dots first.  The same holds when matching
2370     # srcdir directly.
2371     if ($srcdir_name =~ /^\//)
2372     {
2373         ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
2374             =~ s/(\W)/\\$1/g;
2375         ($srcdir_rx = $srcdir_name . '/') =~ s/(\W)/\\$1/g;
2376     }
2377     else
2378     {
2379         ($fixup_rx = ($srcdir_name . '/' . $top_builddir . '/'
2380                       . $relative_dir . '/')) =~ s/(\W)/\\$1/g;
2381         $srcdir_rx = $srcdir_name . '/';
2382         # Don't append a spurious "." to the regex.
2383         $srcdir_rx .= $top_builddir
2384             unless $top_builddir eq '.';
2385         $srcdir_rx =~ s/(\W)/\\$1/g;
2386     }
2388     local ($rewrite_builddir) = (($top_builddir eq '.')
2389                                  ? ''
2390                                  : $top_builddir . '/');
2392     while (<DEP_FILE>)
2393     {
2394         if ($last_line)
2395         {
2396             # If LAST_LINE set then we've already seen what we thought
2397             # was the last line.
2398             goto bad_format;
2399         }
2400         next if (/$WHITE_PATTERN/o);
2401         chop;
2402         if (! s/\\$//)
2403         {
2404             # No trailing "\" means this should be the last line.
2405             $last_line = 1;
2406         }
2408         if ($first_line)
2409         {
2410             if (! /^([^:]+:)(.+)$/)
2411             {
2412               bad_format:
2413                 &am_error ("\`$depfile' has incorrect format");
2414                 close (DEP_FILE);
2415                 return;
2416             }
2418             $target = $1;
2419             $_ = $2;
2421             $first_line = 0;
2422         }
2424         foreach $one_dep (split (' ', $_))
2425         {
2426             if ($one_dep =~ /^$fixup_rx/)
2427             {
2428                 # The dependency points to the current directory in
2429                 # some way.
2430                 ($xform = $one_dep) =~ s/^$fixup_rx//;
2431                 push (@dependencies, $xform);
2432             }
2433             elsif ($one_dep =~ /^$srcdir_rx/)
2434             {
2435                 # The dependency is in some other directory in the package.
2436                 ($xform = $one_dep) =~ s/^$srcdir_rx/$rewrite_builddir/;
2437                 push (@dependencies, $xform);
2438             }
2439             elsif ($one_dep =~ /^\//)
2440             {
2441                 # Absolute path; ignore.
2442             }
2443             else
2444             {
2445                 # Anything else is assumed to be correct.  But first
2446                 # make sure it is not on our list of dependencies to
2447                 # omit.
2448                 ($just_file = $one_dep) =~ s,^.*/,,;
2449                 push (@dependencies, $one_dep)
2450                     if ! defined $omit{$just_file};
2451             }
2452         }
2453     }
2455     &pretty_print_rule ($target, "\t", @dependencies);
2457     close (DEP_FILE);
2460 # Handle auto-dependency code.
2461 sub handle_dependencies
2463     if ($use_dependencies)
2464     {
2465         # Include GNU-make-specific auto-dep code.
2466         if ($dir_holds_sources)
2467         {
2468             &define_pretty_variable ('DEP_FILES', sort keys %dep_files);
2469             $output_rules .= &file_contents ('depend');
2470             push (@clean, 'depend');
2471             &push_phony_cleaners ('depend');
2472             $output_rules .=
2473                 &file_contents_with_transform ('s/\@EXT\@/.c/g;'
2474                                                . 's/\@MKDEP\@/MKDEP/g;'
2475                                                . 's/^ONLYC//g;',
2476                                                'depend2');
2477             local ($ext);
2478             local ($need_cxx) = 0;
2479             foreach $ext (sort keys %cxx_extensions)
2480             {
2481                 $output_rules .=
2482                     &file_contents_with_transform ('s/\@EXT\@/' . $ext .'/g;'
2483                                                    . 's/\@MKDEP\@/CXXMKDEP/g;'
2484                                                    . 's/^ONLYC.*$//;',
2485                                                    'depend2');
2486                 $need_cxx = 1;
2487             }
2488             if ($need_cxx)
2489             {
2490                 &define_variable ('CXXMKDEP', '$(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
2491             }
2492         }
2493     }
2494     elsif ($build_directory ne '')
2495     {
2496         # Include any auto-generated deps that are present.  Note that
2497         # $build_directory ends in a "/".
2498         if (-d ($build_directory . $relative_dir . "/.deps")
2499             && -f ($build_directory . $relative_dir . "/.deps/.P"))
2500         {
2501             local ($depfile);
2503             foreach $depfile (&my_glob ($build_directory
2504                                         . $relative_dir . "/.deps/*.P"))
2505             {
2506                 &scan_dependency_file ($depfile);
2507             }
2509             $output_rules .= "\n";
2510         }
2511     }
2514 # Handle subdirectories.
2515 sub handle_subdirs
2517     return if ! &variable_defined ('SUBDIRS');
2519     # Make sure each directory mentioned in SUBDIRS actually exists.
2520     local ($dir);
2521     foreach $dir (&variable_value_as_list ('SUBDIRS'))
2522     {
2523         # Skip directories substituted by configure.
2524         next if $dir =~ /^\@.*\@$/;
2526         if (! -d $am_relative_dir . '/' . $dir)
2527         {
2528             &am_line_error ('SUBDIRS',
2529                             "required directory $am_relative_dir/$dir does not exist");
2530             next;
2531         }
2533         &am_relative_dir ('SUBDIRS',
2534                           "directory should not contain \`/'")
2535             if $dir =~ /\//;
2536     }
2538     local ($xform) = ('s/\@INSTALLINFO\@/' .
2539                       (defined $options{'no-installinfo'}
2540                        ? 'install-info-recursive'
2541                        : '')
2542                       . '/;');
2543     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
2545     # Push a bunch of phony targets.
2546     local ($phonies);
2547     foreach $phonies ('-data', '-exec', 'dirs')
2548     {
2549         push (@phony, 'install' . $phonies . '-recursive');
2550         push (@phony, 'uninstall' . $phonies . '-recursive');
2551     }
2552     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
2553     {
2554         push (@phony, $phonies . '-recursive');
2555     }
2556     &push_phony_cleaners ('recursive');
2558     push (@check_tests, "check-recursive");
2559     push (@installcheck, "installcheck-recursive");
2560     push (@info, "info-recursive");
2561     push (@dvi, "dvi-recursive");
2563     $recursive_install = 1;
2566 # Handle aclocal.m4.
2567 sub handle_aclocal_m4
2569     local ($regen_aclocal) = 0;
2570     if (-f 'aclocal.m4')
2571     {
2572         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
2573         &push_dist_common ('aclocal.m4');
2575         if (open (ACLOCAL, '< aclocal.m4'))
2576         {
2577             local ($line);
2578             $line = <ACLOCAL>;
2579             close (ACLOCAL);
2581             if ($line =~ 'generated automatically by aclocal')
2582             {
2583                 $regen_aclocal = 1;
2584             }
2585         }
2586     }
2588     local ($acinclude) = 0;
2589     if (-f 'acinclude.m4')
2590     {
2591         $regen_aclocal = 1;
2592         $acinclude = 1;
2593     }
2595     # Note that it might be possible that aclocal.m4 doesn't exist but
2596     # should be auto-generated.  This case probably isn't very
2597     # important.
2598     if ($regen_aclocal)
2599     {
2600         local (@ac_deps) = (
2601                             ($seen_maint_mode ? "\@MAINT\@" : "") ,
2602                             "configure.in",
2603                             ($acinclude ? ' acinclude.m4' : '')
2604                             );
2606         # Scan all -I directories for m4 files.  These are our
2607         # dependencies.
2608         if (&variable_defined ('ACLOCAL_AMFLAGS'))
2609         {
2610             local ($amdir);
2611             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS'))
2612             {
2613                 if ($amdir =~ s/^-I//
2614                     && $amdir !~ /^\//
2615                     && -d $amdir)
2616                 {
2617                     push (@ac_deps, &my_glob ($am_dir . '/*.m4'));
2618                 }
2619             }
2620         }
2622         &pretty_print_rule ("\$(srcdir)/aclocal.m4:", "\t\t", @ac_deps);
2624         $output_rules .=  ("\t"
2625                            . 'cd $(srcdir) && $(ACLOCAL)'
2626                            . (&variable_defined ('ACLOCAL_AMFLAGS')
2627                               ? ' $(ACLOCAL_AMFLAGS)' : '')
2628                            . "\n");
2629     }
2632 # Rewrite a list of input files into a form suitable to put on a
2633 # dependency list.  The idea is that if an input file has a directory
2634 # part the same as the current directory, then the directory part is
2635 # simply removed.  But if the directory part is different, then
2636 # $(top_srcdir) is prepended.  Among other things, this is used to
2637 # generate the dependency list for the output files generated by
2638 # AC_OUTPUT.  Consider what the dependencies should look like in this
2639 # case:
2640 #   AC_OUTPUT(src/out:src/in1:lib/in2)
2641 sub rewrite_inputs_into_dependencies
2643     local (@inputs) = @_;
2644     local ($single, @newinputs);
2646     foreach $single (@inputs)
2647     {
2648         if (&dirname ($single) eq $relative_dir)
2649         {
2650             push (@newinputs, &basename ($single));
2651         }
2652         else
2653         {
2654             push (@newinputs, '$(top_srcdir)/' . $single);
2655         }
2656     }
2658     return @newinputs;
2661 # Handle remaking and configure stuff.
2662 # We need the name of the input file, to do proper remaking rules.
2663 sub handle_configure
2665     local ($local, $input, @secondary_inputs) = @_;
2667     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
2668     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
2669         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
2671     local ($top_reldir);
2673     local ($input_base) = &basename ($input);
2674     local ($local_base) = &basename ($local);
2676     local ($amfile) = $input_base . '.am';
2677     # We know we can always add '.in' because it really should be an
2678     # error if the .in was missing originally.
2679     local ($infile) = '$(srcdir)/' . $input_base . '.in';
2680     local ($colon_infile);
2681     if ($local ne $input)
2682     {
2683         $colon_infile = ':' . $input . '.in';
2684     }
2685     $colon_infile .= ':' . join (':', @secondary_inputs)
2686         if @secondary_inputs;
2688     local (@rewritten) = &rewrite_inputs_into_dependencies (@secondary_inputs);
2689     # This rule remakes the Makefile.in.  Note use of @MAINT@ forces
2690     # us to abandon pretty-printing.  Sigh.
2691     $output_rules .= ($infile
2692                       # NOTE perl 5.003 (with -w) gives a
2693                       # uninitialized value error on the next line.
2694                       # Don't know why.
2695                       . ': '
2696                       . ($seen_maint_mode ? '@MAINT@ ' : '')
2697                       . $amfile . ' '
2698                       . '$(top_srcdir)/configure.in $(ACLOCAL_M4) '
2699                       . join (' ', @rewritten) . "\n"
2700                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
2701                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2702                       . ' ' . $input . $colon_infile . "\n\n");
2704     # This rule remakes the Makefile.
2705     $output_rules .= ($local_base
2706                       # NOTE: bogus uninit value error on next line;
2707                       # see comment above.
2708                       . ': '
2709                       . $infile . ' '
2710                       . '$(top_builddir)/config.status $(BUILT_SOURCES)'
2711                       . "\n"
2712                       . "\tcd \$(top_builddir) \\\n"
2713                       . "\t  && CONFIG_FILES="
2714                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
2715                       . $colon_infile
2716                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
2717                       . "\n\n");
2719     if ($relative_dir ne '.')
2720     {
2721         # In subdirectory.
2722         $top_reldir = '../';
2723     }
2724     else
2725     {
2726         &handle_aclocal_m4;
2727         $output_rules .= &file_contents ('remake');
2728         &examine_variable ('CONFIGURE_DEPENDENCIES');
2729         $top_reldir = '';
2730     }
2732     # If we have a configure header, require it.
2733     if ($config_header && $relative_dir eq &dirname ($config_header))
2734     {
2735         local ($ch_sans_dir) = &basename ($config_header);
2736         local ($cn_sans_dir) = &basename ($config_name);
2738         &require_file_with_conf_line ($config_header_line,
2739                                       $FOREIGN, $ch_sans_dir);
2741         # Header defined and in this directory.
2742         local (@files);
2743         if (-f $relative_dir . '/acconfig.h')
2744         {
2745             push (@files, 'acconfig.h');
2746         }
2747         if (-f $config_name . '.top')
2748         {
2749             push (@files, "${cn_sans_dir}.top");
2750         }
2751         if (-f $config_name . '.bot')
2752         {
2753             push (@files, "${cn_sans_dir}.bot");
2754         }
2756         &push_dist_common (@files);
2757         $output_rules .= &file_contents_with_transform ('s/\@FILES\@/'
2758                                                         . join (' ', @files)
2759                                                         . '/;',
2760                                                         'remake-hdr');
2762         &touch ($relative_dir . '/stamp-h.in');
2763         &require_file_with_conf_line ($config_header_line, $FOREIGN,
2764                                       'stamp-h.in');
2766         push (@clean, 'hdr');
2767         &push_phony_cleaners ('hdr');
2768         &define_variable ("CONFIG_HEADER_IN", "${ch_sans_dir}");
2769         &define_variable ('CONFIG_HEADER_FULL', $config_name);
2770     }
2772     # Set location of mkinstalldirs.
2773     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
2774     {
2775         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
2776                                             . '/mkinstalldirs'));
2777     }
2778     else
2779     {
2780         &define_variable ('mkinstalldirs',
2781                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
2782     }
2784     &am_line_error ('CONFIG_HEADER',
2785                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
2786         if &variable_defined ('CONFIG_HEADER');
2788     if ($config_name)
2789     {
2790         # Generate CONFIG_HEADER define.
2791         if ($relative_dir eq &dirname ($config_name))
2792         {
2793             &define_variable ("CONFIG_HEADER", &basename ($config_name));
2794         }
2795         else
2796         {
2797             &define_variable ("CONFIG_HEADER",
2798                               "${top_builddir}/${config_name}");
2799         }
2800     }
2802     # Now look for other files in this directory which must be remade
2803     # by config.status, and generate rules for them.
2804     local (@actual_other_files) = ();
2805     local ($file, $local);
2806     local (@inputs, @rewritten_inputs, $single);
2807     foreach $file (@other_input_files)
2808     {
2809         if ($file =~ /^(.*):(.*)$/)
2810         {
2811             # This is the ":" syntax of AC_OUTPUT.
2812             $file = $1;
2813             $local = &basename ($file);
2814             @inputs = split (':', $2);
2815             @rewritten_inputs = &rewrite_inputs_into_dependencies (@inputs);
2816         }
2817         else
2818         {
2819             # Normal usage.
2820             $local = &basename ($file);
2821             @inputs = ($local . '.in');
2822             @rewritten_inputs =
2823                 &rewrite_inputs_into_dependencies ($file . '.in');
2824         }
2826         # Skip files not in this directory.
2827         next unless &dirname ($file) eq $relative_dir;
2829         # Skip the config header.
2830         next if $local eq $top_builddir . '/' . $config_name;
2832         # Skip any Makefile.
2833         next if $local eq 'Makefile';
2835         $output_rules .= ($local . ': '
2836                           . '$(top_builddir)/config.status '
2837                           . join (' ', @rewritten_inputs) . "\n"
2838                           . "\t"
2839                           . 'cd $(top_builddir) && CONFIG_FILES='
2840                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
2841                           . '$@' . (length (@rewritten_inputs) > 1
2842                                     ? (':' . join (':', @rewritten_inputs))
2843                                     : '')
2844                           . ' CONFIG_HEADERS= ./config.status'
2845                           . "\n");
2846         push (@actual_other_files, $local);
2848         # Require all input files.
2849         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
2850                                       @inputs);
2851     }
2853     # These files get removed by "make clean".
2854     &define_pretty_variable ('CONFIG_CLEAN_FILES', @actual_other_files);
2857 # Handle C headers.
2858 sub handle_headers
2860     $dir_holds_headers = &am_install_var ('header', 'HEADERS', 'include',
2861                                           'oldinclude', 'pkginclude',
2862                                           'noinst', 'check');
2865 sub handle_gettext
2867     return if ! $seen_gettext || $relative_dir ne '.';
2869     if (! &variable_defined ('SUBDIRS'))
2870     {
2871         &am_conf_error
2872             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
2873         return;
2874     }
2876     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
2877         if $seen_gettext;
2879     if (&variable_defined ('SUBDIRS'))
2880     {
2881         &am_line_error
2882             ('SUBDIRS',
2883              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
2884                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
2885         &am_line_error
2886             ('SUBDIRS',
2887              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
2888                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
2889     }
2891     # Ensure that each language in ALL_LINGUAS has a .po file, and
2892     # each po file is mentioned in ALL_LINGUAS.
2893     if ($seen_linguas)
2894     {
2895         local (%linguas) = ();
2896         grep ($linguas{$_} = 1, split (' ', $all_linguas));
2898         foreach (<po/*.po>)
2899         {
2900             s/^po\///;
2901             s/\.po$//;
2903             &am_line_error ($all_linguas_line,
2904                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
2905                 if ! $linguas{$_};
2906         }
2908         foreach (keys %linguas)
2909         {
2910             &am_line_error ($all_linguas_line,
2911                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
2912                 if ! -f "po/$_.po";
2913         }
2914     }
2915     else
2916     {
2917         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
2918     }
2921 # Handle footer elements.
2922 sub handle_footer
2924     if ($contents{'SOURCES'})
2925     {
2926         # NOTE don't use define_pretty_variable here, because
2927         # $contents{...} is already defined.
2928         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
2929     }
2930     if ($contents{'OBJECTS'})
2931     {
2932         # NOTE don't use define_pretty_variable here, because
2933         # $contents{...} is already defined.
2934         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
2935     }
2936     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
2937     {
2938         $output_vars .= "\n";
2939     }
2941     if (&variable_defined ('SUFFIXES'))
2942     {
2943         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
2944         # make do not like variable substitutions on the .SUFFIXES
2945         # line.
2946         push (@suffixes, &variable_value_as_list ('SUFFIXES'));
2947     }
2948     if (&target_defined ('.SUFFIXES'))
2949     {
2950         &am_line_error ('.SUFFIXES',
2951                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
2952     }
2954     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
2955     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
2956     # anything else, by sticking it right after the default: target.
2957     $output_header .= ".SUFFIXES:\n";
2958     if (@suffixes)
2959     {
2960         $output_header .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
2961     }
2962     $output_trailer .= &file_contents ('footer');
2965 # Deal with installdirs target.
2966 sub handle_installdirs
2968     # GNU Makefile standards recommend this.
2969     $output_rules .= ("installdirs:"
2970                       . ($recursive_install
2971                          ? " installdirs-recursive\n"
2972                          : "\n"));
2973     push (@phony, 'installdirs');
2974     if (@installdirs)
2975     {
2976         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
2977                             @installdirs);
2978     }
2979     $output_rules .= "\n";
2982 # There are several targets which need to be merged.  This is because
2983 # their complete definition is compiled from many parts.  Note that we
2984 # avoid double colon rules, otherwise we'd use them instead.
2985 sub handle_merge_targets
2987     # There are a few install-related variables that you should not define.
2988     local ($var);
2989     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
2990     {
2991         if (&variable_defined ($var))
2992         {
2993             &am_line_error ($var, "\`$var' should not be defined");
2994         }
2995     }
2997     push (@all, 'Makefile');
2998     push (@all, &basename ($config_name))
2999         if $config_name && &dirname ($config_name) eq $relative_dir;
3001     &do_one_merge_target ('info', @info);
3002     &do_one_merge_target ('dvi', @dvi);
3003     &do_check_merge_target;
3004     &do_one_merge_target ('installcheck', @installcheck);
3006     if (defined $options{'no-installinfo'})
3007     {
3008         # FIXME: this is kind of a hack; should find another way to
3009         # know that this is required.
3010         local (@dirs);
3011         if (grep ($_ eq 'install-info-am', @phony))
3012         {
3013             push (@dirs, 'install-info-am');
3014         }
3015         if (&variable_defined ('SUBDIRS'))
3016         {
3017             push (@dirs, 'install-info-recursive');
3018         }
3019         &do_one_merge_target ('install-info', @dirs);
3020     }
3022     # Handle the various install targets specially.  We do this so
3023     # that (eg) "make install-exec" will run "install-exec-recursive"
3024     # if required, but "make install" won't run it twice.  Step one is
3025     # to see if the user specified local versions of any of the
3026     # targets we handle.  "all" is treated as one of these since
3027     # "install" can run it.
3028     push (@install_exec, 'install-exec-local')
3029         if defined $contents{'install-exec-local'};
3030     push (@install_data, 'install-data-local')
3031         if defined $contents{'install-data-local'};
3032     push (@uninstall, 'uninstall-local')
3033         if defined $contents{'uninstall-local'};
3034     local ($utarg);
3035     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3036                     'uninstall-exec-local', 'uninstall-exec-hook')
3037     {
3038         if (defined $contents{$utarg})
3039         {
3040             local ($x);
3041             ($x = $utarg) =~ s/(data|exec)-//;
3042             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3043         }
3044     }
3045     push (@all, 'all-local')
3046         if defined $contents{'all-local'};
3048     if (defined $contents{'install-local'})
3049     {
3050         &am_line_error ('install-local',
3051                         "use \`install-data' or \`install-exec', not \`install'");
3052     }
3054     # Step two: if we are doing recursive makes, write out the
3055     # appropriate rules.
3056     local (@install);
3057     if ($recursive_install)
3058     {
3059         push (@install, 'install-recursive');
3061         if (@all)
3062         {
3063             local (@hackall) = ();
3064             if ($config_name && &dirname ($config_name) eq $relative_dir)
3065             {
3067                 # This is kind of a hack, but I couldn't see a better
3068                 # way to handle it.  In this particular case, we need
3069                 # to make sure config.h is built before we recurse.
3070                 # We can't do this by changing the order of
3071                 # dependencies to the "all" because that breaks when
3072                 # using parallel makes.  Instead we handle things
3073                 # explicitly.
3074                 $output_rules .= ('all-recursive-am: $(CONFIG_HEADER)'
3075                                   . "\n\t" . '$(MAKE) all-recursive'
3076                                   . "\n\n");
3077                 push (@hackall, 'all-recursive-am');
3078                 push (@phony, 'all-recursive-am');
3079             }
3080             else
3081             {
3082                 push (@hackall, 'all-recursive');
3083             }
3085             $output_rules .= ('all-am: '
3086                               . join (' ', @all)
3087                               . "\n\n");
3088             @all = @hackall;
3089             push (@all, 'all-am');
3090             push (@phony, 'all-am');
3091         }
3092         else
3093         {
3094             @all = ('all-recursive');
3096             # Must always generate `all-am' target, so it can be
3097             # referred to elsewhere.
3098             $output_rules .= "all-am:\n";
3099         }
3100         if (@install_exec)
3101         {
3102             $output_rules .= ('install-exec-am: '
3103                               . join (' ', @install_exec)
3104                               . "\n\n");
3105             @install_exec = ('install-exec-recursive', 'install-exec-am');
3106             push (@install, 'install-exec-am');
3107             push (@phony, 'install-exec-am');
3108         }
3109         else
3110         {
3111             @install_exec = ('install-exec-recursive');
3112         }
3113         if (@install_data)
3114         {
3115             $output_rules .= ('install-data-am: '
3116                               . join (' ', @install_data)
3117                               . "\n\n");
3118             @install_data = ('install-data-recursive', 'install-data-am');
3119             push (@install, 'install-data-am');
3120             push (@phony, 'install-data-am');
3121         }
3122         else
3123         {
3124             @install_data = ('install-data-recursive');
3125         }
3126         if (@uninstall)
3127         {
3128             $output_rules .= ('uninstall-am: '
3129                               . join (' ', @uninstall)
3130                               . "\n\n");
3131             @uninstall = ('uninstall-recursive', 'uninstall-am');
3132             push (@phony, 'uninstall-am');
3133         }
3134         else
3135         {
3136             @uninstall = ('uninstall-recursive');
3137         }
3138     }
3140     # Step three: print definitions users can use.  Code below knows
3141     # that install-exec is done before install-data, beware.
3142     $output_rules .= ("install-exec: "
3143                       . join (' ', @install_exec)
3144                       . "\n");
3145     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
3146     if (defined $contents{'install-exec-hook'})
3147     {
3148         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
3149     }
3150     $output_rules .= "\n";
3151     push (@install, 'install-exec') if !$recursive_install;
3152     push (@phony, 'install-exec');
3154     $output_rules .= ("install-data: "
3155                       . join (' ', @install_data)
3156                       . "\n");
3157     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
3158     if (defined $contents{'install-data-hook'})
3159     {
3160         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
3161     }
3162     $output_rules .= "\n";
3163     push (@install, 'install-data') if !$recursive_install;
3164     push (@phony, 'install-data');
3166     # If no dependencies for 'install', add 'all'.  Why?  That way
3167     # "make install" at top level of distclean'd distribution won't
3168     # fail because stuff in 'lib' fails to build.
3169     if (! @install || (scalar (@install) == 2
3170                        && $install[0] eq 'install-exec'
3171                        && $install[1] eq 'install-data'))
3172     {
3173         push (@install, 'all');
3174     }
3175     $output_rules .= ('install: '
3176                       . join (' ', @install)
3177                       # Use "@:" as empty command so nothing prints.
3178                       . "\n\t\@:"
3179                       . "\n\n"
3180                       . 'uninstall: '
3181                       . join (' ', @uninstall)
3182                       . "\n\n");
3183     push (@phony, 'install', 'uninstall');
3185     $output_rules .= ('all: '
3186                       . join (' ', @all)
3187                       . "\n\n");
3188     push (@phony, 'all');
3190     # Generate the new 'install-strip' target.
3191     $output_rules .= ("install-strip:\n\t"
3192                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
3193                       . "\n");
3196 # Helper for handle_merge_targets.
3197 sub do_one_merge_target
3199     local ($name, @values) = @_;
3201     if (defined $contents{$name . '-local'})
3202     {
3203         # User defined local form of target.  So include it.
3204         push (@values, $name . '-local');
3205         push (@phony, $name . '-local');
3206     }
3208     &pretty_print_rule ($name . ":", "\t\t", @values);
3209     push (@phony, $name);
3212 # Handle check merge target specially.
3213 sub do_check_merge_target
3215     if (defined $contents{'check-local'})
3216     {
3217         # User defined local form of target.  So include it.
3218         push (@check_tests, 'check-local');
3219         push (@phony, 'check-local');
3220     }
3222     if (! &variable_defined ('SUBDIRS'))
3223     {
3224         # 'check' must depend on `all', but not when doing recursive
3225         # build.
3226         unshift (@check, 'all');
3227     }
3228     else
3229     {
3230         # When subdirs are used, do the `all' build and then do all
3231         # the recursive stuff.  Actually use `all-am' because it
3232         # doesn't recurse; we rely on the check target in the subdirs
3233         # to do the required builds there.
3234         unshift (@check, 'all-am');
3235     }
3237     # The check target must depend on the local equivalent of `all',
3238     # to ensure all the primary targets are built.  Also it must
3239     # depend on the test code named in @check.
3240     &pretty_print_rule ('check:', "\t\t", @check);
3242     # Now the check rules must explicitly run anything named in
3243     # @check_tests.  This is done via a separate make invocation to
3244     # avoid problems with parallel makes.  Every time I write code
3245     # like this I wonder: how could you invent a parallel make and not
3246     # provide any real synchronization facilities?
3247     &pretty_print_rule ("\t\$(MAKE)", "\t  ", @check_tests);
3250 # Handle all 'clean' targets.
3251 sub handle_clean
3253     push (@clean, 'generic');
3254     $output_rules .= &file_contents ('clean');
3255     &push_phony_cleaners ('generic');
3257     local ($target) = $recursive_install ? 'clean-am' : 'clean';
3258     &do_one_clean_target ($target, 'mostly', '', @clean);
3259     &do_one_clean_target ($target, '', 'mostly', @clean);
3260     &do_one_clean_target ($target, 'dist', '', @clean);
3261     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
3263     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
3265     local (@deps);
3266     if ($recursive_install)
3267     {
3268         # Do -recursive before -am.  If you aren't doing a parallel
3269         # make, this can be nicer.
3270         @deps = ('recursive', 'am');
3271         &do_one_clean_target ('', 'mostly', '', @deps);
3272         &do_one_clean_target ('', '', '', @deps);
3273         &do_one_clean_target ('', 'dist', '', @deps);
3274         &do_one_clean_target ('', 'maintainer-', '', @deps);
3275     }
3278 # Helper for handle_clean.
3279 sub do_one_clean_target
3281     local ($target, $name, $last_name, @deps) = @_;
3283     # Special case: if target not passed, then don't generate
3284     # dependency on next "lower" clean target (eg no
3285     # clean<-mostlyclean derivation).  In this case the target is
3286     # implicitly known to be 'clean'.
3287     local ($flag) = $target;
3288     $target = 'clean' if ! $flag;
3290     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
3291     if ($flag)
3292     {
3293         if ($last_name || $name ne 'mostly')
3294         {
3295             push (@deps, $last_name . $target);
3296         }
3297     }
3299     # If a -local version of the rule is given, add it to the list.
3300     if (defined $contents{$name . $target . '-local'})
3301     {
3302         push (@deps, $name . $target . '-local');
3303     }
3305     # Print the target and the dependencies.
3306     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
3308     # FIXME: shouldn't we really print these messages before running
3309     # the dependencies?
3310     if ($name . $target eq 'maintainer-clean')
3311     {
3312         # Print a special warning.
3313         $output_rules .=
3314             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
3315              . "\t\@echo \"it deletes files that may require special "
3316              . "tools to rebuild.\"\n");
3318         $output_rules .= "\trm -f config.status\n"
3319             if $relative_dir eq '.';
3320     }
3321     elsif ($name . $target eq 'distclean')
3322     {
3323         $output_rules .= "\trm -f config.status\n";
3324         $output_rules .= "\trm -f libtool\n" if $seen_libtool;
3325     }
3326     $output_rules .= "\n";
3329 # Handle .PHONY target.
3330 sub handle_phony
3332     &pretty_print_rule ('.PHONY:', "", @phony);
3333     $output_rules .= "\n";
3336 # Handle TESTS variable and other checks.
3337 sub handle_tests
3339     if (defined $options{'dejagnu'})
3340     {
3341         push (@check_tests, 'check-DEJAGNU');
3342         push (@phony, 'check-DEJAGNU');
3344         local ($xform);
3345         if ($cygnus_mode)
3346         {
3347             $xform = 's/^CYGNUS//;';
3348         }
3349         else
3350         {
3351             $xform = 's/^CYGNUS.*$//;';
3352         }
3353         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
3355         # In Cygnus mode, these are found in the build tree.
3356         # Otherwise they are looked for in $PATH.
3357         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
3358         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
3360         # Note that in the rule we don't directly generate site.exp to
3361         # avoid the possibility of a corrupted site.exp if make is
3362         # interrupted.  Jim Meyering has some useful text on this
3363         # topic.
3364         $output_rules .= ("site.exp: Makefile\n"
3365                           . "\t\@echo 'Making a new site.exp file...'\n"
3366                           . "\t-\@rm -f site.bak\n"
3367                           . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
3368                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
3369                           . "\t\@echo '# edit the last section' >> \$\@-t\n"
3370                           . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
3371                           . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
3372                           . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
3374         # Extra stuff for AC_CANONICAL_*
3375         local (@whatlist) = ();
3376         if ($seen_canonical)
3377         {
3378             push (@whatlist, 'host')
3379         }
3381         # Extra stuff only for AC_CANONICAL_SYSTEM.
3382         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
3383         {
3384             push (@whatlist, 'target', 'build');
3385         }
3387         local ($c1, $c2);
3388         foreach $c1 (@whatlist)
3389         {
3390             foreach $c2 ('alias', 'triplet')
3391             {
3392                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
3393             }
3394         }
3396         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
3397                           . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
3398                           . "\t-\@mv site.exp site.bak\n"
3399                           . "\t\@mv \$\@-t site.exp\n");
3400     }
3401     else
3402     {
3403         local ($c);
3404         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
3405         {
3406             if (&variable_defined ($c))
3407             {
3408                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
3409             }
3410         }
3411     }
3413     if (&variable_defined ('TESTS'))
3414     {
3415         push (@check_tests, 'check-TESTS');
3416         push (@phony, 'check-TESTS');
3418         $output_rules .= 'check-TESTS: $(TESTS)
3419         @failed=0; all=0; \\
3420         srcdir=$(srcdir); export srcdir; \\
3421         for tst in $(TESTS); do \\
3422           all=`expr $$all + 1`; \\
3423           if test -f $$tst; then dir=.; \\
3424           else dir="$(srcdir)"; fi; \\
3425           if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
3426             echo "PASS: $$tst"; \\
3427           else \\
3428             failed=`expr $$failed + 1`; \\
3429             echo "FAIL: $$tst"; \\
3430           fi; \\
3431         done; \\
3432         if test "$$failed" -eq 0; then \\
3433           echo "========================"; \\
3434           echo "All $$all tests passed"; \\
3435           echo "========================"; \\
3436         else \\
3437           echo "$$failed of $$all tests failed"; \\
3438           exit 1; \\
3439         fi
3441     }
3444 # Handle Emacs Lisp.
3445 sub handle_emacs_lisp
3447     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
3449     if (@elfiles)
3450     {
3451         # Found some lisp.
3452         &define_configure_variable ('lispdir');
3453         &define_configure_variable ('EMACS');
3454         $output_rules .= (".el.elc:\n"
3455                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
3456                           . "\tif test \$(EMACS) != no; then \\\n"
3457                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
3458                           . "\tfi\n");
3459         push (@suffixes, '.el', '.elc');
3461         # Generate .elc files.
3462         grep ($_ .= 'c', @elfiles);
3463         &define_pretty_variable ('ELCFILES', @elfiles);
3465         push (@clean, 'lisp');
3466         &push_phony_cleaners ('lisp');
3468         push (@all, '$(ELCFILES)');
3470         local ($varname);
3471         if (&variable_defined ('lisp_LISP'))
3472         {
3473             $varname = 'lisp_LISP';
3474             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
3475                 if ! $seen_lispdir;
3476         }
3477         else
3478         {
3479             $varname = 'noinst_LISP';
3480         }
3482         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
3483     }
3486 ################################################################
3488 # Scan one file for interesting things.  Subroutine of scan_configure.
3489 sub scan_one_configure_file
3491     local ($filename) = @_;
3493     open (CONFIGURE, $filename)
3494         || die "automake: couldn't open \`$filename': $!\n";
3495     print "automake: reading $filename\n" if $verbose;
3497     while (<CONFIGURE>)
3498     {
3499         # Remove comments from current line.
3500         s/\bdnl\b.*$//;
3501         s/\#.*$//;
3503         # Skip macro definitions.  Otherwise we might be confused into
3504         # thinking that a macro that was only defined was actually
3505         # used.
3506         next if /AC_DEFUN/;
3508         # Populate libobjs array.
3509         if (/AC_FUNC_ALLOCA/)
3510         {
3511             $libsources{'alloca.c'} = 1;
3512         }
3513         elsif (/AC_FUNC_GETLOADAVG/)
3514         {
3515             $libsources{'getloadavg.c'} = 1;
3516         }
3517         elsif (/AC_FUNC_MEMCMP/)
3518         {
3519             $libsources{'memcmp.c'} = 1;
3520         }
3521         elsif (/AC_STRUCT_ST_BLOCKS/)
3522         {
3523             $libsources{'fileblocks.c'} = 1;
3524         }
3525         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
3526         {
3527             $libsources{'getopt.c'} = 1;
3528             $libsources{'getopt1.c'} = 1;
3529         }
3530         elsif (/AM_FUNC_STRTOD/)
3531         {
3532             $libsources{'strtod.c'} = 1;
3533         }
3534         elsif (/AM_WITH_REGEX/)
3535         {
3536             $libsources{'rx.c'} = 1;
3537             $libsources{'rx.h'} = 1;
3538             $libsources{'regex.c'} = 1;
3539             $libsources{'regex.h'} = 1;
3540             $omit_dependencies{'rx.h'} = 1;
3541             $omit_dependencies{'regex.h'} = 1;
3542         }
3543         elsif (/AM_FUNC_MKTIME/)
3544         {
3545             $libsources{'mktime.c'} = 1;
3546         }
3547         elsif (/AM_FUNC_ERROR_AT_LINE/)
3548         {
3549             $libsources{'error.c'} = 1;
3550             $libsources{'error.h'} = 1;
3551         }
3552         elsif (/AM_FUNC_OBSTACK/)
3553         {
3554             $libsources{'obstack.c'} = 1;
3555             $libsources{'obstack.h'} = 1;
3556         }
3557         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
3558                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
3559         {
3560             foreach $libobj_iter (split (' ', $1))
3561             {
3562                 if ($libobj_iter =~ /^(.*)\.o$/)
3563                 {
3564                     $libsources{$1 . '.c'} = 1;
3565                 }
3566             }
3567         }
3569         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
3570         {
3571             $in_ac_replace = 1;
3572         }
3573         if ($in_ac_replace)
3574         {
3575             $in_ac_replace = 0 if s/[\]\)].*$//;
3576             # Remove trailing backslash.
3577             s/\\$//;
3578             foreach (split)
3579             {
3580                 # Need to skip empty elements for Perl 4.
3581                 next if $_ eq '';
3582                 $libsources{$_ . '.c'} = 1;
3583             }
3584         }
3586         if (/$obsolete_rx/o)
3587         {
3588             local ($hint) = '';
3589             if ($obsolete_macros{$1})
3590             {
3591                 $hint = '; ' . $obsolete_macros{$1};
3592             }
3593             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
3594         }
3596         # Process the AC_OUTPUT macro.
3597         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
3598         {
3599             $in_ac_output = 1;
3600             $ac_output_line = $.;
3601         }
3602         if ($in_ac_output)
3603         {
3604             $in_ac_output = 0 if s/[\]\),].*$//;
3606             # Look at potential Makefile.am's.
3607             foreach (split)
3608             {
3609                 next if $_ eq "\\";
3611                 # Handle $local:$input syntax.  Note that we ignore
3612                 # every input file past the first, though we keep
3613                 # those around for later.
3614                 local ($local, $input, @rest) = split (/:/);
3615                 if (! $input)
3616                 {
3617                     $input = $local;
3618                 }
3619                 else
3620                 {
3621                     # FIXME: should be error if .in is missing.
3622                     $input =~ s/\.in$//;
3623                 }
3625                 if (-f $input . '.am')
3626                 {
3627                     # We have a file that automake should generate.
3628                     push (@make_input_list, $input);
3629                     $make_list{$input} = join (':', ($local, @rest));
3630                 }
3631                 else
3632                 {
3633                     # We have a file that automake should cause to be
3634                     # rebuilt, but shouldn't generate itself.
3635                     push (@other_input_files, $_);
3636                 }
3637             }
3638         }
3640         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
3641         {
3642             @config_aux_path = $1;
3643         }
3645         # Check for ansi2knr.
3646         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
3648         # Check for Cygwin32.
3649         if (/AM_CYGWIN32/)
3650         {
3651             $seen_cygwin32 = 1;
3652             $configure_vars{'EXEEXT'} = 1;
3653         }
3655         # Check for NLS support.
3656         if (/AM_GNU_GETTEXT/)
3657         {
3658             $seen_gettext = 1;
3659             $ac_gettext_line = $.;
3660             $omit_dependencies{'libintl.h'} = 1;
3661         }
3663         # Look for ALL_LINGUAS.
3664         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
3665         {
3666             $seen_linguas = 1;
3667             $all_linguas = $1;
3668             $all_linguas_line = $.;
3669         }
3671         # Handle configuration headers.  A config header of `[$1]'
3672         # means we are actually scanning AM_CONFIG_HEADER from
3673         # aclocal.m4.
3674         if (/A([CM])_CONFIG_HEADER\s*\((.*)\)/
3675             && $2 ne '[$1]')
3676         {
3677             &am_conf_line_error
3678                 ($filename, $.,
3679                  "\`AC_CONFIG_HEADER' is obsolete; use \`AM_CONFIG_HEADER'")
3680                     if $1 eq 'C';
3682             $config_header_line = $.;
3683             $config_name = $2;
3684             if ($config_name =~ /^([^:]+):(.+)$/)
3685             {
3686                 $config_name = $1;
3687                 $config_header = $2;
3688             }
3689             else
3690             {
3691                 $config_header = $config_name . '.in';
3692             }
3693         }
3695         # Handle AC_CANONICAL_*.  Always allow upgrading to
3696         # AC_CANONICAL_SYSTEM, but never downgrading.
3697         $seen_canonical = $AC_CANONICAL_HOST
3698             if ! $seen_canonical
3699                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
3700         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
3702         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
3704         # This macro handles several different things.
3705         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
3706         {
3707             $seen_make_set = 1;
3708             $seen_package = 1;
3709             $seen_version = 1;
3710             $seen_arg_prog = 1;
3711             $seen_prog_install = 2;
3712             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
3713             $package_version_line = $.;
3714         }
3716         # This is like AM_INIT_AUTOMAKE, but doesn't actually set the
3717         # package and version number.  (This might change in the
3718         # future).  Yes, I'm not above hacking Automake so it works
3719         # well with other GNU tools -- that is actually the point.
3720         if (/AM_INIT_GUILE_MODULE/)
3721         {
3722             $seen_make_set = 1;
3723             $seen_package = 1;
3724             $seen_version = 1;
3725             $seen_arg_prog = 1;
3726             $seen_prog_install = 2;
3727             @config_aux_path = ('..');
3728         }
3730         # Some things required by Automake.
3731         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
3732         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
3734         if (/AC_PROG_(YACC|RANLIB|CC|CXX|LEX)/)
3735         {
3736             $configure_vars{$1} = 1;
3737         }
3738         if (/$AC_CHECK_PATTERN/o)
3739         {
3740             $configure_vars{$3} = 1;
3741         }
3742         if (/$AC_SUBST_PATTERN/o)
3743         {
3744             $configure_vars{$1} = 1;
3745         }
3747         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
3748         $seen_maint_mode = 1 if /AM_MAINTAINER_MODE/;
3749         $seen_package = 1 if /PACKAGE=/;
3751         # Skip VERSION of [$2]; that is from AM_INIT_AUTOMAKE.
3752         if (/\bVERSION=(\S+)/ && $1 ne '[$2]')
3753         {
3754             $seen_version = 1;
3755             $package_version = $1;
3756             $package_version_line = $.;
3757         }
3758         elsif (/VERSION=/)
3759         {
3760             $seen_version = 1;
3761         }
3763         # Weird conditionals here because it is always allowed to
3764         # upgrade to AM_PROG_INSTALL but never to downgrade to
3765         # AC_PROG_INSTALL.
3766         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
3767         $seen_prog_install = 2 if /AM_PROG_INSTALL/;
3769         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
3771         if (/AM_PROG_LIBTOOL/)
3772         {
3773             $seen_libtool = 1;
3774             $libtool_line = $.;
3775             $configure_vars{'LIBTOOL'} = 1;
3776             $configure_vars{'RANLIB'} = 1;
3777             $configure_vars{'CC'} = 1;
3778             # AM_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
3779             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
3780             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
3781         }
3782     }
3784     close (CONFIGURE);
3787 # Scan configure.in and aclocal.m4 for interesting things.  We must
3788 # scan aclocal.m4 because there might be AC_SUBSTs and such there.
3789 sub scan_configure
3791     # Reinitialize libsources here.  This isn't really necessary,
3792     # since we currently assume there is only one configure.in.  But
3793     # that won't always be the case.
3794     %libsources = ();
3796     local ($in_ac_output, $in_ac_replace) = (0, 0);
3797     local (%make_list, @make_input_list);
3798     local ($libobj_iter);
3800     &scan_one_configure_file ('configure.in');
3801     &scan_one_configure_file ('aclocal.m4')
3802         if -f 'aclocal.m4';
3804     # Set input and output files if not specified by user.
3805     if (! @input_files)
3806     {
3807         @input_files = @make_input_list;
3808         %output_files = %make_list;
3809     }
3811     &am_conf_error ("\`PACKAGE' not defined in configure.in")
3812         if ! $seen_package;
3813     &am_conf_error ("\`VERSION' not defined in configure.in")
3814         if ! $seen_version;
3816     # Look for some files we need.  Always check for these.  This
3817     # check must be done for every run, even those where we are only
3818     # looking at a subdir Makefile.  We must set relative_dir so that
3819     # the file-finding machinery works.
3820     local ($relative_dir) = '.';
3821     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
3822     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
3823         if -f $config_aux_path[0] . '/install.sh';
3826 ################################################################
3828 # Set up for Cygnus mode.
3829 sub check_cygnus
3831     return unless $cygnus_mode;
3833     &set_strictness ('foreign');
3834     $options{'no-installinfo'} = 1;
3835     $options{'no-dependencies'} = 1;
3836     $use_dependencies = 0;
3838     if (! $seen_maint_mode)
3839     {
3840         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
3841     }
3843     if (! $seen_cygwin32)
3844     {
3845         &am_conf_error ("\`AM_CYGWIN32' required when --cygnus specified");
3846     }
3849 # Do any extra checking for GNU standards.
3850 sub check_gnu_standards
3852     if ($relative_dir eq '.')
3853     {
3854         # In top level (or only) directory.
3855         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
3856                        'AUTHORS', 'ChangeLog');
3857     }
3859     if ($strictness >= $GNU)
3860     {
3861         if (defined $options{'no-installman'})
3862         {
3863             &am_line_error ('AUTOMAKE_OPTIONS',
3864                             "option \`no-installman' disallowed by GNU standards");
3865         }
3867         if (defined $options{'no-installinfo'})
3868         {
3869             &am_line_error ('AUTOMAKE_OPTIONS',
3870                             "option \`no-installinfo' disallowed by GNU standards");
3871         }
3872     }
3875 # Do any extra checking for GNITS standards.
3876 sub check_gnits_standards
3878     if ($strictness >= $GNITS)
3879     {
3880         if (-f $relative_dir . '/COPYING.LIB')
3881         {
3882             &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
3883         }
3885         if ($relative_dir eq '.')
3886         {
3887             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
3888             {
3889                 # FIXME: allow real filename.
3890                 &am_conf_line_error ('configure.in',
3891                                      $package_version_line,
3892                                      "version \`$package_version' doesn't follow Gnits standards");
3893             }
3894             elsif (defined $1 && -f 'README-alpha')
3895             {
3896                 # This means we have an alpha release.  See
3897                 # GNITS_VERSION_PATTERN for details.
3898                 &require_file ($GNITS, 'README-alpha');
3899             }
3900         }
3901     }
3903     if ($relative_dir eq '.')
3904     {
3905         # In top level (or only) directory.
3906         &require_file ($GNITS, 'THANKS');
3907     }
3910 ################################################################
3912 # Pretty-print something.  HEAD is what should be printed at the
3913 # beginning of the first line, FILL is what should be printed at the
3914 # beginning of every subsequent line.
3915 sub pretty_print_internal
3917     local ($head, $fill, @values) = @_;
3919     local ($column) = length ($head);
3920     local ($result) = $head;
3922     # Fill length is number of characters.  However, each Tab
3923     # character counts for eight.  So we count the number of Tabs and
3924     # multiply by 7.
3925     local ($fill_length) = length ($fill);
3926     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
3928     local ($bol) = ($head eq '');
3929     foreach (@values)
3930     {
3931         # "71" because we also print a space.
3932         if ($column + length ($_) > 71)
3933         {
3934             $result .= " \\\n" . $fill;
3935             $column = $fill_length;
3936             $bol = 1;
3937         }
3939         $result .= ' ' unless ($bol);
3940         $result .= $_;
3941         $column += length ($_) + 1;
3942         $bol = 0;
3943     }
3945     $result .= "\n";
3946     return $result;
3949 # Pretty-print something and append to output_vars.
3950 sub pretty_print
3952     $output_vars .= &pretty_print_internal (@_);
3955 # Pretty-print something and append to output_rules.
3956 sub pretty_print_rule
3958     $output_rules .= &pretty_print_internal (@_);
3962 ################################################################
3964 # See if a target exists.
3965 sub target_defined
3967     local ($target) = @_;
3968     return defined $targets{$target};
3971 # See if a variable exists.
3972 sub variable_defined
3974     local ($var) = @_;
3975     if (defined $targets{$var})
3976     {
3977         &am_line_error ($var, "\`$var' is target; expected variable");
3978         return 0;
3979     }
3980     elsif (defined $contents{$var})
3981     {
3982         $content_seen{$var} = 1;
3983         return 1;
3984     }
3985     return 0;
3988 # Mark a variable as examined.
3989 sub examine_variable
3991     local ($var) = @_;
3992     &variable_defined ($var);
3995 # Return contents of variable as list, split as whitespace.  This will
3996 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
3997 # substitutions.  If PARENT is specified, it is the name of the
3998 # including variable; this is only used for error reports.
3999 sub variable_value_as_list
4001     local ($var, $parent) = @_;
4002     local (@result);
4004     if (defined $targets{$var})
4005     {
4006         &am_line_error ($var, "\`$var' is target; expected variable");
4007     }
4008     elsif (! defined $contents{$var})
4009     {
4010         &am_line_error ($parent, "variable \`$var' not defined");
4011     }
4012     else
4013     {
4014         local (@temp_list);
4015         $content_seen{$var} = 1;
4016         foreach (split (' ', $contents{$var}))
4017         {
4018             # If a comment seen, just leave.
4019             last if /^#/;
4021             # Handle variable substitutions.
4022             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
4023             {
4024                 local ($varname) = $1;
4025                 local ($from, $to);
4026                 if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
4027                 {
4028                     $varname = $1;
4029                     $to = $3;
4030                     ($from = $2) =~ s/(\W)/\\$1/g;
4031                 }
4033                 # Find the value.
4034                 @temp_list = &variable_value_as_list ($1, $var);
4036                 # Now rewrite the value if appropriate.
4037                 if ($from)
4038                 {
4039                     grep (s/$from$/$to/, @temp_list);
4040                 }
4042                 push (@result, @temp_list);
4043             }
4044             else
4045             {
4046                 push (@result, $_);
4047             }
4048         }
4049     }
4051     return @result;
4054 # Define a new variable, but only if not already defined.
4055 sub define_variable
4057     local ($var, $value) = @_;
4059     if (! defined $contents{$var})
4060     {
4061         $output_vars .= $var . ' = ' . $value . "\n";
4062         $contents{$var} = $value;
4063         $content_seen{$var} = 1;
4064     }
4067 # Like define_variable, but second arg is a list, and is
4068 # pretty-printed.
4069 sub define_pretty_variable
4071     local ($var, @value) = @_;
4072     if (! defined $contents{$var})
4073     {
4074         $contents{$var} = join (' ', @value);
4075         &pretty_print ($var . ' = ', '', @value);
4076         $content_seen{$var} = 1;
4077     }
4080 # Like define_variable, but define a variable to be the configure
4081 # substitution by the same name.
4082 sub define_configure_variable
4084     local ($var) = @_;
4085     local ($value) = '@' . $var . '@';
4086     &define_variable ($var, $value);
4089 # Define a variable that represents a program to run.  If in Cygnus
4090 # mode, the program is searched for in the build (or source) tree.
4091 # Otherwise no searching is done at all.  Arguments are:
4092 # * VAR      Name of variable to define
4093 # * WHATDIR  Either `src' or `build', depending on where program should
4094 #            be found.  (runtest is in srcdir!)
4095 # * SUBDIR   Subdir of top-level dir
4096 # * PROGRAM  Name of program
4097 sub define_program_variable
4099     local ($var, $whatdir, $subdir, $program) = @_;
4101     if ($cygnus_mode)
4102     {
4103         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
4104                          . $subdir . '/' . $program);
4105         &define_variable ($var, ('`if test -f ' . $full
4106                                  . '; then echo ' . $full . '; else echo '
4107                                  . $program . '; fi`'));
4108     }
4109     else
4110     {
4111         &define_variable ($var, $program);
4112     }
4116 ################################################################
4118 # Read Makefile.am and set up %contents.  Simultaneously copy lines
4119 # from Makefile.am into $output_trailer or $output_vars as
4120 # appropriate.  NOTE we put rules in the trailer section.  We want
4121 # user rules to come after our generated stuff.
4122 sub read_am_file
4124     local ($amfile) = @_;
4126     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
4127     print "automake: reading $amfile\n" if $verbose;
4129     $output_vars = ("# $in_file_name generated automatically by automake "
4130                     . $VERSION . " from $am_file_name\n");
4132     # Generate copyright for generated Makefile.in.
4133     $output_vars .= $gen_copyright;
4135     local ($saw_bk) = 0;
4136     local ($was_rule) = 0;
4137     local ($spacing) = '';
4138     local ($comment) = '';
4139     local ($last_var_name) = '';
4140     local ($blank) = 0;
4142     while (<AM_FILE>)
4143     {
4144         if (/$IGNORE_PATTERN/o)
4145         {
4146             # Merely delete comments beginning with two hashes.
4147         }
4148         elsif (/$WHITE_PATTERN/o)
4149         {
4150             # Stick a single white line before the incoming macro or rule.
4151             $spacing = "\n";
4152             $blank = 1;
4153         }
4154         elsif (/$COMMENT_PATTERN/o)
4155         {
4156             # Stick comments before the incoming macro or rule.  Make
4157             # sure a blank line preceeds first block of comments.
4158             $spacing = "\n" unless $blank;
4159             $blank = 1;
4160             $comment .= $spacing . $_;
4161             $spacing = '';
4162         }
4163         else
4164         {
4165             last;
4166         }
4167     }
4169     $output_vars .= $comment . "\n";
4170     $comment = '';
4171     $spacing = "\n";
4172     local ($am_vars) = '';
4174     local ($is_ok_macro);
4175     while ($_)
4176     {
4177         $_ .= "\n"
4178             unless substr ($_, -1, 1) eq "\n";
4180         $_ =~ s/\@MAINT\@//g
4181             unless $seen_maint_mode;
4183         if (/$IGNORE_PATTERN/o)
4184         {
4185             # Merely delete comments beginning with two hashes.
4186         }
4187         elsif (/$WHITE_PATTERN/o)
4188         {
4189             # Stick a single white line before the incoming macro or rule.
4190             $spacing = "\n";
4191         }
4192         elsif (/$COMMENT_PATTERN/o)
4193         {
4194             # Stick comments before the incoming macro or rule.
4195             $comment .= $spacing . $_;
4196             $spacing = '';
4197         }
4198         elsif ($saw_bk)
4199         {
4200             if ($was_rule)
4201             {
4202                 $output_trailer .= $_;
4203                 $saw_bk = /\\$/;
4204             }
4205             else
4206             {
4207                 $am_vars .= $_;
4208                 $saw_bk = /\\$/;
4209                 # Chop newline and backslash if this line is
4210                 # continued.  FIXME: maybe ensure trailing whitespace
4211                 # exists?
4212                 chop if $saw_bk;
4213                 chop if $saw_bk;
4214                 $contents{$last_var_name} .= $_;
4215             }
4216         }
4217         elsif (/$RULE_PATTERN/o)
4218         {
4219             # warn "** Saw rule .$1.\n";
4220             # Found a rule.
4221             $was_rule = 1;
4222             # Value here doesn't matter; for targets we only note
4223             # existence.
4224             $contents{$1} = 1;
4225             $targets{$1} = 1;
4226             $content_lines{$1} = $.;
4227             $output_trailer .= $comment . $spacing . $_;
4228             $comment = $spacing = '';
4229             $saw_bk = /\\$/;
4230         }
4231         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
4232                || /$BOGUS_MACRO_PATTERN/o)
4233         {
4234             # Found a macro definition.
4235             $was_rule = 0;
4236             $last_var_name = $1;
4237             if ($2 ne '' && substr ($2, -1) eq "\\")
4238             {
4239                 $contents{$1} = substr ($2, 0, length ($2) - 1);
4240             }
4241             else
4242             {
4243                 $contents{$1} = $2;
4244             }
4245             $content_lines{$1} = $.;
4246             $am_vars .= $comment . $spacing . $_;
4247             $comment = $spacing = '';
4248             $saw_bk = /\\$/;
4250             # Error if bogus.
4251             &am_line_error ($., "bad macro name \`$1'")
4252                 if ! $is_ok_macro;
4253         }
4254         else
4255         {
4256             # This isn't an error; it is probably a continued rule.
4257             # In fact, this is what we assume.
4258             $was_rule = 1;
4259             $output_trailer .= $comment . $spacing . $_;
4260             $comment = $spacing = '';
4261             $saw_bk = /\\$/;
4262         }
4264         $_ = <AM_FILE>;
4265     }
4267     $output_trailer .= $comment;
4269     # Compute relative location of the top object directory.
4270     local (@topdir) = ();
4271     foreach (split (/\//, $relative_dir))
4272     {
4273         next if $_ eq '.' || $_ eq '';
4274         if ($_ eq '..')
4275         {
4276             pop @topdir;
4277         }
4278         else
4279         {
4280             push (@topdir, '..');
4281         }
4282     }
4283     @topdir = ('.') if ! @topdir;
4285     $top_builddir = join ('/', @topdir);
4286     local ($build_rx);
4287     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
4288     $output_vars .= &file_contents_with_transform
4289                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
4290                          'header-vars');
4292     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
4293     # this should use generic %configure_vars method.
4294     if ($seen_canonical)
4295     {
4296         local ($curs, %vars);
4297         $vars{'host_alias'} = 'host_alias';
4298         $vars{'host_triplet'} = 'host';
4299         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
4300         {
4301             $vars{'build_alias'} = 'build_alias';
4302             $vars{'build_triplet'} = 'build';
4303             $vars{'target_alias'} = 'target_alias';
4304             $vars{'target_triplet'} = 'target';
4305         }
4306         foreach $curs (sort keys %vars)
4307         {
4308             $output_vars .= "$curs = \@$vars{$curs}\@\n";
4309             $contents{$curs} = "\@$vars{$curs}\@";
4310         }
4311     }
4313     local ($curs);
4314     foreach $curs (sort keys %configure_vars)
4315     {
4316         &define_configure_variable ($curs);
4317     }
4319     $output_vars .= $am_vars;
4322 ################################################################
4324 sub initialize_global_constants
4326     # Values for AC_CANONICAL_*
4327     $AC_CANONICAL_HOST = 1;
4328     $AC_CANONICAL_SYSTEM = 2;
4330     # Associative array of standard directory names.  Entry is TRUE if
4331     # corresponding directory should be installed during
4332     # 'install-exec' phase.
4333     %exec_dir_p =
4334         ('bin', 1,
4335          'sbin', 1,
4336          'libexec', 1,
4337          'data', 0,
4338          'sysconf', 1,
4339          'localstate', 1,
4340          'lib', 1,
4341          'info', 0,
4342          'man', 0,
4343          'include', 0,
4344          'oldinclude', 0,
4345          'pkgdata', 0,
4346          'pkglib', 1,
4347          'pkginclude', 0
4348          );
4350     # Helper text for dealing with man pages.
4351     $install_man_format =
4352     '   @sect=@SECTION@;                                \\
4353         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
4354         if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
4355         else file=@MAN@; fi; \\
4356         echo " $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst"; \\
4357         $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst
4360     $uninstall_man_format =
4361     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
4362         rm -f $(mandir)/man@SECTION@/$$inst
4365     # Commonly found files we look for and automatically include in
4366     # DISTFILES.
4367     @common_files =
4368         (
4369          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
4370          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
4371          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
4372          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
4373          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
4374          'interlock', 'ylwrap', 'acinclude.m4', @libtoolize_files,
4375          'missing'
4376          );
4378     # Commonly used files we auto-include, but only sometimes.
4379     @common_sometimes =
4380         (
4381          "aclocal.m4", "acconfig.h", "config.h.top",
4382          "config.h.bot", "stamp-h.in", 'stamp-vti'
4383          );
4385     $USAGE = "\
4386   -a, --add-missing     add missing standard files to package
4387   --amdir=DIR           directory storing config files
4388   --build-dir=DIR       directory where build being done (for dependencies)
4389   --cygnus              assume program is part of Cygnus-style tree
4390   --foreign             set strictness to foreign
4391   --gnits               set strictness to gnits
4392   --gnu                 set strictness to gnu
4393   --help                print this help, then exit
4394   -i, --include-deps    include generated dependencies in Makefile.in
4395   --no-force            only update Makefile.in's that are out of date
4396   -o DIR, --output-dir=DIR
4397                         put generated Makefile.in's into DIR
4398   --srcdir-name=DIR     name used for srcdir (for dependencies)
4399   -v, --verbose         verbosely list files processed
4400   --version             print version number, then exit\n";
4402     # Copyright on generated Makefile.ins.
4403     $gen_copyright = "\
4404 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
4405 # This Makefile.in is free software; the Free Software Foundation
4406 # gives unlimited permission to copy, distribute and modify it.
4409     # Ignore return result from chmod, because it might give an error
4410     # if we chmod a symlink.
4411     $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
4412     $dist{'tarZ'} = ("\t"
4413                      . '$(TAR) chf - $(distdir) | compress -c > $(distdir).tar.Z'
4414                      . "\n");
4415     $dist{'shar'} = ("\t"
4416                      . 'shar $(distdir) | gzip > $(distdir).shar.gz'
4417                      . "\n");
4418     $dist{'zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
4419     $dist{'dist'} = "\t" .  'GZIP=$(GZIP) $(TAR) chozf $(distdir).tar.gz $(distdir)' . "\n";
4420     $dist_trailer = "\t" . 'rm -rf $(distdir)' . "\n";
4423 # (Re)-Initialize per-Makefile.am variables.
4424 sub initialize_per_input
4426     # These two variables are used when generating each Makefile.in.
4427     # They hold the Makefile.in until it is ready to be printed.
4428     $output_rules = '';
4429     $output_vars = '';
4430     $output_trailer = '';
4431     $output_header = '';
4433     # Suffixes found during a run.
4434     @suffixes = ();
4436     # This holds the contents of a Makefile.am, as parsed by
4437     # read_am_file.
4438     %contents = ();
4440     # This holds the names which are targets.  These also appear in
4441     # %contents.
4442     %targets = ();
4444     # This holds the line numbers at which various elements of
4445     # %contents are defined.
4446     %content_lines = ();
4448     # This holds a 1 if a particular variable was examined.
4449     %content_seen = ();
4451     # This holds the "relative directory" of the current Makefile.in.
4452     # Eg for src/Makefile.in, this is "src".
4453     $relative_dir = '';
4455     # This holds a list of files that are included in the
4456     # distribution.
4457     %dist_common = ();
4459     # List of dependencies for the obvious targets.
4460     @install_data = ();
4461     @install_exec = ();
4462     @uninstall = ();
4463     @installdirs = ();
4465     @info = ();
4466     @dvi = ();
4467     @all = ();
4468     @check = ();
4469     @check_tests = ();
4470     @installcheck = ();
4471     @clean = ();
4473     @phony = ();
4475     # These are pretty obvious, too.  They are used to define the
4476     # SOURCES and OBJECTS variables.
4477     @sources = ();
4478     @objects = ();
4480     # TRUE if current directory holds any C source files.
4481     $dir_holds_sources = 0;
4483     # These variables track inclusion of various compile-related .am
4484     # files.  $included_generic_compile is TRUE if the basic code has
4485     # been included.  $included_knr_compile is TRUE if the ansi2knr
4486     # code has been included.  $included_libtool_compile is TRUE if
4487     # libtool support has been included.
4488     $included_generic_compile = 0;
4489     $included_knr_compile = 0;
4490     $included_libtool_compile = 0;
4492     # TRUE if current directory holds any headers.
4493     $dir_holds_headers = 0;
4495     # TRUE if install targets should work recursively.
4496     $recursive_install = 0;
4498     # All .P files.
4499     %dep_files = ();
4501     # Strictness levels.
4502     $strictness = $default_strictness;
4503     $strictness_name = $default_strictness_name;
4505     # Options from AUTOMAKE_OPTIONS.
4506     %options = ();
4508     # Whether or not dependencies are handled.  Can be further changed
4509     # in handle_options.
4510     $use_dependencies = $cmdline_use_dependencies;
4512     # Per Makefile.am.
4513     $local_maint_charset = $maint_charset;
4515     # All yacc and lex source filenames for this directory.  Use
4516     # filenames instead of raw count so that multiple instances are
4517     # counted correctly (eg one yacc file can appear in multiple
4518     # programs without harm).
4519     %yacc_sources = ();
4520     %lex_sources = ();
4522     # C++ source extensions we've seen.
4523     %cxx_extensions = ();
4525     # TRUE if we've seen any non-C++ sources.  This actually holds a
4526     # line number or the name of a symbol corresponding to a line
4527     # number where the C sources were seen.  If it is -1 then it means
4528     # we couldn't (easily) figure out which line of the Makefile.am
4529     # mentioned the sources.
4530     $seen_c_source = 0;
4532     # This is a list of all targets to run during "make dist".
4533     @dist_targets = ();
4535     # Keys in this hash are the names of ._o files which must depend
4536     # on ansi2knr.  Ugh.
4537     %de_ansi_objects = ();
4541 ################################################################
4543 # Return contents of a file from $am_dir, automatically skipping
4544 # macros or rules which are already known.  Runs command on each line
4545 # as it is read; this command can modify $_.
4546 sub file_contents_with_transform
4548     local ($command, $basename) = @_;
4549     local ($file) = $am_dir . '/' . $basename . '.am';
4551     if ($command ne '' && substr ($command, -1) ne ';')
4552     {
4553         die "automake: programming error in file_contents_with_transform\n";
4554     }
4556     open (FC_FILE, $file)
4557         || die "automake: installation error: cannot open \`$file'\n";
4558     # Looks stupid?
4559     # print "automake: reading $file\n" if $verbose;
4561     local ($was_rule) = 0;
4562     local ($result_vars) = '';
4563     local ($result_rules) = '';
4564     local ($comment) = '';
4565     local ($spacing) = "\n";
4566     local ($skipping) = 0;
4567     local ($had_chars);
4569     while (<FC_FILE>)
4570     {
4571         $_ =~ s/\@MAINT\@//g
4572             unless $seen_maint_mode;
4574         $had_chars = length ($_);
4575         eval $command;
4576         # If the transform caused all the characters to go away, then
4577         # ignore the line.  Why do this?  Because in Perl 4, a "next"
4578         # inside of an eval doesn't affect a loop outside the eval.
4579         # So we can't pass in a "transform" that uses next.  We used
4580         # to do this.
4581         next if $had_chars && $_ eq '';
4583         if (/$IGNORE_PATTERN/o)
4584         {
4585             # Merely delete comments beginning with two hashes.
4586         }
4587         elsif (/$WHITE_PATTERN/o)
4588         {
4589             # Stick a single white line before the incoming macro or rule.
4590             $spacing = "\n";
4591         }
4592         elsif (/$COMMENT_PATTERN/o)
4593         {
4594             # Stick comments before the incoming macro or rule.
4595             $comment .= $spacing . $_;
4596             $spacing = '';
4597         }
4598         elsif ($saw_bk)
4599         {
4600             if ($was_rule)
4601             {
4602                 $result_rules .= $_ if ! $skipping;
4603             }
4604             else
4605             {
4606                 $result_vars .= $_ if ! $skipping;
4607             }
4608             $saw_bk = /\\$/;
4609         }
4610         elsif (/$RULE_PATTERN/o)
4611         {
4612             # warn "** Found rule .$1.\n";
4613             # Found a rule.
4614             $was_rule = 1;
4615             $skipping = defined $contents{$1};
4616             # warn "** Skip $skipping\n" if $skipping;
4617             $result_rules .= $comment . $spacing . $_ if ! $skipping;
4618             $comment = $spacing = '';
4619             $saw_bk = /\\$/;
4620         }
4621         elsif (/$MACRO_PATTERN/o)
4622         {
4623             # warn "** Found macro .$1.\n";
4624             # Found a variable reference.
4625             $was_rule = 0;
4626             $skipping = defined $contents{$1};
4627             # warn "** Skip $skipping\n" if $skipping;
4628             $result_vars .= $comment . $spacing . $_ if ! $skipping;
4629             $comment = $spacing = '';
4630             $saw_bk = /\\$/;
4631         }
4632         else
4633         {
4634             # This isn't an error; it is probably a continued rule.
4635             # In fact, this is what we assume.
4636             $was_rule = 1;
4637             $result_rules .= $comment . $spacing . $_ if ! $skipping;
4638             $comment = $spacing = '';
4639             $saw_bk = /\\$/;
4640         }
4641     }
4643     close (FC_FILE);
4644     return $result_vars . $result_rules . $comment;
4647 # Like file_contents_with_transform, but no transform.
4648 sub file_contents
4650     return &file_contents_with_transform ('', @_);
4653 # Find all variable prefixes that are used for install directories.  A
4654 # prefix `zar' qualifies iff:
4655 # * `zardir' is a variable.
4656 # * `zar_PRIMARY' is a variable.
4657 sub am_primary_prefixes
4659     local ($primary, @prefixes) = @_;
4661     local (%valid, $varname);
4662     grep ($valid{$_} = 0, @prefixes);
4663     $valid{'EXTRA'} = 0;
4664     foreach $varname (keys %contents)
4665     {
4666         if ($varname =~ /^(.*)_$primary$/)
4667         {
4668             if (! defined $valid{$1}
4669                 && ! &variable_defined ($1 . 'dir')
4670                 # Note that a configure variable is always legitimate.
4671                 # It is natural to name such variables after the
4672                 # primary, so we explicitly allow it.
4673                 && ! defined $configure_vars{$varname})
4674             {
4675                 &am_line_error ($varname, "invalid variable \"$varname\"");
4676             }
4677             else
4678             {
4679                 # Ensure all extended prefixes are actually used.
4680                 $valid{$1} = 1;
4681             }
4682         }
4683     }
4685     return %valid;
4688 # Handle `where_HOW' variable magic.  Does all lookups, generates
4689 # install code, and possibly generates code to define the primary
4690 # variable.  The first argument is the name of the .am file to munge,
4691 # the second argument is the primary variable (eg HEADERS), and all
4692 # subsequent arguments are possible installation locations.  Returns
4693 # list of all values of all _HOW targets.
4695 # FIXME: this should be rewritten to be cleaner.  It should be broken
4696 # up into multiple functions.
4698 # Usage is: am_install_var (OPTION..., file, HOW, where...)
4699 sub am_install_var
4701     local (@args) = @_;
4703     local ($do_clean) = 0;
4705     local ($ltxform);
4706     if (defined $configure_vars{'LIBTOOL'})
4707     {
4708         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
4709         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
4710     }
4711     else
4712     {
4713         # Delete '@LIBTOOL ...@'
4714         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
4715     }
4717     local ($cygxform);
4718     if (! $seen_cygwin32)
4719     {
4720         $cygxform = 's/\@EXEEXT\@//g; s/^NOTCYGWIN.*$//;';
4721     }
4722     else
4723     {
4724         $cygxform .= 's/^CYGWIN.*$//;';
4725     }
4727     while (@args)
4728     {
4729         if ($args[0] eq '-clean')
4730         {
4731             $do_clean = 1;
4732         }
4733         elsif ($args[0] !~ /^-/)
4734         {
4735             last;
4736         }
4737         shift (@args);
4738     }
4739     local ($file, $primary, @prefixes) = @args;
4741     local (@used) = ();
4742     local (@result) = ();
4744     # Now that configure substitutions are allowed in where_HOW
4745     # variables, it is an error to actually define the primary.
4746     &am_line_error ($primary, "\`$primary' is an anachronism")
4747         if &variable_defined ($primary);
4750     # Look for misspellings.  It is an error to have a variable ending
4751     # in a "reserved" suffix whose prefix is unknown, eg
4752     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
4753     # variable of the same name (with "dir" appended) exists.  For
4754     # instance, if the variable "zardir" is defined, then
4755     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
4756     # flexibility in those cases which need it.  Perhaps it should be
4757     # disallowed in the Gnits case?  The problem is, sometimes it is
4758     # useful to put things in a subdir of eg pkgdatadir, perhaps even
4759     # for Gnitsoids.
4760     local (%valid) = &am_primary_prefixes ($primary, @prefixes);
4762     # If a primary includes a configure substitution, then the EXTRA_
4763     # form is required.  Otherwise we can't properly do our job.
4764     local ($require_extra);
4765     local ($warned_about_extra) = 0;
4767     local ($clean_file) = $file . '-clean';
4768     local ($one_name);
4769     local ($X);
4770     foreach $X (sort keys %valid)
4771     {
4772         $one_name = $X . '_' . $primary;
4773         if (&variable_defined ($one_name))
4774         {
4775             # Append actual contents of where_PRIMARY variable to
4776             # result.
4777             local ($rcurs);
4778             foreach $rcurs (&variable_value_as_list ($one_name))
4779             {
4780                 # Skip configure substitutions.  Possibly bogus.
4781                 if ($rcurs =~ /^\@.*\@$/)
4782                 {
4783                     if ($X eq 'EXTRA')
4784                     {
4785                         if (! $warned_about_extra)
4786                         {
4787                             $warned_about_extra = 1;
4788                             &am_line_error ($one_name,
4789                                             "\`$one_name' contains configure substitution, but shouldn't");
4790                         }
4791                     }
4792                     # Check here to make sure variables defined in
4793                     # configure.in do not imply that EXTRA_PRIMARY
4794                     # must be defined.
4795                     elsif (! defined $configure_vars{$one_name})
4796                     {
4797                         $require_extra = $one_name;
4798                     }
4799                     next;
4800                 }
4801                 push (@result, $rcurs);
4802             }
4804             # "EXTRA" shouldn't be used when generating clean targets,
4805             # @all, or install targets.
4806             next if $X eq 'EXTRA';
4808             if ($do_clean)
4809             {
4810                 $output_rules .=
4811                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
4812                                                    . $cygxform,
4813                                                    $clean_file);
4815                 push (@clean, $X . $primary);
4816                 &push_phony_cleaners ($X . $primary);
4817             }
4819             if ($X eq 'check')
4820             {
4821                 push (@check, '$(' . $one_name . ')');
4822             }
4823             else
4824             {
4825                 push (@used, '$(' . $one_name . ')');
4826             }
4827             if ($X eq 'noinst' || $X eq 'check')
4828             {
4829                 # Objects which don't get installed by default.
4830                 next;
4831             }
4833             $output_rules .=
4834                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
4835                                                . $ltxform . $cygxform,
4836                                                $file);
4838             push (@uninstall, 'uninstall-' . $X . $primary);
4839             push (@phony, 'uninstall-' . $X . $primary);
4840             push (@installdirs, '$(' . $X . 'dir)');
4841             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
4842             {
4843                 push (@install_exec, 'install-' . $X . $primary);
4844                 push (@phony, 'install-' . $X . $primary);
4845             }
4846             else
4847             {
4848                 push (@install_data, 'install-' . $X . $primary);
4849                 push (@phony, 'install-' . $X . $primary);
4850             }
4851         }
4852     }
4854     if (@used)
4855     {
4856         # Define it.
4857         &define_pretty_variable ($primary, @used);
4858         $output_vars .= "\n";
4859     }
4861     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
4862     {
4863         &am_line_error ($require_extra,
4864                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
4865     }
4867     # Push here because PRIMARY might be configure time determined.
4868     push (@all, '$(' . $primary . ')')
4869         if @used;
4871     return (@result);
4875 ################################################################
4877 # This variable is local to the "require file" set of functions.
4878 @require_file_paths = ();
4880 # Verify that the file must exist in the current directory.  Usage:
4881 # require_file (isconfigure, line_number, strictness, file) strictness
4882 # is the strictness level at which this file becomes required.  Must
4883 # set require_file_paths before calling this function.
4884 # require_file_paths is set to hold a single directory (the one in
4885 # which the first file was found) before return.
4886 sub require_file_internal
4888     local ($is_configure, $line, $mystrict, @files) = @_;
4889     local ($file, $fullfile);
4890     local ($found_it, $errfile, $errdir);
4891     local ($save_dir);
4893     foreach $file (@files)
4894     {
4895         $found_it = 0;
4896         foreach $dir (@require_file_paths)
4897         {
4898             if ($dir eq '.')
4899             {
4900                 $fullfile = $relative_dir . "/" . $file;
4901                 $errdir = $relative_dir unless $errdir;
4902             }
4903             else
4904             {
4905                 $fullfile = $dir . "/" . $file;
4906                 $errdir = $dir unless $errdir;
4907             }
4909             # Use different name for "error filename".  Otherwise on
4910             # an error the bad file will be reported as eg
4911             # `../../install-sh' when using the default
4912             # config_aux_path.
4913             $errfile = $errdir . '/' . $file;
4915             if (-f $fullfile)
4916             {
4917                 $found_it = 1;
4918                 # FIXME: Once again, special-case `.'.
4919                 &push_dist_common ($file)
4920                     if $dir eq $relative_dir || $dir eq '.';
4921                 $save_dir = $dir;
4922                 last;
4923             }
4924         }
4926         if ($found_it)
4927         {
4928             # Prune the path list.
4929             @require_file_paths = $save_dir;
4930         }
4931         else
4932         {
4933             if ($strictness >= $mystrict)
4934             {
4935                 local ($trailer) = '';
4936                 local ($suppress) = 0;
4938                 # Only install missing files according to our desired
4939                 # strictness level.
4940                 if ($add_missing)
4941                 {
4942                     $trailer = "; installing";
4943                     $suppress = 1;
4945                     # Maybe run libtoolize.
4946                     if ($seen_libtool
4947                         && grep ($_ eq $file, @libtoolize_files)
4948                         && system ('libtoolize', '--automake'))
4949                     {
4950                         $suppress = 0;
4951                         $trailer .= "; cannot run \`libtoolize': $!";
4952                     }
4953                     elsif (-f ($am_dir . '/' . $file))
4954                     {
4955                         # Install the missing file.  Symlink if we
4956                         # can, copy if we must.  Note: delete the file
4957                         # first, in case it is a dangling symlink.
4958                         unlink ($errfile);
4959                         if ($symlink_exists)
4960                         {
4961                             if (! symlink ($am_dir . '/' . $file, $errfile))
4962                             {
4963                                 $suppress = 0;
4964                                 $trailer .= "; error while making link: $!\n";
4965                             }
4966                         }
4967                         elsif (! system ('cp', $am_dir . '/' . $file, $errfile))
4968                         {
4969                             $suppress = 0;
4970                             $trailer .= "\n    error while making link\n";
4971                         }
4972                     }
4973                 }
4975                 local ($save) = $exit_status;
4976                 if ($is_configure)
4977                 {
4978                     # FIXME: allow actual file to be specified.
4979                     &am_conf_line_error
4980                         ('configure.in', $line,
4981                          "required file \"$errfile\" not found$trailer");
4982                 }
4983                 else
4984                 {
4985                     &am_line_error
4986                         ($line,
4987                          "required file \"$errfile\" not found$trailer");
4988                 }
4989                 $exit_status = $save if $suppress;
4990             }
4991         }
4992     }
4995 # Like require_file_with_line, but error messages refer to
4996 # configure.in, not the current Makefile.am.
4997 sub require_file_with_conf_line
4999     @require_file_paths = '.';
5000     &require_file_internal (1, @_);
5003 sub require_file_with_line
5005     @require_file_paths = '.';
5006     &require_file_internal (0, @_);
5009 sub require_file
5011     @require_file_paths = '.';
5012     &require_file_internal (0, '', @_);
5015 # Require a file that is also required by Autoconf.  Looks in
5016 # configuration path, as specified by AC_CONFIG_AUX_DIR.
5017 sub require_config_file
5019     @require_file_paths = @config_aux_path;
5020     &require_file_internal (1, '', @_);
5021     local ($dir) = $require_file_paths[0];
5022     @config_aux_path = @require_file_paths;
5023     if ($dir eq '.')
5024     {
5025         $config_aux_dir = '.';
5026     }
5027     else
5028     {
5029         $config_aux_dir = '$(top_srcdir)/' . $dir;
5030     }
5033 # Assumes that the line number is in Makefile.am.
5034 sub require_conf_file_with_line
5036     @require_file_paths = @config_aux_path;
5037     &require_file_internal (0, @_);
5038     local ($dir) = $require_file_paths[0];
5039     @config_aux_path = @require_file_paths;
5040     if ($dir eq '.')
5041     {
5042         $config_aux_dir = '.';
5043     }
5044     else
5045     {
5046         $config_aux_dir = '$(top_srcdir)/' . $dir;
5047     }
5050 # Assumes that the line number is in Makefile.am.
5051 sub require_conf_file_with_conf_line
5053     @require_file_paths = @config_aux_path;
5054     &require_file_internal (1, @_);
5055     local ($dir) = $require_file_paths[0];
5056     @config_aux_path = @require_file_paths;
5057     if ($dir eq '.')
5058     {
5059         $config_aux_dir = '.';
5060     }
5061     else
5062     {
5063         $config_aux_dir = '$(top_srcdir)/' . $dir;
5064     }
5067 ################################################################
5069 # Push a list of files onto dist_common.
5070 sub push_dist_common
5072     local (@files) = @_;
5073     local ($file);
5075     foreach $file (@files)
5076     {
5077         $dist_common{$file} = 1;
5078     }
5081 # Push a list of clean targets onto phony.
5082 sub push_phony_cleaners
5084     local ($base) = @_;
5085     local ($target);
5086     foreach $target ('mostly', 'dist', '', 'maintainer-')
5087     {
5088         push (@phony, $target . 'clean-' . $base);
5089     }
5092 # Set strictness.
5093 sub set_strictness
5095     $strictness_name = $_[0];
5096     if ($strictness_name eq 'gnu')
5097     {
5098         $strictness = $GNU;
5099     }
5100     elsif ($strictness_name eq 'gnits')
5101     {
5102         $strictness = $GNITS;
5103     }
5104     elsif ($strictness_name eq 'foreign')
5105     {
5106         $strictness = $FOREIGN;
5107     }
5108     else
5109     {
5110         die "automake: level \`$strictness_name' not recognized\n";
5111     }
5115 ################################################################
5117 # Return directory name of file.
5118 sub dirname
5120     local ($file) = @_;
5121     local ($sub);
5123     ($sub = $file) =~ s,/+[^/]+$,,g;
5124     $sub = '.' if $sub eq $file;
5125     return $sub;
5128 # Return file name of a file.
5129 sub basename
5131     local ($file) = @_;
5132     local ($sub);
5134     ($sub = $file) =~s,^.*/+,,g;
5135     return $sub;
5138 # Touch a file.
5139 sub touch
5141     local ($file) = @_;
5143     open (TOUCH, ">> $file");
5144     close (TOUCH);
5147 # Glob something.  Do this to avoid indentation screwups everywhere we
5148 # want to glob.  Gross!
5149 sub my_glob
5151     local ($pat) = @_;
5152     return <${pat}>;
5155 ################################################################
5157 # Print an error message and set exit status.
5158 sub am_error
5160     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
5161     $exit_status = 1;
5164 sub am_line_error
5166     local ($symbol, @args) = @_;
5168     if ($symbol && "$symbol" ne '-1')
5169     {
5170         # If SYMBOL not already a line number, look it up in Makefile.am.
5171         if ($symbol =~ /^\d+$/)
5172         {
5173             $symbol .= ': ';
5174         }
5175         elsif (defined $content_lines{$symbol})
5176         {
5177             $symbol = $content_lines{$symbol} . ': ';
5178         }
5179         else
5180         {
5181             # A single space, to provide nice separation.
5182             $symbol = ' ';
5183         }
5184         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
5185         $exit_status = 1;
5186     }
5187     else
5188     {
5189         &am_error (@args);
5190     }
5193 # Like am_error, but while scanning configure.in.
5194 sub am_conf_error
5196     # FIXME: can run in subdirs.
5197     warn "automake: configure.in: ", join (' ', @_), "\n";
5198     $exit_status = 1;
5201 # Error message with line number referring to configure.in.
5202 sub am_conf_line_error
5204     local ($file, $line, @args) = @_;
5206     if ($line)
5207     {
5208         warn "$file: $line: ", join (' ', @args), "\n";
5209         $exit_status = 1;
5210     }
5211     else
5212     {
5213         &am_conf_error (@args);
5214     }
5217 # Tell user where our aclocal.m4 is, but only once.
5218 sub keyed_aclocal_warning
5220     local ($key) = @_;
5221     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
5224 # Print usage information.
5225 sub usage
5227     print "Usage: automake [OPTION] ... [Makefile]...\n";
5228     print $USAGE;
5229     print "\nFiles which are automatically distributed, if found:\n";
5230     $~ = "USAGE_FORMAT";
5231     local (@lcomm) = sort ((@common_files, @common_sometimes));
5232     local ($one, $two, $three, $four);
5233     while (@lcomm > 0)
5234     {
5235         $one = shift @lcomm;
5236         $two = @lcomm ? shift @lcomm : '';
5237         $three = @lcomm ? shift @lcomm : '';
5238         $four = @lcomm ? shift @lcomm : '';
5239         write;
5240     }
5242     print "\nReport bugs to <automake-bugs\@gnu.ai.mit.edu>\n";
5244     exit 0;
5247 format USAGE_FORMAT =
5248   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
5249   $one,               $two,               $three,             $four