ba81419378759bb8c62c6d21a48d3cdfd63967ba
[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 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@drip.colorado.edu>.
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
37 # String constants.
38 $IGNORE_PATTERN = "^##([^#].*)?\$";
39 $WHITE_PATTERN = "^[ \t]*\$";
40 $COMMENT_PATTERN = "^#";
41 $RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/]*) *:([^=].*|)\$";
42 $MACRO_PATTERN = "^([A-Za-z][A-Za-z0-9_]*)[ \t]*:?=[ \t]*(.*)\$";
43 $BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*:?=[ \t]*(.*)\$";
44 $GNITS_VERSION_PATTERN = "[0-9]+\\.[0-9]+([a-z]|\\.[0-9]+)?";
45
46 # Some regular expressions.  One reason to put them here is that it
47 # makes indentation work better in Emacs.
48 $AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
49 $AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^)]+)\\)";
50
51 # Constants to define the "strictness" level.
52 $FOREIGN = 0;
53 $GNU = 1;
54 $GNITS = 2;
55
56 \f
57
58 # Variables global to entire run.
59
60 # TRUE if we should always generate Makefile.in.
61 $force_generation = 1;
62
63 # Strictness level as set on command line.
64 $default_strictness = $GNU;
65
66 # Name of strictness level, as set on command line.
67 $default_strictness_name = 'gnu';
68
69 # This is TRUE if GNU make specific automatic dependency generation
70 # code should be included in generated Makefile.in.
71 $cmdline_use_dependencies = 1;
72
73 # TRUE if in verbose mode.
74 $verbose = 0;
75
76 # This holds our (eventual) exit status.  We don't actually exit until
77 # we have processed all input files.
78 $exit_status = 0;
79
80 # From the Perl manual.
81 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
82
83 # TRUE if missing standard files should be installed.
84 $add_missing = 0;
85
86 # Files found by scanning configure.in for LIBOBJS.
87 %libsources = ();
88
89 # True if AM_C_PROTOTYPES appears in configure.in.
90 $am_c_prototypes = 0;
91
92 # Names used in AC_CONFIG_HEADER call.  $config_name is the actual
93 # (first) argument.  $config_header is the '.in' file.  Ordinarily the
94 # second is derived from the first, but they can be different if the
95 # weird "NAME:FILE" syntax is used.
96 $config_name = '';
97 $config_header = '';
98 # Line number at which AC_CONFIG_HEADER appears in configure.in.
99 $config_header_line = 0;
100
101 # Directory where output files go.  Actually, output files are
102 # relative to this directory.
103 $output_directory = '.';
104
105 # Relative location of top build directory.
106 $top_builddir = '';
107
108 # Absolute location of top build directory.
109 $build_directory = '';
110
111 # Name of srcdir as given in build directory's Makefile.  For
112 # dependencies only.
113 $srcdir_name = '';
114
115 # List of Makefile.am's to process.
116 @input_files = ();
117
118 # List of files in AC_OUTPUT without Makefile.am.
119 @other_input_files = ();
120 # Line number at which AC_OUTPUT seen.
121 $ac_output_line = 0;
122
123 # List of directories to search for configure-required files.  This
124 # can be set by AC_CONFIG_AUX_DIR.
125 @config_aux_path = ('.', '..', '../..');
126 $config_aux_dir = '';
127
128 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
129 $seen_make_set = 0;
130
131 # Whether ud_GNU_GETTEXT has been seen in configure.in.
132 $seen_gettext = 0;
133 # Line number at which ud_GNU_GETTEXT seen.
134 $ac_gettext_line = 0;
135
136 # Whether ALL_LINGUAS has been seen.
137 $seen_linguas = '';
138 # The actual text.
139 $all_linguas = '';
140 # Line number at which it appears.
141 $all_linguas_line = 0;
142
143 # 1 if AC_PROG_INSTALL seen, 2 if AM_PROG_INSTALL seen.
144 $seen_prog_install = 0;
145
146 # 1 if any scripts installed, 0 otherwise.
147 $scripts_installed = 0;
148
149 # Whether AC_PATH_XTRA has been seen in configure.in.
150 $seen_path_xtra = 0;
151
152 # Whether YACC variable has been seen in configure.in.
153 $seen_prog_yacc = 0;
154
155 # Two variables to control lex use.  One is for AC_DECL_YYTEXT and the
156 # other is for AC_PROG_LEX.
157 $seen_decl_yytext = 0;
158 $seen_prog_lex = 0;
159
160 # TRUE if we've seen AC_PROG_CC.
161 $seen_prog_cc = 0;
162
163 # TRUE if we've seen AC_PROG_CXX.
164 $seen_prog_cxx = 0;
165
166 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
167 # AC_CHECK_TOOL also sets this.
168 $seen_canonical = 0;
169
170 # TRUE if we've seen AC_PROG_RANLIB.
171 $seen_ranlib = 0;
172
173 # TRUE if we've seen AC_ARG_PROGRAM.
174 $seen_arg_prog = 0;
175
176 # TRUE if we've seen AM_PROG_LIBTOOL.
177 $seen_libtool = 0;
178 $libtool_line = 0;
179
180 # TRUE if we've seen AM_MAINTAINER_MODE.
181 $seen_maint_mode = 0;
182
183 # TRUE if we've seen PACKAGE and VERSION.
184 $seen_package = 0;
185 $seen_version = 0;
186
187 # Actual version we've seen.
188 $package_version = '';
189
190 # Line number where we saw version definition.
191 $package_version_line = 0;
192
193 # TRUE if we've seen AM_PATH_LISPDIR.
194 $seen_lispdir = 0;
195
196
197 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
198 # handled in a funny way: if seen in the top-level Makefile.am, it is
199 # used for every directory which does not specify a different value.
200 # The rationale here is that some directories (eg gettext) might be
201 # distributions of other packages, and thus require their own charset
202 # info.  However, the DIST_CHARSET must be the same for the entire
203 # package; it can only be set at top-level.
204 # FIXME: this yields bugs when rebuilding.  What to do?  Always
205 # read (and sometimes discard) top-level Makefile.am?
206 $maint_charset = '';
207 $dist_charset = 'utf8';         # recode doesn't support this yet.
208
209 # Name of input file ("Makefile.in") and output file ("Makefile.am").
210 # These have no directory components.
211 $am_file_name = '';
212 $in_file_name = '';
213
214 \f
215
216 &initialize_global_constants;
217
218 # Parse command line.
219 &parse_arguments (@ARGV);
220
221 # Do configure.in scan only once.
222 &scan_configure;
223
224 die "automake: no \`Makefile.am' found or specified\n"
225     if ! @input_files;
226
227 # Now do all the work on each file.
228 foreach $am_file (@input_files)
229 {
230     # FIXME: should support the AC_OUTPUT ":" syntax here.
231     if (! -f ($am_file . '.am'))
232     {
233         &am_error ('no such file');
234     }
235     else
236     {
237         &generate_makefile ($am_file);
238     }
239 }
240
241 if ($seen_prog_install <= $scripts_installed)
242 {
243     &am_conf_error (($scripts_installed ? 'AM_PROG_INSTALL' : 'AC_PROG_INSTALL')
244                     . " must be used in configure.in");
245     &keyed_aclocal_warning ('AM_PROG_INSTALL')
246         if $scripts_installed;
247 }
248
249 exit $exit_status;
250
251
252 ################################################################
253
254 # Parse command line.
255 sub parse_arguments
256 {
257     local (@arglist) = @_;
258
259     # Start off as gnu.
260     &set_strictness ('gnu');
261
262     while (@arglist)
263     {
264         if ($arglist[0] eq "--version")
265         {
266             print "automake (GNU $PACKAGE) $VERSION\n";
267             print "Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.\n";
268             print "automake comes with ABSOLUTELY NO WARRANTY.\n";
269             print "You may redistribute copies of automake\n";
270             print "under the terms of the GNU General Public License.\n";
271             print "For more information about these matters, see the file named COPYING.\n";
272             exit 0;
273         }
274         elsif ($arglist[0] eq "--help")
275         {
276             &usage;
277         }
278         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
279         {
280             $am_dir = $1;
281         }
282         elsif ($arglist[0] eq '--amdir')
283         {
284             &require_argument (@arglist);
285             shift (@arglist);
286             $am_dir = $arglist[0];
287         }
288         elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
289         {
290             # Must end in /.
291             $build_directory = $1 . '/';
292         }
293         elsif ($arglist[0] eq '--build-dir')
294         {
295             &require_argument (@arglist);
296             shift (@arglist);
297             # Must end in /.
298             $build_directory = $arglist[0] . '/';
299         }
300         elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
301         {
302             $srcdir_name = $1;
303         }
304         elsif ($arglist[0] eq '--srcdir-name')
305         {
306             &require_argument (@arglist);
307             shift (@arglist);
308             $srcdir_name = $arglist[0];
309         }
310         elsif ($arglist[0] =~ /^--strictness=(.+)$/)
311         {
312             &set_strictness ($1);
313         }
314         elsif ($arglist[0] eq '--gnu')
315         {
316             &set_strictness ('gnu');
317         }
318         elsif ($arglist[0] eq '--gnits')
319         {
320             &set_strictness ('gnits');
321         }
322         elsif ($arglist[0] eq '--foreign')
323         {
324             &set_strictness ('foreign');
325         }
326         elsif ($arglist[0] eq '--strictness' || $arglist[0] eq '-s')
327         {
328             &require_argument (@arglist);
329             shift (@arglist);
330             &set_strictness ($arglist[0]);
331         }
332         elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
333         {
334             $cmdline_use_dependencies = 0;
335         }
336         elsif ($arglist[0] eq '--no-force')
337         {
338             $force_generation = 0;
339         }
340         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
341         {
342             # Set output directory.
343             $output_directory = $1;
344         }
345         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
346         {
347             &require_argument (@arglist);
348             shift (@arglist);
349             $output_directory = $arglist[0];
350         }
351         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
352         {
353             $add_missing = 1;
354         }
355         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
356         {
357             $verbose = 1;
358         }
359         elsif ($arglist[0] eq '--')
360         {
361             # Stop option processing.
362             shift (@arglist);
363             push (@input_files, @arglist);
364             last;
365         }
366         elsif ($arglist[0] =~ /^-/)
367         {
368             die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
369         }
370         else
371         {
372             push (@input_files, $arglist[0]);
373         }
374
375         shift (@arglist);
376     }
377
378     # Take global strictness from whatever we currently have set.
379     $default_strictness = $strictness;
380     $default_strictness_name = $strictness_name;
381 }
382
383 # Ensure argument exists, or die.
384 sub require_argument
385 {
386     local ($arg, @arglist) = @_;
387     die "automake: no argument given for option \`$arg'\n"
388         if ! @arglist;
389 }
390
391 ################################################################
392
393 # Generate a Makefile.in given the name of the corresponding Makefile.
394 sub generate_makefile
395 {
396     local ($makefile) = @_;
397
398     ($am_file_name = $makefile) =~ s/^.*\///;
399     $in_file_name = $am_file_name . '.in';
400     $am_file_name .= '.am';
401
402     &initialize_per_input;
403     $relative_dir = &dirname ($makefile);
404
405     # At the toplevel directory, we might need config.guess, config.sub
406     # or libtool.
407     if ($relative_dir eq '.')
408     {
409         # libtool requires some files.
410         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
411                                            'config.sub', 'config.guess',
412                                            'libtool') if $seen_libtool;
413
414         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
415         # config.sub.
416         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
417             if $seen_canonical;
418     }
419
420     # We still need Makefile.in here, because sometimes the `dist'
421     # target doesn't re-run automake.
422     &push_dist_common ($in_file_name, $am_file_name);
423     push (@sources, '$(SOURCES)')
424         if &variable_defined ('SOURCES');
425     push (@objects, '$(OBJECTS)')
426         if &variable_defined ('OBJECTS');
427
428     # This is always the default target.  This gives us freedom to do
429     # things in whatever order is convenient.
430     $output_rules .= "default: all\n\n";
431     push (@phony, 'default');
432
433     &read_am_file ($makefile . '.am');
434     if (&handle_options)
435     {
436         # Fatal error.  Just return, so we can continue with next file.
437         return;
438     }
439
440     # Check first, because we might modify some state.
441     &check_gnu_standards;
442     &check_gnits_standards;
443
444     &handle_configure;
445     &handle_gettext;
446     &handle_libraries;
447     &handle_programs;
448     &handle_scripts;
449
450     # This must be run after all the sources are scanned.
451     &handle_yacc_lex_cxx;
452
453     # This is here for lack of a better place to put it.
454     if (&variable_defined ('BUILT_SOURCES'))
455     {
456         push (@all, '$(BUILT_SOURCES)');
457     }
458
459     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
460     # on this (but currently does).
461     $contents{'SOURCES'} = join (' ', @sources);
462     $contents{'OBJECTS'} = join (' ', @objects);
463
464     &handle_texinfo;
465     &handle_emacs_lisp;
466     &handle_man_pages;
467     &handle_data;
468     &handle_headers;
469     &handle_subdirs;
470     &handle_tags;
471     &handle_dist;
472     &handle_dependencies;
473     &handle_tests;
474     &handle_footer;
475     &handle_merge_targets;
476     &handle_installdirs;
477     &handle_clean;
478     &handle_phony;
479
480     &check_typos;
481
482     if (! -d ($output_directory . '/' . $relative_dir))
483     {
484         mkdir ($output_directory . '/' . $relative_dir, 0755);
485     }
486
487     local ($out_file) = $output_directory . '/' . $makefile . ".in";
488     if (! $force_generation && -e $out_file)
489     {
490         local ($am_time) = (stat ($makefile . '.am'))[9];
491         local ($in_time) = (stat ($out_file))[9];
492         # FIXME: how to do unsigned comparison?
493         if ($am_time < $in_time)
494         {
495             # No need to update.
496             return;
497         }
498     }
499
500     if (! open (GM_FILE, "> " . $out_file))
501     {
502         warn "automake: ${am_file}.in: cannot open: $!\n";
503         $exit_status = 1;
504         return;
505     }
506     print "automake: creating ", $makefile, ".in\n" if $verbose;
507
508     print GM_FILE $output_vars;
509     print GM_FILE $output_rules;
510     print GM_FILE $output_trailer;
511
512     close (GM_FILE);
513 }
514
515 ################################################################
516
517 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
518 sub handle_options
519 {
520     return 0 if ! &variable_defined ('AUTOMAKE_OPTIONS');
521
522     foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS'))
523     {
524         $options{$_} = 1;
525         if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
526         {
527             &set_strictness ($_);
528         }
529         elsif (/ansi2knr/)
530         {
531             # An option like "../lib/ansi2knr" is allowed.  With no
532             # path prefix, we assume the required programs are in this
533             # directory.  We save the actual option for later.
534             $options{'ansi2knr'} = $_;
535         }
536         elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
537                || $_ eq 'dist-shar' || $_ eq 'dist-zip'
538                || $_ eq 'dist-tarZ' || $_ eq 'dejagnu')
539         {
540             # Explicitly recognize these.
541         }
542         elsif ($_ eq 'no-dependencies')
543         {
544             $use_dependencies = 0;
545         }
546         elsif (/([0-9]+)\.([0-9]+)/)
547         {
548             # Got a version number.  Note that alpha releases count as
549             # the next higher release.  Note also that we assume there
550             # will be a maximum of 100 minor releases for any given
551             # major release.
552             local ($rmajor, $rminor) = ($1, $2);
553             if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
554             {
555                 print STDERR
556                     "automake: programming error: version is incorrect\n";
557                 exit 1;
558             }
559             local ($tmajor, $tminor) = ($1, $2);
560             # Handle alpha versions.
561             ++$tminor if defined $3;
562
563             if ($rmajor > $tmajor || ($rmajor == $tmajor && $rminor > $tminor))
564             {
565                 &am_line_error ('AUTOMAKE_OPTIONS',
566                                 "require version $_, only have $VERSION");
567                 return 1;
568             }
569         }
570         else
571         {
572             &am_line_error ('AUTOMAKE_OPTIONS',
573                             'option ', $_, 'not recognized');
574         }
575     }
576
577     return 0;
578 }
579
580 # Return object extension.  Just once, put some code into the output.
581 sub get_object_extension
582 {
583     if (! $dir_holds_sources)
584     {
585         # Boilerplate.
586         local ($xform) = '';
587         if (&variable_defined ('CONFIG_HEADER'))
588         {
589             ($xform = &dirname ($contents{'CONFIG_HEADER'}))
590                 =~ s/(\W)/\\$1/g;
591             $xform = '-I' . $xform;
592         }
593         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go';
594         $output_vars .= &file_contents_with_transform ($xform,
595                                                        'comp-vars');
596         $output_rules .= &file_contents ('compile');
597         &push_phony_cleaners ('compile');
598
599         # If using X, include some extra variable definitions.  NOTE
600         # we don't want to force these into CFLAGS or anything,
601         # because not all programs will necessarily use X.
602         if ($seen_path_xtra)
603         {
604             local ($var);
605             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
606             {
607                 &define_variable ($var, "\@$var\@");
608             }
609         }
610
611         # Check for automatic de-ANSI-fication.
612         $dir_holds_sources = '.o';
613         push (@suffixes, '.c', '.o');
614         push (@clean, 'compile');
615
616         if (defined $options{'ansi2knr'})
617         {
618             if (! $am_c_prototypes)
619             {
620                 &am_line_error ('AUTOMAKE_OPTIONS',
621                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
622                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
623                 # Only give this error once.
624                 $am_c_prototypes = 1;
625             }
626
627             $dir_holds_sources = '$o';
628             push (@suffixes, '._c', '._o');
629
630             # Only require ansi2knr files if they should appear in
631             # this directory.
632             if ($options{'ansi2knr'} eq 'ansi2knr')
633             {
634                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
635                                          'ansi2knr.c', 'ansi2knr.1');
636                 $output_rules .= &file_contents ('kr-extra');
637                 push (@clean, 'krextra');
638                 &push_phony_cleaners ('krextra');
639             }
640
641             &define_variable ('o', ".\@U\@o");
642
643             # Make sure ansi2knr can be found: if no path specified,
644             # specify "./".
645             local ($apath) = $options{'ansi2knr'};
646             $apath = './' . $apath
647                 unless $apath =~ /\//;
648             &define_variable ("ANSI2KNR", $apath);
649
650             $output_rules .= &file_contents ('compile-kr');
651             $output_rules .= &file_contents ('clean-kr');
652
653             push (@clean, 'kr');
654             &push_phony_cleaners ('kr');
655         }
656     }
657     return $dir_holds_sources;
658 }
659
660 # Handle yacc and lex.
661 sub handle_yacc_lex_cxx
662 {
663     #
664     # First do yacc and lex.
665     #
666
667     local ($yacc_count) = scalar (keys %yacc_sources);
668     local ($lex_count) = scalar (keys %lex_sources);
669     if ($yacc_count)
670     {
671         push (@suffixes, '.y');
672         &define_variable ('YACC', "\@YACC\@");
673         $output_rules .= ".y.c:\n\t";
674         if ($yacc_count > 1)
675         {
676             $output_rules .= '$(SHELL) $(INTERLOCK) =yacclockdir $(YLWRAP) "$(YACC)" y.tab.c $*.c y.tab.h $*.h -- $(YFLAGS) $<';
677         }
678         else
679         {
680             $output_rules .= ('$(YACC) $(YFLAGS) $< && mv y.tab.c $@' . "\n\t"
681                               . 'if test -f y.tab.h; then mv y.tab.h $*.h; else :; fi');
682         }
683         $output_rules .= "\n";
684
685         if (! $seen_prog_yacc)
686         {
687             # FIXME: should include a reference line.  FIXME: maybe
688             # directly reference AC_PROG_YACC somehow?
689             &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'\n");
690         }
691     }
692     if ($lex_count)
693     {
694         push (@suffixes, '.l');
695         &define_variable ("LEX", "\@LEX\@");
696         &define_variable ("LEX_OUTPUT_ROOT", "\@LEX_OUTPUT_ROOT\@");
697         &define_variable ("LEXLIB", "\@LEXLIB\@");
698         $output_rules .= ".l.c:\n\t";
699         if ($lex_count > 1)
700         {
701             $output_rules .= '$(SHELL) $(INTERLOCK) =lexlockdir $(YLWRAP) "$(LEX)" $(LEX_OUTPUT_ROOT).c $@ -- $(LFLAGS) $<';
702         }
703         else
704         {
705             $output_rules .= '$(LEX) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
706         }
707         $output_rules .= "\n";
708
709         if (! $seen_prog_lex)
710         {
711             &am_error ("lex source seen but \`AC_PROG_LEX' not in \`configure.in'\n");
712         }
713         if (! $seen_decl_yytext)
714         {
715             &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'\n");
716         }
717     }
718
719     if ($yacc_count > 1 || $lex_count > 1)
720     {
721         # If there is more than one distinct yacc (resp lex) source
722         # file in a given directory, then the `interlock' program is
723         # required to allow parallel builds to work correctly.  FIXME:
724         # for now, no line number.
725         &require_config_file ($FOREIGN, 'interlock', 'ylwrap');
726         &define_variable ('INTERLOCK', $config_aux_dir . "/interlock");
727         &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
728     }
729
730     #
731     # Now handle C++.
732     #
733     local (@cxx_list) = keys %cxx_extensions;
734     local ($cxx_count) = scalar @cxx_list;
735     if ($cxx_count)
736     {
737         push (@suffixes, @cxx_list);
738
739         &define_variable ("CXX", "\@CXX\@");
740         &define_variable ("CXXFLAGS", "\@CXXFLAGS\@");
741         &define_variable ('CXXCOMPILE', '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
742         &define_variable ('CXXLINK', '$(CXX) $(LDFLAGS) -o $@');
743
744         local ($ext);
745         foreach $ext (@cxx_list)
746         {
747             $output_rules .= ("$ext.o:\n"
748                               . "\t\$(CXXCOMPILE) -c \$<\n");
749         }
750
751         if (! $seen_prog_cxx)
752         {
753             &am_error ("C++ source seen but \`AC_PROG_CXX' not in \`configure.in'\n");
754         }
755     }
756
757     #
758     # Last, handle some C cleanup.
759     #
760     if ($seen_c_source)
761     {
762         &define_variable ('CC', "\@CC\@");
763         &define_variable ('CFLAGS', "\@CFLAGS\@");
764         &define_variable ('COMPILE',
765                           '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)');
766         &define_variable ('LINK', '$(CC) $(LDFLAGS) -o $@');
767     }
768 }
769
770 # Handle SOURCE->OBJECT transform for one program or library.
771 # Arguments are:
772 #   canonical (transformed) name of object to build
773 #   actual name of object to build
774 #   object extension (ie either `.o' or `$o'.
775 # Return result is name of linker variable that must be used.
776 # Empty return means just use `LINK'.
777 sub handle_source_transform
778 {
779     # one_file is canonical name.  unxformed is given name.  obj is
780     # object extension.
781     local ($one_file, $unxformed, $obj) = @_;
782     local ($objpat) = $obj;
783     $objpat =~ s/(\W)/\\$1/g;
784     # Handle explicit `.o' as well as whatever we're passed.
785     $objpat = '(' . $objpat . "|\\.o)";
786
787     local ($linker) = '';
788
789     if (&variable_defined ($one_file . "_OBJECTS"))
790     {
791         &am_line_error ($one_file . '_OBJECTS',
792                         $one_file . '_OBJECTS', 'should not be defined');
793         # No point in continuing.
794         return;
795     }
796
797     local (@files);
798     local ($prefix);
799     foreach $prefix ('', 'EXTRA_')
800     {
801         @files = ();
802         if (&variable_defined ($prefix . $one_file . "_SOURCES"))
803         {
804             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
805             push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
806                 unless $prefix eq 'EXTRA_';
807             @files = &variable_value_as_list ($prefix
808                                               . $one_file . "_SOURCES");
809         }
810         elsif ($prefix eq '')
811         {
812             &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
813             push (@sources, $unxformed . '.c');
814             push (@objects, $unxformed . $obj);
815             push (@files, $unxformed . '.c');
816         }
817         else
818         {
819             &define_variable ("EXTRA_" . $one_file . "_SOURCES", '');
820         }
821
822         if (length (@files))
823         {
824             # Turn sources into objects.
825             local (@result) = ();
826             foreach (@files)
827             {
828                 # If an automatically-discovered source file is
829                 # mentioned, that is an error.
830                 if (defined $libsources{$_})
831                 {
832                     # FIXME: saving $_ is stupid.
833                     local ($save) = $_;
834                     &am_line_error ($prefix . $one_file . '_SOURCES',
835                                     "automatically discovered file \`$_' should not be explicitly mentioned");
836                     $_ = $save;
837                 }
838
839                 # Skip header files, including C++-ish ones.  The list
840                 # of C++ header extensions comes from Emacs 19.32
841                 # etags.
842                 next if /\.[hH]$/;
843                 next if /\.hxx$/;
844                 next if /\.h\+\+$/;
845                 next if /\.hh$/;
846                 next if /\.hpp$/;
847                 # Skip things that look like configure substitutions.
848                 next if /^\@.*\@$/;
849
850                 # Include .c file for lex or yacc source in distribution.
851                 if (/^(.*)\.y$/)
852                 {
853                     # Yacc source.
854                     &push_dist_common ($1 . '.c');
855                     $yacc_sources{$_} = 1;
856                 }
857                 elsif (/^(.*)\.l$/)
858                 {
859                     # Lex source.
860                     &push_dist_common ($1 . '.c');
861                     $lex_sources{$_} = 1;
862                 }
863
864                 # Transform source files into .o files.  List of C++
865                 # extensions comes from Emacs 19.32 etags.
866                 if (s/\.c\+\+$/.o/g
867                     || s/\.cc$/.o/g
868                     || s/\.cpp$/.o/g
869                     || s/\.cxx$/.o/g
870                     || s/\.C$/.o/g)
871                 {
872                     $cxx_extensions{$&} = 1;
873                     $linker = 'CXXLINK';
874                 }
875                 else
876                 {
877                     # FORTRAN support.  FIXME: not finished.
878                     s/\.f90$/.o/g;
879                     s/\.for$/.o/g;
880
881                     # C, yacc, and lex need special $obj extension,
882                     # for de-ansification.  Hopefully someday this
883                     # will go away.
884                     s/\.[cly]$/$obj/g;
885
886                     # .f and .F is fortran.  .s is assembly.  .M is
887                     # Objective-C++.  .m is Objective-C.
888                     s/\.[fFsmM]$/$obj/g;
889
890                     # FIXME: of course, this should only happen for C
891                     # source.  The multi-language support must really
892                     # be cleaned up more globally.
893                     $seen_c_source = 1;
894                 }
895
896                 push (@result, $_)
897                     unless $prefix eq 'EXTRA_';
898
899                 # Transform .o or $o file into .P file (for automatic
900                 # dependency code).
901                 s/$objpat$/.P/g;
902                 $dep_files{'.deps/' . $_} = 1;
903             }
904
905             &define_pretty_variable ($one_file . "_OBJECTS", @result)
906                 unless $prefix eq 'EXTRA_';
907         }
908     }
909
910     if (&variable_defined ('CONFIG_HEADER'))
911     {
912         $output_rules .= ('$(' . $one_file . "_OBJECTS): "
913                           . $contents{'CONFIG_HEADER'} . "\n");
914     }
915
916     return $linker;
917 }
918
919 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
920 # Also, generate _DEPENDENCIES variable if appropriate.
921 # Arguments are:
922 #   transformed name of object being built, or empty string if no object
923 #   name of _LDADD/_LIBADD-type variable to examine
924 #   boolean (lex_seen) which is true if a lex source file was seen in this
925 #     object.  valid only for LDADDs, not LIBADDs.  If set, LEXLIB
926 #     must be in LDADD.
927 sub handle_lib_objects
928 {
929     local ($xname, $var, $lex_seen) = @_;
930
931     die "programming error 1 in handle_lib_objects"
932         if ! &variable_defined ($var);
933
934     die "programming error 2 in handle_lib_objects"
935         if $lex_seen && $var =~ /LIBADD/;
936
937     # We recognize certain things that are commonly put in LIBADD or
938     # LDADD.
939     local ($lsearch);
940     local (@dep_list) = ();
941
942     # If no lex source seen, just assume this is ok.
943     local ($lex_ok) = $lex_seen ? 0 : 1;
944
945     foreach $lsearch (&variable_value_as_list ($var))
946     {
947         # Skip -lfoo and -Ldir.
948         next if $lsearch =~ /^-[lL]/;
949
950         # Assume we have a file of some sort, and push it onto the
951         # dependency list.  Autoconf substitutions are not pushed;
952         # rarely is a new dependency substituted into (eg) foo_LDADD
953         # -- but "bad things (eg -lX11) are routinely substituted.
954         push (@dep_list, $lsearch)
955             unless $lsearch =~ /^\@.*\@$/;
956
957         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
958         # means adding entries to dep_files.
959         if ($lsearch eq '@LIBOBJS@')
960         {
961             if (! keys %libsources)
962             {
963                 &am_line_error ($var, "\@LIBOBJS\@ seen but never set in \`configure.in'");
964             }
965
966             local ($iter, $rewrite);
967             foreach $iter (keys %libsources)
968             {
969                 if ($iter =~ /\.h$/)
970                 {
971                     &require_file_with_line ($var, $FOREIGN, $iter);
972                 }
973                 elsif ($iter ne 'alloca.c')
974                 {
975                     ($rewrite = $iter) =~ s/\.c$/.P/;
976                     $dep_files{'.deps/' . $rewrite} = 1;
977                     &require_file_with_line ($var, $FOREIGN, $iter);
978                 }
979             }
980         }
981         elsif ($lsearch eq '@ALLOCA@')
982         {
983             &am_line_error ($var,
984                             "\@ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
985                 if ! defined $libsources{'alloca.c'};
986             $dep_files{'.deps/alloca.P'} = 1;
987             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
988         }
989         elsif ($lsearch eq '@LEXLIB@')
990         {
991             # FIXME: variable_value_as_list requires us to force
992             # @LEXLIB@ here, where we're really prefer $(LEXLIB).
993             # Nasty -- this will have to wait until many cleanups are
994             # made, I think.
995             $lex_ok = 1;
996         }
997
998     }
999
1000     if (! $lex_ok)
1001     {
1002         &am_line_error ($var, 'lex source file used without @LEXLIB@');
1003     }
1004
1005     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES'))
1006     {
1007         &define_pretty_variable ($xname . '_DEPENDENCIES', @dep_list);
1008     }
1009 }
1010
1011 # Handle C programs.
1012 sub handle_programs
1013 {
1014     local (@proglist) = &am_install_var ('-clean',
1015                                          'progs', 'PROGRAMS',
1016                                          'bin', 'sbin', 'libexec', 'pkglib',
1017                                          'noinst', 'check');
1018     return if ! @proglist;
1019
1020     # If a program is installed, this is required.  We only want this
1021     # error to appear once.
1022     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1023         unless $seen_arg_prog;
1024     $seen_arg_prog = 1;
1025
1026     local ($obj) = &get_object_extension;
1027     local ($one_file, $xname, $munge);
1028
1029     foreach $one_file (@proglist)
1030     {
1031         # Canonicalize names.
1032         ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1033         if ($xname ne $one_file)
1034         {
1035             local ($xt);
1036             foreach $xt ('_LDADD', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
1037             {
1038                 &am_line_error ($one_file . $xt,
1039                                 "invalid variable \`" . $one_file . $xt
1040                                 . "'; should be \`" . $xname . $xt . "'")
1041                     if &variable_defined ($one_file . $xt);
1042             }
1043         }
1044
1045         # FIXME: Using a trick to figure out if any lex sources appear
1046         # in our program; should use some cleaner method.
1047         local ($lex_num) = scalar (keys %lex_sources);
1048         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1049         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1050
1051         if (&variable_defined ($xname . "_LDADD"))
1052         {
1053             &handle_lib_objects ($xname, $xname . '_LDADD', $lex_file_seen);
1054             $lex_file_seen = 0;
1055         }
1056         else
1057         {
1058             # User didn't define prog_LDADD override.  So do it.
1059             &define_variable ($xname . '_LDADD', '$(LDADD)');
1060
1061             # This does a bit too much work.  But we need it to
1062             # generate _DEPENDENCIES when appropriate.
1063             if (&variable_defined ('LDADD'))
1064             {
1065                 &handle_lib_objects ($xname, 'LDADD', $lex_file_seen);
1066                 $lex_file_seen = 0;
1067             }
1068         }
1069
1070         if ($lex_file_seen)
1071         {
1072             &am_line_error ($one_file . $xt,
1073                             'lex source file used without @LEXLIB@');
1074         }
1075
1076         # Determine program to use for link.
1077         local ($xlink);
1078         if (&variable_defined ($xname . '_LINK'))
1079         {
1080             $xlink = $xname . '_LINK';
1081         }
1082         else
1083         {
1084             $xlink = $linker ? $linker : 'LINK';
1085         }
1086
1087         $output_rules .=
1088             &file_contents_with_transform
1089                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1090                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1091                  . 's/\@XLINK\@/' . $xlink . '/go;',
1092                  'program');
1093     }
1094
1095     &handle_lib_objects ('', 'LDADD', 0)
1096         if &variable_defined ('LDADD');
1097 }
1098
1099 # Handle libraries.
1100 sub handle_libraries
1101 {
1102     local (@liblist) = &am_install_var ('-no-all', '-clean',
1103                                         'libs', 'LIBRARIES',
1104                                         'lib', 'pkglib', 'noinst', 'check');
1105     return if ! @liblist;
1106
1107     local (%valid) = &am_primary_prefixes ('LIBRARIES', 'lib', 'pkglib',
1108                                            'noinst', 'check');
1109     if (! $seen_ranlib)
1110     {
1111         local ($key);
1112         foreach $key (keys %valid)
1113         {
1114             if (&variable_defined ($key . '_LIBRARIES'))
1115             {
1116                 &am_line_error ($key . '_LIBRARIES', "library requires either \`AC_PROG_RANLIB' or `AM_PROG_LIBTOOL' in configure.in");
1117                 # Only get this error once.
1118                 $seen_ranlib = 1;
1119                 last;
1120             }
1121         }
1122     }
1123
1124     # Generate _LIBFILES variables.  Too bad we can't do this in
1125     # am_install_var.
1126     local ($onedir, $onelib);
1127     local (@outlist);
1128     local (@libfiles_list);
1129     foreach $onedir (keys %valid) 
1130     {
1131         if (&variable_defined ($onedir . '_LIBRARIES'))
1132         {
1133             @outlist = ();
1134             foreach $onelib (&variable_value_as_list ($onedir . '_LIBRARIES'))
1135             {
1136                 push (@outlist, 'lib' . $onelib . '.a');
1137             }
1138             &define_pretty_variable ($onedir . '_LIBFILES', @outlist);
1139         }
1140
1141         push (@libfiles_list, '$(' . $onedir . '_LIBFILES)')
1142             unless $onedir eq 'EXTRA';
1143     }
1144     push (@all, '$(LIBFILES)');
1145
1146     local ($obj) = &get_object_extension;
1147     local ($munge);
1148     local ($xlib);
1149     foreach $onelib (@liblist)
1150     {
1151         # Canonicalize names.
1152         ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1153         if ($xlib ne $onelib)
1154         {
1155             local ($xt);
1156             foreach $xt ('_LIBADD', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
1157             {
1158                 &am_line_error ($one_file . $xt,
1159                                 "invalid variable \`" . $onelib . $xt
1160                                 . "'; should be \`" . $xlib . $xt . "'")
1161                     if &variable_defined ($onelib . $xt);
1162             }
1163         }
1164
1165         if (&variable_defined ($xlib . '_LIBADD'))
1166         {
1167             &handle_lib_objects ($xlib, $xlib . '_LIBADD', 0);
1168         }
1169         else
1170         {
1171             # Generate support for conditional object inclusion in
1172             # libraries.
1173             &define_variable ($xlib . "_LIBADD", '');
1174         }
1175
1176         &handle_source_transform ($xlib, $onelib, $obj);
1177
1178         $output_rules .=
1179             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1180                                            . 's/\@XLIBRARY\@/'
1181                                            . $xlib . '/go;',
1182                                            'library');
1183     }
1184
1185     # Turn "foo" into "libfoo.a" and include macro definition.
1186     grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
1187
1188     if (! &variable_defined ('LIBFILES'))
1189     {
1190         &define_pretty_variable ('LIBFILES ', @libfiles_list);
1191     }
1192
1193     if ($seen_libtool)
1194     {
1195         &define_variable ('AR', '$(LIBTOOL) archive');
1196         &define_variable ('RANLIB', '$(LIBTOOL) ranlib');
1197         &define_variable ('LCOMPILE', ('$(LIBTOOL) compile $(DEFS) $(INCLUDES)'
1198                                        . ' $(CPPFLAGS) $(CFLAGS)'));
1199     }
1200     else
1201     {
1202         &define_variable ('AR', 'ar');
1203         &define_variable ('RANLIB', '@RANLIB@');
1204     }
1205 }
1206
1207 # See if any _SOURCES variable were misspelled.
1208 sub check_typos
1209 {
1210     local ($varname, $primary);
1211     foreach $varname (keys %contents)
1212     {
1213         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_DEPENDENCIES')
1214         {
1215             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
1216             {
1217                 &am_line_error ($varname,
1218                                 "invalid unused variable name: \`$varname'");
1219             }
1220         }
1221     }
1222 }
1223
1224 # Handle scripts.
1225 sub handle_scripts
1226 {
1227     # NOTE we no longer automatically clean SCRIPTS, because it is
1228     # useful to sometimes distribute scripts verbatim.  This happens
1229     # eg in Automake itself.
1230     &am_install_var ('scripts', 'SCRIPTS',
1231                      'bin', 'sbin', 'libexec', 'pkgdata',
1232                      'noinst', 'check');
1233
1234     # Set $scripts_installed if appropriate.  Make sure we only find
1235     # scripts which are actually installed -- this is why we can't
1236     # simply use the return value of am_install_var.
1237     local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
1238                                            'libexec', 'pkgdata',
1239                                            'noinst', 'check');
1240     local ($key);
1241     foreach $key (keys %valid)
1242     {
1243         if ($key ne 'noinst'
1244             && $key ne 'check'
1245             && &variable_defined ($key . '_SCRIPTS'))
1246         {
1247             $scripts_installed = 1;
1248             # push (@check, 'check-' . $key . 'SCRIPTS');
1249         }
1250     }
1251
1252     if ($scripts_installed)
1253     {
1254         # If a program is installed, this is required.  We only want this
1255         # error to appear once.
1256         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1257             unless $seen_arg_prog;
1258         $seen_arg_prog = 1;
1259     }
1260 }
1261
1262 # Search a file for a "version.texi" Texinfo include.  Return the name
1263 # of the include file if found, or the empty string if not.  A
1264 # "version.texi" file is actually any file whose name matches
1265 # "vers*.texi".
1266 sub grep_for_vers_texi
1267 {
1268     local ($filename) = @_;
1269
1270     if (! open (TEXI, $filename))
1271     {
1272         &am_error ("couldn't open \`$filename': $!");
1273         return '';
1274     }
1275     print "automake: reading $filename\n" if $verbose;
1276
1277     while (<TEXI>)
1278     {
1279         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
1280         {
1281             # Found it.
1282             close (TEXI);
1283             return $1;
1284         }
1285     }
1286
1287     close (TEXI);
1288     return '';
1289 }
1290
1291 # Handle all Texinfo source.
1292 sub handle_texinfo
1293 {
1294     &am_line_error ('TEXINFOS',
1295                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
1296         if &variable_defined ('TEXINFOS');
1297     return if (! &variable_defined ('info_TEXINFOS')
1298                && ! &variable_defined ('html_TEXINFOS'));
1299
1300     local (@texis) = &variable_value_as_list ('info_TEXINFOS');
1301
1302     local (@infos_list, @info_deps_list, @dvis_list, @texi_deps);
1303     local ($infobase, $info_cursor);
1304     local (%versions);
1305     local ($done) = 0;
1306     local ($vti);
1307     local ($tc_cursor, @texi_cleans);
1308     local ($canonical);
1309
1310     foreach $info_cursor (@texis)
1311     {
1312         ($infobase = $info_cursor) =~ s/\.texi(nfo)?$//;
1313
1314         # If 'version.texi' is referenced by input file, then include
1315         # automatic versioning capability.
1316         local ($vtexi)
1317             = &grep_for_vers_texi ($relative_dir . "/" . $info_cursor);
1318         if ($vtexi)
1319         {
1320             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
1321                 if (defined $versions{$vtexi});
1322             $versions{$vtexi} = $info_cursor;
1323
1324             # We number the stamp-vti files.  This is doable since the
1325             # actual names don't matter much.  We only number starting
1326             # with the second one, so that the common case looks nice.
1327             $vti = 'vti' . ($done ? $done : '');
1328             &push_dist_common ($vtexi, 'stamp-' . $vti);
1329             push (@clean, $vti);
1330
1331             # Only require once.
1332             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
1333                                           'mdate-sh')
1334                 if ! $done;
1335             ++$done;
1336
1337             local ($conf_pat);
1338             ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
1339             $output_rules .=
1340                 &file_contents_with_transform
1341                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
1342                      . 's/\@VTI\@/' . $vti . '/g; '
1343                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
1344                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
1345                      'texi-vers');
1346
1347             &push_phony_cleaners ($vti);
1348         }
1349
1350         # If user specified file_TEXINFOS, then use that as explicit
1351         # dependency list.
1352         @texi_deps = ();
1353         push (@texi_deps, $info_cursor);
1354         push (@texi_deps, $vtexi) if $vtexi;
1355
1356         # Canonicalize name first.
1357         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
1358         if (&variable_defined ($canonical . "_TEXINFOS"))
1359         {
1360             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
1361             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
1362         }
1363
1364         $output_rules .= ("\n" . $infobase . ".info: "
1365                           . join (' ', @texi_deps)
1366                           . "\n" . $infobase . ".dvi: "
1367                           . join (' ', @texi_deps)
1368                           . "\n\n");
1369
1370         # FIXME: this distributes too much.  How to find out precisely
1371         # which files will be generated by `makeinfo'?
1372         push (@infos_list, $infobase . '.info', $infobase . '.info[-0-9]*');
1373         push (@info_deps_list, $infobase . '.info');
1374         push (@dvis_list, $infobase . '.dvi');
1375
1376         # Generate list of things to clean for this target.  We do
1377         # this explicitly because otherwise too many things could be
1378         # removed.  In particular the ".log" extension might
1379         # reasonably be used in other contexts by the user.
1380         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
1381                             'ky', 'log', 'pg', 'toc', 'tp', 'vr', 'op')
1382         {
1383             push (@texi_cleans, $infobase . '.' . $tc_cursor);
1384         }
1385     }
1386
1387     # Some boilerplate.
1388     $output_vars .= &file_contents ('texi-vars');
1389     $output_rules .= &file_contents ('texinfos');
1390     push (@phony, 'install-info', 'uninstall-info');
1391
1392     # How to clean.
1393     $output_rules .= "\nmostlyclean-info:\n";
1394     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
1395     $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
1396                       . "maintainer-clean-info:\n\t"
1397                       . 'rm -f $(INFOS)' . "\n");
1398     &push_phony_cleaners ('info');
1399
1400     push (@suffixes, '.texi', '.texinfo', '.info', '.dvi');
1401
1402     if (! defined $options{'no-installinfo'})
1403     {
1404         push (@uninstall, 'uninstall-info');
1405         push (@installdirs, '$(infodir)');
1406         unshift (@install_data, 'install-info');
1407
1408         # Make sure documentation is made and installed first.  Use
1409         # $(INFO_DEPS), not 'info', because otherwise recursive makes
1410         # get run twice during "make all".
1411         unshift (@all, '$(INFO_DEPS)');
1412     }
1413     push (@clean, 'info');
1414     push (@info, '$(INFO_DEPS)');
1415     push (@dvi, '$(DVIS)');
1416
1417     &define_variable ("INFOS", join (' ', @infos_list));
1418     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
1419     &define_variable ("DVIS", join (' ', @dvis_list));
1420     # This next isn't strictly needed now -- the places that look here
1421     # could easily be changed to look in info_TEXINFOS.  But this is
1422     # probably better, in case noinst_TEXINFOS is ever supported.
1423     &define_variable ("TEXINFOS", $contents{'info_TEXINFOS'});
1424
1425     # Do some error checking.
1426     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
1427 }
1428
1429 # Handle any man pages.
1430 sub handle_man_pages
1431 {
1432     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
1433         if &variable_defined ('MANS');
1434     return if ! &variable_defined ('man_MANS');
1435
1436     # We generate the manpage install code by hand to avoid the use of
1437     # basename in the generated Makefile.
1438     local (@mans) = &variable_value_as_list ('man_MANS');
1439     local (%sections, %inames, %mbases, %secmap, %fullsecmap);
1440     local ($i) = 1;
1441     foreach (@mans)
1442     {
1443         # FIXME: statement without effect:
1444         /^(.*)\.([0-9])([a-z]*)$/;
1445         $sections{$2} = 1;
1446         $inames{$i} = $_;
1447         $mbases{$i} = $1;
1448         $secmap{$i} = $2;
1449         $fullsecmap{$i} = $2 . $3;
1450         $i++;
1451     }
1452
1453     # We don't really need this, but we use it in case we ever want to
1454     # support noinst_MANS.
1455     &define_variable ("MANS", $contents{'man_MANS'});
1456
1457     # Generate list of install dirs.
1458     $output_rules .= "install-man: \$(MANS)\n";
1459     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
1460     foreach (keys %sections)
1461     {
1462         push (@installdirs, '$(mandir)/man' . $_)
1463             unless defined $options{'no-installman'};
1464         $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
1465                           . $_ . "\n");
1466     }
1467     push (@phony, 'install-man');
1468
1469     # Generate install target.
1470     local ($key);
1471     foreach $key (keys %inames)
1472     {
1473         $_ = $install_man_format;
1474         s/\@SECTION\@/$secmap{$key}/g;
1475         s/\@MAN\@/$inames{$key}/g;
1476         s/\@FULLSECT\@/$fullsecmap{$key}/g;
1477         s/\@MANBASE\@/$mbases{$key}/g;
1478         $output_rules .= $_;
1479     }
1480     $output_rules .= "\n";
1481
1482     $output_rules .= "uninstall-man:\n";
1483     foreach $key (keys %inames)
1484     {
1485         $_ = $uninstall_man_format;
1486         s/\@SECTION\@/$secmap{$key}/g;
1487         s/\@MAN\@/$inames{$key}/g;
1488         s/\@FULLSECT\@/$fullsecmap{$key}/g;
1489         s/\@MANBASE\@/$mbases{$key}/g;
1490         $output_rules .= $_;
1491     }
1492     $output_rules .= "\n";
1493     push (@phony, 'uninstall-man');
1494
1495     $output_vars .= &file_contents ('mans-vars');
1496
1497     if (! defined $options{'no-installman'})
1498     {
1499         push (@install_data, 'install-man');
1500         push (@uninstall, 'uninstall-man');
1501         push (@all, '$(MANS)');
1502     }
1503 }
1504
1505 # Handle DATA variables.
1506 sub handle_data
1507 {
1508     &am_install_var ('data', 'DATA', 'data', 'sysconf',
1509                      'sharedstate', 'localstate', 'pkgdata',
1510                      'noinst', 'check');
1511 }
1512
1513 # Handle TAGS.
1514 sub handle_tags
1515 {
1516     local ($tagging) = 0;
1517
1518     push (@phony, 'tags');
1519     if (&variable_defined ('SUBDIRS'))
1520     {
1521         $output_rules .= &file_contents ('tags');
1522         push (@phony, 'tags-recursive');
1523         $tagging = 1;
1524     }
1525     elsif ($dir_holds_sources
1526            || $dir_holds_headers
1527            || &variable_defined ('ETAGS_ARGS'))
1528     {
1529         $output_rules .= &file_contents ('tags-subd');
1530         $tagging = 1;
1531     }
1532     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
1533     {
1534         &am_line_error ('TAGS_DEPENDENCIES',
1535                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
1536     }
1537
1538     if ($tagging)
1539     {
1540         $output_rules .= &file_contents ('tags-clean');
1541         push (@clean, 'tags');
1542         &push_phony_cleaners ('tags');
1543         &examine_variable ('TAGS_DEPENDENCIES');
1544     }
1545     else
1546     {
1547         # Every Makefile must define some sort of TAGS rule.
1548         # Otherwise, it would be possible for a top-level "make TAGS"
1549         # to fail because some subdirectory failed.
1550         $output_rules .= "tags: TAGS\nTAGS:\n\n";
1551     }
1552 }
1553
1554 # Worker for handle_dist.
1555 sub handle_dist_worker
1556 {
1557     $output_rules .= 'distdir: $(DEP_DISTFILES)' . "\n";
1558
1559     # Initialization; only at top level.
1560     if ($relative_dir eq '.')
1561     {
1562         if ($strictness >= $GNITS)
1563         {
1564             # For Gnits users, this is pretty handy.  Look at 15 lines
1565             # in case some explanatory text is desirable.
1566             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
1567           echo "NEWS not updated; not releasing" 1>&2; \\
1568           exit 1; \\
1569         fi
1570 ';
1571         }
1572
1573
1574         $output_rules .=
1575             # Create dist directory.
1576             '   rm -rf $(distdir)
1577         mkdir $(distdir)
1578         -chmod 755 $(distdir)
1579 ';
1580
1581         # Only run automake in `dist' target if --include-deps not
1582         # specified.  That way the recipient of a distribution can run
1583         # "make dist" and not need Automake.
1584         if ($cmdline_use_dependencies)
1585         {
1586             $output_rules .=
1587                 (
1588                  # We need an absolute path for --output-dir.  Thus the
1589                  # weirdness.
1590                  '      here=`pwd`; distdir=`cd $(distdir) && pwd` \\
1591           && cd $(srcdir) \\
1592           && automake --include-deps --build-dir=$$here --srcdir-name=$(srcdir) --output-dir=$$distdir --strictness='
1593                  # Set strictness of output.
1594                  . $strictness_name . "\n"
1595                  );
1596         }
1597     }
1598
1599     # Scan EXTRA_DIST to see if we need to distribute anything from a
1600     # subdir.  If so, add it to the list.  I didn't want to do this
1601     # originally, but there were so many requests that I finally
1602     # relented.
1603     local (@dist_dirs);
1604     if (&variable_defined ('EXTRA_DIST'))
1605     {
1606         foreach (&variable_value_as_list ('EXTRA_DIST'))
1607         {
1608             next if /^\@.*\@$/;
1609             next unless s,/+[^/]+$,,;
1610             push (@dist_dirs, $_)
1611                 unless $_ eq '.';
1612         }
1613     }
1614     if (&variable_defined ('EXTRA_DIST_DIRS'))
1615     {
1616         push (@dist_dirs, &variable_value_as_list ('EXTRA_DIST_DIRS'));
1617     }
1618     if (@dist_dirs)
1619     {
1620         # Prepend $(distdir) to each directory given.  Doing it via a
1621         # hash lets us ensure that each directory is used only once.
1622         local (%dhash);
1623         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
1624         $output_rules .= "\t";
1625         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
1626     }
1627
1628     # In loop, test for file existence because sometimes a file gets
1629     # included in DISTFILES twice.  For example this happens when a
1630     # single source file is used in building more than one program.
1631     # Also, there are situations in which "ln" can fail.  For instance
1632     # a file to distribute could actually be a cross-filesystem
1633     # symlink -- this can easily happen if "gettextize" was run on the
1634     # distribution.  Note that DISTFILES can contain a wildcard (for
1635     # info files, sigh), so we must use the echo trick.
1636     $output_rules .= '  @for file in `cd $(srcdir) && echo $(DISTFILES)`; do \\
1637           test -f $(distdir)/$$file \\
1638           || ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \\
1639           || cp -p $(srcdir)/$$file $(distdir)/$$file; \\
1640         done
1641 ';
1642
1643     # If we have SUBDIRS, create all dist subdirectories and do
1644     # recursive build.
1645     if (&variable_defined ('SUBDIRS'))
1646     {
1647         # Test for directory existence here because previous automake
1648         # invocation might have created some directories.  Note that
1649         # we explicitly set distdir for the subdir make; that lets us
1650         # mix-n-match many automake-using packages into one large
1651         # package, and have "dist" at the top level do the right
1652         # thing.
1653         $output_rules .= '      for subdir in $(SUBDIRS); do            \\
1654           test -d $(distdir)/$$subdir           \\
1655           || mkdir $(distdir)/$$subdir          \\
1656           || exit 1;                            \\
1657           chmod 755 $(distdir)/$$subdir;        \\
1658           (cd $$subdir && $(MAKE) distdir=../$(distdir)/$$subdir distdir) \\
1659             || exit 1; \\
1660         done
1661 ';
1662     }
1663
1664     # If the target `dist-hook' exists, run it now.  This allows
1665     # users to do random weird things to the distribution before it is
1666     # packaged up.
1667     if (defined $contents{'dist-hook'})
1668     {
1669         $output_rules .= "\t\$(MAKE) dist-hook\n";
1670     }
1671
1672     push (@phony, 'distdir');
1673 }
1674
1675 # Handle 'dist' target.
1676 sub handle_dist
1677 {
1678     # Set up maint_charset.
1679     $local_maint_charset = $contents{'MAINT_CHARSET'}
1680         if &variable_defined ('MAINT_CHARSET');
1681     $maint_charset = $local_maint_charset
1682         if $relative_dir eq '.';
1683
1684     if (&variable_defined ('DIST_CHARSET'))
1685     {
1686         &am_line_error ('DIST_CHARSET',
1687                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
1688             if ! $local_maint_charset;
1689         if ($relative_dir eq '.')
1690         {
1691             $dist_charset = $contents{'DIST_CHARSET'}
1692         }
1693         else
1694         {
1695             &am_line_error ('DIST_CHARSET',
1696                             "DIST_CHARSET can only be defined at top level");
1697         }
1698     }
1699
1700     # Look for common files that should be included in distribution.
1701     local ($cfile);
1702     foreach $cfile (@common_files)
1703     {
1704         if (-f ($relative_dir . "/" . $cfile))
1705         {
1706             &push_dist_common ($cfile);
1707         }
1708     }
1709
1710     # Keys of %dist_common are names of files to distributed.  We put
1711     # README first because it then becomes easier to make a
1712     # Usenet-compliant shar file (in these, README must be first).
1713     # FIXME: do more ordering of files here.
1714     local (@coms);
1715     if (defined $dist_common{'README'})
1716     {
1717         push (@coms, 'README');
1718         undef $dist_common{'README'};
1719     }
1720     push (@coms, sort keys %dist_common);
1721
1722     &define_pretty_variable ("DIST_COMMON", @coms);
1723     $output_vars .= "\n";
1724
1725     # Some boilerplate.
1726     $output_vars .= &file_contents ('dist-vars');
1727
1728     # Put these things in rules section so it is easier for whoever
1729     # reads Makefile.in.
1730     if (! &variable_defined ('distdir'))
1731     {
1732         if ($relative_dir eq '.')
1733         {
1734             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
1735         }
1736         else
1737         {
1738             $output_rules .= ("\n"
1739                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
1740                               . "\n");
1741         }
1742     }
1743     if ($relative_dir ne '.')
1744     {
1745         $output_rules .= "\nsubdir = " . $relative_dir . "\n";
1746     }
1747
1748     # Generate 'dist' target, and maybe dist-shar / dist-zip / dist-tarZ.
1749     if ($relative_dir eq '.')
1750     {
1751         # Rule to check whether a distribution is viable.
1752         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
1753 # it guarantees that the distribution is self-contained by making another
1754 # tarfile.
1755 distcheck: dist
1756         rm -rf $(distdir)
1757         $(TAR) zxf $(distdir).tar.gz
1758         mkdir $(distdir)/=build
1759         mkdir $(distdir)/=inst
1760         dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
1761                           . (defined $contents{'distcheck-hook'}
1762                              ? "\t\$(MAKE) distcheck-hook"
1763                              : '')
1764                           . '
1765         cd $(distdir)/=build \\
1766           && ../configure '
1767
1768                           . ($seen_gettext ? '--with-included-gettext ' : '')
1769                           . '--srcdir=.. --prefix=$$dc_install_base \\
1770           && $(MAKE) \\
1771           && $(MAKE) dvi \\
1772           && $(MAKE) check \\
1773           && $(MAKE) install \\
1774           && $(MAKE) installcheck \\
1775           && $(MAKE) dist
1776         rm -rf $(distdir)
1777         @echo "========================"; \\
1778         echo "$(distdir).tar.gz is ready for distribution"; \\
1779         echo "========================"
1780 ');
1781
1782         local ($dist_all) = ('dist-all: distdir' . "\n"
1783                              . $dist_header);
1784         local ($curs);
1785         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ')
1786         {
1787             if (defined $options{$curs} || $curs eq 'dist')
1788             {
1789                 $output_rules .= ($curs . ': distdir' . "\n"
1790                                   . $dist_header
1791                                   . $dist{$curs}
1792                                   . $dist_trailer);
1793                 $dist_all .= $dist{$curs};
1794             }
1795         }
1796         $output_rules .= $dist_all . $dist_trailer;
1797     }
1798
1799     # Generate distdir target.
1800     &handle_dist_worker;
1801 }
1802
1803 # Scan a single dependency file and rewrite the dependencies as
1804 # appropriate.  Essentially this means:
1805 # * Clean out absolute dependencies which are not desirable.
1806 # * Rewrite other dependencies to be relative to $(top_srcdir).
1807 sub scan_dependency_file
1808 {
1809     local ($depfile) = @_;
1810
1811     if (! open (DEP_FILE, $depfile))
1812     {
1813         &am_error ("couldn't open \`$depfile': $!");
1814         return;
1815     }
1816     print "automake: reading $depfile\n" if $verbose;
1817
1818     local ($first_line) = 1;
1819     local ($last_line) = 0;
1820     local ($target, @dependencies);
1821     local ($one_dep, $xform);
1822
1823     local ($srcdir_rx, $fixup_rx);
1824     # If the top srcdir is absolute, then the current directory is
1825     # just relative_dir.  But if the top srcdir is relative, then we
1826     # need to add some dots first.  The same holds when matching
1827     # srcdir directly.
1828     if ($srcdir_name =~ /^\//)
1829     {
1830         ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
1831             =~ s/(\W)/\\$1/g;
1832         ($srcdir_rx = $srcdir_name) =~ s/(\W)/\\$1/g;
1833     }
1834     else
1835     {
1836         ($fixup_rx = ($srcdir_name . '/' . $top_builddir . '/'
1837                       . $relative_dir . '/')) =~ s/(\W)/\\$1/g;
1838         ($srcdir_rx = ($srcdir_name . '/' . $top_builddir))
1839             =~ s/(\W)/\\$1/g;
1840     }
1841
1842     while (<DEP_FILE>)
1843     {
1844         if ($last_line)
1845         {
1846             # If LAST_LINE set then we've already seen what we thought
1847             # was the last line.
1848             goto bad_format;
1849         }
1850         next if (/$WHITE_PATTERN/o);
1851         chop;
1852         if (! s/\\$//)
1853         {
1854             # No trailing "\" means this should be the last line.
1855             $last_line = 1;
1856         }
1857
1858         if ($first_line)
1859         {
1860             if (! /^([^:]+:)(.+)$/)
1861             {
1862               bad_format:
1863                 &am_error ("\`$depfile' has incorrect format");
1864                 close (DEP_FILE);
1865                 return;
1866             }
1867
1868             $target = $1;
1869             $_ = $2;
1870
1871             $first_line = 0;
1872         }
1873
1874         foreach $one_dep (split (' ', $_))
1875         {
1876             if ($one_dep =~ /^$fixup_rx/)
1877             {
1878                 # The dependency points to the current directory in
1879                 # some way.
1880                 ($xform = $one_dep) =~ s/^$fixup_rx//;
1881                 push (@dependencies, $xform);
1882             }
1883             elsif ($one_dep =~ /^$srcdir_rx\//)
1884             {
1885                 # The dependency is in some other directory in the package.
1886                 ($xform = $one_dep) =~ s/^$srcdir_rx/$top_builddir/;
1887                 push (@dependencies, $xform);
1888             }
1889             elsif ($one_dep =~ /^\//)
1890             {
1891                 # Absolute path; ignore.
1892             }
1893             else
1894             {
1895                 # Anything else is assumed to be correct.
1896                 push (@dependencies, $one_dep);
1897             }
1898         }
1899     }
1900
1901     &pretty_print_rule ($target, "\t", @dependencies);
1902
1903     close (DEP_FILE);
1904 }
1905
1906 # Handle auto-dependency code.
1907 sub handle_dependencies
1908 {
1909     if ($use_dependencies)
1910     {
1911         # Include GNU-make-specific auto-dep code.
1912         if ($dir_holds_sources)
1913         {
1914             &define_pretty_variable ('DEP_FILES', sort keys %dep_files);
1915             $output_rules .= &file_contents ('depend');
1916             push (@clean, 'depend');
1917             &push_phony_cleaners ('depend');
1918             $output_rules .=
1919                 &file_contents_with_transform ('s/\@EXT\@/.c/g;'
1920                                                . 's/\@MKDEP\@/MKDEP/g',
1921                                                'depend2');
1922             local ($ext);
1923             local ($need_cxx) = 0;
1924             foreach $ext (keys %cxx_extensions)
1925             {
1926                 $output_rules .=
1927                     &file_contents_with_transform ('s/\@EXT\@/' . $ext .'/g;'
1928                                                    . 's/\@MKDEP\@/CXXMKDEP/g',
1929                                                    'depend2');
1930                 $need_cxx = 1;
1931             }
1932             if ($need_cxx)
1933             {
1934                 &define_variable ('CXXMKDEP', '$(CXX) -MM $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
1935             }
1936         }
1937     }
1938     else
1939     {
1940         # FIXME: consider requiring --build-dir here.  What about case
1941         # where this is done via an option?
1942
1943         # Include any auto-generated deps that are present.  Note that
1944         # $build_directory ends in a "/".
1945         if (-d ($build_directory . $relative_dir . "/.deps")
1946             && -f ($build_directory . $relative_dir . "/.deps/.P"))
1947         {
1948             local ($depfile);
1949             local ($gpat) = $build_directory . $relative_dir . "/.deps/*.P";
1950
1951             foreach $depfile (<${gpat}>)
1952             {
1953                 &scan_dependency_file ($depfile);
1954             }
1955
1956             $output_rules .= "\n";
1957         }
1958     }
1959 }
1960
1961 # Handle subdirectories.
1962 sub handle_subdirs
1963 {
1964     return if ! &variable_defined ('SUBDIRS');
1965
1966     # Make sure each directory mentioned in SUBDIRS actually exists.
1967     local ($dir);
1968     foreach $dir (&variable_value_as_list ('SUBDIRS'))
1969     {
1970         # Skip directories substituted by configure.
1971         next if $dir =~ /^\@.*\@$/;
1972         &am_line_error ('SUBDIRS',
1973                         "required directory $relative_dir/$dir does not exist")
1974             if ! -d $relative_dir . '/' . $dir;
1975     }
1976
1977     $output_rules .= &file_contents ('subdirs');
1978
1979     # Push a bunch of phony targets.
1980     local ($phonies);
1981     foreach $phonies ('-data', '-exec', 'dirs')
1982     {
1983         push (@phony, 'install' . $phonies . '-recursive');
1984         push (@phony, 'uninstall' . $phonies . '-recursive');
1985     }
1986     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
1987     {
1988         push (@phony, $phonies . '-recursive');
1989     }
1990     &push_phony_cleaners ('recursive');
1991
1992     push (@check, "check-recursive");
1993     push (@installcheck, "installcheck-recursive");
1994     push (@info, "info-recursive");
1995     push (@dvi, "dvi-recursive");
1996
1997     $recursive_install = 1;
1998 }
1999
2000 # Handle aclocal.m4.
2001 sub handle_aclocal_m4
2002 {
2003     local ($regen_aclocal) = 0;
2004     if (-f 'aclocal.m4')
2005     {
2006         &define_variable ("ACLOCAL", "aclocal.m4");
2007         &push_dist_common ('aclocal.m4');
2008
2009         if (open (ACLOCAL, '< aclocal.m4'))
2010         {
2011             local ($line);
2012             $line = <ACLOCAL>;
2013             close (ACLOCAL);
2014
2015             if ($line =~ 'generated automatically by aclocal')
2016             {
2017                 $regen_aclocal = 1;
2018             }
2019         }
2020     }
2021
2022     local ($acinclude) = 0;
2023     if (-f 'acinclude.m4')
2024     {
2025         $regen_aclocal = 1;
2026         $acinclude = 1;
2027     }
2028
2029     # Note that it might be possible that aclocal.m4 doesn't exist but
2030     # should be auto-generated.  This case probably isn't very
2031     # important.
2032     if ($regen_aclocal)
2033     {
2034         $output_rules .= ("aclocal.m4: "
2035                           . ($seen_maint_mode ? "\@MAINT\@" : "")
2036                           . "configure.in"
2037                           . ($acinclude ? ' acinclude.m4' : '')
2038                           . "\n\t"
2039                           . 'cd $(srcdir) && aclocal'
2040                           . "\n");
2041     }
2042 }
2043
2044 # Handle remaking and configure stuff.
2045 sub handle_configure
2046 {
2047     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
2048     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
2049         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
2050
2051     local ($top_reldir);
2052     if ($relative_dir ne '.')
2053     {
2054         # In subdirectory.
2055         $output_rules .= &file_contents ('remake-subd');
2056         $top_reldir = '../';
2057     }
2058     else
2059     {
2060         &handle_aclocal_m4;
2061         $output_rules .= &file_contents_with_transform ('s/\@STRICTNESS\@/'
2062                                                         . $strictness_name
2063                                                         . '/g',
2064                                                         'remake');
2065         &examine_variable ('CONFIGURE_DEPENDENCIES');
2066         $top_reldir = '';
2067     }
2068
2069     # If we have a configure header, require it.
2070     if ($config_header && $relative_dir eq &dirname ($config_header))
2071     {
2072         local ($ch_sans_dir) = &basename ($config_header);
2073         local ($cn_sans_dir) = &basename ($config_name);
2074
2075         &require_file_with_conf_line ($config_header_line,
2076                                       $FOREIGN, $ch_sans_dir);
2077
2078         # Header defined and in this directory.
2079         if (-f $relative_dir . '/acconfig.h')
2080         {
2081             &define_variable ("ACCONFIG", "acconfig.h");
2082             &push_dist_common ('acconfig.h');
2083         }
2084         if (-f $config_name . '.top')
2085         {
2086             &define_variable ("CONFIG_TOP", "${cn_sans_dir}.top");
2087             &push_dist_common ($cn_sans_dir . '.top');
2088         }
2089         if (-f $config_name . '.bot')
2090         {
2091             &define_variable ("CONFIG_BOT", "${cn_sans_dir}.bot");
2092             &push_dist_common ($cn_sans_dir . '.bot');
2093         }
2094
2095         &touch ($relative_dir . '/stamp-h.in');
2096         &require_file_with_conf_line ($config_header_line, $FOREIGN,
2097                                       'stamp-h.in');
2098
2099         $output_rules .= &file_contents ('remake-hdr');
2100         push (@clean, 'hdr');
2101         &push_phony_cleaners ('hdr');
2102         &define_variable ("CONFIG_HEADER_IN", "${ch_sans_dir}");
2103     }
2104
2105     # Set location of mkinstalldirs.
2106     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
2107     {
2108         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
2109                                             . '/mkinstalldirs'));
2110     }
2111     else
2112     {
2113         &define_variable ('mkinstalldirs',
2114                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
2115     }
2116
2117     &am_line_error ('CONFIG_HEADER',
2118                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
2119         if &variable_defined ('CONFIG_HEADER');
2120
2121     if ($config_name)
2122     {
2123         # Generate CONFIG_HEADER define.
2124         if ($relative_dir eq &dirname ($config_name))
2125         {
2126             &define_variable ("CONFIG_HEADER", &basename ($config_name));
2127         }
2128         else
2129         {
2130             &define_variable ("CONFIG_HEADER",
2131                               "${top_builddir}/${config_name}");
2132         }
2133     }
2134
2135     # Now look for other files in this directory which must be remade
2136     # by config.status, and generate rules for them.
2137     local (@actual_other_files) = ();
2138     local ($file, $local, $input);
2139     foreach $file (@other_input_files)
2140     {
2141         # Skip files not in this directory, any Makefile, and the
2142         # config header.  These last two must be handled specially.
2143         next unless &dirname ($file) eq $relative_dir;
2144         next if $file eq $top_builddir . '/' . $config_name;
2145         ($local = $file) =~ s/^.*\///;
2146         next if $local eq 'Makefile';
2147
2148         if ($local =~ /^(.*):(.*)$/)
2149         {
2150             # This is the ":" syntax of AC_OUTPUT.
2151             $input = $2;
2152             $local = $1;
2153         }
2154         else
2155         {
2156             # Normal usage.
2157             $input = $local . '.in';
2158         }
2159         # FIXME: when using autoconf ":" syntax, should we set CONFIG_FILES
2160         # to $local:$input?
2161         $output_rules .= ($local . ': '
2162                           . '$(top_builddir)/config.status ' . $input . "\n"
2163                           . "\t"
2164                           . 'cd $(top_builddir) && CONFIG_FILES='
2165                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
2166                           . '$@ CONFIG_HEADERS= ./config.status'
2167                           . "\n");
2168         push (@actual_other_files, $local);
2169
2170         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
2171                                       $input);
2172     }
2173
2174     # These files get removed by "make clean".
2175     &define_pretty_variable ('CONFIG_CLEAN_FILES', @actual_other_files);
2176 }
2177
2178 # Handle C headers.
2179 sub handle_headers
2180 {
2181     $dir_holds_headers = &am_install_var ('header', 'HEADERS', 'include',
2182                                           'oldinclude', 'pkginclude',
2183                                           'noinst', 'check');
2184 }
2185
2186 sub handle_gettext
2187 {
2188     return if ! $seen_gettext || $relative_dir ne '.';
2189
2190     if (! &variable_defined ('SUBDIRS'))
2191     {
2192         &am_conf_error
2193             ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined");
2194         return;
2195     }
2196
2197     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
2198         if $seen_gettext;
2199
2200     if (&variable_defined ('SUBDIRS'))
2201     {
2202         &am_line_error
2203             ('SUBDIRS',
2204              "ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
2205                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
2206         &am_line_error
2207             ('SUBDIRS',
2208              "ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
2209                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
2210     }
2211
2212     # Ensure that each language in ALL_LINGUAS has a .po file, and
2213     # each po file is mentioned in ALL_LINGUAS.
2214     if ($seen_linguas)
2215     {
2216         local (%linguas) = ();
2217         grep ($linguas{$_} = 1, split (' ', $all_linguas));
2218
2219         foreach (<po/*.po>)
2220         {
2221             s/^po\///;
2222             s/\.po$//;
2223
2224             &am_line_error ($all_linguas_line,
2225                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
2226                 if ! $linguas{$_};
2227         }
2228
2229         foreach (keys %linguas)
2230         {
2231             &am_line_error ($all_linguas_line,
2232                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
2233                 if ! -f "po/$_.po";
2234         }
2235     }
2236     else
2237     {
2238         &am_error ("ud_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
2239     }
2240 }
2241
2242 # Handle footer elements.
2243 sub handle_footer
2244 {
2245     if ($contents{'SOURCES'})
2246     {
2247         # NOTE don't use define_pretty_variable here, because
2248         # $contents{...} is already defined.
2249         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
2250     }
2251     if ($contents{'OBJECTS'})
2252     {
2253         # NOTE don't use define_pretty_variable here, because
2254         # $contents{...} is already defined.
2255         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
2256     }
2257     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
2258     {
2259         $output_vars .= "\n";
2260     }
2261
2262     if (defined $contents{'SUFFIXES'})
2263     {
2264         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
2265         # make do not like variable substitutions on the .SUFFIXES
2266         # line.
2267         push (@suffixes, split (' ', $contents{'SUFFIXES'}));
2268     }
2269
2270     $output_trailer .= ".SUFFIXES:\n";
2271     if (@suffixes)
2272     {
2273         $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
2274     }
2275     $output_trailer .= &file_contents ('footer');
2276 }
2277
2278 # Deal with installdirs target.
2279 sub handle_installdirs
2280 {
2281     # GNU Makefile standards recommend this.
2282     $output_rules .= ("installdirs:"
2283                       . ($recursive_install
2284                          ? " installdirs-recursive\n"
2285                          : "\n"));
2286     push (@phony, 'installdirs');
2287     if (@installdirs)
2288     {
2289         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
2290                             @installdirs);
2291     }
2292     $output_rules .= "\n";
2293 }
2294
2295 # There are several targets which need to be merged.  This is because
2296 # their complete definition is compiled from many parts.  Note that we
2297 # avoid double colon rules, otherwise we'd use them instead.
2298 sub handle_merge_targets
2299 {
2300     # There are a few install-related variables that you should not define.
2301     local ($var);
2302     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
2303     {
2304         if (&variable_defined ($var))
2305         {
2306             &am_line_error ($var, "\`$var' should not be defined");
2307         }
2308     }
2309
2310     push (@all, 'Makefile');
2311     push (@all, $config_name)
2312         if $config_name && &dirname ($config_name) eq $relative_dir;
2313
2314     &do_one_merge_target ('info', @info);
2315     &do_one_merge_target ('dvi', @dvi);
2316     &do_one_merge_target ('check', @check);
2317     &do_one_merge_target ('installcheck', @installcheck);
2318
2319     # Handle the various install targets specially.  We do this so
2320     # that (eg) "make install-exec" will run "install-exec-recursive"
2321     # if required, but "make install" won't run it twice.  Step one is
2322     # to see if the user specified local versions of any of the
2323     # targets we handle.  "all" is treated as one of these since
2324     # "install" can run it.
2325     push (@install_exec, 'install-exec-local')
2326         if defined $contents{'install-exec-local'};
2327     push (@install_data, 'install-data-local')
2328         if defined $contents{'install-data-local'};
2329     push (@uninstall, 'uninstall-local')
2330         if defined $contents{'uninstall-local'};
2331     local ($utarg);
2332     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
2333                     'uninstall-exec-local', 'uninstall-exec-hook')
2334     {
2335         if (defined $contents{$utarg})
2336         {
2337             local ($x);
2338             ($x = $utarg) =~ s/(data|exec)-//;
2339             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
2340         }
2341     }
2342     push (@all, 'all-local')
2343         if defined $contents{'all-local'};
2344
2345     if (defined $contents{'install-local'})
2346     {
2347         &am_line_error ('install-local',
2348                         "use \`install-data' or \`install-exec', not \`install'");
2349     }
2350
2351     # Step two: if we are doing recursive makes, write out the
2352     # appropriate rules.
2353     local (@install);
2354     if ($recursive_install)
2355     {
2356         push (@install, 'install-recursive');
2357
2358         if (@all)
2359         {
2360             local (@hackall) = ();
2361             if ($config_name && &dirname ($config_name) eq $relative_dir)
2362             {
2363
2364                 # This is kind of a hack, but I couldn't see a better
2365                 # way to handle it.  In this particular case, we need
2366                 # to make sure config.h is built before we recurse.
2367                 # We can't do this by changing the order of
2368                 # dependencies to the "all" because that breaks when
2369                 # using parallel makes.  Instead we handle things
2370                 # explicitly.
2371                 $output_rules .= ('all-recursive-hack: $(CONFIG_HEADER)'
2372                                   . "\n\t" . '$(MAKE) all-recursive'
2373                                   . "\n\n");
2374                 push (@hackall, 'all-recursive-hack');
2375                 push (@phony, 'all-recursive-hack');
2376             }
2377             else
2378             {
2379                 push (@hackall, 'all-recursive');
2380             }
2381
2382             $output_rules .= ('all-am: '
2383                               . join (' ', @all)
2384                               . "\n\n");
2385             @all = @hackall;
2386             push (@all, 'all-am');
2387             push (@phony, 'all-am');
2388         }
2389         else
2390         {
2391             @all = ('all-recursive');
2392
2393             # Must always generate `all-am' target, so it can be
2394             # referred to elsewhere.
2395             $output_rules .= "all-am:\n";
2396         }
2397         if (@install_exec)
2398         {
2399             $output_rules .= ('install-exec-am: '
2400                               . join (' ', @install_exec)
2401                               . "\n\n");
2402             @install_exec = ('install-exec-recursive', 'install-exec-am');
2403             push (@install, 'install-exec-am');
2404             push (@phony, 'install-exec-am');
2405         }
2406         else
2407         {
2408             @install_exec = ('install-exec-recursive');
2409         }
2410         if (@install_data)
2411         {
2412             $output_rules .= ('install-data-am: '
2413                               . join (' ', @install_data)
2414                               . "\n\n");
2415             @install_data = ('install-data-recursive', 'install-data-am');
2416             push (@install, 'install-data-am');
2417             push (@phony, 'install-data-am');
2418         }
2419         else
2420         {
2421             @install_data = ('install-data-recursive');
2422         }
2423         if (@uninstall)
2424         {
2425             $output_rules .= ('uninstall-am: '
2426                               . join (' ', @uninstall)
2427                               . "\n\n");
2428             @uninstall = ('uninstall-recursive', 'uninstall-am');
2429             push (@phony, 'uninstall-am');
2430         }
2431         else
2432         {
2433             @uninstall = ('uninstall-recursive');
2434         }
2435     }
2436
2437     # Step three: print definitions users can use.  Code below knows
2438     # that install-exec is done before install-data, beware.
2439     $output_rules .= ("install-exec: "
2440                       . join (' ', @install_exec)
2441                       . "\n");
2442     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
2443     if (defined $contents{'install-exec-hook'})
2444     {
2445         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
2446     }
2447     $output_rules .= "\n";
2448     push (@install, 'install-exec') if !$recursive_install;
2449     push (@phony, 'install-exec');
2450
2451     $output_rules .= ("install-data: "
2452                       . join (' ', @install_data)
2453                       . "\n");
2454     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
2455     if (defined $contents{'install-data-hook'})
2456     {
2457         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
2458     }
2459     $output_rules .= "\n";
2460     push (@install, 'install-data') if !$recursive_install;
2461     push (@phony, 'install-data');
2462
2463     # If no dependencies for 'install', add 'all'.  Why?  That way
2464     # "make install" at top level of distclean'd distribution won't
2465     # fail because stuff in 'lib' fails to build.
2466     if (! @install || (scalar (@install) == 2
2467                        && $install[0] eq 'install-exec'
2468                        && $install[1] eq 'install-data'))
2469     {
2470         push (@install, 'all');
2471     }
2472     $output_rules .= ('install: '
2473                       . join (' ', @install)
2474                       # Use "@:" as empty command so nothing prints.
2475                       . "\n\t\@:"
2476                       . "\n\n"
2477                       . 'uninstall: '
2478                       . join (' ', @uninstall)
2479                       . "\n\n");
2480     push (@phony, 'install', 'uninstall');
2481
2482     $output_rules .= ('all: '
2483                       . join (' ', @all)
2484                       . "\n\n");
2485     push (@phony, 'all');
2486
2487     # Generate the new 'install-strip' target.
2488     $output_rules .= ("install-strip:\n\t"
2489                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
2490                       . "\n");
2491 }
2492
2493 # Helper for handle_merge_targets.
2494 sub do_one_merge_target
2495 {
2496     local ($name, @values) = @_;
2497
2498     if (defined $contents{$name . '-local'})
2499     {
2500         # User defined local form of target.  So include it.
2501         push (@values, $name . '-local');
2502         push (@phony, $name . '-local');
2503     }
2504
2505     local ($done) = 0;
2506     if ($name eq 'check')
2507     {
2508         if (! &variable_defined ('SUBDIRS'))
2509         {
2510             # 'check' must depend on `all', but not when doing
2511             # recursive build.
2512             unshift (@values, 'all');
2513         }
2514         else
2515         {
2516             # When subdirs are used, do the `all' build and then do
2517             # all the recursive stuff.  Actually use `all-am' because
2518             # it doesn't recurse; we rely on the check target in the
2519             # subdirs to do the required builds there.
2520             $output_rules .= "check: all-am\n";
2521             &pretty_print_rule ("\t\$(MAKE)", "\t  ", @values);
2522             $done = 1;
2523         }
2524     }
2525
2526     &pretty_print_rule ($name . ":", "\t\t", @values)
2527         unless $done;
2528     push (@phony, $name);
2529 }
2530
2531 # Handle all 'clean' targets.
2532 sub handle_clean
2533 {
2534     push (@clean, 'generic');
2535     $output_rules .= &file_contents ('clean');
2536     &push_phony_cleaners ('generic');
2537
2538     local ($target) = $recursive_install ? 'clean-am' : 'clean';
2539     &do_one_clean_target ($target, 'mostly', '', @clean);
2540     &do_one_clean_target ($target, '', 'mostly', @clean);
2541     &do_one_clean_target ($target, 'dist', '', @clean);
2542     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
2543
2544     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
2545
2546     local (@deps);
2547     if ($recursive_install)
2548     {
2549         @deps = ('am', 'recursive');
2550         &do_one_clean_target ('', 'mostly', '', @deps);
2551         &do_one_clean_target ('', '', '', @deps);
2552         &do_one_clean_target ('', 'dist', '', @deps);
2553         &do_one_clean_target ('', 'maintainer-', '', @deps);
2554     }
2555 }
2556
2557 # Helper for handle_clean.
2558 sub do_one_clean_target
2559 {
2560     local ($target, $name, $last_name, @deps) = @_;
2561
2562     # Special case: if target not passed, then don't generate
2563     # dependency on next "lower" clean target (eg no
2564     # clean<-mostlyclean derivation).  In this case the target is
2565     # implicitly known to be 'clean'.
2566     local ($flag) = $target;
2567     $target = 'clean' if ! $flag;
2568
2569     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
2570     if ($flag)
2571     {
2572         if ($last_name || $name ne 'mostly')
2573         {
2574             push (@deps, $last_name . $target . " ");
2575         }
2576     }
2577     # FIXME: not sure if I like the tabs here.
2578     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
2579
2580     # FIXME: shouldn't we really print these messages before running
2581     # the dependencies?
2582     if ($name . $target eq 'maintainer-clean')
2583     {
2584         # Print a special warning.
2585         $output_rules .=
2586             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
2587              . "\t\@echo \"it deletes files that may require special "
2588              . "tools to rebuild.\"\n");
2589
2590         $output_rules .= "\trm -f config.status\n"
2591             if $relative_dir eq '.';
2592     }
2593     elsif ($name . $target eq 'distclean')
2594     {
2595         $output_rules .= "\trm -f config.status\n";
2596     }
2597     $output_rules .= "\n";
2598 }
2599
2600 # Handle .PHONY target.
2601 sub handle_phony
2602 {
2603     &pretty_print_rule ('.PHONY:', "", @phony);
2604     $output_rules .= "\n";
2605 }
2606
2607 # Handle TESTS variable and other checks.
2608 sub handle_tests
2609 {
2610     if (defined $options{'dejagnu'})
2611     {
2612         push (@check, 'check-DEJAGNU');
2613         push (@phony, 'check-DEJAGNU');
2614         $output_rules .= &file_contents ('dejagnu') . "\n";
2615         # Note that in the rule we don't directly generate site.exp to
2616         # avoid the possibility of a corrupted site.exp if make is
2617         # interrupted.  Jim Meyering has some useful text on this
2618         # topic.
2619         $output_rules .= ("site.exp: Makefile\n"
2620                           . "\t\@echo 'Making a new site.exp file...'\n"
2621                           . "\t-\@rm -f site.bak\n"
2622                           . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
2623                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
2624                           . "\t\@echo '# edit the last section' >> \$\@-t\n"
2625                           . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
2626                           . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
2627                           . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
2628
2629         # Extra stuff for AC_CANONICAL_*
2630         local (@whatlist) = ();
2631         if ($seen_canonical)
2632         {
2633             push (@whatlist, 'host')
2634         }
2635
2636         # Extra stuff only for AC_CANONICAL_SYSTEM.
2637         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
2638         {
2639             push (@whatlist, 'target', 'build');
2640         }
2641
2642         local ($c1, $c2);
2643         foreach $c1 (@whatlist)
2644         {
2645             foreach $c2 ('alias', 'triplet')
2646             {
2647                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
2648             }
2649         }
2650
2651         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
2652                           . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
2653                           . "\t-\@mv site.exp site.bak\n"
2654                           . "\t\@mv \$\@-t site.exp\n");
2655     }
2656     else
2657     {
2658         local ($c);
2659         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
2660         {
2661             if (&variable_defined ($c))
2662             {
2663                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
2664             }
2665         }
2666     }
2667
2668     if (&variable_defined ('TESTS'))
2669     {
2670         push (@check, 'check-TESTS');
2671         push (@phony, 'check-TESTS');
2672         # FIXME: use $(SHELL) here?  That is what Ulrich suggests.
2673         # Maybe a new macro, $(TEST_SHELL), a la $(CONFIG_SHELL)?  For
2674         # now we just execute the file directly; this allows test
2675         # files which are compiled -- a possibly useful feature.
2676         $output_rules .= 'check-TESTS: $(TESTS)
2677         @failed=0; all=0; \\
2678         srcdir=$(srcdir); export srcdir; \\
2679         for tst in $(TESTS); do \\
2680           all=`expr $$all + 1`; \\
2681           if test -f $$tst; then dir=.; \\
2682           else dir="$(srcdir)"; fi; \\
2683           if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
2684             echo "PASS: $$tst"; \\
2685           else \\
2686             failed=`expr $$failed + 1`; \\
2687             echo "FAIL: $$tst"; \\
2688           fi; \\
2689         done; \\
2690         if test "$$failed" -eq 0; then \\
2691           echo "========================"; \\
2692           echo "All $$all tests passed"; \\
2693           echo "========================"; \\
2694         else \\
2695           echo "$$failed of $$all tests failed"; \\
2696         fi
2697 ';
2698     }
2699 }
2700
2701 # Handle Emacs Lisp.
2702 sub handle_emacs_lisp
2703 {
2704     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
2705
2706     if (@elfiles)
2707     {
2708         # Found some lisp.
2709         &define_variable ("lispdir", "\@lispdir\@");
2710         &define_variable ("EMACS", "\@EMACS\@");
2711         $output_rules .= (".el.elc:\n"
2712                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
2713                           . "\t\EMACS=$(EMACS) $(SHELL) \$(srcdir)/elisp-comp \$<\n");
2714         push (@suffixes, '.el', '.elc');
2715
2716         # Generate .elc files.
2717         grep ($_ .= 'c', @elfiles);
2718         &define_pretty_variable ('ELCFILES', @elfiles);
2719
2720         push (@clean, 'lisp');
2721         &push_phony_cleaners ('lisp');
2722
2723         local ($varname);
2724         if (&variable_defined ('lisp_LISP'))
2725         {
2726             $varname = 'lisp_LISP';
2727             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
2728                 if ! $seen_lispdir;
2729         }
2730         else
2731         {
2732             $varname = 'noinst_LISP';
2733         }
2734
2735         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
2736     }
2737 }
2738
2739 ################################################################
2740
2741 # Scan configure.in for interesting things.
2742 sub scan_configure
2743 {
2744     open (CONFIGURE, 'configure.in')
2745         || die "automake: couldn't open \`configure.in': $!\n";
2746     print "automake: reading configure.in\n" if $verbose;
2747
2748     # Reinitialize libsources here.  This isn't really necessary,
2749     # since we currently assume there is only one configure.in.  But
2750     # that won't always be the case.
2751     %libsources = ();
2752
2753     local ($in_ac_output, $in_ac_replace, @make_list) = (0, 0);
2754     local ($libobj_iter);
2755     while (<CONFIGURE>)
2756     {
2757         # Remove comments from current line.
2758         s/\bdnl\b.*$//;
2759         s/\#.*$//;
2760
2761         # Populate libobjs array.
2762         if (/AC_FUNC_ALLOCA/)
2763         {
2764             $libsources{'alloca.c'} = 1;
2765         }
2766         elsif (/AC_FUNC_GETLOADAVG/)
2767         {
2768             $libsources{'getloadavg.c'} = 1;
2769         }
2770         elsif (/AC_FUNC_MEMCMP/)
2771         {
2772             $libsources{'memcmp.c'} = 1;
2773         }
2774         elsif (/AC_STRUCT_ST_BLOCKS/)
2775         {
2776             $libsources{'fileblocks.c'} = 1;
2777         }
2778         elsif (/AM_FUNC_FNMATCH/)
2779         {
2780             $libsources{'fnmatch.c'} = 1;
2781         }
2782         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
2783         {
2784             $libsources{'getopt.c'} = 1;
2785             $libsources{'getopt1.c'} = 1;
2786         }
2787         elsif (/AM_FUNC_STRTOD/)
2788         {
2789             $libsources{'strtod.c'} = 1;
2790         }
2791         elsif (/AM_WITH_REGEX/)
2792         {
2793             $libsources{'rx.c'} = 1;
2794             $libsources{'rx.h'} = 1;
2795             $libsources{'regex.c'} = 1;
2796             $libsources{'regex.h'} = 1;
2797         }
2798         elsif (/AM_FUNC_MKTIME/)
2799         {
2800             $libsources{'mktime.c'} = 1;
2801         }
2802         elsif (/AM_FUNC_ERROR_AT_LINE/)
2803         {
2804             $libsources{'error.c'} = 1;
2805             $libsources{'error.h'} = 1;
2806         }
2807         elsif (/AM_FUNC_OBSTACK/)
2808         {
2809             $libsources{'obstack.c'} = 1;
2810             $libsources{'obstack.h'} = 1;
2811         }
2812         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
2813                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
2814         {
2815             foreach $libobj_iter (split (' ', $1))
2816             {
2817                 if ($libobj_iter =~ /^(.*)\.o$/)
2818                 {
2819                     $libsources{$1 . '.c'} = 1;
2820                 }
2821             }
2822         }
2823
2824         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
2825         {
2826             $in_ac_replace = 1;
2827         }
2828         if ($in_ac_replace)
2829         {
2830             $in_ac_replace = 0 if s/[\]\)].*$//;
2831             # Remove trailing backslash.
2832             s/\\$//;
2833             foreach (split)
2834             {
2835                 $libsources{$_ . '.c'} = 1;
2836             }
2837         }
2838
2839         if (/(fp_WITH_DMALLOC|fp_WITH_REGEX|fp_FUNC_FNMATCH|fp_PROG_INSTALL|fp_C_PROTOTYPES|jm_MAINTAINER_MODE)/)
2840         {
2841             &am_conf_line_error ($., "\`$1' is obsolete; use corresponding \`AM_' macro");
2842         }
2843
2844         # Process the AC_OUTPUT macro.
2845         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
2846         {
2847             $in_ac_output = 1;
2848             $ac_output_line = $.;
2849         }
2850         if ($in_ac_output)
2851         {
2852             $in_ac_output = 0 if s/[\]\),].*$//;
2853
2854             # Look at potential Makefile.am's.
2855             foreach (split)
2856             {
2857                 next if $_ eq "\\";
2858                 if (-f $_ . '.am')
2859                 {
2860                     push (@make_list, $_);
2861                 }
2862                 else
2863                 {
2864                     push (@other_input_files, $_);
2865                 }
2866             }
2867         }
2868
2869         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
2870         {
2871             @config_aux_path = $1;
2872         }
2873
2874         # Check for ansi2knr.
2875         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
2876
2877         # Check for NLS support.
2878         if (/ud_GNU_GETTEXT/)
2879         {
2880             $seen_gettext = 1;
2881             $ac_gettext_line = $.;
2882         }
2883
2884         # Look for ALL_LINGUAS.
2885         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
2886         {
2887             $seen_linguas = 1;
2888             $all_linguas = $1;
2889             $all_linguas_line = $.;
2890         }
2891
2892         # Handle configuration headers.
2893         if (/AC_CONFIG_HEADER\s*\((.*)\)/)
2894         {
2895             $config_header_line = $.;
2896             $config_name = $1;
2897             if ($config_name =~ /^([^:]+):(.+)$/)
2898             {
2899                 $config_name = $1;
2900                 $config_header = $2;
2901             }
2902             else
2903             {
2904                 $config_header = $config_name . '.in';
2905             }
2906         }
2907
2908         # Handle AC_CANONICAL_*.  Always allow upgrading to
2909         # AC_CANONICAL_SYSTEM, but never downgrading.
2910         $seen_canonical = $AC_CANONICAL_HOST
2911             if ! $seen_canonical
2912                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
2913         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
2914
2915         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
2916
2917         # Sometimes it is desirable to explicitly set YACC.  For
2918         # instance some people don't want to use bison.
2919         $seen_prog_yacc = 1 if (/AC_PROG_YACC/
2920                                 || /AC_SUBST\(YACC\)/
2921                                 || /AC_(PATH|CHECK)_PROGS?\(YACC/);
2922
2923         # This macro handles several different things.
2924         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
2925         {
2926             $seen_make_set = 1;
2927             $seen_package = 1;
2928             $seen_version = 1;
2929             $seen_arg_prog = 1;
2930             $seen_prog_install = 2;
2931             ($package_version = $1) =~ s/\s//;
2932             $package_version_line = $.;
2933         }
2934
2935         # Some things required by Automake.
2936         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
2937         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
2938         $seen_ranlib = 1 if /AC_PROG_RANLIB/;
2939         $seen_prog_cc = 1 if /AC_PROG_CC/;
2940         $seen_prog_cxx = 1 if /AC_PROG_CXX/;
2941         $seen_prog_lex = 1 if /AC_PROG_LEX/;
2942         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
2943         $seen_maint_mode = 1 if /AM_MAINTAINER_MODE/;
2944         $seen_package = 1 if /PACKAGE=/;
2945
2946         if (/VERSION=(\S+)/)
2947         {
2948             $seen_version = 1;
2949             $package_version = $1;
2950             $package_version_line = $.;
2951         }
2952         elsif (/VERSION=/)
2953         {
2954             $seen_version = 1;
2955         }
2956
2957         # Weird conditionals here because it is always allowed to
2958         # upgrade to AM_PROG_INSTALL but never to downgrade to
2959         # AC_PROG_INSTALL.
2960         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
2961         $seen_prog_install = 2 if /AM_PROG_INSTALL/;
2962
2963         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
2964
2965         if (/AM_PROG_LIBTOOL/)
2966         {
2967             $seen_libtool = 1;
2968             $seen_ranlib = 2;
2969             $libtool_line = $.;
2970         }
2971     }
2972
2973     # Set input files if not specified by user.
2974     @input_files = @make_list if (! @input_files);
2975
2976     close (CONFIGURE);
2977
2978     &am_conf_error ("\`PACKAGE' not defined in configure.in")
2979         if ! $seen_package;
2980     &am_conf_error ("\`VERSION' not defined in configure.in")
2981         if ! $seen_version;
2982
2983     # Look for some files we need.  Always check for these.  This
2984     # check must be done for every run, even those where we are only
2985     # looking at a subdir Makefile.  We must set relative_dir so that
2986     # the file-finding machinery works.
2987     local ($relative_dir) = '.';
2988     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs');
2989     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
2990         if -f $config_aux_path[0] . '/install.sh';
2991 }
2992
2993 ################################################################
2994
2995 # Do any extra checking for GNU standards.
2996 sub check_gnu_standards
2997 {
2998     if ($relative_dir eq '.')
2999     {
3000         # In top level (or only) directory.
3001         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
3002                        'AUTHORS', 'ChangeLog');
3003     }
3004
3005     if ($strictness >= $GNU)
3006     {
3007         if (defined $options{'no-installman'})
3008         {
3009             &am_line_error ('AUTOMAKE_OPTIONS',
3010                             "option \`no-installman' disallowed by GNU standards");
3011         }
3012
3013         if (defined $options{'no-installinfo'})
3014         {
3015             &am_line_error ('AUTOMAKE_OPTIONS',
3016                             "option \`no-installinfo' disallowed by GNU standards");
3017         }
3018     }
3019 }
3020
3021 # Do any extra checking for GNITS standards.
3022 sub check_gnits_standards
3023 {
3024     if ($strictness >= $GNITS)
3025     {
3026         if (-f $relative_dir . '/COPYING.LIB')
3027         {
3028             &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
3029         }
3030
3031         if ($relative_dir eq '.')
3032         {
3033             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
3034             {
3035                 &am_conf_line_error ($package_version_line,
3036                                      "version \`$package_version' doesn't follow Gnits standards");
3037             }
3038             elsif (defined $1 && -f 'README-alpha')
3039             {
3040                 # This means we have an alpha release.  See
3041                 # GNITS_VERSION_PATTERN for details.
3042                 &require_file ($GNITS, 'README-alpha');
3043             }
3044         }
3045     }
3046
3047     if ($relative_dir eq '.')
3048     {
3049         # In top level (or only) directory.
3050         &require_file ($GNITS, 'THANKS');
3051     }
3052 }
3053
3054 ################################################################
3055
3056 # Pretty-print something.  HEAD is what should be printed at the
3057 # beginning of the first line, FILL is what should be printed at the
3058 # beginning of every subsequent line.
3059 sub pretty_print_internal
3060 {
3061     local ($head, $fill, @values) = @_;
3062
3063     local ($column) = length ($head);
3064     local ($result) = $head;
3065
3066     # Fill length is number of characters.  However, each Tab
3067     # character counts for eight.  So we count the number of Tabs and
3068     # multiply by 7.
3069     local ($fill_length) = length ($fill);
3070     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
3071
3072     local ($bol) = 0;
3073     foreach (@values)
3074     {
3075         # "71" because we also print a space.
3076         if ($column + length ($_) > 71)
3077         {
3078             $result .= " \\\n" . $fill;
3079             $column = $fill_length;
3080             $bol = 1;
3081         }
3082
3083         $result .= ' ' unless ($bol);
3084         $result .= $_;
3085         $column += length ($_) + 1;
3086         $bol = 0;
3087     }
3088
3089     $result .= "\n";
3090     return $result;
3091 }
3092
3093 # Pretty-print something and append to output_vars.
3094 sub pretty_print
3095 {
3096     $output_vars .= &pretty_print_internal (@_);
3097 }
3098
3099 # Pretty-print something and append to output_rules.
3100 sub pretty_print_rule
3101 {
3102     $output_rules .= &pretty_print_internal (@_);
3103 }
3104
3105
3106 ################################################################
3107
3108 # See if a variable exists.
3109 sub variable_defined
3110 {
3111     local ($var) = @_;
3112     if (defined $targets{$var})
3113     {
3114         &am_line_error ($var, "\`$var' is target; expected variable");
3115         return 0;
3116     }
3117     elsif (defined $contents{$var})
3118     {
3119         $content_seen{$var} = 1;
3120         return 1;
3121     }
3122     return 0;
3123 }
3124
3125 # Mark a variable as examined.
3126 sub examine_variable
3127 {
3128     local ($var) = @_;
3129     &variable_defined ($var);
3130 }
3131
3132 # Return contents of variable as list, split as whitespace.  This will
3133 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
3134 # substitutions.  If PARENT is specified, it is the name of the
3135 # including variable; this is only used for error reports.
3136 sub variable_value_as_list
3137 {
3138     local ($var, $parent) = @_;
3139     local (@result);
3140
3141     if (defined $targets{$var})
3142     {
3143         &am_line_error ($var, "\`$var' is target; expected variable");
3144     }
3145     elsif (! defined $contents{$var})
3146     {
3147         &am_line_error ($parent, "variable \`$var' not defined");
3148     }
3149     else
3150     {
3151         $content_seen{$var} = 1;
3152         foreach (split (' ', $contents{$var}))
3153         {
3154             # If a comment seen, just leave.
3155             last if /^#/;
3156
3157             # Handle variable substitutions.
3158             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
3159             {
3160                 push (@result, &variable_value_as_list ($1, $var));
3161             }
3162             else
3163             {
3164                 push (@result, $_);
3165             }
3166         }
3167     }
3168
3169     return @result;
3170 }
3171
3172 # Define a new variable, but only if not already defined.
3173 sub define_variable
3174 {
3175     local ($var, $value) = @_;
3176
3177     if (! defined $contents{$var})
3178     {
3179         $output_vars .= $var . ' = ' . $value . "\n";
3180         $contents{$var} = $value;
3181         $content_seen{$var} = 1;
3182     }
3183 }
3184
3185 # Like define_variable, but second arg is a list, and is
3186 # pretty-printed.
3187 sub define_pretty_variable
3188 {
3189     local ($var, @value) = @_;
3190     if (! defined $contents{$var})
3191     {
3192         $contents{$var} = join (' ', @value);
3193         &pretty_print ($var . ' = ', '', @value);
3194         $content_seen{$var} = 1;
3195     }
3196 }
3197
3198 # Read Makefile.am and set up %contents.  Simultaneously copy lines
3199 # from Makefile.am into $output_trailer or $output_vars as
3200 # appropriate.  NOTE we put rules in the trailer section.  We want
3201 # user rules to come after our generated stuff.
3202 sub read_am_file
3203 {
3204     local ($amfile) = @_;
3205
3206     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
3207     print "automake: reading $amfile\n" if $verbose;
3208
3209     $output_vars = ("# $in_file_name generated automatically by automake "
3210                     . $VERSION . " from $am_file_name\n");
3211
3212     # Generate copyright for generated Makefile.in.
3213     $output_vars .= $gen_copyright;
3214
3215     local ($saw_bk) = 0;
3216     local ($was_rule) = 0;
3217     local ($spacing) = '';
3218     local ($comment) = '';
3219     local ($last_var_name) = '';
3220     local ($blank) = 0;
3221
3222     while (<AM_FILE>)
3223     {
3224         if (/$IGNORE_PATTERN/o)
3225         {
3226             # Merely delete comments beginning with two hashes.
3227         }
3228         elsif (/$WHITE_PATTERN/o)
3229         {
3230             # Stick a single white line before the incoming macro or rule.
3231             $spacing = "\n";
3232             $blank = 1;
3233         }
3234         elsif (/$COMMENT_PATTERN/o)
3235         {
3236             # Stick comments before the incoming macro or rule.  Make
3237             # sure a blank line preceeds first block of comments.
3238             $spacing = "\n" unless $blank;
3239             $blank = 1;
3240             $comment .= $spacing . $_;
3241             $spacing = '';
3242         }
3243         else
3244         {
3245             last;
3246         }
3247     }
3248
3249     $output_vars .= $comment . "\n";
3250     $comment = '';
3251     $spacing = "\n";
3252     local ($am_vars) = '';
3253
3254     local ($is_ok_macro);
3255     while ($_)
3256     {
3257         $_ .= "\n"
3258             unless substr ($_, -1, 1) eq "\n";
3259
3260         $_ =~ s/\@MAINT\@//g
3261             unless $seen_maint_mode;
3262
3263         if (/$IGNORE_PATTERN/o)
3264         {
3265             # Merely delete comments beginning with two hashes.
3266         }
3267         elsif (/$WHITE_PATTERN/o)
3268         {
3269             # Stick a single white line before the incoming macro or rule.
3270             $spacing = "\n";
3271         }
3272         elsif (/$COMMENT_PATTERN/o)
3273         {
3274             # Stick comments before the incoming macro or rule.
3275             $comment .= $spacing . $_;
3276             $spacing = '';
3277         }
3278         elsif ($saw_bk)
3279         {
3280             if ($was_rule)
3281             {
3282                 $output_trailer .= $_;
3283                 $saw_bk = /\\$/;
3284             }
3285             else
3286             {
3287                 $am_vars .= $_;
3288                 $saw_bk = /\\$/;
3289                 # Chop newline and backslash if this line is
3290                 # continued.  FIXME: maybe ensure trailing whitespace
3291                 # exists?
3292                 chop if $saw_bk;
3293                 chop if $saw_bk;
3294                 $contents{$last_var_name} .= $_;
3295             }
3296         }
3297         elsif (/$RULE_PATTERN/o)
3298         {
3299             # warn "** Saw rule .$1.\n";
3300             # Found a rule.
3301             $was_rule = 1;
3302             # Value here doesn't matter; for targets we only note
3303             # existence.
3304             $contents{$1} = 1;
3305             $targets{$1} = 1;
3306             $content_lines{$1} = $.;
3307             $output_trailer .= $comment . $spacing . $_;
3308             $comment = $spacing = '';
3309             $saw_bk = /\\$/;
3310         }
3311         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
3312                || /$BOGUS_MACRO_PATTERN/o)
3313         {
3314             # Found a macro definition.
3315             $was_rule = 0;
3316             $last_var_name = $1;
3317             if (substr ($2, -1) eq "\\")
3318             {
3319                 $contents{$1} = substr ($2, 0, length ($2) - 1);
3320             }
3321             else
3322             {
3323                 $contents{$1} = $2;
3324             }
3325             $content_lines{$1} = $.;
3326             $am_vars .= $comment . $spacing . $_;
3327             $comment = $spacing = '';
3328             $saw_bk = /\\$/;
3329
3330             # Error if bogus.
3331             &am_line_error ($., "bad macro name \`$1'")
3332                 if ! $is_ok_macro;
3333         }
3334         else
3335         {
3336             # This isn't an error; it is probably a continued rule.
3337             # In fact, this is what we assume.
3338             $was_rule = 1;
3339             $output_trailer .= $comment . $spacing . $_;
3340             $comment = $spacing = '';
3341             $saw_bk = /\\$/;
3342         }
3343
3344         $_ = <AM_FILE>;
3345     }
3346
3347     $output_trailer .= $comment;
3348
3349     # Compute relative location of the top object directory.
3350     local (@topdir) = ();
3351     foreach (split (/\//, $relative_dir))
3352     {
3353         next if $_ eq '.' || $_ eq '';
3354         if ($_ eq '..')
3355         {
3356             pop @topdir;
3357         }
3358         else
3359         {
3360             push (@topdir, '..');
3361         }
3362     }
3363     @topdir = ('.') if ! @topdir;
3364
3365     $top_builddir = join ('/', @topdir);
3366     local ($build_rx);
3367     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
3368     $output_vars .= &file_contents_with_transform
3369                         ('s/\@top_builddir\@/' . $build_rx . '/g',
3370                          'header-vars');
3371
3372     # Generate some useful variables when AC_CANONICAL_* used.
3373     if ($seen_canonical)
3374     {
3375         local ($curs, %vars);
3376         $vars{'host_alias'} = 'host_alias';
3377         $vars{'host_triplet'} = 'host';
3378         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
3379         {
3380             $vars{'build_alias'} = 'build_alias';
3381             $vars{'build_triplet'} = 'build';
3382             $vars{'target_alias'} = 'target_alias';
3383             $vars{'target_triplet'} = 'target';
3384         }
3385         foreach $curs (keys %vars)
3386         {
3387             $output_vars .= "$curs = \@$vars{$curs}\@\n";
3388             $contents{$curs} = "\@$vars{$curs}\@";
3389         }
3390     }
3391
3392     $output_vars .= $am_vars;
3393 }
3394
3395 ################################################################
3396
3397 sub initialize_global_constants
3398 {
3399     # Values for AC_CANONICAL_*
3400     $AC_CANONICAL_HOST = 1;
3401     $AC_CANONICAL_SYSTEM = 2;
3402
3403     # Associative array of standard directory names.  Entry is TRUE if
3404     # corresponding directory should be installed during
3405     # 'install-exec' phase.
3406     %exec_dir_p =
3407         ('bin', 1,
3408          'sbin', 1,
3409          'libexec', 1,
3410          'data', 0,
3411          'sysconf', 1,
3412          'localstate', 1,
3413          'lib', 1,
3414          'info', 0,
3415          'man', 0,
3416          'include', 0,
3417          'oldinclude', 0,
3418          'pkgdata', 0,
3419          'pkglib', 1,
3420          'pkginclude', 0
3421          );
3422
3423     # Helper text for dealing with man pages.
3424     $install_man_format =
3425     '   sect=@SECTION@;                         \\
3426         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
3427         if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
3428         else file=@MAN@; fi; \\
3429         $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst
3430 ';
3431
3432     $uninstall_man_format =
3433     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
3434         rm -f $(mandir)/man@SECTION@/$$inst
3435 ';
3436
3437     # Commonly found files we look for and automatically include in
3438     # DISTFILES.
3439     @common_files =
3440         (
3441          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
3442          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
3443          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
3444          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
3445          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
3446          'interlock', 'ylwrap', 'acinclude.m4'
3447          );
3448
3449     # Commonly used files we auto-include, but only sometimes.
3450     @common_sometimes =
3451         (
3452          "aclocal.m4", "acconfig.h", "config.h.top",
3453          "config.h.bot", "stamp-h.in", 'stamp-vti', 'libtool'
3454          );
3455
3456     $USAGE = "\
3457   -a, --add-missing     add missing standard files to package
3458   --amdir=DIR           directory storing config files
3459   --build-dir=DIR       directory where build being done (for dependencies)
3460   --foreign             same as --strictness=foreign
3461   --gnits               same as --strictness=gnits
3462   --gnu                 same as --strictness=gnu
3463   --help                print this help, then exit
3464   -i, --include-deps    include generated dependencies in Makefile.in
3465   --no-force            only update Makefile.in's that are out of date
3466   -o DIR, --output-dir=DIR
3467                         put generated Makefile.in's into DIR
3468   --srcdir-name=DIR     name used for srcdir (for dependencies)
3469   -s LEVEL, --strictness=LEVEL
3470                         set strictness level.  LEVEL is foreign, gnu, gnits
3471   -v, --verbose         verbosely list files processed
3472   --version             print version number, then exit\n";
3473
3474     # Copyright on generated Makefile.ins.
3475     $gen_copyright = "\
3476 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
3477 # This Makefile.in is free software; the Free Software Foundation
3478 # gives unlimited permission to copy, distribute and modify it.
3479 ";
3480
3481     # Ignore return result from chmod, because it might give an error
3482     # if we chmod a symlink.
3483     $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
3484     $dist{'tarZ'} = ("\t"
3485                      . '$(TAR) chf - $(distdir) | compress -c > $(distdir).tar.Z'
3486                      . "\n");
3487     $dist{'shar'} = ("\t"
3488                      . 'shar $(distdir) | gzip > $(distdir).shar.gz'
3489                      . "\n");
3490     $dist{'zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
3491     $dist{'dist'} = "\t" .  '$(TAR) chozf $(distdir).tar.gz $(distdir)' . "\n";
3492     $dist_trailer = "\t" . 'rm -rf $(distdir)' . "\n";
3493 }
3494
3495 # (Re)-Initialize per-Makefile.am variables.
3496 sub initialize_per_input
3497 {
3498     # These two variables are used when generating each Makefile.in.
3499     # They hold the Makefile.in until it is ready to be printed.
3500     $output_rules = '';
3501     $output_vars = '';
3502     $output_trailer = '';
3503
3504     # Suffixes found during a run.
3505     @suffixes = ();
3506
3507     # This holds the contents of a Makefile.am, as parsed by
3508     # read_am_file.
3509     %contents = ();
3510
3511     # This holds the names which are targets.  These also appear in
3512     # %contents.
3513     %targets = ();
3514
3515     # This holds the line numbers at which various elements of
3516     # %contents are defined.
3517     %content_lines = ();
3518
3519     # This holds a 1 if a particular variable was examined.
3520     %content_seen = ();
3521
3522     # This holds the "relative directory" of the current Makefile.in.
3523     # Eg for src/Makefile.in, this is "src".
3524     $relative_dir = '';
3525
3526     # This holds a list of files that are included in the
3527     # distribution.
3528     %dist_common = ();
3529
3530     # List of dependencies for the obvious targets.
3531     @install_data = ();
3532     @install_exec = ();
3533     @uninstall = ();
3534     @installdirs = ();
3535
3536     @info = ();
3537     @dvi = ();
3538     @all = ();
3539     @check = ();
3540     @installcheck = ();
3541     @clean = ();
3542
3543     @phony = ();
3544
3545     # These are pretty obvious, too.  They are used to define the
3546     # SOURCES and OBJECTS variables.
3547     @sources = ();
3548     @objects = ();
3549
3550     # TRUE if current directory holds any C source files.  (Actually
3551     # holds object extension, but this information is encapsulated in
3552     # the function get_object_extension).
3553     $dir_holds_sources = '';
3554
3555     # TRUE if current directory holds any headers.
3556     $dir_holds_headers = 0;
3557
3558     # TRUE if install targets should work recursively.
3559     $recursive_install = 0;
3560
3561     # All .P files.
3562     %dep_files = ();
3563
3564     # Strictness levels.
3565     $strictness = $default_strictness;
3566     $strictness_name = $default_strictness_name;
3567
3568     # Options from AUTOMAKE_OPTIONS.
3569     %options = ();
3570
3571     # Whether or not dependencies are handled.  Can be further changed
3572     # in handle_options.
3573     $use_dependencies = $cmdline_use_dependencies;
3574
3575     # Per Makefile.am.
3576     $local_maint_charset = $maint_charset;
3577
3578     # All yacc and lex source filenames for this directory.  Use
3579     # filenames instead of raw count so that multiple instances are
3580     # counted correctly (eg one yacc file can appear in multiple
3581     # programs without harm).
3582     %yacc_sources = ();
3583     %lex_sources = ();
3584
3585     # C++ source extensions we've seen.
3586     %cxx_extensions = ();
3587
3588     # TRUE if we've seen any non-C++ sources.
3589     $seen_c_source = 0;
3590 }
3591
3592
3593 ################################################################
3594
3595 # Return contents of a file from $am_dir, automatically skipping
3596 # macros or rules which are already known.  Runs command on each line
3597 # as it is read; this command can modify $_.
3598 sub file_contents_with_transform
3599 {
3600     local ($command, $basename) = @_;
3601     local ($file) = $am_dir . '/' . $basename . '.am';
3602
3603     open (FC_FILE, $file)
3604         || die "automake: installation error: cannot open \`$file'\n";
3605     # Looks stupid?
3606     # print "automake: reading $file\n" if $verbose;
3607
3608     local ($was_rule) = 0;
3609     local ($result_vars) = '';
3610     local ($result_rules) = '';
3611     local ($comment) = '';
3612     local ($spacing) = "\n";
3613     local ($skipping) = 0;
3614
3615     while (<FC_FILE>)
3616     {
3617         $_ =~ s/\@MAINT\@//g
3618             unless $seen_maint_mode;
3619
3620         eval $command;
3621
3622         if (/$IGNORE_PATTERN/o)
3623         {
3624             # Merely delete comments beginning with two hashes.
3625         }
3626         elsif (/$WHITE_PATTERN/o)
3627         {
3628             # Stick a single white line before the incoming macro or rule.
3629             $spacing = "\n";
3630         }
3631         elsif (/$COMMENT_PATTERN/o)
3632         {
3633             # Stick comments before the incoming macro or rule.
3634             $comment .= $spacing . $_;
3635             $spacing = '';
3636         }
3637         elsif ($saw_bk)
3638         {
3639             if ($was_rule)
3640             {
3641                 $result_rules .= $_ if ! $skipping;
3642             }
3643             else
3644             {
3645                 $result_vars .= $_ if ! $skipping;
3646             }
3647             $saw_bk = /\\$/;
3648         }
3649         elsif (/$RULE_PATTERN/o)
3650         {
3651             # warn "** Found rule .$1.\n";
3652             # Found a rule.
3653             $was_rule = 1;
3654             $skipping = defined $contents{$1};
3655             # warn "** Skip $skipping\n" if $skipping;
3656             $result_rules .= $comment . $spacing . $_ if ! $skipping;
3657             $comment = $spacing = '';
3658             $saw_bk = /\\$/;
3659         }
3660         elsif (/$MACRO_PATTERN/o)
3661         {
3662             # warn "** Found macro .$1.\n";
3663             # Found a variable reference.
3664             $was_rule = 0;
3665             $skipping = defined $contents{$1};
3666             # warn "** Skip $skipping\n" if $skipping;
3667             $result_vars .= $comment . $spacing . $_ if ! $skipping;
3668             $comment = $spacing = '';
3669             $saw_bk = /\\$/;
3670         }
3671         else
3672         {
3673             # This isn't an error; it is probably a continued rule.
3674             # In fact, this is what we assume.
3675             $was_rule = 1;
3676             $result_rules .= $comment . $spacing . $_ if ! $skipping;
3677             $comment = $spacing = '';
3678             $saw_bk = /\\$/;
3679         }
3680     }
3681
3682     close (FC_FILE);
3683     return $result_vars . $result_rules . $comment;
3684 }
3685
3686 # Like file_contents_with_transform, but no transform.
3687 sub file_contents
3688 {
3689     return &file_contents_with_transform ('', @_);
3690 }
3691
3692 # Find all variable prefixes that are used for install directories.  A
3693 # prefix `zar' qualifies iff:
3694 # * `zardir' is a variable.
3695 # * `zar_PRIMARY' is a variable.
3696 sub am_primary_prefixes
3697 {
3698     local ($primary, @prefixes) = @_;
3699
3700     local (%valid, $varname);
3701     grep ($valid{$_} = 0, @prefixes);
3702     $valid{'EXTRA'} = 0;
3703     foreach $varname (keys %contents)
3704     {
3705         if ($varname =~ /^(.*)_$primary$/)
3706         {
3707             if (! defined $valid{$1} && ! &variable_defined ($1 . 'dir'))
3708             {
3709                 &am_line_error ($varname, "invalid variable \"$varname\"");
3710             }
3711             else
3712             {
3713                 # Ensure all extended prefixes are actually used.
3714                 $valid{$1} = 1;
3715             }
3716         }
3717     }
3718
3719     return %valid;
3720 }
3721
3722 # Handle `where_HOW' variable magic.  Does all lookups, generates
3723 # install code, and possibly generates code to define the primary
3724 # variable.  The first argument is the name of the .am file to munge,
3725 # the second argument is the primary variable (eg HEADERS), and all
3726 # subsequent arguments are possible installation locations.  Returns
3727 # list of all values of all _HOW targets.
3728 #
3729 # FIXME: this should be rewritten to be cleaner.  It should be broken
3730 # up into multiple functions.
3731 #
3732 # Usage is: am_install_var (OPTION..., file, HOW, where...)
3733 sub am_install_var
3734 {
3735     local (@args) = @_;
3736
3737     local ($do_all, $do_clean) = (1, 0);
3738     while (@args)
3739     {
3740         if ($args[0] eq '-clean')
3741         {
3742             $do_clean = 1;
3743         }
3744         elsif ($args[0] eq '-no-all')
3745         {
3746             $do_all = 0;
3747         }
3748         elsif ($args[0] !~ /^-/)
3749         {
3750             last;
3751         }
3752         shift (@args);
3753     }
3754     local ($file, $primary, @prefixes) = @args;
3755
3756     local (@used) = ();
3757     local (@result) = ();
3758
3759     # Now that configure substitutions are allowed in where_HOW
3760     # variables, it is an error to actually define the primary.
3761     &am_line_error ($primary, "\`$primary' is an anachronism")
3762         if &variable_defined ($primary);
3763
3764
3765     # Look for misspellings.  It is an error to have a variable ending
3766     # in a "reserved" suffix whose prefix is unknown, eg
3767     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
3768     # variable of the same name (with "dir" appended) exists.  For
3769     # instance, if the variable "zardir" is defined, then
3770     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
3771     # flexibility in those cases which need it.  Perhaps it should be
3772     # disallowed in the Gnits case?  The problem is, sometimes it is
3773     # useful to put things in a subdir of eg pkgdatadir, perhaps even
3774     # for Gnitsoids.
3775     local (%valid) = &am_primary_prefixes ($primary, @prefixes);
3776
3777     # If a primary includes a configure substitution, then the EXTRA_
3778     # form is required.  Otherwise we can't properly do our job.
3779     local ($require_extra);
3780     local ($warned_about_extra) = 0;
3781
3782     local ($clean_file) = $file . '-clean';
3783     local ($one_name);
3784     local ($X);
3785     foreach $X (keys %valid)
3786     {
3787         $one_name = $X . '_' . $primary;
3788         if (&variable_defined ($one_name))
3789         {
3790             # Append actual contents of where_PRIMARY variable to
3791             # result.
3792             local ($rcurs);
3793             foreach $rcurs (&variable_value_as_list ($one_name))
3794             {
3795                 # Skip configure substitutions.  Possibly bogus.
3796                 if ($rcurs =~ /^\@.*\@$/)
3797                 {
3798                     if ($X eq 'EXTRA')
3799                     {
3800                         if (! $warned_about_extra)
3801                         {
3802                             $warned_about_extra = 1;
3803                             &am_line_error ($one_name,
3804                                             "\`$one_name' contains configure substitution, but shouldn't");
3805                         }
3806                     }
3807                     else
3808                     {
3809                         $require_extra = $one_name;
3810                     }
3811                     next;
3812                 }
3813                 push (@result, $rcurs);
3814             }
3815
3816             # "EXTRA" shouldn't be used when generating clean targets,
3817             # @all, or install targets.
3818             next if $X eq 'EXTRA';
3819
3820             if ($do_clean)
3821             {
3822                 $output_rules .=
3823                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
3824                                                    $clean_file);
3825
3826                 push (@clean, $X . $primary);
3827                 &push_phony_cleaners ($X . $primary);
3828             }
3829
3830             if ($X eq 'check')
3831             {
3832                 push (@check, '$(' . $one_name . ')');
3833             }
3834             else
3835             {
3836                 push (@used, '$(' . $one_name . ')');
3837             }
3838             if ($X eq 'noinst' || $X eq 'check')
3839             {
3840                 # Objects which don't get installed by default.
3841                 next;
3842             }
3843
3844             $output_rules .=
3845                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
3846                                                $file);
3847
3848             push (@uninstall, 'uninstall-' . $X . $primary);
3849             push (@phony, 'uninstall-' . $X . $primary);
3850             push (@installdirs, '$(' . $X . 'dir)');
3851             if ($exec_dir_p{$X})
3852             {
3853                 push (@install_exec, 'install-' . $X . $primary);
3854                 push (@phony, 'install-' . $X . $primary);
3855             }
3856             else
3857             {
3858                 push (@install_data, 'install-' . $X . $primary);
3859                 push (@phony, 'install-' . $X . $primary);
3860             }
3861         }
3862     }
3863
3864     if (@used)
3865     {
3866         # Define it.
3867         &define_pretty_variable ($primary, @used);
3868         $output_vars .= "\n";
3869     }
3870
3871     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
3872     {
3873         &am_line_error ($require_extra,
3874                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
3875     }
3876
3877     # Push here because PRIMARY might be configure time determined.
3878     push (@all, '$(' . $primary . ')')
3879         if $do_all && @used;
3880
3881     return (@result);
3882 }
3883
3884
3885 ################################################################
3886
3887 # This variable is local to the "require file" set of functions.
3888 @require_file_paths = ();
3889
3890 # Verify that the file must exist in the current directory.  Usage:
3891 # require_file (isconfigure, line_number, strictness, file) strictness
3892 # is the strictness level at which this file becomes required.  Must
3893 # set require_file_paths before calling this function.
3894 # require_file_paths is set to hold a single directory (the one in
3895 # which the first file was found) before return.
3896 sub require_file_internal
3897 {
3898     local ($is_configure, $line, $mystrict, @files) = @_;
3899     local ($file, $fullfile);
3900     local ($found_it, $errfile, $errdir);
3901     local ($save_dir);
3902
3903     foreach $file (@files)
3904     {
3905         $found_it = 0;
3906         foreach $dir (@require_file_paths)
3907         {
3908             if ($dir eq '.')
3909             {
3910                 $fullfile = $relative_dir . "/" . $file;
3911                 $errdir = $relative_dir unless $errdir;
3912             }
3913             else
3914             {
3915                 $fullfile = $dir . "/" . $file;
3916                 $errdir = $dir unless $errdir;
3917             }
3918
3919             # Use different name for "error filename".  Otherwise on
3920             # an error the bad file will be reported as eg
3921             # `../../install-sh' when using the default
3922             # config_aux_path.
3923             $errfile = $errdir . '/' . $file;
3924
3925             if (-f $fullfile)
3926             {
3927                 $found_it = 1;
3928                 # FIXME: Once again, special-case `.'.
3929                 &push_dist_common ($file)
3930                     if $dir eq $relative_dir || $dir eq '.';
3931                 $save_dir = $dir;
3932                 last;
3933             }
3934         }
3935
3936         if ($found_it)
3937         {
3938             # Prune the path list.
3939             @require_file_paths = $save_dir;
3940         }
3941         else
3942         {
3943             if ($strictness >= $mystrict)
3944             {
3945                 local ($trailer) = '';
3946                 local ($suppress) = 0;
3947
3948                 # Only install missing files according to our desired
3949                 # strictness level.
3950                 if ($add_missing && -f ($am_dir . '/' . $file))
3951                 {
3952                     $trailer = "; installing";
3953                     $suppress = 1;
3954                     # Install the missing file.  Symlink if we can, copy
3955                     # if we must.
3956                     if ($symlink_exists)
3957                     {
3958                         if (! symlink ($am_dir . '/' . $file, $errfile))
3959                         {
3960                             $suppress = 0;
3961                             $trailer .= "; error while making link: $!\n";
3962                         }
3963                     }
3964                     else
3965                     {
3966                         if (! system ('cp', $am_dir . '/' . $file, $errfile))
3967                         {
3968                             $suppress = 0;
3969                             $trailer .= "\n    error while making link: $!\n";
3970                         }
3971                     }
3972                 }
3973
3974                 local ($save) = $exit_status;
3975                 if ($is_configure)
3976                 {
3977                     &am_conf_line_error
3978                         ($line,
3979                          "required file \"$errfile\" not found$trailer");
3980                 }
3981                 else
3982                 {
3983                     &am_line_error
3984                         ($line,
3985                          "required file \"$errfile\" not found$trailer");
3986                 }
3987                 $exit_status = $save if $suppress;
3988             }
3989         }
3990     }
3991 }
3992
3993 # Like require_file_with_line, but error messages refer to
3994 # configure.in, not the current Makefile.am.
3995 sub require_file_with_conf_line
3996 {
3997     @require_file_paths = '.';
3998     &require_file_internal (1, @_);
3999 }
4000
4001 sub require_file_with_line
4002 {
4003     @require_file_paths = '.';
4004     &require_file_internal (0, @_);
4005 }
4006
4007 sub require_file
4008 {
4009     @require_file_paths = '.';
4010     &require_file_internal (0, '', @_);
4011 }
4012
4013 # Require a file that is also required by Autoconf.  Looks in
4014 # configuration path, as specified by AC_CONFIG_AUX_DIR.
4015 sub require_config_file
4016 {
4017     @require_file_paths = @config_aux_path;
4018     &require_file_internal (1, '', @_);
4019     local ($dir) = $require_file_paths[0];
4020     @config_aux_path = @require_file_paths;
4021     if ($dir eq '.')
4022     {
4023         $config_aux_dir = '.';
4024     }
4025     else
4026     {
4027         $config_aux_dir = '$(top_srcdir)/' . $dir;
4028     }
4029 }
4030
4031 # Assumes that the line number is in Makefile.am.
4032 sub require_conf_file_with_line
4033 {
4034     @require_file_paths = @config_aux_path;
4035     &require_file_internal (0, @_);
4036     local ($dir) = $require_file_paths[0];
4037     @config_aux_path = @require_file_paths;
4038     if ($dir eq '.')
4039     {
4040         $config_aux_dir = '.';
4041     }
4042     else
4043     {
4044         $config_aux_dir = '$(top_srcdir)/' . $dir;
4045     }
4046 }
4047
4048 # Assumes that the line number is in Makefile.am.
4049 sub require_conf_file_with_conf_line
4050 {
4051     @require_file_paths = @config_aux_path;
4052     &require_file_internal (1, @_);
4053     local ($dir) = $require_file_paths[0];
4054     @config_aux_path = @require_file_paths;
4055     if ($dir eq '.')
4056     {
4057         $config_aux_dir = '.';
4058     }
4059     else
4060     {
4061         $config_aux_dir = '$(top_srcdir)/' . $dir;
4062     }
4063 }
4064
4065 ################################################################
4066
4067 # Push a list of files onto dist_common.
4068 sub push_dist_common
4069 {
4070     local (@files) = @_;
4071     local ($file);
4072
4073     foreach $file (@files)
4074     {
4075         $dist_common{$file} = 1;
4076     }
4077 }
4078
4079 # Push a list of clean targets onto phony.
4080 sub push_phony_cleaners
4081 {
4082     local ($base) = @_;
4083     local ($target);
4084     foreach $target ('mostly', 'dist', '', 'maintainer-')
4085     {
4086         push (@phony, $target . 'clean-' . $base);
4087     }
4088 }
4089
4090 # Set strictness.
4091 sub set_strictness
4092 {
4093     $strictness_name = $_[0];
4094     if ($strictness_name eq 'gnu')
4095     {
4096         $strictness = $GNU;
4097     }
4098     elsif ($strictness_name eq 'gnits')
4099     {
4100         $strictness = $GNITS;
4101     }
4102     elsif ($strictness_name eq 'foreign')
4103     {
4104         $strictness = $FOREIGN;
4105     }
4106     else
4107     {
4108         die "automake: level \`$strictness_name' not recognized\n";
4109     }
4110 }
4111
4112
4113 ################################################################
4114
4115 # Return directory name of file.
4116 sub dirname
4117 {
4118     local ($file) = @_;
4119     local ($sub);
4120
4121     ($sub = $file) =~ s,/+[^/]+$,,g;
4122     $sub = '.' if $sub eq $file;
4123     return $sub;
4124 }
4125
4126 # Return file name of a file.
4127 sub basename
4128 {
4129     local ($file) = @_;
4130     local ($sub);
4131
4132     ($sub = $file) =~s,^.*/+,,g;
4133     return $sub;
4134 }
4135
4136 # Touch a file.
4137 sub touch
4138 {
4139     local ($file) = @_;
4140
4141     open (TOUCH, ">> $file");
4142     close (TOUCH);
4143 }
4144
4145 ################################################################
4146
4147 # Print an error message and set exit status.
4148 sub am_error
4149 {
4150     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
4151     $exit_status = 1;
4152 }
4153
4154 sub am_line_error
4155 {
4156     local ($symbol, @args) = @_;
4157
4158     if ($symbol)
4159     {
4160         # If SYMBOL not already a line number, look it up in Makefile.am.
4161         $symbol = $content_lines{$symbol} unless $symbol =~ /^\d+$/;
4162         $symbol .= ': ' if $symbol;
4163         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
4164         $exit_status = 1;
4165     }
4166     else
4167     {
4168         &am_error (@args);
4169     }
4170 }
4171
4172 # Like am_error, but while scanning configure.in.
4173 sub am_conf_error
4174 {
4175     # FIXME: can run in subdirs.
4176     warn "automake: configure.in: ", join (' ', @_), "\n";
4177     $exit_status = 1;
4178 }
4179
4180 # Error message with line number referring to configure.in.
4181 sub am_conf_line_error
4182 {
4183     local ($line, @args) = @_;
4184
4185     if ($line)
4186     {
4187         warn "configure.in: $line: ", join (' ', @args), "\n";
4188         $exit_status = 1;
4189     }
4190     else
4191     {
4192         &am_conf_error (@args);
4193     }
4194 }
4195
4196 # Tell user where our aclocal.m4 is, but only once.
4197 sub keyed_aclocal_warning
4198 {
4199     local ($key) = @_;
4200     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
4201 }
4202
4203 # Print usage information.
4204 sub usage
4205 {
4206     print "Usage: automake [OPTION] ... [Makefile]...\n";
4207     print $USAGE;
4208     print "\nFiles which are automatically distributed, if found:\n";
4209     $~ = "USAGE_FORMAT";
4210     local (@lcomm) = sort ((@common_files, @common_sometimes));
4211     local ($one, $two, $three, $four);
4212     while (@lcomm > 0)
4213     {
4214         $one = shift @lcomm;
4215         $two = @lcomm ? shift @lcomm : '';
4216         $three = @lcomm ? shift @lcomm : '';
4217         $four = @lcomm ? shift @lcomm : '';
4218         write;
4219     }
4220
4221     print "\nReport bugs to <bug-gnu-utils\@prep.ai.mit.edu>\n";
4222
4223     exit 0;
4224 }
4225
4226 format USAGE_FORMAT =
4227   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
4228   $one,               $two,               $three,             $four
4229 .