more texinfo files to remove
[automake.git] / automake.in
blobaf5e46c8acc43560d5adac642dfce6aac06bb509
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 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 $MACRO_PATTERN = "^([A-Za-z][A-Za-z0-9_]*)[ \t]*:?=[ \t]*(.*)\$";
44 $BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*:?=[ \t]*(.*)\$";
45 $GNITS_VERSION_PATTERN = "[0-9]+\\.[0-9]+([a-z]|\\.[0-9]+)?";
46 $IF_PATTERN = "^if[ \t]+\([A-Za-z][A-Za-z0-9_]*\)[ \t]*\(#.*\)?\$";
47 $ELSE_PATTERN = "^else[ \t]*\(#.*\)?\$";
48 $ENDIF_PATTERN = "^endif[ \t]*\(#.*\)?\$";
50 # Some regular expressions.  One reason to put them here is that it
51 # makes indentation work better in Emacs.
52 $AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
53 $AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^,)]+)[,)]";
54 $AM_PACKAGE_VERSION_PATTERN = "^\\s*\\[?([^]\\s]+)\\]?\\s*\$";
55 # Note that there is no AC_PATH_TOOL.  But we don't really care.
56 $AC_CHECK_PATTERN = "AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\\(\\[?(\\w+)";
57 $AM_MISSING_PATTERN = "AM_MISSING_PROG\\(\\[?(\\w+)";
58 # Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
59 # then too bad.
60 $AC_SUBST_PATTERN = "AC_SUBST\\(\\[?(\\w+)";
61 $AM_CONDITIONAL_PATTERN = "AM_CONDITIONAL\\((\\w+)";
63 # Constants to define the "strictness" level.
64 $FOREIGN = 0;
65 $GNU = 1;
66 $GNITS = 2;
70 # Variables global to entire run.
72 # TRUE if we should always generate Makefile.in.
73 $force_generation = 1;
75 # Strictness level as set on command line.
76 $default_strictness = $GNU;
78 # Name of strictness level, as set on command line.
79 $default_strictness_name = 'gnu';
81 # This is TRUE if GNU make specific automatic dependency generation
82 # code should be included in generated Makefile.in.
83 $cmdline_use_dependencies = 1;
85 # TRUE if in verbose mode.
86 $verbose = 0;
88 # This holds our (eventual) exit status.  We don't actually exit until
89 # we have processed all input files.
90 $exit_status = 0;
92 # From the Perl manual.
93 $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
95 # TRUE if missing standard files should be installed.
96 $add_missing = 0;
98 # Files found by scanning configure.in for LIBOBJS.
99 %libsources = ();
101 # True if AM_C_PROTOTYPES appears in configure.in.
102 $am_c_prototypes = 0;
104 # Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
105 # name which appears in AC_CONFIG_HEADER, colon and all.
106 # @config_names holds the file names.  @config_headers holds the '.in'
107 # files.  Ordinarily these are similar, but they can be different if
108 # the weird "NAME:FILE" syntax is used.
109 @config_fullnames = ();
110 @config_names = ();
111 @config_headers = ();
112 # Line number at which AC_CONFIG_HEADER appears in configure.in.
113 $config_header_line = 0;
115 # Directory where output files go.  Actually, output files are
116 # relative to this directory.
117 $output_directory = '.';
119 # Relative location of top build directory.
120 $top_builddir = '';
122 # Absolute location of top build directory.
123 $build_directory = '';
125 # Name of srcdir as given in build directory's Makefile.  For
126 # dependencies only.
127 $srcdir_name = '';
129 # List of Makefile.am's to process, and their corresponding outputs.
130 @input_files = ();
131 %output_files = ();
133 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
134 @other_input_files = ();
135 # Line number at which AC_OUTPUT seen.
136 $ac_output_line = 0;
138 # List of directories to search for configure-required files.  This
139 # can be set by AC_CONFIG_AUX_DIR.
140 @config_aux_path = ('.', '..', '../..');
141 $config_aux_dir = '';
143 # Whether AC_PROG_MAKE_SET has been seen in configure.in.
144 $seen_make_set = 0;
146 # Whether AM_GNU_GETTEXT has been seen in configure.in.
147 $seen_gettext = 0;
148 # Line number at which AM_GNU_GETTEXT seen.
149 $ac_gettext_line = 0;
151 # Whether ALL_LINGUAS has been seen.
152 $seen_linguas = '';
153 # The actual text.
154 $all_linguas = '';
155 # Line number at which it appears.
156 $all_linguas_line = 0;
158 # 1 if AC_PROG_INSTALL seen, 2 if AM_PROG_INSTALL seen.
159 $seen_prog_install = 0;
161 # 1 if any scripts installed, 0 otherwise.
162 $scripts_installed = 0;
164 # Whether AC_PATH_XTRA has been seen in configure.in.
165 $seen_path_xtra = 0;
167 # TRUE if AC_DECL_YYTEXT was seen.
168 $seen_decl_yytext = 0;
170 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
171 # AC_CHECK_TOOL also sets this.
172 $seen_canonical = 0;
174 # TRUE if we've seen AC_ARG_PROGRAM.
175 $seen_arg_prog = 0;
177 # TRUE if we've seen AM_PROG_LIBTOOL.
178 $seen_libtool = 0;
179 $libtool_line = 0;
181 # Files installed by libtoolize.
182 @libtoolize_files = ('ltconfig', 'ltmain.sh', 'config.guess', 'config.sub');
184 # TRUE if we've seen AM_MAINTAINER_MODE.
185 $seen_maint_mode = 0;
187 # TRUE if we've seen PACKAGE and VERSION.
188 $seen_package = 0;
189 $seen_version = 0;
191 # Actual version we've seen.
192 $package_version = '';
194 # Line number where we saw version definition.
195 $package_version_line = 0;
197 # TRUE if we've seen AM_PATH_LISPDIR.
198 $seen_lispdir = 0;
200 # TRUE if we've seen AM_EXEEXT.
201 $seen_exeext = 0;
203 # Hash table of discovered configure substitutions.  Keys are names,
204 # values are meaningless.
205 %configure_vars = ();
207 # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
208 # handled in a funny way: if seen in the top-level Makefile.am, it is
209 # used for every directory which does not specify a different value.
210 # The rationale here is that some directories (eg gettext) might be
211 # distributions of other packages, and thus require their own charset
212 # info.  However, the DIST_CHARSET must be the same for the entire
213 # package; it can only be set at top-level.
214 # FIXME: this yields bugs when rebuilding.  What to do?  Always
215 # read (and sometimes discard) top-level Makefile.am?
216 $maint_charset = '';
217 $dist_charset = 'utf8';         # recode doesn't support this yet.
219 # Name of input file ("Makefile.in") and output file ("Makefile.am").
220 # These have no directory components.
221 $am_file_name = '';
222 $in_file_name = '';
224 # TRUE if --cygnus seen.
225 $cygnus_mode = 0;
227 # Keys of this hash are names of dependency files to ignore.
228 %omit_dependencies = ();
230 # Hash table of AM_CONDITIONAL variables seen in configure.
231 %configure_cond = ();
233 # Map from obsolete macros to hints for new macros.
234 # FIXME complete the list so that there are no `0' hints.
235 %obsolete_macros =
236     (
237      'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
238      'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
239      'AC_FEATURE_EXIT', 0,
240      'AC_SYSTEM_HEADER', 0,
242      # Note that we do not handle this one, because it is still run
243      # from AM_CONFIG_HEADER.  So we deal with it specially in
244      # scan_configure.
245      # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",
247      'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
248      'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
249      'fp_PROG_INSTALL', "use \`AM_PROG_INSTALL'",
250      'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
251      'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
252      'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
253      'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
254      'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
255      'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",
257      # Now part of autoconf proper, under a different name.
258      'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
259      'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
260      'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",
262 # These aren't quite obsolete.
263 #      'md_PATH_PROG',
264      );
266 # Regexp to match the above macros.
267 $obsolete_rx = '(' . join ('|', keys %obsolete_macros) . ')';
271 &initialize_global_constants;
273 # Parse command line.
274 &parse_arguments (@ARGV);
276 # Do configure.in scan only once.
277 &scan_configure;
279 die "automake: no \`Makefile.am' found or specified\n"
280     if ! @input_files;
282 # Now do all the work on each file.
283 foreach $am_file (@input_files)
285     if (! -f ($am_file . '.am'))
286     {
287         &am_error ("\`" . $am_file . ".am' does not exist");
288     }
289     else
290     {
291         &generate_makefile ($output_files{$am_file}, $am_file);
292     }
295 if ($seen_prog_install <= $scripts_installed)
297     &am_conf_error (($scripts_installed ? 'AM_PROG_INSTALL' : 'AC_PROG_INSTALL')
298                     . " must be used in configure.in");
299     &keyed_aclocal_warning ('AM_PROG_INSTALL')
300         if $scripts_installed;
303 exit $exit_status;
306 ################################################################
308 # Parse command line.
309 sub parse_arguments
311     local (@arglist) = @_;
313     # Start off as gnu.
314     &set_strictness ('gnu');
316     while (@arglist)
317     {
318         if ($arglist[0] eq "--version")
319         {
320             print "automake (GNU $PACKAGE) $VERSION\n\n";
321             print "Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.\n";
322             print "This is free software; see the source for copying conditions.  There is NO\n";
323             print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
324             print "Written by Tom Tromey <tromey\@cygnus.com>\n";
326             exit 0;
327         }
328         elsif ($arglist[0] eq "--help")
329         {
330             &usage;
331         }
332         elsif ($arglist[0] =~ /^--amdir=(.+)$/)
333         {
334             $am_dir = $1;
335         }
336         elsif ($arglist[0] eq '--amdir')
337         {
338             &require_argument (@arglist);
339             shift (@arglist);
340             $am_dir = $arglist[0];
341         }
342         elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
343         {
344             # Must end in /.
345             $build_directory = $1 . '/';
346         }
347         elsif ($arglist[0] eq '--build-dir')
348         {
349             &require_argument (@arglist);
350             shift (@arglist);
351             # Must end in /.
352             $build_directory = $arglist[0] . '/';
353         }
354         elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
355         {
356             $srcdir_name = $1;
357         }
358         elsif ($arglist[0] eq '--srcdir-name')
359         {
360             &require_argument (@arglist);
361             shift (@arglist);
362             $srcdir_name = $arglist[0];
363         }
364         elsif ($arglist[0] eq '--gnu')
365         {
366             &set_strictness ('gnu');
367         }
368         elsif ($arglist[0] eq '--gnits')
369         {
370             &set_strictness ('gnits');
371         }
372         elsif ($arglist[0] eq '--cygnus')
373         {
374             $cygnus_mode = 1;
375         }
376         elsif ($arglist[0] eq '--foreign')
377         {
378             &set_strictness ('foreign');
379         }
380         elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
381         {
382             $cmdline_use_dependencies = 0;
383         }
384         elsif ($arglist[0] eq '--no-force')
385         {
386             $force_generation = 0;
387         }
388         elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
389         {
390             # Set output directory.
391             $output_directory = $1;
392         }
393         elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
394         {
395             &require_argument (@arglist);
396             shift (@arglist);
397             $output_directory = $arglist[0];
398         }
399         elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
400         {
401             $add_missing = 1;
402         }
403         elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
404         {
405             $verbose = 1;
406         }
407         elsif ($arglist[0] eq '--')
408         {
409             # Stop option processing.
410             shift (@arglist);
411             push (@input_files, @arglist);
412             last;
413         }
414         elsif ($arglist[0] =~ /^-/)
415         {
416             die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
417         }
418         else
419         {
420             # Handle $local:$input syntax.  Note that we only examine
421             # the first ":" file to see if it is automake input; the
422             # rest are just taken verbatim.  We still keep all the
423             # files around for dependency checking, however.
424             local ($local, $input, @rest) = split (/:/, $arglist[0]);
425             if (! $input)
426             {
427                 $input = $local;
428             }
429             else
430             {
431                 # Strip .in; later on .am is tacked on.  That is how
432                 # the automake input file is found.  Maybe not the
433                 # best way, but it is easy to explain.  FIXME: should
434                 # be error if .in is missing.
435                 $input =~ s/\.in$//;
436             }
437             push (@input_files, $input);
438             $output_files{$input} = join (':', ($local, @rest));
439         }
441         shift (@arglist);
442     }
444     # Take global strictness from whatever we currently have set.
445     $default_strictness = $strictness;
446     $default_strictness_name = $strictness_name;
449 # Ensure argument exists, or die.
450 sub require_argument
452     local ($arg, @arglist) = @_;
453     die "automake: no argument given for option \`$arg'\n"
454         if ! @arglist;
457 ################################################################
459 # Generate a Makefile.in given the name of the corresponding Makefile and
460 # the name of the file output by config.status.
461 sub generate_makefile
463     local ($output, $makefile) = @_;
465     ($am_file_name = $makefile) =~ s/^.*\///;
466     $in_file_name = $am_file_name . '.in';
467     $am_file_name .= '.am';
469     # $OUTPUT is encoded.  If it contains a ":" then the first element
470     # is the real output file, and all remaining elements are input
471     # files.  We don't scan or otherwise deal with these input file,
472     # other than to mark them as dependencies.  See scan_configure for
473     # details.
474     local (@secondary_inputs);
475     ($output, @secondary_inputs) = split (/:/, $output);
477     &initialize_per_input;
478     $relative_dir = &dirname ($output);
479     $am_relative_dir = &dirname ($makefile);
481     # At the toplevel directory, we might need config.guess, config.sub
482     # or libtool scripts (ltconfig and ltmain.sh).
483     if ($relative_dir eq '.')
484     {
485         # libtool requires some files.
486         &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
487                                            @libtoolize_files)
488             if $seen_libtool;
490         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
491         # config.sub.
492         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
493             if $seen_canonical;
494     }
496     # We still need Makefile.in here, because sometimes the `dist'
497     # target doesn't re-run automake.
498     if ($am_relative_dir eq $relative_dir)
499     {
500         # Only distribute the files if they are in the same subdir as
501         # the generated makefile.
502         &push_dist_common ($in_file_name, $am_file_name);
503     }
504     push (@sources, '$(SOURCES)')
505         if &variable_defined ('SOURCES');
506     push (@objects, '$(OBJECTS)')
507         if &variable_defined ('OBJECTS');
509     # This is always the default target.  This gives us freedom to do
510     # things in whatever order is convenient.  Note that we set up
511     # $output_header here so that we can insert some text just after
512     # the "default" target, but before any other targets.  In
513     # particular we want to support the .SUFFIX hack here; this is
514     # documented elsewhere.
515     $output_header = "default: all\n\n";
516     push (@phony, 'default');
518     &read_am_file ($makefile . '.am');
519     if (&handle_options)
520     {
521         # Fatal error.  Just return, so we can continue with next file.
522         return;
523     }
525     # Check first, because we might modify some state.
526     &check_cygnus;
527     &check_gnu_standards;
528     &check_gnits_standards;
530     &handle_configure ($output, $makefile, @secondary_inputs);
531     &handle_gettext;
532     &handle_libraries;
533     &handle_ltlibraries;
534     &handle_programs;
535     &handle_scripts;
537     &handle_built_sources;
539     # This must be run after all the sources are scanned.
540     &handle_yacc_lex_cxx;
542     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
543     # on this (but currently does).
544     $contents{'SOURCES'} = join (' ', @sources);
545     $contents{'OBJECTS'} = join (' ', @objects);
547     &handle_texinfo;
548     &handle_emacs_lisp;
549     &handle_man_pages;
550     &handle_data;
551     &handle_headers;
552     &handle_subdirs;
553     &handle_tags;
554     &handle_dist ($makefile);
555     &handle_dependencies;
556     &handle_tests;
557     &handle_footer;
558     &handle_merge_targets ($makefile);
559     &handle_installdirs;
560     &handle_clean;
561     &handle_phony;
563     &check_typos;
565     if (! -d ($output_directory . '/' . $am_relative_dir))
566     {
567         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
568     }
570     local ($out_file) = $output_directory . '/' . $makefile . ".in";
571     if (! $force_generation && -e $out_file)
572     {
573         local ($am_time) = (stat ($makefile . '.am'))[9];
574         local ($in_time) = (stat ($out_file))[9];
575         # FIXME: should cache these times.
576         local ($conf_time) = (stat ('configure.in'))[9];
577         # FIXME: how to do unsigned comparison?
578         if ($am_time < $in_time || $am_time < $conf_time)
579         {
580             # No need to update.
581             return;
582         }
583         if (-f 'aclocal.m4')
584         {
585             local ($acl_time) = (stat _)[9];
586             return if ($am_time < $acl_time);
587         }
588     }
590     if (! open (GM_FILE, "> " . $out_file))
591     {
592         warn "automake: ${am_file}.in: cannot write: $!\n";
593         $exit_status = 1;
594         return;
595     }
596     print "automake: creating ", $makefile, ".in\n" if $verbose;
598     print GM_FILE $output_vars;
599     print GM_FILE $output_header;
600     print GM_FILE $output_rules;
601     print GM_FILE $output_trailer;
603     close (GM_FILE);
606 ################################################################
608 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
609 sub handle_options
611     return 0 if ! &variable_defined ('AUTOMAKE_OPTIONS');
613     foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
614     {
615         $options{$_} = 1;
616         if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
617         {
618             &set_strictness ($_);
619         }
620         elsif (/ansi2knr/)
621         {
622             # An option like "../lib/ansi2knr" is allowed.  With no
623             # path prefix, we assume the required programs are in this
624             # directory.  We save the actual option for later.
625             $options{'ansi2knr'} = $_;
626         }
627         elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
628                || $_ eq 'dist-shar' || $_ eq 'dist-zip'
629                || $_ eq 'dist-tarZ' || $_ eq 'dejagnu'
630                || $_ eq 'no-texinfo.tex')
631         {
632             # Explicitly recognize these.
633         }
634         elsif ($_ eq 'no-dependencies')
635         {
636             $use_dependencies = 0;
637         }
638         elsif (/([0-9]+)\.([0-9]+)/)
639         {
640             # Got a version number.  Note that alpha releases count as
641             # the next higher release.  Note also that we assume there
642             # will be a maximum of 100 minor releases for any given
643             # major release.
644             local ($rmajor, $rminor) = ($1, $2);
645             if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
646             {
647                 print STDERR
648                     "automake: programming error: version is incorrect\n";
649                 exit 1;
650             }
651             local ($tmajor, $tminor) = ($1, $2);
652             # Handle alpha versions.
653             ++$tminor if defined $3;
655             if ($rmajor > $tmajor || ($rmajor == $tmajor && $rminor > $tminor))
656             {
657                 &am_line_error ('AUTOMAKE_OPTIONS',
658                                 "require version $_, only have $VERSION");
659                 return 1;
660             }
661         }
662         else
663         {
664             &am_line_error ('AUTOMAKE_OPTIONS',
665                             'option ', $_, 'not recognized');
666         }
667     }
669     return 0;
672 # Return object extension.  Just once, put some code into the output.
673 # Argument is the name of the output file
674 sub get_object_extension
676     local ($out) = @_;
678     # Always set this.
679     $dir_holds_sources = 1;
681     # Maybe require libtool library object files.
682     local ($extension) = '.o';
683     $extension = '.lo' if ($out =~ /\.la$/);
685     if (! $included_generic_compile)
686     {
687         # Boilerplate.
688         local ($xform) = '';
689         if (&variable_defined ('CONFIG_HEADER'))
690         {
691             local ($one_hdr);
692             foreach $one_hdr (split (' ', &variable_value ('CONFIG_HEADER')))
693             {
694                 local ($var);
695                 ($var = &dirname ($one_hdr)) =~ s/(\W)/\\$1/g;
696                 $xform .= ' ' if $xform;
697                 $xform .= '-I' . $var;
698             }
699         }
700         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go;';
701         $output_vars .= &file_contents_with_transform ($xform,
702                                                        'comp-vars');
703         $output_rules .= &file_contents ('compile');
704         &push_phony_cleaners ('compile');
706         # If using X, include some extra variable definitions.  NOTE
707         # we don't want to force these into CFLAGS or anything,
708         # because not all programs will necessarily use X.
709         if ($seen_path_xtra)
710         {
711             local ($var);
712             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
713             {
714                 &define_configure_variable ($var);
715             }
716         }
718         push (@suffixes, '.c', '.o');
719         push (@clean, 'compile');
721         $included_generic_compile = 1;
722     }
724     if ($seen_libtool && ! $included_libtool_compile)
725     {
726         # Output the libtool compilation rules.
727         $output_rules .= &file_contents ('libtool');
728         &push_phony_cleaners ('libtool');
730         push (@suffixes, '.lo');
731         push (@clean, 'libtool');
733         $included_libtool_compile = 1;
734     }
736     # Check for automatic de-ANSI-fication.
737     if (defined $options{'ansi2knr'})
738     {
739         $extension = '$U' . $extension;
740         if (! $included_knr_compile)
741         {
742             if (! $am_c_prototypes)
743             {
744                 &am_line_error ('AUTOMAKE_OPTIONS',
745                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
746                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
747                 # Only give this error once.
748                 $am_c_prototypes = 1;
749             }
751             # Only require ansi2knr files if they should appear in
752             # this directory.
753             if ($options{'ansi2knr'} eq 'ansi2knr')
754             {
755                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
756                                          'ansi2knr.c', 'ansi2knr.1');
757                 $output_rules .= &file_contents ('kr-extra');
758                 push (@clean, 'krextra');
759                 &push_phony_cleaners ('krextra');
760             }
762             # Generate rules to build ansi2knr.  If it is in some
763             # other directory, then generate dependencies but have the
764             # rule just run elsewhere.
765             $output_rules .= ($options{'ansi2knr'} . ': '
766                               . $options{'ansi2knr'} . ".o\n");
767             if ($options{'ansi2knr'} eq 'ansi2knr')
768             {
769                 $output_rules .= ("\t\$(LINK) ansi2knr.o \$(LIBS)\n"
770                                   . "ansi2knr.o: \$(CONFIG_HEADER)\n\n");
771             }
772             else
773             {
774                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
775                                   . " && \$(MAKE) ansi2knr\n\n");
776             }
778             # Make sure ansi2knr can be found: if no path specified,
779             # specify "./".
780             if ($options{'ansi2knr'} eq 'ansi2knr')
781             {
782                 # Substitution from AM_C_PROTOTYPES.  This makes it be
783                 # built only when necessary.
784                 &define_configure_variable ('ANSI2KNR');
785                 # ansi2knr needs to be built before subdirs, so unshift it.
786                 unshift (@all, '$(ANSI2KNR)');
787             }
788             else
789             {
790                 # Found in another directory.
791                 &define_variable ("ANSI2KNR", $options{'ansi2knr'});
792             }
794             $output_rules .= &file_contents ('clean-kr');
796             push (@clean, 'kr');
797             &push_phony_cleaners ('kr');
799             $included_knr_compile = 1;
800         }
801     }
803     return $extension;
806 # Handle yacc and lex.
807 sub handle_yacc_lex_cxx
809     #
810     # First do yacc and lex.
811     #
813     local ($yacc_count) = scalar (keys %yacc_sources);
814     local ($lex_count) = scalar (keys %lex_sources);
816     if ($yacc_count)
817     {
818         local (%seen_suffix) = ();
819         foreach (keys %yacc_sources)
820         {
821             /(\..*)$/;
822             &output_yacc_build_rule ($1, $yacc_count > 1)
823                 if (! defined $seen_suffix{$1});
824             $seen_suffix{$1} = 1;
825         }
827         if (! defined $configure_vars{'YACC'})
828         {
829             &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
830         }
831     }
832     if ($lex_count)
833     {
834         local (%seen_suffix) = ();
835         foreach (keys %lex_sources)
836         {
837             /(\..*)$/;
838             &output_lex_build_rule ($1, $lex_count > 1)
839                 if (! defined $seen_suffix{$1});
840             $seen_suffix{$1} = 1;
841         }
843         if (! defined $configure_vars{'LEX'})
844         {
845             &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
846         }
847         if (! $seen_decl_yytext)
848         {
849             &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
850         }
851     }
853     if ($yacc_count > 1 || $lex_count > 1)
854     {
855         # If there is more than one distinct yacc (resp lex) source
856         # file in a given directory, then the `ylwrap' program is
857         # required to allow parallel builds to work correctly.  FIXME:
858         # for now, no line number.
859         &require_config_file ($FOREIGN, 'ylwrap');
860         if ($config_aux_dir ne '.' && $config_aux_dir ne '')
861         {
862                 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
863         }
864         else
865         {
866                 &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
867         }
868     }
870     #
871     # Handle libtool.
872     #
873     local ($ltcompile, $ltlink) = ('', '');
874     if ($seen_libtool)
875     {
876         &define_configure_variable ("LIBTOOL");
877         $ltcompile = '$(LIBTOOL) --mode=compile ';
878         $ltlink = '$(LIBTOOL) --mode=link ';
879     }
881     #
882     # Now handle C++.
883     #
884     local (@cxx_list) = keys %cxx_extensions;
885     local ($cxx_count) = scalar @cxx_list;
886     if ($cxx_count)
887     {
888         push (@suffixes, @cxx_list);
890         &define_configure_variable ("CXXFLAGS");
891         &define_variable ('CXXCOMPILE', '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
892         &define_variable ('LTCXXCOMPILE',
893                           $ltcompile . '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)')
894             if ($seen_libtool);
896         &define_variable ('CXXLINK', $ltlink . '$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@');
898         local ($ext);
899         foreach $ext (@cxx_list)
900         {
901             $output_rules .= ("$ext.o:\n"
902                               . "\t\$(CXXCOMPILE) -c \$<\n");
903             $output_rules .= ("$ext.lo:\n"
904                               . "\t\$(LTCXXCOMPILE) -c \$<\n")
905                 if ($seen_libtool);
906         }
908         if (! defined $configure_vars{'CXX'})
909         {
910             &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
911         }
912     }
914     #
915     # Handle some ansi2knr cleanup.
916     #
917     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
918     {
919         # Make all _.c files depend on their corresponding .c files.
920         local ($base, @objects);
921         foreach $base (sort (keys %de_ansi_files))
922         {
923             # Each _.c file must depend on ansi2knr; otherwise it
924             # might be used in a parallel build before it is built.
925             $output_rules .= $base . "_.c: $base.c \$(ANSI2KNR)\n\t"
926                 . '$(ANSI2KNR) ' . $base . '.c ' . $base . "_.c\n";
927             push (@objects, $base . '_.o');
928             push (@objects, $base . '_.lo') if $seen_libtool;
929         }
931         # Make all _.o (and _.lo) files depend on ansi2knr.
932         # Use a sneaky little hack to make it print nicely.
933         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
934     }
936     #
937     # Last, handle some C cleanup.
938     #
939     if ($seen_c_source)
940     {
941         &define_configure_variable ('CFLAGS');
942         &define_variable ('COMPILE',
943                           '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)');
944         &define_variable ('LTCOMPILE',
945                           $ltcompile .
946                           '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)')
947             if ($seen_libtool);
948         &define_variable ('LINK', $ltlink . '$(CC) $(CFLAGS) $(LDFLAGS) -o $@');
950         if (! defined $configure_vars{'CC'})
951         {
952             &am_line_error ($seen_c_source,
953                             "C source seen but \`CC' not defined in \`configure.in'");
954         }
955     }
959 # Output a rule to build from a YACC source.  The output from YACC is
960 # compiled with C or C++, depending on the extension of the YACC file.
961 sub output_yacc_build_rule
963     local ($yacc_suffix, $use_ylwrap, $c_suffix) = @_;
965     local ($c_suffix, $suffix);
966     ($c_suffix = $yacc_suffix) =~ tr/y/c/;
967     push (@suffixes, $yacc_suffix, $c_suffix, '.h');
969     # Generate rule for c/c++ and header file.  Probably should only
970     # do header if `yacc -d' is run.  But how can we determine that?
971     foreach $suffix ($c_suffix, '.h')
972     {
973         $output_rules .= "$yacc_suffix$suffix:\n\t";
975         if ($use_ylwrap)
976         {
977             $output_rules .= ('$(SHELL) $(YLWRAP)'
978                               . ' "$(YACC)" $< y.tab.c $*' . $c_suffix
979                               . ' y.tab.h $*.h -- $(YACCFLAGS)');
980         }
981         else
982         {
983             $output_rules .= ('$(YACC) $(YACCFLAGS) $< && mv y.tab.c $@' . "\n"
984                               . "\tif test -f y.tab.h; then \\\n"
985                               . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
986                           . "\telse :; fi");
987         }
988         $output_rules .= "\n";
989     }
992 sub output_lex_build_rule
994     local ($lex_suffix, $use_ylwrap) = @_;
995     local ($c_suffix);
997     ($c_suffix = $lex_suffix) =~ tr/l/c/;
998     push (@suffixes, $lex_suffix);
999     &define_configure_variable ('LEX_OUTPUT_ROOT');
1000     &define_configure_variable ('LEXLIB');
1001     $output_rules .= "$lex_suffix$c_suffix:\n\t";
1003     if ($use_ylwrap)
1004     {
1005         # Is the $@ correct here?  If so, why not use it in the ylwrap
1006         # build rule for yacc above?
1007         $output_rules .= '$(SHELL) $(YLWRAP)'
1008             . ' "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(LFLAGS)';
1009     }
1010     else
1011     {
1012         $output_rules .= '$(LEX) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
1013     }
1014     $output_rules .= "\n";
1018 # Check to make sure a source defined in LIBOBJS is not explicitly
1019 # mentioned.  This is a separate function (as opposed to being inlined
1020 # in handle_source_transform) because it isn't always appropriate to
1021 # do this check.
1022 sub check_libobjs_sources
1024     local ($one_file, $unxformed) = @_;
1026     local ($prefix, $file, @files);
1027     foreach $prefix ('', 'EXTRA_')
1028     {
1029         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1030         {
1031             @files = &variable_value_as_list (($prefix
1032                                                . $one_file . '_SOURCES'),
1033                                               'all');
1034         }
1035         elsif ($prefix eq '')
1036         {
1037             @files = ($unxformed . '.c');
1038         }
1039         else
1040         {
1041             next;
1042         }
1044         foreach $file (@files)
1045         {
1046             if (defined $libsources{$file})
1047             {
1048                 &am_line_error ($prefix . $one_file . '_SOURCES',
1049                                 "automatically discovered file \`$file' should not be explicitly mentioned");
1050             }
1051         }
1052     }
1055 # Does much of the actual work for handle_source_transform.
1056 # Arguments are:
1057 #   list of source files to transform
1058 # Result is a list
1059 #   first element is name of linker to use (empty string for default linker)
1060 #   remaining elements are names of `.o's
1061 sub handle_single_transform_list
1063     local (@files) = @_;
1064     local ($linker) = '';
1065     local (@result) = ();
1066     local ($nonansi_obj) = $obj;
1067     $nonansi_obj =~ s/_//g;
1068     if (length (@files))
1069     {
1070         # Turn sources into objects.
1071         foreach (@files)
1072         {
1073             # Skip header files, including C++-ish ones.  The list
1074             # of C++ header extensions comes from Emacs 19.32
1075             # etags.
1076             next if /\.[hH]$/;
1077             next if /\.hxx$/;
1078             next if /\.h\+\+$/;
1079             next if /\.hh$/;
1080             next if /\.hpp$/;
1081             # Skip things that look like configure substitutions.
1082             next if /^\@.*\@$/;
1084             # Include appropriate file for lex or yacc source in
1085             # distribution.  If the extension is the regular '.y' or
1086             # '.l', we assume C compilation, and the generated file
1087             # has exension .c.  Otherwise, we compile with C++, and
1088             # make the following association: (yy -> cc, y++ -> c++,
1089             # yxx -> cxx), similarly for .ll, etc.
1090             if (/^(.*)\.(y|yy|y\+\+|yxx)$/)
1091             {
1092                 # Yacc source.
1093                 local ($ext) = $2;
1094                 $ext =~ tr/y/c/;
1095                 &push_dist_common ("$1.$ext");
1096                 $yacc_sources{$_} = 1;
1097             }
1098             elsif (/^(.*)\.(l|ll|l\+\+|lxx)$/)
1099             {
1100                 # Lex source.
1101                 local ($ext) = $2;
1102                 $ext =~ tr/l/c/;
1103                 &push_dist_common ("$1.$ext");
1104                 $lex_sources{$_} = 1;
1105             }
1107             # Strip any directory prefix.
1108             $_ = &basename ($_);
1110             # Transform source files into .o files.  List of C++
1111             # extensions comes from Emacs 19.34 etags.
1112             if (s/\.(c\+\+|cc|cpp|cxx|C)$/$nonansi_obj/)
1113             {
1114                 $cxx_extensions{'.' . $1} = 1;
1115                 $linker = 'CXXLINK';
1116             }
1117             elsif (s/\.(yy|y\+\+|yxx|ll|l\+\+|lxx)$/$nonansi_obj/)
1118             {
1119                 # Compiling lex or yacc with C++
1120                 local ($ext) = $1;
1121                 $ext =~ tr/ly/cc/;
1122                 $cxx_extensions{".$ext"} = 1;
1123                 $linker = 'CXXLINK';
1124             }
1125             elsif (s/\.([Ff]\\|f90\\|for)$/$nonansi_obj/)
1126             {
1127                 # FORTRAN support.  FIXME: not finished.
1128             }
1129             elsif (s/\.[sS]$/$nonansi_obj/)
1130             {
1131                 # .s is assembly.  Just rewrite it.  FIXME: not finished.
1132             }
1133             elsif (defined ($options{'ansi2knr'}) && s/_\.[cly]$/_.c/)
1134             {
1135                 # FIXME include line number in error.
1136                 &am_error ("C source file \`$_' would be deleted by ansi2knr rules");
1137             }
1138             elsif (s/\.[cly]$//)
1139             {
1140                 # .c is C.  .l is lex.  .y is yacc.
1141   
1142                 # Note: first we rewrite (eg) foo.c to foo and push
1143                 # the file onto the list of deansified files.  Then we add
1144                 # $obj, which can either be `_.o', or simply `.o' if
1145                 # deansification is not required.
1146                 $de_ansi_files{$_} = 1;
1147                 $_ .= $obj;
1148                 $seen_c_source = 1;
1149             }
1150             else
1151             {
1152                 # No error message here.  Used to have one, but it was
1153                 # very unpopular.
1154                 next;
1155             }
1157             push (@result, $_);
1159             # Transform .o or $o file into .P file (for automatic
1160             # dependency code).
1161             s/$objpat$/.P/g;
1162             $dep_files{'.deps/' . $_} = 1;
1163         }
1164     }
1166     return ($linker, @result);
1169 # Handle SOURCE->OBJECT transform for one program or library.
1170 # Arguments are:
1171 #   canonical (transformed) name of object to build
1172 #   actual name of object to build
1173 #   object extension (ie either `.o' or `$o'.
1174 # Return result is name of linker variable that must be used.
1175 # Empty return means just use `LINK'.
1176 sub handle_source_transform
1178     # one_file is canonical name.  unxformed is given name.  obj is
1179     # object extension.
1180     local ($one_file, $unxformed, $obj) = @_;
1181     local ($objpat) = $obj;
1182     $objpat =~ s/(\W)/\\$1/g;
1183     # Handle explicit `.o' as well as whatever we're passed.
1184     $objpat = '(' . $objpat . "|\\.o)";
1186     local ($linker) = '';
1188     if (&variable_defined ($one_file . "_OBJECTS"))
1189     {
1190         &am_line_error ($one_file . '_OBJECTS',
1191                         $one_file . '_OBJECTS', 'should not be defined');
1192         # No point in continuing.
1193         return;
1194     }
1196     local (@files, @result, $prefix, $temp);
1197     foreach $prefix ('', 'EXTRA_')
1198     {
1199         @files = ();
1200         local ($var) = $prefix . $one_file . "_SOURCES";
1201         if (&variable_defined ($var))
1202         {
1203             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1204             push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
1205                 unless $prefix eq 'EXTRA_';
1206             local (@conds) = &variable_conditions ($var);
1207             if (! @conds)
1208             {
1209                 @files = &variable_value_as_list ($var, '');
1210             }
1211             else
1212             {
1213                 local ($cond);
1214                 foreach $cond (@conds)
1215                 {
1216                     @files = &variable_value_as_list ($var, $cond);
1217                     ($temp, @result) = &handle_single_transform_list (@files);
1218                     $linker = $temp if $linker eq '';
1219                     &define_pretty_variable ($one_file . "_OBJECTS", $cond,
1220                                              @result)
1221                         unless $prefix eq 'EXTRA_';
1222                 }
1224                 next;
1225             }
1226         }
1227         elsif ($prefix eq '')
1228         {
1229             &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1230             push (@sources, $unxformed . '.c');
1231             push (@objects, $unxformed . $obj);
1232             push (@files, $unxformed . '.c');
1233         }
1235         ($temp, @result) = &handle_single_transform_list (@files);
1236         $linker = $temp if $linker eq '';
1237         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
1238             unless $prefix eq 'EXTRA_';
1239     }
1241     return $linker;
1244 # Handle the BUILT_SOURCES variable.
1245 sub handle_built_sources
1247     return unless &variable_defined ('BUILT_SOURCES');
1249     local (@sources) = &variable_value_as_list ('BUILT_SOURCES', 'all');
1250     local ($s);
1251     foreach $s (@sources)
1252     {
1253         if (/^\@.*\@$/)
1254         {
1255             # FIXME: is this really the right thing to do?
1256             &am_line_error ('BUILT_SOURCES',
1257                             "\`BUILT_SOURCES' should not contain a configure substitution");
1258             last;
1259         }
1260     }
1262     # We don't care about the return value of this function.  We just
1263     # want to make sure to update %dep_files with the contents of
1264     # BUILT_SOURCES.
1265     &handle_single_transform_list (@sources);
1268 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1269 # Also, generate _DEPENDENCIES variable if appropriate.
1270 # Arguments are:
1271 #   transformed name of object being built, or empty string if no object
1272 #   name of _LDADD/_LIBADD-type variable to examine
1273 #   boolean (lex_seen) which is true if a lex source file was seen in this
1274 #     object.  valid only for LDADDs, not LIBADDs.  If set, LEXLIB
1275 #     must be in LDADD.
1276 # Returns 1 if LIBOBJS seen, 0 otherwise.
1277 sub handle_lib_objects
1279     local ($xname, $var, $lex_seen) = @_;
1280     local ($ret);
1282     die "automake: programming error 1 in handle_lib_objects\n"
1283         if ! &variable_defined ($var);
1285     die "automake: programming error 2 in handle_lib_objects\n"
1286         if $lex_seen && $var =~ /LIBADD/;
1288     local (@conds) = &variable_conditions ($var);
1289     if (! @conds)
1290     {
1291         $ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
1292     }
1293     else
1294     {
1295         local ($cond);
1296         $ret = 0;
1297         foreach $cond (@conds)
1298         {
1299             if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
1300             {
1301                 $ret = 1;
1302             }
1303         }
1304     }
1306     return $ret;
1309 # Subroutine of handle_lib_objects: handle a particular condition.
1310 sub handle_lib_objects_cond
1312     local ($xname, $var, $lex_seen, $cond) = @_;
1314     # We recognize certain things that are commonly put in LIBADD or
1315     # LDADD.
1316     local ($lsearch);
1317     local (@dep_list) = ();
1319     # If no lex source seen, just assume this is ok.
1320     local ($lex_ok) = $lex_seen ? 0 : 1;
1322     local ($seen_libobjs) = 0;
1323     local ($flagvar) = 0;
1325     foreach $lsearch (&variable_value_as_list ($var, $cond))
1326     {
1327         # Skip -lfoo and -Ldir; these are explicitly allowed.
1328         next if $lsearch =~ /^-[lL]/;
1329         if (! $flagvar && $lsearch =~ /^-/)
1330         {
1331             if ($var =~ /^(.*)LDADD$/)
1332             {
1333                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1334             }
1335             else
1336             {
1337                 # Only get this error once.
1338                 $flagvar = 1;
1339                 &am_line_error ($var, "you cannot use linker flags such as \`$lsearch' in \`$var'");
1340             }
1341         }
1343         # Assume we have a file of some sort, and push it onto the
1344         # dependency list.  Autoconf substitutions are not pushed;
1345         # rarely is a new dependency substituted into (eg) foo_LDADD
1346         # -- but "bad things (eg -lX11) are routinely substituted.
1347         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1348         # and handled specially below.
1349         push (@dep_list, $lsearch)
1350             unless $lsearch =~ /^\@.*\@$/;
1352         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1353         # means adding entries to dep_files.
1354         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1355         {
1356             push (@dep_list, $lsearch);
1357             $seen_libobjs = 1;
1358             if (! keys %libsources)
1359             {
1360                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
1361             }
1363             local ($iter, $rewrite);
1364             foreach $iter (keys %libsources)
1365             {
1366                 if ($iter =~ /\.[cly]$/)
1367                 {
1368                     $seen_c_source = $var;
1369                 }
1371                 if ($iter =~ /\.h$/)
1372                 {
1373                     &require_file_with_line ($var, $FOREIGN, $iter);
1374                 }
1375                 elsif ($iter ne 'alloca.c')
1376                 {
1377                     ($rewrite = $iter) =~ s/\.c$/.P/;
1378                     $dep_files{'.deps/' . $rewrite} = 1;
1379                     &require_file_with_line ($var, $FOREIGN, $iter);
1380                 }
1381             }
1382         }
1383         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1384         {
1385             push (@dep_list, $lsearch);
1386             &am_line_error ($var,
1387                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
1388                 if ! defined $libsources{'alloca.c'};
1389             $dep_files{'.deps/alloca.P'} = 1;
1390             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1391             $seen_c_source = $var;
1392         }
1393         elsif ($lsearch eq '@LEXLIB@')
1394         {
1395             # FIXME: variable_value_as_list requires us to force
1396             # @LEXLIB@ here, where we'd really prefer $(LEXLIB).
1397             # Nasty -- this will have to wait until many cleanups are
1398             # made, I think.
1399             $lex_ok = 1;
1400         }
1401     }
1403     if (! $lex_ok)
1404     {
1405         &am_line_error ($var, 'lex source file used without @LEXLIB@');
1406     }
1408     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
1409     {
1410         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
1411     }
1413     return $seen_libobjs;
1416 # Canonicalize a name, and check to make sure the non-canonical name
1417 # is never used.  Returns canonical name.  Arguments are name and a
1418 # list of suffixes to check for.
1419 sub check_canonical_spelling
1421     local ($name, @suffixes) = @_;
1422     local ($xname, $xt);
1424     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
1425     if ($xname ne $name)
1426     {
1427         local ($xt);
1428         foreach $xt (@suffixes)
1429         {
1430             &am_line_error ($name . $xt,
1431                             "invalid variable \`" . $name . $xt
1432                             . "'; should be \`" . $xname . $xt . "'")
1433                 if &variable_defined ($name . $xt);
1434         }
1435     }
1437     return $xname;
1440 # Handle C programs.
1441 sub handle_programs
1443     local (@proglist) = &am_install_var ('-clean',
1444                                          'progs', 'PROGRAMS',
1445                                          'bin', 'sbin', 'libexec', 'pkglib',
1446                                          'noinst', 'check');
1447     return if ! @proglist;
1449     # If a program is installed, this is required.  We only want this
1450     # error to appear once.
1451     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1452         unless $seen_arg_prog;
1453     $seen_arg_prog = 1;
1455     local ($one_file, $xname, $munge);
1457     local ($seen_libobjs) = 0;
1458     foreach $one_file (@proglist)
1459     {
1460         local ($obj) = &get_object_extension ($one_file);
1462         # Canonicalize names and check for misspellings.
1463         $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
1464                                             '_SOURCES', '_OBJECTS',
1465                                             '_DEPENDENCIES');
1467         # FIXME: Using a trick to figure out if any lex sources appear
1468         # in our program; should use some cleaner method.
1469         local ($lex_num) = scalar (keys %lex_sources);
1470         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1471         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1473         local ($xt) = '';
1474         if (&variable_defined ($xname . "_LDADD"))
1475         {
1476             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1477                                      $lex_file_seen))
1478             {
1479                 $seen_libobjs = 1;
1480             }
1481             $lex_file_seen = 0;
1482             $xt = '_LDADD';
1483         }
1484         else
1485         {
1486             # User didn't define prog_LDADD override.  So do it.
1487             &define_variable ($xname . '_LDADD', '$(LDADD)');
1489             # This does a bit too much work.  But we need it to
1490             # generate _DEPENDENCIES when appropriate.
1491             if (&variable_defined ('LDADD'))
1492             {
1493                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1494                 {
1495                     $seen_libobjs = 1;
1496                 }
1497                 $lex_file_seen = 0;
1498             }
1499             $xt = '_SOURCES'
1500         }
1502         if (&variable_defined ($xname . '_LIBADD'))
1503         {
1504             &am_line_error ($xname . '_LIBADD',
1505                             "use \`" . $xname . "_LDADD', not \`"
1506                             . $xname . "_LIBADD'");
1507         }
1509         if (! &variable_defined ($xname . '_LDFLAGS'))
1510         {
1511             # Define the prog_LDFLAGS variable.
1512             &define_variable ($xname . '_LDFLAGS', '');
1513         }
1515         if ($lex_file_seen)
1516         {
1517             &am_line_error ($xname . $xt,
1518                             'lex source file used without @LEXLIB@');
1519         }
1521         # Determine program to use for link.
1522         local ($xlink);
1523         if (&variable_defined ($xname . '_LINK'))
1524         {
1525             $xlink = $xname . '_LINK';
1526         }
1527         else
1528         {
1529             $xlink = $linker ? $linker : 'LINK';
1530         }
1532         local ($xexe);
1533         if ($seen_exeext && $one_file !~ /\./)
1534         {
1535             $xexe = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
1536         }
1537         else
1538         {
1539             $xexe = 's/\@EXEEXT\@//g;';
1540         }
1542         $output_rules .=
1543             &file_contents_with_transform
1544                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1545                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1546                  . 's/\@XLINK\@/' . $xlink . '/go;'
1547                  . $xexe,
1548                  'program');
1549     }
1551     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1552     {
1553         $seen_libobjs = 1;
1554     }
1556     if ($seen_libobjs)
1557     {
1558         foreach $one_file (@proglist)
1559         {
1560             # Canonicalize names.
1561             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1563             if (&variable_defined ($xname . '_LDADD'))
1564             {
1565                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1566             }
1567             elsif (&variable_defined ('LDADD'))
1568             {
1569                 &check_libobjs_sources ($xname, 'LDADD');
1570             }
1571         }
1572     }
1576 # Handle libraries.
1577 sub handle_libraries
1579     local (@liblist) = &am_install_var ('-clean',
1580                                         'libs', 'LIBRARIES',
1581                                         'lib', 'pkglib', 'noinst', 'check');
1582     return if ! @liblist;
1584     local (%valid) = &am_primary_prefixes ('LIBRARIES', 'lib', 'pkglib',
1585                                            'noinst', 'check');
1586     if (! defined $configure_vars{'RANLIB'})
1587     {
1588         local ($key);
1589         foreach $key (keys %valid)
1590         {
1591             if (&variable_defined ($key . '_LIBRARIES'))
1592             {
1593                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1594                 # Only get this error once.
1595                 $configure_vars{'RANLIB'} = 1;
1596                 last;
1597             }
1598         }
1599     }
1601     local ($onelib);
1602     local ($munge);
1603     local ($xlib);
1604     local ($seen_libobjs) = 0;
1605     foreach $onelib (@liblist)
1606     {
1607         # Check that the library fits the standard naming convention.
1608         if ($onelib !~ /^lib.*\.a$/)
1609         {
1610             # FIXME this should only be a warning for foreign packages
1611             # FIXME should put line number here.  That means mapping
1612             # from library name back to variable name.
1613             &am_error ("\`$onelib' is not a standard library name");
1614         }
1616         local ($obj) = &get_object_extension ($onelib);
1618         # Canonicalize names and check for misspellings.
1619         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
1620                                            '_OBJECTS', '_DEPENDENCIES');
1622         if (&variable_defined ($xlib . '_LIBADD'))
1623         {
1624             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1625             {
1626                 $seen_libobjs = 1;
1627             }
1628         }
1629         else
1630         {
1631             # Generate support for conditional object inclusion in
1632             # libraries.
1633             &define_variable ($xlib . "_LIBADD", '');
1634         }
1636         if (&variable_defined ($xlib . '_LDADD'))
1637         {
1638             &am_line_error ($xlib . '_LDADD',
1639                             "use \`" . $xlib . "_LIBADD', not \`"
1640                             . $xlib . "_LDADD'");
1641         }
1643         &handle_source_transform ($xlib, $onelib, $obj);
1645         $output_rules .=
1646             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1647                                            . 's/\@XLIBRARY\@/'
1648                                            . $xlib . '/go;',
1649                                            'library');
1650     }
1652     if ($seen_libobjs)
1653     {
1654         foreach $onelib (@liblist)
1655         {
1656             # Canonicalize names.
1657             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1658             if (&variable_defined ($xlib . '_LIBADD'))
1659             {
1660                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1661             }
1662         }
1663     }
1665     &define_variable ('AR', 'ar');
1666     &define_configure_variable ('RANLIB');
1669 # Handle shared libraries.
1670 sub handle_ltlibraries
1672     local (@liblist) = &am_install_var ('-clean',
1673                                         'ltlib', 'LTLIBRARIES',
1674                                         'lib', 'pkglib');
1675     return if ! @liblist;
1677     local (%instdirs);
1678     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 'lib', 'pkglib');
1680     local ($key);
1681     foreach $key (keys %valid)
1682     {
1683         if (&variable_defined ($key . '_LTLIBRARIES'))
1684         {
1685             if (!$seen_libtool)
1686             {
1687                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
1688                 # Only get this error once.
1689                 $configure_vars{'LIBTOOL'} = 1;
1690                 $seen_libtool = 1;
1691             }
1693             # Get the installation directory of each library.
1694             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
1695             {
1696                 if ($instdirs{$_})
1697                 {
1698                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1699                 }
1700                 else
1701                 {
1702                     $instdirs{$_} = $key;
1703                 }
1704             }
1705         }
1706     }
1708     local ($onelib);
1709     local ($munge);
1710     local ($xlib);
1711     local ($seen_libobjs) = 0;
1712     foreach $onelib (@liblist)
1713     {
1714         # Check that the library fits the standard naming convention.
1715         if ($onelib !~ /^lib.*\.la$/)
1716         {
1717             # FIXME this should only be a warning for foreign packages
1718             # FIXME should put line number here.  That means mapping
1719             # from library name back to variable name.
1720             &am_error ("\`$onelib' is not a standard libtool library name");
1721         }
1723         local ($obj) = &get_object_extension ($onelib);
1725         # Canonicalize names and check for misspellings.
1726         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
1727                                            '_SOURCES', '_OBJECTS',
1728                                            '_DEPENDENCIES');
1730         if (! &variable_defined ($xlib . '_LDFLAGS'))
1731         {
1732             # Define the lib_LDFLAGS variable.
1733             &define_variable ($xlib . '_LDFLAGS', '');
1734         }
1736         if (&variable_defined ($xlib . '_LIBADD'))
1737         {
1738             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1739             {
1740                 $seen_libobjs = 1;
1741             }
1742         }
1743         else
1744         {
1745             # Generate support for conditional object inclusion in
1746             # libraries.
1747             &define_variable ($xlib . "_LIBADD", '');
1748         }
1750         if (&variable_defined ($xlib . '_LDADD'))
1751         {
1752             &am_line_error ($xlib . '_LDADD',
1753                             "use \`" . $xlib . "_LIBADD', not \`"
1754                             . $xlib . "_LDADD'");
1755         }
1757         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
1759         # Determine program to use for link.
1760         local ($xlink);
1761         if (&variable_defined ($xlib . '_LINK'))
1762         {
1763             $xlink = $xlib . '_LINK';
1764         }
1765         else
1766         {
1767             $xlink = $linker ? $linker : 'LINK';
1768         }
1770         local ($rpath);
1771         if ($instdirs{$onelib} eq 'EXTRA')
1772         {
1773             # It's an EXTRA_ library, so we can't specify -rpath.
1774             # Yuck.
1775             $rpath = 's/\@RPATH\@//go;';
1776         }
1777         else
1778         {
1779             $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
1780                       . 'dir)/go;');
1781         }
1783         $output_rules .=
1784             &file_contents_with_transform ('s/\@LTLIBRARY\@/'
1785                                            . $onelib . '/go;'
1786                                            . 's/\@XLTLIBRARY\@/'
1787                                            . $xlib . '/go;'
1788                                            . $rpath
1789                                            . 's/\@XLINK\@/' . $xlink . '/go;',
1790                                            'ltlibrary');
1791     }
1793     if ($seen_libobjs)
1794     {
1795         foreach $onelib (@liblist)
1796         {
1797             # Canonicalize names.
1798             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1799             if (&variable_defined ($xlib . '_LIBADD'))
1800             {
1801                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1802             }
1803         }
1804     }
1807 # See if any _SOURCES variable were misspelled.  Also, make sure that
1808 # EXTRA_ variables don't contain configure substitutions.
1809 sub check_typos
1811     local ($varname, $primary);
1812     foreach $varname (keys %contents)
1813     {
1814         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
1815                           '_DEPENDENCIES')
1816         {
1817             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
1818             {
1819                 &am_line_error ($varname,
1820                                 "invalid unused variable name: \`$varname'");
1821             }
1822         }
1823     }
1826 # Handle scripts.
1827 sub handle_scripts
1829     # NOTE we no longer automatically clean SCRIPTS, because it is
1830     # useful to sometimes distribute scripts verbatim.  This happens
1831     # eg in Automake itself.
1832     &am_install_var ('scripts', 'SCRIPTS',
1833                      'bin', 'sbin', 'libexec', 'pkgdata',
1834                      'noinst', 'check');
1836     # Set $scripts_installed if appropriate.  Make sure we only find
1837     # scripts which are actually installed -- this is why we can't
1838     # simply use the return value of am_install_var.
1839     local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
1840                                            'libexec', 'pkgdata',
1841                                            'noinst', 'check');
1842     local ($key);
1843     foreach $key (keys %valid)
1844     {
1845         if ($key ne 'noinst'
1846             && $key ne 'check'
1847             && &variable_defined ($key . '_SCRIPTS'))
1848         {
1849             $scripts_installed = 1;
1850             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
1851         }
1852     }
1854     if ($scripts_installed)
1855     {
1856         # If a program is installed, this is required.  We only want this
1857         # error to appear once.
1858         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1859             unless $seen_arg_prog;
1860         $seen_arg_prog = 1;
1861     }
1864 # Search a file for a "version.texi" Texinfo include.  Return the name
1865 # of the include file if found, or the empty string if not.  A
1866 # "version.texi" file is actually any file whose name matches
1867 # "vers*.texi".
1868 sub scan_texinfo_file
1870     local ($filename) = @_;
1872     if (! open (TEXI, $filename))
1873     {
1874         &am_error ("couldn't open \`$filename': $!");
1875         return '';
1876     }
1877     print "automake: reading $filename\n" if $verbose;
1879     local ($vfile, $outfile);
1880     while (<TEXI>)
1881     {
1882         if (/^\@setfilename +(\S+)/)
1883         {
1884             $outfile = $1;
1885             last if ($vfile);
1886         }
1888         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
1889         {
1890             # Found version.texi include.
1891             $vfile = $1;
1892             last if $outfile;
1893         }
1894     }
1896     close (TEXI);
1897     return ($outfile, $vfile);
1900 # Handle all Texinfo source.
1901 sub handle_texinfo
1903     &am_line_error ('TEXINFOS',
1904                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
1905         if &variable_defined ('TEXINFOS');
1906     return if (! &variable_defined ('info_TEXINFOS')
1907                && ! &variable_defined ('html_TEXINFOS'));
1909     local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');
1911     local (@info_deps_list, @dvis_list, @texi_deps);
1912     local ($infobase, $info_cursor);
1913     local (%versions);
1914     local ($done) = 0;
1915     local ($vti);
1916     local ($tc_cursor, @texi_cleans);
1917     local ($canonical);
1919     foreach $info_cursor (@texis)
1920     {
1921         ($infobase = $info_cursor) =~ s/\.texi(nfo)?$//;
1923         # If 'version.texi' is referenced by input file, then include
1924         # automatic versioning capability.
1925         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
1926                                                         . "/" . $info_cursor);
1928         if ($out_file eq '')
1929         {
1930             &am_error ("\`$info_cursor' missing \@setfilename");
1931             next;
1932         }
1934         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
1935         {
1936             # FIXME should report line number in input file.
1937             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
1938             next;
1939         }
1941         if ($vtexi)
1942         {
1943             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
1944                 if (defined $versions{$vtexi});
1945             $versions{$vtexi} = $info_cursor;
1947             # We number the stamp-vti files.  This is doable since the
1948             # actual names don't matter much.  We only number starting
1949             # with the second one, so that the common case looks nice.
1950             $vti = 'vti' . ($done ? $done : '');
1951             &push_dist_common ($vtexi, 'stamp-' . $vti);
1952             push (@clean, $vti);
1954             # Only require once.
1955             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
1956                                           'mdate-sh')
1957                 if ! $done;
1958             ++$done;
1960             local ($conf_pat);
1961             ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
1962             $output_rules .=
1963                 &file_contents_with_transform
1964                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
1965                      . 's/\@VTI\@/' . $vti . '/g; '
1966                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
1967                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
1968                      'texi-vers');
1970             &push_phony_cleaners ($vti);
1971         }
1973         # If user specified file_TEXINFOS, then use that as explicit
1974         # dependency list.
1975         @texi_deps = ();
1976         push (@texi_deps, $info_cursor);
1977         push (@texi_deps, $vtexi) if $vtexi;
1979         # Canonicalize name first.
1980         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
1981         if (&variable_defined ($canonical . "_TEXINFOS"))
1982         {
1983             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
1984             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
1985         }
1987         $output_rules .= ("\n" . $out_file . ": "
1988                           . join (' ', @texi_deps)
1989                           . "\n" . $infobase . ".dvi: "
1990                           . join (' ', @texi_deps)
1991                           . "\n\n");
1993         push (@info_deps_list, $out_file);
1994         push (@dvis_list, $infobase . '.dvi');
1996         # Generate list of things to clean for this target.  We do
1997         # this explicitly because otherwise too many things could be
1998         # removed.  In particular the ".log" extension might
1999         # reasonably be used in other contexts by the user.
2000         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
2001                             'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
2002                             'vr', 'vrs', 'op', 'tr', 'cv', 'cn')
2003         {
2004             push (@texi_cleans, $infobase . '.' . $tc_cursor);
2005         }
2006     }
2008     # Find these programs wherever they may lie.  Yes, this has
2009     # intimate knowledge of the structure of the texinfo distribution.
2010     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
2011                               'makeinfo',
2012                               # Circumlocution to avoid accidental
2013                               # configure substitution.
2014                               '@MAKE' . 'INFO@');
2015     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
2016                               'texi2dvi');
2018     # Set transform for including texinfos.am.  First, handle --cygnus
2019     # stuff.
2020     local ($xform);
2021     if ($cygnus_mode)
2022     {
2023         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
2024     }
2025     else
2026     {
2027         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
2028     }
2030     # Handle location of texinfo.tex.
2031     local ($need_texi_file) = 0;
2032     if ($cygnus_mode)
2033     {
2034         &define_variable ('TEXINFO_TEX',
2035                           '$(top_srcdir)/../texinfo/texinfo.tex');
2036     }
2037     elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
2038     {
2039         &define_variable ('TEXINFO_TEX', $config_aux_dir . '/texinfo.tex');
2040     }
2041     elsif (! &variable_defined ('TEXINFO_TEX'))
2042     {
2043         &define_variable ('TEXINFO_TEX', '$(srcdir)/texinfo.tex');
2044         $need_texi_file = 1;
2045     }
2046     local ($xxform) = &dirname (&variable_value ('TEXINFO_TEX'));
2047     $xxform =~ s/(\W)/\\$1/g;
2048     $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';
2050     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
2051     push (@phony, 'install-info-am', 'uninstall-info');
2052     push (@dist_targets, 'dist-info');
2054     # How to clean.  The funny name is due to --cygnus influence; in
2055     # Cygnus mode, `clean-info' is a target that users can use.
2056     $output_rules .= "\nmostlyclean-aminfo:\n";
2057     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
2058     $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
2059                       . "maintainer-clean-aminfo:\n\t"
2060                       # Eww.  But how else can we find all the output
2061                       # files from makeinfo?
2062                       . 'for i in $(INFO_DEPS); do' . " \\\n"
2063                       . "\t" . '  rm -f $$i;' . " \\\n"
2064                       . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
2065                       . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
2066                       . "\t" . '  fi;' . " \\\n"
2067                       . "\tdone\n");
2068     &push_phony_cleaners ('aminfo');
2069     if ($cygnus_mode)
2070     {
2071         $output_rules .= "clean-info: mostlyclean-aminfo\n";
2072     }
2074     push (@suffixes, '.texi', '.texinfo', '.info', '.dvi', '.ps');
2076     if (! defined $options{'no-installinfo'})
2077     {
2078         push (@uninstall, 'uninstall-info');
2079         push (@installdirs, '$(infodir)');
2080         unshift (@install_data, 'install-info-am');
2082         # Make sure documentation is made and installed first.  Use
2083         # $(INFO_DEPS), not 'info', because otherwise recursive makes
2084         # get run twice during "make all".
2085         unshift (@all, '$(INFO_DEPS)');
2086     }
2087     push (@clean, 'aminfo');
2088     push (@info, '$(INFO_DEPS)');
2089     push (@dvi, '$(DVIS)');
2091     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2092     &define_variable ("DVIS", join (' ', @dvis_list));
2093     # This next isn't strictly needed now -- the places that look here
2094     # could easily be changed to look in info_TEXINFOS.  But this is
2095     # probably better, in case noinst_TEXINFOS is ever supported.
2096     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
2098     # Do some error checking.  Note that this file is not required
2099     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2100     # up above.
2101     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
2102         if $need_texi_file || ! defined $options{'no-texinfo.tex'};
2105 # Handle any man pages.
2106 sub handle_man_pages
2108     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
2109         if &variable_defined ('MANS');
2110     return if ! &variable_defined ('man_MANS');
2112     # We generate the manpage install code by hand to avoid the use of
2113     # basename in the generated Makefile.
2114     local (@mans) = &variable_value_as_list ('man_MANS', 'all');
2115     local (%sections, %inames, %mbases, %secmap, %fullsecmap);
2116     local ($i) = 1;
2117     foreach (@mans)
2118     {
2119         # FIXME: statement without effect:
2120         /^(.*)\.([0-9])([a-z]*)$/;
2121         $sections{$2} = 1;
2122         $inames{$i} = $_;
2123         $mbases{$i} = $1;
2124         $secmap{$i} = $2;
2125         $fullsecmap{$i} = $2 . $3;
2126         $i++;
2127     }
2129     # We don't really need this, but we use it in case we ever want to
2130     # support noinst_MANS.
2131     &define_variable ("MANS", &variable_value ('man_MANS'));
2133     # Generate list of install dirs.
2134     $output_rules .= "install-man: \$(MANS)\n";
2135     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
2136     # Sort keys so that output is deterministic.
2137     foreach (sort keys %sections)
2138     {
2139         push (@installdirs, '$(mandir)/man' . $_)
2140             unless defined $options{'no-installman'};
2141         $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
2142                           . $_ . "\n");
2143     }
2144     push (@phony, 'install-man');
2146     # Generate install target.
2147     local ($key);
2148     foreach $key (sort keys %inames)
2149     {
2150         $_ = $install_man_format;
2151         s/\@SECTION\@/$secmap{$key}/g;
2152         s/\@MAN\@/$inames{$key}/g;
2153         s/\@FULLSECT\@/$fullsecmap{$key}/g;
2154         s/\@MANBASE\@/$mbases{$key}/g;
2155         $output_rules .= $_;
2156     }
2157     $output_rules .= "\n";
2159     $output_rules .= "uninstall-man:\n\t\$(NORMAL_UNINSTALL)\n";
2160     foreach $key (sort keys %inames)
2161     {
2162         $_ = $uninstall_man_format;
2163         s/\@SECTION\@/$secmap{$key}/g;
2164         s/\@MAN\@/$inames{$key}/g;
2165         s/\@FULLSECT\@/$fullsecmap{$key}/g;
2166         s/\@MANBASE\@/$mbases{$key}/g;
2167         $output_rules .= $_;
2168     }
2169     $output_rules .= "\n";
2170     push (@phony, 'uninstall-man');
2172     $output_vars .= &file_contents ('mans-vars');
2174     if (! defined $options{'no-installman'})
2175     {
2176         push (@install_data, 'install-man');
2177         push (@uninstall, 'uninstall-man');
2178         push (@all, '$(MANS)');
2179     }
2182 # Handle DATA variables.
2183 sub handle_data
2185     &am_install_var ('data', 'DATA', 'data', 'sysconf',
2186                      'sharedstate', 'localstate', 'pkgdata',
2187                      'noinst', 'check');
2190 # Handle TAGS.
2191 sub handle_tags
2193     push (@phony, 'tags');
2194     local (@tag_deps) = ();
2195     if (&variable_defined ('SUBDIRS'))
2196     {
2197         $output_rules .= ("tags-recursive:\n"
2198                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
2199                           # Never fail here if a subdir fails; it
2200                           # isn't important.
2201                           . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
2202                           . "\tdone\n");
2203         push (@tag_deps, 'tags-recursive');
2204         push (@phony, 'tags-recursive');
2205     }
2207     if ($dir_holds_sources
2208         || $dir_holds_headers
2209         || &variable_defined ('ETAGS_ARGS')
2210         || @tag_deps)
2211     {
2212         local ($xform) = '';
2213         local ($one_hdr);
2214         foreach $one_hdr (@config_headers)
2215         {
2216             if ($relative_dir eq &dirname ($one_hdr))
2217             {
2218                 # The config header is in this directory.  So require it.
2219                 local ($var);
2220                 ($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
2221                 $xform .= ' ' if $xform;
2222                 $xform .= $var;
2223             }
2224         }
2225         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
2226                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
2228         if (&variable_defined ('SUBDIRS'))
2229         {
2230             $xform .= 's/^SUBDIRS//;';
2231         }
2232         else
2233         {
2234             $xform .= 's/^SUBDIRS.*$//;';
2235         }
2237         $output_rules .= &file_contents_with_transform ($xform, 'tags');
2238         $output_rules .= &file_contents ('tags-clean');
2239         push (@clean, 'tags');
2240         &push_phony_cleaners ('tags');
2241         &examine_variable ('TAGS_DEPENDENCIES');
2242     }
2243     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2244     {
2245         &am_line_error ('TAGS_DEPENDENCIES',
2246                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2247     }
2248     else
2249     {
2250         # Every Makefile must define some sort of TAGS rule.
2251         # Otherwise, it would be possible for a top-level "make TAGS"
2252         # to fail because some subdirectory failed.
2253         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2254     }
2257 # Worker for handle_dist.
2258 sub handle_dist_worker
2260     local ($makefile) = @_;
2262     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
2264     # Initialization; only at top level.
2265     if ($relative_dir eq '.')
2266     {
2267         if ($strictness >= $GNITS)
2268         {
2269             # For Gnits users, this is pretty handy.  Look at 15 lines
2270             # in case some explanatory text is desirable.
2271             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
2272           echo "NEWS not updated; not releasing" 1>&2; \\
2273           exit 1; \\
2274         fi
2276         }
2279         # Create dist directory.
2280         $output_rules .= ("\trm -rf \$(distdir)\n"
2281                           . "\tmkdir \$(distdir)\n"
2282                           . "\t-chmod 777 \$(distdir)\n");
2283     }
2285     # Only run automake in `dist' target if --include-deps and
2286     # `no-dependencies' not specified.  That way the recipient of a
2287     # distribution can run "make dist" and not need Automake.  You
2288     # might be wondering why we run automake once for each directory
2289     # we distribute, instead of running it once at the top level.  The
2290     # answer is that we want to run automake after the dependencies
2291     # have been generated.  This occurs when "make" is run in the
2292     # subdir.  So automake must be run after make has updated the
2293     # Makefile, which means that it must run once per directory.
2294     if ($use_dependencies)
2295     {
2296         $output_rules .=
2297             (
2298              # We need an absolute path for --output-dir.  Thus the
2299              # weirdness.
2300              "\t" . 'here=`cd $(top_builddir) && pwd`; ' . "\\\n"
2301              . "\t" . 'top_distdir=`cd $(top_distdir) && pwd`; ' . "\\\n"
2302              . "\tcd \$(top_srcdir) \\\n"
2303              . "\t  && \$(AUTOMAKE) --include-deps --build-dir=\$\$here --srcdir-name=\$(top_srcdir) --output-dir=\$\$top_distdir "
2304              # Set strictness of output.
2305              . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2306              . ($cmdline_use_dependencies ? '' : ' --include-deps')
2307              . " " . $makefile . "\n"
2308              );
2309     }
2311     # Scan EXTRA_DIST to see if we need to distribute anything from a
2312     # subdir.  If so, add it to the list.  I didn't want to do this
2313     # originally, but there were so many requests that I finally
2314     # relented.
2315     local (@dist_dirs);
2316     if (&variable_defined ('EXTRA_DIST'))
2317     {
2318         # FIXME: This should be fixed to work with conditionals.  That
2319         # will require only making the entries in @dist_dirs under the
2320         # appropriate condition.  This is meaningful if the nature of
2321         # the distribution should depend upon the configure options
2322         # used.
2323         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
2324         {
2325             next if /^\@.*\@$/;
2326             next unless s,/+[^/]+$,,;
2327             push (@dist_dirs, $_)
2328                 unless $_ eq '.';
2329         }
2330     }
2331     if (@dist_dirs)
2332     {
2333         # Prepend $(distdir) to each directory given.  Doing it via a
2334         # hash lets us ensure that each directory is used only once.
2335         local (%dhash);
2336         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
2337         $output_rules .= "\t";
2338         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
2339     }
2341     # In loop, test for file existence because sometimes a file gets
2342     # included in DISTFILES twice.  For example this happens when a
2343     # single source file is used in building more than one program.
2344     # Also, there are situations in which "ln" can fail.  For instance
2345     # a file to distribute could actually be a cross-filesystem
2346     # symlink -- this can easily happen if "gettextize" was run on the
2347     # distribution.
2348     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
2349     if ($cygnus_mode)
2350     {
2351         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
2352     }
2353     else
2354     {
2355         $output_rules .= "\t  d=\$(srcdir); \\\n";
2356     }
2357     $output_rules .= '    test -f $(distdir)/$$file \\
2358           || ln $$d/$$file $(distdir)/$$file 2> /dev/null \\
2359           || cp -p $$d/$$file $(distdir)/$$file; \\
2360         done
2363     # If we have SUBDIRS, create all dist subdirectories and do
2364     # recursive build.
2365     if (&variable_defined ('SUBDIRS'))
2366     {
2367         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
2368         # to all possible directories, and use it.
2369         if (! &variable_conditions ('SUBDIRS'))
2370         {
2371             $dist_subdir_name = 'SUBDIRS';
2372         }
2373         else
2374         {
2375             $dist_subdir_name = 'DIST_SUBDIRS';
2376             if (! &variable_defined ('DIST_SUBDIRS'))
2377             {
2378                 &define_pretty_variable ('DIST_SUBDIRS', '',
2379                                          &variable_value_as_list ('SUBDIRS',
2380                                                                   'all'));
2381             }
2382         }
2384         # Test for directory existence here because previous automake
2385         # invocation might have created some directories.  Note that
2386         # we explicitly set distdir for the subdir make; that lets us
2387         # mix-n-match many automake-using packages into one large
2388         # package, and have "dist" at the top level do the right
2389         # thing.
2390         $output_rules .= '      for subdir in $(' . $dist_subdir_name . '); do          \\
2391           test -d $(distdir)/$$subdir           \\
2392           || mkdir $(distdir)/$$subdir          \\
2393           || exit 1;                            \\
2394           chmod 777 $(distdir)/$$subdir;        \\
2395           (cd $$subdir && $(MAKE) top_distdir=../$(top_distdir) distdir=../$(distdir)/$$subdir distdir) \\
2396             || exit 1; \\
2397         done
2399     }
2401     # If the target `dist-hook' exists, make sure it is run.  This
2402     # allows users to do random weird things to the distribution
2403     # before it is packaged up.
2404     push (@dist_targets, 'dist-hook') if defined $contents{'dist-hook'};
2406     local ($targ);
2407     foreach $targ (@dist_targets)
2408     {
2409         # We must explicitly set distdir and top_distdir for these
2410         # sub-makes.
2411         $output_rules .= "\t\$(MAKE) top_distdir=\"\$(top_distdir)\" distdir=\"\$(distdir)\" $targ\n";
2412     }
2414     push (@phony, 'distdir');
2417 # Handle 'dist' target.
2418 sub handle_dist
2420     local ($makefile) = @_;
2422     # Set up maint_charset.
2423     $local_maint_charset = &variable_value ('MAINT_CHARSET')
2424         if &variable_defined ('MAINT_CHARSET');
2425     $maint_charset = $local_maint_charset
2426         if $relative_dir eq '.';
2428     if (&variable_defined ('DIST_CHARSET'))
2429     {
2430         &am_line_error ('DIST_CHARSET',
2431                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2432             if ! $local_maint_charset;
2433         if ($relative_dir eq '.')
2434         {
2435             $dist_charset = &variable_value ('DIST_CHARSET')
2436         }
2437         else
2438         {
2439             &am_line_error ('DIST_CHARSET',
2440                             "DIST_CHARSET can only be defined at top level");
2441         }
2442     }
2444     # Look for common files that should be included in distribution.
2445     local ($cfile);
2446     foreach $cfile (@common_files)
2447     {
2448         if (-f ($relative_dir . "/" . $cfile))
2449         {
2450             &push_dist_common ($cfile);
2451         }
2452     }
2454     # Keys of %dist_common are names of files to distributed.  We put
2455     # README first because it then becomes easier to make a
2456     # Usenet-compliant shar file (in these, README must be first).
2457     # FIXME: do more ordering of files here.
2458     local (@coms);
2459     if (defined $dist_common{'README'})
2460     {
2461         push (@coms, 'README');
2462         delete $dist_common{'README'};
2463     }
2464     push (@coms, sort keys %dist_common);
2466     &define_pretty_variable ("DIST_COMMON", '', @coms);
2467     $output_vars .= "\n";
2469     # Some boilerplate.
2470     $output_vars .= &file_contents ('dist-vars') . "\n";
2471     &define_variable ('TAR', $TAR);
2472     &define_variable ('GZIP', '--best');
2474     # Put these things in rules section so it is easier for whoever
2475     # reads Makefile.in.
2476     if (! &variable_defined ('distdir'))
2477     {
2478         if ($relative_dir eq '.')
2479         {
2480             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2481         }
2482         else
2483         {
2484             $output_rules .= ("\n"
2485                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2486                               . "\n");
2487         }
2488     }
2489     if ($relative_dir eq '.')
2490     {
2491         $output_rules .= "top_distdir = \$(distdir)\n\n";
2492     }
2493     else
2494     {
2495         $output_rules .= "\nsubdir = " . $relative_dir . "\n\n";
2496     }
2498     # Generate 'dist' target, and maybe dist-shar / dist-zip / dist-tarZ.
2499     if ($relative_dir eq '.')
2500     {
2501         # Rule to check whether a distribution is viable.
2502         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
2503 # it guarantees that the distribution is self-contained by making another
2504 # tarfile.
2505 distcheck: dist
2506         rm -rf $(distdir)
2507         GZIP=$(GZIP) $(TAR) zxf $(distdir).tar.gz
2508         mkdir $(distdir)/=build
2509         mkdir $(distdir)/=inst
2510         dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
2511                           . (defined $contents{'distcheck-hook'}
2512                              ? "\t\$(MAKE) distcheck-hook"
2513                              : '')
2514                           . '
2515         cd $(distdir)/=build \\
2516           && ../configure '
2518                           . ($seen_gettext ? '--with-included-gettext ' : '')
2519                           . '--srcdir=.. --prefix=$$dc_install_base \\
2520           && $(MAKE) \\
2521           && $(MAKE) dvi \\
2522           && $(MAKE) check \\
2523           && $(MAKE) install \\
2524           && $(MAKE) installcheck \\
2525           && $(MAKE) dist
2526         rm -rf $(distdir)
2527         @echo "========================"; \\
2528         echo "$(distdir).tar.gz is ready for distribution"; \\
2529         echo "========================"
2532         local ($dist_all) = ('dist-all: distdir' . "\n"
2533                              . $dist_header);
2534         local ($curs);
2535         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ')
2536         {
2537             if (defined $options{$curs} || $curs eq 'dist')
2538             {
2539                 $output_rules .= ($curs . ': distdir' . "\n"
2540                                   . $dist_header
2541                                   . $dist{$curs}
2542                                   . $dist_trailer);
2543                 $dist_all .= $dist{$curs};
2544             }
2545         }
2546         $output_rules .= $dist_all . $dist_trailer;
2547     }
2549     # Generate distdir target.
2550     &handle_dist_worker ($makefile);
2553 # Scan a single dependency file and rewrite the dependencies as
2554 # appropriate.  Essentially this means:
2555 # * Clean out absolute dependencies which are not desirable.
2556 # * Rewrite other dependencies to be relative to $(top_srcdir).
2557 sub scan_dependency_file
2559     local ($depfile) = @_;
2561     if (! open (DEP_FILE, $depfile))
2562     {
2563         &am_error ("couldn't open \`$depfile': $!");
2564         return;
2565     }
2566     print "automake: reading $depfile\n" if $verbose;
2568     # Sometimes it is necessary to omit some dependencies.
2569     local (%omit) = %omit_dependencies;
2570     if (&variable_defined ('OMIT_DEPENDENCIES'))
2571     {
2572         # FIXME: Doesn't work with conditionals.  I'm not sure if this
2573         # matters.
2574         grep ($omit{$_} = 1,
2575               &variable_value_as_list ('OMIT_DEPENDENCIES', ''));
2576     }
2578     local ($first_line) = 1;
2579     local ($last_line) = 0;
2580     local ($target, @dependencies);
2581     local ($one_dep, $xform);
2582     local ($just_file);
2584     local ($srcdir_rx, $fixup_rx);
2585     ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
2586         =~ s/(\W)/\\$1/g;
2587     ($srcdir_rx = $srcdir_name . '/') =~ s/(\W)/\\$1/g;
2589     local ($rewrite_builddir) = (($top_builddir eq '.')
2590                                  ? ''
2591                                  : $top_builddir . '/');
2593     while (<DEP_FILE>)
2594     {
2595         if ($last_line)
2596         {
2597             # If LAST_LINE set then we've already seen what we thought
2598             # was the last line.
2599             goto bad_format;
2600         }
2601         next if (/$WHITE_PATTERN/o);
2602         chop;
2603         if (! s/\\$//)
2604         {
2605             # No trailing "\" means this should be the last line.
2606             $last_line = 1;
2607         }
2609         if ($first_line)
2610         {
2611             if (! /^([^:]+:)(.+)$/)
2612             {
2613               bad_format:
2614                 &am_error ("\`$depfile' has incorrect format");
2615                 close (DEP_FILE);
2616                 return;
2617             }
2619             $_ = $2;
2620             # Make sure to strip the .P file from the target.
2621             ($target = $1) =~ s, *\.deps/[^.]+\.P,,;
2623             $first_line = 0;
2624         }
2626         foreach $one_dep (split (' ', $_))
2627         {
2628             ($just_file = $one_dep) =~ s,^.*/,,;
2629             next if defined $omit{$just_file};
2631             if ($one_dep =~ /^$fixup_rx/)
2632             {
2633                 # The dependency points to the current directory in
2634                 # some way.
2635                 ($xform = $one_dep) =~ s/^$fixup_rx//;
2636                 push (@dependencies, $xform);
2637             }
2638             elsif ($one_dep =~ /^$srcdir_rx/)
2639             {
2640                 # The dependency is in some other directory in the package.
2641                 ($xform = $one_dep) =~ s/^$srcdir_rx/$rewrite_builddir/;
2642                 push (@dependencies, $xform);
2643             }
2644             elsif ($one_dep =~ /^\//)
2645             {
2646                 # Absolute path; ignore.
2647             }
2648             else
2649             {
2650                 # Anything else is assumed to be correct.
2651                 push (@dependencies, $one_dep);
2652             }
2653         }
2654     }
2656     &pretty_print_rule ($target, "\t", @dependencies);
2658     close (DEP_FILE);
2661 # Handle auto-dependency code.
2662 sub handle_dependencies
2664     # Make sure this variable is always marked as used.
2665     &examine_variable ('OMIT_DEPENDENCIES');
2667     if ($use_dependencies)
2668     {
2669         # Include GNU-make-specific auto-dep code.  Don't include it
2670         # if DEP_FILES would be empty.
2671         if ($dir_holds_sources && keys %dep_files)
2672         {
2673             &define_pretty_variable ('DEP_FILES', '', sort keys %dep_files);
2674             $output_rules .= &file_contents ('depend');
2675             push (@clean, 'depend');
2676             &push_phony_cleaners ('depend');
2677             $output_rules .=
2678                 &file_contents_with_transform ('s/\@EXT\@/.c/g;'
2679                                                . 's/\@MKDEP\@/MKDEP/g;'
2680                                                . 's/^ONLYC//g;',
2681                                                'depend2');
2682             local ($ext);
2683             local ($need_cxx) = 0;
2684             foreach $ext (sort keys %cxx_extensions)
2685             {
2686                 $output_rules .=
2687                     &file_contents_with_transform ('s/\@EXT\@/' . $ext .'/g;'
2688                                                    . 's/\@MKDEP\@/CXXMKDEP/g;'
2689                                                    . 's/^ONLYC.*$//;',
2690                                                    'depend2');
2691                 $need_cxx = 1;
2692             }
2693             if ($need_cxx)
2694             {
2695                 &define_variable ('CXXMKDEP', '$(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
2696             }
2697         }
2698     }
2699     elsif ($build_directory ne '')
2700     {
2701         # Include any auto-generated deps that are present.  Note that
2702         # $build_directory ends in a "/".
2703         if (-d ($build_directory . $relative_dir . "/.deps")
2704             && -f ($build_directory . $relative_dir . "/.deps/.P"))
2705         {
2706             local ($depfile);
2708             foreach $depfile (&my_glob ($build_directory
2709                                         . $relative_dir . "/.deps/*.P"))
2710             {
2711                 &scan_dependency_file ($depfile);
2712             }
2714             $output_rules .= "\n";
2715         }
2716     }
2719 # Handle subdirectories.
2720 sub handle_subdirs
2722     return if ! &variable_defined ('SUBDIRS');
2724     # Make sure each directory mentioned in SUBDIRS actually exists.
2725     local ($dir);
2726     foreach $dir (&variable_value_as_list ('SUBDIRS', 'all'))
2727     {
2728         # Skip directories substituted by configure.
2729         next if $dir =~ /^\@.*\@$/;
2731         if (! -d $am_relative_dir . '/' . $dir)
2732         {
2733             &am_line_error ('SUBDIRS',
2734                             "required directory $am_relative_dir/$dir does not exist");
2735             next;
2736         }
2738         &am_line_error ('SUBDIRS', "directory should not contain \`/'")
2739             if $dir =~ /\//;
2740     }
2742     local ($xform) = ('s/\@INSTALLINFO\@/' .
2743                       (defined $options{'no-installinfo'}
2744                        ? 'install-info-recursive'
2745                        : '')
2746                       . '/;');
2747     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
2749     # Push a bunch of phony targets.
2750     local ($phonies);
2751     foreach $phonies ('-data', '-exec', 'dirs')
2752     {
2753         push (@phony, 'install' . $phonies . '-recursive');
2754         push (@phony, 'uninstall' . $phonies . '-recursive');
2755     }
2756     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
2757     {
2758         push (@phony, $phonies . '-recursive');
2759     }
2760     &push_phony_cleaners ('recursive');
2762     push (@check_tests, "check-recursive");
2763     push (@installcheck, "installcheck-recursive");
2764     push (@info, "info-recursive");
2765     push (@dvi, "dvi-recursive");
2767     $recursive_install = 1;
2770 # Handle aclocal.m4.
2771 sub handle_aclocal_m4
2773     local ($regen_aclocal) = 0;
2774     if (-f 'aclocal.m4')
2775     {
2776         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
2777         &push_dist_common ('aclocal.m4');
2779         if (open (ACLOCAL, '< aclocal.m4'))
2780         {
2781             local ($line);
2782             $line = <ACLOCAL>;
2783             close (ACLOCAL);
2785             if ($line =~ 'generated automatically by aclocal')
2786             {
2787                 $regen_aclocal = 1;
2788             }
2789         }
2790     }
2792     local ($acinclude) = 0;
2793     if (-f 'acinclude.m4')
2794     {
2795         $regen_aclocal = 1;
2796         $acinclude = 1;
2797     }
2799     # Note that it might be possible that aclocal.m4 doesn't exist but
2800     # should be auto-generated.  This case probably isn't very
2801     # important.
2802     if ($regen_aclocal)
2803     {
2804         local (@ac_deps) = (
2805                             ($seen_maint_mode ? "\@MAINT\@" : "") ,
2806                             "configure.in",
2807                             ($acinclude ? ' acinclude.m4' : '')
2808                             );
2810         # Scan all -I directories for m4 files.  These are our
2811         # dependencies.
2812         if (&variable_defined ('ACLOCAL_AMFLAGS'))
2813         {
2814             local ($amdir);
2815             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
2816             {
2817                 if ($amdir =~ s/^-I//
2818                     && $amdir !~ /^\//
2819                     && -d $amdir)
2820                 {
2821                     push (@ac_deps, &my_glob ($am_dir . '/*.m4'));
2822                 }
2823             }
2824         }
2826         &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
2828         $output_rules .=  ("\t"
2829                            . 'cd $(srcdir) && $(ACLOCAL)'
2830                            . (&variable_defined ('ACLOCAL_AMFLAGS')
2831                               ? ' $(ACLOCAL_AMFLAGS)' : '')
2832                            . "\n");
2833     }
2836 # Rewrite a list of input files into a form suitable to put on a
2837 # dependency list.  The idea is that if an input file has a directory
2838 # part the same as the current directory, then the directory part is
2839 # simply removed.  But if the directory part is different, then
2840 # $(top_srcdir) is prepended.  Among other things, this is used to
2841 # generate the dependency list for the output files generated by
2842 # AC_OUTPUT.  Consider what the dependencies should look like in this
2843 # case:
2844 #   AC_OUTPUT(src/out:src/in1:lib/in2)
2845 sub rewrite_inputs_into_dependencies
2847     local (@inputs) = @_;
2848     local ($single, @newinputs);
2850     foreach $single (@inputs)
2851     {
2852         if (&dirname ($single) eq $relative_dir)
2853         {
2854             push (@newinputs, &basename ($single));
2855         }
2856         else
2857         {
2858             push (@newinputs, '$(top_srcdir)/' . $single);
2859         }
2860     }
2862     return @newinputs;
2865 # Handle remaking and configure stuff.
2866 # We need the name of the input file, to do proper remaking rules.
2867 sub handle_configure
2869     local ($local, $input, @secondary_inputs) = @_;
2871     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
2872     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
2873         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
2875     local ($top_reldir);
2877     local ($input_base) = &basename ($input);
2878     local ($local_base) = &basename ($local);
2880     local ($amfile) = $input_base . '.am';
2881     # We know we can always add '.in' because it really should be an
2882     # error if the .in was missing originally.
2883     local ($infile) = '$(srcdir)/' . $input_base . '.in';
2884     local ($colon_infile);
2885     if ($local ne $input)
2886     {
2887         $colon_infile = ':' . $input . '.in';
2888     }
2889     $colon_infile .= ':' . join (':', @secondary_inputs)
2890         if @secondary_inputs;
2892     local (@rewritten) = &rewrite_inputs_into_dependencies (@secondary_inputs);
2893     # This rule remakes the Makefile.in.  Note use of @MAINT@ forces
2894     # us to abandon pretty-printing.  Sigh.
2895     $output_rules .= ($infile
2896                       # NOTE perl 5.003 (with -w) gives a
2897                       # uninitialized value error on the next line.
2898                       # Don't know why.
2899                       . ': '
2900                       . ($seen_maint_mode ? '@MAINT@ ' : '')
2901                       . $amfile . ' '
2902                       . '$(top_srcdir)/configure.in $(ACLOCAL_M4) '
2903                       . join (' ', @rewritten) . "\n"
2904                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
2905                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2906                       . ($cmdline_use_dependencies ? '' : ' --include-deps')
2907                       . ' ' . $input . $colon_infile . "\n\n");
2909     # This rule remakes the Makefile.
2910     $output_rules .= ($local_base
2911                       # NOTE: bogus uninit value error on next line;
2912                       # see comment above.
2913                       . ': '
2914                       . $infile . ' '
2915                       . '$(top_builddir)/config.status'
2916                       # NOTE: Makefile only depends on BUILT_SOURCES
2917                       # when dependencies are being computed.  This is
2918                       # a workaround for an obscure bug with
2919                       # AC_LINK_FILES.  Anyway, when dependencies are
2920                       # turned off, this shouldn't matter.
2921                       . ($use_dependencies ? ' $(BUILT_SOURCES)' : '')
2922                       . "\n"
2923                       . "\tcd \$(top_builddir) \\\n"
2924                       . "\t  && CONFIG_FILES="
2925                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
2926                       . $colon_infile
2927                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
2928                       . "\n\n");
2930     if ($relative_dir ne '.')
2931     {
2932         # In subdirectory.
2933         $top_reldir = '../';
2934     }
2935     else
2936     {
2937         &handle_aclocal_m4;
2938         $output_rules .= &file_contents ('remake');
2939         &examine_variable ('CONFIGURE_DEPENDENCIES');
2940         $top_reldir = '';
2941     }
2943     # If we have a configure header, require it.
2944     local ($one_hdr);
2945     local (@local_fullnames) = @config_fullnames;
2946     local (@local_names) = @config_names;
2947     local ($hdr_index) = 0;
2948     local ($distclean_config) = '';
2949     foreach $one_hdr (@config_headers)
2950     {
2951         local ($one_fullname) = shift (@local_fullnames);
2952         local ($one_name) = shift (@local_names);
2953         $hdr_index += 1;
2954         if ($relative_dir eq &dirname ($one_hdr))
2955         {
2956             local ($ch_sans_dir) = &basename ($one_hdr);
2957             local ($cn_sans_dir) = &basename ($one_name);
2959             &require_file_with_conf_line ($config_header_line,
2960                                           $FOREIGN, $ch_sans_dir);
2962             # Header defined and in this directory.
2963             local (@files);
2964             if (-f $relative_dir . '/acconfig.h')
2965             {
2966                 push (@files, 'acconfig.h');
2967             }
2968             if (-f $one_name . '.top')
2969             {
2970                 push (@files, "${cn_sans_dir}.top");
2971             }
2972             if (-f $one_name . '.bot')
2973             {
2974                 push (@files, "${cn_sans_dir}.bot");
2975             }
2977             &push_dist_common (@files);
2979             local ($stamp_name) = 'stamp-h';
2980             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
2982             local ($xform) = '';
2984             $xform = 's,\@FILES\@,' . join (' ', @files) . ',;';
2985             $xform .= 's,\@CONFIG_HEADER\@,' . "${cn_sans_dir}" . ',;';
2986             $xform .= 's,\@CONFIG_HEADER_IN\@,' . "${ch_sans_dir}" . ',;';
2987             $xform .= 's,\@CONFIG_HEADER_FULL\@,' . "${one_fullname}" . ',;';
2988             $xform .= 's,\@STAMP\@,' . "${stamp_name}" . ',;';
2990             $output_rules .= &file_contents_with_transform ($xform,
2991                                                             'remake-hdr');
2993             &touch ($relative_dir . "/${stamp_name}.in");
2994             &require_file_with_conf_line ($config_header_line, $FOREIGN,
2995                                           "${stamp_name}.in");
2997             $distclean_config .= ' ' if $distclean_config;
2998             $distclean_config .= $cn_sans_dir;
2999         }
3000     }
3002     if ($distclean_config)
3003     {
3004         $output_rules .= &file_contents_with_transform ('s,\@FILES\@,'
3005                                                         . $distclean_config
3006                                                         . ',;',
3007                                                         'clean-hdr');
3008         push (@clean, 'hdr');
3009         &push_phony_cleaners ('hdr');
3010     }
3012     # Set location of mkinstalldirs.
3013     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
3014     {
3015         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
3016                                             . '/mkinstalldirs'));
3017     }
3018     else
3019     {
3020         &define_variable ('mkinstalldirs',
3021                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
3022     }
3024     &am_line_error ('CONFIG_HEADER',
3025                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
3026         if &variable_defined ('CONFIG_HEADER');
3028     local ($one_name);
3029     local ($config_header) = '';
3030     foreach $one_name (@config_names)
3031     {
3032         # Generate CONFIG_HEADER define.
3033         local ($one_hdr);
3034         if ($relative_dir eq &dirname ($one_name))
3035         {
3036             $one_hdr = &basename ($one_name);
3037         }
3038         else
3039         {
3040             $one_hdr = "${top_builddir}/${one_name}";
3041         }
3043         $config_header .= ' ' if $config_header;
3044         $config_header .= $one_hdr;
3045     }
3046     if ($config_header)
3047     {
3048         &define_variable ("CONFIG_HEADER", $config_header);
3049     }
3051     # Now look for other files in this directory which must be remade
3052     # by config.status, and generate rules for them.
3053     local (@actual_other_files) = ();
3054     local ($file, $local);
3055     local (@inputs, @rewritten_inputs, $single);
3056     local ($need_rewritten);
3057     foreach $file (@other_input_files)
3058     {
3059         if ($file =~ /^(.*):(.*)$/)
3060         {
3061             # This is the ":" syntax of AC_OUTPUT.
3062             $file = $1;
3063             $local = &basename ($file);
3064             @inputs = split (':', $2);
3065             @rewritten_inputs = &rewrite_inputs_into_dependencies (@inputs);
3066             $need_rewritten = 1;
3067         }
3068         else
3069         {
3070             # Normal usage.
3071             $local = &basename ($file);
3072             @inputs = ($local . '.in');
3073             @rewritten_inputs =
3074                 &rewrite_inputs_into_dependencies ($file . '.in');
3075             $need_rewritten = 0;
3076         }
3078         # Skip files not in this directory.
3079         next unless &dirname ($file) eq $relative_dir;
3081         # Skip any file that is an automake input.
3082         next if -f $file . '.am';
3084         # Some users have been tempted to put `stamp-h' in the
3085         # AC_OUTPUT line.  This won't do the right thing, so we
3086         # explicitly fail here.
3087         if ($local eq 'stamp-h')
3088         {
3089             # FIXME: allow real filename.
3090             &am_conf_error ('configure.in', $ac_output_line,
3091                             'stamp-h should not appear in AC_OUTPUT');
3092             next;
3093         }
3095         $output_rules .= ($local . ': '
3096                           . '$(top_builddir)/config.status '
3097                           . join (' ', @rewritten_inputs) . "\n"
3098                           . "\t"
3099                           . 'cd $(top_builddir) && CONFIG_FILES='
3100                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3101                           . '$@' . ($need_rewritten
3102                                     ? (':' . join (':', @rewritten_inputs))
3103                                     : '')
3104                           . ' CONFIG_HEADERS= ./config.status'
3105                           . "\n");
3106         push (@actual_other_files, $local);
3108         # Require all input files.
3109         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3110                                       @inputs);
3111     }
3113     # These files get removed by "make clean".
3114     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3117 # Handle C headers.
3118 sub handle_headers
3120     $dir_holds_headers = &am_install_var ('header', 'HEADERS', 'include',
3121                                           'oldinclude', 'pkginclude',
3122                                           'noinst', 'check');
3125 sub handle_gettext
3127     return if ! $seen_gettext || $relative_dir ne '.';
3129     if (! &variable_defined ('SUBDIRS'))
3130     {
3131         &am_conf_error
3132             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
3133         return;
3134     }
3136     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
3137         if $seen_gettext;
3139     if (&variable_defined ('SUBDIRS'))
3140     {
3141         &am_line_error
3142             ('SUBDIRS',
3143              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
3144                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
3145         &am_line_error
3146             ('SUBDIRS',
3147              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
3148                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
3149     }
3151     # Ensure that each language in ALL_LINGUAS has a .po file, and
3152     # each po file is mentioned in ALL_LINGUAS.
3153     if ($seen_linguas)
3154     {
3155         local (%linguas) = ();
3156         grep ($linguas{$_} = 1, split (' ', $all_linguas));
3158         foreach (<po/*.po>)
3159         {
3160             s/^po\///;
3161             s/\.po$//;
3163             &am_line_error ($all_linguas_line,
3164                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
3165                 if ! $linguas{$_};
3166         }
3168         foreach (keys %linguas)
3169         {
3170             &am_line_error ($all_linguas_line,
3171                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
3172                 if ! -f "po/$_.po";
3173         }
3174     }
3175     else
3176     {
3177         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
3178     }
3181 # Handle footer elements.
3182 sub handle_footer
3184     if ($contents{'SOURCES'})
3185     {
3186         # NOTE don't use define_pretty_variable here, because
3187         # $contents{...} is already defined.
3188         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
3189     }
3190     if ($contents{'OBJECTS'})
3191     {
3192         # NOTE don't use define_pretty_variable here, because
3193         # $contents{...} is already defined.
3194         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
3195     }
3196     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
3197     {
3198         $output_vars .= "\n";
3199     }
3201     if (&variable_defined ('SUFFIXES'))
3202     {
3203         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
3204         # make do not like variable substitutions on the .SUFFIXES
3205         # line.
3206         push (@suffixes, &variable_value_as_list ('SUFFIXES', ''));
3207     }
3208     if (&target_defined ('.SUFFIXES'))
3209     {
3210         &am_line_error ('.SUFFIXES',
3211                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
3212     }
3214     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3215     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3216     # anything else, by sticking it right after the default: target.
3217     $output_header .= ".SUFFIXES:\n";
3218     if (@suffixes)
3219     {
3221         # Make sure suffixes has unique elements.  Sort them to ensure
3222         # the output remains consistent.
3223         local (%suffixes);
3225         grep ($suffixes{$_} = 1, @suffixes);
3227         $output_header .= (".SUFFIXES: "
3228                            . join (' ', sort keys %suffixes)
3229                            . "\n");
3230     }
3231     $output_trailer .= &file_contents ('footer');
3234 # Deal with installdirs target.
3235 sub handle_installdirs
3237     # GNU Makefile standards recommend this.
3238     $output_rules .= ("installdirs:"
3239                       . ($recursive_install
3240                          ? " installdirs-recursive\n"
3241                          : "\n"));
3242     push (@phony, 'installdirs');
3243     if (@installdirs)
3244     {
3245         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
3246                             @installdirs);
3247     }
3248     $output_rules .= "\n";
3251 # There are several targets which need to be merged.  This is because
3252 # their complete definition is compiled from many parts.  Note that we
3253 # avoid double colon rules, otherwise we'd use them instead.
3254 sub handle_merge_targets
3256     local ($makefile) = @_;
3258     # There are a few install-related variables that you should not define.
3259     local ($var);
3260     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
3261     {
3262         if (&variable_defined ($var))
3263         {
3264             &am_line_error ($var, "\`$var' should not be defined");
3265         }
3266     }
3268     # Put this at the beginning for the sake of non-GNU makes.  This
3269     # is still wrong if these makes can run parallel jobs.  But it is
3270     # right enough.
3271     unshift (@all, &basename ($makefile));
3273     local ($one_name);
3274     foreach $one_name (@config_names)
3275     {
3276         push (@all, &basename ($one_name))
3277             if &dirname ($one_name) eq $relative_dir;
3278     }
3280     &do_one_merge_target ('info', @info);
3281     &do_one_merge_target ('dvi', @dvi);
3282     &do_check_merge_target;
3283     &do_one_merge_target ('installcheck', @installcheck);
3285     if (defined $options{'no-installinfo'})
3286     {
3287         # FIXME: this is kind of a hack; should find another way to
3288         # know that this is required.
3289         local (@dirs);
3290         if (grep ($_ eq 'install-info-am', @phony))
3291         {
3292             push (@dirs, 'install-info-am');
3293         }
3294         if (&variable_defined ('SUBDIRS'))
3295         {
3296             push (@dirs, 'install-info-recursive');
3297         }
3298         &do_one_merge_target ('install-info', @dirs);
3299     }
3301     # Handle the various install targets specially.  We do this so
3302     # that (eg) "make install-exec" will run "install-exec-recursive"
3303     # if required, but "make install" won't run it twice.  Step one is
3304     # to see if the user specified local versions of any of the
3305     # targets we handle.  "all" is treated as one of these since
3306     # "install" can run it.
3307     push (@install_exec, 'install-exec-local')
3308         if defined $contents{'install-exec-local'};
3309     push (@install_data, 'install-data-local')
3310         if defined $contents{'install-data-local'};
3311     push (@uninstall, 'uninstall-local')
3312         if defined $contents{'uninstall-local'};
3313     local ($utarg);
3314     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3315                     'uninstall-exec-local', 'uninstall-exec-hook')
3316     {
3317         if (defined $contents{$utarg})
3318         {
3319             local ($x);
3320             ($x = $utarg) =~ s/(data|exec)-//;
3321             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3322         }
3323     }
3324     push (@all, 'all-local')
3325         if defined $contents{'all-local'};
3327     if (defined $contents{'install-local'})
3328     {
3329         &am_line_error ('install-local',
3330                         "use \`install-data' or \`install-exec', not \`install'");
3331     }
3333     # Step two: if we are doing recursive makes, write out the
3334     # appropriate rules.
3335     local (@install);
3336     if ($recursive_install)
3337     {
3338         push (@install, 'install-recursive');
3340         if (@all)
3341         {
3342             local (@hackall) = ();
3343             local ($one_name);
3344             local ($local_headers) = '';
3345             foreach $one_name (@config_names)
3346             {
3347                 if (&dirname ($one_name) eq $relative_dir)
3348                 {
3349                     $local_headers .= ' ' if $local_headers;
3350                     $local_headers .= &basename ($one_name);
3351                 }
3352             }
3353             if ($local_headers)
3354             {
3356                 # This is kind of a hack, but I couldn't see a better
3357                 # way to handle it.  In this particular case, we need
3358                 # to make sure config.h is built before we recurse.
3359                 # We can't do this by changing the order of
3360                 # dependencies to the "all" because that breaks when
3361                 # using parallel makes.  Instead we handle things
3362                 # explicitly.
3363                 $output_rules .= ("all-recursive-am: ${local_headers}"
3364                                   . "\n\t" . '$(MAKE) all-recursive'
3365                                   . "\n\n");
3366                 push (@hackall, 'all-recursive-am');
3367                 push (@phony, 'all-recursive-am');
3368             }
3369             else
3370             {
3371                 push (@hackall, 'all-recursive');
3372             }
3374             $output_rules .= ('all-am: '
3375                               . join (' ', @all)
3376                               . "\n\n");
3377             @all = @hackall;
3378             push (@all, 'all-am');
3379             push (@phony, 'all-am');
3380         }
3381         else
3382         {
3383             @all = ('all-recursive');
3385             # Must always generate `all-am' target, so it can be
3386             # referred to elsewhere.
3387             $output_rules .= "all-am:\n";
3388         }
3389         if (@install_exec)
3390         {
3391             $output_rules .= ('install-exec-am: '
3392                               . join (' ', @install_exec)
3393                               . "\n\n");
3394             @install_exec = ('install-exec-recursive', 'install-exec-am');
3395             push (@install, 'install-exec-am');
3396             push (@phony, 'install-exec-am');
3397         }
3398         else
3399         {
3400             @install_exec = ('install-exec-recursive');
3401         }
3402         if (@install_data)
3403         {
3404             $output_rules .= ('install-data-am: '
3405                               . join (' ', @install_data)
3406                               . "\n\n");
3407             @install_data = ('install-data-recursive', 'install-data-am');
3408             push (@install, 'install-data-am');
3409             push (@phony, 'install-data-am');
3410         }
3411         else
3412         {
3413             @install_data = ('install-data-recursive');
3414         }
3415         if (@uninstall)
3416         {
3417             $output_rules .= ('uninstall-am: '
3418                               . join (' ', @uninstall)
3419                               . "\n\n");
3420             @uninstall = ('uninstall-recursive', 'uninstall-am');
3421             push (@phony, 'uninstall-am');
3422         }
3423         else
3424         {
3425             @uninstall = ('uninstall-recursive');
3426         }
3427     }
3429     # Step three: print definitions users can use.  Code below knows
3430     # that install-exec is done before install-data, beware.
3431     $output_rules .= ("install-exec: "
3432                       . join (' ', @install_exec)
3433                       . "\n");
3434     $output_rules .= "\t\@\$(NORMAL_INSTALL)\n";
3435     if (defined $contents{'install-exec-hook'})
3436     {
3437         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
3438     }
3439     $output_rules .= "\n";
3440     push (@install, 'install-exec') if !$recursive_install;
3441     push (@phony, 'install-exec');
3443     $output_rules .= ("install-data: "
3444                       . join (' ', @install_data)
3445                       . "\n");
3446     $output_rules .= "\t\@\$(NORMAL_INSTALL)\n";
3447     if (defined $contents{'install-data-hook'})
3448     {
3449         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
3450     }
3451     $output_rules .= "\n";
3452     push (@install, 'install-data') if !$recursive_install;
3453     push (@phony, 'install-data');
3455     # If no dependencies for 'install', add 'all'.  Why?  That way
3456     # "make install" at top level of distclean'd distribution won't
3457     # fail because stuff in 'lib' fails to build.
3458     if (! @install || (scalar (@install) == 2
3459                        && $install[0] eq 'install-exec'
3460                        && $install[1] eq 'install-data'))
3461     {
3462         push (@install, 'all');
3463     }
3464     $output_rules .= ('install: '
3465                       . join (' ', @install)
3466                       # Use "@:" as empty command so nothing prints.
3467                       . "\n\t\@:"
3468                       . "\n\n"
3469                       . 'uninstall: '
3470                       . join (' ', @uninstall)
3471                       . "\n\n");
3472     push (@phony, 'install', 'uninstall');
3474     $output_rules .= ('all: '
3475                       . join (' ', @all)
3476                       . "\n\n");
3477     push (@phony, 'all');
3479     # Generate the new 'install-strip' target.  Must set
3480     # INSTALL_SCRIPT to avoid stripping scripts.
3481     $output_rules .= ("install-strip:\n\t"
3482                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' INSTALL_SCRIPT=\'$(INSTALL_PROGRAM)\' install'
3483                       . "\n");
3486 # Helper for handle_merge_targets.
3487 sub do_one_merge_target
3489     local ($name, @values) = @_;
3491     if (defined $contents{$name . '-local'})
3492     {
3493         # User defined local form of target.  So include it.
3494         push (@values, $name . '-local');
3495         push (@phony, $name . '-local');
3496     }
3498     &pretty_print_rule ($name . ":", "\t\t", @values);
3499     push (@phony, $name);
3502 # Handle check merge target specially.
3503 sub do_check_merge_target
3505     if (defined $contents{'check-local'})
3506     {
3507         # User defined local form of target.  So include it.
3508         push (@check_tests, 'check-local');
3509         push (@phony, 'check-local');
3510     }
3512     # In --cygnus mode, check doesn't depend on all.
3513     if (! $cygnus_mode)
3514     {
3515         if (! &variable_defined ('SUBDIRS'))
3516         {
3517             # 'check' must depend on `all', but not when doing
3518             # recursive build.
3519             unshift (@check, 'all');
3520         }
3521         else
3522         {
3523             # When subdirs are used, do the `all' build and then do
3524             # all the recursive stuff.  Actually use `all-am' because
3525             # it doesn't recurse; we rely on the check target in the
3526             # subdirs to do the required builds there.
3527             unshift (@check, 'all-am');
3528         }
3529     }
3531     # The check target must depend on the local equivalent of `all',
3532     # to ensure all the primary targets are built.  Also it must
3533     # depend on the test code named in @check.
3534     &pretty_print_rule ('check:', "\t\t", @check);
3536     # Now the check rules must explicitly run anything named in
3537     # @check_tests.  This is done via a separate make invocation to
3538     # avoid problems with parallel makes.  Every time I write code
3539     # like this I wonder: how could you invent a parallel make and not
3540     # provide any real synchronization facilities?
3541     &pretty_print_rule ("\t\$(MAKE)", "\t  ", @check_tests);
3544 # Handle all 'clean' targets.
3545 sub handle_clean
3547     push (@clean, 'generic');
3548     $output_rules .= &file_contents ('clean');
3549     &push_phony_cleaners ('generic');
3551     local ($target) = $recursive_install ? 'clean-am' : 'clean';
3552     &do_one_clean_target ($target, 'mostly', '', @clean);
3553     &do_one_clean_target ($target, '', 'mostly', @clean);
3554     &do_one_clean_target ($target, 'dist', '', @clean);
3555     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
3557     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
3559     local (@deps);
3560     if ($recursive_install)
3561     {
3562         # Do -recursive before -am.  If you aren't doing a parallel
3563         # make, this can be nicer.
3564         @deps = ('recursive', 'am');
3565         &do_one_clean_target ('', 'mostly', '', @deps);
3566         &do_one_clean_target ('', '', '', @deps);
3567         &do_one_clean_target ('', 'dist', '', @deps);
3568         &do_one_clean_target ('', 'maintainer-', '', @deps);
3569     }
3572 # Helper for handle_clean.
3573 sub do_one_clean_target
3575     local ($target, $name, $last_name, @deps) = @_;
3577     # Special case: if target not passed, then don't generate
3578     # dependency on next "lower" clean target (eg no
3579     # clean<-mostlyclean derivation).  In this case the target is
3580     # implicitly known to be 'clean'.
3581     local ($flag) = $target;
3582     $target = 'clean' if ! $flag;
3584     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
3585     if ($flag)
3586     {
3587         if ($last_name || $name ne 'mostly')
3588         {
3589             push (@deps, $last_name . $target);
3590         }
3591     }
3593     # If a -local version of the rule is given, add it to the list.
3594     if (defined $contents{$name . $target . '-local'})
3595     {
3596         push (@deps, $name . $target . '-local');
3597     }
3599     # Print the target and the dependencies.
3600     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
3602     # FIXME: shouldn't we really print these messages before running
3603     # the dependencies?
3604     if ($name . $target eq 'maintainer-clean')
3605     {
3606         # Print a special warning.
3607         $output_rules .=
3608             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
3609              . "\t\@echo \"it deletes files that may require special "
3610              . "tools to rebuild.\"\n");
3612         $output_rules .= "\trm -f config.status\n"
3613             if $relative_dir eq '.';
3614     }
3615     elsif ($name . $target eq 'distclean')
3616     {
3617         $output_rules .= "\trm -f config.status\n";
3618         $output_rules .= "\trm -f libtool\n" if $seen_libtool;
3619     }
3620     $output_rules .= "\n";
3623 # Handle .PHONY target.
3624 sub handle_phony
3626     &pretty_print_rule ('.PHONY:', "", @phony);
3627     $output_rules .= "\n";
3630 # Handle TESTS variable and other checks.
3631 sub handle_tests
3633     if (defined $options{'dejagnu'})
3634     {
3635         push (@check_tests, 'check-DEJAGNU');
3636         push (@phony, 'check-DEJAGNU');
3638         local ($xform);
3639         if ($cygnus_mode)
3640         {
3641             $xform = 's/^CYGNUS//;';
3642         }
3643         else
3644         {
3645             $xform = 's/^CYGNUS.*$//;';
3646         }
3647         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
3649         # In Cygnus mode, these are found in the build tree.
3650         # Otherwise they are looked for in $PATH.
3651         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
3652         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
3654         # Note that in the rule we don't directly generate site.exp to
3655         # avoid the possibility of a corrupted site.exp if make is
3656         # interrupted.  Jim Meyering has some useful text on this
3657         # topic.
3658         $output_rules .= ("site.exp: Makefile\n"
3659                           . "\t\@echo 'Making a new site.exp file...'\n"
3660                           . "\t-\@rm -f site.bak\n"
3661                           . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
3662                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
3663                           . "\t\@echo '# edit the last section' >> \$\@-t\n"
3664                           . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
3665                           . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
3666                           . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
3668         # Extra stuff for AC_CANONICAL_*
3669         local (@whatlist) = ();
3670         if ($seen_canonical)
3671         {
3672             push (@whatlist, 'host')
3673         }
3675         # Extra stuff only for AC_CANONICAL_SYSTEM.
3676         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
3677         {
3678             push (@whatlist, 'target', 'build');
3679         }
3681         local ($c1, $c2);
3682         foreach $c1 (@whatlist)
3683         {
3684             foreach $c2 ('alias', 'triplet')
3685             {
3686                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
3687             }
3688         }
3690         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
3691                           . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
3692                           . "\t-\@mv site.exp site.bak\n"
3693                           . "\t\@mv \$\@-t site.exp\n");
3694     }
3695     else
3696     {
3697         local ($c);
3698         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
3699         {
3700             if (&variable_defined ($c))
3701             {
3702                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
3703             }
3704         }
3705     }
3707     if (&variable_defined ('TESTS'))
3708     {
3709         push (@check_tests, 'check-TESTS');
3710         push (@phony, 'check-TESTS');
3712         $output_rules .= 'check-TESTS: $(TESTS)
3713         @failed=0; all=0; \\
3714         srcdir=$(srcdir); export srcdir; \\
3715         for tst in $(TESTS); do \\
3716           if test -f $$tst; then dir=.; \\
3717           else dir="$(srcdir)"; fi; \\
3718           if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
3719             all=`expr $$all + 1`; \\
3720             echo "PASS: $$tst"; \\
3721           elif test $$? -ne 77; then \\
3722             all=`expr $$all + 1`; \\
3723             failed=`expr $$failed + 1`; \\
3724             echo "FAIL: $$tst"; \\
3725           fi; \\
3726         done; \\
3727         if test "$$failed" -eq 0; then \\
3728           banner="All $$all tests passed"; \\
3729         else \\
3730           banner="$$failed of $$all tests failed"; \\
3731         fi; \\
3732         dashes=`echo "$$banner" | sed s/./=/g`; \\
3733         echo "$$dashes"; \\
3734         echo "$$banner"; \\
3735         echo "$$dashes"; \\
3736         test "$$failed" -eq 0
3738     }
3741 # Handle Emacs Lisp.
3742 sub handle_emacs_lisp
3744     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
3746     if (@elfiles)
3747     {
3748         # Found some lisp.
3749         &define_configure_variable ('lispdir');
3750         &define_configure_variable ('EMACS');
3751         $output_rules .= (".el.elc:\n"
3752                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
3753                           . "\tif test \$(EMACS) != no; then \\\n"
3754                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
3755                           . "\tfi\n");
3756         push (@suffixes, '.el', '.elc');
3758         # Generate .elc files.
3759         grep ($_ .= 'c', @elfiles);
3760         &define_pretty_variable ('ELCFILES', '', @elfiles);
3762         $output_rules .= &file_contents ('lisp-clean');
3763         push (@clean, 'lisp');
3764         &push_phony_cleaners ('lisp');
3766         push (@all, '$(ELCFILES)');
3768         local ($varname);
3769         if (&variable_defined ('lisp_LISP'))
3770         {
3771             $varname = 'lisp_LISP';
3772             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
3773                 if ! $seen_lispdir;
3774         }
3775         else
3776         {
3777             $varname = 'noinst_LISP';
3778         }
3780         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
3781     }
3784 ################################################################
3786 # Scan one file for interesting things.  Subroutine of scan_configure.
3787 sub scan_one_configure_file
3789     local ($filename) = @_;
3791     open (CONFIGURE, $filename)
3792         || die "automake: couldn't open \`$filename': $!\n";
3793     print "automake: reading $filename\n" if $verbose;
3795     while (<CONFIGURE>)
3796     {
3797         # Remove comments from current line.
3798         s/\bdnl\b.*$//;
3799         s/\#.*$//;
3801         # Skip macro definitions.  Otherwise we might be confused into
3802         # thinking that a macro that was only defined was actually
3803         # used.
3804         next if /AC_DEFUN/;
3806         # Populate libobjs array.
3807         if (/AC_FUNC_ALLOCA/)
3808         {
3809             $libsources{'alloca.c'} = 1;
3810         }
3811         elsif (/AC_FUNC_GETLOADAVG/)
3812         {
3813             $libsources{'getloadavg.c'} = 1;
3814         }
3815         elsif (/AC_FUNC_MEMCMP/)
3816         {
3817             $libsources{'memcmp.c'} = 1;
3818         }
3819         elsif (/AC_STRUCT_ST_BLOCKS/)
3820         {
3821             $libsources{'fileblocks.c'} = 1;
3822         }
3823         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
3824         {
3825             $libsources{'getopt.c'} = 1;
3826             $libsources{'getopt1.c'} = 1;
3827         }
3828         elsif (/AM_FUNC_STRTOD/)
3829         {
3830             $libsources{'strtod.c'} = 1;
3831         }
3832         elsif (/AM_WITH_REGEX/)
3833         {
3834             $libsources{'rx.c'} = 1;
3835             $libsources{'rx.h'} = 1;
3836             $libsources{'regex.c'} = 1;
3837             $libsources{'regex.h'} = 1;
3838             $omit_dependencies{'rx.h'} = 1;
3839             $omit_dependencies{'regex.h'} = 1;
3840         }
3841         elsif (/AM_FUNC_MKTIME/)
3842         {
3843             $libsources{'mktime.c'} = 1;
3844         }
3845         elsif (/AM_FUNC_ERROR_AT_LINE/)
3846         {
3847             $libsources{'error.c'} = 1;
3848             $libsources{'error.h'} = 1;
3849         }
3850         elsif (/AM_FUNC_OBSTACK/)
3851         {
3852             $libsources{'obstack.c'} = 1;
3853             $libsources{'obstack.h'} = 1;
3854         }
3855         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
3856                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
3857         {
3858             foreach $libobj_iter (split (' ', $1))
3859             {
3860                 if ($libobj_iter =~ /^(.*)\.o$/)
3861                 {
3862                     $libsources{$1 . '.c'} = 1;
3863                 }
3864             }
3865         }
3867         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
3868         {
3869             $in_ac_replace = 1;
3870         }
3871         if ($in_ac_replace)
3872         {
3873             $in_ac_replace = 0 if s/[\]\)].*$//;
3874             # Remove trailing backslash.
3875             s/\\$//;
3876             foreach (split)
3877             {
3878                 # Need to skip empty elements for Perl 4.
3879                 next if $_ eq '';
3880                 $libsources{$_ . '.c'} = 1;
3881             }
3882         }
3884         if (/$obsolete_rx/o)
3885         {
3886             local ($hint) = '';
3887             if ($obsolete_macros{$1})
3888             {
3889                 $hint = '; ' . $obsolete_macros{$1};
3890             }
3891             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
3892         }
3894         # Process the AC_OUTPUT macro.
3895         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
3896         {
3897             $in_ac_output = 1;
3898             $ac_output_line = $.;
3899         }
3900         if ($in_ac_output)
3901         {
3902             $in_ac_output = 0 if s/[\]\),].*$//;
3904             # Look at potential Makefile.am's.
3905             foreach (split)
3906             {
3907                 next if $_ eq "\\";
3909                 # Handle $local:$input syntax.  Note that we ignore
3910                 # every input file past the first, though we keep
3911                 # those around for later.
3912                 local ($local, $input, @rest) = split (/:/);
3913                 if (! $input)
3914                 {
3915                     $input = $local;
3916                 }
3917                 else
3918                 {
3919                     # FIXME: should be error if .in is missing.
3920                     $input =~ s/\.in$//;
3921                 }
3923                 if (-f $input . '.am')
3924                 {
3925                     # We have a file that automake should generate.
3926                     push (@make_input_list, $input);
3927                     $make_list{$input} = join (':', ($local, @rest));
3928                 }
3929                 else
3930                 {
3931                     # We have a file that automake should cause to be
3932                     # rebuilt, but shouldn't generate itself.
3933                     push (@other_input_files, $_);
3934                 }
3935             }
3936         }
3938         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
3939         {
3940             @config_aux_path = $1;
3941         }
3943         # Check for ansi2knr.
3944         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
3946         # Check for exe extension stuff.
3947         if (/AM_EXEEXT/)
3948         {
3949             $seen_exeext = 1;
3950             $configure_vars{'EXEEXT'} = 1;
3951         }
3953         # Check for NLS support.
3954         if (/AM_GNU_GETTEXT/)
3955         {
3956             $seen_gettext = 1;
3957             $ac_gettext_line = $.;
3958             $omit_dependencies{'libintl.h'} = 1;
3959         }
3961         # Look for ALL_LINGUAS.
3962         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
3963         {
3964             $seen_linguas = 1;
3965             $all_linguas = $1;
3966             $all_linguas_line = $.;
3967         }
3969         # Handle configuration headers.  A config header of `[$1]'
3970         # means we are actually scanning AM_CONFIG_HEADER from
3971         # aclocal.m4.
3972         if (/A([CM])_CONFIG_HEADER\s*\((.*)\)/
3973             && $2 ne '[$1]')
3974         {
3975             &am_conf_line_error
3976                 ($filename, $.,
3977                  "\`AC_CONFIG_HEADER' is obsolete; use \`AM_CONFIG_HEADER'")
3978                     if $1 eq 'C';
3980             $config_header_line = $.;
3981             local ($one_hdr);
3982             foreach $one_hdr (split (' ', $2))
3983             {
3984                 push (@config_fullnames, $one_hdr);
3985                 if ($one_hdr =~ /^([^:]+):(.+)$/)
3986                 {
3987                     push (@config_names, $1);
3988                     push (@config_headers, $2);
3989                 }
3990                 else
3991                 {
3992                     push (@config_names, $one_hdr);
3993                     push (@config_headers, $one_hdr . '.in');
3994                 }
3995             }
3996         }
3998         # Handle AC_CANONICAL_*.  Always allow upgrading to
3999         # AC_CANONICAL_SYSTEM, but never downgrading.
4000         $seen_canonical = $AC_CANONICAL_HOST
4001             if ! $seen_canonical
4002                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4003         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4005         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
4007         # This macro handles several different things.
4008         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4009         {
4010             $seen_make_set = 1;
4011             $seen_package = 1;
4012             $seen_version = 1;
4013             $seen_arg_prog = 1;
4014             $seen_prog_install = 2;
4015             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4016             $package_version_line = $.;
4017         }
4019         # This is like AM_INIT_AUTOMAKE, but doesn't actually set the
4020         # package and version number.  (This might change in the
4021         # future).  Yes, I'm not above hacking Automake so it works
4022         # well with other GNU tools -- that is actually the point.
4023         if (/AM_INIT_GUILE_MODULE/)
4024         {
4025             $seen_make_set = 1;
4026             $seen_package = 1;
4027             $seen_version = 1;
4028             $seen_arg_prog = 1;
4029             $seen_prog_install = 2;
4030             @config_aux_path = ('..');
4031         }
4033         # Some things required by Automake.
4034         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
4035         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
4037         if (/AC_PROG_(YACC|RANLIB|CC|CXX|LEX|AWK|CPP|CXXCPP|LN_S)/)
4038         {
4039             $configure_vars{$1} = 1;
4040         }
4041         if (/$AC_CHECK_PATTERN/o)
4042         {
4043             $configure_vars{$3} = 1;
4044         }
4045         if (/$AM_MISSING_PATTERN/o
4046             && $1 ne 'ACLOCAL'
4047             && $1 ne 'AUTOCONF'
4048             && $1 ne 'AUTOMAKE'
4049             && $1 ne 'AUTOHEADER')
4050         {
4051             $configure_vars{$1} = 1;
4052         }
4054         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4055         # but later define it elsewhere.  This is pretty hacky.  We
4056         # also explicitly avoid INSTALL_SCRIPT and some other
4057         # variables because they are defined in header-vars.am.
4058         # FIXME.
4059         if (/$AC_SUBST_PATTERN/o
4060             && $1 ne 'ANSI2KNR'
4061             && $1 ne 'INSTALL_SCRIPT')
4062         {
4063             $configure_vars{$1} = 1;
4064         }
4066         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4067         $seen_maint_mode = 1 if /AM_MAINTAINER_MODE/;
4068         $seen_package = 1 if /PACKAGE=/;
4070         # Skip VERSION of [$2]; that is from AM_INIT_AUTOMAKE.
4071         if (/\bVERSION=(\S+)/ && $1 ne '[$2]')
4072         {
4073             $seen_version = 1;
4074             $package_version = $1;
4075             $package_version_line = $.;
4076         }
4077         elsif (/VERSION=/)
4078         {
4079             $seen_version = 1;
4080         }
4082         # Weird conditionals here because it is always allowed to
4083         # upgrade to AM_PROG_INSTALL but never to downgrade to
4084         # AC_PROG_INSTALL.
4085         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
4086         $seen_prog_install = 2 if /AM_PROG_INSTALL/;
4088         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4090         if (/AM_PROG_LIBTOOL/)
4091         {
4092             $seen_libtool = 1;
4093             $libtool_line = $.;
4094             $configure_vars{'LIBTOOL'} = 1;
4095             $configure_vars{'RANLIB'} = 1;
4096             $configure_vars{'CC'} = 1;
4097             # AM_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
4098             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4099             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4100         }
4102         if (/$AM_CONDITIONAL_PATTERN/o)
4103         {
4104             $configure_cond{$1} = 1;
4105         }
4106     }
4108     close (CONFIGURE);
4111 # Scan configure.in and aclocal.m4 for interesting things.  We must
4112 # scan aclocal.m4 because there might be AC_SUBSTs and such there.
4113 sub scan_configure
4115     # Reinitialize libsources here.  This isn't really necessary,
4116     # since we currently assume there is only one configure.in.  But
4117     # that won't always be the case.
4118     %libsources = ();
4120     local ($in_ac_output, $in_ac_replace) = (0, 0);
4121     local (%make_list, @make_input_list);
4122     local ($libobj_iter);
4124     &scan_one_configure_file ('configure.in');
4125     &scan_one_configure_file ('aclocal.m4')
4126         if -f 'aclocal.m4';
4128     # Set input and output files if not specified by user.
4129     if (! @input_files)
4130     {
4131         @input_files = @make_input_list;
4132         %output_files = %make_list;
4133     }
4135     &am_conf_error ("\`PACKAGE' not defined in configure.in")
4136         if ! $seen_package;
4137     &am_conf_error ("\`VERSION' not defined in configure.in")
4138         if ! $seen_version;
4140     # Look for some files we need.  Always check for these.  This
4141     # check must be done for every run, even those where we are only
4142     # looking at a subdir Makefile.  We must set relative_dir so that
4143     # the file-finding machinery works.
4144     local ($relative_dir) = '.';
4145     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4146     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
4147         if -f $config_aux_path[0] . '/install.sh';
4150 ################################################################
4152 # Set up for Cygnus mode.
4153 sub check_cygnus
4155     return unless $cygnus_mode;
4157     &set_strictness ('foreign');
4158     $options{'no-installinfo'} = 1;
4159     $options{'no-dependencies'} = 1;
4160     $use_dependencies = 0;
4162     if (! $seen_maint_mode)
4163     {
4164         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
4165     }
4167     if (! $seen_exeext)
4168     {
4169         &am_conf_error ("\`AM_EXEEXT' required when --cygnus specified");
4170     }
4173 # Do any extra checking for GNU standards.
4174 sub check_gnu_standards
4176     if ($relative_dir eq '.')
4177     {
4178         # In top level (or only) directory.
4179         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4180                        'AUTHORS', 'ChangeLog');
4181     }
4183     if ($strictness >= $GNU)
4184     {
4185         if (defined $options{'no-installman'})
4186         {
4187             &am_line_error ('AUTOMAKE_OPTIONS',
4188                             "option \`no-installman' disallowed by GNU standards");
4189         }
4191         if (defined $options{'no-installinfo'})
4192         {
4193             &am_line_error ('AUTOMAKE_OPTIONS',
4194                             "option \`no-installinfo' disallowed by GNU standards");
4195         }
4196     }
4199 # Do any extra checking for GNITS standards.
4200 sub check_gnits_standards
4202     if ($strictness >= $GNITS)
4203     {
4204         if (-f $relative_dir . '/COPYING.LIB')
4205         {
4206             &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
4207         }
4209         if ($relative_dir eq '.')
4210         {
4211             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4212             {
4213                 # FIXME: allow real filename.
4214                 &am_conf_line_error ('configure.in',
4215                                      $package_version_line,
4216                                      "version \`$package_version' doesn't follow Gnits standards");
4217             }
4218             elsif (defined $1 && -f 'README-alpha')
4219             {
4220                 # This means we have an alpha release.  See
4221                 # GNITS_VERSION_PATTERN for details.
4222                 &require_file ($GNITS, 'README-alpha');
4223             }
4224         }
4225     }
4227     if ($relative_dir eq '.')
4228     {
4229         # In top level (or only) directory.
4230         &require_file ($GNITS, 'THANKS');
4231     }
4234 ################################################################
4236 # Pretty-print something.  HEAD is what should be printed at the
4237 # beginning of the first line, FILL is what should be printed at the
4238 # beginning of every subsequent line.
4239 sub pretty_print_internal
4241     local ($head, $fill, @values) = @_;
4243     local ($column) = length ($head);
4244     local ($result) = $head;
4246     # Fill length is number of characters.  However, each Tab
4247     # character counts for eight.  So we count the number of Tabs and
4248     # multiply by 7.
4249     local ($fill_length) = length ($fill);
4250     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
4252     local ($bol) = ($head eq '');
4253     foreach (@values)
4254     {
4255         # "71" because we also print a space.
4256         if ($column + length ($_) > 71)
4257         {
4258             $result .= " \\\n" . $fill;
4259             $column = $fill_length;
4260             $bol = 1;
4261         }
4263         $result .= ' ' unless ($bol);
4264         $result .= $_;
4265         $column += length ($_) + 1;
4266         $bol = 0;
4267     }
4269     $result .= "\n";
4270     return $result;
4273 # Pretty-print something and append to output_vars.
4274 sub pretty_print
4276     $output_vars .= &pretty_print_internal (@_);
4279 # Pretty-print something and append to output_rules.
4280 sub pretty_print_rule
4282     $output_rules .= &pretty_print_internal (@_);
4286 ################################################################
4288 # See if a target exists.
4289 sub target_defined
4291     local ($target) = @_;
4292     return defined $targets{$target};
4295 # See if two conditionals are the same.
4296 sub conditional_same
4298     local ($cond1, $cond2) = @_;
4300     return (&conditional_true_when ($cond1, $cond2)
4301             && &conditional_true_when ($cond2, $cond1));
4304 # See if a conditional is true.  Both arguments are conditional
4305 # strings.  This returns true if the first conditional is true when
4306 # the second conditional is true.
4307 sub conditional_true_when
4309     local ($cond, $when) = @_;
4311     # Check the easy case first.
4312     if ($cond eq $when)
4313     {
4314         return 1;
4315     }
4317     # Check each component of $cond, which looks @COND1@@COND2@.
4318     foreach $comp (split ('@', $cond))
4319     {
4320         # The way we split will give null strings between each
4321         # condition.
4322         next if ! $comp;
4324         if (index ($when, '@' . $comp . '@') == -1)
4325         {
4326             return 0;
4327         }
4328     }
4330     return 1;
4333 # Check for an ambiguous conditional.  This is called when a variable
4334 # or target is being defined conditionally.  If we already know about
4335 # a definition that is true under the same conditions, then we have an
4336 # ambiguity.
4337 sub check_ambiguous_conditional
4339     local ($var_name, $cond) = @_;
4340     local (@cond_vals) = split (' ', $conditional{$var_name});
4341     while (@cond_vals)
4342     {
4343         local ($vcond) = shift (@cond_vals);
4344         shift (@cond_vals);
4345         if (&conditional_true_when ($vcond, $cond)
4346             || &conditional_true_when ($cond, $vcond))
4347         {
4348             &am_line_error ($var_name,
4349                             "$var_name multiply defined in condition");
4350         }
4351     }
4354 # See if a variable exists.  The first argument is the variable name,
4355 # and the optional second argument is the condition which we should
4356 # check.  If no condition is given, we currently return true if the
4357 # variable is defined under any condition.
4358 sub variable_defined
4360     local ($var, $cond) = @_;
4361     if (defined $targets{$var})
4362     {
4363         &am_line_error ($var, "\`$var' is target; expected variable");
4364         return 0;
4365     }
4366     elsif (defined $contents{$var})
4367     {
4368         if ($cond && $conditional{$var})
4369         {
4370             # We have been asked to check for a particular condition,
4371             # and the variable is defined conditionally.  We need to
4372             # look through the conditions under which the variable is
4373             # defined, and see if any of them match the conditional we
4374             # have been asked to check.
4375             local (@cond_vars) = split (' ', $conditional{$var});
4376             while (@cond_vars)
4377             {
4378                 if (&conditional_same ($cond, shift (@cond_vars)))
4379                 {
4380                     # Even a conditional examination is good enough
4381                     # for us.  FIXME: really should maintain examined
4382                     # status on a per-condition basis.
4383                     $content_seen{$var} = 1;
4384                     return 1;
4385                 }
4386                 shift (@cond_vars);
4387             }
4389             # The variable is not defined for the given condition.
4390             return 0;
4391         }
4393         $content_seen{$var} = 1;
4394         return 1;
4395     }
4396     return 0;
4399 # Mark a variable as examined.
4400 sub examine_variable
4402     local ($var) = @_;
4403     &variable_defined ($var);
4406 # Quote a value in order to put it in $conditional.  We need to quote
4407 # spaces, and we need to handle null strings, so that we can later
4408 # retrieve values by splitting on space.
4409 sub quote_cond_val
4411     local ($val) = @_;
4412     $val =~ s/ /\001/g;
4413     $val = '\002' if $val eq '';
4414     return $val;
4417 # Unquote a value in $conditional.
4418 sub unquote_cond_val
4420     local ($val) = @_;
4421     $val =~ s/\001/ /g;
4422     $val = '' if $val eq '\002';
4423     return $val;
4426 # Return the set of conditions for which a variable is defined.
4428 # If the variable is not defined conditionally, and is not defined in
4429 # terms of any variables which are defined conditionally, then this
4430 # returns the empty list.
4432 # If the variable is defined conditionally, but is not defined in
4433 # terms of any variables which are defined conditionally, then this
4434 # returns the list of conditions for which the variable is defined.
4436 # If the variable is defined in terms of any variables which are
4437 # defined conditionally, then this returns a full set of permutations
4438 # of the subvariable conditions.  For example, if the variable is
4439 # defined in terms of a variable which is defined for @COND_TRUE@,
4440 # then this returns both @COND_TRUE@ and @COND_FALSE@.  This is
4441 # because we will need to define the variable under both conditions.
4443 sub variable_conditions
4445     local ($var) = @_;
4446     local (%uniqify);
4447     local ($cond);
4449     foreach $cond (&variable_conditions_sub ($var, '', ()))
4450     {
4451         $uniqify{$cond} = 1;
4452     }
4454     return keys %uniqify;
4457 # A subroutine of variable_conditions.  We only return conditions
4458 # which are true for all the conditions in @PARENT_CONDS.
4459 sub variable_conditions_sub
4461     local ($var, $parent, @parent_conds) = @_;
4462     local (@new_conds) = ();
4464     if (! $conditional{$var})
4465     {
4466         foreach (split (' ', $contents{$var}))
4467         {
4468             # If a comment seen, just leave.
4469             last if /^#/;
4471             # Handle variable substitutions.
4472             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
4473             {
4474                 push (@new_conds,
4475                       &variable_conditions_sub ($1, $var, @parent_conds));
4476             }
4477         }
4479         return &variable_conditions_reduce (@new_conds);
4480     }
4482     local (@this_conds) = ();
4483     local (@condvals) = split (' ', $conditional{$var});
4484     while (@condvals)
4485     {
4486         local ($cond) = shift (@condvals);
4487         local ($val) = &unquote_cond_val (shift (@condvals));
4489         if (@parent_conds)
4490         {
4491             local ($ok) = 1;
4492             local ($parent_cond);
4493             foreach $parent_cond (@parent_conds)
4494             {
4495                 if (! &conditional_true_when ($parent_cond, $cond))
4496                 {
4497                     $ok = 0;
4498                     last;
4499                 }
4500             }
4502             next if ! $ok;
4503         }
4505         push (@this_conds, $cond);
4507         push (@parent_conds, $cond);
4508         local (@subvar_conds) = ();
4509         foreach (split (' ', $val))
4510         {
4511             # If a comment seen, just leave.
4512             last if /^#/;
4514             # Handle variable substitutions.
4515             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
4516             {
4517                 push (@subvar_conds,
4518                       &variable_conditions_sub ($1, $var, @parent_conds));
4519             }
4520         }
4521         pop (@parent_conds);
4523         # If there are no conditional subvariables, then we want to
4524         # return this condition.  Otherwise, we want to return the
4525         # permutations of the subvariables.
4526         if (! @subvar_conds)
4527         {
4528             push (@new_conds, $cond);
4529         }
4530         else
4531         {
4532             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
4533         }
4534     }
4536     return @new_conds
4537         if ! $parent;
4539     # If we are being called on behalf of another variable, we need to
4540     # return all possible permutations of the conditions.  We have
4541     # already handled everything in @this_conds along with their
4542     # subvariables.  We now need to add any permutations that are not
4543     # in @this_conds.
4544     local ($this_cond);
4545     foreach $this_cond (@this_conds)
4546     {
4547         local (@perms) =
4548             &variable_conditions_permutations (split('@', $this_cond));
4549         local ($perm);
4550         foreach $perm (@perms)
4551         {
4552             local ($scan);
4553             local ($ok) = 1;
4554             foreach $scan (@this_conds)
4555             {
4556                 if (&conditional_true_when ($perm, $scan)
4557                     || &conditional_true_when ($scan, $perm))
4558                 {
4559                     $ok = 0;
4560                     last;
4561                 }
4562             }
4563             next if ! $ok;
4565             if (@parent_conds)
4566             {
4567                 local ($ok) = 1;
4568                 local ($parent_cond);
4569                 foreach $parent_cond (@parent_conds)
4570                 {
4571                     if (! &conditional_true_when ($parent_cond, $perm))
4572                     {
4573                         $ok = 0;
4574                         last;
4575                     }
4576                 }
4578                 next if ! $ok;
4579             }
4581             # This permutation was not already handled, and is valid
4582             # for the parents.
4583             push (@new_conds, $perm);
4584         }
4585     }
4587     return @new_conds;
4590 # Subroutine for variable_conditions_sort
4591 sub variable_conditions_cmp
4593     local ($as) = $a;
4594     $as =~ s/[^@]//g;
4595     local ($bs) = $b;
4596     $bs =~ s/[^@]//g;
4597     return (length ($as) <=> length ($bs)
4598             || $a cmp $b);
4601 # Sort a list of conditionals so that only the exclusive ones are
4602 # retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
4603 # @COND1_TRUE@ are in the list, discard the latter.
4604 sub variable_conditions_reduce
4606     local (@conds) = @_;
4607     local (@ret) = ();
4608     local ($cond);
4609     foreach $cond (sort variable_conditions_cmp @conds)
4610     {
4611         local ($ok) = 1;
4612         local ($scan);
4613         foreach $scan (@ret)
4614         {
4615             if (&conditional_true_when ($cond, $scan))
4616             {
4617                 $ok = 0;
4618                 last;
4619             }
4620         }
4621         next if ! $ok;
4622         push (@ret, $cond);
4623     }
4625     return @ret;
4628 # Return a list of permutations of a conditional string.
4629 sub variable_conditions_permutations
4631     local (@comps) = @_;
4632     return ()
4633         if ! @comps;
4634     local ($comp) = shift (@comps);
4635     return &variable_conditions_permutations (@comps)
4636         if $comp eq '';
4637     local ($neg) = $comp;
4638     $neg =~ s/TRUE$/TRUEO/;
4639     $neg =~ s/FALSE$/TRUE/;
4640     $neg =~ s/TRUEO$/FALSE/;
4641     local (@ret);
4642     local ($sub);
4643     foreach $sub (&variable_conditions_permutations (@comps))
4644     {
4645         push (@ret, '@' . $comp . '@' . $sub);
4646         push (@ret, '@' . $neg . '@' . $sub);
4647     }
4648     if (! @ret)
4649     {
4650         push (@ret, '@' . $comp . '@');
4651         push (@ret, '@' . $neg . '@');
4652     }
4653     return @ret;
4656 # Warn if a variable is conditionally defined.  This is called if we
4657 # are using the value of a variable.
4658 sub variable_conditionally_defined
4660     local ($var, $parent) = @_;
4661     if ($conditional{$var})
4662     {
4663         if ($parent)
4664         {
4665             &am_line_error ($parent,
4666                             "warning: automake does not support conditional definition of $var in $parent");
4667         }
4668         else
4669         {
4670             &am_line_error ($parent,
4671                             "warning: automake does not support $var being defined conditionally")
4672         }
4673     }
4676 # Get the value of a variable.  This just returns $contents, but warns
4677 # if the variable is conditionally defined.
4678 sub variable_value
4680     local ($var) = @_;
4681     &variable_conditionally_defined ($var);
4682     return $contents{$var};
4685 # Convert a variable value to a list, split as whitespace.  This will
4686 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
4687 # substitutions.  If COND is 'all', then all values under all
4688 # conditions should be returned; if COND is a particular condition
4689 # (all conditions are surrounded by @...@) then only the value for
4690 # that condition should be returned; otherwise, warn if VAR is
4691 # conditionally defined.
4692 sub value_to_list
4694     local ($var, $val, $cond) = @_;
4695     local (@result);
4697     foreach (split (' ', $val))
4698     {
4699         # If a comment seen, just leave.
4700         last if /^#/;
4702         # Handle variable substitutions.
4703         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
4704         {
4705             local ($varname) = $1;
4707             # If the user uses a losing variable name, just ignore it.
4708             # This isn't ideal, but people have requested it.
4709             next if ($varname =~ /\@.*\@/);
4711             local ($from, $to);
4712             local (@temp_list);
4713             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
4714             {
4715                 $varname = $1;
4716                 $to = $3;
4717                 ($from = $2) =~ s/(\W)/\\$1/g;
4718             }
4720             # Find the value.
4721             @temp_list = &variable_value_as_list ($1, $cond, $var);
4723             # Now rewrite the value if appropriate.
4724             if ($from)
4725             {
4726                 grep (s/$from$/$to/, @temp_list);
4727             }
4729             push (@result, @temp_list);
4730         }
4731         else
4732         {
4733             push (@result, $_);
4734         }
4735     }
4737     return @result;
4740 # Return contents of variable as list, split as whitespace.  This will
4741 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
4742 # substitutions.  If COND is 'all', then all values under all
4743 # conditions should be returned; if COND is a particular condition
4744 # (all conditions are surrounded by @...@) then only the value for
4745 # that condition should be returned; otherwise, warn if VAR is
4746 # conditionally defined.  If PARENT is specified, it is the name of
4747 # the including variable; this is only used for error reports.
4748 sub variable_value_as_list
4750     local ($var, $cond, $parent) = @_;
4751     local (@result);
4753     if (defined $targets{$var})
4754     {
4755         &am_line_error ($var, "\`$var' is target; expected variable");
4756     }
4757     elsif (! defined $contents{$var})
4758     {
4759         &am_line_error ($parent, "variable \`$var' not defined");
4760     }
4761     elsif ($cond eq 'all' && $conditional{$var})
4762     {
4763         local (@condvals) = split (' ', $conditional{$var});
4764         while (@condvals)
4765         {
4766             shift (@condvals);
4767             local ($val) = &unquote_cond_val (shift (@condvals));
4768             push (@result, &value_to_list ($var, $val, $cond));
4769         }
4770     }
4771     elsif ($cond && $conditional{$var})
4772     {
4773         local (@condvals) = split (' ', $conditional{$var});
4774         local ($onceflag);
4775         while (@condvals)
4776         {
4777             local ($vcond) = shift (@condvals);
4778             local ($val) = &unquote_cond_val (shift (@condvals));
4779             if (&conditional_true_when ($vcond, $cond))
4780             {
4781                 # Warn if we have an ambiguity.  It's hard to know how
4782                 # to handle this case correctly.
4783                 &variable_conditionally_defined ($var, $parent)
4784                     if $onceflag;
4785                 $onceflag = 1;
4786                 push (@result, &value_to_list ($var, $val, $cond));
4787             }
4788         }
4789     }
4790     else
4791     {
4792         &variable_conditionally_defined ($var, $parent);
4793         $content_seen{$var} = 1;
4794         push (@result, &value_to_list ($var, $contents{$var}, $cond));
4795     }
4797     return @result;
4800 # Define a new variable, but only if not already defined.
4801 sub define_variable
4803     local ($var, $value) = @_;
4805     if (! defined $contents{$var})
4806     {
4807         $output_vars .= $var . ' = ' . $value . "\n";
4808         $contents{$var} = $value;
4809         $content_seen{$var} = 1;
4810     }
4813 # Like define_variable, but the value is a list, and the variable may
4814 # be defined conditionally.  The second argument is the conditional
4815 # under which the value should be defined; this should be the empty
4816 # string to define the variable unconditionally.  The third argument
4817 # is a list holding the values to use for the variable.  The value is
4818 # pretty printed in the output file.
4819 sub define_pretty_variable
4821     local ($var, $cond, @value) = @_;
4822     if (! defined $contents{$var}
4823         || ($cond && ! &variable_defined ($var, $cond)))
4824     {
4825         $contents{$var} = join (' ', @value);
4826         if ($cond)
4827         {
4828             if ($conditional{$var})
4829             {
4830                 $conditional{$var} .= ' ';
4831             }
4832             else
4833             {
4834                 $conditional{$var} = '';
4835             }
4836             $conditional{$var} .= ($cond
4837                                    . ' '
4838                                    . &quote_cond_val ($contents{$var}));
4839         }
4840         &pretty_print ($cond . $var . ' = ', $cond, @value);
4841         $content_seen{$var} = 1;
4842     }
4845 # Like define_variable, but define a variable to be the configure
4846 # substitution by the same name.
4847 sub define_configure_variable
4849     local ($var) = @_;
4850     local ($value) = '@' . $var . '@';
4851     &define_variable ($var, $value);
4854 # Define a variable that represents a program to run.  If in Cygnus
4855 # mode, the program is searched for in the build (or source) tree.
4856 # Otherwise no searching is done at all.  Arguments are:
4857 # * VAR      Name of variable to define
4858 # * WHATDIR  Either `src' or `build', depending on where program should
4859 #            be found.  (runtest is in srcdir!)
4860 # * SUBDIR   Subdir of top-level dir
4861 # * PROGRAM  Name of program
4862 # * OVERRIDE If specified, the name of the program to use when not in
4863 #            Cygnus mode.  Defaults to PROGRAM.
4864 sub define_program_variable
4866     local ($var, $whatdir, $subdir, $program, $override) = @_;
4868     if (! $override)
4869     {
4870         $override = $program;
4871     }
4873     if ($cygnus_mode)
4874     {
4875         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
4876                          . $subdir . '/' . $program);
4877         &define_variable ($var, ('`if test -f ' . $full
4878                                  . '; then echo ' . $full . '; else echo '
4879                                  . $program . '; fi`'));
4880     }
4881     else
4882     {
4883         &define_variable ($var, $override);
4884     }
4888 ################################################################
4890 # Read Makefile.am and set up %contents.  Simultaneously copy lines
4891 # from Makefile.am into $output_trailer or $output_vars as
4892 # appropriate.  NOTE we put rules in the trailer section.  We want
4893 # user rules to come after our generated stuff.
4894 sub read_am_file
4896     local ($amfile) = @_;
4898     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
4899     print "automake: reading $amfile\n" if $verbose;
4901     $output_vars = ("# $in_file_name generated automatically by automake "
4902                     . $VERSION . " from $am_file_name\n");
4904     # Generate copyright for generated Makefile.in.
4905     $output_vars .= $gen_copyright;
4907     local ($saw_bk) = 0;
4908     local ($was_rule) = 0;
4909     local ($spacing) = '';
4910     local ($comment) = '';
4911     local ($last_var_name) = '';
4912     local ($blank) = 0;
4914     while (<AM_FILE>)
4915     {
4916         if (/$IGNORE_PATTERN/o)
4917         {
4918             # Merely delete comments beginning with two hashes.
4919         }
4920         elsif (/$WHITE_PATTERN/o)
4921         {
4922             # Stick a single white line before the incoming macro or rule.
4923             $spacing = "\n";
4924             $blank = 1;
4925         }
4926         elsif (/$COMMENT_PATTERN/o)
4927         {
4928             # Stick comments before the incoming macro or rule.  Make
4929             # sure a blank line preceeds first block of comments.
4930             $spacing = "\n" unless $blank;
4931             $blank = 1;
4932             $comment .= $spacing . $_;
4933             $spacing = '';
4934         }
4935         else
4936         {
4937             last;
4938         }
4939     }
4941     $output_vars .= $comment . "\n";
4942     $comment = '';
4943     $spacing = "\n";
4944     local ($am_vars) = '';
4946     local ($is_ok_macro);
4947     while ($_)
4948     {
4949         $_ .= "\n"
4950             unless substr ($_, -1, 1) eq "\n";
4952         $_ =~ s/\@MAINT\@//g
4953             unless $seen_maint_mode;
4955         if (/$IGNORE_PATTERN/o)
4956         {
4957             # Merely delete comments beginning with two hashes.
4958         }
4959         elsif (/$WHITE_PATTERN/o)
4960         {
4961             # Stick a single white line before the incoming macro or rule.
4962             $spacing = "\n";
4963         }
4964         elsif (/$COMMENT_PATTERN/o)
4965         {
4966             # Stick comments before the incoming macro or rule.
4967             $comment .= $spacing . $_;
4968             $spacing = '';
4969         }
4970         elsif ($saw_bk)
4971         {
4972             if ($was_rule)
4973             {
4974                 $output_trailer .= join ('', @conditional_stack) . $_;
4975                 $saw_bk = /\\$/;
4976             }
4977             else
4978             {
4979                 $am_vars .= join ('', @conditional_stack) . $_;
4980                 $saw_bk = /\\$/;
4981                 # Chop newline and backslash if this line is
4982                 # continued.  FIXME: maybe ensure trailing whitespace
4983                 # exists?
4984                 chop if $saw_bk;
4985                 chop if $saw_bk;
4986                 $contents{$last_var_name} .= $_;
4987                 if (@conditional_stack)
4988                 {
4989                     $conditional{$last_var_name} .= &quote_cond_val ($_);
4990                 }
4991             }
4992         }
4993         elsif (/$IF_PATTERN/o)
4994         {
4995             &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
4996                 if (! $configure_cond{$1});
4997             push (@conditional_stack, "\@" . $1 . "_TRUE\@");
4998         }
4999         elsif (/$ELSE_PATTERN/o)
5000         {
5001             if (! @conditional_stack)
5002             {
5003                 &am_line_error ($., "else without if");
5004             }
5005             elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
5006             {
5007                 &am_line_error ($., "else after else");
5008             }
5009             else
5010             {
5011                 $conditional_stack[$#conditional_stack]
5012                     =~ s/_TRUE\@$/_FALSE\@/;
5013             }
5014         }
5015         elsif (/$ENDIF_PATTERN/o)
5016         {
5017             if (! @conditional_stack)
5018             {
5019                 &am_line_error ($., "endif without if");
5020             }
5021             else
5022             {
5023                 pop @conditional_stack;
5024             }
5025         }
5026         elsif (/$RULE_PATTERN/o)
5027         {
5028             # Found a rule.
5029             $was_rule = 1;
5030             if (defined $contents{$1}
5031                 && (@conditional_stack
5032                     ? ! defined $conditional{$1}
5033                     : defined $conditional{$1}))
5034             {
5035                 &am_line_error ($1,
5036                                 "$1 defined both conditionally and unconditionally");
5037             }
5038             # Value here doesn't matter; for targets we only note
5039             # existence.
5040             $contents{$1} = 1;
5041             $targets{$1} = 1;
5042             local ($cond_string) = join ('', @conditional_stack);
5043             if (@conditional_stack)
5044             {
5045                 if ($conditional{$1})
5046                 {
5047                     &check_ambiguous_conditional ($1, $cond_string);
5048                     $conditional{$1} .= ' ';
5049                 }
5050                 else
5051                 {
5052                     $conditional{$1} = '';
5053                 }
5054                 $conditional{$1} .= $cond_string . ' 1';
5055             }
5056             $content_lines{$1} = $.;
5057             $output_trailer .= $comment . $spacing . $cond_string . $_;
5058             $comment = $spacing = '';
5059             $saw_bk = /\\$/;
5060         }
5061         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
5062                || /$BOGUS_MACRO_PATTERN/o)
5063         {
5064             # Found a macro definition.
5065             $was_rule = 0;
5066             $last_var_name = $1;
5067             if (defined $contents{$1}
5068                 && (@conditional_stack
5069                     ? ! defined $conditional{$1}
5070                     : defined $conditional{$1}))
5071             {
5072                 &am_line_error ($1,
5073                                 "$1 defined both conditionally and unconditionally");
5074             }
5075             if ($2 ne '' && substr ($2, -1) eq "\\")
5076             {
5077                 $contents{$last_var_name} = substr ($2, 0, length ($2) - 1);
5078             }
5079             else
5080             {
5081                 $contents{$last_var_name} = $2;
5082             }
5083             local ($cond_string) = join ('', @conditional_stack);
5084             if (@conditional_stack)
5085             {
5086                 if ($conditional{$last_var_name})
5087                 {
5088                     &check_ambiguous_conditional ($last_var_name,
5089                                                   $cond_string);
5090                     $conditional{$last_var_name} .= ' ';
5091                 }
5092                 else
5093                 {
5094                     $conditional{$last_var_name} = '';
5095                 }
5096                 local ($val) = $contents{$last_var_name};
5097                 $conditional{$last_var_name} .= ($cond_string
5098                                                  . ' '
5099                                                  . &quote_cond_val ($val));
5100             }
5101             $content_lines{$last_var_name} = $.;
5102             $am_vars .= $comment . $spacing . $cond_string . $_;
5103             $comment = $spacing = '';
5104             $saw_bk = /\\$/;
5106             # Error if bogus.
5107             &am_line_error ($., "bad macro name \`$last_var_name'")
5108                 if ! $is_ok_macro;
5109         }
5110         else
5111         {
5112             # This isn't an error; it is probably a continued rule.
5113             # In fact, this is what we assume.
5114             $was_rule = 1;
5115             $output_trailer .= ($comment . $spacing
5116                                 . join ('', @conditional_stack) . $_);
5117             $comment = $spacing = '';
5118             $saw_bk = /\\$/;
5119         }
5121         $_ = <AM_FILE>;
5122     }
5124     $output_trailer .= $comment;
5126     &am_error ("unterminated conditionals: " . join (' ', @conditional_stack))
5127         if (@conditional_stack);
5129     # Compute relative location of the top object directory.
5130     local (@topdir) = ();
5131     foreach (split (/\//, $relative_dir))
5132     {
5133         next if $_ eq '.' || $_ eq '';
5134         if ($_ eq '..')
5135         {
5136             pop @topdir;
5137         }
5138         else
5139         {
5140             push (@topdir, '..');
5141         }
5142     }
5143     @topdir = ('.') if ! @topdir;
5145     $top_builddir = join ('/', @topdir);
5146     local ($build_rx);
5147     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
5148     $output_vars .= &file_contents_with_transform
5149                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
5150                          'header-vars');
5152     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
5153     # this should use generic %configure_vars method.
5154     if ($seen_canonical)
5155     {
5156         local ($curs, %vars);
5157         $vars{'host_alias'} = 'host_alias';
5158         $vars{'host_triplet'} = 'host';
5159         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
5160         {
5161             $vars{'build_alias'} = 'build_alias';
5162             $vars{'build_triplet'} = 'build';
5163             $vars{'target_alias'} = 'target_alias';
5164             $vars{'target_triplet'} = 'target';
5165         }
5166         foreach $curs (sort keys %vars)
5167         {
5168             $output_vars .= "$curs = \@$vars{$curs}\@\n";
5169             $contents{$curs} = "\@$vars{$curs}\@";
5170         }
5171     }
5173     local ($curs);
5174     foreach $curs (sort keys %configure_vars)
5175     {
5176         &define_configure_variable ($curs);
5177     }
5179     $output_vars .= $am_vars;
5182 ################################################################
5184 sub initialize_global_constants
5186     # Values for AC_CANONICAL_*
5187     $AC_CANONICAL_HOST = 1;
5188     $AC_CANONICAL_SYSTEM = 2;
5190     # Associative array of standard directory names.  Entry is TRUE if
5191     # corresponding directory should be installed during
5192     # 'install-exec' phase.
5193     %exec_dir_p =
5194         ('bin', 1,
5195          'sbin', 1,
5196          'libexec', 1,
5197          'data', 0,
5198          'sysconf', 1,
5199          'localstate', 1,
5200          'lib', 1,
5201          'info', 0,
5202          'man', 0,
5203          'include', 0,
5204          'oldinclude', 0,
5205          'pkgdata', 0,
5206          'pkglib', 1,
5207          'pkginclude', 0
5208          );
5210     # Helper text for dealing with man pages.
5211     $install_man_format =
5212     '   @sect=@SECTION@;                                \\
5213         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
5214         if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
5215         else file=@MAN@; fi; \\
5216         echo " $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst"; \\
5217         $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst
5220     $uninstall_man_format =
5221     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
5222         rm -f $(mandir)/man@SECTION@/$$inst
5225     # Commonly found files we look for and automatically include in
5226     # DISTFILES.
5227     @common_files =
5228         (
5229          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
5230          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
5231          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
5232          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
5233          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
5234          'ylwrap', 'acinclude.m4', @libtoolize_files,
5235          'missing'
5236          );
5238     # Commonly used files we auto-include, but only sometimes.
5239     @common_sometimes =
5240         (
5241          "aclocal.m4", "acconfig.h", "config.h.top",
5242          "config.h.bot", "stamp-h.in", 'stamp-vti'
5243          );
5245     $USAGE = "\
5246   -a, --add-missing     add missing standard files to package
5247   --amdir=DIR           directory storing config files
5248   --build-dir=DIR       directory where build being done (for dependencies)
5249   --cygnus              assume program is part of Cygnus-style tree
5250   --foreign             set strictness to foreign
5251   --gnits               set strictness to gnits
5252   --gnu                 set strictness to gnu
5253   --help                print this help, then exit
5254   -i, --include-deps    include generated dependencies in Makefile.in
5255   --no-force            only update Makefile.in's that are out of date
5256   -o DIR, --output-dir=DIR
5257                         put generated Makefile.in's into DIR
5258   --srcdir-name=DIR     name used for srcdir (for dependencies)
5259   -v, --verbose         verbosely list files processed
5260   --version             print version number, then exit\n";
5262     # Copyright on generated Makefile.ins.
5263     $gen_copyright = "\
5264 # Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
5265 # This Makefile.in is free software; the Free Software Foundation
5266 # gives unlimited permission to copy and/or distribute it,
5267 # with or without modifications, as long as this notice is preserved.
5269 # This program is distributed in the hope that it will be useful,
5270 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
5271 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
5272 # PARTICULAR PURPOSE.
5275     # Ignore return result from chmod, because it might give an error
5276     # if we chmod a symlink.
5277     $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
5278     $dist{'dist-tarZ'} = ("\t"
5279                      . '$(TAR) chf - $(distdir) | compress -c > $(distdir).tar.Z'
5280                      . "\n");
5281     $dist{'dist-shar'} = ("\t"
5282                      . 'shar $(distdir) | gzip > $(distdir).shar.gz'
5283                      . "\n");
5284     $dist{'dist-zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
5285     $dist{'dist'} = "\t" .  'GZIP=$(GZIP) $(TAR) chozf $(distdir).tar.gz $(distdir)' . "\n";
5286     $dist_trailer = "\t" . 'rm -rf $(distdir)' . "\n";
5289 # (Re)-Initialize per-Makefile.am variables.
5290 sub initialize_per_input
5292     # These two variables are used when generating each Makefile.in.
5293     # They hold the Makefile.in until it is ready to be printed.
5294     $output_rules = '';
5295     $output_vars = '';
5296     $output_trailer = '';
5297     $output_header = '';
5299     # Suffixes found during a run.
5300     @suffixes = ();
5302     # This holds the contents of a Makefile.am, as parsed by
5303     # read_am_file.
5304     %contents = ();
5306     # This holds the names which are targets.  These also appear in
5307     # %contents.
5308     %targets = ();
5310     # For a variable or target which is defined conditionally, this
5311     # holds an array of the conditional values.  The array is composed
5312     # of pairs of condition strings (the variables which configure
5313     # will substitute) and values (the value of a target is
5314     # meaningless).  For an unconditional variable, this is empty.
5315     %conditional = ();
5317     # This holds the line numbers at which various elements of
5318     # %contents are defined.
5319     %content_lines = ();
5321     # This holds a 1 if a particular variable was examined.
5322     %content_seen = ();
5324     # This is the conditional stack.
5325     @conditional_stack = ();
5327     # This holds the "relative directory" of the current Makefile.in.
5328     # Eg for src/Makefile.in, this is "src".
5329     $relative_dir = '';
5331     # This holds a list of files that are included in the
5332     # distribution.
5333     %dist_common = ();
5335     # List of dependencies for the obvious targets.
5336     @install_data = ();
5337     @install_exec = ();
5338     @uninstall = ();
5339     @installdirs = ();
5341     @info = ();
5342     @dvi = ();
5343     @all = ();
5344     @check = ();
5345     @check_tests = ();
5346     @installcheck = ();
5347     @clean = ();
5349     @phony = ();
5351     # These are pretty obvious, too.  They are used to define the
5352     # SOURCES and OBJECTS variables.
5353     @sources = ();
5354     @objects = ();
5356     # TRUE if current directory holds any C source files.
5357     $dir_holds_sources = 0;
5359     # These variables track inclusion of various compile-related .am
5360     # files.  $included_generic_compile is TRUE if the basic code has
5361     # been included.  $included_knr_compile is TRUE if the ansi2knr
5362     # code has been included.  $included_libtool_compile is TRUE if
5363     # libtool support has been included.
5364     $included_generic_compile = 0;
5365     $included_knr_compile = 0;
5366     $included_libtool_compile = 0;
5368     # TRUE if current directory holds any headers.
5369     $dir_holds_headers = 0;
5371     # TRUE if install targets should work recursively.
5372     $recursive_install = 0;
5374     # All .P files.
5375     %dep_files = ();
5377     # Strictness levels.
5378     $strictness = $default_strictness;
5379     $strictness_name = $default_strictness_name;
5381     # Options from AUTOMAKE_OPTIONS.
5382     %options = ();
5384     # Whether or not dependencies are handled.  Can be further changed
5385     # in handle_options.
5386     $use_dependencies = $cmdline_use_dependencies;
5388     # Per Makefile.am.
5389     $local_maint_charset = $maint_charset;
5391     # All yacc and lex source filenames for this directory.  Use
5392     # filenames instead of raw count so that multiple instances are
5393     # counted correctly (eg one yacc file can appear in multiple
5394     # programs without harm).
5395     %yacc_sources = ();
5396     %lex_sources = ();
5398     # C++ source extensions we've seen.
5399     %cxx_extensions = ();
5401     # TRUE if we've seen any non-C++ sources.  This actually holds a
5402     # line number or the name of a symbol corresponding to a line
5403     # number where the C sources were seen.  If it is -1 then it means
5404     # we couldn't (easily) figure out which line of the Makefile.am
5405     # mentioned the sources.
5406     $seen_c_source = 0;
5408     # This is a list of all targets to run during "make dist".
5409     @dist_targets = ();
5411     # Keys in this hash are the basenames of files which must depend
5412     # on ansi2knr.
5413     %de_ansi_files = ();
5417 ################################################################
5419 # Return contents of a file from $am_dir, automatically skipping
5420 # macros or rules which are already known.  Runs command on each line
5421 # as it is read; this command can modify $_.
5422 sub file_contents_with_transform
5424     local ($command, $basename) = @_;
5425     local ($file) = $am_dir . '/' . $basename . '.am';
5427     if ($command ne '' && substr ($command, -1) ne ';')
5428     {
5429         die "automake: programming error in file_contents_with_transform\n";
5430     }
5432     open (FC_FILE, $file)
5433         || die "automake: installation error: cannot open \`$file'\n";
5434     # Looks stupid?
5435     # print "automake: reading $file\n" if $verbose;
5437     local ($was_rule) = 0;
5438     local ($result_vars) = '';
5439     local ($result_rules) = '';
5440     local ($comment) = '';
5441     local ($spacing) = "\n";
5442     local ($skipping) = 0;
5443     local ($had_chars);
5445     while (<FC_FILE>)
5446     {
5447         $_ =~ s/\@MAINT\@//g
5448             unless $seen_maint_mode;
5450         $had_chars = length ($_) && $_ ne "\n";
5451         eval $command;
5452         # If the transform caused all the characters to go away, then
5453         # ignore the line.  Why do this?  Because in Perl 4, a "next"
5454         # inside of an eval doesn't affect a loop outside the eval.
5455         # So we can't pass in a "transform" that uses next.  We used
5456         # to do this.  "Empty" also means consisting of a single
5457         # newline.
5458         next if $had_chars && ($_ eq '' || $_ eq "\n");
5460         if (/$IGNORE_PATTERN/o)
5461         {
5462             # Merely delete comments beginning with two hashes.
5463         }
5464         elsif (/$WHITE_PATTERN/o)
5465         {
5466             # Stick a single white line before the incoming macro or rule.
5467             $spacing = "\n";
5468         }
5469         elsif (/$COMMENT_PATTERN/o)
5470         {
5471             # Stick comments before the incoming macro or rule.
5472             $comment .= $spacing . $_;
5473             $spacing = '';
5474         }
5475         elsif ($saw_bk)
5476         {
5477             if ($was_rule)
5478             {
5479                 $result_rules .= $_ if ! $skipping;
5480             }
5481             else
5482             {
5483                 $result_vars .= $_ if ! $skipping;
5484             }
5485             $saw_bk = /\\$/;
5486         }
5487         elsif (/$RULE_PATTERN/o)
5488         {
5489             # Found a rule.
5490             $was_rule = 1;
5491             $skipping = defined $contents{$1};
5492             $result_rules .= $comment . $spacing . $_ if ! $skipping;
5493             $comment = $spacing = '';
5494             $saw_bk = /\\$/;
5495         }
5496         elsif (/$MACRO_PATTERN/o)
5497         {
5498             # Found a variable reference.
5499             $was_rule = 0;
5500             $skipping = defined $contents{$1};
5501             $result_vars .= $comment . $spacing . $_ if ! $skipping;
5502             $comment = $spacing = '';
5503             $saw_bk = /\\$/;
5504         }
5505         else
5506         {
5507             # This isn't an error; it is probably a continued rule.
5508             # In fact, this is what we assume.
5509             $was_rule = 1;
5510             $result_rules .= $comment . $spacing . $_ if ! $skipping;
5511             $comment = $spacing = '';
5512             $saw_bk = /\\$/;
5513         }
5514     }
5516     close (FC_FILE);
5517     return $result_vars . $result_rules . $comment;
5520 # Like file_contents_with_transform, but no transform.
5521 sub file_contents
5523     return &file_contents_with_transform ('', @_);
5526 # Find all variable prefixes that are used for install directories.  A
5527 # prefix `zar' qualifies iff:
5528 # * `zardir' is a variable.
5529 # * `zar_PRIMARY' is a variable.
5530 sub am_primary_prefixes
5532     local ($primary, @prefixes) = @_;
5534     local (%valid, $varname);
5535     grep ($valid{$_} = 0, @prefixes);
5536     $valid{'EXTRA'} = 0;
5537     foreach $varname (keys %contents)
5538     {
5539         if ($varname =~ /^(.*)_$primary$/)
5540         {
5541             if (! defined $valid{$1}
5542                 && ! &variable_defined ($1 . 'dir')
5543                 # Note that a configure variable is always legitimate.
5544                 # It is natural to name such variables after the
5545                 # primary, so we explicitly allow it.
5546                 && ! defined $configure_vars{$varname})
5547             {
5548                 &am_line_error ($varname, "invalid variable \`$varname'");
5549             }
5550             else
5551             {
5552                 # Ensure all extended prefixes are actually used.
5553                 $valid{$1} = 1;
5554             }
5555         }
5556     }
5558     return %valid;
5561 # Handle `where_HOW' variable magic.  Does all lookups, generates
5562 # install code, and possibly generates code to define the primary
5563 # variable.  The first argument is the name of the .am file to munge,
5564 # the second argument is the primary variable (eg HEADERS), and all
5565 # subsequent arguments are possible installation locations.  Returns
5566 # list of all values of all _HOW targets.
5568 # FIXME: this should be rewritten to be cleaner.  It should be broken
5569 # up into multiple functions.
5571 # Usage is: am_install_var (OPTION..., file, HOW, where...)
5572 sub am_install_var
5574     local (@args) = @_;
5576     local ($do_clean) = 0;
5578     local ($ltxform);
5579     if (defined $configure_vars{'LIBTOOL'})
5580     {
5581         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
5582         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
5583     }
5584     else
5585     {
5586         # Delete '@LIBTOOL ...@'
5587         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
5588     }
5590     local ($cygxform);
5591     if (! $seen_exeext)
5592     {
5593         $cygxform = 's/\@EXEEXT\@//g;';
5594     }
5595     else
5596     {
5597         $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
5598     }
5600     while (@args)
5601     {
5602         if ($args[0] eq '-clean')
5603         {
5604             $do_clean = 1;
5605         }
5606         elsif ($args[0] !~ /^-/)
5607         {
5608             last;
5609         }
5610         shift (@args);
5611     }
5612     local ($file, $primary, @prefixes) = @args;
5614     local (@used) = ();
5615     local (@result) = ();
5617     # Now that configure substitutions are allowed in where_HOW
5618     # variables, it is an error to actually define the primary.
5619     &am_line_error ($primary, "\`$primary' is an anachronism")
5620         if &variable_defined ($primary);
5623     # Look for misspellings.  It is an error to have a variable ending
5624     # in a "reserved" suffix whose prefix is unknown, eg
5625     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
5626     # variable of the same name (with "dir" appended) exists.  For
5627     # instance, if the variable "zardir" is defined, then
5628     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
5629     # flexibility in those cases which need it.  Perhaps it should be
5630     # disallowed in the Gnits case?  The problem is, sometimes it is
5631     # useful to put things in a subdir of eg pkgdatadir, perhaps even
5632     # for Gnitsoids.
5633     local (%valid) = &am_primary_prefixes ($primary, @prefixes);
5635     # If a primary includes a configure substitution, then the EXTRA_
5636     # form is required.  Otherwise we can't properly do our job.
5637     local ($require_extra);
5638     local ($warned_about_extra) = 0;
5640     local ($clean_file) = $file . '-clean';
5641     local ($one_name);
5642     local ($X);
5643     foreach $X (sort keys %valid)
5644     {
5645         $one_name = $X . '_' . $primary;
5646         if (&variable_defined ($one_name))
5647         {
5648             # Append actual contents of where_PRIMARY variable to
5649             # result.
5650             local ($rcurs);
5651             foreach $rcurs (&variable_value_as_list ($one_name, 'all'))
5652             {
5653                 # Skip configure substitutions.  Possibly bogus.
5654                 if ($rcurs =~ /^\@.*\@$/)
5655                 {
5656                     if ($X eq 'EXTRA')
5657                     {
5658                         if (! $warned_about_extra)
5659                         {
5660                             $warned_about_extra = 1;
5661                             &am_line_error ($one_name,
5662                                             "\`$one_name' contains configure substitution, but shouldn't");
5663                         }
5664                     }
5665                     # Check here to make sure variables defined in
5666                     # configure.in do not imply that EXTRA_PRIMARY
5667                     # must be defined.
5668                     elsif (! defined $configure_vars{$one_name})
5669                     {
5670                         $require_extra = $one_name;
5671                     }
5673                     next;
5674                 }
5676                 push (@result, $rcurs);
5677             }
5679             # "EXTRA" shouldn't be used when generating clean targets,
5680             # all, or install targets.
5681             next if $X eq 'EXTRA';
5683             # A blatant hack: we rewrite each _PROGRAMS primary to
5684             # include EXEEXT when in Cygwin32 mode.
5685             if ($seen_exeext && $primary eq 'PROGRAMS')
5686             {
5687                 local (@conds) = &variable_conditions ($one_name);
5688                 local (@one_binlist);
5690                 # FIXME: this definitely loses aesthetically; it
5691                 # redefines $ONE_NAME.  Instead we should arrange for
5692                 # variable definitions to be output later, instead of
5693                 # at scan time.
5695                 if (! @conds)
5696                 {
5697                     @one_binlist = ();
5698                     foreach $rcurs (&variable_value_as_list ($one_name, ''))
5699                     {
5700                         if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
5701                         {
5702                             push (@one_binlist, $rcurs);
5703                         }
5704                         else
5705                         {
5706                             push (@one_binlist, $rcurs . '$(EXEEXT)');
5707                         }
5708                     }
5710                     delete $contents{$one_name};
5711                     &define_pretty_variable ($one_name, '', @one_binlist);
5712                 }
5713                 else
5714                 {
5715                     local ($cond);
5716                     local ($condvals) = '';
5717                     foreach $cond (@conds)
5718                     {
5719                         @one_binlist = ();
5720                         local (@condval) = &variable_value_as_list ($one_name,
5721                                                                     $cond);
5722                         foreach $rcurs (@condval)
5723                         {
5724                             if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
5725                             {
5726                                 push (@one_binlist, $rcurs);
5727                             }
5728                             else
5729                             {
5730                                 push (@one_binlist, $rcurs . '$(EXEEXT)');
5731                             }
5732                         }
5734                         push (@condvals, $cond);
5735                         push (@condvals, join (' ', @one_binlist));
5736                     }
5738                     delete $contents{$one_name};
5740                     while (@condvals)
5741                     {
5742                         $cond = shift (@condvals);
5743                         local (@val) = split (' ', shift (@condvals));
5744                         &define_pretty_variable ($one_name, $cond, @val);
5745                     }
5746                 }
5747             }
5749             if ($do_clean)
5750             {
5751                 $output_rules .=
5752                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
5753                                                    . $cygxform,
5754                                                    $clean_file);
5756                 push (@clean, $X . $primary);
5757                 &push_phony_cleaners ($X . $primary);
5758             }
5760             if ($X eq 'check')
5761             {
5762                 push (@check, '$(' . $one_name . ')');
5763             }
5764             else
5765             {
5766                 push (@used, '$(' . $one_name . ')');
5767             }
5768             if ($X eq 'noinst' || $X eq 'check')
5769             {
5770                 # Objects which don't get installed by default.
5771                 next;
5772             }
5774             $output_rules .=
5775                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
5776                                                . $ltxform . $cygxform,
5777                                                $file);
5779             push (@uninstall, 'uninstall-' . $X . $primary);
5780             push (@phony, 'uninstall-' . $X . $primary);
5781             push (@installdirs, '$(' . $X . 'dir)');
5782             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
5783             {
5784                 push (@install_exec, 'install-' . $X . $primary);
5785                 push (@phony, 'install-' . $X . $primary);
5786             }
5787             else
5788             {
5789                 push (@install_data, 'install-' . $X . $primary);
5790                 push (@phony, 'install-' . $X . $primary);
5791             }
5792         }
5793     }
5795     if (@used)
5796     {
5797         # Define it.
5798         &define_pretty_variable ($primary, '', @used);
5799         $output_vars .= "\n";
5800     }
5802     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
5803     {
5804         &am_line_error ($require_extra,
5805                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
5806     }
5808     # Push here because PRIMARY might be configure time determined.
5809     push (@all, '$(' . $primary . ')')
5810         if @used;
5812     return (@result);
5816 ################################################################
5818 # This variable is local to the "require file" set of functions.
5819 @require_file_paths = ();
5821 # Verify that the file must exist in the current directory.  Usage:
5822 # require_file (isconfigure, line_number, strictness, file) strictness
5823 # is the strictness level at which this file becomes required.  Must
5824 # set require_file_paths before calling this function.
5825 # require_file_paths is set to hold a single directory (the one in
5826 # which the first file was found) before return.
5827 sub require_file_internal
5829     local ($is_configure, $line, $mystrict, @files) = @_;
5830     local ($file, $fullfile);
5831     local ($found_it, $errfile, $errdir);
5832     local ($save_dir);
5834     foreach $file (@files)
5835     {
5836         $found_it = 0;
5837         foreach $dir (@require_file_paths)
5838         {
5839             if ($dir eq '.')
5840             {
5841                 $fullfile = $relative_dir . "/" . $file;
5842                 $errdir = $relative_dir unless $errdir;
5843             }
5844             else
5845             {
5846                 $fullfile = $dir . "/" . $file;
5847                 $errdir = $dir unless $errdir;
5848             }
5850             # Use different name for "error filename".  Otherwise on
5851             # an error the bad file will be reported as eg
5852             # `../../install-sh' when using the default
5853             # config_aux_path.
5854             $errfile = $errdir . '/' . $file;
5856             if (-f $fullfile)
5857             {
5858                 $found_it = 1;
5859                 # FIXME: Once again, special-case `.'.
5860                 &push_dist_common ($file)
5861                     if $dir eq $relative_dir || $dir eq '.';
5862                 $save_dir = $dir;
5863                 last;
5864             }
5865         }
5867         if ($found_it)
5868         {
5869             # Prune the path list.
5870             @require_file_paths = $save_dir;
5871         }
5872         else
5873         {
5874             if ($strictness >= $mystrict)
5875             {
5876                 local ($trailer) = '';
5877                 local ($suppress) = 0;
5879                 # Only install missing files according to our desired
5880                 # strictness level.
5881                 local ($message) = "required file \`$errfile' not found";
5882                 if ($add_missing)
5883                 {
5884                     $suppress = 1;
5886                     # Maybe run libtoolize.
5887                     if ($seen_libtool
5888                         && grep ($_ eq $file, @libtoolize_files)
5889                         && system ('libtoolize', '--automake'))
5890                     {
5891                         $message = "installing \`$errfile'";
5892                         $suppress = 0;
5893                         $trailer = "; cannot run \`libtoolize': $!";
5894                     }
5895                     elsif (-f ($am_dir . '/' . $file))
5896                     {
5897                         # Install the missing file.  Symlink if we
5898                         # can, copy if we must.  Note: delete the file
5899                         # first, in case it is a dangling symlink.
5900                         $message = "installing \`$errfile'";
5901                         unlink ($errfile);
5902                         if ($symlink_exists)
5903                         {
5904                             if (! symlink ($am_dir . '/' . $file, $errfile))
5905                             {
5906                                 $suppress = 0;
5907                                 $trailer = "; error while making link: $!\n";
5908                             }
5909                         }
5910                         elsif (! system ('cp', $am_dir . '/' . $file, $errfile))
5911                         {
5912                             $suppress = 0;
5913                             $trailer = "\n    error while making link\n";
5914                         }
5915                     }
5916                 }
5918                 local ($save) = $exit_status;
5919                 if ($is_configure)
5920                 {
5921                     # FIXME: allow actual file to be specified.
5922                     &am_conf_line_error ('configure.in', $line,
5923                                          "$message$trailer");
5924                 }
5925                 else
5926                 {
5927                     &am_line_error ($line, "$message$trailer");
5928                 }
5929                 $exit_status = $save if $suppress;
5930             }
5931         }
5932     }
5935 # Like require_file_with_line, but error messages refer to
5936 # configure.in, not the current Makefile.am.
5937 sub require_file_with_conf_line
5939     @require_file_paths = '.';
5940     &require_file_internal (1, @_);
5943 sub require_file_with_line
5945     @require_file_paths = '.';
5946     &require_file_internal (0, @_);
5949 sub require_file
5951     @require_file_paths = '.';
5952     &require_file_internal (0, '', @_);
5955 # Require a file that is also required by Autoconf.  Looks in
5956 # configuration path, as specified by AC_CONFIG_AUX_DIR.
5957 sub require_config_file
5959     @require_file_paths = @config_aux_path;
5960     &require_file_internal (1, '', @_);
5961     local ($dir) = $require_file_paths[0];
5962     @config_aux_path = @require_file_paths;
5963     if ($dir eq '.')
5964     {
5965         $config_aux_dir = '.';
5966     }
5967     else
5968     {
5969         $config_aux_dir = '$(top_srcdir)/' . $dir;
5970     }
5973 # Assumes that the line number is in Makefile.am.
5974 sub require_conf_file_with_line
5976     @require_file_paths = @config_aux_path;
5977     &require_file_internal (0, @_);
5978     local ($dir) = $require_file_paths[0];
5979     @config_aux_path = @require_file_paths;
5980     if ($dir eq '.')
5981     {
5982         $config_aux_dir = '.';
5983     }
5984     else
5985     {
5986         $config_aux_dir = '$(top_srcdir)/' . $dir;
5987     }
5990 # Assumes that the line number is in Makefile.am.
5991 sub require_conf_file_with_conf_line
5993     @require_file_paths = @config_aux_path;
5994     &require_file_internal (1, @_);
5995     local ($dir) = $require_file_paths[0];
5996     @config_aux_path = @require_file_paths;
5997     if ($dir eq '.')
5998     {
5999         $config_aux_dir = '.';
6000     }
6001     else
6002     {
6003         $config_aux_dir = '$(top_srcdir)/' . $dir;
6004     }
6007 ################################################################
6009 # Push a list of files onto dist_common.
6010 sub push_dist_common
6012     local (@files) = @_;
6013     local ($file);
6015     foreach $file (@files)
6016     {
6017         $dist_common{$file} = 1;
6018     }
6021 # Push a list of clean targets onto phony.
6022 sub push_phony_cleaners
6024     local ($base) = @_;
6025     local ($target);
6026     foreach $target ('mostly', 'dist', '', 'maintainer-')
6027     {
6028         push (@phony, $target . 'clean-' . $base);
6029     }
6032 # Set strictness.
6033 sub set_strictness
6035     $strictness_name = $_[0];
6036     if ($strictness_name eq 'gnu')
6037     {
6038         $strictness = $GNU;
6039     }
6040     elsif ($strictness_name eq 'gnits')
6041     {
6042         $strictness = $GNITS;
6043     }
6044     elsif ($strictness_name eq 'foreign')
6045     {
6046         $strictness = $FOREIGN;
6047     }
6048     else
6049     {
6050         die "automake: level \`$strictness_name' not recognized\n";
6051     }
6055 ################################################################
6057 # Return directory name of file.
6058 sub dirname
6060     local ($file) = @_;
6061     local ($sub);
6063     ($sub = $file) =~ s,/+[^/]+$,,g;
6064     $sub = '.' if $sub eq $file;
6065     return $sub;
6068 # Return file name of a file.
6069 sub basename
6071     local ($file) = @_;
6072     local ($sub);
6074     ($sub = $file) =~s,^.*/+,,g;
6075     return $sub;
6078 # Touch a file.
6079 sub touch
6081     local ($file) = @_;
6083     open (TOUCH, ">> $file");
6084     close (TOUCH);
6087 # Glob something.  Do this to avoid indentation screwups everywhere we
6088 # want to glob.  Gross!
6089 sub my_glob
6091     local ($pat) = @_;
6092     return <${pat}>;
6095 ################################################################
6097 # Print an error message and set exit status.
6098 sub am_error
6100     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
6101     $exit_status = 1;
6104 sub am_line_error
6106     local ($symbol, @args) = @_;
6108     if ($symbol && "$symbol" ne '-1')
6109     {
6110         # If SYMBOL not already a line number, look it up in Makefile.am.
6111         if ($symbol =~ /^\d+$/)
6112         {
6113             $symbol .= ': ';
6114         }
6115         elsif (defined $content_lines{$symbol})
6116         {
6117             $symbol = $content_lines{$symbol} . ': ';
6118         }
6119         else
6120         {
6121             # A single space, to provide nice separation.
6122             $symbol = ' ';
6123         }
6124         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
6125         $exit_status = 1;
6126     }
6127     else
6128     {
6129         &am_error (@args);
6130     }
6133 # Like am_error, but while scanning configure.in.
6134 sub am_conf_error
6136     # FIXME: can run in subdirs.
6137     warn "automake: configure.in: ", join (' ', @_), "\n";
6138     $exit_status = 1;
6141 # Error message with line number referring to configure.in.
6142 sub am_conf_line_error
6144     local ($file, $line, @args) = @_;
6146     if ($line)
6147     {
6148         warn "$file: $line: ", join (' ', @args), "\n";
6149         $exit_status = 1;
6150     }
6151     else
6152     {
6153         &am_conf_error (@args);
6154     }
6157 # Tell user where our aclocal.m4 is, but only once.
6158 sub keyed_aclocal_warning
6160     local ($key) = @_;
6161     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
6164 # Print usage information.
6165 sub usage
6167     print "Usage: automake [OPTION] ... [Makefile]...\n\n";
6168     print "Generate Makefile.in for autoconf from Makefile.am\n";
6169     print $USAGE;
6170     print "\nFiles which are automatically distributed, if found:\n";
6171     $~ = "USAGE_FORMAT";
6172     local (@lcomm) = sort ((@common_files, @common_sometimes));
6173     local ($one, $two, $three, $four);
6174     while (@lcomm > 0)
6175     {
6176         $one = shift @lcomm;
6177         $two = @lcomm ? shift @lcomm : '';
6178         $three = @lcomm ? shift @lcomm : '';
6179         $four = @lcomm ? shift @lcomm : '';
6180         write;
6181     }
6183     print "\nReport bugs to <automake-bugs\@gnu.ai.mit.edu>.\n";
6185     exit 0;
6188 format USAGE_FORMAT =
6189   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
6190   $one,               $two,               $three,             $four