fixlet
[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         local ($xt) = '';
1311         if (&variable_defined ($xname . "_LDADD"))
1312         {
1313             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1314                                      $lex_file_seen))
1315             {
1316                 $seen_libobjs = 1;
1317             }
1318             $lex_file_seen = 0;
1319             $xt = '_LDADD';
1320         }
1321         else
1322         {
1323             # User didn't define prog_LDADD override.  So do it.
1324             &define_variable ($xname . '_LDADD', '$(LDADD)');
1325
1326             # This does a bit too much work.  But we need it to
1327             # generate _DEPENDENCIES when appropriate.
1328             if (&variable_defined ('LDADD'))
1329             {
1330                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1331                 {
1332                     $seen_libobjs = 1;
1333                 }
1334                 $lex_file_seen = 0;
1335             }
1336             $xt = '_SOURCES'
1337         }
1338
1339         if (! &variable_defined ($xname . '_LDFLAGS'))
1340         {
1341             # Define the prog_LDFLAGS variable.
1342             &define_variable ($xname . '_LDFLAGS', '');
1343         }
1344
1345         if ($lex_file_seen)
1346         {
1347             &am_line_error ($xname . $xt,
1348                             'lex source file used without @LEXLIB@');
1349         }
1350
1351         # Determine program to use for link.
1352         local ($xlink);
1353         if (&variable_defined ($xname . '_LINK'))
1354         {
1355             $xlink = $xname . '_LINK';
1356         }
1357         else
1358         {
1359             $xlink = $linker ? $linker : 'LINK';
1360         }
1361
1362         $output_rules .=
1363             &file_contents_with_transform
1364                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1365                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1366                  . 's/\@XLINK\@/' . $xlink . '/go;',
1367                  'program');
1368     }
1369
1370     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1371     {
1372         $seen_libobjs = 1;
1373     }
1374
1375     if ($seen_libobjs)
1376     {
1377         foreach $one_file (@proglist)
1378         {
1379             # Canonicalize names.
1380             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1381
1382             if (&variable_defined ($xname . '_LDADD'))
1383             {
1384                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1385             }
1386             elsif (&variable_defined ('LDADD'))
1387             {
1388                 &check_libobjs_sources ($xname, 'LDADD');
1389             }
1390         }
1391     }
1392 }
1393
1394
1395 # Handle libraries.
1396 sub handle_libraries
1397 {
1398     local (@liblist) = &am_install_var ('-clean',
1399                                         'libs', 'LIBRARIES',
1400                                         'lib', 'pkglib', 'noinst', 'check');
1401     return if ! @liblist;
1402
1403     local (%valid) = &am_primary_prefixes ('LIBRARIES', 'lib', 'pkglib',
1404                                            'noinst', 'check');
1405     if (! defined $configure_vars{'RANLIB'})
1406     {
1407         local ($key);
1408         foreach $key (keys %valid)
1409         {
1410             if (&variable_defined ($key . '_LIBRARIES'))
1411             {
1412                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1413                 # Only get this error once.
1414                 $configure_vars{'RANLIB'} = 1;
1415                 last;
1416             }
1417         }
1418     }
1419
1420     local ($onelib);
1421     local ($munge);
1422     local ($xlib);
1423     local ($seen_libobjs) = 0;
1424     foreach $onelib (@liblist)
1425     {
1426         # Check that the library fits the standard naming convention.
1427         if ($onelib !~ /^lib.*\.a$/)
1428         {
1429             # FIXME this should only be a warning for foreign packages
1430             # FIXME should put line number here.  That means mapping
1431             # from library name back to variable name.
1432             &am_error ("\`$onelib' is not a standard library name");
1433         }
1434
1435         local ($obj) = &get_object_extension ($onelib);
1436
1437         # Canonicalize names.
1438         ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1439         if ($xlib ne $onelib)
1440         {
1441             local ($xt);
1442             foreach $xt ('_LIBADD', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
1443             {
1444                 &am_line_error ($onelib . $xt,
1445                                 "invalid variable \`" . $onelib . $xt
1446                                 . "'; should be \`" . $xlib . $xt . "'")
1447                     if &variable_defined ($onelib . $xt);
1448             }
1449         }
1450
1451         if (&variable_defined ($xlib . '_LIBADD'))
1452         {
1453             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1454             {
1455                 $seen_libobjs = 1;
1456             }
1457         }
1458         else
1459         {
1460             # Generate support for conditional object inclusion in
1461             # libraries.
1462             &define_variable ($xlib . "_LIBADD", '');
1463         }
1464
1465         &handle_source_transform ($xlib, $onelib, $obj);
1466
1467         $output_rules .=
1468             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1469                                            . 's/\@XLIBRARY\@/'
1470                                            . $xlib . '/go;',
1471                                            'library');
1472     }
1473
1474     if ($seen_libobjs)
1475     {
1476         foreach $onelib (@liblist)
1477         {
1478             # Canonicalize names.
1479             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1480             if (&variable_defined ($xlib . '_LIBADD'))
1481             {
1482                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1483             }
1484         }
1485     }
1486
1487     &define_variable ('AR', 'ar');
1488     &define_configure_variable ('RANLIB');
1489 }
1490
1491 # See if any _SOURCES variable were misspelled.  Also, make sure that
1492 # EXTRA_ variables don't contain configure substitutions.
1493 sub check_typos
1494 {
1495     local ($varname, $primary, $ckey);
1496     foreach $varname (keys %contents)
1497     {
1498         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS', '_DEPENDENCIES')
1499         {
1500             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
1501             {
1502                 &am_line_error ($varname,
1503                                 "invalid unused variable name: \`$varname'");
1504             }
1505         }
1506
1507         if ($varname =~ /^EXTRA_/)
1508         {
1509             foreach $ckey (&variable_value_as_list ($varname))
1510             {
1511                 if ($ckey =~ /^\@.*\@$/)
1512                 {
1513                     &am_line_error ($varname, "variable \`$varname' must not contain configure substitution");
1514                     last;
1515                 }
1516             }
1517         }
1518     }
1519 }
1520
1521 # Handle scripts.
1522 sub handle_scripts
1523 {
1524     # NOTE we no longer automatically clean SCRIPTS, because it is
1525     # useful to sometimes distribute scripts verbatim.  This happens
1526     # eg in Automake itself.
1527     &am_install_var ('scripts', 'SCRIPTS',
1528                      'bin', 'sbin', 'libexec', 'pkgdata',
1529                      'noinst', 'check');
1530
1531     # Set $scripts_installed if appropriate.  Make sure we only find
1532     # scripts which are actually installed -- this is why we can't
1533     # simply use the return value of am_install_var.
1534     local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
1535                                            'libexec', 'pkgdata',
1536                                            'noinst', 'check');
1537     local ($key);
1538     foreach $key (keys %valid)
1539     {
1540         if ($key ne 'noinst'
1541             && $key ne 'check'
1542             && &variable_defined ($key . '_SCRIPTS'))
1543         {
1544             $scripts_installed = 1;
1545             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
1546         }
1547     }
1548
1549     if ($scripts_installed)
1550     {
1551         # If a program is installed, this is required.  We only want this
1552         # error to appear once.
1553         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1554             unless $seen_arg_prog;
1555         $seen_arg_prog = 1;
1556     }
1557 }
1558
1559 # Search a file for a "version.texi" Texinfo include.  Return the name
1560 # of the include file if found, or the empty string if not.  A
1561 # "version.texi" file is actually any file whose name matches
1562 # "vers*.texi".
1563 sub scan_texinfo_file
1564 {
1565     local ($filename) = @_;
1566
1567     if (! open (TEXI, $filename))
1568     {
1569         &am_error ("couldn't open \`$filename': $!");
1570         return '';
1571     }
1572     print "automake: reading $filename\n" if $verbose;
1573
1574     local ($vfile, $outfile);
1575     while (<TEXI>)
1576     {
1577         if (/^\@setfilename +(\S+)/)
1578         {
1579             $outfile = $1;
1580             last if ($vfile);
1581         }
1582
1583         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
1584         {
1585             # Found version.texi include.
1586             $vfile = $1;
1587             last if $outfile;
1588         }
1589     }
1590
1591     close (TEXI);
1592     return ($outfile, $vfile);
1593 }
1594
1595 # Handle all Texinfo source.
1596 sub handle_texinfo
1597 {
1598     &am_line_error ('TEXINFOS',
1599                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
1600         if &variable_defined ('TEXINFOS');
1601     return if (! &variable_defined ('info_TEXINFOS')
1602                && ! &variable_defined ('html_TEXINFOS'));
1603
1604     local (@texis) = &variable_value_as_list ('info_TEXINFOS');
1605
1606     local (@info_deps_list, @dvis_list, @texi_deps);
1607     local ($infobase, $info_cursor);
1608     local (%versions);
1609     local ($done) = 0;
1610     local ($vti);
1611     local ($tc_cursor, @texi_cleans);
1612     local ($canonical);
1613
1614     foreach $info_cursor (@texis)
1615     {
1616         ($infobase = $info_cursor) =~ s/\.texi(nfo)?$//;
1617
1618         # If 'version.texi' is referenced by input file, then include
1619         # automatic versioning capability.
1620         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
1621                                                         . "/" . $info_cursor);
1622
1623         if ($out_file eq '')
1624         {
1625             &am_error ("\`$info_cursor' missing \@setfilename");
1626             next;
1627         }
1628
1629         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
1630         {
1631             # FIXME should report line number in input file.
1632             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
1633             next;
1634         }
1635
1636         if ($vtexi)
1637         {
1638             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
1639                 if (defined $versions{$vtexi});
1640             $versions{$vtexi} = $info_cursor;
1641
1642             # We number the stamp-vti files.  This is doable since the
1643             # actual names don't matter much.  We only number starting
1644             # with the second one, so that the common case looks nice.
1645             $vti = 'vti' . ($done ? $done : '');
1646             &push_dist_common ($vtexi, 'stamp-' . $vti);
1647             push (@clean, $vti);
1648
1649             # Only require once.
1650             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
1651                                           'mdate-sh')
1652                 if ! $done;
1653             ++$done;
1654
1655             local ($conf_pat);
1656             ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
1657             $output_rules .=
1658                 &file_contents_with_transform
1659                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
1660                      . 's/\@VTI\@/' . $vti . '/g; '
1661                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
1662                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
1663                      'texi-vers');
1664
1665             &push_phony_cleaners ($vti);
1666         }
1667
1668         # If user specified file_TEXINFOS, then use that as explicit
1669         # dependency list.
1670         @texi_deps = ();
1671         push (@texi_deps, $info_cursor);
1672         push (@texi_deps, $vtexi) if $vtexi;
1673
1674         # Canonicalize name first.
1675         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
1676         if (&variable_defined ($canonical . "_TEXINFOS"))
1677         {
1678             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
1679             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
1680         }
1681
1682         $output_rules .= ("\n" . $out_file . ": "
1683                           . join (' ', @texi_deps)
1684                           . "\n" . $infobase . ".dvi: "
1685                           . join (' ', @texi_deps)
1686                           . "\n\n");
1687
1688         push (@info_deps_list, $out_file);
1689         push (@dvis_list, $infobase . '.dvi');
1690
1691         # Generate list of things to clean for this target.  We do
1692         # this explicitly because otherwise too many things could be
1693         # removed.  In particular the ".log" extension might
1694         # reasonably be used in other contexts by the user.
1695         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
1696                             'ky', 'log', 'pg', 'toc', 'tp', 'tps',
1697                             'vr', 'vrs', 'op')
1698         {
1699             push (@texi_cleans, $infobase . '.' . $tc_cursor);
1700         }
1701     }
1702
1703     # Find these programs wherever they may lie.  Yes, this has
1704     # intimate knowledge of the structure of the texinfo distribution.
1705     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
1706                               'makeinfo');
1707     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
1708                               'texi2dvi');
1709
1710     local ($xform);
1711     if ($cygnus_mode)
1712     {
1713         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
1714     }
1715     else
1716     {
1717         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
1718     }
1719     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
1720     push (@phony, 'install-info-am', 'uninstall-info');
1721     push (@dist_targets, 'dist-info');
1722
1723     # How to clean.
1724     $output_rules .= "\nmostlyclean-info:\n";
1725     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
1726     $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
1727                       . "maintainer-clean-info:\n\t"
1728                       . 'for i in $(INFO_DEPS); do rm -f `eval echo $$i*`; done'
1729                       . "\n");
1730     &push_phony_cleaners ('info');
1731
1732     push (@suffixes, '.texi', '.texinfo', '.info', '.dvi', '.ps');
1733
1734     if (! defined $options{'no-installinfo'})
1735     {
1736         push (@uninstall, 'uninstall-info');
1737         push (@installdirs, '$(infodir)');
1738         unshift (@install_data, 'install-info-am');
1739
1740         # Make sure documentation is made and installed first.  Use
1741         # $(INFO_DEPS), not 'info', because otherwise recursive makes
1742         # get run twice during "make all".
1743         unshift (@all, '$(INFO_DEPS)');
1744     }
1745     push (@clean, 'info');
1746     push (@info, '$(INFO_DEPS)');
1747     push (@dvi, '$(DVIS)');
1748
1749     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
1750     &define_variable ("DVIS", join (' ', @dvis_list));
1751     # This next isn't strictly needed now -- the places that look here
1752     # could easily be changed to look in info_TEXINFOS.  But this is
1753     # probably better, in case noinst_TEXINFOS is ever supported.
1754     &define_variable ("TEXINFOS", $contents{'info_TEXINFOS'});
1755
1756     # Do some error checking.  Note that this file is not required
1757     # when in Cygnus mode -- a bletcherous hack.
1758     &require_file_with_line ('info_TEXINFOS',
1759                              $cygnus_mode ? $GNU : $FOREIGN,
1760                              'texinfo.tex')
1761         unless defined $options{'no-texinfo.tex'};
1762 }
1763
1764 # Handle any man pages.
1765 sub handle_man_pages
1766 {
1767     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
1768         if &variable_defined ('MANS');
1769     return if ! &variable_defined ('man_MANS');
1770
1771     # We generate the manpage install code by hand to avoid the use of
1772     # basename in the generated Makefile.
1773     local (@mans) = &variable_value_as_list ('man_MANS');
1774     local (%sections, %inames, %mbases, %secmap, %fullsecmap);
1775     local ($i) = 1;
1776     foreach (@mans)
1777     {
1778         # FIXME: statement without effect:
1779         /^(.*)\.([0-9])([a-z]*)$/;
1780         $sections{$2} = 1;
1781         $inames{$i} = $_;
1782         $mbases{$i} = $1;
1783         $secmap{$i} = $2;
1784         $fullsecmap{$i} = $2 . $3;
1785         $i++;
1786     }
1787
1788     # We don't really need this, but we use it in case we ever want to
1789     # support noinst_MANS.
1790     &define_variable ("MANS", $contents{'man_MANS'});
1791
1792     # Generate list of install dirs.
1793     $output_rules .= "install-man: \$(MANS)\n";
1794     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
1795     # Sort keys so that output is deterministic.
1796     foreach (sort keys %sections)
1797     {
1798         push (@installdirs, '$(mandir)/man' . $_)
1799             unless defined $options{'no-installman'};
1800         $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
1801                           . $_ . "\n");
1802     }
1803     push (@phony, 'install-man');
1804
1805     # Generate install target.
1806     local ($key);
1807     foreach $key (sort keys %inames)
1808     {
1809         $_ = $install_man_format;
1810         s/\@SECTION\@/$secmap{$key}/g;
1811         s/\@MAN\@/$inames{$key}/g;
1812         s/\@FULLSECT\@/$fullsecmap{$key}/g;
1813         s/\@MANBASE\@/$mbases{$key}/g;
1814         $output_rules .= $_;
1815     }
1816     $output_rules .= "\n";
1817
1818     $output_rules .= "uninstall-man:\n";
1819     foreach $key (sort keys %inames)
1820     {
1821         $_ = $uninstall_man_format;
1822         s/\@SECTION\@/$secmap{$key}/g;
1823         s/\@MAN\@/$inames{$key}/g;
1824         s/\@FULLSECT\@/$fullsecmap{$key}/g;
1825         s/\@MANBASE\@/$mbases{$key}/g;
1826         $output_rules .= $_;
1827     }
1828     $output_rules .= "\n";
1829     push (@phony, 'uninstall-man');
1830
1831     $output_vars .= &file_contents ('mans-vars');
1832
1833     if (! defined $options{'no-installman'})
1834     {
1835         push (@install_data, 'install-man');
1836         push (@uninstall, 'uninstall-man');
1837         push (@all, '$(MANS)');
1838     }
1839 }
1840
1841 # Handle DATA variables.
1842 sub handle_data
1843 {
1844     &am_install_var ('data', 'DATA', 'data', 'sysconf',
1845                      'sharedstate', 'localstate', 'pkgdata',
1846                      'noinst', 'check');
1847 }
1848
1849 # Handle TAGS.
1850 sub handle_tags
1851 {
1852     push (@phony, 'tags');
1853     local (@tag_deps) = ();
1854     if (&variable_defined ('SUBDIRS'))
1855     {
1856         $output_rules .= ("tags-recursive:\n"
1857                           . "\tlist=\"\$(SUBDIRS)\"; for subdir in \$\$list; do \\\n"
1858                           # Never fail here if a subdir fails; it
1859                           # isn't important.
1860                           . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
1861                           . "\tdone\n");
1862         push (@tag_deps, 'tags-recursive');
1863         push (@phony, 'tags-recursive');
1864     }
1865
1866     if ($dir_holds_sources
1867         || $dir_holds_headers
1868         || &variable_defined ('ETAGS_ARGS')
1869         || @tag_deps)
1870     {
1871         local ($xform) = '';
1872         if ($config_header && $relative_dir eq &dirname ($config_header))
1873         {
1874             # The config header is in this directory.  So require it.
1875             ($xform = &basename ($config_header)) =~ s/(\W)/\\$1/g;
1876         }
1877         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
1878                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
1879
1880         $output_rules .= &file_contents_with_transform ($xform, 'tags');
1881         $output_rules .= &file_contents ('tags-clean');
1882         push (@clean, 'tags');
1883         &push_phony_cleaners ('tags');
1884         &examine_variable ('TAGS_DEPENDENCIES');
1885     }
1886     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
1887     {
1888         &am_line_error ('TAGS_DEPENDENCIES',
1889                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
1890     }
1891     else
1892     {
1893         # Every Makefile must define some sort of TAGS rule.
1894         # Otherwise, it would be possible for a top-level "make TAGS"
1895         # to fail because some subdirectory failed.
1896         $output_rules .= "tags: TAGS\nTAGS:\n\n";
1897     }
1898 }
1899
1900 # Worker for handle_dist.
1901 sub handle_dist_worker
1902 {
1903     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
1904
1905     # Initialization; only at top level.
1906     if ($relative_dir eq '.')
1907     {
1908         if ($strictness >= $GNITS)
1909         {
1910             # For Gnits users, this is pretty handy.  Look at 15 lines
1911             # in case some explanatory text is desirable.
1912             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
1913           echo "NEWS not updated; not releasing" 1>&2; \\
1914           exit 1; \\
1915         fi
1916 ';
1917         }
1918
1919
1920         $output_rules .=
1921             # Create dist directory.
1922             '   rm -rf $(distdir)
1923         mkdir $(distdir)
1924         -chmod 755 $(distdir)
1925 ';
1926
1927         # Only run automake in `dist' target if --include-deps not
1928         # specified.  That way the recipient of a distribution can run
1929         # "make dist" and not need Automake.
1930         if ($cmdline_use_dependencies)
1931         {
1932             $output_rules .=
1933                 (
1934                  # We need an absolute path for --output-dir.  Thus the
1935                  # weirdness.
1936                  '      here=`pwd`; distdir=`cd $(distdir) && pwd` \\
1937           && cd $(srcdir) \\
1938           && automake --include-deps --build-dir=$$here --srcdir-name=$(srcdir) --output-dir=$$distdir '
1939                  # Set strictness of output.
1940                  . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
1941                  . "\n"
1942                  );
1943         }
1944     }
1945
1946     # Scan EXTRA_DIST to see if we need to distribute anything from a
1947     # subdir.  If so, add it to the list.  I didn't want to do this
1948     # originally, but there were so many requests that I finally
1949     # relented.
1950     local (@dist_dirs);
1951     if (&variable_defined ('EXTRA_DIST'))
1952     {
1953         foreach (&variable_value_as_list ('EXTRA_DIST'))
1954         {
1955             next if /^\@.*\@$/;
1956             next unless s,/+[^/]+$,,;
1957             push (@dist_dirs, $_)
1958                 unless $_ eq '.';
1959         }
1960     }
1961     if (@dist_dirs)
1962     {
1963         # Prepend $(distdir) to each directory given.  Doing it via a
1964         # hash lets us ensure that each directory is used only once.
1965         local (%dhash);
1966         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
1967         $output_rules .= "\t";
1968         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
1969     }
1970
1971     # In loop, test for file existence because sometimes a file gets
1972     # included in DISTFILES twice.  For example this happens when a
1973     # single source file is used in building more than one program.
1974     # Also, there are situations in which "ln" can fail.  For instance
1975     # a file to distribute could actually be a cross-filesystem
1976     # symlink -- this can easily happen if "gettextize" was run on the
1977     # distribution.
1978     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
1979     if ($cygnus_mode)
1980     {
1981         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
1982     }
1983     else
1984     {
1985         $output_rules .= "\t  d=\$(srcdir); \\\n";
1986     }
1987     $output_rules .= '    test -f $(distdir)/$$file \\
1988           || ln $$d/$$file $(distdir)/$$file 2> /dev/null \\
1989           || cp -p $$d/$$file $(distdir)/$$file; \\
1990         done
1991 ';
1992
1993     # If we have SUBDIRS, create all dist subdirectories and do
1994     # recursive build.
1995     if (&variable_defined ('SUBDIRS'))
1996     {
1997         # Test for directory existence here because previous automake
1998         # invocation might have created some directories.  Note that
1999         # we explicitly set distdir for the subdir make; that lets us
2000         # mix-n-match many automake-using packages into one large
2001         # package, and have "dist" at the top level do the right
2002         # thing.
2003         $output_rules .= '      for subdir in $(SUBDIRS); do            \\
2004           test -d $(distdir)/$$subdir           \\
2005           || mkdir $(distdir)/$$subdir          \\
2006           || exit 1;                            \\
2007           chmod 755 $(distdir)/$$subdir;        \\
2008           (cd $$subdir && $(MAKE) distdir=../$(distdir)/$$subdir distdir) \\
2009             || exit 1; \\
2010         done
2011 ';
2012     }
2013
2014     # If the target `dist-hook' exists, make sure it is run.  This
2015     # allows users to do random weird things to the distribution
2016     # before it is packaged up.
2017     push (@dist_targets, 'dist-hook') if defined $contents{'dist-hook'};
2018
2019     local ($targ);
2020     foreach $targ (@dist_targets)
2021     {
2022         # We must explicitly set distdir for these sub-makes.
2023         $output_rules .= "\t\$(MAKE) distdir=\"\$(distdir)\" $targ\n";
2024     }
2025
2026     push (@phony, 'distdir');
2027 }
2028
2029 # Handle 'dist' target.
2030 sub handle_dist
2031 {
2032     # Set up maint_charset.
2033     $local_maint_charset = $contents{'MAINT_CHARSET'}
2034         if &variable_defined ('MAINT_CHARSET');
2035     $maint_charset = $local_maint_charset
2036         if $relative_dir eq '.';
2037
2038     if (&variable_defined ('DIST_CHARSET'))
2039     {
2040         &am_line_error ('DIST_CHARSET',
2041                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2042             if ! $local_maint_charset;
2043         if ($relative_dir eq '.')
2044         {
2045             $dist_charset = $contents{'DIST_CHARSET'}
2046         }
2047         else
2048         {
2049             &am_line_error ('DIST_CHARSET',
2050                             "DIST_CHARSET can only be defined at top level");
2051         }
2052     }
2053
2054     # Look for common files that should be included in distribution.
2055     local ($cfile);
2056     foreach $cfile (@common_files)
2057     {
2058         if (-f ($relative_dir . "/" . $cfile))
2059         {
2060             &push_dist_common ($cfile);
2061         }
2062     }
2063
2064     # Keys of %dist_common are names of files to distributed.  We put
2065     # README first because it then becomes easier to make a
2066     # Usenet-compliant shar file (in these, README must be first).
2067     # FIXME: do more ordering of files here.
2068     local (@coms);
2069     if (defined $dist_common{'README'})
2070     {
2071         push (@coms, 'README');
2072         undef $dist_common{'README'};
2073     }
2074     push (@coms, sort keys %dist_common);
2075
2076     &define_pretty_variable ("DIST_COMMON", @coms);
2077     $output_vars .= "\n";
2078
2079     # Some boilerplate.
2080     $output_vars .= &file_contents ('dist-vars') . "\n";
2081     &define_variable ('TAR', $TAR);
2082     &define_variable ('GZIP', '--best');
2083
2084     # Put these things in rules section so it is easier for whoever
2085     # reads Makefile.in.
2086     if (! &variable_defined ('distdir'))
2087     {
2088         if ($relative_dir eq '.')
2089         {
2090             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2091         }
2092         else
2093         {
2094             $output_rules .= ("\n"
2095                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2096                               . "\n");
2097         }
2098     }
2099     if ($relative_dir ne '.')
2100     {
2101         $output_rules .= "\nsubdir = " . $relative_dir . "\n";
2102     }
2103
2104     # Generate 'dist' target, and maybe dist-shar / dist-zip / dist-tarZ.
2105     if ($relative_dir eq '.')
2106     {
2107         # Rule to check whether a distribution is viable.
2108         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
2109 # it guarantees that the distribution is self-contained by making another
2110 # tarfile.
2111 distcheck: dist
2112         rm -rf $(distdir)
2113         GZIP=$(GZIP) $(TAR) zxf $(distdir).tar.gz
2114         mkdir $(distdir)/=build
2115         mkdir $(distdir)/=inst
2116         dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
2117                           . (defined $contents{'distcheck-hook'}
2118                              ? "\t\$(MAKE) distcheck-hook"
2119                              : '')
2120                           . '
2121         cd $(distdir)/=build \\
2122           && ../configure '
2123
2124                           . ($seen_gettext ? '--with-included-gettext ' : '')
2125                           . '--srcdir=.. --prefix=$$dc_install_base \\
2126           && $(MAKE) \\
2127           && $(MAKE) dvi \\
2128           && $(MAKE) check \\
2129           && $(MAKE) install \\
2130           && $(MAKE) installcheck \\
2131           && $(MAKE) dist
2132         rm -rf $(distdir)
2133         @echo "========================"; \\
2134         echo "$(distdir).tar.gz is ready for distribution"; \\
2135         echo "========================"
2136 ');
2137
2138         local ($dist_all) = ('dist-all: distdir' . "\n"
2139                              . $dist_header);
2140         local ($curs);
2141         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ')
2142         {
2143             if (defined $options{$curs} || $curs eq 'dist')
2144             {
2145                 $output_rules .= ($curs . ': distdir' . "\n"
2146                                   . $dist_header
2147                                   . $dist{$curs}
2148                                   . $dist_trailer);
2149                 $dist_all .= $dist{$curs};
2150             }
2151         }
2152         $output_rules .= $dist_all . $dist_trailer;
2153     }
2154
2155     # Generate distdir target.
2156     &handle_dist_worker;
2157 }
2158
2159 # Scan a single dependency file and rewrite the dependencies as
2160 # appropriate.  Essentially this means:
2161 # * Clean out absolute dependencies which are not desirable.
2162 # * Rewrite other dependencies to be relative to $(top_srcdir).
2163 sub scan_dependency_file
2164 {
2165     local ($depfile) = @_;
2166
2167     if (! open (DEP_FILE, $depfile))
2168     {
2169         &am_error ("couldn't open \`$depfile': $!");
2170         return;
2171     }
2172     print "automake: reading $depfile\n" if $verbose;
2173
2174     # Sometimes it is necessary to omit some dependencies.
2175     local (%omit) = %omit_dependencies;
2176     if (&variable_defined ('OMIT_DEPENDENCIES'))
2177     {
2178         grep ($omit{$_} = 1, &variable_value_as_list ('OMIT_DEPENDENCIES'));
2179     }
2180
2181     local ($first_line) = 1;
2182     local ($last_line) = 0;
2183     local ($target, @dependencies);
2184     local ($one_dep, $xform);
2185     local ($just_file);
2186
2187     local ($srcdir_rx, $fixup_rx);
2188     # If the top srcdir is absolute, then the current directory is
2189     # just relative_dir.  But if the top srcdir is relative, then we
2190     # need to add some dots first.  The same holds when matching
2191     # srcdir directly.
2192     if ($srcdir_name =~ /^\//)
2193     {
2194         ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
2195             =~ s/(\W)/\\$1/g;
2196         ($srcdir_rx = $srcdir_name . '/') =~ s/(\W)/\\$1/g;
2197     }
2198     else
2199     {
2200         ($fixup_rx = ($srcdir_name . '/' . $top_builddir . '/'
2201                       . $relative_dir . '/')) =~ s/(\W)/\\$1/g;
2202         $srcdir_rx = $srcdir_name . '/';
2203         # Don't append a spurious "." to the regex.
2204         $srcdir_rx .= $top_builddir
2205             unless $top_builddir eq '.';
2206         $srcdir_rx =~ s/(\W)/\\$1/g;
2207     }
2208
2209     local ($rewrite_builddir) = (($top_builddir eq '.')
2210                                  ? ''
2211                                  : $top_builddir . '/');
2212
2213     while (<DEP_FILE>)
2214     {
2215         if ($last_line)
2216         {
2217             # If LAST_LINE set then we've already seen what we thought
2218             # was the last line.
2219             goto bad_format;
2220         }
2221         next if (/$WHITE_PATTERN/o);
2222         chop;
2223         if (! s/\\$//)
2224         {
2225             # No trailing "\" means this should be the last line.
2226             $last_line = 1;
2227         }
2228
2229         if ($first_line)
2230         {
2231             if (! /^([^:]+:)(.+)$/)
2232             {
2233               bad_format:
2234                 &am_error ("\`$depfile' has incorrect format");
2235                 close (DEP_FILE);
2236                 return;
2237             }
2238
2239             $target = $1;
2240             $_ = $2;
2241
2242             $first_line = 0;
2243         }
2244
2245         foreach $one_dep (split (' ', $_))
2246         {
2247             if ($one_dep =~ /^$fixup_rx/)
2248             {
2249                 # The dependency points to the current directory in
2250                 # some way.
2251                 ($xform = $one_dep) =~ s/^$fixup_rx//;
2252                 push (@dependencies, $xform);
2253             }
2254             elsif ($one_dep =~ /^$srcdir_rx/)
2255             {
2256                 # The dependency is in some other directory in the package.
2257                 ($xform = $one_dep) =~ s/^$srcdir_rx/$rewrite_builddir/;
2258                 push (@dependencies, $xform);
2259             }
2260             elsif ($one_dep =~ /^\//)
2261             {
2262                 # Absolute path; ignore.
2263             }
2264             else
2265             {
2266                 # Anything else is assumed to be correct.  But first
2267                 # make sure it is not on our list of dependencies to
2268                 # omit.
2269                 ($just_file = $one_dep) =~ s,^.*/,,;
2270                 push (@dependencies, $one_dep)
2271                     if ! defined $omit{$just_file};
2272             }
2273         }
2274     }
2275
2276     &pretty_print_rule ($target, "\t", @dependencies);
2277
2278     close (DEP_FILE);
2279 }
2280
2281 # Handle auto-dependency code.
2282 sub handle_dependencies
2283 {
2284     if ($use_dependencies)
2285     {
2286         # Include GNU-make-specific auto-dep code.
2287         if ($dir_holds_sources)
2288         {
2289             &define_pretty_variable ('DEP_FILES', sort keys %dep_files);
2290             $output_rules .= &file_contents ('depend');
2291             push (@clean, 'depend');
2292             &push_phony_cleaners ('depend');
2293             $output_rules .=
2294                 &file_contents_with_transform ('s/\@EXT\@/.c/g;'
2295                                                . 's/\@MKDEP\@/MKDEP/g;'
2296                                                . 's/^ONLYC//g;',
2297                                                'depend2');
2298             local ($ext);
2299             local ($need_cxx) = 0;
2300             foreach $ext (sort keys %cxx_extensions)
2301             {
2302                 $output_rules .=
2303                     &file_contents_with_transform ('s/\@EXT\@/' . $ext .'/g;'
2304                                                    . 's/\@MKDEP\@/CXXMKDEP/g;'
2305                                                    . 's/^ONLYC.*$//;',
2306                                                    'depend2');
2307                 $need_cxx = 1;
2308             }
2309             if ($need_cxx)
2310             {
2311                 &define_variable ('CXXMKDEP', '$(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
2312             }
2313         }
2314     }
2315     elsif ($build_directory ne '')
2316     {
2317         # Include any auto-generated deps that are present.  Note that
2318         # $build_directory ends in a "/".
2319         if (-d ($build_directory . $relative_dir . "/.deps")
2320             && -f ($build_directory . $relative_dir . "/.deps/.P"))
2321         {
2322             local ($depfile);
2323
2324             foreach $depfile (&my_glob ($build_directory
2325                                         . $relative_dir . "/.deps/*.P"))
2326             {
2327                 &scan_dependency_file ($depfile);
2328             }
2329
2330             $output_rules .= "\n";
2331         }
2332     }
2333 }
2334
2335 # Handle subdirectories.
2336 sub handle_subdirs
2337 {
2338     return if ! &variable_defined ('SUBDIRS');
2339
2340     # Make sure each directory mentioned in SUBDIRS actually exists.
2341     local ($dir);
2342     foreach $dir (&variable_value_as_list ('SUBDIRS'))
2343     {
2344         # Skip directories substituted by configure.
2345         next if $dir =~ /^\@.*\@$/;
2346
2347         if (! -d $am_relative_dir . '/' . $dir)
2348         {
2349             &am_line_error ('SUBDIRS',
2350                             "required directory $am_relative_dir/$dir does not exist");
2351             next;
2352         }
2353
2354         &am_relative_dir ('SUBDIRS',
2355                           "directory should not contain \`/'")
2356             if $dir =~ /\//;
2357     }
2358
2359     local ($xform) = ('s/\@INSTALLINFO\@/' .
2360                       (defined $options{'no-installinfo'}
2361                        ? 'install-info-recursive'
2362                        : '')
2363                       . '/;');
2364     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
2365
2366     # Push a bunch of phony targets.
2367     local ($phonies);
2368     foreach $phonies ('-data', '-exec', 'dirs')
2369     {
2370         push (@phony, 'install' . $phonies . '-recursive');
2371         push (@phony, 'uninstall' . $phonies . '-recursive');
2372     }
2373     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
2374     {
2375         push (@phony, $phonies . '-recursive');
2376     }
2377     &push_phony_cleaners ('recursive');
2378
2379     push (@check_tests, "check-recursive");
2380     push (@installcheck, "installcheck-recursive");
2381     push (@info, "info-recursive");
2382     push (@dvi, "dvi-recursive");
2383
2384     $recursive_install = 1;
2385 }
2386
2387 # Handle aclocal.m4.
2388 sub handle_aclocal_m4
2389 {
2390     local ($regen_aclocal) = 0;
2391     if (-f 'aclocal.m4')
2392     {
2393         &define_variable ("ACLOCAL", '$(top_srcdir)/aclocal.m4');
2394         &push_dist_common ('aclocal.m4');
2395
2396         if (open (ACLOCAL, '< aclocal.m4'))
2397         {
2398             local ($line);
2399             $line = <ACLOCAL>;
2400             close (ACLOCAL);
2401
2402             if ($line =~ 'generated automatically by aclocal')
2403             {
2404                 $regen_aclocal = 1;
2405             }
2406         }
2407     }
2408
2409     local ($acinclude) = 0;
2410     if (-f 'acinclude.m4')
2411     {
2412         $regen_aclocal = 1;
2413         $acinclude = 1;
2414     }
2415
2416     # Note that it might be possible that aclocal.m4 doesn't exist but
2417     # should be auto-generated.  This case probably isn't very
2418     # important.
2419     if ($regen_aclocal)
2420     {
2421         local (@ac_deps) = (
2422                             ($seen_maint_mode ? "\@MAINT\@" : "") ,
2423                             "configure.in",
2424                             ($acinclude ? ' acinclude.m4' : '')
2425                             );
2426
2427         # Scan all -I directories for m4 files.  These are our
2428         # dependencies.
2429         if (&variable_defined ('ACLOCAL_AMFLAGS'))
2430         {
2431             local ($amdir);
2432             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS'))
2433             {
2434                 if ($amdir =~ s/^-I//
2435                     && $amdir !~ /^\//
2436                     && -d $amdir)
2437                 {
2438                     push (@ac_deps, &my_glob ($am_dir . '/*.m4'));
2439                 }
2440             }
2441         }
2442
2443         &pretty_print_rule ("\$(srcdir)/aclocal.m4:", "\t\t", @ac_deps);
2444
2445         $output_rules .=  ("\t"
2446                            . 'cd $(srcdir) && aclocal'
2447                            . (&variable_defined ('ACLOCAL_AMFLAGS')
2448                               ? ' $(ACLOCAL_AMFLAGS)' : '')
2449                            . "\n");
2450     }
2451 }
2452
2453 # Rewrite a list of input files into a form suitable to put on a
2454 # dependency list.  The idea is that if an input file has a directory
2455 # part the same as the current directory, then the directory part is
2456 # simply removed.  But if the directory part is different, then
2457 # $(top_srcdir) is prepended.  Among other things, this is used to
2458 # generate the dependency list for the output files generated by
2459 # AC_OUTPUT.  Consider what the dependencies should look like in this
2460 # case:
2461 #   AC_OUTPUT(src/out:src/in1:lib/in2)
2462 sub rewrite_inputs_into_dependencies
2463 {
2464     local (@inputs) = @_;
2465     local ($single, @newinputs);
2466
2467     foreach $single (@inputs)
2468     {
2469         if (&dirname ($single) eq $relative_dir)
2470         {
2471             push (@newinputs, &basename ($single));
2472         }
2473         else
2474         {
2475             push (@newinputs, '$(top_srcdir)/' . $single);
2476         }
2477     }
2478
2479     return @newinputs;
2480 }
2481
2482 # Handle remaking and configure stuff.
2483 # We need the name of the input file, to do proper remaking rules.
2484 sub handle_configure
2485 {
2486     local ($local, $input, @secondary_inputs) = @_;
2487
2488     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
2489     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
2490         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
2491
2492     local ($top_reldir);
2493
2494     local ($input_base) = &basename ($input);
2495     local ($local_base) = &basename ($local);
2496
2497     local ($amfile) = $input_base . '.am';
2498     # We know we can always add '.in' because it really should be an
2499     # error if the .in was missing originally.
2500     local ($infile) = '$(srcdir)/' . $input_base . '.in';
2501     local ($colon_infile);
2502     if ($local ne $input)
2503     {
2504         $colon_infile = ':' . $input . '.in';
2505     }
2506     $colon_infile .= ':' . join (':', @secondary_inputs)
2507         if @secondary_inputs;
2508
2509     local (@rewritten) = &rewrite_inputs_into_dependencies (@secondary_inputs);
2510     # This rule remakes the Makefile.in.  Note use of @MAINT@ forces
2511     # us to abandon pretty-printing.  Sigh.
2512     $output_rules .= ($infile
2513                       # NOTE perl 5.003 (with -w) gives a
2514                       # uninitialized value error on the next line.
2515                       # Don't know why.
2516                       . ': '
2517                       . ($seen_maint_mode ? '@MAINT@ ' : '')
2518                       . $amfile . ' '
2519                       . '$(top_srcdir)/configure.in $(ACLOCAL) '
2520                       . join (' ', @rewritten) . "\n"
2521                       . "\tcd \$(top_srcdir) && automake "
2522                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2523                       . ' ' . $input . $colon_infile . "\n\n");
2524
2525     # This rule remakes the Makefile.
2526     $output_rules .= ($local_base
2527                       # NOTE: bogus uninit value error on next line;
2528                       # see comment above.
2529                       . ': '
2530                       . $infile . ' '
2531                       . '$(top_builddir)/config.status $(BUILT_SOURCES)'
2532                       . "\n"
2533                       . "\tcd \$(top_builddir) \\\n"
2534                       . "\t  && CONFIG_FILES="
2535                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
2536                       . $colon_infile
2537                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
2538                       . "\n\n");
2539
2540     if ($relative_dir ne '.')
2541     {
2542         # In subdirectory.
2543         $top_reldir = '../';
2544     }
2545     else
2546     {
2547         &handle_aclocal_m4;
2548         $output_rules .= &file_contents ('remake');
2549         &examine_variable ('CONFIGURE_DEPENDENCIES');
2550         $top_reldir = '';
2551     }
2552
2553     # If we have a configure header, require it.
2554     if ($config_header && $relative_dir eq &dirname ($config_header))
2555     {
2556         local ($ch_sans_dir) = &basename ($config_header);
2557         local ($cn_sans_dir) = &basename ($config_name);
2558
2559         &require_file_with_conf_line ($config_header_line,
2560                                       $FOREIGN, $ch_sans_dir);
2561
2562         # Header defined and in this directory.
2563         local (@files);
2564         if (-f $relative_dir . '/acconfig.h')
2565         {
2566             push (@files, 'acconfig.h');
2567         }
2568         if (-f $config_name . '.top')
2569         {
2570             push (@files, "${cn_sans_dir}.top");
2571         }
2572         if (-f $config_name . '.bot')
2573         {
2574             push (@files, "${cn_sans_dir}.bot");
2575         }
2576
2577         &push_dist_common (@files);
2578         $output_rules .= &file_contents_with_transform ('s/\@FILES\@/'
2579                                                         . join (' ', @files)
2580                                                         . '/;',
2581                                                         'remake-hdr');
2582
2583         &touch ($relative_dir . '/stamp-h.in');
2584         &require_file_with_conf_line ($config_header_line, $FOREIGN,
2585                                       'stamp-h.in');
2586
2587         push (@clean, 'hdr');
2588         &push_phony_cleaners ('hdr');
2589         &define_variable ("CONFIG_HEADER_IN", "${ch_sans_dir}");
2590     }
2591
2592     # Set location of mkinstalldirs.
2593     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
2594     {
2595         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
2596                                             . '/mkinstalldirs'));
2597     }
2598     else
2599     {
2600         &define_variable ('mkinstalldirs',
2601                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
2602     }
2603
2604     &am_line_error ('CONFIG_HEADER',
2605                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
2606         if &variable_defined ('CONFIG_HEADER');
2607
2608     if ($config_name)
2609     {
2610         # Generate CONFIG_HEADER define.
2611         if ($relative_dir eq &dirname ($config_name))
2612         {
2613             &define_variable ("CONFIG_HEADER", &basename ($config_name));
2614         }
2615         else
2616         {
2617             &define_variable ("CONFIG_HEADER",
2618                               "${top_builddir}/${config_name}");
2619         }
2620     }
2621
2622     # Now look for other files in this directory which must be remade
2623     # by config.status, and generate rules for them.
2624     local (@actual_other_files) = ();
2625     local ($file, $local);
2626     local (@inputs, @rewritten_inputs, $single);
2627     foreach $file (@other_input_files)
2628     {
2629         if ($file =~ /^(.*):(.*)$/)
2630         {
2631             # This is the ":" syntax of AC_OUTPUT.
2632             $file = $1;
2633             $local = &basename ($file);
2634             @inputs = split (':', $2);
2635             @rewritten_inputs = &rewrite_inputs_into_dependencies (@inputs);
2636         }
2637         else
2638         {
2639             # Normal usage.
2640             $local = &basename ($file);
2641             @inputs = ($local . '.in');
2642             @rewritten_inputs =
2643                 &rewrite_inputs_into_dependencies ($file . '.in');
2644         }
2645
2646         # Skip files not in this directory.
2647         next unless &dirname ($file) eq $relative_dir;
2648
2649         # Skip the config header.
2650         next if $local eq $top_builddir . '/' . $config_name;
2651
2652         # Skip any Makefile.
2653         next if $local eq 'Makefile';
2654
2655         $output_rules .= ($local . ': '
2656                           . '$(top_builddir)/config.status '
2657                           . join (' ', @rewritten_inputs) . "\n"
2658                           . "\t"
2659                           . 'cd $(top_builddir) && CONFIG_FILES='
2660                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
2661                           . '$@' . (length (@rewritten_inputs) > 1
2662                                     ? (':' . join (':', @rewritten_inputs))
2663                                     : '')
2664                           . ' CONFIG_HEADERS= ./config.status'
2665                           . "\n");
2666         push (@actual_other_files, $local);
2667
2668         # Require all input files.
2669         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
2670                                       @inputs);
2671     }
2672
2673     # These files get removed by "make clean".
2674     &define_pretty_variable ('CONFIG_CLEAN_FILES', @actual_other_files);
2675 }
2676
2677 # Handle C headers.
2678 sub handle_headers
2679 {
2680     $dir_holds_headers = &am_install_var ('header', 'HEADERS', 'include',
2681                                           'oldinclude', 'pkginclude',
2682                                           'noinst', 'check');
2683 }
2684
2685 sub handle_gettext
2686 {
2687     return if ! $seen_gettext || $relative_dir ne '.';
2688
2689     if (! &variable_defined ('SUBDIRS'))
2690     {
2691         &am_conf_error
2692             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
2693         return;
2694     }
2695
2696     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
2697         if $seen_gettext;
2698
2699     if (&variable_defined ('SUBDIRS'))
2700     {
2701         &am_line_error
2702             ('SUBDIRS',
2703              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
2704                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
2705         &am_line_error
2706             ('SUBDIRS',
2707              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
2708                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
2709     }
2710
2711     # Ensure that each language in ALL_LINGUAS has a .po file, and
2712     # each po file is mentioned in ALL_LINGUAS.
2713     if ($seen_linguas)
2714     {
2715         local (%linguas) = ();
2716         grep ($linguas{$_} = 1, split (' ', $all_linguas));
2717
2718         foreach (<po/*.po>)
2719         {
2720             s/^po\///;
2721             s/\.po$//;
2722
2723             &am_line_error ($all_linguas_line,
2724                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
2725                 if ! $linguas{$_};
2726         }
2727
2728         foreach (keys %linguas)
2729         {
2730             &am_line_error ($all_linguas_line,
2731                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
2732                 if ! -f "po/$_.po";
2733         }
2734     }
2735     else
2736     {
2737         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
2738     }
2739 }
2740
2741 # Handle footer elements.
2742 sub handle_footer
2743 {
2744     if ($contents{'SOURCES'})
2745     {
2746         # NOTE don't use define_pretty_variable here, because
2747         # $contents{...} is already defined.
2748         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
2749     }
2750     if ($contents{'OBJECTS'})
2751     {
2752         # NOTE don't use define_pretty_variable here, because
2753         # $contents{...} is already defined.
2754         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
2755     }
2756     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
2757     {
2758         $output_vars .= "\n";
2759     }
2760
2761     if (&variable_defined ('SUFFIXES'))
2762     {
2763         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
2764         # make do not like variable substitutions on the .SUFFIXES
2765         # line.
2766         push (@suffixes, &variable_value_as_list ('SUFFIXES'));
2767     }
2768
2769     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
2770     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
2771     # anything else, by sticking it right after the default: target.
2772     $output_header .= ".SUFFIXES:\n";
2773     if (@suffixes)
2774     {
2775         $output_header .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
2776     }
2777     $output_trailer .= &file_contents ('footer');
2778 }
2779
2780 # Deal with installdirs target.
2781 sub handle_installdirs
2782 {
2783     # GNU Makefile standards recommend this.
2784     $output_rules .= ("installdirs:"
2785                       . ($recursive_install
2786                          ? " installdirs-recursive\n"
2787                          : "\n"));
2788     push (@phony, 'installdirs');
2789     if (@installdirs)
2790     {
2791         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
2792                             @installdirs);
2793     }
2794     $output_rules .= "\n";
2795 }
2796
2797 # There are several targets which need to be merged.  This is because
2798 # their complete definition is compiled from many parts.  Note that we
2799 # avoid double colon rules, otherwise we'd use them instead.
2800 sub handle_merge_targets
2801 {
2802     # There are a few install-related variables that you should not define.
2803     local ($var);
2804     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
2805     {
2806         if (&variable_defined ($var))
2807         {
2808             &am_line_error ($var, "\`$var' should not be defined");
2809         }
2810     }
2811
2812     push (@all, 'Makefile');
2813     push (@all, &basename ($config_name))
2814         if $config_name && &dirname ($config_name) eq $relative_dir;
2815
2816     &do_one_merge_target ('info', @info);
2817     &do_one_merge_target ('dvi', @dvi);
2818     &do_check_merge_target;
2819     &do_one_merge_target ('installcheck', @installcheck);
2820
2821     if (defined $options{'no-installinfo'})
2822     {
2823         # FIXME: this is kind of a hack; should find another way to
2824         # know that this is required.
2825         local (@dirs);
2826         if (grep ($_ eq 'install-info-am', @phony))
2827         {
2828             push (@dirs, 'install-info-am');
2829         }
2830         if (&variable_defined ('SUBDIRS'))
2831         {
2832             push (@dirs, 'install-info-recursive');
2833         }
2834         &do_one_merge_target ('install-info', @dirs);
2835     }
2836
2837     # Handle the various install targets specially.  We do this so
2838     # that (eg) "make install-exec" will run "install-exec-recursive"
2839     # if required, but "make install" won't run it twice.  Step one is
2840     # to see if the user specified local versions of any of the
2841     # targets we handle.  "all" is treated as one of these since
2842     # "install" can run it.
2843     push (@install_exec, 'install-exec-local')
2844         if defined $contents{'install-exec-local'};
2845     push (@install_data, 'install-data-local')
2846         if defined $contents{'install-data-local'};
2847     push (@uninstall, 'uninstall-local')
2848         if defined $contents{'uninstall-local'};
2849     local ($utarg);
2850     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
2851                     'uninstall-exec-local', 'uninstall-exec-hook')
2852     {
2853         if (defined $contents{$utarg})
2854         {
2855             local ($x);
2856             ($x = $utarg) =~ s/(data|exec)-//;
2857             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
2858         }
2859     }
2860     push (@all, 'all-local')
2861         if defined $contents{'all-local'};
2862
2863     if (defined $contents{'install-local'})
2864     {
2865         &am_line_error ('install-local',
2866                         "use \`install-data' or \`install-exec', not \`install'");
2867     }
2868
2869     # Step two: if we are doing recursive makes, write out the
2870     # appropriate rules.
2871     local (@install);
2872     if ($recursive_install)
2873     {
2874         push (@install, 'install-recursive');
2875
2876         if (@all)
2877         {
2878             local (@hackall) = ();
2879             if ($config_name && &dirname ($config_name) eq $relative_dir)
2880             {
2881
2882                 # This is kind of a hack, but I couldn't see a better
2883                 # way to handle it.  In this particular case, we need
2884                 # to make sure config.h is built before we recurse.
2885                 # We can't do this by changing the order of
2886                 # dependencies to the "all" because that breaks when
2887                 # using parallel makes.  Instead we handle things
2888                 # explicitly.
2889                 $output_rules .= ('all-recursive-am: $(CONFIG_HEADER)'
2890                                   . "\n\t" . '$(MAKE) all-recursive'
2891                                   . "\n\n");
2892                 push (@hackall, 'all-recursive-am');
2893                 push (@phony, 'all-recursive-am');
2894             }
2895             else
2896             {
2897                 push (@hackall, 'all-recursive');
2898             }
2899
2900             $output_rules .= ('all-am: '
2901                               . join (' ', @all)
2902                               . "\n\n");
2903             @all = @hackall;
2904             push (@all, 'all-am');
2905             push (@phony, 'all-am');
2906         }
2907         else
2908         {
2909             @all = ('all-recursive');
2910
2911             # Must always generate `all-am' target, so it can be
2912             # referred to elsewhere.
2913             $output_rules .= "all-am:\n";
2914         }
2915         if (@install_exec)
2916         {
2917             $output_rules .= ('install-exec-am: '
2918                               . join (' ', @install_exec)
2919                               . "\n\n");
2920             @install_exec = ('install-exec-recursive', 'install-exec-am');
2921             push (@install, 'install-exec-am');
2922             push (@phony, 'install-exec-am');
2923         }
2924         else
2925         {
2926             @install_exec = ('install-exec-recursive');
2927         }
2928         if (@install_data)
2929         {
2930             $output_rules .= ('install-data-am: '
2931                               . join (' ', @install_data)
2932                               . "\n\n");
2933             @install_data = ('install-data-recursive', 'install-data-am');
2934             push (@install, 'install-data-am');
2935             push (@phony, 'install-data-am');
2936         }
2937         else
2938         {
2939             @install_data = ('install-data-recursive');
2940         }
2941         if (@uninstall)
2942         {
2943             $output_rules .= ('uninstall-am: '
2944                               . join (' ', @uninstall)
2945                               . "\n\n");
2946             @uninstall = ('uninstall-recursive', 'uninstall-am');
2947             push (@phony, 'uninstall-am');
2948         }
2949         else
2950         {
2951             @uninstall = ('uninstall-recursive');
2952         }
2953     }
2954
2955     # Step three: print definitions users can use.  Code below knows
2956     # that install-exec is done before install-data, beware.
2957     $output_rules .= ("install-exec: "
2958                       . join (' ', @install_exec)
2959                       . "\n");
2960     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
2961     if (defined $contents{'install-exec-hook'})
2962     {
2963         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
2964     }
2965     $output_rules .= "\n";
2966     push (@install, 'install-exec') if !$recursive_install;
2967     push (@phony, 'install-exec');
2968
2969     $output_rules .= ("install-data: "
2970                       . join (' ', @install_data)
2971                       . "\n");
2972     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
2973     if (defined $contents{'install-data-hook'})
2974     {
2975         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
2976     }
2977     $output_rules .= "\n";
2978     push (@install, 'install-data') if !$recursive_install;
2979     push (@phony, 'install-data');
2980
2981     # If no dependencies for 'install', add 'all'.  Why?  That way
2982     # "make install" at top level of distclean'd distribution won't
2983     # fail because stuff in 'lib' fails to build.
2984     if (! @install || (scalar (@install) == 2
2985                        && $install[0] eq 'install-exec'
2986                        && $install[1] eq 'install-data'))
2987     {
2988         push (@install, 'all');
2989     }
2990     $output_rules .= ('install: '
2991                       . join (' ', @install)
2992                       # Use "@:" as empty command so nothing prints.
2993                       . "\n\t\@:"
2994                       . "\n\n"
2995                       . 'uninstall: '
2996                       . join (' ', @uninstall)
2997                       . "\n\n");
2998     push (@phony, 'install', 'uninstall');
2999
3000     $output_rules .= ('all: '
3001                       . join (' ', @all)
3002                       . "\n\n");
3003     push (@phony, 'all');
3004
3005     # Generate the new 'install-strip' target.
3006     $output_rules .= ("install-strip:\n\t"
3007                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
3008                       . "\n");
3009 }
3010
3011 # Helper for handle_merge_targets.
3012 sub do_one_merge_target
3013 {
3014     local ($name, @values) = @_;
3015
3016     if (defined $contents{$name . '-local'})
3017     {
3018         # User defined local form of target.  So include it.
3019         push (@values, $name . '-local');
3020         push (@phony, $name . '-local');
3021     }
3022
3023     &pretty_print_rule ($name . ":", "\t\t", @values);
3024     push (@phony, $name);
3025 }
3026
3027 # Handle check merge target specially.
3028 sub do_check_merge_target
3029 {
3030     if (defined $contents{'check-local'})
3031     {
3032         # User defined local form of target.  So include it.
3033         push (@check_tests, 'check-local');
3034         push (@phony, 'check-local');
3035     }
3036
3037     if (! &variable_defined ('SUBDIRS'))
3038     {
3039         # 'check' must depend on `all', but not when doing recursive
3040         # build.
3041         unshift (@check, 'all');
3042     }
3043     else
3044     {
3045         # When subdirs are used, do the `all' build and then do all
3046         # the recursive stuff.  Actually use `all-am' because it
3047         # doesn't recurse; we rely on the check target in the subdirs
3048         # to do the required builds there.
3049         unshift (@check, 'all-am');
3050     }
3051
3052     # The check target must depend on the local equivalent of `all',
3053     # to ensure all the primary targets are built.  Also it must
3054     # depend on the test code named in @check.
3055     &pretty_print_rule ('check:', "\t\t", @check);
3056
3057     # Now the check rules must explicitly run anything named in
3058     # @check_tests.  This is done via a separate make invocation to
3059     # avoid problems with parallel makes.  Every time I write code
3060     # like this I wonder: how could you invent a parallel make and not
3061     # provide any real synchronization facilities?
3062     &pretty_print_rule ("\t\$(MAKE)", "\t  ", @check_tests);
3063 }
3064
3065 # Handle all 'clean' targets.
3066 sub handle_clean
3067 {
3068     push (@clean, 'generic');
3069     $output_rules .= &file_contents ('clean');
3070     &push_phony_cleaners ('generic');
3071
3072     local ($target) = $recursive_install ? 'clean-am' : 'clean';
3073     &do_one_clean_target ($target, 'mostly', '', @clean);
3074     &do_one_clean_target ($target, '', 'mostly', @clean);
3075     &do_one_clean_target ($target, 'dist', '', @clean);
3076     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
3077
3078     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
3079
3080     local (@deps);
3081     if ($recursive_install)
3082     {
3083         # Do -recursive before -am.  If you aren't doing a parallel
3084         # make, this can be nicer.
3085         @deps = ('recursive', 'am');
3086         &do_one_clean_target ('', 'mostly', '', @deps);
3087         &do_one_clean_target ('', '', '', @deps);
3088         &do_one_clean_target ('', 'dist', '', @deps);
3089         &do_one_clean_target ('', 'maintainer-', '', @deps);
3090     }
3091 }
3092
3093 # Helper for handle_clean.
3094 sub do_one_clean_target
3095 {
3096     local ($target, $name, $last_name, @deps) = @_;
3097
3098     # Special case: if target not passed, then don't generate
3099     # dependency on next "lower" clean target (eg no
3100     # clean<-mostlyclean derivation).  In this case the target is
3101     # implicitly known to be 'clean'.
3102     local ($flag) = $target;
3103     $target = 'clean' if ! $flag;
3104
3105     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
3106     if ($flag)
3107     {
3108         if ($last_name || $name ne 'mostly')
3109         {
3110             push (@deps, $last_name . $target);
3111         }
3112     }
3113
3114     # If a -local version of the rule is given, add it to the list.
3115     if (defined $contents{$name . $target . '-local'})
3116     {
3117         push (@deps, $name . $target . '-local');
3118     }
3119
3120     # Print the target and the dependencies.
3121     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
3122
3123     # FIXME: shouldn't we really print these messages before running
3124     # the dependencies?
3125     if ($name . $target eq 'maintainer-clean')
3126     {
3127         # Print a special warning.
3128         $output_rules .=
3129             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
3130              . "\t\@echo \"it deletes files that may require special "
3131              . "tools to rebuild.\"\n");
3132
3133         $output_rules .= "\trm -f config.status\n"
3134             if $relative_dir eq '.';
3135     }
3136     elsif ($name . $target eq 'distclean')
3137     {
3138         $output_rules .= "\trm -f config.status\n";
3139         $output_rules .= "\trm -f libtool\n" if $seen_libtool;
3140     }
3141     $output_rules .= "\n";
3142 }
3143
3144 # Handle .PHONY target.
3145 sub handle_phony
3146 {
3147     &pretty_print_rule ('.PHONY:', "", @phony);
3148     $output_rules .= "\n";
3149 }
3150
3151 # Handle TESTS variable and other checks.
3152 sub handle_tests
3153 {
3154     if (defined $options{'dejagnu'})
3155     {
3156         push (@check_tests, 'check-DEJAGNU');
3157         push (@phony, 'check-DEJAGNU');
3158
3159         local ($xform);
3160         if ($cygnus_mode)
3161         {
3162             $xform = 's/^CYGNUS//;';
3163         }
3164         else
3165         {
3166             $xform = 's/^CYGNUS.*$//;';
3167         }
3168         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
3169
3170         # In Cygnus mode, these are found in the build tree.
3171         # Otherwise they are looked for in $PATH.
3172         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
3173         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
3174
3175         # Note that in the rule we don't directly generate site.exp to
3176         # avoid the possibility of a corrupted site.exp if make is
3177         # interrupted.  Jim Meyering has some useful text on this
3178         # topic.
3179         $output_rules .= ("site.exp: Makefile\n"
3180                           . "\t\@echo 'Making a new site.exp file...'\n"
3181                           . "\t-\@rm -f site.bak\n"
3182                           . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
3183                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
3184                           . "\t\@echo '# edit the last section' >> \$\@-t\n"
3185                           . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
3186                           . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
3187                           . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
3188
3189         # Extra stuff for AC_CANONICAL_*
3190         local (@whatlist) = ();
3191         if ($seen_canonical)
3192         {
3193             push (@whatlist, 'host')
3194         }
3195
3196         # Extra stuff only for AC_CANONICAL_SYSTEM.
3197         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
3198         {
3199             push (@whatlist, 'target', 'build');
3200         }
3201
3202         local ($c1, $c2);
3203         foreach $c1 (@whatlist)
3204         {
3205             foreach $c2 ('alias', 'triplet')
3206             {
3207                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
3208             }
3209         }
3210
3211         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
3212                           . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
3213                           . "\t-\@mv site.exp site.bak\n"
3214                           . "\t\@mv \$\@-t site.exp\n");
3215     }
3216     else
3217     {
3218         local ($c);
3219         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
3220         {
3221             if (&variable_defined ($c))
3222             {
3223                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
3224             }
3225         }
3226     }
3227
3228     if (&variable_defined ('TESTS'))
3229     {
3230         push (@check_tests, 'check-TESTS');
3231         push (@phony, 'check-TESTS');
3232
3233         $output_rules .= 'check-TESTS: $(TESTS)
3234         @failed=0; all=0; \\
3235         srcdir=$(srcdir); export srcdir; \\
3236         for tst in $(TESTS); do \\
3237           all=`expr $$all + 1`; \\
3238           if test -f $$tst; then dir=.; \\
3239           else dir="$(srcdir)"; fi; \\
3240           if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
3241             echo "PASS: $$tst"; \\
3242           else \\
3243             failed=`expr $$failed + 1`; \\
3244             echo "FAIL: $$tst"; \\
3245           fi; \\
3246         done; \\
3247         if test "$$failed" -eq 0; then \\
3248           echo "========================"; \\
3249           echo "All $$all tests passed"; \\
3250           echo "========================"; \\
3251         else \\
3252           echo "$$failed of $$all tests failed"; \\
3253           exit 1; \\
3254         fi
3255 ';
3256     }
3257 }
3258
3259 # Handle Emacs Lisp.
3260 sub handle_emacs_lisp
3261 {
3262     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
3263
3264     if (@elfiles)
3265     {
3266         # Found some lisp.
3267         &define_configure_variable ('lispdir');
3268         &define_configure_variable ('EMACS');
3269         $output_rules .= (".el.elc:\n"
3270                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
3271                           . "\tEMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<\n");
3272         push (@suffixes, '.el', '.elc');
3273
3274         # Generate .elc files.
3275         grep ($_ .= 'c', @elfiles);
3276         &define_pretty_variable ('ELCFILES', @elfiles);
3277
3278         push (@clean, 'lisp');
3279         &push_phony_cleaners ('lisp');
3280
3281         push (@all, '$(ELCFILES)');
3282
3283         local ($varname);
3284         if (&variable_defined ('lisp_LISP'))
3285         {
3286             $varname = 'lisp_LISP';
3287             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
3288                 if ! $seen_lispdir;
3289         }
3290         else
3291         {
3292             $varname = 'noinst_LISP';
3293         }
3294
3295         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
3296     }
3297 }
3298
3299 ################################################################
3300
3301 # Scan one file for interesting things.  Subroutine of scan_configure.
3302 sub scan_one_configure_file
3303 {
3304     local ($filename) = @_;
3305
3306     open (CONFIGURE, $filename)
3307         || die "automake: couldn't open \`$filename': $!\n";
3308     print "automake: reading $filename\n" if $verbose;
3309
3310     while (<CONFIGURE>)
3311     {
3312         # Remove comments from current line.
3313         s/\bdnl\b.*$//;
3314         s/\#.*$//;
3315
3316         # Skip macro definitions.  Otherwise we might be confused into
3317         # thinking that a macro that was only defined was actually
3318         # used.
3319         next if /AC_DEFUN/;
3320
3321         # Populate libobjs array.
3322         if (/AC_FUNC_ALLOCA/)
3323         {
3324             $libsources{'alloca.c'} = 1;
3325         }
3326         elsif (/AC_FUNC_GETLOADAVG/)
3327         {
3328             $libsources{'getloadavg.c'} = 1;
3329         }
3330         elsif (/AC_FUNC_MEMCMP/)
3331         {
3332             $libsources{'memcmp.c'} = 1;
3333         }
3334         elsif (/AC_STRUCT_ST_BLOCKS/)
3335         {
3336             $libsources{'fileblocks.c'} = 1;
3337         }
3338         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
3339         {
3340             $libsources{'getopt.c'} = 1;
3341             $libsources{'getopt1.c'} = 1;
3342         }
3343         elsif (/AM_FUNC_STRTOD/)
3344         {
3345             $libsources{'strtod.c'} = 1;
3346         }
3347         elsif (/AM_WITH_REGEX/)
3348         {
3349             $libsources{'rx.c'} = 1;
3350             $libsources{'rx.h'} = 1;
3351             $libsources{'regex.c'} = 1;
3352             $libsources{'regex.h'} = 1;
3353             $omit_dependencies{'rx.h'} = 1;
3354             $omit_dependencies{'regex.h'} = 1;
3355         }
3356         elsif (/AM_FUNC_MKTIME/)
3357         {
3358             $libsources{'mktime.c'} = 1;
3359         }
3360         elsif (/AM_FUNC_ERROR_AT_LINE/)
3361         {
3362             $libsources{'error.c'} = 1;
3363             $libsources{'error.h'} = 1;
3364         }
3365         elsif (/AM_FUNC_OBSTACK/)
3366         {
3367             $libsources{'obstack.c'} = 1;
3368             $libsources{'obstack.h'} = 1;
3369         }
3370         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
3371                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
3372         {
3373             foreach $libobj_iter (split (' ', $1))
3374             {
3375                 if ($libobj_iter =~ /^(.*)\.o$/)
3376                 {
3377                     $libsources{$1 . '.c'} = 1;
3378                 }
3379             }
3380         }
3381
3382         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
3383         {
3384             $in_ac_replace = 1;
3385         }
3386         if ($in_ac_replace)
3387         {
3388             $in_ac_replace = 0 if s/[\]\)].*$//;
3389             # Remove trailing backslash.
3390             s/\\$//;
3391             foreach (split)
3392             {
3393                 # Need to skip empty elements for Perl 4.
3394                 next if $_ eq '';
3395                 $libsources{$_ . '.c'} = 1;
3396             }
3397         }
3398
3399         if (/(fp_WITH_DMALLOC|fp_WITH_REGEX|fp_FUNC_FNMATCH|fp_PROG_INSTALL|fp_C_PROTOTYPES|jm_MAINTAINER_MODE|ud_GNU_GETTEXT)/)
3400         {
3401             &am_conf_line_error ($filename, $., "\`$1' is obsolete; use corresponding \`AM_' macro");
3402         }
3403
3404         # Process the AC_OUTPUT macro.
3405         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
3406         {
3407             $in_ac_output = 1;
3408             $ac_output_line = $.;
3409         }
3410         if ($in_ac_output)
3411         {
3412             $in_ac_output = 0 if s/[\]\),].*$//;
3413
3414             # Look at potential Makefile.am's.
3415             foreach (split)
3416             {
3417                 next if $_ eq "\\";
3418
3419                 # Handle $local:$input syntax.  Note that we ignore
3420                 # every input file past the first, though we keep
3421                 # those around for later.
3422                 local ($local, $input, @rest) = split (/:/);
3423                 if (! $input)
3424                 {
3425                     $input = $local;
3426                 }
3427                 else
3428                 {
3429                     # FIXME: should be error if .in is missing.
3430                     $input =~ s/\.in$//;
3431                 }
3432
3433                 if (-f $input . '.am')
3434                 {
3435                     # We have a file that automake should generate.
3436                     push (@make_input_list, $input);
3437                     $make_list{$input} = join (':', ($local, @rest));
3438                 }
3439                 else
3440                 {
3441                     # We have a file that automake should cause to be
3442                     # rebuilt, but shouldn't generate itself.
3443                     push (@other_input_files, $_);
3444                 }
3445             }
3446         }
3447
3448         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
3449         {
3450             @config_aux_path = $1;
3451         }
3452
3453         # Check for ansi2knr.
3454         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
3455
3456         # Check for NLS support.
3457         if (/AM_GNU_GETTEXT/)
3458         {
3459             $seen_gettext = 1;
3460             $ac_gettext_line = $.;
3461             $omit_dependencies{'libintl.h'} = 1;
3462         }
3463
3464         # Look for ALL_LINGUAS.
3465         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
3466         {
3467             $seen_linguas = 1;
3468             $all_linguas = $1;
3469             $all_linguas_line = $.;
3470         }
3471
3472         # Handle configuration headers.  A config header of `[$1]'
3473         # means we are actually scanning AM_CONFIG_HEADER from
3474         # aclocal.m4.
3475         if (/A([CM])_CONFIG_HEADER\s*\((.*)\)/
3476             && $2 ne '[$1]')
3477         {
3478             &am_conf_line_error
3479                 ($filename, $.,
3480                  "use \`AM_CONFIG_HEADER', not \`AC_CONFIG_HEADER'")
3481                     if $1 eq 'C';
3482
3483             $config_header_line = $.;
3484             $config_name = $2;
3485             if ($config_name =~ /^([^:]+):(.+)$/)
3486             {
3487                 $config_name = $1;
3488                 $config_header = $2;
3489             }
3490             else
3491             {
3492                 $config_header = $config_name . '.in';
3493             }
3494         }
3495
3496         # Handle AC_CANONICAL_*.  Always allow upgrading to
3497         # AC_CANONICAL_SYSTEM, but never downgrading.
3498         $seen_canonical = $AC_CANONICAL_HOST
3499             if ! $seen_canonical
3500                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
3501         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
3502
3503         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
3504
3505         # This macro handles several different things.
3506         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
3507         {
3508             $seen_make_set = 1;
3509             $seen_package = 1;
3510             $seen_version = 1;
3511             $seen_arg_prog = 1;
3512             $seen_prog_install = 2;
3513             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
3514             $package_version_line = $.;
3515         }
3516
3517         # This is like AM_INIT_AUTOMAKE, but doesn't actually set the
3518         # package and version number.  (This might change in the
3519         # future).  Yes, I'm not above hacking Automake so it works
3520         # well with other GNU tools -- that is actually the point.
3521         if (/AM_INIT_GUILE_MODULE/)
3522         {
3523             $seen_make_set = 1;
3524             $seen_package = 1;
3525             $seen_version = 1;
3526             $seen_arg_prog = 1;
3527             $seen_prog_install = 2;
3528             @config_aux_path = ('..');
3529         }
3530
3531         # Some things required by Automake.
3532         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
3533         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
3534
3535         if (/AC_PROG_(YACC|RANLIB|CC|CXX|LEX)/)
3536         {
3537             $configure_vars{$1} = 1;
3538         }
3539         if (/$AC_CHECK_PATTERN/o)
3540         {
3541             $configure_vars{$3} = 1;
3542         }
3543         if (/$AC_SUBST_PATTERN/o)
3544         {
3545             $configure_vars{$1} = 1;
3546         }
3547
3548         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
3549         $seen_maint_mode = 1 if /AM_MAINTAINER_MODE/;
3550         $seen_package = 1 if /PACKAGE=/;
3551
3552         # Skip VERSION of [$2]; that is from AM_INIT_AUTOMAKE.
3553         if (/\bVERSION=(\S+)/ && $1 ne '[$2]')
3554         {
3555             $seen_version = 1;
3556             $package_version = $1;
3557             $package_version_line = $.;
3558         }
3559         elsif (/VERSION=/)
3560         {
3561             $seen_version = 1;
3562         }
3563
3564         # Weird conditionals here because it is always allowed to
3565         # upgrade to AM_PROG_INSTALL but never to downgrade to
3566         # AC_PROG_INSTALL.
3567         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
3568         $seen_prog_install = 2 if /AM_PROG_INSTALL/;
3569
3570         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
3571
3572         if (/AM_PROG_LIBTOOL/)
3573         {
3574             $seen_libtool = 1;
3575             $libtool_line = $.;
3576             $configure_vars{'RANLIB'} = 1;
3577             $configure_vars{'CC'} = 1;
3578             # AM_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
3579             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
3580             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
3581         }
3582     }
3583
3584     close (CONFIGURE);
3585 }
3586
3587 # Scan configure.in and aclocal.m4 for interesting things.  We must
3588 # scan aclocal.m4 because there might be AC_SUBSTs and such there.
3589 sub scan_configure
3590 {
3591     # Reinitialize libsources here.  This isn't really necessary,
3592     # since we currently assume there is only one configure.in.  But
3593     # that won't always be the case.
3594     %libsources = ();
3595
3596     local ($in_ac_output, $in_ac_replace) = (0, 0);
3597     local (%make_list, @make_input_list);
3598     local ($libobj_iter);
3599
3600     &scan_one_configure_file ('configure.in');
3601     &scan_one_configure_file ('aclocal.m4')
3602         if -f 'aclocal.m4';
3603
3604     # Set input and output files if not specified by user.
3605     if (! @input_files)
3606     {
3607         @input_files = @make_input_list;
3608         %output_files = %make_list;
3609     }
3610
3611     &am_conf_error ("\`PACKAGE' not defined in configure.in")
3612         if ! $seen_package;
3613     &am_conf_error ("\`VERSION' not defined in configure.in")
3614         if ! $seen_version;
3615
3616     # Look for some files we need.  Always check for these.  This
3617     # check must be done for every run, even those where we are only
3618     # looking at a subdir Makefile.  We must set relative_dir so that
3619     # the file-finding machinery works.
3620     local ($relative_dir) = '.';
3621     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs');
3622     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
3623         if -f $config_aux_path[0] . '/install.sh';
3624 }
3625
3626 ################################################################
3627
3628 # Set up for Cygnus mode.
3629 sub check_cygnus
3630 {
3631     return unless $cygnus_mode;
3632
3633     &set_strictness ('foreign');
3634     $options{'no-installinfo'} = 1;
3635     $options{'no-dependencies'} = 1;
3636     $use_dependencies = 0;
3637
3638     if (! $seen_maint_mode)
3639     {
3640         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
3641     }
3642 }
3643
3644 # Do any extra checking for GNU standards.
3645 sub check_gnu_standards
3646 {
3647     if ($relative_dir eq '.')
3648     {
3649         # In top level (or only) directory.
3650         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
3651                        'AUTHORS', 'ChangeLog');
3652     }
3653
3654     if ($strictness >= $GNU)
3655     {
3656         if (defined $options{'no-installman'})
3657         {
3658             &am_line_error ('AUTOMAKE_OPTIONS',
3659                             "option \`no-installman' disallowed by GNU standards");
3660         }
3661
3662         if (defined $options{'no-installinfo'})
3663         {
3664             &am_line_error ('AUTOMAKE_OPTIONS',
3665                             "option \`no-installinfo' disallowed by GNU standards");
3666         }
3667     }
3668 }
3669
3670 # Do any extra checking for GNITS standards.
3671 sub check_gnits_standards
3672 {
3673     if ($strictness >= $GNITS)
3674     {
3675         if (-f $relative_dir . '/COPYING.LIB')
3676         {
3677             &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
3678         }
3679
3680         if ($relative_dir eq '.')
3681         {
3682             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
3683             {
3684                 # FIXME: allow real filename.
3685                 &am_conf_line_error ('configure.in',
3686                                      $package_version_line,
3687                                      "version \`$package_version' doesn't follow Gnits standards");
3688             }
3689             elsif (defined $1 && -f 'README-alpha')
3690             {
3691                 # This means we have an alpha release.  See
3692                 # GNITS_VERSION_PATTERN for details.
3693                 &require_file ($GNITS, 'README-alpha');
3694             }
3695         }
3696     }
3697
3698     if ($relative_dir eq '.')
3699     {
3700         # In top level (or only) directory.
3701         &require_file ($GNITS, 'THANKS');
3702     }
3703 }
3704
3705 ################################################################
3706
3707 # Pretty-print something.  HEAD is what should be printed at the
3708 # beginning of the first line, FILL is what should be printed at the
3709 # beginning of every subsequent line.
3710 sub pretty_print_internal
3711 {
3712     local ($head, $fill, @values) = @_;
3713
3714     local ($column) = length ($head);
3715     local ($result) = $head;
3716
3717     # Fill length is number of characters.  However, each Tab
3718     # character counts for eight.  So we count the number of Tabs and
3719     # multiply by 7.
3720     local ($fill_length) = length ($fill);
3721     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
3722
3723     local ($bol) = ($head eq '');
3724     foreach (@values)
3725     {
3726         # "71" because we also print a space.
3727         if ($column + length ($_) > 71)
3728         {
3729             $result .= " \\\n" . $fill;
3730             $column = $fill_length;
3731             $bol = 1;
3732         }
3733
3734         $result .= ' ' unless ($bol);
3735         $result .= $_;
3736         $column += length ($_) + 1;
3737         $bol = 0;
3738     }
3739
3740     $result .= "\n";
3741     return $result;
3742 }
3743
3744 # Pretty-print something and append to output_vars.
3745 sub pretty_print
3746 {
3747     $output_vars .= &pretty_print_internal (@_);
3748 }
3749
3750 # Pretty-print something and append to output_rules.
3751 sub pretty_print_rule
3752 {
3753     $output_rules .= &pretty_print_internal (@_);
3754 }
3755
3756
3757 ################################################################
3758
3759 # See if a variable exists.
3760 sub variable_defined
3761 {
3762     local ($var) = @_;
3763     if (defined $targets{$var})
3764     {
3765         &am_line_error ($var, "\`$var' is target; expected variable");
3766         return 0;
3767     }
3768     elsif (defined $contents{$var})
3769     {
3770         $content_seen{$var} = 1;
3771         return 1;
3772     }
3773     return 0;
3774 }
3775
3776 # Mark a variable as examined.
3777 sub examine_variable
3778 {
3779     local ($var) = @_;
3780     &variable_defined ($var);
3781 }
3782
3783 # Return contents of variable as list, split as whitespace.  This will
3784 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
3785 # substitutions.  If PARENT is specified, it is the name of the
3786 # including variable; this is only used for error reports.
3787 sub variable_value_as_list
3788 {
3789     local ($var, $parent) = @_;
3790     local (@result);
3791
3792     if (defined $targets{$var})
3793     {
3794         &am_line_error ($var, "\`$var' is target; expected variable");
3795     }
3796     elsif (! defined $contents{$var})
3797     {
3798         &am_line_error ($parent, "variable \`$var' not defined");
3799     }
3800     else
3801     {
3802         local (@temp_list);
3803         $content_seen{$var} = 1;
3804         foreach (split (' ', $contents{$var}))
3805         {
3806             # If a comment seen, just leave.
3807             last if /^#/;
3808
3809             # Handle variable substitutions.
3810             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
3811             {
3812                 local ($varname) = $1;
3813                 local ($from, $to);
3814                 if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
3815                 {
3816                     $varname = $1;
3817                     $to = $3;
3818                     ($from = $2) =~ s/(\W)/\\$1/g;
3819                 }
3820
3821                 # Find the value.
3822                 @temp_list = &variable_value_as_list ($1, $var);
3823
3824                 # Now rewrite the value if appropriate.
3825                 if ($from)
3826                 {
3827                     grep (s/$from$/$to/, @temp_list);
3828                 }
3829
3830                 push (@result, @temp_list);
3831             }
3832             else
3833             {
3834                 push (@result, $_);
3835             }
3836         }
3837     }
3838
3839     return @result;
3840 }
3841
3842 # Define a new variable, but only if not already defined.
3843 sub define_variable
3844 {
3845     local ($var, $value) = @_;
3846
3847     if (! defined $contents{$var})
3848     {
3849         $output_vars .= $var . ' = ' . $value . "\n";
3850         $contents{$var} = $value;
3851         $content_seen{$var} = 1;
3852     }
3853 }
3854
3855 # Like define_variable, but second arg is a list, and is
3856 # pretty-printed.
3857 sub define_pretty_variable
3858 {
3859     local ($var, @value) = @_;
3860     if (! defined $contents{$var})
3861     {
3862         $contents{$var} = join (' ', @value);
3863         &pretty_print ($var . ' = ', '', @value);
3864         $content_seen{$var} = 1;
3865     }
3866 }
3867
3868 # Like define_variable, but define a variable to be the configure
3869 # substitution by the same name.
3870 sub define_configure_variable
3871 {
3872     local ($var) = @_;
3873     local ($value) = '@' . $var . '@';
3874     &define_variable ($var, $value);
3875 }
3876
3877 # Define a variable that represents a program to run.  If in Cygnus
3878 # mode, the program is searched for in the build (or source) tree.
3879 # Otherwise no searching is done at all.  Arguments are:
3880 # * VAR      Name of variable to define
3881 # * WHATDIR  Either `src' or `build', depending on where program should
3882 #            be found.  (runtest is in srcdir!)
3883 # * SUBDIR   Subdir of top-level dir
3884 # * PROGRAM  Name of program
3885 sub define_program_variable
3886 {
3887     local ($var, $whatdir, $subdir, $program) = @_;
3888
3889     if ($cygnus_mode)
3890     {
3891         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
3892                          . $subdir . '/' . $program);
3893         &define_variable ($var, ('`if test -f ' . $full
3894                                  . '; then echo ' . $full . '; else echo '
3895                                  . $program . '; fi`'));
3896     }
3897     else
3898     {
3899         &define_variable ($var, $program);
3900     }
3901 }
3902
3903
3904 ################################################################
3905
3906 # Read Makefile.am and set up %contents.  Simultaneously copy lines
3907 # from Makefile.am into $output_trailer or $output_vars as
3908 # appropriate.  NOTE we put rules in the trailer section.  We want
3909 # user rules to come after our generated stuff.
3910 sub read_am_file
3911 {
3912     local ($amfile) = @_;
3913
3914     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
3915     print "automake: reading $amfile\n" if $verbose;
3916
3917     $output_vars = ("# $in_file_name generated automatically by automake "
3918                     . $VERSION . " from $am_file_name\n");
3919
3920     # Generate copyright for generated Makefile.in.
3921     $output_vars .= $gen_copyright;
3922
3923     local ($saw_bk) = 0;
3924     local ($was_rule) = 0;
3925     local ($spacing) = '';
3926     local ($comment) = '';
3927     local ($last_var_name) = '';
3928     local ($blank) = 0;
3929
3930     while (<AM_FILE>)
3931     {
3932         if (/$IGNORE_PATTERN/o)
3933         {
3934             # Merely delete comments beginning with two hashes.
3935         }
3936         elsif (/$WHITE_PATTERN/o)
3937         {
3938             # Stick a single white line before the incoming macro or rule.
3939             $spacing = "\n";
3940             $blank = 1;
3941         }
3942         elsif (/$COMMENT_PATTERN/o)
3943         {
3944             # Stick comments before the incoming macro or rule.  Make
3945             # sure a blank line preceeds first block of comments.
3946             $spacing = "\n" unless $blank;
3947             $blank = 1;
3948             $comment .= $spacing . $_;
3949             $spacing = '';
3950         }
3951         else
3952         {
3953             last;
3954         }
3955     }
3956
3957     $output_vars .= $comment . "\n";
3958     $comment = '';
3959     $spacing = "\n";
3960     local ($am_vars) = '';
3961
3962     local ($is_ok_macro);
3963     while ($_)
3964     {
3965         $_ .= "\n"
3966             unless substr ($_, -1, 1) eq "\n";
3967
3968         $_ =~ s/\@MAINT\@//g
3969             unless $seen_maint_mode;
3970
3971         if (/$IGNORE_PATTERN/o)
3972         {
3973             # Merely delete comments beginning with two hashes.
3974         }
3975         elsif (/$WHITE_PATTERN/o)
3976         {
3977             # Stick a single white line before the incoming macro or rule.
3978             $spacing = "\n";
3979         }
3980         elsif (/$COMMENT_PATTERN/o)
3981         {
3982             # Stick comments before the incoming macro or rule.
3983             $comment .= $spacing . $_;
3984             $spacing = '';
3985         }
3986         elsif ($saw_bk)
3987         {
3988             if ($was_rule)
3989             {
3990                 $output_trailer .= $_;
3991                 $saw_bk = /\\$/;
3992             }
3993             else
3994             {
3995                 $am_vars .= $_;
3996                 $saw_bk = /\\$/;
3997                 # Chop newline and backslash if this line is
3998                 # continued.  FIXME: maybe ensure trailing whitespace
3999                 # exists?
4000                 chop if $saw_bk;
4001                 chop if $saw_bk;
4002                 $contents{$last_var_name} .= $_;
4003             }
4004         }
4005         elsif (/$RULE_PATTERN/o)
4006         {
4007             # warn "** Saw rule .$1.\n";
4008             # Found a rule.
4009             $was_rule = 1;
4010             # Value here doesn't matter; for targets we only note
4011             # existence.
4012             $contents{$1} = 1;
4013             $targets{$1} = 1;
4014             $content_lines{$1} = $.;
4015             $output_trailer .= $comment . $spacing . $_;
4016             $comment = $spacing = '';
4017             $saw_bk = /\\$/;
4018         }
4019         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
4020                || /$BOGUS_MACRO_PATTERN/o)
4021         {
4022             # Found a macro definition.
4023             $was_rule = 0;
4024             $last_var_name = $1;
4025             if (substr ($2, -1) eq "\\")
4026             {
4027                 $contents{$1} = substr ($2, 0, length ($2) - 1);
4028             }
4029             else
4030             {
4031                 $contents{$1} = $2;
4032             }
4033             $content_lines{$1} = $.;
4034             $am_vars .= $comment . $spacing . $_;
4035             $comment = $spacing = '';
4036             $saw_bk = /\\$/;
4037
4038             # Error if bogus.
4039             &am_line_error ($., "bad macro name \`$1'")
4040                 if ! $is_ok_macro;
4041         }
4042         else
4043         {
4044             # This isn't an error; it is probably a continued rule.
4045             # In fact, this is what we assume.
4046             $was_rule = 1;
4047             $output_trailer .= $comment . $spacing . $_;
4048             $comment = $spacing = '';
4049             $saw_bk = /\\$/;
4050         }
4051
4052         $_ = <AM_FILE>;
4053     }
4054
4055     $output_trailer .= $comment;
4056
4057     # Compute relative location of the top object directory.
4058     local (@topdir) = ();
4059     foreach (split (/\//, $relative_dir))
4060     {
4061         next if $_ eq '.' || $_ eq '';
4062         if ($_ eq '..')
4063         {
4064             pop @topdir;
4065         }
4066         else
4067         {
4068             push (@topdir, '..');
4069         }
4070     }
4071     @topdir = ('.') if ! @topdir;
4072
4073     $top_builddir = join ('/', @topdir);
4074     local ($build_rx);
4075     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
4076     $output_vars .= &file_contents_with_transform
4077                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
4078                          'header-vars');
4079
4080     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
4081     # this should use generic %configure_vars method.
4082     if ($seen_canonical)
4083     {
4084         local ($curs, %vars);
4085         $vars{'host_alias'} = 'host_alias';
4086         $vars{'host_triplet'} = 'host';
4087         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
4088         {
4089             $vars{'build_alias'} = 'build_alias';
4090             $vars{'build_triplet'} = 'build';
4091             $vars{'target_alias'} = 'target_alias';
4092             $vars{'target_triplet'} = 'target';
4093         }
4094         foreach $curs (sort keys %vars)
4095         {
4096             $output_vars .= "$curs = \@$vars{$curs}\@\n";
4097             $contents{$curs} = "\@$vars{$curs}\@";
4098         }
4099     }
4100
4101     local ($curs);
4102     foreach $curs (sort keys %configure_vars)
4103     {
4104         &define_configure_variable ($curs);
4105     }
4106
4107     $output_vars .= $am_vars;
4108 }
4109
4110 ################################################################
4111
4112 sub initialize_global_constants
4113 {
4114     # Values for AC_CANONICAL_*
4115     $AC_CANONICAL_HOST = 1;
4116     $AC_CANONICAL_SYSTEM = 2;
4117
4118     # Associative array of standard directory names.  Entry is TRUE if
4119     # corresponding directory should be installed during
4120     # 'install-exec' phase.
4121     %exec_dir_p =
4122         ('bin', 1,
4123          'sbin', 1,
4124          'libexec', 1,
4125          'data', 0,
4126          'sysconf', 1,
4127          'localstate', 1,
4128          'lib', 1,
4129          'info', 0,
4130          'man', 0,
4131          'include', 0,
4132          'oldinclude', 0,
4133          'pkgdata', 0,
4134          'pkglib', 1,
4135          'pkginclude', 0
4136          );
4137
4138     # Helper text for dealing with man pages.
4139     $install_man_format =
4140     '   @sect=@SECTION@;                                \\
4141         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
4142         if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
4143         else file=@MAN@; fi; \\
4144         echo " $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst"; \\
4145         $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst
4146 ';
4147
4148     $uninstall_man_format =
4149     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
4150         rm -f $(mandir)/man@SECTION@/$$inst
4151 ';
4152
4153     # Commonly found files we look for and automatically include in
4154     # DISTFILES.
4155     @common_files =
4156         (
4157          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
4158          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
4159          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
4160          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
4161          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
4162          'interlock', 'ylwrap', 'acinclude.m4', @libtoolize_files
4163          );
4164
4165     # Commonly used files we auto-include, but only sometimes.
4166     @common_sometimes =
4167         (
4168          "aclocal.m4", "acconfig.h", "config.h.top",
4169          "config.h.bot", "stamp-h.in", 'stamp-vti'
4170          );
4171
4172     $USAGE = "\
4173   -a, --add-missing     add missing standard files to package
4174   --amdir=DIR           directory storing config files
4175   --build-dir=DIR       directory where build being done (for dependencies)
4176   --cygnus              assume program is part of Cygnus-style tree
4177   --foreign             set strictness to foreign
4178   --gnits               set strictness to gnits
4179   --gnu                 set strictness to gnu
4180   --help                print this help, then exit
4181   -i, --include-deps    include generated dependencies in Makefile.in
4182   --no-force            only update Makefile.in's that are out of date
4183   -o DIR, --output-dir=DIR
4184                         put generated Makefile.in's into DIR
4185   --srcdir-name=DIR     name used for srcdir (for dependencies)
4186   -v, --verbose         verbosely list files processed
4187   --version             print version number, then exit\n";
4188
4189     # Copyright on generated Makefile.ins.
4190     $gen_copyright = "\
4191 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
4192 # This Makefile.in is free software; the Free Software Foundation
4193 # gives unlimited permission to copy, distribute and modify it.
4194 ";
4195
4196     # Ignore return result from chmod, because it might give an error
4197     # if we chmod a symlink.
4198     $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
4199     $dist{'tarZ'} = ("\t"
4200                      . '$(TAR) chf - $(distdir) | compress -c > $(distdir).tar.Z'
4201                      . "\n");
4202     $dist{'shar'} = ("\t"
4203                      . 'shar $(distdir) | gzip > $(distdir).shar.gz'
4204                      . "\n");
4205     $dist{'zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
4206     $dist{'dist'} = "\t" .  'GZIP=$(GZIP) $(TAR) chozf $(distdir).tar.gz $(distdir)' . "\n";
4207     $dist_trailer = "\t" . 'rm -rf $(distdir)' . "\n";
4208 }
4209
4210 # (Re)-Initialize per-Makefile.am variables.
4211 sub initialize_per_input
4212 {
4213     # These two variables are used when generating each Makefile.in.
4214     # They hold the Makefile.in until it is ready to be printed.
4215     $output_rules = '';
4216     $output_vars = '';
4217     $output_trailer = '';
4218     $output_header = '';
4219
4220     # Suffixes found during a run.
4221     @suffixes = ();
4222
4223     # This holds the contents of a Makefile.am, as parsed by
4224     # read_am_file.
4225     %contents = ();
4226
4227     # This holds the names which are targets.  These also appear in
4228     # %contents.
4229     %targets = ();
4230
4231     # This holds the line numbers at which various elements of
4232     # %contents are defined.
4233     %content_lines = ();
4234
4235     # This holds a 1 if a particular variable was examined.
4236     %content_seen = ();
4237
4238     # This holds the "relative directory" of the current Makefile.in.
4239     # Eg for src/Makefile.in, this is "src".
4240     $relative_dir = '';
4241
4242     # This holds a list of files that are included in the
4243     # distribution.
4244     %dist_common = ();
4245
4246     # List of dependencies for the obvious targets.
4247     @install_data = ();
4248     @install_exec = ();
4249     @uninstall = ();
4250     @installdirs = ();
4251
4252     @info = ();
4253     @dvi = ();
4254     @all = ();
4255     @check = ();
4256     @check_tests = ();
4257     @installcheck = ();
4258     @clean = ();
4259
4260     @phony = ();
4261
4262     # These are pretty obvious, too.  They are used to define the
4263     # SOURCES and OBJECTS variables.
4264     @sources = ();
4265     @objects = ();
4266
4267     # TRUE if current directory holds any C source files.
4268     $dir_holds_sources = 0;
4269
4270     # These variables track inclusion of various compile-related .am
4271     # files.  $included_generic_compile is TRUE if the basic code has
4272     # been included.  $included_knr_compile is TRUE if the ansi2knr
4273     # code has been included.  $included_libtool_compile is TRUE if
4274     # libtool support has been included.
4275     $included_generic_compile = 0;
4276     $included_knr_compile = 0;
4277     $included_libtool_compile = 0;
4278
4279     # TRUE if current directory holds any headers.
4280     $dir_holds_headers = 0;
4281
4282     # TRUE if install targets should work recursively.
4283     $recursive_install = 0;
4284
4285     # All .P files.
4286     %dep_files = ();
4287
4288     # Strictness levels.
4289     $strictness = $default_strictness;
4290     $strictness_name = $default_strictness_name;
4291
4292     # Options from AUTOMAKE_OPTIONS.
4293     %options = ();
4294
4295     # Whether or not dependencies are handled.  Can be further changed
4296     # in handle_options.
4297     $use_dependencies = $cmdline_use_dependencies;
4298
4299     # Per Makefile.am.
4300     $local_maint_charset = $maint_charset;
4301
4302     # All yacc and lex source filenames for this directory.  Use
4303     # filenames instead of raw count so that multiple instances are
4304     # counted correctly (eg one yacc file can appear in multiple
4305     # programs without harm).
4306     %yacc_sources = ();
4307     %lex_sources = ();
4308
4309     # C++ source extensions we've seen.
4310     %cxx_extensions = ();
4311
4312     # TRUE if we've seen any non-C++ sources.
4313     $seen_c_source = 0;
4314
4315     # This is a list of all targets to run during "make dist".
4316     @dist_targets = ();
4317
4318     # Keys in this hash are the names of ._o files which must depend
4319     # on ansi2knr.  Ugh.
4320     %de_ansi_objects = ();
4321 }
4322
4323
4324 ################################################################
4325
4326 # Return contents of a file from $am_dir, automatically skipping
4327 # macros or rules which are already known.  Runs command on each line
4328 # as it is read; this command can modify $_.
4329 sub file_contents_with_transform
4330 {
4331     local ($command, $basename) = @_;
4332     local ($file) = $am_dir . '/' . $basename . '.am';
4333
4334     if ($command ne '' && substr ($command, -1) ne ';')
4335     {
4336         die "automake: programming error in file_contents_with_transform\n";
4337     }
4338
4339     open (FC_FILE, $file)
4340         || die "automake: installation error: cannot open \`$file'\n";
4341     # Looks stupid?
4342     # print "automake: reading $file\n" if $verbose;
4343
4344     local ($was_rule) = 0;
4345     local ($result_vars) = '';
4346     local ($result_rules) = '';
4347     local ($comment) = '';
4348     local ($spacing) = "\n";
4349     local ($skipping) = 0;
4350     local ($had_chars);
4351
4352     while (<FC_FILE>)
4353     {
4354         $_ =~ s/\@MAINT\@//g
4355             unless $seen_maint_mode;
4356
4357         $had_chars = length ($_);
4358         eval $command;
4359         # If the transform caused all the characters to go away, then
4360         # ignore the line.  Why do this?  Because in Perl 4, a "next"
4361         # inside of an eval doesn't affect a loop outside the eval.
4362         # So we can't pass in a "transform" that uses next.  We used
4363         # to do this.
4364         next if $had_chars && $_ eq '';
4365
4366         if (/$IGNORE_PATTERN/o)
4367         {
4368             # Merely delete comments beginning with two hashes.
4369         }
4370         elsif (/$WHITE_PATTERN/o)
4371         {
4372             # Stick a single white line before the incoming macro or rule.
4373             $spacing = "\n";
4374         }
4375         elsif (/$COMMENT_PATTERN/o)
4376         {
4377             # Stick comments before the incoming macro or rule.
4378             $comment .= $spacing . $_;
4379             $spacing = '';
4380         }
4381         elsif ($saw_bk)
4382         {
4383             if ($was_rule)
4384             {
4385                 $result_rules .= $_ if ! $skipping;
4386             }
4387             else
4388             {
4389                 $result_vars .= $_ if ! $skipping;
4390             }
4391             $saw_bk = /\\$/;
4392         }
4393         elsif (/$RULE_PATTERN/o)
4394         {
4395             # warn "** Found rule .$1.\n";
4396             # Found a rule.
4397             $was_rule = 1;
4398             $skipping = defined $contents{$1};
4399             # warn "** Skip $skipping\n" if $skipping;
4400             $result_rules .= $comment . $spacing . $_ if ! $skipping;
4401             $comment = $spacing = '';
4402             $saw_bk = /\\$/;
4403         }
4404         elsif (/$MACRO_PATTERN/o)
4405         {
4406             # warn "** Found macro .$1.\n";
4407             # Found a variable reference.
4408             $was_rule = 0;
4409             $skipping = defined $contents{$1};
4410             # warn "** Skip $skipping\n" if $skipping;
4411             $result_vars .= $comment . $spacing . $_ if ! $skipping;
4412             $comment = $spacing = '';
4413             $saw_bk = /\\$/;
4414         }
4415         else
4416         {
4417             # This isn't an error; it is probably a continued rule.
4418             # In fact, this is what we assume.
4419             $was_rule = 1;
4420             $result_rules .= $comment . $spacing . $_ if ! $skipping;
4421             $comment = $spacing = '';
4422             $saw_bk = /\\$/;
4423         }
4424     }
4425
4426     close (FC_FILE);
4427     return $result_vars . $result_rules . $comment;
4428 }
4429
4430 # Like file_contents_with_transform, but no transform.
4431 sub file_contents
4432 {
4433     return &file_contents_with_transform ('', @_);
4434 }
4435
4436 # Find all variable prefixes that are used for install directories.  A
4437 # prefix `zar' qualifies iff:
4438 # * `zardir' is a variable.
4439 # * `zar_PRIMARY' is a variable.
4440 sub am_primary_prefixes
4441 {
4442     local ($primary, @prefixes) = @_;
4443
4444     local (%valid, $varname);
4445     grep ($valid{$_} = 0, @prefixes);
4446     $valid{'EXTRA'} = 0;
4447     foreach $varname (keys %contents)
4448     {
4449         if ($varname =~ /^(.*)_$primary$/)
4450         {
4451             if (! defined $valid{$1}
4452                 && ! &variable_defined ($1 . 'dir')
4453                 # Note that a configure variable is always legitimate.
4454                 # It is natural to name such variables after the
4455                 # primary, so we explicitly allow it.
4456                 && ! defined $configure_vars{$varname})
4457             {
4458                 &am_line_error ($varname, "invalid variable \"$varname\"");
4459             }
4460             else
4461             {
4462                 # Ensure all extended prefixes are actually used.
4463                 $valid{$1} = 1;
4464             }
4465         }
4466     }
4467
4468     return %valid;
4469 }
4470
4471 # Handle `where_HOW' variable magic.  Does all lookups, generates
4472 # install code, and possibly generates code to define the primary
4473 # variable.  The first argument is the name of the .am file to munge,
4474 # the second argument is the primary variable (eg HEADERS), and all
4475 # subsequent arguments are possible installation locations.  Returns
4476 # list of all values of all _HOW targets.
4477 #
4478 # FIXME: this should be rewritten to be cleaner.  It should be broken
4479 # up into multiple functions.
4480 #
4481 # Usage is: am_install_var (OPTION..., file, HOW, where...)
4482 sub am_install_var
4483 {
4484     local (@args) = @_;
4485
4486     local ($do_clean, $do_ltlibs) = (0, 0);
4487     local ($more_xform) = '';
4488     while (@args)
4489     {
4490         if ($args[0] eq '-clean')
4491         {
4492             $do_clean = 1;
4493         }
4494         if ($args[0] eq '-ltlibs')
4495         {
4496             $do_ltlibs = 1;
4497             if ($seen_libtool)
4498             {
4499                 # Note that we explicitly set the mode, to avoid
4500                 # lossage if the program name isn't what we expect.
4501                 $more_xform = 's/\@LIBTOOL\@/\$(LIBTOOL) --mode=install/;';
4502             }
4503             else
4504             {
4505                 $more_xform = 's/\@LIBTOOL\@//;';
4506             }
4507         }
4508         elsif ($args[0] !~ /^-/)
4509         {
4510             last;
4511         }
4512         shift (@args);
4513     }
4514     local ($file, $primary, @prefixes) = @args;
4515     unshift (@prefixes, 'lib') if ($do_ltlibs);
4516
4517     local (@used) = ();
4518     local (@result) = ();
4519
4520     # Now that configure substitutions are allowed in where_HOW
4521     # variables, it is an error to actually define the primary.
4522     &am_line_error ($primary, "\`$primary' is an anachronism")
4523         if &variable_defined ($primary);
4524
4525
4526     # Look for misspellings.  It is an error to have a variable ending
4527     # in a "reserved" suffix whose prefix is unknown, eg
4528     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
4529     # variable of the same name (with "dir" appended) exists.  For
4530     # instance, if the variable "zardir" is defined, then
4531     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
4532     # flexibility in those cases which need it.  Perhaps it should be
4533     # disallowed in the Gnits case?  The problem is, sometimes it is
4534     # useful to put things in a subdir of eg pkgdatadir, perhaps even
4535     # for Gnitsoids.
4536     local (%valid) = &am_primary_prefixes ($primary, @prefixes);
4537
4538     # If a primary includes a configure substitution, then the EXTRA_
4539     # form is required.  Otherwise we can't properly do our job.
4540     local ($require_extra);
4541     local ($warned_about_extra) = 0;
4542
4543     local ($clean_file) = $file . '-clean';
4544     local ($one_name);
4545     local ($X);
4546     foreach $X (sort keys %valid)
4547     {
4548         $one_name = $X . '_' . $primary;
4549         if (&variable_defined ($one_name))
4550         {
4551             # Append actual contents of where_PRIMARY variable to
4552             # result.
4553             local ($rcurs);
4554             foreach $rcurs (&variable_value_as_list ($one_name))
4555             {
4556                 # Skip configure substitutions.  Possibly bogus.
4557                 if ($rcurs =~ /^\@.*\@$/)
4558                 {
4559                     if ($X eq 'EXTRA')
4560                     {
4561                         if (! $warned_about_extra)
4562                         {
4563                             $warned_about_extra = 1;
4564                             &am_line_error ($one_name,
4565                                             "\`$one_name' contains configure substitution, but shouldn't");
4566                         }
4567                     }
4568                     # Check here to make sure variables defined in
4569                     # configure.in do not imply that EXTRA_PRIMARY
4570                     # must be defined.
4571                     elsif (! defined $configure_vars{$one_name})
4572                     {
4573                         $require_extra = $one_name;
4574                     }
4575                     next;
4576                 }
4577
4578                 if ($do_ltlibs)
4579                 {
4580                     if ($rcurs =~ /^lib.*\.l?a$/)
4581                     {
4582                         if (! $seen_libtool)
4583                         {
4584                             &am_line_error ($one_name,
4585                                             "\`$rcurs' is a libtool library name, but AM_PROG_LIBTOOL is not in \`configure.in'");
4586                             $seen_libtool = 1;
4587                         }
4588
4589                         # Check that libtool libraries go only into
4590                         # libdir.  Ignore `EXTRA' libtool libraries.
4591                         if ($rcurs =~ /^lib.*\.la$/ && $X ne 'lib'
4592                             && $X ne 'EXTRA')
4593                         {
4594                             &am_line_error ($one_name,
4595                                             "libtool library \`$rcurs' must only be installed in libdir");
4596                         }
4597                         elsif ($X =~ /^s?bin|libexec$/)
4598                         {
4599                             &am_line_error ($one_name,
4600                                             "library \`$rcurs' must not be installed in a binary directory");
4601                         }
4602                     }
4603                     elsif ($X eq 'lib')
4604                     {
4605                         &am_line_error ($one_name,
4606                                         "only libraries (not \`$rcurs') may be installed in libdir");
4607                     }
4608                 }
4609                 push (@result, $rcurs);
4610             }
4611
4612             # "EXTRA" shouldn't be used when generating clean targets,
4613             # @all, or install targets.
4614             next if $X eq 'EXTRA';
4615
4616             if ($do_clean)
4617             {
4618                 $output_rules .=
4619                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;',
4620                                                    $clean_file);
4621
4622                 push (@clean, $X . $primary);
4623                 &push_phony_cleaners ($X . $primary);
4624             }
4625
4626             if ($X eq 'check')
4627             {
4628                 push (@check, '$(' . $one_name . ')');
4629             }
4630             else
4631             {
4632                 push (@used, '$(' . $one_name . ')');
4633             }
4634             if ($X eq 'noinst' || $X eq 'check')
4635             {
4636                 # Objects which don't get installed by default.
4637                 next;
4638             }
4639
4640             if ($do_ltlibs && $X eq 'lib')
4641             {
4642                 $output_rules .=
4643                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;',
4644                                                    'ltlibs');
4645             }
4646             else
4647             {
4648                 $output_rules .=
4649                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
4650                                                    . $more_xform,
4651                                                    $file);
4652             }
4653
4654             push (@uninstall, 'uninstall-' . $X . $primary);
4655             push (@phony, 'uninstall-' . $X . $primary);
4656             push (@installdirs, '$(' . $X . 'dir)');
4657             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
4658             {
4659                 push (@install_exec, 'install-' . $X . $primary);
4660                 push (@phony, 'install-' . $X . $primary);
4661             }
4662             else
4663             {
4664                 push (@install_data, 'install-' . $X . $primary);
4665                 push (@phony, 'install-' . $X . $primary);
4666             }
4667         }
4668     }
4669
4670     if (@used)
4671     {
4672         # Define it.
4673         &define_pretty_variable ($primary, @used);
4674         $output_vars .= "\n";
4675     }
4676
4677     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
4678     {
4679         &am_line_error ($require_extra,
4680                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
4681     }
4682
4683     # Push here because PRIMARY might be configure time determined.
4684     push (@all, '$(' . $primary . ')')
4685         if @used;
4686
4687     return (@result);
4688 }
4689
4690
4691 ################################################################
4692
4693 # This variable is local to the "require file" set of functions.
4694 @require_file_paths = ();
4695
4696 # Verify that the file must exist in the current directory.  Usage:
4697 # require_file (isconfigure, line_number, strictness, file) strictness
4698 # is the strictness level at which this file becomes required.  Must
4699 # set require_file_paths before calling this function.
4700 # require_file_paths is set to hold a single directory (the one in
4701 # which the first file was found) before return.
4702 sub require_file_internal
4703 {
4704     local ($is_configure, $line, $mystrict, @files) = @_;
4705     local ($file, $fullfile);
4706     local ($found_it, $errfile, $errdir);
4707     local ($save_dir);
4708
4709     foreach $file (@files)
4710     {
4711         $found_it = 0;
4712         foreach $dir (@require_file_paths)
4713         {
4714             if ($dir eq '.')
4715             {
4716                 $fullfile = $relative_dir . "/" . $file;
4717                 $errdir = $relative_dir unless $errdir;
4718             }
4719             else
4720             {
4721                 $fullfile = $dir . "/" . $file;
4722                 $errdir = $dir unless $errdir;
4723             }
4724
4725             # Use different name for "error filename".  Otherwise on
4726             # an error the bad file will be reported as eg
4727             # `../../install-sh' when using the default
4728             # config_aux_path.
4729             $errfile = $errdir . '/' . $file;
4730
4731             if (-f $fullfile)
4732             {
4733                 $found_it = 1;
4734                 # FIXME: Once again, special-case `.'.
4735                 &push_dist_common ($file)
4736                     if $dir eq $relative_dir || $dir eq '.';
4737                 $save_dir = $dir;
4738                 last;
4739             }
4740         }
4741
4742         if ($found_it)
4743         {
4744             # Prune the path list.
4745             @require_file_paths = $save_dir;
4746         }
4747         else
4748         {
4749             if ($strictness >= $mystrict)
4750             {
4751                 local ($trailer) = '';
4752                 local ($suppress) = 0;
4753
4754                 # Only install missing files according to our desired
4755                 # strictness level.
4756                 if ($add_missing)
4757                 {
4758                     $trailer = "; installing";
4759                     $suppress = 1;
4760
4761                     # Maybe run libtoolize.
4762                     if ($seen_libtool
4763                         && grep ($_ eq $file, @libtoolize_files)
4764                         && system ('libtoolize', '--automake'))
4765                     {
4766                         $suppress = 0;
4767                         $trailer .= "; cannot run \`libtoolize': $!";
4768                     }
4769                     elsif (-f ($am_dir . '/' . $file))
4770                     {
4771                         # Install the missing file.  Symlink if we
4772                         # can, copy if we must.  Note: delete the file
4773                         # first, in case it is a dangling symlink.
4774                         unlink ($errfile);
4775                         if ($symlink_exists)
4776                         {
4777                             if (! symlink ($am_dir . '/' . $file, $errfile))
4778                             {
4779                                 $suppress = 0;
4780                                 $trailer .= "; error while making link: $!\n";
4781                             }
4782                         }
4783                         elsif (! system ('cp', $am_dir . '/' . $file, $errfile))
4784                         {
4785                             $suppress = 0;
4786                             $trailer .= "\n    error while making link\n";
4787                         }
4788                     }
4789                 }
4790
4791                 local ($save) = $exit_status;
4792                 if ($is_configure)
4793                 {
4794                     # FIXME: allow actual file to be specified.
4795                     &am_conf_line_error
4796                         ('configure.in', $line,
4797                          "required file \"$errfile\" not found$trailer");
4798                 }
4799                 else
4800                 {
4801                     &am_line_error
4802                         ($line,
4803                          "required file \"$errfile\" not found$trailer");
4804                 }
4805                 $exit_status = $save if $suppress;
4806             }
4807         }
4808     }
4809 }
4810
4811 # Like require_file_with_line, but error messages refer to
4812 # configure.in, not the current Makefile.am.
4813 sub require_file_with_conf_line
4814 {
4815     @require_file_paths = '.';
4816     &require_file_internal (1, @_);
4817 }
4818
4819 sub require_file_with_line
4820 {
4821     @require_file_paths = '.';
4822     &require_file_internal (0, @_);
4823 }
4824
4825 sub require_file
4826 {
4827     @require_file_paths = '.';
4828     &require_file_internal (0, '', @_);
4829 }
4830
4831 # Require a file that is also required by Autoconf.  Looks in
4832 # configuration path, as specified by AC_CONFIG_AUX_DIR.
4833 sub require_config_file
4834 {
4835     @require_file_paths = @config_aux_path;
4836     &require_file_internal (1, '', @_);
4837     local ($dir) = $require_file_paths[0];
4838     @config_aux_path = @require_file_paths;
4839     if ($dir eq '.')
4840     {
4841         $config_aux_dir = '.';
4842     }
4843     else
4844     {
4845         $config_aux_dir = '$(top_srcdir)/' . $dir;
4846     }
4847 }
4848
4849 # Assumes that the line number is in Makefile.am.
4850 sub require_conf_file_with_line
4851 {
4852     @require_file_paths = @config_aux_path;
4853     &require_file_internal (0, @_);
4854     local ($dir) = $require_file_paths[0];
4855     @config_aux_path = @require_file_paths;
4856     if ($dir eq '.')
4857     {
4858         $config_aux_dir = '.';
4859     }
4860     else
4861     {
4862         $config_aux_dir = '$(top_srcdir)/' . $dir;
4863     }
4864 }
4865
4866 # Assumes that the line number is in Makefile.am.
4867 sub require_conf_file_with_conf_line
4868 {
4869     @require_file_paths = @config_aux_path;
4870     &require_file_internal (1, @_);
4871     local ($dir) = $require_file_paths[0];
4872     @config_aux_path = @require_file_paths;
4873     if ($dir eq '.')
4874     {
4875         $config_aux_dir = '.';
4876     }
4877     else
4878     {
4879         $config_aux_dir = '$(top_srcdir)/' . $dir;
4880     }
4881 }
4882
4883 ################################################################
4884
4885 # Push a list of files onto dist_common.
4886 sub push_dist_common
4887 {
4888     local (@files) = @_;
4889     local ($file);
4890
4891     foreach $file (@files)
4892     {
4893         $dist_common{$file} = 1;
4894     }
4895 }
4896
4897 # Push a list of clean targets onto phony.
4898 sub push_phony_cleaners
4899 {
4900     local ($base) = @_;
4901     local ($target);
4902     foreach $target ('mostly', 'dist', '', 'maintainer-')
4903     {
4904         push (@phony, $target . 'clean-' . $base);
4905     }
4906 }
4907
4908 # Set strictness.
4909 sub set_strictness
4910 {
4911     $strictness_name = $_[0];
4912     if ($strictness_name eq 'gnu')
4913     {
4914         $strictness = $GNU;
4915     }
4916     elsif ($strictness_name eq 'gnits')
4917     {
4918         $strictness = $GNITS;
4919     }
4920     elsif ($strictness_name eq 'foreign')
4921     {
4922         $strictness = $FOREIGN;
4923     }
4924     else
4925     {
4926         die "automake: level \`$strictness_name' not recognized\n";
4927     }
4928 }
4929
4930
4931 ################################################################
4932
4933 # Return directory name of file.
4934 sub dirname
4935 {
4936     local ($file) = @_;
4937     local ($sub);
4938
4939     ($sub = $file) =~ s,/+[^/]+$,,g;
4940     $sub = '.' if $sub eq $file;
4941     return $sub;
4942 }
4943
4944 # Return file name of a file.
4945 sub basename
4946 {
4947     local ($file) = @_;
4948     local ($sub);
4949
4950     ($sub = $file) =~s,^.*/+,,g;
4951     return $sub;
4952 }
4953
4954 # Touch a file.
4955 sub touch
4956 {
4957     local ($file) = @_;
4958
4959     open (TOUCH, ">> $file");
4960     close (TOUCH);
4961 }
4962
4963 # Glob something.  Do this to avoid indentation screwups everywhere we
4964 # want to glob.  Gross!
4965 sub my_glob
4966 {
4967     local ($pat) = @_;
4968     return <${pat}>;
4969 }
4970
4971 ################################################################
4972
4973 # Print an error message and set exit status.
4974 sub am_error
4975 {
4976     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
4977     $exit_status = 1;
4978 }
4979
4980 sub am_line_error
4981 {
4982     local ($symbol, @args) = @_;
4983
4984     if ($symbol)
4985     {
4986         # If SYMBOL not already a line number, look it up in Makefile.am.
4987         if ($symbol =~ /^\d+$/)
4988         {
4989             $symbol .= ': ';
4990         }
4991         elsif (defined $content_lines{$symbol})
4992         {
4993             $symbol = $content_lines{$symbol} . ': ';
4994         }
4995         else
4996         {
4997             # A single space, to provide nice separation.
4998             $symbol = ' ';
4999         }
5000         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
5001         $exit_status = 1;
5002     }
5003     else
5004     {
5005         &am_error (@args);
5006     }
5007 }
5008
5009 # Like am_error, but while scanning configure.in.
5010 sub am_conf_error
5011 {
5012     # FIXME: can run in subdirs.
5013     warn "automake: configure.in: ", join (' ', @_), "\n";
5014     $exit_status = 1;
5015 }
5016
5017 # Error message with line number referring to configure.in.
5018 sub am_conf_line_error
5019 {
5020     local ($file, $line, @args) = @_;
5021
5022     if ($line)
5023     {
5024         warn "$file: $line: ", join (' ', @args), "\n";
5025         $exit_status = 1;
5026     }
5027     else
5028     {
5029         &am_conf_error (@args);
5030     }
5031 }
5032
5033 # Tell user where our aclocal.m4 is, but only once.
5034 sub keyed_aclocal_warning
5035 {
5036     local ($key) = @_;
5037     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
5038 }
5039
5040 # Print usage information.
5041 sub usage
5042 {
5043     print "Usage: automake [OPTION] ... [Makefile]...\n";
5044     print $USAGE;
5045     print "\nFiles which are automatically distributed, if found:\n";
5046     $~ = "USAGE_FORMAT";
5047     local (@lcomm) = sort ((@common_files, @common_sometimes));
5048     local ($one, $two, $three, $four);
5049     while (@lcomm > 0)
5050     {
5051         $one = shift @lcomm;
5052         $two = @lcomm ? shift @lcomm : '';
5053         $three = @lcomm ? shift @lcomm : '';
5054         $four = @lcomm ? shift @lcomm : '';
5055         write;
5056     }
5057
5058     print "\nReport bugs to <bug-gnu-utils\@prep.ai.mit.edu>\n";
5059
5060     exit 0;
5061 }
5062
5063 format USAGE_FORMAT =
5064   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
5065   $one,               $two,               $three,             $four
5066 .