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