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