5 eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
8 # automake - create Makefile.in from Makefile.am
9 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
10 # 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free
11 # Software Foundation, Inc.
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2, or (at your option)
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
27 # Perl reimplementation by Tom Tromey <tromey@redhat.com>, and
28 # Alexandre Duret-Lutz <adl@gnu.org>.
34 my $perllibdir = $ENV{'perllibdir'} || '@datadir@/@PACKAGE@-@APIVERSION@';
35 unshift @INC, (split '@PATH_SEPARATOR@', $perllibdir);
37 # Override SHELL. This is required on DJGPP so that system() uses
38 # bash, not COMMAND.COM which doesn't quote arguments properly.
39 # Other systems aren't expected to use $SHELL when Automake
40 # runs, but it should be safe to drop the `if DJGPP' guard if
41 # it turns up other systems need the same thing. After all,
42 # if SHELL is used, ./configure's SHELL is always better than
43 # the user's SHELL (which may be something like tcsh).
44 $ENV{'SHELL'} = '@SHELL@' if exists $ENV{'DJDIR'};
48 struct (# Short name of the language (c, f77...).
50 # Nice name of the language (C, Fortran 77...).
53 # List of configure variables which must be defined.
56 # `pure' is `1' or `'. A `pure' language is one where, if
57 # all the files in a directory are of that language, then we
58 # do not require the C compiler or any code to call it.
63 # Name of the compiling variable (COMPILE).
65 # Content of the compiling variable.
67 # Flag to require compilation without linking (-c).
68 'compile_flag' => "\$",
70 # A subroutine to compute a list of possible extensions of
71 # the product given the input extensions.
72 # (defaults to a subroutine which returns ('.$(OBJEXT)', '.lo'))
73 'output_extensions' => "\$",
74 # A list of flag variables used in 'compile'.
78 # Any tag to pass to libtool while compiling.
79 'libtool_tag' => "\$",
81 # The file to use when generating rules for this language.
82 # The default is 'depend2'.
85 # Name of the linking variable (LINK).
87 # Content of the linking variable.
90 # Name of the compiler variable (CC).
93 # Name of the linker variable (LD).
95 # Content of the linker variable ($(CC)).
98 # Flag to specify the output file (-o).
99 'output_flag' => "\$",
102 # This is a subroutine which is called whenever we finally
103 # determine the context in which a source file will be
105 '_target_hook' => "\$",
107 # If TRUE, nodist_ sources will be compiled using specific rules
108 # (i.e. not inference rules). The default is FALSE.
109 'nodist_specific' => "\$");
115 if (defined $self->_finish)
117 &{$self->_finish} (@_);
121 sub target_hook ($$$$%)
124 if (defined $self->_target_hook)
126 &{$self->_target_hook} (@_);
133 use Automake::Config;
140 require Thread::Queue;
141 import Thread::Queue;
144 use Automake::General;
146 use Automake::Channels;
147 use Automake::ChannelDefs;
148 use Automake::Configure_ac;
149 use Automake::FileUtils;
150 use Automake::Location;
151 use Automake::Condition qw/TRUE FALSE/;
152 use Automake::DisjConditions;
153 use Automake::Options;
154 use Automake::Version;
155 use Automake::Variable;
156 use Automake::VarDef;
158 use Automake::RuleDef;
159 use Automake::Wrap 'makefile_wrap';
168 # Some regular expressions. One reason to put them here is that it
169 # makes indentation work better in Emacs.
171 # Writing singled-quoted-$-terminated regexes is a pain because
172 # perl-mode thinks of $' as the ${'} variable (instead of a $ followed
173 # by a closing quote. Letting perl-mode think the quote is not closed
174 # leads to all sort of misindentations. On the other hand, defining
175 # regexes as double-quoted strings is far less readable. So usually
178 # $REGEX = '^regex_value' . "\$";
180 my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
181 my $WHITE_PATTERN = '^\s*' . "\$";
182 my $COMMENT_PATTERN = '^#';
183 my $TARGET_PATTERN='[$a-zA-Z0-9_.@%][-.a-zA-Z0-9_(){}/$+@%]*';
184 # A rule has three parts: a list of targets, a list of dependencies,
185 # and optionally actions.
187 "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
189 # Only recognize leading spaces, not leading tabs. If we recognize
190 # leading tabs here then we need to make the reader smarter, because
191 # otherwise it will think rules like `foo=bar; \' are errors.
192 my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)' . "\$";
193 # This pattern recognizes a Gnits version id and sets $1 if the
194 # release is an alpha release. We also allow a suffix which can be
195 # used to extend the version number with a "fork" identifier.
196 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
198 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?' . "\$";
200 '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
202 '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
203 my $PATH_PATTERN = '(\w|[+/.-])+';
204 # This will pass through anything not of the prescribed form.
205 my $INCLUDE_PATTERN = ('^include\s+'
206 . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
207 . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
208 . '|([^/\$]' . $PATH_PATTERN . '))\s*(#.*)?' . "\$");
210 # Directories installed during 'install-exec' phase.
211 my $EXEC_DIR_PATTERN =
212 '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)' . "\$";
214 # Values for AC_CANONICAL_*
215 use constant AC_CANONICAL_BUILD => 1;
216 use constant AC_CANONICAL_HOST => 2;
217 use constant AC_CANONICAL_TARGET => 3;
219 # Values indicating when something should be cleaned.
220 use constant MOSTLY_CLEAN => 0;
221 use constant CLEAN => 1;
222 use constant DIST_CLEAN => 2;
223 use constant MAINTAINER_CLEAN => 3;
226 my @libtool_files = qw(ltmain.sh config.guess config.sub);
227 # ltconfig appears here for compatibility with old versions of libtool.
228 my @libtool_sometimes = qw(ltconfig ltcf-c.sh ltcf-cxx.sh ltcf-gcj.sh);
230 # Commonly found files we look for and automatically include in
233 (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
234 COPYING.LESSER ChangeLog INSTALL NEWS README THANKS TODO
235 ar-lib compile config.guess config.rpath
236 config.sub depcomp elisp-comp install-sh libversion.in mdate-sh
237 missing mkinstalldirs py-compile texinfo.tex ylwrap),
238 @libtool_files, @libtool_sometimes);
240 # Commonly used files we auto-include, but only sometimes. This list
241 # is used for the --help output only.
242 my @common_sometimes =
243 qw(aclocal.m4 acconfig.h config.h.top config.h.bot configure
244 configure.ac configure.in stamp-vti);
246 # Standard directories from the GNU Coding Standards, and additional
247 # pkg* directories from Automake. Stored in a hash for fast member check.
248 my %standard_prefix =
249 map { $_ => 1 } (qw(bin data dataroot doc dvi exec html include info
250 lib libexec lisp locale localstate man man1 man2
251 man3 man4 man5 man6 man7 man8 man9 oldinclude pdf
252 pkgdata pkginclude pkglib pkglibexec ps sbin
253 sharedstate sysconf));
255 # Copyright on generated Makefile.ins.
256 my $gen_copyright = "\
257 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
258 # 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
260 # This Makefile.in is free software; the Free Software Foundation
261 # gives unlimited permission to copy and/or distribute it,
262 # with or without modifications, as long as this notice is preserved.
264 # This program is distributed in the hope that it will be useful,
265 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
266 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
267 # PARTICULAR PURPOSE.
270 # These constants are returned by the lang_*_rewrite functions.
271 # LANG_SUBDIR means that the resulting object file should be in a
272 # subdir if the source file is. In this case the file name cannot
273 # have `..' components.
274 use constant LANG_IGNORE => 0;
275 use constant LANG_PROCESS => 1;
276 use constant LANG_SUBDIR => 2;
278 # These are used when keeping track of whether an object can be built
279 # by two different paths.
280 use constant COMPILE_LIBTOOL => 1;
281 use constant COMPILE_ORDINARY => 2;
283 # We can't always associate a location to a variable or a rule,
284 # when it's defined by Automake. We use INTERNAL in this case.
285 use constant INTERNAL => new Automake::Location;
287 # Serialization keys for message queues.
288 use constant QUEUE_MESSAGE => "msg";
289 use constant QUEUE_CONF_FILE => "conf file";
290 use constant QUEUE_LOCATION => "location";
291 use constant QUEUE_STRING => "string";
294 ## ---------------------------------- ##
295 ## Variables related to the options. ##
296 ## ---------------------------------- ##
298 # TRUE if we should always generate Makefile.in.
299 my $force_generation = 1;
301 # From the Perl manual.
302 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
304 # TRUE if missing standard files should be installed.
307 # TRUE if we should copy missing files; otherwise symlink if possible.
308 my $copy_missing = 0;
310 # TRUE if we should always update files that we know about.
311 my $force_missing = 0;
314 ## ---------------------------------------- ##
315 ## Variables filled during files scanning. ##
316 ## ---------------------------------------- ##
318 # Name of the configure.ac file.
321 # Files found by scanning configure.ac for LIBOBJS.
324 # Names used in AC_CONFIG_HEADER call.
325 my @config_headers = ();
327 # Names used in AC_CONFIG_LINKS call.
328 my @config_links = ();
330 # List of Makefile.am's to process, and their corresponding outputs.
331 my @input_files = ();
332 my %output_files = ();
334 # Complete list of Makefile.am's that exist.
335 my @configure_input_files = ();
337 # List of files in AC_CONFIG_FILES/AC_OUTPUT without Makefile.am's,
339 my @other_input_files = ();
340 # Where each AC_CONFIG_FILES/AC_OUTPUT/AC_CONFIG_LINK/AC_CONFIG_HEADER appears.
341 # The keys are the files created by these macros.
342 my %ac_config_files_location = ();
343 # The condition under which AC_CONFIG_FOOS appears.
344 my %ac_config_files_condition = ();
346 # Directory to search for configure-required files. This
347 # will be computed by &locate_aux_dir and can be set using
348 # AC_CONFIG_AUX_DIR in configure.ac.
349 # $CONFIG_AUX_DIR is the `raw' directory, valid only in the source-tree.
350 my $config_aux_dir = '';
351 my $config_aux_dir_set_in_configure_ac = 0;
352 # $AM_CONFIG_AUX_DIR is prefixed with $(top_srcdir), so it can be used
354 my $am_config_aux_dir = '';
356 # Directory to search for AC_LIBSOURCE files, as set by AC_CONFIG_LIBOBJ_DIR
358 my $config_libobj_dir = '';
360 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
361 my $seen_gettext = 0;
362 # Whether AM_GNU_GETTEXT([external]) is used.
363 my $seen_gettext_external = 0;
364 # Where AM_GNU_GETTEXT appears.
365 my $ac_gettext_location;
366 # Whether AM_GNU_GETTEXT_INTL_SUBDIR has been seen.
367 my $seen_gettext_intl = 0;
369 # Lists of tags supported by Libtool.
370 my %libtool_tags = ();
371 # 1 if Libtool uses LT_SUPPORTED_TAG. If it does, then it also
372 # uses AC_REQUIRE_AUX_FILE.
373 my $libtool_new_api = 0;
375 # Most important AC_CANONICAL_* macro seen so far.
376 my $seen_canonical = 0;
377 # Location of that macro.
378 my $canonical_location;
380 # Where AM_MAINTAINER_MODE appears.
383 # Actual version we've seen.
384 my $package_version = '';
386 # Where version is defined.
387 my $package_version_location;
389 # TRUE if we've seen AM_PROG_AR
392 # TRUE if we've seen AM_PROG_CC_C_O
395 # Location of AC_REQUIRE_AUX_FILE calls, indexed by their argument.
396 my %required_aux_file = ();
398 # Where AM_INIT_AUTOMAKE is called;
399 my $seen_init_automake = 0;
401 # TRUE if we've seen AM_AUTOMAKE_VERSION.
402 my $seen_automake_version = 0;
404 # Hash table of discovered configure substitutions. Keys are names,
405 # values are `FILE:LINE' strings which are used by error message
407 my %configure_vars = ();
409 # Ignored configure substitutions (i.e., variables not to be output in
411 my %ignored_configure_vars = ();
413 # Files included by $configure_ac.
414 my @configure_deps = ();
416 # Greatest timestamp of configure's dependencies.
417 my $configure_deps_greatest_timestamp = 0;
419 # Hash table of AM_CONDITIONAL variables seen in configure.
420 my %configure_cond = ();
422 # This maps extensions onto language names.
423 my %extension_map = ();
425 # List of the DIST_COMMON files we discovered while reading
427 my $configure_dist_common = '';
429 # This maps languages names onto objects.
431 # Maps each linker variable onto a language object.
432 my %link_languages = ();
434 # maps extensions to needed source flags.
435 my %sourceflags = ();
437 # List of targets we must always output.
438 # FIXME: Complete, and remove falsely required targets.
439 my %required_targets =
452 # FIXME: Not required, temporary hacks.
453 # Well, actually they are sort of required: the -recursive
454 # targets will run them anyway...
460 'install-data-am' => 1,
461 'install-exec-am' => 1,
462 'install-html-am' => 1,
463 'install-dvi-am' => 1,
464 'install-pdf-am' => 1,
465 'install-ps-am' => 1,
466 'install-info-am' => 1,
467 'installcheck-am' => 1,
473 # Queue to push require_conf_file requirements to.
474 my $required_conf_file_queue;
476 # The name of the Makefile currently being processed.
480 ################################################################
482 ## ------------------------------------------ ##
483 ## Variables reset by &initialize_per_input. ##
484 ## ------------------------------------------ ##
486 # Basename and relative dir of the input file.
490 # Same but wrt Makefile.in.
494 # Relative path to the top directory.
497 # Greatest timestamp of the output's dependencies (excluding
498 # configure's dependencies).
499 my $output_deps_greatest_timestamp;
501 # These variables are used when generating each Makefile.in.
502 # They hold the Makefile.in until it is ready to be printed.
509 # This is the conditional stack, updated on if/else/endif, and
510 # used to build Condition objects.
513 # This holds the set of included files.
516 # List of dependencies for the obvious targets.
521 # Keys in this hash table are files to delete. The associated
522 # value tells when this should happen (MOSTLY_CLEAN, DIST_CLEAN, etc.)
525 # Keys in this hash table are object files or other files in
526 # subdirectories which need to be removed. This only holds files
527 # which are created by compilations. The value in the hash indicates
528 # when the file should be removed.
529 my %compile_clean_files;
531 # Keys in this hash table are directories where we expect to build a
532 # libtool object. We use this information to decide what directories
534 my %libtool_clean_directories;
536 # Value of `$(SOURCES)', used by tags.am.
538 # Sources which go in the distribution.
541 # This hash maps object file names onto their corresponding source
542 # file names. This is used to ensure that each object is created
543 # by a single source file.
546 # This hash maps object file names onto an integer value representing
547 # whether this object has been built via ordinary compilation or
548 # libtool compilation (the COMPILE_* constants).
549 my %object_compilation_map;
552 # This keeps track of the directories for which we've already
553 # created dirstamp code. Keys are directories, values are stamp files.
554 # Several keys can share the same stamp files if they are equivalent
555 # (as are `.//foo' and `foo').
561 # This is a list of all targets to run during "make dist".
564 # Keep track of all programs declared in this Makefile, without
565 # $(EXEEXT). @substitutions@ are not listed.
569 # This keeps track of which extensions we've seen (that we care
573 # This is random scratch space for the language finish functions.
574 # Don't randomly overwrite it; examine other uses of keys first.
575 my %language_scratch;
577 # We keep track of which objects need special (per-executable)
578 # handling on a per-language basis.
579 my %lang_specific_files;
581 # This is set when `handle_dist' has finished. Once this happens,
582 # we should no longer push on dist_common.
585 # Used to store a set of linkers needed to generate the sources currently
586 # under consideration.
589 # True if we need `LINK' defined. This is a hack.
592 # Does the generated Makefile have to build some compiled object
593 # (for binary programs, or plain or libtool libraries)?
594 my $must_handle_compiled_objects;
596 # Record each file processed by make_paragraphs.
597 my %transformed_files;
600 ################################################################
602 ## ---------------------------------------------- ##
603 ## Variables not reset by &initialize_per_input. ##
604 ## ---------------------------------------------- ##
606 # Cache each file processed by make_paragraphs.
607 # (This is different from %transformed_files because
608 # %transformed_files is reset for each file while %am_file_cache
609 # it global to the run.)
612 ################################################################
614 # var_SUFFIXES_trigger ($TYPE, $VALUE)
615 # ------------------------------------
616 # This is called by Automake::Variable::define() when SUFFIXES
617 # is defined ($TYPE eq '') or appended ($TYPE eq '+').
618 # The work here needs to be performed as a side-effect of the
619 # macro_define() call because SUFFIXES definitions impact
620 # on $KNOWN_EXTENSIONS_PATTERN which is used used when parsing
622 sub var_SUFFIXES_trigger ($$)
624 my ($type, $value) = @_;
625 accept_extensions (split (' ', $value));
627 Automake::Variable::hook ('SUFFIXES', \&var_SUFFIXES_trigger);
629 ################################################################
631 ## --------------------------------- ##
632 ## Forward subroutine declarations. ##
633 ## --------------------------------- ##
634 sub register_language (%);
635 sub file_contents_internal ($$$%);
636 sub define_files_variable ($\@$$);
639 # &initialize_per_input ()
640 # ------------------------
641 # (Re)-Initialize per-Makefile.am variables.
642 sub initialize_per_input ()
644 reset_local_duplicates ();
646 $am_file_name = undef;
647 $am_relative_dir = undef;
649 $in_file_name = undef;
650 $relative_dir = undef;
653 $output_deps_greatest_timestamp = 0;
659 $output_trailer = '';
661 Automake::Options::reset;
662 Automake::Variable::reset;
663 Automake::Rule::reset;
674 %compile_clean_files = ();
676 # We always include `.'. This isn't strictly correct.
677 %libtool_clean_directories = ('.' => 1);
683 %object_compilation_map = ();
691 %known_programs = ();
692 %known_libraries= ();
694 %extension_seen = ();
696 %language_scratch = ();
698 %lang_specific_files = ();
700 $handle_dist_run = 0;
704 $must_handle_compiled_objects = 0;
706 %transformed_files = ();
710 ################################################################
712 # Initialize our list of languages that are internally supported.
715 register_language ('name' => 'c',
717 'config_vars' => ['CC'],
719 'flags' => ['CFLAGS', 'CPPFLAGS'],
721 'compiler' => 'COMPILE',
722 'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
726 'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
727 'compile_flag' => '-c',
728 'libtool_tag' => 'CC',
729 'extensions' => ['.c']);
732 register_language ('name' => 'cxx',
734 'config_vars' => ['CXX'],
735 'linker' => 'CXXLINK',
736 'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
738 'flags' => ['CXXFLAGS', 'CPPFLAGS'],
739 'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
741 'compiler' => 'CXXCOMPILE',
742 'compile_flag' => '-c',
743 'output_flag' => '-o',
744 'libtool_tag' => 'CXX',
748 'extensions' => ['.c++', '.cc', '.cpp', '.cxx', '.C']);
751 register_language ('name' => 'objc',
752 'Name' => 'Objective C',
753 'config_vars' => ['OBJC'],
754 'linker' => 'OBJCLINK',
755 'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
757 'flags' => ['OBJCFLAGS', 'CPPFLAGS'],
758 'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
760 'compiler' => 'OBJCCOMPILE',
761 'compile_flag' => '-c',
762 'output_flag' => '-o',
766 'extensions' => ['.m']);
768 # Unified Parallel C.
769 register_language ('name' => 'upc',
770 'Name' => 'Unified Parallel C',
771 'config_vars' => ['UPC'],
772 'linker' => 'UPCLINK',
773 'link' => '$(UPCLD) $(AM_UPCFLAGS) $(UPCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
775 'flags' => ['UPCFLAGS', 'CPPFLAGS'],
776 'compile' => '$(UPC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_UPCFLAGS) $(UPCFLAGS)',
778 'compiler' => 'UPCCOMPILE',
779 'compile_flag' => '-c',
780 'output_flag' => '-o',
784 'extensions' => ['.upc']);
787 register_language ('name' => 'header',
789 'extensions' => ['.h', '.H', '.hxx', '.h++', '.hh',
792 'output_extensions' => sub { return () },
794 '_finish' => sub { });
797 register_language ('name' => 'vala',
799 'config_vars' => ['VALAC'],
801 'compile' => '$(VALAC) $(AM_VALAFLAGS) $(VALAFLAGS)',
803 'compiler' => 'VALACOMPILE',
804 'extensions' => ['.vala'],
805 'output_extensions' => sub { (my $ext = $_[0]) =~ s/vala$/c/;
807 'rule_file' => 'vala',
808 '_finish' => \&lang_vala_finish,
809 '_target_hook' => \&lang_vala_target_hook,
810 'nodist_specific' => 1);
813 register_language ('name' => 'yacc',
815 'config_vars' => ['YACC'],
816 'flags' => ['YFLAGS'],
817 'compile' => '$(YACC) $(AM_YFLAGS) $(YFLAGS)',
819 'compiler' => 'YACCCOMPILE',
820 'extensions' => ['.y'],
821 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
823 'rule_file' => 'yacc',
824 '_finish' => \&lang_yacc_finish,
825 '_target_hook' => \&lang_yacc_target_hook,
826 'nodist_specific' => 1);
827 register_language ('name' => 'yaccxx',
828 'Name' => 'Yacc (C++)',
829 'config_vars' => ['YACC'],
830 'rule_file' => 'yacc',
831 'flags' => ['YFLAGS'],
833 'compiler' => 'YACCCOMPILE',
834 'compile' => '$(YACC) $(AM_YFLAGS) $(YFLAGS)',
835 'extensions' => ['.y++', '.yy', '.yxx', '.ypp'],
836 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
838 '_finish' => \&lang_yacc_finish,
839 '_target_hook' => \&lang_yacc_target_hook,
840 'nodist_specific' => 1);
843 register_language ('name' => 'lex',
845 'config_vars' => ['LEX'],
846 'rule_file' => 'lex',
847 'flags' => ['LFLAGS'],
848 'compile' => '$(LEX) $(AM_LFLAGS) $(LFLAGS)',
850 'compiler' => 'LEXCOMPILE',
851 'extensions' => ['.l'],
852 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
854 '_finish' => \&lang_lex_finish,
855 '_target_hook' => \&lang_lex_target_hook,
856 'nodist_specific' => 1);
857 register_language ('name' => 'lexxx',
858 'Name' => 'Lex (C++)',
859 'config_vars' => ['LEX'],
860 'rule_file' => 'lex',
861 'flags' => ['LFLAGS'],
862 'compile' => '$(LEX) $(AM_LFLAGS) $(LFLAGS)',
864 'compiler' => 'LEXCOMPILE',
865 'extensions' => ['.l++', '.ll', '.lxx', '.lpp'],
866 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
868 '_finish' => \&lang_lex_finish,
869 '_target_hook' => \&lang_lex_target_hook,
870 'nodist_specific' => 1);
873 register_language ('name' => 'asm',
874 'Name' => 'Assembler',
875 'config_vars' => ['CCAS', 'CCASFLAGS'],
877 'flags' => ['CCASFLAGS'],
878 # Users can set AM_CCASFLAGS to include DEFS, INCLUDES,
879 # or anything else required. They can also set CCAS.
880 # Or simply use Preprocessed Assembler.
881 'compile' => '$(CCAS) $(AM_CCASFLAGS) $(CCASFLAGS)',
883 'compiler' => 'CCASCOMPILE',
884 'compile_flag' => '-c',
885 'output_flag' => '-o',
886 'extensions' => ['.s']);
888 # Preprocessed Assembler.
889 register_language ('name' => 'cppasm',
890 'Name' => 'Preprocessed Assembler',
891 'config_vars' => ['CCAS', 'CCASFLAGS'],
894 'flags' => ['CCASFLAGS', 'CPPFLAGS'],
895 'compile' => '$(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS)',
897 'compiler' => 'CPPASCOMPILE',
898 'compile_flag' => '-c',
899 'output_flag' => '-o',
900 'extensions' => ['.S', '.sx']);
903 register_language ('name' => 'f77',
904 'Name' => 'Fortran 77',
905 'config_vars' => ['F77'],
906 'linker' => 'F77LINK',
907 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
908 'flags' => ['FFLAGS'],
909 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
911 'compiler' => 'F77COMPILE',
912 'compile_flag' => '-c',
913 'output_flag' => '-o',
914 'libtool_tag' => 'F77',
918 'extensions' => ['.f', '.for']);
921 register_language ('name' => 'fc',
923 'config_vars' => ['FC'],
924 'linker' => 'FCLINK',
925 'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
926 'flags' => ['FCFLAGS'],
927 'compile' => '$(FC) $(AM_FCFLAGS) $(FCFLAGS)',
929 'compiler' => 'FCCOMPILE',
930 'compile_flag' => '-c',
931 'output_flag' => '-o',
932 'libtool_tag' => 'FC',
936 'extensions' => ['.f90', '.f95', '.f03', '.f08']);
938 # Preprocessed Fortran
939 register_language ('name' => 'ppfc',
940 'Name' => 'Preprocessed Fortran',
941 'config_vars' => ['FC'],
942 'linker' => 'FCLINK',
943 'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
946 'flags' => ['FCFLAGS', 'CPPFLAGS'],
948 'compiler' => 'PPFCCOMPILE',
949 'compile' => '$(FC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FCFLAGS) $(FCFLAGS)',
950 'compile_flag' => '-c',
951 'output_flag' => '-o',
952 'libtool_tag' => 'FC',
954 'extensions' => ['.F90','.F95', '.F03', '.F08']);
956 # Preprocessed Fortran 77
958 # The current support for preprocessing Fortran 77 just involves
959 # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
960 # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
961 # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
962 # for `make' Version 3.76 Beta' (specifically, from info file
963 # `(make)Catalogue of Rules').
965 # A better approach would be to write an Autoconf test
966 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
967 # Fortran 77 compilers know how to do preprocessing. The Autoconf
968 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
969 # preprocessing capabilities, and then fall back on cpp (if cpp were
971 register_language ('name' => 'ppf77',
972 'Name' => 'Preprocessed Fortran 77',
973 'config_vars' => ['F77'],
974 'linker' => 'F77LINK',
975 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
978 'flags' => ['FFLAGS', 'CPPFLAGS'],
980 'compiler' => 'PPF77COMPILE',
981 'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
982 'compile_flag' => '-c',
983 'output_flag' => '-o',
984 'libtool_tag' => 'F77',
986 'extensions' => ['.F']);
989 register_language ('name' => 'ratfor',
991 'config_vars' => ['F77'],
992 'linker' => 'F77LINK',
993 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
996 'flags' => ['RFLAGS', 'FFLAGS'],
998 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
1000 'compiler' => 'RCOMPILE',
1001 'compile_flag' => '-c',
1002 'output_flag' => '-o',
1003 'libtool_tag' => 'F77',
1005 'extensions' => ['.r']);
1008 register_language ('name' => 'java',
1010 'config_vars' => ['GCJ'],
1011 'linker' => 'GCJLINK',
1012 'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
1014 'flags' => ['GCJFLAGS'],
1015 'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
1017 'compiler' => 'GCJCOMPILE',
1018 'compile_flag' => '-c',
1019 'output_flag' => '-o',
1020 'libtool_tag' => 'GCJ',
1024 'extensions' => ['.java', '.class', '.zip', '.jar']);
1026 ################################################################
1028 # Error reporting functions.
1030 # err_am ($MESSAGE, [%OPTIONS])
1031 # -----------------------------
1032 # Uncategorized errors about the current Makefile.am.
1035 msg_am ('error', @_);
1038 # err_ac ($MESSAGE, [%OPTIONS])
1039 # -----------------------------
1040 # Uncategorized errors about configure.ac.
1043 msg_ac ('error', @_);
1046 # msg_am ($CHANNEL, $MESSAGE, [%OPTIONS])
1047 # ---------------------------------------
1048 # Messages about about the current Makefile.am.
1051 my ($channel, $msg, %opts) = @_;
1052 msg $channel, "${am_file}.am", $msg, %opts;
1055 # msg_ac ($CHANNEL, $MESSAGE, [%OPTIONS])
1056 # ---------------------------------------
1057 # Messages about about configure.ac.
1060 my ($channel, $msg, %opts) = @_;
1061 msg $channel, $configure_ac, $msg, %opts;
1064 ################################################################
1068 # Return a configure-style substitution using the indicated text.
1069 # We do this to avoid having the substitutions directly in automake.in;
1070 # when we do that they are sometimes removed and this causes confusion
1075 return '@' . $text . '@';
1078 ################################################################
1082 # &backname ($REL-DIR)
1083 # --------------------
1084 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
1085 # For instance `src/foo' => `../..'.
1086 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
1091 foreach (split (/\//, $file))
1093 next if $_ eq '.' || $_ eq '';
1097 or prog_error ("trying to reverse path `$file' pointing outside tree");
1104 return join ('/', @res) || '.';
1107 ################################################################
1109 # `silent-rules' mode handling functions.
1111 # verbose_var (NAME)
1112 # ------------------
1113 # The public variable stem used to implement `silent-rules'.
1117 return 'AM_V_' . $name;
1120 # verbose_private_var (NAME)
1121 # --------------------------
1122 # The naming policy for the private variables for `silent-rules'.
1123 sub verbose_private_var ($)
1126 return 'am__v_' . $name;
1129 # define_verbose_var (NAME, VAL)
1130 # ------------------------------
1131 # For `silent-rules' mode, setup VAR and dispatcher, to expand to VAL if silent.
1132 sub define_verbose_var ($$)
1134 my ($name, $val) = @_;
1135 my $var = verbose_var ($name);
1136 my $pvar = verbose_private_var ($name);
1137 my $silent_var = $pvar . '_0';
1138 if (option 'silent-rules')
1140 # For typical `make's, `configure' replaces AM_V (inside @@) with $(V)
1141 # and AM_DEFAULT_V (inside @@) with $(AM_DEFAULT_VERBOSITY).
1142 # For strict POSIX 2008 `make's, it replaces them with 0 or 1 instead.
1143 # See AM_SILENT_RULES in m4/silent.m4.
1144 define_variable ($var, '$(' . $pvar . '_@'.'AM_V'.'@)', INTERNAL);
1145 define_variable ($pvar . '_', '$(' . $pvar . '_@'.'AM_DEFAULT_V'.'@)', INTERNAL);
1146 Automake::Variable::define ($silent_var, VAR_AUTOMAKE, '', TRUE, $val,
1147 '', INTERNAL, VAR_ASIS)
1148 if (! vardef ($silent_var, TRUE));
1152 # Above should not be needed in the general automake code.
1154 # verbose_flag (NAME)
1155 # -------------------
1156 # Contents of %VERBOSE%: variable to expand before rule command.
1157 sub verbose_flag ($)
1160 return '$(' . verbose_var ($name) . ')'
1161 if (option 'silent-rules');
1165 sub verbose_nodep_flag ($)
1168 return '$(' . verbose_var ($name) . subst ('am__nodep') . ')'
1169 if (option 'silent-rules');
1175 # Contents of %SILENT%: variable to expand to `@' when silent.
1178 return verbose_flag ('at');
1181 # define_verbose_tagvar (NAME)
1182 # ----------------------------
1183 # Engage the needed `silent-rules' machinery for tag NAME.
1184 sub define_verbose_tagvar ($)
1187 if (option 'silent-rules')
1189 define_verbose_var ($name, '@echo " '. $name . ' ' x (8 - length ($name)) . '" $@;');
1190 define_verbose_var ('at', '@');
1194 # define_verbose_texinfo
1195 # ----------------------
1196 # Engage the needed `silent-rules' machinery for assorted texinfo commands.
1197 sub define_verbose_texinfo ()
1199 my @tagvars = ('DVIPS', 'MAKEINFO', 'INFOHTML', 'TEXI2DVI', 'TEXI2PDF');
1200 foreach my $tag (@tagvars)
1202 define_verbose_tagvar($tag);
1204 define_verbose_var('texinfo', '-q');
1205 define_verbose_var('texidevnull', '> /dev/null');
1208 # define_verbose_libtool
1209 # ----------------------
1210 # Engage the needed `silent-rules' machinery for `libtool --silent'.
1211 sub define_verbose_libtool ()
1213 define_verbose_var ('lt', '--silent');
1214 return verbose_flag ('lt');
1218 ################################################################
1221 # Handle AUTOMAKE_OPTIONS variable. Return 1 on error, 0 otherwise.
1224 my $var = var ('AUTOMAKE_OPTIONS');
1227 if ($var->has_conditional_contents)
1229 msg_var ('unsupported', $var,
1230 "`AUTOMAKE_OPTIONS' cannot have conditional contents");
1232 my @options = map { { option => $_->[1], where => $_->[0] } }
1233 $var->value_as_list_recursive (cond_filter => TRUE,
1235 return 1 if process_option_list (@options);
1238 # Override portability-recursive warning.
1239 switch_warning ('no-portability-recursive')
1240 if option 'silent-rules';
1242 if ($strictness == GNITS)
1244 set_option ('readme-alpha', INTERNAL);
1245 set_option ('std-options', INTERNAL);
1246 set_option ('check-news', INTERNAL);
1252 # shadow_unconditionally ($varname, $where)
1253 # -----------------------------------------
1254 # Return a $(variable) that contains all possible values
1255 # $varname can take.
1256 # If the VAR wasn't defined conditionally, return $(VAR).
1257 # Otherwise we create an am__VAR_DIST variable which contains
1258 # all possible values, and return $(am__VAR_DIST).
1259 sub shadow_unconditionally ($$)
1261 my ($varname, $where) = @_;
1262 my $var = var $varname;
1263 if ($var->has_conditional_contents)
1265 $varname = "am__${varname}_DIST";
1266 my @files = uniq ($var->value_as_list_recursive);
1267 define_pretty_variable ($varname, TRUE, $where, @files);
1269 return "\$($varname)"
1272 # check_user_variables (@LIST)
1273 # ----------------------------
1274 # Make sure each variable VAR in @LIST does not exist, suggest using AM_VAR
1276 sub check_user_variables (@)
1278 my @dont_override = @_;
1279 foreach my $flag (@dont_override)
1281 my $var = var $flag;
1284 for my $cond ($var->conditions->conds)
1286 if ($var->rdef ($cond)->owner == VAR_MAKEFILE)
1288 msg_cond_var ('gnu', $cond, $flag,
1289 "`$flag' is a user variable, "
1290 . "you should not override it;\n"
1291 . "use `AM_$flag' instead");
1298 # Call finish function for each language that was used.
1299 sub handle_languages
1301 if (! option 'no-dependencies')
1303 # Include auto-dep code. Don't include it if DEP_FILES would
1305 if (&saw_sources_p (0) && keys %dep_files)
1307 # Set location of depcomp.
1308 &define_variable ('depcomp',
1309 "\$(SHELL) $am_config_aux_dir/depcomp",
1311 &define_variable ('am__depfiles_maybe', 'depfiles', INTERNAL);
1313 require_conf_file ("$am_file.am", FOREIGN, 'depcomp');
1315 my @deplist = sort keys %dep_files;
1316 # Generate each `include' individually. Irix 6 make will
1317 # not properly include several files resulting from a
1318 # variable expansion; generating many separate includes
1320 $output_rules .= "\n";
1321 foreach my $iter (@deplist)
1323 $output_rules .= (subst ('AMDEP_TRUE')
1324 . subst ('am__include')
1326 . subst ('am__quote')
1328 . subst ('am__quote')
1332 # Compute the set of directories to remove in distclean-depend.
1333 my @depdirs = uniq (map { dirname ($_) } @deplist);
1334 $output_rules .= &file_contents ('depend',
1335 new Automake::Location,
1336 DEPDIRS => "@depdirs");
1341 &define_variable ('depcomp', '', INTERNAL);
1342 &define_variable ('am__depfiles_maybe', '', INTERNAL);
1347 # Is the C linker needed?
1349 foreach my $ext (sort keys %extension_seen)
1351 next unless $extension_map{$ext};
1353 my $lang = $languages{$extension_map{$ext}};
1355 my $rule_file = $lang->rule_file || 'depend2';
1357 # Get information on $LANG.
1358 my $pfx = $lang->autodep;
1359 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1361 my ($AMDEP, $FASTDEP) =
1362 (option 'no-dependencies' || $lang->autodep eq 'no')
1363 ? ('FALSE', 'FALSE') : ('AMDEP', "am__fastdep$fpfx");
1365 my $verbose = verbose_flag ($lang->ccer || 'GEN');
1366 my $verbose_nodep = ($AMDEP eq 'FALSE')
1367 ? $verbose : verbose_nodep_flag ($lang->ccer || 'GEN');
1368 my $silent = silent_flag ();
1370 my %transform = ('EXT' => $ext,
1374 'FASTDEP' => $FASTDEP,
1375 '-c' => $lang->compile_flag || '',
1376 # These are not used, but they need to be defined
1377 # so &transform do not complain.
1379 'DERIVED-EXT' => 'BUG',
1381 VERBOSE => $verbose,
1382 'VERBOSE-NODEP' => $verbose_nodep,
1386 # Generate the appropriate rules for this extension.
1387 if (((! option 'no-dependencies') && $lang->autodep ne 'no')
1388 || defined $lang->compile)
1390 # Some C compilers don't support -c -o. Use it only if really
1392 my $output_flag = $lang->output_flag || '';
1395 && $lang->name eq 'c'
1396 && option 'subdir-objects');
1398 # Compute a possible derived extension.
1399 # This is not used by depend2.am.
1400 my $der_ext = (&{$lang->output_extensions} ($ext))[0];
1402 # When we output an inference rule like `.c.o:' we
1403 # have two cases to consider: either subdir-objects
1404 # is used, or it is not.
1406 # In the latter case the rule is used to build objects
1407 # in the current directory, and dependencies always
1408 # go into `./$(DEPDIR)/'. We can hard-code this value.
1410 # In the former case the rule can be used to build
1411 # objects in sub-directories too. Dependencies should
1412 # go into the appropriate sub-directories, e.g.,
1413 # `sub/$(DEPDIR)/'. The value of this directory
1414 # needs to be computed on-the-fly.
1416 # DEPBASE holds the name of this directory, plus the
1417 # basename part of the object file (extensions Po, TPo,
1418 # Plo, TPlo will be added later as appropriate). It is
1419 # either hardcoded, or a shell variable (`$depbase') that
1420 # will be computed by the rule.
1422 option ('subdir-objects') ? '$$depbase' : '$(DEPDIR)/$*';
1424 file_contents ($rule_file,
1425 new Automake::Location,
1429 'DERIVED-EXT' => $der_ext,
1431 DEPBASE => $depbase,
1434 SOURCEFLAG => $sourceflags{$ext} || '',
1439 COMPILE => '$(' . $lang->compiler . ')',
1440 LTCOMPILE => '$(LT' . $lang->compiler . ')',
1442 SUBDIROBJ => !! option 'subdir-objects');
1445 # Now include code for each specially handled object with this
1447 my %seen_files = ();
1448 foreach my $file (@{$lang_specific_files{$lang->name}})
1450 my ($derived, $source, $obj, $myext, $srcext, %file_transform) = @$file;
1452 # We might see a given object twice, for instance if it is
1453 # used under different conditions.
1454 next if defined $seen_files{$obj};
1455 $seen_files{$obj} = 1;
1457 prog_error ("found " . $lang->name .
1458 " in handle_languages, but compiler not defined")
1459 unless defined $lang->compile;
1461 my $obj_compile = $lang->compile;
1463 # Rewrite each occurrence of `AM_$flag' in the compile
1464 # rule into `${derived}_$flag' if it exists.
1465 for my $flag (@{$lang->flags})
1467 my $val = "${derived}_$flag";
1468 $obj_compile =~ s/\(AM_$flag\)/\($val\)/
1472 my $libtool_tag = '';
1473 if ($lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag})
1475 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
1478 my $ptltflags = "${derived}_LIBTOOLFLAGS";
1479 $ptltflags = 'AM_LIBTOOLFLAGS' unless set_seen $ptltflags;
1481 my $ltverbose = define_verbose_libtool ();
1483 "\$(LIBTOOL) $ltverbose $libtool_tag\$($ptltflags) \$(LIBTOOLFLAGS) "
1484 . "--mode=compile $obj_compile";
1486 # We _need_ `-o' for per object rules.
1487 my $output_flag = $lang->output_flag || '-o';
1489 my $depbase = dirname ($obj);
1493 unless $depbase eq '';
1494 $depbase .= '$(DEPDIR)/' . basename ($obj);
1497 file_contents ($rule_file,
1498 new Automake::Location,
1502 DEPBASE => $depbase,
1505 SOURCEFLAG => $sourceflags{$srcext} || '',
1506 # Use $myext and not `.o' here, in case
1507 # we are actually building a new source
1508 # file -- e.g. via yacc.
1509 OBJ => "$obj$myext",
1510 OBJOBJ => "$obj.obj",
1513 VERBOSE => $verbose,
1514 'VERBOSE-NODEP' => $verbose_nodep,
1516 COMPILE => $obj_compile,
1517 LTCOMPILE => $obj_ltcompile,
1522 # The rest of the loop is done once per language.
1523 next if defined $done{$lang};
1526 # Load the language dependent Makefile chunks.
1527 my %lang = map { uc ($_) => 0 } keys %languages;
1528 $lang{uc ($lang->name)} = 1;
1529 $output_rules .= file_contents ('lang-compile',
1530 new Automake::Location,
1533 # If the source to a program consists entirely of code from a
1534 # `pure' language, for instance C++ or Fortran 77, then we
1535 # don't need the C compiler code. However if we run into
1536 # something unusual then we do generate the C code. There are
1537 # probably corner cases here that do not work properly.
1538 # People linking Java code to Fortran code deserve pain.
1539 $needs_c ||= ! $lang->pure;
1541 define_compiler_variable ($lang)
1542 if ($lang->compile);
1544 define_linker_variable ($lang)
1547 require_variables ("$am_file.am", $lang->Name . " source seen",
1548 TRUE, @{$lang->config_vars});
1550 # Call the finisher.
1553 # Flags listed in `->flags' are user variables (per GNU Standards),
1554 # they should not be overridden in the Makefile...
1555 my @dont_override = @{$lang->flags};
1556 # ... and so is LDFLAGS.
1557 push @dont_override, 'LDFLAGS' if $lang->link;
1559 check_user_variables @dont_override;
1562 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1563 # suffix rule was learned), don't bother with the C stuff. But if
1564 # anything else creeps in, then use it.
1566 if $need_link || suffix_rules_count > 1;
1570 &define_compiler_variable ($languages{'c'})
1571 unless defined $done{$languages{'c'}};
1572 define_linker_variable ($languages{'c'});
1575 # Always provide the user with `AM_V_GEN' for `silent-rules' mode.
1576 define_verbose_tagvar ('GEN');
1580 # append_exeext { PREDICATE } $MACRO
1581 # ----------------------------------
1582 # Append $(EXEEXT) to each filename in $F appearing in the Makefile
1583 # variable $MACRO if &PREDICATE($F) is true. @substitutions@ are
1586 # This is typically used on all filenames of *_PROGRAMS, and filenames
1587 # of TESTS that are programs.
1588 sub append_exeext (&$)
1590 my ($pred, $macro) = @_;
1592 transform_variable_recursively
1593 ($macro, $macro, 'am__EXEEXT', 0, INTERNAL,
1595 my ($subvar, $val, $cond, $full_cond) = @_;
1596 # Append $(EXEEXT) unless the user did it already, or it's a
1599 if $val !~ /(?:\$\(EXEEXT\)$|^[@]\w+[@]$)/ && &$pred ($val);
1605 # Check to make sure a source defined in LIBOBJS is not explicitly
1606 # mentioned. This is a separate function (as opposed to being inlined
1607 # in handle_source_transform) because it isn't always appropriate to
1609 sub check_libobjs_sources
1611 my ($one_file, $unxformed) = @_;
1613 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1614 'dist_EXTRA_', 'nodist_EXTRA_')
1617 my $varname = $prefix . $one_file . '_SOURCES';
1618 my $var = var ($varname);
1621 @files = $var->value_as_list_recursive;
1623 elsif ($prefix eq '')
1625 @files = ($unxformed . '.c');
1632 foreach my $file (@files)
1634 err_var ($prefix . $one_file . '_SOURCES',
1635 "automatically discovered file `$file' should not" .
1636 " be explicitly mentioned")
1637 if defined $libsources{$file};
1644 # handle_single_transform ($VAR, $TOPPARENT, $DERIVED, $OBJ, $FILE, %TRANSFORM)
1645 # -----------------------------------------------------------------------------
1646 # Does much of the actual work for handle_source_transform.
1648 # $VAR is the name of the variable that the source filenames come from
1649 # $TOPPARENT is the name of the _SOURCES variable which is being processed
1650 # $DERIVED is the name of resulting executable or library
1651 # $OBJ is the object extension (e.g., `.lo')
1652 # $FILE the source file to transform
1653 # %TRANSFORM contains extras arguments to pass to file_contents
1654 # when producing explicit rules
1655 # Result is a list of the names of objects
1656 # %linkers_used will be updated with any linkers needed
1657 sub handle_single_transform ($$$$$%)
1659 my ($var, $topparent, $derived, $obj, $_file, %transform) = @_;
1660 my @files = ($_file);
1663 # Turn sources into objects. We use a while loop like this
1664 # because we might add to @files in the loop.
1665 while (scalar @files > 0)
1669 # Configure substitutions in _SOURCES variables are errors.
1672 my $parent_msg = '';
1673 $parent_msg = "\nand is referred to from `$topparent'"
1674 if $topparent ne $var->name;
1676 "`" . $var->name . "' includes configure substitution `$_'"
1677 . $parent_msg . ";\nconfigure " .
1678 "substitutions are not allowed in _SOURCES variables");
1682 # If the source file is in a subdirectory then the `.o' is put
1683 # into the current directory, unless the subdir-objects option
1686 # Split file name into base and extension.
1687 next if ! /^(?:(.*)\/)?([^\/]*)($KNOWN_EXTENSIONS_PATTERN)$/;
1689 my $directory = $1 || '';
1693 # We must generate a rule for the object if it requires its own flags.
1695 my ($linker, $object);
1697 # This records whether we've seen a derived source file (e.g.
1699 my $derived_source = 0;
1701 # This holds the `aggregate context' of the file we are
1702 # currently examining. If the file is compiled with
1703 # per-object flags, then it will be the name of the object.
1704 # Otherwise it will be `AM'. This is used by the target hook
1705 # language function.
1706 my $aggregate = 'AM';
1708 $extension = &derive_suffix ($extension, $obj);
1710 if ($extension_map{$extension} &&
1711 ($lang = $languages{$extension_map{$extension}}))
1713 # Found the language, so see what it says.
1714 &saw_extension ($extension);
1716 # Do we have per-executable flags for this executable?
1717 my $have_per_exec_flags = 0;
1718 my @peflags = @{$lang->flags};
1719 push @peflags, 'LIBTOOLFLAGS' if $obj eq '.lo';
1720 foreach my $flag (@peflags)
1722 if (set_seen ("${derived}_$flag"))
1724 $have_per_exec_flags = 1;
1729 # Note: computed subr call. The language rewrite function
1730 # should return one of the LANG_* constants. It could
1731 # also return a list whose first value is such a constant
1732 # and whose second value is a new source extension which
1733 # should be applied. This means this particular language
1734 # generates another source file which we must then process
1736 my $subr = \&{'lang_' . $lang->name . '_rewrite'};
1737 my ($r, $source_extension)
1738 = &$subr ($directory, $base, $extension,
1739 $obj, $have_per_exec_flags, $var);
1740 # Skip this entry if we were asked not to process it.
1741 next if $r == LANG_IGNORE;
1743 # Now extract linker and other info.
1744 $linker = $lang->linker;
1747 if (defined $source_extension)
1749 $this_obj_ext = $source_extension;
1750 $derived_source = 1;
1754 $this_obj_ext = $obj;
1756 $object = $base . $this_obj_ext;
1758 if ($have_per_exec_flags)
1760 # We have a per-executable flag in effect for this
1761 # object. In this case we rewrite the object's
1762 # name to ensure it is unique.
1764 # We choose the name `DERIVED_OBJECT' to ensure
1765 # (1) uniqueness, and (2) continuity between
1766 # invocations. However, this will result in a
1767 # name that is too long for losing systems, in
1768 # some situations. So we provide _SHORTNAME to
1771 my $dname = $derived;
1772 my $var = var ($derived . '_SHORTNAME');
1775 # FIXME: should use the same Condition as
1776 # the _SOURCES variable. But this is really
1777 # silly overkill -- nobody should have
1778 # conditional shortnames.
1779 $dname = $var->variable_value;
1781 $object = $dname . '-' . $object;
1783 prog_error ($lang->name . " flags defined without compiler")
1784 if ! defined $lang->compile;
1789 # If rewrite said it was ok, put the object into a
1791 if ($r == LANG_SUBDIR && $directory ne '')
1793 $object = $directory . '/' . $object;
1796 # If the object file has been renamed (because per-target
1797 # flags are used) we cannot compile the file with an
1798 # inference rule: we need an explicit rule.
1800 # If the source is in a subdirectory and the object is in
1801 # the current directory, we also need an explicit rule.
1803 # If both source and object files are in a subdirectory
1804 # (this happens when the subdir-objects option is used),
1805 # then the inference will work.
1807 # The latter case deserves a historical note. When the
1808 # subdir-objects option was added on 1999-04-11 it was
1809 # thought that inferences rules would work for
1810 # subdirectory objects too. Later, on 1999-11-22,
1811 # automake was changed to output explicit rules even for
1812 # subdir-objects. Nobody remembers why, but this occurred
1813 # soon after the merge of the user-dep-gen-branch so it
1814 # might be related. In late 2003 people complained about
1815 # the size of the generated Makefile.ins (libgcj, with
1816 # 2200+ subdir objects was reported to have a 9MB
1817 # Makefile), so we now rely on inference rules again.
1818 # Maybe we'll run across the same issue as in the past,
1819 # but at least this time we can document it. However since
1820 # dependency tracking has evolved it is possible that
1821 # our old problem no longer exists.
1822 # Using inference rules for subdir-objects has been tested
1823 # with GNU make, Solaris make, Ultrix make, BSD make,
1824 # HP-UX make, and OSF1 make successfully.
1826 || ($directory ne '' && ! option 'subdir-objects')
1827 # We must also use specific rules for a nodist_ source
1828 # if its language requests it.
1829 || ($lang->nodist_specific && ! $transform{'DIST_SOURCE'}))
1831 my $obj_sans_ext = substr ($object, 0,
1832 - length ($this_obj_ext));
1834 if ($directory ne '')
1836 $full_ansi = $directory . '/' . $base . $extension;
1840 $full_ansi = $base . $extension;
1843 my @specifics = ($full_ansi, $obj_sans_ext,
1844 # Only use $this_obj_ext in the derived
1845 # source case because in the other case we
1846 # *don't* want $(OBJEXT) to appear here.
1847 ($derived_source ? $this_obj_ext : '.o'),
1850 # If we renamed the object then we want to use the
1851 # per-executable flag name. But if this is simply a
1852 # subdir build then we still want to use the AM_ flag
1856 unshift @specifics, $derived;
1857 $aggregate = $derived;
1861 unshift @specifics, 'AM';
1864 # Each item on this list is a reference to a list consisting
1865 # of four values followed by additional transform flags for
1866 # file_contents. The four values are the derived flag prefix
1867 # (e.g. for `foo_CFLAGS', it is `foo'), the name of the
1868 # source file, the base name of the output file, and
1869 # the extension for the object file.
1870 push (@{$lang_specific_files{$lang->name}},
1871 [@specifics, %transform]);
1874 elsif ($extension eq $obj)
1876 # This is probably the result of a direct suffix rule.
1877 # In this case we just accept the rewrite.
1878 $object = "$base$extension";
1879 $object = "$directory/$object" if $directory ne '';
1884 # No error message here. Used to have one, but it was
1886 # FIXME: we could potentially do more processing here,
1887 # perhaps treating the new extension as though it were a
1888 # new source extension (as above). This would require
1889 # more restructuring than is appropriate right now.
1893 err_am "object `$object' created by `$full' and `$object_map{$object}'"
1894 if (defined $object_map{$object}
1895 && $object_map{$object} ne $full);
1897 my $comp_val = (($object =~ /\.lo$/)
1898 ? COMPILE_LIBTOOL : COMPILE_ORDINARY);
1899 (my $comp_obj = $object) =~ s/\.lo$/.\$(OBJEXT)/;
1900 if (defined $object_compilation_map{$comp_obj}
1901 && $object_compilation_map{$comp_obj} != 0
1902 # Only see the error once.
1903 && ($object_compilation_map{$comp_obj}
1904 != (COMPILE_LIBTOOL | COMPILE_ORDINARY))
1905 && $object_compilation_map{$comp_obj} != $comp_val)
1907 err_am "object `$comp_obj' created both with libtool and without";
1909 $object_compilation_map{$comp_obj} |= $comp_val;
1913 # Let the language do some special magic if required.
1914 $lang->target_hook ($aggregate, $object, $full, %transform);
1917 if ($derived_source)
1919 prog_error ($lang->name . " has automatic dependency tracking")
1920 if $lang->autodep ne 'no';
1921 # Make sure this new source file is handled next. That will
1922 # make it appear to be at the right place in the list.
1923 unshift (@files, $object);
1924 # Distribute derived sources unless the source they are
1925 # derived from is not.
1926 &push_dist_common ($object)
1927 unless ($topparent =~ /^(?:nobase_)?nodist_/);
1931 $linkers_used{$linker} = 1;
1933 push (@result, $object);
1935 if (! defined $object_map{$object})
1938 $object_map{$object} = $full;
1940 # If resulting object is in subdir, we need to make
1941 # sure the subdir exists at build time.
1942 if ($object =~ /\//)
1944 # FIXME: check that $DIRECTORY is somewhere in the
1947 # For Java, the way we're handling it right now, a
1948 # `..' component doesn't make sense.
1949 if ($lang && $lang->name eq 'java' && $object =~ /(\/|^)\.\.\//)
1951 err_am "`$full' should not contain a `..' component";
1954 # Make sure object is removed by `make mostlyclean'.
1955 $compile_clean_files{$object} = MOSTLY_CLEAN;
1956 # If we have a libtool object then we also must remove
1958 if ($object =~ /\.lo$/)
1960 (my $xobj = $object) =~ s,lo$,\$(OBJEXT),;
1961 $compile_clean_files{$xobj} = MOSTLY_CLEAN;
1963 # Remove any libtool object in this directory.
1964 $libtool_clean_directories{$directory} = 1;
1967 push (@dep_list, require_build_directory ($directory));
1969 # If we're generating dependencies, we also want
1970 # to make sure that the appropriate subdir of the
1971 # .deps directory is created.
1973 require_build_directory ($directory . '/$(DEPDIR)'))
1974 unless option 'no-dependencies';
1977 &pretty_print_rule ($object . ':', "\t", @dep_list)
1978 if scalar @dep_list > 0;
1981 # Transform .o or $o file into .P file (for automatic
1983 # Properly flatten multiple adjacent slashes, as Solaris 10 make
1984 # might fail over them in an include statement.
1985 # Leading double slashes may be special, as per Posix, so deal
1986 # with them carefully.
1987 if ($lang && $lang->autodep ne 'no')
1989 my $depfile = $object;
1990 $depfile =~ s/\.([^.]*)$/.P$1/;
1991 $depfile =~ s/\$\(OBJEXT\)$/o/;
1992 my $maybe_extra_leading_slash = '';
1993 $maybe_extra_leading_slash = '/' if $depfile =~ m,^//[^/],;
1994 $depfile =~ s,/+,/,g;
1995 my $basename = basename ($depfile);
1996 # This might make $dirname empty, but we account for that below.
1997 (my $dirname = dirname ($depfile)) =~ s/\/*$//;
1998 $dirname = $maybe_extra_leading_slash . $dirname;
1999 $dep_files{$dirname . '/$(DEPDIR)/' . $basename} = 1;
2008 # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
2009 # $OBJ, $PARENT, $TOPPARENT, $WHERE, %TRANSFORM)
2010 # ---------------------------------------------------------------------------
2011 # Define an _OBJECTS variable for a _SOURCES variable (or subvariable)
2014 # $VAR is the name of the _SOURCES variable
2015 # $OBJVAR is the name of the _OBJECTS variable if known (otherwise
2016 # it will be generated and returned).
2017 # $NODEFINE is a boolean: if true, $OBJVAR will not be defined (but
2018 # work done to determine the linker will be).
2019 # $ONE_FILE is the canonical (transformed) name of object to build
2020 # $OBJ is the object extension (i.e. either `.o' or `.lo').
2021 # $TOPPARENT is the _SOURCES variable being processed.
2022 # $WHERE context into which this definition is done
2023 # %TRANSFORM extra arguments to pass to file_contents when producing
2026 # Result is a pair ($LINKER, $OBJVAR):
2027 # $LINKER is a boolean, true if a linker is needed to deal with the objects
2028 sub define_objects_from_sources ($$$$$$$%)
2030 my ($var, $objvar, $nodefine, $one_file,
2031 $obj, $topparent, $where, %transform) = @_;
2033 my $needlinker = "";
2035 transform_variable_recursively
2036 ($var, $objvar, 'am__objects', $nodefine, $where,
2037 # The transform code to run on each filename.
2039 my ($subvar, $val, $cond, $full_cond) = @_;
2040 my @trans = handle_single_transform ($subvar, $topparent,
2041 $one_file, $obj, $val,
2043 $needlinker = "true" if @trans;
2051 # handle_source_transform ($CANON_TARGET, $TARGET, $OBJEXT, $WHERE, %TRANSFORM)
2052 # -----------------------------------------------------------------------------
2053 # Handle SOURCE->OBJECT transform for one program or library.
2055 # canonical (transformed) name of target to build
2056 # actual target of object to build
2057 # object extension (i.e., either `.o' or `$o')
2058 # location of the source variable
2059 # extra arguments to pass to file_contents when producing rules
2060 # Return the name of the linker variable that must be used.
2061 # Empty return means just use `LINK'.
2062 sub handle_source_transform ($$$$%)
2064 # one_file is canonical name. unxformed is given name. obj is
2066 my ($one_file, $unxformed, $obj, $where, %transform) = @_;
2070 # No point in continuing if _OBJECTS is defined.
2071 return if reject_var ($one_file . '_OBJECTS',
2072 $one_file . '_OBJECTS should not be defined');
2077 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2078 'dist_EXTRA_', 'nodist_EXTRA_')
2080 my $varname = $prefix . $one_file . "_SOURCES";
2081 my $var = var $varname;
2084 # We are going to define _OBJECTS variables using the prefix.
2085 # Then we glom them all together. So we can't use the null
2086 # prefix here as we need it later.
2087 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2089 # Keep track of which prefixes we saw.
2090 $used_pfx{$xpfx} = 1
2091 unless $prefix =~ /EXTRA_/;
2093 push @sources, "\$($varname)";
2094 push @dist_sources, shadow_unconditionally ($varname, $where)
2095 unless (option ('no-dist') || $prefix =~ /^nodist_/);
2098 define_objects_from_sources ($varname,
2099 $xpfx . $one_file . '_OBJECTS',
2100 $prefix =~ /EXTRA_/,
2101 $one_file, $obj, $varname, $where,
2102 DIST_SOURCE => ($prefix !~ /^nodist_/),
2107 $linker ||= &resolve_linker (%linkers_used);
2110 my @keys = sort keys %used_pfx;
2111 if (scalar @keys == 0)
2113 # The default source for libfoo.la is libfoo.c, but for
2114 # backward compatibility we first look at libfoo_la.c,
2115 # if no default source suffix is given.
2116 my $old_default_source = "$one_file.c";
2117 my $ext_var = var ('AM_DEFAULT_SOURCE_EXT');
2118 my $default_source_ext = $ext_var ? variable_value ($ext_var) : '.c';
2119 msg_var ('unsupported', $ext_var, $ext_var->name . " can assume at most one value")
2120 if $default_source_ext =~ /[\t ]/;
2121 (my $default_source = $unxformed) =~ s,(\.[^./\\]*)?$,$default_source_ext,;
2122 if ($old_default_source ne $default_source
2124 && (rule $old_default_source
2125 || rule '$(srcdir)/' . $old_default_source
2126 || rule '${srcdir}/' . $old_default_source
2127 || -f $old_default_source))
2129 my $loc = $where->clone;
2131 msg ('obsolete', $loc,
2132 "the default source for `$unxformed' has been changed "
2133 . "to `$default_source'.\n(Using `$old_default_source' for "
2134 . "backward compatibility.)");
2135 $default_source = $old_default_source;
2137 # If a rule exists to build this source with a $(srcdir)
2138 # prefix, use that prefix in our variables too. This is for
2139 # the sake of BSD Make.
2140 if (rule '$(srcdir)/' . $default_source
2141 || rule '${srcdir}/' . $default_source)
2143 $default_source = '$(srcdir)/' . $default_source;
2146 &define_variable ($one_file . "_SOURCES", $default_source, $where);
2147 push (@sources, $default_source);
2148 push (@dist_sources, $default_source);
2152 handle_single_transform ($one_file . '_SOURCES',
2153 $one_file . '_SOURCES',
2155 $default_source, %transform);
2156 $linker ||= &resolve_linker (%linkers_used);
2157 define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @result);
2161 @keys = map { '$(' . $_ . $one_file . '_OBJECTS)' } @keys;
2162 define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @keys);
2165 # If we want to use `LINK' we must make sure it is defined.
2175 # handle_lib_objects ($XNAME, $VAR)
2176 # ---------------------------------
2177 # Special-case ALLOCA and LIBOBJS substitutions in _LDADD or _LIBADD variables.
2178 # Also, generate _DEPENDENCIES variable if appropriate.
2180 # transformed name of object being built, or empty string if no object
2181 # name of _LDADD/_LIBADD-type variable to examine
2182 # Returns 1 if LIBOBJS seen, 0 otherwise.
2183 sub handle_lib_objects
2185 my ($xname, $varname) = @_;
2187 my $var = var ($varname);
2188 prog_error "`$varname' undefined"
2190 prog_error "unexpected variable name `$varname'"
2191 unless $varname =~ /^(.*)(?:LIB|LD)ADD$/;
2192 my $prefix = $1 || 'AM_';
2194 my $seen_libobjs = 0;
2197 transform_variable_recursively
2198 ($varname, $xname . '_DEPENDENCIES', 'am__DEPENDENCIES',
2200 # Transformation function, run on each filename.
2202 my ($subvar, $val, $cond, $full_cond) = @_;
2206 # Skip -lfoo and -Ldir silently; these are explicitly allowed.
2207 if ($val !~ /^-[lL]/ &&
2208 # Skip -dlopen and -dlpreopen; these are explicitly allowed
2209 # for Libtool libraries or programs. (Actually we are a bit
2210 # lax here since this code also applies to non-libtool
2211 # libraries or programs, for which -dlopen and -dlopreopen
2212 # are pure nonsense. Diagnosing this doesn't seem very
2213 # important: the developer will quickly get complaints from
2215 $val !~ /^-dl(?:pre)?open$/ &&
2216 # Only get this error once.
2220 # FIXME: should display a stack of nested variables
2221 # as context when $var != $subvar.
2222 err_var ($var, "linker flags such as `$val' belong in "
2223 . "`${prefix}LDFLAGS'");
2227 elsif ($val !~ /^\@.*\@$/)
2229 # Assume we have a file of some sort, and output it into the
2230 # dependency variable. Autoconf substitutions are not output;
2231 # rarely is a new dependency substituted into e.g. foo_LDADD
2232 # -- but bad things (e.g. -lX11) are routinely substituted.
2233 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2234 # and handled specially below.
2237 elsif ($val =~ /^\@(LT)?LIBOBJS\@$/)
2239 handle_LIBOBJS ($subvar, $cond, $1);
2243 elsif ($val =~ /^\@(LT)?ALLOCA\@$/)
2245 handle_ALLOCA ($subvar, $cond, $1);
2254 return $seen_libobjs;
2257 # handle_LIBOBJS_or_ALLOCA ($VAR)
2258 # -------------------------------
2259 # Definitions common to LIBOBJS and ALLOCA.
2260 # VAR should be one of LIBOBJS, LTLIBOBJS, ALLOCA, or LTALLOCA.
2261 sub handle_LIBOBJS_or_ALLOCA ($)
2267 # If LIBOBJS files must be built in another directory we have
2268 # to define LIBOBJDIR and ensure the files get cleaned.
2269 # Otherwise LIBOBJDIR can be left undefined, and the cleaning
2270 # is achieved by `rm -f *.$(OBJEXT)' in compile.am.
2271 if ($config_libobj_dir
2272 && $relative_dir ne $config_libobj_dir)
2274 if (option 'subdir-objects')
2276 # In the top-level Makefile we do not use $(top_builddir), because
2277 # we are already there, and since the targets are built without
2278 # a $(top_builddir), it helps BSD Make to match them with
2280 $dir = "$config_libobj_dir/" if $config_libobj_dir ne '.';
2281 $dir = "$topsrcdir/$dir" if $relative_dir ne '.';
2282 define_variable ('LIBOBJDIR', "$dir", INTERNAL);
2283 $clean_files{"\$($var)"} = MOSTLY_CLEAN;
2284 # If LTLIBOBJS is used, we must also clear LIBOBJS (which might
2285 # be created by libtool as a side-effect of creating LTLIBOBJS).
2286 $clean_files{"\$($var)"} = MOSTLY_CLEAN if $var =~ s/^LT//;
2290 error ("`\$($var)' cannot be used outside `$config_libobj_dir' if"
2291 . " `subdir-objects' is not set");
2298 sub handle_LIBOBJS ($$$)
2300 my ($var, $cond, $lt) = @_;
2301 my $myobjext = $lt ? 'lo' : 'o';
2304 $var->requires_variables ("\@${lt}LIBOBJS\@ used", $lt . 'LIBOBJS')
2305 if ! keys %libsources;
2307 my $dir = handle_LIBOBJS_or_ALLOCA "${lt}LIBOBJS";
2309 foreach my $iter (keys %libsources)
2311 if ($iter =~ /\.[cly]$/)
2313 &saw_extension ($&);
2314 &saw_extension ('.c');
2317 if ($iter =~ /\.h$/)
2319 require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
2321 elsif ($iter ne 'alloca.c')
2323 my $rewrite = $iter;
2324 $rewrite =~ s/\.c$/.P$myobjext/;
2325 $dep_files{$dir . '$(DEPDIR)/' . $rewrite} = 1;
2326 $rewrite = "^" . quotemeta ($iter) . "\$";
2327 # Only require the file if it is not a built source.
2328 my $bs = var ('BUILT_SOURCES');
2329 if (! $bs || ! grep (/$rewrite/, $bs->value_as_list_recursive))
2331 require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
2337 sub handle_ALLOCA ($$$)
2339 my ($var, $cond, $lt) = @_;
2340 my $myobjext = $lt ? 'lo' : 'o';
2342 my $dir = handle_LIBOBJS_or_ALLOCA "${lt}ALLOCA";
2344 $var->requires_variables ("\@${lt}ALLOCA\@ used", $lt . 'ALLOCA');
2345 $dep_files{$dir . '$(DEPDIR)/alloca.P' . $myobjext} = 1;
2346 require_libsource_with_macro ($cond, $var, FOREIGN, 'alloca.c');
2347 &saw_extension ('.c');
2350 # Canonicalize the input parameter
2354 $string =~ tr/A-Za-z0-9_\@/_/c;
2358 # Canonicalize a name, and check to make sure the non-canonical name
2359 # is never used. Returns canonical name. Arguments are name and a
2360 # list of suffixes to check for.
2361 sub check_canonical_spelling
2363 my ($name, @suffixes) = @_;
2365 my $xname = &canonicalize ($name);
2366 if ($xname ne $name)
2368 foreach my $xt (@suffixes)
2370 reject_var ("$name$xt", "use `$xname$xt', not `$name$xt'");
2380 # Set up the compile suite.
2381 sub handle_compile ()
2383 return if ! $must_handle_compiled_objects;
2386 my $default_includes = '';
2387 if (! option 'nostdinc')
2389 my @incs = ('-I.', subst ('am__isrc'));
2391 my $var = var 'CONFIG_HEADER';
2394 foreach my $hdr (split (' ', $var->variable_value))
2396 push @incs, '-I' . dirname ($hdr);
2399 # We want `-I. -I$(srcdir)', but the latter -I is redundant
2400 # and unaesthetic in non-VPATH builds. We use `-I.@am__isrc@`
2401 # instead. It will be replaced by '-I.' or '-I. -I$(srcdir)'.
2402 # Items in CONFIG_HEADER are never in $(srcdir) so it is safe
2403 # to just put @am__isrc@ right after `-I.', without a space.
2404 ($default_includes = ' ' . uniq (@incs)) =~ s/ @/@/;
2407 my (@mostly_rms, @dist_rms);
2408 foreach my $item (sort keys %compile_clean_files)
2410 if ($compile_clean_files{$item} == MOSTLY_CLEAN)
2412 push (@mostly_rms, "\t-rm -f $item");
2414 elsif ($compile_clean_files{$item} == DIST_CLEAN)
2416 push (@dist_rms, "\t-rm -f $item");
2420 prog_error 'invalid entry in %compile_clean_files';
2424 my ($coms, $vars, $rules) =
2425 &file_contents_internal (1, "$libdir/am/compile.am",
2426 new Automake::Location,
2427 ('DEFAULT_INCLUDES' => $default_includes,
2428 'MOSTLYRMS' => join ("\n", @mostly_rms),
2429 'DISTRMS' => join ("\n", @dist_rms)));
2430 $output_vars .= $vars;
2431 $output_rules .= "$coms$rules";
2436 # Handle libtool rules.
2439 return unless var ('LIBTOOL');
2441 # Libtool requires some files, but only at top level.
2442 # (Starting with Libtool 2.0 we do not have to bother. These
2443 # requirements are done with AC_REQUIRE_AUX_FILE.)
2444 require_conf_file_with_macro (TRUE, 'LIBTOOL', FOREIGN, @libtool_files)
2445 if $relative_dir eq '.' && ! $libtool_new_api;
2448 foreach my $item (sort keys %libtool_clean_directories)
2450 my $dir = ($item eq '.') ? '' : "$item/";
2451 # .libs is for Unix, _libs for DOS.
2452 push (@libtool_rms, "\t-rm -rf ${dir}.libs ${dir}_libs");
2455 check_user_variables 'LIBTOOLFLAGS';
2457 # Output the libtool compilation rules.
2458 $output_rules .= &file_contents ('libtool',
2459 new Automake::Location,
2460 LTRMS => join ("\n", @libtool_rms));
2463 # handle_programs ()
2464 # ------------------
2465 # Handle C programs.
2468 my @proglist = &am_install_var ('progs', 'PROGRAMS',
2469 'bin', 'sbin', 'libexec', 'pkglibexec',
2471 return if ! @proglist;
2472 $must_handle_compiled_objects = 1;
2474 my $seen_global_libobjs =
2475 var ('LDADD') && &handle_lib_objects ('', 'LDADD');
2477 foreach my $pair (@proglist)
2479 my ($where, $one_file) = @$pair;
2481 my $seen_libobjs = 0;
2482 my $obj = '.$(OBJEXT)';
2484 $known_programs{$one_file} = $where;
2486 # Canonicalize names and check for misspellings.
2487 my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2488 '_SOURCES', '_OBJECTS',
2491 $where->push_context ("while processing program `$one_file'");
2492 $where->set (INTERNAL->get);
2494 my $linker = &handle_source_transform ($xname, $one_file, $obj, $where,
2495 NONLIBTOOL => 1, LIBTOOL => 0);
2497 if (var ($xname . "_LDADD"))
2499 $seen_libobjs = &handle_lib_objects ($xname, $xname . '_LDADD');
2503 # User didn't define prog_LDADD override. So do it.
2504 &define_variable ($xname . '_LDADD', '$(LDADD)', $where);
2506 # This does a bit too much work. But we need it to
2507 # generate _DEPENDENCIES when appropriate.
2510 $seen_libobjs = &handle_lib_objects ($xname, 'LDADD');
2514 reject_var ($xname . '_LIBADD',
2515 "use `${xname}_LDADD', not `${xname}_LIBADD'");
2517 set_seen ($xname . '_DEPENDENCIES');
2518 set_seen ('EXTRA_' . $xname . '_DEPENDENCIES');
2519 set_seen ($xname . '_LDFLAGS');
2521 # Determine program to use for link.
2522 my($xlink, $vlink) = &define_per_target_linker_variable ($linker, $xname);
2523 $vlink = verbose_flag ($vlink || 'GEN');
2525 # If the resulting program lies into a subdirectory,
2526 # make sure this directory will exist.
2527 my $dirstamp = require_build_directory_maybe ($one_file);
2529 $libtool_clean_directories{dirname ($one_file)} = 1;
2531 $output_rules .= &file_contents ('program',
2533 PROGRAM => $one_file,
2537 DIRSTAMP => $dirstamp,
2538 EXEEXT => '$(EXEEXT)');
2540 if ($seen_libobjs || $seen_global_libobjs)
2542 if (var ($xname . '_LDADD'))
2544 &check_libobjs_sources ($xname, $xname . '_LDADD');
2546 elsif (var ('LDADD'))
2548 &check_libobjs_sources ($xname, 'LDADD');
2555 # handle_libraries ()
2556 # -------------------
2558 sub handle_libraries
2560 my @liblist = &am_install_var ('libs', 'LIBRARIES',
2561 'lib', 'pkglib', 'noinst', 'check');
2562 return if ! @liblist;
2563 $must_handle_compiled_objects = 1;
2565 my @prefix = am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2570 my $var = rvar ($prefix[0] . '_LIBRARIES');
2571 $var->requires_variables ('library used', 'RANLIB');
2574 &define_variable ('AR', 'ar', INTERNAL);
2575 &define_variable ('ARFLAGS', 'cru', INTERNAL);
2576 &define_verbose_tagvar ('AR');
2578 foreach my $pair (@liblist)
2580 my ($where, $onelib) = @$pair;
2582 my $seen_libobjs = 0;
2583 # Check that the library fits the standard naming convention.
2584 my $bn = basename ($onelib);
2585 if ($bn !~ /^lib.*\.a$/)
2587 $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.a/;
2588 my $suggestion = dirname ($onelib) . "/$bn";
2589 $suggestion =~ s|^\./||g;
2590 msg ('error-gnu/warn', $where,
2591 "`$onelib' is not a standard library name\n"
2592 . "did you mean `$suggestion'?")
2595 ($known_libraries{$onelib} = $bn) =~ s/\.a$//;
2597 $where->push_context ("while processing library `$onelib'");
2598 $where->set (INTERNAL->get);
2600 my $obj = '.$(OBJEXT)';
2602 # Canonicalize names and check for misspellings.
2603 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2604 '_OBJECTS', '_DEPENDENCIES',
2607 if (! var ($xlib . '_AR'))
2609 &define_variable ($xlib . '_AR', '$(AR) $(ARFLAGS)', $where);
2612 # Generate support for conditional object inclusion in
2614 if (var ($xlib . '_LIBADD'))
2616 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2623 &define_variable ($xlib . "_LIBADD", '', $where);
2626 reject_var ($xlib . '_LDADD',
2627 "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
2629 # Make sure we at look at this.
2630 set_seen ($xlib . '_DEPENDENCIES');
2631 set_seen ('EXTRA_' . $xlib . '_DEPENDENCIES');
2633 &handle_source_transform ($xlib, $onelib, $obj, $where,
2634 NONLIBTOOL => 1, LIBTOOL => 0);
2636 # If the resulting library lies into a subdirectory,
2637 # make sure this directory will exist.
2638 my $dirstamp = require_build_directory_maybe ($onelib);
2639 my $verbose = verbose_flag ('AR');
2640 my $silent = silent_flag ();
2642 $output_rules .= &file_contents ('library',
2644 VERBOSE => $verbose,
2648 DIRSTAMP => $dirstamp);
2652 if (var ($xlib . '_LIBADD'))
2654 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2660 msg ('extra-portability', $where,
2661 "`$onelib': linking libraries using a non-POSIX\n"
2662 . "archiver requires `AM_PROG_AR' in `$configure_ac'")
2668 # handle_ltlibraries ()
2669 # ---------------------
2670 # Handle shared libraries.
2671 sub handle_ltlibraries
2673 my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2674 'noinst', 'lib', 'pkglib', 'check');
2675 return if ! @liblist;
2676 $must_handle_compiled_objects = 1;
2678 my @prefix = am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2683 my $var = rvar ($prefix[0] . '_LTLIBRARIES');
2684 $var->requires_variables ('Libtool library used', 'LIBTOOL');
2688 my %instsubdirs = ();
2690 my %liblocations = (); # Location (in Makefile.am) of each library.
2692 foreach my $key (@prefix)
2694 # Get the installation directory of each library.
2696 my $strip_subdir = 1;
2697 if ($dir =~ /^nobase_/)
2699 $dir =~ s/^nobase_//;
2702 my $var = rvar ($key . '_LTLIBRARIES');
2704 # We reject libraries which are installed in several places
2705 # in the same condition, because we can only specify one
2707 $var->traverse_recursively
2710 my ($var, $val, $cond, $full_cond) = @_;
2711 my $hcond = $full_cond->human;
2712 my $where = $var->rdef ($cond)->location;
2714 $ldir = '/' . dirname ($val)
2715 if (!$strip_subdir);
2716 # A library cannot be installed in different directories
2717 # in overlapping conditions.
2718 if (exists $instconds{$val})
2721 $instconds{$val}->ambiguous_p ($val, $full_cond);
2725 error ($where, $msg, partial => 1);
2726 my $dirtxt = "installed " . ($strip_subdir ? "in" : "below") . " `$dir'";
2727 $dirtxt = "built for `$dir'"
2728 if $dir eq 'EXTRA' || $dir eq 'noinst' || $dir eq 'check';
2730 $full_cond->true ? "" : " in condition $hcond";
2732 error ($where, "`$val' should be $dirtxt$dircond ...",
2735 my $hacond = $acond->human;
2736 my $adir = $instdirs{$val}{$acond};
2737 my $adirtxt = "installed in `$adir'";
2738 $adirtxt = "built for `$adir'"
2739 if ($adir eq 'EXTRA' || $adir eq 'noinst'
2740 || $adir eq 'check');
2741 my $adircond = $acond->true ? "" : " in condition $hacond";
2743 my $onlyone = ($dir ne $adir) ?
2744 ("\nLibtool libraries can be built for only one "
2745 . "destination") : "";
2747 error ($liblocations{$val}{$acond},
2748 "... and should also be $adirtxt$adircond.$onlyone");
2754 $instconds{$val} = new Automake::DisjConditions;
2756 $instdirs{$val}{$full_cond} = $dir;
2757 $instsubdirs{$val}{$full_cond} = $ldir;
2758 $liblocations{$val}{$full_cond} = $where;
2759 $instconds{$val} = $instconds{$val}->merge ($full_cond);
2765 skip_ac_subst => 1);
2768 foreach my $pair (@liblist)
2770 my ($where, $onelib) = @$pair;
2772 my $seen_libobjs = 0;
2775 # Canonicalize names and check for misspellings.
2776 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2777 '_SOURCES', '_OBJECTS',
2780 # Check that the library fits the standard naming convention.
2781 my $libname_rx = '^lib.*\.la';
2782 my $ldvar = var ("${xlib}_LDFLAGS") || var ('AM_LDFLAGS');
2783 my $ldvar2 = var ('LDFLAGS');
2784 if (($ldvar && grep (/-module/, $ldvar->value_as_list_recursive))
2785 || ($ldvar2 && grep (/-module/, $ldvar2->value_as_list_recursive)))
2787 # Relax name checking for libtool modules.
2788 $libname_rx = '\.la';
2791 my $bn = basename ($onelib);
2792 if ($bn !~ /$libname_rx$/)
2794 my $type = 'library';
2795 if ($libname_rx eq '\.la')
2797 $bn =~ s/^(lib|)(.*?)(?:\.[^.]*)?$/$1$2.la/;
2802 $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.la/;
2804 my $suggestion = dirname ($onelib) . "/$bn";
2805 $suggestion =~ s|^\./||g;
2806 msg ('error-gnu/warn', $where,
2807 "`$onelib' is not a standard libtool $type name\n"
2808 . "did you mean `$suggestion'?")
2811 ($known_libraries{$onelib} = $bn) =~ s/\.la$//;
2813 $where->push_context ("while processing Libtool library `$onelib'");
2814 $where->set (INTERNAL->get);
2816 # Make sure we look at these.
2817 set_seen ($xlib . '_LDFLAGS');
2818 set_seen ($xlib . '_DEPENDENCIES');
2819 set_seen ('EXTRA_' . $xlib . '_DEPENDENCIES');
2821 # Generate support for conditional object inclusion in
2823 if (var ($xlib . '_LIBADD'))
2825 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2832 &define_variable ($xlib . "_LIBADD", '', $where);
2835 reject_var ("${xlib}_LDADD",
2836 "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
2839 my $linker = &handle_source_transform ($xlib, $onelib, $obj, $where,
2840 NONLIBTOOL => 0, LIBTOOL => 1);
2842 # Determine program to use for link.
2843 my($xlink, $vlink) = &define_per_target_linker_variable ($linker, $xlib);
2844 $vlink = verbose_flag ($vlink || 'GEN');
2846 my $rpathvar = "am_${xlib}_rpath";
2847 my $rpath = "\$($rpathvar)";
2848 foreach my $rcond ($instconds{$onelib}->conds)
2851 if ($instdirs{$onelib}{$rcond} eq 'EXTRA'
2852 || $instdirs{$onelib}{$rcond} eq 'noinst'
2853 || $instdirs{$onelib}{$rcond} eq 'check')
2855 # It's an EXTRA_ library, so we can't specify -rpath,
2856 # because we don't know where the library will end up.
2857 # The user probably knows, but generally speaking automake
2858 # doesn't -- and in fact configure could decide
2859 # dynamically between two different locations.
2864 $val = ('-rpath $(' . $instdirs{$onelib}{$rcond} . 'dir)');
2865 $val .= $instsubdirs{$onelib}{$rcond}
2866 if defined $instsubdirs{$onelib}{$rcond};
2870 # If $rcond is true there is only one condition and
2871 # there is no point defining an helper variable.
2876 define_pretty_variable ($rpathvar, $rcond, INTERNAL, $val);
2880 # If the resulting library lies into a subdirectory,
2881 # make sure this directory will exist.
2882 my $dirstamp = require_build_directory_maybe ($onelib);
2884 # Remember to cleanup .libs/ in this directory.
2885 my $dirname = dirname $onelib;
2886 $libtool_clean_directories{$dirname} = 1;
2888 $output_rules .= &file_contents ('ltlibrary',
2890 LTLIBRARY => $onelib,
2891 XLTLIBRARY => $xlib,
2895 DIRSTAMP => $dirstamp);
2898 if (var ($xlib . '_LIBADD'))
2900 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2906 msg ('extra-portability', $where,
2907 "`$onelib': linking libtool libraries using a non-POSIX\n"
2908 . "archiver requires `AM_PROG_AR' in `$configure_ac'")
2913 # See if any _SOURCES variable were misspelled.
2916 # It is ok if the user sets this particular variable.
2917 set_seen 'AM_LDFLAGS';
2919 foreach my $primary ('SOURCES', 'LIBADD', 'LDADD', 'LDFLAGS', 'DEPENDENCIES')
2921 foreach my $var (variables $primary)
2923 my $varname = $var->name;
2924 # A configure variable is always legitimate.
2925 next if exists $configure_vars{$varname};
2927 for my $cond ($var->conditions->conds)
2929 $varname =~ /^(?:EXTRA_)?(?:nobase_)?(?:dist_|nodist_)?(.*)_[[:alnum:]]+$/;
2930 msg_var ('syntax', $var, "variable `$varname' is defined but no"
2931 . " program or\nlibrary has `$1' as canonical name"
2932 . " (possible typo)")
2933 unless $var->rdef ($cond)->seen;
2943 # NOTE we no longer automatically clean SCRIPTS, because it is
2944 # useful to sometimes distribute scripts verbatim. This happens
2945 # e.g. in Automake itself.
2946 &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2947 'bin', 'sbin', 'libexec', 'pkglibexec', 'pkgdata',
2954 ## ------------------------ ##
2955 ## Handling Texinfo files. ##
2956 ## ------------------------ ##
2958 # ($OUTFILE, $VFILE, @CLEAN_FILES)
2959 # &scan_texinfo_file ($FILENAME)
2960 # ------------------------------
2961 # $OUTFILE - name of the info file produced by $FILENAME.
2962 # $VFILE - name of the version.texi file used (undef if none).
2963 # @CLEAN_FILES - list of byproducts (indexes etc.)
2964 sub scan_texinfo_file ($)
2966 my ($filename) = @_;
2968 # Some of the following extensions are always created, no matter
2969 # whether indexes are used or not. Other (like cps, fns, ... pgs)
2970 # are only created when they are used. We used to scan $FILENAME
2971 # for their use, but that is not enough: they could be used in
2972 # included files. We can't scan included files because we don't
2973 # know the include path. Therefore we always erase these files, no
2974 # matter whether they are used or not.
2976 # (tmp is only created if an @macro is used and a certain e-TeX
2977 # feature is not available.)
2978 my %clean_suffixes =
2979 map { $_ => 1 } (qw(aux log toc tmp
2985 pg pgs)); # grep 'new.*index' texinfo.tex
2987 my $texi = new Automake::XFile "< $filename";
2988 verb "reading $filename";
2990 my ($outfile, $vfile);
2991 while ($_ = $texi->getline)
2993 if (/^\@setfilename +(\S+)/)
2995 # Honor only the first @setfilename. (It's possible to have
2996 # more occurrences later if the manual shows examples of how
2997 # to use @setfilename...)
3001 if ($outfile =~ /\.([^.]+)$/ && $1 ne 'info')
3003 error ("$filename:$.",
3004 "output `$outfile' has unrecognized extension");
3008 # A "version.texi" file is actually any file whose name matches
3010 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
3015 # Try to find new or unused indexes.
3017 # Creating a new category of index.
3018 elsif (/^\@def(code)?index (\w+)/)
3020 $clean_suffixes{$2} = 1;
3021 $clean_suffixes{"$2s"} = 1;
3024 # Merging an index into an another.
3025 elsif (/^\@syn(code)?index (\w+) (\w+)/)
3027 delete $clean_suffixes{"$2s"};
3028 $clean_suffixes{"$3s"} = 1;
3035 err_am "`$filename' missing \@setfilename";
3039 my $infobase = basename ($filename);
3040 $infobase =~ s/\.te?xi(nfo)?$//;
3041 return ($outfile, $vfile,
3042 map { "$infobase.$_" } (sort keys %clean_suffixes));
3046 # ($DIRSTAMP, @CLEAN_FILES)
3047 # output_texinfo_build_rules ($SOURCE, $DEST, $INSRC, @DEPENDENCIES)
3048 # ------------------------------------------------------------------
3049 # SOURCE - the source Texinfo file
3050 # DEST - the destination Info file
3051 # INSRC - whether DEST should be built in the source tree
3052 # DEPENDENCIES - known dependencies
3053 sub output_texinfo_build_rules ($$$@)
3055 my ($source, $dest, $insrc, @deps) = @_;
3057 # Split `a.texi' into `a' and `.texi'.
3058 my ($spfx, $ssfx) = ($source =~ /^(.*?)(\.[^.]*)?$/);
3059 my ($dpfx, $dsfx) = ($dest =~ /^(.*?)(\.[^.]*)?$/);
3064 # We can output two kinds of rules: the "generic" rules use Make
3065 # suffix rules and are appropriate when $source and $dest do not lie
3066 # in a sub-directory; the "specific" rules are needed in the other
3069 # The former are output only once (this is not really apparent here,
3070 # but just remember that some logic deeper in Automake will not
3071 # output the same rule twice); while the later need to be output for
3072 # each Texinfo source.
3075 my $sdir = dirname $source;
3076 if ($sdir eq '.' && dirname ($dest) eq '.')
3079 $makeinfoflags = '-I $(srcdir)';
3084 $makeinfoflags = "-I $sdir -I \$(srcdir)/$sdir";
3087 # A directory can contain two kinds of info files: some built in the
3088 # source tree, and some built in the build tree. The rules are
3089 # different in each case. However we cannot output two different
3090 # set of generic rules. Because in-source builds are more usual, we
3091 # use generic rules in this case and fall back to "specific" rules
3092 # for build-dir builds. (It should not be a problem to invert this
3094 $generic = 0 unless $insrc;
3096 # We cannot use a suffix rule to build info files with an empty
3097 # extension. Otherwise we would output a single suffix inference
3098 # rule, with separate dependencies, as in
3102 # foo.info: foo.texi
3104 # which confuse Solaris make. (See the Autoconf manual for
3105 # details.) Therefore we use a specific rule in this case. This
3106 # applies to info files only (dvi and pdf files always have an
3108 my $generic_info = ($generic && $dsfx) ? 1 : 0;
3110 # If the resulting file lie into a subdirectory,
3111 # make sure this directory will exist.
3112 my $dirstamp = require_build_directory_maybe ($dest);
3114 my $dipfx = ($insrc ? '$(srcdir)/' : '') . $dpfx;
3116 $output_rules .= file_contents ('texibuild',
3117 new Automake::Location,
3118 AM_V_MAKEINFO => verbose_flag('MAKEINFO'),
3119 AM_V_TEXI2DVI => verbose_flag('TEXI2DVI'),
3120 AM_V_TEXI2PDF => verbose_flag('TEXI2PDF'),
3122 DEST_PREFIX => $dpfx,
3123 DEST_INFO_PREFIX => $dipfx,
3124 DEST_SUFFIX => $dsfx,
3125 DIRSTAMP => $dirstamp,
3126 GENERIC => $generic,
3127 GENERIC_INFO => $generic_info,
3129 MAKEINFOFLAGS => $makeinfoflags,
3130 SILENT => silent_flag(),
3133 SOURCE_INFO => ($generic_info
3135 SOURCE_REAL => $source,
3136 SOURCE_SUFFIX => $ssfx,
3137 TEXIQUIET => verbose_flag('texinfo'),
3138 TEXIDEVNULL => verbose_flag('texidevnull'),
3140 return ($dirstamp, "$dpfx.dvi", "$dpfx.pdf", "$dpfx.ps", "$dpfx.html");
3144 # ($MOSTLYCLEAN, $TEXICLEAN, $MAINTCLEAN)
3145 # handle_texinfo_helper ($info_texinfos)
3146 # --------------------------------------
3147 # Handle all Texinfo source; helper for handle_texinfo.
3148 sub handle_texinfo_helper ($)
3150 my ($info_texinfos) = @_;
3151 my (@infobase, @info_deps_list, @texi_deps);
3154 my (@mostly_cleans, @texi_cleans, @maint_cleans) = ('', '', '');
3156 # Build a regex matching user-cleaned files.
3157 my $d = var 'DISTCLEANFILES';
3158 my $c = var 'CLEANFILES';
3160 push @f, $d->value_as_list_recursive (inner_expand => 1) if $d;
3161 push @f, $c->value_as_list_recursive (inner_expand => 1) if $c;
3162 @f = map { s|[^A-Za-z_0-9*\[\]\-]|\\$&|g; s|\*|[^/]*|g; $_; } @f;
3163 my $user_cleaned_files = '^(?:' . join ('|', @f) . ')$';
3166 ($info_texinfos->value_as_list_recursive (inner_expand => 1))
3168 my $infobase = $texi;
3169 $infobase =~ s/\.(txi|texinfo|texi)$//;
3171 if ($infobase eq $texi)
3173 # FIXME: report line number.
3174 err_am "texinfo file `$texi' has unrecognized extension";
3178 push @infobase, $infobase;
3180 # If 'version.texi' is referenced by input file, then include
3181 # automatic versioning capability.
3182 my ($out_file, $vtexi, @clean_files) =
3183 scan_texinfo_file ("$relative_dir/$texi")
3185 push (@mostly_cleans, @clean_files);
3187 # If the Texinfo source is in a subdirectory, create the
3188 # resulting info in this subdirectory. If it is in the current
3189 # directory, try hard to not prefix "./" because it breaks the
3191 my $outdir = dirname ($texi) . '/';
3192 $outdir = "" if $outdir eq './';
3193 $out_file = $outdir . $out_file;
3195 # Until Automake 1.6.3, .info files were built in the
3196 # source tree. This was an obstacle to the support of
3197 # non-distributed .info files, and non-distributed .texi
3200 # * Non-distributed .texi files is important in some packages
3201 # where .texi files are built at make time, probably using
3202 # other binaries built in the package itself, maybe using
3203 # tools or information found on the build host. Because
3204 # these files are not distributed they are always rebuilt
3205 # at make time; they should therefore not lie in the source
3206 # directory. One plan was to support this using
3207 # nodist_info_TEXINFOS or something similar. (Doing this
3208 # requires some sanity checks. For instance Automake should
3210 # dist_info_TEXINFOS = foo.texi
3211 # nodist_foo_TEXINFOS = included.texi
3212 # because a distributed file should never depend on a
3213 # non-distributed file.)
3215 # * If .texi files are not distributed, then .info files should
3216 # not be distributed either. There are also cases where one
3217 # wants to distribute .texi files, but does not want to
3218 # distribute the .info files. For instance the Texinfo package
3219 # distributes the tool used to build these files; it would
3220 # be a waste of space to distribute them. It's not clear
3221 # which syntax we should use to indicate that .info files should
3222 # not be distributed. Akim Demaille suggested that eventually
3223 # we switch to a new syntax:
3224 # | Maybe we should take some inspiration from what's already
3225 # | done in the rest of Automake. Maybe there is too much
3226 # | syntactic sugar here, and you want
3227 # | nodist_INFO = bar.info
3228 # | dist_bar_info_SOURCES = bar.texi
3229 # | bar_texi_DEPENDENCIES = foo.texi
3230 # | with a bit of magic to have bar.info represent the whole
3231 # | bar*info set. That's a lot more verbose that the current
3232 # | situation, but it is # not new, hence the user has less
3235 # | But there is still too much room for meaningless specs:
3236 # | nodist_INFO = bar.info
3237 # | dist_bar_info_SOURCES = bar.texi
3238 # | dist_PS = bar.ps something-written-by-hand.ps
3239 # | nodist_bar_ps_SOURCES = bar.texi
3240 # | bar_texi_DEPENDENCIES = foo.texi
3241 # | here bar.texi is dist_ in line 2, and nodist_ in 4.
3243 # Back to the point, it should be clear that in order to support
3244 # non-distributed .info files, we need to build them in the
3245 # build tree, not in the source tree (non-distributed .texi
3246 # files are less of a problem, because we do not output build
3247 # rules for them). In Automake 1.7 .info build rules have been
3248 # largely cleaned up so that .info files get always build in the
3249 # build tree, even when distributed. The idea was that
3250 # (1) if during a VPATH build the .info file was found to be
3251 # absent or out-of-date (in the source tree or in the
3252 # build tree), Make would rebuild it in the build tree.
3253 # If an up-to-date source-tree of the .info file existed,
3254 # make would not rebuild it in the build tree.
3255 # (2) having two copies of .info files, one in the source tree
3256 # and one (newer) in the build tree is not a problem
3257 # because `make dist' always pick files in the build tree
3259 # However it turned out the be a bad idea for several reasons:
3260 # * Tru64, OpenBSD, and FreeBSD (not NetBSD) Make do not behave
3261 # like GNU Make on point (1) above. These implementations
3262 # of Make would always rebuild .info files in the build
3263 # tree, even if such files were up to date in the source
3264 # tree. Consequently, it was impossible to perform a VPATH
3265 # build of a package containing Texinfo files using these
3266 # Make implementations.
3267 # (Refer to the Autoconf Manual, section "Limitation of
3268 # Make", paragraph "VPATH", item "target lookup", for
3269 # an account of the differences between these
3271 # * The GNU Coding Standards require these files to be built
3272 # in the source-tree (when they are distributed, that is).
3273 # * Keeping a fresher copy of distributed files in the
3274 # build tree can be annoying during development because
3275 # - if the files is kept under CVS, you really want it
3276 # to be updated in the source tree
3277 # - it is confusing that `make distclean' does not erase
3278 # all files in the build tree.
3280 # Consequently, starting with Automake 1.8, .info files are
3281 # built in the source tree again. Because we still plan to
3282 # support non-distributed .info files at some point, we
3283 # have a single variable ($INSRC) that controls whether
3284 # the current .info file must be built in the source tree
3285 # or in the build tree. Actually this variable is switched
3286 # off for .info files that appear to be cleaned; this is
3287 # for backward compatibility with package such as Texinfo,
3288 # which do things like
3289 # info_TEXINFOS = texinfo.txi info-stnd.texi info.texi
3290 # DISTCLEANFILES = texinfo texinfo-* info*.info*
3291 # # Do not create info files for distribution.
3293 # in order not to distribute .info files.
3294 my $insrc = ($out_file =~ $user_cleaned_files) ? 0 : 1;
3296 my $soutdir = '$(srcdir)/' . $outdir;
3297 $outdir = $soutdir if $insrc;
3299 # If user specified file_TEXINFOS, then use that as explicit
3302 push (@texi_deps, "$soutdir$vtexi") if $vtexi;
3304 my $canonical = canonicalize ($infobase);
3305 if (var ($canonical . "_TEXINFOS"))
3307 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
3308 push_dist_common ('$(' . $canonical . '_TEXINFOS)');
3311 my ($dirstamp, @cfiles) =
3312 output_texinfo_build_rules ($texi, $out_file, $insrc, @texi_deps);
3313 push (@texi_cleans, @cfiles);
3315 push (@info_deps_list, $out_file);
3317 # If a vers*.texi file is needed, emit the rule.
3320 err_am ("`$vtexi', included in `$texi', "
3321 . "also included in `$versions{$vtexi}'")
3322 if defined $versions{$vtexi};
3323 $versions{$vtexi} = $texi;
3325 # We number the stamp-vti files. This is doable since the
3326 # actual names don't matter much. We only number starting
3327 # with the second one, so that the common case looks nice.
3328 my $vti = ($done ? $done : 'vti');
3331 # This is ugly, but it is our historical practice.
3332 if ($config_aux_dir_set_in_configure_ac)
3334 require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3339 require_file_with_macro (TRUE, 'info_TEXINFOS',
3340 FOREIGN, 'mdate-sh');
3344 if ($config_aux_dir_set_in_configure_ac)
3346 $conf_dir = "$am_config_aux_dir/";
3350 $conf_dir = '$(srcdir)/';
3352 $output_rules .= file_contents ('texi-vers',
3353 new Automake::Location,
3356 STAMPVTI => "${soutdir}stamp-$vti",
3357 VTEXI => "$soutdir$vtexi",
3359 DIRSTAMP => $dirstamp);
3363 # Handle location of texinfo.tex.
3364 my $need_texi_file = 0;
3366 if (var ('TEXINFO_TEX'))
3368 # The user defined TEXINFO_TEX so assume he knows what he is
3370 $texinfodir = ('$(srcdir)/'
3371 . dirname (variable_value ('TEXINFO_TEX')));
3373 elsif (option 'cygnus')
3375 $texinfodir = '$(top_srcdir)/../texinfo';
3376 define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex", INTERNAL);
3378 elsif ($config_aux_dir_set_in_configure_ac)
3380 $texinfodir = $am_config_aux_dir;
3381 define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex", INTERNAL);
3382 $need_texi_file = 2; # so that we require_conf_file later
3386 $texinfodir = '$(srcdir)';
3387 $need_texi_file = 1;
3389 define_variable ('am__TEXINFO_TEX_DIR', $texinfodir, INTERNAL);
3391 push (@dist_targets, 'dist-info');
3393 if (! option 'no-installinfo')
3395 # Make sure documentation is made and installed first. Use
3396 # $(INFO_DEPS), not 'info', because otherwise recursive makes
3397 # get run twice during "make all".
3398 unshift (@all, '$(INFO_DEPS)');
3401 define_files_variable ("DVIS", @infobase, 'dvi', INTERNAL);
3402 define_files_variable ("PDFS", @infobase, 'pdf', INTERNAL);
3403 define_files_variable ("PSS", @infobase, 'ps', INTERNAL);
3404 define_files_variable ("HTMLS", @infobase, 'html', INTERNAL);
3406 # This next isn't strictly needed now -- the places that look here
3407 # could easily be changed to look in info_TEXINFOS. But this is
3408 # probably better, in case noinst_TEXINFOS is ever supported.
3409 define_variable ("TEXINFOS", variable_value ('info_TEXINFOS'), INTERNAL);
3411 # Do some error checking. Note that this file is not required
3412 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3414 if ($need_texi_file && ! option 'no-texinfo.tex')
3416 if ($need_texi_file > 1)
3418 require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3423 require_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3428 return (makefile_wrap ("", "\t ", @mostly_cleans),
3429 makefile_wrap ("", "\t ", @texi_cleans),
3430 makefile_wrap ("", "\t ", @maint_cleans));
3436 # Handle all Texinfo source.
3437 sub handle_texinfo ()
3439 reject_var 'TEXINFOS', "`TEXINFOS' is an anachronism; use `info_TEXINFOS'";
3440 # FIXME: I think this is an obsolete future feature name.
3441 reject_var 'html_TEXINFOS', "HTML generation not yet supported";
3443 my $info_texinfos = var ('info_TEXINFOS');
3444 my ($mostlyclean, $clean, $maintclean) = ('', '', '');
3447 define_verbose_texinfo;
3448 ($mostlyclean, $clean, $maintclean) = handle_texinfo_helper ($info_texinfos);
3454 $output_rules .= file_contents ('texinfos',
3455 new Automake::Location,
3456 AM_V_DVIPS => verbose_flag('DVIPS'),
3457 MOSTLYCLEAN => $mostlyclean,
3458 TEXICLEAN => $clean,
3459 MAINTCLEAN => $maintclean,
3460 'LOCAL-TEXIS' => !!$info_texinfos,
3461 TEXIQUIET => verbose_flag('texinfo'));
3465 # Handle any man pages.
3466 sub handle_man_pages
3468 reject_var 'MANS', "`MANS' is an anachronism; use `man_MANS'";
3470 # Find all the sections in use. We do this by first looking for
3471 # "standard" sections, and then looking for any additional
3472 # sections used in man_MANS.
3473 my (%sections, %notrans_sections, %trans_sections,
3474 %notrans_vars, %trans_vars, %notrans_sect_vars, %trans_sect_vars);
3475 # We handle nodist_ for uniformity. man pages aren't distributed
3476 # by default so it isn't actually very important.
3477 foreach my $npfx ('', 'notrans_')
3479 foreach my $pfx ('', 'dist_', 'nodist_')
3481 # Add more sections as needed.
3482 foreach my $section ('0'..'9', 'n', 'l')
3484 my $varname = $npfx . $pfx . 'man' . $section . '_MANS';
3487 $sections{$section} = 1;
3488 $varname = '$(' . $varname . ')';
3489 if ($npfx eq 'notrans_')
3491 $notrans_sections{$section} = 1;
3492 $notrans_sect_vars{$varname} = 1;
3496 $trans_sections{$section} = 1;
3497 $trans_sect_vars{$varname} = 1;
3500 &push_dist_common ($varname)
3505 my $varname = $npfx . $pfx . 'man_MANS';
3506 my $var = var ($varname);
3509 foreach ($var->value_as_list_recursive)
3511 # A page like `foo.1c' goes into man1dir.
3512 if (/\.([0-9a-z])([a-z]*)$/)
3515 if ($npfx eq 'notrans_')
3517 $notrans_sections{$1} = 1;
3521 $trans_sections{$1} = 1;
3526 $varname = '$(' . $varname . ')';
3527 if ($npfx eq 'notrans_')
3529 $notrans_vars{$varname} = 1;
3533 $trans_vars{$varname} = 1;
3535 &push_dist_common ($varname)
3541 return unless %sections;
3545 # Build section independent variables.
3546 my $have_notrans = %notrans_vars;
3547 my @notrans_list = sort keys %notrans_vars;
3548 my $have_trans = %trans_vars;
3549 my @trans_list = sort keys %trans_vars;
3551 # Now for each section, generate an install and uninstall rule.
3552 # Sort sections so output is deterministic.
3553 foreach my $section (sort keys %sections)
3555 # Build section dependent variables.
3556 my $notrans_mans = $have_notrans || exists $notrans_sections{$section};
3557 my $trans_mans = $have_trans || exists $trans_sections{$section};
3558 my (%notrans_this_sect, %trans_this_sect);
3559 my $expr = 'man' . $section . '_MANS';
3560 foreach my $varname (keys %notrans_sect_vars)
3562 if ($varname =~ /$expr/)
3564 $notrans_this_sect{$varname} = 1;
3567 foreach my $varname (keys %trans_sect_vars)
3569 if ($varname =~ /$expr/)
3571 $trans_this_sect{$varname} = 1;
3574 my @notrans_sect_list = sort keys %notrans_this_sect;
3575 my @trans_sect_list = sort keys %trans_this_sect;
3576 @unsorted_deps = (keys %notrans_vars, keys %trans_vars,
3577 keys %notrans_this_sect, keys %trans_this_sect);
3578 my @deps = sort @unsorted_deps;
3579 $output_rules .= &file_contents ('mans',
3580 new Automake::Location,
3581 SECTION => $section,
3583 NOTRANS_MANS => $notrans_mans,
3584 NOTRANS_SECT_LIST => "@notrans_sect_list",
3585 HAVE_NOTRANS => $have_notrans,
3586 NOTRANS_LIST => "@notrans_list",
3587 TRANS_MANS => $trans_mans,
3588 TRANS_SECT_LIST => "@trans_sect_list",
3589 HAVE_TRANS => $have_trans,
3590 TRANS_LIST => "@trans_list");
3593 @unsorted_deps = (keys %notrans_vars, keys %trans_vars,
3594 keys %notrans_sect_vars, keys %trans_sect_vars);
3595 my @mans = sort @unsorted_deps;
3596 $output_vars .= file_contents ('mans-vars',
3597 new Automake::Location,
3600 push (@all, '$(MANS)')
3601 unless option 'no-installman';
3604 # Handle DATA variables.
3607 &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3608 'data', 'dataroot', 'doc', 'dvi', 'html', 'pdf',
3609 'ps', 'sysconf', 'sharedstate', 'localstate',
3610 'pkgdata', 'lisp', 'noinst', 'check');
3618 my @cscope_deps = ();
3619 if (var ('SUBDIRS'))
3621 $output_rules .= ("tags-recursive:\n"
3622 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3623 # Never fail here if a subdir fails; it
3625 . "\t test \"\$\$subdir\" = . || (\$(am__cd) \$\$subdir"
3626 . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3628 push (@tag_deps, 'tags-recursive');
3629 &depend ('.PHONY', 'tags-recursive');
3630 &depend ('.MAKE', 'tags-recursive');
3632 $output_rules .= ("ctags-recursive:\n"
3633 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3634 # Never fail here if a subdir fails; it
3636 . "\t test \"\$\$subdir\" = . || (\$(am__cd) \$\$subdir"
3637 . " && \$(MAKE) \$(AM_MAKEFLAGS) ctags); \\\n"
3639 push (@ctag_deps, 'ctags-recursive');
3640 &depend ('.PHONY', 'ctags-recursive');
3641 &depend ('.MAKE', 'ctags-recursive');
3643 $output_rules .= ("cscopelist-recursive:\n"
3644 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3645 # Never fail here if a subdir fails; it
3647 . "\t test \"\$\$subdir\" = . || (\$(am__cd) \$\$subdir"
3648 . " && \$(MAKE) \$(AM_MAKEFLAGS) cscopelist); \\\n"
3650 push (@cscope_deps, 'cscopelist-recursive');
3651 &depend ('.PHONY', 'cscopelist-recursive');
3652 &depend ('.MAKE', 'cscopelist-recursive');
3655 if (&saw_sources_p (1)
3656 || var ('ETAGS_ARGS')
3660 foreach my $spec (@config_headers)
3662 my ($out, @ins) = split_config_file_spec ($spec);
3663 foreach my $in (@ins)
3665 # If the config header source is in this directory,
3667 push @config, basename ($in)
3668 if $relative_dir eq dirname ($in);
3671 $output_rules .= &file_contents ('tags',
3672 new Automake::Location,
3673 CONFIG => "@config",
3674 TAGSDIRS => "@tag_deps",
3675 CTAGSDIRS => "@ctag_deps",
3676 CSCOPEDIRS => "@cscope_deps");
3678 set_seen 'TAGS_DEPENDENCIES';
3680 elsif (reject_var ('TAGS_DEPENDENCIES',
3681 "it doesn't make sense to define `TAGS_DEPENDENCIES'"
3682 . " without\nsources or `ETAGS_ARGS'"))
3687 # Every Makefile must define some sort of TAGS rule.
3688 # Otherwise, it would be possible for a top-level "make TAGS"
3689 # to fail because some subdirectory failed.
3690 $output_rules .= "tags: TAGS\nTAGS:\n\n";
3691 # Ditto ctags and cscope.
3692 $output_rules .= "ctags: CTAGS\nCTAGS:\n\n";
3693 $output_rules .= "cscope cscopelist:\n\n";
3698 # user_phony_rule ($NAME)
3699 # -----------------------
3700 # Return false if rule $NAME does not exist. Otherwise,
3701 # declare it as phony, complete its definition (in case it is
3702 # conditional), and return its Automake::Rule instance.
3703 sub user_phony_rule ($)
3706 my $rule = rule $name;
3709 depend ('.PHONY', $name);
3710 # Define $NAME in all condition where it is not already defined,
3711 # so that it is always OK to depend on $NAME.
3712 for my $c ($rule->not_always_defined_in_cond (TRUE)->conds)
3714 Automake::Rule::define ($name, 'internal', RULE_AUTOMAKE,
3716 $output_rules .= $c->subst_string . "$name:\n";
3724 # &for_dist_common ($A, $B)
3725 # -------------------------
3726 # Subroutine for &handle_dist: sort files to dist.
3728 # We put README first because it then becomes easier to make a
3729 # Usenet-compliant shar file (in these, README must be first).
3731 # FIXME: do more ordering of files here.
3745 # Handle 'dist' target.
3748 # Substitutions for distdir.am
3751 # Define DIST_SUBDIRS. This must always be done, regardless of the
3752 # no-dist setting: target like `distclean' or `maintainer-clean' use it.
3753 my $subdirs = var ('SUBDIRS');
3756 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3757 # to all possible directories, and use it. If DIST_SUBDIRS is
3758 # defined, just use it.
3760 # Note that we check DIST_SUBDIRS first on purpose, so that
3761 # we don't call has_conditional_contents for now reason.
3762 # (In the past one project used so many conditional subdirectories
3763 # that calling has_conditional_contents on SUBDIRS caused
3764 # automake to grow to 150Mb -- this should not happen with
3765 # the current implementation of has_conditional_contents,
3766 # but it's more efficient to avoid the call anyway.)
3767 if (var ('DIST_SUBDIRS'))
3770 elsif ($subdirs->has_conditional_contents)
3772 define_pretty_variable
3773 ('DIST_SUBDIRS', TRUE, INTERNAL,
3774 uniq ($subdirs->value_as_list_recursive));
3778 # We always define this because that is what `distclean'
3780 define_pretty_variable ('DIST_SUBDIRS', TRUE, INTERNAL,
3785 # The remaining definitions are only required when a dist target is used.
3786 return if option 'no-dist';
3788 # At least one of the archive formats must be enabled.
3789 if ($relative_dir eq '.')
3791 my $archive_defined = option 'no-dist-gzip' ? 0 : 1;
3792 $archive_defined ||=
3793 grep { option "dist-$_" } qw(shar zip tarZ bzip2 lzip lzma xz);
3794 error (option 'no-dist-gzip',
3795 "no-dist-gzip specified but no dist-* specified,\n"
3796 . "at least one archive format must be enabled")
3797 unless $archive_defined;
3800 # Look for common files that should be included in distribution.
3801 # If the aux dir is set, and it does not have a Makefile.am, then
3802 # we check for these files there as well.
3804 if ($relative_dir eq '.'
3805 && $config_aux_dir_set_in_configure_ac)
3807 if (! &is_make_dir ($config_aux_dir))
3812 foreach my $cfile (@common_files)
3814 if (dir_has_case_matching_file ($relative_dir, $cfile)
3815 # The file might be absent, but if it can be built it's ok.
3818 &push_dist_common ($cfile);
3821 # Don't use `elsif' here because a file might meaningfully
3822 # appear in both directories.
3823 if ($check_aux && dir_has_case_matching_file ($config_aux_dir, $cfile))
3825 &push_dist_common ("$config_aux_dir/$cfile")
3829 # We might copy elements from $configure_dist_common to
3830 # %dist_common if we think we need to. If the file appears in our
3831 # directory, we would have discovered it already, so we don't
3832 # check that. But if the file is in a subdir without a Makefile,
3833 # we want to distribute it here if we are doing `.'. Ugly!
3834 # Also, in some corner cases, it's possible that the following code
3835 # will cause the same file to appear in the $(DIST_COMMON) variables
3836 # of two distinct Makefiles; but this is not a problem, since the
3837 # `distdir' target in `lib/am/distdir.am' can deal with the same
3838 # file being distributed multiple times.
3839 # See also automake bug#9651.
3840 if ($relative_dir eq '.')
3842 foreach my $file (split (' ' , $configure_dist_common))
3844 my $dir = dirname ($file);
3845 push_dist_common ($file)
3846 if ($dir eq '.' || ! is_make_dir ($dir));
3850 # Files to distributed. Don't use ->value_as_list_recursive
3851 # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3852 my @dist_common = split (' ', rvar ('DIST_COMMON')->variable_value);
3853 @dist_common = uniq (sort for_dist_common (@dist_common));
3854 variable_delete 'DIST_COMMON';
3855 define_pretty_variable ('DIST_COMMON', TRUE, INTERNAL, @dist_common);
3857 # Now that we've processed DIST_COMMON, disallow further attempts
3859 $handle_dist_run = 1;
3861 # Scan EXTRA_DIST to see if we need to distribute anything from a
3862 # subdir. If so, add it to the list. I didn't want to do this
3863 # originally, but there were so many requests that I finally
3865 my $extra_dist = var ('EXTRA_DIST');
3867 $transform{'DISTCHECK-HOOK'} = !! rule 'distcheck-hook';
3868 $transform{'GETTEXT'} = $seen_gettext && !$seen_gettext_external;
3870 # If the target `dist-hook' exists, make sure it is run. This
3871 # allows users to do random weird things to the distribution
3872 # before it is packaged up.
3873 push (@dist_targets, 'dist-hook')
3874 if user_phony_rule 'dist-hook';
3875 $transform{'DIST-TARGETS'} = join (' ', @dist_targets);
3877 my $flm = option ('filename-length-max');
3878 my $filename_filter = $flm ? '.' x $flm->[1] : '';
3880 $output_rules .= &file_contents ('distdir',
3881 new Automake::Location,
3883 FILENAME_FILTER => $filename_filter);
3887 # check_directory ($NAME, $WHERE [, $RELATIVE_DIR = "."])
3888 # -------------------------------------------------------
3889 # Ensure $NAME is a directory (in $RELATIVE_DIR), and that it uses a sane
3890 # name. Use $WHERE as a location in the diagnostic, if any.
3891 sub check_directory ($$;$)
3893 my ($dir, $where, $reldir) = @_;
3894 $reldir = '.' unless defined $reldir;
3896 error $where, "required directory $reldir/$dir does not exist"
3897 unless -d "$reldir/$dir";
3899 # If an `obj/' directory exists, BSD make will enter it before
3900 # reading `Makefile'. Hence the `Makefile' in the current directory
3906 # % cat obj/Makefile
3912 # % pmake # BSD make
3915 msg ('portability', $where,
3916 "naming a subdirectory `obj' causes troubles with BSD make")
3919 # `aux' is probably the most important of the following forbidden name,
3920 # since it's tempting to use it as an AC_CONFIG_AUX_DIR.
3921 msg ('portability', $where,
3922 "name `$dir' is reserved on W32 and DOS platforms")
3923 if grep (/^\Q$dir\E$/i, qw/aux lpt1 lpt2 lpt3 com1 com2 com3 com4 con prn/);
3926 # check_directories_in_var ($VARIABLE)
3927 # ------------------------------------
3928 # Recursively check all items in variables $VARIABLE as directories
3929 sub check_directories_in_var ($)
3932 $var->traverse_recursively
3935 my ($var, $val, $cond, $full_cond) = @_;
3936 check_directory ($val, $var->rdef ($cond)->location, $relative_dir);
3940 skip_ac_subst => 1);
3943 # &handle_subdirs ()
3944 # ------------------
3945 # Handle subdirectories.
3946 sub handle_subdirs ()
3948 my $subdirs = var ('SUBDIRS');
3952 check_directories_in_var $subdirs;
3954 my $dsubdirs = var ('DIST_SUBDIRS');
3955 check_directories_in_var $dsubdirs
3958 $output_rules .= &file_contents ('subdirs', new Automake::Location);
3959 rvar ('RECURSIVE_TARGETS')->rdef (TRUE)->{'pretty'} = VAR_SORTED; # Gross!
3963 # ($REGEN, @DEPENDENCIES)
3966 # If aclocal.m4 creation is automated, return the list of its dependencies.
3967 sub scan_aclocal_m4 ()
3969 my $regen_aclocal = 0;
3971 set_seen 'CONFIG_STATUS_DEPENDENCIES';
3972 set_seen 'CONFIGURE_DEPENDENCIES';
3974 if (-f 'aclocal.m4')
3976 &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4', INTERNAL);
3978 my $aclocal = new Automake::XFile "< aclocal.m4";
3979 my $line = $aclocal->getline;
3980 $regen_aclocal = $line =~ 'generated automatically by aclocal';
3985 if (set_seen ('ACLOCAL_M4_SOURCES'))
3987 push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3988 msg_var ('obsolete', 'ACLOCAL_M4_SOURCES',
3989 "`ACLOCAL_M4_SOURCES' is obsolete.\n"
3990 . "It should be safe to simply remove it");
3993 # Note that it might be possible that aclocal.m4 doesn't exist but
3994 # should be auto-generated. This case probably isn't very
3997 return ($regen_aclocal, @ac_deps);
4001 # Helper function for substitute_ac_subst_variables.
4002 sub substitute_ac_subst_variables_worker($)
4005 return "\@$token\@" if var $token;
4006 return "\${$token\}";
4009 # substitute_ac_subst_variables ($TEXT)
4010 # -------------------------------------
4011 # Replace any occurrence of ${FOO} in $TEXT by @FOO@ if FOO is an AC_SUBST
4013 sub substitute_ac_subst_variables ($)
4016 $text =~ s/\${([^ \t=:+{}]+)}/&substitute_ac_subst_variables_worker ($1)/ge;
4021 # &prepend_srcdir (@INPUTS)
4022 # -------------------------
4023 # Prepend $(srcdir) or $(top_srcdir) to all @INPUTS. The idea is that
4024 # if an input file has a directory part the same as the current
4025 # directory, then the directory part is simply replaced by $(srcdir).
4026 # But if the directory part is different, then $(top_srcdir) is
4028 sub prepend_srcdir (@)
4033 foreach my $single (@inputs)
4035 if (dirname ($single) eq $relative_dir)
4037 push (@newinputs, '$(srcdir)/' . basename ($single));
4041 push (@newinputs, '$(top_srcdir)/' . $single);
4048 # rewrite_inputs_into_dependencies ($OUTPUT, @INPUTS)
4049 # ---------------------------------------------------
4050 # Compute a list of dependencies appropriate for the rebuild
4052 # AC_CONFIG_FILES($OUTPUT:$INPUT[0]:$INPUTS[1]:...)
4053 # Also distribute $INPUTs which are not built by another AC_CONFIG_FOOs.
4054 sub rewrite_inputs_into_dependencies ($@)
4056 my ($file, @inputs) = @_;
4061 # We cannot create dependencies on shell variables.
4062 next if (substitute_ac_subst_variables $i) =~ /\$/;
4064 if (exists $ac_config_files_location{$i} && $i ne $file)
4066 my $di = dirname $i;
4067 if ($di eq $relative_dir)
4071 # In the top-level Makefile we do not use $(top_builddir), because
4072 # we are already there, and since the targets are built without
4073 # a $(top_builddir), it helps BSD Make to match them with
4075 elsif ($relative_dir ne '.')
4077 $i = '$(top_builddir)/' . $i;
4082 msg ('error', $ac_config_files_location{$file},
4083 "required file `$i' not found")
4084 unless $i =~ /\$/ || exists $output_files{$i} || -f $i;
4085 ($i) = prepend_srcdir ($i);
4086 push_dist_common ($i);
4095 # &handle_configure ($MAKEFILE_AM, $MAKEFILE_IN, $MAKEFILE, @INPUTS)
4096 # ------------------------------------------------------------------
4097 # Handle remaking and configure stuff.
4098 # We need the name of the input file, to do proper remaking rules.
4099 sub handle_configure ($$$@)
4101 my ($makefile_am, $makefile_in, $makefile, @inputs) = @_;
4103 prog_error 'empty @inputs'
4106 my ($rel_makefile_am, $rel_makefile_in) = prepend_srcdir ($makefile_am,
4108 my $rel_makefile = basename $makefile;
4110 my $colon_infile = ':' . join (':', @inputs);
4111 $colon_infile = '' if $colon_infile eq ":$makefile.in";
4112 my @rewritten = rewrite_inputs_into_dependencies ($makefile, @inputs);
4113 my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4;
4114 define_pretty_variable ('am__aclocal_m4_deps', TRUE, INTERNAL,
4115 @configure_deps, @aclocal_m4_deps,
4116 '$(top_srcdir)/' . $configure_ac);
4117 my @configuredeps = ('$(am__aclocal_m4_deps)', '$(CONFIGURE_DEPENDENCIES)');
4118 push @configuredeps, '$(ACLOCAL_M4)' if -f 'aclocal.m4';
4119 define_pretty_variable ('am__configure_deps', TRUE, INTERNAL,
4122 my $automake_options = '--' . (global_option 'cygnus' ? 'cygnus' : $strictness_name)
4123 . (global_option 'no-dependencies' ? ' --ignore-deps' : '');
4125 $output_rules .= file_contents
4127 new Automake::Location,
4128 MAKEFILE => $rel_makefile,
4129 'MAKEFILE-DEPS' => "@rewritten",
4130 'CONFIG-MAKEFILE' => ($relative_dir eq '.') ? '$@' : '$(subdir)/$@',
4131 'MAKEFILE-IN' => $rel_makefile_in,
4132 'HAVE-MAKEFILE-IN-DEPS' => (@include_stack > 0),
4133 'MAKEFILE-IN-DEPS' => "@include_stack",
4134 'MAKEFILE-AM' => $rel_makefile_am,
4135 'AUTOMAKE-OPTIONS' => $automake_options,
4136 'MAKEFILE-AM-SOURCES' => "$makefile$colon_infile",
4137 'REGEN-ACLOCAL-M4' => $regen_aclocal_m4,
4138 VERBOSE => verbose_flag ('GEN'));
4140 if ($relative_dir eq '.')
4142 &push_dist_common ('acconfig.h')
4146 # If we have a configure header, require it.
4148 my @distclean_config;
4149 foreach my $spec (@config_headers)
4152 # $CONFIG_H_PATH: config.h from top level.
4153 my ($config_h_path, @ins) = split_config_file_spec ($spec);
4154 my $config_h_dir = dirname ($config_h_path);
4156 # If the header is in the current directory we want to build
4157 # the header here. Otherwise, if we're at the topmost
4158 # directory and the header's directory doesn't have a
4159 # Makefile, then we also want to build the header.
4160 if ($relative_dir eq $config_h_dir
4161 || ($relative_dir eq '.' && ! &is_make_dir ($config_h_dir)))
4163 my ($cn_sans_dir, $stamp_dir);
4164 if ($relative_dir eq $config_h_dir)
4166 $cn_sans_dir = basename ($config_h_path);
4171 $cn_sans_dir = $config_h_path;
4172 if ($config_h_dir eq '.')
4178 $stamp_dir = $config_h_dir . '/';
4182 # This will also distribute all inputs.
4183 @ins = rewrite_inputs_into_dependencies ($config_h_path, @ins);
4185 # Cannot define rebuild rules for filenames with shell variables.
4186 next if (substitute_ac_subst_variables $config_h_path) =~ /\$/;
4188 # Header defined in this directory.
4190 if (-f $config_h_path . '.top')
4192 push (@files, "$cn_sans_dir.top");
4194 if (-f $config_h_path . '.bot')
4196 push (@files, "$cn_sans_dir.bot");
4199 push_dist_common (@files);
4201 # For now, acconfig.h can only appear in the top srcdir.
4202 if (-f 'acconfig.h')
4204 push (@files, '$(top_srcdir)/acconfig.h');
4207 my $stamp = "${stamp_dir}stamp-h${hdr_index}";
4209 file_contents ('remake-hdr',
4210 new Automake::Location,
4212 CONFIG_H => $cn_sans_dir,
4213 CONFIG_HIN => $ins[0],
4214 CONFIG_H_DEPS => "@ins",
4215 CONFIG_H_PATH => $config_h_path,
4218 push @distclean_config, $cn_sans_dir, $stamp;
4222 $output_rules .= file_contents ('clean-hdr',
4223 new Automake::Location,
4224 FILES => "@distclean_config")
4225 if @distclean_config;
4227 # Distribute and define mkinstalldirs only if it is already present
4228 # in the package, for backward compatibility (some people may still
4229 # use $(mkinstalldirs)).
4230 my $mkidpath = "$config_aux_dir/mkinstalldirs";
4233 # Use require_file so that any existing script gets updated
4234 # by --force-missing.
4235 require_conf_file ($mkidpath, FOREIGN, 'mkinstalldirs');
4236 define_variable ('mkinstalldirs',
4237 "\$(SHELL) $am_config_aux_dir/mkinstalldirs", INTERNAL);
4241 # Use $(install_sh), not $(MKDIR_P) because the latter requires
4242 # at least one argument, and $(mkinstalldirs) used to work
4243 # even without arguments (e.g. $(mkinstalldirs) $(conditional_dir)).
4244 define_variable ('mkinstalldirs', '$(install_sh) -d', INTERNAL);
4247 reject_var ('CONFIG_HEADER',
4248 "`CONFIG_HEADER' is an anachronism; now determined "
4249 . "automatically\nfrom `$configure_ac'");
4252 foreach my $spec (@config_headers)
4254 my ($out, @ins) = split_config_file_spec ($spec);
4255 # Generate CONFIG_HEADER define.
4256 if ($relative_dir eq dirname ($out))
4258 push @config_h, basename ($out);
4262 push @config_h, "\$(top_builddir)/$out";
4265 define_variable ("CONFIG_HEADER", "@config_h", INTERNAL)
4268 # Now look for other files in this directory which must be remade
4269 # by config.status, and generate rules for them.
4270 my @actual_other_files = ();
4271 # These get cleaned only in a VPATH build.
4272 my @actual_other_vpath_files = ();
4273 foreach my $lfile (@other_input_files)
4277 if ($lfile =~ /^([^:]*):(.*)$/)
4279 # This is the ":" syntax of AC_OUTPUT.
4281 @inputs = split (':', $2);
4287 @inputs = $file . '.in';
4290 # Automake files should not be stored in here, but in %MAKE_LIST.
4291 prog_error ("$lfile in \@other_input_files\n"
4292 . "\@other_input_files = (@other_input_files)")
4293 if -f $file . '.am';
4295 my $local = basename ($file);
4297 # We skip files that aren't in this directory. However, if
4298 # the file's directory does not have a Makefile, and we are
4299 # currently doing `.', then we create a rule to rebuild the
4300 # file in the subdir.
4301 my $fd = dirname ($file);
4302 if ($fd ne $relative_dir)
4304 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
4314 my @rewritten_inputs = rewrite_inputs_into_dependencies ($file, @inputs);
4316 # Cannot output rules for shell variables.
4317 next if (substitute_ac_subst_variables $local) =~ /\$/;
4320 my $cond = $ac_config_files_condition{$lfile};
4323 $condstr = $cond->subst_string;
4324 Automake::Rule::define ($local, $configure_ac, RULE_AUTOMAKE, $cond,
4325 $ac_config_files_location{$file});
4327 $output_rules .= ($condstr . $local . ': '
4328 . '$(top_builddir)/config.status '
4329 . "@rewritten_inputs\n"
4331 . 'cd $(top_builddir) && '
4332 . '$(SHELL) ./config.status '
4333 . ($relative_dir eq '.' ? '' : '$(subdir)/')
4336 push (@actual_other_files, $local);
4339 # For links we should clean destinations and distribute sources.
4340 foreach my $spec (@config_links)
4342 my ($link, $file) = split /:/, $spec;
4343 # Some people do AC_CONFIG_LINKS($computed). We only handle
4344 # the DEST:SRC form.
4346 my $where = $ac_config_files_location{$link};
4348 # Skip destinations that contain shell variables.
4349 if ((substitute_ac_subst_variables $link) !~ /\$/)
4351 # We skip links that aren't in this directory. However, if
4352 # the link's directory does not have a Makefile, and we are
4353 # currently doing `.', then we add the link to CONFIG_CLEAN_FILES
4354 # in `.'s Makefile.in.
4355 my $local = basename ($link);
4356 my $fd = dirname ($link);
4357 if ($fd ne $relative_dir)
4359 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
4370 push @actual_other_files, $local if $local;
4374 push @actual_other_vpath_files, $local if $local;
4378 # Do not process sources that contain shell variables.
4379 if ((substitute_ac_subst_variables $file) !~ /\$/)
4381 my $fd = dirname ($file);
4383 # We distribute files that are in this directory.
4384 # At the top-level (`.') we also distribute files whose
4385 # directory does not have a Makefile.
4386 if (($fd eq $relative_dir)
4387 || ($relative_dir eq '.' && ! &is_make_dir ($fd)))
4389 # The following will distribute $file as a side-effect when
4390 # it is appropriate (i.e., when $file is not already an output).
4391 # We do not need the result, just the side-effect.
4392 rewrite_inputs_into_dependencies ($link, $file);
4397 # These files get removed by "make distclean".
4398 define_pretty_variable ('CONFIG_CLEAN_FILES', TRUE, INTERNAL,
4399 @actual_other_files);
4400 define_pretty_variable ('CONFIG_CLEAN_VPATH_FILES', TRUE, INTERNAL,
4401 @actual_other_vpath_files);
4407 my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
4408 'oldinclude', 'pkginclude',
4412 next unless $_->[1] =~ /\..*$/;
4413 &saw_extension ($&);
4419 return if ! $seen_gettext || $relative_dir ne '.';
4421 my $subdirs = var 'SUBDIRS';
4425 err_ac "AM_GNU_GETTEXT used but SUBDIRS not defined";
4429 # Perform some sanity checks to help users get the right setup.
4430 # We disable these tests when po/ doesn't exist in order not to disallow
4431 # unusual gettext setups.
4436 # | 1) If a package doesn't have a directory po/ at top level, it
4437 # | will likely have multiple po/ directories in subpackages.
4439 # | 2) It is useful to warn for the absence of intl/ if AM_GNU_GETTEXT
4440 # | is used without 'external'. It is also useful to warn for the
4441 # | presence of intl/ if AM_GNU_GETTEXT([external]) is used. Both
4442 # | warnings apply only to the usual layout of packages, therefore
4443 # | they should both be disabled if no po/ directory is found at
4448 my @subdirs = $subdirs->value_as_list_recursive;
4450 msg_var ('syntax', $subdirs,
4451 "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
4452 if ! grep ($_ eq 'po', @subdirs);
4454 # intl/ is not required when AM_GNU_GETTEXT is called with the
4455 # `external' option and AM_GNU_GETTEXT_INTL_SUBDIR is not called.
4456 msg_var ('syntax', $subdirs,
4457 "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
4458 if (! ($seen_gettext_external && ! $seen_gettext_intl)
4459 && ! grep ($_ eq 'intl', @subdirs));
4461 # intl/ should not be used with AM_GNU_GETTEXT([external]), except
4462 # if AM_GNU_GETTEXT_INTL_SUBDIR is called.
4463 msg_var ('syntax', $subdirs,
4464 "`intl' should not be in SUBDIRS when "
4465 . "AM_GNU_GETTEXT([external]) is used")
4466 if ($seen_gettext_external && ! $seen_gettext_intl
4467 && grep ($_ eq 'intl', @subdirs));
4470 require_file ($ac_gettext_location, GNU, 'ABOUT-NLS');
4473 # Handle footer elements.
4476 reject_rule ('.SUFFIXES',
4477 "use variable `SUFFIXES', not target `.SUFFIXES'");
4479 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
4480 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
4481 # anything else, by sticking it right after the default: target.
4482 $output_header .= ".SUFFIXES:\n";
4483 my $suffixes = var 'SUFFIXES';
4484 my @suffixes = Automake::Rule::suffixes;
4485 if (@suffixes || $suffixes)
4487 # Make sure SUFFIXES has unique elements. Sort them to ensure
4488 # the output remains consistent. However, $(SUFFIXES) is
4489 # always at the start of the list, unsorted. This is done
4490 # because make will choose rules depending on the ordering of
4491 # suffixes, and this lets the user have some control. Push
4492 # actual suffixes, and not $(SUFFIXES). Some versions of make
4493 # do not like variable substitutions on the .SUFFIXES line.
4494 my @user_suffixes = ($suffixes
4495 ? $suffixes->value_as_list_recursive : ());
4497 my %suffixes = map { $_ => 1 } @suffixes;
4498 delete @suffixes{@user_suffixes};
4500 $output_header .= (".SUFFIXES: "
4501 . join (' ', @user_suffixes, sort keys %suffixes)
4505 $output_trailer .= file_contents ('footer', new Automake::Location);
4509 # Generate `make install' rules.
4510 sub handle_install ()
4512 $output_rules .= &file_contents
4514 new Automake::Location,
4515 maybe_BUILT_SOURCES => (set_seen ('BUILT_SOURCES')
4516 ? (" \$(BUILT_SOURCES)\n"
4517 . "\t\$(MAKE) \$(AM_MAKEFLAGS)")
4519 'installdirs-local' => (user_phony_rule 'installdirs-local'
4520 ? ' installdirs-local' : ''),
4521 am__installdirs => variable_value ('am__installdirs') || '');
4525 # Deal with all and all-am.
4528 my ($makefile) = @_;
4532 # Put this at the beginning for the sake of non-GNU makes. This
4533 # is still wrong if these makes can run parallel jobs. But it is
4535 unshift (@all, basename ($makefile));
4537 foreach my $spec (@config_headers)
4539 my ($out, @ins) = split_config_file_spec ($spec);
4540 push (@all, basename ($out))
4541 if dirname ($out) eq $relative_dir;
4544 # Install `all' hooks.
4545 push (@all, "all-local")
4546 if user_phony_rule "all-local";
4548 &pretty_print_rule ("all-am:", "\t\t", @all);
4549 &depend ('.PHONY', 'all-am', 'all');
4554 my @local_headers = ();
4555 push @local_headers, '$(BUILT_SOURCES)'
4556 if var ('BUILT_SOURCES');
4557 foreach my $spec (@config_headers)
4559 my ($out, @ins) = split_config_file_spec ($spec);
4560 push @local_headers, basename ($out)
4561 if dirname ($out) eq $relative_dir;
4566 # We need to make sure config.h is built before we recurse.
4567 # We also want to make sure that built sources are built
4568 # before any ordinary `all' targets are run. We can't do this
4569 # by changing the order of dependencies to the "all" because
4570 # that breaks when using parallel makes. Instead we handle
4571 # things explicitly.
4572 $output_all .= ("all: @local_headers"
4574 . '$(MAKE) $(AM_MAKEFLAGS) '
4575 . (var ('SUBDIRS') ? 'all-recursive' : 'all-am')
4577 depend ('.MAKE', 'all');
4581 $output_all .= "all: " . (var ('SUBDIRS')
4582 ? 'all-recursive' : 'all-am') . "\n\n";
4587 # &do_check_merge_target ()
4588 # -------------------------
4589 # Handle check merge target specially.
4590 sub do_check_merge_target ()
4592 # Include user-defined local form of target.
4593 push @check_tests, 'check-local'
4594 if user_phony_rule 'check-local';
4596 # In --cygnus mode, check doesn't depend on all.
4597 if (option 'cygnus')
4599 # Just run the local check rules.
4600 pretty_print_rule ('check-am:', "\t\t", @check);
4604 # The check target must depend on the local equivalent of
4605 # `all', to ensure all the primary targets are built. Then it
4606 # must build the local check rules.
4607 $output_rules .= "check-am: all-am\n";
4610 pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4612 depend ('.MAKE', 'check-am');
4617 pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4619 depend ('.MAKE', 'check-am');
4622 depend '.PHONY', 'check', 'check-am';
4623 # Handle recursion. We have to honor BUILT_SOURCES like for `all:'.
4624 $output_rules .= ("check: "
4625 . (var ('BUILT_SOURCES')
4626 ? "\$(BUILT_SOURCES)\n\t\$(MAKE) \$(AM_MAKEFLAGS) "
4628 . (var ('SUBDIRS') ? 'check-recursive' : 'check-am')
4630 depend ('.MAKE', 'check')
4631 if var ('BUILT_SOURCES');
4634 # handle_clean ($MAKEFILE)
4635 # ------------------------
4636 # Handle all 'clean' targets.
4637 sub handle_clean ($)
4639 my ($makefile) = @_;
4641 # Clean the files listed in user variables if they exist.
4642 $clean_files{'$(MOSTLYCLEANFILES)'} = MOSTLY_CLEAN
4643 if var ('MOSTLYCLEANFILES');
4644 $clean_files{'$(CLEANFILES)'} = CLEAN
4645 if var ('CLEANFILES');
4646 $clean_files{'$(DISTCLEANFILES)'} = DIST_CLEAN
4647 if var ('DISTCLEANFILES');
4648 $clean_files{'$(MAINTAINERCLEANFILES)'} = MAINTAINER_CLEAN
4649 if var ('MAINTAINERCLEANFILES');
4651 # Built sources are automatically removed by maintainer-clean.
4652 $clean_files{'$(BUILT_SOURCES)'} = MAINTAINER_CLEAN
4653 if var ('BUILT_SOURCES');
4655 # Compute a list of "rm"s to run for each target.
4656 my %rms = (MOSTLY_CLEAN, [],
4659 MAINTAINER_CLEAN, []);
4661 foreach my $file (keys %clean_files)
4663 my $when = $clean_files{$file};
4664 prog_error 'invalid entry in %clean_files'
4665 unless exists $rms{$when};
4667 my $rm = "rm -f $file";
4668 # If file is a variable, make sure when don't call `rm -f' without args.
4669 $rm ="test -z \"$file\" || $rm"
4670 if ($file =~ /^\s*\$(\(.*\)|\{.*\})\s*$/);
4672 push @{$rms{$when}}, "\t-$rm\n";
4675 $output_rules .= &file_contents
4677 new Automake::Location,
4678 MOSTLYCLEAN_RMS => join ('', sort @{$rms{&MOSTLY_CLEAN}}),
4679 CLEAN_RMS => join ('', sort @{$rms{&CLEAN}}),
4680 DISTCLEAN_RMS => join ('', sort @{$rms{&DIST_CLEAN}}),
4681 MAINTAINER_CLEAN_RMS => join ('', sort @{$rms{&MAINTAINER_CLEAN}}),
4682 MAKEFILE => basename $makefile,
4687 # &target_cmp ($A, $B)
4688 # --------------------
4689 # Subroutine for &handle_factored_dependencies to let `.PHONY' and
4690 # other `.TARGETS' be last.
4693 return 0 if $a eq $b;
4695 my $a1 = substr ($a, 0, 1);
4696 my $b1 = substr ($b, 0, 1);
4699 return -1 if $b1 eq '.';
4700 return 1 if $a1 eq '.';
4706 # &handle_factored_dependencies ()
4707 # --------------------------------
4708 # Handle everything related to gathered targets.
4709 sub handle_factored_dependencies
4712 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4713 'uninstall-exec-local', 'uninstall-exec-hook',
4714 'uninstall-dvi-local',
4715 'uninstall-html-local',
4716 'uninstall-info-local',
4717 'uninstall-pdf-local',
4718 'uninstall-ps-local')
4722 reject_rule ($utarg, "use `$x', not `$utarg'");
4725 reject_rule ('install-local',
4726 "use `install-data-local' or `install-exec-local', "
4727 . "not `install-local'");
4729 reject_rule ('install-hook',
4730 "use `install-data-hook' or `install-exec-hook', "
4731 . "not `install-hook'");
4733 # Install the -local hooks.
4734 foreach (keys %dependencies)
4736 # Hooks are installed on the -am targets.
4738 depend ("$_-am", "$_-local")
4739 if user_phony_rule "$_-local";
4742 # Install the -hook hooks.
4743 # FIXME: Why not be as liberal as we are with -local hooks?
4744 foreach ('install-exec', 'install-data', 'uninstall')
4746 if (user_phony_rule "$_-hook")
4748 depend ('.MAKE', "$_-am");
4749 register_action("$_-am",
4750 ("\t\@\$(NORMAL_INSTALL)\n"
4751 . "\t\$(MAKE) \$(AM_MAKEFLAGS) $_-hook"));
4755 # All the required targets are phony.
4756 depend ('.PHONY', keys %required_targets);
4758 # Actually output gathered targets.
4759 foreach (sort target_cmp keys %dependencies)
4761 # If there is nothing about this guy, skip it.
4763 unless (@{$dependencies{$_}}
4765 || $required_targets{$_});
4767 # Define gathered targets in undefined conditions.
4768 # FIXME: Right now we must handle .PHONY as an exception,
4769 # because people write things like
4770 # .PHONY: myphonytarget
4771 # to append dependencies. This would not work if Automake
4772 # refrained from defining its own .PHONY target as it does
4773 # with other overridden targets.
4774 # Likewise for `.MAKE'.
4775 my @undefined_conds = (TRUE,);
4776 if ($_ ne '.PHONY' && $_ ne '.MAKE')
4779 Automake::Rule::define ($_, 'internal',
4780 RULE_AUTOMAKE, TRUE, INTERNAL);
4782 my @uniq_deps = uniq (sort @{$dependencies{$_}});
4783 foreach my $cond (@undefined_conds)
4785 my $condstr = $cond->subst_string;
4786 &pretty_print_rule ("$condstr$_:", "$condstr\t", @uniq_deps);
4787 $output_rules .= $actions{$_} if defined $actions{$_};
4788 $output_rules .= "\n";
4794 # &handle_tests_dejagnu ()
4795 # ------------------------
4796 sub handle_tests_dejagnu
4798 push (@check_tests, 'check-DEJAGNU');
4799 $output_rules .= file_contents ('dejagnu', new Automake::Location);
4802 sub handle_per_suffix_test
4804 my ($test_suffix, %transform) = @_;
4805 my ($pfx, $generic, $parallel_tests_option, $am_exeext);
4806 prog_error ("called with 'parallel-tests' option not set")
4807 unless $parallel_tests_option = option 'parallel-tests';
4808 if ($test_suffix eq '')
4812 $am_exeext = 'FALSE';
4816 prog_error ("test suffix `$test_suffix' lacks leading dot")
4817 unless $test_suffix =~ m/^\.(.*)/;
4818 $pfx = uc ($1) . '_';
4820 $am_exeext = exists $configure_vars{'EXEEXT'} ? 'am__EXEEXT'
4823 # The "test driver" program, deputed to handle tests protocol used by
4824 # test scripts. By default, it's assumed that no protocol is used,
4825 # so we fall back to the old "parallel-tests" behaviour, implemented
4826 # by the `test-driver' auxiliary script.
4827 if (! var "${pfx}LOG_DRIVER")
4829 require_conf_file ($parallel_tests_option->{position}, FOREIGN,
4831 define_variable ("${pfx}LOG_DRIVER",
4832 "\$(SHELL) $am_config_aux_dir/test-driver",
4835 my $driver = '$(' . $pfx . 'LOG_DRIVER)';
4836 my $driver_flags = '$(AM_' . $pfx . 'LOG_DRIVER_FLAGS)'
4837 . ' $(' . $pfx . 'LOG_DRIVER_FLAGS)';
4838 my $compile = "${pfx}LOG_COMPILE";
4839 define_variable ($compile,
4840 '$(' . $pfx . 'LOG_COMPILER)'
4841 . ' $(AM_' . $pfx . 'LOG_FLAGS)'
4842 . ' $(' . $pfx . 'LOG_FLAGS)',
4844 $output_rules .= file_contents ('check2', new Automake::Location,
4845 GENERIC => $generic,
4847 DRIVER_FLAGS => $driver_flags,
4848 COMPILE => '$(' . $compile . ')',
4849 EXT => $test_suffix,
4850 am__EXEEXT => $am_exeext,
4854 # is_valid_test_extension ($EXT)
4855 # ------------------------------
4856 # Return true if $EXT can appear in $(TEST_EXTENSIONS), return false
4858 sub is_valid_test_extension ($)
4862 if ($ext =~ /^\.[a-zA-Z_][a-zA-Z0-9_]*$/);
4864 if (exists $configure_vars{'EXEEXT'} && $ext eq subst ('EXEEXT'));
4868 # Handle TESTS variable and other checks.
4871 if (option 'dejagnu')
4873 &handle_tests_dejagnu;
4877 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4879 reject_var ($c, "`$c' defined but `dejagnu' not in "
4880 . "`AUTOMAKE_OPTIONS'");
4886 push (@check_tests, 'check-TESTS');
4887 my $check_deps = "@check";
4888 $output_rules .= &file_contents ('check', new Automake::Location,
4889 COLOR => !! option 'color-tests',
4890 PARALLEL_TESTS => !! option 'parallel-tests',
4891 CHECK_DEPS => $check_deps);
4893 # Tests that are known programs should have $(EXEEXT) appended.
4894 # For matching purposes, we need to adjust XFAIL_TESTS as well.
4895 append_exeext { exists $known_programs{$_[0]} } 'TESTS';
4896 append_exeext { exists $known_programs{$_[0]} } 'XFAIL_TESTS'
4897 if (var ('XFAIL_TESTS'));
4899 if (my $parallel_tests = option 'parallel-tests')
4901 define_variable ('TEST_SUITE_LOG', 'test-suite.log', INTERNAL);
4904 my $handle_exeext = exists $configure_vars{'EXEEXT'};
4907 $at_exeext = subst ('EXEEXT');
4908 $suff = $at_exeext . ' ' . $suff;
4910 if (! var 'TEST_EXTENSIONS')
4912 define_variable ('TEST_EXTENSIONS', $suff, INTERNAL);
4914 my $var = var 'TEST_EXTENSIONS';
4915 # Currently, we are not able to deal with conditional contents
4916 # in TEST_EXTENSIONS.
4917 if ($var->has_conditional_contents)
4919 msg_var 'unsupported', $var,
4920 "`TEST_EXTENSIONS' cannot have conditional contents";
4922 my @test_suffixes = $var->value_as_list_recursive;
4923 if ((my @invalid_test_suffixes =
4924 grep { !is_valid_test_extension $_ } @test_suffixes) > 0)
4926 error $var->rdef (TRUE)->location,
4927 "invalid test extensions: @invalid_test_suffixes";
4929 @test_suffixes = grep { is_valid_test_extension $_ } @test_suffixes;
4932 unshift (@test_suffixes, $at_exeext)
4933 unless $test_suffixes[0] eq $at_exeext;
4935 unshift (@test_suffixes, '');
4937 transform_variable_recursively
4938 ('TESTS', 'TEST_LOGS', 'am__testlogs', 1, INTERNAL,
4940 my ($subvar, $val, $cond, $full_cond) = @_;
4943 if $val =~ /^\@.*\@$/;
4944 $obj =~ s/\$\(EXEEXT\)$//o;
4946 if ($val =~ /(\$\((top_)?srcdir\))\//o)
4948 msg ('error', $subvar->rdef ($cond)->location,
4949 "parallel-tests: using `$1' in TESTS is currently broken: `$val'");
4952 foreach my $test_suffix (@test_suffixes)
4955 if $test_suffix eq $at_exeext || $test_suffix eq '';
4956 return substr ($obj, 0, length ($obj) - length ($test_suffix)) . '.log'
4957 if substr ($obj, - length ($test_suffix)) eq $test_suffix;
4961 handle_per_suffix_test ('',
4971 my $last_suffix = $test_suffixes[$#test_suffixes];
4973 foreach my $test_suffix (@test_suffixes)
4975 if ($test_suffix eq $last_suffix)
4981 $cur = 'am__test_logs' . $nhelper;
4983 define_variable ($cur,
4984 '$(' . $prev . ':' . $test_suffix . $post . '=.log)', INTERNAL);
4988 if ($test_suffix ne $at_exeext && $test_suffix ne '')
4990 handle_per_suffix_test ($test_suffix,
4996 $clean_files{'$(TEST_LOGS)'} = MOSTLY_CLEAN;
4997 $clean_files{'$(TEST_LOGS:.log=.trs)'} = MOSTLY_CLEAN;
4998 $clean_files{'$(TEST_SUITE_LOG)'} = MOSTLY_CLEAN;
5003 # Handle Emacs Lisp.
5004 sub handle_emacs_lisp
5006 my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
5009 return if ! @elfiles;
5011 define_pretty_variable ('am__ELFILES', TRUE, INTERNAL,
5012 map { $_->[1] } @elfiles);
5013 define_pretty_variable ('am__ELCFILES', TRUE, INTERNAL,
5014 '$(am__ELFILES:.el=.elc)');
5015 # This one can be overridden by users.
5016 define_pretty_variable ('ELCFILES', TRUE, INTERNAL, '$(LISP:.el=.elc)');
5018 push @all, '$(ELCFILES)';
5020 require_variables ($elfiles[0][0], "Emacs Lisp sources seen", TRUE,
5021 'EMACS', 'lispdir');
5022 require_conf_file ($elfiles[0][0], FOREIGN, 'elisp-comp');
5023 &define_variable ('elisp_comp', "$am_config_aux_dir/elisp-comp", INTERNAL);
5029 my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
5031 return if ! @pyfiles;
5033 require_variables ($pyfiles[0][0], "Python sources seen", TRUE, 'PYTHON');
5034 require_conf_file ($pyfiles[0][0], FOREIGN, 'py-compile');
5035 &define_variable ('py_compile', "$am_config_aux_dir/py-compile", INTERNAL);
5041 my @sourcelist = &am_install_var ('-candist',
5044 return if ! @sourcelist;
5046 my @prefixes = am_primary_prefixes ('JAVA', 1,
5050 my @java_sources = ();
5051 foreach my $prefix (@prefixes)
5053 (my $curs = $prefix) =~ s/^(?:nobase_)?(?:dist_|nodist_)?//;
5056 if $curs eq 'EXTRA';
5058 push @java_sources, '$(' . $prefix . '_JAVA' . ')';
5062 err_var "${curs}_JAVA", "multiple _JAVA primaries in use"
5063 unless $curs eq $dir;
5069 define_pretty_variable ('am__java_sources', TRUE, INTERNAL,
5072 if ($dir eq 'check')
5074 push (@check, "class$dir.stamp");
5078 push (@all, "class$dir.stamp");
5083 # Handle some of the minor options.
5084 sub handle_minor_options
5086 if (option 'readme-alpha')
5088 if ($relative_dir eq '.')
5090 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
5092 msg ('error-gnits', $package_version_location,
5093 "version `$package_version' doesn't follow " .
5096 if (defined $1 && -f 'README-alpha')
5098 # This means we have an alpha release. See
5099 # GNITS_VERSION_PATTERN for details.
5100 push_dist_common ('README-alpha');
5106 ################################################################
5108 # ($OUTPUT, @INPUTS)
5109 # &split_config_file_spec ($SPEC)
5110 # -------------------------------
5111 # Decode the Autoconf syntax for config files (files, headers, links
5113 sub split_config_file_spec ($)
5116 my ($output, @inputs) = split (/:/, $spec);
5118 push @inputs, "$output.in"
5121 return ($output, @inputs);
5125 # locate_am (@POSSIBLE_SOURCES)
5126 # -----------------------------
5127 # AC_CONFIG_FILES allow specifications such as Makefile:top.in:mid.in:bot.in
5128 # This functions returns the first *.in file for which a *.am exists.
5129 # It returns undef otherwise.
5134 foreach my $file (@rest)
5136 if (($file =~ /^(.*)\.in$/) && -f "$1.am")
5147 # &scan_autoconf_config_files ($WHERE, $CONFIG-FILES)
5148 # ---------------------------------------------------
5149 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
5151 sub scan_autoconf_config_files ($$)
5153 my ($where, $config_files) = @_;
5155 # Look at potential Makefile.am's.
5156 foreach (split ' ', $config_files)
5158 # Must skip empty string for Perl 4.
5159 next if $_ eq "\\" || $_ eq '';
5161 # Handle $local:$input syntax.
5162 my ($local, @rest) = split (/:/);
5163 @rest = ("$local.in",) unless @rest;
5164 # Keep in sync with 'conffile-leading-dot.test'.
5165 msg ('unsupported', $where,
5166 "omit leading './' from config file names such as '$local';"
5167 . "\nremake rules might be subtly broken otherwise")
5168 if ($local =~ /^\.\//);
5169 my $input = locate_am @rest;
5172 # We have a file that automake should generate.
5173 $make_list{$input} = join (':', ($local, @rest));
5177 # We have a file that automake should cause to be
5178 # rebuilt, but shouldn't generate itself.
5179 push (@other_input_files, $_);
5181 $ac_config_files_location{$local} = $where;
5182 $ac_config_files_condition{$local} =
5183 new Automake::Condition (@cond_stack)
5189 # &scan_autoconf_traces ($FILENAME)
5190 # ---------------------------------
5191 sub scan_autoconf_traces ($)
5193 my ($filename) = @_;
5195 # Macros to trace, with their minimal number of arguments.
5197 # IMPORTANT: If you add a macro here, you should also add this macro
5198 # ========= to Automake-preselection in autoconf/lib/autom4te.in.
5200 AC_CANONICAL_BUILD => 0,
5201 AC_CANONICAL_HOST => 0,
5202 AC_CANONICAL_TARGET => 0,
5203 AC_CONFIG_AUX_DIR => 1,
5204 AC_CONFIG_FILES => 1,
5205 AC_CONFIG_HEADERS => 1,
5206 AC_CONFIG_LIBOBJ_DIR => 1,
5207 AC_CONFIG_LINKS => 1,
5211 AC_REQUIRE_AUX_FILE => 1,
5212 AC_SUBST_TRACE => 1,
5213 AM_AUTOMAKE_VERSION => 1,
5214 AM_CONDITIONAL => 2,
5215 AM_GNU_GETTEXT => 0,
5216 AM_GNU_GETTEXT_INTL_SUBDIR => 0,
5217 AM_INIT_AUTOMAKE => 0,
5218 AM_MAINTAINER_MODE => 0,
5220 AM_PROG_CC_C_O => 0,
5221 AM_SILENT_RULES => 0,
5222 _AM_SUBST_NOTMAKE => 1,
5225 _AM_COND_ENDIF => 1,
5226 LT_SUPPORTED_TAG => 1,
5227 _LT_AC_TAGCONFIG => 0,
5233 my $traces = ($ENV{AUTOCONF} || '@am_AUTOCONF@') . " ";
5235 # Use a separator unlikely to be used, not `:', the default, which
5236 # has a precise meaning for AC_CONFIG_FILES and so on.
5237 $traces .= join (' ',
5238 map { "--trace=$_" . ':\$f:\$l::\$d::\$n::\${::}%' }
5241 my $tracefh = new Automake::XFile ("$traces $filename |");
5242 verb "reading $traces";
5247 while ($_ = $tracefh->getline)
5250 my ($here, $depth, @args) = split (/::/);
5251 $where = new Automake::Location $here;
5252 my $macro = $args[0];
5254 prog_error ("unrequested trace `$macro'")
5255 unless exists $traced{$macro};
5257 # Skip and diagnose malformed calls.
5258 if ($#args < $traced{$macro})
5260 msg ('syntax', $where, "not enough arguments for $macro");
5264 # Alphabetical ordering please.
5265 if ($macro eq 'AC_CANONICAL_BUILD')
5267 if ($seen_canonical <= AC_CANONICAL_BUILD)
5269 $seen_canonical = AC_CANONICAL_BUILD;
5270 $canonical_location = $where;
5273 elsif ($macro eq 'AC_CANONICAL_HOST')
5275 if ($seen_canonical <= AC_CANONICAL_HOST)
5277 $seen_canonical = AC_CANONICAL_HOST;
5278 $canonical_location = $where;
5281 elsif ($macro eq 'AC_CANONICAL_TARGET')
5283 $seen_canonical = AC_CANONICAL_TARGET;
5284 $canonical_location = $where;
5286 elsif ($macro eq 'AC_CONFIG_AUX_DIR')
5288 if ($seen_init_automake)
5290 error ($where, "AC_CONFIG_AUX_DIR must be called before "
5291 . "AM_INIT_AUTOMAKE ...", partial => 1);
5292 error ($seen_init_automake, "... AM_INIT_AUTOMAKE called here");
5294 $config_aux_dir = $args[1];
5295 $config_aux_dir_set_in_configure_ac = 1;
5296 check_directory ($config_aux_dir, $where);
5298 elsif ($macro eq 'AC_CONFIG_FILES')
5300 # Look at potential Makefile.am's.
5301 scan_autoconf_config_files ($where, $args[1]);
5303 elsif ($macro eq 'AC_CONFIG_HEADERS')
5305 foreach my $spec (split (' ', $args[1]))
5307 my ($dest, @src) = split (':', $spec);
5308 $ac_config_files_location{$dest} = $where;
5309 push @config_headers, $spec;
5312 elsif ($macro eq 'AC_CONFIG_LIBOBJ_DIR')
5314 $config_libobj_dir = $args[1];
5315 check_directory ($config_libobj_dir, $where);
5317 elsif ($macro eq 'AC_CONFIG_LINKS')
5319 foreach my $spec (split (' ', $args[1]))
5321 my ($dest, $src) = split (':', $spec);
5322 $ac_config_files_location{$dest} = $where;
5323 push @config_links, $spec;
5326 elsif ($macro eq 'AC_FC_SRCEXT')
5328 my $suffix = $args[1];
5329 # These flags are used as %SOURCEFLAG% in depend2.am,
5330 # where the trailing space is important.
5331 $sourceflags{'.' . $suffix} = '$(FCFLAGS_' . $suffix . ') '
5332 if ($suffix eq 'f90' || $suffix eq 'f95' || $suffix eq 'f03' || $suffix eq 'f08');
5334 elsif ($macro eq 'AC_INIT')
5336 if (defined $args[2])
5338 $package_version = $args[2];
5339 $package_version_location = $where;
5342 elsif ($macro eq 'AC_LIBSOURCE')
5344 $libsources{$args[1]} = $here;
5346 elsif ($macro eq 'AC_REQUIRE_AUX_FILE')
5348 # Only remember the first time a file is required.
5349 $required_aux_file{$args[1]} = $where
5350 unless exists $required_aux_file{$args[1]};
5352 elsif ($macro eq 'AC_SUBST_TRACE')
5354 # Just check for alphanumeric in AC_SUBST_TRACE. If you do
5355 # AC_SUBST(5), then too bad.
5356 $configure_vars{$args[1]} = $where
5357 if $args[1] =~ /^\w+$/;
5359 elsif ($macro eq 'AM_AUTOMAKE_VERSION')
5362 "version mismatch. This is Automake $VERSION,\n" .
5363 "but the definition used by this AM_INIT_AUTOMAKE\n" .
5364 "comes from Automake $args[1]. You should recreate\n" .
5365 "aclocal.m4 with aclocal and run automake again.\n",
5366 # $? = 63 is used to indicate version mismatch to missing.
5368 if $VERSION ne $args[1];
5370 $seen_automake_version = 1;
5372 elsif ($macro eq 'AM_CONDITIONAL')
5374 $configure_cond{$args[1]} = $where;
5376 elsif ($macro eq 'AM_GNU_GETTEXT')
5378 $seen_gettext = $where;
5379 $ac_gettext_location = $where;
5380 $seen_gettext_external = grep ($_ eq 'external', @args);
5382 elsif ($macro eq 'AM_GNU_GETTEXT_INTL_SUBDIR')
5384 $seen_gettext_intl = $where;
5386 elsif ($macro eq 'AM_INIT_AUTOMAKE')
5388 $seen_init_automake = $where;
5389 if (defined $args[2])
5391 $package_version = $args[2];
5392 $package_version_location = $where;
5394 elsif (defined $args[1])
5396 my @opts = split (' ', $args[1]);
5397 @opts = map { { option => $_, where => $where } } @opts;
5398 exit $exit_code if process_global_option_list (@opts);
5401 elsif ($macro eq 'AM_MAINTAINER_MODE')
5403 $seen_maint_mode = $where;
5405 elsif ($macro eq 'AM_PROG_AR')
5409 elsif ($macro eq 'AM_PROG_CC_C_O')
5411 $seen_cc_c_o = $where;
5413 elsif ($macro eq 'AM_SILENT_RULES')
5415 set_global_option ('silent-rules', $where);
5417 elsif ($macro eq '_AM_COND_IF')
5419 cond_stack_if ('', $args[1], $where);
5420 error ($where, "missing m4 quoting, macro depth $depth")
5423 elsif ($macro eq '_AM_COND_ELSE')
5425 cond_stack_else ('!', $args[1], $where);
5426 error ($where, "missing m4 quoting, macro depth $depth")
5429 elsif ($macro eq '_AM_COND_ENDIF')
5431 cond_stack_endif (undef, undef, $where);
5432 error ($where, "missing m4 quoting, macro depth $depth")
5435 elsif ($macro eq '_AM_SUBST_NOTMAKE')
5437 $ignored_configure_vars{$args[1]} = $where;
5439 elsif ($macro eq 'm4_include'
5440 || $macro eq 'm4_sinclude'
5441 || $macro eq 'sinclude')
5443 # Skip missing `sinclude'd files.
5444 next if $macro ne 'm4_include' && ! -f $args[1];
5446 # Some modified versions of Autoconf don't use
5447 # frozen files. Consequently it's possible that we see all
5448 # m4_include's performed during Autoconf's startup.
5449 # Obviously we don't want to distribute Autoconf's files
5450 # so we skip absolute filenames here.
5451 push @configure_deps, '$(top_srcdir)/' . $args[1]
5452 unless $here =~ m,^(?:\w:)?[\\/],;
5453 # Keep track of the greatest timestamp.
5456 my $mtime = mtime $args[1];
5457 $configure_deps_greatest_timestamp = $mtime
5458 if $mtime > $configure_deps_greatest_timestamp;
5461 elsif ($macro eq 'LT_SUPPORTED_TAG')
5463 $libtool_tags{$args[1]} = 1;
5464 $libtool_new_api = 1;
5466 elsif ($macro eq '_LT_AC_TAGCONFIG')
5468 # _LT_AC_TAGCONFIG is an old macro present in Libtool 1.5.
5469 # We use it to detect whether tags are supported. Our
5470 # preferred interface is LT_SUPPORTED_TAG, but it was
5471 # introduced in Libtool 1.6.
5472 if (0 == keys %libtool_tags)
5474 # Hardcode the tags supported by Libtool 1.5.
5475 %libtool_tags = (CC => 1, CXX => 1, GCJ => 1, F77 => 1);
5480 error ($where, "condition stack not properly closed")
5487 # &scan_autoconf_files ()
5488 # -----------------------
5489 # Check whether we use `configure.ac' or `configure.in'.
5490 # Scan it (and possibly `aclocal.m4') for interesting things.
5491 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
5492 sub scan_autoconf_files ()
5494 # Reinitialize libsources here. This isn't really necessary,
5495 # since we currently assume there is only one configure.ac. But
5496 # that won't always be the case.
5499 # Keep track of the youngest configure dependency.
5500 $configure_deps_greatest_timestamp = mtime $configure_ac;
5501 if (-e 'aclocal.m4')
5503 my $mtime = mtime 'aclocal.m4';
5504 $configure_deps_greatest_timestamp = $mtime
5505 if $mtime > $configure_deps_greatest_timestamp;
5508 scan_autoconf_traces ($configure_ac);
5510 @configure_input_files = sort keys %make_list;
5511 # Set input and output files if not specified by user.
5514 @input_files = @configure_input_files;
5515 %output_files = %make_list;
5519 if (! $seen_init_automake)
5521 err_ac ("no proper invocation of AM_INIT_AUTOMAKE was found.\nYou "
5522 . "should verify that $configure_ac invokes AM_INIT_AUTOMAKE,"
5523 . "\nthat aclocal.m4 is present in the top-level directory,\n"
5524 . "and that aclocal.m4 was recently regenerated "
5525 . "(using aclocal)");
5529 if (! $seen_automake_version)
5531 if (-f 'aclocal.m4')
5533 error ($seen_init_automake,
5534 "your implementation of AM_INIT_AUTOMAKE comes from " .
5535 "an\nold Automake version. You should recreate " .
5536 "aclocal.m4\nwith aclocal and run automake again",
5537 # $? = 63 is used to indicate version mismatch to missing.
5542 error ($seen_init_automake,
5543 "no proper implementation of AM_INIT_AUTOMAKE was " .
5544 "found,\nprobably because aclocal.m4 is missing.\n" .
5545 "You should run aclocal to create this file, then\n" .
5546 "run automake again");
5553 # Look for some files we need. Always check for these. This
5554 # check must be done for every run, even those where we are only
5555 # looking at a subdir Makefile. We must set relative_dir for
5556 # push_required_file to work.
5557 # Sort the files for stable verbose output.
5558 $relative_dir = '.';
5559 foreach my $file (sort keys %required_aux_file)
5561 require_conf_file ($required_aux_file{$file}->get, FOREIGN, $file)
5563 err_am "`install.sh' is an anachronism; use `install-sh' instead"
5564 if -f $config_aux_dir . '/install.sh';
5566 # Preserve dist_common for later.
5567 $configure_dist_common = variable_value ('DIST_COMMON') || '';
5571 ################################################################
5573 # Set up for Cygnus mode.
5576 my $cygnus = option 'cygnus';
5577 return unless $cygnus;
5579 set_strictness ('foreign');
5580 set_option ('no-installinfo', $cygnus);
5581 set_option ('no-dependencies', $cygnus);
5582 set_option ('no-dist', $cygnus);
5584 err_ac "`AM_MAINTAINER_MODE' required when --cygnus specified"
5585 if !$seen_maint_mode;
5588 # Do any extra checking for GNU standards.
5589 sub check_gnu_standards
5591 if ($relative_dir eq '.')
5593 # In top level (or only) directory.
5594 require_file ("$am_file.am", GNU,
5595 qw/INSTALL NEWS README AUTHORS ChangeLog/);
5597 # Accept one of these three licenses; default to COPYING.
5598 # Make sure we do not overwrite an existing license.
5600 foreach (qw /COPYING COPYING.LIB COPYING.LESSER/)
5608 require_file ("$am_file.am", GNU, 'COPYING')
5612 for my $opt ('no-installman', 'no-installinfo')
5614 msg ('error-gnu', option $opt,
5615 "option `$opt' disallowed by GNU standards")
5620 # Do any extra checking for GNITS standards.
5621 sub check_gnits_standards
5623 if ($relative_dir eq '.')
5625 # In top level (or only) directory.
5626 require_file ("$am_file.am", GNITS, 'THANKS');
5630 ################################################################
5632 # Functions to handle files of each language.
5634 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
5635 # simple formula: Return value is LANG_SUBDIR if the resulting object
5636 # file should be in a subdir if the source file is, LANG_PROCESS if
5637 # file is to be dealt with, LANG_IGNORE otherwise.
5639 # Much of the actual processing is handled in
5640 # handle_single_transform. These functions exist so that
5641 # auxiliary information can be recorded for a later cleanup pass.
5642 # Note that the calls to these functions are computed, so don't bother
5643 # searching for their precise names in the source.
5645 # This is just a convenience function that can be used to determine
5646 # when a subdir object should be used.
5649 return option 'subdir-objects' ? LANG_SUBDIR : LANG_PROCESS;
5652 # Rewrite a single C source file.
5655 my ($directory, $base, $ext, $obj, $have_per_exec_flags, $var) = @_;
5657 my $r = LANG_PROCESS;
5658 if (option 'subdir-objects')
5661 if ($directory && $directory ne '.')
5663 $base = $directory . '/' . $base;
5665 # libtool is always able to put the object at the proper place,
5666 # so we do not have to require AM_PROG_CC_C_O when building .lo files.
5667 msg_var ('portability', $var,
5668 "compiling `$base.c' in subdir requires "
5669 . "`AM_PROG_CC_C_O' in `$configure_ac'",
5670 uniq_scope => US_GLOBAL,
5671 uniq_part => 'AM_PROG_CC_C_O subdir')
5672 unless $seen_cc_c_o || $obj eq '.lo';
5677 && $have_per_exec_flags
5678 && ! option 'subdir-objects'
5681 msg_var ('portability',
5682 $var, "compiling `$base.c' with per-target flags requires "
5683 . "`AM_PROG_CC_C_O' in `$configure_ac'",
5684 uniq_scope => US_GLOBAL,
5685 uniq_part => 'AM_PROG_CC_C_O per-target')
5691 # Rewrite a single C++ source file.
5692 sub lang_cxx_rewrite
5694 return &lang_sub_obj;
5697 # Rewrite a single header file.
5698 sub lang_header_rewrite
5700 # Header files are simply ignored.
5704 # Rewrite a single Vala source file.
5705 sub lang_vala_rewrite
5707 my ($directory, $base, $ext) = @_;
5709 (my $newext = $ext) =~ s/vala$/c/;
5710 return (LANG_SUBDIR, $newext);
5713 # Rewrite a single yacc file.
5714 sub lang_yacc_rewrite
5716 my ($directory, $base, $ext) = @_;
5718 my $r = &lang_sub_obj;
5719 (my $newext = $ext) =~ tr/y/c/;
5720 return ($r, $newext);
5723 # Rewrite a single yacc++ file.
5724 sub lang_yaccxx_rewrite
5726 my ($directory, $base, $ext) = @_;
5728 my $r = &lang_sub_obj;
5729 (my $newext = $ext) =~ tr/y/c/;
5730 return ($r, $newext);
5733 # Rewrite a single lex file.
5734 sub lang_lex_rewrite
5736 my ($directory, $base, $ext) = @_;
5738 my $r = &lang_sub_obj;
5739 (my $newext = $ext) =~ tr/l/c/;
5740 return ($r, $newext);
5743 # Rewrite a single lex++ file.
5744 sub lang_lexxx_rewrite
5746 my ($directory, $base, $ext) = @_;
5748 my $r = &lang_sub_obj;
5749 (my $newext = $ext) =~ tr/l/c/;
5750 return ($r, $newext);
5753 # Rewrite a single assembly file.
5754 sub lang_asm_rewrite
5756 return &lang_sub_obj;
5759 # Rewrite a single preprocessed assembly file.
5760 sub lang_cppasm_rewrite
5762 return &lang_sub_obj;
5765 # Rewrite a single Fortran 77 file.
5766 sub lang_f77_rewrite
5768 return &lang_sub_obj;
5771 # Rewrite a single Fortran file.
5774 return &lang_sub_obj;
5777 # Rewrite a single preprocessed Fortran file.
5778 sub lang_ppfc_rewrite
5780 return &lang_sub_obj;
5783 # Rewrite a single preprocessed Fortran 77 file.
5784 sub lang_ppf77_rewrite
5786 return &lang_sub_obj;
5789 # Rewrite a single ratfor file.
5790 sub lang_ratfor_rewrite
5792 return &lang_sub_obj;
5795 # Rewrite a single Objective C file.
5796 sub lang_objc_rewrite
5798 return &lang_sub_obj;
5801 # Rewrite a single Unified Parallel C file.
5802 sub lang_upc_rewrite
5804 return &lang_sub_obj;
5807 # Rewrite a single Java file.
5808 sub lang_java_rewrite
5813 # The lang_X_finish functions are called after all source file
5814 # processing is done. Each should handle defining rules for the
5815 # language, etc. A finish function is only called if a source file of
5816 # the appropriate type has been seen.
5818 sub lang_vala_finish_target ($$)
5820 my ($self, $name) = @_;
5822 my $derived = canonicalize ($name);
5823 my $varname = $derived . '_SOURCES';
5824 my $var = var ($varname);
5828 foreach my $file ($var->value_as_list_recursive)
5830 $output_rules .= "\$(srcdir)/$file: \$(srcdir)/${derived}_vala.stamp\n"
5831 . "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n"
5832 . "\t\@if test -f \$@; then :; else \\\n"
5833 . "\t \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n"
5835 if $file =~ s/(.*)\.vala$/$1.c/;
5839 # Add rebuild rules for generated header and vapi files
5840 my $flags = var ($derived . '_VALAFLAGS');
5844 foreach my $flag ($flags->value_as_list_recursive)
5846 if (grep (/$lastflag/, ('-H', '-h', '--header', '--internal-header',
5847 '--vapi', '--internal-vapi', '--gir')))
5849 my $headerfile = $flag;
5850 $output_rules .= "\$(srcdir)/$headerfile: \$(srcdir)/${derived}_vala.stamp\n"
5851 . "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n"
5852 . "\t\@if test -f \$@; then :; else \\\n"
5853 . "\t \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n"
5856 # valac is not used when building from dist tarballs
5857 # distribute the generated files
5858 push_dist_common ($headerfile);
5859 $clean_files{$headerfile} = MAINTAINER_CLEAN;
5865 my $compile = $self->compile;
5867 # Rewrite each occurrence of `AM_VALAFLAGS' in the compile
5868 # rule into `${derived}_VALAFLAGS' if it exists.
5869 my $val = "${derived}_VALAFLAGS";
5870 $compile =~ s/\(AM_VALAFLAGS\)/\($val\)/
5873 # VALAFLAGS is a user variable (per GNU Standards),
5874 # it should not be overridden in the Makefile...
5875 check_user_variables ['VALAFLAGS'];
5877 my $dirname = dirname ($name);
5879 # Only generate C code, do not run C compiler
5882 my $verbose = verbose_flag ('VALAC');
5883 my $silent = silent_flag ();
5886 "\$(srcdir)/${derived}_vala.stamp: \$(${derived}_SOURCES)\n".
5887 # Since the C files generated from the vala sources depend on the
5888 # ${derived}_vala.stamp file, we must ensure its timestamp is older than
5889 # those of the C files generated by the valac invocation below (this is
5890 # especially important on systems with sub-second timestamp resolution).
5891 # Thus we need to create the stamp file *before* invoking valac, and to
5892 # move it to its final location only after valac has been invoked.
5893 "\t${silent}rm -f \$\@ && echo stamp > \$\@-t\n".
5894 "\t${verbose}\$(am__cd) \$(srcdir) && ${compile} \$(${derived}_SOURCES)\n".
5895 "\t${silent}mv -f \$\@-t \$\@\n";
5897 push_dist_common ("${derived}_vala.stamp");
5899 $clean_files{"${derived}_vala.stamp"} = MAINTAINER_CLEAN;
5902 # Add output rules to invoke valac and create stamp file as a witness
5903 # to handle multiple outputs. This function is called after all source
5904 # file processing is done.
5905 sub lang_vala_finish
5909 foreach my $prog (keys %known_programs)
5911 lang_vala_finish_target ($self, $prog);
5914 while (my ($name) = each %known_libraries)
5916 lang_vala_finish_target ($self, $name);
5920 # The built .c files should be cleaned only on maintainer-clean
5921 # as the .c files are distributed. This function is called for each
5922 # .vala source file.
5923 sub lang_vala_target_hook
5925 my ($self, $aggregate, $output, $input, %transform) = @_;
5927 $clean_files{$output} = MAINTAINER_CLEAN;
5930 # This is a yacc helper which is called whenever we have decided to
5931 # compile a yacc file.
5932 sub lang_yacc_target_hook
5934 my ($self, $aggregate, $output, $input, %transform) = @_;
5936 # If some relevant *YFLAGS variable contains the `-d' flag, we'll
5937 # have to to generate special code.
5938 my $yflags_contains_minus_d = 0;
5940 foreach my $pfx ("", "${aggregate}_")
5942 my $yflagsvar = var ("${pfx}YFLAGS");
5943 next unless $yflagsvar;
5944 # We cannot work reliably with conditionally-defined YFLAGS.
5945 if ($yflagsvar->has_conditional_contents)
5947 msg_var ('unsupported', $yflagsvar,
5948 "`${pfx}YFLAGS' cannot have conditional contents");
5952 $yflags_contains_minus_d = 1
5953 if grep (/^-d$/, $yflagsvar->value_as_list_recursive);
5957 if ($yflags_contains_minus_d)
5959 # Found a `-d' that applies to the compilation of this file.
5960 # Add a dependency for the generated header file, and arrange
5961 # for that file to be included in the distribution.
5963 # The extension of the output file (e.g., `.c' or `.cxx').
5964 # We'll need it to compute the name of the generated header file.
5965 (my $output_ext = basename ($output)) =~ s/.*(\.[^.]+)$/$1/;
5967 # We know that a yacc input should be turned into either a C or
5968 # C++ output file. We depend on this fact (here and in yacc.am),
5969 # so check that it really holds.
5970 my $lang = $languages{$extension_map{$output_ext}};
5971 prog_error "invalid output name `$output' for yacc file `$input'"
5972 if (!$lang || ($lang->name ne 'c' && $lang->name ne 'cxx'));
5974 (my $header_ext = $output_ext) =~ s/c/h/g;
5975 # Quote $output_ext in the regexp, so that dots in it are taken
5976 # as literal dots, not as metacharacters.
5977 (my $header = $output) =~ s/\Q$output_ext\E$/$header_ext/;
5979 foreach my $cond (Automake::Rule::define (${header}, 'internal',
5980 RULE_AUTOMAKE, TRUE,
5983 my $condstr = $cond->subst_string;
5985 "$condstr${header}: $output\n"
5986 # Recover from removal of $header
5987 . "$condstr\t\@if test ! -f \$@; then rm -f $output; else :; fi\n"
5988 . "$condstr\t\@if test ! -f \$@; then \$(MAKE) \$(AM_MAKEFLAGS) $output; else :; fi\n";
5990 # Distribute the generated file, unless its .y source was
5991 # listed in a nodist_ variable. (&handle_source_transform
5992 # will set DIST_SOURCE.)
5993 &push_dist_common ($header)
5994 if $transform{'DIST_SOURCE'};
5996 # The GNU rules say that yacc/lex output files should be removed
5997 # by maintainer-clean. However, if the files are not distributed,
5998 # then we want to remove them with "make clean"; otherwise,
5999 # "make distcheck" will fail.
6000 $clean_files{$header} = $transform{'DIST_SOURCE'} ? MAINTAINER_CLEAN : CLEAN;
6002 # See the comment above for $HEADER.
6003 $clean_files{$output} = $transform{'DIST_SOURCE'} ? MAINTAINER_CLEAN : CLEAN;
6006 # This is a lex helper which is called whenever we have decided to
6007 # compile a lex file.
6008 sub lang_lex_target_hook
6010 my ($self, $aggregate, $output, $input, %transform) = @_;
6011 # The GNU rules say that yacc/lex output files should be removed
6012 # by maintainer-clean. However, if the files are not distributed,
6013 # then we want to remove them with "make clean"; otherwise,
6014 # "make distcheck" will fail.
6015 $clean_files{$output} = $transform{'DIST_SOURCE'} ? MAINTAINER_CLEAN : CLEAN;
6018 # This is a helper for both lex and yacc.
6019 sub yacc_lex_finish_helper
6021 return if defined $language_scratch{'lex-yacc-done'};
6022 $language_scratch{'lex-yacc-done'} = 1;
6024 # FIXME: for now, no line number.
6025 require_conf_file ($configure_ac, FOREIGN, 'ylwrap');
6026 &define_variable ('YLWRAP', "$am_config_aux_dir/ylwrap", INTERNAL);
6029 sub lang_yacc_finish
6031 return if defined $language_scratch{'yacc-done'};
6032 $language_scratch{'yacc-done'} = 1;
6034 reject_var 'YACCFLAGS', "`YACCFLAGS' obsolete; use `YFLAGS' instead";
6036 yacc_lex_finish_helper;
6042 return if defined $language_scratch{'lex-done'};
6043 $language_scratch{'lex-done'} = 1;
6045 yacc_lex_finish_helper;
6049 # Given a hash table of linker names, pick the name that has the most
6050 # precedence. This is lame, but something has to have global
6051 # knowledge in order to eliminate the conflict. Add more linkers as
6057 foreach my $l (qw(GCJLINK CXXLINK F77LINK FCLINK OBJCLINK UPCLINK))
6059 return $l if defined $linkers{$l};
6064 # Called to indicate that an extension was used.
6068 if (! defined $extension_seen{$ext})
6070 $extension_seen{$ext} = 1;
6074 ++$extension_seen{$ext};
6078 # Return the number of files seen for a given language. Knows about
6079 # special cases we care about. FIXME: this is hideous. We need
6080 # something that involves real language objects. For instance yacc
6081 # and yaccxx could both derive from a common yacc class which would
6082 # know about the strange ylwrap requirement. (Or better yet we could
6083 # just not support legacy yacc!)
6084 sub count_files_for_language
6089 if ($name eq 'yacc' || $name eq 'yaccxx')
6091 @names = ('yacc', 'yaccxx');
6093 elsif ($name eq 'lex' || $name eq 'lexxx')
6095 @names = ('lex', 'lexxx');
6103 foreach $name (@names)
6105 my $lang = $languages{$name};
6106 foreach my $ext (@{$lang->extensions})
6108 $r += $extension_seen{$ext}
6109 if defined $extension_seen{$ext};
6116 # Called to ask whether source files have been seen . If HEADERS is 1,
6117 # headers can be included.
6122 # count all the sources
6124 foreach my $val (values %extension_seen)
6131 $count -= count_files_for_language ('header');
6138 # register_language (%ATTRIBUTE)
6139 # ------------------------------
6140 # Register a single language.
6141 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
6142 sub register_language (%)
6147 $option{'autodep'} = 'no'
6148 unless defined $option{'autodep'};
6149 $option{'linker'} = ''
6150 unless defined $option{'linker'};
6151 $option{'flags'} = []
6152 unless defined $option{'flags'};
6153 $option{'output_extensions'} = sub { return ( '.$(OBJEXT)', '.lo' ) }
6154 unless defined $option{'output_extensions'};
6155 $option{'nodist_specific'} = 0
6156 unless defined $option{'nodist_specific'};
6158 my $lang = new Language (%option);
6161 $extension_map{$_} = $lang->name foreach @{$lang->extensions};
6162 $languages{$lang->name} = $lang;
6163 my $link = $lang->linker;
6166 if (exists $link_languages{$link})
6168 prog_error ("`$link' has different definitions in "
6169 . $lang->name . " and " . $link_languages{$link}->name)
6170 if $lang->link ne $link_languages{$link}->link;
6174 $link_languages{$link} = $lang;
6178 # Update the pattern of known extensions.
6179 accept_extensions (@{$lang->extensions});
6181 # Upate the $suffix_rule map.
6182 foreach my $suffix (@{$lang->extensions})
6184 foreach my $dest (&{$lang->output_extensions} ($suffix))
6186 register_suffix_rule (INTERNAL, $suffix, $dest);
6191 # derive_suffix ($EXT, $OBJ)
6192 # --------------------------
6193 # This function is used to find a path from a user-specified suffix $EXT
6194 # to $OBJ or to some other suffix we recognize internally, e.g. `cc'.
6195 sub derive_suffix ($$)
6197 my ($source_ext, $obj) = @_;
6199 while (! $extension_map{$source_ext}
6200 && $source_ext ne $obj
6201 && exists $suffix_rules->{$source_ext}
6202 && exists $suffix_rules->{$source_ext}{$obj})
6204 $source_ext = $suffix_rules->{$source_ext}{$obj}[0];
6211 ################################################################
6213 # Pretty-print something and append to output_rules.
6214 sub pretty_print_rule
6216 $output_rules .= &makefile_wrap (@_);
6220 ################################################################
6223 ## -------------------------------- ##
6224 ## Handling the conditional stack. ##
6225 ## -------------------------------- ##
6229 # make_conditional_string ($NEGATE, $COND)
6230 # ----------------------------------------
6231 sub make_conditional_string ($$)
6233 my ($negate, $cond) = @_;
6234 $cond = "${cond}_TRUE"
6235 unless $cond =~ /^TRUE|FALSE$/;
6236 $cond = Automake::Condition::conditional_negate ($cond)
6242 my %_am_macro_for_cond =
6244 AMDEP => "one of the compiler tests\n"
6245 . " AC_PROG_CC, AC_PROG_CXX, AC_PROG_CXX, AC_PROG_OBJC,\n"
6246 . " AM_PROG_AS, AM_PROG_GCJ, AM_PROG_UPC",
6247 am__fastdepCC => 'AC_PROG_CC',
6248 am__fastdepCCAS => 'AM_PROG_AS',
6249 am__fastdepCXX => 'AC_PROG_CXX',
6250 am__fastdepGCJ => 'AM_PROG_GCJ',
6251 am__fastdepOBJC => 'AC_PROG_OBJC',
6252 am__fastdepUPC => 'AM_PROG_UPC'
6256 # cond_stack_if ($NEGATE, $COND, $WHERE)
6257 # --------------------------------------
6258 sub cond_stack_if ($$$)
6260 my ($negate, $cond, $where) = @_;
6262 if (! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/)
6264 my $text = "$cond does not appear in AM_CONDITIONAL";
6265 my $scope = US_LOCAL;
6266 if (exists $_am_macro_for_cond{$cond})
6268 my $mac = $_am_macro_for_cond{$cond};
6269 $text .= "\n The usual way to define `$cond' is to add ";
6270 $text .= ($mac =~ / /) ? $mac : "`$mac'";
6271 $text .= "\n to `$configure_ac' and run `aclocal' and `autoconf' again";
6272 # These warnings appear in Automake files (depend2.am),
6273 # so there is no need to display them more than once:
6276 error $where, $text, uniq_scope => $scope;
6279 push (@cond_stack, make_conditional_string ($negate, $cond));
6281 return new Automake::Condition (@cond_stack);
6286 # cond_stack_else ($NEGATE, $COND, $WHERE)
6287 # ----------------------------------------
6288 sub cond_stack_else ($$$)
6290 my ($negate, $cond, $where) = @_;
6294 error $where, "else without if";
6298 $cond_stack[$#cond_stack] =
6299 Automake::Condition::conditional_negate ($cond_stack[$#cond_stack]);
6301 # If $COND is given, check against it.
6304 $cond = make_conditional_string ($negate, $cond);
6306 error ($where, "else reminder ($negate$cond) incompatible with "
6307 . "current conditional: $cond_stack[$#cond_stack]")
6308 if $cond_stack[$#cond_stack] ne $cond;
6311 return new Automake::Condition (@cond_stack);
6316 # cond_stack_endif ($NEGATE, $COND, $WHERE)
6317 # -----------------------------------------
6318 sub cond_stack_endif ($$$)
6320 my ($negate, $cond, $where) = @_;
6325 error $where, "endif without if";
6329 # If $COND is given, check against it.
6332 $cond = make_conditional_string ($negate, $cond);
6334 error ($where, "endif reminder ($negate$cond) incompatible with "
6335 . "current conditional: $cond_stack[$#cond_stack]")
6336 if $cond_stack[$#cond_stack] ne $cond;
6341 return new Automake::Condition (@cond_stack);
6348 ## ------------------------ ##
6349 ## Handling the variables. ##
6350 ## ------------------------ ##
6353 # &define_pretty_variable ($VAR, $COND, $WHERE, @VALUE)
6354 # -----------------------------------------------------
6355 # Like define_variable, but the value is a list, and the variable may
6356 # be defined conditionally. The second argument is the condition
6357 # under which the value should be defined; this should be the empty
6358 # string to define the variable unconditionally. The third argument
6359 # is a list holding the values to use for the variable. The value is
6360 # pretty printed in the output file.
6361 sub define_pretty_variable ($$$@)
6363 my ($var, $cond, $where, @value) = @_;
6365 if (! vardef ($var, $cond))
6367 Automake::Variable::define ($var, VAR_AUTOMAKE, '', $cond, "@value",
6368 '', $where, VAR_PRETTY);
6369 rvar ($var)->rdef ($cond)->set_seen;
6374 # define_variable ($VAR, $VALUE, $WHERE)
6375 # --------------------------------------
6376 # Define a new Automake Makefile variable VAR to VALUE, but only if
6377 # not already defined.
6378 sub define_variable ($$$)
6380 my ($var, $value, $where) = @_;
6381 define_pretty_variable ($var, TRUE, $where, $value);
6385 # define_files_variable ($VAR, \@BASENAME, $EXTENSION, $WHERE)
6386 # ------------------------------------------------------------
6387 # Define the $VAR which content is the list of file names composed of
6388 # a @BASENAME and the $EXTENSION.
6389 sub define_files_variable ($\@$$)
6391 my ($var, $basename, $extension, $where) = @_;
6392 define_variable ($var,
6393 join (' ', map { "$_.$extension" } @$basename),
6398 # Like define_variable, but define a variable to be the configure
6399 # substitution by the same name.
6400 sub define_configure_variable ($)
6403 # Some variables we do not want to output. For instance it
6404 # would be a bad idea to output `U = @U@` when `@U@` can be
6405 # substituted as `\`.
6406 my $pretty = exists $ignored_configure_vars{$var} ? VAR_SILENT : VAR_ASIS;
6407 Automake::Variable::define ($var, VAR_CONFIGURE, '', TRUE, subst $var,
6408 '', $configure_vars{$var}, $pretty);
6412 # define_compiler_variable ($LANG)
6413 # --------------------------------
6414 # Define a compiler variable. We also handle defining the `LT'
6415 # version of the command when using libtool.
6416 sub define_compiler_variable ($)
6420 my ($var, $value) = ($lang->compiler, $lang->compile);
6421 my $libtool_tag = '';
6422 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
6423 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
6424 &define_variable ($var, $value, INTERNAL);
6425 if (var ('LIBTOOL'))
6427 my $verbose = define_verbose_libtool ();
6428 &define_variable ("LT$var",
6429 "\$(LIBTOOL) $verbose $libtool_tag\$(AM_LIBTOOLFLAGS) "
6430 . "\$(LIBTOOLFLAGS) --mode=compile $value",
6433 define_verbose_tagvar ($lang->ccer || 'GEN');
6437 # define_linker_variable ($LANG)
6438 # ------------------------------
6439 # Define linker variables.
6440 sub define_linker_variable ($)
6444 my $libtool_tag = '';
6445 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
6446 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
6448 &define_variable ($lang->lder, $lang->ld, INTERNAL);
6449 # CCLINK = $(CCLD) blah blah...
6451 if (var ('LIBTOOL'))
6453 my $verbose = define_verbose_libtool ();
6454 $link = "\$(LIBTOOL) $verbose $libtool_tag\$(AM_LIBTOOLFLAGS) "
6455 . "\$(LIBTOOLFLAGS) --mode=link ";
6457 &define_variable ($lang->linker, $link . $lang->link, INTERNAL);
6458 &define_variable ($lang->compiler, $lang);
6459 &define_verbose_tagvar ($lang->lder || 'GEN');
6462 sub define_per_target_linker_variable ($$)
6464 my ($linker, $target) = @_;
6466 # If the user wrote a custom link command, we don't define ours.
6467 return "${target}_LINK"
6468 if set_seen "${target}_LINK";
6470 my $xlink = $linker ? $linker : 'LINK';
6472 my $lang = $link_languages{$xlink};
6473 prog_error "Unknown language for linker variable `$xlink'"
6476 my $link_command = $lang->link;
6479 my $libtool_tag = '';
6480 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
6481 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
6483 my $verbose = define_verbose_libtool ();
6485 "\$(LIBTOOL) $verbose $libtool_tag\$(AM_LIBTOOLFLAGS) \$(LIBTOOLFLAGS) "
6486 . "--mode=link " . $link_command;
6489 # Rewrite each occurrence of `AM_$flag' in the link
6490 # command into `${derived}_$flag' if it exists.
6491 my $orig_command = $link_command;
6492 my @flags = (@{$lang->flags}, 'LDFLAGS');
6493 push @flags, 'LIBTOOLFLAGS' if var 'LIBTOOL';
6494 for my $flag (@flags)
6496 my $val = "${target}_$flag";
6497 $link_command =~ s/\(AM_$flag\)/\($val\)/
6501 # If the computed command is the same as the generic command, use
6502 # the command linker variable.
6503 return ($lang->linker, $lang->lder)
6504 if $link_command eq $orig_command;
6506 &define_variable ("${target}_LINK", $link_command, INTERNAL);
6507 return ("${target}_LINK", $lang->lder);
6510 ################################################################
6512 # &check_trailing_slash ($WHERE, $LINE)
6513 # -------------------------------------
6514 # Return 1 iff $LINE ends with a slash.
6515 # Might modify $LINE.
6516 sub check_trailing_slash ($\$)
6518 my ($where, $line) = @_;
6520 # Ignore `##' lines.
6521 return 0 if $$line =~ /$IGNORE_PATTERN/o;
6523 # Catch and fix a common error.
6524 msg "syntax", $where, "whitespace following trailing backslash"
6525 if $$line =~ s/\\\s+\n$/\\\n/;
6527 return $$line =~ /\\$/;
6531 # &read_am_file ($AMFILE, $WHERE)
6532 # -------------------------------
6533 # Read Makefile.am and set up %contents. Simultaneously copy lines
6534 # from Makefile.am into $output_trailer, or define variables as
6535 # appropriate. NOTE we put rules in the trailer section. We want
6536 # user rules to come after our generated stuff.
6537 sub read_am_file ($$)
6539 my ($amfile, $where) = @_;
6541 my $am_file = new Automake::XFile ("< $amfile");
6542 verb "reading $amfile";
6544 # Keep track of the youngest output dependency.
6545 my $mtime = mtime $amfile;
6546 $output_deps_greatest_timestamp = $mtime
6547 if $mtime > $output_deps_greatest_timestamp;
6553 my $var_look = VAR_ASIS;
6555 use constant IN_VAR_DEF => 0;
6556 use constant IN_RULE_DEF => 1;
6557 use constant IN_COMMENT => 2;
6558 my $prev_state = IN_RULE_DEF;
6560 while ($_ = $am_file->getline)
6562 $where->set ("$amfile:$.");
6563 if (/$IGNORE_PATTERN/o)
6565 # Merely delete comments beginning with two hashes.
6567 elsif (/$WHITE_PATTERN/o)
6569 error $where, "blank line following trailing backslash"
6571 # Stick a single white line before the incoming macro or rule.
6574 # Flush all comments seen so far.
6577 $output_vars .= $comment;
6581 elsif (/$COMMENT_PATTERN/o)
6583 # Stick comments before the incoming macro or rule. Make
6584 # sure a blank line precedes the first block of comments.
6585 $spacing = "\n" unless $blank;
6587 $comment .= $spacing . $_;
6589 $prev_state = IN_COMMENT;
6595 $saw_bk = check_trailing_slash ($where, $_);
6598 # We save the conditional stack on entry, and then check to make
6599 # sure it is the same on exit. This lets us conditionally include
6601 my @saved_cond_stack = @cond_stack;
6602 my $cond = new Automake::Condition (@cond_stack);
6604 my $last_var_name = '';
6605 my $last_var_type = '';
6606 my $last_var_value = '';
6608 # FIXME: shouldn't use $_ in this loop; it is too big.
6611 $where->set ("$amfile:$.");
6613 # Make sure the line is \n-terminated.
6617 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
6618 # used by users. @MAINT@ is an anachronism now.
6619 $_ =~ s/\@MAINT\@//g
6620 unless $seen_maint_mode;
6622 my $new_saw_bk = check_trailing_slash ($where, $_);
6624 if (/$IGNORE_PATTERN/o)
6626 # Merely delete comments beginning with two hashes.
6628 # Keep any backslash from the previous line.
6629 $new_saw_bk = $saw_bk;
6631 elsif (/$WHITE_PATTERN/o)
6633 # Stick a single white line before the incoming macro or rule.
6635 error $where, "blank line following trailing backslash"
6638 elsif (/$COMMENT_PATTERN/o)
6640 error $where, "comment following trailing backslash"
6641 if $saw_bk && $prev_state != IN_COMMENT;
6643 # Stick comments before the incoming macro or rule.
6644 $comment .= $spacing . $_;
6646 $prev_state = IN_COMMENT;
6650 if ($prev_state == IN_RULE_DEF)
6652 my $cond = new Automake::Condition @cond_stack;
6653 $output_trailer .= $cond->subst_string;
6654 $output_trailer .= $_;
6656 elsif ($prev_state == IN_COMMENT)
6658 # If the line doesn't start with a `#', add it.
6659 # We do this because a continued comment like
6663 # is not portable. BSD make doesn't honor
6664 # escaped newlines in comments.
6666 $comment .= $spacing . $_;
6668 else # $prev_state == IN_VAR_DEF
6670 $last_var_value .= ' '
6671 unless $last_var_value =~ /\s$/;
6672 $last_var_value .= $_;
6676 Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
6677 $last_var_type, $cond,
6678 $last_var_value, $comment,
6679 $last_where, VAR_ASIS)
6681 $comment = $spacing = '';
6686 elsif (/$IF_PATTERN/o)
6688 $cond = cond_stack_if ($1, $2, $where);
6690 elsif (/$ELSE_PATTERN/o)
6692 $cond = cond_stack_else ($1, $2, $where);
6694 elsif (/$ENDIF_PATTERN/o)
6696 $cond = cond_stack_endif ($1, $2, $where);
6699 elsif (/$RULE_PATTERN/o)
6702 $prev_state = IN_RULE_DEF;
6704 # For now we have to output all definitions of user rules
6705 # and can't diagnose duplicates (see the comment in
6706 # Automake::Rule::define). So we go on and ignore the return value.
6707 Automake::Rule::define ($1, $amfile, RULE_USER, $cond, $where);
6709 check_variable_expansions ($_, $where);
6711 $output_trailer .= $comment . $spacing;
6712 my $cond = new Automake::Condition @cond_stack;
6713 $output_trailer .= $cond->subst_string;
6714 $output_trailer .= $_;
6715 $comment = $spacing = '';
6717 elsif (/$ASSIGNMENT_PATTERN/o)
6719 # Found a macro definition.
6720 $prev_state = IN_VAR_DEF;
6721 $last_var_name = $1;
6722 $last_var_type = $2;
6723 $last_var_value = $3;
6724 $last_where = $where->clone;
6725 if ($3 ne '' && substr ($3, -1) eq "\\")
6727 # We preserve the `\' because otherwise the long lines
6728 # that are generated will be truncated by broken
6730 $last_var_value = $3 . "\n";
6732 # Normally we try to output variable definitions in the
6733 # same format they were input. However, POSIX compliant
6734 # systems are not required to support lines longer than
6735 # 2048 bytes (most notably, some sed implementation are
6736 # limited to 4000 bytes, and sed is used by config.status
6737 # to rewrite Makefile.in into Makefile). Moreover nobody
6738 # would really write such long lines by hand since it is
6739 # hardly maintainable. So if a line is longer that 1000
6740 # bytes (an arbitrary limit), assume it has been
6741 # automatically generated by some tools, and flatten the
6742 # variable definition. Otherwise, keep the variable as it
6744 $var_look = VAR_PRETTY if length ($last_var_value) >= 1000;
6748 Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
6749 $last_var_type, $cond,
6750 $last_var_value, $comment,
6751 $last_where, $var_look)
6753 $comment = $spacing = '';
6754 $var_look = VAR_ASIS;
6757 elsif (/$INCLUDE_PATTERN/o)
6761 if ($path =~ s/^\$\(top_srcdir\)\///)
6763 push (@include_stack, "\$\(top_srcdir\)/$path");
6764 # Distribute any included file.
6766 # Always use the $(top_srcdir) prefix in DIST_COMMON,
6767 # otherwise OSF make will implicitly copy the included
6768 # file in the build tree during `make distdir' to satisfy
6770 # (subdircond2.test and subdircond3.test will fail.)
6771 push_dist_common ("\$\(top_srcdir\)/$path");
6775 $path =~ s/\$\(srcdir\)\///;
6776 push (@include_stack, "\$\(srcdir\)/$path");
6777 # Always use the $(srcdir) prefix in DIST_COMMON,
6778 # otherwise OSF make will implicitly copy the included
6779 # file in the build tree during `make distdir' to satisfy
6781 # (subdircond2.test and subdircond3.test will fail.)
6782 push_dist_common ("\$\(srcdir\)/$path");
6783 $path = $relative_dir . "/" . $path if $relative_dir ne '.';
6785 $where->push_context ("`$path' included from here");
6786 &read_am_file ($path, $where);
6787 $where->pop_context;
6791 # This isn't an error; it is probably a continued rule.
6792 # In fact, this is what we assume.
6793 $prev_state = IN_RULE_DEF;
6794 check_variable_expansions ($_, $where);
6795 $output_trailer .= $comment . $spacing;
6796 my $cond = new Automake::Condition @cond_stack;
6797 $output_trailer .= $cond->subst_string;
6798 $output_trailer .= $_;
6799 $comment = $spacing = '';
6800 error $where, "`#' comment at start of rule is unportable"
6801 if $_ =~ /^\t\s*\#/;
6804 $saw_bk = $new_saw_bk;
6805 $_ = $am_file->getline;
6808 $output_trailer .= $comment;
6810 error ($where, "trailing backslash on last line")
6813 error ($where, (@cond_stack ? "unterminated conditionals: @cond_stack"
6814 : "too many conditionals closed in include file"))
6815 if "@saved_cond_stack" ne "@cond_stack";
6819 # define_standard_variables ()
6820 # ----------------------------
6821 # A helper for read_main_am_file which initializes configure variables
6822 # and variables from header-vars.am.
6823 sub define_standard_variables
6825 my $saved_output_vars = $output_vars;
6826 my ($comments, undef, $rules) =
6827 file_contents_internal (1, "$libdir/am/header-vars.am",
6828 new Automake::Location);
6830 foreach my $var (sort keys %configure_vars)
6832 &define_configure_variable ($var);
6835 $output_vars .= $comments . $rules;
6838 # Read main am file.
6839 sub read_main_am_file
6843 # This supports the strange variable tricks we are about to play.
6844 prog_error ("variable defined before read_main_am_file\n" . variables_dump ())
6845 if (scalar (variables) > 0);
6847 # Generate copyright header for generated Makefile.in.
6848 # We do discard the output of predefined variables, handled below.
6849 $output_vars = ("# $in_file_name generated by automake "
6850 . $VERSION . " from $am_file_name.\n");
6851 $output_vars .= '# ' . subst ('configure_input') . "\n";
6852 $output_vars .= $gen_copyright;
6854 # We want to predefine as many variables as possible. This lets
6855 # the user set them with `+=' in Makefile.am.
6856 &define_standard_variables;
6858 # Read user file, which might override some of our values.
6859 &read_am_file ($amfile, new Automake::Location);
6864 ################################################################
6867 # &flatten ($STRING)
6868 # ------------------
6869 # Flatten the $STRING and return the result.
6883 # transform_token ($TOKEN, \%PAIRS, $KEY)
6884 # =======================================
6885 # Return the value associated to $KEY in %PAIRS, as used on $TOKEN
6886 # (which should be ?KEY? or any of the special %% requests)..
6887 sub transform_token ($$$)
6889 my ($token, $transform, $key) = @_;
6890 my $res = $transform->{$key};
6891 prog_error "Unknown key `$key' in `$token'" unless defined $res;
6896 # transform ($TOKEN, \%PAIRS)
6897 # ===========================
6898 # If ($TOKEN, $VAL) is in %PAIRS:
6899 # - replaces %KEY% with $VAL,
6900 # - enables/disables ?KEY? and ?!KEY?,
6901 # - replaces %?KEY% with TRUE or FALSE.
6902 # - replaces %KEY?IFTRUE%, %KEY:IFFALSE%, and %KEY?IFTRUE:IFFALSE% with
6903 # IFTRUE / IFFALSE, as appropriate.
6906 my ($token, $transform) = @_;
6909 # Must be before the following pattern to exclude the case
6910 # when there is neither IFTRUE nor IFFALSE.
6911 if ($token =~ /^%([\w\-]+)%$/)
6913 return transform_token ($token, $transform, $1);
6915 # %KEY?IFTRUE%, %KEY:IFFALSE%, and %KEY?IFTRUE:IFFALSE%.
6916 elsif ($token =~ /^%([\w\-]+)(?:\?([^?:%]+))?(?::([^?:%]+))?%$/)
6918 return transform_token ($token, $transform, $1) ? ($2 || '') : ($3 || '');
6921 elsif ($token =~ /^%\?([\w\-]+)%$/)
6923 return transform_token ($token, $transform, $1) ? 'TRUE' : 'FALSE';
6926 elsif ($token =~ /^ \? (!?) ([\w\-]+) \? $/x)
6928 my $neg = ($1 eq '!') ? 1 : 0;
6929 my $val = transform_token ($token, $transform, $2);
6930 return (!!$val == $neg) ? '##%' : '';
6934 prog_error "Unknown request format: $token";
6940 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
6941 # ------------------------------------------
6942 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6944 sub make_paragraphs ($%)
6946 my ($file, %transform) = @_;
6948 # Complete %transform with global options.
6949 # Note that %transform goes last, so it overrides global options.
6950 %transform = ('CYGNUS' => !! option 'cygnus',
6952 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
6954 'XZ' => !! option 'dist-xz',
6955 'LZMA' => !! option 'dist-lzma',
6956 'LZIP' => !! option 'dist-lzip',
6957 'BZIP2' => !! option 'dist-bzip2',
6958 'COMPRESS' => !! option 'dist-tarZ',
6959 'GZIP' => ! option 'no-dist-gzip',
6960 'SHAR' => !! option 'dist-shar',
6961 'ZIP' => !! option 'dist-zip',
6963 'INSTALL-INFO' => ! option 'no-installinfo',
6964 'INSTALL-MAN' => ! option 'no-installman',
6965 'HAVE-MANS' => !! var ('MANS'),
6966 'CK-NEWS' => !! option 'check-news',
6968 'SUBDIRS' => !! var ('SUBDIRS'),
6969 'TOPDIR_P' => $relative_dir eq '.',
6971 'BUILD' => ($seen_canonical >= AC_CANONICAL_BUILD),
6972 'HOST' => ($seen_canonical >= AC_CANONICAL_HOST),
6973 'TARGET' => ($seen_canonical >= AC_CANONICAL_TARGET),
6975 'LIBTOOL' => !! var ('LIBTOOL'),
6977 'FIRST' => ! $transformed_files{$file},
6980 $transformed_files{$file} = 1;
6981 $_ = $am_file_cache{$file};
6985 verb "reading $file";
6986 # Swallow the whole file.
6987 my $fc_file = new Automake::XFile "< $file";
6988 my $saved_dollar_slash = $/;
6990 $_ = $fc_file->getline;
6991 $/ = $saved_dollar_slash;
6994 # Remove ##-comments.
6995 # Besides we don't need more than two consecutive new-lines.
6996 s/(?:$IGNORE_PATTERN|(?<=\n\n)\n+)//gom;
6998 $am_file_cache{$file} = $_;
7001 # Substitute Automake template tokens.
7002 s/(?: % \?? [\w\-]+ %
7003 | % [\w\-]+ (?:\?[^?:%]+)? (?::[^?:%]+)? %
7005 )/transform($&, \%transform)/gex;
7006 # transform() may have added some ##%-comments to strip.
7007 # (we use `##%' instead of `##' so we can distinguish ##%##%##% from
7008 # ####### and do not remove the latter.)
7009 s/^[ \t]*(?:##%)+.*\n//gm;
7011 # Split at unescaped new lines.
7012 my @lines = split (/(?<!\\)\n/, $_);
7015 while (defined ($_ = shift @lines))
7018 # If we are a rule, eat as long as we start with a tab.
7019 if (/$RULE_PATTERN/smo)
7021 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
7023 $paragraph .= "\n$_";
7025 unshift (@lines, $_);
7028 # If we are a comments, eat as much comments as you can.
7029 elsif (/$COMMENT_PATTERN/smo)
7031 while (defined ($_ = shift @lines)
7032 && $_ =~ /$COMMENT_PATTERN/smo)
7034 $paragraph .= "\n$_";
7036 unshift (@lines, $_);
7039 push @res, $paragraph;
7047 # ($COMMENT, $VARIABLES, $RULES)
7048 # &file_contents_internal ($IS_AM, $FILE, $WHERE, [%TRANSFORM])
7049 # -------------------------------------------------------------
7050 # Return contents of a file from $libdir/am, automatically skipping
7051 # macros or rules which are already known. $IS_AM iff the caller is
7052 # reading an Automake file (as opposed to the user's Makefile.am).
7053 sub file_contents_internal ($$$%)
7055 my ($is_am, $file, $where, %transform) = @_;
7057 $where->set ($file);
7059 my $result_vars = '';
7060 my $result_rules = '';
7064 # The following flags are used to track rules spanning across
7065 # multiple paragraphs.
7066 my $is_rule = 0; # 1 if we are processing a rule.
7067 my $discard_rule = 0; # 1 if the current rule should not be output.
7069 # We save the conditional stack on entry, and then check to make
7070 # sure it is the same on exit. This lets us conditionally include
7072 my @saved_cond_stack = @cond_stack;
7073 my $cond = new Automake::Condition (@cond_stack);
7075 foreach (make_paragraphs ($file, %transform))
7077 # FIXME: no line number available.
7078 $where->set ($file);
7081 error $where, "blank line following trailing backslash:\n$_"
7083 error $where, "comment following trailing backslash:\n$_"
7089 # Stick empty line before the incoming macro or rule.
7092 elsif (/$COMMENT_PATTERN/mso)
7095 # Stick comments before the incoming macro or rule.
7099 # Handle inclusion of other files.
7100 elsif (/$INCLUDE_PATTERN/o)
7104 my $file = ($is_am ? "$libdir/am/" : '') . $1;
7105 $where->push_context ("`$file' included from here");
7107 my ($com, $vars, $rules)
7108 = file_contents_internal ($is_am, $file, $where, %transform);
7109 $where->pop_context;
7111 $result_vars .= $vars;
7112 $result_rules .= $rules;
7116 # Handling the conditionals.
7117 elsif (/$IF_PATTERN/o)
7119 $cond = cond_stack_if ($1, $2, $file);
7121 elsif (/$ELSE_PATTERN/o)
7123 $cond = cond_stack_else ($1, $2, $file);
7125 elsif (/$ENDIF_PATTERN/o)
7127 $cond = cond_stack_endif ($1, $2, $file);
7131 elsif (/$RULE_PATTERN/mso)
7135 # Separate relationship from optional actions: the first
7136 # `new-line tab" not preceded by backslash (continuation
7139 /^(.*?)(?:(?<!\\)\n(\t.*))?$/s;
7140 my ($relationship, $actions) = ($1, $2 || '');
7142 # Separate targets from dependencies: the first colon.
7143 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
7144 my ($targets, $dependencies) = ($1, $2);
7145 # Remove the escaped new lines.
7146 # I don't know why, but I have to use a tmp $flat_deps.
7147 my $flat_deps = &flatten ($dependencies);
7148 my @deps = split (' ', $flat_deps);
7150 foreach (split (' ', $targets))
7152 # FIXME: 1. We are not robust to people defining several targets
7153 # at once, only some of them being in %dependencies. The
7154 # actions from the targets in %dependencies are usually generated
7155 # from the content of %actions, but if some targets in $targets
7156 # are not in %dependencies the ELSE branch will output
7157 # a rule for all $targets (i.e. the targets which are both
7158 # in %dependencies and $targets will have two rules).
7160 # FIXME: 2. The logic here is not able to output a
7161 # multi-paragraph rule several time (e.g. for each condition
7162 # it is defined for) because it only knows the first paragraph.
7164 # FIXME: 3. We are not robust to people defining a subset
7165 # of a previously defined "multiple-target" rule. E.g.
7166 # `foo:' after `foo bar:'.
7168 # Output only if not in FALSE.
7169 if (defined $dependencies{$_} && $cond != FALSE)
7171 &depend ($_, @deps);
7172 register_action ($_, $actions);
7176 # Free-lance dependency. Output the rule for all the
7177 # targets instead of one by one.
7178 my @undefined_conds =
7179 Automake::Rule::define ($targets, $file,
7180 $is_am ? RULE_AUTOMAKE : RULE_USER,
7182 for my $undefined_cond (@undefined_conds)
7184 my $condparagraph = $paragraph;
7185 $condparagraph =~ s/^/$undefined_cond->subst_string/gme;
7186 $result_rules .= "$spacing$comment$condparagraph\n";
7188 if (scalar @undefined_conds == 0)
7190 # Remember to discard next paragraphs
7191 # if they belong to this rule.
7192 # (but see also FIXME: #2 above.)
7195 $comment = $spacing = '';
7201 elsif (/$ASSIGNMENT_PATTERN/mso)
7203 my ($var, $type, $val) = ($1, $2, $3);
7204 error $where, "variable `$var' with trailing backslash"
7209 Automake::Variable::define ($var,
7210 $is_am ? VAR_AUTOMAKE : VAR_MAKEFILE,
7211 $type, $cond, $val, $comment, $where,
7215 $comment = $spacing = '';
7219 # This isn't an error; it is probably some tokens which
7220 # configure is supposed to replace, such as `@SET-MAKE@',
7221 # or some part of a rule cut by an if/endif.
7222 if (! $cond->false && ! ($is_rule && $discard_rule))
7224 s/^/$cond->subst_string/gme;
7225 $result_rules .= "$spacing$comment$_\n";
7227 $comment = $spacing = '';
7231 error ($where, @cond_stack ?
7232 "unterminated conditionals: @cond_stack" :
7233 "too many conditionals closed in include file")
7234 if "@saved_cond_stack" ne "@cond_stack";
7236 return ($comment, $result_vars, $result_rules);
7241 # &file_contents ($BASENAME, $WHERE, [%TRANSFORM])
7242 # ------------------------------------------------
7243 # Return contents of a file from $libdir/am, automatically skipping
7244 # macros or rules which are already known.
7245 sub file_contents ($$%)
7247 my ($basename, $where, %transform) = @_;
7248 my ($comments, $variables, $rules) =
7249 file_contents_internal (1, "$libdir/am/$basename.am", $where,
7251 return "$comments$variables$rules";
7256 # &am_primary_prefixes ($PRIMARY, $CAN_DIST, @PREFIXES)
7257 # -----------------------------------------------------
7258 # Find all variable prefixes that are used for install directories. A
7259 # prefix `zar' qualifies iff:
7261 # * `zardir' is a variable.
7262 # * `zar_PRIMARY' is a variable.
7264 # As a side effect, it looks for misspellings. It is an error to have
7265 # a variable ending in a "reserved" suffix whose prefix is unknown, e.g.
7266 # "bni_PROGRAMS". However, unusual prefixes are allowed if a variable
7267 # of the same name (with "dir" appended) exists. For instance, if the
7268 # variable "zardir" is defined, then "zar_PROGRAMS" becomes valid.
7269 # This is to provide a little extra flexibility in those cases which
7271 sub am_primary_prefixes ($$@)
7273 my ($primary, $can_dist, @prefixes) = @_;
7276 my %valid = map { $_ => 0 } @prefixes;
7277 $valid{'EXTRA'} = 0;
7278 foreach my $var (variables $primary)
7280 # Automake is allowed to define variables that look like primaries
7281 # but which aren't. E.g. INSTALL_sh_DATA.
7282 # Autoconf can also define variables like INSTALL_DATA, so
7283 # ignore all configure variables (at least those which are not
7284 # redefined in Makefile.am).
7285 # FIXME: We should make sure that these variables are not
7286 # conditionally defined (or else adjust the condition below).
7287 my $def = $var->def (TRUE);
7288 next if $def && $def->owner != VAR_MAKEFILE;
7290 my $varname = $var->name;
7292 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_[[:alnum:]]+$/)
7294 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
7295 if ($dist ne '' && ! $can_dist)
7298 "invalid variable `$varname': `dist' is forbidden");
7300 # Standard directories must be explicitly allowed.
7301 elsif (! defined $valid{$X} && exists $standard_prefix{$X})
7304 "`${X}dir' is not a legitimate directory " .
7307 # A not explicitly valid directory is allowed if Xdir is defined.
7308 elsif (! defined $valid{$X} &&
7309 $var->requires_variables ("`$varname' is used", "${X}dir"))
7311 # Nothing to do. Any error message has been output
7312 # by $var->requires_variables.
7316 # Ensure all extended prefixes are actually used.
7317 $valid{"$base$dist$X"} = 1;
7322 prog_error "unexpected variable name: $varname";
7326 # Return only those which are actually defined.
7327 return sort grep { var ($_ . '_' . $primary) } keys %valid;
7331 # Handle `where_HOW' variable magic. Does all lookups, generates
7332 # install code, and possibly generates code to define the primary
7333 # variable. The first argument is the name of the .am file to munge,
7334 # the second argument is the primary variable (e.g. HEADERS), and all
7335 # subsequent arguments are possible installation locations.
7337 # Returns list of [$location, $value] pairs, where
7338 # $value's are the values in all where_HOW variable, and $location
7339 # there associated location (the place here their parent variables were
7342 # FIXME: this should be rewritten to be cleaner. It should be broken
7343 # up into multiple functions.
7345 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7352 my $default_dist = 0;
7355 if ($args[0] eq '-noextra')
7359 elsif ($args[0] eq '-candist')
7363 elsif ($args[0] eq '-defaultdist')
7368 elsif ($args[0] !~ /^-/)
7375 my ($file, $primary, @prefix) = @args;
7377 # Now that configure substitutions are allowed in where_HOW
7378 # variables, it is an error to actually define the primary. We
7379 # allow `JAVA', as it is customarily used to mean the Java
7380 # interpreter. This is but one of several Java hacks. Similarly,
7381 # `PYTHON' is customarily used to mean the Python interpreter.
7382 reject_var $primary, "`$primary' is an anachronism"
7383 unless $primary eq 'JAVA' || $primary eq 'PYTHON';
7385 # Get the prefixes which are valid and actually used.
7386 @prefix = am_primary_prefixes ($primary, $can_dist, @prefix);
7388 # If a primary includes a configure substitution, then the EXTRA_
7389 # form is required. Otherwise we can't properly do our job.
7395 foreach my $X (@prefix)
7397 my $nodir_name = $X;
7398 my $one_name = $X . '_' . $primary;
7399 my $one_var = var $one_name;
7401 my $strip_subdir = 1;
7402 # If subdir prefix should be preserved, do so.
7403 if ($nodir_name =~ /^nobase_/)
7406 $nodir_name =~ s/^nobase_//;
7409 # If files should be distributed, do so.
7413 $dist_p = (($default_dist && $nodir_name !~ /^nodist_/)
7414 || (! $default_dist && $nodir_name =~ /^dist_/));
7415 $nodir_name =~ s/^(dist|nodist)_//;
7419 # Use the location of the currently processed variable.
7420 # We are not processing a particular condition, so pick the first
7422 my $tmpcond = $one_var->conditions->one_cond;
7423 my $where = $one_var->rdef ($tmpcond)->location->clone;
7425 # Append actual contents of where_PRIMARY variable to
7426 # @result, skipping @substitutions@.
7427 foreach my $locvals ($one_var->value_as_list_recursive (location => 1))
7429 my ($loc, $value) = @$locvals;
7430 # Skip configure substitutions.
7431 if ($value =~ /^\@.*\@$/)
7433 if ($nodir_name eq 'EXTRA')
7436 "`$one_name' contains configure substitution, "
7439 # Check here to make sure variables defined in
7440 # configure.ac do not imply that EXTRA_PRIMARY
7442 elsif (! defined $configure_vars{$one_name})
7444 $require_extra = $one_name
7450 # Strip any $(EXEEXT) suffix the user might have added, or this
7451 # will confuse &handle_source_transform and &check_canonical_spelling.
7452 # We'll add $(EXEEXT) back later anyway.
7453 # Do it here rather than in handle_programs so the uniquifying at the
7454 # end of this function works.
7455 ${$locvals}[1] =~ s/\$\(EXEEXT\)$//
7456 if $primary eq 'PROGRAMS';
7458 push (@result, $locvals);
7461 # A blatant hack: we rewrite each _PROGRAMS primary to include
7463 append_exeext { 1 } $one_name
7464 if $primary eq 'PROGRAMS';
7465 # "EXTRA" shouldn't be used when generating clean targets,
7466 # all, or install targets. We used to warn if EXTRA_FOO was
7467 # defined uselessly, but this was annoying.
7469 if $nodir_name eq 'EXTRA';
7471 if ($nodir_name eq 'check')
7473 push (@check, '$(' . $one_name . ')');
7477 push (@used, '$(' . $one_name . ')');
7480 # Is this to be installed?
7481 my $install_p = $nodir_name ne 'noinst' && $nodir_name ne 'check';
7483 # If so, with install-exec? (or install-data?).
7484 my $exec_p = ($nodir_name =~ /$EXEC_DIR_PATTERN/o);
7486 my $check_options_p = $install_p && !! option 'std-options';
7488 # Use the location of the currently processed variable as context.
7489 $where->push_context ("while processing `$one_name'");
7491 # The variable containing all files to distribute.
7492 my $distvar = "\$($one_name)";
7493 $distvar = shadow_unconditionally ($one_name, $where)
7494 if ($dist_p && $one_var->has_conditional_contents);
7496 # Singular form of $PRIMARY.
7497 (my $one_primary = $primary) =~ s/S$//;
7498 $output_rules .= &file_contents ($file, $where,
7499 PRIMARY => $primary,
7500 ONE_PRIMARY => $one_primary,
7502 NDIR => $nodir_name,
7503 BASE => $strip_subdir,
7506 INSTALL => $install_p,
7508 DISTVAR => $distvar,
7509 'CK-OPTS' => $check_options_p);
7512 # The JAVA variable is used as the name of the Java interpreter.
7513 # The PYTHON variable is used as the name of the Python interpreter.
7514 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7517 define_pretty_variable ($primary, TRUE, INTERNAL, @used);
7518 $output_vars .= "\n";
7521 err_var ($require_extra,
7522 "`$require_extra' contains configure substitution,\n"
7523 . "but `EXTRA_$primary' not defined")
7524 if ($require_extra && ! var ('EXTRA_' . $primary));
7526 # Push here because PRIMARY might be configure time determined.
7527 push (@all, '$(' . $primary . ')')
7528 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7530 # Make the result unique. This lets the user use conditionals in
7531 # a natural way, but still lets us program lazily -- we don't have
7532 # to worry about handling a particular object more than once.
7533 # We will keep only one location per object.
7535 for my $pair (@result)
7537 my ($loc, $val) = @$pair;
7538 $result{$val} = $loc;
7540 my @l = sort keys %result;
7541 return map { [$result{$_}->clone, $_] } @l;
7545 ################################################################
7547 # Each key in this hash is the name of a directory holding a
7548 # Makefile.in. These variables are local to `is_make_dir'.
7550 my $make_dirs_set = 0;
7555 if (! $make_dirs_set)
7557 foreach my $iter (@configure_input_files)
7559 $make_dirs{dirname ($iter)} = 1;
7561 # We also want to notice Makefile.in's.
7562 foreach my $iter (@other_input_files)
7564 if ($iter =~ /Makefile\.in$/)
7566 $make_dirs{dirname ($iter)} = 1;
7571 return defined $make_dirs{$dir};
7574 ################################################################
7576 # Find the aux dir. This should match the algorithm used by
7577 # ./configure. (See the Autoconf documentation for for
7578 # AC_CONFIG_AUX_DIR.)
7579 sub locate_aux_dir ()
7581 if (! $config_aux_dir_set_in_configure_ac)
7583 # The default auxiliary directory is the first
7584 # of ., .., or ../.. that contains install-sh.
7585 # Assume . if install-sh doesn't exist yet.
7586 for my $dir (qw (. .. ../..))
7588 if (-f "$dir/install-sh")
7590 $config_aux_dir = $dir;
7594 $config_aux_dir = '.' unless $config_aux_dir;
7596 # Avoid unsightly '/.'s.
7597 $am_config_aux_dir =
7598 '$(top_srcdir)' . ($config_aux_dir eq '.' ? "" : "/$config_aux_dir");
7599 $am_config_aux_dir =~ s,/*$,,;
7603 # &push_required_file ($DIR, $FILE, $FULLFILE)
7604 # --------------------------------------------------
7605 # Push the given file onto DIST_COMMON.
7606 sub push_required_file
7608 my ($dir, $file, $fullfile) = @_;
7610 # If the file to be distributed is in the same directory of the
7611 # currently processed Makefile.am, then we want to distribute it
7612 # from this same Makefile.am.
7613 if ($dir eq $relative_dir)
7615 push_dist_common ($file);
7617 # This is needed to allow a construct in a non-top-level Makefile.am
7618 # to require a file in the build-aux directory (see at least the test
7619 # script `test-driver-is-distributed.test'). This is related to the
7620 # automake bug#9546. Note that the use of $config_aux_dir instead
7621 # of $am_config_aux_dir here is deliberate and necessary.
7622 elsif ($dir eq $config_aux_dir)
7624 push_dist_common ("$am_config_aux_dir/$file");
7626 # FIXME: another spacial case, for AC_LIBOBJ/AC_LIBSOURCE support.
7627 # We probably need some refactoring of this function and its callers,
7628 # to have a more explicit and systematic handling of all the special
7629 # cases; but, since there are only two of them, this is low-priority
7631 elsif ($config_libobj_dir && $dir eq $config_libobj_dir)
7633 # Avoid unsightly '/.'s.
7634 my $am_config_libobj_dir =
7636 ($config_libobj_dir eq '.' ? "" : "/$config_libobj_dir");
7637 $am_config_libobj_dir =~ s|/*$||;
7638 push_dist_common ("$am_config_libobj_dir/$file");
7640 elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7642 # If we are doing the topmost directory, and the file is in a
7643 # subdir which does not have a Makefile, then we distribute it
7646 # If a required file is above the source tree, it is important
7647 # to prefix it with `$(srcdir)' so that no VPATH search is
7648 # performed. Otherwise problems occur with Make implementations
7649 # that rewrite and simplify rules whose dependencies are found in a
7650 # VPATH location. Here is an example with OSF1/Tru64 Make.
7662 # Dependency `../a' was found in `sub/../a', but this make
7663 # implementation simplified it as `a'. (Note that the sub/
7664 # directory does not even exist.)
7666 # This kind of VPATH rewriting seems hard to cancel. The
7667 # distdir.am hack against VPATH rewriting works only when no
7668 # simplification is done, i.e., for dependencies which are in
7669 # subdirectories, not in enclosing directories. Hence, in
7670 # the latter case we use a full path to make sure no VPATH
7672 $fullfile = '$(srcdir)/' . $fullfile
7673 if $dir =~ m,^\.\.(?:$|/),;
7675 push_dist_common ($fullfile);
7679 prog_error "a Makefile in relative directory $relative_dir " .
7680 "can't add files in directory $dir to DIST_COMMON";
7685 # If a file name appears as a key in this hash, then it has already
7686 # been checked for. This allows us not to report the same error more
7688 my %required_file_not_found = ();
7690 # &required_file_check_or_copy ($WHERE, $DIRECTORY, $FILE)
7691 # --------------------------------------------------------
7692 # Verify that the file must exist in $DIRECTORY, or install it.
7693 sub required_file_check_or_copy ($$$)
7695 my ($where, $dir, $file) = @_;
7697 my $fullfile = "$dir/$file";
7699 my $dangling_sym = 0;
7701 if (-l $fullfile && ! -f $fullfile)
7705 elsif (dir_has_case_matching_file ($dir, $file))
7710 # `--force-missing' only has an effect if `--add-missing' is
7713 if $found_it && (! $add_missing || ! $force_missing);
7715 # If we've already looked for it, we're done. You might
7716 # wonder why we don't do this before searching for the
7717 # file. If we do that, then something like
7718 # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
7722 return if defined $required_file_not_found{$fullfile};
7723 $required_file_not_found{$fullfile} = 1;
7725 if ($dangling_sym && $add_missing)
7734 # Only install missing files according to our desired
7736 my $message = "required file `$fullfile' not found";
7739 if (-f "$libdir/$file")
7743 # Install the missing file. Symlink if we
7744 # can, copy if we must. Note: delete the file
7745 # first, in case it is a dangling symlink.
7746 $message = "installing `$fullfile'";
7748 # The license file should not be volatile.
7749 if ($file eq "COPYING")
7751 $message .= " using GNU General Public License v3 file";
7752 $trailer2 = "\n Consider adding the COPYING file"
7753 . " to the version control system"
7754 . "\n for your code, to avoid questions"
7755 . " about which license your project uses";
7758 # Windows Perl will hang if we try to delete a
7759 # file that doesn't exist.
7760 unlink ($fullfile) if -f $fullfile;
7761 if ($symlink_exists && ! $copy_missing)
7763 if (! symlink ("$libdir/$file", $fullfile)
7767 $trailer = "; error while making link: $!";
7770 elsif (system ('cp', "$libdir/$file", $fullfile))
7773 $trailer = "\n error while copying";
7775 set_dir_cache_file ($dir, $file);
7780 $trailer = "\n `automake --add-missing' can install `$file'"
7781 if -f "$libdir/$file";
7784 # If --force-missing was specified, and we have
7785 # actually found the file, then do nothing.
7787 if $found_it && $force_missing;
7789 # If we couldn't install the file, but it is a target in
7790 # the Makefile, don't print anything. This allows files
7791 # like README, AUTHORS, or THANKS to be generated.
7793 if !$suppress && rule $file;
7795 msg ($suppress ? 'note' : 'error', $where, "$message$trailer$trailer2");
7799 # &require_file_internal ($WHERE, $MYSTRICT, $DIRECTORY, $QUEUE, @FILES)
7800 # ----------------------------------------------------------------------
7801 # Verify that the file must exist in $DIRECTORY, or install it.
7802 # $MYSTRICT is the strictness level at which this file becomes required.
7803 # Worker threads may queue up the action to be serialized by the master,
7805 sub require_file_internal ($$$@)
7807 my ($where, $mystrict, $dir, $queue, @files) = @_;
7810 unless $strictness >= $mystrict;
7812 foreach my $file (@files)
7814 push_required_file ($dir, $file, "$dir/$file");
7817 queue_required_file_check_or_copy ($required_conf_file_queue,
7818 QUEUE_CONF_FILE, $relative_dir,
7819 $where, $mystrict, @files);
7823 required_file_check_or_copy ($where, $dir, $file);
7828 # &require_file ($WHERE, $MYSTRICT, @FILES)
7829 # -----------------------------------------
7830 sub require_file ($$@)
7832 my ($where, $mystrict, @files) = @_;
7833 require_file_internal ($where, $mystrict, $relative_dir, 0, @files);
7836 # &require_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7837 # -----------------------------------------------------------
7838 sub require_file_with_macro ($$$@)
7840 my ($cond, $macro, $mystrict, @files) = @_;
7841 $macro = rvar ($macro) unless ref $macro;
7842 require_file ($macro->rdef ($cond)->location, $mystrict, @files);
7845 # &require_libsource_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7846 # ----------------------------------------------------------------
7847 # Require an AC_LIBSOURCEd file. If AC_CONFIG_LIBOBJ_DIR was called, it
7848 # must be in that directory. Otherwise expect it in the current directory.
7849 sub require_libsource_with_macro ($$$@)
7851 my ($cond, $macro, $mystrict, @files) = @_;
7852 $macro = rvar ($macro) unless ref $macro;
7853 if ($config_libobj_dir)
7855 require_file_internal ($macro->rdef ($cond)->location, $mystrict,
7856 $config_libobj_dir, 0, @files);
7860 require_file ($macro->rdef ($cond)->location, $mystrict, @files);
7864 # &queue_required_file_check_or_copy ($QUEUE, $KEY, $DIR, $WHERE,
7865 # $MYSTRICT, @FILES)
7866 # ---------------------------------------------------------------
7867 sub queue_required_file_check_or_copy ($$$$@)
7869 my ($queue, $key, $dir, $where, $mystrict, @files) = @_;
7873 @serial_loc = (QUEUE_LOCATION, $where->serialize ());
7877 @serial_loc = (QUEUE_STRING, $where);
7879 $queue->enqueue ($key, $dir, @serial_loc, $mystrict, 0 + @files, @files);
7882 # &require_queued_file_check_or_copy ($QUEUE)
7883 # -------------------------------------------
7884 sub require_queued_file_check_or_copy ($)
7888 my $dir = $queue->dequeue ();
7889 my $loc_key = $queue->dequeue ();
7890 if ($loc_key eq QUEUE_LOCATION)
7892 $where = Automake::Location::deserialize ($queue);
7894 elsif ($loc_key eq QUEUE_STRING)
7896 $where = $queue->dequeue ();
7900 prog_error "unexpected key $loc_key";
7902 my $mystrict = $queue->dequeue ();
7903 my $nfiles = $queue->dequeue ();
7905 push @files, $queue->dequeue ()
7906 foreach (1 .. $nfiles);
7908 unless $strictness >= $mystrict;
7909 foreach my $file (@files)
7911 required_file_check_or_copy ($where, $config_aux_dir, $file);
7915 # &require_conf_file ($WHERE, $MYSTRICT, @FILES)
7916 # ----------------------------------------------
7917 # Looks in configuration path, as specified by AC_CONFIG_AUX_DIR.
7918 sub require_conf_file ($$@)
7920 my ($where, $mystrict, @files) = @_;
7921 my $queue = defined $required_conf_file_queue ? 1 : 0;
7922 require_file_internal ($where, $mystrict, $config_aux_dir,
7927 # &require_conf_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7928 # ----------------------------------------------------------------
7929 sub require_conf_file_with_macro ($$$@)
7931 my ($cond, $macro, $mystrict, @files) = @_;
7932 require_conf_file (rvar ($macro)->rdef ($cond)->location,
7936 ################################################################
7938 # &require_build_directory ($DIRECTORY)
7939 # -------------------------------------
7940 # Emit rules to create $DIRECTORY if needed, and return
7941 # the file that any target requiring this directory should be made
7943 # We don't want to emit the rule twice, and want to reuse it
7944 # for directories with equivalent names (e.g., `foo/bar' and `./foo//bar').
7945 sub require_build_directory ($)
7947 my $directory = shift;
7949 return $directory_map{$directory} if exists $directory_map{$directory};
7951 my $cdir = File::Spec->canonpath ($directory);
7953 if (exists $directory_map{$cdir})
7955 my $stamp = $directory_map{$cdir};
7956 $directory_map{$directory} = $stamp;
7960 my $dirstamp = "$cdir/\$(am__dirstamp)";
7962 $directory_map{$directory} = $dirstamp;
7963 $directory_map{$cdir} = $dirstamp;
7965 # Set a variable for the dirstamp basename.
7966 define_pretty_variable ('am__dirstamp', TRUE, INTERNAL,
7967 '$(am__leading_dot)dirstamp');
7969 # Directory must be removed by `make distclean'.
7970 $clean_files{$dirstamp} = DIST_CLEAN;
7972 $output_rules .= ("$dirstamp:\n"
7973 . "\t\@\$(MKDIR_P) $directory\n"
7974 . "\t\@: > $dirstamp\n");
7979 # &require_build_directory_maybe ($FILE)
7980 # --------------------------------------
7981 # If $FILE lies in a subdirectory, emit a rule to create this
7982 # directory and return the file that $FILE should be made
7983 # dependent upon. Otherwise, just return the empty string.
7984 sub require_build_directory_maybe ($)
7987 my $directory = dirname ($file);
7989 if ($directory ne '.')
7991 return require_build_directory ($directory);
7999 ################################################################
8001 # Push a list of files onto dist_common.
8002 sub push_dist_common
8004 prog_error "push_dist_common run after handle_dist"
8005 if $handle_dist_run;
8006 Automake::Variable::define ('DIST_COMMON', VAR_AUTOMAKE, '+', TRUE, "@_",
8007 '', INTERNAL, VAR_PRETTY);
8011 ################################################################
8013 # generate_makefile ($MAKEFILE_AM, $MAKEFILE_IN)
8014 # ----------------------------------------------
8015 # Generate a Makefile.in given the name of the corresponding Makefile and
8016 # the name of the file output by config.status.
8017 sub generate_makefile ($$)
8019 my ($makefile_am, $makefile_in) = @_;
8021 # Reset all the Makefile.am related variables.
8022 initialize_per_input;
8024 # AUTOMAKE_OPTIONS can contains -W flags to disable or enable
8025 # warnings for this file. So hold any warning issued before
8026 # we have processed AUTOMAKE_OPTIONS.
8027 buffer_messages ('warning');
8029 # Name of input file ("Makefile.am") and output file
8030 # ("Makefile.in"). These have no directory components.
8031 $am_file_name = basename ($makefile_am);
8032 $in_file_name = basename ($makefile_in);
8034 # $OUTPUT is encoded. If it contains a ":" then the first element
8035 # is the real output file, and all remaining elements are input
8036 # files. We don't scan or otherwise deal with these input files,
8037 # other than to mark them as dependencies. See
8038 # &scan_autoconf_files for details.
8039 my ($makefile, @inputs) = split (/:/, $output_files{$makefile_in});
8041 $relative_dir = dirname ($makefile);
8042 $am_relative_dir = dirname ($makefile_am);
8043 $topsrcdir = backname ($relative_dir);
8045 read_main_am_file ($makefile_am);
8048 # Process buffered warnings.
8050 # Fatal error. Just return, so we can continue with next file.
8053 # Process buffered warnings.
8056 # There are a few install-related variables that you should not define.
8057 foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
8062 my $def = $v->def (TRUE);
8063 prog_error "$var not defined in condition TRUE"
8065 reject_var $var, "`$var' should not be defined"
8066 if $def->owner != VAR_AUTOMAKE;
8070 # Catch some obsolete variables.
8071 msg_var ('obsolete', 'INCLUDES',
8072 "`INCLUDES' is the old name for `AM_CPPFLAGS' (or `*_CPPFLAGS')")
8073 if var ('INCLUDES');
8075 # Must do this after reading .am file.
8076 define_variable ('subdir', $relative_dir, INTERNAL);
8078 # If DIST_SUBDIRS is defined, make sure SUBDIRS is, so that
8079 # recursive rules are enabled.
8080 define_pretty_variable ('SUBDIRS', TRUE, INTERNAL, '')
8081 if var 'DIST_SUBDIRS' && ! var 'SUBDIRS';
8083 # Check first, because we might modify some state.
8085 check_gnu_standards;
8086 check_gnits_standards;
8088 handle_configure ($makefile_am, $makefile_in, $makefile, @inputs);
8095 # These must be run after all the sources are scanned. They
8096 # use variables defined by &handle_libraries, &handle_ltlibraries,
8097 # or &handle_programs.
8102 # Variables used by distdir.am and tags.am.
8103 define_pretty_variable ('SOURCES', TRUE, INTERNAL, @sources);
8104 if (! option 'no-dist')
8106 define_pretty_variable ('DIST_SOURCES', TRUE, INTERNAL, @dist_sources);
8118 handle_minor_options;
8119 # Must come after handle_programs so that %known_programs is up-to-date.
8122 # This must come after most other rules.
8126 do_check_merge_target;
8127 handle_all ($makefile);
8130 if (var ('lib_LTLIBRARIES') && var ('bin_PROGRAMS'))
8132 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
8134 if (var ('nobase_lib_LTLIBRARIES') && var ('bin_PROGRAMS'))
8136 $output_rules .= "install-binPROGRAMS: install-nobase_libLTLIBRARIES\n\n";
8140 handle_clean ($makefile);
8141 handle_factored_dependencies;
8143 # Comes last, because all the above procedures may have
8144 # defined or overridden variables.
8145 $output_vars .= output_variables;
8149 if ($exit_code != 0)
8151 verb "not writing $makefile_in because of earlier errors";
8155 mkdir ($am_relative_dir, 0755) if ! -d $am_relative_dir;
8157 # We make sure that `all:' is the first target.
8159 "$output_vars$output_all$output_header$output_rules$output_trailer";
8161 # Decide whether we must update the output file or not.
8162 # We have to update in the following situations.
8163 # * $force_generation is set.
8164 # * any of the output dependencies is younger than the output
8165 # * the contents of the output is different (this can happen
8166 # if the project has been populated with a file listed in
8167 # @common_files since the last run).
8168 # Output's dependencies are split in two sets:
8169 # * dependencies which are also configure dependencies
8170 # These do not change between each Makefile.am
8171 # * other dependencies, specific to the Makefile.am being processed
8172 # (such as the Makefile.am itself, or any Makefile fragment
8174 my $timestamp = mtime $makefile_in;
8175 if (! $force_generation
8176 && $configure_deps_greatest_timestamp < $timestamp
8177 && $output_deps_greatest_timestamp < $timestamp
8178 && $output eq contents ($makefile_in))
8180 verb "$makefile_in unchanged";
8181 # No need to update.
8185 if (-e $makefile_in)
8187 unlink ($makefile_in)
8188 or fatal "cannot remove $makefile_in: $!";
8191 my $gm_file = new Automake::XFile "> $makefile_in";
8192 verb "creating $makefile_in";
8193 print $gm_file $output;
8196 ################################################################
8201 ################################################################
8203 # Helper function for usage().
8204 sub print_autodist_files (@)
8206 my @lcomm = sort (&uniq (@_));
8209 format USAGE_FORMAT =
8210 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
8211 $four[0], $four[1], $four[2], $four[3]
8213 local $~ = "USAGE_FORMAT";
8216 my $rows = int(@lcomm / $cols);
8217 my $rest = @lcomm % $cols;
8228 for (my $y = 0; $y < $rows; $y++)
8230 @four = ("", "", "", "");
8231 for (my $x = 0; $x < $cols; $x++)
8233 last if $y + 1 == $rows && $x == $rest;
8235 my $idx = (($x > $rest)
8236 ? ($rows * $rest + ($rows - 1) * ($x - $rest))
8240 $four[$x] = $lcomm[$idx];
8247 # Print usage information.
8250 print "Usage: $0 [OPTION]... [Makefile]...
8252 Generate Makefile.in for configure from Makefile.am.
8255 --help print this help, then exit
8256 --version print version number, then exit
8257 -v, --verbose verbosely list files processed
8258 --no-force only update Makefile.in's that are out of date
8259 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
8261 Dependency tracking:
8262 -i, --ignore-deps disable dependency tracking code
8263 --include-deps enable dependency tracking code
8266 --cygnus assume program is part of Cygnus-style tree
8267 --foreign set strictness to foreign
8268 --gnits set strictness to gnits
8269 --gnu set strictness to gnu
8272 -a, --add-missing add missing standard files to package
8273 --libdir=DIR directory storing library files
8274 -c, --copy with -a, copy missing files (default is symlink)
8275 -f, --force-missing force update of standard files
8278 Automake::ChannelDefs::usage;
8280 print "\nFiles automatically distributed if found " .
8282 print_autodist_files @common_files;
8283 print "\nFiles automatically distributed if found " .
8284 "(under certain conditions):\n";
8285 print_autodist_files @common_sometimes;
8288 Report bugs to <@PACKAGE_BUGREPORT@>.
8289 GNU Automake home page: <@PACKAGE_URL@>.
8290 General help using GNU software: <http://www.gnu.org/gethelp/>.
8293 # --help always returns 0 per GNU standards.
8300 # Print version information
8304 automake (GNU $PACKAGE) $VERSION
8305 Copyright (C) 2011 Free Software Foundation, Inc.
8306 License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
8307 This is free software: you are free to change and redistribute it.
8308 There is NO WARRANTY, to the extent permitted by law.
8310 Written by Tom Tromey <tromey\@redhat.com>
8311 and Alexandre Duret-Lutz <adl\@gnu.org>.
8313 # --version always returns 0 per GNU standards.
8317 ################################################################
8319 # Parse command line.
8320 sub parse_arguments ()
8324 my $ignore_deps = 0;
8329 'version' => \&version,
8331 'libdir=s' => \$libdir,
8332 'gnu' => sub { $strict = 'gnu'; },
8333 'gnits' => sub { $strict = 'gnits'; },
8334 'foreign' => sub { $strict = 'foreign'; },
8335 'cygnus' => \$cygnus,
8336 'include-deps' => sub { $ignore_deps = 0; },
8337 'i|ignore-deps' => sub { $ignore_deps = 1; },
8338 'no-force' => sub { $force_generation = 0; },
8339 'f|force-missing' => \$force_missing,
8340 'a|add-missing' => \$add_missing,
8341 'c|copy' => \$copy_missing,
8342 'v|verbose' => sub { setup_channel 'verb', silent => 0; },
8343 'W|warnings=s' => \@warnings,
8346 use Automake::Getopt ();
8347 Automake::Getopt::parse_options %cli_options;
8349 set_strictness ($strict);
8350 my $cli_where = new Automake::Location;
8351 set_global_option ('cygnus', $cli_where) if $cygnus;
8352 set_global_option ('no-dependencies', $cli_where) if $ignore_deps;
8353 for my $warning (@warnings)
8355 &parse_warnings ('-W', $warning);
8358 return unless @ARGV;
8361 foreach my $arg (@ARGV)
8363 fatal ("empty argument\nTry `$0 --help' for more information")
8366 # Handle $local:$input syntax.
8367 my ($local, @rest) = split (/:/, $arg);
8368 @rest = ("$local.in",) unless @rest;
8369 my $input = locate_am @rest;
8372 push @input_files, $input;
8373 $output_files{$input} = join (':', ($local, @rest));
8377 error "no Automake input file found for `$arg'";
8381 fatal "no input file found among supplied arguments"
8382 if $errspec && ! @input_files;
8386 # handle_makefile ($MAKEFILE_IN)
8387 # ------------------------------
8388 # Deal with $MAKEFILE_IN.
8389 sub handle_makefile ($)
8392 ($am_file = $file) =~ s/\.in$//;
8393 if (! -f ($am_file . '.am'))
8395 error "`$am_file.am' does not exist";
8399 # Any warning setting now local to this Makefile.am.
8402 generate_makefile ($am_file . '.am', $file);
8404 # Back out any warning setting.
8409 # handle_makefiles_serial ()
8410 # --------------------------
8411 # Deal with all makefiles, without threads.
8412 sub handle_makefiles_serial ()
8414 foreach my $file (@input_files)
8416 handle_makefile ($file);
8420 # get_number_of_threads ()
8421 # ------------------------
8422 # Logic for deciding how many worker threads to use.
8423 sub get_number_of_threads
8425 my $nthreads = $ENV{'AUTOMAKE_JOBS'} || 0;
8428 unless $nthreads =~ /^[0-9]+$/;
8430 # It doesn't make sense to use more threads than makefiles,
8431 my $max_threads = @input_files;
8433 if ($nthreads > $max_threads)
8435 $nthreads = $max_threads;
8440 # handle_makefiles_threaded ($NTHREADS)
8441 # -------------------------------------
8442 # Deal with all makefiles, using threads. The general strategy is to
8443 # spawn NTHREADS worker threads, dispatch makefiles to them, and let the
8444 # worker threads push back everything that needs serialization:
8445 # * warning and (normal) error messages, for stable stderr output
8446 # order and content (avoiding duplicates, for example),
8447 # * races when installing aux files (and respective messages),
8448 # * races when collecting aux files for distribution.
8450 # The latter requires that the makefile that deals with the aux dir
8451 # files be handled last, done by the master thread.
8452 sub handle_makefiles_threaded ($)
8454 my ($nthreads) = @_;
8456 # The file queue distributes all makefiles, the message queues
8457 # collect all serializations needed for respective files.
8458 my $file_queue = Thread::Queue->new;
8460 foreach my $file (@input_files)
8462 $msg_queues{$file} = Thread::Queue->new;
8465 verb "spawning $nthreads worker threads";
8466 my @threads = (1 .. $nthreads);
8467 foreach my $t (@threads)
8469 $t = threads->new (sub
8471 while (my $file = $file_queue->dequeue)
8473 verb "handling $file";
8474 my $queue = $msg_queues{$file};
8475 setup_channel_queue ($queue, QUEUE_MESSAGE);
8476 $required_conf_file_queue = $queue;
8477 handle_makefile ($file);
8478 $queue->enqueue (undef);
8479 setup_channel_queue (undef, undef);
8480 $required_conf_file_queue = undef;
8486 # Queue all makefiles.
8487 verb "queuing " . @input_files . " input files";
8488 $file_queue->enqueue (@input_files, (undef) x @threads);
8490 # Collect and process serializations.
8491 foreach my $file (@input_files)
8493 verb "dequeuing messages for " . $file;
8494 reset_local_duplicates ();
8495 my $queue = $msg_queues{$file};
8496 while (my $key = $queue->dequeue)
8498 if ($key eq QUEUE_MESSAGE)
8500 pop_channel_queue ($queue);
8502 elsif ($key eq QUEUE_CONF_FILE)
8504 require_queued_file_check_or_copy ($queue);
8508 prog_error "unexpected key $key";
8513 foreach my $t (@threads)
8515 my @exit_thread = $t->join;
8516 $exit_code = $exit_thread[0]
8517 if ($exit_thread[0] > $exit_code);
8521 ################################################################
8523 # Parse the WARNINGS environment variable.
8526 # Parse command line.
8529 $configure_ac = require_configure_ac;
8531 # Do configure.ac scan only once.
8532 scan_autoconf_files;
8537 $msg = "\nDid you forget AC_CONFIG_FILES([Makefile]) in $configure_ac?"
8538 if -f 'Makefile.am';
8539 fatal ("no `Makefile.am' found for any configure output$msg");
8542 my $nthreads = get_number_of_threads ();
8544 if ($perl_threads && $nthreads >= 1)
8546 handle_makefiles_threaded ($nthreads);
8550 handle_makefiles_serial ();
8556 ### Setup "GNU" style for perl-mode and cperl-mode.
8558 ## perl-indent-level: 2
8559 ## perl-continued-statement-offset: 2
8560 ## perl-continued-brace-offset: 0
8561 ## perl-brace-offset: 0
8562 ## perl-brace-imaginary-offset: 0
8563 ## perl-label-offset: -2
8564 ## cperl-indent-level: 2
8565 ## cperl-brace-offset: 0
8566 ## cperl-continued-brace-offset: 0
8567 ## cperl-label-offset: -2
8568 ## cperl-extra-newline-before-brace: t
8569 ## cperl-merge-trailing-else: nil
8570 ## cperl-continued-statement-offset: 2