* automake.in (am_print_error): New function.
[automake.git] / automake.in
blobf34cdb8a963209114c523901bbece0e0c29c89a8
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 ('|', 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_OBJEXT.
429 my $seen_objext = 0;
431 # TRUE if we've seen AC_ENABLE_MULTILIB.
432 my $seen_multilib = 0;
434 # TRUE if we've seen AM_PROG_CC_C_O
435 my $seen_cc_c_o = 0;
437 # TRUE if we've seen AM_INIT_AUTOMAKE.
438 my $seen_init_automake = 0;
440 # Hash table of discovered configure substitutions.  Keys are names,
441 # values are `FILE:LINE' strings which are used by error message
442 # generation.
443 my %configure_vars = ();
445 # This is used to keep track of which variable definitions we are
446 # scanning.  It is only used in certain limited ways, but it has to be
447 # global.  It is declared just for documentation purposes.
448 my %vars_scanned = ();
450 # TRUE if --cygnus seen.
451 my $cygnus_mode = 0;
453 # Hash table of AM_CONDITIONAL variables seen in configure.
454 my %configure_cond = ();
456 # This maps extensions onto language names.
457 my %extension_map = ();
459 # List of the DIST_COMMON files we discovered while reading
460 # configure.in
461 my $configure_dist_common = '';
463 # This maps languages names onto objects.
464 my %languages = ();
466 # List of targets we must always output.
467 # FIXME: Complete, and remove falsely required targets.
468 my %required_targets =
469   (
470    'all'          => 1,
471    'dvi'          => 1,
472    'info'         => 1,
473    'install-info' => 1,
474    'install'      => 1,
475    'install-data' => 1,
476    'install-exec' => 1,
477    'uninstall'    => 1,
479    # FIXME: Not required, temporary hacks.
480    # Well, actually they are sort of required: the -recursive
481    # targets will run them anyway...
482    'dvi-am'          => 1,
483    'info-am'         => 1,
484    'install-data-am' => 1,
485    'install-exec-am' => 1,
486    'installcheck-am' => 1,
487    'uninstall-am' => 1,
489    'install-man' => 1,
490   );
494 ################################################################
496 ## ------------------------------------------ ##
497 ## Variables reset by &initialize_per_input.  ##
498 ## ------------------------------------------ ##
500 # Basename and relative dir of the input file.
501 my $am_file_name;
502 my $am_relative_dir;
504 # Same but wrt Makefile.in.
505 my $in_file_name;
506 my $relative_dir;
508 # These two variables are used when generating each Makefile.in.
509 # They hold the Makefile.in until it is ready to be printed.
510 my $output_rules;
511 my $output_vars;
512 my $output_trailer;
513 my $output_all;
514 my $output_header;
516 # Suffixes found during a run.
517 my @suffixes;
519 # Handling the variables.
521 # For a $VAR:
522 # - $var_value{$VAR}{$COND} is its value associated to $COND,
523 # - $var_line{$VAR} is where it has been defined,
524 # - $var_comment{$VAR} are the comments associated to it.
525 # - $var_type{$VAR} is how it has been defined (`', `+', or `:'),
526 # - $var_is_am{$VAR} is true if the variable is owned by Automake.
527 my %var_value;
528 my %var_line;
529 my %var_comment;
530 my %var_type;
531 my %var_is_am;
533 # This holds a 1 if a particular variable was examined.
534 my %content_seen;
536 # This holds the names which are targets.  These also appear in
537 # %contents.
538 my %targets;
540 # Same as %VAR_VALUE, but for targets.
541 my %target_conditional;
543 # This is the conditional stack.
544 my @cond_stack;
546 # This holds the set of included files.
547 my @include_stack;
549 # This holds a list of directories which we must create at `dist'
550 # time.  This is used in some strange scenarios involving weird
551 # AC_OUTPUT commands.
552 my %dist_dirs;
554 # List of dependencies for the obvious targets.
555 my @all;
556 my @check;
557 my @check_tests;
559 # Holds the dependencies of targets which dependencies are factored.
560 # Typically, `.PHONY' will appear in plenty of *.am files, but must
561 # be output once.  Arguably all pure dependencies could be subject
562 # to this factorization, but it is not unpleasant to have paragraphs
563 # in Makefile: keeping related stuff altogether.
564 my %dependencies;
566 # Holds the factored actions.  Tied to %DEPENDENCIES, i.e., filled
567 # only when keys exists in %DEPENDENCIES.
568 my %actions;
570 # A list of files deleted by `maintainer-clean'.
571 my @maintainer_clean_files;
573 # Keys in this hash table are object files or other files in
574 # subdirectories which need to be removed.  This only holds files
575 # which are created by compilations.  The value in the hash indicates
576 # when the file should be removed.
577 my %compile_clean_files;
579 # Value of `$(SOURCES)', used by tags.am.
580 my @sources;
581 # Sources which go in the distribution.
582 my @dist_sources;
584 # This hash maps object file names onto their corresponding source
585 # file names.  This is used to ensure that each object is created
586 # by a single source file.
587 my %object_map;
589 # This keeps track of the directories for which we've already
590 # created `.dirstamp' code.
591 my %directory_map;
593 # All .P files.
594 my %dep_files;
596 # Strictness levels.
597 my $strictness;
598 my $strictness_name;
600 # Options from AUTOMAKE_OPTIONS.
601 my %options;
603 # Whether or not dependencies are handled.  Can be further changed
604 # in handle_options.
605 my $use_dependencies;
607 # This is a list of all targets to run during "make dist".
608 my @dist_targets;
610 # Keys in this hash are the basenames of files which must depend
611 # on ansi2knr.
612 my %de_ansi_files;
614 # This maps the source extension of a suffix rule to its
615 # corresponding output extension.
616 my %suffix_rules;
618 # This is the name of the redirect `all' target to use.
619 my $all_target;
621 # This keeps track of which extensions we've seen (that we care
622 # about).
623 my %extension_seen;
625 # This is random scratch space for the language finish functions.
626 # Don't randomly overwrite it; examine other uses of keys first.
627 my %language_scratch;
629 # We keep track of which objects need special (per-executable)
630 # handling on a per-language basis.
631 my %lang_specific_files;
633 # This is set when `handle_dist' has finished.  Once this happens,
634 # we should no longer push on dist_common.
635 my $handle_dist_run;
637 # True if we need `LINK' defined.  This is a hack.
638 my $need_link;
640 # This is the list of such variables to output.
641 # FIXME: Might be useless actually.
642 my @var_list;
644 # Was get_object_extension run?
645 # FIXME: This is a hack. a better switch should be found.
646 my $get_object_extension_was_run;
649 ## --------------------------------- ##
650 ## Forward subroutine declarations.  ##
651 ## --------------------------------- ##
652 sub register_language (%);
653 sub file_contents_internal ($$%);
656 # &initialize_per_input ()
657 # ------------------------
658 # (Re)-Initialize per-Makefile.am variables.
659 sub initialize_per_input ()
661     $am_file_name = '';
662     $am_relative_dir = '';
664     $in_file_name = '';
665     $relative_dir = '';
667     $output_rules = '';
668     $output_vars = '';
669     $output_trailer = '';
670     $output_all = '';
671     $output_header = '';
673     @suffixes = ();
675     %var_value = ();
676     %var_line = ();
677     %var_comment = ();
678     %var_type = ();
679     %var_is_am = ();
681     %content_seen = ();
683     %targets = ();
685     %target_conditional = ();
687     @cond_stack = ();
689     @include_stack = ();
691     $relative_dir = '';
693     $am_relative_dir = '';
695     %dist_dirs = ();
697     @all = ();
698     @check = ();
699     @check_tests = ();
701     %dependencies =
702       (
703        # Texinfoing.
704        'dvi'      => [],
705        'dvi-am'   => [],
706        'info'     => [],
707        'info-am'  => [],
709        # Installing/uninstalling.
710        'install-data-am'      => [],
711        'install-exec-am'      => [],
712        'uninstall-am'         => [],
714        'install-man'          => [],
715        'uninstall-man'        => [],
717        'install-info'         => [],
718        'install-info-am'      => [],
719        'uninstall-info'       => [],
721        'installcheck-am'      => [],
723        # Cleaning.
724        'clean-am'             => [],
725        'mostlyclean-am'       => [],
726        'maintainer-clean-am'  => [],
727        'distclean-am'         => [],
728        'clean'                => [],
729        'mostlyclean'          => [],
730        'maintainer-clean'     => [],
731        'distclean'            => [],
733        # Tarballing.
734        'dist-all'             => [],
736        # Phoning.
737        '.PHONY'               => []
738       );
739     %actions = ();
741     @maintainer_clean_files = ();
743     @sources = ();
744     @dist_sources = ();
746     %object_map = ();
748     %directory_map = ();
750     %dep_files = ();
752     $strictness = $default_strictness;
753     $strictness_name = $default_strictness_name;
755     %options = ();
757     $use_dependencies = $cmdline_use_dependencies;
759     @dist_targets = ();
761     %de_ansi_files = ();
763     %suffix_rules = ();
765     $all_target = '';
767     %extension_seen = ();
769     %language_scratch = ();
771     %lang_specific_files = ();
773     $handle_dist_run = 0;
775     $need_link = 0;
777     @var_list = ();
779     $get_object_extension_was_run = 0;
781     %compile_clean_files = ();
785 ################################################################
787 # Initialize our list of languages that are internally supported.
789 # C.
790 register_language ('name' => 'c',
791                    'Name' => 'C',
792                    'config_vars' => ['CC'],
793                    'ansi' => 1,
794                    'autodep' => '',
795                    'flags' => 'CFLAGS',
796                    'compiler' => 'COMPILE',
797                    'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
798                    'lder' => 'CCLD',
799                    'ld' => '$(CC)',
800                    'linker' => 'LINK',
801                    'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
802                    'compile_flag' => '-c',
803                    'extensions' => ['c'],
804                    '_finish' => \&lang_c_finish);
806 # C++.
807 register_language ('name' => 'cxx',
808                    'Name' => 'C++',
809                    'config_vars' => ['CXX'],
810                    'linker' => 'CXXLINK',
811                    'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
812                    'autodep' => 'CXX',
813                    'flags' => 'CXXFLAGS',
814                    'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
815                    'compiler' => 'CXXCOMPILE',
816                    'compile_flag' => '-c',
817                    'output_flag' => '-o',
818                    'lder' => 'CXXLD',
819                    'ld' => '$(CXX)',
820                    'pure' => 1,
821                    'extensions' => ['c++', 'cc', 'cpp', 'cxx', 'C']);
823 # Objective C.
824 register_language ('name' => 'objc',
825                    'Name' => 'Objective C',
826                    'config_vars' => ['OBJC'],
827                    'linker' => 'OBJCLINK',,
828                    'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
829                    'autodep' => 'OBJC',
830                    'flags' => 'OBJCFLAGS',
831                    'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
832                    'compiler' => 'OBJCCOMPILE',
833                    'compile_flag' => '-c',
834                    'output_flag' => '-o',
835                    'lder' => 'OBJCLD',
836                    'ld' => '$(OBJC)',
837                    'pure' => 1,
838                    'extensions' => ['m']);
840 # Headers.
841 register_language ('name' => 'header',
842                    'Name' => 'Header',
843                    'extensions' => ['h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc'],
844                    # Nothing to do.
845                    '_finish' => sub { });
847 # Yacc (C & C++).
848 register_language ('name' => 'yacc',
849                    'Name' => 'Yacc',
850                    'config_vars' => ['YACC'],
851                    'flags' => 'YFLAGS',
852                    'define_flag' => 0,
853                    'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
854                    'compiler' => 'YACCCOMPILE',
855                    'extensions' => ['y'],
856                    'rule_file' => 'yacc',
857                    '_finish' => \&lang_yacc_finish,
858                    '_target_hook' => \&lang_yacc_target_hook);
859 register_language ('name' => 'yaccxx',
860                    'Name' => 'Yacc (C++)',
861                    'config_vars' => ['YACC'],
862                    'rule_file' => 'yacc',
863                    'flags' => 'YFLAGS',
864                    'define_flag' => 0,
865                    'compiler' => 'YACCCOMPILE',
866                    'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
867                    'extensions' => ['y++', 'yy', 'yxx', 'ypp'],
868                    '_finish' => \&lang_yacc_finish,
869                    '_target_hook' => \&lang_yacc_target_hook);
871 # Lex (C & C++).
872 register_language ('name' => 'lex',
873                    'Name' => 'Lex',
874                    'config_vars' => ['LEX'],
875                    'rule_file' => 'lex',
876                    'flags' => 'LFLAGS',
877                    'define_flag' => 0,
878                    'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
879                    'compiler' => 'LEXCOMPILE',
880                    'extensions' => ['l'],
881                    '_finish' => \&lang_lex_finish);
882 register_language ('name' => 'lexxx',
883                    'Name' => 'Lex (C++)',
884                    'config_vars' => ['LEX'],
885                    'rule_file' => 'lex',
886                    'flags' => 'LFLAGS',
887                    'define_flag' => 0,
888                    'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
889                    'compiler' => 'LEXCOMPILE',
890                    'extensions' => ['l++', 'll', 'lxx', 'lpp'],
891                    '_finish' => \&lang_lex_finish);
893 # Assembler.
894 register_language ('name' => 'asm',
895                    'Name' => 'Assembler',
896                    'config_vars' => ['AS', 'ASFLAGS'],
898                    'flags' => 'ASFLAGS',
899                    # Users can set AM_ASFLAGS to includes DEFS, INCLUDES,
900                    # or anything else required.  They can also set AS.
901                    'compile' => '$(AS) $(AM_ASFLAGS) $(ASFLAGS)',
902                    'compiler' => 'ASCOMPILE',
903                    'compile_flag' => '-c',
904                    'extensions' => ['s', 'S'],
906                    # With assembly we still use the C linker.
907                    '_finish' => \&lang_c_finish);
909 # Fortran 77
910 register_language ('name' => 'f77',
911                    'Name' => 'Fortran 77',
912                    'linker' => 'F77LINK',
913                    'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
914                    'flags' => 'FFLAGS',
915                    'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
916                    'compiler' => 'F77COMPILE',
917                    'compile_flag' => '-c',
918                    'output_flag' => '-o',
919                    'lder' => 'F77LD',
920                    'ld' => '$(F77)',
921                    'pure' => 1,
922                    'extensions' => ['f', 'for', 'f90']);
924 # Preprocessed Fortran 77
926 # The current support for preprocessing Fortran 77 just involves
927 # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
928 # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
929 # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
930 # for `make' Version 3.76 Beta' (specifically, from info file
931 # `(make)Catalogue of Rules').
933 # A better approach would be to write an Autoconf test
934 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
935 # Fortran 77 compilers know how to do preprocessing.  The Autoconf
936 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
937 # preprocessing capabilities, and then fall back on cpp (if cpp were
938 # available).
939 register_language ('name' => 'ppf77',
940                    'Name' => 'Preprocessed Fortran 77',
941                    'config_vars' => ['F77'],
942                    'linker' => 'F77LINK',
943                    'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
944                    'lder' => 'F77LD',
945                    'ld' => '$(F77)',
946                    'flags' => 'FFLAGS',
947                    'compiler' => 'PPF77COMPILE',
948                    'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
949                    'compile_flag' => '-c',
950                    'output_flag' => '-o',
951                    'pure' => 1,
952                    'extensions' => ['F']);
954 # Ratfor.
955 register_language ('name' => 'ratfor',
956                    'Name' => 'Ratfor',
957                    'config_vars' => ['F77'],
958                    'linker' => 'F77LINK',
959                    'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
960                    'lder' => 'F77LD',
961                    'ld' => '$(F77)',
962                    'flags' => 'RFLAGS',
963                    # FIXME also FFLAGS.
964                    'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
965                    'compiler' => 'RCOMPILE',
966                    'compile_flag' => '-c',
967                    'output_flag' => '-o',
968                    'pure' => 1,
969                    'extensions' => ['r']);
971 # Java via gcj.
972 register_language ('name' => 'java',
973                    'Name' => 'Java',
974                    'config_vars' => ['GCJ'],
975                    'linker' => 'GCJLINK',
976                    'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
977                    'autodep' => 'GCJ',
978                    'flags' => 'GCJFLAGS',
979                    'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
980                    'compiler' => 'GCJCOMPILE',
981                    'compile_flag' => '-c',
982                    'output_flag' => '-o',
983                    'lder' => 'GCJLD',
984                    'ld' => '$(GCJ)',
985                    'pure' => 1,
986                    'extensions' => ['java', 'class', 'zip', 'jar']);
988 ################################################################
990 # Parse command line.
991 &parse_arguments;
993 # Do configure.ac scan only once.
994 &scan_autoconf_files;
996 die "$me: no `Makefile.am' found or specified\n"
997     if ! @input_files;
999 # Now do all the work on each file.
1000 # This guy must be local otherwise it's private to the loop.
1001 use vars '$am_file';
1002 local $am_file;
1003 foreach $am_file (@input_files)
1005     if (! -f ($am_file . '.am'))
1006     {
1007         &am_error ("`" . $am_file . ".am' does not exist");
1008     }
1009     else
1010     {
1011         &generate_makefile ($output_files{$am_file}, $am_file);
1012     }
1015 exit $exit_status;
1017 # FIXME: This should be `my'ed next to its subs.
1018 use vars '%require_file_found';
1020 ################################################################
1022 # prog_error (@PRINT-ME)
1023 # ----------------------
1024 # Signal a programming error, display PRINT-ME, and exit 1.
1025 sub prog_error (@)
1027     print STDERR "$me: programming error: @_\n";
1028     exit 1;
1032 # @RES
1033 # uniq (@LIST)
1034 # ------------
1035 # Return LIST with no duplicates.
1036 sub uniq (@)
1038    my @res = ();
1039    my %seen = ();
1040    foreach my $item (@_)
1041      {
1042        if (! defined $seen{$item})
1043          {
1044            $seen{$item} = 1;
1045            push (@res, $item);
1046          }
1047      }
1048    return @res;
1051 # subst ($TEXT)
1052 # -------------
1053 # Return a configure-style substitution using the indicated text.
1054 # We do this to avoid having the substitutions directly in automake.in;
1055 # when we do that they are sometimes removed and this causes confusion
1056 # and bugs.
1057 sub subst ($)
1059     my ($text) = @_;
1060     return '@' . $text . '@';
1063 ################################################################
1066 # $BACKPATH
1067 # &backname ($REL-DIR)
1068 # --------------------
1069 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
1070 # For instance `src/foo' => `../..'.
1071 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
1072 sub backname ($)
1074     my ($file) = @_;
1075     my @res;
1076     foreach (split (/\//, $file))
1077     {
1078         next if $_ eq '.' || $_ eq '';
1079         if ($_ eq '..')
1080         {
1081             pop @res;
1082         }
1083         else
1084         {
1085             push (@res, '..');
1086         }
1087     }
1088     return join ('/', @res) || '.';
1091 ################################################################
1093 # Parse command line.
1094 sub parse_arguments ()
1096     # Start off as gnu.
1097     &set_strictness ('gnu');
1099     use Getopt::Long;
1100     Getopt::Long::config ("bundling");
1101     Getopt::Long::GetOptions
1102       (
1103        'version'        => \&version,
1104        'help'           => \&usage,
1105        'libdir:s'       => \$libdir,
1106        'gnu'            => sub { &set_strictness ('gnu'); },
1107        'gnits'          => sub { &set_strictness ('gnits'); },
1108        'cygnus'         => \$cygnus_mode,
1109        'foreign'        => sub { &set_strictness ('foreign'); },
1110        'include-deps'   => sub { $cmdline_use_dependencies = 1; },
1111        'i|ignore-deps'  => sub { $cmdline_use_dependencies = 0; },
1112        'no-force'       => sub { $force_generation = 0; },
1113        'f|force-missing'=> \$force_missing,
1114        'o|output-dir:s' => \$output_directory,
1115        'a|add-missing'  => \$add_missing,
1116        'c|copy'         => \$copy_missing,
1117        'v|verbose'      => \$verbose,
1118        'Werror'         => sub { $SIG{"__WARN__"} = sub { die $_[0] } },
1119        'Wno-error'      => sub { $SIG{"__WARN__"} = 'DEFAULT' }
1120       )
1121         or exit 1;
1123     foreach my $arg (@ARGV)
1124     {
1125       # Handle $local:$input syntax.  Note that we only examine the
1126       # first ":" file to see if it is automake input; the rest are
1127       # just taken verbatim.  We still keep all the files around for
1128       # dependency checking, however.
1129       my ($local, $input, @rest) = split (/:/, $arg);
1130       if (! $input)
1131         {
1132           $input = $local;
1133         }
1134       else
1135         {
1136           # Strip .in; later on .am is tacked on.  That is how the
1137           # automake input file is found.  Maybe not the best way, but
1138           # it is easy to explain.
1139           $input =~ s/\.in$//
1140             or die "$me: invalid input file name `$arg'\n.";
1141         }
1142       push (@input_files, $input);
1143       $output_files{$input} = join (':', ($local, @rest));
1144     }
1146     # Take global strictness from whatever we currently have set.
1147     $default_strictness = $strictness;
1148     $default_strictness_name = $strictness_name;
1151 ################################################################
1153 # Generate a Makefile.in given the name of the corresponding Makefile and
1154 # the name of the file output by config.status.
1155 sub generate_makefile
1157     my ($output, $makefile) = @_;
1159     # Reset all the Makefile.am related variables.
1160     &initialize_per_input;
1162     # Name of input file ("Makefile.am") and output file
1163     # ("Makefile.in").  These have no directory components.
1164     $am_file_name = basename ($makefile) . '.am';
1165     $in_file_name = basename ($makefile) . '.in';
1167     # $OUTPUT is encoded.  If it contains a ":" then the first element
1168     # is the real output file, and all remaining elements are input
1169     # files.  We don't scan or otherwise deal with these input file,
1170     # other than to mark them as dependencies.  See
1171     # &scan_autoconf_files for details.
1172     my (@secondary_inputs);
1173     ($output, @secondary_inputs) = split (/:/, $output);
1175     $relative_dir = dirname ($output);
1176     $am_relative_dir = dirname ($makefile);
1178     &read_main_am_file ($makefile . '.am');
1179     if (&handle_options)
1180     {
1181         # Fatal error.  Just return, so we can continue with next file.
1182         return;
1183     }
1185     # There are a few install-related variables that you should not define.
1186     foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
1187     {
1188         if (&variable_defined ($var) && !$var_is_am{$var})
1189         {
1190             &am_line_error ($var, "`$var' should not be defined");
1191         }
1192     }
1194     &handle_libtool;
1196     # At the toplevel directory, we might need config.guess, config.sub
1197     # or libtool scripts (ltconfig and ltmain.sh).
1198     if ($relative_dir eq '.')
1199     {
1200         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1201         # config.sub.
1202         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
1203             if $seen_canonical;
1204     }
1206     # We still need Makefile.in here, because sometimes the `dist'
1207     # target doesn't re-run automake.
1208     if ($am_relative_dir eq $relative_dir)
1209     {
1210         # Only distribute the files if they are in the same subdir as
1211         # the generated makefile.
1212         &push_dist_common ($in_file_name, $am_file_name);
1213     }
1215     push (@sources, '$(SOURCES)')
1216         if &variable_defined ('SOURCES');
1218     # Must do this after reading .am file.  See read_main_am_file to
1219     # understand weird tricks we play there with variables.
1220     &define_variable ('subdir', $relative_dir);
1222     # Check first, because we might modify some state.
1223     &check_cygnus;
1224     &check_gnu_standards;
1225     &check_gnits_standards;
1227     &handle_configure ($output, $makefile, @secondary_inputs);
1228     &handle_gettext;
1229     &handle_libraries;
1230     &handle_ltlibraries;
1231     &handle_programs;
1232     &handle_scripts;
1234     # This must run first so that the ANSI2KNR definition is generated
1235     # before it is used by the _.c rules.  We have to do this because
1236     # a variable which is used in a dependency must be defined before
1237     # the target, or else make won't properly see it.
1238     &handle_compile;
1239     # This must be run after all the sources are scanned.
1240     &handle_languages;
1242     # Re-init SOURCES.  FIXME: other code shouldn't depend on this
1243     # (but currently does).
1244     macro_define ('SOURCES', 1, '', 'TRUE',
1245                      join (' ', @sources), 'internal');
1246     &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
1248     &handle_multilib;
1249     &handle_texinfo;
1250     &handle_emacs_lisp;
1251     &handle_python;
1252     &handle_java;
1253     &handle_man_pages;
1254     &handle_data;
1255     &handle_headers;
1256     &handle_subdirs;
1257     &handle_tags;
1258     &handle_minor_options;
1259     &handle_tests;
1261     # This must come after most other rules.
1262     &handle_dist ($makefile);
1264     &handle_footer;
1265     &do_check_merge_target;
1266     &handle_all ($output);
1268     # FIXME: Gross!
1269     if (&variable_defined('lib_LTLIBRARIES') &&
1270         &variable_defined('bin_PROGRAMS'))
1271     {
1272         $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
1273     }
1275     &handle_installdirs;
1276     &handle_clean;
1277     &handle_factored_dependencies;
1279     &check_typos;
1281     if (! -d ($output_directory . '/' . $am_relative_dir))
1282     {
1283         mkdir ($output_directory . '/' . $am_relative_dir, 0755);
1284     }
1286     my ($out_file) = $output_directory . '/' . $makefile . ".in";
1287     if (! $force_generation && -e $out_file)
1288     {
1289         my ($am_time) = (stat ($makefile . '.am'))[9];
1290         my ($in_time) = (stat ($out_file))[9];
1291         # FIXME: should cache these times.
1292         my ($conf_time) = (stat ($configure_ac))[9];
1293         # FIXME: how to do unsigned comparison?
1294         if ($am_time < $in_time || $am_time < $conf_time)
1295         {
1296             # No need to update.
1297             return;
1298         }
1299         if (-f 'aclocal.m4')
1300         {
1301             my ($acl_time) = (stat _)[9];
1302             return if ($am_time < $acl_time);
1303         }
1304     }
1306     my $gm_file = new IO::File "> $out_file";
1307     if (! $gm_file)
1308     {
1309         warn "$me: ${am_file}.in: cannot write: $!\n";
1310         $exit_status = 1;
1311         return;
1312     }
1313     print "$me: creating ", $makefile, ".in\n" if $verbose;
1315     # In case we're running under MSWindows, don't write with CRLF
1316     # (as it causes problems for the dependency-file extraction in
1317     # AM_OUTPUT_DEPENDENCY_COMMANDS).
1318     binmode $gm_file;
1320     print $gm_file $output_vars;
1321     # We make sure that `all:' is the first target.
1322     print $gm_file $output_all;
1323     print $gm_file $output_header;
1324     print $gm_file $output_rules;
1325     print $gm_file $output_trailer;
1327     if (! $gm_file->close)
1328       {
1329         warn "$me: $am_file.in: cannot close: $!\n";
1330         $exit_status = 1;
1331         return;
1332       }
1335 ################################################################
1337 # A helper which handles the logic of requiring a version number in
1338 # AUTOMAKE_OPTIONS.  Return 1 on error, 0 on success.
1339 sub version_check ($$$$)
1341     my ($rmajor, $rminor, $ralpha, $rfork) = ($1, $2, $3, $4);
1343     &prog_error ("version is incorrect: $VERSION")
1344         if $VERSION !~ /(\d+)\.(\d+)([a-z]?)-?([A-Za-z0-9]+)?/;
1346     my ($tmajor, $tminor, $talpha, $tfork) = ($1, $2, $3, $4);
1348     $rfork ||= '';
1349     $tfork ||= '';
1351     my $rminorminor = 0;
1352     my $tminorminor = 0;
1354     # Some versions were labelled like `1.4-p3a'.  This is the same as
1355     # an alpha release labelled `1.4.3a'.  However, a version like
1356     # `1.4g' is the same as `1.4.99g'.  Yes, this sucks.  Moral:
1357     # always listen to the users.
1358     if ($rfork =~ /p([0-9]+)([a-z]?)/)
1359     {
1360         $rminorminor = $1;
1361         # `1.4a-p3b' never existed.  But we'll accept it anyway.
1362         $ralpha = $ralpha || $2 || '';
1363         $rfork = '';
1364     }
1365     if ($tfork =~ /p([0-9]+)([a-z]?)/)
1366     {
1367         $tminorminor = $1;
1368         # `1.4a-p3b' never existed.  But we'll accept it anyway.
1369         $talpha = $talpha || $2 || '';
1370         $tfork = '';
1371     }
1373     $rminorminor = 99 if $ralpha ne '' && $rminorminor == 0;
1374     $tminorminor = 99 if $talpha ne '' && $tminorminor == 0;
1376     # 2.0 is better than 1.0.
1377     # 1.2 is better than 1.1.
1378     # 1.2a is better than 1.2.
1379     # If we require 3.4n-foo then we require something
1380     # >= 3.4n, with the `foo' fork identifier.
1381     # The $r* variables are what the user specified.
1382     # The $t* variables denote automake itself.
1383     if ($rmajor > $tmajor
1384         || ($rmajor == $tmajor && $rminor > $tminor)
1385         || ($rminor == $tminor && $rminor == $tminor
1386             && $rminorminor > $tminorminor)
1387         || ($rminor == $tminor && $rminor == $tminor
1388             && $rminorminor == $tminorminor
1389             && $ralpha gt $talpha)
1390         || ($rfork ne '' && $rfork ne $tfork))
1391     {
1392         &am_line_error ('AUTOMAKE_OPTIONS',
1393                         "require version $_, but have $VERSION");
1394         return 1;
1395     }
1397     return 0;
1400 # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
1401 sub handle_options
1403     if (&variable_defined ('AUTOMAKE_OPTIONS'))
1404     {
1405         foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
1406         {
1407             $options{$_} = 1;
1408             if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
1409             {
1410                 &set_strictness ($_);
1411             }
1412             elsif ($_ eq 'cygnus')
1413             {
1414                 $cygnus_mode = 1;
1415             }
1416             elsif (/ansi2knr/)
1417             {
1418                 # An option like "../lib/ansi2knr" is allowed.  With
1419                 # no path prefix, we assume the required programs are
1420                 # in this directory.  We save the actual option for
1421                 # later.
1422                 $options{'ansi2knr'} = $_;
1423             }
1424             elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
1425                    || $_ eq 'dist-shar' || $_ eq 'dist-zip'
1426                    || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
1427                    || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
1428                    || $_ eq 'readme-alpha' || $_ eq 'check-news'
1429                    || $_ eq 'subdir-objects' || $_ eq 'nostdinc'
1430                    || $_ eq 'no-exeext')
1431             {
1432                 # Explicitly recognize these.
1433             }
1434             elsif ($_ eq 'no-dependencies')
1435             {
1436                 $use_dependencies = 0;
1437             }
1438             elsif (/(\d+)\.(\d+)([a-z]?)(-[A-Za-z0-9]+)?/)
1439             {
1440                 # Got a version number.
1441                 if (version_check ($1, $2, $3, $4))
1442                 {
1443                     return 1;
1444                 }
1445             }
1446             else
1447             {
1448                 &am_line_error ('AUTOMAKE_OPTIONS',
1449                                 "option `" . $_ . "\' not recognized");
1450             }
1451         }
1452     }
1454     if ($strictness == $GNITS)
1455     {
1456         $options{'readme-alpha'} = 1;
1457         $options{'check-news'} = 1;
1458     }
1460     return 0;
1464 # get_object_extension ($OUT)
1465 # ---------------------------
1466 # Return object extension.  Just once, put some code into the output.
1467 # OUT is the name of the output file
1468 sub get_object_extension
1470     my ($out) = @_;
1472     # Maybe require libtool library object files.
1473     my $extension = '.$(OBJEXT)';
1474     $extension = '.lo' if ($out =~ /\.la$/);
1476     # Check for automatic de-ANSI-fication.
1477     $extension = '$U' . $extension
1478       if defined $options{'ansi2knr'};
1480     $get_object_extension_was_run = 1;
1482     return $extension;
1486 # Call finish function for each language that was used.
1487 sub handle_languages
1489     if ($use_dependencies)
1490     {
1491         # Include auto-dep code.  Don't include it if DEP_FILES would
1492         # be empty.
1493         if (&saw_sources_p (0) && keys %dep_files)
1494         {
1495             # Set location of depcomp.
1496             &define_variable ('depcomp', "\$(SHELL) $config_aux_dir/depcomp");
1498             &require_config_file ($FOREIGN, 'depcomp');
1500             my @deplist = sort keys %dep_files;
1502             # We define this as a conditional variable because BSD
1503             # make can't handle backslashes for continuing comments on
1504             # the following line.
1505             &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
1507             # Generate each `include' individually.  Irix 6 make will
1508             # not properly include several files resulting from a
1509             # variable expansion; generating many separate includes
1510             # seems safest.
1511             $output_rules .= "\n";
1512             foreach my $iter (@deplist)
1513             {
1514                 $output_rules .= (subst ('AMDEP_TRUE')
1515                                   . subst ('am__include')
1516                                   . ' '
1517                                   . subst ('am__quote')
1518                                   . $iter
1519                                   . subst ('am__quote')
1520                                   . "\n");
1521             }
1523             $output_rules .= &file_contents ('depend');
1524         }
1525     }
1526     else
1527     {
1528         &define_variable ('depcomp', '');
1529     }
1531     my %done;
1533     # Is the c linker needed?
1534     my $needs_c = 0;
1535     foreach my $ext (sort keys %extension_seen)
1536     {
1537         next unless $extension_map{$ext};
1539         my $lang = $languages{$extension_map{$ext}};
1541         my $rule_file = $lang->rule_file || 'depend2';
1543         # Get information on $LANG.
1544         my $pfx = $lang->autodep;
1545         my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1547         my $AMDEP = (($use_dependencies && $lang->autodep ne 'no')
1548                      ? 'AMDEP' : 'FALSE');
1550         my %transform = ('EXT'     => $ext,
1551                          'PFX'     => $pfx,
1552                          'FPFX'    => $fpfx,
1553                          'LIBTOOL' => $seen_libtool,
1554                          'AMDEP'   => $AMDEP,
1555                          '-c'      => $lang->compile_flag || '',
1556                          'MORE-THAN-ONE'
1557                                    => (count_files_for_language ($lang->name) > 1));
1559         # Generate the appropriate rules for this extension.
1560         if (($use_dependencies && $lang->autodep ne 'no')
1561             || defined $lang->compile)
1562         {
1563             # Some C compilers don't support -c -o.  Use it only if really
1564             # needed.
1565             my $output_flag = $lang->output_flag || '';
1566             $output_flag = '-o'
1567               if (! $output_flag
1568                   && $lang->flags eq 'CFLAGS'
1569                   && defined $options{'subdir-objects'});
1571             # FIXME: this is a temporary hack to compute a possible
1572             # derived extension.  This is not used by depend2.am.
1573             (my $der_ext = $ext) =~ tr/yl/cc/;
1575             # Another yacc/lex hack.
1576             my $destfile = '$*.' . $der_ext;
1578             $output_rules .=
1579               file_contents ($rule_file,
1580                              %transform,
1581                              'GENERIC'   => 1,
1583                              'DERIVED-EXT' => $der_ext,
1585                              'BASE'      => '$*',
1586                              'SOURCE'    => '$<',
1587                              'OBJ'       => '$@',
1588                              'OBJOBJ'    => '$@',
1589                              'LTOBJ'     => '$@',
1591                              'COMPILE'   => '$(' . $lang->compiler . ')',
1592                              'LTCOMPILE' => '$(LT' . $lang->compiler . ')',
1593                              '-o'        => $output_flag);
1594         }
1596         # Now include code for each specially handled object with this
1597         # language.
1598         my %seen_files = ();
1599         foreach my $file (@{$lang_specific_files{$lang->name}})
1600         {
1601             my ($derived, $source, $obj, $myext) = split (' ', $file);
1603             # We might see a given object twice, for instance if it is
1604             # used under different conditions.
1605             next if defined $seen_files{$obj};
1606             $seen_files{$obj} = 1;
1608             my $flags = $lang->flags || '';
1609             my $val = "${derived}_${flags}";
1611             &prog_error ("found $lang->name in handle_languages, but compiler not defined")
1612                 unless defined $lang->compile;
1614             (my $obj_compile = $lang->compile) =~ s/\(AM_$flags/\($val/;
1615             my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
1617             # We _need_ `-o' for per object rules.
1618             my $output_flag = $lang->output_flag || '-o';
1620             # Generate a transform which will turn suffix targets in
1621             # depend2.am into real targets for the particular objects we
1622             # are building.
1623             $output_rules .=
1624               file_contents ($rule_file,
1625                              (%transform,
1626                               'GENERIC'   => 0,
1628                               'BASE'      => $obj,
1629                               'SOURCE'    => $source,
1630                               # Use $myext and not `.o' here, in case
1631                               # we are actually building a new source
1632                               # file -- e.g. via yacc.
1633                               'OBJ'       => "$obj$myext",
1634                               'OBJOBJ'    => "$obj.obj",
1635                               'LTOBJ'     => "$obj.lo",
1637                               'COMPILE'   => $obj_compile,
1638                               'LTCOMPILE' => $obj_ltcompile,
1639                               '-o'        => $output_flag));
1640         }
1642         # The rest of the loop is done once per language.
1643         next if defined $done{$lang};
1644         $done{$lang} = 1;
1646         # Load the language dependent Makefile chunks.
1647         my %lang = map { uc ($_) => 0 } keys %languages;
1648         $lang{uc ($lang->name)} = 1;
1649         $output_rules .= file_contents ('lang-compile', %transform, %lang);
1651         # If the source to a program consists entirely of code from a
1652         # `pure' language, for instance C++ for Fortran 77, then we
1653         # don't need the C compiler code.  However if we run into
1654         # something unusual then we do generate the C code.  There are
1655         # probably corner cases here that do not work properly.
1656         # People linking Java code to Fortran code deserve pain.
1657         $needs_c ||= ! $lang->pure;
1659         define_compiler_variable ($lang)
1660           if ($lang->compile);
1662         define_linker_variable ($lang)
1663           if ($lang->link);
1665         foreach my $var (@{$lang->config_vars})
1666           {
1667             am_error ($lang->Name
1668                       . " source seen but `$var' not defined in"
1669                       . " `$configure_ac'")
1670               if !exists $configure_vars{$var};
1671           }
1673         # The compiler's flag must be a configure variable.
1674         define_configure_variable ($lang->flags)
1675             if defined $lang->flags && $lang->define_flag;
1677         # Call the finisher.
1678         $lang->finish;
1679     }
1681     # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1682     # suffix rule was learned), don't bother with the C stuff.  But if
1683     # anything else creeps in, then use it.
1684     $needs_c = 1
1685       if $need_link || scalar keys %suffix_rules > 1;
1687     if ($needs_c)
1688       {
1689         if (! defined $done{$languages{'c'}})
1690           {
1691             &define_configure_variable ($languages{'c'}->flags);
1692             &define_compiler_variable ($languages{'c'});
1693           }
1694         define_linker_variable ($languages{'c'});
1695       }
1698 # Check to make sure a source defined in LIBOBJS is not explicitly
1699 # mentioned.  This is a separate function (as opposed to being inlined
1700 # in handle_source_transform) because it isn't always appropriate to
1701 # do this check.
1702 sub check_libobjs_sources
1704     my ($one_file, $unxformed) = @_;
1706     foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1707                         'dist_EXTRA_', 'nodist_EXTRA_')
1708     {
1709         my @files;
1710         if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1711         {
1712             @files = &variable_value_as_list (($prefix
1713                                                . $one_file . '_SOURCES'),
1714                                               'all');
1715         }
1716         elsif ($prefix eq '')
1717         {
1718             @files = ($unxformed . '.c');
1719         }
1720         else
1721         {
1722             next;
1723         }
1725         foreach my $file (@files)
1726         {
1727             if (defined $libsources{$file})
1728             {
1729                 &am_line_error ($prefix . $one_file . '_SOURCES',
1730                                 "automatically discovered file `$file' should not be explicitly mentioned");
1731             }
1732         }
1733     }
1737 # ($LINKER, @OBJECTS)
1738 # handle_single_transform_list ($VAR, $DERIVED, $OBJ, @FILES)
1739 # -----------------------------------------------------------
1740 # Does much of the actual work for handle_source_transform.
1741 # Arguments are:
1742 #   $DERIVED is the name of resulting executable or library
1743 #   $OBJ is the object extension (e.g., `$U.lo')
1744 #   @FILES is the list of source files to transform
1745 # Result is a list
1746 #   $LINKER is name of linker to use (empty string for default linker)
1747 #   @OBJECTS are names of objects
1748 sub handle_single_transform_list ($$$@)
1750     my ($var, $derived, $obj, @files) = @_;
1751     my @result = ();
1752     my $nonansi_obj = $obj;
1753     $nonansi_obj =~ s/\$U//g;
1754     my %linkers_used = ();
1756     # Turn sources into objects.  We use a while loop like this
1757     # because we might add to @files in the loop.
1758     while (scalar @files > 0)
1759     {
1760         $_ = shift @files;
1762         # Configure substitutions in _SOURCES variables are errors.
1763         if (/^\@.*\@$/)
1764         {
1765             &am_line_error ($var, "$var includes configure substitution `$_'");
1766             next;
1767         }
1769         # If the source file is in a subdirectory then the `.o' is put
1770         # into the current directory, unless the subdir-objects option
1771         # is in effect.
1773         # Split file name into base and extension.
1774         next if ! /^(?:(.*)\/)?([^\/]*)\.(.*)$/;
1775         my $full = $_;
1776         my $directory = $1 || '';
1777         my $base = $2;
1778         my $extension = $3;
1780         # We must generate a rule for the object if it requires its own flags.
1781         my $renamed = 0;
1782         my ($linker, $object);
1784         # This records whether we've seen a derived source file (eg,
1785         # yacc output).
1786         my $derived_source = 0;
1788         # This holds the `aggregate context' of the file we are
1789         # currently examining.  If the file is compiled with
1790         # per-object flags, then it will be the name of the object.
1791         # Otherwise it will be `AM'.  This is used by the target hook
1792         # language function.
1793         my $aggregate = 'AM';
1795         $extension = &derive_suffix ($extension);
1796         my $lang;
1797         if ($extension_map{$extension} &&
1798             ($lang = $languages{$extension_map{$extension}}))
1799         {
1800             # Found the language, so see what it says.
1801             &saw_extension ($extension);
1803             # Note: computed subr call.  The language rewrite function
1804             # should return one of the $LANG_* constants.  It could
1805             # also return a list whose first value is such a constant
1806             # and whose second value is a new source extension which
1807             # should be applied.  This means this particular language
1808             # generates another source file which we must then process
1809             # further.
1810             my $subr = 'lang_' . $lang->name . '_rewrite';
1811             my ($r, $source_extension)
1812                 = & $subr ($directory, $base, $extension);
1813             # Skip this entry if we were asked not to process it.
1814             next if $r == $LANG_IGNORE;
1816             # Now extract linker and other info.
1817             $linker = $lang->linker;
1819             my $this_obj_ext;
1820             if (defined $source_extension)
1821             {
1822                 $this_obj_ext = '.' . $source_extension;
1823                 $derived_source = 1;
1824             }
1825             elsif ($lang->ansi)
1826             {
1827                 $this_obj_ext = $obj;
1828             }
1829             else
1830             {
1831                 $this_obj_ext = $nonansi_obj;
1832             }
1833             $object = $base . $this_obj_ext;
1835             if (defined $lang->flags
1836                 && &variable_defined ($derived . '_' . $lang->flags))
1837             {
1838                 # We have a per-executable flag in effect for this
1839                 # object.  In this case we rewrite the object's
1840                 # name to ensure it is unique.  We also require
1841                 # the `compile' program to deal with compilers
1842                 # where `-c -o' does not work.
1844                 # We choose the name `DERIVED_OBJECT' to ensure
1845                 # (1) uniqueness, and (2) continuity between
1846                 # invocations.  However, this will result in a
1847                 # name that is too long for losing systems, in
1848                 # some situations.  So we provide _SHORTNAME to
1849                 # override.
1851                 my $dname = $derived;
1852                 if (&variable_defined ($derived . '_SHORTNAME'))
1853                 {
1854                     # FIXME: should use the same conditional as
1855                     # the _SOURCES variable.  But this is really
1856                     # silly overkill -- nobody should have
1857                     # conditional shortnames.
1858                     $dname = &variable_value ($derived . '_SHORTNAME');
1859                 }
1860                 $object = $dname . '-' . $object;
1862                 &require_config_file ($FOREIGN, 'compile')
1863                     if $lang->name eq 'c';
1865                 &prog_error ("$lang->name flags defined without compiler")
1866                     if ! defined $lang->compile;
1868                 $renamed = 1;
1869             }
1871             # If rewrite said it was ok, put the object into a
1872             # subdir.
1873             if ($r == $LANG_SUBDIR && $directory ne '')
1874             {
1875                 $object = $directory . '/' . $object;
1876             }
1878             # If doing dependency tracking, then we can't print
1879             # the rule.  If we have a subdir object, we need to
1880             # generate an explicit rule.  Actually, in any case
1881             # where the object is not in `.' we need a special
1882             # rule.  The per-object rules in this case are
1883             # generated later, by handle_languages.
1884             if ($renamed || $directory ne '')
1885             {
1886                 my $obj_sans_ext = substr ($object, 0,
1887                                            - length ($this_obj_ext));
1888                 my $val = ("$full $obj_sans_ext "
1889                            # Only use $this_obj_ext in the derived
1890                            # source case because in the other case we
1891                            # *don't* want $(OBJEXT) to appear here.
1892                            . ($derived_source ? $this_obj_ext : '.o'));
1894                 # If we renamed the object then we want to use the
1895                 # per-executable flag name.  But if this is simply a
1896                 # subdir build then we still want to use the AM_ flag
1897                 # name.
1898                 if ($renamed)
1899                 {
1900                     $val = "$derived $val";
1901                     $aggregate = $derived;
1902                 }
1903                 else
1904                 {
1905                     $val = "AM $val";
1906                 }
1908                 # Each item on this list is a string consisting of
1909                 # four space-separated values: the derived flag prefix
1910                 # (eg, for `foo_CFLAGS', it is `foo'), the name of the
1911                 # source file, the base name of the output file, and
1912                 # the extension for the object file.
1913                 push (@{$lang_specific_files{$lang->name}}, $val);
1914             }
1915         }
1916         elsif ($extension eq 'o')
1917         {
1918             # This is probably the result of a direct suffix rule.
1919             # In this case we just accept the rewrite.  FIXME:
1920             # this fails if we want libtool objects.
1921             $object = $base . '.' . $extension;
1922             $linker = '';
1923         }
1924         else
1925         {
1926             # No error message here.  Used to have one, but it was
1927             # very unpopular.
1928             # FIXME: we could potentially do more processing here,
1929             # perhaps treating the new extension as though it were a
1930             # new source extension (as above).  This would require
1931             # more restructuring than is appropriate right now.
1932             next;
1933         }
1935         if (defined $object_map{$object})
1936         {
1937             if ($object_map{$object} ne $full)
1938             {
1939                 &am_error ("object `$object' created by `$full' and `$object_map{$object}'");
1940             }
1941         }
1943         # Let the language do some special magic if required.
1944         $lang->target_hook ($aggregate, $object, $full);
1946         if ($derived_source)
1947         {
1948             &prog_error ("$lang->name has automatic dependency tracking")
1949                 if $lang->autodep ne 'no';
1950             # Make sure this new source file is handled next.  That will
1951             # make it appear to be at the right place in the list.
1952             unshift (@files, $object);
1953             # FIXME: nodist.
1954             &push_dist_common ($object);
1955             next;
1956         }
1958         $linkers_used{$linker} = 1;
1960         push (@result, $object);
1962         if (! defined $object_map{$object})
1963         {
1964             my @dep_list = ();
1965             $object_map{$object} = $full;
1967             # If file is in subdirectory, we need explicit
1968             # dependency.
1969             if ($directory ne '' || $renamed)
1970             {
1971                 push (@dep_list, $full);
1972             }
1974             # If resulting object is in subdir, we need to make
1975             # sure the subdir exists at build time.
1976             if ($object =~ /\//)
1977             {
1978                 # FIXME: check that $DIRECTORY is somewhere in the
1979                 # project
1981                 # We don't allow `..' in object file names for
1982                 # *any* source, not just Java.  For Java it just
1983                 # doesn't make sense, but in general it is
1984                 # a problem because we can't pick a good name for
1985                 # the .deps entry.
1986                 if ($object =~ /(\/|^)\.\.\//)
1987                 {
1988                     &am_error ("`$full' contains `..' component but should not");
1989                 }
1991                 # Make sure object is removed by `make mostlyclean'.
1992                 $compile_clean_files{$object} = $MOSTLY_CLEAN;
1994                 push (@dep_list, &require_build_directory ($directory));
1996                 # If we're generating dependencies, we also want
1997                 # to make sure that the appropriate subdir of the
1998                 # .deps directory is created.
1999                 push (@dep_list, &require_build_directory ('$(DEPDIR)/' . $directory))
2000                     if ($use_dependencies);
2001             }
2003             &pretty_print_rule ($object . ':', "\t", @dep_list)
2004                 if scalar @dep_list > 0;
2005         }
2007         # Transform .o or $o file into .P file (for automatic
2008         # dependency code).
2009         if ($lang && $lang->autodep ne 'no')
2010         {
2011             my $depfile = $object;
2012             $depfile =~ s/\.([^.]*)$/.P$1/;
2013             $depfile =~ s/\$\(OBJEXT\)$/o/;
2014             $dep_files{'$(DEPDIR)/' . $depfile} = 1;
2015         }
2016     }
2018     return (&resolve_linker (%linkers_used), @result);
2023 # Handle SOURCE->OBJECT transform for one program or library.
2024 # Arguments are:
2025 #   canonical (transformed) name of object to build
2026 #   actual name of object to build
2027 #   object extension (ie either `.o' or `$o'.
2028 # Return result is name of linker variable that must be used.
2029 # Empty return means just use `LINK'.
2030 sub handle_source_transform
2032     # one_file is canonical name.  unxformed is given name.  obj is
2033     # object extension.
2034     my ($one_file, $unxformed, $obj) = @_;
2036     my ($linker) = '';
2038     if (&variable_defined ($one_file . "_OBJECTS"))
2039     {
2040         &am_line_error ($one_file . '_OBJECTS',
2041                         $one_file . '_OBJECTS', 'should not be defined');
2042         # No point in continuing.
2043         return;
2044     }
2046     my %used_pfx = ();
2047     foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2048                         'dist_EXTRA_', 'nodist_EXTRA_')
2049     {
2050         my $var = $prefix . $one_file . "_SOURCES";
2051         next
2052           if !variable_defined ($var);
2054         # We are going to define _OBJECTS variables using the prefix.
2055         # Then we glom them all together.  So we can't use the null
2056         # prefix here as we need it later.
2057         my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2059         # Keep track of which prefixes we saw.
2060         $used_pfx{$xpfx} = 1
2061           unless $prefix =~ /EXTRA_/;
2063         push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
2064         push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
2065           unless $prefix =~ /^nodist_/;
2066         foreach my $cond (variable_conditions ($var))
2067           {
2068             my @files = &variable_value_as_list ($var, $cond);
2069             my ($temp, @result) =
2070               &handle_single_transform_list ($var, $one_file, $obj,
2071                                              @files);
2072             # If there are no files to compile, don't require a linker (yet).
2073             $linker ||= $temp
2074               if @files;
2076             # Define _OBJECTS conditionally.
2077             &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
2078                                      $cond, @result)
2079               unless $prefix =~ /EXTRA_/;
2080           }
2081     }
2083     my @keys = sort keys %used_pfx;
2084     if (scalar @keys == 0)
2085     {
2086         &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
2087         push (@sources, $unxformed . '.c');
2088         push (@dist_sources, $unxformed . '.c');
2090         my ($temp, @result) =
2091           &handle_single_transform_list ($one_file . '_SOURCES',
2092                                          $one_file, $obj,
2093                                          "$unxformed.c");
2094         $linker = $temp if $linker eq '';
2095         &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
2096     }
2097     else
2098     {
2099         grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
2100         &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
2101     }
2103     # If we want to use `LINK' we must make sure it is defined.
2104     if ($linker eq '')
2105     {
2106         $need_link = 1;
2107     }
2109     return $linker;
2113 # handle_lib_objects ($XNAME, $VAR)
2114 # ---------------------------------
2115 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
2116 # Also, generate _DEPENDENCIES variable if appropriate.
2117 # Arguments are:
2118 #   transformed name of object being built, or empty string if no object
2119 #   name of _LDADD/_LIBADD-type variable to examine
2120 # Returns 1 if LIBOBJS seen, 0 otherwise.
2121 sub handle_lib_objects
2123     my ($xname, $var) = @_;
2125     &prog_error ("handle_lib_objects: $var undefined")
2126         if ! &variable_defined ($var);
2128     my $ret = 0;
2129     foreach my $cond (&variable_conditions ($var))
2130       {
2131         if (&handle_lib_objects_cond ($xname, $var, $cond))
2132           {
2133             $ret = 1;
2134           }
2135       }
2136     return $ret;
2139 # Subroutine of handle_lib_objects: handle a particular condition.
2140 sub handle_lib_objects_cond
2142     my ($xname, $var, $cond) = @_;
2144     # We recognize certain things that are commonly put in LIBADD or
2145     # LDADD.
2146     my @dep_list = ();
2148     my $seen_libobjs = 0;
2149     my $flagvar = 0;
2151     foreach my $lsearch (&variable_value_as_list ($var, $cond))
2152     {
2153         # Skip -lfoo and -Ldir; these are explicitly allowed.
2154         next if $lsearch =~ /^-[lL]/;
2155         if (! $flagvar && $lsearch =~ /^-/)
2156         {
2157             if ($var =~ /^(.*)LDADD$/)
2158             {
2159                 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
2160                 next if $lsearch =~ /^-dl(pre)?open$/;
2161                 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2162             }
2163             else
2164             {
2165                 # Only get this error once.
2166                 $flagvar = 1;
2167                 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2168             }
2169         }
2171         # Assume we have a file of some sort, and push it onto the
2172         # dependency list.  Autoconf substitutions are not pushed;
2173         # rarely is a new dependency substituted into (eg) foo_LDADD
2174         # -- but "bad things (eg -lX11) are routinely substituted.
2175         # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2176         # and handled specially below.
2177         push (@dep_list, $lsearch)
2178             unless $lsearch =~ /^\@.*\@$/;
2180         # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
2181         # means adding entries to dep_files.
2182         if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
2183         {
2184             my $myobjext = ($1 ? 'l' : '') . 'o';
2186             push (@dep_list, $lsearch);
2187             $seen_libobjs = 1;
2188             if (! keys %libsources
2189                 && ! &variable_defined ($1 . 'LIBOBJS'))
2190             {
2191                 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in `$configure_ac'");
2192             }
2194             foreach my $iter (keys %libsources)
2195             {
2196                 if ($iter =~ /\.([cly])$/)
2197                 {
2198                     &saw_extension ($1);
2199                     &saw_extension ('c');
2200                 }
2202                 if ($iter =~ /\.h$/)
2203                 {
2204                     &require_file_with_line ($var, $FOREIGN, $iter);
2205                 }
2206                 elsif ($iter ne 'alloca.c')
2207                 {
2208                     my $rewrite = $iter;
2209                     $rewrite =~ s/\.c$/.P$myobjext/;
2210                     $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
2211                     ($rewrite = $iter) =~ s/(\W)/\\$1/g;
2212                     $rewrite = "^" . $rewrite . "\$";
2213                     # Only require the file if it is not a built source.
2214                     if (! &variable_defined ('BUILT_SOURCES')
2215                         || ! grep (/$rewrite/,
2216                                    &variable_value_as_list ('BUILT_SOURCES',
2217                                                             'all')))
2218                     {
2219                         &require_file_with_line ($var, $FOREIGN, $iter);
2220                     }
2221                 }
2222             }
2223         }
2224         elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
2225         {
2226             my $myobjext = ($1 ? 'l' : '') . 'o';
2228             push (@dep_list, $lsearch);
2229             &am_line_error ($var,
2230                             "\@$1" . "ALLOCA\@ seen but `AC_FUNC_ALLOCA' not in `$configure_ac'")
2231                 if ! defined $libsources{'alloca.c'};
2232             $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
2233             &require_file_with_line ($var, $FOREIGN, 'alloca.c');
2234             &saw_extension ('c');
2235         }
2236     }
2238     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
2239     {
2240         &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
2241     }
2243     return $seen_libobjs;
2246 # Canonicalize the input parameter
2247 sub canonicalize
2249     my ($string) = @_;
2250     $string =~ tr/A-Za-z0-9_\@/_/c;
2251     return $string;
2254 # Canonicalize a name, and check to make sure the non-canonical name
2255 # is never used.  Returns canonical name.  Arguments are name and a
2256 # list of suffixes to check for.
2257 sub check_canonical_spelling
2259     my ($name, @suffixes) = @_;
2261     my $xname = &canonicalize ($name);
2262     if ($xname ne $name)
2263     {
2264         foreach my $xt (@suffixes)
2265         {
2266             &am_line_error ("$name$xt",
2267                             "invalid variable `$name$xt'; "
2268                             . "should be `$xname$xt'")
2269                 if &variable_defined ("$name$xt");
2270         }
2271     }
2273     return $xname;
2277 # handle_compile ()
2278 # -----------------
2279 # Set up the compile suite.
2280 sub handle_compile ()
2282     return
2283       unless $get_object_extension_was_run;
2285     # Boilerplate.
2286     my $default_includes = '';
2287     if (! defined $options{'nostdinc'})
2288       {
2289         $default_includes = ' -I. -I$(srcdir)';
2291         if (&variable_defined ('CONFIG_HEADER'))
2292           {
2293             foreach my $hdr (split (' ', &variable_value ('CONFIG_HEADER')))
2294               {
2295                 $default_includes .= ' -I' . dirname ($hdr);
2296               }
2297           }
2298       }
2300     my (@mostly_rms, @dist_rms);
2301     foreach my $item (sort keys %compile_clean_files)
2302     {
2303         if ($compile_clean_files{$item} == $MOSTLY_CLEAN)
2304         {
2305             push (@mostly_rms, "\t-rm -f $item");
2306         }
2307         elsif ($compile_clean_files{$item} == $DIST_CLEAN)
2308         {
2309             push (@dist_rms, "\t-rm -f $item");
2310         }
2311         else
2312         {
2313             &prog_error ("invalid entry in \%compile_clean_files");
2314         }
2315     }
2317     my ($coms, $vars, $rules) =
2318       &file_contents_internal (1, "$libdir/am/compile.am",
2319                                ('DEFAULT_INCLUDES' => $default_includes,
2320                                 'MOSTLYRMS' => join ("\n", @mostly_rms),
2321                                 'DISTRMS' => join ("\n", @dist_rms)));
2322     $output_vars .= $vars;
2323     $output_rules .= "$coms$rules";
2325     # Check for automatic de-ANSI-fication.
2326     if (defined $options{'ansi2knr'})
2327       {
2328         if (! $am_c_prototypes)
2329           {
2330             &am_line_error ('AUTOMAKE_OPTIONS',
2331                             "option `ansi2knr' in use but `AM_C_PROTOTYPES' not in `$configure_ac'");
2332             &keyed_aclocal_warning ('AM_C_PROTOTYPES');
2333             # Only give this error once.
2334             $am_c_prototypes = 1;
2335           }
2337         # topdir is where ansi2knr should be.
2338         if ($options{'ansi2knr'} eq 'ansi2knr')
2339           {
2340             # Only require ansi2knr files if they should appear in
2341             # this directory.
2342             &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
2343                                      'ansi2knr.c', 'ansi2knr.1');
2345             # ansi2knr needs to be built before subdirs, so unshift it.
2346             unshift (@all, '$(ANSI2KNR)');
2347           }
2349         my $ansi2knr_dir = '';
2350         $ansi2knr_dir = dirname ($options{'ansi2knr'})
2351           if $options{'ansi2knr'} ne 'ansi2knr';
2353         $output_rules .= &file_contents ('ansi2knr',
2354                                          ('ANSI2KNR-DIR' => $ansi2knr_dir));
2356     }
2359 # handle_libtool ()
2360 # -----------------
2361 # Handle libtool rules.
2362 sub handle_libtool
2364     return unless $seen_libtool;
2366     # libtool requires some files, but only at top level.
2367     &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
2368                                        @libtoolize_files)
2369         if $relative_dir eq '.';
2371     # Output the libtool compilation rules.
2372     $output_rules .= &file_contents ('libtool');
2375 # handle_programs ()
2376 # ------------------
2377 # Handle C programs.
2378 sub handle_programs
2380     my @proglist = &am_install_var ('progs', 'PROGRAMS',
2381                                     'bin', 'sbin', 'libexec', 'pkglib',
2382                                     'noinst', 'check');
2383     return if ! @proglist;
2385     my $seen_libobjs = 0;
2386     foreach my $one_file (@proglist)
2387     {
2388         my $obj = &get_object_extension ($one_file);
2390         # Canonicalize names and check for misspellings.
2391         my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2392                                                '_SOURCES', '_OBJECTS',
2393                                                '_DEPENDENCIES');
2395         my $linker = &handle_source_transform ($xname, $one_file, $obj);
2397         my $xt = '';
2398         if (&variable_defined ($xname . "_LDADD"))
2399         {
2400             if (&handle_lib_objects ($xname, $xname . '_LDADD'))
2401             {
2402                 $seen_libobjs = 1;
2403             }
2404             $xt = '_LDADD';
2405         }
2406         else
2407         {
2408             # User didn't define prog_LDADD override.  So do it.
2409             &define_variable ($xname . '_LDADD', '$(LDADD)');
2411             # This does a bit too much work.  But we need it to
2412             # generate _DEPENDENCIES when appropriate.
2413             if (&variable_defined ('LDADD'))
2414             {
2415                 if (&handle_lib_objects ($xname, 'LDADD'))
2416                 {
2417                     $seen_libobjs = 1;
2418                 }
2419             }
2420             elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
2421             {
2422                 &define_variable ($xname . '_DEPENDENCIES', '');
2423             }
2424             $xt = '_SOURCES'
2425         }
2427         if (&variable_defined ($xname . '_LIBADD'))
2428         {
2429             &am_line_error ($xname . '_LIBADD',
2430                             "use `" . $xname . "_LDADD', not `"
2431                             . $xname . "_LIBADD'");
2432         }
2434         if (! &variable_defined ($xname . '_LDFLAGS'))
2435         {
2436             # Define the prog_LDFLAGS variable.
2437             &define_variable ($xname . '_LDFLAGS', '');
2438         }
2440         # Determine program to use for link.
2441         my $xlink;
2442         if (&variable_defined ($xname . '_LINK'))
2443         {
2444             $xlink = $xname . '_LINK';
2445         }
2446         else
2447         {
2448             $xlink = $linker ? $linker : 'LINK';
2449         }
2451         # If the resulting program lies into a subdirectory,
2452         # make sure this directory will exist.
2453         my $dirstamp = &require_build_directory_maybe ($one_file);
2455         # Don't add $(EXEEXT) if user already did.
2456         my $extension = ($one_file !~ /\$\(EXEEXT\)$/
2457                          ? "\$(EXEEXT)"
2458                          : '');
2460         $output_rules .= &file_contents ('program',
2461                                          ('PROGRAM'  => $one_file,
2462                                           'XPROGRAM' => $xname,
2463                                           'XLINK'    => $xlink,
2464                                           'DIRSTAMP' => $dirstamp,
2465                                           'EXEEXT'   => $extension));
2466     }
2468     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD'))
2469     {
2470         $seen_libobjs = 1;
2471     }
2473     if ($seen_libobjs)
2474     {
2475         foreach my $one_file (@proglist)
2476         {
2477             my $xname = &canonicalize ($one_file);
2479             if (&variable_defined ($xname . '_LDADD'))
2480             {
2481                 &check_libobjs_sources ($xname, $xname . '_LDADD');
2482             }
2483             elsif (&variable_defined ('LDADD'))
2484             {
2485                 &check_libobjs_sources ($xname, 'LDADD');
2486             }
2487         }
2488     }
2492 # handle_libraries ()
2493 # -------------------
2494 # Handle libraries.
2495 sub handle_libraries
2497     my @liblist = &am_install_var ('libs', 'LIBRARIES',
2498                                    'lib', 'pkglib', 'noinst', 'check');
2499     return if ! @liblist;
2501     my %valid = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2502                                       'noinst', 'check');
2503     if (! defined $configure_vars{'RANLIB'})
2504     {
2505         foreach my $key (keys %valid)
2506         {
2507             if (&variable_defined ($key . '_LIBRARIES'))
2508             {
2509                 &am_line_error ($key . '_LIBRARIES', "library used but `RANLIB' not defined in `$configure_ac'");
2510                 # Only get this error once.  If this is ever printed,
2511                 # we have a bug.
2512                 $configure_vars{'RANLIB'} = 'BUG';
2513                 last;
2514             }
2515         }
2516     }
2518     my $seen_libobjs = 0;
2519     foreach my $onelib (@liblist)
2520     {
2521         # Check that the library fits the standard naming convention.
2522         if (basename ($onelib) !~ /^lib.*\.a/)
2523         {
2524             # FIXME should put line number here.  That means mapping
2525             # from library name back to variable name.
2526             &am_error ("`$onelib' is not a standard library name");
2527         }
2529         my $obj = &get_object_extension ($onelib);
2531         # Canonicalize names and check for misspellings.
2532         my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2533                                               '_OBJECTS', '_DEPENDENCIES',
2534                                               '_AR');
2536         if (! &variable_defined ($xlib . '_AR'))
2537         {
2538             &define_variable ($xlib . '_AR', '$(AR) cru');
2539         }
2541         if (&variable_defined ($xlib . '_LIBADD'))
2542         {
2543             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2544             {
2545                 $seen_libobjs = 1;
2546             }
2547         }
2548         else
2549         {
2550             # Generate support for conditional object inclusion in
2551             # libraries.
2552             &define_variable ($xlib . "_LIBADD", '');
2553         }
2555         if (&variable_defined ($xlib . '_LDADD'))
2556         {
2557             &am_line_error ($xlib . '_LDADD',
2558                             "use `" . $xlib . "_LIBADD', not `"
2559                             . $xlib . "_LDADD'");
2560         }
2562         # Make sure we at look at this.
2563         &examine_variable ($xlib . '_DEPENDENCIES');
2565         &handle_source_transform ($xlib, $onelib, $obj);
2567         # If the resulting library lies into a subdirectory,
2568         # make sure this directory will exist.
2569         my $dirstamp = &require_build_directory_maybe ($onelib);
2571         $output_rules .= &file_contents ('library',
2572                                          ('LIBRARY'  => $onelib,
2573                                           'XLIBRARY' => $xlib,
2574                                           'DIRSTAMP' => $dirstamp));
2575     }
2577     if ($seen_libobjs)
2578     {
2579         foreach my $onelib (@liblist)
2580         {
2581             my $xlib = &canonicalize ($onelib);
2582             if (&variable_defined ($xlib . '_LIBADD'))
2583             {
2584                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2585             }
2586         }
2587     }
2591 # handle_ltlibraries ()
2592 # ---------------------
2593 # Handle shared libraries.
2594 sub handle_ltlibraries
2596     my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2597                                    'noinst', 'lib', 'pkglib', 'check');
2598     return if ! @liblist;
2600     my %instdirs;
2601     my %valid = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2602                                       'noinst', 'check');
2604     foreach my $key (keys %valid)
2605     {
2606         if (&variable_defined ($key . '_LTLIBRARIES'))
2607         {
2608             if (!$seen_libtool)
2609             {
2610                 &am_line_error ($key . '_LTLIBRARIES', "library used but `LIBTOOL' not defined in `$configure_ac'");
2611                 # Only get this error once.  If this is ever printed,
2612                 # we have a bug.
2613                 $configure_vars{'LIBTOOL'} = 'BUG';
2614                 $seen_libtool = 1;
2615             }
2617             # Get the installation directory of each library.
2618             for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
2619             {
2620                 if ($instdirs{$_})
2621                 {
2622                     &am_error ("`$_' is already going to be installed in `$instdirs{$_}'");
2623                 }
2624                 else
2625                 {
2626                     $instdirs{$_} = $key;
2627                 }
2628             }
2629         }
2630     }
2632     my $seen_libobjs = 0;
2633     foreach my $onelib (@liblist)
2634     {
2635         my $obj = &get_object_extension ($onelib);
2637         # Canonicalize names and check for misspellings.
2638         my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2639                                               '_SOURCES', '_OBJECTS',
2640                                               '_DEPENDENCIES');
2642         if (! &variable_defined ($xlib . '_LDFLAGS'))
2643         {
2644             # Define the lib_LDFLAGS variable.
2645             &define_variable ($xlib . '_LDFLAGS', '');
2646         }
2648         # Check that the library fits the standard naming convention.
2649         my $libname_rx = "^lib.*\.la";
2650         if ((&variable_defined ($xlib . '_LDFLAGS')
2651              && grep (/-module/, &variable_value_as_list ($xlib . '_LDFLAGS',
2652                                                           'all')))
2653             || (&variable_defined ('LDFLAGS')
2654                 && grep (/-module/, &variable_value_as_list ('LDFLAGS',
2655                                                              'all'))))
2656         {
2657                 # Relax name checking for libtool modules.
2658                 $libname_rx = "\.la";
2659         }
2660         if (basename ($onelib) !~ /$libname_rx$/)
2661         {
2662             # FIXME this should only be a warning for foreign packages
2663             # FIXME should put line number here.  That means mapping
2664             # from library name back to variable name.
2665             &am_error ("`$onelib' is not a standard libtool library name");
2666         }
2668         if (&variable_defined ($xlib . '_LIBADD'))
2669         {
2670             if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2671             {
2672                 $seen_libobjs = 1;
2673             }
2674         }
2675         else
2676         {
2677             # Generate support for conditional object inclusion in
2678             # libraries.
2679             &define_variable ($xlib . "_LIBADD", '');
2680         }
2682         if (&variable_defined ($xlib . '_LDADD'))
2683         {
2684             &am_line_error ($xlib . '_LDADD',
2685                             "use `" . $xlib . "_LIBADD', not `"
2686                             . $xlib . "_LDADD'");
2687         }
2689         # Make sure we at look at this.
2690         &examine_variable ($xlib . '_DEPENDENCIES');
2692         my $linker = &handle_source_transform ($xlib, $onelib, $obj);
2694         # Determine program to use for link.
2695         my $xlink;
2696         if (&variable_defined ($xlib . '_LINK'))
2697         {
2698             $xlink = $xlib . '_LINK';
2699         }
2700         else
2701         {
2702             $xlink = $linker ? $linker : 'LINK';
2703         }
2705         my $rpath;
2706         if ($instdirs{$onelib} eq 'EXTRA'
2707             || $instdirs{$onelib} eq 'noinst'
2708             || $instdirs{$onelib} eq 'check')
2709         {
2710             # It's an EXTRA_ library, so we can't specify -rpath,
2711             # because we don't know where the library will end up.
2712             # The user probably knows, but generally speaking automake
2713             # doesn't -- and in fact configure could decide
2714             # dynamically between two different locations.
2715             $rpath = '';
2716         }
2717         else
2718         {
2719             $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
2720         }
2722         # If the resulting library lies into a subdirectory,
2723         # make sure this directory will exist.
2724         my $dirstamp = &require_build_directory_maybe ($onelib);
2726         $output_rules .= &file_contents ('ltlibrary',
2727                                          ('LTLIBRARY'  => $onelib,
2728                                           'XLTLIBRARY' => $xlib,
2729                                           'RPATH'      => $rpath,
2730                                           'XLINK'      => $xlink,
2731                                           'DIRSTAMP'   => $dirstamp));
2732     }
2734     if ($seen_libobjs)
2735     {
2736         foreach my $onelib (@liblist)
2737         {
2738             my $xlib = &canonicalize ($onelib);
2739             if (&variable_defined ($xlib . '_LIBADD'))
2740             {
2741                 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2742             }
2743         }
2744     }
2747 # See if any _SOURCES variable were misspelled.  Also, make sure that
2748 # EXTRA_ variables don't contain configure substitutions.
2749 sub check_typos
2751     foreach my $varname (keys %var_value)
2752     {
2753         foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
2754                              '_DEPENDENCIES')
2755         {
2756             if ($varname =~ /$primary$/ && ! $content_seen{$varname})
2757             {
2758                 &am_line_error ($varname,
2759                                 "invalid unused variable name: `$varname'");
2760             }
2761         }
2762     }
2765 # Handle scripts.
2766 sub handle_scripts
2768     # NOTE we no longer automatically clean SCRIPTS, because it is
2769     # useful to sometimes distribute scripts verbatim.  This happens
2770     # eg in Automake itself.
2771     &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2772                      'bin', 'sbin', 'libexec', 'pkgdata',
2773                      'noinst', 'check');
2775     my $scripts_installed = 0;
2776     # Set $scripts_installed if appropriate.  Make sure we only find
2777     # scripts which are actually installed -- this is why we can't
2778     # simply use the return value of am_install_var.
2779     my %valid = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
2780                                       'libexec', 'pkgdata',
2781                                       'noinst', 'check');
2782     foreach my $key (keys %valid)
2783     {
2784         if ($key ne 'noinst'
2785             && $key ne 'check'
2786             && &variable_defined ($key . '_SCRIPTS'))
2787         {
2788             $scripts_installed = 1;
2789             # push (@check_tests, 'check-' . $key . 'SCRIPTS');
2790         }
2791     }
2795 # ($OUTFILE, $VFILE, @CLEAN_FILES)
2796 # &scan_texinfo_file ($FILENAME)
2797 # ------------------------------
2798 # $OUTFILE is the name of the info file produced by $FILENAME.
2799 # $VFILE is the name of the version.texi file used (empty if none).
2800 # @CLEAN_FILES is the list of by products (indexes etc.)
2801 sub scan_texinfo_file
2803     my ($filename) = @_;
2805     # These are always created, no matter whether indexes are used or not.
2806     my @clean_suffixes = ('aux', 'dvi', 'log', 'ps', 'toc',
2807                           # grep new.*index texinfo.tex
2808                           'cp', 'fn', 'ky', 'vr', 'tp', 'pg');
2810     # There are predefined indexes which don't follow the regular rules.
2811     my %predefined_index =
2812       (
2813        # cindex => *.cps
2814        'c' => 'cps', 'f' => 'fns', 'k' => 'kys',
2815        'v' => 'vrs', 't' => 'tps', 'p' => 'pgs'
2816       );
2818     # There are commands which include a hidden index command.
2819     my %hidden_index =
2820       (
2821        # deffn => *.fns.
2822        'fn' => 'fns',     'un' => 'fns',
2823        'typefn' => 'fns', 'typefun' => 'fns',
2824        'mac' => 'fns', 'spec' => 'fns',
2825        'op' => 'fns',  'typeop' => 'fns',
2826        'method' => 'fns', 'typemethod' => 'fns',
2828        'vr' => 'vrs', 'var' => 'vrs',
2829        'typevr' => 'vrs', 'typevar' => 'vrs',
2830        'opt' => 'vrs',
2831        'cv' => 'vrs',
2832        'ivar' => 'vrs', 'typeivar' => 'vrs',
2834        'tp' => 'tps'
2835       );
2837     # Indexes stored into another one.  In this case, the *.??s file
2838     # is not created.
2839     my @syncodeindexes = ();
2841     my $texi = new IO::File ("< $filename");
2842     if (! $texi)
2843       {
2844         &am_error ("couldn't open `$filename': $!");
2845         return '';
2846     }
2847     print "$me: reading $filename\n" if $verbose;
2849     my ($outfile, $vfile);
2850     while ($_ = $texi->getline)
2851     {
2852       if (/^\@setfilename +(\S+)/)
2853       {
2854         $outfile = $1;
2855         if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
2856           {
2857             &am_file_error ($filename, "$.: ",
2858                             "output `$outfile' has unrecognized extension");
2859             return;
2860           }
2861       }
2862       # A "version.texi" file is actually any file whose name
2863       # matches "vers*.texi".
2864       elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2865       {
2866         $vfile = $1;
2867       }
2869       # Try to find what are the indexes which are used.
2871       # Creating a new category of index.
2872       elsif (/^\@def(code)?index (\w+)/)
2873       {
2874         push @clean_suffixes, $2;
2875       }
2877       # Storing in a predefined index.
2878       elsif (/^\@([cfkvtp])index /)
2879       {
2880         push @clean_suffixes, $predefined_index{$1};
2881       }
2882       elsif (/^\@def(\w+) /)
2883       {
2884         push @clean_suffixes, $hidden_index{$1}
2885           if defined $hidden_index{$1};
2886       }
2888       # Merging an index into an another.
2889       elsif (/^\@syn(code)?index (\w+) (\w+)/)
2890       {
2891         push @syncodeindexes, "$2s";
2892         push @clean_suffixes, "$3s";
2893       }
2895     }
2896     $texi->close;
2898     if ($outfile eq '')
2899       {
2900         &am_error ("`$filename' missing \@setfilename");
2901         return;
2902       }
2904     my $infobase = basename ($filename);
2905     $infobase =~ s/\.te?xi(nfo)?$//;
2906     # FIXME: I don't understand why, but I can't use "$infobase.$_" => 1.
2907     my %clean_files = map { "$infobase" . ".$_" => 1 } @clean_suffixes;
2908     grep { delete $clean_files{"$infobase.$_"} } @syncodeindexes;
2909     return ($outfile, $vfile, (sort keys %clean_files));
2913 # ($DO-SOMETHING, $TEXICLEANS)
2914 # handle_texinfo_helper ()
2915 # -----------------
2916 # Handle all Texinfo source; helper for handle_texinfo
2917 sub handle_texinfo_helper
2919     &am_line_error ('TEXINFOS',
2920                     "`TEXINFOS' is an anachronism; use `info_TEXINFOS'")
2921         if &variable_defined ('TEXINFOS');
2922     return (0, '') if (! &variable_defined ('info_TEXINFOS')
2923                        && ! &variable_defined ('html_TEXINFOS'));
2925     if (&variable_defined ('html_TEXINFOS'))
2926     {
2927         &am_line_error ('html_TEXINFOS',
2928                         "HTML generation not yet supported");
2929         return (0, '');
2930     }
2932     my @texis = &variable_value_as_list ('info_TEXINFOS', 'all');
2934     my (@info_deps_list, @dvis_list, @texi_deps);
2935     my %versions;
2936     my $done = 0;
2937     my @texi_cleans;
2938     my $canonical;
2940     my %texi_suffixes;
2941     foreach my $info_cursor (@texis)
2942     {
2943         my $infobase = $info_cursor;
2944         $infobase =~ s/\.(txi|texinfo|texi)$//;
2946         if ($infobase eq $info_cursor)
2947         {
2948             # FIXME: report line number.
2949             &am_error ("texinfo file `$info_cursor' has unrecognized extension");
2950             next;
2951         }
2952         $texi_suffixes{$1} = 1;
2954         # If 'version.texi' is referenced by input file, then include
2955         # automatic versioning capability.
2956         my ($out_file, $vtexi, @clean_files) =
2957           &scan_texinfo_file ("$relative_dir/$info_cursor")
2958             or next;
2959         push (@texi_cleans, @clean_files);
2961         if ($vtexi)
2962         {
2963             &am_error ("`$vtexi', included in `$info_cursor', also included in `$versions{$vtexi}'")
2964                 if (defined $versions{$vtexi});
2965             $versions{$vtexi} = $info_cursor;
2967             # We number the stamp-vti files.  This is doable since the
2968             # actual names don't matter much.  We only number starting
2969             # with the second one, so that the common case looks nice.
2970             my $vti = ($done ? $done : 'vti');
2971             ++$done;
2973             # This is ugly, but it is our historical practice.
2974             if ($config_aux_dir_set_in_configure_in)
2975             {
2976                 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2977                                               'mdate-sh');
2978             }
2979             else
2980             {
2981                 &require_file_with_line ('info_TEXINFOS', $FOREIGN,
2982                                          'mdate-sh');
2983             }
2985             my $conf_dir;
2986             if ($config_aux_dir_set_in_configure_in)
2987             {
2988                 $conf_dir = $config_aux_dir;
2989                 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
2990             }
2991             else
2992             {
2993                 $conf_dir = '$(srcdir)/';
2994             }
2995             $output_rules .= &file_contents ('texi-vers',
2996                                              ('TEXI'  => $info_cursor,
2997                                               'VTI'   => $vti,
2998                                               'VTEXI' => $vtexi,
2999                                               'MDDIR' => $conf_dir));
3000         }
3002         # If user specified file_TEXINFOS, then use that as explicit
3003         # dependency list.
3004         @texi_deps = ();
3005         push (@texi_deps, $info_cursor);
3006         # Prefix with $(srcdir) because some version of make won't
3007         # work if the target has it and the dependency doesn't.
3008         push (@texi_deps, '$(srcdir)/' . $vtexi) if $vtexi;
3010         my $canonical = &canonicalize ($infobase);
3011         if (&variable_defined ($canonical . "_TEXINFOS"))
3012         {
3013             push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
3014             &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
3015         }
3017         $output_rules .= ("\n" . $out_file . ": "
3018                           . join (' ', @texi_deps)
3019                           . "\n" . $infobase . ".dvi: "
3020                           . join (' ', @texi_deps)
3021                           . "\n");
3023         push (@info_deps_list, $out_file);
3024         push (@dvis_list, $infobase . '.dvi');
3025     }
3027     # Handle location of texinfo.tex.
3028     my $need_texi_file = 0;
3029     my $texinfodir;
3030     if ($cygnus_mode)
3031     {
3032         $texinfodir = '$(top_srcdir)/../texinfo';
3033         &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3034     }
3035     elsif ($config_aux_dir_set_in_configure_in)
3036     {
3037         $texinfodir = $config_aux_dir;
3038         &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3039         $need_texi_file = 2; # so that we require_conf_file later
3040     }
3041     elsif (&variable_defined ('TEXINFO_TEX'))
3042     {
3043         # The user defined TEXINFO_TEX so assume he knows what he is
3044         # doing.
3045         $texinfodir = ('$(srcdir)/'
3046                        . dirname (&variable_value ('TEXINFO_TEX')));
3047     }
3048     else
3049     {
3050         $texinfodir = '$(srcdir)';
3051         $need_texi_file = 1;
3052     }
3054     foreach my $txsfx (sort keys %texi_suffixes)
3055     {
3056         $output_rules .= &file_contents ('texibuild',
3057                                          ('TEXINFODIR' => $texinfodir,
3058                                           'SUFFIX'     => $txsfx));
3059     }
3061     # The return value.
3062     my $texiclean = &pretty_print_internal ("", "\t  ", @texi_cleans);
3064     push (@dist_targets, 'dist-info');
3066     if (! defined $options{'no-installinfo'})
3067     {
3068         # Make sure documentation is made and installed first.  Use
3069         # $(INFO_DEPS), not 'info', because otherwise recursive makes
3070         # get run twice during "make all".
3071         unshift (@all, '$(INFO_DEPS)');
3072     }
3074     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
3075     &define_variable ("DVIS", join (' ', @dvis_list));
3076     # This next isn't strictly needed now -- the places that look here
3077     # could easily be changed to look in info_TEXINFOS.  But this is
3078     # probably better, in case noinst_TEXINFOS is ever supported.
3079     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
3081     # Do some error checking.  Note that this file is not required
3082     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3083     # up above.
3084     if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
3085     {
3086         if ($need_texi_file > 1)
3087         {
3088             &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
3089                                           'texinfo.tex');
3090         }
3091         else
3092         {
3093             &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
3094         }
3095     }
3097     return (1, $texiclean);
3100 # handle_texinfo ()
3101 # -----------------
3102 # Handle all Texinfo source.
3103 sub handle_texinfo
3105     my ($do_something, $texiclean) = handle_texinfo_helper ();
3106     $output_rules .=  &file_contents ('texinfos',
3107                                       ('TEXICLEAN' => $texiclean,
3108                                        'LOCAL-TEXIS' => $do_something));
3111 # Handle any man pages.
3112 sub handle_man_pages
3114     &am_line_error ('MANS', "`MANS' is an anachronism; use `man_MANS'")
3115         if &variable_defined ('MANS');
3117     # Find all the sections in use.  We do this by first looking for
3118     # "standard" sections, and then looking for any additional
3119     # sections used in man_MANS.
3120     my (%sections, %vlist);
3121     # We handle nodist_ for uniformity.  man pages aren't distributed
3122     # by default so it isn't actually very important.
3123     foreach my $pfx ('', 'dist_', 'nodist_')
3124     {
3125         # Add more sections as needed.
3126         foreach my $section ('0'..'9', 'n', 'l')
3127         {
3128             if (&variable_defined ($pfx . 'man' . $section . '_MANS'))
3129             {
3130                 $sections{$section} = 1;
3131                 $vlist{'$(' . $pfx . 'man' . $section . '_MANS)'} = 1;
3133                 &push_dist_common ('$(' . $pfx . 'man' . $section . '_MANS)')
3134                     if $pfx eq 'dist_';
3135             }
3136         }
3138         if (&variable_defined ($pfx . 'man_MANS'))
3139         {
3140             $vlist{'$(' . $pfx . 'man_MANS)'} = 1;
3141             foreach (&variable_value_as_list ($pfx . 'man_MANS', 'all'))
3142             {
3143                 # A page like `foo.1c' goes into man1dir.
3144                 if (/\.([0-9a-z])([a-z]*)$/)
3145                 {
3146                     $sections{$1} = 1;
3147                 }
3148             }
3150             &push_dist_common ('$(' . $pfx . 'man_MANS)')
3151                 if $pfx eq 'dist_';
3152         }
3153     }
3155     return unless %sections;
3157     # Now for each section, generate an install and unintall rule.
3158     # Sort sections so output is deterministic.
3159     foreach my $section (sort keys %sections)
3160     {
3161         $output_rules .= &file_contents ('mans', ('SECTION' => $section));
3162     }
3164     $output_vars .= &file_contents ('mans-vars',
3165                                     ('MANS' => join (' ', sort keys %vlist)));
3167     if (! defined $options{'no-installman'})
3168     {
3169         push (@all, '$(MANS)');
3170     }
3173 # Handle DATA variables.
3174 sub handle_data
3176     &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3177                      'data', 'sysconf', 'sharedstate', 'localstate',
3178                      'pkgdata', 'noinst', 'check');
3181 # Handle TAGS.
3182 sub handle_tags
3184     my @tag_deps = ();
3185     if (&variable_defined ('SUBDIRS'))
3186     {
3187         $output_rules .= ("tags-recursive:\n"
3188                           . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3189                           # Never fail here if a subdir fails; it
3190                           # isn't important.
3191                           . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
3192                           . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3193                           . "\tdone\n");
3194         push (@tag_deps, 'tags-recursive');
3195         &depend ('.PHONY', 'tags-recursive');
3196     }
3198     if (&saw_sources_p (1)
3199         || &variable_defined ('ETAGS_ARGS')
3200         || @tag_deps)
3201     {
3202         my $config = '';
3203         foreach my $one_hdr (@config_headers)
3204         {
3205             if ($relative_dir eq dirname ($one_hdr))
3206             {
3207                 # The config header is in this directory.  So require it.
3208                 $config .= ' ' if $config;
3209                 $config .= basename ($one_hdr);
3210             }
3211         }
3212         $output_rules .= &file_contents ('tags',
3213                                          ('CONFIG' => $config,
3214                                           'DIRS'   => join (' ', @tag_deps)));
3215         &examine_variable ('TAGS_DEPENDENCIES');
3216     }
3217     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
3218     {
3219         &am_line_error ('TAGS_DEPENDENCIES',
3220                         "doesn't make sense to define `TAGS_DEPENDENCIES' without sources or `ETAGS_ARGS'");
3221     }
3222     else
3223     {
3224         # Every Makefile must define some sort of TAGS rule.
3225         # Otherwise, it would be possible for a top-level "make TAGS"
3226         # to fail because some subdirectory failed.
3227         $output_rules .= "tags: TAGS\nTAGS:\n\n";
3228     }
3231 # Handle multilib support.
3232 sub handle_multilib
3234     if ($seen_multilib && $relative_dir eq '.')
3235     {
3236         $output_rules .= &file_contents ('multilib');
3237     }
3241 # $BOOLEAN
3242 # &for_dist_common ($A, $B)
3243 # -------------------------
3244 # Subroutine for &handle_dist: sort files to dist.
3246 # We put README first because it then becomes easier to make a
3247 # Usenet-compliant shar file (in these, README must be first).
3249 # FIXME: do more ordering of files here.
3250 sub for_dist_common
3252     return 0
3253         if $a eq $b;
3254     return -1
3255         if $a eq 'README';
3256     return 1
3257         if $b eq 'README';
3258     return $a cmp $b;
3262 # handle_dist ($MAKEFILE)
3263 # -----------------------
3264 # Handle 'dist' target.
3265 sub handle_dist
3267     my ($makefile) = @_;
3269     # `make dist' isn't used in a Cygnus-style tree.
3270     # Omit the rules so that people don't try to use them.
3271     return if $cygnus_mode;
3273     # Look for common files that should be included in distribution.
3274     # If the aux dir is set, and it does not have a Makefile.am, then
3275     # we check for these files there as well.
3276     my $check_aux = 0;
3277     my $auxdir = '';
3278     if ($relative_dir eq '.'
3279         && $config_aux_dir_set_in_configure_in)
3280     {
3281         ($auxdir = $config_aux_dir) =~ s,^\$\(top_srcdir\)/,,;
3282         if (! &is_make_dir ($auxdir))
3283         {
3284             $check_aux = 1;
3285         }
3286     }
3287     foreach my $cfile (@common_files)
3288     {
3289         if (-f ($relative_dir . "/" . $cfile))
3290         {
3291             &push_dist_common ($cfile);
3292         }
3294         # Don't use `elsif' here because a file might meaningfully
3295         # appear in both directories.
3296         if ($check_aux && -f ($auxdir . '/' . $cfile))
3297         {
3298             &push_dist_common ($auxdir . '/' . $cfile);
3299         }
3300     }
3302     # We might copy elements from $configure_dist_common to
3303     # %dist_common if we think we need to.  If the file appears in our
3304     # directory, we would have discovered it already, so we don't
3305     # check that.  But if the file is in a subdir without a Makefile,
3306     # we want to distribute it here if we are doing `.'.  Ugly!
3307     if ($relative_dir eq '.')
3308     {
3309        foreach my $file (split (' ' , $configure_dist_common))
3310        {
3311            if (! &is_make_dir (dirname ($file)))
3312            {
3313                &push_dist_common ($file);
3314            }
3315        }
3316     }
3320     # Files to distributed.  Don't use &variable_value_as_list
3321     # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3322     check_variable_defined_unconditionally ('DIST_COMMON');
3323     my @dist_common = split (' ', variable_value ('DIST_COMMON', 'TRUE'));
3324     @dist_common = uniq (sort for_dist_common (@dist_common));
3325     pretty_print ('DIST_COMMON = ', "\t", @dist_common);
3327     # Now that we've processed DIST_COMMON, disallow further attempts
3328     # to set it.
3329     $handle_dist_run = 1;
3331     # Scan EXTRA_DIST to see if we need to distribute anything from a
3332     # subdir.  If so, add it to the list.  I didn't want to do this
3333     # originally, but there were so many requests that I finally
3334     # relented.
3335     if (&variable_defined ('EXTRA_DIST'))
3336     {
3337         # FIXME: This should be fixed to work with conditionals.  That
3338         # will require only making the entries in %dist_dirs under the
3339         # appropriate condition.  This is meaningful if the nature of
3340         # the distribution should depend upon the configure options
3341         # used.
3342         foreach (&variable_value_as_list ('EXTRA_DIST', ''))
3343         {
3344             next if /^\@.*\@$/;
3345             next unless s,/+[^/]+$,,;
3346             $dist_dirs{$_} = 1
3347                 unless $_ eq '.';
3348         }
3349     }
3351     # We have to check DIST_COMMON for extra directories in case the
3352     # user put a source used in AC_OUTPUT into a subdir.
3353     foreach (&variable_value_as_list ('DIST_COMMON', 'all'))
3354     {
3355         next if /^\@.*\@$/;
3356         next unless s,/+[^/]+$,,;
3357         $dist_dirs{$_} = 1
3358             unless $_ eq '.';
3359     }
3361     # Rule to check whether a distribution is viable.
3362     my %transform = ('DISTCHECK-HOOK' => &target_defined ('distcheck-hook'),
3363                      'GETTEXT'        => $seen_gettext);
3365     # Prepend $(distdir) to each directory given.
3366     my %rewritten = map { '$(distdir)/' . "$_" => 1 } keys %dist_dirs;
3367     $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);
3369     # If we have SUBDIRS, create all dist subdirectories and do
3370     # recursive build.
3371     if (&variable_defined ('SUBDIRS'))
3372     {
3373         # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3374         # to all possible directories, and use it.  If DIST_SUBDIRS is
3375         # defined, just use it.
3376         my $dist_subdir_name;
3377         # Note that we check DIST_SUBDIRS first on purpose.  At least
3378         # one project uses so many conditional subdirectories that
3379         # calling variable_conditionally_defined on SUBDIRS will cause
3380         # automake to grow to 150Mb.  Sigh.
3381         if (&variable_defined ('DIST_SUBDIRS')
3382             || variable_conditionally_defined ('SUBDIRS'))
3383         {
3384             $dist_subdir_name = 'DIST_SUBDIRS';
3385             if (! &variable_defined ('DIST_SUBDIRS'))
3386             {
3387                 &define_pretty_variable
3388                   ('DIST_SUBDIRS', '',
3389                    uniq (&variable_value_as_list ('SUBDIRS', 'all')));
3390             }
3391         }
3392         else
3393         {
3394             $dist_subdir_name = 'SUBDIRS';
3395             # We always define this because that is what `distclean'
3396             # wants.
3397             &define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
3398         }
3400         $transform{'DIST_SUBDIR_NAME'} = $dist_subdir_name;
3401     }
3403     # If the target `dist-hook' exists, make sure it is run.  This
3404     # allows users to do random weird things to the distribution
3405     # before it is packaged up.
3406     push (@dist_targets, 'dist-hook')
3407       if &target_defined ('dist-hook');
3408     $transform{'DIST-TARGETS'} = join(' ', @dist_targets);
3410     # Defining $(DISTDIR).
3411     $transform{'DISTDIR'} = !&variable_defined('distdir');
3412     $transform{'TOP_DISTDIR'} = backname ($relative_dir);
3414     $output_rules .= &file_contents ('distdir', %transform);
3418 # Handle subdirectories.
3419 sub handle_subdirs
3421     return
3422       unless &variable_defined ('SUBDIRS');
3424     # Make sure each directory mentioned in SUBDIRS actually exists.
3425     foreach my $dir (&variable_value_as_list ('SUBDIRS', 'all'))
3426     {
3427         # Skip directories substituted by configure.
3428         next if $dir =~ /^\@.*\@$/;
3430         if (! -d $am_relative_dir . '/' . $dir)
3431         {
3432             &am_line_error ('SUBDIRS',
3433                             "required directory $am_relative_dir/$dir does not exist");
3434             next;
3435         }
3437         &am_line_error ('SUBDIRS', "directory should not contain `/'")
3438             if $dir =~ /\//;
3439     }
3441     $output_rules .= &file_contents ('subdirs');
3442     variable_pretty_output ('RECURSIVE_TARGETS', 'TRUE');
3446 # ($REGEN, @DEPENDENCIES)
3447 # &scan_aclocal_m4
3448 # ----------------
3449 # If aclocal.m4 creation is automated, return the list of its dependencies.
3450 sub scan_aclocal_m4
3452     my $regen_aclocal = 0;
3454     return (0, ())
3455       unless $relative_dir eq '.';
3457     &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3458     &examine_variable ('CONFIGURE_DEPENDENCIES');
3460     if (-f 'aclocal.m4')
3461     {
3462         &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3463         &push_dist_common ('aclocal.m4');
3465         my $aclocal = new IO::File ("< aclocal.m4");
3466         if ($aclocal)
3467         {
3468             my $line = $aclocal->getline;
3469             $aclocal->close;
3471             if ($line =~ 'generated automatically by aclocal')
3472             {
3473                 $regen_aclocal = 1;
3474             }
3475         }
3476     }
3478     my @ac_deps = ();
3480     if (-f 'acinclude.m4')
3481     {
3482         $regen_aclocal = 1;
3483         push @ac_deps, 'acinclude.m4';
3484     }
3486     if (&variable_defined ('ACLOCAL_M4_SOURCES'))
3487     {
3488         push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3489     }
3490     elsif (&variable_defined ('ACLOCAL_AMFLAGS'))
3491     {
3492         # Scan all -I directories for m4 files.  These are our
3493         # dependencies.
3494         my $examine_next = 0;
3495         foreach my $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
3496         {
3497             if ($examine_next)
3498             {
3499                 $examine_next = 0;
3500                 if ($amdir !~ /^\// && -d $amdir)
3501                 {
3502                     foreach my $ac_dep (&my_glob ($amdir . '/*.m4'))
3503                     {
3504                         $ac_dep =~ s/^\.\/+//;
3505                         push (@ac_deps, $ac_dep)
3506                           unless $ac_dep eq "aclocal.m4"
3507                             || $ac_dep eq "acinclude.m4";
3508                     }
3509                 }
3510             }
3511             elsif ($amdir eq '-I')
3512             {
3513                 $examine_next = 1;
3514             }
3515         }
3516     }
3518     # Note that it might be possible that aclocal.m4 doesn't exist but
3519     # should be auto-generated.  This case probably isn't very
3520     # important.
3522     return ($regen_aclocal, @ac_deps);
3525 # Rewrite a list of input files into a form suitable to put on a
3526 # dependency list.  The idea is that if an input file has a directory
3527 # part the same as the current directory, then the directory part is
3528 # simply removed.  But if the directory part is different, then
3529 # $(top_srcdir) is prepended.  Among other things, this is used to
3530 # generate the dependency list for the output files generated by
3531 # AC_OUTPUT.  Consider what the dependencies should look like in this
3532 # case:
3533 #   AC_OUTPUT(src/out:src/in1:lib/in2)
3534 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3535 # If 0 then files that require this addition will simply be ignored.
3536 sub rewrite_inputs_into_dependencies
3538     my ($add_srcdir, @inputs) = @_;
3539     my @newinputs;
3541     foreach my $single (@inputs)
3542     {
3543         if (dirname ($single) eq $relative_dir)
3544         {
3545             push (@newinputs, basename ($single));
3546         }
3547         elsif ($add_srcdir)
3548         {
3549             push (@newinputs, '$(top_srcdir)/' . $single);
3550         }
3551     }
3553     return @newinputs;
3556 # Handle remaking and configure stuff.
3557 # We need the name of the input file, to do proper remaking rules.
3558 sub handle_configure
3560     my ($local, $input, @secondary_inputs) = @_;
3562     my $input_base = basename ($input);
3563     my $local_base = basename ($local);
3565     my $amfile = $input_base . '.am';
3566     # We know we can always add '.in' because it really should be an
3567     # error if the .in was missing originally.
3568     my $infile = '$(srcdir)/' . $input_base . '.in';
3569     my $colon_infile = '';
3570     if ($local ne $input || @secondary_inputs)
3571     {
3572         $colon_infile = ':' . $input . '.in';
3573     }
3574     $colon_infile .= ':' . join (':', @secondary_inputs)
3575         if @secondary_inputs;
3577     my @rewritten = &rewrite_inputs_into_dependencies (1, @secondary_inputs);
3579     my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4 ();
3581     $output_rules .=
3582       &file_contents ('configure',
3583                       ('MAKEFILE'
3584                        => $local_base,
3585                        'MAKEFILE-DEPS'
3586                        => join (' ', @rewritten),
3587                        'CONFIG-MAKEFILE'
3588                        => ((($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3589                            . $colon_infile),
3590                        'MAKEFILE-IN'
3591                        => $infile,
3592                        'MAKEFILE-IN-DEPS'
3593                        => join (' ', @include_stack),
3594                        'MAKEFILE-AM'
3595                        => $amfile,
3596                        'STRICTNESS'
3597                        => $cygnus_mode ? 'cygnus' : $strictness_name,
3598                        'USE-DEPS'
3599                        => $cmdline_use_dependencies ? '' : ' --ignore-deps',
3600                        'MAKEFILE-AM-SOURCES'
3601                        =>  "$input$colon_infile",
3602                        'REGEN-ACLOCAL-M4'
3603                        => $regen_aclocal_m4,
3604                        'ACLOCAL_M4_DEPS'
3605                        => join (' ', @aclocal_m4_deps)));
3607     if ($relative_dir eq '.')
3608     {
3609         &push_dist_common ('acconfig.h')
3610             if -f 'acconfig.h';
3611     }
3613     # If we have a configure header, require it.
3614     my @local_fullnames = @config_fullnames;
3615     my @local_names = @config_names;
3616     my $hdr_index = 0;
3617     my $distclean_config = '';
3618     foreach my $one_hdr (@config_headers)
3619     {
3620         my $one_fullname = shift (@local_fullnames);
3621         my $one_name = shift (@local_names);
3622         $hdr_index += 1;
3623         my $header_dir = dirname ($one_name);
3625         # If the header is in the current directory we want to build
3626         # the header here.  Otherwise, if we're at the topmost
3627         # directory and the header's directory doesn't have a
3628         # Makefile, then we also want to build the header.
3629         if ($relative_dir eq $header_dir
3630             || ($relative_dir eq '.' && ! &is_make_dir ($header_dir)))
3631         {
3632             my ($cn_sans_dir, $stamp_dir);
3633             if ($relative_dir eq $header_dir)
3634             {
3635                 $cn_sans_dir = basename ($one_name);
3636                 $stamp_dir = '';
3637             }
3638             else
3639             {
3640                 $cn_sans_dir = $one_name;
3641                 if ($header_dir eq '.')
3642                 {
3643                     $stamp_dir = '';
3644                 }
3645                 else
3646                 {
3647                     $stamp_dir = $header_dir . '/';
3648                 }
3649             }
3651             # Compute relative path from directory holding output
3652             # header to directory holding input header.  FIXME:
3653             # doesn't handle case where we have multiple inputs.
3654             my $ch_sans_dir;
3655             if (dirname ($one_hdr) eq $relative_dir)
3656             {
3657                 $ch_sans_dir = basename ($one_hdr);
3658             }
3659             else
3660             {
3661                 $ch_sans_dir = backname ($relative_dir) . '/' . $one_hdr;
3662             }
3664             &require_file_with_conf_line ($config_header_line,
3665                                           $FOREIGN, $ch_sans_dir);
3667             # Header defined and in this directory.
3668             my @files;
3669             if (-f $one_name . '.top')
3670             {
3671                 push (@files, "${cn_sans_dir}.top");
3672             }
3673             if (-f $one_name . '.bot')
3674             {
3675                 push (@files, "${cn_sans_dir}.bot");
3676             }
3678             &push_dist_common (@files);
3680             # For now, acconfig.h can only appear in the top srcdir.
3681             if (-f 'acconfig.h')
3682             {
3683                 push (@files, '$(top_srcdir)/acconfig.h');
3684             }
3686             my $stamp_name = 'stamp-h';
3687             $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3689             my $out_dir = dirname ($ch_sans_dir);
3691             $output_rules .=
3692               &file_contents ('remake-hdr',
3693                               ('FILES'              => join (' ', @files),
3694                                'CONFIG_HEADER'      => $cn_sans_dir,
3695                                'CONFIG_HEADER_IN'   => $ch_sans_dir,
3696                                'CONFIG_HEADER_FULL' => $one_fullname,
3697                                'STAMP'            => "$stamp_dir$stamp_name",
3698                                'SRC_STAMP'        => "$out_dir/$stamp_name"));
3700             &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3701             &require_file_with_conf_line ($config_header_line, $FOREIGN,
3702                                           "${out_dir}/${stamp_name}.in");
3704             $distclean_config .= ' ' if $distclean_config;
3705             $distclean_config .= $cn_sans_dir;
3706         }
3707     }
3709     if ($distclean_config)
3710     {
3711         $output_rules .= &file_contents ('clean-hdr',
3712                                          ('FILES' => $distclean_config));
3713     }
3715     # Set location of mkinstalldirs.
3716     &define_variable ('mkinstalldirs',
3717                       ('$(SHELL) ' . $config_aux_dir . '/mkinstalldirs'));
3719     &am_line_error ('CONFIG_HEADER',
3720                     "`CONFIG_HEADER' is an anachronism; now determined from `$configure_ac'")
3721         if &variable_defined ('CONFIG_HEADER');
3723     my $config_header = '';
3724     foreach my $one_name (@config_names)
3725     {
3726         # Generate CONFIG_HEADER define.
3727         my $one_hdr;
3728         if ($relative_dir eq dirname ($one_name))
3729         {
3730             $one_hdr = basename ($one_name);
3731         }
3732         else
3733         {
3734             $one_hdr = "\$(top_builddir)/${one_name}";
3735         }
3737         $config_header .= ' ' if $config_header;
3738         $config_header .= $one_hdr;
3739     }
3740     if ($config_header)
3741     {
3742         &define_variable ("CONFIG_HEADER", $config_header);
3743     }
3745     # Now look for other files in this directory which must be remade
3746     # by config.status, and generate rules for them.
3747     my @actual_other_files = ();
3748     foreach my $lfile (@other_input_files)
3749     {
3750         my ($file, $local);
3751         my (@inputs, @rewritten_inputs);
3752         my ($need_rewritten);
3753         if ($lfile =~ /^([^:]*):(.*)$/)
3754         {
3755             # This is the ":" syntax of AC_OUTPUT.
3756             $file = $1;
3757             $local = basename ($file);
3758             @inputs = split (':', $2);
3759             @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3760             $need_rewritten = 1;
3761         }
3762         else
3763         {
3764             # Normal usage.
3765             $file = $lfile;
3766             $local = basename ($file);
3767             @inputs = ($file . '.in');
3768             @rewritten_inputs =
3769                 &rewrite_inputs_into_dependencies (1, @inputs);
3770             $need_rewritten = 0;
3771         }
3773         # Make sure the dist directory for each input file is created.
3774         # We only have to do this at the topmost level though.  This
3775         # is a bit ugly but it easier than spreading out the logic,
3776         # especially in cases like AC_OUTPUT(foo/out:bar/in), where
3777         # there is no Makefile in bar/.
3778         if ($relative_dir eq '.')
3779         {
3780             foreach (@inputs)
3781             {
3782                 $dist_dirs{dirname ($_)} = 1;
3783             }
3784         }
3786         # We skip any automake input files, as they are handled
3787         # elsewhere.  We also skip files that aren't in this
3788         # directory.  However, if the file's directory does not have a
3789         # Makefile, and we are currently doing `.', then we create a
3790         # rule to rebuild the file in the subdir.
3791         next if -f $file . '.am';
3792         my $fd = dirname ($file);
3793         if ($fd ne $relative_dir)
3794         {
3795             if ($relative_dir eq '.' && ! &is_make_dir ($fd))
3796             {
3797                 $local = $file;
3798             }
3799             else
3800             {
3801                 next;
3802             }
3803         }
3805         # Some users have been tempted to put `stamp-h' in the
3806         # AC_OUTPUT line.  This won't do the right thing, so we
3807         # explicitly fail here.
3808         if ($local eq 'stamp-h')
3809         {
3810             # FIXME: allow real filename.
3811             &am_conf_error ($configure_ac, $ac_output_line,
3812                             'stamp-h should not appear in AC_OUTPUT');
3813             next;
3814         }
3816         $output_rules .= ($local . ': '
3817                           . '$(top_builddir)/config.status '
3818                           . join (' ', @rewritten_inputs) . "\n"
3819                           . "\t"
3820                           . 'cd $(top_builddir) && CONFIG_FILES='
3821                           . ($relative_dir eq '.' ? '' : '$(subdir)/')
3822                           . '$@' . ($need_rewritten
3823                                     ? (':' . join (':', @inputs))
3824                                     : '')
3825                           . ' CONFIG_HEADERS= CONFIG_LINKS= $(SHELL) ./config.status'
3826                           . "\n");
3827         push (@actual_other_files, $local);
3829         # Require all input files.
3830         &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3831                                       &rewrite_inputs_into_dependencies (0, @inputs));
3832     }
3834     # These files get removed by "make clean".
3835     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3838 # Handle C headers.
3839 sub handle_headers
3841     my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3842                              'oldinclude', 'pkginclude',
3843                              'noinst', 'check');
3844     foreach (@r)
3845     {
3846         next unless /\.(.*)$/;
3847         &saw_extension ($1);
3848     }
3851 sub handle_gettext
3853     return if ! $seen_gettext || $relative_dir ne '.';
3855     if (! &variable_defined ('SUBDIRS'))
3856     {
3857         &am_conf_error
3858             ("AM_GNU_GETTEXT used but SUBDIRS not defined");
3859         return;
3860     }
3862     my @subdirs = &variable_value_as_list ('SUBDIRS', 'all');
3863     &am_line_error ('SUBDIRS',
3864                     "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
3865         if ! grep ('po', @subdirs);
3866     &am_line_error ('SUBDIRS',
3867                     "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
3868         if ! grep ('intl', @subdirs);
3870     &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3872     # Ensure that each language in ALL_LINGUAS has a .po file, and
3873     # each po file is mentioned in ALL_LINGUAS.
3874     if ($seen_linguas)
3875     {
3876         my %linguas = map { $_ => 1 } split (' ', $all_linguas);
3878         foreach (<po/*.po>)
3879         {
3880             s/^po\///;
3881             s/\.po$//;
3883             &am_line_error ($all_linguas_line,
3884                             ("po/$_.po exists but `$_' not in `ALL_LINGUAS'"))
3885                 if ! $linguas{$_};
3886         }
3888         foreach (keys %linguas)
3889         {
3890             &am_line_error ($all_linguas_line,
3891                             "$_ in `ALL_LINGUAS' but po/$_.po does not exist")
3892                 if ! -f "po/$_.po";
3893         }
3894     }
3895     else
3896     {
3897         &am_error ("AM_GNU_GETTEXT in `$configure_ac' but `ALL_LINGUAS' not defined");
3898     }
3901 # Handle footer elements.
3902 sub handle_footer
3904     # NOTE don't use define_pretty_variable here, because
3905     # $contents{...} is already defined.
3906     $output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n\n"
3907       if variable_value ('SOURCES');
3910     &am_line_error ('.SUFFIXES',
3911                     "use variable `SUFFIXES', not target `.SUFFIXES'")
3912       if target_defined ('.SUFFIXES');
3914     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3915     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
3916     # anything else, by sticking it right after the default: target.
3917     $output_header .= ".SUFFIXES:\n";
3918     if (@suffixes || &variable_defined ('SUFFIXES'))
3919     {
3920         # Make sure suffixes has unique elements.  Sort them to ensure
3921         # the output remains consistent.  However, $(SUFFIXES) is
3922         # always at the start of the list, unsorted.  This is done
3923         # because make will choose rules depending on the ordering of
3924         # suffixes, and this lets the user have some control.  Push
3925         # actual suffixes, and not $(SUFFIXES).  Some versions of make
3926         # do not like variable substitutions on the .SUFFIXES line.
3927         my @user_suffixes = (&variable_defined ('SUFFIXES')
3928                              ? &variable_value_as_list ('SUFFIXES', '')
3929                              : ());
3931         my %suffixes = map { $_ => 1 } @suffixes;
3932         delete @suffixes{@user_suffixes};
3934         $output_header .= (".SUFFIXES: "
3935                            . join (' ', @user_suffixes, sort keys %suffixes)
3936                            . "\n");
3937     }
3939     $output_trailer .= file_contents ('footer');
3942 # Deal with installdirs target.
3943 sub handle_installdirs ()
3945     $output_rules .=
3946       &file_contents ('install',
3947                       ('_am_installdirs'
3948                        => variable_value ('_am_installdirs') || ''));
3952 # Deal with all and all-am.
3953 sub handle_all ($)
3955     my ($makefile) = @_;
3957     # Output `all-am'.
3959     # Put this at the beginning for the sake of non-GNU makes.  This
3960     # is still wrong if these makes can run parallel jobs.  But it is
3961     # right enough.
3962     unshift (@all, basename ($makefile));
3964     foreach my $one_name (@config_names)
3965     {
3966         push (@all, basename ($one_name))
3967             if dirname ($one_name) eq $relative_dir;
3968     }
3970     # Install `all' hooks.
3971     if (&target_defined ("all-local"))
3972     {
3973       push (@all, "all-local");
3974       &depend ('.PHONY', "all-local");
3975     }
3977     &pretty_print_rule ("all-am:", "\t\t", @all);
3978     &depend ('.PHONY', 'all-am', 'all');
3981     # Output `all'.
3983     my @local_headers = ();
3984     push @local_headers, '$(BUILT_SOURCES)'
3985       if &variable_defined ('BUILT_SOURCES');
3986     foreach my $one_name (@config_names)
3987       {
3988         push @local_headers, basename ($one_name)
3989           if dirname ($one_name) eq $relative_dir;
3990       }
3992     if (@local_headers)
3993       {
3994         # We need to make sure config.h is built before we recurse.
3995         # We also want to make sure that built sources are built
3996         # before any ordinary `all' targets are run.  We can't do this
3997         # by changing the order of dependencies to the "all" because
3998         # that breaks when using parallel makes.  Instead we handle
3999         # things explicitly.
4000         $output_all .= ("all: " . join (' ', @local_headers)
4001                         . "\n\t"
4002                         . '$(MAKE) $(AM_MAKEFLAGS) '
4003                         . (&variable_defined ('SUBDIRS')
4004                            ? 'all-recursive' : 'all-am')
4005                         . "\n\n");
4006       }
4007     else
4008       {
4009         $output_all .= "all: " . (&variable_defined ('SUBDIRS')
4010                                   ? 'all-recursive' : 'all-am') . "\n\n";
4011       }
4015 # Handle check merge target specially.
4016 sub do_check_merge_target
4018     if (&target_defined ('check-local'))
4019     {
4020         # User defined local form of target.  So include it.
4021         push (@check_tests, 'check-local');
4022         &depend ('.PHONY', 'check-local');
4023     }
4025     # In --cygnus mode, check doesn't depend on all.
4026     if ($cygnus_mode)
4027     {
4028         # Just run the local check rules.
4029         &pretty_print_rule ('check-am:', "\t\t", @check);
4030     }
4031     else
4032     {
4033         # The check target must depend on the local equivalent of
4034         # `all', to ensure all the primary targets are built.  Then it
4035         # must build the local check rules.
4036         $output_rules .= "check-am: all-am\n";
4037         &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
4038                             @check)
4039             if @check;
4040     }
4041     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
4042                         @check_tests)
4043         if @check_tests;
4045     &depend ('.PHONY', 'check', 'check-am');
4046     $output_rules .= ("check: "
4047                       . (&variable_defined ('SUBDIRS')
4048                          ? 'check-recursive' : 'check-am')
4049                       . "\n");
4052 # Handle all 'clean' targets.
4053 sub handle_clean
4055     my %transform;
4057     # Don't include `MAINTAINER'; it is handled specially below.
4058     foreach my $name ('MOSTLY', '', 'DIST')
4059     {
4060       $transform{"${name}CLEAN"} = &variable_defined ("${name}CLEANFILES");
4061     }
4063     # Built sources are automatically removed by maintainer-clean.
4064     push (@maintainer_clean_files, '$(BUILT_SOURCES)')
4065         if &variable_defined ('BUILT_SOURCES');
4066     push (@maintainer_clean_files, '$(MAINTAINERCLEANFILES)')
4067         if &variable_defined ('MAINTAINERCLEANFILES');
4069     $output_rules .= &file_contents ('clean',
4070                                      (%transform,
4071                                       'MCFILES'
4072                                       # Join with no space to avoid
4073                                       # spurious `test -z' success at
4074                                       # runtime.
4075                                       => join ('', @maintainer_clean_files),
4076                                       'MFILES'
4077                                       # A space is required in the join here.
4078                                       => join (' ', @maintainer_clean_files)));
4082 # &depend ($CATEGORY, @DEPENDENDEES)
4083 # ----------------------------------
4084 # The target $CATEGORY depends on @DEPENDENDEES.
4085 sub depend
4087     my ($category, @dependendees) = @_;
4088     {
4089       push (@{$dependencies{$category}}, @dependendees);
4090     }
4094 # &target_cmp ($A, $B)
4095 # --------------------
4096 # Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
4097 sub target_cmp
4099     return 0
4100         if $a eq $b;
4101     return -1
4102         if $b eq '.PHONY';
4103     return 1
4104         if $a eq '.PHONY';
4105     return $a cmp $b;
4109 # &handle_factored_dependencies ()
4110 # --------------------------------
4111 # Handle everything related to gathered targets.
4112 sub handle_factored_dependencies
4114     # Reject bad hooks.
4115     foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4116                        'uninstall-exec-local', 'uninstall-exec-hook')
4117     {
4118         if (&target_defined ($utarg))
4119         {
4120             my $x = $utarg;
4121             $x =~ s/(data|exec)-//;
4122             &am_line_error ($utarg, "use `$x', not `$utarg'");
4123         }
4124     }
4126     if (&target_defined ('install-local'))
4127     {
4128         &am_line_error ('install-local',
4129                         "use `install-data-local' or `install-exec-local', "
4130                         . "not `install-local'");
4131     }
4133     if (!defined $options{'no-installinfo'}
4134         && &target_defined ('install-info-local'))
4135     {
4136         &am_line_error ('install-info-local',
4137                         "`install-info-local' target defined but "
4138                         . "`no-installinfo' option not in use");
4139     }
4141     # Install the -local hooks.
4142     foreach (keys %dependencies)
4143     {
4144       # Hooks are installed on the -am targets.
4145       s/-am$// or next;
4146       if (&target_defined ("$_-local"))
4147         {
4148           depend ("$_-am", "$_-local");
4149           &depend ('.PHONY', "$_-local");
4150         }
4151     }
4153     # Install the -hook hooks.
4154     # FIXME: Why not be as liberal as we are with -local hooks?
4155     foreach ('install-exec', 'install-data')
4156     {
4157       if (&target_defined ("$_-hook"))
4158         {
4159           $actions{"$_-am"} .=
4160             ("\t\@\$(NORMAL_INSTALL)\n"
4161              . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
4162         }
4163     }
4165     # All the required targets are phony.
4166     depend ('.PHONY', keys %required_targets);
4168     # Actually output gathered targets.
4169     foreach (sort target_cmp keys %dependencies)
4170     {
4171         # If there is nothing about this guy, skip it.
4172         next
4173           unless (@{$dependencies{$_}}
4174                   || $actions{$_}
4175                   || $required_targets{$_});
4176         &pretty_print_rule ("$_:", "\t",
4177                             uniq (sort @{$dependencies{$_}}));
4178         $output_rules .= $actions{$_}
4179           if defined $actions{$_};
4180         $output_rules .= "\n";
4181     }
4185 # &handle_tests_dejagnu ()
4186 # ------------------------
4187 sub handle_tests_dejagnu
4189     push (@check_tests, 'check-DEJAGNU');
4191     # Only create site.exp rule if user hasn't already written one.
4192     $output_rules .=
4193       file_contents ('dejagnu', ('SITE-EXP' => ! target_defined ('site.exp')));
4197 # Handle TESTS variable and other checks.
4198 sub handle_tests
4200     if (defined $options{'dejagnu'})
4201     {
4202         &handle_tests_dejagnu;
4203     }
4204     else
4205     {
4206         foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4207         {
4208             &am_line_error ($c,
4209                             "`$c' defined but `dejagnu' not in `AUTOMAKE_OPTIONS'")
4210               if &variable_defined ($c);
4211         }
4212     }
4214     if (&variable_defined ('TESTS'))
4215     {
4216         push (@check_tests, 'check-TESTS');
4217         $output_rules .= &file_contents ('check');
4218     }
4221 # Handle Emacs Lisp.
4222 sub handle_emacs_lisp
4224     my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4225                                    'lisp', 'noinst');
4227     return if ! @elfiles;
4229     # Generate .elc files.
4230     my @elcfiles = map { $_ . 'c' } @elfiles;
4231     &define_pretty_variable ('ELCFILES', '', @elcfiles);
4233     push (@all, '$(ELCFILES)');
4235     &am_error ("`lisp_LISP' defined but `AM_PATH_LISPDIR' not in `$configure_ac'")
4236       if ! $seen_lispdir && &variable_defined ('lisp_LISP');
4238     &require_file_with_conf_line ('AM_PATH_LISPDIR', $FOREIGN, 'elisp-comp');
4241 # Handle Python
4242 sub handle_python
4244     my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4245                                    'python', 'noinst');
4246     return if ! @pyfiles;
4248     # Found some python.
4249     &am_error ("`python_PYTHON' defined but `AM_PATH_PYTHON' not in `$configure_ac'")
4250         if ! $seen_pythondir && &variable_defined ('python_PYTHON');
4252     &require_file_with_conf_line ('AM_PATH_PYTHON', $FOREIGN, 'py-compile');
4253     &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4256 # Handle Java.
4257 sub handle_java
4259     my @sourcelist = &am_install_var ('-candist',
4260                                       'java', 'JAVA',
4261                                       'java', 'noinst', 'check');
4262     return if ! @sourcelist;
4264     my %valid = &am_primary_prefixes ('JAVA', 1,
4265                                       'java', 'noinst', 'check');
4267     my $dir;
4268     foreach my $curs (keys %valid)
4269     {
4270         if (! &variable_defined ($curs . '_JAVA') || $curs eq 'EXTRA')
4271         {
4272             next;
4273         }
4275         if (defined $dir)
4276         {
4277             &am_line_error ($curs . '_JAVA',
4278                             "multiple _JAVA primaries in use");
4279         }
4280         $dir = $curs;
4281     }
4283     push (@all, 'class' . $dir . '.stamp');
4287 # Handle some of the minor options.
4288 sub handle_minor_options
4290     if (defined $options{'readme-alpha'})
4291     {
4292         if ($relative_dir eq '.')
4293         {
4294             if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4295             {
4296                 # FIXME: allow real filename.
4297                 &am_conf_line_error ($configure_ac,
4298                                      $package_version_line,
4299                                      "version `$package_version' doesn't follow Gnits standards");
4300             }
4301             elsif (defined $1 && -f 'README-alpha')
4302             {
4303                 # This means we have an alpha release.  See
4304                 # GNITS_VERSION_PATTERN for details.
4305                 &require_file ($FOREIGN, 'README-alpha');
4306             }
4307         }
4308     }
4311 ################################################################
4313 my %make_list;
4315 # &scan_autoconf_config_files ($CONFIG-FILES)
4316 # -------------------------------------------
4317 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4318 # (or AC_OUTPUT).
4319 sub scan_autoconf_config_files
4321     my ($config_files) = @_;
4322     # Look at potential Makefile.am's.
4323     foreach (split ' ', $config_files)
4324     {
4325         # Must skip empty string for Perl 4.
4326         next if $_ eq "\\" || $_ eq '';
4328         # Handle $local:$input syntax.  Note that we ignore
4329         # every input file past the first, though we keep
4330         # those around for later.
4331         my ($local, $input, @rest) = split (/:/);
4332         if (! $input)
4333         {
4334             $input = $local;
4335         }
4336         else
4337         {
4338             # FIXME: should be error if .in is missing.
4339             $input =~ s/\.in$//;
4340         }
4342         if (-f $input . '.am')
4343         {
4344             # We have a file that automake should generate.
4345             $make_list{$input} = join (':', ($local, @rest));
4346         }
4347         else
4348         {
4349             # We have a file that automake should cause to be
4350             # rebuilt, but shouldn't generate itself.
4351             push (@other_input_files, $_);
4352         }
4353     }
4357 # &scan_autoconf_traces ($FILENAME)
4358 # ---------------------------------
4359 # FIXME: For the time being, we don't care about the FILENAME.
4360 sub scan_autoconf_traces
4362     my ($filename) = @_;
4364     my $traces = "$ENV{amtraces} ";
4366     $traces .= ' -t AC_CONFIG_FILES';
4367     $traces .= ' -t AC_LIBSOURCE';
4368     $traces .= ' -t AC_SUBST';
4370     my $tracefh = new IO::File ("$traces |");
4371     if (! $tracefh)
4372     {
4373         die "$me: couldn't open `$traces': $!\n";
4374     }
4375     print "$me: reading $traces\n" if $verbose;
4377     while ($_ = $tracefh->getline)
4378     {
4379         chomp;
4380         my ($file, $line, $macro, @args) = split /:/;
4381         my $here = "$file:$line";
4383         # Alphabetical ordering please.
4384         if ($macro eq 'AC_CONFIG_FILES')
4385         {
4386             # Look at potential Makefile.am's.
4387             &scan_autoconf_config_files ($args[0]);
4388         }
4389         elsif ($macro eq 'AC_LIBSOURCE')
4390         {
4391             my $source = "$args[0].c";
4392             # We should actually also `close' the sources: getopt.c
4393             # wants getopt.h etc.  But actually it should be done in the
4394             # macro itself, i.e., we have to first fix Autoconf to extend
4395             # _AC_LIBOBJ_DECL and use it the in various macros.
4396             if (!defined $libsources{$source})
4397                 {
4398                     print STDERR "traces: discovered $source\n";
4399                     $libsources{$source} = $here;
4400                 }
4401         }
4402         elsif ($macro eq 'AC_SUBST')
4403         {
4404             if (!defined $configure_vars{$args[0]})
4405                 {
4406                     print STDERR "traces: discovered AC_SUBST($args[0])\n";
4407                     $configure_vars{$args[0]} = $here;
4408                 }
4409         }
4410     }
4412     $tracefh->close
4413         || die "$me: close: $traces: $!\n";
4417 # &scan_one_autoconf_file ($FILENAME)
4418 # -----------------------------------
4419 # Scan one file for interesting things.  Subroutine of
4420 # &scan_autoconf_files.
4421 sub scan_one_autoconf_file
4423     my ($filename) = @_;
4425     my $configfh = new IO::File ("< $filename");
4426     if (! $configfh)
4427     {
4428         die "$me: couldn't open `$filename': $!\n";
4429     }
4430     print "$me: reading $filename\n" if $verbose;
4432     my ($in_ac_output, $in_ac_replace) = (0, 0);
4433     while ($_ = $configfh->getline)
4434     {
4435         # Remove comments from current line.
4436         s/\bdnl\b.*$//;
4437         s/\#.*$//;
4439         # Skip macro definitions.  Otherwise we might be confused into
4440         # thinking that a macro that was only defined was actually
4441         # used.
4442         next if /AC_DEFUN/;
4444         # Follow includes.  This is a weirdness commonly in use at
4445         # Cygnus and hopefully nowhere else.
4446         if (/sinclude\((.*)\)/ && -f $1)
4447         {
4448             # $_ being local, if we don't preserve it, when coming
4449             # back we will have $_ undefined, which is bad for the
4450             # the rest of this routine.
4451             my $underscore = $_;
4452             &scan_one_autoconf_file ($1);
4453             $_ = $underscore;
4454         }
4456         # Populate libobjs array.
4457         if (/AC_FUNC_ALLOCA/)
4458         {
4459             $libsources{'alloca.c'} = 1;
4460         }
4461         elsif (/AC_FUNC_GETLOADAVG/)
4462         {
4463             $libsources{'getloadavg.c'} = 1;
4464         }
4465         elsif (/AC_FUNC_MEMCMP/)
4466         {
4467             $libsources{'memcmp.c'} = 1;
4468         }
4469         elsif (/AC_STRUCT_ST_BLOCKS/)
4470         {
4471             $libsources{'fileblocks.c'} = 1;
4472         }
4473         elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4474         {
4475             $libsources{'getopt.c'} = 1;
4476             $libsources{'getopt1.c'} = 1;
4477         }
4478         elsif (/AM_FUNC_STRTOD/)
4479         {
4480             $libsources{'strtod.c'} = 1;
4481         }
4482         elsif (/AM_WITH_REGEX/)
4483         {
4484             $libsources{'rx.c'} = 1;
4485             $libsources{'rx.h'} = 1;
4486             $libsources{'regex.c'} = 1;
4487             $libsources{'regex.h'} = 1;
4488         }
4489         elsif (/AC_FUNC_MKTIME/)
4490         {
4491             $libsources{'mktime.c'} = 1;
4492         }
4493         elsif (/AM_FUNC_ERROR_AT_LINE/)
4494         {
4495             $libsources{'error.c'} = 1;
4496             $libsources{'error.h'} = 1;
4497         }
4498         elsif (/AM_FUNC_OBSTACK/)
4499         {
4500             $libsources{'obstack.c'} = 1;
4501             $libsources{'obstack.h'} = 1;
4502         }
4503         elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4504                || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4505         {
4506             foreach my $libobj_iter (split (' ', $1))
4507             {
4508                 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4509                     || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4510                     || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4511                 {
4512                     $libsources{$1 . '.c'} = 1;
4513                 }
4514             }
4515         }
4516         elsif (/AC_LIBOBJ\(([^)]+)\)/)
4517         {
4518             $libsources{"$1.c"} = 1;
4519         }
4521         if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4522         {
4523             $in_ac_replace = 1;
4524         }
4525         if ($in_ac_replace)
4526         {
4527             $in_ac_replace = 0 if s/[\]\)].*$//;
4528             # Remove trailing backslash.
4529             s/\\$//;
4530             foreach (split)
4531             {
4532                 # Need to skip empty elements for Perl 4.
4533                 next if $_ eq '';
4534                 $libsources{$_ . '.c'} = 1;
4535             }
4536         }
4538         if (/$obsolete_rx/o)
4539         {
4540             my $hint = '';
4541             if ($obsolete_macros{$1} ne '')
4542             {
4543                 $hint = '; ' . $obsolete_macros{$1};
4544             }
4545             &am_conf_line_error ($filename, $., "`$1' is obsolete$hint");
4546         }
4548         # Process the AC_OUTPUT and AC_CONFIG_FILES macros.
4549         if (! $in_ac_output && s/AC_(OUTPUT|CONFIG_FILES)\s*\(\[?//)
4550         {
4551             $in_ac_output = 1;
4552             $ac_output_line = $.;
4553         }
4554         if ($in_ac_output)
4555         {
4556             my $closing = 0;
4557             if (s/[\]\),].*$//)
4558             {
4559                 $in_ac_output = 0;
4560                 $closing = 1;
4561             }
4563             # Look at potential Makefile.am's.
4564             &scan_autoconf_config_files ($_);
4566             if ($closing
4567                 && scalar keys %make_list == 0
4568                 && @other_input_files == 0)
4569             {
4570                 &am_conf_line_error ($filename, $ac_output_line,
4571                                      "No files mentioned in `AC_OUTPUT'");
4572                 exit 1;
4573             }
4574         }
4576         if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4577         {
4578             @config_aux_path = &unquote_m4_arg ($1);
4579             $config_aux_dir_set_in_configure_in = 1;
4580         }
4582         # Check for ansi2knr.
4583         $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4585         if (/AC_OBJEXT/)
4586         {
4587             $seen_objext = 1;
4588             $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4589         }
4591         # Check for `-c -o' code.
4592         $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4594         # Check for NLS support.
4595         if (/AM_GNU_GETTEXT/)
4596         {
4597             $seen_gettext = 1;
4598             $ac_gettext_line = $.;
4599         }
4601         # Look for ALL_LINGUAS.
4602         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4603         {
4604             $seen_linguas = 1;
4605             $all_linguas = $1;
4606             $all_linguas_line = $.;
4607         }
4609         # Handle configuration headers.  A config header of `[$1]'
4610         # means we are actually scanning AM_CONFIG_HEADER from
4611         # aclocal.m4.
4612         if (/A([CM])_CONFIG_HEADERS?\s*\((.*)\)/
4613             && $2 ne '[$1]')
4614         {
4615             &am_conf_line_error
4616                 ($filename, $., "`automake requires `AM_CONFIG_HEADER', not `AC_CONFIG_HEADER'")
4617                     if $1 eq 'C';
4619             $config_header_line = $.;
4620             foreach my $one_hdr (split (' ', &unquote_m4_arg ($2)))
4621             {
4622                 push (@config_fullnames, $one_hdr);
4623                 if ($one_hdr =~ /^([^:]+):(.+)$/)
4624                 {
4625                     push (@config_names, $1);
4626                     push (@config_headers, $2);
4627                 }
4628                 else
4629                 {
4630                     push (@config_names, $one_hdr);
4631                     push (@config_headers, $one_hdr . '.in');
4632                 }
4633             }
4634         }
4636         # Handle AC_CANONICAL_*.  Always allow upgrading to
4637         # AC_CANONICAL_SYSTEM, but never downgrading.
4638         $seen_canonical = $AC_CANONICAL_HOST
4639             if ! $seen_canonical
4640                 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4641         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4643         # If using X, include some extra variable definitions.  NOTE
4644         # we don't want to force these into CFLAGS or anything,
4645         # because not all programs will necessarily use X.
4646         if (/AC_PATH_XTRA/)
4647           {
4648             foreach my $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS',
4649                              'X_PRE_LIBS')
4650               {
4651                 $configure_vars{$var} = $filename . ':' . $.
4652               }
4653           }
4655         # This macro handles several different things.
4656         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4657         {
4658             ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4659             $package_version_line = $.;
4660             $seen_init_automake = 1;
4661         }
4663         if (/AM_PROG_LEX/)
4664         {
4665             $configure_vars{'LEX'} = $filename . ':' . $.;
4666             $seen_decl_yytext = 1;
4667         }
4668         if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.(ac|in)$/)
4669         {
4670             &am_conf_line_warning ($filename, $., "`AC_DECL_YYTEXT' is covered by `AM_PROG_LEX'");
4671         }
4672         if (/AC_PROG_LEX/ && $filename =~ /configure\.(ac|in)$/)
4673         {
4674             &am_conf_line_warning ($filename, $., "automake requires `AM_PROG_LEX', not `AC_PROG_LEX'");
4675         }
4677         if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4678         {
4679             $configure_vars{$1} = $filename . ':' . $.;
4680         }
4681         if (/$AC_CHECK_PATTERN/o)
4682         {
4683             $configure_vars{$3} = $filename . ':' . $.;
4684         }
4685         if (/$AM_MISSING_PATTERN/o
4686             && $1 ne 'ACLOCAL'
4687             && $1 ne 'AUTOCONF'
4688             && $1 ne 'AUTOMAKE'
4689             && $1 ne 'AUTOHEADER'
4690             # AM_INIT_AUTOMAKE is AM_MISSING_PROG'ing MAKEINFO.  But
4691             # we handle it elsewhere.
4692             && $1 ne 'MAKEINFO')
4693         {
4694             $configure_vars{$1} = $filename . ':' . $.;
4695         }
4697         # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4698         # but later define it elsewhere.  This is pretty hacky.  We
4699         # also explicitly avoid INSTALL_SCRIPT and some other
4700         # variables because they are defined in header-vars.am.
4701         # FIXME.
4702         if (/$AC_SUBST_PATTERN/o
4703             && $1 ne 'ANSI2KNR'
4704             && $1 ne 'INSTALL_SCRIPT'
4705             && $1 ne 'INSTALL_DATA')
4706         {
4707             $configure_vars{$1} = $filename . ':' . $.;
4708         }
4710         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4711         if (/AM_MAINTAINER_MODE/)
4712         {
4713             $seen_maint_mode = 1;
4714             $configure_cond{'MAINTAINER_MODE'} = 1;
4715         }
4717         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4719         if (/AM_PATH_PYTHON/)
4720           {
4721             $seen_pythondir = 1;
4722             $configure_vars{'pythondir'} = $filename . ':' . $.;
4723             $configure_vars{'PYTHON'} = $filename . ':' . $.;
4724           }
4726         if (/A(C|M)_PROG_LIBTOOL/)
4727         {
4728             # We're not ready for this yet.  People still use a
4729             # libtool with no AC_PROG_LIBTOOL.  Once that is the
4730             # dominant version we can reenable this code -- but next
4731             # time by mentioning the macro in %obsolete_macros, both
4732             # here and in aclocal.in.
4734             # if (/AM_PROG_LIBTOOL/)
4735             # {
4736             #   &am_conf_line_warning ($filename, $., "`AM_PROG_LIBTOOL' is obsolete, use `AC_PROG_LIBTOOL' instead");
4737             # }
4738             $seen_libtool = 1;
4739             $libtool_line = $.;
4740             $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4741             $configure_vars{'RANLIB'} = $filename . ':' . $.;
4742             $configure_vars{'CC'} = $filename . ':' . $.;
4743             # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
4744             # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4745             $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4746         }
4748         $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4750         if (/$AM_CONDITIONAL_PATTERN/o)
4751         {
4752             $configure_cond{$1} = 1;
4753         }
4755         # Check for Fortran 77 intrinsic and run-time libraries.
4756         if (/AC_F77_LIBRARY_LDFLAGS/)
4757         {
4758             $configure_vars{'FLIBS'} = $filename . ':' . $.;
4759         }
4760     }
4762     $configfh->close;
4766 # &scan_autoconf_files ()
4767 # -----------------------
4768 # Check whether we use `configure.ac' or `configure.in'.
4769 # Scan it (and possibly `aclocal.m4') for interesting things.
4770 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
4771 sub scan_autoconf_files
4773     # Reinitialize libsources here.  This isn't really necessary,
4774     # since we currently assume there is only one configure.ac.  But
4775     # that won't always be the case.
4776     %libsources = ();
4778     warn "$me: both `configure.ac' and `configure.in' present:"
4779          . " ignoring `configure.in'\n"
4780         if -f 'configure.ac' && -f 'configure.in';
4781     $configure_ac = 'configure.in'
4782         if -f 'configure.in';
4783     $configure_ac = 'configure.ac'
4784         if -f 'configure.ac';
4785     die "$me: `configure.ac' or `configure.in' is required\n"
4786         if !$configure_ac;
4788     &scan_one_autoconf_file ($configure_ac);
4789     &scan_one_autoconf_file ('aclocal.m4')
4790         if -f 'aclocal.m4';
4792     if (defined $ENV{'amtraces'})
4793     {
4794         warn '$me: Autoconf traces is an experimental feature';
4795         warn '$me: use at your own risks';
4797         &scan_autoconf_traces ($configure_ac);
4798     }
4800     # Set input and output files if not specified by user.
4801     if (! @input_files)
4802     {
4803         @input_files = sort keys %make_list;
4804         %output_files = %make_list;
4805     }
4807     @configure_input_files = sort keys %make_list;
4809     &am_conf_error ("`AM_INIT_AUTOMAKE' must be used")
4810         if ! $seen_init_automake;
4812     # Look for some files we need.  Always check for these.  This
4813     # check must be done for every run, even those where we are only
4814     # looking at a subdir Makefile.  We must set relative_dir so that
4815     # the file-finding machinery works.
4816     # FIXME: Is this broken because it needs dynamic scopes.
4817     # My tests seems to show it's not the case.
4818     $relative_dir = '.';
4819     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4820     &am_error ("`install.sh' is an anachronism; use `install-sh' instead")
4821         if -f $config_aux_path[0] . '/install.sh';
4823     &require_config_file ($FOREIGN, 'py-compile')
4824         if $seen_pythondir;
4826     # Preserve dist_common for later.
4827     $configure_dist_common = variable_value ('DIST_COMMON', 'TRUE') || '';
4830 ################################################################
4832 # Set up for Cygnus mode.
4833 sub check_cygnus
4835     return unless $cygnus_mode;
4837     &set_strictness ('foreign');
4838     $options{'no-installinfo'} = 1;
4839     $options{'no-dependencies'} = 1;
4840     $use_dependencies = 0;
4842     if (! $seen_maint_mode)
4843     {
4844         &am_conf_error ("`AM_MAINTAINER_MODE' required when --cygnus specified");
4845     }
4848 # Do any extra checking for GNU standards.
4849 sub check_gnu_standards
4851     if ($relative_dir eq '.')
4852     {
4853         # In top level (or only) directory.
4854         &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4855                        'AUTHORS', 'ChangeLog');
4856     }
4858     if ($strictness >= $GNU
4859         && defined $options{'no-installman'})
4860     {
4861         &am_line_error ('AUTOMAKE_OPTIONS',
4862                         "option `no-installman' disallowed by GNU standards");
4863     }
4865     if ($strictness >= $GNU
4866         && defined $options{'no-installinfo'})
4867     {
4868         &am_line_error ('AUTOMAKE_OPTIONS',
4869                         "option `no-installinfo' disallowed by GNU standards");
4870     }
4873 # Do any extra checking for GNITS standards.
4874 sub check_gnits_standards
4876     if ($relative_dir eq '.')
4877     {
4878         # In top level (or only) directory.
4879         &require_file ($GNITS, 'THANKS');
4880     }
4883 ################################################################
4885 # Functions to handle files of each language.
4887 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
4888 # simple formula: Return value is $LANG_SUBDIR if the resulting object
4889 # file should be in a subdir if the source file is, $LANG_PROCESS if
4890 # file is to be dealt with, $LANG_IGNORE otherwise.
4892 # Much of the actual processing is handled in
4893 # handle_single_transform_list.  These functions exist so that
4894 # auxiliary information can be recorded for a later cleanup pass.
4895 # Note that the calls to these functions are computed, so don't bother
4896 # searching for their precise names in the source.
4898 # This is just a convenience function that can be used to determine
4899 # when a subdir object should be used.
4900 sub lang_sub_obj
4902     return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4905 # Rewrite a single C source file.
4906 sub lang_c_rewrite
4908     my ($directory, $base, $ext) = @_;
4910     if (defined $options{'ansi2knr'} && $base =~ /_$/)
4911     {
4912         # FIXME: include line number in error.
4913         &am_error ("C source file `$base.c' would be deleted by ansi2knr rules");
4914     }
4916     my $r = $LANG_PROCESS;
4917     if (defined $options{'subdir-objects'})
4918     {
4919         $r = $LANG_SUBDIR;
4920         $base = $directory . '/' . $base;
4922         if (! $seen_cc_c_o)
4923         {
4924             # Only give error once.
4925             $seen_cc_c_o = 1;
4926             # FIXME: line number.
4927             &am_error ("C objects in subdir but `AM_PROG_CC_C_O' not in `$configure_ac'");
4928         }
4930         &require_config_file ($FOREIGN, 'compile');
4931     }
4933     $de_ansi_files{$base} = 1;
4934     return $r;
4937 # Rewrite a single C++ source file.
4938 sub lang_cxx_rewrite
4940     return &lang_sub_obj;
4943 # Rewrite a single header file.
4944 sub lang_header_rewrite
4946     # Header files are simply ignored.
4947     return $LANG_IGNORE;
4950 # Rewrite a single yacc file.
4951 sub lang_yacc_rewrite
4953     my ($directory, $base, $ext) = @_;
4955     my $r = &lang_sub_obj;
4956     (my $newext = $ext) =~ tr/y/c/;
4957     return ($r, $newext);
4960 # Rewrite a single yacc++ file.
4961 sub lang_yaccxx_rewrite
4963     my ($directory, $base, $ext) = @_;
4965     my $r = &lang_sub_obj;
4966     (my $newext = $ext) =~ tr/y/c/;
4967     return ($r, $newext);
4970 # Rewrite a single lex file.
4971 sub lang_lex_rewrite
4973     my ($directory, $base, $ext) = @_;
4975     my $r = &lang_sub_obj;
4976     (my $newext = $ext) =~ tr/l/c/;
4977     return ($r, $newext);
4980 # Rewrite a single lex++ file.
4981 sub lang_lexxx_rewrite
4983     my ($directory, $base, $ext) = @_;
4985     my $r = &lang_sub_obj;
4986     (my $newext = $ext) =~ tr/l/c/;
4987     return ($r, $newext);
4990 # Rewrite a single assembly file.
4991 sub lang_asm_rewrite
4993     return &lang_sub_obj;
4996 # Rewrite a single Fortran 77 file.
4997 sub lang_f77_rewrite
4999     return $LANG_PROCESS;
5002 # Rewrite a single preprocessed Fortran 77 file.
5003 sub lang_ppf77_rewrite
5005     return $LANG_PROCESS;
5008 # Rewrite a single ratfor file.
5009 sub lang_ratfor_rewrite
5011     return $LANG_PROCESS;
5014 # Rewrite a single Objective C file.
5015 sub lang_objc_rewrite
5017     return &lang_sub_obj;
5020 # Rewrite a single Java file.
5021 sub lang_java_rewrite
5023     return $LANG_SUBDIR;
5026 # The lang_X_finish functions are called after all source file
5027 # processing is done.  Each should handle defining rules for the
5028 # language, etc.  A finish function is only called if a source file of
5029 # the appropriate type has been seen.
5031 sub lang_c_finish
5033     # Push all libobjs files onto de_ansi_files.  We actually only
5034     # push files which exist in the current directory, and which are
5035     # genuine source files.
5036     foreach my $file (keys %libsources)
5037     {
5038         if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
5039         {
5040             $de_ansi_files{$1} = 1;
5041         }
5042     }
5044     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
5045     {
5046         # Make all _.c files depend on their corresponding .c files.
5047         my @objects;
5048         foreach my $base (sort keys %de_ansi_files)
5049         {
5050             # Each _.c file must depend on ansi2knr; otherwise it
5051             # might be used in a parallel build before it is built.
5052             # We need to support files in the srcdir and in the build
5053             # dir (because these files might be auto-generated.  But
5054             # we can't use $< -- some makes only define $< during a
5055             # suffix rule.
5056             $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
5057                               . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5058                               . '`if test -f $(srcdir)/' . $base . '.c'
5059                               . '; then echo $(srcdir)/' . $base . '.c'
5060                               . '; else echo ' . $base . '.c; fi` '
5061                               . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5062                               . '| $(ANSI2KNR) > ' . $base . "_.c"
5063                               # If ansi2knr fails then we shouldn't
5064                               # create the _.c file
5065                               . " || rm -f ${base}_.c\n");
5066             push (@objects, $base . '_.$(OBJEXT)');
5067             push (@objects, $base . '_.lo')
5068               if $seen_libtool;
5069         }
5071         # Make all _.o (and _.lo) files depend on ansi2knr.
5072         # Use a sneaky little hack to make it print nicely.
5073         &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5074     }
5077 # This is a yacc helper which is called whenever we have decided to
5078 # compile a yacc file.
5079 sub lang_yacc_target_hook
5081     my ($self, $aggregate, $output, $input) = @_;
5083     my $flag = $aggregate . "_YFLAGS";
5084     if ((&variable_defined ($flag)
5085          && &variable_value ($flag) =~ /$DASH_D_PATTERN/o)
5086         || (&variable_defined ('YFLAGS')
5087             && &variable_value ('YFLAGS') =~ /$DASH_D_PATTERN/o))
5088     {
5089         (my $output_base = $output) =~ s/\..*$//;
5090         my $header = $output_base . '.h';
5092         # Found a `-d' that applies to the compilation of this file.
5093         # Add a dependency for the generated header file, and arrange
5094         # for that file to be included in the distribution.
5095         # FIXME: this fails for `nodist_*_SOURCES'.
5096         $output_rules .= "${header}: $input\n";
5097         &push_dist_common ($header);
5098         # If the files are built in the build directory, then we want
5099         # to remove them with `make clean'.  If they are in srcdir
5100         # they shouldn't be touched.  However, we can't determine this
5101         # statically, and the GNU rules say that yacc/lex output files
5102         # should be removed by maintainer-clean.  So that's what we
5103         # do.
5104         push (@maintainer_clean_files, $header);
5105     }
5108 # This is a helper for both lex and yacc.
5109 sub yacc_lex_finish_helper
5111     return if defined $language_scratch{'lex-yacc-done'};
5112     $language_scratch{'lex-yacc-done'} = 1;
5114     # If there is more than one distinct yacc (resp lex) source file
5115     # in a given directory, then the `ylwrap' program is required to
5116     # allow parallel builds to work correctly.  FIXME: for now, no
5117     # line number.
5118     &require_config_file ($FOREIGN, 'ylwrap');
5119     if ($config_aux_dir_set_in_configure_in)
5120     {
5121         &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5122     }
5123     else
5124     {
5125         &define_variable ('YLWRAP', '$(top_srcdir)/ylwrap');
5126     }
5129 sub lang_yacc_finish
5131     return if defined $language_scratch{'yacc-done'};
5132     $language_scratch{'yacc-done'} = 1;
5134     if (&variable_defined ('YACCFLAGS'))
5135     {
5136         &am_line_error ('YACCFLAGS',
5137                         "`YACCFLAGS' obsolete; use `YFLAGS' instead");
5138     }
5140     if (count_files_for_language ('yacc') > 1)
5141     {
5142         &yacc_lex_finish_helper;
5143     }
5147 sub lang_lex_finish
5149     return if defined $language_scratch{'lex-done'};
5150     $language_scratch{'lex-done'} = 1;
5152     if (! $seen_decl_yytext)
5153     {
5154         &am_error ("lex source seen but `AC_DECL_YYTEXT' not in `$configure_ac'");
5155     }
5157     if (count_files_for_language ('lex') > 1)
5158     {
5159         &yacc_lex_finish_helper;
5160     }
5164 # Given a hash table of linker names, pick the name that has the most
5165 # precedence.  This is lame, but something has to have global
5166 # knowledge in order to eliminate the conflict.  Add more linkers as
5167 # required.
5168 sub resolve_linker
5170     my (%linkers) = @_;
5172     return 'GCJLINK'
5173         if defined $linkers{'GCJLINK'};
5174     return 'CXXLINK'
5175         if defined $linkers{'CXXLINK'};
5176     return 'F77LINK'
5177         if defined $linkers{'F77LINK'};
5178     return 'OBJCLINK'
5179         if defined $linkers{'OBJCLINK'};
5180     return 'LINK';
5183 # Called to indicate that an extension was used.
5184 sub saw_extension
5186     my ($ext) = @_;
5187     if (! defined $extension_seen{$ext})
5188     {
5189         $extension_seen{$ext} = 1;
5190     }
5191     else
5192     {
5193         ++$extension_seen{$ext};
5194     }
5197 # Return the number of files seen for a given language.  Knows about
5198 # special cases we care about.  FIXME: this is hideous.  We need
5199 # something that involves real language objects.  For instance yacc
5200 # and yaccxx could both derive from a common yacc class which would
5201 # know about the strange ylwrap requirement.  (Or better yet we could
5202 # just not support legacy yacc!)
5203 sub count_files_for_language
5205     my ($name) = @_;
5207     my @names;
5208     if ($name eq 'yacc' || $name eq 'yaccxx')
5209     {
5210         @names = ('yacc', 'yaccxx');
5211     }
5212     elsif ($name eq 'lex' || $name eq 'lexxx')
5213     {
5214         @names = ('lex', 'lexxx');
5215     }
5216     else
5217     {
5218         @names = ($name);
5219     }
5221     my $r = 0;
5222     foreach $name (@names)
5223     {
5224         my $lang = $languages{$name};
5225         foreach my $ext (@{$lang->extensions})
5226         {
5227             $r += $extension_seen{$ext}
5228                 if defined $extension_seen{$ext};
5229         }
5230     }
5232     return $r
5235 # Called to ask whether source files have been seen . If HEADERS is 1,
5236 # headers can be included.
5237 sub saw_sources_p
5239     my ($headers) = @_;
5241     # count all the sources
5242     my $count = 0;
5243     foreach my $val (values %extension_seen)
5244     {
5245         $count += $val;
5246     }
5248     if (!$headers)
5249     {
5250         $count -= count_files_for_language ('header');
5251     }
5253     return $count > 0;
5257 # register_language (%ATTRIBUTE)
5258 # ------------------------------
5259 # Register a single language.
5260 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5261 sub register_language (%)
5263     my (%option) = @_;
5265     # Set the defaults.
5266     $option{'ansi'} = 0
5267       unless defined $option{'ansi'};
5268     $option{'autodep'} = 'no'
5269       unless defined $option{'autodep'};
5270     $option{'linker'} = ''
5271       unless defined $option{'linker'};
5272     $option{'define_flag'} = 1
5273       unless defined $option{'define_flag'};
5275     my $lang = new Language (%option);
5277     # Fill indexes.
5278     grep ($extension_map{$_} = $lang->name, @{$lang->extensions});
5279     $languages{$lang->name} = $lang;
5282 # This function is used to find a path from a user-specified suffix to
5283 # `o' or to some other suffix we recognize internally, eg `cc'.
5284 sub derive_suffix
5286     my ($source_ext) = @_;
5288     # FIXME: hard-coding `o' is a mistake.  Doing something
5289     # intelligent is harder.
5290     while (! $extension_map{$source_ext}
5291            && $source_ext ne 'o'
5292            && defined $suffix_rules{$source_ext})
5293     {
5294         $source_ext = $suffix_rules{$source_ext};
5295     }
5297     return $source_ext;
5301 ################################################################
5303 # Pretty-print something.  HEAD is what should be printed at the
5304 # beginning of the first line, FILL is what should be printed at the
5305 # beginning of every subsequent line.
5306 sub pretty_print_internal
5308     my ($head, $fill, @values) = @_;
5310     my $column = length ($head);
5311     my $result = $head;
5313     # Fill length is number of characters.  However, each Tab
5314     # character counts for eight.  So we count the number of Tabs and
5315     # multiply by 7.
5316     my $fill_length = length ($fill);
5317     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5319     foreach (@values)
5320     {
5321         # "71" because we also print a space.
5322         if ($column + length ($_) > 71)
5323         {
5324             $result .= " \\\n" . $fill;
5325             $column = $fill_length;
5326         }
5327         $result .= ' ' if $result =~ /\S\z/;
5328         $result .= $_;
5329         $column += length ($_) + 1;
5330     }
5332     $result .= "\n";
5333     return $result;
5336 # Pretty-print something and append to output_vars.
5337 sub pretty_print
5339     $output_vars .= &pretty_print_internal (@_);
5342 # Pretty-print something and append to output_rules.
5343 sub pretty_print_rule
5345     $output_rules .= &pretty_print_internal (@_);
5349 ################################################################
5352 # $STRING
5353 # &conditional_string(@COND-STACK)
5354 # --------------------------------
5355 # Build a string which denotes the conditional in @COND-STACK.  Some
5356 # simplifications are done: `TRUE' entries are elided, and any `FALSE'
5357 # entry results in a return of `FALSE'.
5358 sub conditional_string
5360   my (@stack) = @_;
5362   if (grep (/^FALSE$/, @stack))
5363     {
5364       return 'FALSE';
5365     }
5366   else
5367     {
5368       return join (' ', uniq sort grep (!/^TRUE$/, @stack));
5369     }
5373 # $BOOLEAN
5374 # &conditional_true_when ($COND, $WHEN)
5375 # -------------------------------------
5376 # See if a conditional is true.  Both arguments are conditional
5377 # strings.  This returns true if the first conditional is true when
5378 # the second conditional is true.
5379 # For instance with $COND = `BAR FOO', and $WHEN = `BAR BAZ FOO',
5380 # obviously return 1, and 0 when, for instance, $WHEN = `FOO'.
5381 sub conditional_true_when ($$)
5383     my ($cond, $when) = @_;
5385     # Make a hash holding all the values from $WHEN.
5386     my %cond_vals = map { $_ => 1 } split (' ', $when);
5388     # Check each component of $cond, which looks `COND1 COND2'.
5389     foreach my $comp (split (' ', $cond))
5390     {
5391         # TRUE is always true.
5392         next if $comp eq 'TRUE';
5393         return 0 if ! defined $cond_vals{$comp};
5394     }
5396     return 1;
5400 # $BOOLEAN
5401 # &conditionals_true_when (\@CONDS, $WHEN)
5402 # ----------------------------------------
5403 # Same as above, but true only if all the @CONDS are true when $WHEN is true.
5405 # If there are no @CONDS, then return true.
5406 sub conditionals_true_when (\@$)
5408     my ($condsref, $when) = @_;
5410     foreach my $cond (@$condsref)
5411     {
5412         return 0 unless conditional_true_when ($cond, $when);
5413     }
5415     return 1;
5418 # $BOOLEAN
5419 # &conditional_is_redundant ($COND, @WHENS)
5420 # ----------------------------------------
5421 # Determine whether $COND is redundant with respect to @WHENS.
5423 # Returns true if $COND is true for any of the conditions in @WHENS.
5425 # If there are no @WHENS, then behave as if @WHENS contained a single empty
5426 # condition.
5427 sub conditional_is_redundant ($@)
5429     my ($cond, @whens) = @_;
5431     if (@whens == 0)
5432     {
5433         return 1 if conditional_true_when ($cond, "");
5434     }
5435     else
5436     {
5437         foreach my $when (@whens)
5438         {
5439             return 1 if conditional_true_when ($cond, $when);
5440         }
5441     }
5443     return 0;
5447 # $NEGATION
5448 # condition_negate ($COND)
5449 # ------------------------
5450 sub condition_negate ($)
5452     my ($cond) = @_;
5454     $cond =~ s/TRUE$/TRUEO/;
5455     $cond =~ s/FALSE$/TRUE/;
5456     $cond =~ s/TRUEO$/FALSE/;
5458     return $cond;
5462 # Compare condition names.
5463 # Issue them in alphabetical order, foo_TRUE before foo_FALSE.
5464 sub by_condition
5466     # Be careful we might be comparing `' or `#'.
5467     $a =~ /^(.*)_(TRUE|FALSE)$/;
5468     my ($aname, $abool) = ($1 || '', $2 || '');
5469     $b =~ /^(.*)_(TRUE|FALSE)$/;
5470     my ($bname, $bbool) = ($1 || '', $2 || '');
5471     return ($aname cmp $bname
5472             # Don't bother with IFs, given that TRUE is after FALSE
5473             # just cmp in the reverse order.
5474             || $bbool cmp $abool
5475             # Just in case...
5476             || $a cmp $b);
5480 # &make_condition (@CONDITIONS)
5481 # -----------------------------
5482 # Transform a list of conditions (themselves can be an internal list
5483 # of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
5484 # Make conditional (a pattern for AC_SUBST).
5485 # Correctly returns the empty string when there are no conditions.
5486 sub make_condition
5488     my $res = conditional_string (@_);
5490     # There are no conditions.
5491     if ($res eq '')
5492       {
5493         # Nothing to do.
5494       }
5495     # It's impossible.
5496     elsif ($res eq 'FALSE')
5497       {
5498         $res = '#';
5499       }
5500     # Build it.
5501     else
5502       {
5503         $res = '@' . $res . '@';
5504         $res =~ s/ /@@/g;
5505       }
5507     return $res;
5512 ## ------------------------------ ##
5513 ## Handling the condition stack.  ##
5514 ## ------------------------------ ##
5517 # $COND_STRING
5518 # cond_stack_if ($NEGATE, $COND, $WHERE)
5519 # --------------------------------------
5520 sub cond_stack_if ($$$)
5522   my ($negate, $cond, $where) = @_;
5524   &am_file_error ($where, "$cond does not appear in AM_CONDITIONAL")
5525     if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
5527   $cond = "${cond}_TRUE"
5528     unless $cond =~ /^TRUE|FALSE$/;
5529   $cond = condition_negate ($cond)
5530     if $negate;
5532   push (@cond_stack, $cond);
5534   return conditional_string (@cond_stack);
5538 # $COND_STRING
5539 # cond_stack_else ($NEGATE, $COND, $WHERE)
5540 # ----------------------------------------
5541 sub cond_stack_else ($$$)
5543   my ($negate, $cond, $where) = @_;
5545   if (! @cond_stack)
5546     {
5547       &am_file_error ($where, "else without if");
5548       return;
5549     }
5551   $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);
5553   # If $COND is given, check against it.
5554   if (defined $cond)
5555     {
5556       $cond = "${cond}_TRUE"
5557         unless $cond =~ /^TRUE|FALSE$/;
5558       $cond = condition_negate ($cond)
5559         if $negate;
5561       &am_file_error ($where,
5562                       "else reminder ($negate$cond) incompatible with "
5563                       . "current conditional: $cond_stack[$#cond_stack]")
5564         if $cond_stack[$#cond_stack] ne $cond;
5565     }
5567   return conditional_string (@cond_stack);
5571 # $COND_STRING
5572 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5573 # -----------------------------------------
5574 sub cond_stack_endif ($$$)
5576   my ($negate, $cond, $where) = @_;
5577   my $old_cond;
5579   if (! @cond_stack)
5580     {
5581       &am_file_error ($where, "endif without if: $negate$cond");
5582       return;
5583     }
5586   # If $COND is given, check against it.
5587   if (defined $cond)
5588     {
5589       $cond = "${cond}_TRUE"
5590         unless $cond =~ /^TRUE|FALSE$/;
5591       $cond = condition_negate ($cond)
5592         if $negate;
5594       &am_file_error ($where,
5595                       "endif reminder ($negate$cond) incompatible with "
5596                       . "current conditional: $cond_stack[$#cond_stack]")
5597         if $cond_stack[$#cond_stack] ne $cond;
5598     }
5600   pop @cond_stack;
5602   return conditional_string (@cond_stack);
5609 ## ------------------------ ##
5610 ## Handling the variables.  ##
5611 ## ------------------------ ##
5614 # check_ambiguous_conditional ($VAR, $COND)
5615 # -----------------------------------------
5616 # Check for an ambiguous conditional.  This is called when a variable
5617 # is being defined conditionally.  If we already know about a
5618 # definition that is true under the same conditions, then we have an
5619 # ambiguity.
5620 sub check_ambiguous_conditional ($$)
5622     my ($var, $cond) = @_;
5623     foreach my $vcond (keys %{$var_value{$var}})
5624     {
5625        my $message;
5626        if ($vcond eq $cond)
5627        {
5628            $message = "$var multiply defined in condition $cond";
5629        }
5630        elsif (&conditional_true_when ($vcond, $cond))
5631        {
5632          $message = ("$var was already defined in condition $vcond, "
5633                      . "which implies condition $cond");
5634        }
5635        elsif (&conditional_true_when ($cond, $vcond))
5636        {
5637            $message = ("$var was already defined in condition $vcond, "
5638                        . "which is implied by condition $cond");
5639        }
5640        if ($message)
5641        {
5642            &am_line_error ($var, $message);
5643            macro_dump ($var);
5644        }
5645    }
5649 # &macro_define($VAR, $VAR_IS_AM, $TYPE, $COND, $VALUE, $WHERE)
5650 # -------------------------------------------------------------
5651 # The $VAR can go from Automake to user, but not the converse.
5652 sub macro_define ($$$$$$)
5654   my ($var, $var_is_am, $type, $cond, $value, $where) = @_;
5656   am_file_error ($where, "bad macro name `$var'")
5657     if $var !~ /$MACRO_PATTERN/o;
5659   $cond ||= 'TRUE';
5661   # An Automake variable must be consistently defined with the same
5662   # sign by Automake.  A user variable must be set by either `=' or
5663   # `:=', and later promoted to `+='.
5664   if ($var_is_am)
5665     {
5666       if (defined $var_type{$var} && $var_type{$var} ne $type)
5667         {
5668           am_line_error ($var,
5669                          ("$var was set with `$var_type{$var}=' "
5670                           . "and is now set with `$type='"));
5671         }
5672     }
5673   else
5674     {
5675       if (!defined $var_type{$var} && $type eq '+')
5676         {
5677           am_line_error ($var, "$var must be set with `=' before using `+='");
5678         }
5679     }
5680   $var_type{$var} = $type;
5682   # When adding, since we rewrite, don't try to preserve the
5683   # Automake continuation backslashes.
5684   $value =~ s/\\$//mg
5685     if $type eq '+' && $var_is_am;
5687   # Differentiate the first assignment (including with `+=').
5688   if ($type eq '+' && defined $var_value{$var}{$cond})
5689     {
5690       if (substr ($var_value{$var}{$cond}, -1) eq "\n")
5691         {
5692           # Insert a backslash before a trailing newline.
5693           $var_value{$var}{$cond} =
5694             substr ($var_value{$var}{$cond}, 0, -1) . "\\\n";
5695         }
5696       elsif ($var_value{$var}{$cond})
5697         {
5698           # Insert a separator.
5699           $var_value{$var}{$cond} .= ' ';
5700         }
5701        $var_value{$var}{$cond} .= $value;
5702     }
5703   else
5704     {
5705       # The first assignment to a macro sets the line number.  Ideally I
5706       # suppose we would associate line numbers with random bits of text.
5707       # FIXME: We sometimes redefine some variables, but we want to keep
5708       # the original location.  More subs are needed to handle
5709       # properly variables.  Once this done, remove this hack.
5710       $var_line{$var} = $where
5711         unless defined $var_line{$var};
5713       # If Automake tries to override a value specified by the user,
5714       # just don't let it do.
5715       if (defined $var_value{$var}{$cond} && !$var_is_am{$var} && $var_is_am)
5716         {
5717           if ($verbose)
5718             {
5719               print STDERR "$me: refusing to override the user definition of:\n";
5720               macro_dump ($var);
5721               print STDERR "$me: with `$cond' => `$value'\n";
5722             }
5723         }
5724       else
5725         {
5726           # There must be no previous value unless the user is redefining
5727           # an Automake variable or an AC_SUBST variable.
5728           check_ambiguous_conditional ($var, $cond)
5729             unless ($var_is_am{$var} && !$var_is_am
5730                     || exists $configure_vars{$var});
5732           $var_value{$var}{$cond} = $value;
5733         }
5734     }
5736   # An Automake variable can be given to the user, but not the converse.
5737   if (! defined $var_is_am{$var} || !$var_is_am)
5738     {
5739       $var_is_am{$var} = $var_is_am;
5740     }
5744 # &variable_delete ($VAR, [@CONDS])
5745 # ---------------------------------
5746 # Forget about $VAR under the conditions @CONDS, or completely if
5747 # @CONDS is empty.
5748 sub variable_delete ($@)
5750   my ($var, @conds) = @_;
5752   if (!@conds)
5753     {
5754       delete $var_value{$var};
5755       delete $var_line{$var};
5756       delete $var_is_am{$var};
5757       delete $var_comment{$var};
5758       delete $var_type{$var};
5759     }
5760   else
5761     {
5762       foreach my $cond (@conds)
5763         {
5764           delete $var_value{$var}{$cond};
5765         }
5766     }
5770 # &macro_dump ($VAR)
5771 # ------------------
5772 sub macro_dump ($)
5774   my ($var) = @_;
5776   if (!exists $var_value{$var})
5777     {
5778       print STDERR "  $var does not exist\n";
5779     }
5780   else
5781     {
5782       my $var_is_am = $var_is_am{$var} ? "Automake" : "User";
5783       my $where = (defined $var_line{$var}
5784                    ? $var_line{$var} : "undefined");
5785       print STDERR "$var_comment{$var}"
5786         if defined $var_comment{$var};
5787       print STDERR "  $var ($var_is_am, where = $where) $var_type{$var}=\n";
5788       print STDERR "  {\n";
5789       foreach my $vcond (sort by_condition keys %{$var_value{$var}})
5790         {
5791           print STDERR "    $vcond => $var_value{$var}{$vcond}\n";
5792         }
5793       print STDERR "  }\n";
5794     }
5798 # &macros_dump ()
5799 # ---------------
5800 sub macros_dump ()
5802   my ($var) = @_;
5804   print STDERR "%var_value =\n";
5805   print STDERR "{\n";
5806   foreach my $var (sort (keys %var_value))
5807     {
5808       macro_dump ($var);
5809     }
5810   print STDERR "}\n";
5814 # $BOOLEAN
5815 # &variable_defined ($VAR, [$COND])
5816 # ---------------------------------
5817 # See if a variable exists.  $VAR is the variable name, and $COND is
5818 # the condition which we should check.  If no condition is given, we
5819 # currently return true if the variable is defined under any
5820 # condition.
5821 sub variable_defined ($$)
5823     my ($var, $cond) = @_;
5825     # Unfortunately we can't just check for $var_value{VAR}{COND}
5826     # as this would make perl create $condition{VAR}, which we
5827     # don't want.
5828     if (!exists $var_value{$var})
5829       {
5830         if (defined $targets{$var})
5831           {
5832             &am_line_error ($var, "`$var' is a target; expected a variable")
5833           }
5834         # The variable is not defined
5835         return 0;
5836       }
5838     if ($cond && !exists $var_value{$var}{$cond})
5839       {
5840         # The variable is not defined for the given condition.
5841         return 0;
5842       }
5844     # Even a var_value examination is good enough for us.  FIXME:
5845     # really should maintain examined status on a per-condition basis.
5846     $content_seen{$var} = 1;
5847     return 1;
5850 # Mark a variable as examined.
5851 sub examine_variable
5853     my ($var) = @_;
5854     &variable_defined ($var);
5857 # Return the set of conditions for which a variable is defined.
5859 # If the variable is not defined conditionally, and is not defined in
5860 # terms of any variables which are defined conditionally, then this
5861 # returns the empty list.
5863 # If the variable is defined conditionally, but is not defined in
5864 # terms of any variables which are defined conditionally, then this
5865 # returns the list of conditions for which the variable is defined.
5867 # If the variable is defined in terms of any variables which are
5868 # defined conditionally, then this returns a full set of permutations
5869 # of the subvariable conditions.  For example, if the variable is
5870 # defined in terms of a variable which is defined for COND_TRUE,
5871 # then this returns both COND_TRUE and COND_FALSE.  This is
5872 # because we will need to define the variable under both conditions.
5874 sub variable_conditions ($)
5876     my ($var) = @_;
5877     my %uniqify;
5878     my @uniq_list;
5880     %vars_scanned = ();
5882     my @new_conds = &variable_conditions_sub ($var, '', ());
5883     # Now we want to return all permutations of the subvariable
5884     # conditions.
5885     my %allconds = ();
5886     foreach my $item (@new_conds)
5887     {
5888         foreach (split (' ', $item))
5889         {
5890             s/^(.*)_(TRUE|FALSE)$/$1_TRUE/;
5891             $allconds{$_} = 1;
5892         }
5893     }
5894     @new_conds = &variable_conditions_permutations (sort keys %allconds);
5896     foreach my $cond (@new_conds)
5897     {
5898         my $reduce = &variable_conditions_reduce (split (' ', $cond));
5899         next
5900             if $reduce eq 'FALSE';
5901         $uniqify{$cond} = 1;
5902     }
5904     @uniq_list = sort by_condition keys %uniqify;
5905     # Note we cannot just do `return sort keys %uniqify', because this
5906     # function is sometimes used in a scalar context.
5907     return @uniq_list;
5911 # $BOOLEAN
5912 # &variable_conditionally_defined ($VAR)
5913 # --------------------------------------
5914 sub variable_conditionally_defined ($)
5916     my ($var) = @_;
5917     foreach my $cond (variable_conditions ($var))
5918       {
5919         return 1
5920           unless $cond =~ /^TRUE|FALSE$/;
5921       }
5922     return 0;
5927 # &variable_conditions_sub ($VAR, $PARENT, @PARENT_CONDS)
5928 # -------------------------------------------------------
5929 # A subroutine of variable_conditions.  This returns all the
5930 # conditions of $VAR which are satisfiable when all of @PARENT_CONDS
5931 # are true.
5932 sub variable_conditions_sub
5934     my ($var, $parent, @parent_conds) = @_;
5935     my @new_conds = ();
5937     if (defined $vars_scanned{$var})
5938     {
5939         &am_line_error ($parent, "variable `$var' recursively defined");
5940         return ();
5941     }
5942     $vars_scanned{$var} = 1;
5944     my @this_conds = ();
5945     # Examine every condition under which $VAR is defined.
5946     foreach my $vcond (keys %{$var_value{$var}})
5947     {
5948         # If this condition cannot be true when the parent conditions
5949         # are true, then skip it.
5950         next
5951           if ! conditionals_true_when (@parent_conds, $vcond);
5953         push (@this_conds, $vcond);
5955         # If $VAR references some other variable, then compute the
5956         # conditions for that subvariable.
5957         push (@parent_conds, $vcond);
5958         my @subvar_conds = ();
5959         foreach (split (' ', $var_value{$var}{$vcond}))
5960         {
5961             # If a comment seen, just leave.
5962             last if /^#/;
5964             # Handle variable substitutions.
5965             if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5966             {
5968                 # Here we compute all the conditions under which the
5969                 # subvariable is defined.  Then we go through and add
5970                 # $VCOND to each.
5971                 my @svc = &variable_conditions_sub ($1, $var, @parent_conds);
5972                 foreach my $item (@svc)
5973                 {
5974                     my $val = conditional_string ($vcond, split (' ', $item));
5975                     $val ||= 'TRUE';
5976                     push (@subvar_conds, $val);
5977                 }
5978             }
5979         }
5980         pop (@parent_conds);
5982         # If there are no conditional subvariables, then we want to
5983         # return this condition.  Otherwise, we want to return the
5984         # permutations of the subvariables, taking into account the
5985         # conditions of $VAR.
5986         if (! @subvar_conds)
5987         {
5988             push (@new_conds, $vcond);
5989         }
5990         else
5991         {
5992             push (@new_conds, &variable_conditions_reduce (@subvar_conds));
5993         }
5994     }
5996     # Unset our entry in vars_scanned.  We only care about recursive
5997     # definitions.
5998     delete $vars_scanned{$var};
6000     # If we are being called on behalf of another variable, we need to
6001     # return all possible permutations of the conditions.  We have
6002     # already handled everything in @this_conds along with their
6003     # subvariables.  We now need to add any permutations that are not
6004     # in @this_conds.
6005     foreach my $this_cond (@this_conds)
6006     {
6007         my @perms =
6008             &variable_conditions_permutations (split(' ', $this_cond));
6009         foreach my $perm (@perms)
6010         {
6011             my $ok = 1;
6012             foreach my $scan (@this_conds)
6013             {
6014                 if (&conditional_true_when ($perm, $scan)
6015                     || &conditional_true_when ($scan, $perm))
6016                 {
6017                     $ok = 0;
6018                     last;
6019                 }
6020             }
6021             next if ! $ok;
6023             next
6024               if ! conditionals_true_when (@parent_conds, $perm);
6026             # This permutation was not already handled, and is valid
6027             # for the parents.
6028             push (@new_conds, $perm);
6029         }
6030     }
6032     return @new_conds;
6036 # Filter a list of conditionals so that only the exclusive ones are
6037 # retained.  For example, if both `COND1_TRUE COND2_TRUE' and
6038 # `COND1_TRUE' are in the list, discard the latter.
6039 # If the list is empty, return TRUE
6040 sub variable_conditions_reduce
6042     my (@conds) = @_;
6043     my @ret = ();
6044     my $cond;
6045     while(@conds > 0)
6046     {
6047         $cond = shift(@conds);
6049         # FALSE is absorbent.
6050         if ($cond eq 'FALSE')
6051           {
6052             return ('FALSE');
6053           }
6054         elsif (!conditional_is_redundant ($cond, @ret, @conds))
6055           {
6056             push (@ret, $cond);
6057           }
6058     }
6060     return "TRUE" if @ret == 0;
6061     return @ret;
6064 # Return a list of permutations of a conditional string.
6065 sub variable_conditions_permutations
6067     my (@comps) = @_;
6068     return ()
6069         if ! @comps;
6070     my $comp = shift (@comps);
6071     return &variable_conditions_permutations (@comps)
6072         if $comp eq '';
6073     my $neg = condition_negate ($comp);
6075     my @ret;
6076     foreach my $sub (&variable_conditions_permutations (@comps))
6077     {
6078         push (@ret, "$comp $sub");
6079         push (@ret, "$neg $sub");
6080     }
6081     if (! @ret)
6082     {
6083         push (@ret, $comp);
6084         push (@ret, $neg);
6085     }
6086     return @ret;
6090 # $BOOL
6091 # &check_variable_defined_unconditionally($VAR, $PARENT)
6092 # ------------------------------------------------------
6093 # Warn if a variable is conditionally defined.  This is called if we
6094 # are using the value of a variable.
6095 sub check_variable_defined_unconditionally ($$)
6097     my ($var, $parent) = @_;
6098     foreach my $cond (keys %{$var_value{$var}})
6099     {
6100         next
6101           if $cond =~ /^TRUE|FALSE$/;
6103         if ($parent)
6104         {
6105             &am_line_error ($parent,
6106                             "warning: automake does not support conditional definition of $var in $parent");
6107         }
6108         else
6109         {
6110             &am_line_error ($parent,
6111                             "warning: automake does not support $var being defined conditionally");
6112             macro_dump ($var);
6114         }
6115     }
6119 # Get the TRUE value of a variable, warn if the variable is
6120 # conditionally defined.
6121 sub variable_value
6123     my ($var) = @_;
6124     &check_variable_defined_unconditionally ($var);
6125     return $var_value{$var}{'TRUE'};
6129 # @VALUES
6130 # &value_to_list ($VAR, $VAL, $COND)
6131 # ----------------------------------
6132 # Convert a variable value to a list, split as whitespace.  This will
6133 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
6134 # substitutions.
6136 # If COND is 'all', then all values under all conditions should be
6137 # returned; if COND is a particular condition (all conditions are
6138 # surrounded by @...@) then only the value for that condition should
6139 # be returned; otherwise, warn if VAR is conditionally defined.
6140 # SCANNED is a global hash listing whose keys are all the variables
6141 # already scanned; it is an error to rescan a variable.
6142 sub value_to_list
6144     my ($var, $val, $cond) = @_;
6145     my @result;
6147     # Strip backslashes
6148     $val =~ s/\\(\n|$)/ /g;
6150     foreach (split (' ', $val))
6151     {
6152         # If a comment seen, just leave.
6153         last if /^#/;
6155         # Handle variable substitutions.
6156         if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
6157         {
6158             my $varname = $1;
6160             # If the user uses a losing variable name, just ignore it.
6161             # This isn't ideal, but people have requested it.
6162             next if ($varname =~ /\@.*\@/);
6164             my ($from, $to);
6165             my @temp_list;
6166             if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
6167             {
6168                 $varname = $1;
6169                 $to = $3;
6170                 ($from = $2) =~ s/(\W)/\\$1/g;
6171             }
6173             # Find the value.
6174             @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
6176             # Now rewrite the value if appropriate.
6177             if ($from)
6178             {
6179                 grep (s/$from$/$to/, @temp_list);
6180             }
6182             push (@result, @temp_list);
6183         }
6184         else
6185         {
6186             push (@result, $_);
6187         }
6188     }
6190     return @result;
6193 # Return contents of variable as list, split as whitespace.  This will
6194 # recursively follow $(...) and ${...} inclusions.  It preserves @...@
6195 # substitutions.  If COND is 'all', then all values under all
6196 # conditions should be returned; if COND is a particular condition
6197 # (all conditions are surrounded by @...@) then only the value for
6198 # that condition should be returned; otherwise, warn if VAR is
6199 # conditionally defined.  If PARENT is specified, it is the name of
6200 # the including variable; this is only used for error reports.
6201 sub variable_value_as_list_worker
6203     my ($var, $cond, $parent) = @_;
6204     my @result = ();
6206     if (! defined $var_value{$var})
6207     {
6208         if (defined $targets{$var})
6209           {
6210             &am_line_error ($var, "`$var' is a target; expected a variable");
6211           }
6212         else
6213           {
6214             &am_line_error ($parent, "variable `$var' not defined");
6215           }
6216     }
6217     elsif (defined $vars_scanned{$var})
6218     {
6219         # `vars_scanned' is a global we use to keep track of which
6220         # variables we've already examined.
6221         &am_line_error ($parent, "variable `$var' recursively defined");
6222     }
6223     elsif ($cond eq 'all')
6224     {
6225         $vars_scanned{$var} = 1;
6226         foreach my $vcond (keys %{$var_value{$var}})
6227         {
6228             my $val = $var_value{$var}{$vcond};
6229             push (@result, &value_to_list ($var, $val, $cond));
6230         }
6231     }
6232     else
6233     {
6234         $cond ||= 'TRUE';
6235         $vars_scanned{$var} = 1;
6236         my $onceflag;
6237         foreach my $vcond (keys %{$var_value{$var}})
6238         {
6239             my $val = $var_value{$var}{$vcond};
6240             if (&conditional_true_when ($vcond, $cond))
6241             {
6242                 # Warn if we have an ambiguity.  It's hard to know how
6243                 # to handle this case correctly.
6244                 &check_variable_defined_unconditionally ($var, $parent)
6245                     if $onceflag;
6246                 $onceflag = 1;
6247                 push (@result, &value_to_list ($var, $val, $cond));
6248             }
6249         }
6250     }
6252     # Unset our entry in vars_scanned.  We only care about recursive
6253     # definitions.
6254     delete $vars_scanned{$var};
6256     return @result;
6260 # &variable_output ($VAR, [@CONDS])
6261 # ---------------------------------
6262 # Output all the values of $VAR is @COND is not specified, else only
6263 # that corresponding to @COND.
6264 sub variable_output ($@)
6266   my ($var, @conds) = @_;
6268   @conds = sort by_condition keys %{$var_value{$var}}
6269     unless @conds;
6271   $output_vars .= $var_comment{$var}
6272     if defined $var_comment{$var};
6274   foreach my $cond (@conds)
6275     {
6276       my $val = $var_value{$var}{$cond};
6277       my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6278       my $output_var = "$var $equals $val";
6279       $output_var =~ s/^/make_condition ($cond)/meg;
6280       $output_vars .= $output_var . "\n";
6281     }
6285 # &variable_pretty_output ($VAR, [@CONDS])
6286 # ----------------------------------------
6287 # Likewise, but pretty, i.e., we *split* the values at spaces.   Use only
6288 # with variables holding filenames.
6289 sub variable_pretty_output ($@)
6291   my ($var, @conds) = @_;
6293   @conds = sort by_condition keys %{$var_value{$var}}
6294     unless @conds;
6296   $output_vars .= $var_comment{$var}
6297     if defined $var_comment{$var};
6299   foreach my $cond (@conds)
6300     {
6301       my $val = $var_value{$var}{$cond};
6302       my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6303       my $make_condition = make_condition ($cond);
6304       $output_vars .= pretty_print_internal ("$make_condition$var $equals",
6305                                              "$make_condition\t",
6306                                              split (' ' , $val));
6307     }
6311 # This is just a wrapper for variable_value_as_list_worker that
6312 # initializes the global hash `vars_scanned'.  This hash is used to
6313 # avoid infinite recursion.
6314 sub variable_value_as_list
6316     my ($var, $cond, $parent) = @_;
6317     %vars_scanned = ();
6318     return &variable_value_as_list_worker ($var, $cond, $parent);
6322 # Like define_variable, but the value is a list, and the variable may
6323 # be defined conditionally.  The second argument is the conditional
6324 # under which the value should be defined; this should be the empty
6325 # string to define the variable unconditionally.  The third argument
6326 # is a list holding the values to use for the variable.  The value is
6327 # pretty printed in the output file.
6328 sub define_pretty_variable
6330     my ($var, $cond, @value) = @_;
6332     # Beware that an empty $cond has a different semantics for
6333     # macro_define and variable_pretty_output.
6334     $cond ||= 'TRUE';
6336     if (! &variable_defined ($var, $cond))
6337     {
6338         macro_define ($var, 1, '', $cond, join (' ', @value), undef);
6339         variable_pretty_output ($var, $cond || 'TRUE');
6340         $content_seen{$var} = 1;
6341     }
6345 # define_variable ($VAR, $VALUE)
6346 # ------------------------------
6347 # Define a new user variable VAR to VALUE, but only if not already defined.
6348 sub define_variable
6350     my ($var, $value) = @_;
6352     define_pretty_variable ($var, 'TRUE', $value);
6356 # Like define_variable, but define a variable to be the configure
6357 # substitution by the same name.
6358 sub define_configure_variable
6360     my ($var) = @_;
6361     my $value = '@' . $var . '@';
6362     &define_variable ($var, $value);
6366 # define_compiler_variable ($LANG)
6367 # --------------------------------
6368 # Define a compiler variable.  We also handle defining the `LT'
6369 # version of the command when using libtool.
6370 sub define_compiler_variable ($)
6372     my ($lang) = @_;
6374     my ($var, $value) = ($lang->compiler, $lang->compile);
6375     &define_variable ($var, $value);
6376     &define_variable ("LT$var", "\$(LIBTOOL) --mode=compile $value")
6377       if $seen_libtool;
6381 # define_linker_variable ($LANG)
6382 # ------------------------------
6383 # Define linker variables.
6384 sub define_linker_variable ($)
6386     my ($lang) = @_;
6388     my ($var, $value) = ($lang->lder, $lang->ld);
6389     # CCLD = $(CC).
6390     &define_variable ($lang->lder, $lang->ld);
6391     # CCLINK = $(CCLD) blah blah...
6392     &define_variable ($lang->linker,
6393                       (($seen_libtool ? '$(LIBTOOL) --mode=link ' : '')
6394                        . $lang->link));
6397 ################################################################
6399 ## ---------------- ##
6400 ## Handling rules.  ##
6401 ## ---------------- ##
6403 # $BOOL
6404 # rule_define ($TARGET, $IS_AM, $COND, $WHERE)
6405 # --------------------------------------------
6406 # Define a new rule.  $TARGET is the rule name.  $IS_AM is a boolean
6407 # which is true if the new rule is defined by the user.  $COND is the
6408 # condition under which the rule is defined.  $WHERE is where the rule
6409 # is defined (file name or line number).  Returns true if it is ok to
6410 # define the rule, false otherwise.
6411 sub rule_define ($$$$)
6413   my ($target, $rule_is_am, $cond, $where) = @_;
6415   # For now `foo:' will override `foo$(EXEEXT):'.  This is temporary,
6416   # though, so we emit a warning.
6417   (my $noexe = $target) =~ s,\$\(EXEEXT\)$,,;
6418   if ($noexe ne $target && defined $targets{$noexe})
6419   {
6420       # The no-exeext option enables this feature.
6421       if (! defined $options{'no-exeext'})
6422       {
6423           &am_line_error ($noexe,
6424                           "deprecated feature: `$noexe' overrides `$noexe\$(EXEEXT)'\nchange your target to read `$noexe\$(EXEEXT)'");
6425       }
6426       # Don't define.
6427       return 0;
6428   }
6430   if (defined $targets{$target}
6431       && ($cond
6432           ? ! defined $target_conditional{$target}
6433           : defined $target_conditional{$target}))
6434   {
6435       &am_line_error ($target,
6436                       "$target defined both conditionally and unconditionally");
6437   }
6439   # Value here doesn't matter; for targets we only note existence.
6440   $targets{$target} = $where;
6441   if ($cond)
6442   {
6443       if ($target_conditional{$target})
6444       {
6445           &check_ambiguous_conditional ($target, $cond);
6446       }
6447       $target_conditional{$target}{$cond} = $where;
6448   }
6451   # Check the rule for being a suffix rule. If so, store in a hash.
6453   if ((my ($source_suffix, $object_suffix)) = ($target =~ $SUFFIX_RULE_PATTERN))
6454   {
6455       $suffix_rules{$source_suffix} = $object_suffix;
6456       print "Sources ending in .$source_suffix become .$object_suffix\n"
6457           if $verbose;
6458       # Set SUFFIXES from suffix_rules.
6459       push @suffixes, ".$source_suffix", ".$object_suffix";
6460   }
6462   return 1;
6466 # See if a target exists.
6467 sub target_defined
6469     my ($target) = @_;
6470     return defined $targets{$target};
6474 ################################################################
6476 # Read Makefile.am and set up %contents.  Simultaneously copy lines
6477 # from Makefile.am into $output_trailer or $output_vars as
6478 # appropriate.  NOTE we put rules in the trailer section.  We want
6479 # user rules to come after our generated stuff.
6480 sub read_am_file
6482     my ($amfile) = @_;
6484     my $am_file = new IO::File ("< $amfile");
6485     if (! $am_file)
6486     {
6487         die "$me: couldn't open `$amfile': $!\n";
6488     }
6489     print "$me: reading $amfile\n" if $verbose;
6491     my $spacing = '';
6492     my $comment = '';
6493     my $blank = 0;
6495     while ($_ = $am_file->getline)
6496     {
6497         if (/$IGNORE_PATTERN/o)
6498         {
6499             # Merely delete comments beginning with two hashes.
6500         }
6501         elsif (/$WHITE_PATTERN/o)
6502         {
6503             # Stick a single white line before the incoming macro or rule.
6504             $spacing = "\n";
6505             $blank = 1;
6506         }
6507         elsif (/$COMMENT_PATTERN/o)
6508         {
6509             # Stick comments before the incoming macro or rule.  Make
6510             # sure a blank line preceeds first block of comments.
6511             $spacing = "\n" unless $blank;
6512             $blank = 1;
6513             $comment .= $spacing . $_;
6514             $spacing = '';
6515         }
6516         else
6517         {
6518             last;
6519         }
6520     }
6522     $output_vars .= $comment . "\n";
6523     $comment = '';
6524     $spacing = "\n";
6526     # We save the conditional stack on entry, and then check to make
6527     # sure it is the same on exit.  This lets us conditonally include
6528     # other files.
6529     my @saved_cond_stack = @cond_stack;
6530     my $cond = conditional_string (@cond_stack);
6532     my $saw_bk = 0;
6533     my $was_rule = 0;
6534     my $last_var_name = '';
6535     my $last_var_type = '';
6536     my $last_var_value = '';
6537     # FIXME: shouldn't use $_ in this loop; it is too big.
6538     while ($_)
6539     {
6540         $_ .= "\n"
6541             unless substr ($_, -1, 1) eq "\n";
6543         # Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
6544         # used by users.  @MAINT@ is an anachronism now.
6545         $_ =~ s/\@MAINT\@//g
6546             unless $seen_maint_mode;
6548         my $new_saw_bk = /\\$/ && ! /$COMMENT_PATTERN/o;
6550         if (/$IGNORE_PATTERN/o)
6551         {
6552             # Merely delete comments beginning with two hashes.
6553         }
6554         elsif (/$WHITE_PATTERN/o)
6555         {
6556             # Stick a single white line before the incoming macro or rule.
6557             $spacing = "\n";
6558             &am_line_error ($., "blank line following trailing backslash")
6559                 if $saw_bk;
6560         }
6561         elsif (/$COMMENT_PATTERN/o)
6562         {
6563             # Stick comments before the incoming macro or rule.
6564             $comment .= $spacing . $_;
6565             $spacing = '';
6566             &am_line_error ($., "comment following trailing backslash")
6567                 if $saw_bk;
6568         }
6569         elsif ($saw_bk)
6570         {
6571             if ($was_rule)
6572             {
6573                 $output_trailer .= &make_condition (@cond_stack);
6574                 $output_trailer .= $_;
6575             }
6576             else
6577             {
6578               $last_var_value .= ' '
6579                 unless $last_var_value =~ /\s$/;
6580               $last_var_value .= $_;
6582               if (!/\\$/)
6583                 {
6584                   $var_comment{$last_var_name} .= "$spacing"
6585                     if (!defined $var_comment{$last_var_name}
6586                         || substr ($var_comment{$last_var_name}, -1) ne "\n");
6587                   $var_comment{$last_var_name} .= "$comment";
6588                   $comment = $spacing = '';
6589                   macro_define ($last_var_name, 0,
6590                                 $last_var_type, $cond,
6591                                 $last_var_value, $.)
6592                     if $cond ne 'FALSE';
6593                   push (@var_list, $last_var_name);
6594                 }
6595             }
6596         }
6598         elsif (/$IF_PATTERN/o)
6599           {
6600             $cond = cond_stack_if ($1, $2, "$amfile:$.");
6601           }
6602         elsif (/$ELSE_PATTERN/o)
6603           {
6604             $cond = cond_stack_else ($1, $2, "$amfile:$.");
6605           }
6606         elsif (/$ENDIF_PATTERN/o)
6607           {
6608             $cond = cond_stack_endif ($1, $2, "$amfile:$.");
6609           }
6611         elsif (/$RULE_PATTERN/o)
6612         {
6613             # Found a rule.
6614             $was_rule = 1;
6616             rule_define ($1, 0, $cond, $.);
6618             $var_line{$1} = $.;
6619             $output_trailer .= $comment . $spacing;
6620             $output_trailer .= &make_condition (@cond_stack);
6621             $output_trailer .= $_;
6622             $comment = $spacing = '';
6623         }
6624         elsif (/$ASSIGNMENT_PATTERN/o)
6625         {
6626             # Found a macro definition.
6627             $was_rule = 0;
6628             $last_var_name = $1;
6629             $last_var_type = $2;
6630             $last_var_value = $3;
6631             if ($3 ne '' && substr ($3, -1) eq "\\")
6632             {
6633                 # We preserve the `\' because otherwise the long lines
6634                 # that are generated will be truncated by broken
6635                 # `sed's.
6636                 $last_var_value = $3 . "\n";
6637             }
6639             if (!/\\$/)
6640               {
6641                 # FIXME: this doesn't always work correctly; it will
6642                 # group all comments for a given variable, no matter
6643                 # where defined.
6644                 # Accumulating variables must not be output.
6645                 $var_comment{$last_var_name} .= "$spacing"
6646                   if (!defined $var_comment{$last_var_name}
6647                       || substr ($var_comment{$last_var_name}, -1) ne "\n");
6648                 $var_comment{$last_var_name} .= "$comment";
6649                 $comment = $spacing = '';
6651                 macro_define ($last_var_name, 0,
6652                               $last_var_type, $cond,
6653                               $last_var_value, $.)
6654                   if $cond ne 'FALSE';
6655                 push (@var_list, $last_var_name);
6656               }
6657         }
6658         elsif (/$INCLUDE_PATTERN/o)
6659         {
6660             my $path = $1;
6662             if ($path =~ s/^\$\(top_srcdir\)\///)
6663             {
6664                 push (@include_stack, "\$\(top_srcdir\)/$path");
6665             }
6666             else
6667             {
6668                 $path =~ s/\$\(srcdir\)\///;
6669                 push (@include_stack, "\$\(srcdir\)/$path");
6670                 $path = $relative_dir . "/" . $path;
6671             }
6672             &read_am_file ($path);
6673         }
6674         else
6675         {
6676             # This isn't an error; it is probably a continued rule.
6677             # In fact, this is what we assume.
6678             $was_rule = 1;
6679             $output_trailer .= $comment . $spacing;
6680             $output_trailer .= &make_condition  (@cond_stack);
6681             $output_trailer .= $_;
6682             $comment = $spacing = '';
6683             &am_line_error ($., "`#' comment at start of rule is unportable")
6684                 if $_ =~ /^\t\s*\#/;
6685         }
6687         $saw_bk = $new_saw_bk;
6688         $_ = $am_file->getline;
6689     }
6691     $output_trailer .= $comment;
6693     if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
6694     {
6695         if (@cond_stack)
6696         {
6697             &am_error ("unterminated conditionals: @cond_stack");
6698         }
6699         else
6700         {
6701             # FIXME: better error message here.
6702             &am_error ("conditionals not nested in include file");
6703         }
6704     }
6708 # define_standard_variables ()
6709 # ----------------------------
6710 # A helper for read_main_am_file which initializes configure variables
6711 # and variables from header-vars.am.  This is a subr so we can call it
6712 # twice.
6713 sub define_standard_variables
6715     my $saved_output_vars = $output_vars;
6716     my ($comments, undef, $rules) =
6717       file_contents_internal (1, "$libdir/am/header-vars.am");
6719     # This will output the definitions in $output_vars, which we don't
6720     # want...
6721     foreach my $var (sort keys %configure_vars)
6722     {
6723         &define_configure_variable ($var);
6724         push (@var_list, $var);
6725     }
6727     # ... hence, we restore $output_vars.
6728     $output_vars = $saved_output_vars . $comments . $rules;
6731 # Read main am file.
6732 sub read_main_am_file
6734     my ($amfile) = @_;
6736     # This supports the strange variable tricks we are about to play.
6737     if (scalar keys %var_value > 0)
6738       {
6739         macros_dump ();
6740         &prog_error ("variable defined before read_main_am_file");
6741       }
6743     # Generate copyright header for generated Makefile.in.
6744     # We do discard the output of predefined variables, handled below.
6745     $output_vars = ("# $in_file_name generated automatically by automake "
6746                    . $VERSION . " from $am_file_name.\n");
6747     $output_vars .= $gen_copyright;
6749     # We want to predefine as many variables as possible.  This lets
6750     # the user set them with `+=' in Makefile.am.  However, we don't
6751     # want these initial definitions to end up in the output quite
6752     # yet.  So we just load them, but output them later.
6753     &define_standard_variables;
6755     # Read user file, which might override some of our values.
6756     &read_am_file ($amfile);
6758     # Ouput all the Automake variables.  If the user changed one, then
6759     # it is now marked as owned by the user.
6760     foreach my $var (uniq @var_list)
6761     {
6762         # Don't process user variables.
6763         variable_output ($var)
6764           unless !$var_is_am{$var};
6765     }
6767     # Now dump the user variables that were defined.  We do it in the same
6768     # order in which they were defined (skipping duplicates).
6769     foreach my $var (uniq @var_list)
6770     {
6771         # Don't process Automake variables.
6772         variable_output ($var)
6773           unless $var_is_am{$var};
6774     }
6777 ################################################################
6779 # $FLATTENED
6780 # &flatten ($STRING)
6781 # ------------------
6782 # Flatten the $STRING and return the result.
6783 sub flatten
6785   $_ = shift;
6787   s/\\\n//somg;
6788   s/\s+/ /g;
6789   s/^ //;
6790   s/ $//;
6792   return $_;
6796 # @PARAGRAPHS
6797 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
6798 # ------------------------------------------
6799 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6800 # paragraphs.
6801 sub make_paragraphs ($%)
6803     my ($file, %transform) = @_;
6805     # Complete %transform with global options and make it a Perl
6806     # $command.
6807     my $command =
6808       "s/$IGNORE_PATTERN//gm;"
6809         . transform (%transform,
6811                      'CYGNUS'          => $cygnus_mode,
6812                      'MAINTAINER-MODE'
6813                      => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
6815                      'SHAR'        => $options{'dist-shar'} || 0,
6816                      'BZIP2'       => $options{'dist-bzip2'} || 0,
6817                      'ZIP'         => $options{'dist-zip'} || 0,
6818                      'COMPRESS'    => $options{'dist-tarZ'} || 0,
6820                      'INSTALL-INFO' => !$options{'no-installinfo'},
6821                      'INSTALL-MAN'  => !$options{'no-installman'},
6822                      'CK-NEWS'      => $options{'check-news'} || 0,
6824                      'SUBDIRS'      => &variable_defined ('SUBDIRS'),
6825                      'TOPDIR'       => backname ($relative_dir),
6826                      'TOPDIR_P'     => $relative_dir eq '.',
6827                      'CONFIGURE-AC' => $configure_ac,
6829                      'BUILD'    => $seen_canonical == $AC_CANONICAL_SYSTEM,
6830                      'HOST'     => $seen_canonical,
6831                      'TARGET'   => $seen_canonical == $AC_CANONICAL_SYSTEM,
6833                      'LIBTOOL'      => defined $configure_vars{'LIBTOOL'})
6834           # We don't need more than two consecutive new-lines.
6835           . 's/\n{3,}/\n\n/g';
6837     # Swallow the file and apply the COMMAND.
6838     my $fc_file = new IO::File ("< $file");
6839     if (! $fc_file)
6840     {
6841         die "$me: installation error: cannot open `$file'\n";
6842     }
6843     # Looks stupid?
6844     print "$me: reading $file\n"
6845       if $verbose;
6846     my $saved_dollar_slash = $/;
6847     undef $/;
6848     $_ = $fc_file->getline;
6849     $/ = $saved_dollar_slash;
6850     eval $command;
6851     $fc_file->close;
6852     my $content = $_;
6854     # Split at unescaped new lines.
6855     my @lines = split (/(?<!\\)\n/, $content);
6856     my @res;
6858     while (defined ($_ = shift @lines))
6859       {
6860         my $paragraph = "$_";
6861         # If we are a rule, eat as long as we start with a tab.
6862         if (/$RULE_PATTERN/smo)
6863           {
6864             while (defined ($_ = shift @lines) && $_ =~ /^\t/)
6865               {
6866                 $paragraph .= "\n$_";
6867               }
6868             unshift (@lines, $_);
6869           }
6871         # If we are a comments, eat as much comments as you can.
6872         elsif (/$COMMENT_PATTERN/smo)
6873           {
6874             while (defined ($_ = shift @lines)
6875                    && $_ =~ /$COMMENT_PATTERN/smo)
6876               {
6877                 $paragraph .= "\n$_";
6878               }
6879             unshift (@lines, $_);
6880           }
6882         push @res, $paragraph;
6883         $paragraph = '';
6884       }
6886     return @res;
6891 # ($COMMENT, $VARIABLES, $RULES)
6892 # &file_contents_internal ($IS_AM, $FILE, [%TRANSFORM])
6893 # -----------------------------------------------------
6894 # Return contents of a file from $libdir/am, automatically skipping
6895 # macros or rules which are already known. $IS_AM iff the caller is
6896 # reading an Automake file (as opposed to the user's Makefile.am).
6897 sub file_contents_internal ($$%)
6899     my ($is_am, $file, %transform) = @_;
6901     my $result_vars = '';
6902     my $result_rules = '';
6903     my $comment = '';
6904     my $spacing = '';
6906     # We save the conditional stack on entry, and then check to make
6907     # sure it is the same on exit.  This lets us conditonally include
6908     # other files.
6909     my @saved_cond_stack = @cond_stack;
6910     my $cond = conditional_string (@cond_stack);
6912     foreach (make_paragraphs ($file, %transform))
6913     {
6914         # Sanity checks.
6915         &am_file_error ($file, "blank line following trailing backslash:\n$_")
6916           if /\\$/;
6917         &am_file_error ($file, "comment following trailing backslash:\n$_")
6918           if /\\#/;
6920         if (/^$/)
6921         {
6922             # Stick empty line before the incoming macro or rule.
6923             $spacing = "\n";
6924         }
6925         elsif (/$COMMENT_PATTERN/mso)
6926         {
6927             # Stick comments before the incoming macro or rule.
6928             $comment = "$_\n";
6929         }
6931         # Handle inclusion of other files.
6932         elsif (/$INCLUDE_PATTERN/o)
6933         {
6934             if ($cond ne 'FALSE')
6935               {
6936                 my $file = ($is_am ? "$libdir/am/" : '') . $1;
6937                 # N-ary `.=' fails.
6938                 my ($com, $vars, $rules)
6939                   = file_contents_internal ($is_am, $file, %transform);
6940                 $comment .= $com;
6941                 $result_vars .= $vars;
6942                 $result_rules .= $rules;
6943               }
6944         }
6946         # Handling the conditionals.
6947         elsif (/$IF_PATTERN/o)
6948           {
6949             $cond = cond_stack_if ($1, $2, $file);
6950           }
6951         elsif (/$ELSE_PATTERN/o)
6952           {
6953             $cond = cond_stack_else ($1, $2, $file);
6954           }
6955         elsif (/$ENDIF_PATTERN/o)
6956           {
6957             $cond = cond_stack_endif ($1, $2, $file);
6958           }
6960         # Handling rules.
6961         elsif (/$RULE_PATTERN/mso)
6962         {
6963           # Separate relationship from optional actions: the first
6964           # `new-line tab" not preceded by backslash (continuation
6965           # line).
6966           # I'm quite shoked!  It seems that (\\\n|[^\n]) is not the
6967           # same as `([^\n]|\\\n)!!!  Don't swap it, it breaks.
6968           my $paragraph = $_;
6969           /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
6970           my ($relationship, $actions) = ($1, $2 || '');
6972           # Separate targets from dependencies: the first colon.
6973           $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
6974           my ($targets, $dependencies) = ($1, $2);
6975           # Remove the escaped new lines.
6976           # I don't know why, but I have to use a tmp $flat_deps.
6977           my $flat_deps = &flatten ($dependencies);
6978           my @deps = split (' ', $flat_deps);
6980           foreach (split (' ' , $targets))
6981             {
6982               # FIXME: We are not robust to people defining several targets
6983               # at once, only some of them being in %dependencies.
6985               # Output only if not in FALSE.
6986               if (defined $dependencies{$_}
6987                   && $cond ne 'FALSE')
6988                 {
6989                   &depend ($_, @deps);
6990                   $actions{$_} .= $actions;
6991                 }
6992               else
6993                 {
6994                   # Free lance dependency.  Output the rule for all the
6995                   # targets instead of one by one.
6996                   if (!defined $targets{$targets}
6997                       && $cond ne 'FALSE')
6998                     {
6999                       $paragraph =~ s/^/make_condition (@cond_stack)/gme;
7000                       $result_rules .= "$spacing$comment$paragraph\n"
7001                           if rule_define ($targets, $is_am, $cond, $file);
7002                     }
7003                   $comment = $spacing = '';
7004                   last;
7005                 }
7006             }
7007         }
7009         elsif (/$ASSIGNMENT_PATTERN/mso)
7010         {
7011             my ($var, $type, $val) = ($1, $2, $3);
7012             &am_file_error ($file, "macro `$var' with trailing backslash")
7013               if /\\$/;
7015             # Accumulating variables must not be output.
7016             $var_comment{$var} .= "$spacing"
7017               if (!defined $var_comment{$var}
7018                   || substr ($var_comment{$var}, -1) ne "\n");
7019             $var_comment{$var} .= "$comment";
7020             macro_define ($var, $is_am, $type, $cond, $val, $file)
7021               if $cond ne 'FALSE';
7022             push (@var_list, $var);
7024             # If the user has set some variables we were in charge
7025             # of (which is detected by the first reading of
7026             # `header-vars.am'), we must not output them.
7027             $result_vars .= "$spacing$comment$_\n"
7028               if $type ne '+' && $var_is_am{$var} && $cond ne 'FALSE';
7030             $comment = $spacing = '';
7031         }
7032         else
7033         {
7034             # This isn't an error; it is probably some tokens which
7035             # configure is supposed to replace, such as `@SET-MAKE@',
7036             # or some part of a rule cut by an if/endif.
7037             if ($cond ne 'FALSE')
7038               {
7039                 s/^/make_condition (@cond_stack)/gme;
7040                 $result_rules .= "$spacing$comment$_\n";
7041               }
7042             $comment = $spacing = '';
7043         }
7044     }
7046     if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
7047     {
7048         if (@cond_stack)
7049         {
7050             &am_error ("unterminated conditionals: @cond_stack");
7051         }
7052         else
7053         {
7054             # FIXME: better error message here.
7055             &am_error ("conditionals not nested in include file");
7056         }
7057     }
7059     return ($comment, $result_vars, $result_rules);
7063 # $CONTENTS
7064 # &file_contents ($BASENAME, [%TRANSFORM])
7065 # ----------------------------------------
7066 # Return contents of a file from $libdir/am, automatically skipping
7067 # macros or rules which are already known.
7068 sub file_contents ($%)
7070     my ($basename, %transform) = @_;
7071     my ($comments, $variables, $rules) =
7072       file_contents_internal (1, "$libdir/am/$basename.am", %transform);
7073     return "$comments$variables$rules";
7077 # $REGEXP
7078 # &transform (%PAIRS)
7079 # -------------------
7080 # Foreach ($TOKEN, $VAL) in %PAIRS produce a replacement expression suitable
7081 # for file_contents which:
7082 #   - replaces @$TOKEN@ with $VALUE,
7083 #   - enables/disables ?$TOKEN?.
7084 sub transform (%)
7086     my (%pairs) = @_;
7087     my $result = '';
7089     while (my ($token, $val) = each %pairs)
7090     {
7091         $result .= "s/\Q%$token%\E/\Q$val\E/gm;";
7092         if ($val)
7093         {
7094             $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
7095             $result .= "s/\Q%?$token%\E/TRUE/gm;";
7096         }
7097         else
7098         {
7099             $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
7100             $result .= "s/\Q%?$token%\E/FALSE/gm;";
7101         }
7102     }
7104     return $result;
7108 # Find all variable prefixes that are used for install directories.  A
7109 # prefix `zar' qualifies iff:
7110 # * `zardir' is a variable.
7111 # * `zar_PRIMARY' is a variable.
7112 sub am_primary_prefixes
7114     my ($primary, $can_dist, @prefixes) = @_;
7116     my %valid = map { $_ => 0 } @prefixes;
7117     $valid{'EXTRA'} = 0;
7118     foreach my $varname (keys %var_value)
7119     {
7120         # Automake is allowed to define variables that look like they
7121         # are magic variables, such as INSTALL_DATA.
7122         next
7123           if $var_is_am{$varname};
7125         if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
7126         {
7127             my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
7128             if ($dist ne '' && ! $can_dist)
7129             {
7130                 # Note that a configure variable is always legitimate.
7131                 # It is natural to name such variables after the
7132                 # primary, so we explicitly allow it.
7133                 if (! defined $configure_vars{$varname})
7134                 {
7135                     &am_line_error ($varname,
7136                                     "invalid variable `$varname': `dist' is forbidden");
7137                 }
7138             }
7139             elsif (! defined $valid{$X} && ! &variable_defined ("${X}dir"))
7140             {
7141                 # Note that a configure variable is always legitimate.
7142                 # It is natural to name such variables after the
7143                 # primary, so we explicitly allow it.
7144                 if (! defined $configure_vars{$varname})
7145                 {
7146                     &am_line_error ($varname,
7147                                     "invalid variable `$varname'");
7148                 }
7149             }
7150             else
7151             {
7152                 # Ensure all extended prefixes are actually used.
7153                 $valid{"$base$dist$X"} = 1;
7154             }
7155         }
7156     }
7158     return %valid;
7161 # Handle `where_HOW' variable magic.  Does all lookups, generates
7162 # install code, and possibly generates code to define the primary
7163 # variable.  The first argument is the name of the .am file to munge,
7164 # the second argument is the primary variable (eg HEADERS), and all
7165 # subsequent arguments are possible installation locations.  Returns
7166 # list of all values of all _HOW targets.
7168 # FIXME: this should be rewritten to be cleaner.  It should be broken
7169 # up into multiple functions.
7171 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7172 sub am_install_var
7174     my (@args) = @_;
7176     my $do_require = 1;
7177     my $can_dist = 0;
7178     my $default_dist = 0;
7179     while (@args)
7180     {
7181         if ($args[0] eq '-noextra')
7182         {
7183             $do_require = 0;
7184         }
7185         elsif ($args[0] eq '-candist')
7186         {
7187             $can_dist = 1;
7188         }
7189         elsif ($args[0] eq '-defaultdist')
7190         {
7191             $default_dist = 1;
7192             $can_dist = 1;
7193         }
7194         elsif ($args[0] !~ /^-/)
7195         {
7196             last;
7197         }
7198         shift (@args);
7199     }
7201     my ($file, $primary, @prefixes) = @args;
7203     # Now that configure substitutions are allowed in where_HOW
7204     # variables, it is an error to actually define the primary.  We
7205     # allow `JAVA', as it is customarily used to mean the Java
7206     # interpreter.  This is but one of several Java hacks.  Similarly,
7207     # `PYTHON' is customarily used to mean the Python interpreter.
7208     &am_line_error ($primary, "`$primary' is an anachronism")
7209         if &variable_defined ($primary)
7210             && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7213     # Look for misspellings.  It is an error to have a variable ending
7214     # in a "reserved" suffix whose prefix is unknown, eg
7215     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
7216     # variable of the same name (with "dir" appended) exists.  For
7217     # instance, if the variable "zardir" is defined, then
7218     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
7219     # flexibility in those cases which need it.
7220     my %valid = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7222     # If a primary includes a configure substitution, then the EXTRA_
7223     # form is required.  Otherwise we can't properly do our job.
7224     my $require_extra;
7225     my $warned_about_extra = 0;
7227     my @used = ();
7228     my @result = ();
7230     # True if the iteration is the first one.  Used for instance to
7231     # output parts of the associated file only once.
7232     my $first = 1;
7233     foreach my $X (sort keys %valid)
7234     {
7235         my $one_name = $X . '_' . $primary;
7236         next
7237           unless (&variable_defined ($one_name));
7239         my $strip_subdir = 1;
7240         # If subdir prefix should be preserved, do so.
7241         if ($X =~ /^nobase_/)
7242           {
7243             $strip_subdir = 0;
7244             $X =~ s/^nobase_//;
7245           }
7247         my $nodir_name = $X;
7248         # If files should be distributed, do so.
7249         my $dist_p = 0;
7250         if ($can_dist)
7251           {
7252             $dist_p = (($default_dist && $one_name !~ /^nodist_/)
7253                        || (! $default_dist && $one_name =~ /^dist_/));
7254             $nodir_name =~ s/^(dist|nodist)_//;
7255           }
7257         # Append actual contents of where_PRIMARY variable to
7258         # result.
7259         foreach my $rcurs (&variable_value_as_list ($one_name, 'all'))
7260           {
7261             # Skip configure substitutions.  Possibly bogus.
7262             if ($rcurs =~ /^\@.*\@$/)
7263               {
7264                 if ($X eq 'EXTRA')
7265                   {
7266                     if (! $warned_about_extra)
7267                       {
7268                         $warned_about_extra = 1;
7269                         &am_line_error ($one_name,
7270                                         "`$one_name' contains configure substitution, but shouldn't");
7271                       }
7272                   }
7273                 # Check here to make sure variables defined in
7274                 # configure.ac do not imply that EXTRA_PRIMARY
7275                 # must be defined.
7276                 elsif (! defined $configure_vars{$one_name})
7277                   {
7278                     $require_extra = $one_name
7279                       if $do_require;
7280                   }
7282                 next;
7283               }
7285             push (@result, $rcurs);
7286           }
7288         # A blatant hack: we rewrite each _PROGRAMS primary to include
7289         # EXEEXT.
7290         if ($primary eq 'PROGRAMS')
7291         {
7292             my @conds = &variable_conditions ($one_name);
7294             my @condvals;
7295             foreach my $cond (@conds)
7296             {
7297                 my @one_binlist = ();
7298                 my @condval = &variable_value_as_list ($one_name,
7299                                                        $cond);
7300                 foreach my $rcurs (@condval)
7301                 {
7302                     # Skip autoconf substs.  Also skip if the user
7303                     # already applied $(EXEEXT).
7304                     if ($rcurs =~ /^\@.*\@$/ || $rcurs =~ /\$\(EXEEXT\)$/)
7305                     {
7306                         push (@one_binlist, $rcurs);
7307                     }
7308                     else
7309                     {
7310                         push (@one_binlist, $rcurs . '$(EXEEXT)');
7311                     }
7312                 }
7314                 push (@condvals, $cond);
7315                 push (@condvals, join (' ', @one_binlist));
7316             }
7318             variable_delete ($one_name);
7319             while (@condvals)
7320             {
7321                 my $cond = shift (@condvals);
7322                 my @val = split (' ', shift (@condvals));
7323                 &define_pretty_variable ($one_name, $cond, @val);
7324             }
7325         }
7327         # "EXTRA" shouldn't be used when generating clean targets,
7328         # all, or install targets.
7329         if ($X eq 'EXTRA')
7330           {
7331             # We used to warn if EXTRA_FOO was defined uselessly,
7332             # but this was annoying.
7333             next;
7334           }
7336         if ($X eq 'check')
7337           {
7338             push (@check, '$(' . $one_name . ')');
7339           }
7340         else
7341           {
7342             push (@used, '$(' . $one_name . ')');
7343           }
7345         # Is this to be installed?
7346         my $install_p = $X ne 'noinst' && $X ne 'check';
7348         # If so, with install-exec? (or install-data?).
7349         my $exec_p = (defined $exec_dir_p {$X}
7350                       ? $exec_dir_p {$X}
7351                       : ($X =~ /exec/));
7353         # Singular form of $PRIMARY.
7354         (my $one_primary = $primary) =~ s/S$//;
7355         $output_rules .= &file_contents ($file,
7356                                          ('FIRST' => $first,
7358                                           'PRIMARY'     => $primary,
7359                                           'ONE_PRIMARY' => $one_primary,
7360                                           'DIR'         => $X,
7361                                           'NDIR'        => $nodir_name,
7362                                           'BASE'        => $strip_subdir,
7364                                           'EXEC'    => $exec_p,
7365                                           'INSTALL' => $install_p,
7366                                           'DIST'    => $dist_p));
7368         $first = 0;
7369     }
7371     # The JAVA variable is used as the name of the Java interpreter.
7372     # The PYTHON variable is used as the name of the Python interpreter.
7373     if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7374     {
7375         # Define it.
7376         &define_pretty_variable ($primary, '', @used);
7377         $output_vars .= "\n";
7378     }
7380     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7381     {
7382         &am_line_error ($require_extra,
7383                         "`$require_extra' contains configure substitution, but `EXTRA_$primary' not defined");
7384     }
7386     # Push here because PRIMARY might be configure time determined.
7387     push (@all, '$(' . $primary . ')')
7388         if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7390     # Make the result unique.  This lets the user use conditionals in
7391     # a natural way, but still lets us program lazily -- we don't have
7392     # to worry about handling a particular object more than once.
7393     return uniq (sort @result);
7397 ################################################################
7399 # Each key in this hash is the name of a directory holding a
7400 # Makefile.in.  These variables are local to `is_make_dir'.
7401 my %make_dirs = ();
7402 my $make_dirs_set = 0;
7404 sub is_make_dir
7406     my ($dir) = @_;
7407     if (! $make_dirs_set)
7408     {
7409         foreach my $iter (@configure_input_files)
7410         {
7411             $make_dirs{dirname ($iter)} = 1;
7412         }
7413         # We also want to notice Makefile.in's.
7414         foreach my $iter (@other_input_files)
7415         {
7416             if ($iter =~ /Makefile\.in$/)
7417             {
7418                 $make_dirs{dirname ($iter)} = 1;
7419             }
7420         }
7421         $make_dirs_set = 1;
7422     }
7423     return defined $make_dirs{$dir};
7426 ################################################################
7428 # This variable is local to the "require file" set of functions.
7429 my @require_file_paths = ();
7431 # If a file name appears as a key in this hash, then it has already
7432 # been checked for.  This variable is local to the "require file"
7433 # functions.
7434 %require_file_found = ();
7436 # See if we want to push this file onto dist_common.  This function
7437 # encodes the rules for deciding when to do so.
7438 sub maybe_push_required_file
7440     my ($dir, $file, $fullfile) = @_;
7442     if ($dir eq $relative_dir)
7443     {
7444         &push_dist_common ($file);
7445     }
7446     elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7447     {
7448         # If we are doing the topmost directory, and the file is in a
7449         # subdir which does not have a Makefile, then we distribute it
7450         # here.
7451         &push_dist_common ($fullfile);
7452     }
7456 # &require_file_internal ($IS_CONFIGURE, $LINE, $MYSTRICT, @FILES)
7457 # ----------------------------------------------------------------
7458 # Verify that the file must exist in the current directory.
7459 # $MYSTRICT is the strictness level at which this file becomes required.
7461 # Must set require_file_paths before calling this function.
7462 # require_file_paths is set to hold a single directory (the one in
7463 # which the first file was found) before return.
7464 sub require_file_internal
7466     my ($is_configure, $line, $mystrict, @files) = @_;
7468     foreach my $file (@files)
7469     {
7470         my $fullfile;
7471         my $errdir;
7472         my $errfile;
7473         my $save_dir;
7475         my $found_it = 0;
7476         my $dangling_sym = 0;
7477         foreach my $dir (@require_file_paths)
7478         {
7479             $fullfile = $dir . "/" . $file;
7480             $errdir = $dir unless $errdir;
7482             # Use different name for "error filename".  Otherwise on
7483             # an error the bad file will be reported as eg
7484             # `../../install-sh' when using the default
7485             # config_aux_path.
7486             $errfile = $errdir . '/' . $file;
7488             if (-l $fullfile && ! -f $fullfile)
7489             {
7490                 $dangling_sym = 1;
7491                 last;
7492             }
7493             elsif (-f $fullfile)
7494             {
7495                 $found_it = 1;
7496                 &maybe_push_required_file ($dir, $file, $fullfile);
7497                 $save_dir = $dir;
7498                 last;
7499             }
7500         }
7502         # `--force-missing' only has an effect if `--add-missing' is
7503         # specified.
7504         if ($found_it && (! $add_missing || ! $force_missing))
7505         {
7506             # Prune the path list.
7507             @require_file_paths = $save_dir;
7508         }
7509         else
7510         {
7511             # If we've already looked for it, we're done.  You might
7512             # wonder why we don't do this before searching for the
7513             # file.  If we do that, then something like
7514             # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
7515             # DIST_COMMON.
7516             if (! $found_it)
7517             {
7518                 next if defined $require_file_found{$file};
7519                 $require_file_found{$file} = 1;
7520             }
7522             if ($strictness >= $mystrict)
7523             {
7524                 if ($dangling_sym && $add_missing)
7525                 {
7526                     unlink ($fullfile);
7527                 }
7529                 my $trailer = '';
7530                 my $suppress = 0;
7532                 # Only install missing files according to our desired
7533                 # strictness level.
7534                 my $message = "required file `$errfile' not found";
7535                 if ($add_missing)
7536                 {
7537                     $suppress = 1;
7539                     # Maybe run libtoolize.
7540                     my @syslist = ('libtoolize', '--automake');
7541                     push @syslist, '--copy'
7542                         if $copy_missing;
7543                     if ($seen_libtool
7544                         && grep ($_ eq $file, @libtoolize_files)
7545                         && system (@syslist))
7546                     {
7547                         $message = "installing `$errfile'";
7548                         $suppress = 0;
7549                         $trailer = "; cannot run `libtoolize': $!";
7550                     }
7551                     elsif (-f ("$libdir/$file"))
7552                     {
7553                         # Install the missing file.  Symlink if we
7554                         # can, copy if we must.  Note: delete the file
7555                         # first, in case it is a dangling symlink.
7556                         $message = "installing `$errfile'";
7557                         # Windows Perl will hang if we try to delete a
7558                         # file that doesn't exist.
7559                         unlink ($errfile) if -f $errfile;
7560                         if ($symlink_exists && ! $copy_missing)
7561                         {
7562                             if (! symlink ("$libdir/$file", $errfile))
7563                             {
7564                                 $suppress = 0;
7565                                 $trailer = "; error while making link: $!";
7566                             }
7567                         }
7568                         elsif (system ('cp', "$libdir/$file", $errfile))
7569                         {
7570                             $suppress = 0;
7571                             $trailer = "\n    error while copying";
7572                         }
7573                     }
7575                     &maybe_push_required_file (dirname ($errfile),
7576                                                $file, $errfile);
7578                     # Prune the path list.
7579                     @require_file_paths = &dirname ($errfile);
7580                 }
7582                 # If --force-missing was specified, and we have
7583                 # actually found the file, then do nothing.
7584                 next
7585                     if $found_it && $force_missing;
7587                 if ($suppress)
7588                 {
7589                     if ($is_configure)
7590                     {
7591                         # FIXME: allow actual file to be specified.
7592                         &am_conf_line_warning ($configure_ac, $line,
7593                                                "$message$trailer");
7594                     }
7595                     else
7596                     {
7597                         &am_line_warning ($line, "$message$trailer");
7598                     }
7599                 }
7600                 else
7601                 {
7602                     if ($is_configure)
7603                     {
7604                         # FIXME: allow actual file to be specified.
7605                         &am_conf_line_error ($configure_ac, $line,
7606                                              "$message$trailer");
7607                     }
7608                     else
7609                     {
7610                         &am_line_error ($line, "$message$trailer");
7611                     }
7612                 }
7613             }
7614         }
7615     }
7618 # Like require_file_with_line, but error messages refer to
7619 # configure.ac, not the current Makefile.am.
7620 sub require_file_with_conf_line
7622     @require_file_paths = $relative_dir;
7623     &require_file_internal (1, @_);
7626 sub require_file_with_line
7628     @require_file_paths = $relative_dir;
7629     &require_file_internal (0, @_);
7632 sub require_file
7634     @require_file_paths = $relative_dir;
7635     &require_file_internal (0, '', @_);
7638 # Require a file that is also required by Autoconf.  Looks in
7639 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7640 sub require_config_file
7642     @require_file_paths = @config_aux_path;
7643     &require_file_internal (1, '', @_);
7644     my $dir = $require_file_paths[0];
7645     @config_aux_path = @require_file_paths;
7646      # Avoid unsightly '/.'s.
7647     $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7650 # Assumes that the line number is in Makefile.am.
7651 sub require_conf_file_with_line
7653     @require_file_paths = @config_aux_path;
7654     &require_file_internal (0, @_);
7655     my $dir = $require_file_paths[0];
7656     @config_aux_path = @require_file_paths;
7657      # Avoid unsightly '/.'s.
7658     $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7661 # Assumes that the line number is in configure.ac.
7662 sub require_conf_file_with_conf_line
7664     @require_file_paths = @config_aux_path;
7665     &require_file_internal (1, @_);
7666     my $dir = $require_file_paths[0];
7667     @config_aux_path = @require_file_paths;
7668     # avoid unsightly '/.'s.
7669     $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7672 ################################################################
7674 # &require_build_directory ($DIRECTORY)
7675 # ------------------------------------
7676 # Emit rules to create $DIRECTORY if needed, and return
7677 # the file that any target requiring this directory should be made
7678 # dependent upon.
7679 sub require_build_directory ($)
7681     my $directory = shift;
7682     my $dirstamp = "$directory/.dirstamp";
7684     # Don't emit the rule twice.
7685     if (! defined $directory_map{$directory})
7686     {
7687         $directory_map{$directory} = 1;
7689         # Directory must be removed by `make distclean'.
7690         $compile_clean_files{$dirstamp} = $DIST_CLEAN;
7692         $output_rules .= ("$dirstamp:\n"
7693                           . "\t\@\$(mkinstalldirs) $directory\n"
7694                           . "\t\@: > $dirstamp\n");
7695     }
7697     return $dirstamp;
7700 # &require_build_directory_maybe ($FILE)
7701 # --------------------------------------
7702 # If $FILE lies in a subdirectory, emit a rule to create this
7703 # directory and return the file that $FILE should be made
7704 # dependent upon.  Otherwise, just return the empty string.
7705 sub require_build_directory_maybe ($)
7707     my $file = shift;
7708     my $directory = dirname ($file);
7710     if ($directory ne '.')
7711     {
7712         return &require_build_directory ($directory);
7713     }
7714     else
7715     {
7716         return '';
7717     }
7720 ################################################################
7722 # Push a list of files onto dist_common.
7723 sub push_dist_common
7725     &prog_error ("push_dist_common run after handle_dist")
7726         if $handle_dist_run;
7727     macro_define ('DIST_COMMON', 1, '+', '', join (' ', @_), '');
7731 # Set strictness.
7732 sub set_strictness
7734     $strictness_name = $_[0];
7735     if ($strictness_name eq 'gnu')
7736     {
7737         $strictness = $GNU;
7738     }
7739     elsif ($strictness_name eq 'gnits')
7740     {
7741         $strictness = $GNITS;
7742     }
7743     elsif ($strictness_name eq 'foreign')
7744     {
7745         $strictness = $FOREIGN;
7746     }
7747     else
7748     {
7749         die "$me: level `$strictness_name' not recognized\n";
7750     }
7754 ################################################################
7756 # Ensure a file exists.
7757 sub create
7759     my ($file) = @_;
7761     my $touch = new IO::File (">> $file");
7762     $touch->close;
7765 # Glob something.  Do this to avoid indentation screwups everywhere we
7766 # want to glob.  Gross!
7767 sub my_glob
7769     my ($pat) = @_;
7770     return <${pat}>;
7773 # Remove one level of brackets and strip leading spaces,
7774 # as does m4 to function arguments.
7775 sub unquote_m4_arg
7777     $_ = shift;
7778     s/^\s*//;
7780     my @letters = split //;
7781     my @result = ();
7782     my $depth = 0;
7784     foreach (@letters)
7785     {
7786         if ($_ eq '[')
7787         {
7788             ++$depth;
7789             next if $depth == 1;
7790         }
7791         elsif ($_ eq ']')
7792         {
7793             --$depth;
7794             next if $depth == 0;
7795             # don't count orphan right brackets
7796             $depth = 0 if $depth < 0;
7797         }
7798         push @result, $_;
7799     }
7800     return join '', @result;
7803 ################################################################
7805 # am_print_error ($LEADER, @ARGS)
7806 # -------------------------------
7807 # Do the work of printing the error message.  Join @ARGS with spaces,
7808 # then split at newlines and add $LEADER to each line.  Uses `warn' to
7809 # print message.
7810 sub am_print_error
7812     my ($leader, @args) = @_;
7813     my $text = join (' ', @args);
7814     @args = split ("\n", $text);
7815     $text = $leader . join ("\n" . $leader, @args) . "\n";
7816     warn $text;
7819 # Print an error message and set exit status.
7820 sub am_error
7822     am_print_error ("$me: ${am_file}.am: ", @_);
7823     $exit_status = 1;
7826 # am_file_error ($FILE, @ARGS)
7827 # ----------------------------
7828 sub am_file_error
7830     my ($file, @args) = @_;
7832     am_print_error ("$file: ", @args);
7833     $exit_status = 1;
7836 sub am_line_error
7838     my ($symbol, @args) = @_;
7840     if ($symbol && "$symbol" ne '-1')
7841     {
7842         my $file = "${am_file}.am";
7844         if ($symbol =~ /^\d+$/)
7845         {
7846             # SYMBOL is a line number, so just add the colon.
7847             $file .= ':' . $symbol;
7848         }
7849         elsif (defined $var_line{$symbol})
7850         {
7851             # SYMBOL is a variable defined in Makefile.am, so add the
7852             # line number we saved from there.
7853             $file .= ':' . $var_line{$symbol};
7854         }
7855         elsif (defined $configure_vars{$symbol})
7856         {
7857             # SYMBOL is a variable defined in configure.ac, so add the
7858             # appropriate line number.
7859             $file = $configure_vars{$symbol};
7860         }
7861         else
7862         {
7863             # Couldn't find the line number.
7864         }
7866         am_print_error ("$file: ", @args);
7867         $exit_status = 1;
7868     }
7869     else
7870     {
7871         &am_error (@args);
7872     }
7875 # Like am_error, but while scanning configure.ac.
7876 sub am_conf_error
7878     # FIXME: can run in subdirs.
7879     am_print_error ("$me: $configure_ac: ", @_);
7880     $exit_status = 1;
7883 # Error message with line number referring to configure.ac.
7884 sub am_conf_line_error
7886     my ($file, $line, @args) = @_;
7888     if ($line)
7889     {
7890         am_print_error ("$file: $line: ", @args);
7891         $exit_status = 1;
7892     }
7893     else
7894     {
7895         &am_conf_error (@args);
7896     }
7899 # Warning message with line number referring to configure.ac.
7900 # Does not affect exit_status
7901 sub am_conf_line_warning
7903     my $saved_exit_status = $exit_status;
7904     my $sig = $SIG{'__WARN__'};
7905     $SIG{'__WARN__'} = 'DEFAULT';
7906     am_conf_line_error (@_);
7907     $exit_status = $saved_exit_status;
7908     $SIG{'__WARN__'} = $sig;
7911 # Like am_line_error, but doesn't affect exit status.
7912 sub am_line_warning
7914     my $saved_exit_status = $exit_status;
7915     my $sig = $SIG{'__WARN__'};
7916     $SIG{'__WARN__'} = 'DEFAULT';
7917     am_line_error (@_);
7918     $exit_status = $saved_exit_status;
7919     $SIG{'__WARN__'} = $sig;
7922 # Tell user where our aclocal.m4 is, but only once.
7923 sub keyed_aclocal_warning
7925     my ($key) = @_;
7926     warn "$me: macro `$key' can be generated by `aclocal'\n";
7929 # Print usage information.
7930 sub usage
7932     print <<EOF;
7933 Usage: $0 [OPTION] ... [Makefile]...
7935 Generate Makefile.in for configure from Makefile.am.
7937 Operation modes:
7938       --help             print this help, then exit
7939       --version          print version number, then exit
7940   -v, --verbose          verbosely list files processed
7941   -o, --output-dir=DIR   put generated Makefile.in's into DIR
7942       --no-force         only update Makefile.in's that are out of date
7944 Dependency tracking:
7945   -i, --ignore-deps      disable dependency tracking code
7946       --include-deps     enable dependency tracking code
7948 Flavors:
7949       --cygnus           assume program is part of Cygnus-style tree
7950       --foreign          set strictness to foreign
7951       --gnits            set strictness to gnits
7952       --gnu              set strictness to gnu
7954 Library files:
7955   -a, --add-missing      add missing standard files to package
7956       --libdir=DIR       directory storing library files
7957   -c, --copy             with -a, copy missing files (default is symlink)
7958   -f, --force-missing    force update of standard files
7961     my ($last, @lcomm);
7962     $last = '';
7963     foreach my $iter (sort ((@common_files, @common_sometimes)))
7964     {
7965         push (@lcomm, $iter) unless $iter eq $last;
7966         $last = $iter;
7967     }
7969     my @four;
7970     print "\nFiles which are automatically distributed, if found:\n";
7971     format USAGE_FORMAT =
7972   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
7973   $four[0],           $four[1],           $four[2],           $four[3]
7975     $~ = "USAGE_FORMAT";
7977     my $cols = 4;
7978     my $rows = int(@lcomm / $cols);
7979     my $rest = @lcomm % $cols;
7981     if ($rest)
7982     {
7983         $rows++;
7984     }
7985     else
7986     {
7987         $rest = $cols;
7988     }
7990     for (my $y = 0; $y < $rows; $y++)
7991     {
7992         @four = ("", "", "", "");
7993         for (my $x = 0; $x < $cols; $x++)
7994         {
7995             last if $y + 1 == $rows && $x == $rest;
7997             my $idx = (($x > $rest)
7998                        ?  ($rows * $rest + ($rows - 1) * ($x - $rest))
7999                        : ($rows * $x));
8001             $idx += $y;
8002             $four[$x] = $lcomm[$idx];
8003         }
8004         write;
8005     }
8007     print "\nReport bugs to <bug-automake\@gnu.org>.\n";
8009     exit 0;
8012 # &version ()
8013 # -----------
8014 # Print version information
8015 sub version ()
8017   print <<EOF;
8018 automake (GNU $PACKAGE) $VERSION
8019 Written by Tom Tromey <tromey\@cygnus.com>.
8021 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
8022 Free Software Foundation, Inc.
8023 This is free software; see the source for copying conditions.  There is NO
8024 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8026   exit 0;