bug fix
[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         # We must explicitly set distdir here.
1670         $output_rules .= "\t\$(MAKE) distdir=\"$(distdir)\" dist-hook\n";
1671     }
1672
1673     push (@phony, 'distdir');
1674 }
1675
1676 # Handle 'dist' target.
1677 sub handle_dist
1678 {
1679     # Set up maint_charset.
1680     $local_maint_charset = $contents{'MAINT_CHARSET'}
1681         if &variable_defined ('MAINT_CHARSET');
1682     $maint_charset = $local_maint_charset
1683         if $relative_dir eq '.';
1684
1685     if (&variable_defined ('DIST_CHARSET'))
1686     {
1687         &am_line_error ('DIST_CHARSET',
1688                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
1689             if ! $local_maint_charset;
1690         if ($relative_dir eq '.')
1691         {
1692             $dist_charset = $contents{'DIST_CHARSET'}
1693         }
1694         else
1695         {
1696             &am_line_error ('DIST_CHARSET',
1697                             "DIST_CHARSET can only be defined at top level");
1698         }
1699     }
1700
1701     # Look for common files that should be included in distribution.
1702     local ($cfile);
1703     foreach $cfile (@common_files)
1704     {
1705         if (-f ($relative_dir . "/" . $cfile))
1706         {
1707             &push_dist_common ($cfile);
1708         }
1709     }
1710
1711     # Keys of %dist_common are names of files to distributed.  We put
1712     # README first because it then becomes easier to make a
1713     # Usenet-compliant shar file (in these, README must be first).
1714     # FIXME: do more ordering of files here.
1715     local (@coms);
1716     if (defined $dist_common{'README'})
1717     {
1718         push (@coms, 'README');
1719         undef $dist_common{'README'};
1720     }
1721     push (@coms, sort keys %dist_common);
1722
1723     &define_pretty_variable ("DIST_COMMON", @coms);
1724     $output_vars .= "\n";
1725
1726     # Some boilerplate.
1727     $output_vars .= &file_contents ('dist-vars');
1728
1729     # Put these things in rules section so it is easier for whoever
1730     # reads Makefile.in.
1731     if (! &variable_defined ('distdir'))
1732     {
1733         if ($relative_dir eq '.')
1734         {
1735             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
1736         }
1737         else
1738         {
1739             $output_rules .= ("\n"
1740                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
1741                               . "\n");
1742         }
1743     }
1744     if ($relative_dir ne '.')
1745     {
1746         $output_rules .= "\nsubdir = " . $relative_dir . "\n";
1747     }
1748
1749     # Generate 'dist' target, and maybe dist-shar / dist-zip / dist-tarZ.
1750     if ($relative_dir eq '.')
1751     {
1752         # Rule to check whether a distribution is viable.
1753         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
1754 # it guarantees that the distribution is self-contained by making another
1755 # tarfile.
1756 distcheck: dist
1757         rm -rf $(distdir)
1758         $(TAR) zxf $(distdir).tar.gz
1759         mkdir $(distdir)/=build
1760         mkdir $(distdir)/=inst
1761         dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
1762                           . (defined $contents{'distcheck-hook'}
1763                              ? "\t\$(MAKE) distcheck-hook"
1764                              : '')
1765                           . '
1766         cd $(distdir)/=build \\
1767           && ../configure '
1768
1769                           . ($seen_gettext ? '--with-included-gettext ' : '')
1770                           . '--srcdir=.. --prefix=$$dc_install_base \\
1771           && $(MAKE) \\
1772           && $(MAKE) dvi \\
1773           && $(MAKE) check \\
1774           && $(MAKE) install \\
1775           && $(MAKE) installcheck \\
1776           && $(MAKE) dist
1777         rm -rf $(distdir)
1778         @echo "========================"; \\
1779         echo "$(distdir).tar.gz is ready for distribution"; \\
1780         echo "========================"
1781 ');
1782
1783         local ($dist_all) = ('dist-all: distdir' . "\n"
1784                              . $dist_header);
1785         local ($curs);
1786         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ')
1787         {
1788             if (defined $options{$curs} || $curs eq 'dist')
1789             {
1790                 $output_rules .= ($curs . ': distdir' . "\n"
1791                                   . $dist_header
1792                                   . $dist{$curs}
1793                                   . $dist_trailer);
1794                 $dist_all .= $dist{$curs};
1795             }
1796         }
1797         $output_rules .= $dist_all . $dist_trailer;
1798     }
1799
1800     # Generate distdir target.
1801     &handle_dist_worker;
1802 }
1803
1804 # Scan a single dependency file and rewrite the dependencies as
1805 # appropriate.  Essentially this means:
1806 # * Clean out absolute dependencies which are not desirable.
1807 # * Rewrite other dependencies to be relative to $(top_srcdir).
1808 sub scan_dependency_file
1809 {
1810     local ($depfile) = @_;
1811
1812     if (! open (DEP_FILE, $depfile))
1813     {
1814         &am_error ("couldn't open \`$depfile': $!");
1815         return;
1816     }
1817     print "automake: reading $depfile\n" if $verbose;
1818
1819     local ($first_line) = 1;
1820     local ($last_line) = 0;
1821     local ($target, @dependencies);
1822     local ($one_dep, $xform);
1823
1824     local ($srcdir_rx, $fixup_rx);
1825     # If the top srcdir is absolute, then the current directory is
1826     # just relative_dir.  But if the top srcdir is relative, then we
1827     # need to add some dots first.  The same holds when matching
1828     # srcdir directly.
1829     if ($srcdir_name =~ /^\//)
1830     {
1831         ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
1832             =~ s/(\W)/\\$1/g;
1833         ($srcdir_rx = $srcdir_name) =~ s/(\W)/\\$1/g;
1834     }
1835     else
1836     {
1837         ($fixup_rx = ($srcdir_name . '/' . $top_builddir . '/'
1838                       . $relative_dir . '/')) =~ s/(\W)/\\$1/g;
1839         ($srcdir_rx = ($srcdir_name . '/' . $top_builddir))
1840             =~ s/(\W)/\\$1/g;
1841     }
1842
1843     while (<DEP_FILE>)
1844     {
1845         if ($last_line)
1846         {
1847             # If LAST_LINE set then we've already seen what we thought
1848             # was the last line.
1849             goto bad_format;
1850         }
1851         next if (/$WHITE_PATTERN/o);
1852         chop;
1853         if (! s/\\$//)
1854         {
1855             # No trailing "\" means this should be the last line.
1856             $last_line = 1;
1857         }
1858
1859         if ($first_line)
1860         {
1861             if (! /^([^:]+:)(.+)$/)
1862             {
1863               bad_format:
1864                 &am_error ("\`$depfile' has incorrect format");
1865                 close (DEP_FILE);
1866                 return;
1867             }
1868
1869             $target = $1;
1870             $_ = $2;
1871
1872             $first_line = 0;
1873         }
1874
1875         foreach $one_dep (split (' ', $_))
1876         {
1877             if ($one_dep =~ /^$fixup_rx/)
1878             {
1879                 # The dependency points to the current directory in
1880                 # some way.
1881                 ($xform = $one_dep) =~ s/^$fixup_rx//;
1882                 push (@dependencies, $xform);
1883             }
1884             elsif ($one_dep =~ /^$srcdir_rx\//)
1885             {
1886                 # The dependency is in some other directory in the package.
1887                 ($xform = $one_dep) =~ s/^$srcdir_rx/$top_builddir/;
1888                 push (@dependencies, $xform);
1889             }
1890             elsif ($one_dep =~ /^\//)
1891             {
1892                 # Absolute path; ignore.
1893             }
1894             else
1895             {
1896                 # Anything else is assumed to be correct.
1897                 push (@dependencies, $one_dep);
1898             }
1899         }
1900     }
1901
1902     &pretty_print_rule ($target, "\t", @dependencies);
1903
1904     close (DEP_FILE);
1905 }
1906
1907 # Handle auto-dependency code.
1908 sub handle_dependencies
1909 {
1910     if ($use_dependencies)
1911     {
1912         # Include GNU-make-specific auto-dep code.
1913         if ($dir_holds_sources)
1914         {
1915             &define_pretty_variable ('DEP_FILES', sort keys %dep_files);
1916             $output_rules .= &file_contents ('depend');
1917             push (@clean, 'depend');
1918             &push_phony_cleaners ('depend');
1919             $output_rules .=
1920                 &file_contents_with_transform ('s/\@EXT\@/.c/g;'
1921                                                . 's/\@MKDEP\@/MKDEP/g',
1922                                                'depend2');
1923             local ($ext);
1924             local ($need_cxx) = 0;
1925             foreach $ext (keys %cxx_extensions)
1926             {
1927                 $output_rules .=
1928                     &file_contents_with_transform ('s/\@EXT\@/' . $ext .'/g;'
1929                                                    . 's/\@MKDEP\@/CXXMKDEP/g',
1930                                                    'depend2');
1931                 $need_cxx = 1;
1932             }
1933             if ($need_cxx)
1934             {
1935                 &define_variable ('CXXMKDEP', '$(CXX) -MM $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
1936             }
1937         }
1938     }
1939     else
1940     {
1941         # FIXME: consider requiring --build-dir here.  What about case
1942         # where this is done via an option?
1943
1944         # Include any auto-generated deps that are present.  Note that
1945         # $build_directory ends in a "/".
1946         if (-d ($build_directory . $relative_dir . "/.deps")
1947             && -f ($build_directory . $relative_dir . "/.deps/.P"))
1948         {
1949             local ($depfile);
1950             local ($gpat) = $build_directory . $relative_dir . "/.deps/*.P";
1951
1952             foreach $depfile (<${gpat}>)
1953             {
1954                 &scan_dependency_file ($depfile);
1955             }
1956
1957             $output_rules .= "\n";
1958         }
1959     }
1960 }
1961
1962 # Handle subdirectories.
1963 sub handle_subdirs
1964 {
1965     return if ! &variable_defined ('SUBDIRS');
1966
1967     # Make sure each directory mentioned in SUBDIRS actually exists.
1968     local ($dir);
1969     foreach $dir (&variable_value_as_list ('SUBDIRS'))
1970     {
1971         # Skip directories substituted by configure.
1972         next if $dir =~ /^\@.*\@$/;
1973         &am_line_error ('SUBDIRS',
1974                         "required directory $relative_dir/$dir does not exist")
1975             if ! -d $relative_dir . '/' . $dir;
1976     }
1977
1978     $output_rules .= &file_contents ('subdirs');
1979
1980     # Push a bunch of phony targets.
1981     local ($phonies);
1982     foreach $phonies ('-data', '-exec', 'dirs')
1983     {
1984         push (@phony, 'install' . $phonies . '-recursive');
1985         push (@phony, 'uninstall' . $phonies . '-recursive');
1986     }
1987     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
1988     {
1989         push (@phony, $phonies . '-recursive');
1990     }
1991     &push_phony_cleaners ('recursive');
1992
1993     push (@check, "check-recursive");
1994     push (@installcheck, "installcheck-recursive");
1995     push (@info, "info-recursive");
1996     push (@dvi, "dvi-recursive");
1997
1998     $recursive_install = 1;
1999 }
2000
2001 # Handle aclocal.m4.
2002 sub handle_aclocal_m4
2003 {
2004     local ($regen_aclocal) = 0;
2005     if (-f 'aclocal.m4')
2006     {
2007         &define_variable ("ACLOCAL", "aclocal.m4");
2008         &push_dist_common ('aclocal.m4');
2009
2010         if (open (ACLOCAL, '< aclocal.m4'))
2011         {
2012             local ($line);
2013             $line = <ACLOCAL>;
2014             close (ACLOCAL);
2015
2016             if ($line =~ 'generated automatically by aclocal')
2017             {
2018                 $regen_aclocal = 1;
2019             }
2020         }
2021     }
2022
2023     local ($acinclude) = 0;
2024     if (-f 'acinclude.m4')
2025     {
2026         $regen_aclocal = 1;
2027         $acinclude = 1;
2028     }
2029
2030     # Note that it might be possible that aclocal.m4 doesn't exist but
2031     # should be auto-generated.  This case probably isn't very
2032     # important.
2033     if ($regen_aclocal)
2034     {
2035         $output_rules .= ("aclocal.m4: "
2036                           . ($seen_maint_mode ? "\@MAINT\@" : "")
2037                           . "configure.in"
2038                           . ($acinclude ? ' acinclude.m4' : '')
2039                           . "\n\t"
2040                           . 'cd $(srcdir) && aclocal'
2041                           . "\n");
2042     }
2043 }
2044
2045 # Handle remaking and configure stuff.
2046 sub handle_configure
2047 {
2048     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
2049     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
2050         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
2051
2052     local ($top_reldir);
2053     if ($relative_dir ne '.')
2054     {
2055         # In subdirectory.
2056         $output_rules .= &file_contents ('remake-subd');
2057         $top_reldir = '../';
2058     }
2059     else
2060     {
2061         &handle_aclocal_m4;
2062         $output_rules .= &file_contents_with_transform ('s/\@STRICTNESS\@/'
2063                                                         . $strictness_name
2064                                                         . '/g',
2065                                                         'remake');
2066         &examine_variable ('CONFIGURE_DEPENDENCIES');
2067         $top_reldir = '';
2068     }
2069
2070     # If we have a configure header, require it.
2071     if ($config_header && $relative_dir eq &dirname ($config_header))
2072     {
2073         local ($ch_sans_dir) = &basename ($config_header);
2074         local ($cn_sans_dir) = &basename ($config_name);
2075
2076         &require_file_with_conf_line ($config_header_line,
2077                                       $FOREIGN, $ch_sans_dir);
2078
2079         # Header defined and in this directory.
2080         if (-f $relative_dir . '/acconfig.h')
2081         {
2082             &define_variable ("ACCONFIG", "acconfig.h");
2083             &push_dist_common ('acconfig.h');
2084         }
2085         if (-f $config_name . '.top')
2086         {
2087             &define_variable ("CONFIG_TOP", "${cn_sans_dir}.top");
2088             &push_dist_common ($cn_sans_dir . '.top');
2089         }
2090         if (-f $config_name . '.bot')
2091         {
2092             &define_variable ("CONFIG_BOT", "${cn_sans_dir}.bot");
2093             &push_dist_common ($cn_sans_dir . '.bot');
2094         }
2095
2096         &touch ($relative_dir . '/stamp-h.in');
2097         &require_file_with_conf_line ($config_header_line, $FOREIGN,
2098                                       'stamp-h.in');
2099
2100         $output_rules .= &file_contents ('remake-hdr');
2101         push (@clean, 'hdr');
2102         &push_phony_cleaners ('hdr');
2103         &define_variable ("CONFIG_HEADER_IN", "${ch_sans_dir}");
2104     }
2105
2106     # Set location of mkinstalldirs.
2107     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
2108     {
2109         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
2110                                             . '/mkinstalldirs'));
2111     }
2112     else
2113     {
2114         &define_variable ('mkinstalldirs',
2115                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
2116     }
2117
2118     &am_line_error ('CONFIG_HEADER',
2119                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
2120         if &variable_defined ('CONFIG_HEADER');
2121
2122     if ($config_name)
2123     {
2124         # Generate CONFIG_HEADER define.
2125         if ($relative_dir eq &dirname ($config_name))
2126         {
2127             &define_variable ("CONFIG_HEADER", &basename ($config_name));
2128         }
2129         else
2130         {
2131             &define_variable ("CONFIG_HEADER",
2132                               "${top_builddir}/${config_name}");
2133         }
2134     }
2135
2136     # Now look for other files in this directory which must be remade
2137     # by config.status, and generate rules for them.
2138     local (@actual_other_files) = ();
2139     local ($file, $local, $input);
2140     foreach $file (@other_input_files)
2141     {
2142         # Skip files not in this directory, any Makefile, and the
2143         # config header.  These last two must be handled specially.
2144         next unless &dirname ($file) eq $relative_dir;
2145         next if $file eq $top_builddir . '/' . $config_name;
2146         ($local = $file) =~ s/^.*\///;
2147         next if $local eq 'Makefile';
2148
2149         if ($local =~ /^(.*):(.*)$/)
2150         {
2151             # This is the ":" syntax of AC_OUTPUT.
2152             $input = $2;
2153             $local = $1;
2154         }
2155         else
2156         {
2157             # Normal usage.
2158             $input = $local . '.in';
2159         }
2160         # FIXME: when using autoconf ":" syntax, should we set CONFIG_FILES
2161         # to $local:$input?
2162         $output_rules .= ($local . ': '
2163                           . '$(top_builddir)/config.status ' . $input . "\n"
2164                           . "\t"
2165                           . 'cd $(top_builddir) && CONFIG_FILES='
2166                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
2167                           . '$@ CONFIG_HEADERS= ./config.status'
2168                           . "\n");
2169         push (@actual_other_files, $local);
2170
2171         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
2172                                       $input);
2173     }
2174
2175     # These files get removed by "make clean".
2176     &define_pretty_variable ('CONFIG_CLEAN_FILES', @actual_other_files);
2177 }
2178
2179 # Handle C headers.
2180 sub handle_headers
2181 {
2182     $dir_holds_headers = &am_install_var ('header', 'HEADERS', 'include',
2183                                           'oldinclude', 'pkginclude',
2184                                           'noinst', 'check');
2185 }
2186
2187 sub handle_gettext
2188 {
2189     return if ! $seen_gettext || $relative_dir ne '.';
2190
2191     if (! &variable_defined ('SUBDIRS'))
2192     {
2193         &am_conf_error
2194             ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined");
2195         return;
2196     }
2197
2198     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
2199         if $seen_gettext;
2200
2201     if (&variable_defined ('SUBDIRS'))
2202     {
2203         &am_line_error
2204             ('SUBDIRS',
2205              "ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
2206                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
2207         &am_line_error
2208             ('SUBDIRS',
2209              "ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
2210                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
2211     }
2212
2213     # Ensure that each language in ALL_LINGUAS has a .po file, and
2214     # each po file is mentioned in ALL_LINGUAS.
2215     if ($seen_linguas)
2216     {
2217         local (%linguas) = ();
2218         grep ($linguas{$_} = 1, split (' ', $all_linguas));
2219
2220         foreach (<po/*.po>)
2221         {
2222             s/^po\///;
2223             s/\.po$//;
2224
2225             &am_line_error ($all_linguas_line,
2226                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
2227                 if ! $linguas{$_};
2228         }
2229
2230         foreach (keys %linguas)
2231         {
2232             &am_line_error ($all_linguas_line,
2233                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
2234                 if ! -f "po/$_.po";
2235         }
2236     }
2237     else
2238     {
2239         &am_error ("ud_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
2240     }
2241 }
2242
2243 # Handle footer elements.
2244 sub handle_footer
2245 {
2246     if ($contents{'SOURCES'})
2247     {
2248         # NOTE don't use define_pretty_variable here, because
2249         # $contents{...} is already defined.
2250         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
2251     }
2252     if ($contents{'OBJECTS'})
2253     {
2254         # NOTE don't use define_pretty_variable here, because
2255         # $contents{...} is already defined.
2256         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
2257     }
2258     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
2259     {
2260         $output_vars .= "\n";
2261     }
2262
2263     if (defined $contents{'SUFFIXES'})
2264     {
2265         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
2266         # make do not like variable substitutions on the .SUFFIXES
2267         # line.
2268         push (@suffixes, split (' ', $contents{'SUFFIXES'}));
2269     }
2270
2271     $output_trailer .= ".SUFFIXES:\n";
2272     if (@suffixes)
2273     {
2274         $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
2275     }
2276     $output_trailer .= &file_contents ('footer');
2277 }
2278
2279 # Deal with installdirs target.
2280 sub handle_installdirs
2281 {
2282     # GNU Makefile standards recommend this.
2283     $output_rules .= ("installdirs:"
2284                       . ($recursive_install
2285                          ? " installdirs-recursive\n"
2286                          : "\n"));
2287     push (@phony, 'installdirs');
2288     if (@installdirs)
2289     {
2290         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
2291                             @installdirs);
2292     }
2293     $output_rules .= "\n";
2294 }
2295
2296 # There are several targets which need to be merged.  This is because
2297 # their complete definition is compiled from many parts.  Note that we
2298 # avoid double colon rules, otherwise we'd use them instead.
2299 sub handle_merge_targets
2300 {
2301     # There are a few install-related variables that you should not define.
2302     local ($var);
2303     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
2304     {
2305         if (&variable_defined ($var))
2306         {
2307             &am_line_error ($var, "\`$var' should not be defined");
2308         }
2309     }
2310
2311     push (@all, 'Makefile');
2312     push (@all, $config_name)
2313         if $config_name && &dirname ($config_name) eq $relative_dir;
2314
2315     &do_one_merge_target ('info', @info);
2316     &do_one_merge_target ('dvi', @dvi);
2317     &do_one_merge_target ('check', @check);
2318     &do_one_merge_target ('installcheck', @installcheck);
2319
2320     # Handle the various install targets specially.  We do this so
2321     # that (eg) "make install-exec" will run "install-exec-recursive"
2322     # if required, but "make install" won't run it twice.  Step one is
2323     # to see if the user specified local versions of any of the
2324     # targets we handle.  "all" is treated as one of these since
2325     # "install" can run it.
2326     push (@install_exec, 'install-exec-local')
2327         if defined $contents{'install-exec-local'};
2328     push (@install_data, 'install-data-local')
2329         if defined $contents{'install-data-local'};
2330     push (@uninstall, 'uninstall-local')
2331         if defined $contents{'uninstall-local'};
2332     local ($utarg);
2333     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
2334                     'uninstall-exec-local', 'uninstall-exec-hook')
2335     {
2336         if (defined $contents{$utarg})
2337         {
2338             local ($x);
2339             ($x = $utarg) =~ s/(data|exec)-//;
2340             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
2341         }
2342     }
2343     push (@all, 'all-local')
2344         if defined $contents{'all-local'};
2345
2346     if (defined $contents{'install-local'})
2347     {
2348         &am_line_error ('install-local',
2349                         "use \`install-data' or \`install-exec', not \`install'");
2350     }
2351
2352     # Step two: if we are doing recursive makes, write out the
2353     # appropriate rules.
2354     local (@install);
2355     if ($recursive_install)
2356     {
2357         push (@install, 'install-recursive');
2358
2359         if (@all)
2360         {
2361             local (@hackall) = ();
2362             if ($config_name && &dirname ($config_name) eq $relative_dir)
2363             {
2364
2365                 # This is kind of a hack, but I couldn't see a better
2366                 # way to handle it.  In this particular case, we need
2367                 # to make sure config.h is built before we recurse.
2368                 # We can't do this by changing the order of
2369                 # dependencies to the "all" because that breaks when
2370                 # using parallel makes.  Instead we handle things
2371                 # explicitly.
2372                 $output_rules .= ('all-recursive-hack: $(CONFIG_HEADER)'
2373                                   . "\n\t" . '$(MAKE) all-recursive'
2374                                   . "\n\n");
2375                 push (@hackall, 'all-recursive-hack');
2376                 push (@phony, 'all-recursive-hack');
2377             }
2378             else
2379             {
2380                 push (@hackall, 'all-recursive');
2381             }
2382
2383             $output_rules .= ('all-am: '
2384                               . join (' ', @all)
2385                               . "\n\n");
2386             @all = @hackall;
2387             push (@all, 'all-am');
2388             push (@phony, 'all-am');
2389         }
2390         else
2391         {
2392             @all = ('all-recursive');
2393
2394             # Must always generate `all-am' target, so it can be
2395             # referred to elsewhere.
2396             $output_rules .= "all-am:\n";
2397         }
2398         if (@install_exec)
2399         {
2400             $output_rules .= ('install-exec-am: '
2401                               . join (' ', @install_exec)
2402                               . "\n\n");
2403             @install_exec = ('install-exec-recursive', 'install-exec-am');
2404             push (@install, 'install-exec-am');
2405             push (@phony, 'install-exec-am');
2406         }
2407         else
2408         {
2409             @install_exec = ('install-exec-recursive');
2410         }
2411         if (@install_data)
2412         {
2413             $output_rules .= ('install-data-am: '
2414                               . join (' ', @install_data)
2415                               . "\n\n");
2416             @install_data = ('install-data-recursive', 'install-data-am');
2417             push (@install, 'install-data-am');
2418             push (@phony, 'install-data-am');
2419         }
2420         else
2421         {
2422             @install_data = ('install-data-recursive');
2423         }
2424         if (@uninstall)
2425         {
2426             $output_rules .= ('uninstall-am: '
2427                               . join (' ', @uninstall)
2428                               . "\n\n");
2429             @uninstall = ('uninstall-recursive', 'uninstall-am');
2430             push (@phony, 'uninstall-am');
2431         }
2432         else
2433         {
2434             @uninstall = ('uninstall-recursive');
2435         }
2436     }
2437
2438     # Step three: print definitions users can use.  Code below knows
2439     # that install-exec is done before install-data, beware.
2440     $output_rules .= ("install-exec: "
2441                       . join (' ', @install_exec)
2442                       . "\n");
2443     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
2444     if (defined $contents{'install-exec-hook'})
2445     {
2446         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
2447     }
2448     $output_rules .= "\n";
2449     push (@install, 'install-exec') if !$recursive_install;
2450     push (@phony, 'install-exec');
2451
2452     $output_rules .= ("install-data: "
2453                       . join (' ', @install_data)
2454                       . "\n");
2455     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
2456     if (defined $contents{'install-data-hook'})
2457     {
2458         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
2459     }
2460     $output_rules .= "\n";
2461     push (@install, 'install-data') if !$recursive_install;
2462     push (@phony, 'install-data');
2463
2464     # If no dependencies for 'install', add 'all'.  Why?  That way
2465     # "make install" at top level of distclean'd distribution won't
2466     # fail because stuff in 'lib' fails to build.
2467     if (! @install || (scalar (@install) == 2
2468                        && $install[0] eq 'install-exec'
2469                        && $install[1] eq 'install-data'))
2470     {
2471         push (@install, 'all');
2472     }
2473     $output_rules .= ('install: '
2474                       . join (' ', @install)
2475                       # Use "@:" as empty command so nothing prints.
2476                       . "\n\t\@:"
2477                       . "\n\n"
2478                       . 'uninstall: '
2479                       . join (' ', @uninstall)
2480                       . "\n\n");
2481     push (@phony, 'install', 'uninstall');
2482
2483     $output_rules .= ('all: '
2484                       . join (' ', @all)
2485                       . "\n\n");
2486     push (@phony, 'all');
2487
2488     # Generate the new 'install-strip' target.
2489     $output_rules .= ("install-strip:\n\t"
2490                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
2491                       . "\n");
2492 }
2493
2494 # Helper for handle_merge_targets.
2495 sub do_one_merge_target
2496 {
2497     local ($name, @values) = @_;
2498
2499     if (defined $contents{$name . '-local'})
2500     {
2501         # User defined local form of target.  So include it.
2502         push (@values, $name . '-local');
2503         push (@phony, $name . '-local');
2504     }
2505
2506     local ($done) = 0;
2507     if ($name eq 'check')
2508     {
2509         if (! &variable_defined ('SUBDIRS'))
2510         {
2511             # 'check' must depend on `all', but not when doing
2512             # recursive build.
2513             unshift (@values, 'all');
2514         }
2515         else
2516         {
2517             # When subdirs are used, do the `all' build and then do
2518             # all the recursive stuff.  Actually use `all-am' because
2519             # it doesn't recurse; we rely on the check target in the
2520             # subdirs to do the required builds there.
2521             $output_rules .= "check: all-am\n";
2522             &pretty_print_rule ("\t\$(MAKE)", "\t  ", @values);
2523             $done = 1;
2524         }
2525     }
2526
2527     &pretty_print_rule ($name . ":", "\t\t", @values)
2528         unless $done;
2529     push (@phony, $name);
2530 }
2531
2532 # Handle all 'clean' targets.
2533 sub handle_clean
2534 {
2535     push (@clean, 'generic');
2536     $output_rules .= &file_contents ('clean');
2537     &push_phony_cleaners ('generic');
2538
2539     local ($target) = $recursive_install ? 'clean-am' : 'clean';
2540     &do_one_clean_target ($target, 'mostly', '', @clean);
2541     &do_one_clean_target ($target, '', 'mostly', @clean);
2542     &do_one_clean_target ($target, 'dist', '', @clean);
2543     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
2544
2545     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
2546
2547     local (@deps);
2548     if ($recursive_install)
2549     {
2550         @deps = ('am', 'recursive');
2551         &do_one_clean_target ('', 'mostly', '', @deps);
2552         &do_one_clean_target ('', '', '', @deps);
2553         &do_one_clean_target ('', 'dist', '', @deps);
2554         &do_one_clean_target ('', 'maintainer-', '', @deps);
2555     }
2556 }
2557
2558 # Helper for handle_clean.
2559 sub do_one_clean_target
2560 {
2561     local ($target, $name, $last_name, @deps) = @_;
2562
2563     # Special case: if target not passed, then don't generate
2564     # dependency on next "lower" clean target (eg no
2565     # clean<-mostlyclean derivation).  In this case the target is
2566     # implicitly known to be 'clean'.
2567     local ($flag) = $target;
2568     $target = 'clean' if ! $flag;
2569
2570     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
2571     if ($flag)
2572     {
2573         if ($last_name || $name ne 'mostly')
2574         {
2575             push (@deps, $last_name . $target . " ");
2576         }
2577     }
2578     # FIXME: not sure if I like the tabs here.
2579     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
2580
2581     # FIXME: shouldn't we really print these messages before running
2582     # the dependencies?
2583     if ($name . $target eq 'maintainer-clean')
2584     {
2585         # Print a special warning.
2586         $output_rules .=
2587             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
2588              . "\t\@echo \"it deletes files that may require special "
2589              . "tools to rebuild.\"\n");
2590
2591         $output_rules .= "\trm -f config.status\n"
2592             if $relative_dir eq '.';
2593     }
2594     elsif ($name . $target eq 'distclean')
2595     {
2596         $output_rules .= "\trm -f config.status\n";
2597     }
2598     $output_rules .= "\n";
2599 }
2600
2601 # Handle .PHONY target.
2602 sub handle_phony
2603 {
2604     &pretty_print_rule ('.PHONY:', "", @phony);
2605     $output_rules .= "\n";
2606 }
2607
2608 # Handle TESTS variable and other checks.
2609 sub handle_tests
2610 {
2611     if (defined $options{'dejagnu'})
2612     {
2613         push (@check, 'check-DEJAGNU');
2614         push (@phony, 'check-DEJAGNU');
2615         $output_rules .= &file_contents ('dejagnu') . "\n";
2616         # Note that in the rule we don't directly generate site.exp to
2617         # avoid the possibility of a corrupted site.exp if make is
2618         # interrupted.  Jim Meyering has some useful text on this
2619         # topic.
2620         $output_rules .= ("site.exp: Makefile\n"
2621                           . "\t\@echo 'Making a new site.exp file...'\n"
2622                           . "\t-\@rm -f site.bak\n"
2623                           . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
2624                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
2625                           . "\t\@echo '# edit the last section' >> \$\@-t\n"
2626                           . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
2627                           . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
2628                           . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
2629
2630         # Extra stuff for AC_CANONICAL_*
2631         local (@whatlist) = ();
2632         if ($seen_canonical)
2633         {
2634             push (@whatlist, 'host')
2635         }
2636
2637         # Extra stuff only for AC_CANONICAL_SYSTEM.
2638         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
2639         {
2640             push (@whatlist, 'target', 'build');
2641         }
2642
2643         local ($c1, $c2);
2644         foreach $c1 (@whatlist)
2645         {
2646             foreach $c2 ('alias', 'triplet')
2647             {
2648                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
2649             }
2650         }
2651
2652         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
2653                           . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
2654                           . "\t-\@mv site.exp site.bak\n"
2655                           . "\t\@mv \$\@-t site.exp\n");
2656     }
2657     else
2658     {
2659         local ($c);
2660         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
2661         {
2662             if (&variable_defined ($c))
2663             {
2664                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
2665             }
2666         }
2667     }
2668
2669     if (&variable_defined ('TESTS'))
2670     {
2671         push (@check, 'check-TESTS');
2672         push (@phony, 'check-TESTS');
2673         # FIXME: use $(SHELL) here?  That is what Ulrich suggests.
2674         # Maybe a new macro, $(TEST_SHELL), a la $(CONFIG_SHELL)?  For
2675         # now we just execute the file directly; this allows test
2676         # files which are compiled -- a possibly useful feature.
2677         $output_rules .= 'check-TESTS: $(TESTS)
2678         @failed=0; all=0; \\
2679         srcdir=$(srcdir); export srcdir; \\
2680         for tst in $(TESTS); do \\
2681           all=`expr $$all + 1`; \\
2682           if test -f $$tst; then dir=.; \\
2683           else dir="$(srcdir)"; fi; \\
2684           if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
2685             echo "PASS: $$tst"; \\
2686           else \\
2687             failed=`expr $$failed + 1`; \\
2688             echo "FAIL: $$tst"; \\
2689           fi; \\
2690         done; \\
2691         if test "$$failed" -eq 0; then \\
2692           echo "========================"; \\
2693           echo "All $$all tests passed"; \\
2694           echo "========================"; \\
2695         else \\
2696           echo "$$failed of $$all tests failed"; \\
2697         fi
2698 ';
2699     }
2700 }
2701
2702 # Handle Emacs Lisp.
2703 sub handle_emacs_lisp
2704 {
2705     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
2706
2707     if (@elfiles)
2708     {
2709         # Found some lisp.
2710         &define_variable ("lispdir", "\@lispdir\@");
2711         &define_variable ("EMACS", "\@EMACS\@");
2712         $output_rules .= (".el.elc:\n"
2713                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
2714                           . "\t\EMACS=$(EMACS) $(SHELL) \$(srcdir)/elisp-comp \$<\n");
2715         push (@suffixes, '.el', '.elc');
2716
2717         # Generate .elc files.
2718         grep ($_ .= 'c', @elfiles);
2719         &define_pretty_variable ('ELCFILES', @elfiles);
2720
2721         push (@clean, 'lisp');
2722         &push_phony_cleaners ('lisp');
2723
2724         local ($varname);
2725         if (&variable_defined ('lisp_LISP'))
2726         {
2727             $varname = 'lisp_LISP';
2728             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
2729                 if ! $seen_lispdir;
2730         }
2731         else
2732         {
2733             $varname = 'noinst_LISP';
2734         }
2735
2736         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
2737     }
2738 }
2739
2740 ################################################################
2741
2742 # Scan configure.in for interesting things.
2743 sub scan_configure
2744 {
2745     open (CONFIGURE, 'configure.in')
2746         || die "automake: couldn't open \`configure.in': $!\n";
2747     print "automake: reading configure.in\n" if $verbose;
2748
2749     # Reinitialize libsources here.  This isn't really necessary,
2750     # since we currently assume there is only one configure.in.  But
2751     # that won't always be the case.
2752     %libsources = ();
2753
2754     local ($in_ac_output, $in_ac_replace, @make_list) = (0, 0);
2755     local ($libobj_iter);
2756     while (<CONFIGURE>)
2757     {
2758         # Remove comments from current line.
2759         s/\bdnl\b.*$//;
2760         s/\#.*$//;
2761
2762         # Populate libobjs array.
2763         if (/AC_FUNC_ALLOCA/)
2764         {
2765             $libsources{'alloca.c'} = 1;
2766         }
2767         elsif (/AC_FUNC_GETLOADAVG/)
2768         {
2769             $libsources{'getloadavg.c'} = 1;
2770         }
2771         elsif (/AC_FUNC_MEMCMP/)
2772         {
2773             $libsources{'memcmp.c'} = 1;
2774         }
2775         elsif (/AC_STRUCT_ST_BLOCKS/)
2776         {
2777             $libsources{'fileblocks.c'} = 1;
2778         }
2779         elsif (/AM_FUNC_FNMATCH/)
2780         {
2781             $libsources{'fnmatch.c'} = 1;
2782         }
2783         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
2784         {
2785             $libsources{'getopt.c'} = 1;
2786             $libsources{'getopt1.c'} = 1;
2787         }
2788         elsif (/AM_FUNC_STRTOD/)
2789         {
2790             $libsources{'strtod.c'} = 1;
2791         }
2792         elsif (/AM_WITH_REGEX/)
2793         {
2794             $libsources{'rx.c'} = 1;
2795             $libsources{'rx.h'} = 1;
2796             $libsources{'regex.c'} = 1;
2797             $libsources{'regex.h'} = 1;
2798         }
2799         elsif (/AM_FUNC_MKTIME/)
2800         {
2801             $libsources{'mktime.c'} = 1;
2802         }
2803         elsif (/AM_FUNC_ERROR_AT_LINE/)
2804         {
2805             $libsources{'error.c'} = 1;
2806             $libsources{'error.h'} = 1;
2807         }
2808         elsif (/AM_FUNC_OBSTACK/)
2809         {
2810             $libsources{'obstack.c'} = 1;
2811             $libsources{'obstack.h'} = 1;
2812         }
2813         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
2814                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
2815         {
2816             foreach $libobj_iter (split (' ', $1))
2817             {
2818                 if ($libobj_iter =~ /^(.*)\.o$/)
2819                 {
2820                     $libsources{$1 . '.c'} = 1;
2821                 }
2822             }
2823         }
2824
2825         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
2826         {
2827             $in_ac_replace = 1;
2828         }
2829         if ($in_ac_replace)
2830         {
2831             $in_ac_replace = 0 if s/[\]\)].*$//;
2832             # Remove trailing backslash.
2833             s/\\$//;
2834             foreach (split)
2835             {
2836                 $libsources{$_ . '.c'} = 1;
2837             }
2838         }
2839
2840         if (/(fp_WITH_DMALLOC|fp_WITH_REGEX|fp_FUNC_FNMATCH|fp_PROG_INSTALL|fp_C_PROTOTYPES|jm_MAINTAINER_MODE)/)
2841         {
2842             &am_conf_line_error ($., "\`$1' is obsolete; use corresponding \`AM_' macro");
2843         }
2844
2845         # Process the AC_OUTPUT macro.
2846         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
2847         {
2848             $in_ac_output = 1;
2849             $ac_output_line = $.;
2850         }
2851         if ($in_ac_output)
2852         {
2853             $in_ac_output = 0 if s/[\]\),].*$//;
2854
2855             # Look at potential Makefile.am's.
2856             foreach (split)
2857             {
2858                 next if $_ eq "\\";
2859                 if (-f $_ . '.am')
2860                 {
2861                     push (@make_list, $_);
2862                 }
2863                 else
2864                 {
2865                     push (@other_input_files, $_);
2866                 }
2867             }
2868         }
2869
2870         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
2871         {
2872             @config_aux_path = $1;
2873         }
2874
2875         # Check for ansi2knr.
2876         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
2877
2878         # Check for NLS support.
2879         if (/ud_GNU_GETTEXT/)
2880         {
2881             $seen_gettext = 1;
2882             $ac_gettext_line = $.;
2883         }
2884
2885         # Look for ALL_LINGUAS.
2886         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
2887         {
2888             $seen_linguas = 1;
2889             $all_linguas = $1;
2890             $all_linguas_line = $.;
2891         }
2892
2893         # Handle configuration headers.
2894         if (/AC_CONFIG_HEADER\s*\((.*)\)/)
2895         {
2896             $config_header_line = $.;
2897             $config_name = $1;
2898             if ($config_name =~ /^([^:]+):(.+)$/)
2899             {
2900                 $config_name = $1;
2901                 $config_header = $2;
2902             }
2903             else
2904             {
2905                 $config_header = $config_name . '.in';
2906             }
2907         }
2908
2909         # Handle AC_CANONICAL_*.  Always allow upgrading to
2910         # AC_CANONICAL_SYSTEM, but never downgrading.
2911         $seen_canonical = $AC_CANONICAL_HOST
2912             if ! $seen_canonical
2913                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
2914         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
2915
2916         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
2917
2918         # Sometimes it is desirable to explicitly set YACC.  For
2919         # instance some people don't want to use bison.
2920         $seen_prog_yacc = 1 if (/AC_PROG_YACC/
2921                                 || /AC_SUBST\(YACC\)/
2922                                 || /AC_(PATH|CHECK)_PROGS?\(YACC/);
2923
2924         # This macro handles several different things.
2925         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
2926         {
2927             $seen_make_set = 1;
2928             $seen_package = 1;
2929             $seen_version = 1;
2930             $seen_arg_prog = 1;
2931             $seen_prog_install = 2;
2932             ($package_version = $1) =~ s/\s//;
2933             $package_version_line = $.;
2934         }
2935
2936         # Some things required by Automake.
2937         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
2938         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
2939         $seen_ranlib = 1 if /AC_PROG_RANLIB/;
2940         $seen_prog_cc = 1 if /AC_PROG_CC/;
2941         $seen_prog_cxx = 1 if /AC_PROG_CXX/;
2942         $seen_prog_lex = 1 if /AC_PROG_LEX/;
2943         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
2944         $seen_maint_mode = 1 if /AM_MAINTAINER_MODE/;
2945         $seen_package = 1 if /PACKAGE=/;
2946
2947         if (/VERSION=(\S+)/)
2948         {
2949             $seen_version = 1;
2950             $package_version = $1;
2951             $package_version_line = $.;
2952         }
2953         elsif (/VERSION=/)
2954         {
2955             $seen_version = 1;
2956         }
2957
2958         # Weird conditionals here because it is always allowed to
2959         # upgrade to AM_PROG_INSTALL but never to downgrade to
2960         # AC_PROG_INSTALL.
2961         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
2962         $seen_prog_install = 2 if /AM_PROG_INSTALL/;
2963
2964         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
2965
2966         if (/AM_PROG_LIBTOOL/)
2967         {
2968             $seen_libtool = 1;
2969             $seen_ranlib = 2;
2970             $libtool_line = $.;
2971         }
2972     }
2973
2974     # Set input files if not specified by user.
2975     @input_files = @make_list if (! @input_files);
2976
2977     close (CONFIGURE);
2978
2979     &am_conf_error ("\`PACKAGE' not defined in configure.in")
2980         if ! $seen_package;
2981     &am_conf_error ("\`VERSION' not defined in configure.in")
2982         if ! $seen_version;
2983
2984     # Look for some files we need.  Always check for these.  This
2985     # check must be done for every run, even those where we are only
2986     # looking at a subdir Makefile.  We must set relative_dir so that
2987     # the file-finding machinery works.
2988     local ($relative_dir) = '.';
2989     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs');
2990     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
2991         if -f $config_aux_path[0] . '/install.sh';
2992 }
2993
2994 ################################################################
2995
2996 # Do any extra checking for GNU standards.
2997 sub check_gnu_standards
2998 {
2999     if ($relative_dir eq '.')
3000     {
3001         # In top level (or only) directory.
3002         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
3003                        'AUTHORS', 'ChangeLog');
3004     }
3005
3006     if ($strictness >= $GNU)
3007     {
3008         if (defined $options{'no-installman'})
3009         {
3010             &am_line_error ('AUTOMAKE_OPTIONS',
3011                             "option \`no-installman' disallowed by GNU standards");
3012         }
3013
3014         if (defined $options{'no-installinfo'})
3015         {
3016             &am_line_error ('AUTOMAKE_OPTIONS',
3017                             "option \`no-installinfo' disallowed by GNU standards");
3018         }
3019     }
3020 }
3021
3022 # Do any extra checking for GNITS standards.
3023 sub check_gnits_standards
3024 {
3025     if ($strictness >= $GNITS)
3026     {
3027         if (-f $relative_dir . '/COPYING.LIB')
3028         {
3029             &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
3030         }
3031
3032         if ($relative_dir eq '.')
3033         {
3034             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
3035             {
3036                 &am_conf_line_error ($package_version_line,
3037                                      "version \`$package_version' doesn't follow Gnits standards");
3038             }
3039             elsif (defined $1 && -f 'README-alpha')
3040             {
3041                 # This means we have an alpha release.  See
3042                 # GNITS_VERSION_PATTERN for details.
3043                 &require_file ($GNITS, 'README-alpha');
3044             }
3045         }
3046     }
3047
3048     if ($relative_dir eq '.')
3049     {
3050         # In top level (or only) directory.
3051         &require_file ($GNITS, 'THANKS');
3052     }
3053 }
3054
3055 ################################################################
3056
3057 # Pretty-print something.  HEAD is what should be printed at the
3058 # beginning of the first line, FILL is what should be printed at the
3059 # beginning of every subsequent line.
3060 sub pretty_print_internal
3061 {
3062     local ($head, $fill, @values) = @_;
3063
3064     local ($column) = length ($head);
3065     local ($result) = $head;
3066
3067     # Fill length is number of characters.  However, each Tab
3068     # character counts for eight.  So we count the number of Tabs and
3069     # multiply by 7.
3070     local ($fill_length) = length ($fill);
3071     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
3072
3073     local ($bol) = 0;
3074     foreach (@values)
3075     {
3076         # "71" because we also print a space.
3077         if ($column + length ($_) > 71)
3078         {
3079             $result .= " \\\n" . $fill;
3080             $column = $fill_length;
3081             $bol = 1;
3082         }
3083
3084         $result .= ' ' unless ($bol);
3085         $result .= $_;
3086         $column += length ($_) + 1;
3087         $bol = 0;
3088     }
3089
3090     $result .= "\n";
3091     return $result;
3092 }
3093
3094 # Pretty-print something and append to output_vars.
3095 sub pretty_print
3096 {
3097     $output_vars .= &pretty_print_internal (@_);
3098 }
3099
3100 # Pretty-print something and append to output_rules.
3101 sub pretty_print_rule
3102 {
3103     $output_rules .= &pretty_print_internal (@_);
3104 }
3105
3106
3107 ################################################################
3108
3109 # See if a variable exists.
3110 sub variable_defined
3111 {
3112     local ($var) = @_;
3113     if (defined $targets{$var})
3114     {
3115         &am_line_error ($var, "\`$var' is target; expected variable");
3116         return 0;
3117     }
3118     elsif (defined $contents{$var})
3119     {
3120         $content_seen{$var} = 1;
3121         return 1;
3122     }
3123     return 0;
3124 }
3125
3126 # Mark a variable as examined.
3127 sub examine_variable
3128 {
3129     local ($var) = @_;
3130     &variable_defined ($var);
3131 }
3132
3133 # Return contents of variable as list, split as whitespace.  This will
3134 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
3135 # substitutions.  If PARENT is specified, it is the name of the
3136 # including variable; this is only used for error reports.
3137 sub variable_value_as_list
3138 {
3139     local ($var, $parent) = @_;
3140     local (@result);
3141
3142     if (defined $targets{$var})
3143     {
3144         &am_line_error ($var, "\`$var' is target; expected variable");
3145     }
3146     elsif (! defined $contents{$var})
3147     {
3148         &am_line_error ($parent, "variable \`$var' not defined");
3149     }
3150     else
3151     {
3152         $content_seen{$var} = 1;
3153         foreach (split (' ', $contents{$var}))
3154         {
3155             # If a comment seen, just leave.
3156             last if /^#/;
3157
3158             # Handle variable substitutions.
3159             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
3160             {
3161                 push (@result, &variable_value_as_list ($1, $var));
3162             }
3163             else
3164             {
3165                 push (@result, $_);
3166             }
3167         }
3168     }
3169
3170     return @result;
3171 }
3172
3173 # Define a new variable, but only if not already defined.
3174 sub define_variable
3175 {
3176     local ($var, $value) = @_;
3177
3178     if (! defined $contents{$var})
3179     {
3180         $output_vars .= $var . ' = ' . $value . "\n";
3181         $contents{$var} = $value;
3182         $content_seen{$var} = 1;
3183     }
3184 }
3185
3186 # Like define_variable, but second arg is a list, and is
3187 # pretty-printed.
3188 sub define_pretty_variable
3189 {
3190     local ($var, @value) = @_;
3191     if (! defined $contents{$var})
3192     {
3193         $contents{$var} = join (' ', @value);
3194         &pretty_print ($var . ' = ', '', @value);
3195         $content_seen{$var} = 1;
3196     }
3197 }
3198
3199 # Read Makefile.am and set up %contents.  Simultaneously copy lines
3200 # from Makefile.am into $output_trailer or $output_vars as
3201 # appropriate.  NOTE we put rules in the trailer section.  We want
3202 # user rules to come after our generated stuff.
3203 sub read_am_file
3204 {
3205     local ($amfile) = @_;
3206
3207     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
3208     print "automake: reading $amfile\n" if $verbose;
3209
3210     $output_vars = ("# $in_file_name generated automatically by automake "
3211                     . $VERSION . " from $am_file_name\n");
3212
3213     # Generate copyright for generated Makefile.in.
3214     $output_vars .= $gen_copyright;
3215
3216     local ($saw_bk) = 0;
3217     local ($was_rule) = 0;
3218     local ($spacing) = '';
3219     local ($comment) = '';
3220     local ($last_var_name) = '';
3221     local ($blank) = 0;
3222
3223     while (<AM_FILE>)
3224     {
3225         if (/$IGNORE_PATTERN/o)
3226         {
3227             # Merely delete comments beginning with two hashes.
3228         }
3229         elsif (/$WHITE_PATTERN/o)
3230         {
3231             # Stick a single white line before the incoming macro or rule.
3232             $spacing = "\n";
3233             $blank = 1;
3234         }
3235         elsif (/$COMMENT_PATTERN/o)
3236         {
3237             # Stick comments before the incoming macro or rule.  Make
3238             # sure a blank line preceeds first block of comments.
3239             $spacing = "\n" unless $blank;
3240             $blank = 1;
3241             $comment .= $spacing . $_;
3242             $spacing = '';
3243         }
3244         else
3245         {
3246             last;
3247         }
3248     }
3249
3250     $output_vars .= $comment . "\n";
3251     $comment = '';
3252     $spacing = "\n";
3253     local ($am_vars) = '';
3254
3255     local ($is_ok_macro);
3256     while ($_)
3257     {
3258         $_ .= "\n"
3259             unless substr ($_, -1, 1) eq "\n";
3260
3261         $_ =~ s/\@MAINT\@//g
3262             unless $seen_maint_mode;
3263
3264         if (/$IGNORE_PATTERN/o)
3265         {
3266             # Merely delete comments beginning with two hashes.
3267         }
3268         elsif (/$WHITE_PATTERN/o)
3269         {
3270             # Stick a single white line before the incoming macro or rule.
3271             $spacing = "\n";
3272         }
3273         elsif (/$COMMENT_PATTERN/o)
3274         {
3275             # Stick comments before the incoming macro or rule.
3276             $comment .= $spacing . $_;
3277             $spacing = '';
3278         }
3279         elsif ($saw_bk)
3280         {
3281             if ($was_rule)
3282             {
3283                 $output_trailer .= $_;
3284                 $saw_bk = /\\$/;
3285             }
3286             else
3287             {
3288                 $am_vars .= $_;
3289                 $saw_bk = /\\$/;
3290                 # Chop newline and backslash if this line is
3291                 # continued.  FIXME: maybe ensure trailing whitespace
3292                 # exists?
3293                 chop if $saw_bk;
3294                 chop if $saw_bk;
3295                 $contents{$last_var_name} .= $_;
3296             }
3297         }
3298         elsif (/$RULE_PATTERN/o)
3299         {
3300             # warn "** Saw rule .$1.\n";
3301             # Found a rule.
3302             $was_rule = 1;
3303             # Value here doesn't matter; for targets we only note
3304             # existence.
3305             $contents{$1} = 1;
3306             $targets{$1} = 1;
3307             $content_lines{$1} = $.;
3308             $output_trailer .= $comment . $spacing . $_;
3309             $comment = $spacing = '';
3310             $saw_bk = /\\$/;
3311         }
3312         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
3313                || /$BOGUS_MACRO_PATTERN/o)
3314         {
3315             # Found a macro definition.
3316             $was_rule = 0;
3317             $last_var_name = $1;
3318             if (substr ($2, -1) eq "\\")
3319             {
3320                 $contents{$1} = substr ($2, 0, length ($2) - 1);
3321             }
3322             else
3323             {
3324                 $contents{$1} = $2;
3325             }
3326             $content_lines{$1} = $.;
3327             $am_vars .= $comment . $spacing . $_;
3328             $comment = $spacing = '';
3329             $saw_bk = /\\$/;
3330
3331             # Error if bogus.
3332             &am_line_error ($., "bad macro name \`$1'")
3333                 if ! $is_ok_macro;
3334         }
3335         else
3336         {
3337             # This isn't an error; it is probably a continued rule.
3338             # In fact, this is what we assume.
3339             $was_rule = 1;
3340             $output_trailer .= $comment . $spacing . $_;
3341             $comment = $spacing = '';
3342             $saw_bk = /\\$/;
3343         }
3344
3345         $_ = <AM_FILE>;
3346     }
3347
3348     $output_trailer .= $comment;
3349
3350     # Compute relative location of the top object directory.
3351     local (@topdir) = ();
3352     foreach (split (/\//, $relative_dir))
3353     {
3354         next if $_ eq '.' || $_ eq '';
3355         if ($_ eq '..')
3356         {
3357             pop @topdir;
3358         }
3359         else
3360         {
3361             push (@topdir, '..');
3362         }
3363     }
3364     @topdir = ('.') if ! @topdir;
3365
3366     $top_builddir = join ('/', @topdir);
3367     local ($build_rx);
3368     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
3369     $output_vars .= &file_contents_with_transform
3370                         ('s/\@top_builddir\@/' . $build_rx . '/g',
3371                          'header-vars');
3372
3373     # Generate some useful variables when AC_CANONICAL_* used.
3374     if ($seen_canonical)
3375     {
3376         local ($curs, %vars);
3377         $vars{'host_alias'} = 'host_alias';
3378         $vars{'host_triplet'} = 'host';
3379         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
3380         {
3381             $vars{'build_alias'} = 'build_alias';
3382             $vars{'build_triplet'} = 'build';
3383             $vars{'target_alias'} = 'target_alias';
3384             $vars{'target_triplet'} = 'target';
3385         }
3386         foreach $curs (keys %vars)
3387         {
3388             $output_vars .= "$curs = \@$vars{$curs}\@\n";
3389             $contents{$curs} = "\@$vars{$curs}\@";
3390         }
3391     }
3392
3393     $output_vars .= $am_vars;
3394 }
3395
3396 ################################################################
3397
3398 sub initialize_global_constants
3399 {
3400     # Values for AC_CANONICAL_*
3401     $AC_CANONICAL_HOST = 1;
3402     $AC_CANONICAL_SYSTEM = 2;
3403
3404     # Associative array of standard directory names.  Entry is TRUE if
3405     # corresponding directory should be installed during
3406     # 'install-exec' phase.
3407     %exec_dir_p =
3408         ('bin', 1,
3409          'sbin', 1,
3410          'libexec', 1,
3411          'data', 0,
3412          'sysconf', 1,
3413          'localstate', 1,
3414          'lib', 1,
3415          'info', 0,
3416          'man', 0,
3417          'include', 0,
3418          'oldinclude', 0,
3419          'pkgdata', 0,
3420          'pkglib', 1,
3421          'pkginclude', 0
3422          );
3423
3424     # Helper text for dealing with man pages.
3425     $install_man_format =
3426     '   sect=@SECTION@;                         \\
3427         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
3428         if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
3429         else file=@MAN@; fi; \\
3430         $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst
3431 ';
3432
3433     $uninstall_man_format =
3434     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
3435         rm -f $(mandir)/man@SECTION@/$$inst
3436 ';
3437
3438     # Commonly found files we look for and automatically include in
3439     # DISTFILES.
3440     @common_files =
3441         (
3442          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
3443          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
3444          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
3445          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
3446          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
3447          'interlock', 'ylwrap', 'acinclude.m4'
3448          );
3449
3450     # Commonly used files we auto-include, but only sometimes.
3451     @common_sometimes =
3452         (
3453          "aclocal.m4", "acconfig.h", "config.h.top",
3454          "config.h.bot", "stamp-h.in", 'stamp-vti', 'libtool'
3455          );
3456
3457     $USAGE = "\
3458   -a, --add-missing     add missing standard files to package
3459   --amdir=DIR           directory storing config files
3460   --build-dir=DIR       directory where build being done (for dependencies)
3461   --foreign             same as --strictness=foreign
3462   --gnits               same as --strictness=gnits
3463   --gnu                 same as --strictness=gnu
3464   --help                print this help, then exit
3465   -i, --include-deps    include generated dependencies in Makefile.in
3466   --no-force            only update Makefile.in's that are out of date
3467   -o DIR, --output-dir=DIR
3468                         put generated Makefile.in's into DIR
3469   --srcdir-name=DIR     name used for srcdir (for dependencies)
3470   -s LEVEL, --strictness=LEVEL
3471                         set strictness level.  LEVEL is foreign, gnu, gnits
3472   -v, --verbose         verbosely list files processed
3473   --version             print version number, then exit\n";
3474
3475     # Copyright on generated Makefile.ins.
3476     $gen_copyright = "\
3477 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
3478 # This Makefile.in is free software; the Free Software Foundation
3479 # gives unlimited permission to copy, distribute and modify it.
3480 ";
3481
3482     # Ignore return result from chmod, because it might give an error
3483     # if we chmod a symlink.
3484     $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
3485     $dist{'tarZ'} = ("\t"
3486                      . '$(TAR) chf - $(distdir) | compress -c > $(distdir).tar.Z'
3487                      . "\n");
3488     $dist{'shar'} = ("\t"
3489                      . 'shar $(distdir) | gzip > $(distdir).shar.gz'
3490                      . "\n");
3491     $dist{'zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
3492     $dist{'dist'} = "\t" .  '$(TAR) chozf $(distdir).tar.gz $(distdir)' . "\n";
3493     $dist_trailer = "\t" . 'rm -rf $(distdir)' . "\n";
3494 }
3495
3496 # (Re)-Initialize per-Makefile.am variables.
3497 sub initialize_per_input
3498 {
3499     # These two variables are used when generating each Makefile.in.
3500     # They hold the Makefile.in until it is ready to be printed.
3501     $output_rules = '';
3502     $output_vars = '';
3503     $output_trailer = '';
3504
3505     # Suffixes found during a run.
3506     @suffixes = ();
3507
3508     # This holds the contents of a Makefile.am, as parsed by
3509     # read_am_file.
3510     %contents = ();
3511
3512     # This holds the names which are targets.  These also appear in
3513     # %contents.
3514     %targets = ();
3515
3516     # This holds the line numbers at which various elements of
3517     # %contents are defined.
3518     %content_lines = ();
3519
3520     # This holds a 1 if a particular variable was examined.
3521     %content_seen = ();
3522
3523     # This holds the "relative directory" of the current Makefile.in.
3524     # Eg for src/Makefile.in, this is "src".
3525     $relative_dir = '';
3526
3527     # This holds a list of files that are included in the
3528     # distribution.
3529     %dist_common = ();
3530
3531     # List of dependencies for the obvious targets.
3532     @install_data = ();
3533     @install_exec = ();
3534     @uninstall = ();
3535     @installdirs = ();
3536
3537     @info = ();
3538     @dvi = ();
3539     @all = ();
3540     @check = ();
3541     @installcheck = ();
3542     @clean = ();
3543
3544     @phony = ();
3545
3546     # These are pretty obvious, too.  They are used to define the
3547     # SOURCES and OBJECTS variables.
3548     @sources = ();
3549     @objects = ();
3550
3551     # TRUE if current directory holds any C source files.  (Actually
3552     # holds object extension, but this information is encapsulated in
3553     # the function get_object_extension).
3554     $dir_holds_sources = '';
3555
3556     # TRUE if current directory holds any headers.
3557     $dir_holds_headers = 0;
3558
3559     # TRUE if install targets should work recursively.
3560     $recursive_install = 0;
3561
3562     # All .P files.
3563     %dep_files = ();
3564
3565     # Strictness levels.
3566     $strictness = $default_strictness;
3567     $strictness_name = $default_strictness_name;
3568
3569     # Options from AUTOMAKE_OPTIONS.
3570     %options = ();
3571
3572     # Whether or not dependencies are handled.  Can be further changed
3573     # in handle_options.
3574     $use_dependencies = $cmdline_use_dependencies;
3575
3576     # Per Makefile.am.
3577     $local_maint_charset = $maint_charset;
3578
3579     # All yacc and lex source filenames for this directory.  Use
3580     # filenames instead of raw count so that multiple instances are
3581     # counted correctly (eg one yacc file can appear in multiple
3582     # programs without harm).
3583     %yacc_sources = ();
3584     %lex_sources = ();
3585
3586     # C++ source extensions we've seen.
3587     %cxx_extensions = ();
3588
3589     # TRUE if we've seen any non-C++ sources.
3590     $seen_c_source = 0;
3591 }
3592
3593
3594 ################################################################
3595
3596 # Return contents of a file from $am_dir, automatically skipping
3597 # macros or rules which are already known.  Runs command on each line
3598 # as it is read; this command can modify $_.
3599 sub file_contents_with_transform
3600 {
3601     local ($command, $basename) = @_;
3602     local ($file) = $am_dir . '/' . $basename . '.am';
3603
3604     open (FC_FILE, $file)
3605         || die "automake: installation error: cannot open \`$file'\n";
3606     # Looks stupid?
3607     # print "automake: reading $file\n" if $verbose;
3608
3609     local ($was_rule) = 0;
3610     local ($result_vars) = '';
3611     local ($result_rules) = '';
3612     local ($comment) = '';
3613     local ($spacing) = "\n";
3614     local ($skipping) = 0;
3615
3616     while (<FC_FILE>)
3617     {
3618         $_ =~ s/\@MAINT\@//g
3619             unless $seen_maint_mode;
3620
3621         eval $command;
3622
3623         if (/$IGNORE_PATTERN/o)
3624         {
3625             # Merely delete comments beginning with two hashes.
3626         }
3627         elsif (/$WHITE_PATTERN/o)
3628         {
3629             # Stick a single white line before the incoming macro or rule.
3630             $spacing = "\n";
3631         }
3632         elsif (/$COMMENT_PATTERN/o)
3633         {
3634             # Stick comments before the incoming macro or rule.
3635             $comment .= $spacing . $_;
3636             $spacing = '';
3637         }
3638         elsif ($saw_bk)
3639         {
3640             if ($was_rule)
3641             {
3642                 $result_rules .= $_ if ! $skipping;
3643             }
3644             else
3645             {
3646                 $result_vars .= $_ if ! $skipping;
3647             }
3648             $saw_bk = /\\$/;
3649         }
3650         elsif (/$RULE_PATTERN/o)
3651         {
3652             # warn "** Found rule .$1.\n";
3653             # Found a rule.
3654             $was_rule = 1;
3655             $skipping = defined $contents{$1};
3656             # warn "** Skip $skipping\n" if $skipping;
3657             $result_rules .= $comment . $spacing . $_ if ! $skipping;
3658             $comment = $spacing = '';
3659             $saw_bk = /\\$/;
3660         }
3661         elsif (/$MACRO_PATTERN/o)
3662         {
3663             # warn "** Found macro .$1.\n";
3664             # Found a variable reference.
3665             $was_rule = 0;
3666             $skipping = defined $contents{$1};
3667             # warn "** Skip $skipping\n" if $skipping;
3668             $result_vars .= $comment . $spacing . $_ if ! $skipping;
3669             $comment = $spacing = '';
3670             $saw_bk = /\\$/;
3671         }
3672         else
3673         {
3674             # This isn't an error; it is probably a continued rule.
3675             # In fact, this is what we assume.
3676             $was_rule = 1;
3677             $result_rules .= $comment . $spacing . $_ if ! $skipping;
3678             $comment = $spacing = '';
3679             $saw_bk = /\\$/;
3680         }
3681     }
3682
3683     close (FC_FILE);
3684     return $result_vars . $result_rules . $comment;
3685 }
3686
3687 # Like file_contents_with_transform, but no transform.
3688 sub file_contents
3689 {
3690     return &file_contents_with_transform ('', @_);
3691 }
3692
3693 # Find all variable prefixes that are used for install directories.  A
3694 # prefix `zar' qualifies iff:
3695 # * `zardir' is a variable.
3696 # * `zar_PRIMARY' is a variable.
3697 sub am_primary_prefixes
3698 {
3699     local ($primary, @prefixes) = @_;
3700
3701     local (%valid, $varname);
3702     grep ($valid{$_} = 0, @prefixes);
3703     $valid{'EXTRA'} = 0;
3704     foreach $varname (keys %contents)
3705     {
3706         if ($varname =~ /^(.*)_$primary$/)
3707         {
3708             if (! defined $valid{$1} && ! &variable_defined ($1 . 'dir'))
3709             {
3710                 &am_line_error ($varname, "invalid variable \"$varname\"");
3711             }
3712             else
3713             {
3714                 # Ensure all extended prefixes are actually used.
3715                 $valid{$1} = 1;
3716             }
3717         }
3718     }
3719
3720     return %valid;
3721 }
3722
3723 # Handle `where_HOW' variable magic.  Does all lookups, generates
3724 # install code, and possibly generates code to define the primary
3725 # variable.  The first argument is the name of the .am file to munge,
3726 # the second argument is the primary variable (eg HEADERS), and all
3727 # subsequent arguments are possible installation locations.  Returns
3728 # list of all values of all _HOW targets.
3729 #
3730 # FIXME: this should be rewritten to be cleaner.  It should be broken
3731 # up into multiple functions.
3732 #
3733 # Usage is: am_install_var (OPTION..., file, HOW, where...)
3734 sub am_install_var
3735 {
3736     local (@args) = @_;
3737
3738     local ($do_all, $do_clean) = (1, 0);
3739     while (@args)
3740     {
3741         if ($args[0] eq '-clean')
3742         {
3743             $do_clean = 1;
3744         }
3745         elsif ($args[0] eq '-no-all')
3746         {
3747             $do_all = 0;
3748         }
3749         elsif ($args[0] !~ /^-/)
3750         {
3751             last;
3752         }
3753         shift (@args);
3754     }
3755     local ($file, $primary, @prefixes) = @args;
3756
3757     local (@used) = ();
3758     local (@result) = ();
3759
3760     # Now that configure substitutions are allowed in where_HOW
3761     # variables, it is an error to actually define the primary.
3762     &am_line_error ($primary, "\`$primary' is an anachronism")
3763         if &variable_defined ($primary);
3764
3765
3766     # Look for misspellings.  It is an error to have a variable ending
3767     # in a "reserved" suffix whose prefix is unknown, eg
3768     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
3769     # variable of the same name (with "dir" appended) exists.  For
3770     # instance, if the variable "zardir" is defined, then
3771     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
3772     # flexibility in those cases which need it.  Perhaps it should be
3773     # disallowed in the Gnits case?  The problem is, sometimes it is
3774     # useful to put things in a subdir of eg pkgdatadir, perhaps even
3775     # for Gnitsoids.
3776     local (%valid) = &am_primary_prefixes ($primary, @prefixes);
3777
3778     # If a primary includes a configure substitution, then the EXTRA_
3779     # form is required.  Otherwise we can't properly do our job.
3780     local ($require_extra);
3781     local ($warned_about_extra) = 0;
3782
3783     local ($clean_file) = $file . '-clean';
3784     local ($one_name);
3785     local ($X);
3786     foreach $X (keys %valid)
3787     {
3788         $one_name = $X . '_' . $primary;
3789         if (&variable_defined ($one_name))
3790         {
3791             # Append actual contents of where_PRIMARY variable to
3792             # result.
3793             local ($rcurs);
3794             foreach $rcurs (&variable_value_as_list ($one_name))
3795             {
3796                 # Skip configure substitutions.  Possibly bogus.
3797                 if ($rcurs =~ /^\@.*\@$/)
3798                 {
3799                     if ($X eq 'EXTRA')
3800                     {
3801                         if (! $warned_about_extra)
3802                         {
3803                             $warned_about_extra = 1;
3804                             &am_line_error ($one_name,
3805                                             "\`$one_name' contains configure substitution, but shouldn't");
3806                         }
3807                     }
3808                     else
3809                     {
3810                         $require_extra = $one_name;
3811                     }
3812                     next;
3813                 }
3814                 push (@result, $rcurs);
3815             }
3816
3817             # "EXTRA" shouldn't be used when generating clean targets,
3818             # @all, or install targets.
3819             next if $X eq 'EXTRA';
3820
3821             if ($do_clean)
3822             {
3823                 $output_rules .=
3824                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
3825                                                    $clean_file);
3826
3827                 push (@clean, $X . $primary);
3828                 &push_phony_cleaners ($X . $primary);
3829             }
3830
3831             if ($X eq 'check')
3832             {
3833                 push (@check, '$(' . $one_name . ')');
3834             }
3835             else
3836             {
3837                 push (@used, '$(' . $one_name . ')');
3838             }
3839             if ($X eq 'noinst' || $X eq 'check')
3840             {
3841                 # Objects which don't get installed by default.
3842                 next;
3843             }
3844
3845             $output_rules .=
3846                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
3847                                                $file);
3848
3849             push (@uninstall, 'uninstall-' . $X . $primary);
3850             push (@phony, 'uninstall-' . $X . $primary);
3851             push (@installdirs, '$(' . $X . 'dir)');
3852             if ($exec_dir_p{$X})
3853             {
3854                 push (@install_exec, 'install-' . $X . $primary);
3855                 push (@phony, 'install-' . $X . $primary);
3856             }
3857             else
3858             {
3859                 push (@install_data, 'install-' . $X . $primary);
3860                 push (@phony, 'install-' . $X . $primary);
3861             }
3862         }
3863     }
3864
3865     if (@used)
3866     {
3867         # Define it.
3868         &define_pretty_variable ($primary, @used);
3869         $output_vars .= "\n";
3870     }
3871
3872     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
3873     {
3874         &am_line_error ($require_extra,
3875                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
3876     }
3877
3878     # Push here because PRIMARY might be configure time determined.
3879     push (@all, '$(' . $primary . ')')
3880         if $do_all && @used;
3881
3882     return (@result);
3883 }
3884
3885
3886 ################################################################
3887
3888 # This variable is local to the "require file" set of functions.
3889 @require_file_paths = ();
3890
3891 # Verify that the file must exist in the current directory.  Usage:
3892 # require_file (isconfigure, line_number, strictness, file) strictness
3893 # is the strictness level at which this file becomes required.  Must
3894 # set require_file_paths before calling this function.
3895 # require_file_paths is set to hold a single directory (the one in
3896 # which the first file was found) before return.
3897 sub require_file_internal
3898 {
3899     local ($is_configure, $line, $mystrict, @files) = @_;
3900     local ($file, $fullfile);
3901     local ($found_it, $errfile, $errdir);
3902     local ($save_dir);
3903
3904     foreach $file (@files)
3905     {
3906         $found_it = 0;
3907         foreach $dir (@require_file_paths)
3908         {
3909             if ($dir eq '.')
3910             {
3911                 $fullfile = $relative_dir . "/" . $file;
3912                 $errdir = $relative_dir unless $errdir;
3913             }
3914             else
3915             {
3916                 $fullfile = $dir . "/" . $file;
3917                 $errdir = $dir unless $errdir;
3918             }
3919
3920             # Use different name for "error filename".  Otherwise on
3921             # an error the bad file will be reported as eg
3922             # `../../install-sh' when using the default
3923             # config_aux_path.
3924             $errfile = $errdir . '/' . $file;
3925
3926             if (-f $fullfile)
3927             {
3928                 $found_it = 1;
3929                 # FIXME: Once again, special-case `.'.
3930                 &push_dist_common ($file)
3931                     if $dir eq $relative_dir || $dir eq '.';
3932                 $save_dir = $dir;
3933                 last;
3934             }
3935         }
3936
3937         if ($found_it)
3938         {
3939             # Prune the path list.
3940             @require_file_paths = $save_dir;
3941         }
3942         else
3943         {
3944             if ($strictness >= $mystrict)
3945             {
3946                 local ($trailer) = '';
3947                 local ($suppress) = 0;
3948
3949                 # Only install missing files according to our desired
3950                 # strictness level.
3951                 if ($add_missing && -f ($am_dir . '/' . $file))
3952                 {
3953                     $trailer = "; installing";
3954                     $suppress = 1;
3955                     # Install the missing file.  Symlink if we can, copy
3956                     # if we must.
3957                     if ($symlink_exists)
3958                     {
3959                         if (! symlink ($am_dir . '/' . $file, $errfile))
3960                         {
3961                             $suppress = 0;
3962                             $trailer .= "; error while making link: $!\n";
3963                         }
3964                     }
3965                     else
3966                     {
3967                         if (! system ('cp', $am_dir . '/' . $file, $errfile))
3968                         {
3969                             $suppress = 0;
3970                             $trailer .= "\n    error while making link: $!\n";
3971                         }
3972                     }
3973                 }
3974
3975                 local ($save) = $exit_status;
3976                 if ($is_configure)
3977                 {
3978                     &am_conf_line_error
3979                         ($line,
3980                          "required file \"$errfile\" not found$trailer");
3981                 }
3982                 else
3983                 {
3984                     &am_line_error
3985                         ($line,
3986                          "required file \"$errfile\" not found$trailer");
3987                 }
3988                 $exit_status = $save if $suppress;
3989             }
3990         }
3991     }
3992 }
3993
3994 # Like require_file_with_line, but error messages refer to
3995 # configure.in, not the current Makefile.am.
3996 sub require_file_with_conf_line
3997 {
3998     @require_file_paths = '.';
3999     &require_file_internal (1, @_);
4000 }
4001
4002 sub require_file_with_line
4003 {
4004     @require_file_paths = '.';
4005     &require_file_internal (0, @_);
4006 }
4007
4008 sub require_file
4009 {
4010     @require_file_paths = '.';
4011     &require_file_internal (0, '', @_);
4012 }
4013
4014 # Require a file that is also required by Autoconf.  Looks in
4015 # configuration path, as specified by AC_CONFIG_AUX_DIR.
4016 sub require_config_file
4017 {
4018     @require_file_paths = @config_aux_path;
4019     &require_file_internal (1, '', @_);
4020     local ($dir) = $require_file_paths[0];
4021     @config_aux_path = @require_file_paths;
4022     if ($dir eq '.')
4023     {
4024         $config_aux_dir = '.';
4025     }
4026     else
4027     {
4028         $config_aux_dir = '$(top_srcdir)/' . $dir;
4029     }
4030 }
4031
4032 # Assumes that the line number is in Makefile.am.
4033 sub require_conf_file_with_line
4034 {
4035     @require_file_paths = @config_aux_path;
4036     &require_file_internal (0, @_);
4037     local ($dir) = $require_file_paths[0];
4038     @config_aux_path = @require_file_paths;
4039     if ($dir eq '.')
4040     {
4041         $config_aux_dir = '.';
4042     }
4043     else
4044     {
4045         $config_aux_dir = '$(top_srcdir)/' . $dir;
4046     }
4047 }
4048
4049 # Assumes that the line number is in Makefile.am.
4050 sub require_conf_file_with_conf_line
4051 {
4052     @require_file_paths = @config_aux_path;
4053     &require_file_internal (1, @_);
4054     local ($dir) = $require_file_paths[0];
4055     @config_aux_path = @require_file_paths;
4056     if ($dir eq '.')
4057     {
4058         $config_aux_dir = '.';
4059     }
4060     else
4061     {
4062         $config_aux_dir = '$(top_srcdir)/' . $dir;
4063     }
4064 }
4065
4066 ################################################################
4067
4068 # Push a list of files onto dist_common.
4069 sub push_dist_common
4070 {
4071     local (@files) = @_;
4072     local ($file);
4073
4074     foreach $file (@files)
4075     {
4076         $dist_common{$file} = 1;
4077     }
4078 }
4079
4080 # Push a list of clean targets onto phony.
4081 sub push_phony_cleaners
4082 {
4083     local ($base) = @_;
4084     local ($target);
4085     foreach $target ('mostly', 'dist', '', 'maintainer-')
4086     {
4087         push (@phony, $target . 'clean-' . $base);
4088     }
4089 }
4090
4091 # Set strictness.
4092 sub set_strictness
4093 {
4094     $strictness_name = $_[0];
4095     if ($strictness_name eq 'gnu')
4096     {
4097         $strictness = $GNU;
4098     }
4099     elsif ($strictness_name eq 'gnits')
4100     {
4101         $strictness = $GNITS;
4102     }
4103     elsif ($strictness_name eq 'foreign')
4104     {
4105         $strictness = $FOREIGN;
4106     }
4107     else
4108     {
4109         die "automake: level \`$strictness_name' not recognized\n";
4110     }
4111 }
4112
4113
4114 ################################################################
4115
4116 # Return directory name of file.
4117 sub dirname
4118 {
4119     local ($file) = @_;
4120     local ($sub);
4121
4122     ($sub = $file) =~ s,/+[^/]+$,,g;
4123     $sub = '.' if $sub eq $file;
4124     return $sub;
4125 }
4126
4127 # Return file name of a file.
4128 sub basename
4129 {
4130     local ($file) = @_;
4131     local ($sub);
4132
4133     ($sub = $file) =~s,^.*/+,,g;
4134     return $sub;
4135 }
4136
4137 # Touch a file.
4138 sub touch
4139 {
4140     local ($file) = @_;
4141
4142     open (TOUCH, ">> $file");
4143     close (TOUCH);
4144 }
4145
4146 ################################################################
4147
4148 # Print an error message and set exit status.
4149 sub am_error
4150 {
4151     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
4152     $exit_status = 1;
4153 }
4154
4155 sub am_line_error
4156 {
4157     local ($symbol, @args) = @_;
4158
4159     if ($symbol)
4160     {
4161         # If SYMBOL not already a line number, look it up in Makefile.am.
4162         $symbol = $content_lines{$symbol} unless $symbol =~ /^\d+$/;
4163         $symbol .= ': ' if $symbol;
4164         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
4165         $exit_status = 1;
4166     }
4167     else
4168     {
4169         &am_error (@args);
4170     }
4171 }
4172
4173 # Like am_error, but while scanning configure.in.
4174 sub am_conf_error
4175 {
4176     # FIXME: can run in subdirs.
4177     warn "automake: configure.in: ", join (' ', @_), "\n";
4178     $exit_status = 1;
4179 }
4180
4181 # Error message with line number referring to configure.in.
4182 sub am_conf_line_error
4183 {
4184     local ($line, @args) = @_;
4185
4186     if ($line)
4187     {
4188         warn "configure.in: $line: ", join (' ', @args), "\n";
4189         $exit_status = 1;
4190     }
4191     else
4192     {
4193         &am_conf_error (@args);
4194     }
4195 }
4196
4197 # Tell user where our aclocal.m4 is, but only once.
4198 sub keyed_aclocal_warning
4199 {
4200     local ($key) = @_;
4201     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
4202 }
4203
4204 # Print usage information.
4205 sub usage
4206 {
4207     print "Usage: automake [OPTION] ... [Makefile]...\n";
4208     print $USAGE;
4209     print "\nFiles which are automatically distributed, if found:\n";
4210     $~ = "USAGE_FORMAT";
4211     local (@lcomm) = sort ((@common_files, @common_sometimes));
4212     local ($one, $two, $three, $four);
4213     while (@lcomm > 0)
4214     {
4215         $one = shift @lcomm;
4216         $two = @lcomm ? shift @lcomm : '';
4217         $three = @lcomm ? shift @lcomm : '';
4218         $four = @lcomm ? shift @lcomm : '';
4219         write;
4220     }
4221
4222     print "\nReport bugs to <bug-gnu-utils\@prep.ai.mit.edu>\n";
4223
4224     exit 0;
4225 }
4226
4227 format USAGE_FORMAT =
4228   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
4229   $one,               $two,               $three,             $four
4230 .