don't use $< in non-suffix rules
[automake.git] / automake.in
blob09e978f13d28d1d4e1fff9f9a2901fbbed130e35
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_CYGWIN32.
201 $seen_cygwin32 = 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             $output_rules .= $base . "_.c: $base.c\n\t"
924                 . '$(ANSI2KNR) ' . $base . '.c ' . $base . "_.c\n";
925             push (@objects, $base . '_.o');
926             push (@objects, $base . '_.lo') if $seen_libtool;
927         }
929         # Make all _.o (and _.lo) files depend on ansi2knr.
930         # Use a sneaky little hack to make it print nicely.
931         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
932     }
934     #
935     # Last, handle some C cleanup.
936     #
937     if ($seen_c_source)
938     {
939         &define_configure_variable ('CFLAGS');
940         &define_variable ('COMPILE',
941                           '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)');
942         &define_variable ('LTCOMPILE',
943                           $ltcompile .
944                           '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)')
945             if ($seen_libtool);
946         &define_variable ('LINK', $ltlink . '$(CC) $(CFLAGS) $(LDFLAGS) -o $@');
948         if (! defined $configure_vars{'CC'})
949         {
950             &am_line_error ($seen_c_source,
951                             "C source seen but \`CC' not defined in \`configure.in'");
952         }
953     }
957 # Output a rule to build from a YACC source.  The output from YACC is
958 # compiled with C or C++, depending on the extension of the YACC file.
959 sub output_yacc_build_rule
961     local ($yacc_suffix, $use_ylwrap, $c_suffix) = @_;
963     local ($c_suffix, $suffix);
964     ($c_suffix = $yacc_suffix) =~ tr/y/c/;
965     push (@suffixes, $yacc_suffix, $c_suffix, '.h');
967     # Generate rule for c/c++ and header file.  Probably should only
968     # do header if `yacc -d' is run.  But how can we determine that?
969     foreach $suffix ($c_suffix, '.h')
970     {
971         $output_rules .= "$yacc_suffix$suffix:\n\t";
973         if ($use_ylwrap)
974         {
975             $output_rules .= ('$(SHELL) $(YLWRAP)'
976                               . ' "$(YACC)" $< y.tab.c $*' . $c_suffix
977                               . ' y.tab.h $*.h -- $(YACCFLAGS)');
978         }
979         else
980         {
981             $output_rules .= ('$(YACC) $(YACCFLAGS) $< && mv y.tab.c $@' . "\n"
982                               . "\tif test -f y.tab.h; then \\\n"
983                               . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
984                           . "\telse :; fi");
985         }
986         $output_rules .= "\n";
987     }
990 sub output_lex_build_rule
992     local ($lex_suffix, $use_ylwrap) = @_;
993     local ($c_suffix);
995     ($c_suffix = $lex_suffix) =~ tr/l/c/;
996     push (@suffixes, $lex_suffix);
997     &define_configure_variable ('LEX_OUTPUT_ROOT');
998     &define_configure_variable ('LEXLIB');
999     $output_rules .= "$lex_suffix$c_suffix:\n\t";
1001     if ($use_ylwrap)
1002     {
1003         # Is the $@ correct here?  If so, why not use it in the ylwrap
1004         # build rule for yacc above?
1005         $output_rules .= '$(SHELL) $(YLWRAP)'
1006             . ' "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(LFLAGS)';
1007     }
1008     else
1009     {
1010         $output_rules .= '$(LEX) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
1011     }
1012     $output_rules .= "\n";
1016 # Check to make sure a source defined in LIBOBJS is not explicitly
1017 # mentioned.  This is a separate function (as opposed to being inlined
1018 # in handle_source_transform) because it isn't always appropriate to
1019 # do this check.
1020 sub check_libobjs_sources
1022     local ($one_file, $unxformed) = @_;
1024     local ($prefix, $file, @files);
1025     foreach $prefix ('', 'EXTRA_')
1026     {
1027         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1028         {
1029             @files = &variable_value_as_list (($prefix
1030                                                . $one_file . '_SOURCES'),
1031                                               'all');
1032         }
1033         elsif ($prefix eq '')
1034         {
1035             @files = ($unxformed . '.c');
1036         }
1037         else
1038         {
1039             next;
1040         }
1042         foreach $file (@files)
1043         {
1044             if (defined $libsources{$file})
1045             {
1046                 &am_line_error ($prefix . $one_file . '_SOURCES',
1047                                 "automatically discovered file \`$file' should not be explicitly mentioned");
1048             }
1049         }
1050     }
1053 # Does much of the actual work for handle_source_transform.
1054 # Arguments are:
1055 #   list of source files to transform
1056 # Result is a list
1057 #   first element is name of linker to use (empty string for default linker)
1058 #   remaining elements are names of `.o's
1059 sub handle_single_transform_list
1061     local (@files) = @_;
1062     local ($linker) = '';
1063     local (@result) = ();
1064     local ($nonansi_obj) = $obj;
1065     $nonansi_obj =~ s/_//g;
1066     if (length (@files))
1067     {
1068         # Turn sources into objects.
1069         foreach (@files)
1070         {
1071             # Skip header files, including C++-ish ones.  The list
1072             # of C++ header extensions comes from Emacs 19.32
1073             # etags.
1074             next if /\.[hH]$/;
1075             next if /\.hxx$/;
1076             next if /\.h\+\+$/;
1077             next if /\.hh$/;
1078             next if /\.hpp$/;
1079             # Skip things that look like configure substitutions.
1080             next if /^\@.*\@$/;
1082             # Include appropriate file for lex or yacc source in
1083             # distribution.  If the extension is the regular '.y' or
1084             # '.l', we assume C compilation, and the generated file
1085             # has exension .c.  Otherwise, we compile with C++, and
1086             # make the following association: (yy -> cc, y++ -> c++,
1087             # yxx -> cxx), similarly for .ll, etc.
1088             if (/^(.*)\.(y|yy|y\+\+|yxx)$/)
1089             {
1090                 # Yacc source.
1091                 local ($ext) = $2;
1092                 $ext =~ tr/y/c/;
1093                 &push_dist_common ("$1.$ext");
1094                 $yacc_sources{$_} = 1;
1095             }
1096             elsif (/^(.*)\.(l|ll|l\+\+|lxx)$/)
1097             {
1098                 # Lex source.
1099                 local ($ext) = $2;
1100                 $ext =~ tr/l/c/;
1101                 &push_dist_common ("$1.$ext");
1102                 $lex_sources{$_} = 1;
1103             }
1105             # Strip any directory prefix.
1106             $_ = &basename ($_);
1108             # Transform source files into .o files.  List of C++
1109             # extensions comes from Emacs 19.34 etags.
1110             if (s/\.(c\+\+|cc|cpp|cxx|C)$/$nonansi_obj/)
1111             {
1112                 $cxx_extensions{'.' . $1} = 1;
1113                 $linker = 'CXXLINK';
1114             }
1115             elsif (s/\.(yy|y\+\+|yxx|ll|l\+\+|lxx)$/$nonansi_obj/)
1116             {
1117                 # Compiling lex or yacc with C++
1118                 local ($ext) = $1;
1119                 $ext =~ tr/ly/cc/;
1120                 $cxx_extensions{".$ext"} = 1;
1121                 $linker = 'CXXLINK';
1122             }
1123             elsif (s/\.([Ff]\\|f90\\|for)$/$nonansi_obj/)
1124             {
1125                 # FORTRAN support.  FIXME: not finished.
1126             }
1127             elsif (s/\.[sS]$/$nonansi_obj/)
1128             {
1129                 # .s is assembly.  Just rewrite it.  FIXME: not finished.
1130             }
1131             elsif (defined ($options{'ansi2knr'}) && s/_\.[cly]$/_.c/)
1132             {
1133                 # FIXME include line number in error.
1134                 &am_error ("C source file \`$_' would be deleted by ansi2knr rules");
1135             }
1136             elsif (s/\.[cly]$//)
1137             {
1138                 # .c is C.  .l is lex.  .y is yacc.
1139   
1140                 # Note: first we rewrite (eg) foo.c to foo and push
1141                 # the file onto the list of deansified files.  Then we add
1142                 # $obj, which can either be `_.o', or simply `.o' if
1143                 # deansification is not required.
1144                 $de_ansi_files{$_} = 1;
1145                 $_ .= $obj;
1146                 $seen_c_source = 1;
1147             }
1148             else
1149             {
1150                 # No error message here.  Used to have one, but it was
1151                 # very unpopular.
1152                 next;
1153             }
1155             push (@result, $_);
1157             # Transform .o or $o file into .P file (for automatic
1158             # dependency code).
1159             s/$objpat$/.P/g;
1160             $dep_files{'.deps/' . $_} = 1;
1161         }
1162     }
1164     return ($linker, @result);
1167 # Handle SOURCE->OBJECT transform for one program or library.
1168 # Arguments are:
1169 #   canonical (transformed) name of object to build
1170 #   actual name of object to build
1171 #   object extension (ie either `.o' or `$o'.
1172 # Return result is name of linker variable that must be used.
1173 # Empty return means just use `LINK'.
1174 sub handle_source_transform
1176     # one_file is canonical name.  unxformed is given name.  obj is
1177     # object extension.
1178     local ($one_file, $unxformed, $obj) = @_;
1179     local ($objpat) = $obj;
1180     $objpat =~ s/(\W)/\\$1/g;
1181     # Handle explicit `.o' as well as whatever we're passed.
1182     $objpat = '(' . $objpat . "|\\.o)";
1184     local ($linker) = '';
1186     if (&variable_defined ($one_file . "_OBJECTS"))
1187     {
1188         &am_line_error ($one_file . '_OBJECTS',
1189                         $one_file . '_OBJECTS', 'should not be defined');
1190         # No point in continuing.
1191         return;
1192     }
1194     local (@files, @result, $prefix, $temp);
1195     foreach $prefix ('', 'EXTRA_')
1196     {
1197         @files = ();
1198         local ($var) = $prefix . $one_file . "_SOURCES";
1199         if (&variable_defined ($var))
1200         {
1201             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1202             push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
1203                 unless $prefix eq 'EXTRA_';
1204             local (@conds) = &variable_conditions ($var);
1205             if (! @conds)
1206             {
1207                 @files = &variable_value_as_list ($var, '');
1208             }
1209             else
1210             {
1211                 local ($cond);
1212                 foreach $cond (@conds)
1213                 {
1214                     @files = &variable_value_as_list ($var, $cond);
1215                     ($temp, @result) = &handle_single_transform_list (@files);
1216                     $linker = $temp if $linker eq '';
1217                     &define_pretty_variable ($one_file . "_OBJECTS", $cond,
1218                                              @result)
1219                         unless $prefix eq 'EXTRA_';
1220                 }
1222                 next;
1223             }
1224         }
1225         elsif ($prefix eq '')
1226         {
1227             &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1228             push (@sources, $unxformed . '.c');
1229             push (@objects, $unxformed . $obj);
1230             push (@files, $unxformed . '.c');
1231         }
1233         ($temp, @result) = &handle_single_transform_list (@files);
1234         $linker = $temp if $linker eq '';
1235         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
1236             unless $prefix eq 'EXTRA_';
1237     }
1239     return $linker;
1242 # Handle the BUILT_SOURCES variable.
1243 sub handle_built_sources
1245     return unless &variable_defined ('BUILT_SOURCES');
1247     local (@sources) = &variable_value_as_list ('BUILT_SOURCES', 'all');
1248     local ($s);
1249     foreach $s (@sources)
1250     {
1251         if (/^\@.*\@$/)
1252         {
1253             # FIXME: is this really the right thing to do?
1254             &am_line_error ('BUILT_SOURCES',
1255                             "\`BUILT_SOURCES' should not contain a configure substitution");
1256             last;
1257         }
1258     }
1260     # We don't care about the return value of this function.  We just
1261     # want to make sure to update %dep_files with the contents of
1262     # BUILT_SOURCES.
1263     &handle_single_transform_list (@sources);
1266 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1267 # Also, generate _DEPENDENCIES variable if appropriate.
1268 # Arguments are:
1269 #   transformed name of object being built, or empty string if no object
1270 #   name of _LDADD/_LIBADD-type variable to examine
1271 #   boolean (lex_seen) which is true if a lex source file was seen in this
1272 #     object.  valid only for LDADDs, not LIBADDs.  If set, LEXLIB
1273 #     must be in LDADD.
1274 # Returns 1 if LIBOBJS seen, 0 otherwise.
1275 sub handle_lib_objects
1277     local ($xname, $var, $lex_seen) = @_;
1278     local ($ret);
1280     die "automake: programming error 1 in handle_lib_objects\n"
1281         if ! &variable_defined ($var);
1283     die "automake: programming error 2 in handle_lib_objects\n"
1284         if $lex_seen && $var =~ /LIBADD/;
1286     local (@conds) = &variable_conditions ($var);
1287     if (! @conds)
1288     {
1289         $ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
1290     }
1291     else
1292     {
1293         local ($cond);
1294         $ret = 0;
1295         foreach $cond (@conds)
1296         {
1297             if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
1298             {
1299                 $ret = 1;
1300             }
1301         }
1302     }
1304     return $ret;
1307 # Subroutine of handle_lib_objects: handle a particular condition.
1308 sub handle_lib_objects_cond
1310     local ($xname, $var, $lex_seen, $cond) = @_;
1312     # We recognize certain things that are commonly put in LIBADD or
1313     # LDADD.
1314     local ($lsearch);
1315     local (@dep_list) = ();
1317     # If no lex source seen, just assume this is ok.
1318     local ($lex_ok) = $lex_seen ? 0 : 1;
1320     local ($seen_libobjs) = 0;
1321     local ($flagvar) = 0;
1323     foreach $lsearch (&variable_value_as_list ($var, $cond))
1324     {
1325         # Skip -lfoo and -Ldir; these are explicitly allowed.
1326         next if $lsearch =~ /^-[lL]/;
1327         if (! $flagvar && $lsearch =~ /^-/)
1328         {
1329             if ($var =~ /^(.*)LDADD$/)
1330             {
1331                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1332             }
1333             else
1334             {
1335                 # Only get this error once.
1336                 $flagvar = 1;
1337                 &am_line_error ($var, "you cannot use linker flags such as \`$lsearch' in \`$var'");
1338             }
1339         }
1341         # Assume we have a file of some sort, and push it onto the
1342         # dependency list.  Autoconf substitutions are not pushed;
1343         # rarely is a new dependency substituted into (eg) foo_LDADD
1344         # -- but "bad things (eg -lX11) are routinely substituted.
1345         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1346         # and handled specially below.
1347         push (@dep_list, $lsearch)
1348             unless $lsearch =~ /^\@.*\@$/;
1350         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1351         # means adding entries to dep_files.
1352         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1353         {
1354             push (@dep_list, $lsearch);
1355             $seen_libobjs = 1;
1356             if (! keys %libsources)
1357             {
1358                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
1359             }
1361             local ($iter, $rewrite);
1362             foreach $iter (keys %libsources)
1363             {
1364                 if ($iter =~ /\.[cly]$/)
1365                 {
1366                     $seen_c_source = $var;
1367                 }
1369                 if ($iter =~ /\.h$/)
1370                 {
1371                     &require_file_with_line ($var, $FOREIGN, $iter);
1372                 }
1373                 elsif ($iter ne 'alloca.c')
1374                 {
1375                     ($rewrite = $iter) =~ s/\.c$/.P/;
1376                     $dep_files{'.deps/' . $rewrite} = 1;
1377                     &require_file_with_line ($var, $FOREIGN, $iter);
1378                 }
1379             }
1380         }
1381         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1382         {
1383             push (@dep_list, $lsearch);
1384             &am_line_error ($var,
1385                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
1386                 if ! defined $libsources{'alloca.c'};
1387             $dep_files{'.deps/alloca.P'} = 1;
1388             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1389             $seen_c_source = $var;
1390         }
1391         elsif ($lsearch eq '@LEXLIB@')
1392         {
1393             # FIXME: variable_value_as_list requires us to force
1394             # @LEXLIB@ here, where we'd really prefer $(LEXLIB).
1395             # Nasty -- this will have to wait until many cleanups are
1396             # made, I think.
1397             $lex_ok = 1;
1398         }
1399     }
1401     if (! $lex_ok)
1402     {
1403         &am_line_error ($var, 'lex source file used without @LEXLIB@');
1404     }
1406     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
1407     {
1408         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
1409     }
1411     return $seen_libobjs;
1414 # Canonicalize a name, and check to make sure the non-canonical name
1415 # is never used.  Returns canonical name.  Arguments are name and a
1416 # list of suffixes to check for.
1417 sub check_canonical_spelling
1419     local ($name, @suffixes) = @_;
1420     local ($xname, $xt);
1422     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
1423     if ($xname ne $name)
1424     {
1425         local ($xt);
1426         foreach $xt (@suffixes)
1427         {
1428             &am_line_error ($name . $xt,
1429                             "invalid variable \`" . $name . $xt
1430                             . "'; should be \`" . $xname . $xt . "'")
1431                 if &variable_defined ($name . $xt);
1432         }
1433     }
1435     return $xname;
1438 # Handle C programs.
1439 sub handle_programs
1441     local (@proglist) = &am_install_var ('-clean',
1442                                          'progs', 'PROGRAMS',
1443                                          'bin', 'sbin', 'libexec', 'pkglib',
1444                                          'noinst', 'check');
1445     return if ! @proglist;
1447     # If a program is installed, this is required.  We only want this
1448     # error to appear once.
1449     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1450         unless $seen_arg_prog;
1451     $seen_arg_prog = 1;
1453     local ($one_file, $xname, $munge);
1455     local ($seen_libobjs) = 0;
1456     foreach $one_file (@proglist)
1457     {
1458         local ($obj) = &get_object_extension ($one_file);
1460         # Canonicalize names and check for misspellings.
1461         $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
1462                                             '_SOURCES', '_OBJECTS',
1463                                             '_DEPENDENCIES');
1465         # FIXME: Using a trick to figure out if any lex sources appear
1466         # in our program; should use some cleaner method.
1467         local ($lex_num) = scalar (keys %lex_sources);
1468         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1469         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1471         local ($xt) = '';
1472         if (&variable_defined ($xname . "_LDADD"))
1473         {
1474             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1475                                      $lex_file_seen))
1476             {
1477                 $seen_libobjs = 1;
1478             }
1479             $lex_file_seen = 0;
1480             $xt = '_LDADD';
1481         }
1482         else
1483         {
1484             # User didn't define prog_LDADD override.  So do it.
1485             &define_variable ($xname . '_LDADD', '$(LDADD)');
1487             # This does a bit too much work.  But we need it to
1488             # generate _DEPENDENCIES when appropriate.
1489             if (&variable_defined ('LDADD'))
1490             {
1491                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1492                 {
1493                     $seen_libobjs = 1;
1494                 }
1495                 $lex_file_seen = 0;
1496             }
1497             $xt = '_SOURCES'
1498         }
1500         if (&variable_defined ($xname . '_LIBADD'))
1501         {
1502             &am_line_error ($xname . '_LIBADD',
1503                             "use \`" . $xname . "_LDADD', not \`"
1504                             . $xname . "_LIBADD'");
1505         }
1507         if (! &variable_defined ($xname . '_LDFLAGS'))
1508         {
1509             # Define the prog_LDFLAGS variable.
1510             &define_variable ($xname . '_LDFLAGS', '');
1511         }
1513         if ($lex_file_seen)
1514         {
1515             &am_line_error ($xname . $xt,
1516                             'lex source file used without @LEXLIB@');
1517         }
1519         # Determine program to use for link.
1520         local ($xlink);
1521         if (&variable_defined ($xname . '_LINK'))
1522         {
1523             $xlink = $xname . '_LINK';
1524         }
1525         else
1526         {
1527             $xlink = $linker ? $linker : 'LINK';
1528         }
1530         local ($cygxform);
1531         if (! $seen_cygwin32)
1532         {
1533             $cygxform = 's/^CYGWIN.*$//; s/^NOTCYGWIN//;';
1534         }
1535         else
1536         {
1537             $cygxform = 's/^NOTCYGWIN.*$//; s/^CYGWIN//;';
1538         }
1540         $output_rules .=
1541             &file_contents_with_transform
1542                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1543                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1544                  . 's/\@XLINK\@/' . $xlink . '/go;'
1545                  . $cygxform,
1546                  'program');
1547     }
1549     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1550     {
1551         $seen_libobjs = 1;
1552     }
1554     if ($seen_libobjs)
1555     {
1556         foreach $one_file (@proglist)
1557         {
1558             # Canonicalize names.
1559             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1561             if (&variable_defined ($xname . '_LDADD'))
1562             {
1563                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1564             }
1565             elsif (&variable_defined ('LDADD'))
1566             {
1567                 &check_libobjs_sources ($xname, 'LDADD');
1568             }
1569         }
1570     }
1574 # Handle libraries.
1575 sub handle_libraries
1577     local (@liblist) = &am_install_var ('-clean',
1578                                         'libs', 'LIBRARIES',
1579                                         'lib', 'pkglib', 'noinst', 'check');
1580     return if ! @liblist;
1582     local (%valid) = &am_primary_prefixes ('LIBRARIES', 'lib', 'pkglib',
1583                                            'noinst', 'check');
1584     if (! defined $configure_vars{'RANLIB'})
1585     {
1586         local ($key);
1587         foreach $key (keys %valid)
1588         {
1589             if (&variable_defined ($key . '_LIBRARIES'))
1590             {
1591                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1592                 # Only get this error once.
1593                 $configure_vars{'RANLIB'} = 1;
1594                 last;
1595             }
1596         }
1597     }
1599     local ($onelib);
1600     local ($munge);
1601     local ($xlib);
1602     local ($seen_libobjs) = 0;
1603     foreach $onelib (@liblist)
1604     {
1605         # Check that the library fits the standard naming convention.
1606         if ($onelib !~ /^lib.*\.a$/)
1607         {
1608             # FIXME this should only be a warning for foreign packages
1609             # FIXME should put line number here.  That means mapping
1610             # from library name back to variable name.
1611             &am_error ("\`$onelib' is not a standard library name");
1612         }
1614         local ($obj) = &get_object_extension ($onelib);
1616         # Canonicalize names and check for misspellings.
1617         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
1618                                            '_OBJECTS', '_DEPENDENCIES');
1620         if (&variable_defined ($xlib . '_LIBADD'))
1621         {
1622             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1623             {
1624                 $seen_libobjs = 1;
1625             }
1626         }
1627         else
1628         {
1629             # Generate support for conditional object inclusion in
1630             # libraries.
1631             &define_variable ($xlib . "_LIBADD", '');
1632         }
1634         if (&variable_defined ($xlib . '_LDADD'))
1635         {
1636             &am_line_error ($xlib . '_LDADD',
1637                             "use \`" . $xlib . "_LIBADD', not \`"
1638                             . $xlib . "_LDADD'");
1639         }
1641         &handle_source_transform ($xlib, $onelib, $obj);
1643         $output_rules .=
1644             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1645                                            . 's/\@XLIBRARY\@/'
1646                                            . $xlib . '/go;',
1647                                            'library');
1648     }
1650     if ($seen_libobjs)
1651     {
1652         foreach $onelib (@liblist)
1653         {
1654             # Canonicalize names.
1655             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1656             if (&variable_defined ($xlib . '_LIBADD'))
1657             {
1658                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1659             }
1660         }
1661     }
1663     &define_variable ('AR', 'ar');
1664     &define_configure_variable ('RANLIB');
1667 # Handle shared libraries.
1668 sub handle_ltlibraries
1670     local (@liblist) = &am_install_var ('-clean',
1671                                         'ltlib', 'LTLIBRARIES',
1672                                         'lib', 'pkglib');
1673     return if ! @liblist;
1675     local (%instdirs);
1676     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 'lib', 'pkglib');
1678     local ($key);
1679     foreach $key (keys %valid)
1680     {
1681         if (&variable_defined ($key . '_LTLIBRARIES'))
1682         {
1683             if (!$seen_libtool)
1684             {
1685                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
1686                 # Only get this error once.
1687                 $configure_vars{'LIBTOOL'} = 1;
1688                 $seen_libtool = 1;
1689             }
1691             # Get the installation directory of each library.
1692             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
1693             {
1694                 if ($instdirs{$_})
1695                 {
1696                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1697                 }
1698                 else
1699                 {
1700                     $instdirs{$_} = $key;
1701                 }
1702             }
1703         }
1704     }
1706     local ($onelib);
1707     local ($munge);
1708     local ($xlib);
1709     local ($seen_libobjs) = 0;
1710     foreach $onelib (@liblist)
1711     {
1712         # Check that the library fits the standard naming convention.
1713         if ($onelib !~ /^lib.*\.la$/)
1714         {
1715             # FIXME this should only be a warning for foreign packages
1716             # FIXME should put line number here.  That means mapping
1717             # from library name back to variable name.
1718             &am_error ("\`$onelib' is not a standard libtool library name");
1719         }
1721         local ($obj) = &get_object_extension ($onelib);
1723         # Canonicalize names and check for misspellings.
1724         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
1725                                            '_SOURCES', '_OBJECTS',
1726                                            '_DEPENDENCIES');
1728         if (! &variable_defined ($xlib . '_LDFLAGS'))
1729         {
1730             # Define the lib_LDFLAGS variable.
1731             &define_variable ($xlib . '_LDFLAGS', '');
1732         }
1734         if (&variable_defined ($xlib . '_LIBADD'))
1735         {
1736             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1737             {
1738                 $seen_libobjs = 1;
1739             }
1740         }
1741         else
1742         {
1743             # Generate support for conditional object inclusion in
1744             # libraries.
1745             &define_variable ($xlib . "_LIBADD", '');
1746         }
1748         if (&variable_defined ($xlib . '_LDADD'))
1749         {
1750             &am_line_error ($xlib . '_LDADD',
1751                             "use \`" . $xlib . "_LIBADD', not \`"
1752                             . $xlib . "_LDADD'");
1753         }
1755         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
1757         # Determine program to use for link.
1758         local ($xlink);
1759         if (&variable_defined ($xlib . '_LINK'))
1760         {
1761             $xlink = $xlib . '_LINK';
1762         }
1763         else
1764         {
1765             $xlink = $linker ? $linker : 'LINK';
1766         }
1768         local ($rpath);
1769         if ($instdirs{$onelib} eq 'EXTRA')
1770         {
1771             # It's an EXTRA_ library, so we can't specify -rpath.
1772             # Yuck.
1773             $rpath = 's/\@RPATH\@//go;';
1774         }
1775         else
1776         {
1777             $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
1778                       . 'dir)/go;');
1779         }
1781         $output_rules .=
1782             &file_contents_with_transform ('s/\@LTLIBRARY\@/'
1783                                            . $onelib . '/go;'
1784                                            . 's/\@XLTLIBRARY\@/'
1785                                            . $xlib . '/go;'
1786                                            . $rpath
1787                                            . 's/\@XLINK\@/' . $xlink . '/go;',
1788                                            'ltlibrary');
1789     }
1791     if ($seen_libobjs)
1792     {
1793         foreach $onelib (@liblist)
1794         {
1795             # Canonicalize names.
1796             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1797             if (&variable_defined ($xlib . '_LIBADD'))
1798             {
1799                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1800             }
1801         }
1802     }
1805 # See if any _SOURCES variable were misspelled.  Also, make sure that
1806 # EXTRA_ variables don't contain configure substitutions.
1807 sub check_typos
1809     local ($varname, $primary);
1810     foreach $varname (keys %contents)
1811     {
1812         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
1813                           '_DEPENDENCIES')
1814         {
1815             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
1816             {
1817                 &am_line_error ($varname,
1818                                 "invalid unused variable name: \`$varname'");
1819             }
1820         }
1821     }
1824 # Handle scripts.
1825 sub handle_scripts
1827     # NOTE we no longer automatically clean SCRIPTS, because it is
1828     # useful to sometimes distribute scripts verbatim.  This happens
1829     # eg in Automake itself.
1830     &am_install_var ('scripts', 'SCRIPTS',
1831                      'bin', 'sbin', 'libexec', 'pkgdata',
1832                      'noinst', 'check');
1834     # Set $scripts_installed if appropriate.  Make sure we only find
1835     # scripts which are actually installed -- this is why we can't
1836     # simply use the return value of am_install_var.
1837     local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
1838                                            'libexec', 'pkgdata',
1839                                            'noinst', 'check');
1840     local ($key);
1841     foreach $key (keys %valid)
1842     {
1843         if ($key ne 'noinst'
1844             && $key ne 'check'
1845             && &variable_defined ($key . '_SCRIPTS'))
1846         {
1847             $scripts_installed = 1;
1848             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
1849         }
1850     }
1852     if ($scripts_installed)
1853     {
1854         # If a program is installed, this is required.  We only want this
1855         # error to appear once.
1856         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1857             unless $seen_arg_prog;
1858         $seen_arg_prog = 1;
1859     }
1862 # Search a file for a "version.texi" Texinfo include.  Return the name
1863 # of the include file if found, or the empty string if not.  A
1864 # "version.texi" file is actually any file whose name matches
1865 # "vers*.texi".
1866 sub scan_texinfo_file
1868     local ($filename) = @_;
1870     if (! open (TEXI, $filename))
1871     {
1872         &am_error ("couldn't open \`$filename': $!");
1873         return '';
1874     }
1875     print "automake: reading $filename\n" if $verbose;
1877     local ($vfile, $outfile);
1878     while (<TEXI>)
1879     {
1880         if (/^\@setfilename +(\S+)/)
1881         {
1882             $outfile = $1;
1883             last if ($vfile);
1884         }
1886         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
1887         {
1888             # Found version.texi include.
1889             $vfile = $1;
1890             last if $outfile;
1891         }
1892     }
1894     close (TEXI);
1895     return ($outfile, $vfile);
1898 # Handle all Texinfo source.
1899 sub handle_texinfo
1901     &am_line_error ('TEXINFOS',
1902                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
1903         if &variable_defined ('TEXINFOS');
1904     return if (! &variable_defined ('info_TEXINFOS')
1905                && ! &variable_defined ('html_TEXINFOS'));
1907     local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');
1909     local (@info_deps_list, @dvis_list, @texi_deps);
1910     local ($infobase, $info_cursor);
1911     local (%versions);
1912     local ($done) = 0;
1913     local ($vti);
1914     local ($tc_cursor, @texi_cleans);
1915     local ($canonical);
1917     foreach $info_cursor (@texis)
1918     {
1919         ($infobase = $info_cursor) =~ s/\.texi(nfo)?$//;
1921         # If 'version.texi' is referenced by input file, then include
1922         # automatic versioning capability.
1923         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
1924                                                         . "/" . $info_cursor);
1926         if ($out_file eq '')
1927         {
1928             &am_error ("\`$info_cursor' missing \@setfilename");
1929             next;
1930         }
1932         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
1933         {
1934             # FIXME should report line number in input file.
1935             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
1936             next;
1937         }
1939         if ($vtexi)
1940         {
1941             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
1942                 if (defined $versions{$vtexi});
1943             $versions{$vtexi} = $info_cursor;
1945             # We number the stamp-vti files.  This is doable since the
1946             # actual names don't matter much.  We only number starting
1947             # with the second one, so that the common case looks nice.
1948             $vti = 'vti' . ($done ? $done : '');
1949             &push_dist_common ($vtexi, 'stamp-' . $vti);
1950             push (@clean, $vti);
1952             # Only require once.
1953             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
1954                                           'mdate-sh')
1955                 if ! $done;
1956             ++$done;
1958             local ($conf_pat);
1959             ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
1960             $output_rules .=
1961                 &file_contents_with_transform
1962                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
1963                      . 's/\@VTI\@/' . $vti . '/g; '
1964                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
1965                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
1966                      'texi-vers');
1968             &push_phony_cleaners ($vti);
1969         }
1971         # If user specified file_TEXINFOS, then use that as explicit
1972         # dependency list.
1973         @texi_deps = ();
1974         push (@texi_deps, $info_cursor);
1975         push (@texi_deps, $vtexi) if $vtexi;
1977         # Canonicalize name first.
1978         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
1979         if (&variable_defined ($canonical . "_TEXINFOS"))
1980         {
1981             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
1982             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
1983         }
1985         $output_rules .= ("\n" . $out_file . ": "
1986                           . join (' ', @texi_deps)
1987                           . "\n" . $infobase . ".dvi: "
1988                           . join (' ', @texi_deps)
1989                           . "\n\n");
1991         push (@info_deps_list, $out_file);
1992         push (@dvis_list, $infobase . '.dvi');
1994         # Generate list of things to clean for this target.  We do
1995         # this explicitly because otherwise too many things could be
1996         # removed.  In particular the ".log" extension might
1997         # reasonably be used in other contexts by the user.
1998         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
1999                             'ky', 'log', 'pg', 'toc', 'tp', 'tps',
2000                             'vr', 'vrs', 'op', 'tr', 'cv')
2001         {
2002             push (@texi_cleans, $infobase . '.' . $tc_cursor);
2003         }
2004     }
2006     # Find these programs wherever they may lie.  Yes, this has
2007     # intimate knowledge of the structure of the texinfo distribution.
2008     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
2009                               'makeinfo',
2010                               # Circumlocution to avoid accidental
2011                               # configure substitution.
2012                               '@MAKE' . 'INFO@');
2013     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
2014                               'texi2dvi');
2016     # Set transform for including texinfos.am.  First, handle --cygnus
2017     # stuff.
2018     local ($xform);
2019     if ($cygnus_mode)
2020     {
2021         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
2022     }
2023     else
2024     {
2025         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
2026     }
2028     # Handle location of texinfo.tex.
2029     if ($cygnus_mode)
2030     {
2031         &define_variable ('TEXINFO_TEX',
2032                           '$(top_srcdir)/../texinfo/texinfo.tex');
2033     }
2034     elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
2035     {
2036         &define_variable ('TEXINFO_TEX', $config_aux_dir . '/texinfo.tex');
2037     }
2038     elsif (! &variable_defined ('TEXINFO_TEX'))
2039     {
2040         &define_variable ('TEXINFO_TEX', '$(srcdir)/texinfo.tex');
2041     }
2042     local ($xxform) = &dirname (&variable_value ('TEXINFO_TEX'));
2043     $xxform =~ s/(\W)/\\$1/g;
2044     $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';
2046     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
2047     push (@phony, 'install-info-am', 'uninstall-info');
2048     push (@dist_targets, 'dist-info');
2050     # How to clean.  The funny name is due to --cygnus influence; in
2051     # Cygnus mode, `clean-info' is a target that users can use.
2052     $output_rules .= "\nmostlyclean-aminfo:\n";
2053     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
2054     $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
2055                       . "maintainer-clean-aminfo:\n\t"
2056                       # Eww.  But how else can we find all the output
2057                       # files from makeinfo?
2058                       . 'for i in $(INFO_DEPS); do' . " \\\n"
2059                       . "\t" . '  rm -f $$i;' . " \\\n"
2060                       . "\t" . '  if test "`echo $$i-[0-9]*`" = "$$i-[0-9]*"; then' . " \\\n"
2061                       . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
2062                       . "\t" . '  fi;' . " \\\n"
2063                       . "\tdone\n");
2064     &push_phony_cleaners ('aminfo');
2065     if ($cygnus_mode)
2066     {
2067         $output_rules .= "clean-info: mostlyclean-aminfo\n";
2068     }
2070     push (@suffixes, '.texi', '.texinfo', '.info', '.dvi', '.ps');
2072     if (! defined $options{'no-installinfo'})
2073     {
2074         push (@uninstall, 'uninstall-info');
2075         push (@installdirs, '$(infodir)');
2076         unshift (@install_data, 'install-info-am');
2078         # Make sure documentation is made and installed first.  Use
2079         # $(INFO_DEPS), not 'info', because otherwise recursive makes
2080         # get run twice during "make all".
2081         unshift (@all, '$(INFO_DEPS)');
2082     }
2083     push (@clean, 'aminfo');
2084     push (@info, '$(INFO_DEPS)');
2085     push (@dvi, '$(DVIS)');
2087     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2088     &define_variable ("DVIS", join (' ', @dvis_list));
2089     # This next isn't strictly needed now -- the places that look here
2090     # could easily be changed to look in info_TEXINFOS.  But this is
2091     # probably better, in case noinst_TEXINFOS is ever supported.
2092     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
2094     # Do some error checking.  Note that this file is not required
2095     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2096     # up above.
2097     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
2098         unless (defined $options{'no-texinfo.tex'}
2099                 || &variable_defined ('TEXINFO_TEX'));
2102 # Handle any man pages.
2103 sub handle_man_pages
2105     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
2106         if &variable_defined ('MANS');
2107     return if ! &variable_defined ('man_MANS');
2109     # We generate the manpage install code by hand to avoid the use of
2110     # basename in the generated Makefile.
2111     local (@mans) = &variable_value_as_list ('man_MANS', 'all');
2112     local (%sections, %inames, %mbases, %secmap, %fullsecmap);
2113     local ($i) = 1;
2114     foreach (@mans)
2115     {
2116         # FIXME: statement without effect:
2117         /^(.*)\.([0-9])([a-z]*)$/;
2118         $sections{$2} = 1;
2119         $inames{$i} = $_;
2120         $mbases{$i} = $1;
2121         $secmap{$i} = $2;
2122         $fullsecmap{$i} = $2 . $3;
2123         $i++;
2124     }
2126     # We don't really need this, but we use it in case we ever want to
2127     # support noinst_MANS.
2128     &define_variable ("MANS", &variable_value ('man_MANS'));
2130     # Generate list of install dirs.
2131     $output_rules .= "install-man: \$(MANS)\n";
2132     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
2133     # Sort keys so that output is deterministic.
2134     foreach (sort keys %sections)
2135     {
2136         push (@installdirs, '$(mandir)/man' . $_)
2137             unless defined $options{'no-installman'};
2138         $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
2139                           . $_ . "\n");
2140     }
2141     push (@phony, 'install-man');
2143     # Generate install target.
2144     local ($key);
2145     foreach $key (sort keys %inames)
2146     {
2147         $_ = $install_man_format;
2148         s/\@SECTION\@/$secmap{$key}/g;
2149         s/\@MAN\@/$inames{$key}/g;
2150         s/\@FULLSECT\@/$fullsecmap{$key}/g;
2151         s/\@MANBASE\@/$mbases{$key}/g;
2152         $output_rules .= $_;
2153     }
2154     $output_rules .= "\n";
2156     $output_rules .= "uninstall-man:\n\t\$(NORMAL_UNINSTALL)\n";
2157     foreach $key (sort keys %inames)
2158     {
2159         $_ = $uninstall_man_format;
2160         s/\@SECTION\@/$secmap{$key}/g;
2161         s/\@MAN\@/$inames{$key}/g;
2162         s/\@FULLSECT\@/$fullsecmap{$key}/g;
2163         s/\@MANBASE\@/$mbases{$key}/g;
2164         $output_rules .= $_;
2165     }
2166     $output_rules .= "\n";
2167     push (@phony, 'uninstall-man');
2169     $output_vars .= &file_contents ('mans-vars');
2171     if (! defined $options{'no-installman'})
2172     {
2173         push (@install_data, 'install-man');
2174         push (@uninstall, 'uninstall-man');
2175         push (@all, '$(MANS)');
2176     }
2179 # Handle DATA variables.
2180 sub handle_data
2182     &am_install_var ('data', 'DATA', 'data', 'sysconf',
2183                      'sharedstate', 'localstate', 'pkgdata',
2184                      'noinst', 'check');
2187 # Handle TAGS.
2188 sub handle_tags
2190     push (@phony, 'tags');
2191     local (@tag_deps) = ();
2192     if (&variable_defined ('SUBDIRS'))
2193     {
2194         $output_rules .= ("tags-recursive:\n"
2195                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
2196                           # Never fail here if a subdir fails; it
2197                           # isn't important.
2198                           . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
2199                           . "\tdone\n");
2200         push (@tag_deps, 'tags-recursive');
2201         push (@phony, 'tags-recursive');
2202     }
2204     if ($dir_holds_sources
2205         || $dir_holds_headers
2206         || &variable_defined ('ETAGS_ARGS')
2207         || @tag_deps)
2208     {
2209         local ($xform) = '';
2210         local ($one_hdr);
2211         foreach $one_hdr (@config_headers)
2212         {
2213             if ($relative_dir eq &dirname ($one_hdr))
2214             {
2215                 # The config header is in this directory.  So require it.
2216                 local ($var);
2217                 ($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
2218                 $xform .= ' ' if $xform;
2219                 $xform .= $var;
2220             }
2221         }
2222         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
2223                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
2225         if (&variable_defined ('SUBDIRS'))
2226         {
2227             $xform .= 's/^SUBDIRS//;';
2228         }
2229         else
2230         {
2231             $xform .= 's/^SUBDIRS.*$//;';
2232         }
2234         $output_rules .= &file_contents_with_transform ($xform, 'tags');
2235         $output_rules .= &file_contents ('tags-clean');
2236         push (@clean, 'tags');
2237         &push_phony_cleaners ('tags');
2238         &examine_variable ('TAGS_DEPENDENCIES');
2239     }
2240     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2241     {
2242         &am_line_error ('TAGS_DEPENDENCIES',
2243                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2244     }
2245     else
2246     {
2247         # Every Makefile must define some sort of TAGS rule.
2248         # Otherwise, it would be possible for a top-level "make TAGS"
2249         # to fail because some subdirectory failed.
2250         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2251     }
2254 # Worker for handle_dist.
2255 sub handle_dist_worker
2257     local ($makefile) = @_;
2259     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
2261     # Initialization; only at top level.
2262     if ($relative_dir eq '.')
2263     {
2264         if ($strictness >= $GNITS)
2265         {
2266             # For Gnits users, this is pretty handy.  Look at 15 lines
2267             # in case some explanatory text is desirable.
2268             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
2269           echo "NEWS not updated; not releasing" 1>&2; \\
2270           exit 1; \\
2271         fi
2273         }
2276         # Create dist directory.
2277         $output_rules .= ("\trm -rf \$(distdir)\n"
2278                           . "\tmkdir \$(distdir)\n"
2279                           . "\t-chmod 777 \$(distdir)\n");
2280     }
2282     # Only run automake in `dist' target if --include-deps and
2283     # `no-dependencies' not specified.  That way the recipient of a
2284     # distribution can run "make dist" and not need Automake.  You
2285     # might be wondering why we run automake once for each directory
2286     # we distribute, instead of running it once at the top level.  The
2287     # answer is that we want to run automake after the dependencies
2288     # have been generated.  This occurs when "make" is run in the
2289     # subdir.  So automake must be run after make has updated the
2290     # Makefile, which means that it must run once per directory.
2291     if ($use_dependencies)
2292     {
2293         $output_rules .=
2294             (
2295              # We need an absolute path for --output-dir.  Thus the
2296              # weirdness.
2297              "\t" . 'here=`cd $(top_builddir) && pwd`; ' . "\\\n"
2298              . "\t" . 'top_distdir=`cd $(top_distdir) && pwd`; ' . "\\\n"
2299              . "\tcd \$(top_srcdir) \\\n"
2300              . "\t  && \$(AUTOMAKE) --include-deps --build-dir=\$\$here --srcdir-name=\$(top_srcdir) --output-dir=\$\$top_distdir "
2301              # Set strictness of output.
2302              . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2303              . ($cmdline_use_dependencies ? '' : ' --include-deps')
2304              . " " . $makefile . "\n"
2305              );
2306     }
2308     # Scan EXTRA_DIST to see if we need to distribute anything from a
2309     # subdir.  If so, add it to the list.  I didn't want to do this
2310     # originally, but there were so many requests that I finally
2311     # relented.
2312     local (@dist_dirs);
2313     if (&variable_defined ('EXTRA_DIST'))
2314     {
2315         # FIXME: This should be fixed to work with conditionals.  That
2316         # will require only making the entries in @dist_dirs under the
2317         # appropriate condition.  This is meaningful if the nature of
2318         # the distribution should depend upon the configure options
2319         # used.
2320         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
2321         {
2322             next if /^\@.*\@$/;
2323             next unless s,/+[^/]+$,,;
2324             push (@dist_dirs, $_)
2325                 unless $_ eq '.';
2326         }
2327     }
2328     if (@dist_dirs)
2329     {
2330         # Prepend $(distdir) to each directory given.  Doing it via a
2331         # hash lets us ensure that each directory is used only once.
2332         local (%dhash);
2333         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
2334         $output_rules .= "\t";
2335         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
2336     }
2338     # In loop, test for file existence because sometimes a file gets
2339     # included in DISTFILES twice.  For example this happens when a
2340     # single source file is used in building more than one program.
2341     # Also, there are situations in which "ln" can fail.  For instance
2342     # a file to distribute could actually be a cross-filesystem
2343     # symlink -- this can easily happen if "gettextize" was run on the
2344     # distribution.
2345     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
2346     if ($cygnus_mode)
2347     {
2348         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
2349     }
2350     else
2351     {
2352         $output_rules .= "\t  d=\$(srcdir); \\\n";
2353     }
2354     $output_rules .= '    test -f $(distdir)/$$file \\
2355           || ln $$d/$$file $(distdir)/$$file 2> /dev/null \\
2356           || cp -p $$d/$$file $(distdir)/$$file; \\
2357         done
2360     # If we have SUBDIRS, create all dist subdirectories and do
2361     # recursive build.
2362     if (&variable_defined ('SUBDIRS'))
2363     {
2364         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
2365         # to all possible directories, and use it.
2366         if (! &variable_conditions ('SUBDIRS'))
2367         {
2368             $dist_subdir_name = 'SUBDIRS';
2369         }
2370         else
2371         {
2372             $dist_subdir_name = 'DIST_SUBDIRS';
2373             if (! &variable_defined ('DIST_SUBDIRS'))
2374             {
2375                 &define_pretty_variable ('DIST_SUBDIRS', '',
2376                                          &variable_value_as_list ('SUBDIRS',
2377                                                                   'all'));
2378             }
2379         }
2381         # Test for directory existence here because previous automake
2382         # invocation might have created some directories.  Note that
2383         # we explicitly set distdir for the subdir make; that lets us
2384         # mix-n-match many automake-using packages into one large
2385         # package, and have "dist" at the top level do the right
2386         # thing.
2387         $output_rules .= '      for subdir in $(' . $dist_subdir_name . '); do          \\
2388           test -d $(distdir)/$$subdir           \\
2389           || mkdir $(distdir)/$$subdir          \\
2390           || exit 1;                            \\
2391           chmod 777 $(distdir)/$$subdir;        \\
2392           (cd $$subdir && $(MAKE) top_distdir=../$(top_distdir) distdir=../$(distdir)/$$subdir distdir) \\
2393             || exit 1; \\
2394         done
2396     }
2398     # If the target `dist-hook' exists, make sure it is run.  This
2399     # allows users to do random weird things to the distribution
2400     # before it is packaged up.
2401     push (@dist_targets, 'dist-hook') if defined $contents{'dist-hook'};
2403     local ($targ);
2404     foreach $targ (@dist_targets)
2405     {
2406         # We must explicitly set distdir and top_distdir for these
2407         # sub-makes.
2408         $output_rules .= "\t\$(MAKE) top_distdir=\"\$(top_distdir)\" distdir=\"\$(distdir)\" $targ\n";
2409     }
2411     push (@phony, 'distdir');
2414 # Handle 'dist' target.
2415 sub handle_dist
2417     local ($makefile) = @_;
2419     # Set up maint_charset.
2420     $local_maint_charset = &variable_value ('MAINT_CHARSET')
2421         if &variable_defined ('MAINT_CHARSET');
2422     $maint_charset = $local_maint_charset
2423         if $relative_dir eq '.';
2425     if (&variable_defined ('DIST_CHARSET'))
2426     {
2427         &am_line_error ('DIST_CHARSET',
2428                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2429             if ! $local_maint_charset;
2430         if ($relative_dir eq '.')
2431         {
2432             $dist_charset = &variable_value ('DIST_CHARSET')
2433         }
2434         else
2435         {
2436             &am_line_error ('DIST_CHARSET',
2437                             "DIST_CHARSET can only be defined at top level");
2438         }
2439     }
2441     # Look for common files that should be included in distribution.
2442     local ($cfile);
2443     foreach $cfile (@common_files)
2444     {
2445         if (-f ($relative_dir . "/" . $cfile))
2446         {
2447             &push_dist_common ($cfile);
2448         }
2449     }
2451     # Keys of %dist_common are names of files to distributed.  We put
2452     # README first because it then becomes easier to make a
2453     # Usenet-compliant shar file (in these, README must be first).
2454     # FIXME: do more ordering of files here.
2455     local (@coms);
2456     if (defined $dist_common{'README'})
2457     {
2458         push (@coms, 'README');
2459         delete $dist_common{'README'};
2460     }
2461     push (@coms, sort keys %dist_common);
2463     &define_pretty_variable ("DIST_COMMON", '', @coms);
2464     $output_vars .= "\n";
2466     # Some boilerplate.
2467     $output_vars .= &file_contents ('dist-vars') . "\n";
2468     &define_variable ('TAR', $TAR);
2469     &define_variable ('GZIP', '--best');
2471     # Put these things in rules section so it is easier for whoever
2472     # reads Makefile.in.
2473     if (! &variable_defined ('distdir'))
2474     {
2475         if ($relative_dir eq '.')
2476         {
2477             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2478         }
2479         else
2480         {
2481             $output_rules .= ("\n"
2482                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2483                               . "\n");
2484         }
2485     }
2486     if ($relative_dir eq '.')
2487     {
2488         $output_rules .= "top_distdir = \$(distdir)\n\n";
2489     }
2490     else
2491     {
2492         $output_rules .= "\nsubdir = " . $relative_dir . "\n\n";
2493     }
2495     # Generate 'dist' target, and maybe dist-shar / dist-zip / dist-tarZ.
2496     if ($relative_dir eq '.')
2497     {
2498         # Rule to check whether a distribution is viable.
2499         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
2500 # it guarantees that the distribution is self-contained by making another
2501 # tarfile.
2502 distcheck: dist
2503         rm -rf $(distdir)
2504         GZIP=$(GZIP) $(TAR) zxf $(distdir).tar.gz
2505         mkdir $(distdir)/=build
2506         mkdir $(distdir)/=inst
2507         dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
2508                           . (defined $contents{'distcheck-hook'}
2509                              ? "\t\$(MAKE) distcheck-hook"
2510                              : '')
2511                           . '
2512         cd $(distdir)/=build \\
2513           && ../configure '
2515                           . ($seen_gettext ? '--with-included-gettext ' : '')
2516                           . '--srcdir=.. --prefix=$$dc_install_base \\
2517           && $(MAKE) \\
2518           && $(MAKE) dvi \\
2519           && $(MAKE) check \\
2520           && $(MAKE) install \\
2521           && $(MAKE) installcheck \\
2522           && $(MAKE) dist
2523         rm -rf $(distdir)
2524         @echo "========================"; \\
2525         echo "$(distdir).tar.gz is ready for distribution"; \\
2526         echo "========================"
2529         local ($dist_all) = ('dist-all: distdir' . "\n"
2530                              . $dist_header);
2531         local ($curs);
2532         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ')
2533         {
2534             if (defined $options{$curs} || $curs eq 'dist')
2535             {
2536                 $output_rules .= ($curs . ': distdir' . "\n"
2537                                   . $dist_header
2538                                   . $dist{$curs}
2539                                   . $dist_trailer);
2540                 $dist_all .= $dist{$curs};
2541             }
2542         }
2543         $output_rules .= $dist_all . $dist_trailer;
2544     }
2546     # Generate distdir target.
2547     &handle_dist_worker ($makefile);
2550 # Scan a single dependency file and rewrite the dependencies as
2551 # appropriate.  Essentially this means:
2552 # * Clean out absolute dependencies which are not desirable.
2553 # * Rewrite other dependencies to be relative to $(top_srcdir).
2554 sub scan_dependency_file
2556     local ($depfile) = @_;
2558     if (! open (DEP_FILE, $depfile))
2559     {
2560         &am_error ("couldn't open \`$depfile': $!");
2561         return;
2562     }
2563     print "automake: reading $depfile\n" if $verbose;
2565     # Sometimes it is necessary to omit some dependencies.
2566     local (%omit) = %omit_dependencies;
2567     if (&variable_defined ('OMIT_DEPENDENCIES'))
2568     {
2569         # FIXME: Doesn't work with conditionals.  I'm not sure if this
2570         # matters.
2571         grep ($omit{$_} = 1,
2572               &variable_value_as_list ('OMIT_DEPENDENCIES', ''));
2573     }
2575     local ($first_line) = 1;
2576     local ($last_line) = 0;
2577     local ($target, @dependencies);
2578     local ($one_dep, $xform);
2579     local ($just_file);
2581     local ($srcdir_rx, $fixup_rx);
2582     ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
2583         =~ s/(\W)/\\$1/g;
2584     ($srcdir_rx = $srcdir_name . '/') =~ s/(\W)/\\$1/g;
2586     local ($rewrite_builddir) = (($top_builddir eq '.')
2587                                  ? ''
2588                                  : $top_builddir . '/');
2590     while (<DEP_FILE>)
2591     {
2592         if ($last_line)
2593         {
2594             # If LAST_LINE set then we've already seen what we thought
2595             # was the last line.
2596             goto bad_format;
2597         }
2598         next if (/$WHITE_PATTERN/o);
2599         chop;
2600         if (! s/\\$//)
2601         {
2602             # No trailing "\" means this should be the last line.
2603             $last_line = 1;
2604         }
2606         if ($first_line)
2607         {
2608             if (! /^([^:]+:)(.+)$/)
2609             {
2610               bad_format:
2611                 &am_error ("\`$depfile' has incorrect format");
2612                 close (DEP_FILE);
2613                 return;
2614             }
2616             $_ = $2;
2617             # Make sure to strip the .P file from the target.
2618             ($target = $1) =~ s, *\.deps/[^.]+\.P,,;
2620             $first_line = 0;
2621         }
2623         foreach $one_dep (split (' ', $_))
2624         {
2625             if ($one_dep =~ /^$fixup_rx/)
2626             {
2627                 # The dependency points to the current directory in
2628                 # some way.
2629                 ($xform = $one_dep) =~ s/^$fixup_rx//;
2630                 push (@dependencies, $xform);
2631             }
2632             elsif ($one_dep =~ /^$srcdir_rx/)
2633             {
2634                 # The dependency is in some other directory in the package.
2635                 ($xform = $one_dep) =~ s/^$srcdir_rx/$rewrite_builddir/;
2636                 push (@dependencies, $xform);
2637             }
2638             elsif ($one_dep =~ /^\//)
2639             {
2640                 # Absolute path; ignore.
2641             }
2642             else
2643             {
2644                 # Anything else is assumed to be correct.  But first
2645                 # make sure it is not on our list of dependencies to
2646                 # omit.
2647                 ($just_file = $one_dep) =~ s,^.*/,,;
2648                 push (@dependencies, $one_dep)
2649                     if ! defined $omit{$just_file};
2650             }
2651         }
2652     }
2654     &pretty_print_rule ($target, "\t", @dependencies);
2656     close (DEP_FILE);
2659 # Handle auto-dependency code.
2660 sub handle_dependencies
2662     if ($use_dependencies)
2663     {
2664         # Include GNU-make-specific auto-dep code.  Don't include it
2665         # if DEP_FILES would be empty.
2666         if ($dir_holds_sources && keys %dep_files)
2667         {
2668             &define_pretty_variable ('DEP_FILES', '', sort keys %dep_files);
2669             $output_rules .= &file_contents ('depend');
2670             push (@clean, 'depend');
2671             &push_phony_cleaners ('depend');
2672             $output_rules .=
2673                 &file_contents_with_transform ('s/\@EXT\@/.c/g;'
2674                                                . 's/\@MKDEP\@/MKDEP/g;'
2675                                                . 's/^ONLYC//g;',
2676                                                'depend2');
2677             local ($ext);
2678             local ($need_cxx) = 0;
2679             foreach $ext (sort keys %cxx_extensions)
2680             {
2681                 $output_rules .=
2682                     &file_contents_with_transform ('s/\@EXT\@/' . $ext .'/g;'
2683                                                    . 's/\@MKDEP\@/CXXMKDEP/g;'
2684                                                    . 's/^ONLYC.*$//;',
2685                                                    'depend2');
2686                 $need_cxx = 1;
2687             }
2688             if ($need_cxx)
2689             {
2690                 &define_variable ('CXXMKDEP', '$(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
2691             }
2692         }
2693     }
2694     elsif ($build_directory ne '')
2695     {
2696         # Include any auto-generated deps that are present.  Note that
2697         # $build_directory ends in a "/".
2698         if (-d ($build_directory . $relative_dir . "/.deps")
2699             && -f ($build_directory . $relative_dir . "/.deps/.P"))
2700         {
2701             local ($depfile);
2703             foreach $depfile (&my_glob ($build_directory
2704                                         . $relative_dir . "/.deps/*.P"))
2705             {
2706                 &scan_dependency_file ($depfile);
2707             }
2709             $output_rules .= "\n";
2710         }
2711     }
2714 # Handle subdirectories.
2715 sub handle_subdirs
2717     return if ! &variable_defined ('SUBDIRS');
2719     # Make sure each directory mentioned in SUBDIRS actually exists.
2720     local ($dir);
2721     foreach $dir (&variable_value_as_list ('SUBDIRS', 'all'))
2722     {
2723         # Skip directories substituted by configure.
2724         next if $dir =~ /^\@.*\@$/;
2726         if (! -d $am_relative_dir . '/' . $dir)
2727         {
2728             &am_line_error ('SUBDIRS',
2729                             "required directory $am_relative_dir/$dir does not exist");
2730             next;
2731         }
2733         &am_line_error ('SUBDIRS', "directory should not contain \`/'")
2734             if $dir =~ /\//;
2735     }
2737     local ($xform) = ('s/\@INSTALLINFO\@/' .
2738                       (defined $options{'no-installinfo'}
2739                        ? 'install-info-recursive'
2740                        : '')
2741                       . '/;');
2742     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
2744     # Push a bunch of phony targets.
2745     local ($phonies);
2746     foreach $phonies ('-data', '-exec', 'dirs')
2747     {
2748         push (@phony, 'install' . $phonies . '-recursive');
2749         push (@phony, 'uninstall' . $phonies . '-recursive');
2750     }
2751     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
2752     {
2753         push (@phony, $phonies . '-recursive');
2754     }
2755     &push_phony_cleaners ('recursive');
2757     push (@check_tests, "check-recursive");
2758     push (@installcheck, "installcheck-recursive");
2759     push (@info, "info-recursive");
2760     push (@dvi, "dvi-recursive");
2762     $recursive_install = 1;
2765 # Handle aclocal.m4.
2766 sub handle_aclocal_m4
2768     local ($regen_aclocal) = 0;
2769     if (-f 'aclocal.m4')
2770     {
2771         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
2772         &push_dist_common ('aclocal.m4');
2774         if (open (ACLOCAL, '< aclocal.m4'))
2775         {
2776             local ($line);
2777             $line = <ACLOCAL>;
2778             close (ACLOCAL);
2780             if ($line =~ 'generated automatically by aclocal')
2781             {
2782                 $regen_aclocal = 1;
2783             }
2784         }
2785     }
2787     local ($acinclude) = 0;
2788     if (-f 'acinclude.m4')
2789     {
2790         $regen_aclocal = 1;
2791         $acinclude = 1;
2792     }
2794     # Note that it might be possible that aclocal.m4 doesn't exist but
2795     # should be auto-generated.  This case probably isn't very
2796     # important.
2797     if ($regen_aclocal)
2798     {
2799         local (@ac_deps) = (
2800                             ($seen_maint_mode ? "\@MAINT\@" : "") ,
2801                             "configure.in",
2802                             ($acinclude ? ' acinclude.m4' : '')
2803                             );
2805         # Scan all -I directories for m4 files.  These are our
2806         # dependencies.
2807         if (&variable_defined ('ACLOCAL_AMFLAGS'))
2808         {
2809             local ($amdir);
2810             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
2811             {
2812                 if ($amdir =~ s/^-I//
2813                     && $amdir !~ /^\//
2814                     && -d $amdir)
2815                 {
2816                     push (@ac_deps, &my_glob ($am_dir . '/*.m4'));
2817                 }
2818             }
2819         }
2821         &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
2823         $output_rules .=  ("\t"
2824                            . 'cd $(srcdir) && $(ACLOCAL)'
2825                            . (&variable_defined ('ACLOCAL_AMFLAGS')
2826                               ? ' $(ACLOCAL_AMFLAGS)' : '')
2827                            . "\n");
2828     }
2831 # Rewrite a list of input files into a form suitable to put on a
2832 # dependency list.  The idea is that if an input file has a directory
2833 # part the same as the current directory, then the directory part is
2834 # simply removed.  But if the directory part is different, then
2835 # $(top_srcdir) is prepended.  Among other things, this is used to
2836 # generate the dependency list for the output files generated by
2837 # AC_OUTPUT.  Consider what the dependencies should look like in this
2838 # case:
2839 #   AC_OUTPUT(src/out:src/in1:lib/in2)
2840 sub rewrite_inputs_into_dependencies
2842     local (@inputs) = @_;
2843     local ($single, @newinputs);
2845     foreach $single (@inputs)
2846     {
2847         if (&dirname ($single) eq $relative_dir)
2848         {
2849             push (@newinputs, &basename ($single));
2850         }
2851         else
2852         {
2853             push (@newinputs, '$(top_srcdir)/' . $single);
2854         }
2855     }
2857     return @newinputs;
2860 # Handle remaking and configure stuff.
2861 # We need the name of the input file, to do proper remaking rules.
2862 sub handle_configure
2864     local ($local, $input, @secondary_inputs) = @_;
2866     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
2867     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
2868         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
2870     local ($top_reldir);
2872     local ($input_base) = &basename ($input);
2873     local ($local_base) = &basename ($local);
2875     local ($amfile) = $input_base . '.am';
2876     # We know we can always add '.in' because it really should be an
2877     # error if the .in was missing originally.
2878     local ($infile) = '$(srcdir)/' . $input_base . '.in';
2879     local ($colon_infile);
2880     if ($local ne $input)
2881     {
2882         $colon_infile = ':' . $input . '.in';
2883     }
2884     $colon_infile .= ':' . join (':', @secondary_inputs)
2885         if @secondary_inputs;
2887     local (@rewritten) = &rewrite_inputs_into_dependencies (@secondary_inputs);
2888     # This rule remakes the Makefile.in.  Note use of @MAINT@ forces
2889     # us to abandon pretty-printing.  Sigh.
2890     $output_rules .= ($infile
2891                       # NOTE perl 5.003 (with -w) gives a
2892                       # uninitialized value error on the next line.
2893                       # Don't know why.
2894                       . ': '
2895                       . ($seen_maint_mode ? '@MAINT@ ' : '')
2896                       . $amfile . ' '
2897                       . '$(top_srcdir)/configure.in $(ACLOCAL_M4) '
2898                       . join (' ', @rewritten) . "\n"
2899                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
2900                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2901                       . ($cmdline_use_dependencies ? '' : ' --include-deps')
2902                       . ' ' . $input . $colon_infile . "\n\n");
2904     # This rule remakes the Makefile.
2905     $output_rules .= ($local_base
2906                       # NOTE: bogus uninit value error on next line;
2907                       # see comment above.
2908                       . ': '
2909                       . $infile . ' '
2910                       . '$(top_builddir)/config.status'
2911                       # NOTE: Makefile only depends on BUILT_SOURCES
2912                       # when dependencies are being computed.  This is
2913                       # a workaround for an obscure bug with
2914                       # AC_LINK_FILES.  Anyway, when dependencies are
2915                       # turned off, this shouldn't matter.
2916                       . ($use_dependencies ? ' $(BUILT_SOURCES)' : '')
2917                       . "\n"
2918                       . "\tcd \$(top_builddir) \\\n"
2919                       . "\t  && CONFIG_FILES="
2920                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
2921                       . $colon_infile
2922                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
2923                       . "\n\n");
2925     if ($relative_dir ne '.')
2926     {
2927         # In subdirectory.
2928         $top_reldir = '../';
2929     }
2930     else
2931     {
2932         &handle_aclocal_m4;
2933         $output_rules .= &file_contents ('remake');
2934         &examine_variable ('CONFIGURE_DEPENDENCIES');
2935         $top_reldir = '';
2936     }
2938     # If we have a configure header, require it.
2939     local ($one_hdr);
2940     local (@local_fullnames) = @config_fullnames;
2941     local (@local_names) = @config_names;
2942     local ($hdr_index) = 0;
2943     local ($distclean_config) = '';
2944     foreach $one_hdr (@config_headers)
2945     {
2946         local ($one_fullname) = shift (@local_fullnames);
2947         local ($one_name) = shift (@local_names);
2948         $hdr_index += 1;
2949         if ($relative_dir eq &dirname ($one_hdr))
2950         {
2951             local ($ch_sans_dir) = &basename ($one_hdr);
2952             local ($cn_sans_dir) = &basename ($one_name);
2954             &require_file_with_conf_line ($config_header_line,
2955                                           $FOREIGN, $ch_sans_dir);
2957             # Header defined and in this directory.
2958             local (@files);
2959             if (-f $relative_dir . '/acconfig.h')
2960             {
2961                 push (@files, 'acconfig.h');
2962             }
2963             if (-f $one_name . '.top')
2964             {
2965                 push (@files, "${cn_sans_dir}.top");
2966             }
2967             if (-f $one_name . '.bot')
2968             {
2969                 push (@files, "${cn_sans_dir}.bot");
2970             }
2972             &push_dist_common (@files);
2974             local ($stamp_name) = 'stamp-h';
2975             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
2977             local ($xform) = '';
2979             $xform = 's,\@FILES\@,' . join (' ', @files) . ',;';
2980             $xform .= 's,\@CONFIG_HEADER\@,' . "${cn_sans_dir}" . ',;';
2981             $xform .= 's,\@CONFIG_HEADER_IN\@,' . "${ch_sans_dir}" . ',;';
2982             $xform .= 's,\@CONFIG_HEADER_FULL\@,' . "${one_fullname}" . ',;';
2983             $xform .= 's,\@STAMP\@,' . "${stamp_name}" . ',;';
2985             $output_rules .= &file_contents_with_transform ($xform,
2986                                                             'remake-hdr');
2988             &touch ($relative_dir . "/${stamp_name}.in");
2989             &require_file_with_conf_line ($config_header_line, $FOREIGN,
2990                                           "${stamp_name}.in");
2992             $distclean_config .= ' ' if $distclean_config;
2993             $distclean_config .= $cn_sans_dir;
2994         }
2995     }
2997     if ($distclean_config)
2998     {
2999         $output_rules .= &file_contents_with_transform ('s,\@FILES\@,'
3000                                                         . $distclean_config
3001                                                         . ',;',
3002                                                         'clean-hdr');
3003         push (@clean, 'hdr');
3004         &push_phony_cleaners ('hdr');
3005     }
3007     # Set location of mkinstalldirs.
3008     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
3009     {
3010         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
3011                                             . '/mkinstalldirs'));
3012     }
3013     else
3014     {
3015         &define_variable ('mkinstalldirs',
3016                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
3017     }
3019     &am_line_error ('CONFIG_HEADER',
3020                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
3021         if &variable_defined ('CONFIG_HEADER');
3023     local ($one_name);
3024     local ($config_header) = '';
3025     foreach $one_name (@config_names)
3026     {
3027         # Generate CONFIG_HEADER define.
3028         local ($one_hdr);
3029         if ($relative_dir eq &dirname ($one_name))
3030         {
3031             $one_hdr = &basename ($one_name);
3032         }
3033         else
3034         {
3035             $one_hdr = "${top_builddir}/${one_name}";
3036         }
3038         $config_header .= ' ' if $config_header;
3039         $config_header .= $one_hdr;
3040     }
3041     if ($config_header)
3042     {
3043         &define_variable ("CONFIG_HEADER", $config_header);
3044     }
3046     # Now look for other files in this directory which must be remade
3047     # by config.status, and generate rules for them.
3048     local (@actual_other_files) = ();
3049     local ($file, $local);
3050     local (@inputs, @rewritten_inputs, $single);
3051     foreach $file (@other_input_files)
3052     {
3053         if ($file =~ /^(.*):(.*)$/)
3054         {
3055             # This is the ":" syntax of AC_OUTPUT.
3056             $file = $1;
3057             $local = &basename ($file);
3058             @inputs = split (':', $2);
3059             @rewritten_inputs = &rewrite_inputs_into_dependencies (@inputs);
3060         }
3061         else
3062         {
3063             # Normal usage.
3064             $local = &basename ($file);
3065             @inputs = ($local . '.in');
3066             @rewritten_inputs =
3067                 &rewrite_inputs_into_dependencies ($file . '.in');
3068         }
3070         # Skip files not in this directory.
3071         next unless &dirname ($file) eq $relative_dir;
3073         # Skip any file that is an automake input.
3074         next if -f $file . '.am';
3076         # Some users have been tempted to put `stamp-h' in the
3077         # AC_OUTPUT line.  This won't do the right thing, so we
3078         # explicitly fail here.
3079         if ($local eq 'stamp-h')
3080         {
3081             # FIXME: allow real filename.
3082             &am_conf_error ('configure.in', $ac_output_line,
3083                             'stamp-h should not appear in AC_OUTPUT');
3084             next;
3085         }
3087         $output_rules .= ($local . ': '
3088                           . '$(top_builddir)/config.status '
3089                           . join (' ', @rewritten_inputs) . "\n"
3090                           . "\t"
3091                           . 'cd $(top_builddir) && CONFIG_FILES='
3092                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3093                           . '$@' . (length (@rewritten_inputs) > 0
3094                                     ? (':' . join (':', @rewritten_inputs))
3095                                     : '')
3096                           . ' CONFIG_HEADERS= ./config.status'
3097                           . "\n");
3098         push (@actual_other_files, $local);
3100         # Require all input files.
3101         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3102                                       @inputs);
3103     }
3105     # These files get removed by "make clean".
3106     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3109 # Handle C headers.
3110 sub handle_headers
3112     $dir_holds_headers = &am_install_var ('header', 'HEADERS', 'include',
3113                                           'oldinclude', 'pkginclude',
3114                                           'noinst', 'check');
3117 sub handle_gettext
3119     return if ! $seen_gettext || $relative_dir ne '.';
3121     if (! &variable_defined ('SUBDIRS'))
3122     {
3123         &am_conf_error
3124             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
3125         return;
3126     }
3128     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
3129         if $seen_gettext;
3131     if (&variable_defined ('SUBDIRS'))
3132     {
3133         &am_line_error
3134             ('SUBDIRS',
3135              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
3136                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
3137         &am_line_error
3138             ('SUBDIRS',
3139              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
3140                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
3141     }
3143     # Ensure that each language in ALL_LINGUAS has a .po file, and
3144     # each po file is mentioned in ALL_LINGUAS.
3145     if ($seen_linguas)
3146     {
3147         local (%linguas) = ();
3148         grep ($linguas{$_} = 1, split (' ', $all_linguas));
3150         foreach (<po/*.po>)
3151         {
3152             s/^po\///;
3153             s/\.po$//;
3155             &am_line_error ($all_linguas_line,
3156                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
3157                 if ! $linguas{$_};
3158         }
3160         foreach (keys %linguas)
3161         {
3162             &am_line_error ($all_linguas_line,
3163                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
3164                 if ! -f "po/$_.po";
3165         }
3166     }
3167     else
3168     {
3169         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
3170     }
3173 # Handle footer elements.
3174 sub handle_footer
3176     if ($contents{'SOURCES'})
3177     {
3178         # NOTE don't use define_pretty_variable here, because
3179         # $contents{...} is already defined.
3180         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
3181     }
3182     if ($contents{'OBJECTS'})
3183     {
3184         # NOTE don't use define_pretty_variable here, because
3185         # $contents{...} is already defined.
3186         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
3187     }
3188     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
3189     {
3190         $output_vars .= "\n";
3191     }
3193     if (&variable_defined ('SUFFIXES'))
3194     {
3195         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
3196         # make do not like variable substitutions on the .SUFFIXES
3197         # line.
3198         push (@suffixes, &variable_value_as_list ('SUFFIXES', ''));
3199     }
3200     if (&target_defined ('.SUFFIXES'))
3201     {
3202         &am_line_error ('.SUFFIXES',
3203                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
3204     }
3206     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3207     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3208     # anything else, by sticking it right after the default: target.
3209     $output_header .= ".SUFFIXES:\n";
3210     if (@suffixes)
3211     {
3213         # Make sure suffixes has unique elements.  Sort them to ensure
3214         # the output remains consistent.
3215         local (%suffixes);
3217         grep ($suffixes{$_} = 1, @suffixes);
3219         $output_header .= (".SUFFIXES: "
3220                            . join (' ', sort keys %suffixes)
3221                            . "\n");
3222     }
3223     $output_trailer .= &file_contents ('footer');
3226 # Deal with installdirs target.
3227 sub handle_installdirs
3229     # GNU Makefile standards recommend this.
3230     $output_rules .= ("installdirs:"
3231                       . ($recursive_install
3232                          ? " installdirs-recursive\n"
3233                          : "\n"));
3234     push (@phony, 'installdirs');
3235     if (@installdirs)
3236     {
3237         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
3238                             @installdirs);
3239     }
3240     $output_rules .= "\n";
3243 # There are several targets which need to be merged.  This is because
3244 # their complete definition is compiled from many parts.  Note that we
3245 # avoid double colon rules, otherwise we'd use them instead.
3246 sub handle_merge_targets
3248     local ($makefile) = @_;
3250     # There are a few install-related variables that you should not define.
3251     local ($var);
3252     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
3253     {
3254         if (&variable_defined ($var))
3255         {
3256             &am_line_error ($var, "\`$var' should not be defined");
3257         }
3258     }
3260     # Put this at the beginning for the sake of non-GNU makes.  This
3261     # is still wrong if these makes can run parallel jobs.  But it is
3262     # right enough.
3263     unshift (@all, &basename ($makefile));
3265     local ($one_name);
3266     foreach $one_name (@config_names)
3267     {
3268         push (@all, &basename ($one_name))
3269             if &dirname ($one_name) eq $relative_dir;
3270     }
3272     &do_one_merge_target ('info', @info);
3273     &do_one_merge_target ('dvi', @dvi);
3274     &do_check_merge_target;
3275     &do_one_merge_target ('installcheck', @installcheck);
3277     if (defined $options{'no-installinfo'})
3278     {
3279         # FIXME: this is kind of a hack; should find another way to
3280         # know that this is required.
3281         local (@dirs);
3282         if (grep ($_ eq 'install-info-am', @phony))
3283         {
3284             push (@dirs, 'install-info-am');
3285         }
3286         if (&variable_defined ('SUBDIRS'))
3287         {
3288             push (@dirs, 'install-info-recursive');
3289         }
3290         &do_one_merge_target ('install-info', @dirs);
3291     }
3293     # Handle the various install targets specially.  We do this so
3294     # that (eg) "make install-exec" will run "install-exec-recursive"
3295     # if required, but "make install" won't run it twice.  Step one is
3296     # to see if the user specified local versions of any of the
3297     # targets we handle.  "all" is treated as one of these since
3298     # "install" can run it.
3299     push (@install_exec, 'install-exec-local')
3300         if defined $contents{'install-exec-local'};
3301     push (@install_data, 'install-data-local')
3302         if defined $contents{'install-data-local'};
3303     push (@uninstall, 'uninstall-local')
3304         if defined $contents{'uninstall-local'};
3305     local ($utarg);
3306     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3307                     'uninstall-exec-local', 'uninstall-exec-hook')
3308     {
3309         if (defined $contents{$utarg})
3310         {
3311             local ($x);
3312             ($x = $utarg) =~ s/(data|exec)-//;
3313             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3314         }
3315     }
3316     push (@all, 'all-local')
3317         if defined $contents{'all-local'};
3319     if (defined $contents{'install-local'})
3320     {
3321         &am_line_error ('install-local',
3322                         "use \`install-data' or \`install-exec', not \`install'");
3323     }
3325     # Step two: if we are doing recursive makes, write out the
3326     # appropriate rules.
3327     local (@install);
3328     if ($recursive_install)
3329     {
3330         push (@install, 'install-recursive');
3332         if (@all)
3333         {
3334             local (@hackall) = ();
3335             local ($one_name);
3336             local ($local_headers) = '';
3337             foreach $one_name (@config_names)
3338             {
3339                 if (&dirname ($one_name) eq $relative_dir)
3340                 {
3341                     $local_headers .= ' ' if $local_headers;
3342                     $local_headers .= &basename ($one_name);
3343                 }
3344             }
3345             if ($local_headers)
3346             {
3348                 # This is kind of a hack, but I couldn't see a better
3349                 # way to handle it.  In this particular case, we need
3350                 # to make sure config.h is built before we recurse.
3351                 # We can't do this by changing the order of
3352                 # dependencies to the "all" because that breaks when
3353                 # using parallel makes.  Instead we handle things
3354                 # explicitly.
3355                 $output_rules .= ("all-recursive-am: ${local_headers}"
3356                                   . "\n\t" . '$(MAKE) all-recursive'
3357                                   . "\n\n");
3358                 push (@hackall, 'all-recursive-am');
3359                 push (@phony, 'all-recursive-am');
3360             }
3361             else
3362             {
3363                 push (@hackall, 'all-recursive');
3364             }
3366             $output_rules .= ('all-am: '
3367                               . join (' ', @all)
3368                               . "\n\n");
3369             @all = @hackall;
3370             push (@all, 'all-am');
3371             push (@phony, 'all-am');
3372         }
3373         else
3374         {
3375             @all = ('all-recursive');
3377             # Must always generate `all-am' target, so it can be
3378             # referred to elsewhere.
3379             $output_rules .= "all-am:\n";
3380         }
3381         if (@install_exec)
3382         {
3383             $output_rules .= ('install-exec-am: '
3384                               . join (' ', @install_exec)
3385                               . "\n\n");
3386             @install_exec = ('install-exec-recursive', 'install-exec-am');
3387             push (@install, 'install-exec-am');
3388             push (@phony, 'install-exec-am');
3389         }
3390         else
3391         {
3392             @install_exec = ('install-exec-recursive');
3393         }
3394         if (@install_data)
3395         {
3396             $output_rules .= ('install-data-am: '
3397                               . join (' ', @install_data)
3398                               . "\n\n");
3399             @install_data = ('install-data-recursive', 'install-data-am');
3400             push (@install, 'install-data-am');
3401             push (@phony, 'install-data-am');
3402         }
3403         else
3404         {
3405             @install_data = ('install-data-recursive');
3406         }
3407         if (@uninstall)
3408         {
3409             $output_rules .= ('uninstall-am: '
3410                               . join (' ', @uninstall)
3411                               . "\n\n");
3412             @uninstall = ('uninstall-recursive', 'uninstall-am');
3413             push (@phony, 'uninstall-am');
3414         }
3415         else
3416         {
3417             @uninstall = ('uninstall-recursive');
3418         }
3419     }
3421     # Step three: print definitions users can use.  Code below knows
3422     # that install-exec is done before install-data, beware.
3423     $output_rules .= ("install-exec: "
3424                       . join (' ', @install_exec)
3425                       . "\n");
3426     $output_rules .= "\t\@\$(NORMAL_INSTALL)\n";
3427     if (defined $contents{'install-exec-hook'})
3428     {
3429         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
3430     }
3431     $output_rules .= "\n";
3432     push (@install, 'install-exec') if !$recursive_install;
3433     push (@phony, 'install-exec');
3435     $output_rules .= ("install-data: "
3436                       . join (' ', @install_data)
3437                       . "\n");
3438     $output_rules .= "\t\@\$(NORMAL_INSTALL)\n";
3439     if (defined $contents{'install-data-hook'})
3440     {
3441         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
3442     }
3443     $output_rules .= "\n";
3444     push (@install, 'install-data') if !$recursive_install;
3445     push (@phony, 'install-data');
3447     # If no dependencies for 'install', add 'all'.  Why?  That way
3448     # "make install" at top level of distclean'd distribution won't
3449     # fail because stuff in 'lib' fails to build.
3450     if (! @install || (scalar (@install) == 2
3451                        && $install[0] eq 'install-exec'
3452                        && $install[1] eq 'install-data'))
3453     {
3454         push (@install, 'all');
3455     }
3456     $output_rules .= ('install: '
3457                       . join (' ', @install)
3458                       # Use "@:" as empty command so nothing prints.
3459                       . "\n\t\@:"
3460                       . "\n\n"
3461                       . 'uninstall: '
3462                       . join (' ', @uninstall)
3463                       . "\n\n");
3464     push (@phony, 'install', 'uninstall');
3466     $output_rules .= ('all: '
3467                       . join (' ', @all)
3468                       . "\n\n");
3469     push (@phony, 'all');
3471     # Generate the new 'install-strip' target.  Must set
3472     # INSTALL_SCRIPT to avoid stripping scripts.
3473     $output_rules .= ("install-strip:\n\t"
3474                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' INSTALL_SCRIPT=\'$(INSTALL_PROGRAM)\' install'
3475                       . "\n");
3478 # Helper for handle_merge_targets.
3479 sub do_one_merge_target
3481     local ($name, @values) = @_;
3483     if (defined $contents{$name . '-local'})
3484     {
3485         # User defined local form of target.  So include it.
3486         push (@values, $name . '-local');
3487         push (@phony, $name . '-local');
3488     }
3490     &pretty_print_rule ($name . ":", "\t\t", @values);
3491     push (@phony, $name);
3494 # Handle check merge target specially.
3495 sub do_check_merge_target
3497     if (defined $contents{'check-local'})
3498     {
3499         # User defined local form of target.  So include it.
3500         push (@check_tests, 'check-local');
3501         push (@phony, 'check-local');
3502     }
3504     # In --cygnus mode, check doesn't depend on all.
3505     if (! $cygnus_mode)
3506     {
3507         if (! &variable_defined ('SUBDIRS'))
3508         {
3509             # 'check' must depend on `all', but not when doing
3510             # recursive build.
3511             unshift (@check, 'all');
3512         }
3513         else
3514         {
3515             # When subdirs are used, do the `all' build and then do
3516             # all the recursive stuff.  Actually use `all-am' because
3517             # it doesn't recurse; we rely on the check target in the
3518             # subdirs to do the required builds there.
3519             unshift (@check, 'all-am');
3520         }
3521     }
3523     # The check target must depend on the local equivalent of `all',
3524     # to ensure all the primary targets are built.  Also it must
3525     # depend on the test code named in @check.
3526     &pretty_print_rule ('check:', "\t\t", @check);
3528     # Now the check rules must explicitly run anything named in
3529     # @check_tests.  This is done via a separate make invocation to
3530     # avoid problems with parallel makes.  Every time I write code
3531     # like this I wonder: how could you invent a parallel make and not
3532     # provide any real synchronization facilities?
3533     &pretty_print_rule ("\t\$(MAKE)", "\t  ", @check_tests);
3536 # Handle all 'clean' targets.
3537 sub handle_clean
3539     push (@clean, 'generic');
3540     $output_rules .= &file_contents ('clean');
3541     &push_phony_cleaners ('generic');
3543     local ($target) = $recursive_install ? 'clean-am' : 'clean';
3544     &do_one_clean_target ($target, 'mostly', '', @clean);
3545     &do_one_clean_target ($target, '', 'mostly', @clean);
3546     &do_one_clean_target ($target, 'dist', '', @clean);
3547     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
3549     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
3551     local (@deps);
3552     if ($recursive_install)
3553     {
3554         # Do -recursive before -am.  If you aren't doing a parallel
3555         # make, this can be nicer.
3556         @deps = ('recursive', 'am');
3557         &do_one_clean_target ('', 'mostly', '', @deps);
3558         &do_one_clean_target ('', '', '', @deps);
3559         &do_one_clean_target ('', 'dist', '', @deps);
3560         &do_one_clean_target ('', 'maintainer-', '', @deps);
3561     }
3564 # Helper for handle_clean.
3565 sub do_one_clean_target
3567     local ($target, $name, $last_name, @deps) = @_;
3569     # Special case: if target not passed, then don't generate
3570     # dependency on next "lower" clean target (eg no
3571     # clean<-mostlyclean derivation).  In this case the target is
3572     # implicitly known to be 'clean'.
3573     local ($flag) = $target;
3574     $target = 'clean' if ! $flag;
3576     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
3577     if ($flag)
3578     {
3579         if ($last_name || $name ne 'mostly')
3580         {
3581             push (@deps, $last_name . $target);
3582         }
3583     }
3585     # If a -local version of the rule is given, add it to the list.
3586     if (defined $contents{$name . $target . '-local'})
3587     {
3588         push (@deps, $name . $target . '-local');
3589     }
3591     # Print the target and the dependencies.
3592     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
3594     # FIXME: shouldn't we really print these messages before running
3595     # the dependencies?
3596     if ($name . $target eq 'maintainer-clean')
3597     {
3598         # Print a special warning.
3599         $output_rules .=
3600             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
3601              . "\t\@echo \"it deletes files that may require special "
3602              . "tools to rebuild.\"\n");
3604         $output_rules .= "\trm -f config.status\n"
3605             if $relative_dir eq '.';
3606     }
3607     elsif ($name . $target eq 'distclean')
3608     {
3609         $output_rules .= "\trm -f config.status\n";
3610         $output_rules .= "\trm -f libtool\n" if $seen_libtool;
3611     }
3612     $output_rules .= "\n";
3615 # Handle .PHONY target.
3616 sub handle_phony
3618     &pretty_print_rule ('.PHONY:', "", @phony);
3619     $output_rules .= "\n";
3622 # Handle TESTS variable and other checks.
3623 sub handle_tests
3625     if (defined $options{'dejagnu'})
3626     {
3627         push (@check_tests, 'check-DEJAGNU');
3628         push (@phony, 'check-DEJAGNU');
3630         local ($xform);
3631         if ($cygnus_mode)
3632         {
3633             $xform = 's/^CYGNUS//;';
3634         }
3635         else
3636         {
3637             $xform = 's/^CYGNUS.*$//;';
3638         }
3639         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
3641         # In Cygnus mode, these are found in the build tree.
3642         # Otherwise they are looked for in $PATH.
3643         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
3644         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
3646         # Note that in the rule we don't directly generate site.exp to
3647         # avoid the possibility of a corrupted site.exp if make is
3648         # interrupted.  Jim Meyering has some useful text on this
3649         # topic.
3650         $output_rules .= ("site.exp: Makefile\n"
3651                           . "\t\@echo 'Making a new site.exp file...'\n"
3652                           . "\t-\@rm -f site.bak\n"
3653                           . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
3654                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
3655                           . "\t\@echo '# edit the last section' >> \$\@-t\n"
3656                           . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
3657                           . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
3658                           . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
3660         # Extra stuff for AC_CANONICAL_*
3661         local (@whatlist) = ();
3662         if ($seen_canonical)
3663         {
3664             push (@whatlist, 'host')
3665         }
3667         # Extra stuff only for AC_CANONICAL_SYSTEM.
3668         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
3669         {
3670             push (@whatlist, 'target', 'build');
3671         }
3673         local ($c1, $c2);
3674         foreach $c1 (@whatlist)
3675         {
3676             foreach $c2 ('alias', 'triplet')
3677             {
3678                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
3679             }
3680         }
3682         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
3683                           . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
3684                           . "\t-\@mv site.exp site.bak\n"
3685                           . "\t\@mv \$\@-t site.exp\n");
3686     }
3687     else
3688     {
3689         local ($c);
3690         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
3691         {
3692             if (&variable_defined ($c))
3693             {
3694                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
3695             }
3696         }
3697     }
3699     if (&variable_defined ('TESTS'))
3700     {
3701         push (@check_tests, 'check-TESTS');
3702         push (@phony, 'check-TESTS');
3704         $output_rules .= 'check-TESTS: $(TESTS)
3705         @failed=0; all=0; \\
3706         srcdir=$(srcdir); export srcdir; \\
3707         for tst in $(TESTS); do \\
3708           if test -f $$tst; then dir=.; \\
3709           else dir="$(srcdir)"; fi; \\
3710           if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
3711             all=`expr $$all + 1`; \\
3712             echo "PASS: $$tst"; \\
3713           elif test $$? -ne 77; then \\
3714             all=`expr $$all + 1`; \\
3715             failed=`expr $$failed + 1`; \\
3716             echo "FAIL: $$tst"; \\
3717           fi; \\
3718         done; \\
3719         if test "$$failed" -eq 0; then \\
3720           banner="All $$all tests passed"; \\
3721         else \\
3722           banner="$$failed of $$all tests failed"; \\
3723         fi; \\
3724         dashes=`echo "$$banner" | sed s/./=/g`; \\
3725         echo "$$dashes"; \\
3726         echo "$$banner"; \\
3727         echo "$$dashes"; \\
3728         test "$$failed" -eq 0
3730     }
3733 # Handle Emacs Lisp.
3734 sub handle_emacs_lisp
3736     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
3738     if (@elfiles)
3739     {
3740         # Found some lisp.
3741         &define_configure_variable ('lispdir');
3742         &define_configure_variable ('EMACS');
3743         $output_rules .= (".el.elc:\n"
3744                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
3745                           . "\tif test \$(EMACS) != no; then \\\n"
3746                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
3747                           . "\tfi\n");
3748         push (@suffixes, '.el', '.elc');
3750         # Generate .elc files.
3751         grep ($_ .= 'c', @elfiles);
3752         &define_pretty_variable ('ELCFILES', '', @elfiles);
3754         $output_rules .= &file_contents ('lisp-clean');
3755         push (@clean, 'lisp');
3756         &push_phony_cleaners ('lisp');
3758         push (@all, '$(ELCFILES)');
3760         local ($varname);
3761         if (&variable_defined ('lisp_LISP'))
3762         {
3763             $varname = 'lisp_LISP';
3764             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
3765                 if ! $seen_lispdir;
3766         }
3767         else
3768         {
3769             $varname = 'noinst_LISP';
3770         }
3772         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
3773     }
3776 ################################################################
3778 # Scan one file for interesting things.  Subroutine of scan_configure.
3779 sub scan_one_configure_file
3781     local ($filename) = @_;
3783     open (CONFIGURE, $filename)
3784         || die "automake: couldn't open \`$filename': $!\n";
3785     print "automake: reading $filename\n" if $verbose;
3787     while (<CONFIGURE>)
3788     {
3789         # Remove comments from current line.
3790         s/\bdnl\b.*$//;
3791         s/\#.*$//;
3793         # Skip macro definitions.  Otherwise we might be confused into
3794         # thinking that a macro that was only defined was actually
3795         # used.
3796         next if /AC_DEFUN/;
3798         # Populate libobjs array.
3799         if (/AC_FUNC_ALLOCA/)
3800         {
3801             $libsources{'alloca.c'} = 1;
3802         }
3803         elsif (/AC_FUNC_GETLOADAVG/)
3804         {
3805             $libsources{'getloadavg.c'} = 1;
3806         }
3807         elsif (/AC_FUNC_MEMCMP/)
3808         {
3809             $libsources{'memcmp.c'} = 1;
3810         }
3811         elsif (/AC_STRUCT_ST_BLOCKS/)
3812         {
3813             $libsources{'fileblocks.c'} = 1;
3814         }
3815         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
3816         {
3817             $libsources{'getopt.c'} = 1;
3818             $libsources{'getopt1.c'} = 1;
3819         }
3820         elsif (/AM_FUNC_STRTOD/)
3821         {
3822             $libsources{'strtod.c'} = 1;
3823         }
3824         elsif (/AM_WITH_REGEX/)
3825         {
3826             $libsources{'rx.c'} = 1;
3827             $libsources{'rx.h'} = 1;
3828             $libsources{'regex.c'} = 1;
3829             $libsources{'regex.h'} = 1;
3830             $omit_dependencies{'rx.h'} = 1;
3831             $omit_dependencies{'regex.h'} = 1;
3832         }
3833         elsif (/AM_FUNC_MKTIME/)
3834         {
3835             $libsources{'mktime.c'} = 1;
3836         }
3837         elsif (/AM_FUNC_ERROR_AT_LINE/)
3838         {
3839             $libsources{'error.c'} = 1;
3840             $libsources{'error.h'} = 1;
3841         }
3842         elsif (/AM_FUNC_OBSTACK/)
3843         {
3844             $libsources{'obstack.c'} = 1;
3845             $libsources{'obstack.h'} = 1;
3846         }
3847         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
3848                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
3849         {
3850             foreach $libobj_iter (split (' ', $1))
3851             {
3852                 if ($libobj_iter =~ /^(.*)\.o$/)
3853                 {
3854                     $libsources{$1 . '.c'} = 1;
3855                 }
3856             }
3857         }
3859         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
3860         {
3861             $in_ac_replace = 1;
3862         }
3863         if ($in_ac_replace)
3864         {
3865             $in_ac_replace = 0 if s/[\]\)].*$//;
3866             # Remove trailing backslash.
3867             s/\\$//;
3868             foreach (split)
3869             {
3870                 # Need to skip empty elements for Perl 4.
3871                 next if $_ eq '';
3872                 $libsources{$_ . '.c'} = 1;
3873             }
3874         }
3876         if (/$obsolete_rx/o)
3877         {
3878             local ($hint) = '';
3879             if ($obsolete_macros{$1})
3880             {
3881                 $hint = '; ' . $obsolete_macros{$1};
3882             }
3883             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
3884         }
3886         # Process the AC_OUTPUT macro.
3887         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
3888         {
3889             $in_ac_output = 1;
3890             $ac_output_line = $.;
3891         }
3892         if ($in_ac_output)
3893         {
3894             $in_ac_output = 0 if s/[\]\),].*$//;
3896             # Look at potential Makefile.am's.
3897             foreach (split)
3898             {
3899                 next if $_ eq "\\";
3901                 # Handle $local:$input syntax.  Note that we ignore
3902                 # every input file past the first, though we keep
3903                 # those around for later.
3904                 local ($local, $input, @rest) = split (/:/);
3905                 if (! $input)
3906                 {
3907                     $input = $local;
3908                 }
3909                 else
3910                 {
3911                     # FIXME: should be error if .in is missing.
3912                     $input =~ s/\.in$//;
3913                 }
3915                 if (-f $input . '.am')
3916                 {
3917                     # We have a file that automake should generate.
3918                     push (@make_input_list, $input);
3919                     $make_list{$input} = join (':', ($local, @rest));
3920                 }
3921                 else
3922                 {
3923                     # We have a file that automake should cause to be
3924                     # rebuilt, but shouldn't generate itself.
3925                     push (@other_input_files, $_);
3926                 }
3927             }
3928         }
3930         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
3931         {
3932             @config_aux_path = $1;
3933         }
3935         # Check for ansi2knr.
3936         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
3938         # Check for Cygwin32.
3939         if (/AM_CYGWIN32/)
3940         {
3941             $seen_cygwin32 = 1;
3942             $configure_vars{'EXEEXT'} = 1;
3943         }
3945         # Check for NLS support.
3946         if (/AM_GNU_GETTEXT/)
3947         {
3948             $seen_gettext = 1;
3949             $ac_gettext_line = $.;
3950             $omit_dependencies{'libintl.h'} = 1;
3951         }
3953         # Look for ALL_LINGUAS.
3954         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
3955         {
3956             $seen_linguas = 1;
3957             $all_linguas = $1;
3958             $all_linguas_line = $.;
3959         }
3961         # Handle configuration headers.  A config header of `[$1]'
3962         # means we are actually scanning AM_CONFIG_HEADER from
3963         # aclocal.m4.
3964         if (/A([CM])_CONFIG_HEADER\s*\((.*)\)/
3965             && $2 ne '[$1]')
3966         {
3967             &am_conf_line_error
3968                 ($filename, $.,
3969                  "\`AC_CONFIG_HEADER' is obsolete; use \`AM_CONFIG_HEADER'")
3970                     if $1 eq 'C';
3972             $config_header_line = $.;
3973             local ($one_hdr);
3974             foreach $one_hdr (split (' ', $2))
3975             {
3976                 push (@config_fullnames, $one_hdr);
3977                 if ($one_hdr =~ /^([^:]+):(.+)$/)
3978                 {
3979                     push (@config_names, $1);
3980                     push (@config_headers, $2);
3981                 }
3982                 else
3983                 {
3984                     push (@config_names, $one_hdr);
3985                     push (@config_headers, $one_hdr . '.in');
3986                 }
3987             }
3988         }
3990         # Handle AC_CANONICAL_*.  Always allow upgrading to
3991         # AC_CANONICAL_SYSTEM, but never downgrading.
3992         $seen_canonical = $AC_CANONICAL_HOST
3993             if ! $seen_canonical
3994                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
3995         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
3997         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
3999         # This macro handles several different things.
4000         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4001         {
4002             $seen_make_set = 1;
4003             $seen_package = 1;
4004             $seen_version = 1;
4005             $seen_arg_prog = 1;
4006             $seen_prog_install = 2;
4007             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4008             $package_version_line = $.;
4009         }
4011         # This is like AM_INIT_AUTOMAKE, but doesn't actually set the
4012         # package and version number.  (This might change in the
4013         # future).  Yes, I'm not above hacking Automake so it works
4014         # well with other GNU tools -- that is actually the point.
4015         if (/AM_INIT_GUILE_MODULE/)
4016         {
4017             $seen_make_set = 1;
4018             $seen_package = 1;
4019             $seen_version = 1;
4020             $seen_arg_prog = 1;
4021             $seen_prog_install = 2;
4022             @config_aux_path = ('..');
4023         }
4025         # Some things required by Automake.
4026         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
4027         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
4029         if (/AC_PROG_(YACC|RANLIB|CC|CXX|LEX|AWK|CPP|CXXCPP|LN_S)/)
4030         {
4031             $configure_vars{$1} = 1;
4032         }
4033         if (/$AC_CHECK_PATTERN/o)
4034         {
4035             $configure_vars{$3} = 1;
4036         }
4037         if (/$AM_MISSING_PATTERN/o
4038             && $1 ne 'ACLOCAL'
4039             && $1 ne 'AUTOCONF'
4040             && $1 ne 'AUTOMAKE'
4041             && $1 ne 'AUTOHEADER')
4042         {
4043             $configure_vars{$1} = 1;
4044         }
4046         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4047         # but later define it elsewhere.  This is pretty hacky.  We
4048         # also explicitly avoid INSTALL_SCRIPT and some other
4049         # variables because they are defined in header-vars.am.
4050         # FIXME.
4051         if (/$AC_SUBST_PATTERN/o
4052             && $1 ne 'ANSI2KNR'
4053             && $1 ne 'INSTALL_SCRIPT')
4054         {
4055             $configure_vars{$1} = 1;
4056         }
4058         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4059         $seen_maint_mode = 1 if /AM_MAINTAINER_MODE/;
4060         $seen_package = 1 if /PACKAGE=/;
4062         # Skip VERSION of [$2]; that is from AM_INIT_AUTOMAKE.
4063         if (/\bVERSION=(\S+)/ && $1 ne '[$2]')
4064         {
4065             $seen_version = 1;
4066             $package_version = $1;
4067             $package_version_line = $.;
4068         }
4069         elsif (/VERSION=/)
4070         {
4071             $seen_version = 1;
4072         }
4074         # Weird conditionals here because it is always allowed to
4075         # upgrade to AM_PROG_INSTALL but never to downgrade to
4076         # AC_PROG_INSTALL.
4077         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
4078         $seen_prog_install = 2 if /AM_PROG_INSTALL/;
4080         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4082         if (/AM_PROG_LIBTOOL/)
4083         {
4084             $seen_libtool = 1;
4085             $libtool_line = $.;
4086             $configure_vars{'LIBTOOL'} = 1;
4087             $configure_vars{'RANLIB'} = 1;
4088             $configure_vars{'CC'} = 1;
4089             # AM_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
4090             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4091             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4092         }
4094         if (/$AM_CONDITIONAL_PATTERN/o)
4095         {
4096             $configure_cond{$1} = 1;
4097         }
4098     }
4100     close (CONFIGURE);
4103 # Scan configure.in and aclocal.m4 for interesting things.  We must
4104 # scan aclocal.m4 because there might be AC_SUBSTs and such there.
4105 sub scan_configure
4107     # Reinitialize libsources here.  This isn't really necessary,
4108     # since we currently assume there is only one configure.in.  But
4109     # that won't always be the case.
4110     %libsources = ();
4112     local ($in_ac_output, $in_ac_replace) = (0, 0);
4113     local (%make_list, @make_input_list);
4114     local ($libobj_iter);
4116     &scan_one_configure_file ('configure.in');
4117     &scan_one_configure_file ('aclocal.m4')
4118         if -f 'aclocal.m4';
4120     # Set input and output files if not specified by user.
4121     if (! @input_files)
4122     {
4123         @input_files = @make_input_list;
4124         %output_files = %make_list;
4125     }
4127     &am_conf_error ("\`PACKAGE' not defined in configure.in")
4128         if ! $seen_package;
4129     &am_conf_error ("\`VERSION' not defined in configure.in")
4130         if ! $seen_version;
4132     # Look for some files we need.  Always check for these.  This
4133     # check must be done for every run, even those where we are only
4134     # looking at a subdir Makefile.  We must set relative_dir so that
4135     # the file-finding machinery works.
4136     local ($relative_dir) = '.';
4137     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4138     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
4139         if -f $config_aux_path[0] . '/install.sh';
4142 ################################################################
4144 # Set up for Cygnus mode.
4145 sub check_cygnus
4147     return unless $cygnus_mode;
4149     &set_strictness ('foreign');
4150     $options{'no-installinfo'} = 1;
4151     $options{'no-dependencies'} = 1;
4152     $use_dependencies = 0;
4154     if (! $seen_maint_mode)
4155     {
4156         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
4157     }
4159     if (! $seen_cygwin32)
4160     {
4161         &am_conf_error ("\`AM_CYGWIN32' required when --cygnus specified");
4162     }
4165 # Do any extra checking for GNU standards.
4166 sub check_gnu_standards
4168     if ($relative_dir eq '.')
4169     {
4170         # In top level (or only) directory.
4171         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4172                        'AUTHORS', 'ChangeLog');
4173     }
4175     if ($strictness >= $GNU)
4176     {
4177         if (defined $options{'no-installman'})
4178         {
4179             &am_line_error ('AUTOMAKE_OPTIONS',
4180                             "option \`no-installman' disallowed by GNU standards");
4181         }
4183         if (defined $options{'no-installinfo'})
4184         {
4185             &am_line_error ('AUTOMAKE_OPTIONS',
4186                             "option \`no-installinfo' disallowed by GNU standards");
4187         }
4188     }
4191 # Do any extra checking for GNITS standards.
4192 sub check_gnits_standards
4194     if ($strictness >= $GNITS)
4195     {
4196         if (-f $relative_dir . '/COPYING.LIB')
4197         {
4198             &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
4199         }
4201         if ($relative_dir eq '.')
4202         {
4203             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4204             {
4205                 # FIXME: allow real filename.
4206                 &am_conf_line_error ('configure.in',
4207                                      $package_version_line,
4208                                      "version \`$package_version' doesn't follow Gnits standards");
4209             }
4210             elsif (defined $1 && -f 'README-alpha')
4211             {
4212                 # This means we have an alpha release.  See
4213                 # GNITS_VERSION_PATTERN for details.
4214                 &require_file ($GNITS, 'README-alpha');
4215             }
4216         }
4217     }
4219     if ($relative_dir eq '.')
4220     {
4221         # In top level (or only) directory.
4222         &require_file ($GNITS, 'THANKS');
4223     }
4226 ################################################################
4228 # Pretty-print something.  HEAD is what should be printed at the
4229 # beginning of the first line, FILL is what should be printed at the
4230 # beginning of every subsequent line.
4231 sub pretty_print_internal
4233     local ($head, $fill, @values) = @_;
4235     local ($column) = length ($head);
4236     local ($result) = $head;
4238     # Fill length is number of characters.  However, each Tab
4239     # character counts for eight.  So we count the number of Tabs and
4240     # multiply by 7.
4241     local ($fill_length) = length ($fill);
4242     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
4244     local ($bol) = ($head eq '');
4245     foreach (@values)
4246     {
4247         # "71" because we also print a space.
4248         if ($column + length ($_) > 71)
4249         {
4250             $result .= " \\\n" . $fill;
4251             $column = $fill_length;
4252             $bol = 1;
4253         }
4255         $result .= ' ' unless ($bol);
4256         $result .= $_;
4257         $column += length ($_) + 1;
4258         $bol = 0;
4259     }
4261     $result .= "\n";
4262     return $result;
4265 # Pretty-print something and append to output_vars.
4266 sub pretty_print
4268     $output_vars .= &pretty_print_internal (@_);
4271 # Pretty-print something and append to output_rules.
4272 sub pretty_print_rule
4274     $output_rules .= &pretty_print_internal (@_);
4278 ################################################################
4280 # See if a target exists.
4281 sub target_defined
4283     local ($target) = @_;
4284     return defined $targets{$target};
4287 # See if two conditionals are the same.
4288 sub conditional_same
4290     local ($cond1, $cond2) = @_;
4292     return (&conditional_true_when ($cond1, $cond2)
4293             && &conditional_true_when ($cond2, $cond1));
4296 # See if a conditional is true.  Both arguments are conditional
4297 # strings.  This returns true if the first conditional is true when
4298 # the second conditional is true.
4299 sub conditional_true_when
4301     local ($cond, $when) = @_;
4303     # Check the easy case first.
4304     if ($cond eq $when)
4305     {
4306         return 1;
4307     }
4309     # Check each component of $cond, which looks @COND1@@COND2@.
4310     foreach $comp (split ('@', $cond))
4311     {
4312         # The way we split will give null strings between each
4313         # condition.
4314         next if ! $comp;
4316         if (index ($when, '@' . $comp . '@') == -1)
4317         {
4318             return 0;
4319         }
4320     }
4322     return 1;
4325 # Check for an ambiguous conditional.  This is called when a variable
4326 # or target is being defined conditionally.  If we already know about
4327 # a definition that is true under the same conditions, then we have an
4328 # ambiguity.
4329 sub check_ambiguous_conditional
4331     local ($var_name, $cond) = @_;
4332     local (@cond_vals) = split (' ', $conditional{$var_name});
4333     while (@cond_vals)
4334     {
4335         local ($vcond) = shift (@cond_vals);
4336         shift (@cond_vals);
4337         if (&conditional_true_when ($vcond, $cond)
4338             || &conditional_true_when ($cond, $vcond))
4339         {
4340             &am_line_error ($var_name,
4341                             "$var_name multiply defined in condition");
4342         }
4343     }
4346 # See if a variable exists.  The first argument is the variable name,
4347 # and the optional second argument is the condition which we should
4348 # check.  If no condition is given, we currently return true if the
4349 # variable is defined under any condition.
4350 sub variable_defined
4352     local ($var, $cond) = @_;
4353     if (defined $targets{$var})
4354     {
4355         &am_line_error ($var, "\`$var' is target; expected variable");
4356         return 0;
4357     }
4358     elsif (defined $contents{$var})
4359     {
4360         if ($cond && $conditional{$var})
4361         {
4362             # We have been asked to check for a particular condition,
4363             # and the variable is defined conditionally.  We need to
4364             # look through the conditions under which the variable is
4365             # defined, and see if any of them match the conditional we
4366             # have been asked to check.
4367             local (@cond_vars) = split (' ', $conditional{$var});
4368             while (@cond_vars)
4369             {
4370                 if (&conditional_same ($cond, shift (@cond_vars)))
4371                 {
4372                     # Even a conditional examination is good enough
4373                     # for us.  FIXME: really should maintain examined
4374                     # status on a per-condition basis.
4375                     $content_seen{$var} = 1;
4376                     return 1;
4377                 }
4378                 shift (@cond_vars);
4379             }
4381             # The variable is not defined for the given condition.
4382             return 0;
4383         }
4385         $content_seen{$var} = 1;
4386         return 1;
4387     }
4388     return 0;
4391 # Mark a variable as examined.
4392 sub examine_variable
4394     local ($var) = @_;
4395     &variable_defined ($var);
4398 # Quote a value in order to put it in $conditional.  We need to quote
4399 # spaces, and we need to handle null strings, so that we can later
4400 # retrieve values by splitting on space.
4401 sub quote_cond_val
4403     local ($val) = @_;
4404     $val =~ s/ /\001/g;
4405     $val = '\002' if $val eq '';
4406     return $val;
4409 # Unquote a value in $conditional.
4410 sub unquote_cond_val
4412     local ($val) = @_;
4413     $val =~ s/\001/ /g;
4414     $val = '' if $val eq '\002';
4415     return $val;
4418 # Return the set of conditions for which a variable is defined.
4420 # If the variable is not defined conditionally, and is not defined in
4421 # terms of any variables which are defined conditionally, then this
4422 # returns the empty list.
4424 # If the variable is defined conditionally, but is not defined in
4425 # terms of any variables which are defined conditionally, then this
4426 # returns the list of conditions for which the variable is defined.
4428 # If the variable is defined in terms of any variables which are
4429 # defined conditionally, then this returns a full set of permutations
4430 # of the subvariable conditions.  For example, if the variable is
4431 # defined in terms of a variable which is defined for @COND_TRUE@,
4432 # then this returns both @COND_TRUE@ and @COND_FALSE@.  This is
4433 # because we will need to define the variable under both conditions.
4435 sub variable_conditions
4437     local ($var) = @_;
4438     local (%uniqify);
4439     local ($cond);
4441     foreach $cond (&variable_conditions_sub ($var, '', ()))
4442     {
4443         $uniqify{$cond} = 1;
4444     }
4446     return keys %uniqify;
4449 # A subroutine of variable_conditions.  We only return conditions
4450 # which are true for all the conditions in @PARENT_CONDS.
4451 sub variable_conditions_sub
4453     local ($var, $parent, @parent_conds) = @_;
4454     local (@new_conds) = ();
4456     if (! $conditional{$var})
4457     {
4458         foreach (split (' ', $contents{$var}))
4459         {
4460             # If a comment seen, just leave.
4461             last if /^#/;
4463             # Handle variable substitutions.
4464             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
4465             {
4466                 push (@new_conds,
4467                       &variable_conditions_sub ($1, $var, @parent_conds));
4468             }
4469         }
4471         return &variable_conditions_reduce (@new_conds);
4472     }
4474     local (@this_conds) = ();
4475     local (@condvals) = split (' ', $conditional{$var});
4476     while (@condvals)
4477     {
4478         local ($cond) = shift (@condvals);
4479         local ($val) = &unquote_cond_val (shift (@condvals));
4481         if (@parent_conds)
4482         {
4483             local ($ok) = 1;
4484             local ($parent_cond);
4485             foreach $parent_cond (@parent_conds)
4486             {
4487                 if (! &conditional_true_when ($parent_cond, $cond))
4488                 {
4489                     $ok = 0;
4490                     last;
4491                 }
4492             }
4494             next if ! $ok;
4495         }
4497         push (@this_conds, $cond);
4499         push (@parent_conds, $cond);
4500         local (@subvar_conds) = ();
4501         foreach (split (' ', $val))
4502         {
4503             # If a comment seen, just leave.
4504             last if /^#/;
4506             # Handle variable substitutions.
4507             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
4508             {
4509                 push (@subvar_conds,
4510                       &variable_conditions_sub ($1, $var, @parent_conds));
4511             }
4512         }
4513         pop (@parent_conds);
4515         # If there are no conditional subvariables, then we want to
4516         # return this condition.  Otherwise, we want to return the
4517         # permutations of the subvariables.
4518         if (! @subvar_conds)
4519         {
4520             push (@new_conds, $cond);
4521         }
4522         else
4523         {
4524             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
4525         }
4526     }
4528     return @new_conds
4529         if ! $parent;
4531     # If we are being called on behalf of another variable, we need to
4532     # return all possible permutations of the conditions.  We have
4533     # already handled everything in @this_conds along with their
4534     # subvariables.  We now need to add any permutations that are not
4535     # in @this_conds.
4536     local ($this_cond);
4537     foreach $this_cond (@this_conds)
4538     {
4539         local (@perms) =
4540             &variable_conditions_permutations (split('@', $this_cond));
4541         local ($perm);
4542         foreach $perm (@perms)
4543         {
4544             local ($scan);
4545             local ($ok) = 1;
4546             foreach $scan (@this_conds)
4547             {
4548                 if (&conditional_true_when ($perm, $scan)
4549                     || &conditional_true_when ($scan, $perm))
4550                 {
4551                     $ok = 0;
4552                     last;
4553                 }
4554             }
4555             next if ! $ok;
4557             if (@parent_conds)
4558             {
4559                 local ($ok) = 1;
4560                 local ($parent_cond);
4561                 foreach $parent_cond (@parent_conds)
4562                 {
4563                     if (! &conditional_true_when ($parent_cond, $perm))
4564                     {
4565                         $ok = 0;
4566                         last;
4567                     }
4568                 }
4570                 next if ! $ok;
4571             }
4573             # This permutation was not already handled, and is valid
4574             # for the parents.
4575             push (@new_conds, $perm);
4576         }
4577     }
4579     return @new_conds;
4582 # Subroutine for variable_conditions_sort
4583 sub variable_conditions_cmp
4585     local ($as) = $a;
4586     $as =~ s/[^@]//g;
4587     local ($bs) = $b;
4588     $bs =~ s/[^@]//g;
4589     return (length ($as) <=> length ($bs)
4590             || $a cmp $b);
4593 # Sort a list of conditionals so that only the exclusive ones are
4594 # retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
4595 # @COND1_TRUE@ are in the list, discard the latter.
4596 sub variable_conditions_reduce
4598     local (@conds) = @_;
4599     local (@ret) = ();
4600     local ($cond);
4601     foreach $cond (sort variable_conditions_cmp @conds)
4602     {
4603         local ($ok) = 1;
4604         local ($scan);
4605         foreach $scan (@ret)
4606         {
4607             if (&conditional_true_when ($cond, $scan))
4608             {
4609                 $ok = 0;
4610                 last;
4611             }
4612         }
4613         next if ! $ok;
4614         push (@ret, $cond);
4615     }
4617     return @ret;
4620 # Return a list of permutations of a conditional string.
4621 sub variable_conditions_permutations
4623     local (@comps) = @_;
4624     return ()
4625         if ! @comps;
4626     local ($comp) = shift (@comps);
4627     return &variable_conditions_permutations (@comps)
4628         if $comp eq '';
4629     local ($neg) = $comp;
4630     $neg =~ s/TRUE$/TRUEO/;
4631     $neg =~ s/FALSE$/TRUE/;
4632     $neg =~ s/TRUEO$/FALSE/;
4633     local (@ret);
4634     local ($sub);
4635     foreach $sub (&variable_conditions_permutations (@comps))
4636     {
4637         push (@ret, '@' . $comp . '@' . $sub);
4638         push (@ret, '@' . $neg . '@' . $sub);
4639     }
4640     if (! @ret)
4641     {
4642         push (@ret, '@' . $comp . '@');
4643         push (@ret, '@' . $neg . '@');
4644     }
4645     return @ret;
4648 # Warn if a variable is conditionally defined.  This is called if we
4649 # are using the value of a variable.
4650 sub variable_conditionally_defined
4652     local ($var, $parent) = @_;
4653     if ($conditional{$var})
4654     {
4655         if ($parent)
4656         {
4657             &am_line_error ($parent,
4658                             "warning: automake does not support conditional definition of $var in $parent");
4659         }
4660         else
4661         {
4662             &am_line_error ($parent,
4663                             "warning: automake does not support $var being defined conditionally")
4664         }
4665     }
4668 # Get the value of a variable.  This just returns $contents, but warns
4669 # if the variable is conditionally defined.
4670 sub variable_value
4672     local ($var) = @_;
4673     &variable_conditionally_defined ($var);
4674     return $contents{$var};
4677 # Convert a variable value to a list, split as whitespace.  This will
4678 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
4679 # substitutions.  If COND is 'all', then all values under all
4680 # conditions should be returned; if COND is a particular condition
4681 # (all conditions are surrounded by @...@) then only the value for
4682 # that condition should be returned; otherwise, warn if VAR is
4683 # conditionally defined.
4684 sub value_to_list
4686     local ($var, $val, $cond) = @_;
4687     local (@result);
4689     foreach (split (' ', $val))
4690     {
4691         # If a comment seen, just leave.
4692         last if /^#/;
4694         # Handle variable substitutions.
4695         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
4696         {
4697             local ($varname) = $1;
4699             # If the user uses a losing variable name, just ignore it.
4700             # This isn't ideal, but people have requested it.
4701             next if ($varname =~ /\@.*\@/);
4703             local ($from, $to);
4704             local (@temp_list);
4705             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
4706             {
4707                 $varname = $1;
4708                 $to = $3;
4709                 ($from = $2) =~ s/(\W)/\\$1/g;
4710             }
4712             # Find the value.
4713             @temp_list = &variable_value_as_list ($1, $cond, $var);
4715             # Now rewrite the value if appropriate.
4716             if ($from)
4717             {
4718                 grep (s/$from$/$to/, @temp_list);
4719             }
4721             push (@result, @temp_list);
4722         }
4723         else
4724         {
4725             push (@result, $_);
4726         }
4727     }
4729     return @result;
4732 # Return contents of variable as list, split as whitespace.  This will
4733 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
4734 # substitutions.  If COND is 'all', then all values under all
4735 # conditions should be returned; if COND is a particular condition
4736 # (all conditions are surrounded by @...@) then only the value for
4737 # that condition should be returned; otherwise, warn if VAR is
4738 # conditionally defined.  If PARENT is specified, it is the name of
4739 # the including variable; this is only used for error reports.
4740 sub variable_value_as_list
4742     local ($var, $cond, $parent) = @_;
4743     local (@result);
4745     if (defined $targets{$var})
4746     {
4747         &am_line_error ($var, "\`$var' is target; expected variable");
4748     }
4749     elsif (! defined $contents{$var})
4750     {
4751         &am_line_error ($parent, "variable \`$var' not defined");
4752     }
4753     elsif ($cond eq 'all' && $conditional{$var})
4754     {
4755         local (@condvals) = split (' ', $conditional{$var});
4756         while (@condvals)
4757         {
4758             shift (@condvals);
4759             local ($val) = &unquote_cond_val (shift (@condvals));
4760             push (@result, &value_to_list ($var, $val, $cond));
4761         }
4762     }
4763     elsif ($cond && $conditional{$var})
4764     {
4765         local (@condvals) = split (' ', $conditional{$var});
4766         local ($onceflag);
4767         while (@condvals)
4768         {
4769             local ($vcond) = shift (@condvals);
4770             local ($val) = &unquote_cond_val (shift (@condvals));
4771             if (&conditional_true_when ($vcond, $cond))
4772             {
4773                 # Warn if we have an ambiguity.  It's hard to know how
4774                 # to handle this case correctly.
4775                 &variable_conditionally_defined ($var, $parent)
4776                     if $onceflag;
4777                 $onceflag = 1;
4778                 push (@result, &value_to_list ($var, $val, $cond));
4779             }
4780         }
4781     }
4782     else
4783     {
4784         &variable_conditionally_defined ($var, $parent);
4785         $content_seen{$var} = 1;
4786         push (@result, &value_to_list ($var, $contents{$var}, $cond));
4787     }
4789     return @result;
4792 # Define a new variable, but only if not already defined.
4793 sub define_variable
4795     local ($var, $value) = @_;
4797     if (! defined $contents{$var})
4798     {
4799         $output_vars .= $var . ' = ' . $value . "\n";
4800         $contents{$var} = $value;
4801         $content_seen{$var} = 1;
4802     }
4805 # Like define_variable, but the value is a list, and the variable may
4806 # be defined conditionally.  The second argument is the conditional
4807 # under which the value should be defined; this should be the empty
4808 # string to define the variable unconditionally.  The third argument
4809 # is a list holding the values to use for the variable.  The value is
4810 # pretty printed in the output file.
4811 sub define_pretty_variable
4813     local ($var, $cond, @value) = @_;
4814     if (! defined $contents{$var}
4815         || ($cond && ! &variable_defined ($var, $cond)))
4816     {
4817         $contents{$var} = join (' ', @value);
4818         if ($cond)
4819         {
4820             if ($conditional{$var})
4821             {
4822                 $conditional{$var} .= ' ';
4823             }
4824             else
4825             {
4826                 $conditional{$var} = '';
4827             }
4828             $conditional{$var} .= ($cond
4829                                    . ' '
4830                                    . &quote_cond_val ($contents{$var}));
4831         }
4832         &pretty_print ($cond . $var . ' = ', $cond, @value);
4833         $content_seen{$var} = 1;
4834     }
4837 # Like define_variable, but define a variable to be the configure
4838 # substitution by the same name.
4839 sub define_configure_variable
4841     local ($var) = @_;
4842     local ($value) = '@' . $var . '@';
4843     &define_variable ($var, $value);
4846 # Define a variable that represents a program to run.  If in Cygnus
4847 # mode, the program is searched for in the build (or source) tree.
4848 # Otherwise no searching is done at all.  Arguments are:
4849 # * VAR      Name of variable to define
4850 # * WHATDIR  Either `src' or `build', depending on where program should
4851 #            be found.  (runtest is in srcdir!)
4852 # * SUBDIR   Subdir of top-level dir
4853 # * PROGRAM  Name of program
4854 # * OVERRIDE If specified, the name of the program to use when not in
4855 #            Cygnus mode.  Defaults to PROGRAM.
4856 sub define_program_variable
4858     local ($var, $whatdir, $subdir, $program, $override) = @_;
4860     if (! $override)
4861     {
4862         $override = $program;
4863     }
4865     if ($cygnus_mode)
4866     {
4867         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
4868                          . $subdir . '/' . $program);
4869         &define_variable ($var, ('`if test -f ' . $full
4870                                  . '; then echo ' . $full . '; else echo '
4871                                  . $program . '; fi`'));
4872     }
4873     else
4874     {
4875         &define_variable ($var, $override);
4876     }
4880 ################################################################
4882 # Read Makefile.am and set up %contents.  Simultaneously copy lines
4883 # from Makefile.am into $output_trailer or $output_vars as
4884 # appropriate.  NOTE we put rules in the trailer section.  We want
4885 # user rules to come after our generated stuff.
4886 sub read_am_file
4888     local ($amfile) = @_;
4890     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
4891     print "automake: reading $amfile\n" if $verbose;
4893     $output_vars = ("# $in_file_name generated automatically by automake "
4894                     . $VERSION . " from $am_file_name\n");
4896     # Generate copyright for generated Makefile.in.
4897     $output_vars .= $gen_copyright;
4899     local ($saw_bk) = 0;
4900     local ($was_rule) = 0;
4901     local ($spacing) = '';
4902     local ($comment) = '';
4903     local ($last_var_name) = '';
4904     local ($blank) = 0;
4906     while (<AM_FILE>)
4907     {
4908         if (/$IGNORE_PATTERN/o)
4909         {
4910             # Merely delete comments beginning with two hashes.
4911         }
4912         elsif (/$WHITE_PATTERN/o)
4913         {
4914             # Stick a single white line before the incoming macro or rule.
4915             $spacing = "\n";
4916             $blank = 1;
4917         }
4918         elsif (/$COMMENT_PATTERN/o)
4919         {
4920             # Stick comments before the incoming macro or rule.  Make
4921             # sure a blank line preceeds first block of comments.
4922             $spacing = "\n" unless $blank;
4923             $blank = 1;
4924             $comment .= $spacing . $_;
4925             $spacing = '';
4926         }
4927         else
4928         {
4929             last;
4930         }
4931     }
4933     $output_vars .= $comment . "\n";
4934     $comment = '';
4935     $spacing = "\n";
4936     local ($am_vars) = '';
4938     local ($is_ok_macro);
4939     while ($_)
4940     {
4941         $_ .= "\n"
4942             unless substr ($_, -1, 1) eq "\n";
4944         $_ =~ s/\@MAINT\@//g
4945             unless $seen_maint_mode;
4947         if (/$IGNORE_PATTERN/o)
4948         {
4949             # Merely delete comments beginning with two hashes.
4950         }
4951         elsif (/$WHITE_PATTERN/o)
4952         {
4953             # Stick a single white line before the incoming macro or rule.
4954             $spacing = "\n";
4955         }
4956         elsif (/$COMMENT_PATTERN/o)
4957         {
4958             # Stick comments before the incoming macro or rule.
4959             $comment .= $spacing . $_;
4960             $spacing = '';
4961         }
4962         elsif ($saw_bk)
4963         {
4964             if ($was_rule)
4965             {
4966                 $output_trailer .= join ('', @conditional_stack) . $_;
4967                 $saw_bk = /\\$/;
4968             }
4969             else
4970             {
4971                 $am_vars .= join ('', @conditional_stack) . $_;
4972                 $saw_bk = /\\$/;
4973                 # Chop newline and backslash if this line is
4974                 # continued.  FIXME: maybe ensure trailing whitespace
4975                 # exists?
4976                 chop if $saw_bk;
4977                 chop if $saw_bk;
4978                 $contents{$last_var_name} .= $_;
4979                 if (@conditional_stack)
4980                 {
4981                     $conditional{$last_var_name} .= &quote_cond_val ($_);
4982                 }
4983             }
4984         }
4985         elsif (/$IF_PATTERN/o)
4986         {
4987             &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
4988                 if (! $configure_cond{$1});
4989             push (@conditional_stack, "\@" . $1 . "_TRUE\@");
4990         }
4991         elsif (/$ELSE_PATTERN/o)
4992         {
4993             if (! @conditional_stack)
4994             {
4995                 &am_line_error ($., "else without if");
4996             }
4997             elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
4998             {
4999                 &am_line_error ($., "else after else");
5000             }
5001             else
5002             {
5003                 $conditional_stack[$#conditional_stack]
5004                     =~ s/_TRUE\@$/_FALSE\@/;
5005             }
5006         }
5007         elsif (/$ENDIF_PATTERN/o)
5008         {
5009             if (! @conditional_stack)
5010             {
5011                 &am_line_error ($., "endif without if");
5012             }
5013             else
5014             {
5015                 pop @conditional_stack;
5016             }
5017         }
5018         elsif (/$RULE_PATTERN/o)
5019         {
5020             # Found a rule.
5021             $was_rule = 1;
5022             if (defined $contents{$1}
5023                 && (@conditional_stack
5024                     ? ! defined $conditional{$1}
5025                     : defined $conditional{$1}))
5026             {
5027                 &am_line_error ($1,
5028                                 "$1 defined both conditionally and unconditionally");
5029             }
5030             # Value here doesn't matter; for targets we only note
5031             # existence.
5032             $contents{$1} = 1;
5033             $targets{$1} = 1;
5034             local ($cond_string) = join ('', @conditional_stack);
5035             if (@conditional_stack)
5036             {
5037                 if ($conditional{$1})
5038                 {
5039                     &check_ambiguous_conditional ($1, $cond_string);
5040                     $conditional{$1} .= ' ';
5041                 }
5042                 else
5043                 {
5044                     $conditional{$1} = '';
5045                 }
5046                 $conditional{$1} .= $cond_string . ' 1';
5047             }
5048             $content_lines{$1} = $.;
5049             $output_trailer .= $comment . $spacing . $cond_string . $_;
5050             $comment = $spacing = '';
5051             $saw_bk = /\\$/;
5052         }
5053         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
5054                || /$BOGUS_MACRO_PATTERN/o)
5055         {
5056             # Found a macro definition.
5057             $was_rule = 0;
5058             $last_var_name = $1;
5059             if (defined $contents{$1}
5060                 && (@conditional_stack
5061                     ? ! defined $conditional{$1}
5062                     : defined $conditional{$1}))
5063             {
5064                 &am_line_error ($1,
5065                                 "$1 defined both conditionally and unconditionally");
5066             }
5067             if ($2 ne '' && substr ($2, -1) eq "\\")
5068             {
5069                 $contents{$last_var_name} = substr ($2, 0, length ($2) - 1);
5070             }
5071             else
5072             {
5073                 $contents{$last_var_name} = $2;
5074             }
5075             local ($cond_string) = join ('', @conditional_stack);
5076             if (@conditional_stack)
5077             {
5078                 if ($conditional{$last_var_name})
5079                 {
5080                     &check_ambiguous_conditional ($last_var_name,
5081                                                   $cond_string);
5082                     $conditional{$last_var_name} .= ' ';
5083                 }
5084                 else
5085                 {
5086                     $conditional{$last_var_name} = '';
5087                 }
5088                 local ($val) = $contents{$last_var_name};
5089                 $conditional{$last_var_name} .= ($cond_string
5090                                                  . ' '
5091                                                  . &quote_cond_val ($val));
5092             }
5093             $content_lines{$last_var_name} = $.;
5094             $am_vars .= $comment . $spacing . $cond_string . $_;
5095             $comment = $spacing = '';
5096             $saw_bk = /\\$/;
5098             # Error if bogus.
5099             &am_line_error ($., "bad macro name \`$last_var_name'")
5100                 if ! $is_ok_macro;
5101         }
5102         else
5103         {
5104             # This isn't an error; it is probably a continued rule.
5105             # In fact, this is what we assume.
5106             $was_rule = 1;
5107             $output_trailer .= ($comment . $spacing
5108                                 . join ('', @conditional_stack) . $_);
5109             $comment = $spacing = '';
5110             $saw_bk = /\\$/;
5111         }
5113         $_ = <AM_FILE>;
5114     }
5116     $output_trailer .= $comment;
5118     &am_error ("unterminated conditionals: " . join (' ', @conditional_stack))
5119         if (@conditional_stack);
5121     # Compute relative location of the top object directory.
5122     local (@topdir) = ();
5123     foreach (split (/\//, $relative_dir))
5124     {
5125         next if $_ eq '.' || $_ eq '';
5126         if ($_ eq '..')
5127         {
5128             pop @topdir;
5129         }
5130         else
5131         {
5132             push (@topdir, '..');
5133         }
5134     }
5135     @topdir = ('.') if ! @topdir;
5137     $top_builddir = join ('/', @topdir);
5138     local ($build_rx);
5139     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
5140     $output_vars .= &file_contents_with_transform
5141                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
5142                          'header-vars');
5144     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
5145     # this should use generic %configure_vars method.
5146     if ($seen_canonical)
5147     {
5148         local ($curs, %vars);
5149         $vars{'host_alias'} = 'host_alias';
5150         $vars{'host_triplet'} = 'host';
5151         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
5152         {
5153             $vars{'build_alias'} = 'build_alias';
5154             $vars{'build_triplet'} = 'build';
5155             $vars{'target_alias'} = 'target_alias';
5156             $vars{'target_triplet'} = 'target';
5157         }
5158         foreach $curs (sort keys %vars)
5159         {
5160             $output_vars .= "$curs = \@$vars{$curs}\@\n";
5161             $contents{$curs} = "\@$vars{$curs}\@";
5162         }
5163     }
5165     local ($curs);
5166     foreach $curs (sort keys %configure_vars)
5167     {
5168         &define_configure_variable ($curs);
5169     }
5171     $output_vars .= $am_vars;
5174 ################################################################
5176 sub initialize_global_constants
5178     # Values for AC_CANONICAL_*
5179     $AC_CANONICAL_HOST = 1;
5180     $AC_CANONICAL_SYSTEM = 2;
5182     # Associative array of standard directory names.  Entry is TRUE if
5183     # corresponding directory should be installed during
5184     # 'install-exec' phase.
5185     %exec_dir_p =
5186         ('bin', 1,
5187          'sbin', 1,
5188          'libexec', 1,
5189          'data', 0,
5190          'sysconf', 1,
5191          'localstate', 1,
5192          'lib', 1,
5193          'info', 0,
5194          'man', 0,
5195          'include', 0,
5196          'oldinclude', 0,
5197          'pkgdata', 0,
5198          'pkglib', 1,
5199          'pkginclude', 0
5200          );
5202     # Helper text for dealing with man pages.
5203     $install_man_format =
5204     '   @sect=@SECTION@;                                \\
5205         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
5206         if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
5207         else file=@MAN@; fi; \\
5208         echo " $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst"; \\
5209         $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst
5212     $uninstall_man_format =
5213     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
5214         rm -f $(mandir)/man@SECTION@/$$inst
5217     # Commonly found files we look for and automatically include in
5218     # DISTFILES.
5219     @common_files =
5220         (
5221          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
5222          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
5223          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
5224          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
5225          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
5226          'ylwrap', 'acinclude.m4', @libtoolize_files,
5227          'missing'
5228          );
5230     # Commonly used files we auto-include, but only sometimes.
5231     @common_sometimes =
5232         (
5233          "aclocal.m4", "acconfig.h", "config.h.top",
5234          "config.h.bot", "stamp-h.in", 'stamp-vti'
5235          );
5237     $USAGE = "\
5238   -a, --add-missing     add missing standard files to package
5239   --amdir=DIR           directory storing config files
5240   --build-dir=DIR       directory where build being done (for dependencies)
5241   --cygnus              assume program is part of Cygnus-style tree
5242   --foreign             set strictness to foreign
5243   --gnits               set strictness to gnits
5244   --gnu                 set strictness to gnu
5245   --help                print this help, then exit
5246   -i, --include-deps    include generated dependencies in Makefile.in
5247   --no-force            only update Makefile.in's that are out of date
5248   -o DIR, --output-dir=DIR
5249                         put generated Makefile.in's into DIR
5250   --srcdir-name=DIR     name used for srcdir (for dependencies)
5251   -v, --verbose         verbosely list files processed
5252   --version             print version number, then exit\n";
5254     # Copyright on generated Makefile.ins.
5255     $gen_copyright = "\
5256 # Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
5257 # This Makefile.in is free software; the Free Software Foundation
5258 # gives unlimited permission to copy and/or distribute it,
5259 # with or without modifications, as long as this notice is preserved.
5262     # Ignore return result from chmod, because it might give an error
5263     # if we chmod a symlink.
5264     $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
5265     $dist{'dist-tarZ'} = ("\t"
5266                      . '$(TAR) chf - $(distdir) | compress -c > $(distdir).tar.Z'
5267                      . "\n");
5268     $dist{'dist-shar'} = ("\t"
5269                      . 'shar $(distdir) | gzip > $(distdir).shar.gz'
5270                      . "\n");
5271     $dist{'dist-zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
5272     $dist{'dist'} = "\t" .  'GZIP=$(GZIP) $(TAR) chozf $(distdir).tar.gz $(distdir)' . "\n";
5273     $dist_trailer = "\t" . 'rm -rf $(distdir)' . "\n";
5276 # (Re)-Initialize per-Makefile.am variables.
5277 sub initialize_per_input
5279     # These two variables are used when generating each Makefile.in.
5280     # They hold the Makefile.in until it is ready to be printed.
5281     $output_rules = '';
5282     $output_vars = '';
5283     $output_trailer = '';
5284     $output_header = '';
5286     # Suffixes found during a run.
5287     @suffixes = ();
5289     # This holds the contents of a Makefile.am, as parsed by
5290     # read_am_file.
5291     %contents = ();
5293     # This holds the names which are targets.  These also appear in
5294     # %contents.
5295     %targets = ();
5297     # For a variable or target which is defined conditionally, this
5298     # holds an array of the conditional values.  The array is composed
5299     # of pairs of condition strings (the variables which configure
5300     # will substitute) and values (the value of a target is
5301     # meaningless).  For an unconditional variable, this is empty.
5302     %conditional = ();
5304     # This holds the line numbers at which various elements of
5305     # %contents are defined.
5306     %content_lines = ();
5308     # This holds a 1 if a particular variable was examined.
5309     %content_seen = ();
5311     # This is the conditional stack.
5312     @conditional_stack = ();
5314     # This holds the "relative directory" of the current Makefile.in.
5315     # Eg for src/Makefile.in, this is "src".
5316     $relative_dir = '';
5318     # This holds a list of files that are included in the
5319     # distribution.
5320     %dist_common = ();
5322     # List of dependencies for the obvious targets.
5323     @install_data = ();
5324     @install_exec = ();
5325     @uninstall = ();
5326     @installdirs = ();
5328     @info = ();
5329     @dvi = ();
5330     @all = ();
5331     @check = ();
5332     @check_tests = ();
5333     @installcheck = ();
5334     @clean = ();
5336     @phony = ();
5338     # These are pretty obvious, too.  They are used to define the
5339     # SOURCES and OBJECTS variables.
5340     @sources = ();
5341     @objects = ();
5343     # TRUE if current directory holds any C source files.
5344     $dir_holds_sources = 0;
5346     # These variables track inclusion of various compile-related .am
5347     # files.  $included_generic_compile is TRUE if the basic code has
5348     # been included.  $included_knr_compile is TRUE if the ansi2knr
5349     # code has been included.  $included_libtool_compile is TRUE if
5350     # libtool support has been included.
5351     $included_generic_compile = 0;
5352     $included_knr_compile = 0;
5353     $included_libtool_compile = 0;
5355     # TRUE if current directory holds any headers.
5356     $dir_holds_headers = 0;
5358     # TRUE if install targets should work recursively.
5359     $recursive_install = 0;
5361     # All .P files.
5362     %dep_files = ();
5364     # Strictness levels.
5365     $strictness = $default_strictness;
5366     $strictness_name = $default_strictness_name;
5368     # Options from AUTOMAKE_OPTIONS.
5369     %options = ();
5371     # Whether or not dependencies are handled.  Can be further changed
5372     # in handle_options.
5373     $use_dependencies = $cmdline_use_dependencies;
5375     # Per Makefile.am.
5376     $local_maint_charset = $maint_charset;
5378     # All yacc and lex source filenames for this directory.  Use
5379     # filenames instead of raw count so that multiple instances are
5380     # counted correctly (eg one yacc file can appear in multiple
5381     # programs without harm).
5382     %yacc_sources = ();
5383     %lex_sources = ();
5385     # C++ source extensions we've seen.
5386     %cxx_extensions = ();
5388     # TRUE if we've seen any non-C++ sources.  This actually holds a
5389     # line number or the name of a symbol corresponding to a line
5390     # number where the C sources were seen.  If it is -1 then it means
5391     # we couldn't (easily) figure out which line of the Makefile.am
5392     # mentioned the sources.
5393     $seen_c_source = 0;
5395     # This is a list of all targets to run during "make dist".
5396     @dist_targets = ();
5398     # Keys in this hash are the basenames of files which must depend
5399     # on ansi2knr.
5400     %de_ansi_files = ();
5404 ################################################################
5406 # Return contents of a file from $am_dir, automatically skipping
5407 # macros or rules which are already known.  Runs command on each line
5408 # as it is read; this command can modify $_.
5409 sub file_contents_with_transform
5411     local ($command, $basename) = @_;
5412     local ($file) = $am_dir . '/' . $basename . '.am';
5414     if ($command ne '' && substr ($command, -1) ne ';')
5415     {
5416         die "automake: programming error in file_contents_with_transform\n";
5417     }
5419     open (FC_FILE, $file)
5420         || die "automake: installation error: cannot open \`$file'\n";
5421     # Looks stupid?
5422     # print "automake: reading $file\n" if $verbose;
5424     local ($was_rule) = 0;
5425     local ($result_vars) = '';
5426     local ($result_rules) = '';
5427     local ($comment) = '';
5428     local ($spacing) = "\n";
5429     local ($skipping) = 0;
5430     local ($had_chars);
5432     while (<FC_FILE>)
5433     {
5434         $_ =~ s/\@MAINT\@//g
5435             unless $seen_maint_mode;
5437         $had_chars = length ($_) && $_ ne "\n";
5438         eval $command;
5439         # If the transform caused all the characters to go away, then
5440         # ignore the line.  Why do this?  Because in Perl 4, a "next"
5441         # inside of an eval doesn't affect a loop outside the eval.
5442         # So we can't pass in a "transform" that uses next.  We used
5443         # to do this.  "Empty" also means consisting of a single
5444         # newline.
5445         next if $had_chars && ($_ eq '' || $_ eq "\n");
5447         if (/$IGNORE_PATTERN/o)
5448         {
5449             # Merely delete comments beginning with two hashes.
5450         }
5451         elsif (/$WHITE_PATTERN/o)
5452         {
5453             # Stick a single white line before the incoming macro or rule.
5454             $spacing = "\n";
5455         }
5456         elsif (/$COMMENT_PATTERN/o)
5457         {
5458             # Stick comments before the incoming macro or rule.
5459             $comment .= $spacing . $_;
5460             $spacing = '';
5461         }
5462         elsif ($saw_bk)
5463         {
5464             if ($was_rule)
5465             {
5466                 $result_rules .= $_ if ! $skipping;
5467             }
5468             else
5469             {
5470                 $result_vars .= $_ if ! $skipping;
5471             }
5472             $saw_bk = /\\$/;
5473         }
5474         elsif (/$RULE_PATTERN/o)
5475         {
5476             # Found a rule.
5477             $was_rule = 1;
5478             $skipping = defined $contents{$1};
5479             $result_rules .= $comment . $spacing . $_ if ! $skipping;
5480             $comment = $spacing = '';
5481             $saw_bk = /\\$/;
5482         }
5483         elsif (/$MACRO_PATTERN/o)
5484         {
5485             # Found a variable reference.
5486             $was_rule = 0;
5487             $skipping = defined $contents{$1};
5488             $result_vars .= $comment . $spacing . $_ if ! $skipping;
5489             $comment = $spacing = '';
5490             $saw_bk = /\\$/;
5491         }
5492         else
5493         {
5494             # This isn't an error; it is probably a continued rule.
5495             # In fact, this is what we assume.
5496             $was_rule = 1;
5497             $result_rules .= $comment . $spacing . $_ if ! $skipping;
5498             $comment = $spacing = '';
5499             $saw_bk = /\\$/;
5500         }
5501     }
5503     close (FC_FILE);
5504     return $result_vars . $result_rules . $comment;
5507 # Like file_contents_with_transform, but no transform.
5508 sub file_contents
5510     return &file_contents_with_transform ('', @_);
5513 # Find all variable prefixes that are used for install directories.  A
5514 # prefix `zar' qualifies iff:
5515 # * `zardir' is a variable.
5516 # * `zar_PRIMARY' is a variable.
5517 sub am_primary_prefixes
5519     local ($primary, @prefixes) = @_;
5521     local (%valid, $varname);
5522     grep ($valid{$_} = 0, @prefixes);
5523     $valid{'EXTRA'} = 0;
5524     foreach $varname (keys %contents)
5525     {
5526         if ($varname =~ /^(.*)_$primary$/)
5527         {
5528             if (! defined $valid{$1}
5529                 && ! &variable_defined ($1 . 'dir')
5530                 # Note that a configure variable is always legitimate.
5531                 # It is natural to name such variables after the
5532                 # primary, so we explicitly allow it.
5533                 && ! defined $configure_vars{$varname})
5534             {
5535                 &am_line_error ($varname, "invalid variable \`$varname'");
5536             }
5537             else
5538             {
5539                 # Ensure all extended prefixes are actually used.
5540                 $valid{$1} = 1;
5541             }
5542         }
5543     }
5545     return %valid;
5548 # Handle `where_HOW' variable magic.  Does all lookups, generates
5549 # install code, and possibly generates code to define the primary
5550 # variable.  The first argument is the name of the .am file to munge,
5551 # the second argument is the primary variable (eg HEADERS), and all
5552 # subsequent arguments are possible installation locations.  Returns
5553 # list of all values of all _HOW targets.
5555 # FIXME: this should be rewritten to be cleaner.  It should be broken
5556 # up into multiple functions.
5558 # Usage is: am_install_var (OPTION..., file, HOW, where...)
5559 sub am_install_var
5561     local (@args) = @_;
5563     local ($do_clean) = 0;
5565     local ($ltxform);
5566     if (defined $configure_vars{'LIBTOOL'})
5567     {
5568         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
5569         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
5570     }
5571     else
5572     {
5573         # Delete '@LIBTOOL ...@'
5574         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
5575     }
5577     local ($cygxform);
5578     if (! $seen_cygwin32)
5579     {
5580         $cygxform = 's/\@EXEEXT\@//g; s/^NOTCYGWIN//; s/^CYGWIN.*$//;';
5581     }
5582     else
5583     {
5584         $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g; s/^CYGWIN//; s/^NOTCYGWIN.*$//;';
5585     }
5587     while (@args)
5588     {
5589         if ($args[0] eq '-clean')
5590         {
5591             $do_clean = 1;
5592         }
5593         elsif ($args[0] !~ /^-/)
5594         {
5595             last;
5596         }
5597         shift (@args);
5598     }
5599     local ($file, $primary, @prefixes) = @args;
5601     local (@used) = ();
5602     local (@result) = ();
5604     # Now that configure substitutions are allowed in where_HOW
5605     # variables, it is an error to actually define the primary.
5606     &am_line_error ($primary, "\`$primary' is an anachronism")
5607         if &variable_defined ($primary);
5610     # Look for misspellings.  It is an error to have a variable ending
5611     # in a "reserved" suffix whose prefix is unknown, eg
5612     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
5613     # variable of the same name (with "dir" appended) exists.  For
5614     # instance, if the variable "zardir" is defined, then
5615     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
5616     # flexibility in those cases which need it.  Perhaps it should be
5617     # disallowed in the Gnits case?  The problem is, sometimes it is
5618     # useful to put things in a subdir of eg pkgdatadir, perhaps even
5619     # for Gnitsoids.
5620     local (%valid) = &am_primary_prefixes ($primary, @prefixes);
5622     # If a primary includes a configure substitution, then the EXTRA_
5623     # form is required.  Otherwise we can't properly do our job.
5624     local ($require_extra);
5625     local ($warned_about_extra) = 0;
5627     local ($clean_file) = $file . '-clean';
5628     local ($one_name);
5629     local ($X);
5630     foreach $X (sort keys %valid)
5631     {
5632         $one_name = $X . '_' . $primary;
5633         if (&variable_defined ($one_name))
5634         {
5635             # Append actual contents of where_PRIMARY variable to
5636             # result.
5637             local ($rcurs);
5638             foreach $rcurs (&variable_value_as_list ($one_name, 'all'))
5639             {
5640                 # Skip configure substitutions.  Possibly bogus.
5641                 if ($rcurs =~ /^\@.*\@$/)
5642                 {
5643                     if ($X eq 'EXTRA')
5644                     {
5645                         if (! $warned_about_extra)
5646                         {
5647                             $warned_about_extra = 1;
5648                             &am_line_error ($one_name,
5649                                             "\`$one_name' contains configure substitution, but shouldn't");
5650                         }
5651                     }
5652                     # Check here to make sure variables defined in
5653                     # configure.in do not imply that EXTRA_PRIMARY
5654                     # must be defined.
5655                     elsif (! defined $configure_vars{$one_name})
5656                     {
5657                         $require_extra = $one_name;
5658                     }
5659                     next;
5660                 }
5661                 push (@result, $rcurs);
5662             }
5664             # "EXTRA" shouldn't be used when generating clean targets,
5665             # @all, or install targets.
5666             next if $X eq 'EXTRA';
5668             if ($do_clean)
5669             {
5670                 $output_rules .=
5671                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
5672                                                    . $cygxform,
5673                                                    $clean_file);
5675                 push (@clean, $X . $primary);
5676                 &push_phony_cleaners ($X . $primary);
5677             }
5679             if ($X eq 'check')
5680             {
5681                 push (@check, '$(' . $one_name . ')');
5682             }
5683             else
5684             {
5685                 push (@used, '$(' . $one_name . ')');
5686             }
5687             if ($X eq 'noinst' || $X eq 'check')
5688             {
5689                 # Objects which don't get installed by default.
5690                 next;
5691             }
5693             $output_rules .=
5694                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
5695                                                . $ltxform . $cygxform,
5696                                                $file);
5698             push (@uninstall, 'uninstall-' . $X . $primary);
5699             push (@phony, 'uninstall-' . $X . $primary);
5700             push (@installdirs, '$(' . $X . 'dir)');
5701             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
5702             {
5703                 push (@install_exec, 'install-' . $X . $primary);
5704                 push (@phony, 'install-' . $X . $primary);
5705             }
5706             else
5707             {
5708                 push (@install_data, 'install-' . $X . $primary);
5709                 push (@phony, 'install-' . $X . $primary);
5710             }
5711         }
5712     }
5714     if (@used)
5715     {
5716         # Define it.
5717         &define_pretty_variable ($primary, '', @used);
5718         $output_vars .= "\n";
5719     }
5721     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
5722     {
5723         &am_line_error ($require_extra,
5724                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
5725     }
5727     # Push here because PRIMARY might be configure time determined.
5728     push (@all, '$(' . $primary . ')')
5729         if @used;
5731     return (@result);
5735 ################################################################
5737 # This variable is local to the "require file" set of functions.
5738 @require_file_paths = ();
5740 # Verify that the file must exist in the current directory.  Usage:
5741 # require_file (isconfigure, line_number, strictness, file) strictness
5742 # is the strictness level at which this file becomes required.  Must
5743 # set require_file_paths before calling this function.
5744 # require_file_paths is set to hold a single directory (the one in
5745 # which the first file was found) before return.
5746 sub require_file_internal
5748     local ($is_configure, $line, $mystrict, @files) = @_;
5749     local ($file, $fullfile);
5750     local ($found_it, $errfile, $errdir);
5751     local ($save_dir);
5753     foreach $file (@files)
5754     {
5755         $found_it = 0;
5756         foreach $dir (@require_file_paths)
5757         {
5758             if ($dir eq '.')
5759             {
5760                 $fullfile = $relative_dir . "/" . $file;
5761                 $errdir = $relative_dir unless $errdir;
5762             }
5763             else
5764             {
5765                 $fullfile = $dir . "/" . $file;
5766                 $errdir = $dir unless $errdir;
5767             }
5769             # Use different name for "error filename".  Otherwise on
5770             # an error the bad file will be reported as eg
5771             # `../../install-sh' when using the default
5772             # config_aux_path.
5773             $errfile = $errdir . '/' . $file;
5775             if (-f $fullfile)
5776             {
5777                 $found_it = 1;
5778                 # FIXME: Once again, special-case `.'.
5779                 &push_dist_common ($file)
5780                     if $dir eq $relative_dir || $dir eq '.';
5781                 $save_dir = $dir;
5782                 last;
5783             }
5784         }
5786         if ($found_it)
5787         {
5788             # Prune the path list.
5789             @require_file_paths = $save_dir;
5790         }
5791         else
5792         {
5793             if ($strictness >= $mystrict)
5794             {
5795                 local ($trailer) = '';
5796                 local ($suppress) = 0;
5798                 # Only install missing files according to our desired
5799                 # strictness level.
5800                 local ($message) = "required file \`$errfile' not found";
5801                 if ($add_missing)
5802                 {
5803                     $suppress = 1;
5805                     # Maybe run libtoolize.
5806                     if ($seen_libtool
5807                         && grep ($_ eq $file, @libtoolize_files)
5808                         && system ('libtoolize', '--automake'))
5809                     {
5810                         $message = "installing \`$errfile'";
5811                         $suppress = 0;
5812                         $trailer = "; cannot run \`libtoolize': $!";
5813                     }
5814                     elsif (-f ($am_dir . '/' . $file))
5815                     {
5816                         # Install the missing file.  Symlink if we
5817                         # can, copy if we must.  Note: delete the file
5818                         # first, in case it is a dangling symlink.
5819                         $message = "installing \`$errfile'";
5820                         unlink ($errfile);
5821                         if ($symlink_exists)
5822                         {
5823                             if (! symlink ($am_dir . '/' . $file, $errfile))
5824                             {
5825                                 $suppress = 0;
5826                                 $trailer = "; error while making link: $!\n";
5827                             }
5828                         }
5829                         elsif (! system ('cp', $am_dir . '/' . $file, $errfile))
5830                         {
5831                             $suppress = 0;
5832                             $trailer = "\n    error while making link\n";
5833                         }
5834                     }
5835                 }
5837                 local ($save) = $exit_status;
5838                 if ($is_configure)
5839                 {
5840                     # FIXME: allow actual file to be specified.
5841                     &am_conf_line_error ('configure.in', $line,
5842                                          "$message$trailer");
5843                 }
5844                 else
5845                 {
5846                     &am_line_error ($line, "$message$trailer");
5847                 }
5848                 $exit_status = $save if $suppress;
5849             }
5850         }
5851     }
5854 # Like require_file_with_line, but error messages refer to
5855 # configure.in, not the current Makefile.am.
5856 sub require_file_with_conf_line
5858     @require_file_paths = '.';
5859     &require_file_internal (1, @_);
5862 sub require_file_with_line
5864     @require_file_paths = '.';
5865     &require_file_internal (0, @_);
5868 sub require_file
5870     @require_file_paths = '.';
5871     &require_file_internal (0, '', @_);
5874 # Require a file that is also required by Autoconf.  Looks in
5875 # configuration path, as specified by AC_CONFIG_AUX_DIR.
5876 sub require_config_file
5878     @require_file_paths = @config_aux_path;
5879     &require_file_internal (1, '', @_);
5880     local ($dir) = $require_file_paths[0];
5881     @config_aux_path = @require_file_paths;
5882     if ($dir eq '.')
5883     {
5884         $config_aux_dir = '.';
5885     }
5886     else
5887     {
5888         $config_aux_dir = '$(top_srcdir)/' . $dir;
5889     }
5892 # Assumes that the line number is in Makefile.am.
5893 sub require_conf_file_with_line
5895     @require_file_paths = @config_aux_path;
5896     &require_file_internal (0, @_);
5897     local ($dir) = $require_file_paths[0];
5898     @config_aux_path = @require_file_paths;
5899     if ($dir eq '.')
5900     {
5901         $config_aux_dir = '.';
5902     }
5903     else
5904     {
5905         $config_aux_dir = '$(top_srcdir)/' . $dir;
5906     }
5909 # Assumes that the line number is in Makefile.am.
5910 sub require_conf_file_with_conf_line
5912     @require_file_paths = @config_aux_path;
5913     &require_file_internal (1, @_);
5914     local ($dir) = $require_file_paths[0];
5915     @config_aux_path = @require_file_paths;
5916     if ($dir eq '.')
5917     {
5918         $config_aux_dir = '.';
5919     }
5920     else
5921     {
5922         $config_aux_dir = '$(top_srcdir)/' . $dir;
5923     }
5926 ################################################################
5928 # Push a list of files onto dist_common.
5929 sub push_dist_common
5931     local (@files) = @_;
5932     local ($file);
5934     foreach $file (@files)
5935     {
5936         $dist_common{$file} = 1;
5937     }
5940 # Push a list of clean targets onto phony.
5941 sub push_phony_cleaners
5943     local ($base) = @_;
5944     local ($target);
5945     foreach $target ('mostly', 'dist', '', 'maintainer-')
5946     {
5947         push (@phony, $target . 'clean-' . $base);
5948     }
5951 # Set strictness.
5952 sub set_strictness
5954     $strictness_name = $_[0];
5955     if ($strictness_name eq 'gnu')
5956     {
5957         $strictness = $GNU;
5958     }
5959     elsif ($strictness_name eq 'gnits')
5960     {
5961         $strictness = $GNITS;
5962     }
5963     elsif ($strictness_name eq 'foreign')
5964     {
5965         $strictness = $FOREIGN;
5966     }
5967     else
5968     {
5969         die "automake: level \`$strictness_name' not recognized\n";
5970     }
5974 ################################################################
5976 # Return directory name of file.
5977 sub dirname
5979     local ($file) = @_;
5980     local ($sub);
5982     ($sub = $file) =~ s,/+[^/]+$,,g;
5983     $sub = '.' if $sub eq $file;
5984     return $sub;
5987 # Return file name of a file.
5988 sub basename
5990     local ($file) = @_;
5991     local ($sub);
5993     ($sub = $file) =~s,^.*/+,,g;
5994     return $sub;
5997 # Touch a file.
5998 sub touch
6000     local ($file) = @_;
6002     open (TOUCH, ">> $file");
6003     close (TOUCH);
6006 # Glob something.  Do this to avoid indentation screwups everywhere we
6007 # want to glob.  Gross!
6008 sub my_glob
6010     local ($pat) = @_;
6011     return <${pat}>;
6014 ################################################################
6016 # Print an error message and set exit status.
6017 sub am_error
6019     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
6020     $exit_status = 1;
6023 sub am_line_error
6025     local ($symbol, @args) = @_;
6027     if ($symbol && "$symbol" ne '-1')
6028     {
6029         # If SYMBOL not already a line number, look it up in Makefile.am.
6030         if ($symbol =~ /^\d+$/)
6031         {
6032             $symbol .= ': ';
6033         }
6034         elsif (defined $content_lines{$symbol})
6035         {
6036             $symbol = $content_lines{$symbol} . ': ';
6037         }
6038         else
6039         {
6040             # A single space, to provide nice separation.
6041             $symbol = ' ';
6042         }
6043         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
6044         $exit_status = 1;
6045     }
6046     else
6047     {
6048         &am_error (@args);
6049     }
6052 # Like am_error, but while scanning configure.in.
6053 sub am_conf_error
6055     # FIXME: can run in subdirs.
6056     warn "automake: configure.in: ", join (' ', @_), "\n";
6057     $exit_status = 1;
6060 # Error message with line number referring to configure.in.
6061 sub am_conf_line_error
6063     local ($file, $line, @args) = @_;
6065     if ($line)
6066     {
6067         warn "$file: $line: ", join (' ', @args), "\n";
6068         $exit_status = 1;
6069     }
6070     else
6071     {
6072         &am_conf_error (@args);
6073     }
6076 # Tell user where our aclocal.m4 is, but only once.
6077 sub keyed_aclocal_warning
6079     local ($key) = @_;
6080     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
6083 # Print usage information.
6084 sub usage
6086     print "Usage: automake [OPTION] ... [Makefile]...\n\n";
6087     print "Generate Makefile.in for autoconf from Makefile.am\n";
6088     print $USAGE;
6089     print "\nFiles which are automatically distributed, if found:\n";
6090     $~ = "USAGE_FORMAT";
6091     local (@lcomm) = sort ((@common_files, @common_sometimes));
6092     local ($one, $two, $three, $four);
6093     while (@lcomm > 0)
6094     {
6095         $one = shift @lcomm;
6096         $two = @lcomm ? shift @lcomm : '';
6097         $three = @lcomm ? shift @lcomm : '';
6098         $four = @lcomm ? shift @lcomm : '';
6099         write;
6100     }
6102     print "\nReport bugs to <automake-bugs\@gnu.ai.mit.edu>.\n";
6104     exit 0;
6107 format USAGE_FORMAT =
6108   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
6109   $one,               $two,               $three,             $four