fixed test
[automake.git] / automake.in
blob94d881399b61de407d7edff8bc48e7438ba8a960
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: how to do unsigned comparison?
576         if ($am_time < $in_time)
577         {
578             # No need to update.
579             return;
580         }
581     }
583     if (! open (GM_FILE, "> " . $out_file))
584     {
585         warn "automake: ${am_file}.in: cannot write: $!\n";
586         $exit_status = 1;
587         return;
588     }
589     print "automake: creating ", $makefile, ".in\n" if $verbose;
591     print GM_FILE $output_vars;
592     print GM_FILE $output_header;
593     print GM_FILE $output_rules;
594     print GM_FILE $output_trailer;
596     close (GM_FILE);
599 ################################################################
601 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
602 sub handle_options
604     return 0 if ! &variable_defined ('AUTOMAKE_OPTIONS');
606     foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
607     {
608         $options{$_} = 1;
609         if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
610         {
611             &set_strictness ($_);
612         }
613         elsif (/ansi2knr/)
614         {
615             # An option like "../lib/ansi2knr" is allowed.  With no
616             # path prefix, we assume the required programs are in this
617             # directory.  We save the actual option for later.
618             $options{'ansi2knr'} = $_;
619         }
620         elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
621                || $_ eq 'dist-shar' || $_ eq 'dist-zip'
622                || $_ eq 'dist-tarZ' || $_ eq 'dejagnu'
623                || $_ eq 'no-texinfo.tex')
624         {
625             # Explicitly recognize these.
626         }
627         elsif ($_ eq 'no-dependencies')
628         {
629             $use_dependencies = 0;
630         }
631         elsif (/([0-9]+)\.([0-9]+)/)
632         {
633             # Got a version number.  Note that alpha releases count as
634             # the next higher release.  Note also that we assume there
635             # will be a maximum of 100 minor releases for any given
636             # major release.
637             local ($rmajor, $rminor) = ($1, $2);
638             if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
639             {
640                 print STDERR
641                     "automake: programming error: version is incorrect\n";
642                 exit 1;
643             }
644             local ($tmajor, $tminor) = ($1, $2);
645             # Handle alpha versions.
646             ++$tminor if defined $3;
648             if ($rmajor > $tmajor || ($rmajor == $tmajor && $rminor > $tminor))
649             {
650                 &am_line_error ('AUTOMAKE_OPTIONS',
651                                 "require version $_, only have $VERSION");
652                 return 1;
653             }
654         }
655         else
656         {
657             &am_line_error ('AUTOMAKE_OPTIONS',
658                             'option ', $_, 'not recognized');
659         }
660     }
662     return 0;
665 # Return object extension.  Just once, put some code into the output.
666 # Argument is the name of the output file
667 sub get_object_extension
669     local ($out) = @_;
671     # Always set this.
672     $dir_holds_sources = 1;
674     # Maybe require libtool library object files.
675     local ($l, $extension) = ('', 'o');
676     $l = 'l' if ($out =~ /^lib.*\.la$/);
678     if (! $included_generic_compile)
679     {
680         # Boilerplate.
681         local ($xform) = '';
682         if (&variable_defined ('CONFIG_HEADER'))
683         {
684             local ($one_hdr);
685             foreach $one_hdr (split (' ', &variable_value ('CONFIG_HEADER')))
686             {
687                 local ($var);
688                 ($var = &dirname ($one_hdr)) =~ s/(\W)/\\$1/g;
689                 $xform .= ' ' if $xform;
690                 $xform .= '-I' . $var;
691             }
692         }
693         $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go;';
694         $output_vars .= &file_contents_with_transform ($xform,
695                                                        'comp-vars');
696         $output_rules .= &file_contents ('compile');
697         &push_phony_cleaners ('compile');
699         # If using X, include some extra variable definitions.  NOTE
700         # we don't want to force these into CFLAGS or anything,
701         # because not all programs will necessarily use X.
702         if ($seen_path_xtra)
703         {
704             local ($var);
705             foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
706             {
707                 &define_configure_variable ($var);
708             }
709         }
711         push (@suffixes, '.c', '.o');
712         push (@clean, 'compile');
714         $included_generic_compile = 1;
715     }
717     if ($seen_libtool && ! $included_libtool_compile)
718     {
719         # Output the libtool compilation rules.
720         $output_rules .= &file_contents ('libtool');
721         &push_phony_cleaners ('libtool');
723         push (@suffixes, '.lo');
724         push (@clean, 'libtool');
726         $included_libtool_compile = 1;
727     }
729     # Check for automatic de-ANSI-fication.
730     if (defined $options{'ansi2knr'})
731     {
732         $extension = '$o';
733         if (! $included_knr_compile)
734         {
735             if (! $am_c_prototypes)
736             {
737                 &am_line_error ('AUTOMAKE_OPTIONS',
738                                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
739                 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
740                 # Only give this error once.
741                 $am_c_prototypes = 1;
742             }
744             push (@suffixes, '._c', '._o');
745             push (@suffixes, '.l_o') if $seen_libtool;
747             # Only require ansi2knr files if they should appear in
748             # this directory.
749             if ($options{'ansi2knr'} eq 'ansi2knr')
750             {
751                 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
752                                          'ansi2knr.c', 'ansi2knr.1');
753                 $output_rules .= &file_contents ('kr-extra');
754                 push (@clean, 'krextra');
755                 &push_phony_cleaners ('krextra');
756             }
758             # Generate rules to build ansi2knr.  If it is in some
759             # other directory, then generate dependencies but have the
760             # rule just run elsewhere.
761             $output_rules .= ($options{'ansi2knr'} . ': '
762                               . $options{'ansi2knr'} . ".o\n");
763             if ($options{'ansi2knr'} eq 'ansi2knr')
764             {
765                 $output_rules .= ("\t\$(LINK) ansi2knr.o \$(LIBS)\n"
766                                   . "ansi2knr.o: \$(CONFIG_HEADER)\n\n");
767             }
768             else
769             {
770                 $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
771                                   . " && \$(MAKE) ansi2knr\n\n");
772             }
774             &define_variable ('o', "\@U\@o");
776             # Make sure ansi2knr can be found: if no path specified,
777             # specify "./".
778             if ($options{'ansi2knr'} eq 'ansi2knr')
779             {
780                 # Substitution from AM_C_PROTOTYPES.  This makes it be
781                 # built only when necessary.
782                 &define_configure_variable ('ANSI2KNR');
783                 # ansi2knr needs to be built before subdirs, so unshift it.
784                 unshift (@all, '$(ANSI2KNR)');
785             }
786             else
787             {
788                 # Found in another directory.
789                 &define_variable ("ANSI2KNR", &dirname ($options{'ansi2knr'}));
790             }
792             $output_rules .= &file_contents ('compile-kr');
793             $output_rules .= &file_contents ('clean-kr');
795             push (@clean, 'kr');
796             &push_phony_cleaners ('kr');
798             $included_knr_compile = 1;
799         }
800     }
802     return '.' . $l . $extension;
805 # Handle yacc and lex.
806 sub handle_yacc_lex_cxx
808     #
809     # First do yacc and lex.
810     #
812     local ($yacc_count) = scalar (keys %yacc_sources);
813     local ($lex_count) = scalar (keys %lex_sources);
815     if ($yacc_count)
816     {
817         local (%seen_suffix) = ();
818         foreach (keys %yacc_sources)
819         {
820             /(\..*)$/;
821             &output_yacc_build_rule ($1, $yacc_count > 1)
822                 if (! defined $seen_suffix{$1});
823             $seen_suffix{$1} = 1;
824         }
826         if (! defined $configure_vars{'YACC'})
827         {
828             &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
829         }
830     }
831     if ($lex_count)
832     {
833         local (%seen_suffix) = ();
834         foreach (keys %lex_sources)
835         {
836             /(\..*)$/;
837             &output_lex_build_rule ($1, $lex_count > 1)
838                 if (! defined $seen_suffix{$1});
839             $seen_suffix{$1} = 1;
840         }
842         if (! defined $configure_vars{'LEX'})
843         {
844             &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
845         }
846         if (! $seen_decl_yytext)
847         {
848             &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
849         }
850     }
852     if ($yacc_count > 1 || $lex_count > 1)
853     {
854         # If there is more than one distinct yacc (resp lex) source
855         # file in a given directory, then the `ylwrap' program is
856         # required to allow parallel builds to work correctly.  FIXME:
857         # for now, no line number.
858         &require_config_file ($FOREIGN, 'ylwrap');
859         if ($config_aux_dir ne '.' && $config_aux_dir ne '')
860         {
861                 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
862         }
863         else
864         {
865                 &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
866         }
867     }
869     #
870     # Handle libtool.
871     #
872     local ($ltcompile, $ltlink) = ('', '');
873     if ($seen_libtool)
874     {
875         &define_configure_variable ("LIBTOOL");
876         $ltcompile = '$(LIBTOOL) --mode=compile ';
877         $ltlink = '$(LIBTOOL) --mode=link ';
878     }
880     #
881     # Now handle C++.
882     #
883     local (@cxx_list) = keys %cxx_extensions;
884     local ($cxx_count) = scalar @cxx_list;
885     if ($cxx_count)
886     {
887         push (@suffixes, @cxx_list);
889         &define_configure_variable ("CXXFLAGS");
890         &define_variable ('CXXCOMPILE', '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
891         &define_variable ('LTCXXCOMPILE',
892                           $ltcompile . '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)')
893             if ($seen_libtool);
895         &define_variable ('CXXLINK', $ltlink . '$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@');
897         local ($ext);
898         foreach $ext (@cxx_list)
899         {
900             $output_rules .= ("$ext.o:\n"
901                               . "\t\$(CXXCOMPILE) -c \$<\n");
902             $output_rules .= ("$ext.lo:\n"
903                               . "\t\$(LTCXXCOMPILE) -c \$<\n")
904                 if ($seen_libtool);
905         }
907         if (! defined $configure_vars{'CXX'})
908         {
909             &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
910         }
911     }
913     #
914     # Handle some ansi2knr cleanup.
915     #
916     if (defined $options{'ansi2knr'} && keys %de_ansi_objects)
917     {
918         # Make all ._o files depend on ansi2knr.  Use a sneaky little
919         # hack to make it print nicely.
920         &pretty_print_rule ('', '', ((sort keys %de_ansi_objects),
921                                      ':', '$(ANSI2KNR)'));
922         # The ._c files also depend on ansi2knr.  We need both because
923         # some makes don't apply transitivity through implicit rules.
924         local (%de_ansi_sources, $x);
925         foreach $x (keys %de_ansi_objects)
926         {
927             $x =~ s/o$/c/;
928             $de_ansi_sources{$x} = 1;
929         }
930         &pretty_print_rule ('', '', ((sort keys %de_ansi_sources),
931                                      ':', '$(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.
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 $*' . $suffix
977                               . ' y.tab.h $*.h -- $(YFLAGS)');
978         }
979         else
980         {
981             $output_rules .= ('$(YACC) $(YFLAGS) $< && 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 (s/\.[cly]$/._o/)
1132             {
1133                 # .c is C.  .l is lex.  .y is yacc.
1135                 # Note: first we rewrite (eg) foo.c to foo._o and push
1136                 # the file onto the list of objects that require
1137                 # ansi2knr.  Then we rewrite ._o to $obj; $obj can be
1138                 # simply `.o' if deansification is not really
1139                 # required.
1140                 $de_ansi_objects{$_} = 1;
1141                 s/\._o$/$obj/;
1142                 $seen_c_source = -1 unless $seen_c_source;
1143             }
1144             else
1145             {
1146                 # No error message here.  Used to have one, but it was
1147                 # very unpopular.
1148                 next;
1149             }
1151             push (@result, $_);
1153             # Transform .o or $o file into .P file (for automatic
1154             # dependency code).
1155             s/$objpat$/.P/g;
1156             $dep_files{'.deps/' . $_} = 1;
1157         }
1158     }
1160     return ($linker, @result);
1163 # Handle SOURCE->OBJECT transform for one program or library.
1164 # Arguments are:
1165 #   canonical (transformed) name of object to build
1166 #   actual name of object to build
1167 #   object extension (ie either `.o' or `$o'.
1168 # Return result is name of linker variable that must be used.
1169 # Empty return means just use `LINK'.
1170 sub handle_source_transform
1172     # one_file is canonical name.  unxformed is given name.  obj is
1173     # object extension.
1174     local ($one_file, $unxformed, $obj) = @_;
1175     local ($objpat) = $obj;
1176     $objpat =~ s/(\W)/\\$1/g;
1177     # Handle explicit `.o' as well as whatever we're passed.
1178     $objpat = '(' . $objpat . "|\\.o)";
1180     local ($linker) = '';
1182     if (&variable_defined ($one_file . "_OBJECTS"))
1183     {
1184         &am_line_error ($one_file . '_OBJECTS',
1185                         $one_file . '_OBJECTS', 'should not be defined');
1186         # No point in continuing.
1187         return;
1188     }
1190     local (@files, @result, $prefix, $temp);
1191     foreach $prefix ('', 'EXTRA_')
1192     {
1193         @files = ();
1194         local ($var) = $prefix . $one_file . "_SOURCES";
1195         if (&variable_defined ($var))
1196         {
1197             push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1198             push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
1199                 unless $prefix eq 'EXTRA_';
1200             local (@conds) = &variable_conditions ($var);
1201             if (! @conds)
1202             {
1203                 @files = &variable_value_as_list ($var, '');
1204             }
1205             else
1206             {
1207                 local ($cond);
1208                 foreach $cond (@conds)
1209                 {
1210                     @files = &variable_value_as_list ($var, $cond);
1211                     ($temp, @result) = &handle_single_transform_list (@files);
1212                     $linker = $temp if $linker eq '';
1213                     &define_pretty_variable ($one_file . "_OBJECTS", $cond,
1214                                              @result)
1215                         unless $prefix eq 'EXTRA_';
1216                 }
1218                 next;
1219             }
1220         }
1221         elsif ($prefix eq '')
1222         {
1223             &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1224             push (@sources, $unxformed . '.c');
1225             push (@objects, $unxformed . $obj);
1226             push (@files, $unxformed . '.c');
1227         }
1229         ($temp, @result) = &handle_single_transform_list (@files);
1230         $linker = $temp if $linker eq '';
1231         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
1232             unless $prefix eq 'EXTRA_';
1233     }
1235     return $linker;
1238 # Handle the BUILT_SOURCES variable.
1239 sub handle_built_sources
1241     return unless &variable_defined ('BUILT_SOURCES');
1242     push (@all, '$(BUILT_SOURCES)');
1244     local (@sources) = &variable_value_as_list ('BUILT_SOURCES', 'all');
1245     local ($s);
1246     foreach $s (@sources)
1247     {
1248         if (/^\@.*\@$/)
1249         {
1250             # FIXME: is this really the right thing to do?
1251             &am_line_error ('BUILT_SOURCES', "\`BUILT_SOURCES' should not contain a configure substitution");
1252             last;
1253         }
1254     }
1256     # We don't care about the return value of this function.  We just
1257     # want to make sure to update %dep_files with the contents of
1258     # BUILT_SOURCES.
1259     &handle_single_transform_list (@sources);
1262 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
1263 # Also, generate _DEPENDENCIES variable if appropriate.
1264 # Arguments are:
1265 #   transformed name of object being built, or empty string if no object
1266 #   name of _LDADD/_LIBADD-type variable to examine
1267 #   boolean (lex_seen) which is true if a lex source file was seen in this
1268 #     object.  valid only for LDADDs, not LIBADDs.  If set, LEXLIB
1269 #     must be in LDADD.
1270 # Returns 1 if LIBOBJS seen, 0 otherwise.
1271 sub handle_lib_objects
1273     local ($xname, $var, $lex_seen) = @_;
1274     local ($ret);
1276     die "automake: programming error 1 in handle_lib_objects\n"
1277         if ! &variable_defined ($var);
1279     die "automake: programming error 2 in handle_lib_objects\n"
1280         if $lex_seen && $var =~ /LIBADD/;
1282     local (@conds) = &variable_conditions ($var);
1283     if (! @conds)
1284     {
1285         $ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
1286     }
1287     else
1288     {
1289         local ($cond);
1290         $ret = 0;
1291         foreach $cond (@conds)
1292         {
1293             if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
1294             {
1295                 $ret = 1;
1296             }
1297         }
1298     }
1300     return $ret;
1303 # Subroutine of handle_lib_objects: handle a particular condition.
1304 sub handle_lib_objects_cond
1306     local ($xname, $var, $lex_seen, $cond) = @_;
1308     # We recognize certain things that are commonly put in LIBADD or
1309     # LDADD.
1310     local ($lsearch);
1311     local (@dep_list) = ();
1313     # If no lex source seen, just assume this is ok.
1314     local ($lex_ok) = $lex_seen ? 0 : 1;
1316     local ($seen_libobjs) = 0;
1317     local ($flagvar) = 0;
1319     foreach $lsearch (&variable_value_as_list ($var, $cond))
1320     {
1321         # Skip -lfoo and -Ldir; these are explicitly allowed.
1322         next if $lsearch =~ /^-[lL]/;
1323         if (! $flagvar && $lsearch =~ /^-/)
1324         {
1325             if ($var =~ /^(.*)LDADD$/)
1326             {
1327                 &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
1328             }
1329             else
1330             {
1331                 # Only get this error once.
1332                 $flagvar = 1;
1333                 &am_line_error ($var, "you cannot use linker flags such as \`$lsearch' in \`$var'");
1334             }
1335         }
1337         # Assume we have a file of some sort, and push it onto the
1338         # dependency list.  Autoconf substitutions are not pushed;
1339         # rarely is a new dependency substituted into (eg) foo_LDADD
1340         # -- but "bad things (eg -lX11) are routinely substituted.
1341         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
1342         # and handled specially below.
1343         push (@dep_list, $lsearch)
1344             unless $lsearch =~ /^\@.*\@$/;
1346         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
1347         # means adding entries to dep_files.
1348         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
1349         {
1350             push (@dep_list, $lsearch);
1351             $seen_libobjs = 1;
1352             if (! keys %libsources)
1353             {
1354                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
1355             }
1357             local ($iter, $rewrite);
1358             foreach $iter (keys %libsources)
1359             {
1360                 if ($iter =~ /\.[cly]$/)
1361                 {
1362                     $seen_c_source = $var;
1363                 }
1365                 if ($iter =~ /\.h$/)
1366                 {
1367                     &require_file_with_line ($var, $FOREIGN, $iter);
1368                 }
1369                 elsif ($iter ne 'alloca.c')
1370                 {
1371                     ($rewrite = $iter) =~ s/\.c$/.P/;
1372                     $dep_files{'.deps/' . $rewrite} = 1;
1373                     &require_file_with_line ($var, $FOREIGN, $iter);
1374                 }
1375             }
1376         }
1377         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
1378         {
1379             push (@dep_list, $lsearch);
1380             &am_line_error ($var,
1381                             "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
1382                 if ! defined $libsources{'alloca.c'};
1383             $dep_files{'.deps/alloca.P'} = 1;
1384             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
1385             $seen_c_source = $var;
1386         }
1387         elsif ($lsearch eq '@LEXLIB@')
1388         {
1389             # FIXME: variable_value_as_list requires us to force
1390             # @LEXLIB@ here, where we'd really prefer $(LEXLIB).
1391             # Nasty -- this will have to wait until many cleanups are
1392             # made, I think.
1393             $lex_ok = 1;
1394         }
1395     }
1397     if (! $lex_ok)
1398     {
1399         &am_line_error ($var, 'lex source file used without @LEXLIB@');
1400     }
1402     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
1403     {
1404         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
1405     }
1407     return $seen_libobjs;
1410 # Canonicalize a name, and check to make sure the non-canonical name
1411 # is never used.  Returns canonical name.  Arguments are name and a
1412 # list of suffixes to check for.
1413 sub check_canonical_spelling
1415     local ($name, @suffixes) = @_;
1416     local ($xname, $xt);
1418     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
1419     if ($xname ne $name)
1420     {
1421         local ($xt);
1422         foreach $xt (@suffixes)
1423         {
1424             &am_line_error ($name . $xt,
1425                             "invalid variable \`" . $name . $xt
1426                             . "'; should be \`" . $xname . $xt . "'")
1427                 if &variable_defined ($name . $xt);
1428         }
1429     }
1431     return $xname;
1434 # Handle C programs.
1435 sub handle_programs
1437     local (@proglist) = &am_install_var ('-clean',
1438                                          'progs', 'PROGRAMS',
1439                                          'bin', 'sbin', 'libexec', 'pkglib',
1440                                          'noinst', 'check');
1441     return if ! @proglist;
1443     # If a program is installed, this is required.  We only want this
1444     # error to appear once.
1445     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1446         unless $seen_arg_prog;
1447     $seen_arg_prog = 1;
1449     local ($one_file, $xname, $munge);
1451     local ($seen_libobjs) = 0;
1452     foreach $one_file (@proglist)
1453     {
1454         local ($obj) = &get_object_extension ($one_file);
1456         # Canonicalize names and check for misspellings.
1457         $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
1458                                             '_SOURCES', '_OBJECTS',
1459                                             '_DEPENDENCIES');
1461         # FIXME: Using a trick to figure out if any lex sources appear
1462         # in our program; should use some cleaner method.
1463         local ($lex_num) = scalar (keys %lex_sources);
1464         local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
1465         local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
1467         local ($xt) = '';
1468         if (&variable_defined ($xname . "_LDADD"))
1469         {
1470             if (&handle_lib_objects ($xname, $xname . '_LDADD',
1471                                      $lex_file_seen))
1472             {
1473                 $seen_libobjs = 1;
1474             }
1475             $lex_file_seen = 0;
1476             $xt = '_LDADD';
1477         }
1478         else
1479         {
1480             # User didn't define prog_LDADD override.  So do it.
1481             &define_variable ($xname . '_LDADD', '$(LDADD)');
1483             # This does a bit too much work.  But we need it to
1484             # generate _DEPENDENCIES when appropriate.
1485             if (&variable_defined ('LDADD'))
1486             {
1487                 if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
1488                 {
1489                     $seen_libobjs = 1;
1490                 }
1491                 $lex_file_seen = 0;
1492             }
1493             $xt = '_SOURCES'
1494         }
1496         if (&variable_defined ($xname . '_LIBADD'))
1497         {
1498             &am_line_error ($xname . '_LIBADD',
1499                             "use \`" . $xname . "_LDADD', not \`"
1500                             . $xname . "_LIBADD'");
1501         }
1503         if (! &variable_defined ($xname . '_LDFLAGS'))
1504         {
1505             # Define the prog_LDFLAGS variable.
1506             &define_variable ($xname . '_LDFLAGS', '');
1507         }
1509         if ($lex_file_seen)
1510         {
1511             &am_line_error ($xname . $xt,
1512                             'lex source file used without @LEXLIB@');
1513         }
1515         # Determine program to use for link.
1516         local ($xlink);
1517         if (&variable_defined ($xname . '_LINK'))
1518         {
1519             $xlink = $xname . '_LINK';
1520         }
1521         else
1522         {
1523             $xlink = $linker ? $linker : 'LINK';
1524         }
1526         local ($cygxform);
1527         if (! $seen_cygwin32)
1528         {
1529             $cygxform = 's/^CYGWIN.*$//; s/^NOTCYGWIN//;';
1530         }
1531         else
1532         {
1533             $cygxform = 's/^NOTCYGWIN.*$//; s/^CYGWIN//;';
1534         }
1536         $output_rules .=
1537             &file_contents_with_transform
1538                 ('s/\@PROGRAM\@/' . $one_file . '/go;'
1539                  . 's/\@XPROGRAM\@/' . $xname . '/go;'
1540                  . 's/\@XLINK\@/' . $xlink . '/go;'
1541                  . $cygxform,
1542                  'program');
1543     }
1545     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
1546     {
1547         $seen_libobjs = 1;
1548     }
1550     if ($seen_libobjs)
1551     {
1552         foreach $one_file (@proglist)
1553         {
1554             # Canonicalize names.
1555             ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
1557             if (&variable_defined ($xname . '_LDADD'))
1558             {
1559                 &check_libobjs_sources ($xname, $xname . '_LDADD');
1560             }
1561             elsif (&variable_defined ('LDADD'))
1562             {
1563                 &check_libobjs_sources ($xname, 'LDADD');
1564             }
1565         }
1566     }
1570 # Handle libraries.
1571 sub handle_libraries
1573     local (@liblist) = &am_install_var ('-clean',
1574                                         'libs', 'LIBRARIES',
1575                                         'lib', 'pkglib', 'noinst', 'check');
1576     return if ! @liblist;
1578     local (%valid) = &am_primary_prefixes ('LIBRARIES', 'lib', 'pkglib',
1579                                            'noinst', 'check');
1580     if (! defined $configure_vars{'RANLIB'})
1581     {
1582         local ($key);
1583         foreach $key (keys %valid)
1584         {
1585             if (&variable_defined ($key . '_LIBRARIES'))
1586             {
1587                 &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
1588                 # Only get this error once.
1589                 $configure_vars{'RANLIB'} = 1;
1590                 last;
1591             }
1592         }
1593     }
1595     local ($onelib);
1596     local ($munge);
1597     local ($xlib);
1598     local ($seen_libobjs) = 0;
1599     foreach $onelib (@liblist)
1600     {
1601         # Check that the library fits the standard naming convention.
1602         if ($onelib !~ /^lib.*\.a$/)
1603         {
1604             # FIXME this should only be a warning for foreign packages
1605             # FIXME should put line number here.  That means mapping
1606             # from library name back to variable name.
1607             &am_error ("\`$onelib' is not a standard library name");
1608         }
1610         local ($obj) = &get_object_extension ($onelib);
1612         # Canonicalize names and check for misspellings.
1613         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
1614                                            '_OBJECTS', '_DEPENDENCIES');
1616         if (&variable_defined ($xlib . '_LIBADD'))
1617         {
1618             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1619             {
1620                 $seen_libobjs = 1;
1621             }
1622         }
1623         else
1624         {
1625             # Generate support for conditional object inclusion in
1626             # libraries.
1627             &define_variable ($xlib . "_LIBADD", '');
1628         }
1630         if (&variable_defined ($xlib . '_LDADD'))
1631         {
1632             &am_line_error ($xlib . '_LDADD',
1633                             "use \`" . $xlib . "_LIBADD', not \`"
1634                             . $xlib . "_LDADD'");
1635         }
1637         &handle_source_transform ($xlib, $onelib, $obj);
1639         $output_rules .=
1640             &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
1641                                            . 's/\@XLIBRARY\@/'
1642                                            . $xlib . '/go;',
1643                                            'library');
1644     }
1646     if ($seen_libobjs)
1647     {
1648         foreach $onelib (@liblist)
1649         {
1650             # Canonicalize names.
1651             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1652             if (&variable_defined ($xlib . '_LIBADD'))
1653             {
1654                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1655             }
1656         }
1657     }
1659     &define_variable ('AR', 'ar');
1660     &define_configure_variable ('RANLIB');
1663 # Handle shared libraries.
1664 sub handle_ltlibraries
1666     local (@liblist) = &am_install_var ('-clean',
1667                                         'ltlib', 'LTLIBRARIES',
1668                                         'lib', 'pkglib');
1669     return if ! @liblist;
1671     local (%instdirs);
1672     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 'lib', 'pkglib');
1674     local ($key);
1675     foreach $key (keys %valid)
1676     {
1677         if (&variable_defined ($key . '_LTLIBRARIES'))
1678         {
1679             if (!$seen_libtool)
1680             {
1681                 &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
1682                 # Only get this error once.
1683                 $configure_vars{'LIBTOOL'} = 1;
1684                 $seen_libtool = 1;
1685             }
1687             # Get the installation directory of each library.
1688             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
1689             {
1690                 if ($instdirs{$_})
1691                 {
1692                     &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
1693                 }
1694                 else
1695                 {
1696                     $instdirs{$_} = $key;
1697                 }
1698             }
1699         }
1700     }
1702     local ($onelib);
1703     local ($munge);
1704     local ($xlib);
1705     local ($seen_libobjs) = 0;
1706     foreach $onelib (@liblist)
1707     {
1708         # Check that the library fits the standard naming convention.
1709         if ($onelib !~ /^lib.*\.la$/)
1710         {
1711             # FIXME this should only be a warning for foreign packages
1712             # FIXME should put line number here.  That means mapping
1713             # from library name back to variable name.
1714             &am_error ("\`$onelib' is not a standard libtool library name");
1715         }
1717         local ($obj) = &get_object_extension ($onelib);
1719         # Canonicalize names and check for misspellings.
1720         $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
1721                                            '_SOURCES', '_OBJECTS',
1722                                            '_DEPENDENCIES');
1724         if (! &variable_defined ($xlib . '_LDFLAGS'))
1725         {
1726             # Define the lib_LDFLAGS variable.
1727             &define_variable ($xlib . '_LDFLAGS', '');
1728         }
1730         if (&variable_defined ($xlib . '_LIBADD'))
1731         {
1732             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
1733             {
1734                 $seen_libobjs = 1;
1735             }
1736         }
1737         else
1738         {
1739             # Generate support for conditional object inclusion in
1740             # libraries.
1741             &define_variable ($xlib . "_LIBADD", '');
1742         }
1744         if (&variable_defined ($xlib . '_LDADD'))
1745         {
1746             &am_line_error ($xlib . '_LDADD',
1747                             "use \`" . $xlib . "_LIBADD', not \`"
1748                             . $xlib . "_LDADD'");
1749         }
1751         local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
1753         # Determine program to use for link.
1754         local ($xlink);
1755         if (&variable_defined ($xlib . '_LINK'))
1756         {
1757             $xlink = $xlib . '_LINK';
1758         }
1759         else
1760         {
1761             $xlink = $linker ? $linker : 'LINK';
1762         }
1764         local ($rpath);
1765         if ($instdirs{$onelib} eq 'EXTRA')
1766         {
1767             # It's an EXTRA_ library, so we can't specify -rpath.
1768             # Yuck.
1769             $rpath = 's/\@RPATH\@//go;';
1770         }
1771         else
1772         {
1773             $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
1774                       . 'dir)/go;');
1775         }
1777         $output_rules .=
1778             &file_contents_with_transform ('s/\@LTLIBRARY\@/'
1779                                            . $onelib . '/go;'
1780                                            . 's/\@XLTLIBRARY\@/'
1781                                            . $xlib . '/go;'
1782                                            . $rpath
1783                                            . 's/\@XLINK\@/' . $xlink . '/go;',
1784                                            'ltlibrary');
1785     }
1787     if ($seen_libobjs)
1788     {
1789         foreach $onelib (@liblist)
1790         {
1791             # Canonicalize names.
1792             ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
1793             if (&variable_defined ($xlib . '_LIBADD'))
1794             {
1795                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
1796             }
1797         }
1798     }
1801 # See if any _SOURCES variable were misspelled.  Also, make sure that
1802 # EXTRA_ variables don't contain configure substitutions.
1803 sub check_typos
1805     local ($varname, $primary);
1806     foreach $varname (keys %contents)
1807     {
1808         foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS', '_DEPENDENCIES')
1809         {
1810             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
1811             {
1812                 &am_line_error ($varname,
1813                                 "invalid unused variable name: \`$varname'");
1814             }
1815         }
1816     }
1819 # Handle scripts.
1820 sub handle_scripts
1822     # NOTE we no longer automatically clean SCRIPTS, because it is
1823     # useful to sometimes distribute scripts verbatim.  This happens
1824     # eg in Automake itself.
1825     &am_install_var ('scripts', 'SCRIPTS',
1826                      'bin', 'sbin', 'libexec', 'pkgdata',
1827                      'noinst', 'check');
1829     # Set $scripts_installed if appropriate.  Make sure we only find
1830     # scripts which are actually installed -- this is why we can't
1831     # simply use the return value of am_install_var.
1832     local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
1833                                            'libexec', 'pkgdata',
1834                                            'noinst', 'check');
1835     local ($key);
1836     foreach $key (keys %valid)
1837     {
1838         if ($key ne 'noinst'
1839             && $key ne 'check'
1840             && &variable_defined ($key . '_SCRIPTS'))
1841         {
1842             $scripts_installed = 1;
1843             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
1844         }
1845     }
1847     if ($scripts_installed)
1848     {
1849         # If a program is installed, this is required.  We only want this
1850         # error to appear once.
1851         &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
1852             unless $seen_arg_prog;
1853         $seen_arg_prog = 1;
1854     }
1857 # Search a file for a "version.texi" Texinfo include.  Return the name
1858 # of the include file if found, or the empty string if not.  A
1859 # "version.texi" file is actually any file whose name matches
1860 # "vers*.texi".
1861 sub scan_texinfo_file
1863     local ($filename) = @_;
1865     if (! open (TEXI, $filename))
1866     {
1867         &am_error ("couldn't open \`$filename': $!");
1868         return '';
1869     }
1870     print "automake: reading $filename\n" if $verbose;
1872     local ($vfile, $outfile);
1873     while (<TEXI>)
1874     {
1875         if (/^\@setfilename +(\S+)/)
1876         {
1877             $outfile = $1;
1878             last if ($vfile);
1879         }
1881         if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
1882         {
1883             # Found version.texi include.
1884             $vfile = $1;
1885             last if $outfile;
1886         }
1887     }
1889     close (TEXI);
1890     return ($outfile, $vfile);
1893 # Handle all Texinfo source.
1894 sub handle_texinfo
1896     &am_line_error ('TEXINFOS',
1897                     "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
1898         if &variable_defined ('TEXINFOS');
1899     return if (! &variable_defined ('info_TEXINFOS')
1900                && ! &variable_defined ('html_TEXINFOS'));
1902     local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');
1904     local (@info_deps_list, @dvis_list, @texi_deps);
1905     local ($infobase, $info_cursor);
1906     local (%versions);
1907     local ($done) = 0;
1908     local ($vti);
1909     local ($tc_cursor, @texi_cleans);
1910     local ($canonical);
1912     foreach $info_cursor (@texis)
1913     {
1914         ($infobase = $info_cursor) =~ s/\.texi(nfo)?$//;
1916         # If 'version.texi' is referenced by input file, then include
1917         # automatic versioning capability.
1918         local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
1919                                                         . "/" . $info_cursor);
1921         if ($out_file eq '')
1922         {
1923             &am_error ("\`$info_cursor' missing \@setfilename");
1924             next;
1925         }
1927         if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
1928         {
1929             # FIXME should report line number in input file.
1930             &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
1931             next;
1932         }
1934         if ($vtexi)
1935         {
1936             &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
1937                 if (defined $versions{$vtexi});
1938             $versions{$vtexi} = $info_cursor;
1940             # We number the stamp-vti files.  This is doable since the
1941             # actual names don't matter much.  We only number starting
1942             # with the second one, so that the common case looks nice.
1943             $vti = 'vti' . ($done ? $done : '');
1944             &push_dist_common ($vtexi, 'stamp-' . $vti);
1945             push (@clean, $vti);
1947             # Only require once.
1948             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
1949                                           'mdate-sh')
1950                 if ! $done;
1951             ++$done;
1953             local ($conf_pat);
1954             ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
1955             $output_rules .=
1956                 &file_contents_with_transform
1957                     ('s/\@TEXI\@/' . $info_cursor . '/g; '
1958                      . 's/\@VTI\@/' . $vti . '/g; '
1959                      . 's/\@VTEXI\@/' . $vtexi . '/g;'
1960                      . 's,\@MDDIR\@,' . $conf_pat . ',g;',
1961                      'texi-vers');
1963             &push_phony_cleaners ($vti);
1964         }
1966         # If user specified file_TEXINFOS, then use that as explicit
1967         # dependency list.
1968         @texi_deps = ();
1969         push (@texi_deps, $info_cursor);
1970         push (@texi_deps, $vtexi) if $vtexi;
1972         # Canonicalize name first.
1973         ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
1974         if (&variable_defined ($canonical . "_TEXINFOS"))
1975         {
1976             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
1977             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
1978         }
1980         $output_rules .= ("\n" . $out_file . ": "
1981                           . join (' ', @texi_deps)
1982                           . "\n" . $infobase . ".dvi: "
1983                           . join (' ', @texi_deps)
1984                           . "\n\n");
1986         push (@info_deps_list, $out_file);
1987         push (@dvis_list, $infobase . '.dvi');
1989         # Generate list of things to clean for this target.  We do
1990         # this explicitly because otherwise too many things could be
1991         # removed.  In particular the ".log" extension might
1992         # reasonably be used in other contexts by the user.
1993         foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
1994                             'ky', 'log', 'pg', 'toc', 'tp', 'tps',
1995                             'vr', 'vrs', 'op', 'tr', 'cv')
1996         {
1997             push (@texi_cleans, $infobase . '.' . $tc_cursor);
1998         }
1999     }
2001     # Find these programs wherever they may lie.  Yes, this has
2002     # intimate knowledge of the structure of the texinfo distribution.
2003     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
2004                               'makeinfo',
2005                               # Circumlocution to avoid accidental
2006                               # configure substitution.
2007                               '@MAKE' . 'INFO@');
2008     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
2009                               'texi2dvi');
2011     # Set transform for including texinfos.am.  First, handle --cygnus
2012     # stuff.
2013     local ($xform);
2014     if ($cygnus_mode)
2015     {
2016         $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
2017     }
2018     else
2019     {
2020         $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
2021     }
2023     # Handle location of texinfo.tex.
2024     if ($cygnus_mode)
2025     {
2026         &define_variable ('TEXINFO_TEX',
2027                           '$(top_srcdir)/../texinfo/texinfo.tex');
2028     }
2029     elsif (! &variable_defined ('TEXINFO_TEX'))
2030     {
2031         &define_variable ('TEXINFO_TEX', '$(srcdir)/texinfo.tex');
2032     }
2033     local ($xxform) = &dirname (&variable_value ('TEXINFO_TEX'));
2034     $xxform =~ s/(\W)/\\$1/g;
2035     $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';
2037     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
2038     push (@phony, 'install-info-am', 'uninstall-info');
2039     push (@dist_targets, 'dist-info');
2041     # How to clean.  The funny name is due to --cygnus influence; in
2042     # Cygnus mode, `clean-info' is a target that users can use.
2043     $output_rules .= "\nmostlyclean-aminfo:\n";
2044     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
2045     $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
2046                       . "maintainer-clean-aminfo:\n\t"
2047                       . 'for i in $(INFO_DEPS); do rm -f `eval echo $$i*`; done'
2048                       . "\n");
2049     &push_phony_cleaners ('aminfo');
2050     if ($cygnus_mode)
2051     {
2052         $output_rules .= "clean-info: mostlyclean-aminfo\n";
2053     }
2055     push (@suffixes, '.texi', '.texinfo', '.info', '.dvi', '.ps');
2057     if (! defined $options{'no-installinfo'})
2058     {
2059         push (@uninstall, 'uninstall-info');
2060         push (@installdirs, '$(infodir)');
2061         unshift (@install_data, 'install-info-am');
2063         # Make sure documentation is made and installed first.  Use
2064         # $(INFO_DEPS), not 'info', because otherwise recursive makes
2065         # get run twice during "make all".
2066         unshift (@all, '$(INFO_DEPS)');
2067     }
2068     push (@clean, 'aminfo');
2069     push (@info, '$(INFO_DEPS)');
2070     push (@dvi, '$(DVIS)');
2072     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2073     &define_variable ("DVIS", join (' ', @dvis_list));
2074     # This next isn't strictly needed now -- the places that look here
2075     # could easily be changed to look in info_TEXINFOS.  But this is
2076     # probably better, in case noinst_TEXINFOS is ever supported.
2077     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
2079     # Do some error checking.  Note that this file is not required
2080     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2081     # up above.
2082     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
2083         unless (defined $options{'no-texinfo.tex'}
2084                 || &variable_defined ('TEXINFO_TEX'));
2087 # Handle any man pages.
2088 sub handle_man_pages
2090     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
2091         if &variable_defined ('MANS');
2092     return if ! &variable_defined ('man_MANS');
2094     # We generate the manpage install code by hand to avoid the use of
2095     # basename in the generated Makefile.
2096     local (@mans) = &variable_value_as_list ('man_MANS', 'all');
2097     local (%sections, %inames, %mbases, %secmap, %fullsecmap);
2098     local ($i) = 1;
2099     foreach (@mans)
2100     {
2101         # FIXME: statement without effect:
2102         /^(.*)\.([0-9])([a-z]*)$/;
2103         $sections{$2} = 1;
2104         $inames{$i} = $_;
2105         $mbases{$i} = $1;
2106         $secmap{$i} = $2;
2107         $fullsecmap{$i} = $2 . $3;
2108         $i++;
2109     }
2111     # We don't really need this, but we use it in case we ever want to
2112     # support noinst_MANS.
2113     &define_variable ("MANS", &variable_value ('man_MANS'));
2115     # Generate list of install dirs.
2116     $output_rules .= "install-man: \$(MANS)\n";
2117     $output_rules .= "\t\$(NORMAL_INSTALL)\n";
2118     # Sort keys so that output is deterministic.
2119     foreach (sort keys %sections)
2120     {
2121         push (@installdirs, '$(mandir)/man' . $_)
2122             unless defined $options{'no-installman'};
2123         $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
2124                           . $_ . "\n");
2125     }
2126     push (@phony, 'install-man');
2128     # Generate install target.
2129     local ($key);
2130     foreach $key (sort keys %inames)
2131     {
2132         $_ = $install_man_format;
2133         s/\@SECTION\@/$secmap{$key}/g;
2134         s/\@MAN\@/$inames{$key}/g;
2135         s/\@FULLSECT\@/$fullsecmap{$key}/g;
2136         s/\@MANBASE\@/$mbases{$key}/g;
2137         $output_rules .= $_;
2138     }
2139     $output_rules .= "\n";
2141     $output_rules .= "uninstall-man:\n\t\$(NORMAL_UNINSTALL)\n";
2142     foreach $key (sort keys %inames)
2143     {
2144         $_ = $uninstall_man_format;
2145         s/\@SECTION\@/$secmap{$key}/g;
2146         s/\@MAN\@/$inames{$key}/g;
2147         s/\@FULLSECT\@/$fullsecmap{$key}/g;
2148         s/\@MANBASE\@/$mbases{$key}/g;
2149         $output_rules .= $_;
2150     }
2151     $output_rules .= "\n";
2152     push (@phony, 'uninstall-man');
2154     $output_vars .= &file_contents ('mans-vars');
2156     if (! defined $options{'no-installman'})
2157     {
2158         push (@install_data, 'install-man');
2159         push (@uninstall, 'uninstall-man');
2160         push (@all, '$(MANS)');
2161     }
2164 # Handle DATA variables.
2165 sub handle_data
2167     &am_install_var ('data', 'DATA', 'data', 'sysconf',
2168                      'sharedstate', 'localstate', 'pkgdata',
2169                      'noinst', 'check');
2172 # Handle TAGS.
2173 sub handle_tags
2175     push (@phony, 'tags');
2176     local (@tag_deps) = ();
2177     if (&variable_defined ('SUBDIRS'))
2178     {
2179         $output_rules .= ("tags-recursive:\n"
2180                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
2181                           # Never fail here if a subdir fails; it
2182                           # isn't important.
2183                           . "\t  (cd \$\$subdir && \$(MAKE) tags); \\\n"
2184                           . "\tdone\n");
2185         push (@tag_deps, 'tags-recursive');
2186         push (@phony, 'tags-recursive');
2187     }
2189     if ($dir_holds_sources
2190         || $dir_holds_headers
2191         || &variable_defined ('ETAGS_ARGS')
2192         || @tag_deps)
2193     {
2194         local ($xform) = '';
2195         local ($one_hdr);
2196         foreach $one_hdr (@config_headers)
2197         {
2198             if ($relative_dir eq &dirname ($one_hdr))
2199             {
2200                 # The config header is in this directory.  So require it.
2201                 local ($var);
2202                 ($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
2203                 $xform .= ' ' if $xform;
2204                 $xform .= $var;
2205             }
2206         }
2207         $xform = ('s/\@CONFIG\@/' . $xform . '/;'
2208                   . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
2210         if (&variable_defined ('SUBDIRS'))
2211         {
2212             $xform .= 's/^SUBDIRS//;';
2213         }
2214         else
2215         {
2216             $xform .= 's/^SUBDIRS.*$//;';
2217         }
2219         $output_rules .= &file_contents_with_transform ($xform, 'tags');
2220         $output_rules .= &file_contents ('tags-clean');
2221         push (@clean, 'tags');
2222         &push_phony_cleaners ('tags');
2223         &examine_variable ('TAGS_DEPENDENCIES');
2224     }
2225     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
2226     {
2227         &am_line_error ('TAGS_DEPENDENCIES',
2228                         "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
2229     }
2230     else
2231     {
2232         # Every Makefile must define some sort of TAGS rule.
2233         # Otherwise, it would be possible for a top-level "make TAGS"
2234         # to fail because some subdirectory failed.
2235         $output_rules .= "tags: TAGS\nTAGS:\n\n";
2236     }
2239 # Worker for handle_dist.
2240 sub handle_dist_worker
2242     local ($makefile) = @_;
2244     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
2246     # Initialization; only at top level.
2247     if ($relative_dir eq '.')
2248     {
2249         if ($strictness >= $GNITS)
2250         {
2251             # For Gnits users, this is pretty handy.  Look at 15 lines
2252             # in case some explanatory text is desirable.
2253             $output_rules .= '  @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
2254           echo "NEWS not updated; not releasing" 1>&2; \\
2255           exit 1; \\
2256         fi
2258         }
2261         # Create dist directory.
2262         $output_rules .= ("\trm -rf \$(distdir)\n"
2263                           . "\tmkdir \$(distdir)\n"
2264                           . "\t-chmod 777 \$(distdir)\n");
2265     }
2267     # Only run automake in `dist' target if --include-deps and
2268     # `no-dependencies' not specified.  That way the recipient of a
2269     # distribution can run "make dist" and not need Automake.  You
2270     # might be wondering why we run automake once for each directory
2271     # we distribute, instead of running it once at the top level.  The
2272     # answer is that we want to run automake after the dependencies
2273     # have been generated.  This occurs when "make" is run in the
2274     # subdir.  So automake must be run after make has updated the
2275     # Makefile, which means that it must run once per directory.
2276     if ($use_dependencies)
2277     {
2278         $output_rules .=
2279             (
2280              # We need an absolute path for --output-dir.  Thus the
2281              # weirdness.
2282              "\t" . 'here=`cd $(top_builddir) && pwd`; ' . "\\\n"
2283              . "\t" . 'top_distdir=`cd $(top_distdir) && pwd`; ' . "\\\n"
2284              . "\tcd \$(top_srcdir) \\\n"
2285              . "\t  && \$(AUTOMAKE) --include-deps --build-dir=\$\$here --srcdir-name=\$(top_srcdir) --output-dir=\$\$top_distdir "
2286              # Set strictness of output.
2287              . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2288              . " " . $makefile . "\n"
2289              );
2290     }
2292     # Scan EXTRA_DIST to see if we need to distribute anything from a
2293     # subdir.  If so, add it to the list.  I didn't want to do this
2294     # originally, but there were so many requests that I finally
2295     # relented.
2296     local (@dist_dirs);
2297     if (&variable_defined ('EXTRA_DIST'))
2298     {
2299         # FIXME: This should be fixed to work with conditionals.  That
2300         # will require only making the entries in @dist_dirs under the
2301         # appropriate condition.  This is meaningful if the nature of
2302         # the distribution should depend upon the configure options
2303         # used.
2304         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
2305         {
2306             next if /^\@.*\@$/;
2307             next unless s,/+[^/]+$,,;
2308             push (@dist_dirs, $_)
2309                 unless $_ eq '.';
2310         }
2311     }
2312     if (@dist_dirs)
2313     {
2314         # Prepend $(distdir) to each directory given.  Doing it via a
2315         # hash lets us ensure that each directory is used only once.
2316         local (%dhash);
2317         grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
2318         $output_rules .= "\t";
2319         &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
2320     }
2322     # In loop, test for file existence because sometimes a file gets
2323     # included in DISTFILES twice.  For example this happens when a
2324     # single source file is used in building more than one program.
2325     # Also, there are situations in which "ln" can fail.  For instance
2326     # a file to distribute could actually be a cross-filesystem
2327     # symlink -- this can easily happen if "gettextize" was run on the
2328     # distribution.
2329     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
2330     if ($cygnus_mode)
2331     {
2332         $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
2333     }
2334     else
2335     {
2336         $output_rules .= "\t  d=\$(srcdir); \\\n";
2337     }
2338     $output_rules .= '    test -f $(distdir)/$$file \\
2339           || ln $$d/$$file $(distdir)/$$file 2> /dev/null \\
2340           || cp -p $$d/$$file $(distdir)/$$file; \\
2341         done
2344     # If we have SUBDIRS, create all dist subdirectories and do
2345     # recursive build.
2346     if (&variable_defined ('SUBDIRS'))
2347     {
2348         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
2349         # to all possible directories, and use it.
2350         if (! &variable_conditions ('SUBDIRS'))
2351         {
2352             $dist_subdir_name = 'SUBDIRS';
2353         }
2354         else
2355         {
2356             $dist_subdir_name = 'DIST_SUBDIRS';
2357             if (! &variable_defined ('DIST_SUBDIRS'))
2358             {
2359                 &define_pretty_variable ('DIST_SUBDIRS', '',
2360                                          &variable_value_as_list ('SUBDIRS',
2361                                                                   'all'));
2362             }
2363         }
2365         # Test for directory existence here because previous automake
2366         # invocation might have created some directories.  Note that
2367         # we explicitly set distdir for the subdir make; that lets us
2368         # mix-n-match many automake-using packages into one large
2369         # package, and have "dist" at the top level do the right
2370         # thing.
2371         $output_rules .= '      for subdir in $(' . $dist_subdir_name . '); do          \\
2372           test -d $(distdir)/$$subdir           \\
2373           || mkdir $(distdir)/$$subdir          \\
2374           || exit 1;                            \\
2375           chmod 777 $(distdir)/$$subdir;        \\
2376           (cd $$subdir && $(MAKE) top_distdir=../$(top_distdir) distdir=../$(distdir)/$$subdir distdir) \\
2377             || exit 1; \\
2378         done
2380     }
2382     # If the target `dist-hook' exists, make sure it is run.  This
2383     # allows users to do random weird things to the distribution
2384     # before it is packaged up.
2385     push (@dist_targets, 'dist-hook') if defined $contents{'dist-hook'};
2387     local ($targ);
2388     foreach $targ (@dist_targets)
2389     {
2390         # We must explicitly set distdir and top_distdir for these
2391         # sub-makes.
2392         $output_rules .= "\t\$(MAKE) top_distdir=\"\$(top_distdir)\" distdir=\"\$(distdir)\" $targ\n";
2393     }
2395     push (@phony, 'distdir');
2398 # Handle 'dist' target.
2399 sub handle_dist
2401     local ($makefile) = @_;
2403     # Set up maint_charset.
2404     $local_maint_charset = &variable_value ('MAINT_CHARSET')
2405         if &variable_defined ('MAINT_CHARSET');
2406     $maint_charset = $local_maint_charset
2407         if $relative_dir eq '.';
2409     if (&variable_defined ('DIST_CHARSET'))
2410     {
2411         &am_line_error ('DIST_CHARSET',
2412                         "DIST_CHARSET defined but no MAINT_CHARSET defined")
2413             if ! $local_maint_charset;
2414         if ($relative_dir eq '.')
2415         {
2416             $dist_charset = &variable_value ('DIST_CHARSET')
2417         }
2418         else
2419         {
2420             &am_line_error ('DIST_CHARSET',
2421                             "DIST_CHARSET can only be defined at top level");
2422         }
2423     }
2425     # Look for common files that should be included in distribution.
2426     local ($cfile);
2427     foreach $cfile (@common_files)
2428     {
2429         if (-f ($relative_dir . "/" . $cfile))
2430         {
2431             &push_dist_common ($cfile);
2432         }
2433     }
2435     # Keys of %dist_common are names of files to distributed.  We put
2436     # README first because it then becomes easier to make a
2437     # Usenet-compliant shar file (in these, README must be first).
2438     # FIXME: do more ordering of files here.
2439     local (@coms);
2440     if (defined $dist_common{'README'})
2441     {
2442         push (@coms, 'README');
2443         delete $dist_common{'README'};
2444     }
2445     push (@coms, sort keys %dist_common);
2447     &define_pretty_variable ("DIST_COMMON", '', @coms);
2448     $output_vars .= "\n";
2450     # Some boilerplate.
2451     $output_vars .= &file_contents ('dist-vars') . "\n";
2452     &define_variable ('TAR', $TAR);
2453     &define_variable ('GZIP', '--best');
2455     # Put these things in rules section so it is easier for whoever
2456     # reads Makefile.in.
2457     if (! &variable_defined ('distdir'))
2458     {
2459         if ($relative_dir eq '.')
2460         {
2461             $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
2462         }
2463         else
2464         {
2465             $output_rules .= ("\n"
2466                               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
2467                               . "\n");
2468         }
2469     }
2470     if ($relative_dir eq '.')
2471     {
2472         $output_rules .= "top_distdir = \$(distdir)\n\n";
2473     }
2474     else
2475     {
2476         $output_rules .= "\nsubdir = " . $relative_dir . "\n\n";
2477     }
2479     # Generate 'dist' target, and maybe dist-shar / dist-zip / dist-tarZ.
2480     if ($relative_dir eq '.')
2481     {
2482         # Rule to check whether a distribution is viable.
2483         $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
2484 # it guarantees that the distribution is self-contained by making another
2485 # tarfile.
2486 distcheck: dist
2487         rm -rf $(distdir)
2488         GZIP=$(GZIP) $(TAR) zxf $(distdir).tar.gz
2489         mkdir $(distdir)/=build
2490         mkdir $(distdir)/=inst
2491         dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
2492                           . (defined $contents{'distcheck-hook'}
2493                              ? "\t\$(MAKE) distcheck-hook"
2494                              : '')
2495                           . '
2496         cd $(distdir)/=build \\
2497           && ../configure '
2499                           . ($seen_gettext ? '--with-included-gettext ' : '')
2500                           . '--srcdir=.. --prefix=$$dc_install_base \\
2501           && $(MAKE) \\
2502           && $(MAKE) dvi \\
2503           && $(MAKE) check \\
2504           && $(MAKE) install \\
2505           && $(MAKE) installcheck \\
2506           && $(MAKE) dist
2507         rm -rf $(distdir)
2508         @echo "========================"; \\
2509         echo "$(distdir).tar.gz is ready for distribution"; \\
2510         echo "========================"
2513         local ($dist_all) = ('dist-all: distdir' . "\n"
2514                              . $dist_header);
2515         local ($curs);
2516         foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ')
2517         {
2518             if (defined $options{$curs} || $curs eq 'dist')
2519             {
2520                 $output_rules .= ($curs . ': distdir' . "\n"
2521                                   . $dist_header
2522                                   . $dist{$curs}
2523                                   . $dist_trailer);
2524                 $dist_all .= $dist{$curs};
2525             }
2526         }
2527         $output_rules .= $dist_all . $dist_trailer;
2528     }
2530     # Generate distdir target.
2531     &handle_dist_worker ($makefile);
2534 # Scan a single dependency file and rewrite the dependencies as
2535 # appropriate.  Essentially this means:
2536 # * Clean out absolute dependencies which are not desirable.
2537 # * Rewrite other dependencies to be relative to $(top_srcdir).
2538 sub scan_dependency_file
2540     local ($depfile) = @_;
2542     if (! open (DEP_FILE, $depfile))
2543     {
2544         &am_error ("couldn't open \`$depfile': $!");
2545         return;
2546     }
2547     print "automake: reading $depfile\n" if $verbose;
2549     # Sometimes it is necessary to omit some dependencies.
2550     local (%omit) = %omit_dependencies;
2551     if (&variable_defined ('OMIT_DEPENDENCIES'))
2552     {
2553         # FIXME: Doesn't work with conditionals.  I'm not sure if this
2554         # matters.
2555         grep ($omit{$_} = 1,
2556               &variable_value_as_list ('OMIT_DEPENDENCIES', ''));
2557     }
2559     local ($first_line) = 1;
2560     local ($last_line) = 0;
2561     local ($target, @dependencies);
2562     local ($one_dep, $xform);
2563     local ($just_file);
2565     local ($srcdir_rx, $fixup_rx);
2566     ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
2567         =~ s/(\W)/\\$1/g;
2568     ($srcdir_rx = $srcdir_name . '/') =~ s/(\W)/\\$1/g;
2570     local ($rewrite_builddir) = (($top_builddir eq '.')
2571                                  ? ''
2572                                  : $top_builddir . '/');
2574     while (<DEP_FILE>)
2575     {
2576         if ($last_line)
2577         {
2578             # If LAST_LINE set then we've already seen what we thought
2579             # was the last line.
2580             goto bad_format;
2581         }
2582         next if (/$WHITE_PATTERN/o);
2583         chop;
2584         if (! s/\\$//)
2585         {
2586             # No trailing "\" means this should be the last line.
2587             $last_line = 1;
2588         }
2590         if ($first_line)
2591         {
2592             if (! /^([^:]+:)(.+)$/)
2593             {
2594               bad_format:
2595                 &am_error ("\`$depfile' has incorrect format");
2596                 close (DEP_FILE);
2597                 return;
2598             }
2600             $_ = $2;
2601             # Make sure to strip the .P file from the target.
2602             ($target = $1) =~ s, *\.deps/[^.]+\.P,,;
2604             $first_line = 0;
2605         }
2607         foreach $one_dep (split (' ', $_))
2608         {
2609             if ($one_dep =~ /^$fixup_rx/)
2610             {
2611                 # The dependency points to the current directory in
2612                 # some way.
2613                 ($xform = $one_dep) =~ s/^$fixup_rx//;
2614                 push (@dependencies, $xform);
2615             }
2616             elsif ($one_dep =~ /^$srcdir_rx/)
2617             {
2618                 # The dependency is in some other directory in the package.
2619                 ($xform = $one_dep) =~ s/^$srcdir_rx/$rewrite_builddir/;
2620                 push (@dependencies, $xform);
2621             }
2622             elsif ($one_dep =~ /^\//)
2623             {
2624                 # Absolute path; ignore.
2625             }
2626             else
2627             {
2628                 # Anything else is assumed to be correct.  But first
2629                 # make sure it is not on our list of dependencies to
2630                 # omit.
2631                 ($just_file = $one_dep) =~ s,^.*/,,;
2632                 push (@dependencies, $one_dep)
2633                     if ! defined $omit{$just_file};
2634             }
2635         }
2636     }
2638     &pretty_print_rule ($target, "\t", @dependencies);
2640     close (DEP_FILE);
2643 # Handle auto-dependency code.
2644 sub handle_dependencies
2646     if ($use_dependencies)
2647     {
2648         # Include GNU-make-specific auto-dep code.
2649         if ($dir_holds_sources)
2650         {
2651             &define_pretty_variable ('DEP_FILES', '', sort keys %dep_files);
2652             $output_rules .= &file_contents ('depend');
2653             push (@clean, 'depend');
2654             &push_phony_cleaners ('depend');
2655             $output_rules .=
2656                 &file_contents_with_transform ('s/\@EXT\@/.c/g;'
2657                                                . 's/\@MKDEP\@/MKDEP/g;'
2658                                                . 's/^ONLYC//g;',
2659                                                'depend2');
2660             local ($ext);
2661             local ($need_cxx) = 0;
2662             foreach $ext (sort keys %cxx_extensions)
2663             {
2664                 $output_rules .=
2665                     &file_contents_with_transform ('s/\@EXT\@/' . $ext .'/g;'
2666                                                    . 's/\@MKDEP\@/CXXMKDEP/g;'
2667                                                    . 's/^ONLYC.*$//;',
2668                                                    'depend2');
2669                 $need_cxx = 1;
2670             }
2671             if ($need_cxx)
2672             {
2673                 &define_variable ('CXXMKDEP', '$(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
2674             }
2675         }
2676     }
2677     elsif ($build_directory ne '')
2678     {
2679         # Include any auto-generated deps that are present.  Note that
2680         # $build_directory ends in a "/".
2681         if (-d ($build_directory . $relative_dir . "/.deps")
2682             && -f ($build_directory . $relative_dir . "/.deps/.P"))
2683         {
2684             local ($depfile);
2686             foreach $depfile (&my_glob ($build_directory
2687                                         . $relative_dir . "/.deps/*.P"))
2688             {
2689                 &scan_dependency_file ($depfile);
2690             }
2692             $output_rules .= "\n";
2693         }
2694     }
2697 # Handle subdirectories.
2698 sub handle_subdirs
2700     return if ! &variable_defined ('SUBDIRS');
2702     # Make sure each directory mentioned in SUBDIRS actually exists.
2703     local ($dir);
2704     foreach $dir (&variable_value_as_list ('SUBDIRS', 'all'))
2705     {
2706         # Skip directories substituted by configure.
2707         next if $dir =~ /^\@.*\@$/;
2709         if (! -d $am_relative_dir . '/' . $dir)
2710         {
2711             &am_line_error ('SUBDIRS',
2712                             "required directory $am_relative_dir/$dir does not exist");
2713             next;
2714         }
2716         &am_line_error ('SUBDIRS', "directory should not contain \`/'")
2717             if $dir =~ /\//;
2718     }
2720     local ($xform) = ('s/\@INSTALLINFO\@/' .
2721                       (defined $options{'no-installinfo'}
2722                        ? 'install-info-recursive'
2723                        : '')
2724                       . '/;');
2725     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
2727     # Push a bunch of phony targets.
2728     local ($phonies);
2729     foreach $phonies ('-data', '-exec', 'dirs')
2730     {
2731         push (@phony, 'install' . $phonies . '-recursive');
2732         push (@phony, 'uninstall' . $phonies . '-recursive');
2733     }
2734     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
2735     {
2736         push (@phony, $phonies . '-recursive');
2737     }
2738     &push_phony_cleaners ('recursive');
2740     push (@check_tests, "check-recursive");
2741     push (@installcheck, "installcheck-recursive");
2742     push (@info, "info-recursive");
2743     push (@dvi, "dvi-recursive");
2745     $recursive_install = 1;
2748 # Handle aclocal.m4.
2749 sub handle_aclocal_m4
2751     local ($regen_aclocal) = 0;
2752     if (-f 'aclocal.m4')
2753     {
2754         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
2755         &push_dist_common ('aclocal.m4');
2757         if (open (ACLOCAL, '< aclocal.m4'))
2758         {
2759             local ($line);
2760             $line = <ACLOCAL>;
2761             close (ACLOCAL);
2763             if ($line =~ 'generated automatically by aclocal')
2764             {
2765                 $regen_aclocal = 1;
2766             }
2767         }
2768     }
2770     local ($acinclude) = 0;
2771     if (-f 'acinclude.m4')
2772     {
2773         $regen_aclocal = 1;
2774         $acinclude = 1;
2775     }
2777     # Note that it might be possible that aclocal.m4 doesn't exist but
2778     # should be auto-generated.  This case probably isn't very
2779     # important.
2780     if ($regen_aclocal)
2781     {
2782         local (@ac_deps) = (
2783                             ($seen_maint_mode ? "\@MAINT\@" : "") ,
2784                             "configure.in",
2785                             ($acinclude ? ' acinclude.m4' : '')
2786                             );
2788         # Scan all -I directories for m4 files.  These are our
2789         # dependencies.
2790         if (&variable_defined ('ACLOCAL_AMFLAGS'))
2791         {
2792             local ($amdir);
2793             foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
2794             {
2795                 if ($amdir =~ s/^-I//
2796                     && $amdir !~ /^\//
2797                     && -d $amdir)
2798                 {
2799                     push (@ac_deps, &my_glob ($am_dir . '/*.m4'));
2800                 }
2801             }
2802         }
2804         &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
2806         $output_rules .=  ("\t"
2807                            . 'cd $(srcdir) && $(ACLOCAL)'
2808                            . (&variable_defined ('ACLOCAL_AMFLAGS')
2809                               ? ' $(ACLOCAL_AMFLAGS)' : '')
2810                            . "\n");
2811     }
2814 # Rewrite a list of input files into a form suitable to put on a
2815 # dependency list.  The idea is that if an input file has a directory
2816 # part the same as the current directory, then the directory part is
2817 # simply removed.  But if the directory part is different, then
2818 # $(top_srcdir) is prepended.  Among other things, this is used to
2819 # generate the dependency list for the output files generated by
2820 # AC_OUTPUT.  Consider what the dependencies should look like in this
2821 # case:
2822 #   AC_OUTPUT(src/out:src/in1:lib/in2)
2823 sub rewrite_inputs_into_dependencies
2825     local (@inputs) = @_;
2826     local ($single, @newinputs);
2828     foreach $single (@inputs)
2829     {
2830         if (&dirname ($single) eq $relative_dir)
2831         {
2832             push (@newinputs, &basename ($single));
2833         }
2834         else
2835         {
2836             push (@newinputs, '$(top_srcdir)/' . $single);
2837         }
2838     }
2840     return @newinputs;
2843 # Handle remaking and configure stuff.
2844 # We need the name of the input file, to do proper remaking rules.
2845 sub handle_configure
2847     local ($local, $input, @secondary_inputs) = @_;
2849     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
2850     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
2851         if &variable_defined ('SUBDIRS') && ! $seen_make_set;
2853     local ($top_reldir);
2855     local ($input_base) = &basename ($input);
2856     local ($local_base) = &basename ($local);
2858     local ($amfile) = $input_base . '.am';
2859     # We know we can always add '.in' because it really should be an
2860     # error if the .in was missing originally.
2861     local ($infile) = '$(srcdir)/' . $input_base . '.in';
2862     local ($colon_infile);
2863     if ($local ne $input)
2864     {
2865         $colon_infile = ':' . $input . '.in';
2866     }
2867     $colon_infile .= ':' . join (':', @secondary_inputs)
2868         if @secondary_inputs;
2870     local (@rewritten) = &rewrite_inputs_into_dependencies (@secondary_inputs);
2871     # This rule remakes the Makefile.in.  Note use of @MAINT@ forces
2872     # us to abandon pretty-printing.  Sigh.
2873     $output_rules .= ($infile
2874                       # NOTE perl 5.003 (with -w) gives a
2875                       # uninitialized value error on the next line.
2876                       # Don't know why.
2877                       . ': '
2878                       . ($seen_maint_mode ? '@MAINT@ ' : '')
2879                       . $amfile . ' '
2880                       . '$(top_srcdir)/configure.in $(ACLOCAL_M4) '
2881                       . join (' ', @rewritten) . "\n"
2882                       . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
2883                       . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
2884                       . ' ' . $input . $colon_infile . "\n\n");
2886     # This rule remakes the Makefile.
2887     $output_rules .= ($local_base
2888                       # NOTE: bogus uninit value error on next line;
2889                       # see comment above.
2890                       . ': '
2891                       . $infile . ' '
2892                       . '$(top_builddir)/config.status'
2893                       # NOTE: Makefile only depends on BUILT_SOURCES
2894                       # when dependencies are being computed.  This is
2895                       # a workaround for an obscure bug with
2896                       # AC_LINK_FILES.  Anyway, when dependencies are
2897                       # turned off, this shouldn't matter.
2898                       . ($use_dependencies ? ' $(BUILT_SOURCES)' : '')
2899                       . "\n"
2900                       . "\tcd \$(top_builddir) \\\n"
2901                       . "\t  && CONFIG_FILES="
2902                       . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
2903                       . $colon_infile
2904                       . ' CONFIG_HEADERS= $(SHELL) ./config.status'
2905                       . "\n\n");
2907     if ($relative_dir ne '.')
2908     {
2909         # In subdirectory.
2910         $top_reldir = '../';
2911     }
2912     else
2913     {
2914         &handle_aclocal_m4;
2915         $output_rules .= &file_contents ('remake');
2916         &examine_variable ('CONFIGURE_DEPENDENCIES');
2917         $top_reldir = '';
2918     }
2920     # If we have a configure header, require it.
2921     local ($one_hdr);
2922     local (@local_fullnames) = @config_fullnames;
2923     local (@local_names) = @config_names;
2924     local ($hdr_index) = 0;
2925     local ($distclean_config) = '';
2926     foreach $one_hdr (@config_headers)
2927     {
2928         local ($one_fullname) = shift (@local_fullnames);
2929         local ($one_name) = shift (@local_names);
2930         $hdr_index += 1;
2931         if ($relative_dir eq &dirname ($one_hdr))
2932         {
2933             local ($ch_sans_dir) = &basename ($one_hdr);
2934             local ($cn_sans_dir) = &basename ($one_name);
2936             &require_file_with_conf_line ($config_header_line,
2937                                           $FOREIGN, $ch_sans_dir);
2939             # Header defined and in this directory.
2940             local (@files);
2941             if (-f $relative_dir . '/acconfig.h')
2942             {
2943                 push (@files, 'acconfig.h');
2944             }
2945             if (-f $one_name . '.top')
2946             {
2947                 push (@files, "${cn_sans_dir}.top");
2948             }
2949             if (-f $one_name . '.bot')
2950             {
2951                 push (@files, "${cn_sans_dir}.bot");
2952             }
2954             &push_dist_common (@files);
2956             local ($stamp_name) = 'stamp-h';
2957             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
2959             local ($xform) = '';
2961             $xform = 's,\@FILES\@,' . join (' ', @files) . ',;';
2962             $xform .= 's,\@CONFIG_HEADER\@,' . "${cn_sans_dir}" . ',;';
2963             $xform .= 's,\@CONFIG_HEADER_IN\@,' . "${ch_sans_dir}" . ',;';
2964             $xform .= 's,\@CONFIG_HEADER_FULL\@,' . "${one_fullname}" . ',;';
2965             $xform .= 's,\@STAMP\@,' . "${stamp_name}" . ',;';
2967             $output_rules .= &file_contents_with_transform ($xform,
2968                                                             'remake-hdr');
2970             &touch ($relative_dir . "/${stamp_name}.in");
2971             &require_file_with_conf_line ($config_header_line, $FOREIGN,
2972                                           "${stamp_name}.in");
2974             $distclean_config .= ' ' if $distclean_config;
2975             $distclean_config .= $cn_sans_dir;
2976         }
2977     }
2979     if ($distclean_config)
2980     {
2981         $output_rules .= &file_contents_with_transform ('s,\@FILES\@,'
2982                                                         . $distclean_config
2983                                                         . ',;',
2984                                                         'clean-hdr');
2985         push (@clean, 'hdr');
2986         &push_phony_cleaners ('hdr');
2987     }
2989     # Set location of mkinstalldirs.
2990     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
2991     {
2992         &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
2993                                             . '/mkinstalldirs'));
2994     }
2995     else
2996     {
2997         &define_variable ('mkinstalldirs',
2998                           '$(SHELL) $(top_srcdir)/mkinstalldirs');
2999     }
3001     &am_line_error ('CONFIG_HEADER',
3002                     "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
3003         if &variable_defined ('CONFIG_HEADER');
3005     local ($one_name);
3006     local ($config_header) = '';
3007     foreach $one_name (@config_names)
3008     {
3009         # Generate CONFIG_HEADER define.
3010         local ($one_hdr);
3011         if ($relative_dir eq &dirname ($one_name))
3012         {
3013             $one_hdr = &basename ($one_name);
3014         }
3015         else
3016         {
3017             $one_hdr = "${top_builddir}/${one_name}";
3018         }
3020         $config_header .= ' ' if $config_header;
3021         $config_header .= $one_hdr;
3022     }
3023     if ($config_header)
3024     {
3025         &define_variable ("CONFIG_HEADER", $config_header);
3026     }
3028     # Now look for other files in this directory which must be remade
3029     # by config.status, and generate rules for them.
3030     local (@actual_other_files) = ();
3031     local ($file, $local);
3032     local (@inputs, @rewritten_inputs, $single);
3033     foreach $file (@other_input_files)
3034     {
3035         if ($file =~ /^(.*):(.*)$/)
3036         {
3037             # This is the ":" syntax of AC_OUTPUT.
3038             $file = $1;
3039             $local = &basename ($file);
3040             @inputs = split (':', $2);
3041             @rewritten_inputs = &rewrite_inputs_into_dependencies (@inputs);
3042         }
3043         else
3044         {
3045             # Normal usage.
3046             $local = &basename ($file);
3047             @inputs = ($local . '.in');
3048             @rewritten_inputs =
3049                 &rewrite_inputs_into_dependencies ($file . '.in');
3050         }
3052         # Skip files not in this directory.
3053         next unless &dirname ($file) eq $relative_dir;
3055         # Skip any file that is an automake input.
3056         next if -f $file . '.am';
3058         # Some users have been tempted to put `stamp-h' in the
3059         # AC_OUTPUT line.  This won't do the right thing, so we
3060         # explicitly fail here.
3061         if ($local eq 'stamp-h')
3062         {
3063             # FIXME: allow real filename.
3064             &am_conf_error ('configure.in', $ac_output_line,
3065                             'stamp-h should not appear in AC_OUTPUT');
3066             next;
3067         }
3069         $output_rules .= ($local . ': '
3070                           . '$(top_builddir)/config.status '
3071                           . join (' ', @rewritten_inputs) . "\n"
3072                           . "\t"
3073                           . 'cd $(top_builddir) && CONFIG_FILES='
3074                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3075                           . '$@' . (length (@rewritten_inputs) > 1
3076                                     ? (':' . join (':', @rewritten_inputs))
3077                                     : '')
3078                           . ' CONFIG_HEADERS= ./config.status'
3079                           . "\n");
3080         push (@actual_other_files, $local);
3082         # Require all input files.
3083         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3084                                       @inputs);
3085     }
3087     # These files get removed by "make clean".
3088     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3091 # Handle C headers.
3092 sub handle_headers
3094     $dir_holds_headers = &am_install_var ('header', 'HEADERS', 'include',
3095                                           'oldinclude', 'pkginclude',
3096                                           'noinst', 'check');
3099 sub handle_gettext
3101     return if ! $seen_gettext || $relative_dir ne '.';
3103     if (! &variable_defined ('SUBDIRS'))
3104     {
3105         &am_conf_error
3106             ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
3107         return;
3108     }
3110     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
3111         if $seen_gettext;
3113     if (&variable_defined ('SUBDIRS'))
3114     {
3115         &am_line_error
3116             ('SUBDIRS',
3117              "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
3118                 if $contents{'SUBDIRS'} !~ /\bpo\b/;
3119         &am_line_error
3120             ('SUBDIRS',
3121              "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
3122                 if $contents{'SUBDIRS'} !~ /\bintl\b/;
3123     }
3125     # Ensure that each language in ALL_LINGUAS has a .po file, and
3126     # each po file is mentioned in ALL_LINGUAS.
3127     if ($seen_linguas)
3128     {
3129         local (%linguas) = ();
3130         grep ($linguas{$_} = 1, split (' ', $all_linguas));
3132         foreach (<po/*.po>)
3133         {
3134             s/^po\///;
3135             s/\.po$//;
3137             &am_line_error ($all_linguas_line,
3138                             ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
3139                 if ! $linguas{$_};
3140         }
3142         foreach (keys %linguas)
3143         {
3144             &am_line_error ($all_linguas_line,
3145                             "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
3146                 if ! -f "po/$_.po";
3147         }
3148     }
3149     else
3150     {
3151         &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
3152     }
3155 # Handle footer elements.
3156 sub handle_footer
3158     if ($contents{'SOURCES'})
3159     {
3160         # NOTE don't use define_pretty_variable here, because
3161         # $contents{...} is already defined.
3162         $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
3163     }
3164     if ($contents{'OBJECTS'})
3165     {
3166         # NOTE don't use define_pretty_variable here, because
3167         # $contents{...} is already defined.
3168         $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
3169     }
3170     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
3171     {
3172         $output_vars .= "\n";
3173     }
3175     if (&variable_defined ('SUFFIXES'))
3176     {
3177         # Push actual suffixes, and not $(SUFFIXES).  Some versions of
3178         # make do not like variable substitutions on the .SUFFIXES
3179         # line.
3180         push (@suffixes, &variable_value_as_list ('SUFFIXES', ''));
3181     }
3182     if (&target_defined ('.SUFFIXES'))
3183     {
3184         &am_line_error ('.SUFFIXES',
3185                         "use variable \`SUFFIXES', not target \`.SUFFIXES'");
3186     }
3188     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3189     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3190     # anything else, by sticking it right after the default: target.
3191     $output_header .= ".SUFFIXES:\n";
3192     if (@suffixes)
3193     {
3195         # Make sure suffixes has unique elements.  Sort them to ensure
3196         # the output remains consistent.
3197         local (%suffixes);
3199         grep ($suffixes{$_} = 1, @suffixes);
3201         $output_header .= (".SUFFIXES: "
3202                            . join (' ', sort keys %suffixes)
3203                            . "\n");
3204     }
3205     $output_trailer .= &file_contents ('footer');
3208 # Deal with installdirs target.
3209 sub handle_installdirs
3211     # GNU Makefile standards recommend this.
3212     $output_rules .= ("installdirs:"
3213                       . ($recursive_install
3214                          ? " installdirs-recursive\n"
3215                          : "\n"));
3216     push (@phony, 'installdirs');
3217     if (@installdirs)
3218     {
3219         &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
3220                             @installdirs);
3221     }
3222     $output_rules .= "\n";
3225 # There are several targets which need to be merged.  This is because
3226 # their complete definition is compiled from many parts.  Note that we
3227 # avoid double colon rules, otherwise we'd use them instead.
3228 sub handle_merge_targets
3230     local ($makefile) = @_;
3232     # There are a few install-related variables that you should not define.
3233     local ($var);
3234     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
3235     {
3236         if (&variable_defined ($var))
3237         {
3238             &am_line_error ($var, "\`$var' should not be defined");
3239         }
3240     }
3242     # Put this at the beginning for the sake of non-GNU makes.  This
3243     # is still wrong if these makes can run parallel jobs.  But it is
3244     # right enough.
3245     unshift (@all, &basename ($makefile));
3247     local ($one_name);
3248     foreach $one_name (@config_names)
3249     {
3250         push (@all, &basename ($one_name))
3251             if &dirname ($one_name) eq $relative_dir;
3252     }
3254     &do_one_merge_target ('info', @info);
3255     &do_one_merge_target ('dvi', @dvi);
3256     &do_check_merge_target;
3257     &do_one_merge_target ('installcheck', @installcheck);
3259     if (defined $options{'no-installinfo'})
3260     {
3261         # FIXME: this is kind of a hack; should find another way to
3262         # know that this is required.
3263         local (@dirs);
3264         if (grep ($_ eq 'install-info-am', @phony))
3265         {
3266             push (@dirs, 'install-info-am');
3267         }
3268         if (&variable_defined ('SUBDIRS'))
3269         {
3270             push (@dirs, 'install-info-recursive');
3271         }
3272         &do_one_merge_target ('install-info', @dirs);
3273     }
3275     # Handle the various install targets specially.  We do this so
3276     # that (eg) "make install-exec" will run "install-exec-recursive"
3277     # if required, but "make install" won't run it twice.  Step one is
3278     # to see if the user specified local versions of any of the
3279     # targets we handle.  "all" is treated as one of these since
3280     # "install" can run it.
3281     push (@install_exec, 'install-exec-local')
3282         if defined $contents{'install-exec-local'};
3283     push (@install_data, 'install-data-local')
3284         if defined $contents{'install-data-local'};
3285     push (@uninstall, 'uninstall-local')
3286         if defined $contents{'uninstall-local'};
3287     local ($utarg);
3288     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
3289                     'uninstall-exec-local', 'uninstall-exec-hook')
3290     {
3291         if (defined $contents{$utarg})
3292         {
3293             local ($x);
3294             ($x = $utarg) =~ s/(data|exec)-//;
3295             &am_line_error ($utarg, "use \`$x', not \`$utarg'");
3296         }
3297     }
3298     push (@all, 'all-local')
3299         if defined $contents{'all-local'};
3301     if (defined $contents{'install-local'})
3302     {
3303         &am_line_error ('install-local',
3304                         "use \`install-data' or \`install-exec', not \`install'");
3305     }
3307     # Step two: if we are doing recursive makes, write out the
3308     # appropriate rules.
3309     local (@install);
3310     if ($recursive_install)
3311     {
3312         push (@install, 'install-recursive');
3314         if (@all)
3315         {
3316             local (@hackall) = ();
3317             local ($one_name);
3318             local ($local_headers) = '';
3319             foreach $one_name (@config_names)
3320             {
3321                 if (&dirname ($one_name) eq $relative_dir)
3322                 {
3323                     $local_headers .= ' ' if $local_headers;
3324                     $local_headers .= &basename ($one_name);
3325                 }
3326             }
3327             if ($local_headers)
3328             {
3330                 # This is kind of a hack, but I couldn't see a better
3331                 # way to handle it.  In this particular case, we need
3332                 # to make sure config.h is built before we recurse.
3333                 # We can't do this by changing the order of
3334                 # dependencies to the "all" because that breaks when
3335                 # using parallel makes.  Instead we handle things
3336                 # explicitly.
3337                 $output_rules .= ("all-recursive-am: ${local_headers}"
3338                                   . "\n\t" . '$(MAKE) all-recursive'
3339                                   . "\n\n");
3340                 push (@hackall, 'all-recursive-am');
3341                 push (@phony, 'all-recursive-am');
3342             }
3343             else
3344             {
3345                 push (@hackall, 'all-recursive');
3346             }
3348             $output_rules .= ('all-am: '
3349                               . join (' ', @all)
3350                               . "\n\n");
3351             @all = @hackall;
3352             push (@all, 'all-am');
3353             push (@phony, 'all-am');
3354         }
3355         else
3356         {
3357             @all = ('all-recursive');
3359             # Must always generate `all-am' target, so it can be
3360             # referred to elsewhere.
3361             $output_rules .= "all-am:\n";
3362         }
3363         if (@install_exec)
3364         {
3365             $output_rules .= ('install-exec-am: '
3366                               . join (' ', @install_exec)
3367                               . "\n\n");
3368             @install_exec = ('install-exec-recursive', 'install-exec-am');
3369             push (@install, 'install-exec-am');
3370             push (@phony, 'install-exec-am');
3371         }
3372         else
3373         {
3374             @install_exec = ('install-exec-recursive');
3375         }
3376         if (@install_data)
3377         {
3378             $output_rules .= ('install-data-am: '
3379                               . join (' ', @install_data)
3380                               . "\n\n");
3381             @install_data = ('install-data-recursive', 'install-data-am');
3382             push (@install, 'install-data-am');
3383             push (@phony, 'install-data-am');
3384         }
3385         else
3386         {
3387             @install_data = ('install-data-recursive');
3388         }
3389         if (@uninstall)
3390         {
3391             $output_rules .= ('uninstall-am: '
3392                               . join (' ', @uninstall)
3393                               . "\n\n");
3394             @uninstall = ('uninstall-recursive', 'uninstall-am');
3395             push (@phony, 'uninstall-am');
3396         }
3397         else
3398         {
3399             @uninstall = ('uninstall-recursive');
3400         }
3401     }
3403     # Step three: print definitions users can use.  Code below knows
3404     # that install-exec is done before install-data, beware.
3405     $output_rules .= ("install-exec: "
3406                       . join (' ', @install_exec)
3407                       . "\n");
3408     $output_rules .= "\t\@\$(NORMAL_INSTALL)\n";
3409     if (defined $contents{'install-exec-hook'})
3410     {
3411         $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
3412     }
3413     $output_rules .= "\n";
3414     push (@install, 'install-exec') if !$recursive_install;
3415     push (@phony, 'install-exec');
3417     $output_rules .= ("install-data: "
3418                       . join (' ', @install_data)
3419                       . "\n");
3420     $output_rules .= "\t\@\$(NORMAL_INSTALL)\n";
3421     if (defined $contents{'install-data-hook'})
3422     {
3423         $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
3424     }
3425     $output_rules .= "\n";
3426     push (@install, 'install-data') if !$recursive_install;
3427     push (@phony, 'install-data');
3429     # If no dependencies for 'install', add 'all'.  Why?  That way
3430     # "make install" at top level of distclean'd distribution won't
3431     # fail because stuff in 'lib' fails to build.
3432     if (! @install || (scalar (@install) == 2
3433                        && $install[0] eq 'install-exec'
3434                        && $install[1] eq 'install-data'))
3435     {
3436         push (@install, 'all');
3437     }
3438     $output_rules .= ('install: '
3439                       . join (' ', @install)
3440                       # Use "@:" as empty command so nothing prints.
3441                       . "\n\t\@:"
3442                       . "\n\n"
3443                       . 'uninstall: '
3444                       . join (' ', @uninstall)
3445                       . "\n\n");
3446     push (@phony, 'install', 'uninstall');
3448     $output_rules .= ('all: '
3449                       . join (' ', @all)
3450                       . "\n\n");
3451     push (@phony, 'all');
3453     # Generate the new 'install-strip' target.
3454     $output_rules .= ("install-strip:\n\t"
3455                       . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
3456                       . "\n");
3459 # Helper for handle_merge_targets.
3460 sub do_one_merge_target
3462     local ($name, @values) = @_;
3464     if (defined $contents{$name . '-local'})
3465     {
3466         # User defined local form of target.  So include it.
3467         push (@values, $name . '-local');
3468         push (@phony, $name . '-local');
3469     }
3471     &pretty_print_rule ($name . ":", "\t\t", @values);
3472     push (@phony, $name);
3475 # Handle check merge target specially.
3476 sub do_check_merge_target
3478     if (defined $contents{'check-local'})
3479     {
3480         # User defined local form of target.  So include it.
3481         push (@check_tests, 'check-local');
3482         push (@phony, 'check-local');
3483     }
3485     if (! &variable_defined ('SUBDIRS'))
3486     {
3487         # 'check' must depend on `all', but not when doing recursive
3488         # build.
3489         unshift (@check, 'all');
3490     }
3491     else
3492     {
3493         # When subdirs are used, do the `all' build and then do all
3494         # the recursive stuff.  Actually use `all-am' because it
3495         # doesn't recurse; we rely on the check target in the subdirs
3496         # to do the required builds there.
3497         unshift (@check, 'all-am');
3498     }
3500     # The check target must depend on the local equivalent of `all',
3501     # to ensure all the primary targets are built.  Also it must
3502     # depend on the test code named in @check.
3503     &pretty_print_rule ('check:', "\t\t", @check);
3505     # Now the check rules must explicitly run anything named in
3506     # @check_tests.  This is done via a separate make invocation to
3507     # avoid problems with parallel makes.  Every time I write code
3508     # like this I wonder: how could you invent a parallel make and not
3509     # provide any real synchronization facilities?
3510     &pretty_print_rule ("\t\$(MAKE)", "\t  ", @check_tests);
3513 # Handle all 'clean' targets.
3514 sub handle_clean
3516     push (@clean, 'generic');
3517     $output_rules .= &file_contents ('clean');
3518     &push_phony_cleaners ('generic');
3520     local ($target) = $recursive_install ? 'clean-am' : 'clean';
3521     &do_one_clean_target ($target, 'mostly', '', @clean);
3522     &do_one_clean_target ($target, '', 'mostly', @clean);
3523     &do_one_clean_target ($target, 'dist', '', @clean);
3524     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
3526     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
3528     local (@deps);
3529     if ($recursive_install)
3530     {
3531         # Do -recursive before -am.  If you aren't doing a parallel
3532         # make, this can be nicer.
3533         @deps = ('recursive', 'am');
3534         &do_one_clean_target ('', 'mostly', '', @deps);
3535         &do_one_clean_target ('', '', '', @deps);
3536         &do_one_clean_target ('', 'dist', '', @deps);
3537         &do_one_clean_target ('', 'maintainer-', '', @deps);
3538     }
3541 # Helper for handle_clean.
3542 sub do_one_clean_target
3544     local ($target, $name, $last_name, @deps) = @_;
3546     # Special case: if target not passed, then don't generate
3547     # dependency on next "lower" clean target (eg no
3548     # clean<-mostlyclean derivation).  In this case the target is
3549     # implicitly known to be 'clean'.
3550     local ($flag) = $target;
3551     $target = 'clean' if ! $flag;
3553     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
3554     if ($flag)
3555     {
3556         if ($last_name || $name ne 'mostly')
3557         {
3558             push (@deps, $last_name . $target);
3559         }
3560     }
3562     # If a -local version of the rule is given, add it to the list.
3563     if (defined $contents{$name . $target . '-local'})
3564     {
3565         push (@deps, $name . $target . '-local');
3566     }
3568     # Print the target and the dependencies.
3569     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
3571     # FIXME: shouldn't we really print these messages before running
3572     # the dependencies?
3573     if ($name . $target eq 'maintainer-clean')
3574     {
3575         # Print a special warning.
3576         $output_rules .=
3577             ("\t\@echo \"This command is intended for maintainers to use;\"\n"
3578              . "\t\@echo \"it deletes files that may require special "
3579              . "tools to rebuild.\"\n");
3581         $output_rules .= "\trm -f config.status\n"
3582             if $relative_dir eq '.';
3583     }
3584     elsif ($name . $target eq 'distclean')
3585     {
3586         $output_rules .= "\trm -f config.status\n";
3587         $output_rules .= "\trm -f libtool\n" if $seen_libtool;
3588     }
3589     $output_rules .= "\n";
3592 # Handle .PHONY target.
3593 sub handle_phony
3595     &pretty_print_rule ('.PHONY:', "", @phony);
3596     $output_rules .= "\n";
3599 # Handle TESTS variable and other checks.
3600 sub handle_tests
3602     if (defined $options{'dejagnu'})
3603     {
3604         push (@check_tests, 'check-DEJAGNU');
3605         push (@phony, 'check-DEJAGNU');
3607         local ($xform);
3608         if ($cygnus_mode)
3609         {
3610             $xform = 's/^CYGNUS//;';
3611         }
3612         else
3613         {
3614             $xform = 's/^CYGNUS.*$//;';
3615         }
3616         $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
3618         # In Cygnus mode, these are found in the build tree.
3619         # Otherwise they are looked for in $PATH.
3620         &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
3621         &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
3623         # Note that in the rule we don't directly generate site.exp to
3624         # avoid the possibility of a corrupted site.exp if make is
3625         # interrupted.  Jim Meyering has some useful text on this
3626         # topic.
3627         $output_rules .= ("site.exp: Makefile\n"
3628                           . "\t\@echo 'Making a new site.exp file...'\n"
3629                           . "\t-\@rm -f site.bak\n"
3630                           . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
3631                           . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
3632                           . "\t\@echo '# edit the last section' >> \$\@-t\n"
3633                           . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
3634                           . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
3635                           . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
3637         # Extra stuff for AC_CANONICAL_*
3638         local (@whatlist) = ();
3639         if ($seen_canonical)
3640         {
3641             push (@whatlist, 'host')
3642         }
3644         # Extra stuff only for AC_CANONICAL_SYSTEM.
3645         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
3646         {
3647             push (@whatlist, 'target', 'build');
3648         }
3650         local ($c1, $c2);
3651         foreach $c1 (@whatlist)
3652         {
3653             foreach $c2 ('alias', 'triplet')
3654             {
3655                 $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
3656             }
3657         }
3659         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
3660                           . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
3661                           . "\t-\@mv site.exp site.bak\n"
3662                           . "\t\@mv \$\@-t site.exp\n");
3663     }
3664     else
3665     {
3666         local ($c);
3667         foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
3668         {
3669             if (&variable_defined ($c))
3670             {
3671                 &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
3672             }
3673         }
3674     }
3676     if (&variable_defined ('TESTS'))
3677     {
3678         push (@check_tests, 'check-TESTS');
3679         push (@phony, 'check-TESTS');
3681         $output_rules .= 'check-TESTS: $(TESTS)
3682         @failed=0; all=0; \\
3683         srcdir=$(srcdir); export srcdir; \\
3684         for tst in $(TESTS); do \\
3685           all=`expr $$all + 1`; \\
3686           if test -f $$tst; then dir=.; \\
3687           else dir="$(srcdir)"; fi; \\
3688           if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
3689             echo "PASS: $$tst"; \\
3690           else \\
3691             failed=`expr $$failed + 1`; \\
3692             echo "FAIL: $$tst"; \\
3693           fi; \\
3694         done; \\
3695         if test "$$failed" -eq 0; then \\
3696           echo "========================"; \\
3697           echo "All $$all tests passed"; \\
3698           echo "========================"; \\
3699         else \\
3700           echo "$$failed of $$all tests failed"; \\
3701           exit 1; \\
3702         fi
3704     }
3707 # Handle Emacs Lisp.
3708 sub handle_emacs_lisp
3710     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
3712     if (@elfiles)
3713     {
3714         # Found some lisp.
3715         &define_configure_variable ('lispdir');
3716         &define_configure_variable ('EMACS');
3717         $output_rules .= (".el.elc:\n"
3718                           . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
3719                           . "\tif test \$(EMACS) != no; then \\\n"
3720                           . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
3721                           . "\tfi\n");
3722         push (@suffixes, '.el', '.elc');
3724         # Generate .elc files.
3725         grep ($_ .= 'c', @elfiles);
3726         &define_pretty_variable ('ELCFILES', '', @elfiles);
3728         push (@clean, 'lisp');
3729         &push_phony_cleaners ('lisp');
3731         push (@all, '$(ELCFILES)');
3733         local ($varname);
3734         if (&variable_defined ('lisp_LISP'))
3735         {
3736             $varname = 'lisp_LISP';
3737             &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
3738                 if ! $seen_lispdir;
3739         }
3740         else
3741         {
3742             $varname = 'noinst_LISP';
3743         }
3745         &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
3746     }
3749 ################################################################
3751 # Scan one file for interesting things.  Subroutine of scan_configure.
3752 sub scan_one_configure_file
3754     local ($filename) = @_;
3756     open (CONFIGURE, $filename)
3757         || die "automake: couldn't open \`$filename': $!\n";
3758     print "automake: reading $filename\n" if $verbose;
3760     while (<CONFIGURE>)
3761     {
3762         # Remove comments from current line.
3763         s/\bdnl\b.*$//;
3764         s/\#.*$//;
3766         # Skip macro definitions.  Otherwise we might be confused into
3767         # thinking that a macro that was only defined was actually
3768         # used.
3769         next if /AC_DEFUN/;
3771         # Populate libobjs array.
3772         if (/AC_FUNC_ALLOCA/)
3773         {
3774             $libsources{'alloca.c'} = 1;
3775         }
3776         elsif (/AC_FUNC_GETLOADAVG/)
3777         {
3778             $libsources{'getloadavg.c'} = 1;
3779         }
3780         elsif (/AC_FUNC_MEMCMP/)
3781         {
3782             $libsources{'memcmp.c'} = 1;
3783         }
3784         elsif (/AC_STRUCT_ST_BLOCKS/)
3785         {
3786             $libsources{'fileblocks.c'} = 1;
3787         }
3788         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
3789         {
3790             $libsources{'getopt.c'} = 1;
3791             $libsources{'getopt1.c'} = 1;
3792         }
3793         elsif (/AM_FUNC_STRTOD/)
3794         {
3795             $libsources{'strtod.c'} = 1;
3796         }
3797         elsif (/AM_WITH_REGEX/)
3798         {
3799             $libsources{'rx.c'} = 1;
3800             $libsources{'rx.h'} = 1;
3801             $libsources{'regex.c'} = 1;
3802             $libsources{'regex.h'} = 1;
3803             $omit_dependencies{'rx.h'} = 1;
3804             $omit_dependencies{'regex.h'} = 1;
3805         }
3806         elsif (/AM_FUNC_MKTIME/)
3807         {
3808             $libsources{'mktime.c'} = 1;
3809         }
3810         elsif (/AM_FUNC_ERROR_AT_LINE/)
3811         {
3812             $libsources{'error.c'} = 1;
3813             $libsources{'error.h'} = 1;
3814         }
3815         elsif (/AM_FUNC_OBSTACK/)
3816         {
3817             $libsources{'obstack.c'} = 1;
3818             $libsources{'obstack.h'} = 1;
3819         }
3820         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
3821                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
3822         {
3823             foreach $libobj_iter (split (' ', $1))
3824             {
3825                 if ($libobj_iter =~ /^(.*)\.o$/)
3826                 {
3827                     $libsources{$1 . '.c'} = 1;
3828                 }
3829             }
3830         }
3832         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
3833         {
3834             $in_ac_replace = 1;
3835         }
3836         if ($in_ac_replace)
3837         {
3838             $in_ac_replace = 0 if s/[\]\)].*$//;
3839             # Remove trailing backslash.
3840             s/\\$//;
3841             foreach (split)
3842             {
3843                 # Need to skip empty elements for Perl 4.
3844                 next if $_ eq '';
3845                 $libsources{$_ . '.c'} = 1;
3846             }
3847         }
3849         if (/$obsolete_rx/o)
3850         {
3851             local ($hint) = '';
3852             if ($obsolete_macros{$1})
3853             {
3854                 $hint = '; ' . $obsolete_macros{$1};
3855             }
3856             &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
3857         }
3859         # Process the AC_OUTPUT macro.
3860         if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
3861         {
3862             $in_ac_output = 1;
3863             $ac_output_line = $.;
3864         }
3865         if ($in_ac_output)
3866         {
3867             $in_ac_output = 0 if s/[\]\),].*$//;
3869             # Look at potential Makefile.am's.
3870             foreach (split)
3871             {
3872                 next if $_ eq "\\";
3874                 # Handle $local:$input syntax.  Note that we ignore
3875                 # every input file past the first, though we keep
3876                 # those around for later.
3877                 local ($local, $input, @rest) = split (/:/);
3878                 if (! $input)
3879                 {
3880                     $input = $local;
3881                 }
3882                 else
3883                 {
3884                     # FIXME: should be error if .in is missing.
3885                     $input =~ s/\.in$//;
3886                 }
3888                 if (-f $input . '.am')
3889                 {
3890                     # We have a file that automake should generate.
3891                     push (@make_input_list, $input);
3892                     $make_list{$input} = join (':', ($local, @rest));
3893                 }
3894                 else
3895                 {
3896                     # We have a file that automake should cause to be
3897                     # rebuilt, but shouldn't generate itself.
3898                     push (@other_input_files, $_);
3899                 }
3900             }
3901         }
3903         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
3904         {
3905             @config_aux_path = $1;
3906         }
3908         # Check for ansi2knr.
3909         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
3911         # Check for Cygwin32.
3912         if (/AM_CYGWIN32/)
3913         {
3914             $seen_cygwin32 = 1;
3915             $configure_vars{'EXEEXT'} = 1;
3916         }
3918         # Check for NLS support.
3919         if (/AM_GNU_GETTEXT/)
3920         {
3921             $seen_gettext = 1;
3922             $ac_gettext_line = $.;
3923             $omit_dependencies{'libintl.h'} = 1;
3924         }
3926         # Look for ALL_LINGUAS.
3927         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
3928         {
3929             $seen_linguas = 1;
3930             $all_linguas = $1;
3931             $all_linguas_line = $.;
3932         }
3934         # Handle configuration headers.  A config header of `[$1]'
3935         # means we are actually scanning AM_CONFIG_HEADER from
3936         # aclocal.m4.
3937         if (/A([CM])_CONFIG_HEADER\s*\((.*)\)/
3938             && $2 ne '[$1]')
3939         {
3940             &am_conf_line_error
3941                 ($filename, $.,
3942                  "\`AC_CONFIG_HEADER' is obsolete; use \`AM_CONFIG_HEADER'")
3943                     if $1 eq 'C';
3945             $config_header_line = $.;
3946             local ($one_hdr);
3947             foreach $one_hdr (split (' ', $2))
3948             {
3949                 push (@config_fullnames, $one_hdr);
3950                 if ($one_hdr =~ /^([^:]+):(.+)$/)
3951                 {
3952                     push (@config_names, $1);
3953                     push (@config_headers, $2);
3954                 }
3955                 else
3956                 {
3957                     push (@config_names, $one_hdr);
3958                     push (@config_headers, $one_hdr . '.in');
3959                 }
3960             }
3961         }
3963         # Handle AC_CANONICAL_*.  Always allow upgrading to
3964         # AC_CANONICAL_SYSTEM, but never downgrading.
3965         $seen_canonical = $AC_CANONICAL_HOST
3966             if ! $seen_canonical
3967                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
3968         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
3970         $seen_path_xtra = 1 if /AC_PATH_XTRA/;
3972         # This macro handles several different things.
3973         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
3974         {
3975             $seen_make_set = 1;
3976             $seen_package = 1;
3977             $seen_version = 1;
3978             $seen_arg_prog = 1;
3979             $seen_prog_install = 2;
3980             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
3981             $package_version_line = $.;
3982         }
3984         # This is like AM_INIT_AUTOMAKE, but doesn't actually set the
3985         # package and version number.  (This might change in the
3986         # future).  Yes, I'm not above hacking Automake so it works
3987         # well with other GNU tools -- that is actually the point.
3988         if (/AM_INIT_GUILE_MODULE/)
3989         {
3990             $seen_make_set = 1;
3991             $seen_package = 1;
3992             $seen_version = 1;
3993             $seen_arg_prog = 1;
3994             $seen_prog_install = 2;
3995             @config_aux_path = ('..');
3996         }
3998         # Some things required by Automake.
3999         $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
4000         $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
4002         if (/AC_PROG_(YACC|RANLIB|CC|CXX|LEX|AWK|CPP|CXXCPP|LN_S)/)
4003         {
4004             $configure_vars{$1} = 1;
4005         }
4006         if (/$AC_CHECK_PATTERN/o)
4007         {
4008             $configure_vars{$3} = 1;
4009         }
4010         if (/$AM_MISSING_PATTERN/o)
4011         {
4012             $configure_vars{$1} = 1;
4013         }
4015         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4016         # but later define it elsewhere.  This is pretty hacky.  We
4017         # also explicitly avoid INSTALL_SCRIPT because it is defined
4018         # in header-vars.am.  FIXME.
4019         if (/$AC_SUBST_PATTERN/o
4020             && $1 ne 'ANSI2KNR'
4021             && $1 ne 'INSTALL_SCRIPT')
4022         {
4023             $configure_vars{$1} = 1;
4024         }
4026         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4027         $seen_maint_mode = 1 if /AM_MAINTAINER_MODE/;
4028         $seen_package = 1 if /PACKAGE=/;
4030         # Skip VERSION of [$2]; that is from AM_INIT_AUTOMAKE.
4031         if (/\bVERSION=(\S+)/ && $1 ne '[$2]')
4032         {
4033             $seen_version = 1;
4034             $package_version = $1;
4035             $package_version_line = $.;
4036         }
4037         elsif (/VERSION=/)
4038         {
4039             $seen_version = 1;
4040         }
4042         # Weird conditionals here because it is always allowed to
4043         # upgrade to AM_PROG_INSTALL but never to downgrade to
4044         # AC_PROG_INSTALL.
4045         $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
4046         $seen_prog_install = 2 if /AM_PROG_INSTALL/;
4048         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4050         if (/AM_PROG_LIBTOOL/)
4051         {
4052             $seen_libtool = 1;
4053             $libtool_line = $.;
4054             $configure_vars{'LIBTOOL'} = 1;
4055             $configure_vars{'RANLIB'} = 1;
4056             $configure_vars{'CC'} = 1;
4057             # AM_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
4058             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4059             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4060         }
4062         if (/$AM_CONDITIONAL_PATTERN/o)
4063         {
4064             $configure_cond{$1} = 1;
4065         }
4066     }
4068     close (CONFIGURE);
4071 # Scan configure.in and aclocal.m4 for interesting things.  We must
4072 # scan aclocal.m4 because there might be AC_SUBSTs and such there.
4073 sub scan_configure
4075     # Reinitialize libsources here.  This isn't really necessary,
4076     # since we currently assume there is only one configure.in.  But
4077     # that won't always be the case.
4078     %libsources = ();
4080     local ($in_ac_output, $in_ac_replace) = (0, 0);
4081     local (%make_list, @make_input_list);
4082     local ($libobj_iter);
4084     &scan_one_configure_file ('configure.in');
4085     &scan_one_configure_file ('aclocal.m4')
4086         if -f 'aclocal.m4';
4088     # Set input and output files if not specified by user.
4089     if (! @input_files)
4090     {
4091         @input_files = @make_input_list;
4092         %output_files = %make_list;
4093     }
4095     &am_conf_error ("\`PACKAGE' not defined in configure.in")
4096         if ! $seen_package;
4097     &am_conf_error ("\`VERSION' not defined in configure.in")
4098         if ! $seen_version;
4100     # Look for some files we need.  Always check for these.  This
4101     # check must be done for every run, even those where we are only
4102     # looking at a subdir Makefile.  We must set relative_dir so that
4103     # the file-finding machinery works.
4104     local ($relative_dir) = '.';
4105     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4106     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
4107         if -f $config_aux_path[0] . '/install.sh';
4110 ################################################################
4112 # Set up for Cygnus mode.
4113 sub check_cygnus
4115     return unless $cygnus_mode;
4117     &set_strictness ('foreign');
4118     $options{'no-installinfo'} = 1;
4119     $options{'no-dependencies'} = 1;
4120     $use_dependencies = 0;
4122     if (! $seen_maint_mode)
4123     {
4124         &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
4125     }
4127     if (! $seen_cygwin32)
4128     {
4129         &am_conf_error ("\`AM_CYGWIN32' required when --cygnus specified");
4130     }
4133 # Do any extra checking for GNU standards.
4134 sub check_gnu_standards
4136     if ($relative_dir eq '.')
4137     {
4138         # In top level (or only) directory.
4139         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4140                        'AUTHORS', 'ChangeLog');
4141     }
4143     if ($strictness >= $GNU)
4144     {
4145         if (defined $options{'no-installman'})
4146         {
4147             &am_line_error ('AUTOMAKE_OPTIONS',
4148                             "option \`no-installman' disallowed by GNU standards");
4149         }
4151         if (defined $options{'no-installinfo'})
4152         {
4153             &am_line_error ('AUTOMAKE_OPTIONS',
4154                             "option \`no-installinfo' disallowed by GNU standards");
4155         }
4156     }
4159 # Do any extra checking for GNITS standards.
4160 sub check_gnits_standards
4162     if ($strictness >= $GNITS)
4163     {
4164         if (-f $relative_dir . '/COPYING.LIB')
4165         {
4166             &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
4167         }
4169         if ($relative_dir eq '.')
4170         {
4171             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4172             {
4173                 # FIXME: allow real filename.
4174                 &am_conf_line_error ('configure.in',
4175                                      $package_version_line,
4176                                      "version \`$package_version' doesn't follow Gnits standards");
4177             }
4178             elsif (defined $1 && -f 'README-alpha')
4179             {
4180                 # This means we have an alpha release.  See
4181                 # GNITS_VERSION_PATTERN for details.
4182                 &require_file ($GNITS, 'README-alpha');
4183             }
4184         }
4185     }
4187     if ($relative_dir eq '.')
4188     {
4189         # In top level (or only) directory.
4190         &require_file ($GNITS, 'THANKS');
4191     }
4194 ################################################################
4196 # Pretty-print something.  HEAD is what should be printed at the
4197 # beginning of the first line, FILL is what should be printed at the
4198 # beginning of every subsequent line.
4199 sub pretty_print_internal
4201     local ($head, $fill, @values) = @_;
4203     local ($column) = length ($head);
4204     local ($result) = $head;
4206     # Fill length is number of characters.  However, each Tab
4207     # character counts for eight.  So we count the number of Tabs and
4208     # multiply by 7.
4209     local ($fill_length) = length ($fill);
4210     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
4212     local ($bol) = ($head eq '');
4213     foreach (@values)
4214     {
4215         # "71" because we also print a space.
4216         if ($column + length ($_) > 71)
4217         {
4218             $result .= " \\\n" . $fill;
4219             $column = $fill_length;
4220             $bol = 1;
4221         }
4223         $result .= ' ' unless ($bol);
4224         $result .= $_;
4225         $column += length ($_) + 1;
4226         $bol = 0;
4227     }
4229     $result .= "\n";
4230     return $result;
4233 # Pretty-print something and append to output_vars.
4234 sub pretty_print
4236     $output_vars .= &pretty_print_internal (@_);
4239 # Pretty-print something and append to output_rules.
4240 sub pretty_print_rule
4242     $output_rules .= &pretty_print_internal (@_);
4246 ################################################################
4248 # See if a target exists.
4249 sub target_defined
4251     local ($target) = @_;
4252     return defined $targets{$target};
4255 # See if two conditionals are the same.
4256 sub conditional_same
4258     local ($cond1, $cond2) = @_;
4260     return (&conditional_true_when ($cond1, $cond2)
4261             && &conditional_true_when ($cond2, $cond1));
4264 # See if a conditional is true.  Both arguments are conditional
4265 # strings.  This returns true if the first conditional is true when
4266 # the second conditional is true.
4267 sub conditional_true_when
4269     local ($cond, $when) = @_;
4271     # Check the easy case first.
4272     if ($cond eq $when)
4273     {
4274         return 1;
4275     }
4277     # Check each component of $cond, which looks @COND1@@COND2@.
4278     foreach $comp (split ('@', $cond))
4279     {
4280         # The way we split will give null strings between each
4281         # condition.
4282         next if ! $comp;
4284         if (index ($when, '@' . $comp . '@') == -1)
4285         {
4286             return 0;
4287         }
4288     }
4290     return 1;
4293 # Check for an ambiguous conditional.  This is called when a variable
4294 # or target is being defined conditionally.  If we already know about
4295 # a definition that is true under the same conditions, then we have an
4296 # ambiguity.
4297 sub check_ambiguous_conditional
4299     local ($var_name, $cond) = @_;
4300     local (@cond_vals) = split (/ /, $conditional{$var_name});
4301     while (@cond_vals)
4302     {
4303         local ($vcond) = shift (@cond_vals);
4304         shift (@cond_vals);
4305         if (&conditional_true_when ($vcond, $cond)
4306             || &conditional_true_when ($cond, $vcond))
4307         {
4308             &am_line_error ($var_name,
4309                             "$var_name multiply defined in condition");
4310         }
4311     }
4314 # See if a variable exists.  The first argument is the variable name,
4315 # and the optional second argument is the condition which we should
4316 # check.  If no condition is given, we currently return true if the
4317 # variable is defined under any condition.
4318 sub variable_defined
4320     local ($var, $cond) = @_;
4321     if (defined $targets{$var})
4322     {
4323         &am_line_error ($var, "\`$var' is target; expected variable");
4324         return 0;
4325     }
4326     elsif (defined $contents{$var})
4327     {
4328         if ($cond && $conditional{$var})
4329         {
4330             # We have been asked to check for a particular condition,
4331             # and the variable is defined conditionally.  We need to
4332             # look through the conditions under which the variable is
4333             # defined, and see if any of them match the conditional we
4334             # have been asked to check.
4335             local (@cond_vars) = split (/ /, $conditional{$var});
4336             while (@cond_vars)
4337             {
4338                 if (&conditional_same ($cond, shift (@cond_vars)))
4339                 {
4340                     return 1;
4341                 }
4342                 shift (@cond_vars);
4343             }
4345             # The variable is not defined for the given condition.
4346             return 0;
4347         }
4349         $content_seen{$var} = 1;
4350         return 1;
4351     }
4352     return 0;
4355 # Mark a variable as examined.
4356 sub examine_variable
4358     local ($var) = @_;
4359     &variable_defined ($var);
4362 # Quote a value in order to put it in $conditional.  We need to quote
4363 # spaces, and we need to handle null strings, so that we can later
4364 # retrieve values by splitting on space.
4365 sub quote_cond_val
4367     local ($val) = @_;
4368     $val =~ s/ /\001/g;
4369     $val = '\002' if $val eq '';
4370     return $val;
4373 # Unquote a value in $conditional.
4374 sub unquote_cond_val
4376     local ($val) = @_;
4377     $val =~ s/\001/ /g;
4378     $val = '' if $val eq '\002';
4379     return $val;
4382 # Return the set of conditions for which a variable is defined.
4384 # If the variable is not defined conditionally, and is not defined in
4385 # terms of any variables which are defined conditionally, then this
4386 # returns the empty list.
4388 # If the variable is defined conditionally, but is not defined in
4389 # terms of any variables which are defined conditionally, then this
4390 # returns the list of conditions for which the variable is defined.
4392 # If the variable is defined in terms of any variables which are
4393 # defined conditionally, then this returns a full set of permutations
4394 # of the subvariable conditions.  For example, if the variable is
4395 # defined in terms of a variable which is defined for @COND_TRUE@,
4396 # then this returns both @COND_TRUE@ and @COND_FALSE@.  This is
4397 # because we will need to define the variable under both conditions.
4399 sub variable_conditions
4401     local ($var) = @_;
4402     local (%uniqify);
4403     local ($cond);
4405     foreach $cond (&variable_conditions_sub ($var, '', ()))
4406     {
4407         $uniqify{$cond} = 1;
4408     }
4410     return keys %uniqify;
4413 # A subroutine of variable_conditions.  We only return conditions
4414 # which are true for all the conditions in @PARENT_CONDS.
4415 sub variable_conditions_sub
4417     local ($var, $parent, @parent_conds) = @_;
4418     local (@new_conds) = ();
4420     if (! $conditional{$var})
4421     {
4422         foreach (split (' ', $contents{$var}))
4423         {
4424             # If a comment seen, just leave.
4425             last if /^#/;
4427             # Handle variable substitutions.
4428             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
4429             {
4430                 push (@new_conds,
4431                       &variable_conditions_sub ($1, $var, @parent_conds));
4432             }
4433         }
4435         return &variable_conditions_reduce (@new_conds);
4436     }
4438     local (@this_conds) = ();
4439     local (@condvals) = split (/ /, $conditional{$var});
4440     while (@condvals)
4441     {
4442         local ($cond) = shift (@condvals);
4443         local ($val) = &unquote_cond_val (shift (@condvals));
4445         if (@parent_conds)
4446         {
4447             local ($ok) = 1;
4448             local ($parent_cond);
4449             foreach $parent_cond (@parent_conds)
4450             {
4451                 if (! &conditional_true_when ($parent_cond, $cond))
4452                 {
4453                     $ok = 0;
4454                     last;
4455                 }
4456             }
4458             next if ! $ok;
4459         }
4461         push (@this_conds, $cond);
4463         push (@parent_conds, $cond);
4464         local (@subvar_conds) = ();
4465         foreach (split (' ', $val))
4466         {
4467             # If a comment seen, just leave.
4468             last if /^#/;
4470             # Handle variable substitutions.
4471             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
4472             {
4473                 push (@subvar_conds,
4474                       &variable_conditions_sub ($1, $var, @parent_conds));
4475             }
4476         }
4477         pop (@parent_conds);
4479         # If there are no conditional subvariables, then we want to
4480         # return this condition.  Otherwise, we want to return the
4481         # permutations of the subvariables.
4482         if (! @subvar_conds)
4483         {
4484             push (@new_conds, $cond);
4485         }
4486         else
4487         {
4488             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
4489         }
4490     }
4492     return @new_conds
4493         if ! $parent;
4495     # If we are being called on behalf of another variable, we need to
4496     # return all possible permutations of the conditions.  We have
4497     # already handled everything in @this_conds along with their
4498     # subvariables.  We now need to add any permutations that are not
4499     # in @this_conds.
4500     local ($this_cond);
4501     foreach $this_cond (@this_conds)
4502     {
4503         local (@perms) =
4504             &variable_conditions_permutations (split('@', $this_cond));
4505         local ($perm);
4506         foreach $perm (@perms)
4507         {
4508             local ($scan);
4509             local ($ok) = 1;
4510             foreach $scan (@this_conds)
4511             {
4512                 if (&conditional_true_when ($perm, $scan)
4513                     || &conditional_true_when ($scan, $perm))
4514                 {
4515                     $ok = 0;
4516                     last;
4517                 }
4518             }
4519             next if ! $ok;
4521             if (@parent_conds)
4522             {
4523                 local ($ok) = 1;
4524                 local ($parent_cond);
4525                 foreach $parent_cond (@parent_conds)
4526                 {
4527                     if (! &conditional_true_when ($parent_cond, $perm))
4528                     {
4529                         $ok = 0;
4530                         last;
4531                     }
4532                 }
4534                 next if ! $ok;
4535             }
4537             # This permutation was not already handled, and is valid
4538             # for the parents.
4539             push (@new_conds, $perm);
4540         }
4541     }
4543     return @new_conds;
4546 # Subroutine for variable_conditions_sort
4547 sub variable_conditions_cmp
4549     local ($as) = $a;
4550     $as =~ s/[^@]//g;
4551     local ($bs) = $b;
4552     $bs =~ s/[^@]//g;
4553     return (length ($as) <=> length ($bs)
4554             || $a cmp $b);
4557 # Sort a list of conditionals so that only the exclusive ones are
4558 # retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
4559 # @COND1_TRUE@ are in the list, discard the latter.
4560 sub variable_conditions_reduce
4562     local (@conds) = @_;
4563     local (@ret) = ();
4564     local ($cond);
4565     foreach $cond (sort variable_conditions_cmp @conds)
4566     {
4567         local ($ok) = 1;
4568         local ($scan);
4569         foreach $scan (@ret)
4570         {
4571             if (&conditional_true_when ($cond, $scan))
4572             {
4573                 $ok = 0;
4574                 last;
4575             }
4576         }
4577         next if ! $ok;
4578         push (@ret, $cond);
4579     }
4581     return @ret;
4584 # Return a list of permutations of a conditional string.
4585 sub variable_conditions_permutations
4587     local (@comps) = @_;
4588     return ()
4589         if ! @comps;
4590     local ($comp) = shift (@comps);
4591     return &variable_conditions_permutations (@comps)
4592         if $comp eq '';
4593     local ($neg) = $comp;
4594     $neg =~ s/TRUE$/TRUEO/;
4595     $neg =~ s/FALSE$/TRUE/;
4596     $neg =~ s/TRUEO$/FALSE/;
4597     local (@ret);
4598     local ($sub);
4599     foreach $sub (&variable_conditions_permutations (@comps))
4600     {
4601         push (@ret, '@' . $comp . '@' . $sub);
4602         push (@ret, '@' . $neg . '@' . $sub);
4603     }
4604     if (! @ret)
4605     {
4606         push (@ret, '@' . $comp . '@');
4607         push (@ret, '@' . $neg . '@');
4608     }
4609     return @ret;
4612 # Warn if a variable is conditionally defined.  This is called if we
4613 # are using the value of a variable.
4614 sub variable_conditionally_defined
4616     local ($var, $parent) = @_;
4617     if ($conditional{$var})
4618     {
4619         if ($parent)
4620         {
4621             &am_line_error ($parent,
4622                             "warning: automake does not support conditional definition of $var in $parent");
4623         }
4624         else
4625         {
4626             &am_line_error ($parent,
4627                             "warning: automake does not support $var being defined conditionally")
4628         }
4629     }
4632 # Get the value of a variable.  This just returns $contents, but warns
4633 # if the variable is conditionally defined.
4634 sub variable_value
4636     local ($var) = @_;
4637     &variable_conditionally_defined ($var);
4638     return $contents{$var};
4641 # Convert a variable value to a list, split as whitespace.  This will
4642 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
4643 # substitutions.  If COND is 'all', then all values under all
4644 # conditions should be returned; if COND is a particular condition
4645 # (all conditions are surrounded by @...@) then only the value for
4646 # that condition should be returned; otherwise, warn if VAR is
4647 # conditionally defined.
4648 sub value_to_list
4650     local ($var, $val, $cond) = @_;
4651     local (@result);
4653     foreach (split (' ', $val))
4654     {
4655         # If a comment seen, just leave.
4656         last if /^#/;
4658         # Handle variable substitutions.
4659         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
4660         {
4661             local ($varname) = $1;
4662             local ($from, $to);
4663             local (@temp_list);
4664             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
4665             {
4666                 $varname = $1;
4667                 $to = $3;
4668                 ($from = $2) =~ s/(\W)/\\$1/g;
4669             }
4671             # Find the value.
4672             @temp_list = &variable_value_as_list ($1, $cond, $var);
4674             # Now rewrite the value if appropriate.
4675             if ($from)
4676             {
4677                 grep (s/$from$/$to/, @temp_list);
4678             }
4680             push (@result, @temp_list);
4681         }
4682         else
4683         {
4684             push (@result, $_);
4685         }
4686     }
4688     return @result;
4691 # Return contents of variable as list, split as whitespace.  This will
4692 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
4693 # substitutions.  If COND is 'all', then all values under all
4694 # conditions should be returned; if COND is a particular condition
4695 # (all conditions are surrounded by @...@) then only the value for
4696 # that condition should be returned; otherwise, warn if VAR is
4697 # conditionally defined.  If PARENT is specified, it is the name of
4698 # the including variable; this is only used for error reports.
4699 sub variable_value_as_list
4701     local ($var, $cond, $parent) = @_;
4702     local (@result);
4704     if (defined $targets{$var})
4705     {
4706         &am_line_error ($var, "\`$var' is target; expected variable");
4707     }
4708     elsif (! defined $contents{$var})
4709     {
4710         &am_line_error ($parent, "variable \`$var' not defined");
4711     }
4712     elsif ($cond eq 'all' && $conditional{$var})
4713     {
4714         local (@condvals) = split (/ /, $conditional{$var});
4715         while (@condvals)
4716         {
4717             shift (@condvals);
4718             local ($val) = &unquote_cond_val (shift (@condvals));
4719             push (@result, &value_to_list ($var, $val, $cond));
4720         }
4721     }
4722     elsif ($cond && $conditional{$var})
4723     {
4724         local (@condvals) = split (/ /, $conditional{$var});
4725         local ($onceflag);
4726         while (@condvals)
4727         {
4728             local ($vcond) = shift (@condvals);
4729             local ($val) = &unquote_cond_val (shift (@condvals));
4730             if (&conditional_true_when ($vcond, $cond))
4731             {
4732                 # Warn if we have an ambiguity.  It's hard to know how
4733                 # to handle this case correctly.
4734                 &variable_conditionally_defined ($var, $parent)
4735                     if $onceflag;
4736                 $onceflag = 1;
4737                 push (@result, &value_to_list ($var, $val, $cond));
4738             }
4739         }
4740     }
4741     else
4742     {
4743         &variable_conditionally_defined ($var, $parent);
4744         $content_seen{$var} = 1;
4745         push (@result, &value_to_list ($var, $contents{$var}, $cond));
4746     }
4748     return @result;
4751 # Define a new variable, but only if not already defined.
4752 sub define_variable
4754     local ($var, $value) = @_;
4756     if (! defined $contents{$var})
4757     {
4758         $output_vars .= $var . ' = ' . $value . "\n";
4759         $contents{$var} = $value;
4760         $content_seen{$var} = 1;
4761     }
4764 # Like define_variable, but the value is a list, and the variable may
4765 # be defined conditionally.  The second argument is the conditional
4766 # under which the value should be defined; this should be the empty
4767 # string to define the variable unconditionally.  The third argument
4768 # is a list holding the values to use for the variable.  The value is
4769 # pretty printed in the output file.
4770 sub define_pretty_variable
4772     local ($var, $cond, @value) = @_;
4773     if (! defined $contents{$var}
4774         || ($cond && ! &variable_defined ($var, $cond)))
4775     {
4776         $contents{$var} = join (' ', @value);
4777         if ($cond)
4778         {
4779             if ($conditional{$var})
4780             {
4781                 $conditional{$var} .= ' ';
4782             }
4783             else
4784             {
4785                 $conditional{$var} = '';
4786             }
4787             $conditional{$var} .= ($cond
4788                                    . ' '
4789                                    . &quote_cond_val ($contents{$var}));
4790         }
4791         &pretty_print ($cond . $var . ' = ', $cond, @value);
4792         $content_seen{$var} = 1;
4793     }
4796 # Like define_variable, but define a variable to be the configure
4797 # substitution by the same name.
4798 sub define_configure_variable
4800     local ($var) = @_;
4801     local ($value) = '@' . $var . '@';
4802     &define_variable ($var, $value);
4805 # Define a variable that represents a program to run.  If in Cygnus
4806 # mode, the program is searched for in the build (or source) tree.
4807 # Otherwise no searching is done at all.  Arguments are:
4808 # * VAR      Name of variable to define
4809 # * WHATDIR  Either `src' or `build', depending on where program should
4810 #            be found.  (runtest is in srcdir!)
4811 # * SUBDIR   Subdir of top-level dir
4812 # * PROGRAM  Name of program
4813 # * OVERRIDE If specified, the name of the program to use when not in
4814 #            Cygnus mode.  Defaults to PROGRAM.
4815 sub define_program_variable
4817     local ($var, $whatdir, $subdir, $program, $override) = @_;
4819     if (! $override)
4820     {
4821         $override = $program;
4822     }
4824     if ($cygnus_mode)
4825     {
4826         local ($full) = ('$(top_' . $whatdir . 'dir)/../'
4827                          . $subdir . '/' . $program);
4828         &define_variable ($var, ('`if test -f ' . $full
4829                                  . '; then echo ' . $full . '; else echo '
4830                                  . $program . '; fi`'));
4831     }
4832     else
4833     {
4834         &define_variable ($var, $override);
4835     }
4839 ################################################################
4841 # Read Makefile.am and set up %contents.  Simultaneously copy lines
4842 # from Makefile.am into $output_trailer or $output_vars as
4843 # appropriate.  NOTE we put rules in the trailer section.  We want
4844 # user rules to come after our generated stuff.
4845 sub read_am_file
4847     local ($amfile) = @_;
4849     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
4850     print "automake: reading $amfile\n" if $verbose;
4852     $output_vars = ("# $in_file_name generated automatically by automake "
4853                     . $VERSION . " from $am_file_name\n");
4855     # Generate copyright for generated Makefile.in.
4856     $output_vars .= $gen_copyright;
4858     local ($saw_bk) = 0;
4859     local ($was_rule) = 0;
4860     local ($spacing) = '';
4861     local ($comment) = '';
4862     local ($last_var_name) = '';
4863     local ($blank) = 0;
4865     while (<AM_FILE>)
4866     {
4867         if (/$IGNORE_PATTERN/o)
4868         {
4869             # Merely delete comments beginning with two hashes.
4870         }
4871         elsif (/$WHITE_PATTERN/o)
4872         {
4873             # Stick a single white line before the incoming macro or rule.
4874             $spacing = "\n";
4875             $blank = 1;
4876         }
4877         elsif (/$COMMENT_PATTERN/o)
4878         {
4879             # Stick comments before the incoming macro or rule.  Make
4880             # sure a blank line preceeds first block of comments.
4881             $spacing = "\n" unless $blank;
4882             $blank = 1;
4883             $comment .= $spacing . $_;
4884             $spacing = '';
4885         }
4886         else
4887         {
4888             last;
4889         }
4890     }
4892     $output_vars .= $comment . "\n";
4893     $comment = '';
4894     $spacing = "\n";
4895     local ($am_vars) = '';
4897     local ($is_ok_macro);
4898     while ($_)
4899     {
4900         $_ .= "\n"
4901             unless substr ($_, -1, 1) eq "\n";
4903         $_ =~ s/\@MAINT\@//g
4904             unless $seen_maint_mode;
4906         if (/$IGNORE_PATTERN/o)
4907         {
4908             # Merely delete comments beginning with two hashes.
4909         }
4910         elsif (/$WHITE_PATTERN/o)
4911         {
4912             # Stick a single white line before the incoming macro or rule.
4913             $spacing = "\n";
4914         }
4915         elsif (/$COMMENT_PATTERN/o)
4916         {
4917             # Stick comments before the incoming macro or rule.
4918             $comment .= $spacing . $_;
4919             $spacing = '';
4920         }
4921         elsif ($saw_bk)
4922         {
4923             if ($was_rule)
4924             {
4925                 $output_trailer .= join ('', @conditional_stack) . $_;
4926                 $saw_bk = /\\$/;
4927             }
4928             else
4929             {
4930                 $am_vars .= join ('', @conditional_stack) . $_;
4931                 $saw_bk = /\\$/;
4932                 # Chop newline and backslash if this line is
4933                 # continued.  FIXME: maybe ensure trailing whitespace
4934                 # exists?
4935                 chop if $saw_bk;
4936                 chop if $saw_bk;
4937                 $contents{$last_var_name} .= $_;
4938                 if (@conditional_stack)
4939                 {
4940                     $conditional{$last_var_name} .= &quote_cond_val ($_);
4941                 }
4942             }
4943         }
4944         elsif (/$IF_PATTERN/o)
4945         {
4946             &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
4947                 if (! $configure_cond{$1});
4948             push (@conditional_stack, "\@" . $1 . "_TRUE\@");
4949         }
4950         elsif (/$ELSE_PATTERN/o)
4951         {
4952             if (! @conditional_stack)
4953             {
4954                 &am_line_error ($., "else without if");
4955             }
4956             elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
4957             {
4958                 &am_line_error ($., "else after else");
4959             }
4960             else
4961             {
4962                 $conditional_stack[$#conditional_stack]
4963                     =~ s/_TRUE\@$/_FALSE\@/;
4964             }
4965         }
4966         elsif (/$ENDIF_PATTERN/o)
4967         {
4968             if (! @conditional_stack)
4969             {
4970                 &am_line_error ($., "endif without if");
4971             }
4972             else
4973             {
4974                 pop @conditional_stack;
4975             }
4976         }
4977         elsif (/$RULE_PATTERN/o)
4978         {
4979             # Found a rule.
4980             $was_rule = 1;
4981             if (defined $contents{$1}
4982                 && (@conditional_stack
4983                     ? ! defined $conditional{$1}
4984                     : defined $conditional{$1}))
4985             {
4986                 &am_line_error ($1,
4987                                 "$1 defined both conditionally and unconditionally");
4988             }
4989             # Value here doesn't matter; for targets we only note
4990             # existence.
4991             $contents{$1} = 1;
4992             $targets{$1} = 1;
4993             local ($cond_string) = join ('', @conditional_stack);
4994             if (@conditional_stack)
4995             {
4996                 if ($conditional{$1})
4997                 {
4998                     &check_ambiguous_conditional ($1, $cond_string);
4999                     $conditional{$1} .= ' ';
5000                 }
5001                 else
5002                 {
5003                     $conditional{$1} = '';
5004                 }
5005                 $conditional{$1} .= $cond_string . ' 1';
5006             }
5007             $content_lines{$1} = $.;
5008             $output_trailer .= $comment . $spacing . $cond_string . $_;
5009             $comment = $spacing = '';
5010             $saw_bk = /\\$/;
5011         }
5012         elsif (($is_ok_macro = /$MACRO_PATTERN/o)
5013                || /$BOGUS_MACRO_PATTERN/o)
5014         {
5015             # Found a macro definition.
5016             $was_rule = 0;
5017             $last_var_name = $1;
5018             if (defined $contents{$1}
5019                 && (@conditional_stack
5020                     ? ! defined $conditional{$1}
5021                     : defined $conditional{$1}))
5022             {
5023                 &am_line_error ($1,
5024                                 "$1 defined both conditionally and unconditionally");
5025             }
5026             if ($2 ne '' && substr ($2, -1) eq "\\")
5027             {
5028                 $contents{$last_var_name} = substr ($2, 0, length ($2) - 1);
5029             }
5030             else
5031             {
5032                 $contents{$last_var_name} = $2;
5033             }
5034             local ($cond_string) = join ('', @conditional_stack);
5035             if (@conditional_stack)
5036             {
5037                 if ($conditional{$last_var_name})
5038                 {
5039                     &check_ambiguous_conditional ($last_var_name,
5040                                                   $cond_string);
5041                     $conditional{$last_var_name} .= ' ';
5042                 }
5043                 else
5044                 {
5045                     $conditional{$last_var_name} = '';
5046                 }
5047                 local ($val) = $contents{$last_var_name};
5048                 $conditional{$last_var_name} .= ($cond_string
5049                                                  . ' '
5050                                                  . &quote_cond_val ($val));
5051             }
5052             $content_lines{$last_var_name} = $.;
5053             $am_vars .= $comment . $spacing . $cond_string . $_;
5054             $comment = $spacing = '';
5055             $saw_bk = /\\$/;
5057             # Error if bogus.
5058             &am_line_error ($., "bad macro name \`$last_var_name'")
5059                 if ! $is_ok_macro;
5060         }
5061         else
5062         {
5063             # This isn't an error; it is probably a continued rule.
5064             # In fact, this is what we assume.
5065             $was_rule = 1;
5066             $output_trailer .= ($comment . $spacing
5067                                 . join ('', @conditional_stack) . $_);
5068             $comment = $spacing = '';
5069             $saw_bk = /\\$/;
5070         }
5072         $_ = <AM_FILE>;
5073     }
5075     $output_trailer .= $comment;
5077     &am_error ("unterminated conditionals: " . join (' ', @conditional_stack))
5078         if (@conditional_stack);
5080     # Compute relative location of the top object directory.
5081     local (@topdir) = ();
5082     foreach (split (/\//, $relative_dir))
5083     {
5084         next if $_ eq '.' || $_ eq '';
5085         if ($_ eq '..')
5086         {
5087             pop @topdir;
5088         }
5089         else
5090         {
5091             push (@topdir, '..');
5092         }
5093     }
5094     @topdir = ('.') if ! @topdir;
5096     $top_builddir = join ('/', @topdir);
5097     local ($build_rx);
5098     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
5099     $output_vars .= &file_contents_with_transform
5100                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
5101                          'header-vars');
5103     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
5104     # this should use generic %configure_vars method.
5105     if ($seen_canonical)
5106     {
5107         local ($curs, %vars);
5108         $vars{'host_alias'} = 'host_alias';
5109         $vars{'host_triplet'} = 'host';
5110         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
5111         {
5112             $vars{'build_alias'} = 'build_alias';
5113             $vars{'build_triplet'} = 'build';
5114             $vars{'target_alias'} = 'target_alias';
5115             $vars{'target_triplet'} = 'target';
5116         }
5117         foreach $curs (sort keys %vars)
5118         {
5119             $output_vars .= "$curs = \@$vars{$curs}\@\n";
5120             $contents{$curs} = "\@$vars{$curs}\@";
5121         }
5122     }
5124     local ($curs);
5125     foreach $curs (sort keys %configure_vars)
5126     {
5127         &define_configure_variable ($curs);
5128     }
5130     $output_vars .= $am_vars;
5133 ################################################################
5135 sub initialize_global_constants
5137     # Values for AC_CANONICAL_*
5138     $AC_CANONICAL_HOST = 1;
5139     $AC_CANONICAL_SYSTEM = 2;
5141     # Associative array of standard directory names.  Entry is TRUE if
5142     # corresponding directory should be installed during
5143     # 'install-exec' phase.
5144     %exec_dir_p =
5145         ('bin', 1,
5146          'sbin', 1,
5147          'libexec', 1,
5148          'data', 0,
5149          'sysconf', 1,
5150          'localstate', 1,
5151          'lib', 1,
5152          'info', 0,
5153          'man', 0,
5154          'include', 0,
5155          'oldinclude', 0,
5156          'pkgdata', 0,
5157          'pkglib', 1,
5158          'pkginclude', 0
5159          );
5161     # Helper text for dealing with man pages.
5162     $install_man_format =
5163     '   @sect=@SECTION@;                                \\
5164         inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
5165         if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
5166         else file=@MAN@; fi; \\
5167         echo " $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst"; \\
5168         $(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst
5171     $uninstall_man_format =
5172     '   inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
5173         rm -f $(mandir)/man@SECTION@/$$inst
5176     # Commonly found files we look for and automatically include in
5177     # DISTFILES.
5178     @common_files =
5179         (
5180          "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
5181          "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
5182          "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
5183          "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
5184          'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
5185          'ylwrap', 'acinclude.m4', @libtoolize_files,
5186          'missing'
5187          );
5189     # Commonly used files we auto-include, but only sometimes.
5190     @common_sometimes =
5191         (
5192          "aclocal.m4", "acconfig.h", "config.h.top",
5193          "config.h.bot", "stamp-h.in", 'stamp-vti'
5194          );
5196     $USAGE = "\
5197   -a, --add-missing     add missing standard files to package
5198   --amdir=DIR           directory storing config files
5199   --build-dir=DIR       directory where build being done (for dependencies)
5200   --cygnus              assume program is part of Cygnus-style tree
5201   --foreign             set strictness to foreign
5202   --gnits               set strictness to gnits
5203   --gnu                 set strictness to gnu
5204   --help                print this help, then exit
5205   -i, --include-deps    include generated dependencies in Makefile.in
5206   --no-force            only update Makefile.in's that are out of date
5207   -o DIR, --output-dir=DIR
5208                         put generated Makefile.in's into DIR
5209   --srcdir-name=DIR     name used for srcdir (for dependencies)
5210   -v, --verbose         verbosely list files processed
5211   --version             print version number, then exit\n";
5213     # Copyright on generated Makefile.ins.
5214     $gen_copyright = "\
5215 # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
5216 # This Makefile.in is free software; the Free Software Foundation
5217 # gives unlimited permission to copy, distribute and modify it.
5220     # Ignore return result from chmod, because it might give an error
5221     # if we chmod a symlink.
5222     $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
5223     $dist{'tarZ'} = ("\t"
5224                      . '$(TAR) chf - $(distdir) | compress -c > $(distdir).tar.Z'
5225                      . "\n");
5226     $dist{'shar'} = ("\t"
5227                      . 'shar $(distdir) | gzip > $(distdir).shar.gz'
5228                      . "\n");
5229     $dist{'zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
5230     $dist{'dist'} = "\t" .  'GZIP=$(GZIP) $(TAR) chozf $(distdir).tar.gz $(distdir)' . "\n";
5231     $dist_trailer = "\t" . 'rm -rf $(distdir)' . "\n";
5234 # (Re)-Initialize per-Makefile.am variables.
5235 sub initialize_per_input
5237     # These two variables are used when generating each Makefile.in.
5238     # They hold the Makefile.in until it is ready to be printed.
5239     $output_rules = '';
5240     $output_vars = '';
5241     $output_trailer = '';
5242     $output_header = '';
5244     # Suffixes found during a run.
5245     @suffixes = ();
5247     # This holds the contents of a Makefile.am, as parsed by
5248     # read_am_file.
5249     %contents = ();
5251     # This holds the names which are targets.  These also appear in
5252     # %contents.
5253     %targets = ();
5255     # For a variable or target which is defined conditionally, this
5256     # holds an array of the conditional values.  The array is composed
5257     # of pairs of condition strings (the variables which configure
5258     # will substitute) and values (the value of a target is
5259     # meaningless).  For an unconditional variable, this is empty.
5260     %conditional = ();
5262     # This holds the line numbers at which various elements of
5263     # %contents are defined.
5264     %content_lines = ();
5266     # This holds a 1 if a particular variable was examined.
5267     %content_seen = ();
5269     # This is the conditional stack.
5270     @conditional_stack = ();
5272     # This holds the "relative directory" of the current Makefile.in.
5273     # Eg for src/Makefile.in, this is "src".
5274     $relative_dir = '';
5276     # This holds a list of files that are included in the
5277     # distribution.
5278     %dist_common = ();
5280     # List of dependencies for the obvious targets.
5281     @install_data = ();
5282     @install_exec = ();
5283     @uninstall = ();
5284     @installdirs = ();
5286     @info = ();
5287     @dvi = ();
5288     @all = ();
5289     @check = ();
5290     @check_tests = ();
5291     @installcheck = ();
5292     @clean = ();
5294     @phony = ();
5296     # These are pretty obvious, too.  They are used to define the
5297     # SOURCES and OBJECTS variables.
5298     @sources = ();
5299     @objects = ();
5301     # TRUE if current directory holds any C source files.
5302     $dir_holds_sources = 0;
5304     # These variables track inclusion of various compile-related .am
5305     # files.  $included_generic_compile is TRUE if the basic code has
5306     # been included.  $included_knr_compile is TRUE if the ansi2knr
5307     # code has been included.  $included_libtool_compile is TRUE if
5308     # libtool support has been included.
5309     $included_generic_compile = 0;
5310     $included_knr_compile = 0;
5311     $included_libtool_compile = 0;
5313     # TRUE if current directory holds any headers.
5314     $dir_holds_headers = 0;
5316     # TRUE if install targets should work recursively.
5317     $recursive_install = 0;
5319     # All .P files.
5320     %dep_files = ();
5322     # Strictness levels.
5323     $strictness = $default_strictness;
5324     $strictness_name = $default_strictness_name;
5326     # Options from AUTOMAKE_OPTIONS.
5327     %options = ();
5329     # Whether or not dependencies are handled.  Can be further changed
5330     # in handle_options.
5331     $use_dependencies = $cmdline_use_dependencies;
5333     # Per Makefile.am.
5334     $local_maint_charset = $maint_charset;
5336     # All yacc and lex source filenames for this directory.  Use
5337     # filenames instead of raw count so that multiple instances are
5338     # counted correctly (eg one yacc file can appear in multiple
5339     # programs without harm).
5340     %yacc_sources = ();
5341     %lex_sources = ();
5343     # C++ source extensions we've seen.
5344     %cxx_extensions = ();
5346     # TRUE if we've seen any non-C++ sources.  This actually holds a
5347     # line number or the name of a symbol corresponding to a line
5348     # number where the C sources were seen.  If it is -1 then it means
5349     # we couldn't (easily) figure out which line of the Makefile.am
5350     # mentioned the sources.
5351     $seen_c_source = 0;
5353     # This is a list of all targets to run during "make dist".
5354     @dist_targets = ();
5356     # Keys in this hash are the names of ._o files which must depend
5357     # on ansi2knr.  Ugh.
5358     %de_ansi_objects = ();
5362 ################################################################
5364 # Return contents of a file from $am_dir, automatically skipping
5365 # macros or rules which are already known.  Runs command on each line
5366 # as it is read; this command can modify $_.
5367 sub file_contents_with_transform
5369     local ($command, $basename) = @_;
5370     local ($file) = $am_dir . '/' . $basename . '.am';
5372     if ($command ne '' && substr ($command, -1) ne ';')
5373     {
5374         die "automake: programming error in file_contents_with_transform\n";
5375     }
5377     open (FC_FILE, $file)
5378         || die "automake: installation error: cannot open \`$file'\n";
5379     # Looks stupid?
5380     # print "automake: reading $file\n" if $verbose;
5382     local ($was_rule) = 0;
5383     local ($result_vars) = '';
5384     local ($result_rules) = '';
5385     local ($comment) = '';
5386     local ($spacing) = "\n";
5387     local ($skipping) = 0;
5388     local ($had_chars);
5390     while (<FC_FILE>)
5391     {
5392         $_ =~ s/\@MAINT\@//g
5393             unless $seen_maint_mode;
5395         $had_chars = length ($_) && $_ ne "\n";
5396         eval $command;
5397         # If the transform caused all the characters to go away, then
5398         # ignore the line.  Why do this?  Because in Perl 4, a "next"
5399         # inside of an eval doesn't affect a loop outside the eval.
5400         # So we can't pass in a "transform" that uses next.  We used
5401         # to do this.  "Empty" also means consisting of a single
5402         # newline.
5403         next if $had_chars && ($_ eq '' || $_ eq "\n");
5405         if (/$IGNORE_PATTERN/o)
5406         {
5407             # Merely delete comments beginning with two hashes.
5408         }
5409         elsif (/$WHITE_PATTERN/o)
5410         {
5411             # Stick a single white line before the incoming macro or rule.
5412             $spacing = "\n";
5413         }
5414         elsif (/$COMMENT_PATTERN/o)
5415         {
5416             # Stick comments before the incoming macro or rule.
5417             $comment .= $spacing . $_;
5418             $spacing = '';
5419         }
5420         elsif ($saw_bk)
5421         {
5422             if ($was_rule)
5423             {
5424                 $result_rules .= $_ if ! $skipping;
5425             }
5426             else
5427             {
5428                 $result_vars .= $_ if ! $skipping;
5429             }
5430             $saw_bk = /\\$/;
5431         }
5432         elsif (/$RULE_PATTERN/o)
5433         {
5434             # Found a rule.
5435             $was_rule = 1;
5436             $skipping = defined $contents{$1};
5437             $result_rules .= $comment . $spacing . $_ if ! $skipping;
5438             $comment = $spacing = '';
5439             $saw_bk = /\\$/;
5440         }
5441         elsif (/$MACRO_PATTERN/o)
5442         {
5443             # Found a variable reference.
5444             $was_rule = 0;
5445             $skipping = defined $contents{$1};
5446             $result_vars .= $comment . $spacing . $_ if ! $skipping;
5447             $comment = $spacing = '';
5448             $saw_bk = /\\$/;
5449         }
5450         else
5451         {
5452             # This isn't an error; it is probably a continued rule.
5453             # In fact, this is what we assume.
5454             $was_rule = 1;
5455             $result_rules .= $comment . $spacing . $_ if ! $skipping;
5456             $comment = $spacing = '';
5457             $saw_bk = /\\$/;
5458         }
5459     }
5461     close (FC_FILE);
5462     return $result_vars . $result_rules . $comment;
5465 # Like file_contents_with_transform, but no transform.
5466 sub file_contents
5468     return &file_contents_with_transform ('', @_);
5471 # Find all variable prefixes that are used for install directories.  A
5472 # prefix `zar' qualifies iff:
5473 # * `zardir' is a variable.
5474 # * `zar_PRIMARY' is a variable.
5475 sub am_primary_prefixes
5477     local ($primary, @prefixes) = @_;
5479     local (%valid, $varname);
5480     grep ($valid{$_} = 0, @prefixes);
5481     $valid{'EXTRA'} = 0;
5482     foreach $varname (keys %contents)
5483     {
5484         if ($varname =~ /^(.*)_$primary$/)
5485         {
5486             if (! defined $valid{$1}
5487                 && ! &variable_defined ($1 . 'dir')
5488                 # Note that a configure variable is always legitimate.
5489                 # It is natural to name such variables after the
5490                 # primary, so we explicitly allow it.
5491                 && ! defined $configure_vars{$varname})
5492             {
5493                 &am_line_error ($varname, "invalid variable \"$varname\"");
5494             }
5495             else
5496             {
5497                 # Ensure all extended prefixes are actually used.
5498                 $valid{$1} = 1;
5499             }
5500         }
5501     }
5503     return %valid;
5506 # Handle `where_HOW' variable magic.  Does all lookups, generates
5507 # install code, and possibly generates code to define the primary
5508 # variable.  The first argument is the name of the .am file to munge,
5509 # the second argument is the primary variable (eg HEADERS), and all
5510 # subsequent arguments are possible installation locations.  Returns
5511 # list of all values of all _HOW targets.
5513 # FIXME: this should be rewritten to be cleaner.  It should be broken
5514 # up into multiple functions.
5516 # Usage is: am_install_var (OPTION..., file, HOW, where...)
5517 sub am_install_var
5519     local (@args) = @_;
5521     local ($do_clean) = 0;
5523     local ($ltxform);
5524     if (defined $configure_vars{'LIBTOOL'})
5525     {
5526         # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
5527         $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
5528     }
5529     else
5530     {
5531         # Delete '@LIBTOOL ...@'
5532         $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
5533     }
5535     local ($cygxform);
5536     if (! $seen_cygwin32)
5537     {
5538         $cygxform = 's/\@EXEEXT\@//g; s/^NOTCYGWIN//; s/^CYGWIN.*$//;';
5539     }
5540     else
5541     {
5542         $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g; s/^CYGWIN//; s/^NOTCYGWIN.*$//;';
5543     }
5545     while (@args)
5546     {
5547         if ($args[0] eq '-clean')
5548         {
5549             $do_clean = 1;
5550         }
5551         elsif ($args[0] !~ /^-/)
5552         {
5553             last;
5554         }
5555         shift (@args);
5556     }
5557     local ($file, $primary, @prefixes) = @args;
5559     local (@used) = ();
5560     local (@result) = ();
5562     # Now that configure substitutions are allowed in where_HOW
5563     # variables, it is an error to actually define the primary.
5564     &am_line_error ($primary, "\`$primary' is an anachronism")
5565         if &variable_defined ($primary);
5568     # Look for misspellings.  It is an error to have a variable ending
5569     # in a "reserved" suffix whose prefix is unknown, eg
5570     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
5571     # variable of the same name (with "dir" appended) exists.  For
5572     # instance, if the variable "zardir" is defined, then
5573     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
5574     # flexibility in those cases which need it.  Perhaps it should be
5575     # disallowed in the Gnits case?  The problem is, sometimes it is
5576     # useful to put things in a subdir of eg pkgdatadir, perhaps even
5577     # for Gnitsoids.
5578     local (%valid) = &am_primary_prefixes ($primary, @prefixes);
5580     # If a primary includes a configure substitution, then the EXTRA_
5581     # form is required.  Otherwise we can't properly do our job.
5582     local ($require_extra);
5583     local ($warned_about_extra) = 0;
5585     local ($clean_file) = $file . '-clean';
5586     local ($one_name);
5587     local ($X);
5588     foreach $X (sort keys %valid)
5589     {
5590         $one_name = $X . '_' . $primary;
5591         if (&variable_defined ($one_name))
5592         {
5593             # Append actual contents of where_PRIMARY variable to
5594             # result.
5595             local ($rcurs);
5596             foreach $rcurs (&variable_value_as_list ($one_name, 'all'))
5597             {
5598                 # Skip configure substitutions.  Possibly bogus.
5599                 if ($rcurs =~ /^\@.*\@$/)
5600                 {
5601                     if ($X eq 'EXTRA')
5602                     {
5603                         if (! $warned_about_extra)
5604                         {
5605                             $warned_about_extra = 1;
5606                             &am_line_error ($one_name,
5607                                             "\`$one_name' contains configure substitution, but shouldn't");
5608                         }
5609                     }
5610                     # Check here to make sure variables defined in
5611                     # configure.in do not imply that EXTRA_PRIMARY
5612                     # must be defined.
5613                     elsif (! defined $configure_vars{$one_name})
5614                     {
5615                         $require_extra = $one_name;
5616                     }
5617                     next;
5618                 }
5619                 push (@result, $rcurs);
5620             }
5622             # "EXTRA" shouldn't be used when generating clean targets,
5623             # @all, or install targets.
5624             next if $X eq 'EXTRA';
5626             if ($do_clean)
5627             {
5628                 $output_rules .=
5629                     &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
5630                                                    . $cygxform,
5631                                                    $clean_file);
5633                 push (@clean, $X . $primary);
5634                 &push_phony_cleaners ($X . $primary);
5635             }
5637             if ($X eq 'check')
5638             {
5639                 push (@check, '$(' . $one_name . ')');
5640             }
5641             else
5642             {
5643                 push (@used, '$(' . $one_name . ')');
5644             }
5645             if ($X eq 'noinst' || $X eq 'check')
5646             {
5647                 # Objects which don't get installed by default.
5648                 next;
5649             }
5651             $output_rules .=
5652                 &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
5653                                                . $ltxform . $cygxform,
5654                                                $file);
5656             push (@uninstall, 'uninstall-' . $X . $primary);
5657             push (@phony, 'uninstall-' . $X . $primary);
5658             push (@installdirs, '$(' . $X . 'dir)');
5659             if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
5660             {
5661                 push (@install_exec, 'install-' . $X . $primary);
5662                 push (@phony, 'install-' . $X . $primary);
5663             }
5664             else
5665             {
5666                 push (@install_data, 'install-' . $X . $primary);
5667                 push (@phony, 'install-' . $X . $primary);
5668             }
5669         }
5670     }
5672     if (@used)
5673     {
5674         # Define it.
5675         &define_pretty_variable ($primary, '', @used);
5676         $output_vars .= "\n";
5677     }
5679     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
5680     {
5681         &am_line_error ($require_extra,
5682                         "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
5683     }
5685     # Push here because PRIMARY might be configure time determined.
5686     push (@all, '$(' . $primary . ')')
5687         if @used;
5689     return (@result);
5693 ################################################################
5695 # This variable is local to the "require file" set of functions.
5696 @require_file_paths = ();
5698 # Verify that the file must exist in the current directory.  Usage:
5699 # require_file (isconfigure, line_number, strictness, file) strictness
5700 # is the strictness level at which this file becomes required.  Must
5701 # set require_file_paths before calling this function.
5702 # require_file_paths is set to hold a single directory (the one in
5703 # which the first file was found) before return.
5704 sub require_file_internal
5706     local ($is_configure, $line, $mystrict, @files) = @_;
5707     local ($file, $fullfile);
5708     local ($found_it, $errfile, $errdir);
5709     local ($save_dir);
5711     foreach $file (@files)
5712     {
5713         $found_it = 0;
5714         foreach $dir (@require_file_paths)
5715         {
5716             if ($dir eq '.')
5717             {
5718                 $fullfile = $relative_dir . "/" . $file;
5719                 $errdir = $relative_dir unless $errdir;
5720             }
5721             else
5722             {
5723                 $fullfile = $dir . "/" . $file;
5724                 $errdir = $dir unless $errdir;
5725             }
5727             # Use different name for "error filename".  Otherwise on
5728             # an error the bad file will be reported as eg
5729             # `../../install-sh' when using the default
5730             # config_aux_path.
5731             $errfile = $errdir . '/' . $file;
5733             if (-f $fullfile)
5734             {
5735                 $found_it = 1;
5736                 # FIXME: Once again, special-case `.'.
5737                 &push_dist_common ($file)
5738                     if $dir eq $relative_dir || $dir eq '.';
5739                 $save_dir = $dir;
5740                 last;
5741             }
5742         }
5744         if ($found_it)
5745         {
5746             # Prune the path list.
5747             @require_file_paths = $save_dir;
5748         }
5749         else
5750         {
5751             if ($strictness >= $mystrict)
5752             {
5753                 local ($trailer) = '';
5754                 local ($suppress) = 0;
5756                 # Only install missing files according to our desired
5757                 # strictness level.
5758                 if ($add_missing)
5759                 {
5760                     $trailer = "; installing";
5761                     $suppress = 1;
5763                     # Maybe run libtoolize.
5764                     if ($seen_libtool
5765                         && grep ($_ eq $file, @libtoolize_files)
5766                         && system ('libtoolize', '--automake'))
5767                     {
5768                         $suppress = 0;
5769                         $trailer .= "; cannot run \`libtoolize': $!";
5770                     }
5771                     elsif (-f ($am_dir . '/' . $file))
5772                     {
5773                         # Install the missing file.  Symlink if we
5774                         # can, copy if we must.  Note: delete the file
5775                         # first, in case it is a dangling symlink.
5776                         unlink ($errfile);
5777                         if ($symlink_exists)
5778                         {
5779                             if (! symlink ($am_dir . '/' . $file, $errfile))
5780                             {
5781                                 $suppress = 0;
5782                                 $trailer .= "; error while making link: $!\n";
5783                             }
5784                         }
5785                         elsif (! system ('cp', $am_dir . '/' . $file, $errfile))
5786                         {
5787                             $suppress = 0;
5788                             $trailer .= "\n    error while making link\n";
5789                         }
5790                     }
5791                 }
5793                 local ($save) = $exit_status;
5794                 if ($is_configure)
5795                 {
5796                     # FIXME: allow actual file to be specified.
5797                     &am_conf_line_error
5798                         ('configure.in', $line,
5799                          "required file \"$errfile\" not found$trailer");
5800                 }
5801                 else
5802                 {
5803                     &am_line_error
5804                         ($line,
5805                          "required file \"$errfile\" not found$trailer");
5806                 }
5807                 $exit_status = $save if $suppress;
5808             }
5809         }
5810     }
5813 # Like require_file_with_line, but error messages refer to
5814 # configure.in, not the current Makefile.am.
5815 sub require_file_with_conf_line
5817     @require_file_paths = '.';
5818     &require_file_internal (1, @_);
5821 sub require_file_with_line
5823     @require_file_paths = '.';
5824     &require_file_internal (0, @_);
5827 sub require_file
5829     @require_file_paths = '.';
5830     &require_file_internal (0, '', @_);
5833 # Require a file that is also required by Autoconf.  Looks in
5834 # configuration path, as specified by AC_CONFIG_AUX_DIR.
5835 sub require_config_file
5837     @require_file_paths = @config_aux_path;
5838     &require_file_internal (1, '', @_);
5839     local ($dir) = $require_file_paths[0];
5840     @config_aux_path = @require_file_paths;
5841     if ($dir eq '.')
5842     {
5843         $config_aux_dir = '.';
5844     }
5845     else
5846     {
5847         $config_aux_dir = '$(top_srcdir)/' . $dir;
5848     }
5851 # Assumes that the line number is in Makefile.am.
5852 sub require_conf_file_with_line
5854     @require_file_paths = @config_aux_path;
5855     &require_file_internal (0, @_);
5856     local ($dir) = $require_file_paths[0];
5857     @config_aux_path = @require_file_paths;
5858     if ($dir eq '.')
5859     {
5860         $config_aux_dir = '.';
5861     }
5862     else
5863     {
5864         $config_aux_dir = '$(top_srcdir)/' . $dir;
5865     }
5868 # Assumes that the line number is in Makefile.am.
5869 sub require_conf_file_with_conf_line
5871     @require_file_paths = @config_aux_path;
5872     &require_file_internal (1, @_);
5873     local ($dir) = $require_file_paths[0];
5874     @config_aux_path = @require_file_paths;
5875     if ($dir eq '.')
5876     {
5877         $config_aux_dir = '.';
5878     }
5879     else
5880     {
5881         $config_aux_dir = '$(top_srcdir)/' . $dir;
5882     }
5885 ################################################################
5887 # Push a list of files onto dist_common.
5888 sub push_dist_common
5890     local (@files) = @_;
5891     local ($file);
5893     foreach $file (@files)
5894     {
5895         $dist_common{$file} = 1;
5896     }
5899 # Push a list of clean targets onto phony.
5900 sub push_phony_cleaners
5902     local ($base) = @_;
5903     local ($target);
5904     foreach $target ('mostly', 'dist', '', 'maintainer-')
5905     {
5906         push (@phony, $target . 'clean-' . $base);
5907     }
5910 # Set strictness.
5911 sub set_strictness
5913     $strictness_name = $_[0];
5914     if ($strictness_name eq 'gnu')
5915     {
5916         $strictness = $GNU;
5917     }
5918     elsif ($strictness_name eq 'gnits')
5919     {
5920         $strictness = $GNITS;
5921     }
5922     elsif ($strictness_name eq 'foreign')
5923     {
5924         $strictness = $FOREIGN;
5925     }
5926     else
5927     {
5928         die "automake: level \`$strictness_name' not recognized\n";
5929     }
5933 ################################################################
5935 # Return directory name of file.
5936 sub dirname
5938     local ($file) = @_;
5939     local ($sub);
5941     ($sub = $file) =~ s,/+[^/]+$,,g;
5942     $sub = '.' if $sub eq $file;
5943     return $sub;
5946 # Return file name of a file.
5947 sub basename
5949     local ($file) = @_;
5950     local ($sub);
5952     ($sub = $file) =~s,^.*/+,,g;
5953     return $sub;
5956 # Touch a file.
5957 sub touch
5959     local ($file) = @_;
5961     open (TOUCH, ">> $file");
5962     close (TOUCH);
5965 # Glob something.  Do this to avoid indentation screwups everywhere we
5966 # want to glob.  Gross!
5967 sub my_glob
5969     local ($pat) = @_;
5970     return <${pat}>;
5973 ################################################################
5975 # Print an error message and set exit status.
5976 sub am_error
5978     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
5979     $exit_status = 1;
5982 sub am_line_error
5984     local ($symbol, @args) = @_;
5986     if ($symbol && "$symbol" ne '-1')
5987     {
5988         # If SYMBOL not already a line number, look it up in Makefile.am.
5989         if ($symbol =~ /^\d+$/)
5990         {
5991             $symbol .= ': ';
5992         }
5993         elsif (defined $content_lines{$symbol})
5994         {
5995             $symbol = $content_lines{$symbol} . ': ';
5996         }
5997         else
5998         {
5999             # A single space, to provide nice separation.
6000             $symbol = ' ';
6001         }
6002         warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
6003         $exit_status = 1;
6004     }
6005     else
6006     {
6007         &am_error (@args);
6008     }
6011 # Like am_error, but while scanning configure.in.
6012 sub am_conf_error
6014     # FIXME: can run in subdirs.
6015     warn "automake: configure.in: ", join (' ', @_), "\n";
6016     $exit_status = 1;
6019 # Error message with line number referring to configure.in.
6020 sub am_conf_line_error
6022     local ($file, $line, @args) = @_;
6024     if ($line)
6025     {
6026         warn "$file: $line: ", join (' ', @args), "\n";
6027         $exit_status = 1;
6028     }
6029     else
6030     {
6031         &am_conf_error (@args);
6032     }
6035 # Tell user where our aclocal.m4 is, but only once.
6036 sub keyed_aclocal_warning
6038     local ($key) = @_;
6039     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
6042 # Print usage information.
6043 sub usage
6045     print "Usage: automake [OPTION] ... [Makefile]...\n";
6046     print $USAGE;
6047     print "\nFiles which are automatically distributed, if found:\n";
6048     $~ = "USAGE_FORMAT";
6049     local (@lcomm) = sort ((@common_files, @common_sometimes));
6050     local ($one, $two, $three, $four);
6051     while (@lcomm > 0)
6052     {
6053         $one = shift @lcomm;
6054         $two = @lcomm ? shift @lcomm : '';
6055         $three = @lcomm ? shift @lcomm : '';
6056         $four = @lcomm ? shift @lcomm : '';
6057         write;
6058     }
6060     print "\nReport bugs to <automake-bugs\@gnu.ai.mit.edu>\n";
6062     exit 0;
6065 format USAGE_FORMAT =
6066   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
6067   $one,               $two,               $three,             $four