Work around MinGW mangling of "host:/path"
[msysgit/historical-msysgit.git] / bin / automake-1.7
blob22d974dbef6e53bad3b1ac119de3207b990aae74
1 #!/bin/perl -w
2 # -*- perl -*-
3 # Makefile. Generated from Makefile.in by configure.
5 eval 'case $# in 0) exec /bin/perl -S "$0";; *) exec /bin/perl -S "$0" "$@";; esac'
6 if 0;
8 # automake - create Makefile.in from Makefile.am
9 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
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@redhat.com>.
30 package Language;
32 BEGIN
34 my $perllibdir = $ENV{'perllibdir'} || '/usr/share/automake-1.7';
35 unshift @INC, $perllibdir;
38 use Automake::Struct;
39 struct (# Short name of the language (c, f77...).
40 'name' => "\$",
41 # Nice name of the language (C, Fortran 77...).
42 'Name' => "\$",
44 # List of configure variables which must be defined.
45 'config_vars' => '@',
47 'ansi' => "\$",
48 # `pure' is `1' or `'. A `pure' language is one where, if
49 # all the files in a directory are of that language, then we
50 # do not require the C compiler or any code to call it.
51 'pure' => "\$",
53 'autodep' => "\$",
55 # Name of the compiling variable (COMPILE).
56 'compiler' => "\$",
57 # Content of the compiling variable.
58 'compile' => "\$",
59 # Flag to require compilation without linking (-c).
60 'compile_flag' => "\$",
61 'extensions' => '@',
62 # A subroutine to compute a list of possible extensions of
63 # the product given the input extensions.
64 # (defaults to a subroutine which returns ('.$(OBJEXT)', '.lo'))
65 'output_extensions' => "\$",
66 # A list of flag variables used in 'compile'.
67 # (defaults to [])
68 'flags' => "@",
70 # The file to use when generating rules for this language.
71 # The default is 'depend2'.
72 'rule_file' => "\$",
74 # Name of the linking variable (LINK).
75 'linker' => "\$",
76 # Content of the linking variable.
77 'link' => "\$",
79 # Name of the linker variable (LD).
80 'lder' => "\$",
81 # Content of the linker variable ($(CC)).
82 'ld' => "\$",
84 # Flag to specify the output file (-o).
85 'output_flag' => "\$",
86 '_finish' => "\$",
88 # This is a subroutine which is called whenever we finally
89 # determine the context in which a source file will be
90 # compiled.
91 '_target_hook' => "\$");
94 sub finish ($)
96 my ($self) = @_;
97 if (defined $self->_finish)
99 &{$self->_finish} ();
103 sub target_hook ($$$$)
105 my ($self) = @_;
106 if (defined $self->_target_hook)
108 &{$self->_target_hook} (@_);
112 package Automake;
114 use strict 'vars', 'subs';
115 use Automake::General;
116 use Automake::XFile;
117 use Automake::Channels;
118 use File::Basename;
119 use Carp;
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 = '1.7.1';
128 my $PACKAGE = 'automake';
129 my $libdir = '/usr/share/automake-1.7';
131 # Some regular expressions. One reason to put them here is that it
132 # makes indentation work better in Emacs.
134 # Writting singled-quoted-$-terminated regexes is a pain because
135 # perl-mode thinks of $' as the ${'} variable (intead of a $ followed
136 # by a closing quote. Letting perl-mode think the quote is not closed
137 # leads to all sort of misindentations. On the other hand, defining
138 # regexes as double-quoted strings is far less readable. So usually
139 # we will write:
141 # $REGEX = '^regex_value' . "\$";
143 my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
144 my $WHITE_PATTERN = '^\s*' . "\$";
145 my $COMMENT_PATTERN = '^#';
146 my $TARGET_PATTERN='[$a-zA-Z_.@%][-.a-zA-Z0-9_(){}/$+@%]*';
147 # A rule has three parts: a list of targets, a list of dependencies,
148 # and optionally actions.
149 my $RULE_PATTERN =
150 "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
152 my $SUFFIX_RULE_PATTERN =
153 '^(\.[a-zA-Z0-9_(){}$+@]+)(\.[a-zA-Z0-9_(){}$+@]+)' . "\$";
154 # Only recognize leading spaces, not leading tabs. If we recognize
155 # leading tabs here then we need to make the reader smarter, because
156 # otherwise it will think rules like `foo=bar; \' are errors.
157 my $MACRO_PATTERN = '^[.A-Za-z0-9_@]+' . "\$";
158 my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)' . "\$";
159 # This pattern recognizes a Gnits version id and sets $1 if the
160 # release is an alpha release. We also allow a suffix which can be
161 # used to extend the version number with a "fork" identifier.
162 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
164 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?' . "\$";
165 my $ELSE_PATTERN =
166 '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
167 my $ENDIF_PATTERN =
168 '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
169 my $PATH_PATTERN = '(\w|[/.-])+';
170 # This will pass through anything not of the prescribed form.
171 my $INCLUDE_PATTERN = ('^include\s+'
172 . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
173 . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
174 . '|([^/\$]' . $PATH_PATTERN . '))\s*(#.*)?' . "\$");
176 # This handles substitution references like ${foo:.a=.b}.
177 my $SUBST_REF_PATTERN = "^([^:]*):([^=]*)=(.*)\$";
179 # Match `-d' as a command-line argument in a string.
180 my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)";
181 # Directories installed during 'install-exec' phase.
182 my $EXEC_DIR_PATTERN =
183 '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)' . "\$";
185 # Constants to define the "strictness" level.
186 use constant FOREIGN => 0;
187 use constant GNU => 1;
188 use constant GNITS => 2;
190 # Values for AC_CANONICAL_*
191 use constant AC_CANONICAL_HOST => 1;
192 use constant AC_CANONICAL_SYSTEM => 2;
194 # Values indicating when something should be cleaned.
195 use constant MOSTLY_CLEAN => 0;
196 use constant CLEAN => 1;
197 use constant DIST_CLEAN => 2;
198 use constant MAINTAINER_CLEAN => 3;
200 # Libtool files.
201 my @libtool_files = qw(ltmain.sh config.guess config.sub);
202 # ltconfig appears here for compatibility with old versions of libtool.
203 my @libtool_sometimes = qw(ltconfig ltcf-c.sh ltcf-cxx.sh ltcf-gcj.sh);
205 # Commonly found files we look for and automatically include in
206 # DISTFILES.
207 my @common_files =
208 (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
209 COPYING.LESSER ChangeLog INSTALL NEWS README THANKS TODO acinclude.m4
210 ansi2knr.1 ansi2knr.c compile config.guess config.rpath config.sub
211 configure configure.ac configure.in depcomp elisp-comp
212 install-sh libversion.in mdate-sh missing mkinstalldirs
213 py-compile texinfo.tex ylwrap),
214 @libtool_files, @libtool_sometimes);
216 # Commonly used files we auto-include, but only sometimes.
217 my @common_sometimes =
218 qw(aclocal.m4 acconfig.h config.h.top config.h.bot stamp-vti);
220 # Standard directories from the GNU Coding Standards, and additional
221 # pkg* directories from Automake. Stored in a hash for fast member check.
222 my %standard_prefix =
223 map { $_ => 1 } (qw(bin data exec include info lib libexec lisp
224 localstate man man1 man2 man3 man4 man5 man6
225 man7 man8 man9 oldinclude pkgdatadir
226 pkgincludedir pkglibdir sbin sharedstate
227 sysconf));
229 # Declare the macros that define known variables, so we can
230 # hint the user if she try to use one of these variables.
232 # Macros accessible via aclocal.
233 my %am_macro_for_var =
235 ANSI2KNR => 'AM_C_PROTOTYPES',
236 CCAS => 'AM_PROG_AS',
237 CCASFLAGS => 'AM_PROG_AS',
238 EMACS => 'AM_PATH_LISPDIR',
239 GCJ => 'AM_PROG_GCJ',
240 LEX => 'AM_PROG_LEX',
241 LIBTOOL => 'AC_PROG_LIBTOOL',
242 lispdir => 'AM_PATH_LISPDIR',
243 pkgpyexecdir => 'AM_PATH_PYTHON',
244 pkgpythondir => 'AM_PATH_PYTHON',
245 pyexecdir => 'AM_PATH_PYTHON',
246 PYTHON => 'AM_PATH_PYTHON',
247 pythondir => 'AM_PATH_PYTHON',
248 U => 'AM_C_PROTOTYPES',
251 # Macros shipped with Autoconf.
252 my %ac_macro_for_var =
254 CC => 'AC_PROG_CC',
255 CFLAGS => 'AC_PROG_CC',
256 CXX => 'AC_PROG_CXX',
257 CXXFLAGS => 'AC_PROG_CXX',
258 F77 => 'AC_PROG_F77',
259 F77FLAGS => 'AC_PROG_F77',
260 RANLIB => 'AC_PROG_RANLIB',
261 YACC => 'AC_PROG_YACC',
264 # Copyright on generated Makefile.ins.
265 my $gen_copyright = "\
266 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
267 # Free Software Foundation, Inc.
268 # This Makefile.in is free software; the Free Software Foundation
269 # gives unlimited permission to copy and/or distribute it,
270 # with or without modifications, as long as this notice is preserved.
272 # This program is distributed in the hope that it will be useful,
273 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
274 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
275 # PARTICULAR PURPOSE.
278 # These constants are returned by lang_*_rewrite functions.
279 # LANG_SUBDIR means that the resulting object file should be in a
280 # subdir if the source file is. In this case the file name cannot
281 # have `..' components.
282 use constant LANG_IGNORE => 0;
283 use constant LANG_PROCESS => 1;
284 use constant LANG_SUBDIR => 2;
286 # These are used when keeping track of whether an object can be built
287 # by two different paths.
288 use constant COMPILE_LIBTOOL => 1;
289 use constant COMPILE_ORDINARY => 2;
293 ## ---------------------------------- ##
294 ## Variables related to the options. ##
295 ## ---------------------------------- ##
297 # TRUE if we should always generate Makefile.in.
298 my $force_generation = 1;
300 # Strictness level as set on command line.
301 my $default_strictness = GNU;
303 # Name of strictness level, as set on command line.
304 my $default_strictness_name = 'gnu';
306 # This is TRUE if automatic dependency generation code should be
307 # included in generated Makefile.in.
308 my $cmdline_use_dependencies = 1;
310 # From the Perl manual.
311 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
313 # TRUE if missing standard files should be installed.
314 my $add_missing = 0;
316 # TRUE if we should copy missing files; otherwise symlink if possible.
317 my $copy_missing = 0;
319 # TRUE if we should always update files that we know about.
320 my $force_missing = 0;
323 ## ---------------------------------------- ##
324 ## Variables filled during files scanning. ##
325 ## ---------------------------------------- ##
327 # Name of the top autoconf input: `configure.ac' or `configure.in'.
328 my $configure_ac = '';
330 # Files found by scanning configure.ac for LIBOBJS.
331 my %libsources = ();
333 # Names used in AC_CONFIG_HEADER call.
334 my @config_headers = ();
335 # Where AC_CONFIG_HEADER appears.
336 my $config_header_location;
338 # Directory where output files go. Actually, output files are
339 # relative to this directory.
340 my $output_directory;
342 # List of Makefile.am's to process, and their corresponding outputs.
343 my @input_files = ();
344 my %output_files = ();
346 # Complete list of Makefile.am's that exist.
347 my @configure_input_files = ();
349 # List of files in AC_CONFIG_FILES/AC_OUTPUT without Makefile.am's,
350 # and their outputs.
351 my @other_input_files = ();
352 # Where the last AC_CONFIG_FILES/AC_OUTPUT appears.
353 my $ac_config_files_location;
355 # List of directories to search for configure-required files. This
356 # can be set by AC_CONFIG_AUX_DIR.
357 my @config_aux_path = qw(. .. ../..);
358 my $config_aux_dir = '';
359 my $config_aux_dir_set_in_configure_in = 0;
361 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
362 my $seen_gettext = 0;
363 # Whether AM_GNU_GETTEXT([external]) is used.
364 my $seen_gettext_external = 0;
365 # Where AM_GNU_GETTEXT appears.
366 my $ac_gettext_location;
368 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).
369 my $seen_canonical = 0;
370 my $canonical_location;
372 # Where AM_MAINTAINER_MODE appears.
373 my $seen_maint_mode;
375 # Actual version we've seen.
376 my $package_version = '';
378 # Where version is defined.
379 my $package_version_location;
381 # TRUE if we've seen AC_ENABLE_MULTILIB.
382 my $seen_multilib = 0;
384 # TRUE if we've seen AM_PROG_CC_C_O
385 my $seen_cc_c_o = 0;
387 # Where AM_INIT_AUTOMAKE is called;
388 my $seen_init_automake = 0;
390 # TRUE if we've seen AM_AUTOMAKE_VERSION.
391 my $seen_automake_version = 0;
393 # Hash table of discovered configure substitutions. Keys are names,
394 # values are `FILE:LINE' strings which are used by error message
395 # generation.
396 my %configure_vars = ();
398 # This is used to keep track of which variable definitions we are
399 # scanning. It is only used in certain limited ways, but it has to be
400 # global. It is declared just for documentation purposes.
401 my %vars_scanned = ();
403 # TRUE if --cygnus seen.
404 my $cygnus_mode = 0;
406 # Hash table of AM_CONDITIONAL variables seen in configure.
407 my %configure_cond = ();
409 # This maps extensions onto language names.
410 my %extension_map = ();
412 # List of the DIST_COMMON files we discovered while reading
413 # configure.in
414 my $configure_dist_common = '';
416 # This maps languages names onto objects.
417 my %languages = ();
419 # List of targets we must always output.
420 # FIXME: Complete, and remove falsely required targets.
421 my %required_targets =
423 'all' => 1,
424 'dvi' => 1,
425 'pdf' => 1,
426 'ps' => 1,
427 'info' => 1,
428 'install-info' => 1,
429 'install' => 1,
430 'install-data' => 1,
431 'install-exec' => 1,
432 'uninstall' => 1,
434 # FIXME: Not required, temporary hacks.
435 # Well, actually they are sort of required: the -recursive
436 # targets will run them anyway...
437 'dvi-am' => 1,
438 'pdf-am' => 1,
439 'ps-am' => 1,
440 'info-am' => 1,
441 'install-data-am' => 1,
442 'install-exec-am' => 1,
443 'installcheck-am' => 1,
444 'uninstall-am' => 1,
446 'install-man' => 1,
449 # This is set to 1 when Automake needs to be run again.
450 # (For instance, this happens when an auxiliary file such as
451 # depcomp is added after the toplevel Makefile.in -- which
452 # should distribute depcomp -- has been generated.)
453 my $automake_needs_to_reprocess_all_files = 0;
455 # Options set via AM_INIT_AUTOMAKE.
456 my $global_options = '';
458 # Same as $suffix_rules (declared below), but records only the
459 # default rules supplied by the languages Automake supports.
460 my $suffix_rules_default;
462 # If a file name appears as a key in this hash, then it has already
463 # been checked for. This variable is local to the "require file"
464 # functions.
465 my %require_file_found = ();
468 ################################################################
470 ## ------------------------------------------ ##
471 ## Variables reset by &initialize_per_input. ##
472 ## ------------------------------------------ ##
474 # Basename and relative dir of the input file.
475 my $am_file_name;
476 my $am_relative_dir;
478 # Same but wrt Makefile.in.
479 my $in_file_name;
480 my $relative_dir;
482 # These two variables are used when generating each Makefile.in.
483 # They hold the Makefile.in until it is ready to be printed.
484 my $output_rules;
485 my $output_vars;
486 my $output_trailer;
487 my $output_all;
488 my $output_header;
490 # Suffixes found during a run.
491 my @suffixes;
493 # Handling the variables.
495 # For a $VAR:
496 # - $var_value{$VAR}{$COND} is its value associated to $COND,
497 # - $var_location{$VAR}{$COND} is where it was defined,
498 # - $var_comment{$VAR}{$COND} are the comments associated to it.
499 # - $var_type{$VAR}{$COND} is how it has been defined (`', `+', or `:'),
500 # - $var_owner{$VAR}{$COND} tells who owns the variable (VAR_AUTOMAKE,
501 # VAR_CONFIGURE, or VAR_MAKEFILE).
502 my %var_value;
503 my %var_location;
504 my %var_comment;
505 my %var_type;
506 my %var_owner;
507 # Possible values for var_owner. Defined so that the owner of
508 # a variable can only be increased (e.g Automake should not
509 # override a configure or Makefile variable).
510 use constant VAR_AUTOMAKE => 0; # Variable defined by Automake.
511 use constant VAR_CONFIGURE => 1;# Variable defined in configure.ac.
512 use constant VAR_MAKEFILE => 2; # Variable defined in Makefile.am.
514 # This holds a 1 if a particular variable was examined.
515 my %content_seen;
517 # This holds the names which are targets. These also appear in
518 # %contents. $targets{TARGET}{COND} is the location of the definition
519 # of TARGET for condition COND. TARGETs should not include
520 # a trailing $(EXEEXT), we record this in %target_name.
521 my %targets;
523 # $target_source{TARGET}{COND} is the filename where TARGET
524 # were defined for condition COND. Note this must be a
525 # filename, *without* any line number.
526 my %target_source;
528 # $target_name{TARGET}{COND} is the real name of TARGET (in condition COND).
529 # The real name is often TARGET or TARGET$(EXEEXT), and TARGET never
530 # contain $(EXEEXT)
531 my %target_name;
533 # $target_owner{TARGET}{COND} the owner of TARGET in condition COND.
534 my %target_owner;
535 use constant TARGET_AUTOMAKE => 0; # Target defined by Automake.
536 use constant TARGET_USER => 1; # Target defined in the user's Makefile.am.
538 # This is the conditional stack.
539 my @cond_stack;
541 # This holds the set of included files.
542 my @include_stack;
544 # This holds a list of directories which we must create at `dist'
545 # time. This is used in some strange scenarios involving weird
546 # AC_OUTPUT commands.
547 my %dist_dirs;
549 # List of dependencies for the obvious targets.
550 my @all;
551 my @check;
552 my @check_tests;
554 # Holds the dependencies of targets which dependencies are factored.
555 # Typically, `.PHONY' will appear in plenty of *.am files, but must
556 # be output once. Arguably all pure dependencies could be subject
557 # to this factorization, but it is not unpleasant to have paragraphs
558 # in Makefile: keeping related stuff altogether.
559 my %dependencies;
561 # Holds the factored actions. Tied to %DEPENDENCIES, i.e., filled
562 # only when keys exists in %DEPENDENCIES.
563 my %actions;
565 # Keys in this hash table are files to delete. The associated
566 # value tells when this should happen (MOSTLY_CLEAN, DIST_CLEAN, etc.)
567 my %clean_files;
569 # Keys in this hash table are object files or other files in
570 # subdirectories which need to be removed. This only holds files
571 # which are created by compilations. The value in the hash indicates
572 # when the file should be removed.
573 my %compile_clean_files;
575 # Keys in this hash table are directories where we expect to build a
576 # libtool object. We use this information to decide what directories
577 # to delete.
578 my %libtool_clean_directories;
580 # Value of `$(SOURCES)', used by tags.am.
581 my @sources;
582 # Sources which go in the distribution.
583 my @dist_sources;
585 # This hash maps object file names onto their corresponding source
586 # file names. This is used to ensure that each object is created
587 # by a single source file.
588 my %object_map;
590 # This hash maps object file names onto an integer value representing
591 # whether this object has been built via ordinary compilation or
592 # libtool compilation (the COMPILE_* constants).
593 my %object_compilation_map;
596 # This keeps track of the directories for which we've already
597 # created `.dirstamp' code.
598 my %directory_map;
600 # All .P files.
601 my %dep_files;
603 # Strictness levels.
604 my $strictness;
605 my $strictness_name;
607 # Options from AUTOMAKE_OPTIONS.
608 my %options;
610 # Whether or not dependencies are handled. Can be further changed
611 # in handle_options.
612 my $use_dependencies;
614 # This is a list of all targets to run during "make dist".
615 my @dist_targets;
617 # Keys in this hash are the basenames of files which must depend on
618 # ansi2knr. Values are either the empty string, or the directory in
619 # which the ANSI source file appears; the directory must have a
620 # trailing `/'.
621 my %de_ansi_files;
623 # This maps the source extension for all suffix rule seen to
624 # a \hash whose keys are the possible output extensions.
626 # Note that this is transitively closed by construction:
627 # if we have
628 # exists $suffix_rules{$ext1}{$ext2}
629 # && exists $suffix_rules{$ext2}{$ext3}
630 # then we also have
631 # exists $suffix_rules{$ext1}{$ext3}
633 # So it's easy to check whether '.foo' can be transformed to '.$(OBJEXT)'
634 # by checking whether $suffix_rules{'.foo'}{'.$(OBJEXT)'} exist. This
635 # will work even if transforming '.foo' to '.$(OBJEXT)' involves a chain
636 # of several suffix rules.
638 # The value of `$suffix_rules{$ext1}{$ext2}' is the a pair
639 # `[ $next_sfx, $dist ]' where `$next_sfx' is target suffix
640 # for the next rule to use to reach '$ext2', and `$dist' the
641 # distance to `$ext2'.
642 my $suffix_rules;
644 # This is the name of the redirect `all' target to use.
645 my $all_target;
647 # This keeps track of which extensions we've seen (that we care
648 # about).
649 my %extension_seen;
651 # This is random scratch space for the language finish functions.
652 # Don't randomly overwrite it; examine other uses of keys first.
653 my %language_scratch;
655 # We keep track of which objects need special (per-executable)
656 # handling on a per-language basis.
657 my %lang_specific_files;
659 # This is set when `handle_dist' has finished. Once this happens,
660 # we should no longer push on dist_common.
661 my $handle_dist_run;
663 # Used to store a set of linkers needed to generate the sources currently
664 # under consideration.
665 my %linkers_used;
667 # True if we need `LINK' defined. This is a hack.
668 my $need_link;
670 # This is the list of such variables to output.
671 # FIXME: Might be useless actually.
672 my @var_list;
674 # Was get_object_extension run?
675 # FIXME: This is a hack. a better switch should be found.
676 my $get_object_extension_was_run;
678 # Contains a stack of `from' parts of variable substitutions currently in
679 # force.
680 my @substfroms;
682 # Contains a stack of `to' parts of variable substitutions currently in
683 # force.
684 my @substtos;
686 # This keeps track of all variables defined by subobjname.
687 # The value stored is the variable names.
688 # The key has the form "(COND1)VAL1(COND2)VAL2..." where VAL1 and VAL2
689 # are the values of the variable for condition COND1 and COND2.
690 my %subobjvar = ();
692 # This hash records helper variables used to implement '+=' in conditionals.
693 # Keys have the form "VAR:CONDITIONS". The value associated to a key is
694 # the named of the helper variable used to append to VAR in CONDITIONS.
695 my %appendvar = ();
698 ## --------------------------------- ##
699 ## Forward subroutine declarations. ##
700 ## --------------------------------- ##
701 sub register_language (%);
702 sub file_contents_internal ($$%);
703 sub define_objects_from_sources ($$$$$$$);
706 # &initialize_per_input ()
707 # ------------------------
708 # (Re)-Initialize per-Makefile.am variables.
709 sub initialize_per_input ()
711 reset_local_duplicates ();
713 $am_file_name = '';
714 $am_relative_dir = '';
716 $in_file_name = '';
717 $relative_dir = '';
719 $output_rules = '';
720 $output_vars = '';
721 $output_trailer = '';
722 $output_all = '';
723 $output_header = '';
725 @suffixes = ();
727 %var_value = ();
728 %var_location = ();
729 %var_comment = ();
730 %var_type = ();
731 %var_owner = ();
733 %content_seen = ();
735 %targets = ();
736 %target_source = ();
737 %target_name = ();
738 %target_owner = ();
740 @cond_stack = ();
742 @include_stack = ();
744 %dist_dirs = ();
746 @all = ();
747 @check = ();
748 @check_tests = ();
750 %dependencies =
752 # Texinfoing.
753 'dvi' => [],
754 'dvi-am' => [],
755 'pdf' => [],
756 'pdf-am' => [],
757 'ps' => [],
758 'ps-am' => [],
759 'info' => [],
760 'info-am' => [],
762 # Installing/uninstalling.
763 'install-data-am' => [],
764 'install-exec-am' => [],
765 'uninstall-am' => [],
767 'install-man' => [],
768 'uninstall-man' => [],
770 'install-info' => [],
771 'install-info-am' => [],
772 'uninstall-info' => [],
774 'installcheck-am' => [],
776 # Cleaning.
777 'clean-am' => [],
778 'mostlyclean-am' => [],
779 'maintainer-clean-am' => [],
780 'distclean-am' => [],
781 'clean' => [],
782 'mostlyclean' => [],
783 'maintainer-clean' => [],
784 'distclean' => [],
786 # Tarballing.
787 'dist-all' => [],
789 # Phoning.
790 '.PHONY' => []
792 %actions = ();
794 %clean_files = ();
796 @sources = ();
797 @dist_sources = ();
799 %object_map = ();
800 %object_compilation_map = ();
802 %directory_map = ();
804 %dep_files = ();
806 $strictness = $default_strictness;
807 $strictness_name = $default_strictness_name;
809 %options = ();
811 $use_dependencies = $cmdline_use_dependencies;
813 @dist_targets = ();
815 %de_ansi_files = ();
818 # The first time we initialize the variables,
819 # we save the value of $suffix_rules.
820 if (defined $suffix_rules_default)
822 $suffix_rules = $suffix_rules_default;
824 else
826 $suffix_rules_default = $suffix_rules;
829 $all_target = '';
831 %extension_seen = ();
833 %language_scratch = ();
835 %lang_specific_files = ();
837 $handle_dist_run = 0;
839 $need_link = 0;
841 @var_list = ();
843 $get_object_extension_was_run = 0;
845 %compile_clean_files = ();
847 # We always include `.'. This isn't strictly correct.
848 %libtool_clean_directories = ('.' => 1);
850 %subobjvar = ();
852 %appendvar = ();
856 ################################################################
858 # Initialize our list of error/warning channels.
859 # Do not forget to update &usage and the manual
860 # if you add or change a warning channel.
862 # Fatal errors.
863 register_channel 'fatal', type => 'fatal';
864 # Common errors.
865 register_channel 'error', type => 'error';
866 # Errors related to GNU Standards.
867 register_channel 'error-gnu', type => 'error';
868 # Errors related to GNU Standards that should be warnings in `foreign' mode.
869 register_channel 'error-gnu/warn', type => 'error';
870 # Errors related to GNITS Standards (silent by default).
871 register_channel 'error-gnits', type => 'error', silent => 1;
872 # Internal errors.
873 register_channel 'automake', type => 'fatal', backtrace => 1,
874 header => ("####################\n" .
875 "## Internal Error ##\n" .
876 "####################\n"),
877 footer => "\nPlease contact <bug-automake\@gnu.org>.";
879 # Warnings related to GNU Coding Standards.
880 register_channel 'gnu', type => 'warning';
881 # Warnings about obsolete features (silent by default).
882 register_channel 'obsolete', type => 'warning', silent => 1;
883 # Warnings about non-portable constructs.
884 register_channel 'portability', type => 'warning', silent => 1;
885 # Weird syntax, unused variables, typos...
886 register_channel 'syntax', type => 'warning';
887 # Warnings about unsupported (or mis-supported) features.
888 register_channel 'unsupported', type => 'warning';
890 # For &verb.
891 register_channel 'verb', type => 'debug', silent => 1;
892 # Informative messages.
893 register_channel 'note', type => 'debug', silent => 0;
896 # Initialize our list of languages that are internally supported.
898 # C.
899 register_language ('name' => 'c',
900 'Name' => 'C',
901 'config_vars' => ['CC'],
902 'ansi' => 1,
903 'autodep' => '',
904 'flags' => ['CFLAGS', 'CPPFLAGS'],
905 'compiler' => 'COMPILE',
906 'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
907 'lder' => 'CCLD',
908 'ld' => '$(CC)',
909 'linker' => 'LINK',
910 'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
911 'compile_flag' => '-c',
912 'extensions' => ['.c'],
913 '_finish' => \&lang_c_finish);
915 # C++.
916 register_language ('name' => 'cxx',
917 'Name' => 'C++',
918 'config_vars' => ['CXX'],
919 'linker' => 'CXXLINK',
920 'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
921 'autodep' => 'CXX',
922 'flags' => ['CXXFLAGS', 'CPPFLAGS'],
923 'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
924 'compiler' => 'CXXCOMPILE',
925 'compile_flag' => '-c',
926 'output_flag' => '-o',
927 'lder' => 'CXXLD',
928 'ld' => '$(CXX)',
929 'pure' => 1,
930 'extensions' => ['.c++', '.cc', '.cpp', '.cxx', '.C']);
932 # Objective C.
933 register_language ('name' => 'objc',
934 'Name' => 'Objective C',
935 'config_vars' => ['OBJC'],
936 'linker' => 'OBJCLINK',,
937 'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
938 'autodep' => 'OBJC',
939 'flags' => ['OBJCFLAGS', 'CPPFLAGS'],
940 'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
941 'compiler' => 'OBJCCOMPILE',
942 'compile_flag' => '-c',
943 'output_flag' => '-o',
944 'lder' => 'OBJCLD',
945 'ld' => '$(OBJC)',
946 'pure' => 1,
947 'extensions' => ['.m']);
949 # Headers.
950 register_language ('name' => 'header',
951 'Name' => 'Header',
952 'extensions' => ['.h', '.H', '.hxx', '.h++', '.hh',
953 '.hpp', '.inc'],
954 # No output.
955 'output_extensions' => sub { return () },
956 # Nothing to do.
957 '_finish' => sub { });
959 # Yacc (C & C++).
960 register_language ('name' => 'yacc',
961 'Name' => 'Yacc',
962 'config_vars' => ['YACC'],
963 'flags' => ['YFLAGS'],
964 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
965 'compiler' => 'YACCCOMPILE',
966 'extensions' => ['.y'],
967 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
968 return ($ext,) },
969 'rule_file' => 'yacc',
970 '_finish' => \&lang_yacc_finish,
971 '_target_hook' => \&lang_yacc_target_hook);
972 register_language ('name' => 'yaccxx',
973 'Name' => 'Yacc (C++)',
974 'config_vars' => ['YACC'],
975 'rule_file' => 'yacc',
976 'flags' => ['YFLAGS'],
977 'compiler' => 'YACCCOMPILE',
978 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
979 'extensions' => ['.y++', '.yy', '.yxx', '.ypp'],
980 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
981 return ($ext,) },
982 '_finish' => \&lang_yacc_finish,
983 '_target_hook' => \&lang_yacc_target_hook);
985 # Lex (C & C++).
986 register_language ('name' => 'lex',
987 'Name' => 'Lex',
988 'config_vars' => ['LEX'],
989 'rule_file' => 'lex',
990 'flags' => ['LFLAGS'],
991 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
992 'compiler' => 'LEXCOMPILE',
993 'extensions' => ['.l'],
994 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
995 return ($ext,) },
996 '_finish' => \&lang_lex_finish,
997 '_target_hook' => \&lang_lex_target_hook);
998 register_language ('name' => 'lexxx',
999 'Name' => 'Lex (C++)',
1000 'config_vars' => ['LEX'],
1001 'rule_file' => 'lex',
1002 'flags' => ['LFLAGS'],
1003 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
1004 'compiler' => 'LEXCOMPILE',
1005 'extensions' => ['.l++', '.ll', '.lxx', '.lpp'],
1006 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
1007 return ($ext,) },
1008 '_finish' => \&lang_lex_finish,
1009 '_target_hook' => \&lang_lex_target_hook);
1011 # Assembler.
1012 register_language ('name' => 'asm',
1013 'Name' => 'Assembler',
1014 'config_vars' => ['CCAS', 'CCASFLAGS'],
1016 'flags' => ['CCASFLAGS'],
1017 # Users can set AM_ASFLAGS to includes DEFS, INCLUDES,
1018 # or anything else required. They can also set AS.
1019 'compile' => '$(CCAS) $(AM_CCASFLAGS) $(CCASFLAGS)',
1020 'compiler' => 'CCASCOMPILE',
1021 'compile_flag' => '-c',
1022 'extensions' => ['.s', '.S'],
1024 # With assembly we still use the C linker.
1025 '_finish' => \&lang_c_finish);
1027 # Fortran 77
1028 register_language ('name' => 'f77',
1029 'Name' => 'Fortran 77',
1030 'linker' => 'F77LINK',
1031 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
1032 'flags' => ['FFLAGS'],
1033 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
1034 'compiler' => 'F77COMPILE',
1035 'compile_flag' => '-c',
1036 'output_flag' => '-o',
1037 'lder' => 'F77LD',
1038 'ld' => '$(F77)',
1039 'pure' => 1,
1040 'extensions' => ['.f', '.for', '.f90']);
1042 # Preprocessed Fortran 77
1044 # The current support for preprocessing Fortran 77 just involves
1045 # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
1046 # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
1047 # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
1048 # for `make' Version 3.76 Beta' (specifically, from info file
1049 # `(make)Catalogue of Rules').
1051 # A better approach would be to write an Autoconf test
1052 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
1053 # Fortran 77 compilers know how to do preprocessing. The Autoconf
1054 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
1055 # preprocessing capabilities, and then fall back on cpp (if cpp were
1056 # available).
1057 register_language ('name' => 'ppf77',
1058 'Name' => 'Preprocessed Fortran 77',
1059 'config_vars' => ['F77'],
1060 'linker' => 'F77LINK',
1061 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
1062 'lder' => 'F77LD',
1063 'ld' => '$(F77)',
1064 'flags' => ['FFLAGS', 'CPPFLAGS'],
1065 'compiler' => 'PPF77COMPILE',
1066 'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
1067 'compile_flag' => '-c',
1068 'output_flag' => '-o',
1069 'pure' => 1,
1070 'extensions' => ['.F']);
1072 # Ratfor.
1073 register_language ('name' => 'ratfor',
1074 'Name' => 'Ratfor',
1075 'config_vars' => ['F77'],
1076 'linker' => 'F77LINK',
1077 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
1078 'lder' => 'F77LD',
1079 'ld' => '$(F77)',
1080 'flags' => ['RFLAGS', 'FFLAGS'],
1081 # FIXME also FFLAGS.
1082 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
1083 'compiler' => 'RCOMPILE',
1084 'compile_flag' => '-c',
1085 'output_flag' => '-o',
1086 'pure' => 1,
1087 'extensions' => ['.r']);
1089 # Java via gcj.
1090 register_language ('name' => 'java',
1091 'Name' => 'Java',
1092 'config_vars' => ['GCJ'],
1093 'linker' => 'GCJLINK',
1094 'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
1095 'autodep' => 'GCJ',
1096 'flags' => ['GCJFLAGS'],
1097 'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
1098 'compiler' => 'GCJCOMPILE',
1099 'compile_flag' => '-c',
1100 'output_flag' => '-o',
1101 'lder' => 'GCJLD',
1102 'ld' => '$(GCJ)',
1103 'pure' => 1,
1104 'extensions' => ['.java', '.class', '.zip', '.jar']);
1106 ################################################################
1108 # Parse the WARNINGS environnent variable.
1109 &parse_WARNINGS;
1111 # Parse command line.
1112 &parse_arguments;
1114 # Do configure.ac scan only once.
1115 &scan_autoconf_files;
1117 &fatal ("no `Makefile.am' found or specified\n")
1118 if ! @input_files;
1120 my $automake_has_run = 0;
1124 if ($automake_has_run)
1126 &verb ('processing Makefiles another time to fix them up.');
1127 &prog_error ('running more than two times should never be needed.')
1128 if $automake_has_run >= 2;
1130 $automake_needs_to_reprocess_all_files = 0;
1132 # Now do all the work on each file.
1133 # This guy must be local otherwise it's private to the loop.
1134 use vars '$am_file';
1135 local $am_file;
1136 foreach $am_file (@input_files)
1138 if (! -f ($am_file . '.am'))
1140 &err ("`$am_file.am' does not exist");
1142 else
1144 &generate_makefile ($output_files{$am_file}, $am_file);
1147 ++$automake_has_run;
1149 while ($automake_needs_to_reprocess_all_files);
1151 exit $exit_code;
1153 ################################################################
1155 # Error reporting functions.
1157 # prog_error ($MESSAGE, [%OPTIONS])
1158 # -------------------------------
1159 # Signal a programming error, display $MESSAGE, and exit 1.
1160 sub prog_error ($;%)
1162 my ($msg, %opts) = @_;
1163 msg 'automake', '', $msg, %opts;
1166 # err ($WHERE, $MESSAGE, [%OPTIONS])
1167 # err ($MESSAGE)
1168 # ----------------------------------
1169 # Uncategorized errors.
1170 sub err ($;$%)
1172 my ($where, $msg, %opts) = @_;
1173 msg ('error', $where, $msg, %opts);
1176 # fatal ($WHERE, $MESSAGE, [%OPTIONS])
1177 # fatal ($MESSAGE)
1178 # ----------------------------------
1179 # Fatal errors.
1180 sub fatal ($;$%)
1182 my ($where, $msg, %opts) = @_;
1183 msg ('fatal', $where, $msg, %opts);
1186 # err_var ($VARNAME, $MESSAGE, [%OPTIONS])
1187 # ----------------------------------------
1188 # Uncategorized errors about variables.
1189 sub err_var ($$;%)
1191 msg_var ('error', @_);
1194 # err_target ($TARGETNAME, $MESSAGE, [%OPTIONS])
1195 # ----------------------------------------------
1196 # Uncategorized errors about targets.
1197 sub err_target ($$;%)
1199 msg_target ('error', @_);
1202 # err_cond_target ($COND, $TARGETNAME, $MESSAGE, [%OPTIONS])
1203 # ----------------------------------------------------------
1204 # Uncategorized errors about conditional targets.
1205 sub err_cond_target ($$$;%)
1207 msg_cond_target ('error', @_);
1210 # err_am ($MESSAGE, [%OPTIONS])
1211 # -----------------------------
1212 # Uncategorized errors about the current Makefile.am.
1213 sub err_am ($;%)
1215 msg_am ('error', @_);
1218 # err_ac ($MESSAGE, [%OPTIONS])
1219 # -----------------------------
1220 # Uncategorized errors about configure.ac.
1221 sub err_ac ($;%)
1223 msg_ac ('error', @_);
1226 # msg_cond_var ($CHANNEL, $COND, $VARNAME, $MESSAGE, [%OPTIONS])
1227 # --------------------------------------------------------------
1228 # Messages about conditional variable.
1229 sub msg_cond_var ($$$$;%)
1231 my ($channel, $cond, $var, $msg, %opts) = @_;
1232 msg $channel, $var_location{$var}{$cond}, $msg, %opts;
1235 # msg_var ($CHANNEL, $VARNAME, $MESSAGE, [%OPTIONS])
1236 # --------------------------------------------------
1237 # Messages about variables.
1238 sub msg_var ($$$;%)
1240 my ($channel, $var, $msg, %opts) = @_;
1241 # Don't know which condition is concerned. Pick any.
1242 my $cond = (keys %{$var_value{$var}})[0];
1243 msg_cond_var $channel, $cond, $var, $msg, %opts;
1246 # msg_cond_target ($CHANNEL, $COND, $TARGETNAME, $MESSAGE, [%OPTIONS])
1247 # --------------------------------------------------------------------
1248 # Messages about conditional targets.
1249 sub msg_cond_target ($$$$;%)
1251 my ($channel, $cond, $target, $msg, %opts) = @_;
1252 msg $channel, $targets{$target}{$cond}, $msg, %opts;
1255 # msg_target ($CHANNEL, $TARGETNAME, $MESSAGE, [%OPTIONS])
1256 # --------------------------------------------------------
1257 # Messages about targets.
1258 sub msg_target ($$$;%)
1260 my ($channel, $target, $msg, %opts) = @_;
1261 # Don't know which condition is concerned. Pick any.
1262 my $cond = (keys %{$targets{$target}})[0];
1263 msg_cond_target ($channel, $cond, $target, $msg, %opts);
1266 # msg_am ($CHANNEL, $MESSAGE, [%OPTIONS])
1267 # ---------------------------------------
1268 # Messages about about the current Makefile.am.
1269 sub msg_am ($$;%)
1271 my ($channel, $msg, %opts) = @_;
1272 msg $channel, "${am_file}.am", $msg, %opts;
1275 # msg_ac ($CHANNEL, $MESSAGE, [%OPTIONS])
1276 # ---------------------------------------
1277 # Messages about about configure.ac.
1278 sub msg_ac ($$;%)
1280 my ($channel, $msg, %opts) = @_;
1281 msg $channel, $configure_ac, $msg, %opts;
1284 # $BOOL
1285 # reject_var ($VAR, $ERROR_MSG)
1286 # -----------------------------
1287 sub reject_var ($$)
1289 my ($var, $msg) = @_;
1290 if (variable_defined ($var))
1292 err_var $var, $msg;
1293 return 1;
1295 return 0;
1298 # $BOOL
1299 # reject_target ($VAR, $ERROR_MSG)
1300 # --------------------------------
1301 sub reject_target ($$)
1303 my ($target, $msg) = @_;
1304 if (target_defined ($target))
1306 err_target $target, $msg;
1307 return 1;
1309 return 0;
1312 # verb ($MESSAGE, [%OPTIONS])
1313 # ---------------------------
1314 sub verb ($;%)
1316 my ($msg, %opts) = @_;
1317 msg 'verb', '', $msg, %opts;
1320 ################################################################
1322 # subst ($TEXT)
1323 # -------------
1324 # Return a configure-style substitution using the indicated text.
1325 # We do this to avoid having the substitutions directly in automake.in;
1326 # when we do that they are sometimes removed and this causes confusion
1327 # and bugs.
1328 sub subst ($)
1330 my ($text) = @_;
1331 return '@' . $text . '@';
1334 ################################################################
1337 # $BACKPATH
1338 # &backname ($REL-DIR)
1339 # --------------------
1340 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
1341 # For instance `src/foo' => `../..'.
1342 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
1343 sub backname ($)
1345 my ($file) = @_;
1346 my @res;
1347 foreach (split (/\//, $file))
1349 next if $_ eq '.' || $_ eq '';
1350 if ($_ eq '..')
1352 pop @res;
1354 else
1356 push (@res, '..');
1359 return join ('/', @res) || '.';
1362 ################################################################
1364 # Pattern that matches all know input extensions (i.e. extensions used
1365 # by the languages supported by Automake). Using this pattern
1366 # (instead of `\..*$') to match extensions allows Automake to support
1367 # dot-less extensions.
1368 my $KNOWN_EXTENSIONS_PATTERN = "";
1369 my @known_extensions_list = ();
1371 # accept_extensions (@EXTS)
1372 # -------------------------
1373 # Update $KNOWN_EXTENSIONS_PATTERN to recognize the extensions
1374 # listed @EXTS. Extensions should contain a dot if needed.
1375 sub accept_extensions (@)
1377 push @known_extensions_list, @_;
1378 $KNOWN_EXTENSIONS_PATTERN =
1379 '(?:' . join ('|', map (quotemeta, @known_extensions_list)) . ')';
1382 # var_SUFFIXES_trigger ($TYPE, $VALUE)
1383 # ------------------------------------
1384 # This is called automagically by macro_define() when SUFFIXES
1385 # is defined ($TYPE eq '') or appended ($TYPE eq '+').
1386 # The work here needs to be performed as a side-effect of the
1387 # macro_define() call because SUFFIXES definitions impact
1388 # on $KNOWN_EXTENSIONS_PATTERN, and $KNOWN_EXTENSIONS_PATTERN
1389 # are used when parsing the input am file.
1390 sub var_SUFFIXES_trigger ($$)
1392 my ($type, $value) = @_;
1393 accept_extensions (split (' ', $value));
1396 ################################################################
1399 # switch_warning ($CATEGORY)
1400 # --------------------------
1401 # If $CATEGORY is mumble, turn on the mumble channel.
1402 # If it's no-mumble, turn mumble off.
1403 # Alse handle `all' and `none' for completeness.
1404 sub switch_warning ($)
1406 my ($cat) = @_;
1407 my $has_no = 0;
1409 if ($cat =~ /^no-(.*)$/)
1411 $cat = $1;
1412 $has_no = 1;
1415 if ($cat eq 'all')
1417 setup_channel_type 'warning', silent => $has_no;
1419 elsif ($cat eq 'none')
1421 setup_channel_type 'warning', silent => 1 - $has_no;
1423 elsif ($cat eq 'error')
1425 $warnings_are_errors = 1 - $has_no;
1427 elsif (channel_type ($cat) eq 'warning')
1429 setup_channel $cat, silent => $has_no;
1431 else
1433 return 1;
1435 return 0;
1438 # parse_WARNINGS
1439 # --------------
1440 # Honor the WARNINGS environment variable.
1441 sub parse_WARNINGS ($$)
1443 if (exists $ENV{'WARNINGS'})
1445 # Ignore unknown categories. This is required because WARNINGS
1446 # should be honored by many tools.
1447 switch_warning $_ foreach (split (',', $ENV{'WARNINGS'}));
1451 # parse_warning ($OPTION, $ARGUMENT)
1452 # ----------------------------------
1453 # Parse the argument of --warning=CATEGORY or -WCATEGORY.
1454 sub parse_warnings ($$)
1456 my ($opt, $categories) = @_;
1458 foreach my $cat (split (',', $categories))
1460 msg 'unsupported', "unknown warning category `$cat'"
1461 if switch_warning $cat;
1465 # Parse command line.
1466 sub parse_arguments ()
1468 # Start off as gnu.
1469 &set_strictness ('gnu');
1471 my %options =
1473 'libdir:s' => \$libdir,
1474 'gnu' => sub { &set_strictness ('gnu'); },
1475 'gnits' => sub { &set_strictness ('gnits'); },
1476 'cygnus' => \$cygnus_mode,
1477 'foreign' => sub { &set_strictness ('foreign'); },
1478 'include-deps' => sub { $cmdline_use_dependencies = 1; },
1479 'i|ignore-deps' => sub { $cmdline_use_dependencies = 0; },
1480 'no-force' => sub { $force_generation = 0; },
1481 'f|force-missing' => \$force_missing,
1482 'o|output-dir:s' => \$output_directory,
1483 'a|add-missing' => \$add_missing,
1484 'c|copy' => \$copy_missing,
1485 'v|verbose' => sub { setup_channel 'verb', silent => 0; },
1486 'W|warnings:s' => \&parse_warnings,
1487 # These long options (--Werror and --Wno-error) for backward
1488 # compatibility. Use -Werror and -Wno-error today.
1489 'Werror' => sub { parse_warnings 'W', 'error'; },
1490 'Wno-error' => sub { parse_warnings 'W', 'no-error'; },
1493 use Getopt::Long;
1494 Getopt::Long::config ("bundling", "pass_through");
1496 # See if --version or --help is used. We want to process these before
1497 # anything else because the GNU Coding Standards require us to
1498 # `exit 0' after processing these options, and we can't garanty this
1499 # if we treat other options first. (Handling other options first
1500 # could produce error diagnostics, and in this condition it is
1501 # confusing if Automake `exit 0'.)
1502 my %options_1st_pass =
1504 'version' => \&version,
1505 'help' => \&usage,
1506 # Recognize all other options (and their arguments) but do nothing.
1507 map { $_ => sub {} } (keys %options)
1509 my @ARGV_backup = @ARGV;
1510 Getopt::Long::GetOptions %options_1st_pass
1511 or exit 1;
1512 @ARGV = @ARGV_backup;
1514 # Now *really* process the options. This time we know
1515 # that --help and --version are not present.
1516 Getopt::Long::GetOptions %options
1517 or exit 1;
1519 if (defined $output_directory)
1521 msg 'obsolete', "`--output-dir' is deprecated\n";
1523 else
1525 # In the next release we'll remove this entirely.
1526 $output_directory = '.';
1529 foreach my $arg (@ARGV)
1531 if ($arg =~ /^-./)
1533 fatal ("unrecognized option `$arg'\n"
1534 . "Try `$0 --help' for more information.");
1537 # Handle $local:$input syntax. Note that we only examine the
1538 # first ":" file to see if it is automake input; the rest are
1539 # just taken verbatim. We still keep all the files around for
1540 # dependency checking, however.
1541 my ($local, $input, @rest) = split (/:/, $arg);
1542 if (! $input)
1544 $input = $local;
1546 else
1548 # Strip .in; later on .am is tacked on. That is how the
1549 # automake input file is found. Maybe not the best way, but
1550 # it is easy to explain.
1551 $input =~ s/\.in$//
1552 or fatal "invalid input file name `$arg'\n.";
1554 push (@input_files, $input);
1555 $output_files{$input} = join (':', ($local, @rest));
1558 # Take global strictness from whatever we currently have set.
1559 $default_strictness = $strictness;
1560 $default_strictness_name = $strictness_name;
1563 ################################################################
1565 # Generate a Makefile.in given the name of the corresponding Makefile and
1566 # the name of the file output by config.status.
1567 sub generate_makefile
1569 my ($output, $makefile) = @_;
1571 # Reset all the Makefile.am related variables.
1572 &initialize_per_input;
1574 # Any warning setting now local to this Makefile.am.
1575 &dup_channel_setup;
1576 # AUTOMAKE_OPTIONS can contains -W flags to disable or enable
1577 # warnings for this file. So hold any warning issued before
1578 # we have processed AUTOMAKE_OPTIONS.
1579 &buffer_messages ('warning');
1581 # Name of input file ("Makefile.am") and output file
1582 # ("Makefile.in"). These have no directory components.
1583 $am_file_name = basename ($makefile) . '.am';
1584 $in_file_name = basename ($makefile) . '.in';
1586 # $OUTPUT is encoded. If it contains a ":" then the first element
1587 # is the real output file, and all remaining elements are input
1588 # files. We don't scan or otherwise deal with these input file,
1589 # other than to mark them as dependencies. See
1590 # &scan_autoconf_files for details.
1591 my (@secondary_inputs);
1592 ($output, @secondary_inputs) = split (/:/, $output);
1594 $relative_dir = dirname ($output);
1595 $am_relative_dir = dirname ($makefile);
1597 &read_main_am_file ($makefile . '.am');
1598 if (&handle_options)
1600 # Process buffered warnings.
1601 &flush_messages;
1602 # Fatal error. Just return, so we can continue with next file.
1603 return;
1605 # Process buffered warnings.
1606 &flush_messages;
1608 # There are a few install-related variables that you should not define.
1609 foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
1611 if (exists $var_owner{$var})
1613 prog_error "\$var_owner{$var}{TRUE} doesn't exist"
1614 unless exists $var_owner{$var}{'TRUE'};
1615 reject_var $var, "`$var' should not be defined"
1616 if $var_owner{$var}{'TRUE'} != VAR_AUTOMAKE;
1620 # Catch some obsolete variables.
1621 msg_var ('obsolete', 'INCLUDES',
1622 "`INCLUDES' is the old name for `AM_CPPFLAGS'")
1623 if variable_defined ('INCLUDES');
1625 # At the toplevel directory, we might need config.guess, config.sub
1626 # or libtool scripts (ltconfig and ltmain.sh).
1627 if ($relative_dir eq '.')
1629 # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1630 # config.sub.
1631 require_conf_file ($canonical_location, FOREIGN,
1632 'config.guess', 'config.sub')
1633 if $seen_canonical;
1636 # We still need Makefile.in here, because sometimes the `dist'
1637 # target doesn't re-run automake.
1638 if ($am_relative_dir eq $relative_dir)
1640 # Only distribute the files if they are in the same subdir as
1641 # the generated makefile.
1642 &push_dist_common ($in_file_name, $am_file_name);
1645 push (@sources, '$(SOURCES)')
1646 if variable_defined ('SOURCES');
1648 # Must do this after reading .am file. See read_main_am_file to
1649 # understand weird tricks we play there with variables.
1650 &define_variable ('subdir', $relative_dir);
1652 # Check first, because we might modify some state.
1653 &check_cygnus;
1654 &check_gnu_standards;
1655 &check_gnits_standards;
1657 &handle_configure ($output, $makefile, @secondary_inputs);
1658 &handle_gettext;
1659 &handle_libraries;
1660 &handle_ltlibraries;
1661 &handle_programs;
1662 &handle_scripts;
1664 # This must run first so that the ANSI2KNR definition is generated
1665 # before it is used by the _.c rules. We have to do this because
1666 # a variable which is used in a dependency must be defined before
1667 # the target, or else make won't properly see it.
1668 &handle_compile;
1669 # This must be run after all the sources are scanned.
1670 &handle_languages;
1672 # We have to run this after dealing with all the programs.
1673 &handle_libtool;
1675 # Re-init SOURCES. FIXME: other code shouldn't depend on this
1676 # (but currently does).
1677 macro_define ('SOURCES', VAR_AUTOMAKE, '', 'TRUE', "@sources", 'internal');
1678 define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
1680 &handle_multilib;
1681 &handle_texinfo;
1682 &handle_emacs_lisp;
1683 &handle_python;
1684 &handle_java;
1685 &handle_man_pages;
1686 &handle_data;
1687 &handle_headers;
1688 &handle_subdirs;
1689 &handle_tags;
1690 &handle_minor_options;
1691 &handle_tests;
1693 # This must come after most other rules.
1694 &handle_dist ($makefile);
1696 &handle_footer;
1697 &do_check_merge_target;
1698 &handle_all ($output);
1700 # FIXME: Gross!
1701 if (variable_defined ('lib_LTLIBRARIES') &&
1702 variable_defined ('bin_PROGRAMS'))
1704 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
1707 &handle_installdirs;
1708 &handle_clean;
1709 &handle_factored_dependencies;
1711 check_typos ();
1713 if (! -d ($output_directory . '/' . $am_relative_dir))
1715 mkdir ($output_directory . '/' . $am_relative_dir, 0755);
1718 my ($out_file) = $output_directory . '/' . $makefile . ".in";
1719 if (! $force_generation && -e $out_file)
1721 my ($am_time) = (stat ($makefile . '.am'))[9];
1722 my ($in_time) = (stat ($out_file))[9];
1723 # FIXME: should cache these times.
1724 my ($conf_time) = (stat ($configure_ac))[9];
1725 # FIXME: how to do unsigned comparison?
1726 if ($am_time < $in_time || $am_time < $conf_time)
1728 # No need to update.
1729 return;
1731 if (-f 'aclocal.m4')
1733 my ($acl_time) = (stat _)[9];
1734 return if ($am_time < $acl_time);
1738 if (-e "$out_file")
1740 unlink ($out_file)
1741 or fatal "cannot remove $out_file: $!\n";
1743 my $gm_file = new Automake::XFile "> $out_file";
1744 verb "creating $makefile.in";
1746 print $gm_file $output_vars;
1747 # We make sure that `all:' is the first target.
1748 print $gm_file $output_all;
1749 print $gm_file $output_header;
1750 print $gm_file $output_rules;
1751 print $gm_file $output_trailer;
1753 # Back out any warning setting.
1754 &drop_channel_setup;
1757 ################################################################
1759 # A version is a string that looks like
1760 # MAJOR.MINOR[.MICRO][ALPHA][-FORK]
1761 # where
1762 # MAJOR, MINOR, and MICRO are digits, ALPHA is a character, and
1763 # FORK any alphanumeric word.
1764 # Usually, ALPHA is used to label alpha releases or intermediate snapshots,
1765 # FORK is used for CVS branches or patched releases, and MICRO is used
1766 # for bug fixes releases on the MAJOR.MINOR branch.
1768 # For the purpose of ordering, 1.4 is the same as 1.4.0, but 1.4g is
1769 # the same as 1.4.99g. The FORK identifier is ignored in the
1770 # ordering, except when it looks like -pMINOR[ALPHA]: some versions
1771 # were labelled like 1.4-p3a, this is the same as an alpha release
1772 # labelled 1.4.3a. Yes it's horrible, but Automake did not support
1773 # two-dot versions in the past.
1775 # version_split (VERSION)
1776 # -----------------------
1777 # Split a version string into the corresponding (MAJOR, MINOR, MICRO,
1778 # ALPHA, FORK) tuple. For instance "1.4g" would be split into
1779 # (1, 4, 99, 'g', '').
1780 # Return () on error.
1781 sub version_split ($)
1783 my ($ver) = @_;
1785 # Special case for versions like 1.4-p2a.
1786 if ($ver =~ /^(\d+)\.(\d+)(?:-p(\d+)([a-z]+)?)$/)
1788 return ($1, $2, $3, $4 || '', '');
1790 # Common case.
1791 elsif ($ver =~ /^(\d+)\.(\d+)(?:\.(\d+))?([a-z])?(?:-([A-Za-z0-9]+))?$/)
1793 return ($1, $2, $3 || (defined $4 ? 99 : 0), $4 || '', $5 || '');
1795 return ();
1798 # version_compare (\@LVERSION, \@RVERSION)
1799 # ----------------------------------------
1800 # Return 1 if LVERSION > RVERSION,
1801 # -1 if LVERSION < RVERSION,
1802 # 0 if LVERSION = RVERSION.
1803 sub version_compare (\@\@)
1805 my @l = @{$_[0]};
1806 my @r = @{$_[1]};
1808 for my $i (0, 1, 2)
1810 return 1 if ($l[$i] > $r[$i]);
1811 return -1 if ($l[$i] < $r[$i]);
1813 for my $i (3, 4)
1815 return 1 if ($l[$i] gt $r[$i]);
1816 return -1 if ($l[$i] lt $r[$i]);
1818 return 0;
1821 # Handles the logic of requiring a version number in AUTOMAKE_OPTIONS.
1822 # Return 0 if the required version is satisfied, 1 otherwise.
1823 sub version_check ($)
1825 my ($required) = @_;
1826 my @version = version_split $VERSION;
1827 my @required = version_split $required;
1829 prog_error "version is incorrect: $VERSION"
1830 if $#version == -1;
1832 # This should not happen, because process_option_list and split_version
1833 # use similar regexes.
1834 prog_error "required version is incorrect: $required"
1835 if $#required == -1;
1837 # If we require 3.4n-foo then we require something
1838 # >= 3.4n, with the `foo' fork identifier.
1839 return 1
1840 if ($required[4] ne '' && $required[4] ne $version[4]);
1842 return 0 > version_compare @version, @required;
1845 # $BOOL
1846 # process_option_list ($CONFIG, @OPTIONS)
1847 # ------------------------------
1848 # Process a list of options. Return 1 on error, 0 otherwise.
1849 # This is a helper for handle_options. CONFIG is true if we're
1850 # handling global options.
1851 sub process_option_list
1853 my ($config, @list) = @_;
1855 # FIXME: We should disallow conditional deffinitions of AUTOMAKE_OPTIONS.
1856 my $where = ($config ?
1857 $seen_init_automake :
1858 $var_location{'AUTOMAKE_OPTIONS'}{'TRUE'});
1860 foreach (@list)
1862 $options{$_} = 1;
1863 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
1865 &set_strictness ($_);
1867 elsif ($_ eq 'cygnus')
1869 $cygnus_mode = 1;
1871 elsif (/^(.*\/)?ansi2knr$/)
1873 # An option like "../lib/ansi2knr" is allowed. With no
1874 # path prefix, we assume the required programs are in this
1875 # directory. We save the actual option for later.
1876 $options{'ansi2knr'} = $_;
1878 elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
1879 || $_ eq 'dist-shar' || $_ eq 'dist-zip'
1880 || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
1881 || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
1882 || $_ eq 'readme-alpha' || $_ eq 'check-news'
1883 || $_ eq 'subdir-objects' || $_ eq 'nostdinc'
1884 || $_ eq 'no-exeext' || $_ eq 'no-define'
1885 || $_ eq 'std-options')
1887 # Explicitly recognize these.
1889 elsif ($_ eq 'no-dependencies')
1891 $use_dependencies = 0;
1893 elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/)
1895 # Got a version number.
1896 if (version_check $&)
1898 err ($where, "require Automake $_, but have $VERSION",
1899 uniq_scope => US_GLOBAL);
1900 return 1;
1903 elsif (/^(?:--warnings=|-W)(.*)$/)
1905 foreach my $cat (split (',', $1))
1907 msg 'unsupported', $where, "unknown warning category `$cat'"
1908 if switch_warning $cat;
1911 else
1913 err ($where, "option `$_' not recognized",
1914 uniq_scope => US_GLOBAL);
1915 return 1;
1920 # Handle AUTOMAKE_OPTIONS variable. Return 1 on error, 0 otherwise.
1921 sub handle_options
1923 # Process global options first so that more specific options can
1924 # override.
1925 if (&process_option_list (1, split (' ', $global_options)))
1927 return 1;
1930 if (variable_defined ('AUTOMAKE_OPTIONS'))
1932 if (&process_option_list (0, &variable_value_as_list_recursive ('AUTOMAKE_OPTIONS', '')))
1934 return 1;
1938 if ($strictness == GNITS)
1940 $options{'readme-alpha'} = 1;
1941 $options{'std-options'} = 1;
1942 $options{'check-news'} = 1;
1945 return 0;
1949 # get_object_extension ($OUT)
1950 # ---------------------------
1951 # Return object extension. Just once, put some code into the output.
1952 # OUT is the name of the output file
1953 sub get_object_extension
1955 my ($out) = @_;
1957 # Maybe require libtool library object files.
1958 my $extension = '.$(OBJEXT)';
1959 $extension = '.lo' if ($out =~ /\.la$/);
1961 # Check for automatic de-ANSI-fication.
1962 $extension = '$U' . $extension
1963 if defined $options{'ansi2knr'};
1965 $get_object_extension_was_run = 1;
1967 return $extension;
1971 # Call finish function for each language that was used.
1972 sub handle_languages
1974 if ($use_dependencies)
1976 # Include auto-dep code. Don't include it if DEP_FILES would
1977 # be empty.
1978 if (&saw_sources_p (0) && keys %dep_files)
1980 # Set location of depcomp.
1981 &define_variable ('depcomp', "\$(SHELL) $config_aux_dir/depcomp");
1982 &define_variable ('am__depfiles_maybe', 'depfiles');
1984 require_conf_file ("$am_file.am", FOREIGN, 'depcomp');
1986 my @deplist = sort keys %dep_files;
1988 # We define this as a conditional variable because BSD
1989 # make can't handle backslashes for continuing comments on
1990 # the following line.
1991 define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
1993 # Generate each `include' individually. Irix 6 make will
1994 # not properly include several files resulting from a
1995 # variable expansion; generating many separate includes
1996 # seems safest.
1997 $output_rules .= "\n";
1998 foreach my $iter (@deplist)
2000 $output_rules .= (subst ('AMDEP_TRUE')
2001 . subst ('am__include')
2002 . ' '
2003 . subst ('am__quote')
2004 . $iter
2005 . subst ('am__quote')
2006 . "\n");
2009 # Compute the set of directories to remove in distclean-depend.
2010 my @depdirs = uniq (map { dirname ($_) } @deplist);
2011 $output_rules .= &file_contents ('depend',
2012 DEPDIRS => "@depdirs");
2015 else
2017 &define_variable ('depcomp', '');
2018 &define_variable ('am__depfiles_maybe', '');
2021 my %done;
2023 # Is the c linker needed?
2024 my $needs_c = 0;
2025 foreach my $ext (sort keys %extension_seen)
2027 next unless $extension_map{$ext};
2029 my $lang = $languages{$extension_map{$ext}};
2031 my $rule_file = $lang->rule_file || 'depend2';
2033 # Get information on $LANG.
2034 my $pfx = $lang->autodep;
2035 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
2037 my $AMDEP = (($use_dependencies && $lang->autodep ne 'no')
2038 ? 'AMDEP' : 'FALSE');
2039 my $FASTDEP = (($use_dependencies && $lang->autodep ne 'no')
2040 ? ('am__fastdep' . $fpfx) : 'FALSE');
2042 my %transform = ('EXT' => $ext,
2043 'PFX' => $pfx,
2044 'FPFX' => $fpfx,
2045 'AMDEP' => $AMDEP,
2046 'FASTDEP' => $FASTDEP,
2047 '-c' => $lang->compile_flag || '',
2048 'MORE-THAN-ONE'
2049 => (count_files_for_language ($lang->name) > 1));
2051 # Generate the appropriate rules for this extension.
2052 if (($use_dependencies && $lang->autodep ne 'no')
2053 || defined $lang->compile)
2055 # Some C compilers don't support -c -o. Use it only if really
2056 # needed.
2057 my $output_flag = $lang->output_flag || '';
2058 $output_flag = '-o'
2059 if (! $output_flag
2060 && $lang->name eq 'c'
2061 && defined $options{'subdir-objects'});
2063 # Compute a possible derived extension.
2064 # This is not used by depend2.am.
2065 my $der_ext = (&{$lang->output_extensions} ($ext))[0];
2067 $output_rules .=
2068 file_contents ($rule_file,
2069 %transform,
2070 'GENERIC' => 1,
2072 'DERIVED-EXT' => $der_ext,
2074 # In this situation we know that the
2075 # object is in this directory, so
2076 # $(DEPDIR) is the correct location for
2077 # dependencies.
2078 'DEPBASE' => '$(DEPDIR)/$*',
2079 'BASE' => '$*',
2080 'SOURCE' => '$<',
2081 'OBJ' => '$@',
2082 'OBJOBJ' => '$@',
2083 'LTOBJ' => '$@',
2085 'COMPILE' => '$(' . $lang->compiler . ')',
2086 'LTCOMPILE' => '$(LT' . $lang->compiler . ')',
2087 '-o' => $output_flag);
2090 # Now include code for each specially handled object with this
2091 # language.
2092 my %seen_files = ();
2093 foreach my $file (@{$lang_specific_files{$lang->name}})
2095 my ($derived, $source, $obj, $myext) = split (' ', $file);
2097 # For any specially-generated object, we must respect the
2098 # ansi2knr setting so that we don't inadvertently try to
2099 # use the default rule.
2100 if ($lang->ansi && defined $options{'ansi2knr'})
2102 $myext = '$U' . $myext;
2105 # We might see a given object twice, for instance if it is
2106 # used under different conditions.
2107 next if defined $seen_files{$obj};
2108 $seen_files{$obj} = 1;
2110 prog_error ("found " . $lang->name .
2111 " in handle_languages, but compiler not defined")
2112 unless defined $lang->compile;
2114 my $obj_compile = $lang->compile;
2116 # Rewrite each occurence of `AM_$flag' in the compile
2117 # rule into `${derived}_$flag' if it exists.
2118 for my $flag (@{$lang->flags})
2120 my $val = "${derived}_$flag";
2121 $obj_compile =~ s/\(AM_$flag\)/\($val\)/
2122 if variable_defined ($val);
2125 my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
2127 # We _need_ `-o' for per object rules.
2128 my $output_flag = $lang->output_flag || '-o';
2130 my $depbase = dirname ($obj);
2131 $depbase = ''
2132 if $depbase eq '.';
2133 $depbase .= '/'
2134 unless $depbase eq '';
2135 $depbase .= '$(DEPDIR)/' . basename ($obj);
2137 # Generate a transform which will turn suffix targets in
2138 # depend2.am into real targets for the particular objects we
2139 # are building.
2140 $output_rules .=
2141 file_contents ($rule_file,
2142 (%transform,
2143 'GENERIC' => 0,
2145 'DEPBASE' => $depbase,
2146 'BASE' => $obj,
2147 'SOURCE' => $source,
2148 # Use $myext and not `.o' here, in case
2149 # we are actually building a new source
2150 # file -- e.g. via yacc.
2151 'OBJ' => "$obj$myext",
2152 'OBJOBJ' => "$obj.obj",
2153 'LTOBJ' => "$obj.lo",
2155 'COMPILE' => $obj_compile,
2156 'LTCOMPILE' => $obj_ltcompile,
2157 '-o' => $output_flag));
2160 # The rest of the loop is done once per language.
2161 next if defined $done{$lang};
2162 $done{$lang} = 1;
2164 # Load the language dependent Makefile chunks.
2165 my %lang = map { uc ($_) => 0 } keys %languages;
2166 $lang{uc ($lang->name)} = 1;
2167 $output_rules .= file_contents ('lang-compile', %transform, %lang);
2169 # If the source to a program consists entirely of code from a
2170 # `pure' language, for instance C++ for Fortran 77, then we
2171 # don't need the C compiler code. However if we run into
2172 # something unusual then we do generate the C code. There are
2173 # probably corner cases here that do not work properly.
2174 # People linking Java code to Fortran code deserve pain.
2175 $needs_c ||= ! $lang->pure;
2177 define_compiler_variable ($lang)
2178 if ($lang->compile);
2180 define_linker_variable ($lang)
2181 if ($lang->link);
2183 require_variables ("$am_file.am", $lang->Name . " source seen",
2184 'TRUE', @{$lang->config_vars});
2186 # Call the finisher.
2187 $lang->finish;
2189 # Flags listed in `->flags' are user variables (per GNU Standards),
2190 # they should not be overriden in the Makefile...
2191 my @dont_override = @{$lang->flags};
2192 # ... and so is LDFLAGS.
2193 push @dont_override, 'LDFLAGS' if $lang->link;
2195 foreach my $flag (@dont_override)
2197 if (exists $var_owner{$flag})
2199 for my $cond (keys %{$var_owner{$flag}})
2201 if ($var_owner{$flag}{$cond} == VAR_MAKEFILE)
2203 msg_cond_var ('gnu', $cond, $flag,
2204 "`$flag' is a user variable, "
2205 . "you should not override it;\n"
2206 . "use `AM_$flag' instead.");
2213 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
2214 # suffix rule was learned), don't bother with the C stuff. But if
2215 # anything else creeps in, then use it.
2216 $needs_c = 1
2217 if $need_link || ((scalar keys %$suffix_rules)
2218 - (scalar keys %$suffix_rules_default)) > 1;
2220 if ($needs_c)
2222 &define_compiler_variable ($languages{'c'})
2223 unless defined $done{$languages{'c'}};
2224 define_linker_variable ($languages{'c'});
2228 # Check to make sure a source defined in LIBOBJS is not explicitly
2229 # mentioned. This is a separate function (as opposed to being inlined
2230 # in handle_source_transform) because it isn't always appropriate to
2231 # do this check.
2232 sub check_libobjs_sources
2234 my ($one_file, $unxformed) = @_;
2236 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2237 'dist_EXTRA_', 'nodist_EXTRA_')
2239 my @files;
2240 if (variable_defined ($prefix . $one_file . '_SOURCES'))
2242 @files = &variable_value_as_list_recursive (
2243 ($prefix . $one_file . '_SOURCES'),
2244 'all');
2246 elsif ($prefix eq '')
2248 @files = ($unxformed . '.c');
2250 else
2252 next;
2255 foreach my $file (@files)
2257 err_var ($prefix . $one_file . '_SOURCES',
2258 "automatically discovered file `$file' should not" .
2259 " be explicitly mentioned")
2260 if defined $libsources{$file};
2266 # @OBJECTS
2267 # handle_single_transform_list ($VAR, $TOPPARENT, $DERIVED, $OBJ, @FILES)
2268 # -----------------------------------------------------------------------
2269 # Does much of the actual work for handle_source_transform.
2270 # Arguments are:
2271 # $VAR is the name of the variable that the source filenames come from
2272 # $TOPPARENT is the name of the _SOURCES variable which is being processed
2273 # $DERIVED is the name of resulting executable or library
2274 # $OBJ is the object extension (e.g., `$U.lo')
2275 # @FILES is the list of source files to transform
2276 # Result is a list of the names of objects
2277 # %linkers_used will be updated with any linkers needed
2278 sub handle_single_transform_list ($$$$@)
2280 my ($var, $topparent, $derived, $obj, @files) = @_;
2281 my @result = ();
2282 my $nonansi_obj = $obj;
2283 $nonansi_obj =~ s/\$U//g;
2285 # Turn sources into objects. We use a while loop like this
2286 # because we might add to @files in the loop.
2287 while (scalar @files > 0)
2289 $_ = shift @files;
2291 # Configure substitutions in _SOURCES variables are errors.
2292 if (/^\@.*\@$/)
2294 err_var ($var,
2295 "`$var' includes configure substitution `$_', and is " .
2296 "referred to\nfrom `$topparent': configure " .
2297 "substitutions are not allowed\nin _SOURCES variables");
2298 next;
2301 # If the source file is in a subdirectory then the `.o' is put
2302 # into the current directory, unless the subdir-objects option
2303 # is in effect.
2305 # Split file name into base and extension.
2306 next if ! /^(?:(.*)\/)?([^\/]*)($KNOWN_EXTENSIONS_PATTERN)$/;
2307 my $full = $_;
2308 my $directory = $1 || '';
2309 my $base = $2;
2310 my $extension = $3;
2311 my $full_ansi = $full; # We'll add `$U' if needed.
2313 # We must generate a rule for the object if it requires its own flags.
2314 my $renamed = 0;
2315 my ($linker, $object);
2317 # This records whether we've seen a derived source file (eg,
2318 # yacc output).
2319 my $derived_source = 0;
2321 # This holds the `aggregate context' of the file we are
2322 # currently examining. If the file is compiled with
2323 # per-object flags, then it will be the name of the object.
2324 # Otherwise it will be `AM'. This is used by the target hook
2325 # language function.
2326 my $aggregate = 'AM';
2328 $extension = &derive_suffix ($extension, $nonansi_obj);
2329 my $lang;
2330 if ($extension_map{$extension} &&
2331 ($lang = $languages{$extension_map{$extension}}))
2333 # Found the language, so see what it says.
2334 &saw_extension ($extension);
2336 # Note: computed subr call. The language rewrite function
2337 # should return one of the LANG_* constants. It could
2338 # also return a list whose first value is such a constant
2339 # and whose second value is a new source extension which
2340 # should be applied. This means this particular language
2341 # generates another source file which we must then process
2342 # further.
2343 my $subr = 'lang_' . $lang->name . '_rewrite';
2344 my ($r, $source_extension)
2345 = & $subr ($directory, $base, $extension);
2346 # Skip this entry if we were asked not to process it.
2347 next if $r == LANG_IGNORE;
2349 # Now extract linker and other info.
2350 $linker = $lang->linker;
2352 my $this_obj_ext;
2353 if (defined $source_extension)
2355 $this_obj_ext = $source_extension;
2356 $derived_source = 1;
2358 elsif ($lang->ansi)
2360 $this_obj_ext = $obj;
2362 else
2364 $this_obj_ext = $nonansi_obj;
2366 $object = $base . $this_obj_ext;
2368 # Do we have per-executable flags for this executable?
2369 my $have_per_exec_flags = 0;
2370 foreach my $flag (@{$lang->flags})
2372 if (variable_defined ("${derived}_$flag"))
2374 $have_per_exec_flags = 1;
2375 last;
2379 if ($have_per_exec_flags)
2381 # We have a per-executable flag in effect for this
2382 # object. In this case we rewrite the object's
2383 # name to ensure it is unique. We also require
2384 # the `compile' program to deal with compilers
2385 # where `-c -o' does not work.
2387 # We choose the name `DERIVED_OBJECT' to ensure
2388 # (1) uniqueness, and (2) continuity between
2389 # invocations. However, this will result in a
2390 # name that is too long for losing systems, in
2391 # some situations. So we provide _SHORTNAME to
2392 # override.
2394 my $dname = $derived;
2395 if (variable_defined ($derived . '_SHORTNAME'))
2397 # FIXME: should use the same conditional as
2398 # the _SOURCES variable. But this is really
2399 # silly overkill -- nobody should have
2400 # conditional shortnames.
2401 $dname = &variable_value ($derived . '_SHORTNAME');
2403 $object = $dname . '-' . $object;
2405 require_conf_file ("$am_file.am", FOREIGN, 'compile')
2406 if $lang->name eq 'c';
2408 prog_error ($lang->name . " flags defined without compiler")
2409 if ! defined $lang->compile;
2411 $renamed = 1;
2414 # If rewrite said it was ok, put the object into a
2415 # subdir.
2416 if ($r == LANG_SUBDIR && $directory ne '')
2418 $object = $directory . '/' . $object;
2421 # If doing dependency tracking, then we can't print
2422 # the rule. If we have a subdir object, we need to
2423 # generate an explicit rule. Actually, in any case
2424 # where the object is not in `.' we need a special
2425 # rule. The per-object rules in this case are
2426 # generated later, by handle_languages.
2427 if ($renamed || $directory ne '')
2429 my $obj_sans_ext = substr ($object, 0,
2430 - length ($this_obj_ext));
2431 if ($lang->ansi && defined $options{'ansi2knr'})
2433 $full_ansi =~ s/$KNOWN_EXTENSIONS_PATTERN$/\$U$&/;
2434 $full_ansi = basename $full_ansi
2435 unless defined $options{'subdir-objects'};
2438 my $val = ("$full_ansi $obj_sans_ext "
2439 # Only use $this_obj_ext in the derived
2440 # source case because in the other case we
2441 # *don't* want $(OBJEXT) to appear here.
2442 . ($derived_source ? $this_obj_ext : '.o'));
2444 # If we renamed the object then we want to use the
2445 # per-executable flag name. But if this is simply a
2446 # subdir build then we still want to use the AM_ flag
2447 # name.
2448 if ($renamed)
2450 $val = "$derived $val";
2451 $aggregate = $derived;
2453 else
2455 $val = "AM $val";
2458 # Each item on this list is a string consisting of
2459 # four space-separated values: the derived flag prefix
2460 # (eg, for `foo_CFLAGS', it is `foo'), the name of the
2461 # source file, the base name of the output file, and
2462 # the extension for the object file.
2463 push (@{$lang_specific_files{$lang->name}}, $val);
2466 elsif ($extension eq $nonansi_obj)
2468 # This is probably the result of a direct suffix rule.
2469 # In this case we just accept the rewrite.
2470 $object = "$base$extension";
2471 $linker = '';
2473 else
2475 # No error message here. Used to have one, but it was
2476 # very unpopular.
2477 # FIXME: we could potentially do more processing here,
2478 # perhaps treating the new extension as though it were a
2479 # new source extension (as above). This would require
2480 # more restructuring than is appropriate right now.
2481 next;
2484 err_am "object `$object' created by `$full' and `$object_map{$object}'"
2485 if (defined $object_map{$object}
2486 && $object_map{$object} ne $full);
2488 my $comp_val = (($object =~ /\.lo$/)
2489 ? COMPILE_LIBTOOL : COMPILE_ORDINARY);
2490 (my $comp_obj = $object) =~ s/\.lo$/.\$(OBJEXT)/;
2491 if (defined $object_compilation_map{$comp_obj}
2492 && $object_compilation_map{$comp_obj} != 0
2493 # Only see the error once.
2494 && ($object_compilation_map{$comp_obj}
2495 != (COMPILE_LIBTOOL | COMPILE_ORDINARY))
2496 && $object_compilation_map{$comp_obj} != $comp_val)
2498 err_am "object `$object' created both with libtool and without";
2500 $object_compilation_map{$comp_obj} |= $comp_val;
2502 if (defined $lang)
2504 # Let the language do some special magic if required.
2505 $lang->target_hook ($aggregate, $object, $full);
2508 if ($derived_source)
2510 prog_error ($lang->name . " has automatic dependency tracking")
2511 if $lang->autodep ne 'no';
2512 # Make sure this new source file is handled next. That will
2513 # make it appear to be at the right place in the list.
2514 unshift (@files, $object);
2515 # Distribute derived sources unless the source they are
2516 # derived from is not.
2517 &push_dist_common ($object)
2518 unless ($topparent =~ /^(?:nobase_)?nodist_/);
2519 next;
2522 $linkers_used{$linker} = 1;
2524 push (@result, $object);
2526 if (! defined $object_map{$object})
2528 my @dep_list = ();
2529 $object_map{$object} = $full;
2531 # If file is in subdirectory, we need explicit
2532 # dependency.
2533 if ($directory ne '' || $renamed)
2535 push (@dep_list, $full_ansi);
2538 # If resulting object is in subdir, we need to make
2539 # sure the subdir exists at build time.
2540 if ($object =~ /\//)
2542 # FIXME: check that $DIRECTORY is somewhere in the
2543 # project
2545 # For Java, the way we're handling it right now, a
2546 # `..' component doesn't make sense.
2547 if ($lang->name eq 'java' && $object =~ /(\/|^)\.\.\//)
2549 err_am "`$full' should not contain a `..' component";
2552 # Make sure object is removed by `make mostlyclean'.
2553 $compile_clean_files{$object} = MOSTLY_CLEAN;
2554 # If we have a libtool object then we also must remove
2555 # the ordinary .o.
2556 if ($object =~ /\.lo$/)
2558 (my $xobj = $object) =~ s,lo$,\$(OBJEXT),;
2559 $compile_clean_files{$xobj} = MOSTLY_CLEAN;
2561 # Remove any libtool object in this directory.
2562 $libtool_clean_directories{$directory} = 1;
2565 push (@dep_list, require_build_directory ($directory));
2567 # If we're generating dependencies, we also want
2568 # to make sure that the appropriate subdir of the
2569 # .deps directory is created.
2570 push (@dep_list,
2571 require_build_directory ($directory . '/$(DEPDIR)'))
2572 if $use_dependencies;
2575 &pretty_print_rule ($object . ':', "\t", @dep_list)
2576 if scalar @dep_list > 0;
2579 # Transform .o or $o file into .P file (for automatic
2580 # dependency code).
2581 if ($lang && $lang->autodep ne 'no')
2583 my $depfile = $object;
2584 $depfile =~ s/\.([^.]*)$/.P$1/;
2585 $depfile =~ s/\$\(OBJEXT\)$/o/;
2586 $dep_files{dirname ($depfile) . '/$(DEPDIR)/'
2587 . basename ($depfile)} = 1;
2591 return @result;
2594 # ($LINKER, $OBJVAR)
2595 # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
2596 # $OBJ, $PARENT, $TOPPARENT)
2597 # ---------------------------------------------------------------------
2598 # Define an _OBJECTS variable for a _SOURCES variable (or subvariable)
2600 # Arguments are:
2601 # $VAR is the name of the _SOURCES variable
2602 # $OBJVAR is the name of the _OBJECTS variable if known (otherwise
2603 # it will be generated and returned).
2604 # $NODEFINE is a boolean: if true, $OBJVAR will not be defined (but
2605 # work done to determine the linker will be).
2606 # $ONE_FILE is the canonical (transformed) name of object to build
2607 # $OBJ is the object extension (ie either `.o' or `.lo').
2608 # $PARENT is the variable in which $VAR is used, or $VAR if not applicable.
2609 # $TOPPARENT is the _SOURCES variable being processed.
2611 # Result is a pair ($LINKER, $OBJVAR):
2612 # $LINKER is a boolean, true if a linker is needed to deal with the objects,
2613 # $OBJVAR is the name of the variable defined to hold the objects.
2615 # %linkers_used, %vars_scanned, @substfroms and @substtos should be cleared
2616 # before use:
2617 # %linkers_used variable will be set to contain the linkers desired.
2618 # %vars_scanned will be used to check for recursive definitions.
2619 # @substfroms and @substtos will be used to keep a stack of variable
2620 # substitutions to be applied.
2622 sub define_objects_from_sources ($$$$$$$)
2624 my ($var, $objvar, $nodefine, $one_file, $obj, $parent, $topparent) = @_;
2626 if (defined $vars_scanned{$var})
2628 err_var $var, "variable `$var' recursively defined";
2629 return "";
2631 $vars_scanned{$var} = 1;
2633 my $needlinker = "";
2634 my @allresults = ();
2635 foreach my $cond (variable_conditions ($var))
2637 my @result;
2638 foreach my $val (&variable_value_as_list ($var, $cond, $parent))
2640 # If $val is a variable (i.e. ${foo} or $(bar), not a filename),
2641 # handle the sub variable recursively.
2642 if ($val =~ /^\$\{([^}]*)\}$/ || $val =~ /^\$\(([^)]*)\)$/)
2644 my $subvar = $1;
2646 # If the user uses a losing variable name, just ignore it.
2647 # This isn't ideal, but people have requested it.
2648 next if ($subvar =~ /\@.*\@/);
2650 # See if the variable is actually a substitution reference
2651 my ($from, $to);
2652 my @temp_list;
2653 if ($subvar =~ /$SUBST_REF_PATTERN/o)
2655 $subvar = $1;
2656 $to = $3;
2657 $from = quotemeta $2;
2659 push @substfroms, $from;
2660 push @substtos, $to;
2662 my ($temp, $varname)
2663 = define_objects_from_sources ($subvar, undef,
2664 $nodefine, $one_file,
2665 $obj, $var, $topparent);
2667 push (@result, '$('. $varname . ')');
2668 $needlinker ||= $temp;
2670 pop @substfroms;
2671 pop @substtos;
2673 else # $var is a filename
2675 my $substnum=$#substfroms;
2676 while ($substnum >= 0)
2678 $val =~ s/$substfroms[$substnum]$/$substtos[$substnum]/
2679 if defined $substfroms[$substnum];
2680 $substnum -= 1;
2683 my (@transformed) =
2684 &handle_single_transform_list ($var, $topparent, $one_file, $obj, $val);
2685 push (@result, @transformed);
2686 $needlinker = "true" if @transformed;
2689 push (@allresults, [$cond, @result]);
2691 # Find a name for the variable, unless imposed.
2692 $objvar = subobjname (@allresults) unless defined $objvar;
2693 # Define _OBJECTS conditionally
2694 unless ($nodefine)
2696 foreach my $pair (@allresults)
2698 my ($cond, @result) = @$pair;
2699 define_pretty_variable ($objvar, $cond, @result);
2703 delete $vars_scanned{$var};
2704 return ($needlinker, $objvar);
2708 # $VARNAME
2709 # subobjname (@DEFINITIONS)
2710 # -------------------------
2711 # Return a name for an object variable that with definitions @DEFINITIONS.
2712 # @DEFINITIONS is a list of pair [$COND, @OBJECTS].
2714 # If we already have an object variable containing @DEFINITIONS, reuse it.
2715 # This way, we avoid combinatorial explosion of the generated
2716 # variables. Especially, in a Makefile such as:
2718 # | if FOO1
2719 # | A1=1
2720 # | endif
2722 # | if FOO2
2723 # | A2=2
2724 # | endif
2726 # | ...
2728 # | if FOON
2729 # | AN=N
2730 # | endif
2732 # | B=$(A1) $(A2) ... $(AN)
2734 # | c_SOURCES=$(B)
2735 # | d_SOURCES=$(B)
2737 # The generated c_OBJECTS and d_OBJECTS will share the same variable
2738 # definitions.
2740 # This setup can be the case of a testsuite containing lots (>100) of
2741 # small C programs, all testing the same set of source files.
2742 sub subobjname (@)
2744 my $key = '';
2745 foreach my $pair (@_)
2747 my ($cond, @values) = @$pair;
2748 $key .= "($cond)@values";
2751 return $subobjvar{$key} if exists $subobjvar{$key};
2753 my $num = 1 + keys (%subobjvar);
2754 my $name = "am__objects_${num}";
2755 $subobjvar{$key} = $name;
2756 return $name;
2760 # Handle SOURCE->OBJECT transform for one program or library.
2761 # Arguments are:
2762 # canonical (transformed) name of object to build
2763 # actual name of object to build
2764 # object extension (ie either `.o' or `$o'.
2765 # Return result is name of linker variable that must be used.
2766 # Empty return means just use `LINK'.
2767 sub handle_source_transform
2769 # one_file is canonical name. unxformed is given name. obj is
2770 # object extension.
2771 my ($one_file, $unxformed, $obj) = @_;
2773 my ($linker) = '';
2775 # No point in continuing if _OBJECTS is defined.
2776 return if reject_var ($one_file . '_OBJECTS',
2777 $one_file . '_OBJECTS should not be defined');
2779 my %used_pfx = ();
2780 my $needlinker;
2781 %linkers_used = ();
2782 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2783 'dist_EXTRA_', 'nodist_EXTRA_')
2785 my $var = $prefix . $one_file . "_SOURCES";
2786 next
2787 if !variable_defined ($var);
2789 # We are going to define _OBJECTS variables using the prefix.
2790 # Then we glom them all together. So we can't use the null
2791 # prefix here as we need it later.
2792 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2794 # Keep track of which prefixes we saw.
2795 $used_pfx{$xpfx} = 1
2796 unless $prefix =~ /EXTRA_/;
2798 push @sources, "\$($var)";
2799 if ($prefix !~ /^nodist_/)
2801 # If the VAR wasn't definined conditionally, we add
2802 # it to DIST_SOURCES as is. Otherwise we create a
2803 # am__VAR_DIST variable which contains all possible values,
2804 # and add this variable to DIST_SOURCES.
2805 my $distvar = "$var";
2806 my @conds = variable_conditions_recursive ($var);
2807 if (@conds && $conds[0] ne 'TRUE')
2809 $distvar = "am__${var}_DIST";
2810 my @files =
2811 uniq (variable_value_as_list_recursive ($var, 'all'));
2812 define_pretty_variable ($distvar, '', @files);
2814 push @dist_sources, "\$($distvar)"
2817 @substfroms = ();
2818 @substtos = ();
2819 %vars_scanned = ();
2820 my ($temp, $objvar) =
2821 define_objects_from_sources ($var,
2822 $xpfx . $one_file . '_OBJECTS',
2823 $prefix =~ /EXTRA_/,
2824 $one_file, $obj, $var, $var);
2825 $needlinker ||= $temp;
2827 if ($needlinker)
2829 $linker ||= &resolve_linker (%linkers_used);
2832 my @keys = sort keys %used_pfx;
2833 if (scalar @keys == 0)
2835 &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
2836 push (@sources, $unxformed . '.c');
2837 push (@dist_sources, $unxformed . '.c');
2839 %linkers_used = ();
2840 my (@result) =
2841 &handle_single_transform_list ($one_file . '_SOURCES',
2842 $one_file . '_SOURCES',
2843 $one_file, $obj,
2844 "$unxformed.c");
2845 $linker ||= &resolve_linker (%linkers_used);
2846 define_pretty_variable ($one_file . "_OBJECTS", '', @result)
2848 else
2850 grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
2851 define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
2854 # If we want to use `LINK' we must make sure it is defined.
2855 if ($linker eq '')
2857 $need_link = 1;
2860 return $linker;
2864 # handle_lib_objects ($XNAME, $VAR)
2865 # ---------------------------------
2866 # Special-case ALLOCA and LIBOBJS substitutions in _LDADD or _LIBADD variables.
2867 # Also, generate _DEPENDENCIES variable if appropriate.
2868 # Arguments are:
2869 # transformed name of object being built, or empty string if no object
2870 # name of _LDADD/_LIBADD-type variable to examine
2871 # Returns 1 if LIBOBJS seen, 0 otherwise.
2872 sub handle_lib_objects
2874 my ($xname, $var) = @_;
2876 prog_error "handle_lib_objects: $var undefined"
2877 if ! variable_defined ($var);
2879 my $ret = 0;
2880 foreach my $cond (variable_conditions_recursive ($var))
2882 if (&handle_lib_objects_cond ($xname, $var, $cond))
2884 $ret = 1;
2887 return $ret;
2890 # Subroutine of handle_lib_objects: handle a particular condition.
2891 sub handle_lib_objects_cond
2893 my ($xname, $var, $cond) = @_;
2895 # We recognize certain things that are commonly put in LIBADD or
2896 # LDADD.
2897 my @dep_list = ();
2899 my $seen_libobjs = 0;
2900 my $flagvar = 0;
2902 foreach my $lsearch (&variable_value_as_list_recursive ($var, $cond))
2904 # Skip -lfoo and -Ldir; these are explicitly allowed.
2905 next if $lsearch =~ /^-[lL]/;
2906 if (! $flagvar && $lsearch =~ /^-/)
2908 if ($var =~ /^(.*)LDADD$/)
2910 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
2911 next if $lsearch =~ /^-dl(pre)?open$/;
2912 my $prefix = $1 || 'AM_';
2913 err_var ($var, "linker flags such as `$lsearch' belong in "
2914 . "`${prefix}LDFLAGS");
2916 else
2918 $var =~ /^(.*)LIBADD$/;
2919 # Only get this error once.
2920 $flagvar = 1;
2921 err_var ($var, "linker flags such as `$lsearch' belong in "
2922 . "`${1}LDFLAGS");
2926 # Assume we have a file of some sort, and push it onto the
2927 # dependency list. Autoconf substitutions are not pushed;
2928 # rarely is a new dependency substituted into (eg) foo_LDADD
2929 # -- but "bad things (eg -lX11) are routinely substituted.
2930 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2931 # and handled specially below.
2932 push (@dep_list, $lsearch)
2933 unless $lsearch =~ /^\@.*\@$/;
2935 # Automatically handle LIBOBJS and ALLOCA substitutions.
2936 # Basically this means adding entries to dep_files.
2937 if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
2939 my $lt = $1 ? $1 : '';
2940 my $myobjext = ($1 ? 'l' : '') . 'o';
2942 push (@dep_list, $lsearch);
2943 $seen_libobjs = 1;
2944 if (! keys %libsources
2945 && ! variable_defined ($lt . 'LIBOBJS'))
2947 err_var ($var, "\@${lt}LIBOBJS\@ seen but never set in "
2948 . "`$configure_ac'");
2951 foreach my $iter (keys %libsources)
2953 if ($iter =~ /\.[cly]$/)
2955 &saw_extension ($&);
2956 &saw_extension ('.c');
2959 if ($iter =~ /\.h$/)
2961 require_file_with_macro ($cond, $var, FOREIGN, $iter);
2963 elsif ($iter ne 'alloca.c')
2965 my $rewrite = $iter;
2966 $rewrite =~ s/\.c$/.P$myobjext/;
2967 $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
2968 $rewrite = "^" . quotemeta ($iter) . "\$";
2969 # Only require the file if it is not a built source.
2970 if (! variable_defined ('BUILT_SOURCES')
2971 || ! grep (/$rewrite/,
2972 &variable_value_as_list_recursive (
2973 'BUILT_SOURCES', 'all')))
2975 require_file_with_macro ($cond, $var, FOREIGN, $iter);
2980 elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
2982 my $lt = $1 ? $1 : '';
2983 my $myobjext = ($1 ? 'l' : '') . 'o';
2985 push (@dep_list, $lsearch);
2986 err_var ($var, "\@${lt}ALLOCA\@ seen but `AC_FUNC_ALLOCA' not in "
2987 . "`$configure_ac'")
2988 if ! defined $libsources{'alloca.c'};
2989 $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
2990 require_file_with_macro ($cond, $var, FOREIGN, 'alloca.c');
2991 &saw_extension ('c');
2995 if ($xname ne '')
2997 my $depvar = $xname . '_DEPENDENCIES';
2998 if ((conditional_ambiguous_p ($depvar, $cond,
2999 keys %{$var_value{$depvar}}))[0] ne '')
3001 # Note that we've examined this.
3002 &examine_variable ($depvar);
3004 else
3006 define_pretty_variable ($depvar, $cond, @dep_list);
3010 return $seen_libobjs;
3013 # Canonicalize the input parameter
3014 sub canonicalize
3016 my ($string) = @_;
3017 $string =~ tr/A-Za-z0-9_\@/_/c;
3018 return $string;
3021 # Canonicalize a name, and check to make sure the non-canonical name
3022 # is never used. Returns canonical name. Arguments are name and a
3023 # list of suffixes to check for.
3024 sub check_canonical_spelling
3026 my ($name, @suffixes) = @_;
3028 my $xname = &canonicalize ($name);
3029 if ($xname ne $name)
3031 foreach my $xt (@suffixes)
3033 reject_var ("$name$xt", "use `$xname$xt', not `$name$xt'");
3037 return $xname;
3041 # handle_compile ()
3042 # -----------------
3043 # Set up the compile suite.
3044 sub handle_compile ()
3046 return
3047 unless $get_object_extension_was_run;
3049 # Boilerplate.
3050 my $default_includes = '';
3051 if (! defined $options{'nostdinc'})
3053 $default_includes = ' -I. -I$(srcdir)';
3055 if (variable_defined ('CONFIG_HEADER'))
3057 foreach my $hdr (split (' ', &variable_value ('CONFIG_HEADER')))
3059 $default_includes .= ' -I' . dirname ($hdr);
3064 my (@mostly_rms, @dist_rms);
3065 foreach my $item (sort keys %compile_clean_files)
3067 if ($compile_clean_files{$item} == MOSTLY_CLEAN)
3069 push (@mostly_rms, "\t-rm -f $item");
3071 elsif ($compile_clean_files{$item} == DIST_CLEAN)
3073 push (@dist_rms, "\t-rm -f $item");
3075 else
3077 prog_error 'invalid entry in %compile_clean_files';
3081 my ($coms, $vars, $rules) =
3082 &file_contents_internal (1, "$libdir/am/compile.am",
3083 ('DEFAULT_INCLUDES' => $default_includes,
3084 'MOSTLYRMS' => join ("\n", @mostly_rms),
3085 'DISTRMS' => join ("\n", @dist_rms)));
3086 $output_vars .= $vars;
3087 $output_rules .= "$coms$rules";
3089 # Check for automatic de-ANSI-fication.
3090 if (defined $options{'ansi2knr'})
3092 require_variables_for_macro ('AUTOMAKE_OPTIONS',
3093 "option `ansi2knr' is used",
3094 "ANSI2KNR", "U");
3096 # topdir is where ansi2knr should be.
3097 if ($options{'ansi2knr'} eq 'ansi2knr')
3099 # Only require ansi2knr files if they should appear in
3100 # this directory.
3101 require_file_with_macro ('TRUE', 'AUTOMAKE_OPTIONS', FOREIGN,
3102 'ansi2knr.c', 'ansi2knr.1');
3104 # ansi2knr needs to be built before subdirs, so unshift it.
3105 unshift (@all, '$(ANSI2KNR)');
3108 my $ansi2knr_dir = '';
3109 $ansi2knr_dir = dirname ($options{'ansi2knr'})
3110 if $options{'ansi2knr'} ne 'ansi2knr';
3112 $output_rules .= &file_contents ('ansi2knr',
3113 ('ANSI2KNR-DIR' => $ansi2knr_dir));
3118 # handle_libtool ()
3119 # -----------------
3120 # Handle libtool rules.
3121 sub handle_libtool
3123 return unless variable_defined ('LIBTOOL');
3125 # Libtool requires some files, but only at top level.
3126 require_conf_file_with_macro ('TRUE', 'LIBTOOL', FOREIGN, @libtool_files)
3127 if $relative_dir eq '.';
3129 my @libtool_rms;
3130 foreach my $item (sort keys %libtool_clean_directories)
3132 my $dir = ($item eq '.') ? '' : "$item/";
3133 # .libs is for Unix, _libs for DOS.
3134 push (@libtool_rms, "\t-rm -rf ${dir}.libs ${dir}_libs");
3137 # Output the libtool compilation rules.
3138 $output_rules .= &file_contents ('libtool',
3139 ('LTRMS' => join ("\n", @libtool_rms)));
3142 # handle_programs ()
3143 # ------------------
3144 # Handle C programs.
3145 sub handle_programs
3147 my @proglist = &am_install_var ('progs', 'PROGRAMS',
3148 'bin', 'sbin', 'libexec', 'pkglib',
3149 'noinst', 'check');
3150 return if ! @proglist;
3152 my $seen_global_libobjs =
3153 variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD');
3155 foreach my $one_file (@proglist)
3157 my $seen_libobjs = 0;
3158 my $obj = &get_object_extension ($one_file);
3160 # Canonicalize names and check for misspellings.
3161 my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
3162 '_SOURCES', '_OBJECTS',
3163 '_DEPENDENCIES');
3165 my $linker = &handle_source_transform ($xname, $one_file, $obj);
3167 my $xt = '';
3168 if (variable_defined ($xname . "_LDADD"))
3170 $seen_libobjs = &handle_lib_objects ($xname, $xname . '_LDADD');
3171 $xt = '_LDADD';
3173 else
3175 # User didn't define prog_LDADD override. So do it.
3176 &define_variable ($xname . '_LDADD', '$(LDADD)');
3178 # This does a bit too much work. But we need it to
3179 # generate _DEPENDENCIES when appropriate.
3180 if (variable_defined ('LDADD'))
3182 $seen_libobjs = &handle_lib_objects ($xname, 'LDADD');
3184 elsif (! variable_defined ($xname . '_DEPENDENCIES'))
3186 &define_variable ($xname . '_DEPENDENCIES', '');
3188 $xt = '_SOURCES';
3191 reject_var ($xname . '_LIBADD',
3192 "use `${xname}_LDADD', not `${xname}_LIBADD'");
3194 if (! variable_defined ($xname . '_LDFLAGS'))
3196 # Define the prog_LDFLAGS variable.
3197 &define_variable ($xname . '_LDFLAGS', '');
3200 # Determine program to use for link.
3201 my $xlink;
3202 if (variable_defined ($xname . '_LINK'))
3204 $xlink = $xname . '_LINK';
3206 else
3208 $xlink = $linker ? $linker : 'LINK';
3211 # If the resulting program lies into a subdirectory,
3212 # make sure this directory will exist.
3213 my $dirstamp = require_build_directory_maybe ($one_file);
3215 # Don't add $(EXEEXT) if user already did.
3216 my $extension = ($one_file !~ /\$\(EXEEXT\)$/
3217 ? "\$(EXEEXT)"
3218 : '');
3220 $output_rules .= &file_contents ('program',
3221 ('PROGRAM' => $one_file,
3222 'XPROGRAM' => $xname,
3223 'XLINK' => $xlink,
3224 'DIRSTAMP' => $dirstamp,
3225 'EXEEXT' => $extension));
3227 if ($seen_libobjs || $seen_global_libobjs)
3229 if (variable_defined ($xname . '_LDADD'))
3231 &check_libobjs_sources ($xname, $xname . '_LDADD');
3233 elsif (variable_defined ('LDADD'))
3235 &check_libobjs_sources ($xname, 'LDADD');
3242 # handle_libraries ()
3243 # -------------------
3244 # Handle libraries.
3245 sub handle_libraries
3247 my @liblist = &am_install_var ('libs', 'LIBRARIES',
3248 'lib', 'pkglib', 'noinst', 'check');
3249 return if ! @liblist;
3251 my @prefix = am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
3252 'noinst', 'check');
3254 require_variables_for_macro ($prefix[0] . '_LIBRARIES',
3255 'library used', 'RANLIB')
3256 if (@prefix);
3258 foreach my $onelib (@liblist)
3260 my $seen_libobjs = 0;
3261 # Check that the library fits the standard naming convention.
3262 if (basename ($onelib) !~ /^lib.*\.a/)
3264 # FIXME should put line number here. That means mapping
3265 # from library name back to variable name.
3266 err_am "`$onelib' is not a standard library name";
3269 my $obj = &get_object_extension ($onelib);
3271 # Canonicalize names and check for misspellings.
3272 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
3273 '_OBJECTS', '_DEPENDENCIES',
3274 '_AR');
3276 if (! variable_defined ($xlib . '_AR'))
3278 &define_variable ($xlib . '_AR', '$(AR) cru');
3281 if (variable_defined ($xlib . '_LIBADD'))
3283 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
3285 $seen_libobjs = 1;
3288 else
3290 # Generate support for conditional object inclusion in
3291 # libraries.
3292 &define_variable ($xlib . "_LIBADD", '');
3295 reject_var ($xlib . '_LDADD',
3296 "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
3298 # Make sure we at look at this.
3299 &examine_variable ($xlib . '_DEPENDENCIES');
3301 &handle_source_transform ($xlib, $onelib, $obj);
3303 # If the resulting library lies into a subdirectory,
3304 # make sure this directory will exist.
3305 my $dirstamp = require_build_directory_maybe ($onelib);
3307 $output_rules .= &file_contents ('library',
3308 ('LIBRARY' => $onelib,
3309 'XLIBRARY' => $xlib,
3310 'DIRSTAMP' => $dirstamp));
3312 if ($seen_libobjs)
3314 if (variable_defined ($xlib . '_LIBADD'))
3316 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
3323 # handle_ltlibraries ()
3324 # ---------------------
3325 # Handle shared libraries.
3326 sub handle_ltlibraries
3328 my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
3329 'noinst', 'lib', 'pkglib', 'check');
3330 return if ! @liblist;
3332 my %instdirs;
3333 my @prefix = am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
3334 'noinst', 'check');
3336 require_variables_for_macro ($prefix[0] . '_LTLIBRARIES',
3337 'Libtool library used', 'LIBTOOL')
3338 if (@prefix);
3340 foreach my $key (@prefix)
3342 # Get the installation directory of each library.
3343 (my $dir = $key) =~ s/^nobase_//;
3344 for (variable_value_as_list_recursive ($key . '_LTLIBRARIES', 'all'))
3346 # We reject libraries which are installed in several places,
3347 # because we don't handle this in the rules (think `-rpath').
3349 # However, we allow the same library to be listed many times
3350 # for the same directory. This is for users who need setups
3351 # like
3352 # if COND1
3353 # lib_LTLIBRARIES = libfoo.la
3354 # endif
3355 # if COND2
3356 # lib_LTLIBRARIES = libfoo.la
3357 # endif
3359 # Actually this will also allow
3360 # lib_LTLIBRARIES = libfoo.la libfoo.la
3361 # Diagnosing this case doesn't seem worth the plain (we'd
3362 # have to fill $instdirs on a per-condition basis, check
3363 # implied conditions, etc.)
3364 if (defined $instdirs{$_} && $instdirs{$_} ne $dir)
3366 err_am ("`$_' is already going to be installed in "
3367 . "`$instdirs{$_}'");
3369 else
3371 $instdirs{$_} = $dir;
3376 foreach my $onelib (@liblist)
3378 my $seen_libobjs = 0;
3379 my $obj = &get_object_extension ($onelib);
3381 # Canonicalize names and check for misspellings.
3382 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
3383 '_SOURCES', '_OBJECTS',
3384 '_DEPENDENCIES');
3386 if (! variable_defined ($xlib . '_LDFLAGS'))
3388 # Define the lib_LDFLAGS variable.
3389 &define_variable ($xlib . '_LDFLAGS', '');
3392 # Check that the library fits the standard naming convention.
3393 my $libname_rx = "^lib.*\.la";
3394 if ((variable_defined ($xlib . '_LDFLAGS')
3395 && grep (/-module/,
3396 &variable_value_as_list_recursive ($xlib . '_LDFLAGS',
3397 'all')))
3398 || (variable_defined ('LDFLAGS')
3399 && grep (/-module/,
3400 &variable_value_as_list_recursive ('LDFLAGS', 'all'))))
3402 # Relax name checking for libtool modules.
3403 $libname_rx = "\.la";
3405 if (basename ($onelib) !~ /$libname_rx$/)
3407 # FIXME should put line number here. That means mapping
3408 # from library name back to variable name.
3409 msg_am ('error-gnu/warn',
3410 "`$onelib' is not a standard libtool library name");
3413 if (variable_defined ($xlib . '_LIBADD'))
3415 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
3417 $seen_libobjs = 1;
3420 else
3422 # Generate support for conditional object inclusion in
3423 # libraries.
3424 &define_variable ($xlib . "_LIBADD", '');
3427 reject_var ("${xlib}_LDADD",
3428 "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
3430 # Make sure we at look at this.
3431 &examine_variable ($xlib . '_DEPENDENCIES');
3433 my $linker = &handle_source_transform ($xlib, $onelib, $obj);
3435 # Determine program to use for link.
3436 my $xlink;
3437 if (variable_defined ($xlib . '_LINK'))
3439 $xlink = $xlib . '_LINK';
3441 else
3443 $xlink = $linker ? $linker : 'LINK';
3446 my $rpath;
3447 if ($instdirs{$onelib} eq 'EXTRA'
3448 || $instdirs{$onelib} eq 'noinst'
3449 || $instdirs{$onelib} eq 'check')
3451 # It's an EXTRA_ library, so we can't specify -rpath,
3452 # because we don't know where the library will end up.
3453 # The user probably knows, but generally speaking automake
3454 # doesn't -- and in fact configure could decide
3455 # dynamically between two different locations.
3456 $rpath = '';
3458 else
3460 $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
3463 # If the resulting library lies into a subdirectory,
3464 # make sure this directory will exist.
3465 my $dirstamp = require_build_directory_maybe ($onelib);
3467 # Remember to cleanup .libs/ in this directory.
3468 my $dirname = dirname $onelib;
3469 $libtool_clean_directories{$dirname} = 1;
3471 $output_rules .= &file_contents ('ltlibrary',
3472 ('LTLIBRARY' => $onelib,
3473 'XLTLIBRARY' => $xlib,
3474 'RPATH' => $rpath,
3475 'XLINK' => $xlink,
3476 'DIRSTAMP' => $dirstamp));
3477 if ($seen_libobjs)
3479 if (variable_defined ($xlib . '_LIBADD'))
3481 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
3487 # See if any _SOURCES variable were misspelled.
3488 sub check_typos ()
3490 # It is ok if the user sets this particular variable.
3491 &examine_variable ('AM_LDFLAGS');
3493 foreach my $varname (keys %var_value)
3495 foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
3496 '_DEPENDENCIES')
3498 msg_var 'syntax', $varname, "unused variable: `$varname'"
3499 # Note that a configure variable is always legitimate.
3500 if ($varname =~ /$primary$/ && ! $content_seen{$varname}
3501 && ! exists $configure_vars{$varname});
3507 # Handle scripts.
3508 sub handle_scripts
3510 # NOTE we no longer automatically clean SCRIPTS, because it is
3511 # useful to sometimes distribute scripts verbatim. This happens
3512 # eg in Automake itself.
3513 &am_install_var ('-candist', 'scripts', 'SCRIPTS',
3514 'bin', 'sbin', 'libexec', 'pkgdata',
3515 'noinst', 'check');
3519 # ($OUTFILE, $VFILE, @CLEAN_FILES)
3520 # &scan_texinfo_file ($FILENAME)
3521 # ------------------------------
3522 # $OUTFILE is the name of the info file produced by $FILENAME.
3523 # $VFILE is the name of the version.texi file used (empty if none).
3524 # @CLEAN_FILES is the list of by products (indexes etc.)
3525 sub scan_texinfo_file
3527 my ($filename) = @_;
3529 # These are always created, no matter whether indexes are used or not.
3530 # (Actually tmp is only created if an @macro is used and a certain e-TeX
3531 # feature is not available.)
3532 my @clean_suffixes = qw(aux log toc tmp
3533 cp fn ky vr tp pg); # grep new.*index texinfo.tex
3535 # There are predefined indexes which don't follow the regular rules.
3536 my %predefined_index = qw(c cps
3537 f fns
3538 k kys
3539 v vrs
3540 t tps
3541 p pgs);
3543 # There are commands which include a hidden index command.
3544 my %hidden_index = (tp => 'tps');
3545 $hidden_index{$_} = 'fns' foreach qw(fn un typefn typefun max spec
3546 op typeop method typemethod);
3547 $hidden_index{$_} = 'vrs' foreach qw(vr var typevr typevar opt cv
3548 ivar typeivar);
3550 # Indexes stored into another one. In this case, the *.??s file
3551 # is not created.
3552 my @syncodeindexes = ();
3554 my $texi = new Automake::XFile "< $filename";
3555 verb "reading $filename";
3557 my ($outfile, $vfile);
3558 while ($_ = $texi->getline)
3560 if (/^\@setfilename +(\S+)/)
3562 $outfile = $1;
3563 if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
3565 err "$filename:$.", "output `$outfile' has unrecognized extension";
3566 return;
3569 # A "version.texi" file is actually any file whose name
3570 # matches "vers*.texi".
3571 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
3573 $vfile = $1;
3576 # Try to find what are the indexes which are used.
3578 # Creating a new category of index.
3579 elsif (/^\@def(code)?index (\w+)/)
3581 push @clean_suffixes, $2;
3584 # Storing in a predefined index.
3585 elsif (/^\@([cfkvtp])index /)
3587 push @clean_suffixes, $predefined_index{$1};
3589 elsif (/^\@def(\w+) /)
3591 push @clean_suffixes, $hidden_index{$1}
3592 if defined $hidden_index{$1};
3595 # Merging an index into an another.
3596 elsif (/^\@syn(code)?index (\w+) (\w+)/)
3598 push @syncodeindexes, "$2s";
3599 push @clean_suffixes, "$3s";
3604 if ($outfile eq '')
3606 err_am "`$filename' missing \@setfilename";
3607 return;
3610 my $infobase = basename ($filename);
3611 $infobase =~ s/\.te?xi(nfo)?$//;
3612 my %clean_files = map { +"$infobase.$_" => 1 } @clean_suffixes;
3613 grep { delete $clean_files{"$infobase.$_"} } @syncodeindexes;
3614 return ($outfile, $vfile, (sort keys %clean_files));
3617 # ($DIRSTAMP, @CLEAN_FILES)
3618 # output_texinfo_build_rules ($SOURCE, $DEST, @DEPENDENCIES)
3619 # ----------------------------------------------------------
3620 # SOURCE - the source Texinfo file
3621 # DEST - the destination Info file
3622 # DEPENDENCIES - known dependencies
3623 sub output_texinfo_build_rules ($$@)
3625 my ($source, $dest, @deps) = @_;
3627 # Split `a.texi' into `a' and `.texi'.
3628 my ($spfx, $ssfx) = ($source =~ /^(.*?)(\.[^.]*)?$/);
3629 my ($dpfx, $dsfx) = ($dest =~ /^(.*?)(\.[^.]*)?$/);
3631 $ssfx ||= "";
3632 $dsfx ||= "";
3634 # We can output two kinds of rules: the "generic" rules
3635 # use Make suffix rules and are appropritate when
3636 # $source and $dest lie in the current directory; the "specifix"
3637 # rules is needed in the other case.
3639 # The former are output only once (this is not really apparent
3640 # here, but just remember that some logic deeper in Automake will
3641 # not output the same rule twice); while the later need to be output
3642 # for each Texinfo source.
3643 my $generic;
3644 my $makeinfoflags;
3645 my $sdir = dirname $source;
3646 if ($sdir eq '.' && dirname ($dest) eq '.')
3648 $generic = 1;
3649 $makeinfoflags = '-I $(srcdir)';
3651 else
3653 $generic = 0;
3654 $makeinfoflags = "-I $sdir -I \$(srcdir)/$sdir";
3657 # If the resulting file lie into a subdirectory,
3658 # make sure this directory will exist.
3659 my $dirstamp = require_build_directory_maybe ($dest);
3661 $output_rules .= &file_contents ('texibuild',
3662 GENERIC => $generic,
3663 SOURCE_SUFFIX => $ssfx,
3664 SOURCE => ($generic ? '$<' : $source),
3665 SOURCE_REAL => $source,
3666 DEST_PREFIX => $dpfx,
3667 DEST_SUFFIX => $dsfx,
3668 MAKEINFOFLAGS => $makeinfoflags,
3669 DEPS => "@deps",
3670 DIRSTAMP => $dirstamp);
3671 return ($dirstamp, "$dpfx.dvi", "$dpfx.pdf", "$dpfx.ps");
3675 # ($DO-SOMETHING, $TEXICLEANS)
3676 # handle_texinfo_helper ()
3677 # ------------------------
3678 # Handle all Texinfo source; helper for handle_texinfo
3679 sub handle_texinfo_helper
3681 reject_var 'TEXINFOS', "`TEXINFOS' is an anachronism; use `info_TEXINFOS'";
3682 reject_var 'html_TEXINFOS', "HTML generation not yet supported";
3684 return (0, '') if ! variable_defined ('info_TEXINFOS');
3686 my @texis = &variable_value_as_list_recursive ('info_TEXINFOS', 'all');
3688 my (@info_deps_list, @dvis_list, @pdfs_list, @pss_list, @texi_deps);
3689 my %versions;
3690 my $done = 0;
3691 my @texi_cleans;
3692 my $canonical;
3694 foreach my $info_cursor (@texis)
3696 my $infobase = $info_cursor;
3697 $infobase =~ s/\.(txi|texinfo|texi)$//;
3699 if ($infobase eq $info_cursor)
3701 # FIXME: report line number.
3702 err_am "texinfo file `$info_cursor' has unrecognized extension";
3703 next;
3706 # If 'version.texi' is referenced by input file, then include
3707 # automatic versioning capability.
3708 my ($out_file, $vtexi, @clean_files) =
3709 &scan_texinfo_file ("$relative_dir/$info_cursor")
3710 or next;
3711 push (@texi_cleans, @clean_files);
3713 # If the Texinfo source is in a subdirectory, create the
3714 # resulting info in this subdirectory. If it is in the
3715 # current directory, try hard to not prefix "./" because
3716 # it breaks the generic rules.
3717 my $outdir = dirname ($info_cursor) . '/';
3718 $outdir = "" if $outdir eq './';
3719 $out_file = $outdir . $out_file;
3721 # If user specified file_TEXINFOS, then use that as explicit
3722 # dependency list.
3723 @texi_deps = ();
3724 push (@texi_deps, "$outdir$vtexi") if $vtexi;
3726 my $canonical = &canonicalize ($infobase);
3727 if (variable_defined ($canonical . "_TEXINFOS"))
3729 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
3730 &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
3733 my ($dirstamp, @cfiles) =
3734 output_texinfo_build_rules ($info_cursor, $out_file, @texi_deps);
3735 push (@texi_cleans, @cfiles);
3737 push (@info_deps_list, $out_file);
3738 push (@dvis_list, $infobase . '.dvi');
3739 push (@pdfs_list, $infobase . '.pdf');
3740 push (@pss_list, $infobase . '.ps');
3742 # If a vers*.texi file is needed, emit the rule.
3743 if ($vtexi)
3745 err_am ("`$vtexi', included in `$info_cursor', "
3746 . "also included in `$versions{$vtexi}'")
3747 if defined $versions{$vtexi};
3748 $versions{$vtexi} = $info_cursor;
3750 # We number the stamp-vti files. This is doable since the
3751 # actual names don't matter much. We only number starting
3752 # with the second one, so that the common case looks nice.
3753 my $vti = ($done ? $done : 'vti');
3754 ++$done;
3756 # This is ugly, but it is our historical practice.
3757 if ($config_aux_dir_set_in_configure_in)
3759 require_conf_file_with_macro ('TRUE', 'info_TEXINFOS', FOREIGN,
3760 'mdate-sh');
3762 else
3764 require_file_with_macro ('TRUE', 'info_TEXINFOS',
3765 FOREIGN, 'mdate-sh');
3768 my $conf_dir;
3769 if ($config_aux_dir_set_in_configure_in)
3771 $conf_dir = $config_aux_dir;
3772 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
3774 else
3776 $conf_dir = '$(srcdir)/';
3778 $output_rules .= &file_contents ('texi-vers',
3779 TEXI => $info_cursor,
3780 VTI => $vti,
3781 STAMPVTI => "${outdir}stamp-$vti",
3782 VTEXI => "$outdir$vtexi",
3783 MDDIR => $conf_dir,
3784 DIRSTAMP => $dirstamp);
3788 # Handle location of texinfo.tex.
3789 my $need_texi_file = 0;
3790 my $texinfodir;
3791 if ($cygnus_mode)
3793 $texinfodir = '$(top_srcdir)/../texinfo';
3794 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3796 elsif ($config_aux_dir_set_in_configure_in)
3798 $texinfodir = $config_aux_dir;
3799 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3800 $need_texi_file = 2; # so that we require_conf_file later
3802 elsif (variable_defined ('TEXINFO_TEX'))
3804 # The user defined TEXINFO_TEX so assume he knows what he is
3805 # doing.
3806 $texinfodir = ('$(srcdir)/'
3807 . dirname (&variable_value ('TEXINFO_TEX')));
3809 else
3811 $texinfodir = '$(srcdir)';
3812 $need_texi_file = 1;
3814 &define_variable ('am__TEXINFO_TEX_DIR', $texinfodir);
3816 # The return value.
3817 my $texiclean = &pretty_print_internal ("", "\t ", @texi_cleans);
3819 push (@dist_targets, 'dist-info');
3821 if (! defined $options{'no-installinfo'})
3823 # Make sure documentation is made and installed first. Use
3824 # $(INFO_DEPS), not 'info', because otherwise recursive makes
3825 # get run twice during "make all".
3826 unshift (@all, '$(INFO_DEPS)');
3829 &define_variable ("INFO_DEPS", "@info_deps_list");
3830 &define_variable ("DVIS", "@dvis_list");
3831 &define_variable ("PDFS", "@pdfs_list");
3832 &define_variable ("PSS", "@pss_list");
3833 # This next isn't strictly needed now -- the places that look here
3834 # could easily be changed to look in info_TEXINFOS. But this is
3835 # probably better, in case noinst_TEXINFOS is ever supported.
3836 &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
3838 # Do some error checking. Note that this file is not required
3839 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3840 # up above.
3841 if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
3843 if ($need_texi_file > 1)
3845 require_conf_file_with_macro ('TRUE', 'info_TEXINFOS', FOREIGN,
3846 'texinfo.tex');
3848 else
3850 require_file_with_macro ('TRUE', 'info_TEXINFOS', FOREIGN,
3851 'texinfo.tex');
3855 return (1, $texiclean);
3858 # handle_texinfo ()
3859 # -----------------
3860 # Handle all Texinfo source.
3861 sub handle_texinfo
3863 my ($do_something, $texiclean) = handle_texinfo_helper ();
3864 $output_rules .= &file_contents ('texinfos',
3865 ('TEXICLEAN' => $texiclean,
3866 'LOCAL-TEXIS' => $do_something));
3869 # Handle any man pages.
3870 sub handle_man_pages
3872 reject_var 'MANS', "`MANS' is an anachronism; use `man_MANS'";
3874 # Find all the sections in use. We do this by first looking for
3875 # "standard" sections, and then looking for any additional
3876 # sections used in man_MANS.
3877 my (%sections, %vlist);
3878 # We handle nodist_ for uniformity. man pages aren't distributed
3879 # by default so it isn't actually very important.
3880 foreach my $pfx ('', 'dist_', 'nodist_')
3882 # Add more sections as needed.
3883 foreach my $section ('0'..'9', 'n', 'l')
3885 if (variable_defined ($pfx . 'man' . $section . '_MANS'))
3887 $sections{$section} = 1;
3888 $vlist{'$(' . $pfx . 'man' . $section . '_MANS)'} = 1;
3890 &push_dist_common ('$(' . $pfx . 'man' . $section . '_MANS)')
3891 if $pfx eq 'dist_';
3895 if (variable_defined ($pfx . 'man_MANS'))
3897 $vlist{'$(' . $pfx . 'man_MANS)'} = 1;
3898 foreach (&variable_value_as_list_recursive ($pfx . 'man_MANS', 'all'))
3900 # A page like `foo.1c' goes into man1dir.
3901 if (/\.([0-9a-z])([a-z]*)$/)
3903 $sections{$1} = 1;
3907 &push_dist_common ('$(' . $pfx . 'man_MANS)')
3908 if $pfx eq 'dist_';
3912 return unless %sections;
3914 # Now for each section, generate an install and unintall rule.
3915 # Sort sections so output is deterministic.
3916 foreach my $section (sort keys %sections)
3918 $output_rules .= &file_contents ('mans', ('SECTION' => $section));
3921 my @mans = sort keys %vlist;
3922 $output_vars .= file_contents ('mans-vars',
3923 ('MANS' => "@mans"));
3925 if (! defined $options{'no-installman'})
3927 push (@all, '$(MANS)');
3931 # Handle DATA variables.
3932 sub handle_data
3934 &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3935 'data', 'sysconf', 'sharedstate', 'localstate',
3936 'pkgdata', 'noinst', 'check');
3939 # Handle TAGS.
3940 sub handle_tags
3942 my @tag_deps = ();
3943 my @ctag_deps = ();
3944 if (variable_defined ('SUBDIRS'))
3946 $output_rules .= ("tags-recursive:\n"
3947 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3948 # Never fail here if a subdir fails; it
3949 # isn't important.
3950 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3951 . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3952 . "\tdone\n");
3953 push (@tag_deps, 'tags-recursive');
3954 &depend ('.PHONY', 'tags-recursive');
3956 $output_rules .= ("ctags-recursive:\n"
3957 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3958 # Never fail here if a subdir fails; it
3959 # isn't important.
3960 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3961 . " && \$(MAKE) \$(AM_MAKEFLAGS) ctags); \\\n"
3962 . "\tdone\n");
3963 push (@ctag_deps, 'ctags-recursive');
3964 &depend ('.PHONY', 'ctags-recursive');
3967 if (&saw_sources_p (1)
3968 || variable_defined ('ETAGS_ARGS')
3969 || @tag_deps)
3971 my @config;
3972 foreach my $spec (@config_headers)
3974 my ($out, @ins) = split_config_file_spec ($spec);
3975 foreach my $in (@ins)
3977 # If the config header source is in this directory,
3978 # require it.
3979 push @config, basename ($in)
3980 if $relative_dir eq dirname ($in);
3983 $output_rules .= &file_contents ('tags',
3984 ('CONFIG' => "@config",
3985 'TAGSDIRS' => "@tag_deps",
3986 'CTAGSDIRS' => "@ctag_deps"));
3987 &examine_variable ('TAGS_DEPENDENCIES');
3989 elsif (reject_var ('TAGS_DEPENDENCIES',
3990 "doesn't make sense to define `TAGS_DEPENDENCIES'"
3991 . "without\nsources or `ETAGS_ARGS'"))
3994 else
3996 # Every Makefile must define some sort of TAGS rule.
3997 # Otherwise, it would be possible for a top-level "make TAGS"
3998 # to fail because some subdirectory failed.
3999 $output_rules .= "tags: TAGS\nTAGS:\n\n";
4000 # Ditto ctags.
4001 $output_rules .= "ctags: CTAGS\nCTAGS:\n\n";
4005 # Handle multilib support.
4006 sub handle_multilib
4008 if ($seen_multilib && $relative_dir eq '.')
4010 $output_rules .= &file_contents ('multilib');
4015 # $BOOLEAN
4016 # &for_dist_common ($A, $B)
4017 # -------------------------
4018 # Subroutine for &handle_dist: sort files to dist.
4020 # We put README first because it then becomes easier to make a
4021 # Usenet-compliant shar file (in these, README must be first).
4023 # FIXME: do more ordering of files here.
4024 sub for_dist_common
4026 return 0
4027 if $a eq $b;
4028 return -1
4029 if $a eq 'README';
4030 return 1
4031 if $b eq 'README';
4032 return $a cmp $b;
4036 # handle_dist ($MAKEFILE)
4037 # -----------------------
4038 # Handle 'dist' target.
4039 sub handle_dist
4041 my ($makefile) = @_;
4043 # `make dist' isn't used in a Cygnus-style tree.
4044 # Omit the rules so that people don't try to use them.
4045 return if $cygnus_mode;
4047 # Look for common files that should be included in distribution.
4048 # If the aux dir is set, and it does not have a Makefile.am, then
4049 # we check for these files there as well.
4050 my $check_aux = 0;
4051 my $auxdir = '';
4052 if ($relative_dir eq '.'
4053 && $config_aux_dir_set_in_configure_in)
4055 ($auxdir = $config_aux_dir) =~ s,^\$\(top_srcdir\)/,,;
4056 if (! &is_make_dir ($auxdir))
4058 $check_aux = 1;
4061 foreach my $cfile (@common_files)
4063 if (-f ($relative_dir . "/" . $cfile)
4064 # The file might be absent, but if it can be built it's ok.
4065 || exists $targets{$cfile})
4067 &push_dist_common ($cfile);
4070 # Don't use `elsif' here because a file might meaningfully
4071 # appear in both directories.
4072 if ($check_aux && -f ($auxdir . '/' . $cfile))
4074 &push_dist_common ($auxdir . '/' . $cfile);
4078 # We might copy elements from $configure_dist_common to
4079 # %dist_common if we think we need to. If the file appears in our
4080 # directory, we would have discovered it already, so we don't
4081 # check that. But if the file is in a subdir without a Makefile,
4082 # we want to distribute it here if we are doing `.'. Ugly!
4083 if ($relative_dir eq '.')
4085 foreach my $file (split (' ' , $configure_dist_common))
4087 push_dist_common ($file)
4088 unless is_make_dir (dirname ($file));
4094 # Files to distributed. Don't use &variable_value_as_list_recursive
4095 # as it recursively expands `$(dist_pkgdata_DATA)' etc.
4096 check_variable_defined_unconditionally ('DIST_COMMON');
4097 my @dist_common = split (' ', variable_value ('DIST_COMMON', 'TRUE'));
4098 @dist_common = uniq (sort for_dist_common (@dist_common));
4099 pretty_print ('DIST_COMMON = ', "\t", @dist_common);
4101 # Now that we've processed DIST_COMMON, disallow further attempts
4102 # to set it.
4103 $handle_dist_run = 1;
4105 # Scan EXTRA_DIST to see if we need to distribute anything from a
4106 # subdir. If so, add it to the list. I didn't want to do this
4107 # originally, but there were so many requests that I finally
4108 # relented.
4109 if (variable_defined ('EXTRA_DIST'))
4111 # FIXME: This should be fixed to work with conditionals. That
4112 # will require only making the entries in %dist_dirs under the
4113 # appropriate condition. This is meaningful if the nature of
4114 # the distribution should depend upon the configure options
4115 # used.
4116 foreach (&variable_value_as_list_recursive ('EXTRA_DIST', ''))
4118 next if /^\@.*\@$/;
4119 next unless s,/+[^/]+$,,;
4120 $dist_dirs{$_} = 1
4121 unless $_ eq '.';
4125 # We have to check DIST_COMMON for extra directories in case the
4126 # user put a source used in AC_OUTPUT into a subdir.
4127 my $topsrcdir = backname ($relative_dir);
4128 foreach (&variable_value_as_list_recursive ('DIST_COMMON', 'all'))
4130 next if /^\@.*\@$/;
4131 s/\$\(top_srcdir\)/$topsrcdir/;
4132 s/\$\(srcdir\)/./;
4133 next unless s,/+[^/]+$,,;
4134 $dist_dirs{$_} = 1
4135 unless $_ eq '.';
4138 # Rule to check whether a distribution is viable.
4139 my %transform = ('DISTCHECK-HOOK' => &target_defined ('distcheck-hook'),
4140 'GETTEXT' => $seen_gettext);
4142 # Prepend $(distdir) to each directory given.
4143 my %rewritten = map { '$(distdir)/' . "$_" => 1 } keys %dist_dirs;
4144 $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);
4146 # If we have SUBDIRS, create all dist subdirectories and do
4147 # recursive build.
4148 if (variable_defined ('SUBDIRS'))
4150 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
4151 # to all possible directories, and use it. If DIST_SUBDIRS is
4152 # defined, just use it.
4153 my $dist_subdir_name;
4154 # Note that we check DIST_SUBDIRS first on purpose. At least
4155 # one project uses so many conditional subdirectories that
4156 # calling variable_conditionally_defined on SUBDIRS will cause
4157 # automake to grow to 150Mb. Sigh.
4158 if (variable_defined ('DIST_SUBDIRS')
4159 || variable_conditionally_defined ('SUBDIRS'))
4161 $dist_subdir_name = 'DIST_SUBDIRS';
4162 if (! variable_defined ('DIST_SUBDIRS'))
4164 define_pretty_variable
4165 ('DIST_SUBDIRS', '',
4166 uniq (&variable_value_as_list_recursive ('SUBDIRS', 'all')));
4169 else
4171 $dist_subdir_name = 'SUBDIRS';
4172 # We always define this because that is what `distclean'
4173 # wants.
4174 define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
4177 $transform{'DIST_SUBDIR_NAME'} = $dist_subdir_name;
4180 # If the target `dist-hook' exists, make sure it is run. This
4181 # allows users to do random weird things to the distribution
4182 # before it is packaged up.
4183 push (@dist_targets, 'dist-hook')
4184 if &target_defined ('dist-hook');
4185 $transform{'DIST-TARGETS'} = join(' ', @dist_targets);
4187 # Defining $(DISTDIR).
4188 $transform{'DISTDIR'} = !variable_defined('distdir');
4189 $transform{'TOP_DISTDIR'} = backname ($relative_dir);
4191 $output_rules .= &file_contents ('distdir', %transform);
4195 # Handle subdirectories.
4196 sub handle_subdirs
4198 return
4199 unless variable_defined ('SUBDIRS');
4201 my @subdirs = &variable_value_as_list_recursive ('SUBDIRS', 'all');
4202 my @dsubdirs = ();
4203 @dsubdirs = &variable_value_as_list_recursive ('DIST_SUBDIRS', 'all')
4204 if variable_defined ('DIST_SUBDIRS');
4206 # If an `obj/' directory exists, BSD make will enter it before
4207 # reading `Makefile'. Hence the `Makefile' in the current directory
4208 # will not be read.
4210 # % cat Makefile
4211 # all:
4212 # echo Hello
4213 # % cat obj/Makefile
4214 # all:
4215 # echo World
4216 # % make # GNU make
4217 # echo Hello
4218 # Hello
4219 # % pmake # BSD make
4220 # echo World
4221 # World
4222 msg_var ('portability', 'SUBDIRS',
4223 "naming a subdirectory `obj' causes troubles with BSD make")
4224 if grep ($_ eq 'obj', @subdirs);
4225 msg_var ('portability', 'DIST_SUBDIRS',
4226 "naming a subdirectory `obj' causes troubles with BSD make")
4227 if grep ($_ eq 'obj', @dsubdirs);
4229 # Make sure each directory mentioned in SUBDIRS actually exists.
4230 foreach my $dir (@subdirs)
4232 # Skip directories substituted by configure.
4233 next if $dir =~ /^\@.*\@$/;
4235 if (! -d $am_relative_dir . '/' . $dir)
4237 err_var ('SUBDIRS', "required directory $am_relative_dir/$dir "
4238 . "does not exist");
4239 next;
4242 err_var 'SUBDIRS', "directory should not contain `/'"
4243 if $dir =~ /\//;
4246 $output_rules .= &file_contents ('subdirs');
4247 variable_pretty_output ('RECURSIVE_TARGETS', 'TRUE');
4251 # ($REGEN, @DEPENDENCIES)
4252 # &scan_aclocal_m4
4253 # ----------------
4254 # If aclocal.m4 creation is automated, return the list of its dependencies.
4255 sub scan_aclocal_m4
4257 my $regen_aclocal = 0;
4259 return (0, ())
4260 unless $relative_dir eq '.';
4262 &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
4263 &examine_variable ('CONFIGURE_DEPENDENCIES');
4265 if (-f 'aclocal.m4')
4267 &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
4268 &push_dist_common ('aclocal.m4');
4270 my $aclocal = new Automake::XFile "< aclocal.m4";
4271 my $line = $aclocal->getline;
4272 $regen_aclocal = $line =~ 'generated automatically by aclocal';
4275 my @ac_deps = ();
4277 if (-f 'acinclude.m4')
4279 $regen_aclocal = 1;
4280 push @ac_deps, 'acinclude.m4';
4283 if (variable_defined ('ACLOCAL_M4_SOURCES'))
4285 push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
4287 elsif (variable_defined ('ACLOCAL_AMFLAGS'))
4289 # Scan all -I directories for m4 files. These are our
4290 # dependencies.
4291 my $examine_next = 0;
4292 foreach my $amdir (&variable_value_as_list_recursive ('ACLOCAL_AMFLAGS', ''))
4294 if ($examine_next)
4296 $examine_next = 0;
4297 if ($amdir !~ /^\// && -d $amdir)
4299 foreach my $ac_dep (&my_glob ($amdir . '/*.m4'))
4301 $ac_dep =~ s/^\.\/+//;
4302 push (@ac_deps, $ac_dep)
4303 unless $ac_dep eq "aclocal.m4"
4304 || $ac_dep eq "acinclude.m4";
4308 elsif ($amdir eq '-I')
4310 $examine_next = 1;
4315 # Note that it might be possible that aclocal.m4 doesn't exist but
4316 # should be auto-generated. This case probably isn't very
4317 # important.
4319 return ($regen_aclocal, @ac_deps);
4323 # @DEPENDENCY
4324 # &rewrite_inputs_into_dependencies ($ADD_SRCDIR, @INPUTS)
4325 # --------------------------------------------------------
4326 # Rewrite a list of input files into a form suitable to put on a
4327 # dependency list. The idea is that if an input file has a directory
4328 # part the same as the current directory, then the directory part is
4329 # simply removed. But if the directory part is different, then
4330 # $(top_srcdir) is prepended. Among other things, this is used to
4331 # generate the dependency list for the output files generated by
4332 # AC_OUTPUT. Consider what the dependencies should look like in this
4333 # case:
4334 # AC_OUTPUT(src/out:src/in1:lib/in2)
4335 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
4336 # If 0 then files that require this addition will simply be ignored.
4337 sub rewrite_inputs_into_dependencies ($@)
4339 my ($add_srcdir, @inputs) = @_;
4340 my @newinputs;
4342 foreach my $single (@inputs)
4344 if (dirname ($single) eq $relative_dir)
4346 push (@newinputs, basename ($single));
4348 elsif ($add_srcdir)
4350 push (@newinputs, '$(top_srcdir)/' . $single);
4354 return @newinputs;
4357 # Handle remaking and configure stuff.
4358 # We need the name of the input file, to do proper remaking rules.
4359 sub handle_configure
4361 my ($local, $input, @secondary_inputs) = @_;
4363 my $input_base = basename ($input);
4364 my $local_base = basename ($local);
4366 my $amfile = $input_base . '.am';
4367 # We know we can always add '.in' because it really should be an
4368 # error if the .in was missing originally.
4369 my $infile = '$(srcdir)/' . $input_base . '.in';
4370 my $colon_infile = '';
4371 if ($local ne $input || @secondary_inputs)
4373 $colon_infile = ':' . $input . '.in';
4375 $colon_infile .= ':' . join (':', @secondary_inputs)
4376 if @secondary_inputs;
4378 my @rewritten = rewrite_inputs_into_dependencies (1, @secondary_inputs);
4380 my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4 ();
4382 $output_rules .=
4383 &file_contents ('configure',
4384 ('MAKEFILE'
4385 => $local_base,
4386 'MAKEFILE-DEPS'
4387 => "@rewritten",
4388 'CONFIG-MAKEFILE'
4389 => ((($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
4390 . $colon_infile),
4391 'MAKEFILE-IN'
4392 => $infile,
4393 'MAKEFILE-IN-DEPS'
4394 => "@include_stack",
4395 'MAKEFILE-AM'
4396 => $amfile,
4397 'STRICTNESS'
4398 => $cygnus_mode ? 'cygnus' : $strictness_name,
4399 'USE-DEPS'
4400 => $cmdline_use_dependencies ? '' : ' --ignore-deps',
4401 'MAKEFILE-AM-SOURCES'
4402 => "$input$colon_infile",
4403 'REGEN-ACLOCAL-M4'
4404 => $regen_aclocal_m4,
4405 'ACLOCAL_M4_DEPS'
4406 => "@aclocal_m4_deps"));
4408 if ($relative_dir eq '.')
4410 &push_dist_common ('acconfig.h')
4411 if -f 'acconfig.h';
4414 # If we have a configure header, require it.
4415 my $hdr_index = 0;
4416 my @distclean_config;
4417 foreach my $spec (@config_headers)
4419 $hdr_index += 1;
4420 # $CONFIG_H_PATH: config.h from top level.
4421 my ($config_h_path, @ins) = split_config_file_spec ($spec);
4422 my $config_h_dir = dirname ($config_h_path);
4424 # If the header is in the current directory we want to build
4425 # the header here. Otherwise, if we're at the topmost
4426 # directory and the header's directory doesn't have a
4427 # Makefile, then we also want to build the header.
4428 if ($relative_dir eq $config_h_dir
4429 || ($relative_dir eq '.' && ! &is_make_dir ($config_h_dir)))
4431 my ($cn_sans_dir, $stamp_dir);
4432 if ($relative_dir eq $config_h_dir)
4434 $cn_sans_dir = basename ($config_h_path);
4435 $stamp_dir = '';
4437 else
4439 $cn_sans_dir = $config_h_path;
4440 if ($config_h_dir eq '.')
4442 $stamp_dir = '';
4444 else
4446 $stamp_dir = $config_h_dir . '/';
4450 # Compute relative path from directory holding output
4451 # header to directory holding input header. FIXME:
4452 # doesn't handle case where we have multiple inputs.
4453 my $in0_sans_dir;
4454 if (dirname ($ins[0]) eq $relative_dir)
4456 $in0_sans_dir = basename ($ins[0]);
4458 else
4460 $in0_sans_dir = backname ($relative_dir) . '/' . $ins[0];
4463 require_file ($config_header_location, FOREIGN, $in0_sans_dir);
4465 # Header defined and in this directory.
4466 my @files;
4467 if (-f $config_h_path . '.top')
4469 push (@files, "$cn_sans_dir.top");
4471 if (-f $config_h_path . '.bot')
4473 push (@files, "$cn_sans_dir.bot");
4476 push_dist_common (@files);
4478 # For now, acconfig.h can only appear in the top srcdir.
4479 if (-f 'acconfig.h')
4481 push (@files, '$(top_srcdir)/acconfig.h');
4484 my $stamp = "${stamp_dir}stamp-h${hdr_index}";
4485 $output_rules .=
4486 file_contents ('remake-hdr',
4487 ('FILES' => "@files",
4488 'CONFIG_H' => $cn_sans_dir,
4489 'CONFIG_HIN' => $in0_sans_dir,
4490 'CONFIG_H_PATH' => $config_h_path,
4491 'STAMP' => "$stamp"));
4493 push @distclean_config, $cn_sans_dir, $stamp;
4497 $output_rules .= file_contents ('clean-hdr',
4498 ('FILES' => "@distclean_config"))
4499 if @distclean_config;
4501 # Set location of mkinstalldirs.
4502 define_variable ('mkinstalldirs',
4503 ('$(SHELL) ' . $config_aux_dir . '/mkinstalldirs'));
4505 reject_var ('CONFIG_HEADER',
4506 "`CONFIG_HEADER' is an anachronism; now determined "
4507 . "automatically\nfrom `$configure_ac'");
4509 my @config_h;
4510 foreach my $spec (@config_headers)
4512 my ($out, @ins) = split_config_file_spec ($spec);
4513 # Generate CONFIG_HEADER define.
4514 if ($relative_dir eq dirname ($out))
4516 push @config_h, basename ($out);
4518 else
4520 push @config_h, "\$(top_builddir)/$out";
4523 define_variable ("CONFIG_HEADER", "@config_h")
4524 if @config_h;
4526 # Now look for other files in this directory which must be remade
4527 # by config.status, and generate rules for them.
4528 my @actual_other_files = ();
4529 foreach my $lfile (@other_input_files)
4531 my $file;
4532 my @inputs;
4533 if ($lfile =~ /^([^:]*):(.*)$/)
4535 # This is the ":" syntax of AC_OUTPUT.
4536 $file = $1;
4537 @inputs = split (':', $2);
4539 else
4541 # Normal usage.
4542 $file = $lfile;
4543 @inputs = $file . '.in';
4546 # Automake files should not be stored in here, but in %MAKE_LIST.
4547 prog_error "$lfile in \@other_input_files"
4548 if -f $file . '.am';
4550 my $local = basename ($file);
4552 # Make sure the dist directory for each input file is created.
4553 # We only have to do this at the topmost level though. This
4554 # is a bit ugly but it easier than spreading out the logic,
4555 # especially in cases like AC_OUTPUT(foo/out:bar/in), where
4556 # there is no Makefile in bar/.
4557 if ($relative_dir eq '.')
4559 foreach (@inputs)
4561 $dist_dirs{dirname ($_)} = 1;
4565 # We skip files that aren't in this directory. However, if
4566 # the file's directory does not have a Makefile, and we are
4567 # currently doing `.', then we create a rule to rebuild the
4568 # file in the subdir.
4569 my $fd = dirname ($file);
4570 if ($fd ne $relative_dir)
4572 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
4574 $local = $file;
4576 else
4578 next;
4582 my @rewritten_inputs = rewrite_inputs_into_dependencies (1, @inputs);
4583 $output_rules .= ($local . ': '
4584 . '$(top_builddir)/config.status '
4585 . "@rewritten_inputs\n"
4586 . "\t"
4587 . 'cd $(top_builddir) && '
4588 . '$(SHELL) ./config.status '
4589 . ($relative_dir eq '.' ? '' : '$(subdir)/')
4590 . '$@'
4591 . "\n");
4592 push (@actual_other_files, $local);
4594 # Require all input files.
4595 require_file ($ac_config_files_location, FOREIGN,
4596 rewrite_inputs_into_dependencies (0, @inputs));
4599 # These files get removed by "make clean".
4600 define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
4603 # Handle C headers.
4604 sub handle_headers
4606 my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
4607 'oldinclude', 'pkginclude',
4608 'noinst', 'check');
4609 foreach (@r)
4611 next unless /\..*$/;
4612 &saw_extension ($&);
4616 sub handle_gettext
4618 return if ! $seen_gettext || $relative_dir ne '.';
4620 if (! variable_defined ('SUBDIRS'))
4622 err_ac "AM_GNU_GETTEXT used but SUBDIRS not defined";
4623 return;
4626 my @subdirs = &variable_value_as_list_recursive ('SUBDIRS', 'all');
4627 err_var 'SUBDIRS', "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
4628 if ! grep ($_ eq 'po', @subdirs);
4629 # intl/ is not required when AM_GNU_GETTEXT is called with
4630 # the `external' option.
4631 err_var 'SUBDIRS', "AM_GNU_GETTEXT used but `intl' not in SUBDIRS"
4632 if (! $seen_gettext_external
4633 && ! grep ($_ eq 'intl', @subdirs));
4635 require_file ($ac_gettext_location, GNU, 'ABOUT-NLS');
4638 # Handle footer elements.
4639 sub handle_footer
4641 # NOTE don't use define_pretty_variable here, because
4642 # $contents{...} is already defined.
4643 $output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n\n"
4644 if variable_value ('SOURCES');
4646 reject_target ('.SUFFIXES',
4647 "use variable `SUFFIXES', not target `.SUFFIXES'");
4649 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
4650 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
4651 # anything else, by sticking it right after the default: target.
4652 $output_header .= ".SUFFIXES:\n";
4653 if (@suffixes || variable_defined ('SUFFIXES'))
4655 # Make sure suffixes has unique elements. Sort them to ensure
4656 # the output remains consistent. However, $(SUFFIXES) is
4657 # always at the start of the list, unsorted. This is done
4658 # because make will choose rules depending on the ordering of
4659 # suffixes, and this lets the user have some control. Push
4660 # actual suffixes, and not $(SUFFIXES). Some versions of make
4661 # do not like variable substitutions on the .SUFFIXES line.
4662 my @user_suffixes = (variable_defined ('SUFFIXES')
4663 ? &variable_value_as_list_recursive ('SUFFIXES', '')
4664 : ());
4666 my %suffixes = map { $_ => 1 } @suffixes;
4667 delete @suffixes{@user_suffixes};
4669 $output_header .= (".SUFFIXES: "
4670 . join (' ', @user_suffixes, sort keys %suffixes)
4671 . "\n");
4674 $output_trailer .= file_contents ('footer');
4677 # Deal with installdirs target.
4678 sub handle_installdirs ()
4680 $output_rules .=
4681 &file_contents ('install',
4682 ('am__installdirs'
4683 => variable_value ('am__installdirs') || '',
4684 'installdirs-local'
4685 => (target_defined ('installdirs-local')
4686 ? ' installdirs-local' : '')));
4690 # Deal with all and all-am.
4691 sub handle_all ($)
4693 my ($makefile) = @_;
4695 # Output `all-am'.
4697 # Put this at the beginning for the sake of non-GNU makes. This
4698 # is still wrong if these makes can run parallel jobs. But it is
4699 # right enough.
4700 unshift (@all, basename ($makefile));
4702 foreach my $spec (@config_headers)
4704 my ($out, @ins) = split_config_file_spec ($spec);
4705 push (@all, basename ($out))
4706 if dirname ($out) eq $relative_dir;
4709 # Install `all' hooks.
4710 if (&target_defined ("all-local"))
4712 push (@all, "all-local");
4713 &depend ('.PHONY', "all-local");
4716 &pretty_print_rule ("all-am:", "\t\t", @all);
4717 &depend ('.PHONY', 'all-am', 'all');
4720 # Output `all'.
4722 my @local_headers = ();
4723 push @local_headers, '$(BUILT_SOURCES)'
4724 if variable_defined ('BUILT_SOURCES');
4725 foreach my $spec (@config_headers)
4727 my ($out, @ins) = split_config_file_spec ($spec);
4728 push @local_headers, basename ($out)
4729 if dirname ($out) eq $relative_dir;
4732 if (@local_headers)
4734 # We need to make sure config.h is built before we recurse.
4735 # We also want to make sure that built sources are built
4736 # before any ordinary `all' targets are run. We can't do this
4737 # by changing the order of dependencies to the "all" because
4738 # that breaks when using parallel makes. Instead we handle
4739 # things explicitly.
4740 $output_all .= ("all: @local_headers"
4741 . "\n\t"
4742 . '$(MAKE) $(AM_MAKEFLAGS) '
4743 . (variable_defined ('SUBDIRS')
4744 ? 'all-recursive' : 'all-am')
4745 . "\n\n");
4747 else
4749 $output_all .= "all: " . (variable_defined ('SUBDIRS')
4750 ? 'all-recursive' : 'all-am') . "\n\n";
4755 # Handle check merge target specially.
4756 sub do_check_merge_target
4758 if (&target_defined ('check-local'))
4760 # User defined local form of target. So include it.
4761 push (@check_tests, 'check-local');
4762 &depend ('.PHONY', 'check-local');
4765 # In --cygnus mode, check doesn't depend on all.
4766 if ($cygnus_mode)
4768 # Just run the local check rules.
4769 &pretty_print_rule ('check-am:', "\t\t", @check);
4771 else
4773 # The check target must depend on the local equivalent of
4774 # `all', to ensure all the primary targets are built. Then it
4775 # must build the local check rules.
4776 $output_rules .= "check-am: all-am\n";
4777 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4778 @check)
4779 if @check;
4781 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4782 @check_tests)
4783 if @check_tests;
4785 &depend ('.PHONY', 'check', 'check-am');
4786 $output_rules .= ("check: "
4787 . (variable_defined ('SUBDIRS')
4788 ? 'check-recursive' : 'check-am')
4789 . "\n");
4792 # Handle all 'clean' targets.
4793 sub handle_clean
4795 # Clean the files listed in user variables if they exist.
4796 $clean_files{'$(MOSTLYCLEANFILES)'} = MOSTLY_CLEAN
4797 if variable_defined ('MOSTLYCLEANFILES');
4798 $clean_files{'$(CLEANFILES)'} = CLEAN
4799 if variable_defined ('CLEANFILES');
4800 $clean_files{'$(DISTCLEANFILES)'} = DIST_CLEAN
4801 if variable_defined ('DISTCLEANFILES');
4802 $clean_files{'$(MAINTAINERCLEANFILES)'} = MAINTAINER_CLEAN
4803 if variable_defined ('MAINTAINERCLEANFILES');
4805 # Built sources are automatically removed by maintainer-clean.
4806 $clean_files{'$(BUILT_SOURCES)'} = MAINTAINER_CLEAN
4807 if variable_defined ('BUILT_SOURCES');
4809 # Compute a list of "rm"s to run for each target.
4810 my %rms = (MOSTLY_CLEAN, [],
4811 CLEAN, [],
4812 DIST_CLEAN, [],
4813 MAINTAINER_CLEAN, []);
4815 foreach my $file (keys %clean_files)
4817 my $when = $clean_files{$file};
4818 prog_error 'invalid entry in %clean_files'
4819 unless exists $rms{$when};
4821 my $rm = "rm -f $file";
4822 # If file is a variable, make sure when don't call `rm -f' without args.
4823 $rm ="test -z \"$file\" || $rm"
4824 if ($file =~ /^\s*\$(\(.*\)|\{.*\})\s*$/);
4826 push @{$rms{$when}}, "\t-$rm\n";
4829 $output_rules .= &file_contents
4830 ('clean',
4831 MOSTLYCLEAN_RMS => join ('', @{$rms{&MOSTLY_CLEAN}}),
4832 CLEAN_RMS => join ('', @{$rms{&CLEAN}}),
4833 DISTCLEAN_RMS => join ('', @{$rms{&DIST_CLEAN}}),
4834 MAINTAINER_CLEAN_RMS => join ('', @{$rms{&MAINTAINER_CLEAN}}));
4838 # &depend ($CATEGORY, @DEPENDENDEES)
4839 # ----------------------------------
4840 # The target $CATEGORY depends on @DEPENDENDEES.
4841 sub depend
4843 my ($category, @dependendees) = @_;
4845 push (@{$dependencies{$category}}, @dependendees);
4850 # &target_cmp ($A, $B)
4851 # --------------------
4852 # Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
4853 sub target_cmp
4855 return 0
4856 if $a eq $b;
4857 return -1
4858 if $b eq '.PHONY';
4859 return 1
4860 if $a eq '.PHONY';
4861 return $a cmp $b;
4865 # &handle_factored_dependencies ()
4866 # --------------------------------
4867 # Handle everything related to gathered targets.
4868 sub handle_factored_dependencies
4870 # Reject bad hooks.
4871 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4872 'uninstall-exec-local', 'uninstall-exec-hook')
4874 my $x = $utarg;
4875 $x =~ s/(data|exec)-//;
4876 reject_target ($utarg, "use `$x', not `$utarg'");
4879 reject_target ('install-local',
4880 "use `install-data-local' or `install-exec-local', "
4881 . "not `install-local'");
4883 reject_target ('install-info-local',
4884 "`install-info-local' target defined but "
4885 . "`no-installinfo' option not in use")
4886 unless defined $options{'no-installinfo'};
4888 # Install the -local hooks.
4889 foreach (keys %dependencies)
4891 # Hooks are installed on the -am targets.
4892 s/-am$// or next;
4893 if (&target_defined ("$_-local"))
4895 depend ("$_-am", "$_-local");
4896 &depend ('.PHONY', "$_-local");
4900 # Install the -hook hooks.
4901 # FIXME: Why not be as liberal as we are with -local hooks?
4902 foreach ('install-exec', 'install-data', 'uninstall')
4904 if (&target_defined ("$_-hook"))
4906 $actions{"$_-am"} .=
4907 ("\t\@\$(NORMAL_INSTALL)\n"
4908 . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
4912 # All the required targets are phony.
4913 depend ('.PHONY', keys %required_targets);
4915 # Actually output gathered targets.
4916 foreach (sort target_cmp keys %dependencies)
4918 # If there is nothing about this guy, skip it.
4919 next
4920 unless (@{$dependencies{$_}}
4921 || $actions{$_}
4922 || $required_targets{$_});
4923 &pretty_print_rule ("$_:", "\t",
4924 uniq (sort @{$dependencies{$_}}));
4925 $output_rules .= $actions{$_}
4926 if defined $actions{$_};
4927 $output_rules .= "\n";
4932 # &handle_tests_dejagnu ()
4933 # ------------------------
4934 sub handle_tests_dejagnu
4936 push (@check_tests, 'check-DEJAGNU');
4937 $output_rules .= file_contents ('dejagnu');
4941 # Handle TESTS variable and other checks.
4942 sub handle_tests
4944 if (defined $options{'dejagnu'})
4946 &handle_tests_dejagnu;
4948 else
4950 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4952 reject_var ($c, "`$c' defined but `dejagnu' not in "
4953 . "`AUTOMAKE_OPTIONS'");
4957 if (variable_defined ('TESTS'))
4959 push (@check_tests, 'check-TESTS');
4960 $output_rules .= &file_contents ('check');
4964 # Handle Emacs Lisp.
4965 sub handle_emacs_lisp
4967 my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4968 'lisp', 'noinst');
4970 return if ! @elfiles;
4972 # Generate .elc files.
4973 my @elcfiles = map { $_ . 'c' } @elfiles;
4974 define_pretty_variable ('ELCFILES', '', @elcfiles);
4976 push (@all, '$(ELCFILES)');
4978 require_variables ("$am_file.am", "Emacs Lisp sources seen", 'TRUE',
4979 'EMACS', 'lispdir');
4980 require_conf_file ("$am_file.am", FOREIGN, 'elisp-comp');
4981 &define_variable ('elisp_comp', $config_aux_dir . '/elisp-comp');
4984 # Handle Python
4985 sub handle_python
4987 my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4988 'noinst');
4989 return if ! @pyfiles;
4991 require_variables ("$am_file.am", "Python sources seen", 'TRUE',
4992 'PYTHON');
4993 require_conf_file ("$am_file.am", FOREIGN, 'py-compile');
4994 &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4997 # Handle Java.
4998 sub handle_java
5000 my @sourcelist = &am_install_var ('-candist',
5001 'java', 'JAVA',
5002 'java', 'noinst', 'check');
5003 return if ! @sourcelist;
5005 my @prefix = am_primary_prefixes ('JAVA', 1,
5006 'java', 'noinst', 'check');
5008 my $dir;
5009 foreach my $curs (@prefix)
5011 next
5012 if $curs eq 'EXTRA';
5014 err_var "${curs}_JAVA", "multiple _JAVA primaries in use"
5015 if defined $dir;
5016 $dir = $curs;
5020 push (@all, 'class' . $dir . '.stamp');
5024 # Handle some of the minor options.
5025 sub handle_minor_options
5027 if (defined $options{'readme-alpha'})
5029 if ($relative_dir eq '.')
5031 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
5033 msg ('error-gnits', $package_version_location,
5034 "version `$package_version' doesn't follow " .
5035 "Gnits standards");
5037 if (defined $1 && -f 'README-alpha')
5039 # This means we have an alpha release. See
5040 # GNITS_VERSION_PATTERN for details.
5041 require_file_with_macro ('TRUE', 'AUTOMAKE_OPTIONS',
5042 FOREIGN, 'README-alpha');
5048 ################################################################
5050 # ($OUTPUT, @INPUTS)
5051 # &split_config_file_spec ($SPEC)
5052 # -------------------------------
5053 # Decode the Autoconf syntax for config files (files, headers, links
5054 # etc.).
5055 sub split_config_file_spec ($)
5057 my ($spec) = @_;
5058 my ($output, @inputs) = split (/:/, $spec);
5060 push @inputs, "$output.in"
5061 unless @inputs;
5063 return ($output, @inputs);
5067 my %make_list;
5069 # &scan_autoconf_config_files ($CONFIG-FILES)
5070 # -------------------------------------------
5071 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
5072 # (or AC_OUTPUT).
5073 sub scan_autoconf_config_files
5075 my ($config_files) = @_;
5076 # Look at potential Makefile.am's.
5077 foreach (split ' ', $config_files)
5079 # Must skip empty string for Perl 4.
5080 next if $_ eq "\\" || $_ eq '';
5082 # Handle $local:$input syntax. Note that we ignore
5083 # every input file past the first, though we keep
5084 # those around for later.
5085 my ($local, $input, @rest) = split (/:/);
5086 if (! $input)
5088 $input = $local;
5090 else
5092 # FIXME: should be error if .in is missing.
5093 $input =~ s/\.in$//;
5096 if (-f $input . '.am')
5098 # We have a file that automake should generate.
5099 $make_list{$input} = join (':', ($local, @rest));
5101 else
5103 # We have a file that automake should cause to be
5104 # rebuilt, but shouldn't generate itself.
5105 push (@other_input_files, $_);
5111 # &scan_autoconf_traces ($FILENAME)
5112 # ---------------------------------
5113 sub scan_autoconf_traces ($)
5115 my ($filename) = @_;
5117 my @traced = qw(AC_CANONICAL_HOST
5118 AC_CANONICAL_SYSTEM
5119 AC_CONFIG_AUX_DIR
5120 AC_CONFIG_FILES
5121 AC_CONFIG_HEADERS
5122 AC_INIT
5123 AC_LIBSOURCE
5124 AC_SUBST
5125 AM_AUTOMAKE_VERSION
5126 AM_CONDITIONAL
5127 AM_GNU_GETTEXT
5128 AM_INIT_AUTOMAKE
5129 AM_MAINTAINER_MODE
5130 AM_PROG_CC_C_O);
5132 my $traces = ($ENV{AUTOCONF} || 'autoconf') . " ";
5134 # Use a separator unlikely to be used, not `:', the default, which
5135 # has a precise meaning for AC_CONFIG_FILES and so on.
5136 $traces .= join (' ',
5137 map { "--trace=$_" . ':\$f:\$l::\$n::\${::}%' } @traced);
5139 my $tracefh = new Automake::XFile ("$traces $filename |");
5140 verb "reading $traces";
5142 while ($_ = $tracefh->getline)
5144 chomp;
5145 my ($here, @args) = split /::/;
5146 my $macro = $args[0];
5148 # Alphabetical ordering please.
5149 if ($macro eq 'AC_CANONICAL_HOST')
5151 if (! $seen_canonical)
5153 $seen_canonical = AC_CANONICAL_HOST;
5154 $canonical_location = $here;
5157 elsif ($macro eq 'AC_CANONICAL_SYSTEM')
5159 $seen_canonical = AC_CANONICAL_SYSTEM;
5160 $canonical_location = $here;
5162 elsif ($macro eq 'AC_CONFIG_AUX_DIR')
5164 @config_aux_path = $args[1];
5165 $config_aux_dir_set_in_configure_in = 1;
5167 elsif ($macro eq 'AC_CONFIG_FILES')
5169 # Look at potential Makefile.am's.
5170 $ac_config_files_location = $here;
5171 &scan_autoconf_config_files ($args[1]);
5173 elsif ($macro eq 'AC_CONFIG_HEADERS')
5175 $config_header_location = $here;
5176 push @config_headers, split (' ', $args[1]);
5178 elsif ($macro eq 'AC_INIT')
5180 if (defined $args[2])
5182 $package_version = $args[2];
5183 $package_version_location = $here;
5186 elsif ($macro eq 'AC_LIBSOURCE')
5188 $libsources{$args[1]} = $here;
5190 elsif ($macro eq 'AC_SUBST')
5192 # Just check for alphanumeric in AC_SUBST. If you do
5193 # AC_SUBST(5), then too bad.
5194 $configure_vars{$args[1]} = $here
5195 if $args[1] =~ /^\w+$/;
5197 elsif ($macro eq 'AM_AUTOMAKE_VERSION')
5199 err ($here,
5200 "version mismatch. This is Automake $VERSION,\n" .
5201 "but the definition used by this AM_INIT_AUTOMAKE\n" .
5202 "comes from Automake $args[1]. You should recreate\n" .
5203 "aclocal.m4 with aclocal and run automake again.\n")
5204 if ($VERSION ne $args[1]);
5206 $seen_automake_version = 1;
5208 elsif ($macro eq 'AM_CONDITIONAL')
5210 $configure_cond{$args[1]} = $here;
5212 elsif ($macro eq 'AM_GNU_GETTEXT')
5214 $seen_gettext = $here;
5215 $ac_gettext_location = $here;
5216 $seen_gettext_external = grep ($_ eq 'external', @args);
5218 elsif ($macro eq 'AM_INIT_AUTOMAKE')
5220 $seen_init_automake = $here;
5221 if (defined $args[2])
5223 $package_version = $args[2];
5224 $package_version_location = $here;
5226 elsif (defined $args[1])
5228 $global_options = $args[1];
5231 elsif ($macro eq 'AM_MAINTAINER_MODE')
5233 $seen_maint_mode = $here;
5235 elsif ($macro eq 'AM_PROG_CC_C_O')
5237 $seen_cc_c_o = $here;
5243 # &scan_autoconf_files ()
5244 # -----------------------
5245 # Check whether we use `configure.ac' or `configure.in'.
5246 # Scan it (and possibly `aclocal.m4') for interesting things.
5247 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
5248 sub scan_autoconf_files
5250 # Reinitialize libsources here. This isn't really necessary,
5251 # since we currently assume there is only one configure.ac. But
5252 # that won't always be the case.
5253 %libsources = ();
5255 $configure_ac = find_configure_ac;
5256 fatal "`configure.ac' or `configure.in' is required\n"
5257 if !$configure_ac;
5259 scan_autoconf_traces ($configure_ac);
5261 # Set input and output files if not specified by user.
5262 if (! @input_files)
5264 @input_files = sort keys %make_list;
5265 %output_files = %make_list;
5268 @configure_input_files = sort keys %make_list;
5270 err_ac "`AM_INIT_AUTOMAKE' must be used"
5271 if ! $seen_init_automake;
5273 if (! $seen_automake_version)
5275 if (-f 'aclocal.m4')
5277 err ($seen_init_automake || $me,
5278 "your implementation of AM_INIT_AUTOMAKE comes from " .
5279 "an\nold Automake version. You should recreate " .
5280 "aclocal.m4\nwith aclocal and run automake again.\n");
5282 else
5284 err ($seen_init_automake || $me,
5285 "no proper implementation of AM_INIT_AUTOMAKE was " .
5286 "found,\nprobably because aclocal.m4 is missing...\n" .
5287 "You should run aclocal to create this file, then\n" .
5288 "run automake again.\n");
5292 # Look for some files we need. Always check for these. This
5293 # check must be done for every run, even those where we are only
5294 # looking at a subdir Makefile. We must set relative_dir so that
5295 # the file-finding machinery works.
5296 # FIXME: Is this broken because it needs dynamic scopes.
5297 # My tests seems to show it's not the case.
5298 $relative_dir = '.';
5299 require_conf_file ($configure_ac, FOREIGN,
5300 'install-sh', 'mkinstalldirs', 'missing');
5301 err_am "`install.sh' is an anachronism; use `install-sh' instead"
5302 if -f $config_aux_path[0] . '/install.sh';
5304 # Preserve dist_common for later.
5305 $configure_dist_common = variable_value ('DIST_COMMON', 'TRUE') || '';
5308 ################################################################
5310 # Set up for Cygnus mode.
5311 sub check_cygnus
5313 return unless $cygnus_mode;
5315 &set_strictness ('foreign');
5316 $options{'no-installinfo'} = 1;
5317 $options{'no-dependencies'} = 1;
5318 $use_dependencies = 0;
5320 err_ac "`AM_MAINTAINER_MODE' required when --cygnus specified"
5321 if !$seen_maint_mode;
5324 # Do any extra checking for GNU standards.
5325 sub check_gnu_standards
5327 if ($relative_dir eq '.')
5329 # In top level (or only) directory.
5331 # Accept one of these three licenses; default to COPYING.
5332 my $license = 'COPYING';
5333 foreach (qw /COPYING.LIB COPYING.LESSER/)
5335 $license = $_ if -f $_;
5337 require_file ("$am_file.am", GNU, $license,
5338 qw/INSTALL NEWS README AUTHORS ChangeLog/);
5341 for my $opt ('no-installman', 'no-installinfo')
5343 msg_var ('error-gnu', 'AUTOMAKE_OPTIONS',
5344 "option `$opt' disallowed by GNU standards")
5345 if (defined $options{$opt});
5349 # Do any extra checking for GNITS standards.
5350 sub check_gnits_standards
5352 if ($relative_dir eq '.')
5354 # In top level (or only) directory.
5355 require_file ("$am_file.am", GNITS, 'THANKS');
5359 ################################################################
5361 # Functions to handle files of each language.
5363 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
5364 # simple formula: Return value is LANG_SUBDIR if the resulting object
5365 # file should be in a subdir if the source file is, LANG_PROCESS if
5366 # file is to be dealt with, LANG_IGNORE otherwise.
5368 # Much of the actual processing is handled in
5369 # handle_single_transform_list. These functions exist so that
5370 # auxiliary information can be recorded for a later cleanup pass.
5371 # Note that the calls to these functions are computed, so don't bother
5372 # searching for their precise names in the source.
5374 # This is just a convenience function that can be used to determine
5375 # when a subdir object should be used.
5376 sub lang_sub_obj
5378 return defined $options{'subdir-objects'} ? LANG_SUBDIR : LANG_PROCESS;
5381 # Rewrite a single C source file.
5382 sub lang_c_rewrite
5384 my ($directory, $base, $ext) = @_;
5386 if (defined $options{'ansi2knr'} && $base =~ /_$/)
5388 # FIXME: include line number in error.
5389 err_am "C source file `$base.c' would be deleted by ansi2knr rules";
5392 my $r = LANG_PROCESS;
5393 if (defined $options{'subdir-objects'})
5395 $r = LANG_SUBDIR;
5396 $base = $directory . '/' . $base
5397 unless $directory eq '.' || $directory eq '';
5399 err_am ("C objects in subdir but `AM_PROG_CC_C_O' "
5400 . "not in `$configure_ac'",
5401 uniq_scope => US_GLOBAL)
5402 unless $seen_cc_c_o;
5404 require_conf_file ("$am_file.am", FOREIGN, 'compile');
5406 # In this case we already have the directory information, so
5407 # don't add it again.
5408 $de_ansi_files{$base} = '';
5410 else
5412 $de_ansi_files{$base} = (($directory eq '.' || $directory eq '')
5413 ? ''
5414 : "$directory/");
5417 return $r;
5420 # Rewrite a single C++ source file.
5421 sub lang_cxx_rewrite
5423 return &lang_sub_obj;
5426 # Rewrite a single header file.
5427 sub lang_header_rewrite
5429 # Header files are simply ignored.
5430 return LANG_IGNORE;
5433 # Rewrite a single yacc file.
5434 sub lang_yacc_rewrite
5436 my ($directory, $base, $ext) = @_;
5438 my $r = &lang_sub_obj;
5439 (my $newext = $ext) =~ tr/y/c/;
5440 return ($r, $newext);
5443 # Rewrite a single yacc++ file.
5444 sub lang_yaccxx_rewrite
5446 my ($directory, $base, $ext) = @_;
5448 my $r = &lang_sub_obj;
5449 (my $newext = $ext) =~ tr/y/c/;
5450 return ($r, $newext);
5453 # Rewrite a single lex file.
5454 sub lang_lex_rewrite
5456 my ($directory, $base, $ext) = @_;
5458 my $r = &lang_sub_obj;
5459 (my $newext = $ext) =~ tr/l/c/;
5460 return ($r, $newext);
5463 # Rewrite a single lex++ file.
5464 sub lang_lexxx_rewrite
5466 my ($directory, $base, $ext) = @_;
5468 my $r = &lang_sub_obj;
5469 (my $newext = $ext) =~ tr/l/c/;
5470 return ($r, $newext);
5473 # Rewrite a single assembly file.
5474 sub lang_asm_rewrite
5476 return &lang_sub_obj;
5479 # Rewrite a single Fortran 77 file.
5480 sub lang_f77_rewrite
5482 return LANG_PROCESS;
5485 # Rewrite a single preprocessed Fortran 77 file.
5486 sub lang_ppf77_rewrite
5488 return LANG_PROCESS;
5491 # Rewrite a single ratfor file.
5492 sub lang_ratfor_rewrite
5494 return LANG_PROCESS;
5497 # Rewrite a single Objective C file.
5498 sub lang_objc_rewrite
5500 return &lang_sub_obj;
5503 # Rewrite a single Java file.
5504 sub lang_java_rewrite
5506 return LANG_SUBDIR;
5509 # The lang_X_finish functions are called after all source file
5510 # processing is done. Each should handle defining rules for the
5511 # language, etc. A finish function is only called if a source file of
5512 # the appropriate type has been seen.
5514 sub lang_c_finish
5516 # Push all libobjs files onto de_ansi_files. We actually only
5517 # push files which exist in the current directory, and which are
5518 # genuine source files.
5519 foreach my $file (keys %libsources)
5521 if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
5523 $de_ansi_files{$1} = (($relative_dir eq '.' || $relative_dir eq '')
5524 ? ''
5525 : "$relative_dir/");
5529 if (defined $options{'ansi2knr'} && keys %de_ansi_files)
5531 # Make all _.c files depend on their corresponding .c files.
5532 my @objects;
5533 foreach my $base (sort keys %de_ansi_files)
5535 # Each _.c file must depend on ansi2knr; otherwise it
5536 # might be used in a parallel build before it is built.
5537 # We need to support files in the srcdir and in the build
5538 # dir (because these files might be auto-generated. But
5539 # we can't use $< -- some makes only define $< during a
5540 # suffix rule.
5541 my $ansfile = $de_ansi_files{$base} . $base . '.c';
5542 $output_rules .= ($base . "_.c: $ansfile \$(ANSI2KNR)\n\t"
5543 . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5544 . '`if test -f $(srcdir)/' . $ansfile
5545 . '; then echo $(srcdir)/' . $ansfile
5546 . '; else echo ' . $ansfile . '; fi` '
5547 . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5548 . '| $(ANSI2KNR) > ' . $base . "_.c"
5549 # If ansi2knr fails then we shouldn't
5550 # create the _.c file
5551 . " || rm -f ${base}_.c\n");
5552 push (@objects, $base . '_.$(OBJEXT)');
5553 push (@objects, $base . '_.lo')
5554 if variable_defined ('LIBTOOL');
5557 # Make all _.o (and _.lo) files depend on ansi2knr.
5558 # Use a sneaky little hack to make it print nicely.
5559 &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5563 # This is a yacc helper which is called whenever we have decided to
5564 # compile a yacc file.
5565 sub lang_yacc_target_hook
5567 my ($self, $aggregate, $output, $input) = @_;
5569 my $flag = $aggregate . "_YFLAGS";
5570 if ((variable_defined ($flag)
5571 && &variable_value ($flag) =~ /$DASH_D_PATTERN/o)
5572 || (variable_defined ('YFLAGS')
5573 && &variable_value ('YFLAGS') =~ /$DASH_D_PATTERN/o))
5575 (my $output_base = $output) =~ s/$KNOWN_EXTENSIONS_PATTERN$//;
5576 my $header = $output_base . '.h';
5578 # Found a `-d' that applies to the compilation of this file.
5579 # Add a dependency for the generated header file, and arrange
5580 # for that file to be included in the distribution.
5581 # FIXME: this fails for `nodist_*_SOURCES'.
5582 $output_rules .= ("${header}: $output\n"
5583 # Recover from removal of $header
5584 . "\t\@if test ! -f \$@; then \\\n"
5585 . "\t rm -f $output; \\\n"
5586 . "\t \$(MAKE) $output; \\\n"
5587 . "\telse :; fi\n");
5588 &push_dist_common ($header);
5589 # If the files are built in the build directory, then we want
5590 # to remove them with `make clean'. If they are in srcdir
5591 # they shouldn't be touched. However, we can't determine this
5592 # statically, and the GNU rules say that yacc/lex output files
5593 # should be removed by maintainer-clean. So that's what we
5594 # do.
5595 $clean_files{$header} = MAINTAINER_CLEAN;
5597 # Erase $OUTPUT on `make maintainer-clean' (by GNU standards).
5598 # See the comment above for $HEADER.
5599 $clean_files{$output} = MAINTAINER_CLEAN;
5602 # This is a lex helper which is called whenever we have decided to
5603 # compile a lex file.
5604 sub lang_lex_target_hook
5606 my ($self, $aggregate, $output, $input) = @_;
5607 # If the files are built in the build directory, then we want to
5608 # remove them with `make clean'. If they are in srcdir they
5609 # shouldn't be touched. However, we can't determine this
5610 # statically, and the GNU rules say that yacc/lex output files
5611 # should be removed by maintainer-clean. So that's what we do.
5612 $clean_files{$output} = MAINTAINER_CLEAN;
5615 # This is a helper for both lex and yacc.
5616 sub yacc_lex_finish_helper
5618 return if defined $language_scratch{'lex-yacc-done'};
5619 $language_scratch{'lex-yacc-done'} = 1;
5621 # If there is more than one distinct yacc (resp lex) source file
5622 # in a given directory, then the `ylwrap' program is required to
5623 # allow parallel builds to work correctly. FIXME: for now, no
5624 # line number.
5625 require_conf_file ($configure_ac, FOREIGN, 'ylwrap');
5626 if ($config_aux_dir_set_in_configure_in)
5628 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5630 else
5632 &define_variable ('YLWRAP', '$(top_srcdir)/ylwrap');
5636 sub lang_yacc_finish
5638 return if defined $language_scratch{'yacc-done'};
5639 $language_scratch{'yacc-done'} = 1;
5641 reject_var 'YACCFLAGS', "`YACCFLAGS' obsolete; use `YFLAGS' instead";
5643 &yacc_lex_finish_helper
5644 if count_files_for_language ('yacc') > 1;
5648 sub lang_lex_finish
5650 return if defined $language_scratch{'lex-done'};
5651 $language_scratch{'lex-done'} = 1;
5653 &yacc_lex_finish_helper
5654 if count_files_for_language ('lex') > 1;
5658 # Given a hash table of linker names, pick the name that has the most
5659 # precedence. This is lame, but something has to have global
5660 # knowledge in order to eliminate the conflict. Add more linkers as
5661 # required.
5662 sub resolve_linker
5664 my (%linkers) = @_;
5666 foreach my $l (qw(GCJLINK CXXLINK F77LINK OBJCLINK))
5668 return $l if defined $linkers{$l};
5670 return 'LINK';
5673 # Called to indicate that an extension was used.
5674 sub saw_extension
5676 my ($ext) = @_;
5677 if (! defined $extension_seen{$ext})
5679 $extension_seen{$ext} = 1;
5681 else
5683 ++$extension_seen{$ext};
5687 # Return the number of files seen for a given language. Knows about
5688 # special cases we care about. FIXME: this is hideous. We need
5689 # something that involves real language objects. For instance yacc
5690 # and yaccxx could both derive from a common yacc class which would
5691 # know about the strange ylwrap requirement. (Or better yet we could
5692 # just not support legacy yacc!)
5693 sub count_files_for_language
5695 my ($name) = @_;
5697 my @names;
5698 if ($name eq 'yacc' || $name eq 'yaccxx')
5700 @names = ('yacc', 'yaccxx');
5702 elsif ($name eq 'lex' || $name eq 'lexxx')
5704 @names = ('lex', 'lexxx');
5706 else
5708 @names = ($name);
5711 my $r = 0;
5712 foreach $name (@names)
5714 my $lang = $languages{$name};
5715 foreach my $ext (@{$lang->extensions})
5717 $r += $extension_seen{$ext}
5718 if defined $extension_seen{$ext};
5722 return $r
5725 # Called to ask whether source files have been seen . If HEADERS is 1,
5726 # headers can be included.
5727 sub saw_sources_p
5729 my ($headers) = @_;
5731 # count all the sources
5732 my $count = 0;
5733 foreach my $val (values %extension_seen)
5735 $count += $val;
5738 if (!$headers)
5740 $count -= count_files_for_language ('header');
5743 return $count > 0;
5747 # register_language (%ATTRIBUTE)
5748 # ------------------------------
5749 # Register a single language.
5750 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5751 sub register_language (%)
5753 my (%option) = @_;
5755 # Set the defaults.
5756 $option{'ansi'} = 0
5757 unless defined $option{'ansi'};
5758 $option{'autodep'} = 'no'
5759 unless defined $option{'autodep'};
5760 $option{'linker'} = ''
5761 unless defined $option{'linker'};
5762 $option{'flags'} = []
5763 unless defined $option{'flags'};
5764 $option{'output_extensions'} = sub { return ( '.$(OBJEXT)', '.lo' ) }
5765 unless defined $option{'output_extensions'};
5767 my $lang = new Language (%option);
5769 # Fill indexes.
5770 grep ($extension_map{$_} = $lang->name, @{$lang->extensions});
5771 $languages{$lang->name} = $lang;
5773 # Update the pattern of known extensions.
5774 accept_extensions (@{$lang->extensions});
5776 # Upate the $suffix_rule map.
5777 foreach my $suffix (@{$lang->extensions})
5779 foreach my $dest (&{$lang->output_extensions} ($suffix))
5781 &register_suffix_rule ('internal', $suffix, $dest);
5786 # derive_suffix ($EXT, $OBJ)
5787 # --------------------------
5788 # This function is used to find a path from a user-specified suffix $EXT
5789 # to $OBJ or to some other suffix we recognize internally, eg `cc'.
5790 sub derive_suffix ($$)
5792 my ($source_ext, $obj) = @_;
5794 while (! $extension_map{$source_ext}
5795 && $source_ext ne $obj
5796 && exists $suffix_rules->{$source_ext}
5797 && exists $suffix_rules->{$source_ext}{$obj})
5799 $source_ext = $suffix_rules->{$source_ext}{$obj}[0];
5802 return $source_ext;
5806 ################################################################
5808 # Pretty-print something. HEAD is what should be printed at the
5809 # beginning of the first line, FILL is what should be printed at the
5810 # beginning of every subsequent line.
5811 sub pretty_print_internal
5813 my ($head, $fill, @values) = @_;
5815 my $column = length ($head);
5816 my $result = $head;
5818 # Fill length is number of characters. However, each Tab
5819 # character counts for eight. So we count the number of Tabs and
5820 # multiply by 7.
5821 my $fill_length = length ($fill);
5822 $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5824 foreach (@values)
5826 # "71" because we also print a space.
5827 if ($column + length ($_) > 71)
5829 $result .= " \\\n" . $fill;
5830 $column = $fill_length;
5832 $result .= ' ' if $result =~ /\S\z/;
5833 $result .= $_;
5834 $column += length ($_) + 1;
5837 $result .= "\n";
5838 return $result;
5841 # Pretty-print something and append to output_vars.
5842 sub pretty_print
5844 $output_vars .= &pretty_print_internal (@_);
5847 # Pretty-print something and append to output_rules.
5848 sub pretty_print_rule
5850 $output_rules .= &pretty_print_internal (@_);
5854 ################################################################
5857 # $STRING
5858 # &conditional_string(@COND-STACK)
5859 # --------------------------------
5860 # Build a string which denotes the conditional in @COND-STACK. Some
5861 # simplifications are done: `TRUE' entries are elided, and any `FALSE'
5862 # entry results in a return of `FALSE'.
5863 sub conditional_string
5865 my (@stack) = @_;
5867 if (grep (/^FALSE$/, @stack))
5869 return 'FALSE';
5871 else
5873 return join (' ', uniq sort grep (!/^TRUE$/, @stack));
5878 # $BOOLEAN
5879 # &conditional_true_when ($COND, $WHEN)
5880 # -------------------------------------
5881 # See if a conditional is true. Both arguments are conditional
5882 # strings. This returns true if the first conditional is true when
5883 # the second conditional is true.
5884 # For instance with $COND = `BAR FOO', and $WHEN = `BAR BAZ FOO',
5885 # obviously return 1, and 0 when, for instance, $WHEN = `FOO'.
5886 sub conditional_true_when ($$)
5888 my ($cond, $when) = @_;
5890 # Make a hash holding all the values from $WHEN.
5891 my %cond_vals = map { $_ => 1 } split (' ', $when);
5893 # Nothing is true when FALSE (not even FALSE itself, but it
5894 # shouldn't hurt if you decide to change that).
5895 return 0 if exists $cond_vals{'FALSE'};
5897 # Check each component of $cond, which looks `COND1 COND2'.
5898 foreach my $comp (split (' ', $cond))
5900 # TRUE is always true.
5901 next if $comp eq 'TRUE';
5902 return 0 if ! defined $cond_vals{$comp};
5905 return 1;
5909 # $BOOLEAN
5910 # &conditional_is_redundant ($COND, @WHENS)
5911 # ----------------------------------------
5912 # Determine whether $COND is redundant with respect to @WHENS.
5914 # Returns true if $COND is true for any of the conditions in @WHENS.
5916 # If there are no @WHENS, then behave as if @WHENS contained a single empty
5917 # condition.
5918 sub conditional_is_redundant ($@)
5920 my ($cond, @whens) = @_;
5922 @whens = ("") if @whens == 0;
5924 foreach my $when (@whens)
5926 return 1 if conditional_true_when ($cond, $when);
5928 return 0;
5932 # $BOOLEAN
5933 # &conditional_implies_any ($COND, @CONDS)
5934 # ----------------------------------------
5935 # Returns true iff $COND implies any of the conditions in @CONDS.
5936 sub conditional_implies_any ($@)
5938 my ($cond, @conds) = @_;
5940 @conds = ("") if @conds == 0;
5942 foreach my $c (@conds)
5944 return 1 if conditional_true_when ($c, $cond);
5946 return 0;
5950 # $NEGATION
5951 # condition_negate ($COND)
5952 # ------------------------
5953 sub condition_negate ($)
5955 my ($cond) = @_;
5957 $cond =~ s/TRUE$/TRUEO/;
5958 $cond =~ s/FALSE$/TRUE/;
5959 $cond =~ s/TRUEO$/FALSE/;
5961 return $cond;
5965 # Compare condition names.
5966 # Issue them in alphabetical order, foo_TRUE before foo_FALSE.
5967 sub by_condition
5969 # Be careful we might be comparing `' or `#'.
5970 $a =~ /^(.*)_(TRUE|FALSE)$/;
5971 my ($aname, $abool) = ($1 || '', $2 || '');
5972 $b =~ /^(.*)_(TRUE|FALSE)$/;
5973 my ($bname, $bbool) = ($1 || '', $2 || '');
5974 return ($aname cmp $bname
5975 # Don't bother with IFs, given that TRUE is after FALSE
5976 # just cmp in the reverse order.
5977 || $bbool cmp $abool
5978 # Just in case...
5979 || $a cmp $b);
5983 # &make_condition (@CONDITIONS)
5984 # -----------------------------
5985 # Transform a list of conditions (themselves can be an internal list
5986 # of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
5987 # Make conditional (a pattern for AC_SUBST).
5988 # Correctly returns the empty string when there are no conditions.
5989 sub make_condition
5991 my $res = conditional_string (@_);
5993 # There are no conditions.
5994 if ($res eq '')
5996 # Nothing to do.
5998 # It's impossible.
5999 elsif ($res eq 'FALSE')
6001 $res = '#';
6003 # Build it.
6004 else
6006 $res = '@' . $res . '@';
6007 $res =~ s/ /@@/g;
6010 return $res;
6015 ## ------------------------------ ##
6016 ## Handling the condition stack. ##
6017 ## ------------------------------ ##
6020 # $COND_STRING
6021 # cond_stack_if ($NEGATE, $COND, $WHERE)
6022 # --------------------------------------
6023 sub cond_stack_if ($$$)
6025 my ($negate, $cond, $where) = @_;
6027 err $where, "$cond does not appear in AM_CONDITIONAL"
6028 if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
6030 $cond = "${cond}_TRUE"
6031 unless $cond =~ /^TRUE|FALSE$/;
6032 $cond = condition_negate ($cond)
6033 if $negate;
6035 push (@cond_stack, $cond);
6037 return conditional_string (@cond_stack);
6041 # $COND_STRING
6042 # cond_stack_else ($NEGATE, $COND, $WHERE)
6043 # ----------------------------------------
6044 sub cond_stack_else ($$$)
6046 my ($negate, $cond, $where) = @_;
6048 if (! @cond_stack)
6050 err $where, "else without if";
6051 return;
6054 $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);
6056 # If $COND is given, check against it.
6057 if (defined $cond)
6059 $cond = "${cond}_TRUE"
6060 unless $cond =~ /^TRUE|FALSE$/;
6061 $cond = condition_negate ($cond)
6062 if $negate;
6064 err ($where, "else reminder ($negate$cond) incompatible with "
6065 . "current conditional: $cond_stack[$#cond_stack]")
6066 if $cond_stack[$#cond_stack] ne $cond;
6069 return conditional_string (@cond_stack);
6073 # $COND_STRING
6074 # cond_stack_endif ($NEGATE, $COND, $WHERE)
6075 # -----------------------------------------
6076 sub cond_stack_endif ($$$)
6078 my ($negate, $cond, $where) = @_;
6079 my $old_cond;
6081 if (! @cond_stack)
6083 err $where, "endif without if: $negate$cond";
6084 return;
6088 # If $COND is given, check against it.
6089 if (defined $cond)
6091 $cond = "${cond}_TRUE"
6092 unless $cond =~ /^TRUE|FALSE$/;
6093 $cond = condition_negate ($cond)
6094 if $negate;
6096 err ($where, "endif reminder ($negate$cond) incompatible with "
6097 . "current conditional: $cond_stack[$#cond_stack]")
6098 if $cond_stack[$#cond_stack] ne $cond;
6101 pop @cond_stack;
6103 return conditional_string (@cond_stack);
6110 ## ------------------------ ##
6111 ## Handling the variables. ##
6112 ## ------------------------ ##
6115 # check_ambiguous_conditional ($VAR, $COND, $WHERE)
6116 # -------------------------------------------------
6117 # Check for an ambiguous conditional. This is called when a variable
6118 # is being defined conditionally. If we already know about a
6119 # definition that is true under the same conditions, then we have an
6120 # ambiguity.
6121 sub check_ambiguous_conditional ($$$)
6123 my ($var, $cond, $where) = @_;
6124 my ($message, $ambig_cond) =
6125 conditional_ambiguous_p ($var, $cond, keys %{$var_value{$var}});
6126 if ($message)
6128 msg 'syntax', $where, "$message ...";
6129 msg_var ('syntax', $var, "... `$var' previously defined here.");
6130 verb (macro_dump ($var));
6134 # $STRING, $AMBIG_COND
6135 # conditional_ambiguous_p ($WHAT, $COND, @CONDS)
6136 # ----------------------------------------------
6137 # Check for an ambiguous conditional. Return an error message and
6138 # the other condition involved if we have one, two empty strings otherwise.
6139 # WHAT: the thing being defined
6140 # COND: the condition under which is is being defined
6141 # CONDS: the conditons under which is had already been defined
6142 sub conditional_ambiguous_p ($$@)
6144 my ($var, $cond, @conds) = @_;
6145 foreach my $vcond (@conds)
6147 # Note that these rules doesn't consider the following
6148 # example as ambiguous.
6150 # if COND1
6151 # FOO = foo
6152 # endif
6153 # if COND2
6154 # FOO = bar
6155 # endif
6157 # It's up to the user to not define COND1 and COND2
6158 # simultaneously.
6159 my $message;
6160 if ($vcond eq $cond)
6162 return ("$var multiply defined in condition $cond", $vcond);
6164 elsif (&conditional_true_when ($vcond, $cond))
6166 return ("$var was already defined in condition $vcond, "
6167 . "which implies condition $cond", $vcond);
6169 elsif (&conditional_true_when ($cond, $vcond))
6171 return ("$var was already defined in condition $vcond, "
6172 . "which is implied by condition $cond", $vcond);
6175 return ('', '');
6178 # @MISSING_CONDS
6179 # variable_not_always_defined_in_cond ($VAR, $COND)
6180 # ---------------------------------------------
6181 # Check whether $VAR is always defined for condition $COND.
6182 # Return a list of conditions where the definition is missing.
6184 # For instance, given
6186 # if COND1
6187 # if COND2
6188 # A = foo
6189 # D = d1
6190 # else
6191 # A = bar
6192 # D = d2
6193 # endif
6194 # else
6195 # D = d3
6196 # endif
6197 # if COND3
6198 # A = baz
6199 # B = mumble
6200 # endif
6201 # C = mumble
6203 # we should have:
6204 # variable_not_always_defined_in_cond ('A', 'COND1_TRUE COND2_TRUE')
6205 # => ()
6206 # variable_not_always_defined_in_cond ('A', 'COND1_TRUE')
6207 # => ()
6208 # variable_not_always_defined_in_cond ('A', 'TRUE')
6209 # => ("COND1_FALSE COND2_FALSE COND3_FALSE",
6210 # "COND1_FALSE COND2_TRUE COND3_FALSE",
6211 # "COND1_TRUE COND2_FALSE COND3_FALSE",
6212 # "COND1_TRUE COND2_TRUE COND3_FALSE")
6213 # variable_not_always_defined_in_cond ('B', 'COND1_TRUE')
6214 # => ("COND3_FALSE")
6215 # variable_not_always_defined_in_cond ('C', 'COND1_TRUE')
6216 # => ()
6217 # variable_not_always_defined_in_cond ('D', 'TRUE')
6218 # => ()
6219 # variable_not_always_defined_in_cond ('Z', 'TRUE')
6220 # => ("TRUE")
6222 sub variable_not_always_defined_in_cond ($$)
6224 my ($var, $cond) = @_;
6226 # It's easy to answer if the variable is not defined.
6227 return ("TRUE",) unless exists $var_value{$var};
6229 # How does it work? Let's take the second example:
6231 # variable_not_always_defined_in_cond ('A', 'COND1_TRUE')
6233 # (1) First, we get the list of conditions where A is defined:
6235 # ("COND1_TRUE COND2_TRUE", "COND1_TRUE COND2_FALSE", "COND3_TRUE")
6237 # (2) Then we generate the set of inverted conditions:
6239 # ("COND1_FALSE COND2_TRUE COND3_FALSE",
6240 # "COND1_FALSE COND2_FALSE COND3_FALSE")
6242 # (3) Finally we remove these conditions which are not implied by
6243 # COND1_TRUE. This yields an empty list and we are done.
6245 my @res = ();
6246 my @cond_defs = keys %{$var_value{$var}}; # (1)
6247 foreach my $icond (invert_conditions (@cond_defs)) # (2)
6249 prog_error "invert_conditions returned an input condition"
6250 if exists $var_value{$var}{$icond};
6252 push @res, $icond
6253 if (conditional_true_when ($cond, $icond)); # (3)
6255 return @res;
6258 # &macro_define($VAR, $OWNER, $TYPE, $COND, $VALUE, $WHERE)
6259 # -------------------------------------------------------------
6260 # The $VAR can go from Automake to user, but not the converse.
6261 sub macro_define ($$$$$$)
6263 my ($var, $owner, $type, $cond, $value, $where) = @_;
6265 # We will adjust the owener of this variable unless told otherwise.
6266 my $adjust_owner = 1;
6268 err $where, "bad characters in variable name `$var'"
6269 if $var !~ /$MACRO_PATTERN/o;
6271 # NEWS-OS 4.2R complains if a Makefile variable begins with `_'.
6272 msg ('portability', $where,
6273 "$var: variable names starting with `_' are not portable")
6274 if $var =~ /^_/;
6276 # `:='-style assignments are not acknowledged by POSIX. Moreover it
6277 # has multiple meanings. In GNU make or BSD make it means "assign
6278 # with immediate expansion", while in OSF make it is used for
6279 # conditional assignments.
6280 msg ('portability', $where, "`:='-style assignments are not portable")
6281 if $type eq ':';
6283 check_variable_expansions ($value, $where);
6285 $cond ||= 'TRUE';
6287 # An Automake variable must be consistently defined with the same
6288 # sign by Automake. A user variable must be set by either `=' or
6289 # `:=', and later promoted to `+='.
6290 if ($owner == VAR_AUTOMAKE)
6292 if (exists $var_type{$var}
6293 && exists $var_type{$var}{$cond}
6294 && $var_type{$var}{$cond} ne $type)
6296 err ($where, "$var was set with `$var_type{$var}=' "
6297 . "and is now set with `$type='");
6300 else
6302 if (!exists $var_type{$var} && $type eq '+')
6304 err $where, "$var must be set with `=' before using `+='";
6307 $var_type{$var}{$cond} = $type;
6309 # When adding, since we rewrite, don't try to preserve the
6310 # Automake continuation backslashes.
6311 $value =~ s/\\$//mg
6312 if $type eq '+' && $owner == VAR_AUTOMAKE;
6314 # Differentiate assignment types.
6316 # 1. append (+=) to a variable defined for current condition
6317 if ($type eq '+' && exists $var_value{$var}{$cond})
6319 if (chomp $var_value{$var}{$cond})
6321 # Insert a backslash before a trailing newline.
6322 $var_value{$var}{$cond} .= "\\\n";
6324 elsif ($var_value{$var}{$cond})
6326 # Insert a separator.
6327 $var_value{$var}{$cond} .= ' ';
6329 $var_value{$var}{$cond} .= $value;
6331 # 2. append (+=) to a variable defined for *another* condition
6332 elsif ($type eq '+' && keys %{$var_value{$var}})
6334 # * Generally, $cond is not TRUE. For instance:
6335 # FOO = foo
6336 # if COND
6337 # FOO += bar
6338 # endif
6339 # In this case, we declare an helper variable conditionally,
6340 # and append it to FOO:
6341 # FOO = foo $(am__append_1)
6342 # @COND_TRUE@am__append_1 = bar
6343 # Of course if FOO is defined under several conditions, we add
6344 # $(am__append_1) to each definitions.
6346 # * If $cond is TRUE, we don't need the helper variable. E.g., in
6347 # if COND1
6348 # FOO = foo1
6349 # else
6350 # FOO = foo2
6351 # endif
6352 # FOO += bar
6353 # we can add bar directly to all definition of FOO, and output
6354 # @COND_TRUE@FOO = foo1 bar
6355 # @COND_FALSE@FOO = foo2 bar
6357 # Do we need an helper variable?
6358 if ($cond ne 'TRUE')
6360 # Does the helper variable already exists?
6361 my $key = "$var:$cond";
6362 if (exists $appendvar{$key})
6364 # Yes, let's simply append to it.
6365 $var = $appendvar{$key};
6366 $owner = VAR_AUTOMAKE;
6368 else
6370 # No, create it.
6371 my $num = 1 + keys (%appendvar);
6372 my $hvar = "am__append_$num";
6373 $appendvar{$key} = $hvar;
6374 &macro_define ($hvar, VAR_AUTOMAKE, '+',
6375 $cond, $value, $where);
6376 push @var_list, $hvar;
6377 # Now HVAR is to be added to VAR.
6378 $value = "\$($hvar)";
6382 # Add VALUE to all definitions of VAR.
6383 foreach my $vcond (keys %{$var_value{$var}})
6385 # We have a bit of error detection to do here.
6386 # This:
6387 # if COND1
6388 # X = Y
6389 # endif
6390 # X += Z
6391 # should be rejected because X is not defined for all conditions
6392 # where `+=' applies.
6393 my @undef_cond = variable_not_always_defined_in_cond $var, $cond;
6394 if (@undef_cond != 0)
6396 err ($where,
6397 "Cannot apply `+=' because `$var' is not defined "
6398 . "in\nthe following conditions:\n "
6399 . join ("\n ", @undef_cond)
6400 . "\nEither define `$var' in these conditions,"
6401 . " or use\n`+=' in the same conditions as"
6402 . " the definitions.");
6404 else
6406 &macro_define ($var, $owner, '+', $vcond, $value, $where);
6409 # Don't adjust the owner. The above &macro_define did it in the
6410 # right conditions.
6411 $adjust_owner = 0;
6413 # 3. first assignment (=, :=, or +=)
6414 else
6416 # If Automake tries to override a value specified by the user,
6417 # just don't let it do.
6418 if (exists $var_value{$var}{$cond}
6419 && $var_owner{$var} != VAR_AUTOMAKE
6420 && $owner == VAR_AUTOMAKE)
6422 verb ("refusing to override the user definition of:\n"
6423 . macro_dump ($var)
6424 ."with `$cond' => `$value'");
6426 else
6428 # There must be no previous value unless the user is redefining
6429 # an Automake variable or an AC_SUBST variable for an existing
6430 # condition.
6431 check_ambiguous_conditional ($var, $cond, $where)
6432 unless (exists $var_owner{$var}{$cond}
6433 && (($var_owner{$var}{$cond} == VAR_AUTOMAKE
6434 && $owner != VAR_AUTOMAKE)
6435 || $var_owner{$var}{$cond} == VAR_CONFIGURE));
6437 $var_value{$var}{$cond} = $value;
6438 # Assignments to a macro set its location. We don't adjust
6439 # locations for `+='. Ideally I suppose we would associate
6440 # line numbers with random bits of text.
6441 $var_location{$var}{$cond} = $where;
6445 # The owner of a variable can only increase, because an Automake
6446 # variable can be given to the user, but not the converse.
6447 if ($adjust_owner &&
6448 (! exists $var_owner{$var}{$cond}
6449 || $owner > $var_owner{$var}{$cond}))
6451 $var_owner{$var}{$cond} = $owner;
6452 # Always adjust the location when the owner changes (even for
6453 # `+=' statements). The risk otherwise is to warn about
6454 # a VAR_MAKEFILE variable and locate it in configure.ac...
6455 $var_location{$var}{$cond} = $where;
6458 # Call var_VAR_trigger if it's defined.
6459 # This hook helps to update some internal state *while*
6460 # parsing the file. For instance the handling of SUFFIXES
6461 # requires this (see var_SUFFIXES_trigger).
6462 my $var_trigger = "var_${var}_trigger";
6463 &$var_trigger($type, $value) if defined &$var_trigger;
6467 # &macro_delete ($VAR, [@CONDS])
6468 # ------------------------------
6469 # Forget about $VAR under the conditions @CONDS, or completely if
6470 # @CONDS is empty.
6471 sub macro_delete ($@)
6473 my ($var, @conds) = @_;
6475 if (!@conds)
6477 delete $var_value{$var};
6478 delete $var_location{$var};
6479 delete $var_owner{$var};
6480 delete $var_comment{$var};
6481 delete $var_type{$var};
6483 else
6485 foreach my $cond (@conds)
6487 delete $var_value{$var}{$cond};
6488 delete $var_location{$var}{$cond};
6489 delete $var_owner{$var}{$cond};
6490 delete $var_comment{$var}{$cond};
6491 delete $var_type{$var}{$cond};
6497 # &macro_dump ($VAR)
6498 # ------------------
6499 sub macro_dump ($)
6501 my ($var) = @_;
6502 my $text = '';
6504 if (!exists $var_value{$var})
6506 $text = " $var does not exist\n";
6508 else
6510 $text .= " $var $var_type{$var}=\n {\n";
6511 foreach my $vcond (sort by_condition keys %{$var_value{$var}})
6513 prog_error ("`$var' is a key in \$var_value, "
6514 . "but not in \$var_owner\n")
6515 unless exists $var_owner{$var}{$vcond};
6517 my $var_owner;
6518 if ($var_owner{$var}{$vcond} == VAR_AUTOMAKE)
6520 $var_owner = 'Automake';
6522 elsif ($var_owner{$var}{$vcond} == VAR_CONFIGURE)
6524 $var_owner = 'Configure';
6526 elsif ($var_owner{$var}{$vcond} == VAR_MAKEFILE)
6528 $var_owner = 'Makefile';
6530 else
6532 prog_error ("unexpected value for `\$var_owner{$var}{$vcond}': "
6533 . $var_owner{$var}{$vcond})
6534 unless defined $var_owner;
6537 my $where = (defined $var_location{$var}{$vcond}
6538 ? $var_location{$var}{$vcond} : "undefined");
6539 $text .= "$var_comment{$var}{$vcond}"
6540 if exists $var_comment{$var}{$vcond};
6541 $text .= " $vcond => $var_value{$var}{$vcond}\n";
6543 $text .= " }\n";
6545 return $text;
6549 # &macros_dump ()
6550 # ---------------
6551 sub macros_dump ()
6553 my ($var) = @_;
6555 my $text = "%var_value =\n{\n";
6556 foreach my $var (sort (keys %var_value))
6558 $text .= macro_dump ($var);
6560 $text .= "}\n";
6561 return $text;
6565 # $BOOLEAN
6566 # variable_defined ($VAR, [$COND])
6567 # ---------------------------------
6568 # See if a variable exists. $VAR is the variable name, and $COND is
6569 # the condition which we should check. If no condition is given, we
6570 # currently return true if the variable is defined under any
6571 # condition.
6572 sub variable_defined ($;$)
6574 my ($var, $cond) = @_;
6576 if (! exists $var_value{$var}
6577 || (defined $cond && ! exists $var_value{$var}{$cond}))
6579 # VAR is not defined.
6581 # Check there is no target defined with the name of the
6582 # variable we check.
6584 # adl> I'm wondering if this error still makes any sense today. I
6585 # adl> guess it was because targets and variables used to share
6586 # adl> the same namespace in older versions of Automake?
6587 # tom> While what you say is definitely part of it, I think it
6588 # tom> might also have been due to someone making a "spelling error"
6589 # tom> -- writing "foo:..." instead of "foo = ...".
6590 # tom> I'm not sure whether it is really worth diagnosing
6591 # tom> this sort of problem. In the old days I used to add warnings
6592 # tom> and errors like this pretty randomly, based on bug reports I
6593 # tom> got. But there's a plausible argument that I was trying
6594 # tom> too hard to prevent people from making mistakes.
6595 if (exists $targets{$var}
6596 && (! defined $cond || exists $targets{$var}{$cond}))
6598 for my $tcond ($cond || keys %{$targets{$var}})
6600 prog_error ("\$targets{$var}{$tcond} exists but "
6601 . "\$target_owner doesn't")
6602 unless exists $target_owner{$var}{$tcond};
6603 # Diagnose the first user target encountered, if any.
6604 # Restricting this test to user targets allows Automake
6605 # to create rules for things like `bin_PROGRAMS = LDADD'.
6606 if ($target_owner{$var}{$tcond} == TARGET_USER)
6608 msg_cond_target ('syntax', $tcond, $var,
6609 "`$var' is a target; "
6610 . "expected a variable");
6611 return 0;
6615 return 0;
6618 # Even a var_value examination is good enough for us. FIXME:
6619 # really should maintain examined status on a per-condition basis.
6620 $content_seen{$var} = 1;
6621 return 1;
6625 # $BOOLEAN
6626 # variable_assert ($VAR, $WHERE)
6627 # ------------------------------
6628 # Make sure a variable exists. $VAR is the variable name, and $WHERE
6629 # is the name of a macro which refers to $VAR.
6630 sub variable_assert ($$)
6632 my ($var, $where) = @_;
6634 return 1
6635 if variable_defined $var;
6637 require_variables ($where, "variable `$var' is used", 'TRUE', $var);
6639 return 0;
6642 # Mark a variable as examined.
6643 sub examine_variable
6645 my ($var) = @_;
6646 variable_defined ($var);
6650 # &variable_conditions_recursive ($VAR)
6651 # -------------------------------------
6652 # Return the set of conditions for which a variable is defined.
6654 # If the variable is not defined conditionally, and is not defined in
6655 # terms of any variables which are defined conditionally, then this
6656 # returns the empty list.
6658 # If the variable is defined conditionally, but is not defined in
6659 # terms of any variables which are defined conditionally, then this
6660 # returns the list of conditions for which the variable is defined.
6662 # If the variable is defined in terms of any variables which are
6663 # defined conditionally, then this returns a full set of permutations
6664 # of the subvariable conditions. For example, if the variable is
6665 # defined in terms of a variable which is defined for COND_TRUE,
6666 # then this returns both COND_TRUE and COND_FALSE. This is
6667 # because we will need to define the variable under both conditions.
6668 sub variable_conditions_recursive ($)
6670 my ($var) = @_;
6672 %vars_scanned = ();
6674 my @new_conds = variable_conditions_recursive_sub ($var, '');
6676 # Now we want to return all permutations of the subvariable
6677 # conditions.
6678 my %allconds = ();
6679 foreach my $item (@new_conds)
6681 foreach (split (' ', $item))
6683 s/^(.*)_(TRUE|FALSE)$/$1_TRUE/;
6684 $allconds{$_} = 1;
6687 @new_conds = variable_conditions_permutations (sort keys %allconds);
6689 my %uniqify;
6690 foreach my $cond (@new_conds)
6692 my $reduce = variable_conditions_reduce (split (' ', $cond));
6693 next
6694 if $reduce eq 'FALSE';
6695 $uniqify{$cond} = 1;
6698 # Note we cannot just do `return sort keys %uniqify', because this
6699 # function is sometimes used in a scalar context.
6700 my @uniq_list = sort by_condition keys %uniqify;
6701 return @uniq_list;
6705 # @CONDS
6706 # variable_conditions ($VAR)
6707 # --------------------------
6708 # Get the list of conditions that a variable is defined with, without
6709 # recursing through the conditions of any subvariables.
6710 # Argument is $VAR: the variable to get the conditions of.
6711 # Returns the list of conditions.
6712 sub variable_conditions ($)
6714 my ($var) = @_;
6715 my @conds = keys %{$var_value{$var}};
6716 return sort by_condition @conds;
6720 # $BOOLEAN
6721 # &variable_conditionally_defined ($VAR)
6722 # --------------------------------------
6723 sub variable_conditionally_defined ($)
6725 my ($var) = @_;
6726 foreach my $cond (variable_conditions_recursive ($var))
6728 return 1
6729 unless $cond =~ /^TRUE|FALSE$/;
6731 return 0;
6734 # @LIST
6735 # &scan_variable_expansions ($TEXT)
6736 # ---------------------------------
6737 # Return the list of variable names expanded in $TEXT.
6738 # Note that unlike some other functions, $TEXT is not split
6739 # on spaces before we check for subvariables.
6740 sub scan_variable_expansions ($)
6742 my ($text) = @_;
6743 my @result = ();
6745 # Strip comments.
6746 $text =~ s/#.*$//;
6748 # Record each use of ${stuff} or $(stuff) that do not follow a $.
6749 while ($text =~ /(?<!\$)\$(?:\{([^\}]*)\}|\(([^\)]*)\))/g)
6751 my $var = $1 || $2;
6752 # The occurent may look like $(string1[:subst1=[subst2]]) but
6753 # we want only `string1'.
6754 $var =~ s/:[^:=]*=[^=]*$//;
6755 push @result, $var;
6758 return @result;
6761 # &check_variable_expansions ($TEXT, $WHERE)
6762 # ------------------------------------------
6763 # Check variable expansions in $TEXT and warn about any name that
6764 # does not conform to POSIX. $WHERE is the location of $TEXT for
6765 # the error message.
6766 sub check_variable_expansions ($$)
6768 my ($text, $where) = @_;
6769 # Catch expansion of variables whose name does not conform to POSIX.
6770 foreach my $var (scan_variable_expansions ($text))
6772 if ($var !~ /$MACRO_PATTERN/)
6774 # If the variable name contains a space, it's likely
6775 # to be a GNU make extension (such as $(addsuffix ...)).
6776 # Mention this in the diagnostic.
6777 my $gnuext = "";
6778 $gnuext = "\n(probably a GNU make extension)" if $var =~ / /;
6779 msg ('portability', $where,
6780 "$var: non-POSIX variable name$gnuext");
6785 # &variable_conditions_recursive_sub ($VAR, $PARENT)
6786 # -------------------------------------------------------
6787 # A subroutine of variable_conditions_recursive. This returns all the
6788 # conditions of $VAR, including those of any sub-variables.
6789 sub variable_conditions_recursive_sub
6791 my ($var, $parent) = @_;
6792 my @new_conds = ();
6794 if (defined $vars_scanned{$var})
6796 err_var $parent, "variable `$var' recursively defined";
6797 return ();
6799 $vars_scanned{$var} = 1;
6801 my @this_conds = ();
6802 # Examine every condition under which $VAR is defined.
6803 foreach my $vcond (keys %{$var_value{$var}})
6805 push (@this_conds, $vcond);
6807 # If $VAR references some other variable, then compute the
6808 # conditions for that subvariable.
6809 my @subvar_conds = ();
6810 foreach my $varname (scan_variable_expansions $var_value{$var}{$vcond})
6812 if ($varname =~ /$SUBST_REF_PATTERN/o)
6814 $varname = $1;
6817 # Here we compute all the conditions under which the
6818 # subvariable is defined. Then we go through and add
6819 # $VCOND to each.
6820 my @svc = variable_conditions_recursive_sub ($varname, $var);
6821 foreach my $item (@svc)
6823 my $val = conditional_string ($vcond, split (' ', $item));
6824 $val ||= 'TRUE';
6825 push (@subvar_conds, $val);
6829 # If there are no conditional subvariables, then we want to
6830 # return this condition. Otherwise, we want to return the
6831 # permutations of the subvariables, taking into account the
6832 # conditions of $VAR.
6833 if (! @subvar_conds)
6835 push (@new_conds, $vcond);
6837 else
6839 push (@new_conds, variable_conditions_reduce (@subvar_conds));
6843 # Unset our entry in vars_scanned. We only care about recursive
6844 # definitions.
6845 delete $vars_scanned{$var};
6847 # If we are being called on behalf of another variable, we need to
6848 # return all possible permutations of the conditions. We have
6849 # already handled everything in @this_conds along with their
6850 # subvariables. We now need to add any permutations that are not
6851 # in @this_conds.
6852 foreach my $this_cond (@this_conds)
6854 my @perms =
6855 variable_conditions_permutations (split (' ', $this_cond));
6856 foreach my $perm (@perms)
6858 my $ok = 1;
6859 foreach my $scan (@this_conds)
6861 if (&conditional_true_when ($perm, $scan)
6862 || &conditional_true_when ($scan, $perm))
6864 $ok = 0;
6865 last;
6868 next if ! $ok;
6870 # This permutation was not already handled, and is valid
6871 # for the parents.
6872 push (@new_conds, $perm);
6876 return @new_conds;
6880 # Filter a list of conditionals so that only the exclusive ones are
6881 # retained. For example, if both `COND1_TRUE COND2_TRUE' and
6882 # `COND1_TRUE' are in the list, discard the latter.
6883 # If the list is empty, return TRUE
6884 sub variable_conditions_reduce
6886 my (@conds) = @_;
6887 my @ret = ();
6888 my $cond;
6889 while(@conds > 0)
6891 $cond = shift(@conds);
6893 # FALSE is absorbent.
6894 return 'FALSE'
6895 if $cond eq 'FALSE';
6897 if (!conditional_is_redundant ($cond, @ret, @conds))
6899 push (@ret, $cond);
6903 return "TRUE" if @ret == 0;
6904 return @ret;
6907 # @CONDS
6908 # invert_conditions (@CONDS)
6909 # --------------------------
6910 # Invert a list of conditionals. Returns a set of conditionals which
6911 # are never true for any of the input conditionals, and when taken
6912 # together with the input conditionals cover all possible cases.
6914 # For example:
6915 # invert_conditions("A_TRUE B_TRUE", "A_FALSE B_FALSE")
6916 # => ("A_FALSE B_TRUE", "A_TRUE B_FALSE")
6918 # invert_conditions("A_TRUE B_TRUE", "A_TRUE B_FALSE", "A_FALSE")
6919 # => ()
6920 sub invert_conditions
6922 my (@conds) = @_;
6924 my @notconds = ();
6926 # Generate all permutation for all inputs.
6927 my @perm =
6928 map { variable_conditions_permutations (split(' ', $_)); } @conds;
6929 # Remove redundant conditions.
6930 @perm = variable_conditions_reduce @perm;
6932 # Now remove all conditions which imply one of the input conditions.
6933 foreach my $perm (@perm)
6935 push @notconds, $perm
6936 if ! conditional_implies_any ($perm, @conds);
6938 return @notconds;
6941 # Return a list of permutations of a conditional string.
6942 # (But never output FALSE conditions, they are useless.)
6944 # Examples:
6945 # variable_conditions_permutations ("FOO_FALSE", "BAR_TRUE")
6946 # => ("FOO_FALSE BAR_FALSE",
6947 # "FOO_FALSE BAR_TRUE",
6948 # "FOO_TRUE BAR_FALSE",
6949 # "FOO_TRUE BAR_TRUE")
6950 # variable_conditions_permutations ("FOO_FALSE", "TRUE")
6951 # => ("FOO_FALSE TRUE",
6952 # "FOO_TRUE TRUE")
6953 # variable_conditions_permutations ("TRUE")
6954 # => ("TRUE")
6955 # variable_conditions_permutations ("FALSE")
6956 # => ("TRUE")
6957 sub variable_conditions_permutations
6959 my (@comps) = @_;
6960 return ()
6961 if ! @comps;
6962 my $comp = shift (@comps);
6963 return variable_conditions_permutations (@comps)
6964 if $comp eq '';
6965 my $neg = condition_negate ($comp);
6967 my @ret;
6968 foreach my $sub (variable_conditions_permutations (@comps))
6970 push (@ret, "$comp $sub") if $comp ne 'FALSE';
6971 push (@ret, "$neg $sub") if $neg ne 'FALSE';
6973 if (! @ret)
6975 push (@ret, $comp) if $comp ne 'FALSE';
6976 push (@ret, $neg) if $neg ne 'FALSE';
6978 return @ret;
6982 # $BOOL
6983 # &check_variable_defined_unconditionally($VAR, $PARENT)
6984 # ------------------------------------------------------
6985 # Warn if a variable is conditionally defined. This is called if we
6986 # are using the value of a variable.
6987 sub check_variable_defined_unconditionally ($$)
6989 my ($var, $parent) = @_;
6990 foreach my $cond (keys %{$var_value{$var}})
6992 next
6993 if $cond =~ /^TRUE|FALSE$/;
6995 if ($parent)
6997 msg_var ('unsupported', $parent,
6998 "automake does not support conditional definition of "
6999 . "$var in $parent");
7001 else
7003 msg_var ('unsupported', $var,
7004 "automake does not support $var being defined "
7005 . "conditionally");
7011 # Get the TRUE value of a variable, warn if the variable is
7012 # conditionally defined.
7013 sub variable_value
7015 my ($var) = @_;
7016 &check_variable_defined_unconditionally ($var);
7017 return $var_value{$var}{'TRUE'};
7021 # @VALUES
7022 # &value_to_list ($VAR, $VAL, $COND)
7023 # ----------------------------------
7024 # Convert a variable value to a list, split as whitespace. This will
7025 # recursively follow $(...) and ${...} inclusions. It preserves @...@
7026 # substitutions.
7028 # If COND is 'all', then all values under all conditions should be
7029 # returned; if COND is a particular condition (all conditions are
7030 # surrounded by @...@) then only the value for that condition should
7031 # be returned; otherwise, warn if VAR is conditionally defined.
7032 # SCANNED is a global hash listing whose keys are all the variables
7033 # already scanned; it is an error to rescan a variable.
7034 sub value_to_list ($$$)
7036 my ($var, $val, $cond) = @_;
7037 my @result;
7039 # Strip backslashes
7040 $val =~ s/\\(\n|$)/ /g;
7042 foreach (split (' ', $val))
7044 # If a comment seen, just leave.
7045 last if /^#/;
7047 # Handle variable substitutions.
7048 if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
7050 my $varname = $1;
7052 # If the user uses a losing variable name, just ignore it.
7053 # This isn't ideal, but people have requested it.
7054 next if ($varname =~ /\@.*\@/);
7056 my ($from, $to);
7057 my @temp_list;
7058 if ($varname =~ /$SUBST_REF_PATTERN/o)
7060 $varname = $1;
7061 $to = $3;
7062 $from = quotemeta $2;
7065 # Find the value.
7066 @temp_list =
7067 variable_value_as_list_recursive_worker ($1, $cond, $var);
7069 # Now rewrite the value if appropriate.
7070 if (defined $from)
7072 grep (s/$from$/$to/, @temp_list);
7075 push (@result, @temp_list);
7077 else
7079 push (@result, $_);
7083 return @result;
7087 # @VALUES
7088 # variable_value_as_list ($VAR, $COND, $PARENT)
7089 # ---------------------------------------------
7090 # Get the value of a variable given a specified condition. without
7091 # recursing through any subvariables.
7092 # Arguments are:
7093 # $VAR is the variable
7094 # $COND is the condition. If this is not given, the value for the
7095 # "TRUE" condition will be returned.
7096 # $PARENT is the variable in which the variable is used: this is used
7097 # only for error messages.
7098 # Returns the list of conditions.
7099 # For example, if A is defined as "foo $(B) bar", and B is defined as
7100 # "baz", this will return ("foo", "$(B)", "bar")
7101 sub variable_value_as_list
7103 my ($var, $cond, $parent) = @_;
7104 my @result;
7106 # Check defined
7107 return
7108 unless variable_assert $var, $parent;
7110 # Get value for given condition
7111 $cond ||= 'TRUE';
7112 my $onceflag;
7113 foreach my $vcond (keys %{$var_value{$var}})
7115 my $val = $var_value{$var}{$vcond};
7117 if (&conditional_true_when ($vcond, $cond))
7119 # Unless variable is not defined conditionally, there should only
7120 # be one value of $vcond true when $cond.
7121 &check_variable_defined_unconditionally ($var, $parent)
7122 if $onceflag;
7123 $onceflag = 1;
7125 # Strip backslashes
7126 $val =~ s/\\(\n|$)/ /g;
7128 foreach (split (' ', $val))
7130 # If a comment seen, just leave.
7131 last if /^#/;
7133 push (@result, $_);
7138 return @result;
7142 # @VALUE
7143 # &variable_value_as_list_recursive_worker ($VAR, $COND, $PARENT)
7144 # ---------------------------------------------------------------
7145 # Return contents of VAR as a list, split on whitespace. This will
7146 # recursively follow $(...) and ${...} inclusions. It preserves @...@
7147 # substitutions. If COND is 'all', then all values under all
7148 # conditions should be returned; if COND is a particular condition
7149 # (all conditions are surrounded by @...@) then only the value for
7150 # that condition should be returned; otherwise, warn if VAR is
7151 # conditionally defined. If PARENT is specified, it is the name of
7152 # the including variable; this is only used for error reports.
7153 sub variable_value_as_list_recursive_worker ($$$)
7155 my ($var, $cond, $parent) = @_;
7156 my @result = ();
7158 return
7159 unless variable_assert $var, $parent;
7161 if (defined $vars_scanned{$var})
7163 # `vars_scanned' is a global we use to keep track of which
7164 # variables we've already examined.
7165 err_var $parent, "variable `$var' recursively defined";
7167 elsif ($cond eq 'all')
7169 $vars_scanned{$var} = 1;
7170 foreach my $vcond (keys %{$var_value{$var}})
7172 my $val = $var_value{$var}{$vcond};
7173 push (@result, &value_to_list ($var, $val, $cond));
7176 else
7178 $cond ||= 'TRUE';
7179 $vars_scanned{$var} = 1;
7180 my $onceflag;
7181 foreach my $vcond (keys %{$var_value{$var}})
7183 my $val = $var_value{$var}{$vcond};
7184 if (&conditional_true_when ($vcond, $cond))
7186 # Warn if we have an ambiguity. It's hard to know how
7187 # to handle this case correctly.
7188 &check_variable_defined_unconditionally ($var, $parent)
7189 if $onceflag;
7190 $onceflag = 1;
7191 push (@result, &value_to_list ($var, $val, $cond));
7196 # Unset our entry in vars_scanned. We only care about recursive
7197 # definitions.
7198 delete $vars_scanned{$var};
7200 return @result;
7204 # &variable_output ($VAR, [@CONDS])
7205 # ---------------------------------
7206 # Output all the values of $VAR is @COND is not specified, else only
7207 # that corresponding to @COND.
7208 sub variable_output ($@)
7210 my ($var, @conds) = @_;
7212 @conds = keys %{$var_value{$var}}
7213 unless @conds;
7215 foreach my $cond (sort by_condition @conds)
7217 prog_error ("unknown condition `$cond' for `$var'")
7218 unless exists $var_value{$var}{$cond};
7220 if (exists $var_comment{$var} && exists $var_comment{$var}{$cond})
7222 $output_vars .= $var_comment{$var}{$cond};
7225 my $val = $var_value{$var}{$cond};
7226 my $equals = $var_type{$var}{$cond} eq ':' ? ':=' : '=';
7227 my $output_var = "$var $equals $val";
7228 $output_var =~ s/^/make_condition ($cond)/meg;
7229 $output_vars .= $output_var . "\n";
7234 # &variable_pretty_output ($VAR, [@CONDS])
7235 # ----------------------------------------
7236 # Likewise, but pretty, i.e., we *split* the values at spaces. Use only
7237 # with variables holding filenames.
7238 sub variable_pretty_output ($@)
7240 my ($var, @conds) = @_;
7242 @conds = keys %{$var_value{$var}}
7243 unless @conds;
7245 foreach my $cond (sort by_condition @conds)
7247 prog_error ("unknown condition `$cond' for `$var'")
7248 unless exists $var_value{$var}{$cond};
7250 if (exists $var_comment{$var} && exists $var_comment{$var}{$cond})
7252 $output_vars .= $var_comment{$var}{$cond};
7255 my $val = $var_value{$var}{$cond};
7256 my $equals = $var_type{$var}{$cond} eq ':' ? ':=' : '=';
7257 my $make_condition = make_condition ($cond);
7258 $output_vars .= pretty_print_internal ("$make_condition$var $equals",
7259 "$make_condition\t",
7260 split (' ' , $val));
7265 # &variable_value_as_list_recursive ($VAR, $COND, $PARENT)
7266 # --------------------------------------------------------
7267 # This is just a wrapper for variable_value_as_list_recursive_worker that
7268 # initializes the global hash `vars_scanned'. This hash is used to
7269 # avoid infinite recursion.
7270 sub variable_value_as_list_recursive ($$@)
7272 my ($var, $cond, $parent) = @_;
7273 %vars_scanned = ();
7274 return &variable_value_as_list_recursive_worker ($var, $cond, $parent);
7278 # &define_pretty_variable ($VAR, $COND, @VALUE)
7279 # ---------------------------------------------
7280 # Like define_variable, but the value is a list, and the variable may
7281 # be defined conditionally. The second argument is the conditional
7282 # under which the value should be defined; this should be the empty
7283 # string to define the variable unconditionally. The third argument
7284 # is a list holding the values to use for the variable. The value is
7285 # pretty printed in the output file.
7286 sub define_pretty_variable ($$@)
7288 my ($var, $cond, @value) = @_;
7290 # Beware that an empty $cond has a different semantics for
7291 # macro_define and variable_pretty_output.
7292 $cond ||= 'TRUE';
7294 if (! variable_defined ($var, $cond))
7296 macro_define ($var, VAR_AUTOMAKE, '', $cond, "@value", undef);
7297 variable_pretty_output ($var, $cond || 'TRUE');
7298 $content_seen{$var} = 1;
7303 # define_variable ($VAR, $VALUE)
7304 # ------------------------------
7305 # Define a new user variable VAR to VALUE, but only if not already defined.
7306 sub define_variable ($$)
7308 my ($var, $value) = @_;
7309 define_pretty_variable ($var, 'TRUE', $value);
7313 # Like define_variable, but define a variable to be the configure
7314 # substitution by the same name.
7315 sub define_configure_variable ($)
7317 my ($var) = @_;
7318 if (! variable_defined ($var, 'TRUE')
7319 # Explicitly avoid ANSI2KNR -- we AC_SUBST that in
7320 # protos.m4, but later define it elsewhere. This is
7321 # pretty hacky. We also explicitly avoid AMDEPBACKSLASH:
7322 # it might be subst'd by `\', which certainly would not be
7323 # appreciated by Make.
7324 && ! grep { $_ eq $var } (qw(ANSI2KNR AMDEPBACKSLASH)))
7326 macro_define ($var, VAR_CONFIGURE, '', 'TRUE',
7327 subst $var, $configure_vars{$var});
7328 variable_pretty_output ($var, 'TRUE');
7333 # define_compiler_variable ($LANG)
7334 # --------------------------------
7335 # Define a compiler variable. We also handle defining the `LT'
7336 # version of the command when using libtool.
7337 sub define_compiler_variable ($)
7339 my ($lang) = @_;
7341 my ($var, $value) = ($lang->compiler, $lang->compile);
7342 &define_variable ($var, $value);
7343 &define_variable ("LT$var", "\$(LIBTOOL) --mode=compile $value")
7344 if variable_defined ('LIBTOOL');
7348 # define_linker_variable ($LANG)
7349 # ------------------------------
7350 # Define linker variables.
7351 sub define_linker_variable ($)
7353 my ($lang) = @_;
7355 my ($var, $value) = ($lang->lder, $lang->ld);
7356 # CCLD = $(CC).
7357 &define_variable ($lang->lder, $lang->ld);
7358 # CCLINK = $(CCLD) blah blah...
7359 &define_variable ($lang->linker,
7360 ((variable_defined ('LIBTOOL')
7361 ? '$(LIBTOOL) --mode=link ' : '')
7362 . $lang->link));
7365 ################################################################
7367 ## ---------------- ##
7368 ## Handling rules. ##
7369 ## ---------------- ##
7371 sub register_suffix_rule ($$$)
7373 my ($where, $src, $dest) = @_;
7375 verb "Sources ending in $src become $dest";
7376 push @suffixes, $src, $dest;
7378 # When tranforming sources to objects, Automake uses the
7379 # %suffix_rules to move from each source extension to
7380 # `.$(OBJEXT)', not to `.o' or `.obj'. However some people
7381 # define suffix rules for `.o' or `.obj', so internally we will
7382 # consider these extensions equivalent to `.$(OBJEXT)'. We
7383 # CANNOT rewrite the target (i.e., automagically replace `.o'
7384 # and `.obj' by `.$(OBJEXT)' in the output), or warn the user
7385 # that (s)he'd better use `.$(OBJEXT)', because Automake itself
7386 # output suffix rules for `.o' or `.obj'...
7387 $dest = '.$(OBJEXT)' if ($dest eq '.o' || $dest eq '.obj');
7389 # Reading the comments near the declaration of $suffix_rules might
7390 # help to understand the update of $suffix_rules that follows...
7392 # Register $dest as a possible destination from $src.
7393 # We might have the create the \hash.
7394 if (exists $suffix_rules->{$src})
7396 $suffix_rules->{$src}{$dest} = [ $dest, 1 ];
7398 else
7400 $suffix_rules->{$src} = { $dest => [ $dest, 1 ] };
7403 # If we know how to transform $dest in something else, then
7404 # we know how to transform $src in that "something else".
7405 if (exists $suffix_rules->{$dest})
7407 for my $dest2 (keys %{$suffix_rules->{$dest}})
7409 my $dist = $suffix_rules->{$dest}{$dest2}[1] + 1;
7410 # Overwrite an existing $src->$dest2 path only if
7411 # the path via $dest which is shorter.
7412 if (! exists $suffix_rules->{$src}{$dest2}
7413 || $suffix_rules->{$src}{$dest2}[1] > $dist)
7415 $suffix_rules->{$src}{$dest2} = [ $dest, $dist ];
7420 # Similarly, any extension that can be derived into $src
7421 # can be derived into the same extenstions as $src can.
7422 my @dest2 = keys %{$suffix_rules->{$src}};
7423 for my $src2 (keys %$suffix_rules)
7425 if (exists $suffix_rules->{$src2}{$src})
7427 for my $dest2 (@dest2)
7429 my $dist = $suffix_rules->{$src}{$dest2} + 1;
7430 # Overwrite an existing $src2->$dest2 path only if
7431 # the path via $src is shorter.
7432 if (! exists $suffix_rules->{$src2}{$dest2}
7433 || $suffix_rules->{$src2}{$dest2}[1] > $dist)
7435 $suffix_rules->{$src2}{$dest2} = [ $src, $dist ];
7442 # @CONDS
7443 # rule_define ($TARGET, $SOURCE, $OWNER, $COND, $WHERE)
7444 # -----------------------------------------------------
7445 # Define a new rule. $TARGET is the rule name. $SOURCE
7446 # is the filename the rule comes from. $OWNER is the
7447 # owener of the rule (TARGET_AUTOMAKE or TARGET_USER).
7448 # $COND is the condition string under which the rule is defined.
7449 # $WHERE is where the rule is defined (file name and/or line number).
7450 # Returns a (possibly empty) list of conditions where the rule
7451 # should be defined.
7452 sub rule_define ($$$$$)
7454 my ($target, $source, $owner, $cond, $where) = @_;
7456 # Don't even think about defining a rule in condition FALSE.
7457 return () if $cond eq 'FALSE';
7459 # For now `foo:' will override `foo$(EXEEXT):'. This is temporary,
7460 # though, so we emit a warning.
7461 (my $noexe = $target) =~ s,\$\(EXEEXT\)$,,;
7462 if ($noexe ne $target
7463 && exists $targets{$noexe}
7464 && exists $targets{$noexe}{$cond}
7465 && $target_name{$noexe}{$cond} ne $target)
7467 # The no-exeext option enables this feature.
7468 if (! defined $options{'no-exeext'})
7470 msg ('obsolete', $noexe,
7471 "deprecated feature: `$noexe' overrides `$noexe\$(EXEEXT)'\n"
7472 . "change your target to read `$noexe\$(EXEEXT)'");
7474 # Don't define.
7475 return ();
7478 # For now on, strip off $(EXEEXT) from $target, so we can diagnose
7479 # a clash if `ctags$(EXEEXT):' is redefined after `ctags:'.
7480 my $realtarget = $target;
7481 $target = $noexe;
7483 # A GNU make-style pattern rule has a single "%" in the target name.
7484 msg ('portability', $where,
7485 "`%'-style pattern rules are a GNU make extension")
7486 if $target =~ /^[^%]*%[^%]*$/;
7488 # Diagnose target redefinitions.
7489 if (exists $target_source{$target}{$cond})
7491 # Sanity checks.
7492 prog_error ("\$target_source{$target}{$cond} exists, but \$target_owner"
7493 . " doesn't.")
7494 unless exists $target_owner{$target}{$cond};
7495 prog_error ("\$target_source{$target}{$cond} exists, but \$targets"
7496 . " doesn't.")
7497 unless exists $targets{$target}{$cond};
7498 prog_error ("\$target_source{$target}{$cond} exists, but \$target_name"
7499 . " doesn't.")
7500 unless exists $target_name{$target}{$cond};
7502 my $oldowner = $target_owner{$target}{$cond};
7504 # Don't mention true conditions in diagnostics.
7505 my $condmsg = $cond ne 'TRUE' ? " in condition `$cond'" : '';
7507 if ($owner == TARGET_USER)
7509 if ($oldowner eq TARGET_USER)
7511 # Ignore `%'-style pattern rules. We'd need the
7512 # dependencies to detect duplicates, and they are
7513 # already diagnosed as unportable by -Wportability.
7514 if ($target !~ /^[^%]*%[^%]*$/)
7516 ## FIXME: Presently we can't diagnose duplcate user rules
7517 ## because we doesn't distinguish rules with commands
7518 ## from rules that only add dependencies. E.g.,
7519 ## .PHONY: foo
7520 ## .PHONY: bar
7521 ## is legitimate. (This is phony.test.)
7523 # msg ('syntax', $where,
7524 # "redefinition of `$target'$condmsg...");
7525 # msg_cond_target ('syntax', $cond, $target,
7526 # "... `$target' previously defined here.");
7528 # Return so we don't redefine the rule in our tables,
7529 # don't check for ambiguous conditional, etc. The rule
7530 # will be output anyway beauce &read_am_file ignore the
7531 # return code.
7532 return ();
7534 else
7536 # Since we parse the user Makefile.am before reading
7537 # the Automake fragments, this condition should never happen.
7538 prog_error ("user target `$target' seen after Automake's "
7539 . "definition\nfrom `$targets{$target}$condmsg'");
7542 else # $owner == TARGET_AUTOMAKE
7544 if ($oldowner == TARGET_USER)
7546 # Don't overwrite the user definition of TARGET.
7547 return ();
7549 else # $oldowner == TARGET_AUTOMAKE
7551 # Automake should ignore redefinitions of its own
7552 # rules if they came from the same file. This makes
7553 # it easier to process a Makefile fragment several times.
7554 # Hower it's an error if the target is defined in many
7555 # files. E.g., the user might be using bin_PROGRAMS = ctags
7556 # which clashes with our `ctags' rule.
7557 # (It would be more accurate if we had a way to compare
7558 # the *content* of both rules. Then $targets_source would
7559 # be useless.)
7560 my $oldsource = $target_source{$target}{$cond};
7561 return () if $source eq $oldsource;
7563 msg ('syntax', $where, "redefinition of `$target'$condmsg...");
7564 msg_cond_target ('syntax', $cond, $target,
7565 "... `$target' previously defined here.");
7566 return ();
7569 # Never reached.
7570 prog_error ("Unreachable place reached.");
7573 # Conditions for which the rule should be defined.
7574 my @conds = $cond;
7576 # Check ambiguous conditional definitions.
7577 my ($message, $ambig_cond) =
7578 conditional_ambiguous_p ($target, $cond, keys %{$targets{$target}});
7579 if ($message) # We have an ambiguty.
7581 if ($owner == TARGET_USER)
7583 # For user rules, just diagnose the ambiguity.
7584 msg 'syntax', $where, "$message ...";
7585 msg_cond_target ('syntax', $ambig_cond, $target,
7586 "... `$target' previously defined here.");
7587 return ();
7589 else
7591 # FIXME: for Automake rules, we can't diagnose ambiguities yet.
7592 # The point is that Automake doesn't propagate conditionals
7593 # everywhere. For instance &handle_PROGRAMS doesn't care if
7594 # bin_PROGRAMS was defined conditionally or not.
7595 # On the following input
7596 # if COND1
7597 # foo:
7598 # ...
7599 # else
7600 # bin_PROGRAMS = foo
7601 # endif
7602 # &handle_PROGRAMS will attempt to define a `foo:' rule
7603 # in condition TRUE (which conflicts with COND1). Fixing
7604 # this in &handle_PROGRAMS and siblings seems hard: you'd
7605 # have to explain &file_contents what to do with a
7606 # conditional. So for now we do our best *here*. If `foo:'
7607 # was already defined in condition COND1 and we want to define
7608 # it in condition TRUE, then define it only in condition !COND1.
7609 # (See cond14.test and cond15.test for some test cases.)
7610 my @defined_conds = keys %{$targets{$target}};
7611 @conds = ();
7612 for my $undefined_cond (invert_conditions(@defined_conds))
7614 push @conds, make_condition ($cond, $undefined_cond);
7616 # No conditions left to define the rule.
7617 # Warn, because our workaround is meaningless in this case.
7618 if (scalar @conds == 0)
7620 msg 'syntax', $where, "$message ...";
7621 msg_cond_target ('syntax', $ambig_cond, $target,
7622 "... `$target' previously defined here.");
7623 return ();
7628 # Finally define this rule.
7629 for my $c (@conds)
7631 $targets{$target}{$c} = $where;
7632 $target_source{$target}{$c} = $source;
7633 $target_owner{$target}{$c} = $owner;
7634 $target_name{$target}{$c} = $realtarget;
7637 # Check the rule for being a suffix rule. If so, store in a hash.
7638 # Either it's a rule for two known extensions...
7639 if ($target =~ /^($KNOWN_EXTENSIONS_PATTERN)($KNOWN_EXTENSIONS_PATTERN)$/
7640 # ...or it's a rule with unknown extensions (.i.e, the rule looks like
7641 # `.foo.bar:' but `.foo' or `.bar' are not declared in SUFFIXES
7642 # and are not known language extensions).
7643 # Automake will complete SUFFIXES from @suffixes automatically
7644 # (see handle_footer).
7645 || ($target =~ /$SUFFIX_RULE_PATTERN/o && accept_extensions($1)))
7647 register_suffix_rule ($where, $1, $2);
7650 # Return "" instead of TRUE so it can be used with make_paragraphs
7651 # directly.
7652 return "" if 1 == @conds && $conds[0] eq 'TRUE';
7653 return @conds;
7657 # See if a target exists.
7658 sub target_defined
7660 my ($target) = @_;
7661 return exists $targets{$target};
7665 ################################################################
7667 # &append_comments ($VARIABLE, $SPACING, $COMMENT)
7668 # ------------------------------------------------
7669 # Apped $COMMENT to the other comments for $VARIABLE, using
7670 # $SPACING as separator.
7671 sub append_comments ($$$$)
7673 my ($cond, $var, $spacing, $comment) = @_;
7674 $var_comment{$var}{$cond} .= $spacing
7675 if (!defined $var_comment{$var}{$cond}
7676 || $var_comment{$var}{$cond} !~ /\n$/o);
7677 $var_comment{$var}{$cond} .= $comment;
7681 # &read_am_file ($AMFILE)
7682 # -----------------------
7683 # Read Makefile.am and set up %contents. Simultaneously copy lines
7684 # from Makefile.am into $output_trailer or $output_vars as
7685 # appropriate. NOTE we put rules in the trailer section. We want
7686 # user rules to come after our generated stuff.
7687 sub read_am_file ($)
7689 my ($amfile) = @_;
7691 my $am_file = new Automake::XFile ("< $amfile");
7692 verb "reading $amfile";
7694 my $spacing = '';
7695 my $comment = '';
7696 my $blank = 0;
7697 my $saw_bk = 0;
7699 use constant IN_VAR_DEF => 0;
7700 use constant IN_RULE_DEF => 1;
7701 use constant IN_COMMENT => 2;
7702 my $prev_state = IN_RULE_DEF;
7704 while ($_ = $am_file->getline)
7706 if (/$IGNORE_PATTERN/o)
7708 # Merely delete comments beginning with two hashes.
7710 elsif (/$WHITE_PATTERN/o)
7712 err "$amfile:$.", "blank line following trailing backslash"
7713 if $saw_bk;
7714 # Stick a single white line before the incoming macro or rule.
7715 $spacing = "\n";
7716 $blank = 1;
7717 # Flush all comments seen so far.
7718 if ($comment ne '')
7720 $output_vars .= $comment;
7721 $comment = '';
7724 elsif (/$COMMENT_PATTERN/o)
7726 # Stick comments before the incoming macro or rule. Make
7727 # sure a blank line preceeds first block of comments.
7728 $spacing = "\n" unless $blank;
7729 $blank = 1;
7730 $comment .= $spacing . $_;
7731 $spacing = '';
7732 $prev_state = IN_COMMENT;
7734 else
7736 last;
7738 $saw_bk = /\\$/ && ! /$IGNORE_PATTERN/o;
7741 # We save the conditional stack on entry, and then check to make
7742 # sure it is the same on exit. This lets us conditonally include
7743 # other files.
7744 my @saved_cond_stack = @cond_stack;
7745 my $cond = conditional_string (@cond_stack);
7747 my $last_var_name = '';
7748 my $last_var_type = '';
7749 my $last_var_value = '';
7750 # FIXME: shouldn't use $_ in this loop; it is too big.
7751 while ($_)
7753 my $here = "$amfile:$.";
7755 # Make sure the line is \n-terminated.
7756 chomp;
7757 $_ .= "\n";
7759 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
7760 # used by users. @MAINT@ is an anachronism now.
7761 $_ =~ s/\@MAINT\@//g
7762 unless $seen_maint_mode;
7764 my $new_saw_bk = /\\$/ && ! /$IGNORE_PATTERN/o;
7766 if (/$IGNORE_PATTERN/o)
7768 # Merely delete comments beginning with two hashes.
7770 elsif (/$WHITE_PATTERN/o)
7772 # Stick a single white line before the incoming macro or rule.
7773 $spacing = "\n";
7774 err $here, "blank line following trailing backslash"
7775 if $saw_bk;
7777 elsif (/$COMMENT_PATTERN/o)
7779 # Stick comments before the incoming macro or rule.
7780 $comment .= $spacing . $_;
7781 $spacing = '';
7782 err $here, "comment following trailing backslash"
7783 if $saw_bk && $comment eq '';
7784 $prev_state = IN_COMMENT;
7786 elsif ($saw_bk)
7788 if ($prev_state == IN_RULE_DEF)
7790 $output_trailer .= &make_condition (@cond_stack);
7791 $output_trailer .= $_;
7793 elsif ($prev_state == IN_COMMENT)
7795 # If the line doesn't start with a `#', add it.
7796 # We do this because a continuated comment like
7797 # # A = foo \
7798 # bar \
7799 # baz
7800 # is not portable. BSD make doesn't honor
7801 # escaped newlines in comments.
7802 s/^#?/#/;
7803 $comment .= $spacing . $_;
7805 else # $prev_state == IN_VAR_DEF
7807 $last_var_value .= ' '
7808 unless $last_var_value =~ /\s$/;
7809 $last_var_value .= $_;
7811 if (!/\\$/)
7813 append_comments ($cond || 'TRUE',
7814 $last_var_name, $spacing, $comment);
7815 $comment = $spacing = '';
7816 macro_define ($last_var_name, VAR_MAKEFILE,
7817 $last_var_type, $cond,
7818 $last_var_value, $here)
7819 if $cond ne 'FALSE';
7820 push (@var_list, $last_var_name);
7825 elsif (/$IF_PATTERN/o)
7827 $cond = cond_stack_if ($1, $2, $here);
7829 elsif (/$ELSE_PATTERN/o)
7831 $cond = cond_stack_else ($1, $2, $here);
7833 elsif (/$ENDIF_PATTERN/o)
7835 $cond = cond_stack_endif ($1, $2, $here);
7838 elsif (/$RULE_PATTERN/o)
7840 # Found a rule.
7841 $prev_state = IN_RULE_DEF;
7843 # For now we have to output all definitions of user rules
7844 # and can't diagnose duplicates (see the comment in
7845 # rule_define). So we go on and ignore the return value.
7846 rule_define ($1, $amfile, TARGET_USER, $cond || 'TRUE', $here);
7848 check_variable_expansions ($_, $here);
7850 $output_trailer .= $comment . $spacing;
7851 $output_trailer .= &make_condition (@cond_stack);
7852 $output_trailer .= $_;
7853 $comment = $spacing = '';
7855 elsif (/$ASSIGNMENT_PATTERN/o)
7857 # Found a macro definition.
7858 $prev_state = IN_VAR_DEF;
7859 $last_var_name = $1;
7860 $last_var_type = $2;
7861 $last_var_value = $3;
7862 if ($3 ne '' && substr ($3, -1) eq "\\")
7864 # We preserve the `\' because otherwise the long lines
7865 # that are generated will be truncated by broken
7866 # `sed's.
7867 $last_var_value = $3 . "\n";
7870 if (!/\\$/)
7872 # Accumulating variables must not be output.
7873 append_comments ($cond || 'TRUE',
7874 $last_var_name, $spacing, $comment);
7875 $comment = $spacing = '';
7877 macro_define ($last_var_name, VAR_MAKEFILE,
7878 $last_var_type, $cond,
7879 $last_var_value, $here)
7880 if $cond ne 'FALSE';
7881 push (@var_list, $last_var_name);
7884 elsif (/$INCLUDE_PATTERN/o)
7886 my $path = $1;
7888 if ($path =~ s/^\$\(top_srcdir\)\///)
7890 push (@include_stack, "\$\(top_srcdir\)/$path");
7891 # Distribute any included file.
7893 # Always use the $(top_srcdir) prefix in DIST_COMMON,
7894 # otherwise OSF make will implicitely copy the included
7895 # file in the build tree during `make distdir' to satisfy
7896 # the dependency.
7897 # (subdircond2.test and subdircond3.test will fail.)
7898 push_dist_common ("\$\(top_srcdir\)/$path");
7900 else
7902 $path =~ s/\$\(srcdir\)\///;
7903 push (@include_stack, "\$\(srcdir\)/$path");
7904 # Always use the $(srcdir) prefix in DIST_COMMON,
7905 # otherwise OSF make will implicitely copy the included
7906 # file in the build tree during `make distdir' to satisfy
7907 # the dependency.
7908 # (subdircond2.test and subdircond3.test will fail.)
7909 push_dist_common ("\$\(srcdir\)/$path");
7910 $path = $relative_dir . "/" . $path;
7912 &read_am_file ($path);
7914 else
7916 # This isn't an error; it is probably a continued rule.
7917 # In fact, this is what we assume.
7918 $prev_state = IN_RULE_DEF;
7919 check_variable_expansions ($_, $here);
7920 $output_trailer .= $comment . $spacing;
7921 $output_trailer .= &make_condition (@cond_stack);
7922 $output_trailer .= $_;
7923 $comment = $spacing = '';
7924 err $here, "`#' comment at start of rule is unportable"
7925 if $_ =~ /^\t\s*\#/;
7928 $saw_bk = $new_saw_bk;
7929 $_ = $am_file->getline;
7932 $output_trailer .= $comment;
7934 err_am (@cond_stack ? "unterminated conditionals: @cond_stack"
7935 : "too many conditionals closed in include file")
7936 if "@saved_cond_stack" ne "@cond_stack";
7940 # define_standard_variables ()
7941 # ----------------------------
7942 # A helper for read_main_am_file which initializes configure variables
7943 # and variables from header-vars.am.
7944 sub define_standard_variables
7946 my $saved_output_vars = $output_vars;
7947 my ($comments, undef, $rules) =
7948 file_contents_internal (1, "$libdir/am/header-vars.am");
7950 # This will output the definitions in $output_vars, which we don't
7951 # want...
7952 foreach my $var (sort keys %configure_vars)
7954 &define_configure_variable ($var);
7955 push (@var_list, $var);
7958 # ... hence, we restore $output_vars.
7959 $output_vars = $saved_output_vars . $comments . $rules;
7962 # Read main am file.
7963 sub read_main_am_file
7965 my ($amfile) = @_;
7967 # This supports the strange variable tricks we are about to play.
7968 prog_error (macros_dump () . "variable defined before read_main_am_file")
7969 if (scalar keys %var_value > 0);
7971 # Generate copyright header for generated Makefile.in.
7972 # We do discard the output of predefined variables, handled below.
7973 $output_vars = ("# $in_file_name generated by automake "
7974 . $VERSION . " from $am_file_name.\n");
7975 $output_vars .= '# ' . subst ('configure_input') . "\n";
7976 $output_vars .= $gen_copyright;
7978 # We want to predefine as many variables as possible. This lets
7979 # the user set them with `+=' in Makefile.am. However, we don't
7980 # want these initial definitions to end up in the output quite
7981 # yet. So we just load them, but output them later.
7982 &define_standard_variables;
7984 # Read user file, which might override some of our values.
7985 &read_am_file ($amfile);
7987 # Output all the Automake variables. If the user changed one,
7988 # then it is now marked as VAR_CONFIGURE or VAR_MAKEFILE.
7989 foreach my $var (uniq @var_list)
7991 # Some variables, like AMDEPBACKSLASH are in @var_list
7992 # but don't have a owner. This is good, because we don't want
7993 # to output them.
7994 foreach my $cond (keys %{$var_owner{$var}})
7996 variable_output ($var, $cond)
7997 if $var_owner{$var}{$cond} == VAR_AUTOMAKE;
8001 # Now dump the user variables that were defined. We do it in the same
8002 # order in which they were defined (skipping duplicates).
8003 foreach my $var (uniq @var_list)
8005 foreach my $cond (keys %{$var_owner{$var}})
8007 variable_output ($var, $cond)
8008 if $var_owner{$var}{$cond} != VAR_AUTOMAKE;
8013 ################################################################
8015 # $FLATTENED
8016 # &flatten ($STRING)
8017 # ------------------
8018 # Flatten the $STRING and return the result.
8019 sub flatten
8021 $_ = shift;
8023 s/\\\n//somg;
8024 s/\s+/ /g;
8025 s/^ //;
8026 s/ $//;
8028 return $_;
8032 # @PARAGRAPHS
8033 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
8034 # ------------------------------------------
8035 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
8036 # paragraphs.
8037 sub make_paragraphs ($%)
8039 my ($file, %transform) = @_;
8041 # Complete %transform with global options and make it a Perl
8042 # $command.
8043 my $command =
8044 "s/$IGNORE_PATTERN//gm;"
8045 . transform (%transform,
8047 'CYGNUS' => $cygnus_mode,
8048 'MAINTAINER-MODE'
8049 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
8051 'SHAR' => $options{'dist-shar'} || 0,
8052 'BZIP2' => $options{'dist-bzip2'} || 0,
8053 'ZIP' => $options{'dist-zip'} || 0,
8054 'COMPRESS' => $options{'dist-tarZ'} || 0,
8056 'INSTALL-INFO' => !$options{'no-installinfo'},
8057 'INSTALL-MAN' => !$options{'no-installman'},
8058 'CK-NEWS' => $options{'check-news'} || 0,
8060 'SUBDIRS' => variable_defined ('SUBDIRS'),
8061 'TOPDIR' => backname ($relative_dir),
8062 'TOPDIR_P' => $relative_dir eq '.',
8063 'CONFIGURE-AC' => $configure_ac,
8065 'BUILD' => $seen_canonical == AC_CANONICAL_SYSTEM,
8066 'HOST' => $seen_canonical,
8067 'TARGET' => $seen_canonical == AC_CANONICAL_SYSTEM,
8069 'LIBTOOL' => variable_defined ('LIBTOOL'))
8070 # We don't need more than two consecutive new-lines.
8071 . 's/\n{3,}/\n\n/g';
8073 # Swallow the file and apply the COMMAND.
8074 my $fc_file = new Automake::XFile "< $file";
8075 # Looks stupid?
8076 verb "reading $file";
8077 my $saved_dollar_slash = $/;
8078 undef $/;
8079 $_ = $fc_file->getline;
8080 $/ = $saved_dollar_slash;
8081 eval $command;
8082 $fc_file->close;
8083 my $content = $_;
8085 # Split at unescaped new lines.
8086 my @lines = split (/(?<!\\)\n/, $content);
8087 my @res;
8089 while (defined ($_ = shift @lines))
8091 my $paragraph = "$_";
8092 # If we are a rule, eat as long as we start with a tab.
8093 if (/$RULE_PATTERN/smo)
8095 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
8097 $paragraph .= "\n$_";
8099 unshift (@lines, $_);
8102 # If we are a comments, eat as much comments as you can.
8103 elsif (/$COMMENT_PATTERN/smo)
8105 while (defined ($_ = shift @lines)
8106 && $_ =~ /$COMMENT_PATTERN/smo)
8108 $paragraph .= "\n$_";
8110 unshift (@lines, $_);
8113 push @res, $paragraph;
8114 $paragraph = '';
8117 return @res;
8122 # ($COMMENT, $VARIABLES, $RULES)
8123 # &file_contents_internal ($IS_AM, $FILE, [%TRANSFORM])
8124 # -----------------------------------------------------
8125 # Return contents of a file from $libdir/am, automatically skipping
8126 # macros or rules which are already known. $IS_AM iff the caller is
8127 # reading an Automake file (as opposed to the user's Makefile.am).
8128 sub file_contents_internal ($$%)
8130 my ($is_am, $file, %transform) = @_;
8132 my $result_vars = '';
8133 my $result_rules = '';
8134 my $comment = '';
8135 my $spacing = '';
8137 # The following flags are used to track rules spanning across
8138 # multiple paragraphs.
8139 my $is_rule = 0; # 1 if we are processing a rule.
8140 my $discard_rule = 0; # 1 if the current rule should not be output.
8142 # We save the conditional stack on entry, and then check to make
8143 # sure it is the same on exit. This lets us conditonally include
8144 # other files.
8145 my @saved_cond_stack = @cond_stack;
8146 my $cond = conditional_string (@cond_stack);
8148 foreach (make_paragraphs ($file, %transform))
8150 # Sanity checks.
8151 err $file, "blank line following trailing backslash:\n$_"
8152 if /\\$/;
8153 err $file, "comment following trailing backslash:\n$_"
8154 if /\\#/;
8156 if (/^$/)
8158 $is_rule = 0;
8159 # Stick empty line before the incoming macro or rule.
8160 $spacing = "\n";
8162 elsif (/$COMMENT_PATTERN/mso)
8164 $is_rule = 0;
8165 # Stick comments before the incoming macro or rule.
8166 $comment = "$_\n";
8169 # Handle inclusion of other files.
8170 elsif (/$INCLUDE_PATTERN/o)
8172 if ($cond ne 'FALSE')
8174 my $file = ($is_am ? "$libdir/am/" : '') . $1;
8175 # N-ary `.=' fails.
8176 my ($com, $vars, $rules)
8177 = file_contents_internal ($is_am, $file, %transform);
8178 $comment .= $com;
8179 $result_vars .= $vars;
8180 $result_rules .= $rules;
8184 # Handling the conditionals.
8185 elsif (/$IF_PATTERN/o)
8187 $cond = cond_stack_if ($1, $2, $file);
8189 elsif (/$ELSE_PATTERN/o)
8191 $cond = cond_stack_else ($1, $2, $file);
8193 elsif (/$ENDIF_PATTERN/o)
8195 $cond = cond_stack_endif ($1, $2, $file);
8198 # Handling rules.
8199 elsif (/$RULE_PATTERN/mso)
8201 $is_rule = 1;
8202 $discard_rule = 0;
8203 # Separate relationship from optional actions: the first
8204 # `new-line tab" not preceded by backslash (continuation
8205 # line).
8206 my $paragraph = $_;
8207 /^(.*?)(?:(?<!\\)\n(\t.*))?$/s;
8208 my ($relationship, $actions) = ($1, $2 || '');
8210 # Separate targets from dependencies: the first colon.
8211 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
8212 my ($targets, $dependencies) = ($1, $2);
8213 # Remove the escaped new lines.
8214 # I don't know why, but I have to use a tmp $flat_deps.
8215 my $flat_deps = &flatten ($dependencies);
8216 my @deps = split (' ', $flat_deps);
8218 foreach (split (' ' , $targets))
8220 # FIXME: 1. We are not robust to people defining several targets
8221 # at once, only some of them being in %dependencies. The
8222 # actions from the targets in %dependencies are usually generated
8223 # from the content of %actions, but if some targets in $targets
8224 # are not in %dependencies the ELSE branch will output
8225 # a rule for all $targets (i.e. the targets which are both
8226 # in %dependencies and $targets will have two rules).
8228 # FIXME: 2. The logic here is not able to output a
8229 # multi-paragraph rule several time (e.g. for each conditional
8230 # it is defined for) because it only knows the first paragraph.
8232 # FIXME: 3. We are not robust to people defining a subset
8233 # of a previously defined "multiple-target" rule. E.g.
8234 # `foo:' after `foo bar:'.
8236 # Output only if not in FALSE.
8237 if (defined $dependencies{$_} && $cond ne 'FALSE')
8239 &depend ($_, @deps);
8240 $actions{$_} .= $actions;
8242 else
8244 # Free-lance dependency. Output the rule for all the
8245 # targets instead of one by one.
8246 my @undefined_conds =
8247 rule_define ($targets, $file,
8248 $is_am ? TARGET_AUTOMAKE : TARGET_USER,
8249 $cond || 'TRUE', $file);
8250 for my $undefined_cond (@undefined_conds)
8252 my $condparagraph = $paragraph;
8253 $condparagraph =~ s/^/$undefined_cond/gm;
8254 $result_rules .= "$spacing$comment$condparagraph\n";
8256 if (scalar @undefined_conds == 0)
8258 # Remember to discard next paragraphs
8259 # if they belong to this rule.
8260 # (but see also FIXME: #2 above.)
8261 $discard_rule = 1;
8263 $comment = $spacing = '';
8264 last;
8269 elsif (/$ASSIGNMENT_PATTERN/mso)
8271 my ($var, $type, $val) = ($1, $2, $3);
8272 err $file, "variable `$var' with trailing backslash"
8273 if /\\$/;
8275 $is_rule = 0;
8277 # Accumulating variables must not be output.
8278 append_comments ($cond || 'TRUE', $var, $spacing, $comment);
8279 macro_define ($var, $is_am ? VAR_AUTOMAKE : VAR_MAKEFILE,
8280 $type, $cond, $val, $file)
8281 if $cond ne 'FALSE';
8282 push (@var_list, $var);
8284 # If the user has set some variables we were in charge
8285 # of (which is detected by the first reading of
8286 # `header-vars.am'), we must not output them.
8287 $result_vars .= "$spacing$comment$_\n"
8288 if ($cond ne 'FALSE' && $type ne '+'
8289 && exists $var_owner{$var}{$cond || 'TRUE'}
8290 && $var_owner{$var}{$cond || 'TRUE'} == VAR_AUTOMAKE);
8292 $comment = $spacing = '';
8294 else
8296 # This isn't an error; it is probably some tokens which
8297 # configure is supposed to replace, such as `@SET-MAKE@',
8298 # or some part of a rule cut by an if/endif.
8299 if ($cond ne 'FALSE' && ! ($is_rule && $discard_rule))
8301 s/^/make_condition (@cond_stack)/gme;
8302 $result_rules .= "$spacing$comment$_\n";
8304 $comment = $spacing = '';
8308 err_am (@cond_stack ?
8309 "unterminated conditionals: @cond_stack" :
8310 "too many conditionals closed in include file")
8311 if "@saved_cond_stack" ne "@cond_stack";
8313 return ($comment, $result_vars, $result_rules);
8317 # $CONTENTS
8318 # &file_contents ($BASENAME, [%TRANSFORM])
8319 # ----------------------------------------
8320 # Return contents of a file from $libdir/am, automatically skipping
8321 # macros or rules which are already known.
8322 sub file_contents ($%)
8324 my ($basename, %transform) = @_;
8325 my ($comments, $variables, $rules) =
8326 file_contents_internal (1, "$libdir/am/$basename.am", %transform);
8327 return "$comments$variables$rules";
8331 # $REGEXP
8332 # &transform (%PAIRS)
8333 # -------------------
8334 # Foreach ($TOKEN, $VAL) in %PAIRS produce a replacement expression suitable
8335 # for file_contents which:
8336 # - replaces %$TOKEN% with $VAL,
8337 # - enables/disables ?$TOKEN? and ?!$TOKEN?,
8338 # - replaces %?$TOKEN% with TRUE or FALSE.
8339 sub transform (%)
8341 my (%pairs) = @_;
8342 my $result = '';
8344 while (my ($token, $val) = each %pairs)
8346 $result .= "s/\Q%$token%\E/\Q$val\E/gm;";
8347 if ($val)
8349 $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
8350 $result .= "s/\Q%?$token%\E/TRUE/gm;";
8352 else
8354 $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
8355 $result .= "s/\Q%?$token%\E/FALSE/gm;";
8359 return $result;
8363 # &append_exeext ($MACRO)
8364 # -----------------------
8365 # Macro is an Automake magic macro which primary is PROGRAMS, e.g.
8366 # bin_PROGRAMS. Make sure these programs have $(EXEEXT) appended.
8367 sub append_exeext ($)
8369 my ($macro) = @_;
8371 prog_error "append_exeext ($macro)"
8372 unless $macro =~ /_PROGRAMS$/;
8374 my @conds = variable_conditions_recursive ($macro);
8376 my @condvals;
8377 foreach my $cond (@conds)
8379 my @one_binlist = ();
8380 my @condval = variable_value_as_list_recursive ($macro, $cond);
8381 foreach my $rcurs (@condval)
8383 # Skip autoconf substs. Also skip if the user
8384 # already applied $(EXEEXT).
8385 if ($rcurs =~ /^\@.*\@$/ || $rcurs =~ /\$\(EXEEXT\)$/)
8387 push (@one_binlist, $rcurs);
8389 else
8391 push (@one_binlist, $rcurs . '$(EXEEXT)');
8395 push (@condvals, $cond);
8396 push (@condvals, "@one_binlist");
8399 macro_delete ($macro);
8400 while (@condvals)
8402 my $cond = shift (@condvals);
8403 my @val = split (' ', shift (@condvals));
8404 define_pretty_variable ($macro, $cond, @val);
8409 # @PREFIX
8410 # &am_primary_prefixes ($PRIMARY, $CAN_DIST, @PREFIXES)
8411 # -----------------------------------------------------
8412 # Find all variable prefixes that are used for install directories. A
8413 # prefix `zar' qualifies iff:
8415 # * `zardir' is a variable.
8416 # * `zar_PRIMARY' is a variable.
8418 # As a side effect, it looks for misspellings. It is an error to have
8419 # a variable ending in a "reserved" suffix whose prefix is unknown, eg
8420 # "bni_PROGRAMS". However, unusual prefixes are allowed if a variable
8421 # of the same name (with "dir" appended) exists. For instance, if the
8422 # variable "zardir" is defined, then "zar_PROGRAMS" becomes valid.
8423 # This is to provide a little extra flexibility in those cases which
8424 # need it.
8425 sub am_primary_prefixes ($$@)
8427 my ($primary, $can_dist, @prefixes) = @_;
8429 local $_;
8430 my %valid = map { $_ => 0 } @prefixes;
8431 $valid{'EXTRA'} = 0;
8432 foreach my $varname (keys %var_value)
8434 # Automake is allowed to define variables that look like primaries
8435 # but which aren't. E.g. INSTALL_sh_DATA.
8436 # Autoconf can also define variables like INSTALL_DATA, so
8437 # ignore all configure variables (at least those which are not
8438 # redefined in Makefile.am).
8439 # FIXME: We should make sure that these variables are not
8440 # conditionally defined (or else adjust the condition below).
8441 next
8442 if (exists $var_owner{$varname}
8443 && exists $var_owner{$varname}{'TRUE'}
8444 && $var_owner{$varname}{'TRUE'} != VAR_MAKEFILE);
8446 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
8448 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
8449 if ($dist ne '' && ! $can_dist)
8451 err_var ($varname,
8452 "invalid variable `$varname': `dist' is forbidden");
8454 # Standard directories must be explicitely allowed.
8455 elsif (! defined $valid{$X} && exists $standard_prefix{$X})
8457 err_var ($varname,
8458 "`${X}dir' is not a legitimate directory " .
8459 "for `$primary'");
8461 # A not explicitely valid directory is allowed if Xdir is defined.
8462 elsif (! defined $valid{$X} &&
8463 require_variables_for_macro ($varname, "`$varname' is used",
8464 "${X}dir"))
8466 # Nothing to do. Any error message has been output
8467 # by require_variables_for_macro.
8469 else
8471 # Ensure all extended prefixes are actually used.
8472 $valid{"$base$dist$X"} = 1;
8477 # Return only those which are actually defined.
8478 return sort grep { variable_defined ($_ . '_' . $primary) } keys %valid;
8482 # Handle `where_HOW' variable magic. Does all lookups, generates
8483 # install code, and possibly generates code to define the primary
8484 # variable. The first argument is the name of the .am file to munge,
8485 # the second argument is the primary variable (eg HEADERS), and all
8486 # subsequent arguments are possible installation locations. Returns
8487 # list of all values of all _HOW targets.
8489 # FIXME: this should be rewritten to be cleaner. It should be broken
8490 # up into multiple functions.
8492 # Usage is: am_install_var (OPTION..., file, HOW, where...)
8493 sub am_install_var
8495 my (@args) = @_;
8497 my $do_require = 1;
8498 my $can_dist = 0;
8499 my $default_dist = 0;
8500 while (@args)
8502 if ($args[0] eq '-noextra')
8504 $do_require = 0;
8506 elsif ($args[0] eq '-candist')
8508 $can_dist = 1;
8510 elsif ($args[0] eq '-defaultdist')
8512 $default_dist = 1;
8513 $can_dist = 1;
8515 elsif ($args[0] !~ /^-/)
8517 last;
8519 shift (@args);
8522 my ($file, $primary, @prefix) = @args;
8524 # Now that configure substitutions are allowed in where_HOW
8525 # variables, it is an error to actually define the primary. We
8526 # allow `JAVA', as it is customarily used to mean the Java
8527 # interpreter. This is but one of several Java hacks. Similarly,
8528 # `PYTHON' is customarily used to mean the Python interpreter.
8529 reject_var $primary, "`$primary' is an anachronism"
8530 unless $primary eq 'JAVA' || $primary eq 'PYTHON';
8532 # Get the prefixes which are valid and actually used.
8533 @prefix = am_primary_prefixes ($primary, $can_dist, @prefix);
8535 # If a primary includes a configure substitution, then the EXTRA_
8536 # form is required. Otherwise we can't properly do our job.
8537 my $require_extra;
8539 my @used = ();
8540 my @result = ();
8542 # True if the iteration is the first one. Used for instance to
8543 # output parts of the associated file only once.
8544 my $first = 1;
8545 foreach my $X (@prefix)
8547 my $nodir_name = $X;
8548 my $one_name = $X . '_' . $primary;
8550 my $strip_subdir = 1;
8551 # If subdir prefix should be preserved, do so.
8552 if ($nodir_name =~ /^nobase_/)
8554 $strip_subdir = 0;
8555 $nodir_name =~ s/^nobase_//;
8558 # If files should be distributed, do so.
8559 my $dist_p = 0;
8560 if ($can_dist)
8562 $dist_p = (($default_dist && $nodir_name !~ /^nodist_/)
8563 || (! $default_dist && $nodir_name =~ /^dist_/));
8564 $nodir_name =~ s/^(dist|nodist)_//;
8567 # Append actual contents of where_PRIMARY variable to
8568 # result.
8569 foreach my $rcurs (&variable_value_as_list_recursive ($one_name, 'all'))
8571 # Skip configure substitutions. Possibly bogus.
8572 if ($rcurs =~ /^\@.*\@$/)
8574 if ($nodir_name eq 'EXTRA')
8576 err_var ($one_name,
8577 "`$one_name' contains configure substitution, "
8578 . "but shouldn't");
8580 # Check here to make sure variables defined in
8581 # configure.ac do not imply that EXTRA_PRIMARY
8582 # must be defined.
8583 elsif (! defined $configure_vars{$one_name})
8585 $require_extra = $one_name
8586 if $do_require;
8589 next;
8592 push (@result, $rcurs);
8594 # A blatant hack: we rewrite each _PROGRAMS primary to include
8595 # EXEEXT.
8596 append_exeext ($one_name)
8597 if $primary eq 'PROGRAMS';
8598 # "EXTRA" shouldn't be used when generating clean targets,
8599 # all, or install targets. We used to warn if EXTRA_FOO was
8600 # defined uselessly, but this was annoying.
8601 next
8602 if $nodir_name eq 'EXTRA';
8604 if ($nodir_name eq 'check')
8606 push (@check, '$(' . $one_name . ')');
8608 else
8610 push (@used, '$(' . $one_name . ')');
8613 # Is this to be installed?
8614 my $install_p = $nodir_name ne 'noinst' && $nodir_name ne 'check';
8616 # If so, with install-exec? (or install-data?).
8617 my $exec_p = ($nodir_name =~ /$EXEC_DIR_PATTERN/o);
8619 my $check_options_p = $install_p
8620 && defined $options{'std-options'};
8622 # Singular form of $PRIMARY.
8623 (my $one_primary = $primary) =~ s/S$//;
8624 $output_rules .= &file_contents ($file,
8625 ('FIRST' => $first,
8627 'PRIMARY' => $primary,
8628 'ONE_PRIMARY' => $one_primary,
8629 'DIR' => $X,
8630 'NDIR' => $nodir_name,
8631 'BASE' => $strip_subdir,
8633 'EXEC' => $exec_p,
8634 'INSTALL' => $install_p,
8635 'DIST' => $dist_p,
8636 'CK-OPTS' => $check_options_p));
8638 $first = 0;
8641 # The JAVA variable is used as the name of the Java interpreter.
8642 # The PYTHON variable is used as the name of the Python interpreter.
8643 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
8645 # Define it.
8646 define_pretty_variable ($primary, '', @used);
8647 $output_vars .= "\n";
8650 err_var ($require_extra,
8651 "`$require_extra' contains configure substitution,\n"
8652 . "but `EXTRA_$primary' not defined")
8653 if ($require_extra && ! variable_defined ('EXTRA_' . $primary));
8655 # Push here because PRIMARY might be configure time determined.
8656 push (@all, '$(' . $primary . ')')
8657 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
8659 # Make the result unique. This lets the user use conditionals in
8660 # a natural way, but still lets us program lazily -- we don't have
8661 # to worry about handling a particular object more than once.
8662 return uniq (sort @result);
8666 ################################################################
8668 # Each key in this hash is the name of a directory holding a
8669 # Makefile.in. These variables are local to `is_make_dir'.
8670 my %make_dirs = ();
8671 my $make_dirs_set = 0;
8673 sub is_make_dir
8675 my ($dir) = @_;
8676 if (! $make_dirs_set)
8678 foreach my $iter (@configure_input_files)
8680 $make_dirs{dirname ($iter)} = 1;
8682 # We also want to notice Makefile.in's.
8683 foreach my $iter (@other_input_files)
8685 if ($iter =~ /Makefile\.in$/)
8687 $make_dirs{dirname ($iter)} = 1;
8690 $make_dirs_set = 1;
8692 return defined $make_dirs{$dir};
8695 ################################################################
8697 # This variable is local to the "require file" set of functions.
8698 my @require_file_paths = ();
8701 # &maybe_push_required_file ($DIR, $FILE, $FULLFILE)
8702 # --------------------------------------------------
8703 # See if we want to push this file onto dist_common. This function
8704 # encodes the rules for deciding when to do so.
8705 sub maybe_push_required_file
8707 my ($dir, $file, $fullfile) = @_;
8709 if ($dir eq $relative_dir)
8711 push_dist_common ($file);
8712 return 1;
8714 elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
8716 # If we are doing the topmost directory, and the file is in a
8717 # subdir which does not have a Makefile, then we distribute it
8718 # here.
8719 push_dist_common ($fullfile);
8720 return 1;
8722 return 0;
8726 # &require_file_internal ($WHERE, $MYSTRICT, @FILES)
8727 # --------------------------------------------------
8728 # Verify that the file must exist in the current directory.
8729 # $MYSTRICT is the strictness level at which this file becomes required.
8731 # Must set require_file_paths before calling this function.
8732 # require_file_paths is set to hold a single directory (the one in
8733 # which the first file was found) before return.
8734 sub require_file_internal ($$@)
8736 my ($where, $mystrict, @files) = @_;
8738 foreach my $file (@files)
8740 my $fullfile;
8741 my $errdir;
8742 my $errfile;
8743 my $save_dir;
8745 my $found_it = 0;
8746 my $dangling_sym = 0;
8747 foreach my $dir (@require_file_paths)
8749 $fullfile = $dir . "/" . $file;
8750 $errdir = $dir unless $errdir;
8752 # Use different name for "error filename". Otherwise on
8753 # an error the bad file will be reported as eg
8754 # `../../install-sh' when using the default
8755 # config_aux_path.
8756 $errfile = $errdir . '/' . $file;
8758 if (-l $fullfile && ! -f $fullfile)
8760 $dangling_sym = 1;
8761 last;
8763 elsif (-f $fullfile)
8765 $found_it = 1;
8766 maybe_push_required_file ($dir, $file, $fullfile);
8767 $save_dir = $dir;
8768 last;
8772 # `--force-missing' only has an effect if `--add-missing' is
8773 # specified.
8774 if ($found_it && (! $add_missing || ! $force_missing))
8776 # Prune the path list.
8777 @require_file_paths = $save_dir;
8779 else
8781 # If we've already looked for it, we're done. You might
8782 # wonder why we don't do this before searching for the
8783 # file. If we do that, then something like
8784 # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
8785 # DIST_COMMON.
8786 if (! $found_it)
8788 next if defined $require_file_found{$fullfile};
8789 $require_file_found{$fullfile} = 1;
8792 if ($strictness >= $mystrict)
8794 if ($dangling_sym && $add_missing)
8796 unlink ($fullfile);
8799 my $trailer = '';
8800 my $suppress = 0;
8802 # Only install missing files according to our desired
8803 # strictness level.
8804 my $message = "required file `$errfile' not found";
8805 if ($add_missing)
8807 $suppress = 1;
8809 if (-f ("$libdir/$file"))
8811 # Install the missing file. Symlink if we
8812 # can, copy if we must. Note: delete the file
8813 # first, in case it is a dangling symlink.
8814 $message = "installing `$errfile'";
8815 # Windows Perl will hang if we try to delete a
8816 # file that doesn't exist.
8817 unlink ($errfile) if -f $errfile;
8818 if ($symlink_exists && ! $copy_missing)
8820 if (! symlink ("$libdir/$file", $errfile))
8822 $suppress = 0;
8823 $trailer = "; error while making link: $!";
8826 elsif (system ('cp', "$libdir/$file", $errfile))
8828 $suppress = 0;
8829 $trailer = "\n error while copying";
8833 if (! maybe_push_required_file (dirname ($errfile),
8834 $file, $errfile))
8836 if (! $found_it)
8838 # We have added the file but could not push it
8839 # into DIST_COMMON (probably because this is
8840 # an auxiliary file and we are not processing
8841 # the top level Makefile). This is unfortunate,
8842 # since it means we are using a file which is not
8843 # distributed!
8845 # Get Automake to be run again: on the second
8846 # run the file will be found, and pushed into
8847 # the toplevel DIST_COMMON automatically.
8848 $automake_needs_to_reprocess_all_files = 1;
8852 # Prune the path list.
8853 @require_file_paths = &dirname ($errfile);
8856 # If --force-missing was specified, and we have
8857 # actually found the file, then do nothing.
8858 next
8859 if $found_it && $force_missing;
8861 msg ($suppress ? 'note' : 'error', $where, "$message$trailer");
8867 # &require_file ($WHERE, $MYSTRICT, @FILES)
8868 # -----------------------------------------
8869 sub require_file ($$@)
8871 my ($where, $mystrict, @files) = @_;
8872 @require_file_paths = $relative_dir;
8873 require_file_internal ($where, $mystrict, @files);
8876 # &require_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
8877 # -----------------------------------------------------------
8878 sub require_file_with_macro ($$$@)
8880 my ($cond, $macro, $mystrict, @files) = @_;
8881 require_file ($var_location{$macro}{$cond}, $mystrict, @files);
8885 # &require_conf_file ($WHERE, $MYSTRICT, @FILES)
8886 # ----------------------------------------------
8887 # Looks in configuration path, as specified by AC_CONFIG_AUX_DIR.
8888 sub require_conf_file ($$@)
8890 my ($where, $mystrict, @files) = @_;
8891 @require_file_paths = @config_aux_path;
8892 require_file_internal ($where, $mystrict, @files);
8893 my $dir = $require_file_paths[0];
8894 @config_aux_path = @require_file_paths;
8895 # Avoid unsightly '/.'s.
8896 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
8900 # &require_conf_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
8901 # ----------------------------------------------------------------
8902 sub require_conf_file_with_macro ($$$@)
8904 my ($cond, $macro, $mystrict, @files) = @_;
8905 require_conf_file ($var_location{$macro}{$cond}, $mystrict, @files);
8908 ################################################################
8910 # &require_build_directory ($DIRECTORY)
8911 # ------------------------------------
8912 # Emit rules to create $DIRECTORY if needed, and return
8913 # the file that any target requiring this directory should be made
8914 # dependent upon.
8915 sub require_build_directory ($)
8917 my $directory = shift;
8918 my $dirstamp = "$directory/.dirstamp";
8920 # Don't emit the rule twice.
8921 if (! defined $directory_map{$directory})
8923 $directory_map{$directory} = 1;
8925 # Directory must be removed by `make distclean'.
8926 $clean_files{$dirstamp} = DIST_CLEAN;
8928 $output_rules .= ("$dirstamp:\n"
8929 . "\t\@\$(mkinstalldirs) $directory\n"
8930 . "\t\@: > $dirstamp\n");
8933 return $dirstamp;
8936 # &require_build_directory_maybe ($FILE)
8937 # --------------------------------------
8938 # If $FILE lies in a subdirectory, emit a rule to create this
8939 # directory and return the file that $FILE should be made
8940 # dependent upon. Otherwise, just return the empty string.
8941 sub require_build_directory_maybe ($)
8943 my $file = shift;
8944 my $directory = dirname ($file);
8946 if ($directory ne '.')
8948 return require_build_directory ($directory);
8950 else
8952 return '';
8956 ################################################################
8958 # Push a list of files onto dist_common.
8959 sub push_dist_common
8961 prog_error "push_dist_common run after handle_dist"
8962 if $handle_dist_run;
8963 macro_define ('DIST_COMMON', VAR_AUTOMAKE, '+', '', "@_", '');
8967 # Set strictness.
8968 sub set_strictness
8970 $strictness_name = $_[0];
8972 # FIXME: 'portability' warnings are currently disabled by default.
8973 # Eventually we want to turn them on in GNU and GNITS modes, but
8974 # we don't do this yet in Automake 1.7 to help the 1.6/1.7 transition.
8976 # Indeed there would be only two ways to get rid of these new warnings:
8977 # 1. adjusting Makefile.am
8978 # This is not always easy (or wanted). Consider %-rules or
8979 # $(function args) variables.
8980 # 2. using -Wno-portability
8981 # This means there is no way to have the same Makefile.am
8982 # working both with Automake 1.6 and 1.7 (since 1.6 does not
8983 # understand -Wno-portability).
8985 # In Automake 1.8 (or whatever it is called) we can turn these
8986 # warnings on, since -Wno-portability will not be an issue for
8987 # the 1.7/1.8 transition.
8988 if ($strictness_name eq 'gnu')
8990 $strictness = GNU;
8991 setup_channel 'error-gnu', silent => 0;
8992 setup_channel 'error-gnu/warn', silent => 0, type => 'error';
8993 setup_channel 'error-gnits', silent => 1;
8994 # setup_channel 'portability', silent => 0;
8995 setup_channel 'gnu', silent => 0;
8997 elsif ($strictness_name eq 'gnits')
8999 $strictness = GNITS;
9000 setup_channel 'error-gnu', silent => 0;
9001 setup_channel 'error-gnu/warn', silent => 0, type => 'error';
9002 setup_channel 'error-gnits', silent => 0;
9003 # setup_channel 'portability', silent => 0;
9004 setup_channel 'gnu', silent => 0;
9006 elsif ($strictness_name eq 'foreign')
9008 $strictness = FOREIGN;
9009 setup_channel 'error-gnu', silent => 1;
9010 setup_channel 'error-gnu/warn', silent => 0, type => 'warning';
9011 setup_channel 'error-gnits', silent => 1;
9012 # setup_channel 'portability', silent => 1;
9013 setup_channel 'gnu', silent => 1;
9015 else
9017 prog_error "level `$strictness_name' not recognized\n";
9022 ################################################################
9024 # Glob something. Do this to avoid indentation screwups everywhere we
9025 # want to glob. Gross!
9026 sub my_glob
9028 my ($pat) = @_;
9029 return <${pat}>;
9032 ################################################################
9034 # INTEGER
9035 # require_variables ($WHERE, $REASON, $COND, @VARIABLES)
9036 # ------------------------------------------------------
9037 # Make sure that each supplied variable is defined in $COND.
9038 # Otherwise, issue a warning. If we know which macro can
9039 # define this variable, hint the user.
9040 # Return the number of undefined variables.
9041 sub require_variables ($$$@)
9043 my ($where, $reason, $cond, @vars) = @_;
9044 my $res = 0;
9045 $reason .= ' but ' unless $reason eq '';
9047 VARIABLE:
9048 foreach my $var (@vars)
9050 # Nothing to do if the variable exists. The $configure_vars test
9051 # needed for strange variables like AMDEPBACKSLASH or ANSI2KNR
9052 # that are AC_SUBST'ed but never macro_define'd.
9053 next VARIABLE
9054 if ((exists $var_value{$var} && exists $var_value{$var}{$cond})
9055 || exists $configure_vars{$var});
9057 my @undef_cond = variable_not_always_defined_in_cond $var, $cond;
9058 next VARIABLE
9059 unless @undef_cond;
9061 my $text = "$reason`$var' is undefined\n";
9062 if (@undef_cond && $undef_cond[0] ne 'TRUE')
9064 $text .= ("in the following conditions:\n "
9065 . join ("\n ", @undef_cond));
9068 ++$res;
9070 if (exists $am_macro_for_var{$var})
9072 $text .= "\nThe usual way to define `$var' is to add "
9073 . "`$am_macro_for_var{$var}'\nto `$configure_ac' and run "
9074 . "`aclocal' and `autoconf' again.";
9076 elsif (exists $ac_macro_for_var{$var})
9078 $text .= "\nThe usual way to define `$var' is to add "
9079 . "`$ac_macro_for_var{$var}'\nto `$configure_ac' and run "
9080 . "`autoconf' again.";
9083 err $where, $text, uniq_scope => US_GLOBAL;
9085 return $res;
9088 # INTEGER
9089 # require_variables_for_macro ($MACRO, $REASON, @VARIABLES)
9090 # ---------------------------------------------------------
9091 # Same as require_variables, but take a macro mame as first argument.
9092 sub require_variables_for_macro ($$@)
9094 my ($macro, $reason, @args) = @_;
9095 for my $cond (keys %{$var_value{$macro}})
9097 return require_variables ($var_location{$macro}{$cond}, $reason,
9098 $cond, @args);
9102 # Print usage information.
9103 sub usage ()
9105 print "Usage: $0 [OPTION] ... [Makefile]...
9107 Generate Makefile.in for configure from Makefile.am.
9109 Operation modes:
9110 --help print this help, then exit
9111 --version print version number, then exit
9112 -v, --verbose verbosely list files processed
9113 --no-force only update Makefile.in's that are out of date
9114 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
9116 Dependency tracking:
9117 -i, --ignore-deps disable dependency tracking code
9118 --include-deps enable dependency tracking code
9120 Flavors:
9121 --cygnus assume program is part of Cygnus-style tree
9122 --foreign set strictness to foreign
9123 --gnits set strictness to gnits
9124 --gnu set strictness to gnu
9126 Library files:
9127 -a, --add-missing add missing standard files to package
9128 --libdir=DIR directory storing library files
9129 -c, --copy with -a, copy missing files (default is symlink)
9130 -f, --force-missing force update of standard files
9132 Warning categories include:
9133 `gnu' GNU coding standards (default in gnu and gnits modes)
9134 `obsolete' obsolete features or constructions
9135 `portability' portability issues
9136 `syntax' dubious syntactic constructs (default)
9137 `unsupported' unsupported or incomplete features (default)
9138 `all' all the warnings
9139 `no-CATEGORY' turn off warnings in CATEGORY
9140 `none' turn off all the warnings
9141 `error' treat warnings as errors
9144 my ($last, @lcomm);
9145 $last = '';
9146 foreach my $iter (sort ((@common_files, @common_sometimes)))
9148 push (@lcomm, $iter) unless $iter eq $last;
9149 $last = $iter;
9152 my @four;
9153 print "\nFiles which are automatically distributed, if found:\n";
9154 format USAGE_FORMAT =
9155 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
9156 $four[0], $four[1], $four[2], $four[3]
9158 $~ = "USAGE_FORMAT";
9160 my $cols = 4;
9161 my $rows = int(@lcomm / $cols);
9162 my $rest = @lcomm % $cols;
9164 if ($rest)
9166 $rows++;
9168 else
9170 $rest = $cols;
9173 for (my $y = 0; $y < $rows; $y++)
9175 @four = ("", "", "", "");
9176 for (my $x = 0; $x < $cols; $x++)
9178 last if $y + 1 == $rows && $x == $rest;
9180 my $idx = (($x > $rest)
9181 ? ($rows * $rest + ($rows - 1) * ($x - $rest))
9182 : ($rows * $x));
9184 $idx += $y;
9185 $four[$x] = $lcomm[$idx];
9187 write;
9190 print "\nReport bugs to <bug-automake\@gnu.org>.\n";
9192 # --help always returns 0 per GNU standards.
9193 exit 0;
9197 # &version ()
9198 # -----------
9199 # Print version information
9200 sub version ()
9202 print <<EOF;
9203 automake (GNU $PACKAGE) $VERSION
9204 Written by Tom Tromey <tromey\@redhat.com>.
9206 Copyright 2002 Free Software Foundation, Inc.
9207 This is free software; see the source for copying conditions. There is NO
9208 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9210 # --version always returns 0 per GNU standards.
9211 exit 0;
9214 ### Setup "GNU" style for perl-mode and cperl-mode.
9215 ## Local Variables:
9216 ## perl-indent-level: 2
9217 ## perl-continued-statement-offset: 2
9218 ## perl-continued-brace-offset: 0
9219 ## perl-brace-offset: 0
9220 ## perl-brace-imaginary-offset: 0
9221 ## perl-label-offset: -2
9222 ## cperl-indent-level: 2
9223 ## cperl-brace-offset: 0
9224 ## cperl-continued-brace-offset: 0
9225 ## cperl-label-offset: -2
9226 ## cperl-extra-newline-before-brace: t
9227 ## cperl-merge-trailing-else: nil
9228 ## cperl-continued-statement-offset: 2
9229 ## End: