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