Fix for nolink.test:
[automake.git] / automake.in
blob6bcae0361f5d6d693f04e76fd2c2165a50f40b4f
1 #!@PERL@ -w
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 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
10 # Free Software Foundation, Inc.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2, or (at your option)
15 # any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 # 02111-1307, USA.
27 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
28 # Perl reimplementation by Tom Tromey <tromey@cygnus.com>.
30 package Language;
32 BEGIN
34   my $prefix = "@prefix@";
35   my $perllibdir = $ENV{'perllibdir'} || "@datadir@/@PACKAGE@";
36   unshift @INC, "$perllibdir";
39 use Automake::Struct;
40 struct (# Short name of the language (c, f77...).
41         'name' => "\$",
42         # Nice name of the language (C, Fortran 77...).
43         'Name' => "\$",
45         # List of configure variables which must be defined.
46         'config_vars' => '@',
48         'ansi'    => "\$",
49         # `pure' is `1' or `'.  A `pure' language is one where, if
50         # all the files in a directory are of that language, then we
51         # do not require the C compiler or any code to call it.
52         'pure'   => "\$",
54         'autodep' => "\$",
56         # Name of the compiling variable (COMPILE).
57         'compiler'  => "\$",
58         # Content of the compiling variable.
59         'compile'  => "\$",
60         # Flag to require compilation without linking (-c).
61         'compile_flag' => "\$",
62         'extensions'      => '@',
63         'flags' => "\$",
64         # Should the flag be defined as a configure variable.
65         # Defaults to true.  FIXME: this should go away once
66         # we move to autoconf tracing.
67         'define_flag' => "\$",
69         # The file to use when generating rules for this language.
70         # The default is 'depend2'.
71         'rule_file' => "\$",
73         # Name of the linking variable (LINK).
74         'linker' => "\$",
75         # Content of the linking variable.
76         'link' => "\$",
78         # Name of the linker variable (LD).
79         'lder' => "\$",
80         # Content of the linker variable ($(CC)).
81         'ld' => "\$",
83         # Flag to specify the output file (-o).
84         'output_flag' => "\$",
85         '_finish' => "\$",
87         # This is a subroutine which is called whenever we finally
88         # determine the context in which a source file will be
89         # compiled.
90         '_target_hook' => "\$");
93 sub finish ($)
95   my ($self) = @_;
96   if (defined $self->_finish)
97     {
98       &{$self->_finish} ();
99     }
102 sub target_hook ($$$$)
104     my ($self) = @_;
105     if (defined $self->_target_hook)
106     {
107         &{$self->_target_hook} (@_);
108     }
111 package Automake;
113 require 5.005;
114 use strict 'vars', 'subs';
115 use File::Basename;
116 use IO::File;
118 my $me = basename ($0);
121 ## ----------- ##
122 ## Constants.  ##
123 ## ----------- ##
125 # Parameters set by configure.  Not to be changed.  NOTE: assign
126 # VERSION as string so that eg version 0.30 will print correctly.
127 my $VERSION = "@VERSION@";
128 my $PACKAGE = "@PACKAGE@";
129 my $prefix = "@prefix@";
130 my $libdir = "@datadir@/@PACKAGE@";
132 # String constants.
133 my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
134 my $WHITE_PATTERN = '^\s*$';
135 my $COMMENT_PATTERN = '^#';
136 my $TARGET_PATTERN='[$a-zA-Z_.][-.a-zA-Z0-9_(){}/$]*';
137 # A rule has three parts: a list of targets, a list of dependencies,
138 # and optionally actions.
139 my $RULE_PATTERN =
140   "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
142 my $SUFFIX_RULE_PATTERN = '^\.([a-zA-Z0-9]+)\.([a-zA-Z0-9]+)$';
143 # Only recognize leading spaces, not leading tabs.  If we recognize
144 # leading tabs here then we need to make the reader smarter, because
145 # otherwise it will think rules like `foo=bar; \' are errors.
146 my $MACRO_PATTERN = '^[A-Za-z0-9_@]+$';
147 my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)$';
148 # This pattern recognizes a Gnits version id and sets $1 if the
149 # release is an alpha release.  We also allow a suffix which can be
150 # used to extend the version number with a "fork" identifier.
151 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
152 my $IF_PATTERN =          '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?$';
153 my $ELSE_PATTERN =   '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
154 my $ENDIF_PATTERN = '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
155 my $PATH_PATTERN='(\w|[/.-])+';
156 # This will pass through anything not of the prescribed form.
157 my $INCLUDE_PATTERN = ('^include\s+'
158                        . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
159                        . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
160                        . '|([^/\$]' . $PATH_PATTERN. '))\s*(#.*)?$');
162 # Some regular expressions.  One reason to put them here is that it
163 # makes indentation work better in Emacs.
164 my $AC_CONFIG_AUX_DIR_PATTERN = 'AC_CONFIG_AUX_DIR\(([^)]+)\)';
165 my $AM_INIT_AUTOMAKE_PATTERN = 'AM_INIT_AUTOMAKE\([^,]*,([^,)]+)[,)]';
166 my $AM_PACKAGE_VERSION_PATTERN = '^\s*\[?([^]\s]+)\]?\s*$';
167 # Note that there is no AC_PATH_TOOL.  But we don't really care.
168 my $AC_CHECK_PATTERN = 'AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\(\[?(\w+)';
169 my $AM_MISSING_PATTERN = 'AM_MISSING_PROG\(\[?(\w+)';
170 # Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
171 # then too bad.
172 my $AC_SUBST_PATTERN = 'AC_SUBST\(\[?(\w+)';
173 my $AM_CONDITIONAL_PATTERN = 'AM_CONDITIONAL\(\[?(\w+)';
174 # Match `-d' as a command-line argument in a string.
175 my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)";
177 # Constants to define the "strictness" level.
178 my $FOREIGN = 0;
179 my $GNU = 1;
180 my $GNITS = 2;
182 # Values for AC_CANONICAL_*
183 my $AC_CANONICAL_HOST = 1;
184 my $AC_CANONICAL_SYSTEM = 2;
186 # Values indicating when something should be cleaned.  Right now we
187 # only need to handle `mostly'- and `dist'-clean; add more as
188 # required.
189 my $MOSTLY_CLEAN = 0;
190 my $DIST_CLEAN = 1;
192 # Files installed by libtoolize.
193 my @libtoolize_files = ('ltmain.sh', 'config.guess', 'config.sub');
194 # ltconfig appears here for compatibility with old versions of libtool.
195 my @libtoolize_sometimes = ('ltconfig', 'ltcf-c.sh', 'ltcf-cxx.sh',
196                             'ltcf-gcj.sh');
198 # Commonly found files we look for and automatically include in
199 # DISTFILES.
200 my @common_files =
201   (
202    'README', 'THANKS', 'TODO', 'NEWS', 'COPYING', 'COPYING.LIB',
203    'INSTALL', 'ABOUT-NLS', 'ChangeLog', 'configure.ac',
204    'configure.in', 'configure', 'config.guess', 'config.sub',
205    'AUTHORS', 'BACKLOG', 'ABOUT-GNU', 'libversion.in',
206    'mdate-sh', 'mkinstalldirs', 'install-sh', 'texinfo.tex',
207    'ansi2knr.c', 'ansi2knr.1', 'elisp-comp',
208    # ltconfig appears here for compatibility with old versions
209    # of libtool.
210    'ylwrap', 'acinclude.m4', @libtoolize_files, @libtoolize_sometimes,
211    'missing', 'depcomp', 'compile', 'py-compile'
212   );
214 # Commonly used files we auto-include, but only sometimes.
215 my @common_sometimes =
216   (
217    'aclocal.m4', 'acconfig.h', 'config.h.top',
218    'config.h.bot', 'stamp-h.in', 'stamp-vti'
219   );
221 # Copyright on generated Makefile.ins.
222 my $gen_copyright = "\
223 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
224 # Free Software Foundation, Inc.
225 # This Makefile.in is free software; the Free Software Foundation
226 # gives unlimited permission to copy and/or distribute it,
227 # with or without modifications, as long as this notice is preserved.
229 # This program is distributed in the hope that it will be useful,
230 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
231 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
232 # PARTICULAR PURPOSE.
235 # These constants are returned by lang_*_rewrite functions.
236 # LANG_SUBDIR means that the resulting object file should be in a
237 # subdir if the source file is.  In this case the file name cannot
238 # have `..' components.
239 my $LANG_IGNORE = 0;
240 my $LANG_PROCESS = 1;
241 my $LANG_SUBDIR = 2;
243 # Directories installed during 'install-exec' phase.
244 my %exec_dir_p =
245   (
246    'bin'        => 1,
247    'sbin'       => 1,
248    'libexec'    => 1,
249    'data'       => 0,
250    'sysconf'    => 1,
251    'localstate' => 1,
252    'lib'        => 1,
253    'info'       => 0,
254    'man'        => 0,
255    'include'    => 0,
256    'oldinclude' => 0,
257    'pkgdata'    => 0,
258    'pkglib'     => 1,
259    'pkginclude' => 0
260   );
262 # Map from obsolete macros to hints for new macros.
263 # If you change this, change the corresponding list in aclocal.in.
264 # FIXME: should just put this into a single file.
265 my %obsolete_macros =
266     (
267      'AC_FEATURE_CTYPE'         => "use `AC_HEADER_STDC'",
268      'AC_FEATURE_ERRNO'         => "add `strerror' to `AC_REPLACE_FUNCS(...)'",
269      'AC_FEATURE_EXIT'          => '',
270      'AC_SYSTEM_HEADER'         => '',
272      # Note that we do not handle this one, because it is still run
273      # from AM_CONFIG_HEADER.  So we deal with it specially in
274      # &scan_autoconf_files.
275      # 'AC_CONFIG_HEADER'       => "use `AM_CONFIG_HEADER'",
277      'fp_C_PROTOTYPES'          => "use `AM_C_PROTOTYPES'",
278      'fp_PROG_CC_STDC'          => "use `AM_PROG_CC_STDC'",
279      'fp_PROG_INSTALL'          => "use `AC_PROG_INSTALL'",
280      'fp_WITH_DMALLOC'          => "use `AM_WITH_DMALLOC'",
281      'fp_WITH_REGEX'            => "use `AM_WITH_REGEX'",
282      'gm_PROG_LIBTOOL'          => "use `AM_PROG_LIBTOOL'",
283      'jm_MAINTAINER_MODE'       => "use `AM_MAINTAINER_MODE'",
284      'md_TYPE_PTRDIFF_T'        => "use `AM_TYPE_PTRDIFF_T'",
285      'ud_PATH_LISPDIR'          => "use `AM_PATH_LISPDIR'",
286      'ud_GNU_GETTEXT'           => "use `AM_GNU_GETTEXT'",
288      # Now part of autoconf proper, under a different name.
289      'AM_FUNC_FNMATCH'          => "use `AC_FUNC_FNMATCH'",
290      'fp_FUNC_FNMATCH'          => "use `AC_FUNC_FNMATCH'",
291      'AM_SANITY_CHECK_CC'       => "automatically done by `AC_PROG_CC'",
292      'AM_PROG_INSTALL'          => "use `AC_PROG_INSTALL'",
293      'AM_EXEEXT'                => "use `AC_EXEEXT'",
294      'AM_CYGWIN32'              => "use `AC_CYGWIN'",
295      'AM_MINGW32'               => "use `AC_MINGW32'",
296      'AM_FUNC_MKTIME'           => "use `AC_FUNC_MKTIME'",
298 # These aren't quite obsolete.
299 #      'md_PATH_PROG',
300      );
302 # Regexp to match the above macros.
303 my $obsolete_rx = '(\b' . join ('\b|\b', keys %obsolete_macros) . '\b)';
307 ## ---------------------------------- ##
308 ## Variables related to the options.  ##
309 ## ---------------------------------- ##
311 # TRUE if we should always generate Makefile.in.
312 my $force_generation = 1;
314 # Strictness level as set on command line.
315 my $default_strictness = $GNU;
317 # Name of strictness level, as set on command line.
318 my $default_strictness_name = 'gnu';
320 # This is TRUE if automatic dependency generation code should be
321 # included in generated Makefile.in.
322 my $cmdline_use_dependencies = 1;
324 # TRUE if in verbose mode.
325 my $verbose = 0;
327 # This holds our (eventual) exit status.  We don't actually exit until
328 # we have processed all input files.
329 my $exit_status = 0;
331 # From the Perl manual.
332 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
334 # TRUE if missing standard files should be installed.
335 my $add_missing = 0;
337 # TRUE if we should copy missing files; otherwise symlink if possible.
338 my $copy_missing = 0;
340 # TRUE if we should always update files that we know about.
341 my $force_missing = 0;
344 ## ---------------------------------------- ##
345 ## Variables filled during files scanning.  ##
346 ## ---------------------------------------- ##
348 # Name of the top autoconf input: `configure.ac' or `configure.in'.
349 my $configure_ac = '';
351 # Files found by scanning configure.ac for LIBOBJS.
352 my %libsources = ();
354 # True if AM_C_PROTOTYPES appears in configure.ac.
355 my $am_c_prototypes = 0;
357 # Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
358 # name which appears in AC_CONFIG_HEADER, colon and all.
359 # @config_names holds the file names.  @config_headers holds the '.in'
360 # files.  Ordinarily these are similar, but they can be different if
361 # the weird "NAME:FILE" syntax is used.
362 my @config_fullnames = ();
363 my @config_names = ();
364 my @config_headers = ();
365 # Line number at which AC_CONFIG_HEADER appears in configure.ac.
366 my $config_header_line = 0;
368 # Directory where output files go.  Actually, output files are
369 # relative to this directory.
370 my $output_directory = '.';
372 # List of Makefile.am's to process, and their corresponding outputs.
373 my @input_files = ();
374 my %output_files = ();
376 # Complete list of Makefile.am's that exist.
377 my @configure_input_files = ();
379 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
380 my @other_input_files = ();
381 # Line number at which AC_OUTPUT seen.
382 my $ac_output_line = 0;
384 # List of directories to search for configure-required files.  This
385 # can be set by AC_CONFIG_AUX_DIR.
386 my @config_aux_path = ('.', '..', '../..');
387 my $config_aux_dir = '';
388 my $config_aux_dir_set_in_configure_in = 0;
390 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
391 my $seen_gettext = 0;
392 # Line number at which AM_GNU_GETTEXT seen.
393 my $ac_gettext_line = 0;
395 # Whether ALL_LINGUAS has been seen.
396 my $seen_linguas = '';
397 # The actual text.
398 my $all_linguas = '';
399 # Line number at which it appears.
400 my $all_linguas_line = 0;
402 # TRUE if AC_DECL_YYTEXT was seen.
403 my $seen_decl_yytext = 0;
405 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
406 # AC_CHECK_TOOL also sets this.
407 my $seen_canonical = 0;
409 # TRUE if we've seen AC_PROG_LIBTOOL.
410 my $seen_libtool = 0;
411 my $libtool_line = 0;
413 # TRUE if we've seen AM_MAINTAINER_MODE.
414 my $seen_maint_mode = 0;
416 # Actual version we've seen.
417 my $package_version = '';
419 # Line number where we saw version definition.
420 my $package_version_line = 0;
422 # TRUE if we've seen AM_PATH_LISPDIR.
423 my $seen_lispdir = 0;
425 # TRUE if we've seen AM_PATH_PYTHON.
426 my $seen_pythondir = 0;
428 # TRUE if we've seen AC_EXEEXT.
429 my $seen_exeext = 0;
431 # TRUE if we've seen AC_OBJEXT.
432 my $seen_objext = 0;
434 # TRUE if we've seen AC_ENABLE_MULTILIB.
435 my $seen_multilib = 0;
437 # TRUE if we've seen AM_PROG_CC_C_O
438 my $seen_cc_c_o = 0;
440 # TRUE if we've seen AM_INIT_AUTOMAKE.
441 my $seen_init_automake = 0;
443 # Hash table of discovered configure substitutions.  Keys are names,
444 # values are `FILE:LINE' strings which are used by error message
445 # generation.
446 my %configure_vars = ();
448 # This is used to keep track of which variable definitions we are
449 # scanning.  It is only used in certain limited ways, but it has to be
450 # global.  It is declared just for documentation purposes.
451 my %vars_scanned = ();
453 # TRUE if --cygnus seen.
454 my $cygnus_mode = 0;
456 # Hash table of AM_CONDITIONAL variables seen in configure.
457 my %configure_cond = ();
459 # This maps extensions onto language names.
460 my %extension_map = ();
462 # List of the DIST_COMMON files we discovered while reading
463 # configure.in
464 my $configure_dist_common = '';
466 # This maps languages names onto objects.
467 my %languages = ();
469 # List of targets we must always output.
470 # FIXME: Complete, and remove falsely required targets.
471 my %required_targets =
472   (
473    'all'          => 1,
474    'dvi'          => 1,
475    'info'         => 1,
476    'install-info' => 1,
477    'install'      => 1,
478    'install-data' => 1,
479    'install-exec' => 1,
480    'uninstall'    => 1,
482    # FIXME: Not required, temporary hacks.
483    # Well, actually they are sort of required: the -recursive
484    # targets will run them anyway...
485    'dvi-am'          => 1,
486    'info-am'         => 1,
487    'install-data-am' => 1,
488    'install-exec-am' => 1,
489    'installcheck-am' => 1,
490    'uninstall-am' => 1,
492    'install-man' => 1,
493   );
497 ################################################################
499 ## ------------------------------------------ ##
500 ## Variables reset by &initialize_per_input.  ##
501 ## ------------------------------------------ ##
503 # Basename and relative dir of the input file.
504 my $am_file_name;
505 my $am_relative_dir;
507 # Same but wrt Makefile.in.
508 my $in_file_name;
509 my $relative_dir;
511 # These two variables are used when generating each Makefile.in.
512 # They hold the Makefile.in until it is ready to be printed.
513 my $output_rules;
514 my $output_vars;
515 my $output_trailer;
516 my $output_all;
517 my $output_header;
519 # Suffixes found during a run.
520 my @suffixes;
522 # Handling the variables.
524 # For a $VAR:
525 # - $var_value{$VAR}{$COND} is its value associated to $COND,
526 # - $var_line{$VAR} is where it has been defined,
527 # - $var_comment{$VAR} are the comments associated to it.
528 # - $var_type{$VAR} is how it has been defined (`', `+', or `:'),
529 # - $var_is_am{$VAR} is true if the variable is owned by Automake.
530 my %var_value;
531 my %var_line;
532 my %var_comment;
533 my %var_type;
534 my %var_is_am;
536 # This holds a 1 if a particular variable was examined.
537 my %content_seen;
539 # This holds the names which are targets.  These also appear in
540 # %contents.
541 my %targets;
543 # Same as %VAR_VALUE, but for targets.
544 my %target_conditional;
546 # This is the conditional stack.
547 my @cond_stack;
549 # This holds the set of included files.
550 my @include_stack;
552 # This holds a list of directories which we must create at `dist'
553 # time.  This is used in some strange scenarios involving weird
554 # AC_OUTPUT commands.
555 my %dist_dirs;
557 # List of dependencies for the obvious targets.
558 my @all;
559 my @check;
560 my @check_tests;
562 # Holds the dependencies of targets which dependencies are factored.
563 # Typically, `.PHONY' will appear in plenty of *.am files, but must
564 # be output once.  Arguably all pure dependencies could be subject
565 # to this factorization, but it is not unpleasant to have paragraphs
566 # in Makefile: keeping related stuff altogether.
567 my %dependencies;
569 # Holds the factored actions.  Tied to %DEPENDENCIES, i.e., filled
570 # only when keys exists in %DEPENDENCIES.
571 my %actions;
573 # A list of files deleted by `maintainer-clean'.
574 my @maintainer_clean_files;
576 # Keys in this hash table are object files or other files in
577 # subdirectories which need to be removed.  This only holds files
578 # which are created by compilations.  The value in the hash indicates
579 # when the file should be removed.
580 my %compile_clean_files;
582 # Value of `$(SOURCES)', used by tags.am.
583 my @sources;
584 # Sources which go in the distribution.
585 my @dist_sources;
587 # This hash maps object file names onto their corresponding source
588 # file names.  This is used to ensure that each object is created
589 # by a single source file.
590 my %object_map;
592 # This keeps track of the directories for which we've already
593 # created `.dirstamp' code.
594 my %directory_map;
596 # All .P files.
597 my %dep_files;
599 # Strictness levels.
600 my $strictness;
601 my $strictness_name;
603 # Options from AUTOMAKE_OPTIONS.
604 my %options;
606 # Whether or not dependencies are handled.  Can be further changed
607 # in handle_options.
608 my $use_dependencies;
610 # This is a list of all targets to run during "make dist".
611 my @dist_targets;
613 # Keys in this hash are the basenames of files which must depend
614 # on ansi2knr.
615 my %de_ansi_files;
617 # This maps the source extension of a suffix rule to its
618 # corresponding output extension.
619 my %suffix_rules;
621 # This is the name of the redirect `all' target to use.
622 my $all_target;
624 # This keeps track of which extensions we've seen (that we care
625 # about).
626 my %extension_seen;
628 # This is random scratch space for the language finish functions.
629 # Don't randomly overwrite it; examine other uses of keys first.
630 my %language_scratch;
632 # We keep track of which objects need special (per-executable)
633 # handling on a per-language basis.
634 my %lang_specific_files;
636 # This is set when `handle_dist' has finished.  Once this happens,
637 # we should no longer push on dist_common.
638 my $handle_dist_run;
640 # True if we need `LINK' defined.  This is a hack.
641 my $need_link;
643 # This is the list of such variables to output.
644 # FIXME: Might be useless actually.
645 my @var_list;
647 # Was get_object_extension run?
648 # FIXME: This is a hack. a better switch should be found.
649 my $get_object_extension_was_run;
652 ## --------------------------------- ##
653 ## Forward subroutine declarations.  ##
654 ## --------------------------------- ##
655 sub register_language (%);
656 sub file_contents_internal ($$%);
659 # &initialize_per_input ()
660 # ------------------------
661 # (Re)-Initialize per-Makefile.am variables.
662 sub initialize_per_input ()
664     $am_file_name = '';
665     $am_relative_dir = '';
667     $in_file_name = '';
668     $relative_dir = '';
670     $output_rules = '';
671     $output_vars = '';
672     $output_trailer = '';
673     $output_all = '';
674     $output_header = '';
676     @suffixes = ();
678     %var_value = ();
679     %var_line = ();
680     %var_comment = ();
681     %var_type = ();
682     %var_is_am = ();
684     %content_seen = ();
686     %targets = ();
688     %target_conditional = ();
690     @cond_stack = ();
692     @include_stack = ();
694     $relative_dir = '';
696     $am_relative_dir = '';
698     %dist_dirs = ();
700     @all = ();
701     @check = ();
702     @check_tests = ();
704     %dependencies =
705       (
706        # Texinfoing.
707        'dvi'      => [],
708        'dvi-am'   => [],
709        'info'     => [],
710        'info-am'  => [],
712        # Installing/uninstalling.
713        'install-data-am'      => [],
714        'install-exec-am'      => [],
715        'uninstall-am'         => [],
717        'install-man'          => [],
718        'uninstall-man'        => [],
720        'install-info'         => [],
721        'install-info-am'      => [],
722        'uninstall-info'       => [],
724        'installcheck-am'      => [],
726        # Cleaning.
727        'clean-am'             => [],
728        'mostlyclean-am'       => [],
729        'maintainer-clean-am'  => [],
730        'distclean-am'         => [],
731        'clean'                => [],
732        'mostlyclean'          => [],
733        'maintainer-clean'     => [],
734        'distclean'            => [],
736        # Tarballing.
737        'dist-all'             => [],
739        # Phoning.
740        '.PHONY'               => []
741       );
742     %actions = ();
744     @maintainer_clean_files = ();
746     @sources = ();
747     @dist_sources = ();
749     %object_map = ();
751     %directory_map = ();
753     %dep_files = ();
755     $strictness = $default_strictness;
756     $strictness_name = $default_strictness_name;
758     %options = ();
760     $use_dependencies = $cmdline_use_dependencies;
762     @dist_targets = ();
764     %de_ansi_files = ();
766     %suffix_rules = ();
768     $all_target = '';
770     %extension_seen = ();
772     %language_scratch = ();
774     %lang_specific_files = ();
776     $handle_dist_run = 0;
778     $need_link = 0;
780     @var_list = ();
782     $get_object_extension_was_run = 0;
784     %compile_clean_files = ();
788 ################################################################
790 # Initialize our list of languages that are internally supported.
792 # C.
793 register_language ('name' => 'c',
794                    'Name' => 'C',
795                    'config_vars' => ['CC'],
796                    'ansi' => 1,
797                    'autodep' => '',
798                    'flags' => 'CFLAGS',
799                    'compiler' => 'COMPILE',
800                    'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
801                    'lder' => 'CCLD',
802                    'ld' => '$(CC)',
803                    'linker' => 'LINK',
804                    'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
805                    'compile_flag' => '-c',
806                    'extensions' => ['c'],
807                    '_finish' => \&lang_c_finish);
809 # C++.
810 register_language ('name' => 'cxx',
811                    'Name' => 'C++',
812                    'config_vars' => ['CXX'],
813                    'linker' => 'CXXLINK',
814                    'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
815                    'autodep' => 'CXX',
816                    'flags' => 'CXXFLAGS',
817                    'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
818                    'compiler' => 'CXXCOMPILE',
819                    'compile_flag' => '-c',
820                    'output_flag' => '-o',
821                    'lder' => 'CXXLD',
822                    'ld' => '$(CXX)',
823                    'pure' => 1,
824                    'extensions' => ['c++', 'cc', 'cpp', 'cxx', 'C']);
826 # Objective C.
827 register_language ('name' => 'objc',
828                    'Name' => 'Objective C',
829                    'config_vars' => ['OBJC'],
830                    'linker' => 'OBJCLINK',,
831                    'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
832                    'autodep' => 'OBJC',
833                    'flags' => 'OBJCFLAGS',
834                    'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
835                    'compiler' => 'OBJCCOMPILE',
836                    'compile_flag' => '-c',
837                    'output_flag' => '-o',
838                    'lder' => 'OBJCLD',
839                    'ld' => '$(OBJC)',
840                    'pure' => 1,
841                    'extensions' => ['m']);
843 # Headers.
844 register_language ('name' => 'header',
845                    'Name' => 'Header',
846                    'extensions' => ['h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc'],
847                    # Nothing to do.
848                    '_finish' => sub { });
850 # Yacc (C & C++).
851 register_language ('name' => 'yacc',
852                    'Name' => 'Yacc',
853                    'config_vars' => ['YACC'],
854                    'flags' => 'YFLAGS',
855                    'define_flag' => 0,
856                    'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
857                    'compiler' => 'YACCCOMPILE',
858                    'extensions' => ['y'],
859                    'rule_file' => 'yacc',
860                    '_finish' => \&lang_yacc_finish,
861                    '_target_hook' => \&lang_yacc_target_hook);
862 register_language ('name' => 'yaccxx',
863                    'Name' => 'Yacc (C++)',
864                    'config_vars' => ['YACC'],
865                    'rule_file' => 'yacc',
866                    'flags' => 'YFLAGS',
867                    'define_flag' => 0,
868                    'compiler' => 'YACCCOMPILE',
869                    'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
870                    'extensions' => ['y++', 'yy', 'yxx', 'ypp'],
871                    '_finish' => \&lang_yacc_finish,
872                    '_target_hook' => \&lang_yacc_target_hook);
874 # Lex (C & C++).
875 register_language ('name' => 'lex',
876                    'Name' => 'Lex',
877                    'config_vars' => ['LEX'],
878                    'rule_file' => 'lex',
879                    'flags' => 'LFLAGS',
880                    'define_flag' => 0,
881                    'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
882                    'compiler' => 'LEXCOMPILE',
883                    'extensions' => ['l'],
884                    '_finish' => \&lang_lex_finish);
885 register_language ('name' => 'lexxx',
886                    'Name' => 'Lex (C++)',
887                    'config_vars' => ['LEX'],
888                    'rule_file' => 'lex',
889                    'flags' => 'LFLAGS',
890                    'define_flag' => 0,
891                    'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
892                    'compiler' => 'LEXCOMPILE',
893                    'extensions' => ['l++', 'll', 'lxx', 'lpp'],
894                    '_finish' => \&lang_lex_finish);
896 # Assembler.
897 register_language ('name' => 'asm',
898                    'Name' => 'Assembler',
899                    'config_vars' => ['AS', 'ASFLAGS'],
901                    'flags' => 'ASFLAGS',
902                    # Users can set AM_ASFLAGS to includes DEFS, INCLUDES,
903                    # or anything else required.  They can also set AS.
904                    'compile' => '$(AS) $(AM_ASFLAGS) $(ASFLAGS)',
905                    'compiler' => 'ASCOMPILE',
906                    'compile_flag' => '-c',
907                    'extensions' => ['s', 'S'],
909                    # With assembly we still use the C linker.
910                    '_finish' => \&lang_c_finish);
912 # Fortran 77
913 register_language ('name' => 'f77',
914                    'Name' => 'Fortran 77',
915                    'linker' => 'F77LINK',
916                    'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
917                    'flags' => 'FFLAGS',
918                    'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
919                    'compiler' => 'F77COMPILE',
920                    'compile_flag' => '-c',
921                    'output_flag' => '-o',
922                    'lder' => 'F77LD',
923                    'ld' => '$(F77)',
924                    'pure' => 1,
925                    'extensions' => ['f', 'for', 'f90']);
927 # Preprocessed Fortran 77
929 # The current support for preprocessing Fortran 77 just involves
930 # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
931 # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
932 # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
933 # for `make' Version 3.76 Beta' (specifically, from info file
934 # `(make)Catalogue of Rules').
936 # A better approach would be to write an Autoconf test
937 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
938 # Fortran 77 compilers know how to do preprocessing.  The Autoconf
939 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
940 # preprocessing capabilities, and then fall back on cpp (if cpp were
941 # available).
942 register_language ('name' => 'ppf77',
943                    'Name' => 'Preprocessed Fortran 77',
944                    'config_vars' => ['F77'],
945                    'linker' => 'F77LINK',
946                    'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
947                    'lder' => 'F77LD',
948                    'ld' => '$(F77)',
949                    'flags' => 'FFLAGS',
950                    'compiler' => 'PPF77COMPILE',
951                    'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
952                    'compile_flag' => '-c',
953                    'output_flag' => '-o',
954                    'pure' => 1,
955                    'extensions' => ['F']);
957 # Ratfor.
958 register_language ('name' => 'ratfor',
959                    'Name' => 'Ratfor',
960                    'config_vars' => ['F77'],
961                    'linker' => 'F77LINK',
962                    'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
963                    'lder' => 'F77LD',
964                    'ld' => '$(F77)',
965                    'flags' => 'RFLAGS',
966                    # FIXME also FFLAGS.
967                    'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
968                    'compiler' => 'RCOMPILE',
969                    'compile_flag' => '-c',
970                    'output_flag' => '-o',
971                    'pure' => 1,
972                    'extensions' => ['r']);
974 # Java via gcj.
975 register_language ('name' => 'java',
976                    'Name' => 'Java',
977                    'config_vars' => ['GCJ'],
978                    'linker' => 'GCJLINK',
979                    'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
980                    'autodep' => 'GCJ',
981                    'flags' => 'GCJFLAGS',
982                    'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
983                    'compiler' => 'GCJCOMPILE',
984                    'compile_flag' => '-c',
985                    'output_flag' => '-o',
986                    'lder' => 'GCJLD',
987                    'ld' => '$(GCJ)',
988                    'pure' => 1,
989                    'extensions' => ['java', 'class', 'zip', 'jar']);
991 ################################################################
993 # Parse command line.
994 &parse_arguments;
996 # Do configure.ac scan only once.
997 &scan_autoconf_files;
999 die "$me: no `Makefile.am' found or specified\n"
1000     if ! @input_files;
1002 # Now do all the work on each file.
1003 # This guy must be local otherwise it's private to the loop.
1004 use vars '$am_file';
1005 local $am_file;
1006 foreach $am_file (@input_files)
1008     if (! -f ($am_file . '.am'))
1009     {
1010         &am_error ("`" . $am_file . ".am' does not exist");
1011     }
1012     else
1013     {
1014         &generate_makefile ($output_files{$am_file}, $am_file);
1015     }
1018 exit $exit_status;
1020 # FIXME: This should be `my'ed next to its subs.
1021 use vars '%require_file_found';
1023 ################################################################
1025 # prog_error (@PRINT-ME)
1026 # ----------------------
1027 # Signal a programming error, display PRINT-ME, and exit 1.
1028 sub prog_error (@)
1030     print STDERR "$me: programming error: @_\n";
1031     exit 1;
1035 # @RES
1036 # uniq (@LIST)
1037 # ------------
1038 # Return LIST with no duplicates.
1039 sub uniq (@)
1041    my @res = ();
1042    my %seen = ();
1043    foreach my $item (@_)
1044      {
1045        if (! defined $seen{$item})
1046          {
1047            $seen{$item} = 1;
1048            push (@res, $item);
1049          }
1050      }
1051    return @res;
1054 # subst ($TEXT)
1055 # -------------
1056 # Return a configure-style substitution using the indicated text.
1057 # We do this to avoid having the substitutions directly in automake.in;
1058 # when we do that they are sometimes removed and this causes confusion
1059 # and bugs.
1060 sub subst ($)
1062     my ($text) = @_;
1063     return '@' . $text . '@';
1066 ################################################################
1069 # $BACKPATH
1070 # &backname ($REL-DIR)
1071 # --------------------
1072 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
1073 # For instance `src/foo' => `../..'.
1074 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
1075 sub backname ($)
1077     my ($file) = @_;
1078     my @res;
1079     foreach (split (/\//, $file))
1080     {
1081         next if $_ eq '.' || $_ eq '';
1082         if ($_ eq '..')
1083         {
1084             pop @res;
1085         }
1086         else
1087         {
1088             push (@res, '..');
1089         }
1090     }
1091     return join ('/', @res) || '.';
1094 ################################################################
1096 # Parse command line.
1097 sub parse_arguments ()
1099     # Start off as gnu.
1100     &set_strictness ('gnu');
1102     use Getopt::Long;
1103     Getopt::Long::config ("bundling");
1104     Getopt::Long::GetOptions
1105       (
1106        'version'        => \&version,
1107        'help'           => \&usage,
1108        'libdir:s'       => \$libdir,
1109        'gnu'            => sub { &set_strictness ('gnu'); },
1110        'gnits'          => sub { &set_strictness ('gnits'); },
1111        'cygnus'         => \$cygnus_mode,
1112        'foreign'        => sub { &set_strictness ('foreign'); },
1113        'include-deps'   => sub { $cmdline_use_dependencies = 1; },
1114        'i|ignore-deps'  => sub { $cmdline_use_dependencies = 0; },
1115        'no-force'       => sub { $force_generation = 0; },
1116        'f|force-missing'=> \$force_missing,
1117        'o|output-dir:s' => \$output_directory,
1118        'a|add-missing'  => \$add_missing,
1119        'c|copy'         => \$copy_missing,
1120        'v|verbose'      => \$verbose,
1121        'Werror'         => sub { $SIG{"__WARN__"} = sub { die $_[0] } },
1122        'Wno-error'      => sub { $SIG{"__WARN__"} = 'DEFAULT' }
1123       )
1124         or exit 1;
1126     foreach my $arg (@ARGV)
1127     {
1128       # Handle $local:$input syntax.  Note that we only examine the
1129       # first ":" file to see if it is automake input; the rest are
1130       # just taken verbatim.  We still keep all the files around for
1131       # dependency checking, however.
1132       my ($local, $input, @rest) = split (/:/, $arg);
1133       if (! $input)
1134         {
1135           $input = $local;
1136         }
1137       else
1138         {
1139           # Strip .in; later on .am is tacked on.  That is how the
1140           # automake input file is found.  Maybe not the best way, but
1141           # it is easy to explain.
1142           $input =~ s/\.in$//
1143             or die "$me: invalid input file name `$arg'\n.";
1144         }
1145       push (@input_files, $input);
1146       $output_files{$input} = join (':', ($local, @rest));
1147     }
1149     # Take global strictness from whatever we currently have set.
1150     $default_strictness = $strictness;
1151     $default_strictness_name = $strictness_name;
1154 ################################################################
1156 # Generate a Makefile.in given the name of the corresponding Makefile and
1157 # the name of the file output by config.status.
1158 sub generate_makefile
1160     my ($output, $makefile) = @_;
1162     # Reset all the Makefile.am related variables.
1163     &initialize_per_input;
1165     # Name of input file ("Makefile.am") and output file
1166     # ("Makefile.in").  These have no directory components.
1167     $am_file_name = basename ($makefile) . '.am';
1168     $in_file_name = basename ($makefile) . '.in';
1170     # $OUTPUT is encoded.  If it contains a ":" then the first element
1171     # is the real output file, and all remaining elements are input
1172     # files.  We don't scan or otherwise deal with these input file,
1173     # other than to mark them as dependencies.  See
1174     # &scan_autoconf_files for details.
1175     my (@secondary_inputs);
1176     ($output, @secondary_inputs) = split (/:/, $output);
1178     $relative_dir = dirname ($output);
1179     $am_relative_dir = dirname ($makefile);
1181     &read_main_am_file ($makefile . '.am');
1182     if (&handle_options)
1183     {
1184         # Fatal error.  Just return, so we can continue with next file.
1185         return;
1186     }
1188     # There are a few install-related variables that you should not define.
1189     foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
1190     {
1191         if (&variable_defined ($var) && !$var_is_am{$var})
1192         {
1193             &am_line_error ($var, "`$var' should not be defined");
1194         }
1195     }
1197     &handle_libtool;
1199     # At the toplevel directory, we might need config.guess, config.sub
1200     # or libtool scripts (ltconfig and ltmain.sh).
1201     if ($relative_dir eq '.')
1202     {
1203         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1204         # config.sub.
1205         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
1206             if $seen_canonical;
1207     }
1209     # We still need Makefile.in here, because sometimes the `dist'
1210     # target doesn't re-run automake.
1211     if ($am_relative_dir eq $relative_dir)
1212     {
1213         # Only distribute the files if they are in the same subdir as
1214         # the generated makefile.
1215         &push_dist_common ($in_file_name, $am_file_name);
1216     }
1218     push (@sources, '$(SOURCES)')
1219         if &variable_defined ('SOURCES');
1221     # If OBJEXT/EXEEXT were not set in configure.in, do it, it
1222     # simplifies our task, and anyway starting with Autoconf 2.50, it
1223     # will always be defined, and this code will be dead.
1224     $output_vars .= "EXEEXT =\n"
1225       unless $seen_exeext;
1226     $output_vars .= "OBJEXT = o\n"
1227       unless $seen_objext;
1229     # Must do this after reading .am file.  See read_main_am_file to
1230     # understand weird tricks we play there with variables.
1231     &define_variable ('subdir', $relative_dir);
1233     # Check first, because we might modify some state.
1234     &check_cygnus;
1235     &check_gnu_standards;
1236     &check_gnits_standards;
1238     &handle_configure ($output, $makefile, @secondary_inputs);
1239     &handle_gettext;
1240     &handle_libraries;
1241     &handle_ltlibraries;
1242     &handle_programs;
1243     &handle_scripts;
1245     # This must run first so that the ANSI2KNR definition is generated
1246     # before it is used by the _.c rules.  We have to do this because
1247     # a variable which is used in a dependency must be defined before
1248     # the target, or else make won't properly see it.
1249     &handle_compile;
1250     # This must be run after all the sources are scanned.
1251     &handle_languages;
1253     # Re-init SOURCES.  FIXME: other code shouldn't depend on this
1254     # (but currently does).
1255     macro_define ('SOURCES', 1, '', 'TRUE',
1256                      join (' ', @sources), 'internal');
1257     &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
1259     &handle_multilib;
1260     &handle_texinfo;
1261     &handle_emacs_lisp;
1262     &handle_python;
1263     &handle_java;
1264     &handle_man_pages;
1265     &handle_data;
1266     &handle_headers;
1267     &handle_subdirs;
1268     &handle_tags;
1269     &handle_minor_options;
1270     &handle_tests;
1272     # This must come after most other rules.
1273     &handle_dist ($makefile);
1275     &handle_footer;
1276     &do_check_merge_target;
1277     &handle_all ($output);
1279     # FIXME: Gross!
1280     if (&variable_defined('lib_LTLIBRARIES') &&
1281         &variable_defined('bin_PROGRAMS'))
1282     {
1283         $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
1284     }
1286     &handle_installdirs;
1287     &handle_clean;
1288     &handle_factored_dependencies;
1290     &check_typos;
1292     if (! -d ($output_directory . '/' . $am_relative_dir))
1293     {
1294         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
1295     }
1297     my ($out_file) = $output_directory . '/' . $makefile . ".in";
1298     if (! $force_generation && -e $out_file)
1299     {
1300         my ($am_time) = (stat ($makefile . '.am'))[9];
1301         my ($in_time) = (stat ($out_file))[9];
1302         # FIXME: should cache these times.
1303         my ($conf_time) = (stat ($configure_ac))[9];
1304         # FIXME: how to do unsigned comparison?
1305         if ($am_time < $in_time || $am_time < $conf_time)
1306         {
1307             # No need to update.
1308             return;
1309         }
1310         if (-f 'aclocal.m4')
1311         {
1312             my ($acl_time) = (stat _)[9];
1313             return if ($am_time < $acl_time);
1314         }
1315     }
1317     my $gm_file = new IO::File "> $out_file";
1318     if (! $gm_file)
1319     {
1320         warn "$me: ${am_file}.in: cannot write: $!\n";
1321         $exit_status = 1;
1322         return;
1323     }
1324     print "$me: creating ", $makefile, ".in\n" if $verbose;
1326     # In case we're running under MSWindows, don't write with CRLF
1327     # (as it causes problems for the dependency-file extraction in
1328     # AM_OUTPUT_DEPENDENCY_COMMANDS).
1329     binmode $gm_file;
1331     print $gm_file $output_vars;
1332     # We make sure that `all:' is the first target.
1333     print $gm_file $output_all;
1334     print $gm_file $output_header;
1335     print $gm_file $output_rules;
1336     print $gm_file $output_trailer;
1338     if (! $gm_file->close)
1339       {
1340         warn "$me: $am_file.in: cannot close: $!\n";
1341         $exit_status = 1;
1342         return;
1343       }
1346 ################################################################
1348 # A helper which handles the logic of requiring a version number in
1349 # AUTOMAKE_OPTIONS.  Return 1 on error, 0 on success.
1350 sub version_check ($$$$)
1352     my ($rmajor, $rminor, $ralpha, $rfork) = ($1, $2, $3, $4);
1354     &prog_error ("version is incorrect: $VERSION")
1355         if $VERSION !~ /(\d+)\.(\d+)([a-z]?)-?([A-Za-z0-9]+)?/;
1357     my ($tmajor, $tminor, $talpha, $tfork) = ($1, $2, $3, $4);
1359     $rfork ||= '';
1360     $tfork ||= '';
1362     my $rminorminor = 0;
1363     my $tminorminor = 0;
1365     # Some versions were labelled like `1.4-p3a'.  This is the same as
1366     # an alpha release labelled `1.4.3a'.  However, a version like
1367     # `1.4g' is the same as `1.4.99g'.  Yes, this sucks.  Moral:
1368     # always listen to the users.
1369     if ($rfork =~ /p([0-9]+)([a-z]?)/)
1370     {
1371         $rminorminor = $1;
1372         # `1.4a-p3b' never existed.  But we'll accept it anyway.
1373         $ralpha = $ralpha || $2 || '';
1374         $rfork = '';
1375     }
1376     if ($tfork =~ /p([0-9]+)([a-z]?)/)
1377     {
1378         $tminorminor = $1;
1379         # `1.4a-p3b' never existed.  But we'll accept it anyway.
1380         $talpha = $talpha || $2 || '';
1381         $tfork = '';
1382     }
1384     $rminorminor = 99 if $ralpha ne '' && $rminorminor == 0;
1385     $tminorminor = 99 if $talpha ne '' && $tminorminor == 0;
1387     # 2.0 is better than 1.0.
1388     # 1.2 is better than 1.1.
1389     # 1.2a is better than 1.2.
1390     # If we require 3.4n-foo then we require something
1391     # >= 3.4n, with the `foo' fork identifier.
1392     # The $r* variables are what the user specified.
1393     # The $t* variables denote automake itself.
1394     if ($rmajor > $tmajor
1395         || ($rmajor == $tmajor && $rminor > $tminor)
1396         || ($rminor == $tminor && $rminor == $tminor
1397             && $rminorminor > $tminorminor)
1398         || ($rminor == $tminor && $rminor == $tminor
1399             && $rminorminor == $tminorminor
1400             && $ralpha gt $talpha)
1401         || ($rfork ne '' && $rfork ne $tfork))
1402     {
1403         &am_line_error ('AUTOMAKE_OPTIONS',
1404                         "require version $_, but have $VERSION");
1405         return 1;
1406     }
1408     return 0;
1411 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
1412 sub handle_options
1414     if (&variable_defined ('AUTOMAKE_OPTIONS'))
1415     {
1416         foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
1417         {
1418             $options{$_} = 1;
1419             if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
1420             {
1421                 &set_strictness ($_);
1422             }
1423             elsif ($_ eq 'cygnus')
1424             {
1425                 $cygnus_mode = 1;
1426             }
1427             elsif (/ansi2knr/)
1428             {
1429                 # An option like "../lib/ansi2knr" is allowed.  With
1430                 # no path prefix, we assume the required programs are
1431                 # in this directory.  We save the actual option for
1432                 # later.
1433                 $options{'ansi2knr'} = $_;
1434             }
1435             elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
1436                    || $_ eq 'dist-shar' || $_ eq 'dist-zip'
1437                    || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
1438                    || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
1439                    || $_ eq 'readme-alpha' || $_ eq 'check-news'
1440                    || $_ eq 'subdir-objects' || $_ eq 'nostdinc')
1441             {
1442                 # Explicitly recognize these.
1443             }
1444             elsif ($_ eq 'no-dependencies')
1445             {
1446                 $use_dependencies = 0;
1447             }
1448             elsif (/(\d+)\.(\d+)([a-z]?)(-[A-Za-z0-9]+)?/)
1449             {
1450                 # Got a version number.
1451                 if (version_check ($1, $2, $3, $4))
1452                 {
1453                     return 1;
1454                 }
1455             }
1456             else
1457             {
1458                 &am_line_error ('AUTOMAKE_OPTIONS',
1459                                 "option `" . $_ . "\' not recognized");
1460             }
1461         }
1462     }
1464     if ($strictness == $GNITS)
1465     {
1466         $options{'readme-alpha'} = 1;
1467         $options{'check-news'} = 1;
1468     }
1470     return 0;
1474 # get_object_extension ($OUT)
1475 # ---------------------------
1476 # Return object extension.  Just once, put some code into the output.
1477 # OUT is the name of the output file
1478 sub get_object_extension
1480     my ($out) = @_;
1482     # Maybe require libtool library object files.
1483     my $extension = '.$(OBJEXT)';
1484     $extension = '.lo' if ($out =~ /\.la$/);
1486     # Check for automatic de-ANSI-fication.
1487     $extension = '$U' . $extension
1488       if defined $options{'ansi2knr'};
1490     $get_object_extension_was_run = 1;
1492     return $extension;
1496 # Call finish function for each language that was used.
1497 sub handle_languages
1499     if ($use_dependencies)
1500     {
1501         # Include auto-dep code.  Don't include it if DEP_FILES would
1502         # be empty.
1503         if (&saw_sources_p (0) && keys %dep_files)
1504         {
1505             # Set location of depcomp.
1506             &define_variable ('depcomp', "\$(SHELL) $config_aux_dir/depcomp");
1508             &require_config_file ($FOREIGN, 'depcomp');
1510             my @deplist = sort keys %dep_files;
1512             # We define this as a conditional variable because BSD
1513             # make can't handle backslashes for continuing comments on
1514             # the following line.
1515             &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
1517             # Generate each `include' individually.  Irix 6 make will
1518             # not properly include several files resulting from a
1519             # variable expansion; generating many separate includes
1520             # seems safest.
1521             $output_rules .= "\n";
1522             foreach my $iter (@deplist)
1523             {
1524                 $output_rules .= (subst ('AMDEP_TRUE')
1525                                   . subst ('_am_include')
1526                                   . ' '
1527                                   . subst ('_am_quote')
1528                                   . $iter
1529                                   . subst ('_am_quote')
1530                                   . "\n");
1531             }
1533             $output_rules .= &file_contents ('depend');
1534         }
1535     }
1536     else
1537     {
1538         &define_variable ('depcomp', '');
1539     }
1541     my %done;
1543     # Is the c linker needed?
1544     my $needs_c = 0;
1545     foreach my $ext (sort keys %extension_seen)
1546     {
1547         next unless $extension_map{$ext};
1549         my $lang = $languages{$extension_map{$ext}};
1551         my $rule_file = $lang->rule_file || 'depend2';
1553         # Get information on $LANG.
1554         my $pfx = $lang->autodep;
1555         my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1557         my $AMDEP = (($use_dependencies && $lang->autodep ne 'no')
1558                      ? 'AMDEP' : 'FALSE');
1560         my %transform = ('EXT'     => $ext,
1561                          'PFX'     => $pfx,
1562                          'FPFX'    => $fpfx,
1563                          'LIBTOOL' => $seen_libtool,
1564                          'AMDEP'   => $AMDEP,
1565                          '-c'      => $lang->compile_flag || '',
1566                          'MORE-THAN-ONE'
1567                                    => (count_files_for_language ($lang->name) > 1));
1569         # Generate the appropriate rules for this extension.
1570         if (($use_dependencies && $lang->autodep ne 'no')
1571             || defined $lang->compile)
1572         {
1573             # Some C compilers don't support -c -o.  Use it only if really
1574             # needed.
1575             my $output_flag = $lang->output_flag || '';
1576             $output_flag = '-o'
1577               if (! $output_flag
1578                   && $lang->flags eq 'CFLAGS'
1579                   && defined $options{'subdir-objects'});
1581             # FIXME: this is a temporary hack to compute a possible
1582             # derived extension.  This is not used by depend2.am.
1583             (my $der_ext = $ext) =~ tr/yl/cc/;
1585             # Another yacc/lex hack.
1586             my $destfile = '$*.' . $der_ext;
1588             $output_rules .=
1589               file_contents ($rule_file,
1590                              %transform,
1591                              'GENERIC'   => 1,
1593                              'DERIVED-EXT' => $der_ext,
1595                              'BASE'      => '$*',
1596                              'SOURCE'    => '$<',
1597                              'OBJ'       => '$@',
1598                              'OBJOBJ'    => '$@',
1599                              'LTOBJ'     => '$@',
1601                              'COMPILE'   => '$(' . $lang->compiler . ')',
1602                              'LTCOMPILE' => '$(LT' . $lang->compiler . ')',
1603                              '-o'        => $output_flag);
1604         }
1606         # Now include code for each specially handled object with this
1607         # language.
1608         my %seen_files = ();
1609         foreach my $file (@{$lang_specific_files{$lang->name}})
1610         {
1611             my ($derived, $source, $obj, $myext) = split (' ', $file);
1613             # We might see a given object twice, for instance if it is
1614             # used under different conditions.
1615             next if defined $seen_files{$obj};
1616             $seen_files{$obj} = 1;
1618             my $flags = $lang->flags || '';
1619             my $val = "${derived}_${flags}";
1621             &prog_error ("found $lang->name in handle_languages, but compiler not defined")
1622                 unless defined $lang->compile;
1624             (my $obj_compile = $lang->compile) =~ s/\(AM_$flags/\($val/;
1625             my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
1627             # We _need_ `-o' for per object rules.
1628             my $output_flag = $lang->output_flag || '-o';
1630             # Generate a transform which will turn suffix targets in
1631             # depend2.am into real targets for the particular objects we
1632             # are building.
1633             $output_rules .=
1634               file_contents ($rule_file,
1635                              (%transform,
1636                               'GENERIC'   => 0,
1638                               'BASE'      => $obj,
1639                               'SOURCE'    => $source,
1640                               # Use $myext and not `.o' here, in case
1641                               # we are actually building a new source
1642                               # file -- e.g. via yacc.
1643                               'OBJ'       => "$obj$myext",
1644                               'OBJOBJ'    => "$obj.obj",
1645                               'LTOBJ'     => "$obj.lo",
1647                               'COMPILE'   => $obj_compile,
1648                               'LTCOMPILE' => $obj_ltcompile,
1649                               '-o'        => $output_flag));
1650         }
1652         # The rest of the loop is done once per language.
1653         next if defined $done{$lang};
1654         $done{$lang} = 1;
1656         # Load the language dependent Makefile chunks.
1657         my %lang = map { uc ($_) => 0 } keys %languages;
1658         $lang{uc ($lang->name)} = 1;
1659         $output_rules .= file_contents ('lang-compile', %transform, %lang);
1661         # If the source to a program consists entirely of code from a
1662         # `pure' language, for instance C++ for Fortran 77, then we
1663         # don't need the C compiler code.  However if we run into
1664         # something unusual then we do generate the C code.  There are
1665         # probably corner cases here that do not work properly.
1666         # People linking Java code to Fortran code deserve pain.
1667         $needs_c ||= ! $lang->pure;
1669         define_compiler_variable ($lang)
1670           if ($lang->compile);
1672         define_linker_variable ($lang)
1673           if ($lang->link);
1675         foreach my $var (@{$lang->config_vars})
1676           {
1677             am_error ($lang->Name
1678                       . " source seen but `$var' not defined in"
1679                       . " `$configure_ac'")
1680               if !exists $configure_vars{$var};
1681           }
1683         # The compiler's flag must be a configure variable.
1684         define_configure_variable ($lang->flags)
1685             if defined $lang->flags && $lang->define_flag;
1687         # Call the finisher.
1688         $lang->finish;
1689     }
1691     # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1692     # suffix rule was learned), don't bother with the C stuff.  But if
1693     # anything else creeps in, then use it.
1694     $needs_c = 1
1695       if $need_link || scalar keys %suffix_rules > 1;
1697     if ($needs_c)
1698       {
1699         if (! defined $done{$languages{'c'}})
1700           {
1701             &define_configure_variable ($languages{'c'}->flags);
1702             &define_compiler_variable ($languages{'c'});
1703           }
1704         define_linker_variable ($languages{'c'});
1705       }
1708 # Check to make sure a source defined in LIBOBJS is not explicitly
1709 # mentioned.  This is a separate function (as opposed to being inlined
1710 # in handle_source_transform) because it isn't always appropriate to
1711 # do this check.
1712 sub check_libobjs_sources
1714     my ($one_file, $unxformed) = @_;
1716     foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1717                         'dist_EXTRA_', 'nodist_EXTRA_')
1718     {
1719         my @files;
1720         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1721         {
1722             @files = &variable_value_as_list (($prefix
1723                                                . $one_file . '_SOURCES'),
1724                                               'all');
1725         }
1726         elsif ($prefix eq '')
1727         {
1728             @files = ($unxformed . '.c');
1729         }
1730         else
1731         {
1732             next;
1733         }
1735         foreach my $file (@files)
1736         {
1737             if (defined $libsources{$file})
1738             {
1739                 &am_line_error ($prefix . $one_file . '_SOURCES',
1740                                 "automatically discovered file `$file' should not be explicitly mentioned");
1741             }
1742         }
1743     }
1747 # ($LINKER, @OBJECTS)
1748 # handle_single_transform_list ($VAR, $DERIVED, $OBJ, @FILES)
1749 # -----------------------------------------------------------
1750 # Does much of the actual work for handle_source_transform.
1751 # Arguments are:
1752 #   $DERIVED is the name of resulting executable or library
1753 #   $OBJ is the object extension (e.g., `$U.lo')
1754 #   @FILES is the list of source files to transform
1755 # Result is a list
1756 #   $LINKER is name of linker to use (empty string for default linker)
1757 #   @OBJECTS are names of objects
1758 sub handle_single_transform_list ($$$@)
1760     my ($var, $derived, $obj, @files) = @_;
1761     my @result = ();
1762     my $nonansi_obj = $obj;
1763     $nonansi_obj =~ s/\$U//g;
1764     my %linkers_used = ();
1766     # Turn sources into objects.  We use a while loop like this
1767     # because we might add to @files in the loop.
1768     while (scalar @files > 0)
1769     {
1770         $_ = shift @files;
1772         # Configure substitutions in _SOURCES variables are errors.
1773         if (/^\@.*\@$/)
1774         {
1775             &am_line_error ($var, "$var includes configure substitution `$_'");
1776             next;
1777         }
1779         # If the source file is in a subdirectory then the `.o' is put
1780         # into the current directory, unless the subdir-objects option
1781         # is in effect.
1783         # Split file name into base and extension.
1784         next if ! /^(?:(.*)\/)?([^\/]*)\.(.*)$/;
1785         my $full = $_;
1786         my $directory = $1 || '';
1787         my $base = $2;
1788         my $extension = $3;
1790         # We must generate a rule for the object if it requires its own flags.
1791         my $renamed = 0;
1792         my ($linker, $object);
1794         # This records whether we've seen a derived source file (eg,
1795         # yacc output).
1796         my $derived_source = 0;
1798         # This holds the `aggregate context' of the file we are
1799         # currently examining.  If the file is compiled with
1800         # per-object flags, then it will be the name of the object.
1801         # Otherwise it will be `AM'.  This is used by the target hook
1802         # language function.
1803         my $aggregate = 'AM';
1805         $extension = &derive_suffix ($extension);
1806         my $lang;
1807         if ($extension_map{$extension} &&
1808             ($lang = $languages{$extension_map{$extension}}))
1809         {
1810             # Found the language, so see what it says.
1811             &saw_extension ($extension);
1813             # Note: computed subr call.  The language rewrite function
1814             # should return one of the $LANG_* constants.  It could
1815             # also return a list whose first value is such a constant
1816             # and whose second value is a new source extension which
1817             # should be applied.  This means this particular language
1818             # generates another source file which we must then process
1819             # further.
1820             my $subr = 'lang_' . $lang->name . '_rewrite';
1821             my ($r, $source_extension)
1822                 = & $subr ($directory, $base, $extension);
1823             # Skip this entry if we were asked not to process it.
1824             next if $r == $LANG_IGNORE;
1826             # Now extract linker and other info.
1827             $linker = $lang->linker;
1829             my $this_obj_ext;
1830             if (defined $source_extension)
1831             {
1832                 $this_obj_ext = '.' . $source_extension;
1833                 $derived_source = 1;
1834             }
1835             elsif ($lang->ansi)
1836             {
1837                 $this_obj_ext = $obj;
1838             }
1839             else
1840             {
1841                 $this_obj_ext = $nonansi_obj;
1842             }
1843             $object = $base . $this_obj_ext;
1845             if (defined $lang->flags
1846                 && &variable_defined ($derived . '_' . $lang->flags))
1847             {
1848                 # We have a per-executable flag in effect for this
1849                 # object.  In this case we rewrite the object's
1850                 # name to ensure it is unique.  We also require
1851                 # the `compile' program to deal with compilers
1852                 # where `-c -o' does not work.
1854                 # We choose the name `DERIVED_OBJECT' to ensure
1855                 # (1) uniqueness, and (2) continuity between
1856                 # invocations.  However, this will result in a
1857                 # name that is too long for losing systems, in
1858                 # some situations.  So we provide _SHORTNAME to
1859                 # override.
1861                 my $dname = $derived;
1862                 if (&variable_defined ($derived . '_SHORTNAME'))
1863                 {
1864                     # FIXME: should use the same conditional as
1865                     # the _SOURCES variable.  But this is really
1866                     # silly overkill -- nobody should have
1867                     # conditional shortnames.
1868                     $dname = &variable_value ($derived . '_SHORTNAME');
1869                 }
1870                 $object = $dname . '-' . $object;
1872                 &require_file ($FOREIGN, 'compile')
1873                     if $lang->name eq 'c';
1875                 &prog_error ("$lang->name flags defined without compiler")
1876                     if ! defined $lang->compile;
1878                 $renamed = 1;
1879             }
1881             # If rewrite said it was ok, put the object into a
1882             # subdir.
1883             if ($r == $LANG_SUBDIR && $directory ne '')
1884             {
1885                 $object = $directory . '/' . $object;
1886             }
1888             # If doing dependency tracking, then we can't print
1889             # the rule.  If we have a subdir object, we need to
1890             # generate an explicit rule.  Actually, in any case
1891             # where the object is not in `.' we need a special
1892             # rule.  The per-object rules in this case are
1893             # generated later, by handle_languages.
1894             if ($renamed || $directory ne '')
1895             {
1896                 my $obj_sans_ext = substr ($object, 0,
1897                                            - length ($this_obj_ext));
1898                 my $val = ("$full $obj_sans_ext "
1899                            # Only use $this_obj_ext in the derived
1900                            # source case because in the other case we
1901                            # *don't* want $(OBJEXT) to appear here.
1902                            . ($derived_source ? $this_obj_ext : '.o'));
1904                 # If we renamed the object then we want to use the
1905                 # per-executable flag name.  But if this is simply a
1906                 # subdir build then we still want to use the AM_ flag
1907                 # name.
1908                 if ($renamed)
1909                 {
1910                     $val = "$derived $val";
1911                     $aggregate = $derived;
1912                 }
1913                 else
1914                 {
1915                     $val = "AM $val";
1916                 }
1918                 # Each item on this list is a string consisting of
1919                 # four space-separated values: the derived flag prefix
1920                 # (eg, for `foo_CFLAGS', it is `foo'), the name of the
1921                 # source file, the base name of the output file, and
1922                 # the extension for the object file.
1923                 push (@{$lang_specific_files{$lang->name}}, $val);
1924             }
1925         }
1926         elsif ($extension eq 'o')
1927         {
1928             # This is probably the result of a direct suffix rule.
1929             # In this case we just accept the rewrite.  FIXME:
1930             # this fails if we want libtool objects.
1931             $object = $base . '.' . $extension;
1932             $linker = '';
1933         }
1934         else
1935         {
1936             # No error message here.  Used to have one, but it was
1937             # very unpopular.
1938             # FIXME: we could potentially do more processing here,
1939             # perhaps treating the new extension as though it were a
1940             # new source extension (as above).  This would require
1941             # more restructuring than is appropriate right now.
1942             next;
1943         }
1945         if (defined $object_map{$object})
1946         {
1947             if ($object_map{$object} ne $full)
1948             {
1949                 &am_error ("object `$object' created by `$full' and `$object_map{$object}'");
1950             }
1951         }
1953         # Let the language do some special magic if required.
1954         $lang->target_hook ($aggregate, $object, $full);
1956         if ($derived_source)
1957         {
1958             &prog_error ("$lang->name has automatic dependency tracking")
1959                 if $lang->autodep ne 'no';
1960             # Make sure this new source file is handled next.  That will
1961             # make it appear to be at the right place in the list.
1962             unshift (@files, $object);
1963             # FIXME: nodist.
1964             &push_dist_common ($object);
1965             next;
1966         }
1968         $linkers_used{$linker} = 1;
1970         push (@result, $object);
1972         if (! defined $object_map{$object})
1973         {
1974             my @dep_list = ();
1975             $object_map{$object} = $full;
1977             # If file is in subdirectory, we need explicit
1978             # dependency.
1979             if ($directory ne '' || $renamed)
1980             {
1981                 push (@dep_list, $full);
1982             }
1984             # If resulting object is in subdir, we need to make
1985             # sure the subdir exists at build time.
1986             if ($object =~ /\//)
1987             {
1988                 # FIXME: check that $DIRECTORY is somewhere in the
1989                 # project
1991                 # We don't allow `..' in object file names for
1992                 # *any* source, not just Java.  For Java it just
1993                 # doesn't make sense, but in general it is
1994                 # a problem because we can't pick a good name for
1995                 # the .deps entry.
1996                 if ($object =~ /(\/|^)\.\.\//)
1997                 {
1998                     &am_error ("`$full' contains `..' component but should not");
1999                 }
2001                 # Make sure object is removed by `make mostlyclean'.
2002                 $compile_clean_files{$object} = $MOSTLY_CLEAN;
2004                 push (@dep_list, $directory . '/.dirstamp');
2006                 # If we're generating dependencies, we also want
2007                 # to make sure that the appropriate subdir of the
2008                 # .deps directory is created.
2009                 if ($use_dependencies)
2010                 {
2011                     push (@dep_list, '.deps/' . $directory . '/.dirstamp');
2012                 }
2014                 if (! defined $directory_map{$directory})
2015                 {
2016                     $directory_map{$directory} = 1;
2018                     # Directory must be removed by `make distclean'.
2019                     $compile_clean_files{$directory . "/.dirstamp"} =
2020                         $DIST_CLEAN;
2021                     $output_rules .= ($directory . "/.dirstamp:\n"
2022                                       . "\t\@\$(mkinstalldirs) $directory\n"
2023                                       . "\t\@: > $directory/.dirstamp\n");
2024                     if ($use_dependencies)
2025                     {
2026                         $output_rules .= ('.deps/' . $directory
2027                                           . "/.dirstamp:\n"
2028                                           . "\t\@\$(mkinstalldirs) .deps/$directory\n"
2029                                           . "\t\@: > .deps/$directory/.dirstamp\n");
2030                     }
2031                 }
2032             }
2034             &pretty_print_rule ($object . ':', "\t", @dep_list)
2035                 if scalar @dep_list > 0;
2036         }
2038         # Transform .o or $o file into .P file (for automatic
2039         # dependency code).
2040         if ($lang && $lang->autodep ne 'no')
2041         {
2042             my $depfile = $object;
2043             $depfile =~ s/\.([^.]*)$/.P$1/;
2044             $depfile =~ s/\$\(OBJEXT\)$/o/;
2045             $dep_files{'$(DEPDIR)/' . $depfile} = 1;
2046         }
2047     }
2049     return (&resolve_linker (%linkers_used), @result);
2054 # Handle SOURCE->OBJECT transform for one program or library.
2055 # Arguments are:
2056 #   canonical (transformed) name of object to build
2057 #   actual name of object to build
2058 #   object extension (ie either `.o' or `$o'.
2059 # Return result is name of linker variable that must be used.
2060 # Empty return means just use `LINK'.
2061 sub handle_source_transform
2063     # one_file is canonical name.  unxformed is given name.  obj is
2064     # object extension.
2065     my ($one_file, $unxformed, $obj) = @_;
2067     my ($linker) = '';
2069     if (&variable_defined ($one_file . "_OBJECTS"))
2070     {
2071         &am_line_error ($one_file . '_OBJECTS',
2072                         $one_file . '_OBJECTS', 'should not be defined');
2073         # No point in continuing.
2074         return;
2075     }
2077     my %used_pfx = ();
2078     foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2079                         'dist_EXTRA_', 'nodist_EXTRA_')
2080     {
2081         my $var = $prefix . $one_file . "_SOURCES";
2082         next
2083           if !variable_defined ($var);
2085         # We are going to define _OBJECTS variables using the prefix.
2086         # Then we glom them all together.  So we can't use the null
2087         # prefix here as we need it later.
2088         my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2090         # Keep track of which prefixes we saw.
2091         $used_pfx{$xpfx} = 1
2092           unless $prefix =~ /EXTRA_/;
2094         push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
2095         push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
2096           unless $prefix =~ /^nodist_/;
2097         foreach my $cond (variable_conditions ($var))
2098           {
2099             my @files = &variable_value_as_list ($var, $cond);
2100             my ($temp, @result) =
2101               &handle_single_transform_list ($var, $one_file, $obj,
2102                                              @files);
2103             # If there are no files to compile, don't require a linker (yet).
2104             $linker ||= $temp
2105               if @files;
2107             # Define _OBJECTS conditionally.
2108             &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
2109                                      $cond, @result)
2110               unless $prefix =~ /EXTRA_/;
2111           }
2112     }
2114     my @keys = sort keys %used_pfx;
2115     if (scalar @keys == 0)
2116     {
2117         &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
2118         push (@sources, $unxformed . '.c');
2119         push (@dist_sources, $unxformed . '.c');
2121         my ($temp, @result) =
2122           &handle_single_transform_list ($one_file . '_SOURCES',
2123                                          $one_file, $obj,
2124                                          "$unxformed.c");
2125         $linker = $temp if $linker eq '';
2126         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
2127     }
2128     else
2129     {
2130         grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
2131         &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
2132     }
2134     # If we want to use `LINK' we must make sure it is defined.
2135     if ($linker eq '')
2136     {
2137         $need_link = 1;
2138     }
2140     return $linker;
2144 # handle_lib_objects ($XNAME, $VAR)
2145 # ---------------------------------
2146 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
2147 # Also, generate _DEPENDENCIES variable if appropriate.
2148 # Arguments are:
2149 #   transformed name of object being built, or empty string if no object
2150 #   name of _LDADD/_LIBADD-type variable to examine
2151 # Returns 1 if LIBOBJS seen, 0 otherwise.
2152 sub handle_lib_objects
2154     my ($xname, $var) = @_;
2156     &prog_error ("handle_lib_objects: $var undefined")
2157         if ! &variable_defined ($var);
2159     my $ret = 0;
2160     foreach my $cond (&variable_conditions ($var))
2161       {
2162         if (&handle_lib_objects_cond ($xname, $var, $cond))
2163           {
2164             $ret = 1;
2165           }
2166       }
2167     return $ret;
2170 # Subroutine of handle_lib_objects: handle a particular condition.
2171 sub handle_lib_objects_cond
2173     my ($xname, $var, $cond) = @_;
2175     # We recognize certain things that are commonly put in LIBADD or
2176     # LDADD.
2177     my @dep_list = ();
2179     my $seen_libobjs = 0;
2180     my $flagvar = 0;
2182     foreach my $lsearch (&variable_value_as_list ($var, $cond))
2183     {
2184         # Skip -lfoo and -Ldir; these are explicitly allowed.
2185         next if $lsearch =~ /^-[lL]/;
2186         if (! $flagvar && $lsearch =~ /^-/)
2187         {
2188             if ($var =~ /^(.*)LDADD$/)
2189             {
2190                 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
2191                 next if $lsearch =~ /^-dl(pre)?open$/;
2192                 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2193             }
2194             else
2195             {
2196                 # Only get this error once.
2197                 $flagvar = 1;
2198                 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2199             }
2200         }
2202         # Assume we have a file of some sort, and push it onto the
2203         # dependency list.  Autoconf substitutions are not pushed;
2204         # rarely is a new dependency substituted into (eg) foo_LDADD
2205         # -- but "bad things (eg -lX11) are routinely substituted.
2206         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2207         # and handled specially below.
2208         push (@dep_list, $lsearch)
2209             unless $lsearch =~ /^\@.*\@$/;
2211         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
2212         # means adding entries to dep_files.
2213         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
2214         {
2215             my $myobjext = ($1 ? 'l' : '') . 'o';
2217             push (@dep_list, $lsearch);
2218             $seen_libobjs = 1;
2219             if (! keys %libsources
2220                 && ! &variable_defined ($1 . 'LIBOBJS'))
2221             {
2222                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in `$configure_ac'");
2223             }
2225             foreach my $iter (keys %libsources)
2226             {
2227                 if ($iter =~ /\.([cly])$/)
2228                 {
2229                     &saw_extension ($1);
2230                     &saw_extension ('c');
2231                 }
2233                 if ($iter =~ /\.h$/)
2234                 {
2235                     &require_file_with_line ($var, $FOREIGN, $iter);
2236                 }
2237                 elsif ($iter ne 'alloca.c')
2238                 {
2239                     my $rewrite = $iter;
2240                     $rewrite =~ s/\.c$/.P$myobjext/;
2241                     $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
2242                     ($rewrite = $iter) =~ s/(\W)/\\$1/g;
2243                     $rewrite = "^" . $rewrite . "\$";
2244                     # Only require the file if it is not a built source.
2245                     if (! &variable_defined ('BUILT_SOURCES')
2246                         || ! grep (/$rewrite/,
2247                                    &variable_value_as_list ('BUILT_SOURCES',
2248                                                             'all')))
2249                     {
2250                         &require_file_with_line ($var, $FOREIGN, $iter);
2251                     }
2252                 }
2253             }
2254         }
2255         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
2256         {
2257             my $myobjext = ($1 ? 'l' : '') . 'o';
2259             push (@dep_list, $lsearch);
2260             &am_line_error ($var,
2261                             "\@$1" . "ALLOCA\@ seen but `AC_FUNC_ALLOCA' not in `$configure_ac'")
2262                 if ! defined $libsources{'alloca.c'};
2263             $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
2264             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
2265             &saw_extension ('c');
2266         }
2267     }
2269     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
2270     {
2271         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
2272     }
2274     return $seen_libobjs;
2277 # Canonicalize the input parameter
2278 sub canonicalize
2280     my ($string) = @_;
2281     $string =~ tr/A-Za-z0-9_\@/_/c;
2282     return $string;
2285 # Canonicalize a name, and check to make sure the non-canonical name
2286 # is never used.  Returns canonical name.  Arguments are name and a
2287 # list of suffixes to check for.
2288 sub check_canonical_spelling
2290     my ($name, @suffixes) = @_;
2292     my $xname = &canonicalize ($name);
2293     if ($xname ne $name)
2294     {
2295         foreach my $xt (@suffixes)
2296         {
2297             &am_line_error ("$name$xt",
2298                             "invalid variable `$name$xt'; "
2299                             . "should be `$xname$xt'")
2300                 if &variable_defined ("$name$xt");
2301         }
2302     }
2304     return $xname;
2308 # handle_compile ()
2309 # -----------------
2310 # Set up the compile suite.
2311 sub handle_compile ()
2313     return
2314       unless $get_object_extension_was_run;
2316     # Boilerplate.
2317     my $default_includes = '';
2318     if (! defined $options{'nostdinc'})
2319       {
2320         $default_includes = ' -I. -I$(srcdir)';
2322         if (&variable_defined ('CONFIG_HEADER'))
2323           {
2324             foreach my $hdr (split (' ', &variable_value ('CONFIG_HEADER')))
2325               {
2326                 $default_includes .= ' -I' . dirname ($hdr);
2327               }
2328           }
2329       }
2331     my (@mostly_rms, @dist_rms);
2332     foreach my $item (sort keys %compile_clean_files)
2333     {
2334         if ($compile_clean_files{$item} == $MOSTLY_CLEAN)
2335         {
2336             push (@mostly_rms, "\t-rm -f $item");
2337         }
2338         elsif ($compile_clean_files{$item} == $DIST_CLEAN)
2339         {
2340             push (@dist_rms, "\t-rm -f $item");
2341         }
2342         else
2343         {
2344             &prog_error ("invalid entry in \%compile_clean_files");
2345         }
2346     }
2348     my ($coms, $vars, $rules) =
2349       &file_contents_internal (1, "$libdir/am/compile.am",
2350                                ('DEFAULT_INCLUDES' => $default_includes,
2351                                 'MOSTLYRMS' => join ("\n", @mostly_rms),
2352                                 'DISTRMS' => join ("\n", @dist_rms)));
2353     $output_vars .= $vars;
2354     $output_rules .= "$coms$rules";
2356     # Check for automatic de-ANSI-fication.
2357     if (defined $options{'ansi2knr'})
2358       {
2359         if (! $am_c_prototypes)
2360           {
2361             &am_line_error ('AUTOMAKE_OPTIONS',
2362                             "option `ansi2knr' in use but `AM_C_PROTOTYPES' not in `$configure_ac'");
2363             &keyed_aclocal_warning ('AM_C_PROTOTYPES');
2364             # Only give this error once.
2365             $am_c_prototypes = 1;
2366           }
2368         # topdir is where ansi2knr should be.
2369         if ($options{'ansi2knr'} eq 'ansi2knr')
2370           {
2371             # Only require ansi2knr files if they should appear in
2372             # this directory.
2373             &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
2374                                      'ansi2knr.c', 'ansi2knr.1');
2376             # ansi2knr needs to be built before subdirs, so unshift it.
2377             unshift (@all, '$(ANSI2KNR)');
2378           }
2380         my $ansi2knr_dir = '';
2381         $ansi2knr_dir = dirname ($options{'ansi2knr'})
2382           if $options{'ansi2knr'} ne 'ansi2knr';
2384         $output_rules .= &file_contents ('ansi2knr',
2385                                          ('ANSI2KNR-DIR' => $ansi2knr_dir));
2387     }
2390 # handle_libtool ()
2391 # -----------------
2392 # Handle libtool rules.
2393 sub handle_libtool
2395     return unless $seen_libtool;
2397     # libtool requires some files, but only at top level.
2398     &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
2399                                        @libtoolize_files)
2400         if $relative_dir eq '.';
2402     # Output the libtool compilation rules.
2403     $output_rules .= &file_contents ('libtool');
2406 # handle_programs ()
2407 # ------------------
2408 # Handle C programs.
2409 sub handle_programs
2411     my @proglist = &am_install_var ('progs', 'PROGRAMS',
2412                                     'bin', 'sbin', 'libexec', 'pkglib',
2413                                     'noinst', 'check');
2414     return if ! @proglist;
2416     my $seen_libobjs = 0;
2417     foreach my $one_file (@proglist)
2418     {
2419         my $obj = &get_object_extension ($one_file);
2421         # Canonicalize names and check for misspellings.
2422         my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2423                                                '_SOURCES', '_OBJECTS',
2424                                                '_DEPENDENCIES');
2426         my $linker = &handle_source_transform ($xname, $one_file, $obj);
2428         my $xt = '';
2429         if (&variable_defined ($xname . "_LDADD"))
2430         {
2431             if (&handle_lib_objects ($xname, $xname . '_LDADD'))
2432             {
2433                 $seen_libobjs = 1;
2434             }
2435             $xt = '_LDADD';
2436         }
2437         else
2438         {
2439             # User didn't define prog_LDADD override.  So do it.
2440             &define_variable ($xname . '_LDADD', '$(LDADD)');
2442             # This does a bit too much work.  But we need it to
2443             # generate _DEPENDENCIES when appropriate.
2444             if (&variable_defined ('LDADD'))
2445             {
2446                 if (&handle_lib_objects ($xname, 'LDADD'))
2447                 {
2448                     $seen_libobjs = 1;
2449                 }
2450             }
2451             elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
2452             {
2453                 &define_variable ($xname . '_DEPENDENCIES', '');
2454             }
2455             $xt = '_SOURCES'
2456         }
2458         if (&variable_defined ($xname . '_LIBADD'))
2459         {
2460             &am_line_error ($xname . '_LIBADD',
2461                             "use `" . $xname . "_LDADD', not `"
2462                             . $xname . "_LIBADD'");
2463         }
2465         if (! &variable_defined ($xname . '_LDFLAGS'))
2466         {
2467             # Define the prog_LDFLAGS variable.
2468             &define_variable ($xname . '_LDFLAGS', '');
2469         }
2471         # Determine program to use for link.
2472         my $xlink;
2473         if (&variable_defined ($xname . '_LINK'))
2474         {
2475             $xlink = $xname . '_LINK';
2476         }
2477         else
2478         {
2479             $xlink = $linker ? $linker : 'LINK';
2480         }
2482         $output_rules .= &file_contents ('program',
2483                                          ('PROGRAM'  => $one_file,
2484                                           'XPROGRAM' => $xname,
2485                                           'XLINK'    => $xlink));
2486     }
2488     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD'))
2489     {
2490         $seen_libobjs = 1;
2491     }
2493     if ($seen_libobjs)
2494     {
2495         foreach my $one_file (@proglist)
2496         {
2497             my $xname = &canonicalize ($one_file);
2499             if (&variable_defined ($xname . '_LDADD'))
2500             {
2501                 &check_libobjs_sources ($xname, $xname . '_LDADD');
2502             }
2503             elsif (&variable_defined ('LDADD'))
2504             {
2505                 &check_libobjs_sources ($xname, 'LDADD');
2506             }
2507         }
2508     }
2512 # handle_libraries ()
2513 # -------------------
2514 # Handle libraries.
2515 sub handle_libraries
2517     my @liblist = &am_install_var ('libs', 'LIBRARIES',
2518                                    'lib', 'pkglib', 'noinst', 'check');
2519     return if ! @liblist;
2521     my %valid = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2522                                       'noinst', 'check');
2523     if (! defined $configure_vars{'RANLIB'})
2524     {
2525         foreach my $key (keys %valid)
2526         {
2527             if (&variable_defined ($key . '_LIBRARIES'))
2528             {
2529                 &am_line_error ($key . '_LIBRARIES', "library used but `RANLIB' not defined in `$configure_ac'");
2530                 # Only get this error once.  If this is ever printed,
2531                 # we have a bug.
2532                 $configure_vars{'RANLIB'} = 'BUG';
2533                 last;
2534             }
2535         }
2536     }
2538     my $seen_libobjs = 0;
2539     foreach my $onelib (@liblist)
2540     {
2541         # Check that the library fits the standard naming convention.
2542         if ($onelib !~ /^lib.*\.a$/)
2543         {
2544             # FIXME should put line number here.  That means mapping
2545             # from library name back to variable name.
2546             &am_error ("`$onelib' is not a standard library name");
2547         }
2549         my $obj = &get_object_extension ($onelib);
2551         # Canonicalize names and check for misspellings.
2552         my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2553                                               '_OBJECTS', '_DEPENDENCIES',
2554                                               '_AR');
2556         if (! &variable_defined ($xlib . '_AR'))
2557         {
2558             &define_variable ($xlib . '_AR', '$(AR) cru');
2559         }
2561         if (&variable_defined ($xlib . '_LIBADD'))
2562         {
2563             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2564             {
2565                 $seen_libobjs = 1;
2566             }
2567         }
2568         else
2569         {
2570             # Generate support for conditional object inclusion in
2571             # libraries.
2572             &define_variable ($xlib . "_LIBADD", '');
2573         }
2575         if (&variable_defined ($xlib . '_LDADD'))
2576         {
2577             &am_line_error ($xlib . '_LDADD',
2578                             "use `" . $xlib . "_LIBADD', not `"
2579                             . $xlib . "_LDADD'");
2580         }
2582         # Make sure we at look at this.
2583         &examine_variable ($xlib . '_DEPENDENCIES');
2585         &handle_source_transform ($xlib, $onelib, $obj);
2587         $output_rules .= &file_contents ('library',
2588                                          ('LIBRARY'  => $onelib,
2589                                           'XLIBRARY' => $xlib));
2590     }
2592     if ($seen_libobjs)
2593     {
2594         foreach my $onelib (@liblist)
2595         {
2596             my $xlib = &canonicalize ($onelib);
2597             if (&variable_defined ($xlib . '_LIBADD'))
2598             {
2599                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2600             }
2601         }
2602     }
2606 # handle_ltlibraries ()
2607 # ---------------------
2608 # Handle shared libraries.
2609 sub handle_ltlibraries
2611     my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2612                                    'noinst', 'lib', 'pkglib', 'check');
2613     return if ! @liblist;
2615     my %instdirs;
2616     my %valid = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2617                                       'noinst', 'check');
2619     foreach my $key (keys %valid)
2620     {
2621         if (&variable_defined ($key . '_LTLIBRARIES'))
2622         {
2623             if (!$seen_libtool)
2624             {
2625                 &am_line_error ($key . '_LTLIBRARIES', "library used but `LIBTOOL' not defined in `$configure_ac'");
2626                 # Only get this error once.  If this is ever printed,
2627                 # we have a bug.
2628                 $configure_vars{'LIBTOOL'} = 'BUG';
2629                 $seen_libtool = 1;
2630             }
2632             # Get the installation directory of each library.
2633             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
2634             {
2635                 if ($instdirs{$_})
2636                 {
2637                     &am_error ("`$_' is already going to be installed in `$instdirs{$_}'");
2638                 }
2639                 else
2640                 {
2641                     $instdirs{$_} = $key;
2642                 }
2643             }
2644         }
2645     }
2647     my $seen_libobjs = 0;
2648     foreach my $onelib (@liblist)
2649     {
2650         my $obj = &get_object_extension ($onelib);
2652         # Canonicalize names and check for misspellings.
2653         my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2654                                               '_SOURCES', '_OBJECTS',
2655                                               '_DEPENDENCIES');
2657         if (! &variable_defined ($xlib . '_LDFLAGS'))
2658         {
2659             # Define the lib_LDFLAGS variable.
2660             &define_variable ($xlib . '_LDFLAGS', '');
2661         }
2663         # Check that the library fits the standard naming convention.
2664         my $libname_rx = "^lib.*\.la";
2665         if ((&variable_defined ($xlib . '_LDFLAGS')
2666              && grep (/-module/, &variable_value_as_list ($xlib . '_LDFLAGS',
2667                                                           'all')))
2668             || (&variable_defined ('LDFLAGS')
2669                 && grep (/-module/, &variable_value_as_list ('LDFLAGS',
2670                                                              'all'))))
2671         {
2672                 # Relax name checking for libtool modules.
2673                 $libname_rx = "\.la";
2674         }
2675         if ($onelib !~ /$libname_rx$/)
2676         {
2677             # FIXME this should only be a warning for foreign packages
2678             # FIXME should put line number here.  That means mapping
2679             # from library name back to variable name.
2680             &am_error ("`$onelib' is not a standard libtool library name");
2681         }
2683         if (&variable_defined ($xlib . '_LIBADD'))
2684         {
2685             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2686             {
2687                 $seen_libobjs = 1;
2688             }
2689         }
2690         else
2691         {
2692             # Generate support for conditional object inclusion in
2693             # libraries.
2694             &define_variable ($xlib . "_LIBADD", '');
2695         }
2697         if (&variable_defined ($xlib . '_LDADD'))
2698         {
2699             &am_line_error ($xlib . '_LDADD',
2700                             "use `" . $xlib . "_LIBADD', not `"
2701                             . $xlib . "_LDADD'");
2702         }
2704         # Make sure we at look at this.
2705         &examine_variable ($xlib . '_DEPENDENCIES');
2707         my $linker = &handle_source_transform ($xlib, $onelib, $obj);
2709         # Determine program to use for link.
2710         my $xlink;
2711         if (&variable_defined ($xlib . '_LINK'))
2712         {
2713             $xlink = $xlib . '_LINK';
2714         }
2715         else
2716         {
2717             $xlink = $linker ? $linker : 'LINK';
2718         }
2720         my $rpath;
2721         if ($instdirs{$onelib} eq 'EXTRA'
2722             || $instdirs{$onelib} eq 'noinst'
2723             || $instdirs{$onelib} eq 'check')
2724         {
2725             # It's an EXTRA_ library, so we can't specify -rpath,
2726             # because we don't know where the library will end up.
2727             # The user probably knows, but generally speaking automake
2728             # doesn't -- and in fact configure could decide
2729             # dynamically between two different locations.
2730             $rpath = '';
2731         }
2732         else
2733         {
2734             $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
2735         }
2737         $output_rules .= &file_contents ('ltlibrary',
2738                                          ('LTLIBRARY'  => $onelib,
2739                                           'XLTLIBRARY' => $xlib,
2740                                           'RPATH'      => $rpath,
2741                                           'XLINK'      => $xlink));
2742     }
2744     if ($seen_libobjs)
2745     {
2746         foreach my $onelib (@liblist)
2747         {
2748             my $xlib = &canonicalize ($onelib);
2749             if (&variable_defined ($xlib . '_LIBADD'))
2750             {
2751                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2752             }
2753         }
2754     }
2757 # See if any _SOURCES variable were misspelled.  Also, make sure that
2758 # EXTRA_ variables don't contain configure substitutions.
2759 sub check_typos
2761     foreach my $varname (keys %var_value)
2762     {
2763         foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
2764                              '_DEPENDENCIES')
2765         {
2766             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
2767             {
2768                 &am_line_error ($varname,
2769                                 "invalid unused variable name: `$varname'");
2770             }
2771         }
2772     }
2775 # Handle scripts.
2776 sub handle_scripts
2778     # NOTE we no longer automatically clean SCRIPTS, because it is
2779     # useful to sometimes distribute scripts verbatim.  This happens
2780     # eg in Automake itself.
2781     &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2782                      'bin', 'sbin', 'libexec', 'pkgdata',
2783                      'noinst', 'check');
2785     my $scripts_installed = 0;
2786     # Set $scripts_installed if appropriate.  Make sure we only find
2787     # scripts which are actually installed -- this is why we can't
2788     # simply use the return value of am_install_var.
2789     my %valid = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
2790                                       'libexec', 'pkgdata',
2791                                       'noinst', 'check');
2792     foreach my $key (keys %valid)
2793     {
2794         if ($key ne 'noinst'
2795             && $key ne 'check'
2796             && &variable_defined ($key . '_SCRIPTS'))
2797         {
2798             $scripts_installed = 1;
2799             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
2800         }
2801     }
2805 # ($OUTFILE, $VFILE, @CLEAN_FILES)
2806 # &scan_texinfo_file ($FILENAME)
2807 # ------------------------------
2808 # $OUTFILE is the name of the info file produced by $FILENAME.
2809 # $VFILE is the name of the version.texi file used (empty if none).
2810 # @CLEAN_FILES is the list of by products (indexes etc.)
2811 sub scan_texinfo_file
2813     my ($filename) = @_;
2815     # These are always created, no matter whether indexes are used or not.
2816     my @clean_suffixes = ('aux', 'dvi', 'log', 'ps', 'toc',
2817                           # grep new.*index texinfo.tex
2818                           'cp', 'fn', 'ky', 'vr', 'tp', 'pg');
2820     # There are predefined indexes which don't follow the regular rules.
2821     my %predefined_index =
2822       (
2823        # cindex => *.cps
2824        'c' => 'cps', 'f' => 'fns', 'k' => 'kys',
2825        'v' => 'vrs', 't' => 'tps', 'p' => 'pgs'
2826       );
2828     # There are commands which include a hidden index command.
2829     my %hidden_index =
2830       (
2831        # deffn => *.fns.
2832        'fn' => 'fns',     'un' => 'fns',
2833        'typefn' => 'fns', 'typefun' => 'fns',
2834        'mac' => 'fns', 'spec' => 'fns',
2835        'op' => 'fns',  'typeop' => 'fns',
2836        'method' => 'fns', 'typemethod' => 'fns',
2838        'vr' => 'vrs', 'var' => 'vrs',
2839        'typevr' => 'vrs', 'typevar' => 'vrs',
2840        'opt' => 'vrs',
2841        'cv' => 'vrs',
2842        'ivar' => 'vrs', 'typeivar' => 'vrs',
2844        'tp' => 'tps'
2845       );
2847     # Indexes stored into another one.  In this case, the *.??s file
2848     # is not created.
2849     my @syncodeindexes = ();
2851     my $texi = new IO::File ("< $filename");
2852     if (! $texi)
2853       {
2854         &am_error ("couldn't open `$filename': $!");
2855         return '';
2856     }
2857     print "$me: reading $filename\n" if $verbose;
2859     my ($outfile, $vfile);
2860     while ($_ = $texi->getline)
2861     {
2862       if (/^\@setfilename +(\S+)/)
2863       {
2864         $outfile = $1;
2865         if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
2866           {
2867             &am_file_error ($filename, "$.: ",
2868                             "output `$outfile' has unrecognized extension");
2869             return;
2870           }
2871       }
2872       # A "version.texi" file is actually any file whose name
2873       # matches "vers*.texi".
2874       elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2875       {
2876         $vfile = $1;
2877       }
2879       # Try to find what are the indexes which are used.
2881       # Creating a new category of index.
2882       elsif (/^\@def(code)?index (\w+)/)
2883       {
2884         push @clean_suffixes, $2;
2885       }
2887       # Storing in a predefined index.
2888       elsif (/^\@([cfkvtp])index /)
2889       {
2890         push @clean_suffixes, $predefined_index{$1};
2891       }
2892       elsif (/^\@def(\w+) /)
2893       {
2894         push @clean_suffixes, $hidden_index{$1}
2895           if defined $hidden_index{$1};
2896       }
2898       # Merging an index into an another.
2899       elsif (/^\@syn(code)?index (\w+) (\w+)/)
2900       {
2901         push @syncodeindexes, "$2s";
2902         push @clean_suffixes, "$3s";
2903       }
2905     }
2906     $texi->close;
2908     if ($outfile eq '')
2909       {
2910         &am_error ("`$filename' missing \@setfilename");
2911         return;
2912       }
2914     my $infobase = basename ($filename);
2915     $infobase =~ s/\.te?xi(nfo)?$//;
2916     # FIXME: I don't understand why, but I can't use "$infobase.$_" => 1.
2917     my %clean_files = map { "$infobase" . ".$_" => 1 } @clean_suffixes;
2918     grep { delete $clean_files{"$infobase.$_"} } @syncodeindexes;
2919     return ($outfile, $vfile, (sort keys %clean_files));
2923 # ($DO-SOMETHING, $TEXICLEANS)
2924 # handle_texinfo_helper ()
2925 # -----------------
2926 # Handle all Texinfo source; helper for handle_texinfo
2927 sub handle_texinfo_helper
2929     &am_line_error ('TEXINFOS',
2930                     "`TEXINFOS' is an anachronism; use `info_TEXINFOS'")
2931         if &variable_defined ('TEXINFOS');
2932     return (0, '') if (! &variable_defined ('info_TEXINFOS')
2933                        && ! &variable_defined ('html_TEXINFOS'));
2935     if (&variable_defined ('html_TEXINFOS'))
2936     {
2937         &am_line_error ('html_TEXINFOS',
2938                         "HTML generation not yet supported");
2939         return (0, '');
2940     }
2942     my @texis = &variable_value_as_list ('info_TEXINFOS', 'all');
2944     my (@info_deps_list, @dvis_list, @texi_deps);
2945     my %versions;
2946     my $done = 0;
2947     my @texi_cleans;
2948     my $canonical;
2950     my %texi_suffixes;
2951     foreach my $info_cursor (@texis)
2952     {
2953         my $infobase = $info_cursor;
2954         $infobase =~ s/\.(txi|texinfo|texi)$//;
2956         if ($infobase eq $info_cursor)
2957         {
2958             # FIXME: report line number.
2959             &am_error ("texinfo file `$info_cursor' has unrecognized extension");
2960             next;
2961         }
2962         $texi_suffixes{$1} = 1;
2964         # If 'version.texi' is referenced by input file, then include
2965         # automatic versioning capability.
2966         my ($out_file, $vtexi, @clean_files) =
2967           &scan_texinfo_file ("$relative_dir/$info_cursor")
2968             or next;
2969         push (@texi_cleans, @clean_files);
2971         if ($vtexi)
2972         {
2973             &am_error ("`$vtexi', included in `$info_cursor', also included in `$versions{$vtexi}'")
2974                 if (defined $versions{$vtexi});
2975             $versions{$vtexi} = $info_cursor;
2977             # We number the stamp-vti files.  This is doable since the
2978             # actual names don't matter much.  We only number starting
2979             # with the second one, so that the common case looks nice.
2980             my $vti = ($done ? $done : 'vti');
2981             ++$done;
2983             # This is ugly, but it is our historical practice.
2984             if ($config_aux_dir_set_in_configure_in)
2985             {
2986                 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2987                                               'mdate-sh');
2988             }
2989             else
2990             {
2991                 &require_file_with_line ('info_TEXINFOS', $FOREIGN,
2992                                          'mdate-sh');
2993             }
2995             my $conf_dir;
2996             if ($config_aux_dir_set_in_configure_in)
2997             {
2998                 $conf_dir = $config_aux_dir;
2999                 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
3000             }
3001             else
3002             {
3003                 $conf_dir = '$(srcdir)/';
3004             }
3005             $output_rules .= &file_contents ('texi-vers',
3006                                              ('TEXI'  => $info_cursor,
3007                                               'VTI'   => $vti,
3008                                               'VTEXI' => $vtexi,
3009                                               'MDDIR' => $conf_dir));
3010         }
3012         # If user specified file_TEXINFOS, then use that as explicit
3013         # dependency list.
3014         @texi_deps = ();
3015         push (@texi_deps, $info_cursor);
3016         # Prefix with $(srcdir) because some version of make won't
3017         # work if the target has it and the dependency doesn't.
3018         push (@texi_deps, '$(srcdir)/' . $vtexi) if $vtexi;
3020         my $canonical = &canonicalize ($infobase);
3021         if (&variable_defined ($canonical . "_TEXINFOS"))
3022         {
3023             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
3024             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
3025         }
3027         $output_rules .= ("\n" . $out_file . ": "
3028                           . join (' ', @texi_deps)
3029                           . "\n" . $infobase . ".dvi: "
3030                           . join (' ', @texi_deps)
3031                           . "\n");
3033         push (@info_deps_list, $out_file);
3034         push (@dvis_list, $infobase . '.dvi');
3035     }
3037     # Handle location of texinfo.tex.
3038     my $need_texi_file = 0;
3039     my $texinfodir;
3040     if ($cygnus_mode)
3041     {
3042         $texinfodir = '$(top_srcdir)/../texinfo';
3043         &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3044     }
3045     elsif ($config_aux_dir_set_in_configure_in)
3046     {
3047         $texinfodir = $config_aux_dir;
3048         &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3049         $need_texi_file = 2; # so that we require_conf_file later
3050     }
3051     elsif (&variable_defined ('TEXINFO_TEX'))
3052     {
3053         # The user defined TEXINFO_TEX so assume he knows what he is
3054         # doing.
3055         $texinfodir = ('$(srcdir)/'
3056                        . dirname (&variable_value ('TEXINFO_TEX')));
3057     }
3058     else
3059     {
3060         $texinfodir = '$(srcdir)';
3061         $need_texi_file = 1;
3062     }
3064     foreach my $txsfx (sort keys %texi_suffixes)
3065     {
3066         $output_rules .= &file_contents ('texibuild',
3067                                          ('TEXINFODIR' => $texinfodir,
3068                                           'SUFFIX'     => $txsfx));
3069     }
3071     # The return value.
3072     my $texiclean = &pretty_print_internal ("", "\t  ", @texi_cleans);
3074     push (@dist_targets, 'dist-info');
3076     if (! defined $options{'no-installinfo'})
3077     {
3078         # Make sure documentation is made and installed first.  Use
3079         # $(INFO_DEPS), not 'info', because otherwise recursive makes
3080         # get run twice during "make all".
3081         unshift (@all, '$(INFO_DEPS)');
3082     }
3084     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
3085     &define_variable ("DVIS", join (' ', @dvis_list));
3086     # This next isn't strictly needed now -- the places that look here
3087     # could easily be changed to look in info_TEXINFOS.  But this is
3088     # probably better, in case noinst_TEXINFOS is ever supported.
3089     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
3091     # Do some error checking.  Note that this file is not required
3092     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3093     # up above.
3094     if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
3095     {
3096         if ($need_texi_file > 1)
3097         {
3098             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
3099                                           'texinfo.tex');
3100         }
3101         else
3102         {
3103             &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
3104         }
3105     }
3107     return (1, $texiclean);
3110 # handle_texinfo ()
3111 # -----------------
3112 # Handle all Texinfo source.
3113 sub handle_texinfo
3115     my ($do_something, $texiclean) = handle_texinfo_helper ();
3116     $output_rules .=  &file_contents ('texinfos',
3117                                       ('TEXICLEAN' => $texiclean,
3118                                        'LOCAL-TEXIS' => $do_something));
3121 # Handle any man pages.
3122 sub handle_man_pages
3124     &am_line_error ('MANS', "`MANS' is an anachronism; use `man_MANS'")
3125         if &variable_defined ('MANS');
3127     # Find all the sections in use.  We do this by first looking for
3128     # "standard" sections, and then looking for any additional
3129     # sections used in man_MANS.
3130     my (%sections, %vlist);
3131     # We handle nodist_ for uniformity.  man pages aren't distributed
3132     # by default so it isn't actually very important.
3133     foreach my $pfx ('', 'dist_', 'nodist_')
3134     {
3135         # Add more sections as needed.
3136         foreach my $section ('0'..'9', 'n', 'l')
3137         {
3138             if (&variable_defined ($pfx . 'man' . $section . '_MANS'))
3139             {
3140                 $sections{$section} = 1;
3141                 $vlist{'$(' . $pfx . 'man' . $section . '_MANS)'} = 1;
3143                 &push_dist_common ('$(' . $pfx . 'man' . $section . '_MANS)')
3144                     if $pfx eq 'dist_';
3145             }
3146         }
3148         if (&variable_defined ($pfx . 'man_MANS'))
3149         {
3150             $vlist{'$(' . $pfx . 'man_MANS)'} = 1;
3151             foreach (&variable_value_as_list ($pfx . 'man_MANS', 'all'))
3152             {
3153                 # A page like `foo.1c' goes into man1dir.
3154                 if (/\.([0-9a-z])([a-z]*)$/)
3155                 {
3156                     $sections{$1} = 1;
3157                 }
3158             }
3160             &push_dist_common ('$(' . $pfx . 'man_MANS)')
3161                 if $pfx eq 'dist_';
3162         }
3163     }
3165     return unless %sections;
3167     # Now for each section, generate an install and unintall rule.
3168     # Sort sections so output is deterministic.
3169     foreach my $section (sort keys %sections)
3170     {
3171         $output_rules .= &file_contents ('mans', ('SECTION' => $section));
3172     }
3174     $output_vars .= &file_contents ('mans-vars',
3175                                     ('MANS' => join (' ', sort keys %vlist)));
3177     if (! defined $options{'no-installman'})
3178     {
3179         push (@all, '$(MANS)');
3180     }
3183 # Handle DATA variables.
3184 sub handle_data
3186     &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3187                      'data', 'sysconf', 'sharedstate', 'localstate',
3188                      'pkgdata', 'noinst', 'check');
3191 # Handle TAGS.
3192 sub handle_tags
3194     my @tag_deps = ();
3195     if (&variable_defined ('SUBDIRS'))
3196     {
3197         $output_rules .= ("tags-recursive:\n"
3198                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3199                           # Never fail here if a subdir fails; it
3200                           # isn't important.
3201                           . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
3202                           . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3203                           . "\tdone\n");
3204         push (@tag_deps, 'tags-recursive');
3205         &depend ('.PHONY', 'tags-recursive');
3206     }
3208     if (&saw_sources_p (1)
3209         || &variable_defined ('ETAGS_ARGS')
3210         || @tag_deps)
3211     {
3212         my $config = '';
3213         foreach my $one_hdr (@config_headers)
3214         {
3215             if ($relative_dir eq dirname ($one_hdr))
3216             {
3217                 # The config header is in this directory.  So require it.
3218                 $config .= ' ' if $config;
3219                 $config .= basename ($one_hdr);
3220             }
3221         }
3222         $output_rules .= &file_contents ('tags',
3223                                          ('CONFIG' => $config,
3224                                           'DIRS'   => join (' ', @tag_deps)));
3225         &examine_variable ('TAGS_DEPENDENCIES');
3226     }
3227     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
3228     {
3229         &am_line_error ('TAGS_DEPENDENCIES',
3230                         "doesn't make sense to define `TAGS_DEPENDENCIES' without sources or `ETAGS_ARGS'");
3231     }
3232     else
3233     {
3234         # Every Makefile must define some sort of TAGS rule.
3235         # Otherwise, it would be possible for a top-level "make TAGS"
3236         # to fail because some subdirectory failed.
3237         $output_rules .= "tags: TAGS\nTAGS:\n\n";
3238     }
3241 # Handle multilib support.
3242 sub handle_multilib
3244     if ($seen_multilib && $relative_dir eq '.')
3245     {
3246         $output_rules .= &file_contents ('multilib');
3247     }
3251 # $BOOLEAN
3252 # &for_dist_common ($A, $B)
3253 # -------------------------
3254 # Subroutine for &handle_dist: sort files to dist.
3256 # We put README first because it then becomes easier to make a
3257 # Usenet-compliant shar file (in these, README must be first).
3259 # FIXME: do more ordering of files here.
3260 sub for_dist_common
3262     return 0
3263         if $a eq $b;
3264     return -1
3265         if $a eq 'README';
3266     return 1
3267         if $b eq 'README';
3268     return $a cmp $b;
3272 # handle_dist ($MAKEFILE)
3273 # -----------------------
3274 # Handle 'dist' target.
3275 sub handle_dist
3277     my ($makefile) = @_;
3279     # `make dist' isn't used in a Cygnus-style tree.
3280     # Omit the rules so that people don't try to use them.
3281     return if $cygnus_mode;
3283     # Look for common files that should be included in distribution.
3284     foreach my $cfile (@common_files)
3285     {
3286         if (-f ($relative_dir . "/" . $cfile))
3287         {
3288             &push_dist_common ($cfile);
3289         }
3290     }
3292     # We might copy elements from $configure_dist_common to
3293     # %dist_common if we think we need to.  If the file appears in our
3294     # directory, we would have discovered it already, so we don't
3295     # check that.  But if the file is in a subdir without a Makefile,
3296     # we want to distribute it here if we are doing `.'.  Ugly!
3297     if ($relative_dir eq '.')
3298     {
3299        foreach my $file (split (' ' , $configure_dist_common))
3300        {
3301            if (! &is_make_dir (dirname ($file)))
3302            {
3303                &push_dist_common ($file);
3304            }
3305        }
3306     }
3310     # Files to distributed.  Don't use &variable_value_as_list
3311     # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3312     check_variable_defined_unconditionally ('DIST_COMMON');
3313     my @dist_common = split (' ', variable_value ('DIST_COMMON', 'TRUE'));
3314     @dist_common = uniq (sort for_dist_common (@dist_common));
3315     pretty_print ('DIST_COMMON = ', "\t", @dist_common);
3317     # Now that we've processed DIST_COMMON, disallow further attempts
3318     # to set it.
3319     $handle_dist_run = 1;
3321     # Scan EXTRA_DIST to see if we need to distribute anything from a
3322     # subdir.  If so, add it to the list.  I didn't want to do this
3323     # originally, but there were so many requests that I finally
3324     # relented.
3325     if (&variable_defined ('EXTRA_DIST'))
3326     {
3327         # FIXME: This should be fixed to work with conditionals.  That
3328         # will require only making the entries in %dist_dirs under the
3329         # appropriate condition.  This is meaningful if the nature of
3330         # the distribution should depend upon the configure options
3331         # used.
3332         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
3333         {
3334             next if /^\@.*\@$/;
3335             next unless s,/+[^/]+$,,;
3336             $dist_dirs{$_} = 1
3337                 unless $_ eq '.';
3338         }
3339     }
3341     # We have to check DIST_COMMON for extra directories in case the
3342     # user put a source used in AC_OUTPUT into a subdir.
3343     foreach (&variable_value_as_list ('DIST_COMMON', 'all'))
3344     {
3345         next if /^\@.*\@$/;
3346         next unless s,/+[^/]+$,,;
3347         $dist_dirs{$_} = 1
3348             unless $_ eq '.';
3349     }
3351     # Rule to check whether a distribution is viable.
3352     my %transform = ('DISTCHECK-HOOK' => &target_defined ('distcheck-hook'),
3353                      'GETTEXT'        => $seen_gettext);
3355     # Prepend $(distdir) to each directory given.
3356     my %rewritten = map { '$(distdir)/' . "$_" => 1 } keys %dist_dirs;
3357     $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);
3359     # If we have SUBDIRS, create all dist subdirectories and do
3360     # recursive build.
3361     if (&variable_defined ('SUBDIRS'))
3362     {
3363         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3364         # to all possible directories, and use it.  If DIST_SUBDIRS is
3365         # defined, just use it.
3366         my $dist_subdir_name;
3367         # Note that we check DIST_SUBDIRS first on purpose.  At least
3368         # one project uses so many conditional subdirectories that
3369         # calling variable_conditionally_defined on SUBDIRS will cause
3370         # automake to grow to 150Mb.  Sigh.
3371         if (&variable_defined ('DIST_SUBDIRS')
3372             || variable_conditionally_defined ('SUBDIRS'))
3373         {
3374             $dist_subdir_name = 'DIST_SUBDIRS';
3375             if (! &variable_defined ('DIST_SUBDIRS'))
3376             {
3377                 &define_pretty_variable
3378                   ('DIST_SUBDIRS', '',
3379                    uniq (&variable_value_as_list ('SUBDIRS', 'all')));
3380             }
3381         }
3382         else
3383         {
3384             $dist_subdir_name = 'SUBDIRS';
3385             # We always define this because that is what `distclean'
3386             # wants.
3387             &define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
3388         }
3390         $transform{'DIST_SUBDIR_NAME'} = $dist_subdir_name;
3391     }
3393     # If the target `dist-hook' exists, make sure it is run.  This
3394     # allows users to do random weird things to the distribution
3395     # before it is packaged up.
3396     push (@dist_targets, 'dist-hook')
3397       if &target_defined ('dist-hook');
3398     $transform{'DIST-TARGETS'} = join(' ', @dist_targets);
3400     # Defining $(DISTDIR).
3401     $transform{'DISTDIR'} = !&variable_defined('distdir');
3402     $transform{'TOP_DISTDIR'} = backname ($relative_dir);
3404     $output_rules .= &file_contents ('distdir', %transform);
3408 # Handle subdirectories.
3409 sub handle_subdirs
3411     return
3412       unless &variable_defined ('SUBDIRS');
3414     # Make sure each directory mentioned in SUBDIRS actually exists.
3415     foreach my $dir (&variable_value_as_list ('SUBDIRS', 'all'))
3416     {
3417         # Skip directories substituted by configure.
3418         next if $dir =~ /^\@.*\@$/;
3420         if (! -d $am_relative_dir . '/' . $dir)
3421         {
3422             &am_line_error ('SUBDIRS',
3423                             "required directory $am_relative_dir/$dir does not exist");
3424             next;
3425         }
3427         &am_line_error ('SUBDIRS', "directory should not contain `/'")
3428             if $dir =~ /\//;
3429     }
3431     $output_rules .= &file_contents ('subdirs');
3432     variable_pretty_output ('RECURSIVE_TARGETS', 'TRUE');
3436 # ($REGEN, @DEPENDENCIES)
3437 # &scan_aclocal_m4
3438 # ----------------
3439 # If aclocal.m4 creation is automated, return the list of its dependencies.
3440 sub scan_aclocal_m4
3442     my $regen_aclocal = 0;
3444     return (0, ())
3445       unless $relative_dir eq '.';
3447     &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3448     &examine_variable ('CONFIGURE_DEPENDENCIES');
3450     if (-f 'aclocal.m4')
3451     {
3452         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3453         &push_dist_common ('aclocal.m4');
3455         my $aclocal = new IO::File ("< aclocal.m4");
3456         if ($aclocal)
3457         {
3458             my $line = $aclocal->getline;
3459             $aclocal->close;
3461             if ($line =~ 'generated automatically by aclocal')
3462             {
3463                 $regen_aclocal = 1;
3464             }
3465         }
3466     }
3468     my @ac_deps = ();
3470     if (-f 'acinclude.m4')
3471     {
3472         $regen_aclocal = 1;
3473         push @ac_deps, 'acinclude.m4';
3474     }
3476     if (&variable_defined ('ACLOCAL_M4_SOURCES'))
3477     {
3478         push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3479     }
3480     elsif (&variable_defined ('ACLOCAL_AMFLAGS'))
3481     {
3482         # Scan all -I directories for m4 files.  These are our
3483         # dependencies.
3484         my $examine_next = 0;
3485         foreach my $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
3486         {
3487             if ($examine_next)
3488             {
3489                 $examine_next = 0;
3490                 if ($amdir !~ /^\// && -d $amdir)
3491                 {
3492                     foreach my $ac_dep (&my_glob ($amdir . '/*.m4'))
3493                     {
3494                         $ac_dep =~ s/^\.\/+//;
3495                         push (@ac_deps, $ac_dep)
3496                           unless $ac_dep eq "aclocal.m4"
3497                             || $ac_dep eq "acinclude.m4";
3498                     }
3499                 }
3500             }
3501             elsif ($amdir eq '-I')
3502             {
3503                 $examine_next = 1;
3504             }
3505         }
3506     }
3508     # Note that it might be possible that aclocal.m4 doesn't exist but
3509     # should be auto-generated.  This case probably isn't very
3510     # important.
3512     return ($regen_aclocal, @ac_deps);
3515 # Rewrite a list of input files into a form suitable to put on a
3516 # dependency list.  The idea is that if an input file has a directory
3517 # part the same as the current directory, then the directory part is
3518 # simply removed.  But if the directory part is different, then
3519 # $(top_srcdir) is prepended.  Among other things, this is used to
3520 # generate the dependency list for the output files generated by
3521 # AC_OUTPUT.  Consider what the dependencies should look like in this
3522 # case:
3523 #   AC_OUTPUT(src/out:src/in1:lib/in2)
3524 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3525 # If 0 then files that require this addition will simply be ignored.
3526 sub rewrite_inputs_into_dependencies
3528     my ($add_srcdir, @inputs) = @_;
3529     my @newinputs;
3531     foreach my $single (@inputs)
3532     {
3533         if (dirname ($single) eq $relative_dir)
3534         {
3535             push (@newinputs, basename ($single));
3536         }
3537         elsif ($add_srcdir)
3538         {
3539             push (@newinputs, '$(top_srcdir)/' . $single);
3540         }
3541     }
3543     return @newinputs;
3546 # Handle remaking and configure stuff.
3547 # We need the name of the input file, to do proper remaking rules.
3548 sub handle_configure
3550     my ($local, $input, @secondary_inputs) = @_;
3552     my $input_base = basename ($input);
3553     my $local_base = basename ($local);
3555     my $amfile = $input_base . '.am';
3556     # We know we can always add '.in' because it really should be an
3557     # error if the .in was missing originally.
3558     my $infile = '$(srcdir)/' . $input_base . '.in';
3559     my $colon_infile = '';
3560     if ($local ne $input || @secondary_inputs)
3561     {
3562         $colon_infile = ':' . $input . '.in';
3563     }
3564     $colon_infile .= ':' . join (':', @secondary_inputs)
3565         if @secondary_inputs;
3567     my @rewritten = &rewrite_inputs_into_dependencies (1, @secondary_inputs);
3569     my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4 ();
3571     $output_rules .=
3572       &file_contents ('configure',
3573                       ('MAKEFILE'
3574                        => $local_base,
3575                        'MAKEFILE-DEPS'
3576                        => join (' ', @rewritten),
3577                        'CONFIG-MAKEFILE'
3578                        => ((($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3579                            . $colon_infile),
3580                        'MAKEFILE-IN'
3581                        => $infile,
3582                        'MAKEFILE-IN-DEPS'
3583                        => join (' ', @include_stack),
3584                        'MAKEFILE-AM'
3585                        => $amfile,
3586                        'STRICTNESS'
3587                        => $cygnus_mode ? 'cygnus' : $strictness_name,
3588                        'USE-DEPS'
3589                        => $cmdline_use_dependencies ? '' : ' --ignore-deps',
3590                        'MAKEFILE-AM-SOURCES'
3591                        =>  "$input$colon_infile",
3592                        'REGEN-ACLOCAL-M4'
3593                        => $regen_aclocal_m4,
3594                        'ACLOCAL_M4_DEPS'
3595                        => join (' ', @aclocal_m4_deps)));
3597     if ($relative_dir eq '.')
3598     {
3599         &push_dist_common ('acconfig.h')
3600             if -f 'acconfig.h';
3601     }
3603     # If we have a configure header, require it.
3604     my @local_fullnames = @config_fullnames;
3605     my @local_names = @config_names;
3606     my $hdr_index = 0;
3607     my $distclean_config = '';
3608     foreach my $one_hdr (@config_headers)
3609     {
3610         my $one_fullname = shift (@local_fullnames);
3611         my $one_name = shift (@local_names);
3612         $hdr_index += 1;
3613         my $header_dir = dirname ($one_name);
3615         # If the header is in the current directory we want to build
3616         # the header here.  Otherwise, if we're at the topmost
3617         # directory and the header's directory doesn't have a
3618         # Makefile, then we also want to build the header.
3619         if ($relative_dir eq $header_dir
3620             || ($relative_dir eq '.' && ! &is_make_dir ($header_dir)))
3621         {
3622             my ($cn_sans_dir, $stamp_dir);
3623             if ($relative_dir eq $header_dir)
3624             {
3625                 $cn_sans_dir = basename ($one_name);
3626                 $stamp_dir = '';
3627             }
3628             else
3629             {
3630                 $cn_sans_dir = $one_name;
3631                 if ($header_dir eq '.')
3632                 {
3633                     $stamp_dir = '';
3634                 }
3635                 else
3636                 {
3637                     $stamp_dir = $header_dir . '/';
3638                 }
3639             }
3641             # Compute relative path from directory holding output
3642             # header to directory holding input header.  FIXME:
3643             # doesn't handle case where we have multiple inputs.
3644             my $ch_sans_dir;
3645             if (dirname ($one_hdr) eq $relative_dir)
3646             {
3647                 $ch_sans_dir = basename ($one_hdr);
3648             }
3649             else
3650             {
3651                 $ch_sans_dir = backname ($relative_dir) . '/' . $one_hdr;
3652             }
3654             &require_file_with_conf_line ($config_header_line,
3655                                           $FOREIGN, $ch_sans_dir);
3657             # Header defined and in this directory.
3658             my @files;
3659             if (-f $one_name . '.top')
3660             {
3661                 push (@files, "${cn_sans_dir}.top");
3662             }
3663             if (-f $one_name . '.bot')
3664             {
3665                 push (@files, "${cn_sans_dir}.bot");
3666             }
3668             &push_dist_common (@files);
3670             # For now, acconfig.h can only appear in the top srcdir.
3671             if (-f 'acconfig.h')
3672             {
3673                 push (@files, '$(top_srcdir)/acconfig.h');
3674             }
3676             my $stamp_name = 'stamp-h';
3677             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3679             my $out_dir = dirname ($ch_sans_dir);
3681             $output_rules .=
3682               &file_contents ('remake-hdr',
3683                               ('FILES'              => join (' ', @files),
3684                                'CONFIG_HEADER'      => $cn_sans_dir,
3685                                'CONFIG_HEADER_IN'   => $ch_sans_dir,
3686                                'CONFIG_HEADER_FULL' => $one_fullname,
3687                                'STAMP'            => "$stamp_dir$stamp_name",
3688                                'SRC_STAMP'        => "$out_dir/$stamp_name"));
3690             &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3691             &require_file_with_conf_line ($config_header_line, $FOREIGN,
3692                                           "${out_dir}/${stamp_name}.in");
3694             $distclean_config .= ' ' if $distclean_config;
3695             $distclean_config .= $cn_sans_dir;
3696         }
3697     }
3699     if ($distclean_config)
3700     {
3701         $output_rules .= &file_contents ('clean-hdr',
3702                                          ('FILES' => $distclean_config));
3703     }
3705     # Set location of mkinstalldirs.
3706     &define_variable ('mkinstalldirs',
3707                       ('$(SHELL) ' . $config_aux_dir . '/mkinstalldirs'));
3709     &am_line_error ('CONFIG_HEADER',
3710                     "`CONFIG_HEADER' is an anachronism; now determined from `$configure_ac'")
3711         if &variable_defined ('CONFIG_HEADER');
3713     my $config_header = '';
3714     foreach my $one_name (@config_names)
3715     {
3716         # Generate CONFIG_HEADER define.
3717         my $one_hdr;
3718         if ($relative_dir eq dirname ($one_name))
3719         {
3720             $one_hdr = basename ($one_name);
3721         }
3722         else
3723         {
3724             $one_hdr = "\$(top_builddir)/${one_name}";
3725         }
3727         $config_header .= ' ' if $config_header;
3728         $config_header .= $one_hdr;
3729     }
3730     if ($config_header)
3731     {
3732         &define_variable ("CONFIG_HEADER", $config_header);
3733     }
3735     # Now look for other files in this directory which must be remade
3736     # by config.status, and generate rules for them.
3737     my @actual_other_files = ();
3738     foreach my $lfile (@other_input_files)
3739     {
3740         my ($file, $local);
3741         my (@inputs, @rewritten_inputs);
3742         my ($need_rewritten);
3743         if ($lfile =~ /^([^:]*):(.*)$/)
3744         {
3745             # This is the ":" syntax of AC_OUTPUT.
3746             $file = $1;
3747             $local = basename ($file);
3748             @inputs = split (':', $2);
3749             @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3750             $need_rewritten = 1;
3751         }
3752         else
3753         {
3754             # Normal usage.
3755             $file = $lfile;
3756             $local = basename ($file);
3757             @inputs = ($file . '.in');
3758             @rewritten_inputs =
3759                 &rewrite_inputs_into_dependencies (1, @inputs);
3760             $need_rewritten = 0;
3761         }
3763         # Make sure the dist directory for each input file is created.
3764         # We only have to do this at the topmost level though.  This
3765         # is a bit ugly but it easier than spreading out the logic,
3766         # especially in cases like AC_OUTPUT(foo/out:bar/in), where
3767         # there is no Makefile in bar/.
3768         if ($relative_dir eq '.')
3769         {
3770             foreach (@inputs)
3771             {
3772                 $dist_dirs{dirname ($_)} = 1;
3773             }
3774         }
3776         # We skip any automake input files, as they are handled
3777         # elsewhere.  We also skip files that aren't in this
3778         # directory.  However, if the file's directory does not have a
3779         # Makefile, and we are currently doing `.', then we create a
3780         # rule to rebuild the file in the subdir.
3781         next if -f $file . '.am';
3782         my $fd = dirname ($file);
3783         if ($fd ne $relative_dir)
3784         {
3785             if ($relative_dir eq '.' && ! &is_make_dir ($fd))
3786             {
3787                 $local = $file;
3788             }
3789             else
3790             {
3791                 next;
3792             }
3793         }
3795         # Some users have been tempted to put `stamp-h' in the
3796         # AC_OUTPUT line.  This won't do the right thing, so we
3797         # explicitly fail here.
3798         if ($local eq 'stamp-h')
3799         {
3800             # FIXME: allow real filename.
3801             &am_conf_error ($configure_ac, $ac_output_line,
3802                             'stamp-h should not appear in AC_OUTPUT');
3803             next;
3804         }
3806         $output_rules .= ($local . ': '
3807                           . '$(top_builddir)/config.status '
3808                           . join (' ', @rewritten_inputs) . "\n"
3809                           . "\t"
3810                           . 'cd $(top_builddir) && CONFIG_FILES='
3811                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3812                           . '$@' . ($need_rewritten
3813                                     ? (':' . join (':', @inputs))
3814                                     : '')
3815                           . ' CONFIG_HEADERS= CONFIG_LINKS= $(SHELL) ./config.status'
3816                           . "\n");
3817         push (@actual_other_files, $local);
3819         # Require all input files.
3820         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3821                                       &rewrite_inputs_into_dependencies (0, @inputs));
3822     }
3824     # These files get removed by "make clean".
3825     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3828 # Handle C headers.
3829 sub handle_headers
3831     my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3832                              'oldinclude', 'pkginclude',
3833                              'noinst', 'check');
3834     foreach (@r)
3835     {
3836         next unless /\.(.*)$/;
3837         &saw_extension ($1);
3838     }
3841 sub handle_gettext
3843     return if ! $seen_gettext || $relative_dir ne '.';
3845     if (! &variable_defined ('SUBDIRS'))
3846     {
3847         &am_conf_error
3848             ("AM_GNU_GETTEXT used but SUBDIRS not defined");
3849         return;
3850     }
3852     my @subdirs = &variable_value_as_list ('SUBDIRS', 'all');
3853     &am_line_error ('SUBDIRS',
3854                     "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
3855         if ! grep ('po', @subdirs);
3856     &am_line_error ('SUBDIRS',
3857                     "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
3858         if ! grep ('intl', @subdirs);
3860     &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3862     # Ensure that each language in ALL_LINGUAS has a .po file, and
3863     # each po file is mentioned in ALL_LINGUAS.
3864     if ($seen_linguas)
3865     {
3866         my %linguas = map { $_ => 1 } split (' ', $all_linguas);
3868         foreach (<po/*.po>)
3869         {
3870             s/^po\///;
3871             s/\.po$//;
3873             &am_line_error ($all_linguas_line,
3874                             ("po/$_.po exists but `$_' not in `ALL_LINGUAS'"))
3875                 if ! $linguas{$_};
3876         }
3878         foreach (keys %linguas)
3879         {
3880             &am_line_error ($all_linguas_line,
3881                             "$_ in `ALL_LINGUAS' but po/$_.po does not exist")
3882                 if ! -f "po/$_.po";
3883         }
3884     }
3885     else
3886     {
3887         &am_error ("AM_GNU_GETTEXT in `$configure_ac' but `ALL_LINGUAS' not defined");
3888     }
3891 # Handle footer elements.
3892 sub handle_footer
3894     # NOTE don't use define_pretty_variable here, because
3895     # $contents{...} is already defined.
3896     $output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n\n"
3897       if variable_value ('SOURCES');
3900     &am_line_error ('.SUFFIXES',
3901                     "use variable `SUFFIXES', not target `.SUFFIXES'")
3902       if target_defined ('.SUFFIXES');
3904     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3905     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3906     # anything else, by sticking it right after the default: target.
3907     $output_header .= ".SUFFIXES:\n";
3908     if (@suffixes || &variable_defined ('SUFFIXES'))
3909     {
3910         # Make sure suffixes has unique elements.  Sort them to ensure
3911         # the output remains consistent.  However, $(SUFFIXES) is
3912         # always at the start of the list, unsorted.  This is done
3913         # because make will choose rules depending on the ordering of
3914         # suffixes, and this lets the user have some control.  Push
3915         # actual suffixes, and not $(SUFFIXES).  Some versions of make
3916         # do not like variable substitutions on the .SUFFIXES line.
3917         my @user_suffixes = (&variable_defined ('SUFFIXES')
3918                              ? &variable_value_as_list ('SUFFIXES', '')
3919                              : ());
3921         my %suffixes = map { $_ => 1 } @suffixes;
3922         delete @suffixes{@user_suffixes};
3924         $output_header .= (".SUFFIXES: "
3925                            . join (' ', @user_suffixes, sort keys %suffixes)
3926                            . "\n");
3927     }
3929     $output_trailer .= file_contents ('footer');
3932 # Deal with installdirs target.
3933 sub handle_installdirs ()
3935     $output_rules .=
3936       &file_contents ('install',
3937                       ('_am_installdirs'
3938                        => variable_value ('_am_installdirs') || ''));
3942 # Deal with all and all-am.
3943 sub handle_all ($)
3945     my ($makefile) = @_;
3947     # Output `all-am'.
3949     # Put this at the beginning for the sake of non-GNU makes.  This
3950     # is still wrong if these makes can run parallel jobs.  But it is
3951     # right enough.
3952     unshift (@all, basename ($makefile));
3954     foreach my $one_name (@config_names)
3955     {
3956         push (@all, basename ($one_name))
3957             if dirname ($one_name) eq $relative_dir;
3958     }
3960     # Install `all' hooks.
3961     if (&target_defined ("all-local"))
3962     {
3963       push (@all, "all-local");
3964       &depend ('.PHONY', "all-local");
3965     }
3967     &pretty_print_rule ("all-am:", "\t\t", @all);
3968     &depend ('.PHONY', 'all-am', 'all');
3971     # Output `all'.
3973     my @local_headers = ();
3974     push @local_headers, '$(BUILT_SOURCES)'
3975       if &variable_defined ('BUILT_SOURCES');
3976     foreach my $one_name (@config_names)
3977       {
3978         push @local_headers, basename ($one_name)
3979           if dirname ($one_name) eq $relative_dir;
3980       }
3982     if (@local_headers)
3983       {
3984         # We need to make sure config.h is built before we recurse.
3985         # We also want to make sure that built sources are built
3986         # before any ordinary `all' targets are run.  We can't do this
3987         # by changing the order of dependencies to the "all" because
3988         # that breaks when using parallel makes.  Instead we handle
3989         # things explicitly.
3990         $output_all .= ("all: " . join (' ', @local_headers)
3991                         . "\n\t"
3992                         . '$(MAKE) $(AM_MAKEFLAGS) '
3993                         . (&variable_defined ('SUBDIRS')
3994                            ? 'all-recursive' : 'all-am')
3995                         . "\n\n");
3996       }
3997     else
3998       {
3999         $output_all .= "all: " . (&variable_defined ('SUBDIRS')
4000                                   ? 'all-recursive' : 'all-am') . "\n\n";
4001       }
4005 # Handle check merge target specially.
4006 sub do_check_merge_target
4008     if (&target_defined ('check-local'))
4009     {
4010         # User defined local form of target.  So include it.
4011         push (@check_tests, 'check-local');
4012         &depend ('.PHONY', 'check-local');
4013     }
4015     # In --cygnus mode, check doesn't depend on all.
4016     if ($cygnus_mode)
4017     {
4018         # Just run the local check rules.
4019         &pretty_print_rule ('check-am:', "\t\t", @check);
4020     }
4021     else
4022     {
4023         # The check target must depend on the local equivalent of
4024         # `all', to ensure all the primary targets are built.  Then it
4025         # must build the local check rules.
4026         $output_rules .= "check-am: all-am\n";
4027         &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
4028                             @check)
4029             if @check;
4030     }
4031     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
4032                         @check_tests)
4033         if @check_tests;
4035     &depend ('.PHONY', 'check', 'check-am');
4036     $output_rules .= ("check: "
4037                       . (&variable_defined ('SUBDIRS')
4038                          ? 'check-recursive' : 'check-am')
4039                       . "\n");
4042 # Handle all 'clean' targets.
4043 sub handle_clean
4045     my %transform;
4047     # Don't include `MAINTAINER'; it is handled specially below.
4048     foreach my $name ('MOSTLY', '', 'DIST')
4049     {
4050       $transform{"${name}CLEAN"} = &variable_defined ("${name}CLEANFILES");
4051     }
4053     # Built sources are automatically removed by maintainer-clean.
4054     push (@maintainer_clean_files, '$(BUILT_SOURCES)')
4055         if &variable_defined ('BUILT_SOURCES');
4056     push (@maintainer_clean_files, '$(MAINTAINERCLEANFILES)')
4057         if &variable_defined ('MAINTAINERCLEANFILES');
4059     $output_rules .= &file_contents ('clean',
4060                                      (%transform,
4061                                       'MCFILES'
4062                                       # Join with no space to avoid
4063                                       # spurious `test -z' success at
4064                                       # runtime.
4065                                       => join ('', @maintainer_clean_files),
4066                                       'MFILES'
4067                                       # A space is required in the join here.
4068                                       => join (' ', @maintainer_clean_files)));
4072 # &depend ($CATEGORY, @DEPENDENDEES)
4073 # ----------------------------------
4074 # The target $CATEGORY depends on @DEPENDENDEES.
4075 sub depend
4077     my ($category, @dependendees) = @_;
4078     {
4079       push (@{$dependencies{$category}}, @dependendees);
4080     }
4084 # &target_cmp ($A, $B)
4085 # --------------------
4086 # Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
4087 sub target_cmp
4089     return 0
4090         if $a eq $b;
4091     return -1
4092         if $b eq '.PHONY';
4093     return 1
4094         if $a eq '.PHONY';
4095     return $a cmp $b;
4099 # &handle_factored_dependencies ()
4100 # --------------------------------
4101 # Handle everything related to gathered targets.
4102 sub handle_factored_dependencies
4104     # Reject bad hooks.
4105     foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4106                        'uninstall-exec-local', 'uninstall-exec-hook')
4107     {
4108         if (&target_defined ($utarg))
4109         {
4110             my $x = $utarg;
4111             $x =~ s/(data|exec)-//;
4112             &am_line_error ($utarg, "use `$x', not `$utarg'");
4113         }
4114     }
4116     if (&target_defined ('install-local'))
4117     {
4118         &am_line_error ('install-local',
4119                         "use `install-data-local' or `install-exec-local', "
4120                         . "not `install-local'");
4121     }
4123     if (!defined $options{'no-installinfo'}
4124         && &target_defined ('install-info-local'))
4125     {
4126         &am_line_error ('install-info-local',
4127                         "`install-info-local' target defined but "
4128                         . "`no-installinfo' option not in use");
4129     }
4131     # Install the -local hooks.
4132     foreach (keys %dependencies)
4133     {
4134       # Hooks are installed on the -am targets.
4135       s/-am$// or next;
4136       if (&target_defined ("$_-local"))
4137         {
4138           depend ("$_-am", "$_-local");
4139           &depend ('.PHONY', "$_-local");
4140         }
4141     }
4143     # Install the -hook hooks.
4144     # FIXME: Why not be as liberal as we are with -local hooks?
4145     foreach ('install-exec', 'install-data')
4146     {
4147       if (&target_defined ("$_-hook"))
4148         {
4149           $actions{"$_-am"} .=
4150             ("\t\@\$(NORMAL_INSTALL)\n"
4151              . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
4152         }
4153     }
4155     # All the required targets are phony.
4156     depend ('.PHONY', keys %required_targets);
4158     # Actually output gathered targets.
4159     foreach (sort target_cmp keys %dependencies)
4160     {
4161         # If there is nothing about this guy, skip it.
4162         next
4163           unless (@{$dependencies{$_}}
4164                   || $actions{$_}
4165                   || $required_targets{$_});
4166         &pretty_print_rule ("$_:", "\t",
4167                             uniq (sort @{$dependencies{$_}}));
4168         $output_rules .= $actions{$_}
4169           if defined $actions{$_};
4170         $output_rules .= "\n";
4171     }
4175 # &handle_tests_dejagnu ()
4176 # ------------------------
4177 sub handle_tests_dejagnu
4179     push (@check_tests, 'check-DEJAGNU');
4181     # Only create site.exp rule if user hasn't already written one.
4182     $output_rules .=
4183       file_contents ('dejagnu', ('SITE-EXP' => ! target_defined ('site.exp')));
4187 # Handle TESTS variable and other checks.
4188 sub handle_tests
4190     if (defined $options{'dejagnu'})
4191     {
4192         &handle_tests_dejagnu;
4193     }
4194     else
4195     {
4196         foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4197         {
4198             &am_line_error ($c,
4199                             "`$c' defined but `dejagnu' not in `AUTOMAKE_OPTIONS'")
4200               if &variable_defined ($c);
4201         }
4202     }
4204     if (&variable_defined ('TESTS'))
4205     {
4206         push (@check_tests, 'check-TESTS');
4207         $output_rules .= &file_contents ('check');
4208     }
4211 # Handle Emacs Lisp.
4212 sub handle_emacs_lisp
4214     my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4215                                    'lisp', 'noinst');
4217     return if ! @elfiles;
4219     # Generate .elc files.
4220     my @elcfiles = map { $_ . 'c' } @elfiles;
4221     &define_pretty_variable ('ELCFILES', '', @elcfiles);
4223     push (@all, '$(ELCFILES)');
4225     &am_error ("`lisp_LISP' defined but `AM_PATH_LISPDIR' not in `$configure_ac'")
4226       if ! $seen_lispdir && &variable_defined ('lisp_LISP');
4228     &require_file_with_conf_line ('AM_PATH_LISPDIR', $FOREIGN, 'elisp-comp');
4231 # Handle Python
4232 sub handle_python
4234     my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4235                                    'python', 'noinst');
4236     return if ! @pyfiles;
4238     # Found some python.
4239     &am_error ("`python_PYTHON' defined but `AM_PATH_PYTHON' not in `$configure_ac'")
4240         if ! $seen_pythondir && &variable_defined ('python_PYTHON');
4242     &require_file_with_conf_line ('AM_PATH_PYTHON', $FOREIGN, 'py-compile');
4243     &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4246 # Handle Java.
4247 sub handle_java
4249     my @sourcelist = &am_install_var ('-candist',
4250                                       'java', 'JAVA',
4251                                       'java', 'noinst', 'check');
4252     return if ! @sourcelist;
4254     my %valid = &am_primary_prefixes ('JAVA', 1,
4255                                       'java', 'noinst', 'check');
4257     my $dir;
4258     foreach my $curs (keys %valid)
4259     {
4260         if (! &variable_defined ($curs . '_JAVA') || $curs eq 'EXTRA')
4261         {
4262             next;
4263         }
4265         if (defined $dir)
4266         {
4267             &am_line_error ($curs . '_JAVA',
4268                             "multiple _JAVA primaries in use");
4269         }
4270         $dir = $curs;
4271     }
4273     push (@all, 'class' . $dir . '.stamp');
4277 # Handle some of the minor options.
4278 sub handle_minor_options
4280     if (defined $options{'readme-alpha'})
4281     {
4282         if ($relative_dir eq '.')
4283         {
4284             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4285             {
4286                 # FIXME: allow real filename.
4287                 &am_conf_line_error ($configure_ac,
4288                                      $package_version_line,
4289                                      "version `$package_version' doesn't follow Gnits standards");
4290             }
4291             elsif (defined $1 && -f 'README-alpha')
4292             {
4293                 # This means we have an alpha release.  See
4294                 # GNITS_VERSION_PATTERN for details.
4295                 &require_file ($FOREIGN, 'README-alpha');
4296             }
4297         }
4298     }
4301 ################################################################
4303 my %make_list;
4304 my @make_input_list;
4305 # &scan_autoconf_config_files ($CONFIG-FILES)
4306 # -------------------------------------------
4307 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4308 # (or AC_OUTPUT).
4309 sub scan_autoconf_config_files
4311     my ($config_files) = @_;
4312     # Look at potential Makefile.am's.
4313     foreach (split ' ', $config_files)
4314     {
4315         # Must skip empty string for Perl 4.
4316         next if $_ eq "\\" || $_ eq '';
4318         # Handle $local:$input syntax.  Note that we ignore
4319         # every input file past the first, though we keep
4320         # those around for later.
4321         my ($local, $input, @rest) = split (/:/);
4322         if (! $input)
4323         {
4324             $input = $local;
4325         }
4326         else
4327         {
4328             # FIXME: should be error if .in is missing.
4329             $input =~ s/\.in$//;
4330         }
4332         if (-f $input . '.am')
4333         {
4334             # We have a file that automake should generate.
4335             push (@make_input_list, $input);
4336             $make_list{$input} = join (':', ($local, @rest));
4337         }
4338         else
4339         {
4340             # We have a file that automake should cause to be
4341             # rebuilt, but shouldn't generate itself.
4342             push (@other_input_files, $_);
4343         }
4344     }
4348 # &scan_autoconf_traces ($FILENAME)
4349 # ---------------------------------
4350 # FIXME: For the time being, we don't care about the FILENAME.
4351 sub scan_autoconf_traces
4353     my ($filename) = @_;
4355     my $traces = "$ENV{amtraces} ";
4357     $traces .= ' -t AC_CONFIG_FILES';
4358     $traces .= ' -t AC_LIBSOURCE';
4359     $traces .= ' -t AC_SUBST';
4361     my $tracefh = new IO::File ("$traces |");
4362     if (! $tracefh)
4363     {
4364         die "$me: couldn't open `$traces': $!\n";
4365     }
4366     print "$me: reading $traces\n" if $verbose;
4368     while ($_ = $tracefh->getline)
4369     {
4370         chomp;
4371         my ($file, $line, $macro, @args) = split /:/;
4372         my $here = "$file:$line";
4374         # Alphabetical ordering please.
4375         if ($macro eq 'AC_CONFIG_FILES')
4376         {
4377             # Look at potential Makefile.am's.
4378             &scan_autoconf_config_files ($args[0]);
4379         }
4380         elsif ($macro eq 'AC_LIBSOURCE')
4381         {
4382             my $source = "$args[0].c";
4383             # We should actually also `close' the sources: getopt.c
4384             # wants getopt.h etc.  But actually it should be done in the
4385             # macro itself, i.e., we have to first fix Autoconf to extend
4386             # _AC_LIBOBJ_DECL and use it the in various macros.
4387             if (!defined $libsources{$source})
4388                 {
4389                     print STDERR "traces: discovered $source\n";
4390                     $libsources{$source} = $here;
4391                 }
4392         }
4393         elsif ($macro eq 'AC_SUBST')
4394         {
4395             if (!defined $configure_vars{$args[0]})
4396                 {
4397                     print STDERR "traces: discovered AC_SUBST($args[0])\n";
4398                     $configure_vars{$args[0]} = $here;
4399                 }
4400         }
4401     }
4403     $tracefh->close
4404         || die "$me: close: $traces: $!\n";
4408 # &scan_one_autoconf_file ($FILENAME)
4409 # -----------------------------------
4410 # Scan one file for interesting things.  Subroutine of
4411 # &scan_autoconf_files.
4412 sub scan_one_autoconf_file
4414     my ($filename) = @_;
4416     my $configfh = new IO::File ("< $filename");
4417     if (! $configfh)
4418     {
4419         die "$me: couldn't open `$filename': $!\n";
4420     }
4421     print "$me: reading $filename\n" if $verbose;
4423     my ($in_ac_output, $in_ac_replace) = (0, 0);
4424     while ($_ = $configfh->getline)
4425     {
4426         # Remove comments from current line.
4427         s/\bdnl\b.*$//;
4428         s/\#.*$//;
4430         # Skip macro definitions.  Otherwise we might be confused into
4431         # thinking that a macro that was only defined was actually
4432         # used.
4433         next if /AC_DEFUN/;
4435         # Follow includes.  This is a weirdness commonly in use at
4436         # Cygnus and hopefully nowhere else.
4437         if (/sinclude\((.*)\)/ && -f $1)
4438         {
4439             # $_ being local, if we don't preserve it, when coming
4440             # back we will have $_ undefined, which is bad for the
4441             # the rest of this routine.
4442             my $underscore = $_;
4443             &scan_one_autoconf_file ($1);
4444             $_ = $underscore;
4445         }
4447         # Populate libobjs array.
4448         if (/AC_FUNC_ALLOCA/)
4449         {
4450             $libsources{'alloca.c'} = 1;
4451         }
4452         elsif (/AC_FUNC_GETLOADAVG/)
4453         {
4454             $libsources{'getloadavg.c'} = 1;
4455         }
4456         elsif (/AC_FUNC_MEMCMP/)
4457         {
4458             $libsources{'memcmp.c'} = 1;
4459         }
4460         elsif (/AC_STRUCT_ST_BLOCKS/)
4461         {
4462             $libsources{'fileblocks.c'} = 1;
4463         }
4464         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4465         {
4466             $libsources{'getopt.c'} = 1;
4467             $libsources{'getopt1.c'} = 1;
4468         }
4469         elsif (/AM_FUNC_STRTOD/)
4470         {
4471             $libsources{'strtod.c'} = 1;
4472         }
4473         elsif (/AM_WITH_REGEX/)
4474         {
4475             $libsources{'rx.c'} = 1;
4476             $libsources{'rx.h'} = 1;
4477             $libsources{'regex.c'} = 1;
4478             $libsources{'regex.h'} = 1;
4479         }
4480         elsif (/AC_FUNC_MKTIME/)
4481         {
4482             $libsources{'mktime.c'} = 1;
4483         }
4484         elsif (/AM_FUNC_ERROR_AT_LINE/)
4485         {
4486             $libsources{'error.c'} = 1;
4487             $libsources{'error.h'} = 1;
4488         }
4489         elsif (/AM_FUNC_OBSTACK/)
4490         {
4491             $libsources{'obstack.c'} = 1;
4492             $libsources{'obstack.h'} = 1;
4493         }
4494         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4495                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4496         {
4497             foreach my $libobj_iter (split (' ', $1))
4498             {
4499                 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4500                     || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4501                     || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4502                 {
4503                     $libsources{$1 . '.c'} = 1;
4504                 }
4505             }
4506         }
4507         elsif (/AC_LIBOBJ\(([^)]+)\)/)
4508         {
4509             $libsources{"$1.c"} = 1;
4510         }
4512         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4513         {
4514             $in_ac_replace = 1;
4515         }
4516         if ($in_ac_replace)
4517         {
4518             $in_ac_replace = 0 if s/[\]\)].*$//;
4519             # Remove trailing backslash.
4520             s/\\$//;
4521             foreach (split)
4522             {
4523                 # Need to skip empty elements for Perl 4.
4524                 next if $_ eq '';
4525                 $libsources{$_ . '.c'} = 1;
4526             }
4527         }
4529         if (/$obsolete_rx/o)
4530         {
4531             my $hint = '';
4532             if ($obsolete_macros{$1} ne '')
4533             {
4534                 $hint = '; ' . $obsolete_macros{$1};
4535             }
4536             &am_conf_line_error ($filename, $., "`$1' is obsolete$hint");
4537         }
4539         # Process the AC_OUTPUT and AC_CONFIG_FILES macros.
4540         if (! $in_ac_output && s/AC_(OUTPUT|CONFIG_FILES)\s*\(\[?//)
4541         {
4542             $in_ac_output = 1;
4543             $ac_output_line = $.;
4544         }
4545         if ($in_ac_output)
4546         {
4547             my $closing = 0;
4548             if (s/[\]\),].*$//)
4549             {
4550                 $in_ac_output = 0;
4551                 $closing = 1;
4552             }
4554             # Look at potential Makefile.am's.
4555             &scan_autoconf_config_files ($_);
4557             if ($closing && @make_input_list == 0 && @other_input_files == 0)
4558             {
4559                 &am_conf_line_error ($filename, $ac_output_line,
4560                                      "No files mentioned in `AC_OUTPUT'");
4561                 exit 1;
4562             }
4563         }
4565         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4566         {
4567             @config_aux_path = &unquote_m4_arg ($1);
4568             $config_aux_dir_set_in_configure_in = 1;
4569         }
4571         # Check for ansi2knr.
4572         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4574         # Check for exe extension stuff.
4575         if (/AC_EXEEXT/)
4576         {
4577             $seen_exeext = 1;
4578             $configure_vars{'EXEEXT'} = $filename . ':' . $.;
4579         }
4581         if (/AC_OBJEXT/)
4582         {
4583             $seen_objext = 1;
4584             $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4585         }
4587         # Check for `-c -o' code.
4588         $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4590         # Check for NLS support.
4591         if (/AM_GNU_GETTEXT/)
4592         {
4593             $seen_gettext = 1;
4594             $ac_gettext_line = $.;
4595         }
4597         # Look for ALL_LINGUAS.
4598         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4599         {
4600             $seen_linguas = 1;
4601             $all_linguas = $1;
4602             $all_linguas_line = $.;
4603         }
4605         # Handle configuration headers.  A config header of `[$1]'
4606         # means we are actually scanning AM_CONFIG_HEADER from
4607         # aclocal.m4.
4608         if (/A([CM])_CONFIG_HEADERS?\s*\((.*)\)/
4609             && $2 ne '[$1]')
4610         {
4611             &am_conf_line_error
4612                 ($filename, $., "`automake requires `AM_CONFIG_HEADER', not `AC_CONFIG_HEADER'")
4613                     if $1 eq 'C';
4615             $config_header_line = $.;
4616             foreach my $one_hdr (split (' ', &unquote_m4_arg ($2)))
4617             {
4618                 push (@config_fullnames, $one_hdr);
4619                 if ($one_hdr =~ /^([^:]+):(.+)$/)
4620                 {
4621                     push (@config_names, $1);
4622                     push (@config_headers, $2);
4623                 }
4624                 else
4625                 {
4626                     push (@config_names, $one_hdr);
4627                     push (@config_headers, $one_hdr . '.in');
4628                 }
4629             }
4630         }
4632         # Handle AC_CANONICAL_*.  Always allow upgrading to
4633         # AC_CANONICAL_SYSTEM, but never downgrading.
4634         $seen_canonical = $AC_CANONICAL_HOST
4635             if ! $seen_canonical
4636                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4637         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4639         # If using X, include some extra variable definitions.  NOTE
4640         # we don't want to force these into CFLAGS or anything,
4641         # because not all programs will necessarily use X.
4642         if (/AC_PATH_XTRA/)
4643           {
4644             foreach my $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS',
4645                              'X_PRE_LIBS')
4646               {
4647                 $configure_vars{$var} = $filename . ':' . $.
4648               }
4649           }
4651         # This macro handles several different things.
4652         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4653         {
4654             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4655             $package_version_line = $.;
4656             $seen_init_automake = 1;
4657         }
4659         if (/AM_PROG_LEX/)
4660         {
4661             $configure_vars{'LEX'} = $filename . ':' . $.;
4662             $seen_decl_yytext = 1;
4663         }
4664         if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.(ac|in)$/)
4665         {
4666             &am_conf_line_warning ($filename, $., "`AC_DECL_YYTEXT' is covered by `AM_PROG_LEX'");
4667         }
4668         if (/AC_PROG_LEX/ && $filename =~ /configure\.(ac|in)$/)
4669         {
4670             &am_conf_line_warning ($filename, $., "automake requires `AM_PROG_LEX', not `AC_PROG_LEX'");
4671         }
4673         if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4674         {
4675             $configure_vars{$1} = $filename . ':' . $.;
4676         }
4677         if (/$AC_CHECK_PATTERN/o)
4678         {
4679             $configure_vars{$3} = $filename . ':' . $.;
4680         }
4681         if (/$AM_MISSING_PATTERN/o
4682             && $1 ne 'ACLOCAL'
4683             && $1 ne 'AUTOCONF'
4684             && $1 ne 'AUTOMAKE'
4685             && $1 ne 'AUTOHEADER'
4686             # AM_INIT_AUTOMAKE is AM_MISSING_PROG'ing MAKEINFO.  But
4687             # we handle it elsewhere.
4688             && $1 ne 'MAKEINFO')
4689         {
4690             $configure_vars{$1} = $filename . ':' . $.;
4691         }
4693         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4694         # but later define it elsewhere.  This is pretty hacky.  We
4695         # also explicitly avoid INSTALL_SCRIPT and some other
4696         # variables because they are defined in header-vars.am.
4697         # FIXME.
4698         if (/$AC_SUBST_PATTERN/o
4699             && $1 ne 'ANSI2KNR'
4700             && $1 ne 'INSTALL_SCRIPT'
4701             && $1 ne 'INSTALL_DATA')
4702         {
4703             $configure_vars{$1} = $filename . ':' . $.;
4704         }
4706         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4707         if (/AM_MAINTAINER_MODE/)
4708         {
4709             $seen_maint_mode = 1;
4710             $configure_cond{'MAINTAINER_MODE'} = 1;
4711         }
4713         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4715         if (/AM_PATH_PYTHON/)
4716           {
4717             $seen_pythondir = 1;
4718             $configure_vars{'pythondir'} = $filename . ':' . $.;
4719             $configure_vars{'PYTHON'} = $filename . ':' . $.;
4720           }
4722         if (/A(C|M)_PROG_LIBTOOL/)
4723         {
4724             # We're not ready for this yet.  People still use a
4725             # libtool with no AC_PROG_LIBTOOL.  Once that is the
4726             # dominant version we can reenable this code -- but next
4727             # time by mentioning the macro in %obsolete_macros, both
4728             # here and in aclocal.in.
4730             # if (/AM_PROG_LIBTOOL/)
4731             # {
4732             #   &am_conf_line_warning ($filename, $., "`AM_PROG_LIBTOOL' is obsolete, use `AC_PROG_LIBTOOL' instead");
4733             # }
4734             $seen_libtool = 1;
4735             $libtool_line = $.;
4736             $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4737             $configure_vars{'RANLIB'} = $filename . ':' . $.;
4738             $configure_vars{'CC'} = $filename . ':' . $.;
4739             # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
4740             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4741             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4742         }
4744         $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4746         if (/$AM_CONDITIONAL_PATTERN/o)
4747         {
4748             $configure_cond{$1} = 1;
4749         }
4751         # Check for Fortran 77 intrinsic and run-time libraries.
4752         if (/AC_F77_LIBRARY_LDFLAGS/)
4753         {
4754             $configure_vars{'FLIBS'} = $filename . ':' . $.;
4755         }
4756     }
4758     $configfh->close;
4762 # &scan_autoconf_files ()
4763 # -----------------------
4764 # Check whether we use `configure.ac' or `configure.in'.
4765 # Scan it (and possibly `aclocal.m4') for interesting things.
4766 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
4767 sub scan_autoconf_files
4769     # Reinitialize libsources here.  This isn't really necessary,
4770     # since we currently assume there is only one configure.ac.  But
4771     # that won't always be the case.
4772     %libsources = ();
4774     warn "$me: both `configure.ac' and `configure.in' present:"
4775          . " ignoring `configure.in'\n"
4776         if -f 'configure.ac' && -f 'configure.in';
4777     $configure_ac = 'configure.in'
4778         if -f 'configure.in';
4779     $configure_ac = 'configure.ac'
4780         if -f 'configure.ac';
4781     die "$me: `configure.ac' or `configure.in' is required\n"
4782         if !$configure_ac;
4784     &scan_one_autoconf_file ($configure_ac);
4785     &scan_one_autoconf_file ('aclocal.m4')
4786         if -f 'aclocal.m4';
4788     if (defined $ENV{'amtraces'})
4789     {
4790         warn '$me: Autoconf traces is an experimental feature';
4791         warn '$me: use at your own risks';
4793         &scan_autoconf_traces ($configure_ac);
4794     }
4796     # Set input and output files if not specified by user.
4797     if (! @input_files)
4798     {
4799         @input_files = @make_input_list;
4800         %output_files = %make_list;
4801     }
4803     @configure_input_files = @make_input_list;
4805     &am_conf_error ("`AM_INIT_AUTOMAKE' must be used")
4806         if ! $seen_init_automake;
4808     # Look for some files we need.  Always check for these.  This
4809     # check must be done for every run, even those where we are only
4810     # looking at a subdir Makefile.  We must set relative_dir so that
4811     # the file-finding machinery works.
4812     # FIXME: Is this broken because it needs dynamic scopes.
4813     # My tests seems to show it's not the case.
4814     $relative_dir = '.';
4815     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4816     &am_error ("`install.sh' is an anachronism; use `install-sh' instead")
4817         if -f $config_aux_path[0] . '/install.sh';
4819     &require_config_file ($FOREIGN, 'py-compile')
4820         if $seen_pythondir;
4822     # Preserve dist_common for later.
4823     $configure_dist_common = variable_value ('DIST_COMMON', 'TRUE') || '';
4826 ################################################################
4828 # Set up for Cygnus mode.
4829 sub check_cygnus
4831     return unless $cygnus_mode;
4833     &set_strictness ('foreign');
4834     $options{'no-installinfo'} = 1;
4835     $options{'no-dependencies'} = 1;
4836     $use_dependencies = 0;
4838     if (! $seen_maint_mode)
4839     {
4840         &am_conf_error ("`AM_MAINTAINER_MODE' required when --cygnus specified");
4841     }
4844 # Do any extra checking for GNU standards.
4845 sub check_gnu_standards
4847     if ($relative_dir eq '.')
4848     {
4849         # In top level (or only) directory.
4850         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4851                        'AUTHORS', 'ChangeLog');
4852     }
4854     if ($strictness >= $GNU
4855         && defined $options{'no-installman'})
4856     {
4857         &am_line_error ('AUTOMAKE_OPTIONS',
4858                         "option `no-installman' disallowed by GNU standards");
4859     }
4861     if ($strictness >= $GNU
4862         && defined $options{'no-installinfo'})
4863     {
4864         &am_line_error ('AUTOMAKE_OPTIONS',
4865                         "option `no-installinfo' disallowed by GNU standards");
4866     }
4869 # Do any extra checking for GNITS standards.
4870 sub check_gnits_standards
4872     if ($relative_dir eq '.')
4873     {
4874         # In top level (or only) directory.
4875         &require_file ($GNITS, 'THANKS');
4876     }
4879 ################################################################
4881 # Functions to handle files of each language.
4883 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
4884 # simple formula: Return value is $LANG_SUBDIR if the resulting object
4885 # file should be in a subdir if the source file is, $LANG_PROCESS if
4886 # file is to be dealt with, $LANG_IGNORE otherwise.
4888 # Much of the actual processing is handled in
4889 # handle_single_transform_list.  These functions exist so that
4890 # auxiliary information can be recorded for a later cleanup pass.
4891 # Note that the calls to these functions are computed, so don't bother
4892 # searching for their precise names in the source.
4894 # This is just a convenience function that can be used to determine
4895 # when a subdir object should be used.
4896 sub lang_sub_obj
4898     return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4901 # Rewrite a single C source file.
4902 sub lang_c_rewrite
4904     my ($directory, $base, $ext) = @_;
4906     if (defined $options{'ansi2knr'} && $base =~ /_$/)
4907     {
4908         # FIXME: include line number in error.
4909         &am_error ("C source file `$base.c' would be deleted by ansi2knr rules");
4910     }
4912     my $r = $LANG_PROCESS;
4913     if (defined $options{'subdir-objects'})
4914     {
4915         $r = $LANG_SUBDIR;
4916         $base = $directory . '/' . $base;
4918         if (! $seen_cc_c_o)
4919         {
4920             # Only give error once.
4921             $seen_cc_c_o = 1;
4922             # FIXME: line number.
4923             &am_error ("C objects in subdir but `AM_PROG_CC_C_O' not in `$configure_ac'");
4924         }
4926         &require_file ($FOREIGN, 'compile')
4927             if $relative_dir eq '.';
4928     }
4930     $de_ansi_files{$base} = 1;
4931     return $r;
4934 # Rewrite a single C++ source file.
4935 sub lang_cxx_rewrite
4937     return &lang_sub_obj;
4940 # Rewrite a single header file.
4941 sub lang_header_rewrite
4943     # Header files are simply ignored.
4944     return $LANG_IGNORE;
4947 # Rewrite a single yacc file.
4948 sub lang_yacc_rewrite
4950     my ($directory, $base, $ext) = @_;
4952     my $r = &lang_sub_obj;
4953     (my $newext = $ext) =~ tr/y/c/;
4954     return ($r, $newext);
4957 # Rewrite a single yacc++ file.
4958 sub lang_yaccxx_rewrite
4960     my ($directory, $base, $ext) = @_;
4962     my $r = &lang_sub_obj;
4963     (my $newext = $ext) =~ tr/y/c/;
4964     return ($r, $newext);
4967 # Rewrite a single lex file.
4968 sub lang_lex_rewrite
4970     my ($directory, $base, $ext) = @_;
4972     my $r = &lang_sub_obj;
4973     (my $newext = $ext) =~ tr/l/c/;
4974     return ($r, $newext);
4977 # Rewrite a single lex++ file.
4978 sub lang_lexxx_rewrite
4980     my ($directory, $base, $ext) = @_;
4982     my $r = &lang_sub_obj;
4983     (my $newext = $ext) =~ tr/l/c/;
4984     return ($r, $newext);
4987 # Rewrite a single assembly file.
4988 sub lang_asm_rewrite
4990     return &lang_sub_obj;
4993 # Rewrite a single Fortran 77 file.
4994 sub lang_f77_rewrite
4996     return $LANG_PROCESS;
4999 # Rewrite a single preprocessed Fortran 77 file.
5000 sub lang_ppf77_rewrite
5002     return $LANG_PROCESS;
5005 # Rewrite a single ratfor file.
5006 sub lang_ratfor_rewrite
5008     return $LANG_PROCESS;
5011 # Rewrite a single Objective C file.
5012 sub lang_objc_rewrite
5014     return &lang_sub_obj;
5017 # Rewrite a single Java file.
5018 sub lang_java_rewrite
5020     return $LANG_SUBDIR;
5023 # The lang_X_finish functions are called after all source file
5024 # processing is done.  Each should handle defining rules for the
5025 # language, etc.  A finish function is only called if a source file of
5026 # the appropriate type has been seen.
5028 sub lang_c_finish
5030     # Push all libobjs files onto de_ansi_files.  We actually only
5031     # push files which exist in the current directory, and which are
5032     # genuine source files.
5033     foreach my $file (keys %libsources)
5034     {
5035         if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
5036         {
5037             $de_ansi_files{$1} = 1;
5038         }
5039     }
5041     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
5042     {
5043         # Make all _.c files depend on their corresponding .c files.
5044         my @objects;
5045         foreach my $base (sort keys %de_ansi_files)
5046         {
5047             # Each _.c file must depend on ansi2knr; otherwise it
5048             # might be used in a parallel build before it is built.
5049             # We need to support files in the srcdir and in the build
5050             # dir (because these files might be auto-generated.  But
5051             # we can't use $< -- some makes only define $< during a
5052             # suffix rule.
5053             $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
5054                               . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5055                               . '`if test -f $(srcdir)/' . $base . '.c'
5056                               . '; then echo $(srcdir)/' . $base . '.c'
5057                               . '; else echo ' . $base . '.c; fi` '
5058                               . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5059                               . '| $(ANSI2KNR) > ' . $base . "_.c"
5060                               # If ansi2knr fails then we shouldn't
5061                               # create the _.c file
5062                               . " || rm -f ${base}_.c\n");
5063             push (@objects, $base . '_.$(OBJEXT)');
5064             push (@objects, $base . '_.lo')
5065               if $seen_libtool;
5066         }
5068         # Make all _.o (and _.lo) files depend on ansi2knr.
5069         # Use a sneaky little hack to make it print nicely.
5070         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5071     }
5074 # This is a yacc helper which is called whenever we have decided to
5075 # compile a yacc file.
5076 sub lang_yacc_target_hook
5078     my ($self, $aggregate, $output, $input) = @_;
5080     my $flag = $aggregate . "_YFLAGS";
5081     if ((&variable_defined ($flag)
5082          && &variable_value ($flag) =~ /$DASH_D_PATTERN/o)
5083         || (&variable_defined ('YFLAGS')
5084             && &variable_value ('YFLAGS') =~ /$DASH_D_PATTERN/o))
5085     {
5086         (my $output_base = $output) =~ s/\..*$//;
5087         my $header = $output_base . '.h';
5089         # Found a `-d' that applies to the compilation of this file.
5090         # Add a dependency for the generated header file, and arrange
5091         # for that file to be included in the distribution.
5092         # FIXME: this fails for `nodist_*_SOURCES'.
5093         $output_rules .= "${header}: $input\n";
5094         &push_dist_common ($header);
5095         # If the files are built in the build directory, then we want
5096         # to remove them with `make clean'.  If they are in srcdir
5097         # they shouldn't be touched.  However, we can't determine this
5098         # statically, and the GNU rules say that yacc/lex output files
5099         # should be removed by maintainer-clean.  So that's what we
5100         # do.
5101         push (@maintainer_clean_files, $header);
5102     }
5105 # This is a helper for both lex and yacc.
5106 sub yacc_lex_finish_helper
5108     return if defined $language_scratch{'lex-yacc-done'};
5109     $language_scratch{'lex-yacc-done'} = 1;
5111     # If there is more than one distinct yacc (resp lex) source file
5112     # in a given directory, then the `ylwrap' program is required to
5113     # allow parallel builds to work correctly.  FIXME: for now, no
5114     # line number.
5115     &require_config_file ($FOREIGN, 'ylwrap');
5116     if ($config_aux_dir_set_in_configure_in)
5117     {
5118         &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5119     }
5120     else
5121     {
5122         &define_variable ('YLWRAP', '$(top_srcdir)/ylwrap');
5123     }
5126 sub lang_yacc_finish
5128     return if defined $language_scratch{'yacc-done'};
5129     $language_scratch{'yacc-done'} = 1;
5131     if (&variable_defined ('YACCFLAGS'))
5132     {
5133         &am_line_error ('YACCFLAGS',
5134                         "`YACCFLAGS' obsolete; use `YFLAGS' instead");
5135     }
5137     if (count_files_for_language ('yacc') > 1)
5138     {
5139         &yacc_lex_finish_helper;
5140     }
5144 sub lang_lex_finish
5146     return if defined $language_scratch{'lex-done'};
5147     $language_scratch{'lex-done'} = 1;
5149     if (! $seen_decl_yytext)
5150     {
5151         &am_error ("lex source seen but `AC_DECL_YYTEXT' not in `$configure_ac'");
5152     }
5154     if (count_files_for_language ('lex') > 1)
5155     {
5156         &yacc_lex_finish_helper;
5157     }
5161 # Given a hash table of linker names, pick the name that has the most
5162 # precedence.  This is lame, but something has to have global
5163 # knowledge in order to eliminate the conflict.  Add more linkers as
5164 # required.
5165 sub resolve_linker
5167     my (%linkers) = @_;
5169     return 'GCJLINK'
5170         if defined $linkers{'GCJLINK'};
5171     return 'CXXLINK'
5172         if defined $linkers{'CXXLINK'};
5173     return 'F77LINK'
5174         if defined $linkers{'F77LINK'};
5175     return 'OBJCLINK'
5176         if defined $linkers{'OBJCLINK'};
5177     return 'LINK';
5180 # Called to indicate that an extension was used.
5181 sub saw_extension
5183     my ($ext) = @_;
5184     if (! defined $extension_seen{$ext})
5185     {
5186         $extension_seen{$ext} = 1;
5187     }
5188     else
5189     {
5190         ++$extension_seen{$ext};
5191     }
5194 # Return the number of files seen for a given language.  Knows about
5195 # special cases we care about.  FIXME: this is hideous.  We need
5196 # something that involves real language objects.  For instance yacc
5197 # and yaccxx could both derive from a common yacc class which would
5198 # know about the strange ylwrap requirement.  (Or better yet we could
5199 # just not support legacy yacc!)
5200 sub count_files_for_language
5202     my ($name) = @_;
5204     my @names;
5205     if ($name eq 'yacc' || $name eq 'yaccxx')
5206     {
5207         @names = ('yacc', 'yaccxx');
5208     }
5209     elsif ($name eq 'lex' || $name eq 'lexxx')
5210     {
5211         @names = ('lex', 'lexxx');
5212     }
5213     else
5214     {
5215         @names = ($name);
5216     }
5218     my $r = 0;
5219     foreach $name (@names)
5220     {
5221         my $lang = $languages{$name};
5222         foreach my $ext (@{$lang->extensions})
5223         {
5224             $r += $extension_seen{$ext}
5225                 if defined $extension_seen{$ext};
5226         }
5227     }
5229     return $r
5232 # Called to ask whether source files have been seen . If HEADERS is 1,
5233 # headers can be included.
5234 sub saw_sources_p
5236     my ($headers) = @_;
5238     # count all the sources
5239     my $count = 0;
5240     foreach my $val (values %extension_seen) 
5241     {
5242         $count += $val;
5243     }
5245     if (!$headers) 
5246     {
5247         $count -= count_files_for_language ('header');
5248     }
5250     return $count > 0;
5254 # register_language (%ATTRIBUTE)
5255 # ------------------------------
5256 # Register a single language.
5257 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5258 sub register_language (%)
5260     my (%option) = @_;
5262     # Set the defaults.
5263     $option{'ansi'} = 0
5264       unless defined $option{'ansi'};
5265     $option{'autodep'} = 'no'
5266       unless defined $option{'autodep'};
5267     $option{'linker'} = ''
5268       unless defined $option{'linker'};
5269     $option{'define_flag'} = 1
5270       unless defined $option{'define_flag'};
5272     my $lang = new Language (%option);
5274     # Fill indexes.
5275     grep ($extension_map{$_} = $lang->name, @{$lang->extensions});
5276     $languages{$lang->name} = $lang;
5279 # This function is used to find a path from a user-specified suffix to
5280 # `o' or to some other suffix we recognize internally, eg `cc'.
5281 sub derive_suffix
5283     my ($source_ext) = @_;
5285     # FIXME: hard-coding `o' is a mistake.  Doing something
5286     # intelligent is harder.
5287     while (! $extension_map{$source_ext}
5288            && $source_ext ne 'o'
5289            && defined $suffix_rules{$source_ext})
5290     {
5291         $source_ext = $suffix_rules{$source_ext};
5292     }
5294     return $source_ext;
5298 ################################################################
5300 # Pretty-print something.  HEAD is what should be printed at the
5301 # beginning of the first line, FILL is what should be printed at the
5302 # beginning of every subsequent line.
5303 sub pretty_print_internal
5305     my ($head, $fill, @values) = @_;
5307     my $column = length ($head);
5308     my $result = $head;
5310     # Fill length is number of characters.  However, each Tab
5311     # character counts for eight.  So we count the number of Tabs and
5312     # multiply by 7.
5313     my $fill_length = length ($fill);
5314     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5316     foreach (@values)
5317     {
5318         # "71" because we also print a space.
5319         if ($column + length ($_) > 71)
5320         {
5321             $result .= " \\\n" . $fill;
5322             $column = $fill_length;
5323         }
5324         $result .= ' ' if $result =~ /\S\z/;
5325         $result .= $_;
5326         $column += length ($_) + 1;
5327     }
5329     $result .= "\n";
5330     return $result;
5333 # Pretty-print something and append to output_vars.
5334 sub pretty_print
5336     $output_vars .= &pretty_print_internal (@_);
5339 # Pretty-print something and append to output_rules.
5340 sub pretty_print_rule
5342     $output_rules .= &pretty_print_internal (@_);
5346 ################################################################
5349 # $STRING
5350 # &conditional_string(@COND-STACK)
5351 # --------------------------------
5352 # Build a string which denotes the conditional in @COND-STACK.  Some
5353 # simplifications are done: `TRUE' entries are elided, and any `FALSE'
5354 # entry results in a return of `FALSE'.
5355 sub conditional_string
5357   my (@stack) = @_;
5359   if (grep (/^FALSE$/, @stack))
5360     {
5361       return 'FALSE';
5362     }
5363   else
5364     {
5365       return join (' ', uniq sort grep (!/^TRUE$/, @stack));
5366     }
5370 # $BOOLEAN
5371 # &conditional_true_when ($COND, $WHEN)
5372 # -------------------------------------
5373 # See if a conditional is true.  Both arguments are conditional
5374 # strings.  This returns true if the first conditional is true when
5375 # the second conditional is true.
5376 # For instance with $COND = `BAR FOO', and $WHEN = `BAR BAZ FOO',
5377 # obviously return 1, and 0 when, for instance, $WHEN = `FOO'.
5378 sub conditional_true_when ($$)
5380     my ($cond, $when) = @_;
5382     # Make a hash holding all the values from $WHEN.
5383     my %cond_vals = map { $_ => 1 } split (' ', $when);
5385     # Check each component of $cond, which looks `COND1 COND2'.
5386     foreach my $comp (split (' ', $cond))
5387     {
5388         # TRUE is always true.
5389         next if $comp eq 'TRUE';
5390         return 0 if ! defined $cond_vals{$comp};
5391     }
5393     return 1;
5397 # $BOOLEAN
5398 # &conditionals_true_when (\@CONDS, $WHEN)
5399 # ----------------------------------------
5400 # Same as above, but true only if all the @CONDS are true when $WHEN is true.
5402 # If there are no @CONDS, then return true.
5403 sub conditionals_true_when (\@$)
5405     my ($condsref, $when) = @_;
5407     foreach my $cond (@$condsref)
5408     {
5409         return 0 unless conditional_true_when ($cond, $when);
5410     }
5412     return 1;
5415 # $BOOLEAN
5416 # &conditional_is_redundant ($COND, @WHENS)
5417 # ----------------------------------------
5418 # Determine whether $COND is redundant with respect to @WHENS.
5420 # Returns true if $COND is true for any of the conditions in @WHENS.
5422 # If there are no @WHENS, then behave as if @WHENS contained a single empty
5423 # condition.
5424 sub conditional_is_redundant ($@)
5426     my ($cond, @whens) = @_;
5428     if (@whens == 0)
5429     {
5430         return 1 if conditional_true_when ($cond, "");
5431     }
5432     else
5433     {
5434         foreach my $when (@whens)
5435         {
5436             return 1 if conditional_true_when ($cond, $when);
5437         }
5438     }
5440     return 0;
5444 # $NEGATION
5445 # condition_negate ($COND)
5446 # ------------------------
5447 sub condition_negate ($)
5449     my ($cond) = @_;
5451     $cond =~ s/TRUE$/TRUEO/;
5452     $cond =~ s/FALSE$/TRUE/;
5453     $cond =~ s/TRUEO$/FALSE/;
5455     return $cond;
5459 # Compare condition names.
5460 # Issue them in alphabetical order, foo_TRUE before foo_FALSE.
5461 sub by_condition
5463     # Be careful we might be comparing `' or `#'.
5464     $a =~ /^(.*)_(TRUE|FALSE)$/;
5465     my ($aname, $abool) = ($1 || '', $2 || '');
5466     $b =~ /^(.*)_(TRUE|FALSE)$/;
5467     my ($bname, $bbool) = ($1 || '', $2 || '');
5468     return ($aname cmp $bname
5469             # Don't bother with IFs, given that TRUE is after FALSE
5470             # just cmp in the reverse order.
5471             || $bbool cmp $abool
5472             # Just in case...
5473             || $a cmp $b);
5477 # &make_condition (@CONDITIONS)
5478 # -----------------------------
5479 # Transform a list of conditions (themselves can be an internal list
5480 # of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
5481 # Make conditional (a pattern for AC_SUBST).
5482 # Correctly returns the empty string when there are no conditions.
5483 sub make_condition
5485     my $res = conditional_string (@_);
5487     # There are no conditions.
5488     if ($res eq '')
5489       {
5490         # Nothing to do.
5491       }
5492     # It's impossible.
5493     elsif ($res eq 'FALSE')
5494       {
5495         $res = '#';
5496       }
5497     # Build it.
5498     else
5499       {
5500         $res = '@' . $res . '@';
5501         $res =~ s/ /@@/g;
5502       }
5504     return $res;
5509 ## ------------------------------ ##
5510 ## Handling the condition stack.  ##
5511 ## ------------------------------ ##
5514 # $COND_STRING
5515 # cond_stack_if ($NEGATE, $COND, $WHERE)
5516 # --------------------------------------
5517 sub cond_stack_if ($$$)
5519   my ($negate, $cond, $where) = @_;
5521   &am_file_error ($where, "$cond does not appear in AM_CONDITIONAL")
5522     if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
5524   $cond = "${cond}_TRUE"
5525     unless $cond =~ /^TRUE|FALSE$/;
5526   $cond = condition_negate ($cond)
5527     if $negate;
5529   push (@cond_stack, $cond);
5531   return conditional_string (@cond_stack);
5535 # $COND_STRING
5536 # cond_stack_else ($NEGATE, $COND, $WHERE)
5537 # ----------------------------------------
5538 sub cond_stack_else ($$$)
5540   my ($negate, $cond, $where) = @_;
5542   if (! @cond_stack)
5543     {
5544       &am_file_error ($where, "else without if");
5545       return;
5546     }
5548   $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);
5550   # If $COND is given, check against it.
5551   if (defined $cond)
5552     {
5553       $cond = "${cond}_TRUE"
5554         unless $cond =~ /^TRUE|FALSE$/;
5555       $cond = condition_negate ($cond)
5556         if $negate;
5558       &am_file_error ($where,
5559                       "else reminder ($negate$cond) incompatible with "
5560                       . "current conditional: $cond_stack[$#cond_stack]")
5561         if $cond_stack[$#cond_stack] ne $cond;
5562     }
5564   return conditional_string (@cond_stack);
5568 # $COND_STRING
5569 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5570 # -----------------------------------------
5571 sub cond_stack_endif ($$$)
5573   my ($negate, $cond, $where) = @_;
5574   my $old_cond;
5576   if (! @cond_stack)
5577     {
5578       &am_file_error ($where, "endif without if: $negate$cond");
5579       return;
5580     }
5583   # If $COND is given, check against it.
5584   if (defined $cond)
5585     {
5586       $cond = "${cond}_TRUE"
5587         unless $cond =~ /^TRUE|FALSE$/;
5588       $cond = condition_negate ($cond)
5589         if $negate;
5591       &am_file_error ($where,
5592                       "endif reminder ($negate$cond) incompatible with "
5593                       . "current conditional: $cond_stack[$#cond_stack]")
5594         if $cond_stack[$#cond_stack] ne $cond;
5595     }
5597   pop @cond_stack;
5599   return conditional_string (@cond_stack);
5606 ## ------------------------ ##
5607 ## Handling the variables.  ##
5608 ## ------------------------ ##
5611 # check_ambiguous_conditional ($VAR, $COND)
5612 # -----------------------------------------
5613 # Check for an ambiguous conditional.  This is called when a variable
5614 # is being defined conditionally.  If we already know about a
5615 # definition that is true under the same conditions, then we have an
5616 # ambiguity.
5617 sub check_ambiguous_conditional ($$)
5619     my ($var, $cond) = @_;
5620     foreach my $vcond (keys %{$var_value{$var}})
5621     {
5622        my $message;
5623        if ($vcond eq $cond)
5624        {
5625            $message = "$var multiply defined in condition $cond";
5626        }
5627        elsif (&conditional_true_when ($vcond, $cond))
5628        {
5629          $message = ("$var was already defined in condition $vcond, "
5630                      . "which implies condition $cond");
5631        }
5632        elsif (&conditional_true_when ($cond, $vcond))
5633        {
5634            $message = ("$var was already defined in condition $vcond, "
5635                        . "which is implied by condition $cond");
5636        }
5637        if ($message)
5638        {
5639            &am_line_error ($var, $message);
5640            macro_dump ($var);
5641        }
5642    }
5646 # &macro_define($VAR, $VAR_IS_AM, $TYPE, $COND, $VALUE, $WHERE)
5647 # -------------------------------------------------------------
5648 # The $VAR can go from Automake to user, but not the converse.
5649 sub macro_define ($$$$$$)
5651   my ($var, $var_is_am, $type, $cond, $value, $where) = @_;
5653   am_file_error ($where, "bad macro name `$var'")
5654     if $var !~ /$MACRO_PATTERN/o;
5656   $cond ||= 'TRUE';
5658   # An Automake variable must be consistently defined with the same
5659   # sign by Automake.  A user variable must be set by either `=' or
5660   # `:=', and later promoted to `+='.
5661   if ($var_is_am)
5662     {
5663       if (defined $var_type{$var} && $var_type{$var} ne $type)
5664         {
5665           am_line_error ($var,
5666                          ("$var was set with `$var_type{$var}=' "
5667                           . "and is now set with `$type='"));
5668         }
5669     }
5670   else
5671     {
5672       if (!defined $var_type{$var} && $type eq '+')
5673         {
5674           am_line_error ($var, "$var must be set with `=' before using `+='");
5675         }
5676     }
5677   $var_type{$var} = $type;
5679   # When adding, since we rewrite, don't try to preserve the
5680   # Automake continuation backslashes.
5681   $value =~ s/\\$//mg
5682     if $type eq '+' && $var_is_am;
5684   # Differentiate the first assignment (including with `+=').
5685   if ($type eq '+' && defined $var_value{$var}{$cond})
5686     {
5687       if (substr ($var_value{$var}{$cond}, -1) eq "\n")
5688         {
5689           # Insert a backslash before a trailing newline.
5690           $var_value{$var}{$cond} =
5691             substr ($var_value{$var}{$cond}, 0, -1) . "\\\n";
5692         }
5693       elsif ($var_value{$var}{$cond})
5694         {
5695           # Insert a separator.
5696           $var_value{$var}{$cond} .= ' ';
5697         }
5698        $var_value{$var}{$cond} .= $value;
5699     }
5700   else
5701     {
5702       # The first assignment to a macro sets the line number.  Ideally I
5703       # suppose we would associate line numbers with random bits of text.
5704       # FIXME: We sometimes redefine some variables, but we want to keep
5705       # the original location.  More subs are needed to handle
5706       # properly variables.  Once this done, remove this hack.
5707       $var_line{$var} = $where
5708         unless defined $var_line{$var};
5710       # If Automake tries to override a value specified by the user,
5711       # just don't let it do.
5712       if (defined $var_value{$var}{$cond} && !$var_is_am{$var} && $var_is_am)
5713         {
5714           if ($verbose)
5715             {
5716               print STDERR "$me: refusing to override the user definition of:\n";
5717               macro_dump ($var);
5718               print STDERR "$me: with `$cond' => `$value'\n";
5719             }
5720         }
5721       else
5722         {
5723           # There must be no previous value unless the user is redefining
5724           # an Automake variable or an AC_SUBST variable.
5725           check_ambiguous_conditional ($var, $cond)
5726             unless ($var_is_am{$var} && !$var_is_am
5727                     || exists $configure_vars{$var});
5729           $var_value{$var}{$cond} = $value;
5730         }
5731     }
5733   # An Automake variable can be given to the user, but not the converse.
5734   if (! defined $var_is_am{$var} || !$var_is_am)
5735     {
5736       $var_is_am{$var} = $var_is_am;
5737     }
5741 # &variable_delete ($VAR, [@CONDS])
5742 # ---------------------------------
5743 # Forget about $VAR under the conditions @CONDS, or completely if
5744 # @CONDS is empty.
5745 sub variable_delete ($@)
5747   my ($var, @conds) = @_;
5749   if (!@conds)
5750     {
5751       delete $var_value{$var};
5752       delete $var_line{$var};
5753       delete $var_is_am{$var};
5754       delete $var_comment{$var};
5755       delete $var_type{$var};
5756     }
5757   else
5758     {
5759       foreach my $cond (@conds)
5760         {
5761           delete $var_value{$var}{$cond};
5762         }
5763     }
5767 # &macro_dump ($VAR)
5768 # ------------------
5769 sub macro_dump ($)
5771   my ($var) = @_;
5773   if (!exists $var_value{$var})
5774     {
5775       print STDERR "  $var does not exist\n";
5776     }
5777   else
5778     {
5779       my $var_is_am = $var_is_am{$var} ? "Automake" : "User";
5780       my $where = (defined $var_line{$var}
5781                    ? $var_line{$var} : "undefined");
5782       print STDERR "$var_comment{$var}"
5783         if defined $var_comment{$var};
5784       print STDERR "  $var ($var_is_am, where = $where) $var_type{$var}=\n";
5785       print STDERR "  {\n";
5786       foreach my $vcond (sort by_condition keys %{$var_value{$var}})
5787         {
5788           print STDERR "    $vcond => $var_value{$var}{$vcond}\n";
5789         }
5790       print STDERR "  }\n";
5791     }
5795 # &macros_dump ()
5796 # ---------------
5797 sub macros_dump ()
5799   my ($var) = @_;
5801   print STDERR "%var_value =\n";
5802   print STDERR "{\n";
5803   foreach my $var (sort (keys %var_value))
5804     {
5805       macro_dump ($var);
5806     }
5807   print STDERR "}\n";
5811 # $BOOLEAN
5812 # &variable_defined ($VAR, [$COND])
5813 # ---------------------------------
5814 # See if a variable exists.  $VAR is the variable name, and $COND is
5815 # the condition which we should check.  If no condition is given, we
5816 # currently return true if the variable is defined under any
5817 # condition.
5818 sub variable_defined ($$)
5820     my ($var, $cond) = @_;
5822     # Unfortunately we can't just check for $var_value{VAR}{COND}
5823     # as this would make perl create $condition{VAR}, which we
5824     # don't want.
5825     if (!exists $var_value{$var})
5826       {
5827         if (defined $targets{$var})
5828           {
5829             &am_line_error ($var, "`$var' is a target; expected a variable")
5830           }
5831         # The variable is not defined
5832         return 0;
5833       }
5835     if ($cond && !exists $var_value{$var}{$cond})
5836       {
5837         # The variable is not defined for the given condition.
5838         return 0;
5839       }
5841     # Even a var_value examination is good enough for us.  FIXME:
5842     # really should maintain examined status on a per-condition basis.
5843     $content_seen{$var} = 1;
5844     return 1;
5847 # Mark a variable as examined.
5848 sub examine_variable
5850     my ($var) = @_;
5851     &variable_defined ($var);
5854 # Return the set of conditions for which a variable is defined.
5856 # If the variable is not defined conditionally, and is not defined in
5857 # terms of any variables which are defined conditionally, then this
5858 # returns the empty list.
5860 # If the variable is defined conditionally, but is not defined in
5861 # terms of any variables which are defined conditionally, then this
5862 # returns the list of conditions for which the variable is defined.
5864 # If the variable is defined in terms of any variables which are
5865 # defined conditionally, then this returns a full set of permutations
5866 # of the subvariable conditions.  For example, if the variable is
5867 # defined in terms of a variable which is defined for COND_TRUE,
5868 # then this returns both COND_TRUE and COND_FALSE.  This is
5869 # because we will need to define the variable under both conditions.
5871 sub variable_conditions ($)
5873     my ($var) = @_;
5874     my %uniqify;
5875     my @uniq_list;
5877     %vars_scanned = ();
5879     my @new_conds = &variable_conditions_sub ($var, '', ());
5880     # Now we want to return all permutations of the subvariable
5881     # conditions.
5882     my %allconds = ();
5883     foreach my $item (@new_conds)
5884     {
5885         foreach (split (' ', $item))
5886         {
5887             s/^(.*)_(TRUE|FALSE)$/$1_TRUE/;
5888             $allconds{$_} = 1;
5889         }
5890     }
5891     @new_conds = &variable_conditions_permutations (sort keys %allconds);
5893     foreach my $cond (@new_conds)
5894     {
5895         my $reduce = &variable_conditions_reduce (split (' ', $cond));
5896         next
5897             if $reduce eq 'FALSE';
5898         $uniqify{$cond} = 1;
5899     }
5901     @uniq_list = sort by_condition keys %uniqify;
5902     # Note we cannot just do `return sort keys %uniqify', because this
5903     # function is sometimes used in a scalar context.
5904     return @uniq_list;
5908 # $BOOLEAN
5909 # &variable_conditionally_defined ($VAR)
5910 # --------------------------------------
5911 sub variable_conditionally_defined ($)
5913     my ($var) = @_;
5914     foreach my $cond (variable_conditions ($var))
5915       {
5916         return 1
5917           unless $cond =~ /^TRUE|FALSE$/;
5918       }
5919     return 0;
5924 # &variable_conditions_sub ($VAR, $PARENT, @PARENT_CONDS)
5925 # -------------------------------------------------------
5926 # A subroutine of variable_conditions.  This returns all the
5927 # conditions of $VAR which are satisfiable when all of @PARENT_CONDS
5928 # are true.
5929 sub variable_conditions_sub
5931     my ($var, $parent, @parent_conds) = @_;
5932     my @new_conds = ();
5934     if (defined $vars_scanned{$var})
5935     {
5936         &am_line_error ($parent, "variable `$var' recursively defined");
5937         return ();
5938     }
5939     $vars_scanned{$var} = 1;
5941     my @this_conds = ();
5942     # Examine every condition under which $VAR is defined.
5943     foreach my $vcond (keys %{$var_value{$var}})
5944     {
5945         # If this condition cannot be true when the parent conditions
5946         # are true, then skip it.
5947         next
5948           if ! conditionals_true_when (@parent_conds, $vcond);
5950         push (@this_conds, $vcond);
5952         # If $VAR references some other variable, then compute the
5953         # conditions for that subvariable.
5954         push (@parent_conds, $vcond);
5955         my @subvar_conds = ();
5956         foreach (split (' ', $var_value{$var}{$vcond}))
5957         {
5958             # If a comment seen, just leave.
5959             last if /^#/;
5961             # Handle variable substitutions.
5962             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5963             {
5965                 # Here we compute all the conditions under which the
5966                 # subvariable is defined.  Then we go through and add
5967                 # $VCOND to each.
5968                 my @svc = &variable_conditions_sub ($1, $var, @parent_conds);
5969                 foreach my $item (@svc)
5970                 {
5971                     my $val = conditional_string ($vcond, split (' ', $item));
5972                     $val ||= 'TRUE';
5973                     push (@subvar_conds, $val);
5974                 }
5975             }
5976         }
5977         pop (@parent_conds);
5979         # If there are no conditional subvariables, then we want to
5980         # return this condition.  Otherwise, we want to return the
5981         # permutations of the subvariables, taking into account the
5982         # conditions of $VAR.
5983         if (! @subvar_conds)
5984         {
5985             push (@new_conds, $vcond);
5986         }
5987         else
5988         {
5989             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
5990         }
5991     }
5993     # Unset our entry in vars_scanned.  We only care about recursive
5994     # definitions.
5995     delete $vars_scanned{$var};
5997     # If we are being called on behalf of another variable, we need to
5998     # return all possible permutations of the conditions.  We have
5999     # already handled everything in @this_conds along with their
6000     # subvariables.  We now need to add any permutations that are not
6001     # in @this_conds.
6002     foreach my $this_cond (@this_conds)
6003     {
6004         my @perms =
6005             &variable_conditions_permutations (split(' ', $this_cond));
6006         foreach my $perm (@perms)
6007         {
6008             my $ok = 1;
6009             foreach my $scan (@this_conds)
6010             {
6011                 if (&conditional_true_when ($perm, $scan)
6012                     || &conditional_true_when ($scan, $perm))
6013                 {
6014                     $ok = 0;
6015                     last;
6016                 }
6017             }
6018             next if ! $ok;
6020             next
6021               if ! conditionals_true_when (@parent_conds, $perm);
6023             # This permutation was not already handled, and is valid
6024             # for the parents.
6025             push (@new_conds, $perm);
6026         }
6027     }
6029     return @new_conds;
6033 # Filter a list of conditionals so that only the exclusive ones are
6034 # retained.  For example, if both `COND1_TRUE COND2_TRUE' and
6035 # `COND1_TRUE' are in the list, discard the latter.
6036 # If the list is empty, return TRUE
6037 sub variable_conditions_reduce
6039     my (@conds) = @_;
6040     my @ret = ();
6041     my $cond;
6042     while(@conds > 0)
6043     {
6044         $cond = shift(@conds);
6046         # FALSE is absorbent.
6047         if ($cond eq 'FALSE')
6048           {
6049             return ('FALSE');
6050           }
6051         elsif (!conditional_is_redundant ($cond, @ret, @conds))
6052           {
6053             push (@ret, $cond);
6054           }
6055     }
6057     return "TRUE" if @ret == 0;
6058     return @ret;
6061 # Return a list of permutations of a conditional string.
6062 sub variable_conditions_permutations
6064     my (@comps) = @_;
6065     return ()
6066         if ! @comps;
6067     my $comp = shift (@comps);
6068     return &variable_conditions_permutations (@comps)
6069         if $comp eq '';
6070     my $neg = condition_negate ($comp);
6072     my @ret;
6073     foreach my $sub (&variable_conditions_permutations (@comps))
6074     {
6075         push (@ret, "$comp $sub");
6076         push (@ret, "$neg $sub");
6077     }
6078     if (! @ret)
6079     {
6080         push (@ret, $comp);
6081         push (@ret, $neg);
6082     }
6083     return @ret;
6087 # $BOOL
6088 # &check_variable_defined_unconditionally($VAR, $PARENT)
6089 # ------------------------------------------------------
6090 # Warn if a variable is conditionally defined.  This is called if we
6091 # are using the value of a variable.
6092 sub check_variable_defined_unconditionally ($$)
6094     my ($var, $parent) = @_;
6095     foreach my $cond (keys %{$var_value{$var}})
6096     {
6097         next
6098           if $cond =~ /^TRUE|FALSE$/;
6100         if ($parent)
6101         {
6102             &am_line_error ($parent,
6103                             "warning: automake does not support conditional definition of $var in $parent");
6104         }
6105         else
6106         {
6107             &am_line_error ($parent,
6108                             "warning: automake does not support $var being defined conditionally");
6109             macro_dump ($var);
6111         }
6112     }
6116 # Get the TRUE value of a variable, warn if the variable is
6117 # conditionally defined.
6118 sub variable_value
6120     my ($var) = @_;
6121     &check_variable_defined_unconditionally ($var);
6122     return $var_value{$var}{'TRUE'};
6126 # @VALUES
6127 # &value_to_list ($VAR, $VAL, $COND)
6128 # ----------------------------------
6129 # Convert a variable value to a list, split as whitespace.  This will
6130 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
6131 # substitutions.
6133 # If COND is 'all', then all values under all conditions should be
6134 # returned; if COND is a particular condition (all conditions are
6135 # surrounded by @...@) then only the value for that condition should
6136 # be returned; otherwise, warn if VAR is conditionally defined.
6137 # SCANNED is a global hash listing whose keys are all the variables
6138 # already scanned; it is an error to rescan a variable.
6139 sub value_to_list
6141     my ($var, $val, $cond) = @_;
6142     my @result;
6144     # Strip backslashes
6145     $val =~ s/\\(\n|$)/ /g;
6147     foreach (split (' ', $val))
6148     {
6149         # If a comment seen, just leave.
6150         last if /^#/;
6152         # Handle variable substitutions.
6153         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
6154         {
6155             my $varname = $1;
6157             # If the user uses a losing variable name, just ignore it.
6158             # This isn't ideal, but people have requested it.
6159             next if ($varname =~ /\@.*\@/);
6161             my ($from, $to);
6162             my @temp_list;
6163             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
6164             {
6165                 $varname = $1;
6166                 $to = $3;
6167                 ($from = $2) =~ s/(\W)/\\$1/g;
6168             }
6170             # Find the value.
6171             @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
6173             # Now rewrite the value if appropriate.
6174             if ($from)
6175             {
6176                 grep (s/$from$/$to/, @temp_list);
6177             }
6179             push (@result, @temp_list);
6180         }
6181         else
6182         {
6183             push (@result, $_);
6184         }
6185     }
6187     return @result;
6190 # Return contents of variable as list, split as whitespace.  This will
6191 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
6192 # substitutions.  If COND is 'all', then all values under all
6193 # conditions should be returned; if COND is a particular condition
6194 # (all conditions are surrounded by @...@) then only the value for
6195 # that condition should be returned; otherwise, warn if VAR is
6196 # conditionally defined.  If PARENT is specified, it is the name of
6197 # the including variable; this is only used for error reports.
6198 sub variable_value_as_list_worker
6200     my ($var, $cond, $parent) = @_;
6201     my @result = ();
6203     if (! defined $var_value{$var})
6204     {
6205         if (defined $targets{$var})
6206           {
6207             &am_line_error ($var, "`$var' is a target; expected a variable");
6208           }
6209         else
6210           {
6211             &am_line_error ($parent, "variable `$var' not defined");
6212           }
6213     }
6214     elsif (defined $vars_scanned{$var})
6215     {
6216         # `vars_scanned' is a global we use to keep track of which
6217         # variables we've already examined.
6218         &am_line_error ($parent, "variable `$var' recursively defined");
6219     }
6220     elsif ($cond eq 'all')
6221     {
6222         $vars_scanned{$var} = 1;
6223         foreach my $vcond (keys %{$var_value{$var}})
6224         {
6225             my $val = $var_value{$var}{$vcond};
6226             push (@result, &value_to_list ($var, $val, $cond));
6227         }
6228     }
6229     else
6230     {
6231         $cond ||= 'TRUE';
6232         $vars_scanned{$var} = 1;
6233         my $onceflag;
6234         foreach my $vcond (keys %{$var_value{$var}})
6235         {
6236             my $val = $var_value{$var}{$vcond};
6237             if (&conditional_true_when ($vcond, $cond))
6238             {
6239                 # Warn if we have an ambiguity.  It's hard to know how
6240                 # to handle this case correctly.
6241                 &check_variable_defined_unconditionally ($var, $parent)
6242                     if $onceflag;
6243                 $onceflag = 1;
6244                 push (@result, &value_to_list ($var, $val, $cond));
6245             }
6246         }
6247     }
6249     # Unset our entry in vars_scanned.  We only care about recursive
6250     # definitions.
6251     delete $vars_scanned{$var};
6253     return @result;
6257 # &variable_output ($VAR, [@CONDS])
6258 # ---------------------------------
6259 # Output all the values of $VAR is @COND is not specified, else only
6260 # that corresponding to @COND.
6261 sub variable_output ($@)
6263   my ($var, @conds) = @_;
6265   @conds = sort by_condition keys %{$var_value{$var}}
6266     unless @conds;
6268   $output_vars .= $var_comment{$var}
6269     if defined $var_comment{$var};
6271   foreach my $cond (@conds)
6272     {
6273       my $val = $var_value{$var}{$cond};
6274       my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6275       my $output_var = "$var $equals $val";
6276       $output_var =~ s/^/make_condition ($cond)/meg;
6277       $output_vars .= $output_var . "\n";
6278     }
6282 # &variable_pretty_output ($VAR, [@CONDS])
6283 # ----------------------------------------
6284 # Likewise, but pretty, i.e., we *split* the values at spaces.   Use only
6285 # with variables holding filenames.
6286 sub variable_pretty_output ($@)
6288   my ($var, @conds) = @_;
6290   @conds = sort by_condition keys %{$var_value{$var}}
6291     unless @conds;
6293   $output_vars .= $var_comment{$var}
6294     if defined $var_comment{$var};
6296   foreach my $cond (@conds)
6297     {
6298       my $val = $var_value{$var}{$cond};
6299       my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6300       my $make_condition = make_condition ($cond);
6301       $output_vars .= pretty_print_internal ("$make_condition$var $equals",
6302                                              "$make_condition\t",
6303                                              split (' ' , $val));
6304     }
6308 # This is just a wrapper for variable_value_as_list_worker that
6309 # initializes the global hash `vars_scanned'.  This hash is used to
6310 # avoid infinite recursion.
6311 sub variable_value_as_list
6313     my ($var, $cond, $parent) = @_;
6314     %vars_scanned = ();
6315     return &variable_value_as_list_worker ($var, $cond, $parent);
6319 # Like define_variable, but the value is a list, and the variable may
6320 # be defined conditionally.  The second argument is the conditional
6321 # under which the value should be defined; this should be the empty
6322 # string to define the variable unconditionally.  The third argument
6323 # is a list holding the values to use for the variable.  The value is
6324 # pretty printed in the output file.
6325 sub define_pretty_variable
6327     my ($var, $cond, @value) = @_;
6329     # Beware that an empty $cond has a different semantics for
6330     # macro_define and variable_pretty_output.
6331     $cond ||= 'TRUE';
6333     if (! &variable_defined ($var, $cond))
6334     {
6335         macro_define ($var, 1, '', $cond, join (' ', @value), undef);
6336         variable_pretty_output ($var, $cond || 'TRUE');
6337         $content_seen{$var} = 1;
6338     }
6342 # define_variable ($VAR, $VALUE)
6343 # ------------------------------
6344 # Define a new user variable VAR to VALUE, but only if not already defined.
6345 sub define_variable
6347     my ($var, $value) = @_;
6349     define_pretty_variable ($var, 'TRUE', $value);
6353 # Like define_variable, but define a variable to be the configure
6354 # substitution by the same name.
6355 sub define_configure_variable
6357     my ($var) = @_;
6358     my $value = '@' . $var . '@';
6359     &define_variable ($var, $value);
6363 # define_compiler_variable ($LANG)
6364 # --------------------------------
6365 # Define a compiler variable.  We also handle defining the `LT'
6366 # version of the command when using libtool.
6367 sub define_compiler_variable ($)
6369     my ($lang) = @_;
6371     my ($var, $value) = ($lang->compiler, $lang->compile);
6372     &define_variable ($var, $value);
6373     &define_variable ("LT$var", "\$(LIBTOOL) --mode=compile $value")
6374       if $seen_libtool;
6378 # define_linker_variable ($LANG)
6379 # ------------------------------
6380 # Define linker variables.
6381 sub define_linker_variable ($)
6383     my ($lang) = @_;
6385     my ($var, $value) = ($lang->lder, $lang->ld);
6386     # CCLD = $(CC).
6387     &define_variable ($lang->lder, $lang->ld);
6388     # CCLINK = $(CCLD) blah blah...
6389     &define_variable ($lang->linker,
6390                       (($seen_libtool ? '$(LIBTOOL) --mode=link ' : '')
6391                        . $lang->link));
6394 ################################################################
6396 ## ---------------- ##
6397 ## Handling rules.  ##
6398 ## ---------------- ##
6400 sub rule_define ($$$$)
6402   my ($target, $rule_is_am, $cond, $where) = @_;
6404   if (defined $targets{$target}
6405       && ($cond
6406           ? ! defined $target_conditional{$target}
6407           : defined $target_conditional{$target}))
6408     {
6409       &am_line_error ($target,
6410                       "$target defined both conditionally and unconditionally");
6411     }
6413   # Value here doesn't matter; for targets we only note existence.
6414   $targets{$target} = $where;
6415   if ($cond)
6416     {
6417       if ($target_conditional{$target})
6418         {
6419           &check_ambiguous_conditional ($target, $cond);
6420         }
6421       $target_conditional{$target}{$cond} = $where;
6422     }
6425   # Check the rule for being a suffix rule. If so, store in a hash.
6427   if ((my ($source_suffix, $object_suffix)) = ($target =~ $SUFFIX_RULE_PATTERN))
6428   {
6429     $suffix_rules{$source_suffix} = $object_suffix;
6430     print "Sources ending in .$source_suffix become .$object_suffix\n"
6431       if $verbose;
6432     # Set SUFFIXES from suffix_rules.
6433     push @suffixes, ".$source_suffix", ".$object_suffix";
6434   }
6438 # See if a target exists.
6439 sub target_defined
6441     my ($target) = @_;
6442     return defined $targets{$target};
6446 ################################################################
6448 # Read Makefile.am and set up %contents.  Simultaneously copy lines
6449 # from Makefile.am into $output_trailer or $output_vars as
6450 # appropriate.  NOTE we put rules in the trailer section.  We want
6451 # user rules to come after our generated stuff.
6452 sub read_am_file
6454     my ($amfile) = @_;
6456     my $am_file = new IO::File ("< $amfile");
6457     if (! $am_file)
6458     {
6459         die "$me: couldn't open `$amfile': $!\n";
6460     }
6461     print "$me: reading $amfile\n" if $verbose;
6463     my $spacing = '';
6464     my $comment = '';
6465     my $blank = 0;
6467     while ($_ = $am_file->getline)
6468     {
6469         if (/$IGNORE_PATTERN/o)
6470         {
6471             # Merely delete comments beginning with two hashes.
6472         }
6473         elsif (/$WHITE_PATTERN/o)
6474         {
6475             # Stick a single white line before the incoming macro or rule.
6476             $spacing = "\n";
6477             $blank = 1;
6478         }
6479         elsif (/$COMMENT_PATTERN/o)
6480         {
6481             # Stick comments before the incoming macro or rule.  Make
6482             # sure a blank line preceeds first block of comments.
6483             $spacing = "\n" unless $blank;
6484             $blank = 1;
6485             $comment .= $spacing . $_;
6486             $spacing = '';
6487         }
6488         else
6489         {
6490             last;
6491         }
6492     }
6494     $output_vars .= $comment . "\n";
6495     $comment = '';
6496     $spacing = "\n";
6498     # We save the conditional stack on entry, and then check to make
6499     # sure it is the same on exit.  This lets us conditonally include
6500     # other files.
6501     my @saved_cond_stack = @cond_stack;
6502     my $cond = conditional_string (@cond_stack);
6504     my $saw_bk = 0;
6505     my $was_rule = 0;
6506     my $last_var_name = '';
6507     my $last_var_type = '';
6508     my $last_var_value = '';
6509     # FIXME: shouldn't use $_ in this loop; it is too big.
6510     while ($_)
6511     {
6512         $_ .= "\n"
6513             unless substr ($_, -1, 1) eq "\n";
6515         # Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
6516         # used by users.  @MAINT@ is an anachronism now.
6517         $_ =~ s/\@MAINT\@//g
6518             unless $seen_maint_mode;
6520         my $new_saw_bk = /\\$/ && ! /$COMMENT_PATTERN/o;
6522         if (/$IGNORE_PATTERN/o)
6523         {
6524             # Merely delete comments beginning with two hashes.
6525         }
6526         elsif (/$WHITE_PATTERN/o)
6527         {
6528             # Stick a single white line before the incoming macro or rule.
6529             $spacing = "\n";
6530             &am_line_error ($., "blank line following trailing backslash")
6531                 if $saw_bk;
6532         }
6533         elsif (/$COMMENT_PATTERN/o)
6534         {
6535             # Stick comments before the incoming macro or rule.
6536             $comment .= $spacing . $_;
6537             $spacing = '';
6538             &am_line_error ($., "comment following trailing backslash")
6539                 if $saw_bk;
6540         }
6541         elsif ($saw_bk)
6542         {
6543             if ($was_rule)
6544             {
6545                 $output_trailer .= &make_condition (@cond_stack);
6546                 $output_trailer .= $_;
6547             }
6548             else
6549             {
6550               $last_var_value .= ' '
6551                 unless $last_var_value =~ /\s$/;
6552               $last_var_value .= $_;
6554               if (!/\\$/)
6555                 {
6556                   $var_comment{$last_var_name} .= "$spacing"
6557                     if (!defined $var_comment{$last_var_name}
6558                         || substr ($var_comment{$last_var_name}, -1) ne "\n");
6559                   $var_comment{$last_var_name} .= "$comment";
6560                   $comment = $spacing = '';
6561                   macro_define ($last_var_name, 0,
6562                                 $last_var_type, $cond,
6563                                 $last_var_value, $.)
6564                     if $cond ne 'FALSE';
6565                   push (@var_list, $last_var_name);
6566                 }
6567             }
6568         }
6570         elsif (/$IF_PATTERN/o)
6571           {
6572             $cond = cond_stack_if ($1, $2, "$amfile:$.");
6573           }
6574         elsif (/$ELSE_PATTERN/o)
6575           {
6576             $cond = cond_stack_else ($1, $2, "$amfile:$.");
6577           }
6578         elsif (/$ENDIF_PATTERN/o)
6579           {
6580             $cond = cond_stack_endif ($1, $2, "$amfile:$.");
6581           }
6583         elsif (/$RULE_PATTERN/o)
6584         {
6585             # Found a rule.
6586             $was_rule = 1;
6588             rule_define ($1, 0, $cond, $.);
6590             $var_line{$1} = $.;
6591             $output_trailer .= $comment . $spacing;
6592             $output_trailer .= &make_condition (@cond_stack);
6593             $output_trailer .= $_;
6594             $comment = $spacing = '';
6595         }
6596         elsif (/$ASSIGNMENT_PATTERN/o)
6597         {
6598             # Found a macro definition.
6599             $was_rule = 0;
6600             $last_var_name = $1;
6601             $last_var_type = $2;
6602             $last_var_value = $3;
6603             if ($3 ne '' && substr ($3, -1) eq "\\")
6604             {
6605                 # We preserve the `\' because otherwise the long lines
6606                 # that are generated will be truncated by broken
6607                 # `sed's.
6608                 $last_var_value = $3 . "\n";
6609             }
6611             if (!/\\$/)
6612               {
6613                 # FIXME: this doesn't always work correctly; it will
6614                 # group all comments for a given variable, no matter
6615                 # where defined.
6616                 # Accumulating variables must not be output.
6617                 $var_comment{$last_var_name} .= "$spacing"
6618                   if (!defined $var_comment{$last_var_name}
6619                       || substr ($var_comment{$last_var_name}, -1) ne "\n");
6620                 $var_comment{$last_var_name} .= "$comment";
6621                 $comment = $spacing = '';
6623                 macro_define ($last_var_name, 0,
6624                               $last_var_type, $cond,
6625                               $last_var_value, $.)
6626                   if $cond ne 'FALSE';
6627                 push (@var_list, $last_var_name);
6628               }
6629         }
6630         elsif (/$INCLUDE_PATTERN/o)
6631         {
6632             my $path = $1;
6634             if ($path =~ s/^\$\(top_srcdir\)\///)
6635             {
6636                 push (@include_stack, "\$\(top_srcdir\)/$path");
6637             }
6638             else
6639             {
6640                 $path =~ s/\$\(srcdir\)\///;
6641                 push (@include_stack, "\$\(srcdir\)/$path");
6642                 $path = $relative_dir . "/" . $path;
6643             }
6644             &read_am_file ($path);
6645         }
6646         else
6647         {
6648             # This isn't an error; it is probably a continued rule.
6649             # In fact, this is what we assume.
6650             $was_rule = 1;
6651             $output_trailer .= $comment . $spacing;
6652             $output_trailer .= &make_condition  (@cond_stack);
6653             $output_trailer .= $_;
6654             $comment = $spacing = '';
6655             &am_line_error ($., "`#' comment at start of rule is unportable")
6656                 if $_ =~ /^\t\s*\#/;
6657         }
6659         $saw_bk = $new_saw_bk;
6660         $_ = $am_file->getline;
6661     }
6663     $output_trailer .= $comment;
6665     if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
6666     {
6667         if (@cond_stack)
6668         {
6669             &am_error ("unterminated conditionals: @cond_stack");
6670         }
6671         else
6672         {
6673             # FIXME: better error message here.
6674             &am_error ("conditionals not nested in include file");
6675         }
6676     }
6680 # define_standard_variables ()
6681 # ----------------------------
6682 # A helper for read_main_am_file which initializes configure variables
6683 # and variables from header-vars.am.  This is a subr so we can call it
6684 # twice.
6685 sub define_standard_variables
6687     my $saved_output_vars = $output_vars;
6688     my ($comments, undef, $rules) =
6689       file_contents_internal (1, "$libdir/am/header-vars.am");
6691     # This will output the definitions in $output_vars, which we don't
6692     # want...
6693     foreach my $var (sort keys %configure_vars)
6694     {
6695         &define_configure_variable ($var);
6696         push (@var_list, $var);
6697     }
6699     # ... hence, we restore $output_vars.
6700     $output_vars = $saved_output_vars . $comments . $rules;
6703 # Read main am file.
6704 sub read_main_am_file
6706     my ($amfile) = @_;
6708     # This supports the strange variable tricks we are about to play.
6709     if (scalar keys %var_value > 0)
6710       {
6711         macros_dump ();
6712         &prog_error ("variable defined before read_main_am_file");
6713       }
6715     # Generate copyright header for generated Makefile.in.
6716     # We do discard the output of predefined variables, handled below.
6717     $output_vars = ("# $in_file_name generated automatically by automake "
6718                    . $VERSION . " from $am_file_name.\n");
6719     $output_vars .= $gen_copyright;
6721     # We want to predefine as many variables as possible.  This lets
6722     # the user set them with `+=' in Makefile.am.  However, we don't
6723     # want these initial definitions to end up in the output quite
6724     # yet.  So we just load them, but output them later.
6725     &define_standard_variables;
6727     # Read user file, which might override some of our values.
6728     &read_am_file ($amfile);
6730     # Ouput all the Automake variables.  If the user changed one, then
6731     # it is now marked as owned by the user.
6732     foreach my $var (uniq @var_list)
6733     {
6734         # Don't process user variables.
6735         variable_output ($var)
6736           unless !$var_is_am{$var};
6737     }
6739     # Now dump the user variables that were defined.  We do it in the same
6740     # order in which they were defined (skipping duplicates).
6741     foreach my $var (uniq @var_list)
6742     {
6743         # Don't process Automake variables.
6744         variable_output ($var)
6745           unless $var_is_am{$var};
6746     }
6749 ################################################################
6751 # $FLATTENED
6752 # &flatten ($STRING)
6753 # ------------------
6754 # Flatten the $STRING and return the result.
6755 sub flatten
6757   $_ = shift;
6759   s/\\\n//somg;
6760   s/\s+/ /g;
6761   s/^ //;
6762   s/ $//;
6764   return $_;
6768 # @PARAGRAPHS
6769 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
6770 # ------------------------------------------
6771 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6772 # paragraphs.
6773 sub make_paragraphs ($%)
6775     my ($file, %transform) = @_;
6777     # Complete %transform with global options and make it a Perl
6778     # $command.
6779     my $command =
6780       "s/$IGNORE_PATTERN//gm;"
6781         . transform (%transform,
6783                      'CYGNUS'          => $cygnus_mode,
6784                      'MAINTAINER-MODE'
6785                      => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
6787                      'SHAR'        => $options{'dist-shar'} || 0,
6788                      'BZIP2'       => $options{'dist-bzip2'} || 0,
6789                      'ZIP'         => $options{'dist-zip'} || 0,
6790                      'COMPRESS'    => $options{'dist-tarZ'} || 0,
6792                      'INSTALL-INFO' => !$options{'no-installinfo'},
6793                      'INSTALL-MAN'  => !$options{'no-installman'},
6794                      'CK-NEWS'      => $options{'check-news'} || 0,
6796                      'SUBDIRS'      => &variable_defined ('SUBDIRS'),
6797                      'TOPDIR'       => backname ($relative_dir),
6798                      'TOPDIR_P'     => $relative_dir eq '.',
6799                      'CONFIGURE-AC' => $configure_ac,
6801                      'BUILD'    => $seen_canonical == $AC_CANONICAL_SYSTEM,
6802                      'HOST'     => $seen_canonical,
6803                      'TARGET'   => $seen_canonical == $AC_CANONICAL_SYSTEM,
6805                      'EXEEXT'   => ($seen_exeext ? '$(EXEEXT)' : ''),
6807                      'LIBTOOL'      => defined $configure_vars{'LIBTOOL'})
6808           # We don't need more than two consecutive new-lines.
6809           . 's/\n{3,}/\n\n/g';
6811     # Swallow the file and apply the COMMAND.
6812     my $fc_file = new IO::File ("< $file");
6813     if (! $fc_file)
6814     {
6815         die "$me: installation error: cannot open `$file'\n";
6816     }
6817     # Looks stupid?
6818     print "$me: reading $file\n"
6819       if $verbose;
6820     my $saved_dollar_slash = $/;
6821     undef $/;
6822     $_ = $fc_file->getline;
6823     $/ = $saved_dollar_slash;
6824     eval $command;
6825     $fc_file->close;
6826     my $content = $_;
6828     # Split at unescaped new lines.
6829     my @lines = split (/(?<!\\)\n/, $content);
6830     my @res;
6832     while (defined ($_ = shift @lines))
6833       {
6834         my $paragraph = "$_";
6835         # If we are a rule, eat as long as we start with a tab.
6836         if (/$RULE_PATTERN/smo)
6837           {
6838             while (defined ($_ = shift @lines) && $_ =~ /^\t/)
6839               {
6840                 $paragraph .= "\n$_";
6841               }
6842             unshift (@lines, $_);
6843           }
6845         # If we are a comments, eat as much comments as you can.
6846         elsif (/$COMMENT_PATTERN/smo)
6847           {
6848             while (defined ($_ = shift @lines)
6849                    && $_ =~ /$COMMENT_PATTERN/smo)
6850               {
6851                 $paragraph .= "\n$_";
6852               }
6853             unshift (@lines, $_);
6854           }
6856         push @res, $paragraph;
6857         $paragraph = '';
6858       }
6860     return @res;
6865 # ($COMMENT, $VARIABLES, $RULES)
6866 # &file_contents_internal ($IS_AM, $FILE, [%TRANSFORM])
6867 # -----------------------------------------------------
6868 # Return contents of a file from $libdir/am, automatically skipping
6869 # macros or rules which are already known. $IS_AM iff the caller is
6870 # reading an Automake file (as opposed to the user's Makefile.am).
6871 sub file_contents_internal ($$%)
6873     my ($is_am, $file, %transform) = @_;
6875     my $result_vars = '';
6876     my $result_rules = '';
6877     my $comment = '';
6878     my $spacing = '';
6880     # We save the conditional stack on entry, and then check to make
6881     # sure it is the same on exit.  This lets us conditonally include
6882     # other files.
6883     my @saved_cond_stack = @cond_stack;
6884     my $cond = conditional_string (@cond_stack);
6886     foreach (make_paragraphs ($file, %transform))
6887     {
6888         # Sanity checks.
6889         &am_file_error ($file, "blank line following trailing backslash:\n$_")
6890           if /\\$/;
6891         &am_file_error ($file, "comment following trailing backslash:\n$_")
6892           if /\\#/;
6894         if (/^$/)
6895         {
6896             # Stick empty line before the incoming macro or rule.
6897             $spacing = "\n";
6898         }
6899         elsif (/$COMMENT_PATTERN/mso)
6900         {
6901             # Stick comments before the incoming macro or rule.
6902             $comment = "$_\n";
6903         }
6905         # Handle inclusion of other files.
6906         elsif (/$INCLUDE_PATTERN/o)
6907         {
6908             if ($cond ne 'FALSE')
6909               {
6910                 my $file = ($is_am ? "$libdir/am/" : '') . $1;
6911                 # N-ary `.=' fails.
6912                 my ($com, $vars, $rules)
6913                   = file_contents_internal ($is_am, $file, %transform);
6914                 $comment .= $com;
6915                 $result_vars .= $vars;
6916                 $result_rules .= $rules;
6917               }
6918         }
6920         # Handling the conditionals.
6921         elsif (/$IF_PATTERN/o)
6922           {
6923             $cond = cond_stack_if ($1, $2, $file);
6924           }
6925         elsif (/$ELSE_PATTERN/o)
6926           {
6927             $cond = cond_stack_else ($1, $2, $file);
6928           }
6929         elsif (/$ENDIF_PATTERN/o)
6930           {
6931             $cond = cond_stack_endif ($1, $2, $file);
6932           }
6934         # Handling rules.
6935         elsif (/$RULE_PATTERN/mso)
6936         {
6937           # Separate relationship from optional actions: the first
6938           # `new-line tab" not preceded by backslash (continuation
6939           # line).
6940           # I'm quite shoked!  It seems that (\\\n|[^\n]) is not the
6941           # same as `([^\n]|\\\n)!!!  Don't swap it, it breaks.
6942           my $paragraph = $_;
6943           /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
6944           my ($relationship, $actions) = ($1, $2 || '');
6946           # Separate targets from dependencies: the first colon.
6947           $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
6948           my ($targets, $dependencies) = ($1, $2);
6949           # Remove the escaped new lines.
6950           # I don't know why, but I have to use a tmp $flat_deps.
6951           my $flat_deps = &flatten ($dependencies);
6952           my @deps = split (' ', $flat_deps);
6954           foreach (split (' ' , $targets))
6955             {
6956               # FIXME: We are not robust to people defining several targets
6957               # at once, only some of them being in %dependencies.
6959               # Output only if not in FALSE.
6960               if (defined $dependencies{$_}
6961                   && $cond ne 'FALSE')
6962                 {
6963                   &depend ($_, @deps);
6964                   $actions{$_} .= $actions;
6965                 }
6966               else
6967                 {
6968                   # Free lance dependency.  Output the rule for all the
6969                   # targets instead of one by one.
6970                   if (!defined $targets{$targets}
6971                       && $cond ne 'FALSE')
6972                     {
6973                       $paragraph =~ s/^/make_condition (@cond_stack)/gme;
6974                       $result_rules .= "$spacing$comment$paragraph\n";
6975                       rule_define ($targets, $is_am, $cond, $file);
6976                     }
6977                   $comment = $spacing = '';
6978                   last;
6979                 }
6980             }
6981         }
6983         elsif (/$ASSIGNMENT_PATTERN/mso)
6984         {
6985             my ($var, $type, $val) = ($1, $2, $3);
6986             &am_file_error ($file, "macro `$var' with trailing backslash")
6987               if /\\$/;
6989             # Accumulating variables must not be output.
6990             $var_comment{$var} .= "$spacing"
6991               if (!defined $var_comment{$var}
6992                   || substr ($var_comment{$var}, -1) ne "\n");
6993             $var_comment{$var} .= "$comment";
6994             macro_define ($var, $is_am, $type, $cond, $val, $file)
6995               if $cond ne 'FALSE';
6996             push (@var_list, $var);
6998             # If the user has set some variables we were in charge
6999             # of (which is detected by the first reading of
7000             # `header-vars.am'), we must not output them.
7001             $result_vars .= "$spacing$comment$_\n"
7002               if $type ne '+' && $var_is_am{$var} && $cond ne 'FALSE';
7004             $comment = $spacing = '';
7005         }
7006         else
7007         {
7008             # This isn't an error; it is probably some tokens which
7009             # configure is supposed to replace, such as `@SET-MAKE@',
7010             # or some part of a rule cut by an if/endif.
7011             if ($cond ne 'FALSE')
7012               {
7013                 s/^/make_condition (@cond_stack)/gme;
7014                 $result_rules .= "$spacing$comment$_\n";
7015               }
7016             $comment = $spacing = '';
7017         }
7018     }
7020     if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
7021     {
7022         if (@cond_stack)
7023         {
7024             &am_error ("unterminated conditionals: @cond_stack");
7025         }
7026         else
7027         {
7028             # FIXME: better error message here.
7029             &am_error ("conditionals not nested in include file");
7030         }
7031     }
7033     return ($comment, $result_vars, $result_rules);
7037 # $CONTENTS
7038 # &file_contents ($BASENAME, [%TRANSFORM])
7039 # ----------------------------------------
7040 # Return contents of a file from $libdir/am, automatically skipping
7041 # macros or rules which are already known.
7042 sub file_contents ($%)
7044     my ($basename, %transform) = @_;
7045     my ($comments, $variables, $rules) =
7046       file_contents_internal (1, "$libdir/am/$basename.am", %transform);
7047     return "$comments$variables$rules";
7051 # $REGEXP
7052 # &transform (%PAIRS)
7053 # -------------------
7054 # Foreach ($TOKEN, $VAL) in %PAIRS produce a replacement expression suitable
7055 # for file_contents which:
7056 #   - replaces @$TOKEN@ with $VALUE,
7057 #   - enables/disables ?$TOKEN?.
7058 sub transform (%)
7060     my (%pairs) = @_;
7061     my $result = '';
7063     while (my ($token, $val) = each %pairs)
7064     {
7065         $result .= "s/\Q%$token%\E/\Q$val\E/gm;";
7066         if ($val)
7067         {
7068             $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
7069             $result .= "s/\Q%?$token%\E/TRUE/gm;";
7070         }
7071         else
7072         {
7073             $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
7074             $result .= "s/\Q%?$token%\E/FALSE/gm;";
7075         }
7076     }
7078     return $result;
7082 # Find all variable prefixes that are used for install directories.  A
7083 # prefix `zar' qualifies iff:
7084 # * `zardir' is a variable.
7085 # * `zar_PRIMARY' is a variable.
7086 sub am_primary_prefixes
7088     my ($primary, $can_dist, @prefixes) = @_;
7090     my %valid = map { $_ => 0 } @prefixes;
7091     $valid{'EXTRA'} = 0;
7092     foreach my $varname (keys %var_value)
7093     {
7094         # Automake is allowed to define variables that look like they
7095         # are magic variables, such as INSTALL_DATA.
7096         next
7097           if $var_is_am{$varname};
7099         if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
7100         {
7101             my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
7102             if ($dist ne '' && ! $can_dist)
7103             {
7104                 # Note that a configure variable is always legitimate.
7105                 # It is natural to name such variables after the
7106                 # primary, so we explicitly allow it.
7107                 if (! defined $configure_vars{$varname})
7108                 {
7109                     &am_line_error ($varname,
7110                                     "invalid variable `$varname': `dist' is forbidden");
7111                 }
7112             }
7113             elsif (! defined $valid{$X} && ! &variable_defined ("${X}dir"))
7114             {
7115                 # Note that a configure variable is always legitimate.
7116                 # It is natural to name such variables after the
7117                 # primary, so we explicitly allow it.
7118                 if (! defined $configure_vars{$varname})
7119                 {
7120                     &am_line_error ($varname,
7121                                     "invalid variable `$varname'");
7122                 }
7123             }
7124             else
7125             {
7126                 # Ensure all extended prefixes are actually used.
7127                 $valid{"$base$dist$X"} = 1;
7128             }
7129         }
7130     }
7132     return %valid;
7135 # Handle `where_HOW' variable magic.  Does all lookups, generates
7136 # install code, and possibly generates code to define the primary
7137 # variable.  The first argument is the name of the .am file to munge,
7138 # the second argument is the primary variable (eg HEADERS), and all
7139 # subsequent arguments are possible installation locations.  Returns
7140 # list of all values of all _HOW targets.
7142 # FIXME: this should be rewritten to be cleaner.  It should be broken
7143 # up into multiple functions.
7145 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7146 sub am_install_var
7148     my (@args) = @_;
7150     my $do_require = 1;
7151     my $can_dist = 0;
7152     my $default_dist = 0;
7153     while (@args)
7154     {
7155         if ($args[0] eq '-noextra')
7156         {
7157             $do_require = 0;
7158         }
7159         elsif ($args[0] eq '-candist')
7160         {
7161             $can_dist = 1;
7162         }
7163         elsif ($args[0] eq '-defaultdist')
7164         {
7165             $default_dist = 1;
7166             $can_dist = 1;
7167         }
7168         elsif ($args[0] !~ /^-/)
7169         {
7170             last;
7171         }
7172         shift (@args);
7173     }
7175     my ($file, $primary, @prefixes) = @args;
7177     # Now that configure substitutions are allowed in where_HOW
7178     # variables, it is an error to actually define the primary.  We
7179     # allow `JAVA', as it is customarily used to mean the Java
7180     # interpreter.  This is but one of several Java hacks.  Similarly,
7181     # `PYTHON' is customarily used to mean the Python interpreter.
7182     &am_line_error ($primary, "`$primary' is an anachronism")
7183         if &variable_defined ($primary)
7184             && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7187     # Look for misspellings.  It is an error to have a variable ending
7188     # in a "reserved" suffix whose prefix is unknown, eg
7189     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
7190     # variable of the same name (with "dir" appended) exists.  For
7191     # instance, if the variable "zardir" is defined, then
7192     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
7193     # flexibility in those cases which need it.
7194     my %valid = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7196     # If a primary includes a configure substitution, then the EXTRA_
7197     # form is required.  Otherwise we can't properly do our job.
7198     my $require_extra;
7199     my $warned_about_extra = 0;
7201     my @used = ();
7202     my @result = ();
7204     # True if the iteration is the first one.  Used for instance to
7205     # output parts of the associated file only once.
7206     my $first = 1;
7207     foreach my $X (sort keys %valid)
7208     {
7209         my $one_name = $X . '_' . $primary;
7210         next
7211           unless (&variable_defined ($one_name));
7213         my $strip_subdir = 1;
7214         # If subdir prefix should be preserved, do so.
7215         if ($X =~ /^nobase_/)
7216           {
7217             $strip_subdir = 0;
7218             $X =~ s/^nobase_//;
7219           }
7221         my $nodir_name = $X;
7222         # If files should be distributed, do so.
7223         my $dist_p = 0;
7224         if ($can_dist)
7225           {
7226             $dist_p = (($default_dist && $one_name !~ /^nodist_/)
7227                        || (! $default_dist && $one_name =~ /^dist_/));
7228             $nodir_name =~ s/^(dist|nodist)_//;
7229           }
7231         # Append actual contents of where_PRIMARY variable to
7232         # result.
7233         foreach my $rcurs (&variable_value_as_list ($one_name, 'all'))
7234           {
7235             # Skip configure substitutions.  Possibly bogus.
7236             if ($rcurs =~ /^\@.*\@$/)
7237               {
7238                 if ($X eq 'EXTRA')
7239                   {
7240                     if (! $warned_about_extra)
7241                       {
7242                         $warned_about_extra = 1;
7243                         &am_line_error ($one_name,
7244                                         "`$one_name' contains configure substitution, but shouldn't");
7245                       }
7246                   }
7247                 # Check here to make sure variables defined in
7248                 # configure.ac do not imply that EXTRA_PRIMARY
7249                 # must be defined.
7250                 elsif (! defined $configure_vars{$one_name})
7251                   {
7252                     $require_extra = $one_name
7253                       if $do_require;
7254                   }
7256                 next;
7257               }
7259             push (@result, $rcurs);
7260           }
7262         # A blatant hack: we rewrite each _PROGRAMS primary to include
7263         # EXEEXT when in Cygwin32 mode.  You might think we could
7264         # simply always use $(EXEEXT), since we define it as empty
7265         # when it isn't available.  However, it isn't that simple.
7266         # See nolink.test.
7267         if ($seen_exeext && $primary eq 'PROGRAMS')
7268           {
7269             my @conds = &variable_conditions ($one_name);
7271             my @condvals;
7272             foreach my $cond (@conds)
7273               {
7274                 my @one_binlist = ();
7275                 my @condval = &variable_value_as_list ($one_name,
7276                                                        $cond);
7277                 foreach my $rcurs (@condval)
7278                   {
7279                     if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7280                       {
7281                         push (@one_binlist, $rcurs);
7282                       }
7283                     else
7284                       {
7285                         push (@one_binlist, $rcurs . '$(EXEEXT)');
7286                       }
7287                   }
7289                 push (@condvals, $cond);
7290                 push (@condvals, join (' ', @one_binlist));
7291               }
7293             variable_delete ($one_name);
7294             while (@condvals)
7295               {
7296                 my $cond = shift (@condvals);
7297                 my @val = split (' ', shift (@condvals));
7298                 &define_pretty_variable ($one_name, $cond, @val);
7299               }
7300           }
7302         # "EXTRA" shouldn't be used when generating clean targets,
7303         # all, or install targets.
7304         if ($X eq 'EXTRA')
7305           {
7306             # We used to warn if EXTRA_FOO was defined uselessly,
7307             # but this was annoying.
7308             next;
7309           }
7311         if ($X eq 'check')
7312           {
7313             push (@check, '$(' . $one_name . ')');
7314           }
7315         else
7316           {
7317             push (@used, '$(' . $one_name . ')');
7318           }
7320         # Is this to be installed?
7321         my $install_p = $X ne 'noinst' && $X ne 'check';
7323         # If so, with install-exec? (or install-data?).
7324         my $exec_p = (defined $exec_dir_p {$X}
7325                       ? $exec_dir_p {$X}
7326                       : ($X =~ /exec/));
7328         # Singular form of $PRIMARY.
7329         (my $one_primary = $primary) =~ s/S$//;
7330         $output_rules .= &file_contents ($file,
7331                                          ('FIRST' => $first,
7333                                           'PRIMARY'     => $primary,
7334                                           'ONE_PRIMARY' => $one_primary,
7335                                           'DIR'         => $X,
7336                                           'NDIR'        => $nodir_name,
7337                                           'BASE'        => $strip_subdir,
7339                                           'EXEC'    => $exec_p,
7340                                           'INSTALL' => $install_p,
7341                                           'DIST'    => $dist_p));
7343         $first = 0;
7344     }
7346     # The JAVA variable is used as the name of the Java interpreter.
7347     # The PYTHON variable is used as the name of the Python interpreter.
7348     if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7349     {
7350         # Define it.
7351         &define_pretty_variable ($primary, '', @used);
7352         $output_vars .= "\n";
7353     }
7355     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7356     {
7357         &am_line_error ($require_extra,
7358                         "`$require_extra' contains configure substitution, but `EXTRA_$primary' not defined");
7359     }
7361     # Push here because PRIMARY might be configure time determined.
7362     push (@all, '$(' . $primary . ')')
7363         if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7365     # Make the result unique.  This lets the user use conditionals in
7366     # a natural way, but still lets us program lazily -- we don't have
7367     # to worry about handling a particular object more than once.
7368     return uniq (sort @result);
7372 ################################################################
7374 # Each key in this hash is the name of a directory holding a
7375 # Makefile.in.  These variables are local to `is_make_dir'.
7376 my %make_dirs = ();
7377 my $make_dirs_set = 0;
7379 sub is_make_dir
7381     my ($dir) = @_;
7382     if (! $make_dirs_set)
7383     {
7384         foreach my $iter (@configure_input_files)
7385         {
7386             $make_dirs{dirname ($iter)} = 1;
7387         }
7388         # We also want to notice Makefile.in's.
7389         foreach my $iter (@other_input_files)
7390         {
7391             if ($iter =~ /Makefile\.in$/)
7392             {
7393                 $make_dirs{dirname ($iter)} = 1;
7394             }
7395         }
7396         $make_dirs_set = 1;
7397     }
7398     return defined $make_dirs{$dir};
7401 ################################################################
7403 # This variable is local to the "require file" set of functions.
7404 my @require_file_paths = ();
7406 # If a file name appears as a key in this hash, then it has already
7407 # been checked for.  This variable is local to the "require file"
7408 # functions.
7409 %require_file_found = ();
7411 # See if we want to push this file onto dist_common.  This function
7412 # encodes the rules for deciding when to do so.
7413 sub maybe_push_required_file
7415     my ($dir, $file, $fullfile) = @_;
7417     if ($dir eq $relative_dir)
7418     {
7419         &push_dist_common ($file);
7420     }
7421     elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7422     {
7423         # If we are doing the topmost directory, and the file is in a
7424         # subdir which does not have a Makefile, then we distribute it
7425         # here.
7426         &push_dist_common ($fullfile);
7427     }
7431 # &require_file_internal ($IS_CONFIGURE, $LINE, $MYSTRICT, @FILES)
7432 # ----------------------------------------------------------------
7433 # Verify that the file must exist in the current directory.
7434 # $MYSTRICT is the strictness level at which this file becomes required.
7436 # Must set require_file_paths before calling this function.
7437 # require_file_paths is set to hold a single directory (the one in
7438 # which the first file was found) before return.
7439 sub require_file_internal
7441     my ($is_configure, $line, $mystrict, @files) = @_;
7443     foreach my $file (@files)
7444     {
7445         my $fullfile;
7446         my $errdir;
7447         my $errfile;
7448         my $save_dir;
7450         my $found_it = 0;
7451         my $dangling_sym = 0;
7452         foreach my $dir (@require_file_paths)
7453         {
7454             $fullfile = $dir . "/" . $file;
7455             $errdir = $dir unless $errdir;
7457             # Use different name for "error filename".  Otherwise on
7458             # an error the bad file will be reported as eg
7459             # `../../install-sh' when using the default
7460             # config_aux_path.
7461             $errfile = $errdir . '/' . $file;
7463             if (-l $fullfile && ! -f $fullfile)
7464             {
7465                 $dangling_sym = 1;
7466                 last;
7467             }
7468             elsif (-f $fullfile)
7469             {
7470                 $found_it = 1;
7471                 &maybe_push_required_file ($dir, $file, $fullfile);
7472                 $save_dir = $dir;
7473                 last;
7474             }
7475         }
7477         # `--force-missing' only has an effect if `--add-missing' is
7478         # specified.
7479         if ($found_it && (! $add_missing || ! $force_missing))
7480         {
7481             # Prune the path list.
7482             @require_file_paths = $save_dir;
7483         }
7484         else
7485         {
7486             # If we've already looked for it, we're done.  You might
7487             # wonder why we don't do this before searching for the
7488             # file.  If we do that, then something like
7489             # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
7490             # DIST_COMMON.
7491             if (! $found_it)
7492             {
7493                 next if defined $require_file_found{$file};
7494                 $require_file_found{$file} = 1;
7495             }
7497             if ($strictness >= $mystrict)
7498             {
7499                 if ($dangling_sym && $add_missing)
7500                 {
7501                     unlink ($fullfile);
7502                 }
7504                 my $trailer = '';
7505                 my $suppress = 0;
7507                 # Only install missing files according to our desired
7508                 # strictness level.
7509                 my $message = "required file `$errfile' not found";
7510                 if ($add_missing)
7511                 {
7512                     $suppress = 1;
7514                     # Maybe run libtoolize.
7515                     my @syslist = ('libtoolize', '--automake');
7516                     push @syslist, '--copy'
7517                         if $copy_missing;
7518                     if ($seen_libtool
7519                         && grep ($_ eq $file, @libtoolize_files)
7520                         && system (@syslist))
7521                     {
7522                         $message = "installing `$errfile'";
7523                         $suppress = 0;
7524                         $trailer = "; cannot run `libtoolize': $!";
7525                     }
7526                     elsif (-f ("$libdir/$file"))
7527                     {
7528                         # Install the missing file.  Symlink if we
7529                         # can, copy if we must.  Note: delete the file
7530                         # first, in case it is a dangling symlink.
7531                         $message = "installing `$errfile'";
7532                         # Windows Perl will hang if we try to delete a
7533                         # file that doesn't exist.
7534                         unlink ($errfile) if -f $errfile;
7535                         if ($symlink_exists && ! $copy_missing)
7536                         {
7537                             if (! symlink ("$libdir/$file", $errfile))
7538                             {
7539                                 $suppress = 0;
7540                                 $trailer = "; error while making link: $!";
7541                             }
7542                         }
7543                         elsif (system ('cp', "$libdir/$file", $errfile))
7544                         {
7545                             $suppress = 0;
7546                             $trailer = "\n    error while copying";
7547                         }
7548                     }
7550                     &maybe_push_required_file (dirname ($errfile),
7551                                                $file, $errfile);
7553                     # Prune the path list.
7554                     @require_file_paths = &dirname ($errfile);
7555                 }
7557                 # If --force-missing was specified, and we have
7558                 # actually found the file, then do nothing.
7559                 next
7560                     if $found_it && $force_missing;
7562                 if ($suppress)
7563                 {
7564                     if ($is_configure)
7565                     {
7566                         # FIXME: allow actual file to be specified.
7567                         &am_conf_line_warning ($configure_ac, $line,
7568                                                "$message$trailer");
7569                     }
7570                     else
7571                     {
7572                         &am_line_warning ($line, "$message$trailer");
7573                     }
7574                 }
7575                 else
7576                 {
7577                     if ($is_configure)
7578                     {
7579                         # FIXME: allow actual file to be specified.
7580                         &am_conf_line_error ($configure_ac, $line,
7581                                              "$message$trailer");
7582                     }
7583                     else
7584                     {
7585                         &am_line_error ($line, "$message$trailer");
7586                     }
7587                 }
7588             }
7589         }
7590     }
7593 # Like require_file_with_line, but error messages refer to
7594 # configure.ac, not the current Makefile.am.
7595 sub require_file_with_conf_line
7597     @require_file_paths = $relative_dir;
7598     &require_file_internal (1, @_);
7601 sub require_file_with_line
7603     @require_file_paths = $relative_dir;
7604     &require_file_internal (0, @_);
7607 sub require_file
7609     @require_file_paths = $relative_dir;
7610     &require_file_internal (0, '', @_);
7613 # Require a file that is also required by Autoconf.  Looks in
7614 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7615 sub require_config_file
7617     @require_file_paths = @config_aux_path;
7618     &require_file_internal (1, '', @_);
7619     my $dir = $require_file_paths[0];
7620     @config_aux_path = @require_file_paths;
7621      # Avoid unsightly '/.'s.
7622     $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7625 # Assumes that the line number is in Makefile.am.
7626 sub require_conf_file_with_line
7628     @require_file_paths = @config_aux_path;
7629     &require_file_internal (0, @_);
7630     my $dir = $require_file_paths[0];
7631     @config_aux_path = @require_file_paths;
7632      # Avoid unsightly '/.'s.
7633     $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7636 # Assumes that the line number is in configure.ac.
7637 sub require_conf_file_with_conf_line
7639     @require_file_paths = @config_aux_path;
7640     &require_file_internal (1, @_);
7641     my $dir = $require_file_paths[0];
7642     @config_aux_path = @require_file_paths;
7643     # avoid unsightly '/.'s.
7644     $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7647 ################################################################
7649 # Push a list of files onto dist_common.
7650 sub push_dist_common
7652     &prog_error ("push_dist_common run after handle_dist")
7653         if $handle_dist_run;
7654     macro_define ('DIST_COMMON', 1, '+', '', join (' ', @_), '');
7658 # Set strictness.
7659 sub set_strictness
7661     $strictness_name = $_[0];
7662     if ($strictness_name eq 'gnu')
7663     {
7664         $strictness = $GNU;
7665     }
7666     elsif ($strictness_name eq 'gnits')
7667     {
7668         $strictness = $GNITS;
7669     }
7670     elsif ($strictness_name eq 'foreign')
7671     {
7672         $strictness = $FOREIGN;
7673     }
7674     else
7675     {
7676         die "$me: level `$strictness_name' not recognized\n";
7677     }
7681 ################################################################
7683 # Ensure a file exists.
7684 sub create
7686     my ($file) = @_;
7688     my $touch = new IO::File (">> $file");
7689     $touch->close;
7692 # Glob something.  Do this to avoid indentation screwups everywhere we
7693 # want to glob.  Gross!
7694 sub my_glob
7696     my ($pat) = @_;
7697     return <${pat}>;
7700 # Remove one level of brackets and strip leading spaces,
7701 # as does m4 to function arguments.
7702 sub unquote_m4_arg
7704     $_ = shift;
7705     s/^\s*//;
7707     my @letters = split //;
7708     my @result = ();
7709     my $depth = 0;
7711     foreach (@letters)
7712     {
7713         if ($_ eq '[')
7714         {
7715             ++$depth;
7716             next if $depth == 1;
7717         }
7718         elsif ($_ eq ']')
7719         {
7720             --$depth;
7721             next if $depth == 0;
7722             # don't count orphan right brackets
7723             $depth = 0 if $depth < 0;
7724         }
7725         push @result, $_;
7726     }
7727     return join '', @result;
7730 ################################################################
7732 # Print an error message and set exit status.
7733 sub am_error
7735     warn "$me: ${am_file}.am: @_\n";
7736     $exit_status = 1;
7739 # am_file_error ($FILE, @ARGS)
7740 # ----------------------------
7741 sub am_file_error
7743     my ($file, @args) = @_;
7745     warn "$file: @args\n";
7746     $exit_status = 1;
7749 sub am_line_error
7751     my ($symbol, @args) = @_;
7753     if ($symbol && "$symbol" ne '-1')
7754     {
7755         my $file = "${am_file}.am";
7757         if ($symbol =~ /^\d+$/)
7758         {
7759             # SYMBOL is a line number, so just add the colon.
7760             $file .= ':' . $symbol;
7761         }
7762         elsif (defined $var_line{$symbol})
7763         {
7764             # SYMBOL is a variable defined in Makefile.am, so add the
7765             # line number we saved from there.
7766             $file .= ':' . $var_line{$symbol};
7767         }
7768         elsif (defined $configure_vars{$symbol})
7769         {
7770             # SYMBOL is a variable defined in configure.ac, so add the
7771             # appropriate line number.
7772             $file = $configure_vars{$symbol};
7773         }
7774         else
7775         {
7776             # Couldn't find the line number.
7777         }
7778         warn $file, ": @args\n";
7779         $exit_status = 1;
7780     }
7781     else
7782     {
7783         &am_error (@args);
7784     }
7787 # Like am_error, but while scanning configure.ac.
7788 sub am_conf_error
7790     # FIXME: can run in subdirs.
7791     warn "$me: $configure_ac: @_\n";
7792     $exit_status = 1;
7795 # Error message with line number referring to configure.ac.
7796 sub am_conf_line_error
7798     my ($file, $line, @args) = @_;
7800     if ($line)
7801     {
7802         warn "$file: $line: @args\n";
7803         $exit_status = 1;
7804     }
7805     else
7806     {
7807         &am_conf_error (@args);
7808     }
7811 # Warning message with line number referring to configure.ac.
7812 # Does not affect exit_status
7813 sub am_conf_line_warning
7815     my $saved_exit_status = $exit_status;
7816     my $sig = $SIG{'__WARN__'};
7817     $SIG{'__WARN__'} = 'DEFAULT';
7818     am_conf_line_error (@_);
7819     $exit_status = $saved_exit_status;
7820     $SIG{'__WARN__'} = $sig;
7823 # Like am_line_error, but doesn't affect exit status.
7824 sub am_line_warning
7826     my $saved_exit_status = $exit_status;
7827     my $sig = $SIG{'__WARN__'};
7828     $SIG{'__WARN__'} = 'DEFAULT';
7829     am_line_error (@_);
7830     $exit_status = $saved_exit_status;
7831     $SIG{'__WARN__'} = $sig;
7834 # Tell user where our aclocal.m4 is, but only once.
7835 sub keyed_aclocal_warning
7837     my ($key) = @_;
7838     warn "$me: macro `$key' can be generated by `aclocal'\n";
7841 # Print usage information.
7842 sub usage
7844     print <<EOF;
7845 Usage: $0 [OPTION] ... [Makefile]...
7847 Generate Makefile.in for configure from Makefile.am.
7849 Operation modes:
7850       --help             print this help, then exit
7851       --version          print version number, then exit
7852   -v, --verbose          verbosely list files processed
7853   -o, --output-dir=DIR   put generated Makefile.in's into DIR
7854       --no-force         only update Makefile.in's that are out of date
7856 Dependency tracking:
7857   -i, --ignore-deps      disable dependency tracking code
7858       --include-deps     enable dependency tracking code
7860 Flavors:
7861       --cygnus           assume program is part of Cygnus-style tree
7862       --foreign          set strictness to foreign
7863       --gnits            set strictness to gnits
7864       --gnu              set strictness to gnu
7866 Library files:
7867   -a, --add-missing      add missing standard files to package
7868       --libdir=DIR       directory storing library files
7869   -c, --copy             with -a, copy missing files (default is symlink)
7870   -f, --force-missing    force update of standard files
7873     my ($last, @lcomm);
7874     $last = '';
7875     foreach my $iter (sort ((@common_files, @common_sometimes)))
7876     {
7877         push (@lcomm, $iter) unless $iter eq $last;
7878         $last = $iter;
7879     }
7881     my ($one, $two, $three, $four, $max);
7882     print "\nFiles which are automatically distributed, if found:\n";
7883     format USAGE_FORMAT =
7884   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
7885   $one,               $two,               $three,             $four
7887     $~ = "USAGE_FORMAT";
7888     $max = int (($#lcomm + 1) / 4);
7890     for (my $i = 0; $i < $max; ++$i)
7891     {
7892         $one = $lcomm[$i];
7893         $two = $lcomm[$max + $i];
7894         $three = $lcomm[2 * $max + $i];
7895         $four = $lcomm[3 * $max + $i];
7896         write;
7897     }
7899     my $mod = ($#lcomm + 1) % 4;
7900     if ($mod != 0)
7901     {
7902         $one = $lcomm[$max];
7903         $two = ($mod > 1) ? $lcomm[2 * $max] : '';
7904         $three = ($mod > 2) ? $lcomm[3 * $max] : '';
7905         $four = ($mod > 3) ? $lcomm[4 * $max] : '';
7906         write;
7907     }
7909     print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7911     exit 0;
7914 # &version ()
7915 # -----------
7916 # Print version information
7917 sub version ()
7919   print <<EOF;
7920 automake (GNU $PACKAGE) $VERSION
7921 Written by Tom Tromey <tromey\@cygnus.com>.
7923 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
7924 Free Software Foundation, Inc.
7925 This is free software; see the source for copying conditions.  There is NO
7926 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7928   exit 0;