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 Free Software Foundation, Inc.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3, or (at your option)
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
26 # Perl reimplementation by Tom Tromey <tromey@redhat.com>, and
27 # Alexandre Duret-Lutz <adl@gnu.org>.
33 my $perllibdir = $ENV{'perllibdir'} || '@datadir@/@PACKAGE@-@APIVERSION@';
34 unshift @INC, (split '@PATH_SEPARATOR@', $perllibdir);
36 # Override SHELL. This is required on DJGPP so that system() uses
37 # bash, not COMMAND.COM which doesn't quote arguments properly.
38 # Other systems aren't expected to use $SHELL when Automake
39 # runs, but it should be safe to drop the `if DJGPP' guard if
40 # it turns up other systems need the same thing. After all,
41 # if SHELL is used, ./configure's SHELL is always better than
42 # the user's SHELL (which may be something like tcsh).
43 $ENV{'SHELL'} = '@SHELL@' if exists $ENV{'DJGPP'};
47 struct (# Short name of the language (c, f77...).
49 # Nice name of the language (C, Fortran 77...).
52 # 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 linker variable (LD).
92 # Content of the linker variable ($(CC)).
95 # Flag to specify the output file (-o).
96 'output_flag' => "\$",
99 # This is a subroutine which is called whenever we finally
100 # determine the context in which a source file will be
102 '_target_hook' => "\$",
104 # If TRUE, nodist_ sources will be compiled using specific rules
105 # (i.e. not inference rules). The default is FALSE.
106 'nodist_specific' => "\$");
112 if (defined $self->_finish)
114 &{$self->_finish} ();
118 sub target_hook ($$$$%)
121 if (defined $self->_target_hook)
123 &{$self->_target_hook} (@_);
130 use Automake::Config;
131 use Automake::General;
133 use Automake::Channels;
134 use Automake::ChannelDefs;
135 use Automake::Configure_ac;
136 use Automake::FileUtils;
137 use Automake::Location;
138 use Automake::Condition qw/TRUE FALSE/;
139 use Automake::DisjConditions;
140 use Automake::Options;
141 use Automake::Version;
142 use Automake::Variable;
143 use Automake::VarDef;
145 use Automake::RuleDef;
146 use Automake::Wrap 'makefile_wrap';
155 # Some regular expressions. One reason to put them here is that it
156 # makes indentation work better in Emacs.
158 # Writing singled-quoted-$-terminated regexes is a pain because
159 # perl-mode thinks of $' as the ${'} variable (instead of a $ followed
160 # by a closing quote. Letting perl-mode think the quote is not closed
161 # leads to all sort of misindentations. On the other hand, defining
162 # regexes as double-quoted strings is far less readable. So usually
165 # $REGEX = '^regex_value' . "\$";
167 my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
168 my $WHITE_PATTERN = '^\s*' . "\$";
169 my $COMMENT_PATTERN = '^#';
170 my $TARGET_PATTERN='[$a-zA-Z0-9_.@%][-.a-zA-Z0-9_(){}/$+@%]*';
171 # A rule has three parts: a list of targets, a list of dependencies,
172 # and optionally actions.
174 "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
176 # Only recognize leading spaces, not leading tabs. If we recognize
177 # leading tabs here then we need to make the reader smarter, because
178 # otherwise it will think rules like `foo=bar; \' are errors.
179 my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)' . "\$";
180 # This pattern recognizes a Gnits version id and sets $1 if the
181 # release is an alpha release. We also allow a suffix which can be
182 # used to extend the version number with a "fork" identifier.
183 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
185 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?' . "\$";
187 '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
189 '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
190 my $PATH_PATTERN = '(\w|[+/.-])+';
191 # This will pass through anything not of the prescribed form.
192 my $INCLUDE_PATTERN = ('^include\s+'
193 . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
194 . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
195 . '|([^/\$]' . $PATH_PATTERN . '))\s*(#.*)?' . "\$");
197 # Match `-d' as a command-line argument in a string.
198 my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)";
199 # Directories installed during 'install-exec' phase.
200 my $EXEC_DIR_PATTERN =
201 '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)' . "\$";
203 # Values for AC_CANONICAL_*
204 use constant AC_CANONICAL_BUILD => 1;
205 use constant AC_CANONICAL_HOST => 2;
206 use constant AC_CANONICAL_TARGET => 3;
208 # Values indicating when something should be cleaned.
209 use constant MOSTLY_CLEAN => 0;
210 use constant CLEAN => 1;
211 use constant DIST_CLEAN => 2;
212 use constant MAINTAINER_CLEAN => 3;
215 my @libtool_files = qw(ltmain.sh config.guess config.sub);
216 # ltconfig appears here for compatibility with old versions of libtool.
217 my @libtool_sometimes = qw(ltconfig ltcf-c.sh ltcf-cxx.sh ltcf-gcj.sh);
219 # Commonly found files we look for and automatically include in
222 (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
223 COPYING.LESSER ChangeLog INSTALL NEWS README THANKS TODO
224 ansi2knr.1 ansi2knr.c compile config.guess config.rpath config.sub
225 depcomp elisp-comp install-sh libversion.in mdate-sh missing
226 mkinstalldirs py-compile texinfo.tex ylwrap),
227 @libtool_files, @libtool_sometimes);
229 # Commonly used files we auto-include, but only sometimes. This list
230 # is used for the --help output only.
231 my @common_sometimes =
232 qw(aclocal.m4 acconfig.h config.h.top config.h.bot configure
233 configure.ac configure.in stamp-vti);
235 # Standard directories from the GNU Coding Standards, and additional
236 # pkg* directories from Automake. Stored in a hash for fast member check.
237 my %standard_prefix =
238 map { $_ => 1 } (qw(bin data dataroot dvi exec html include info
239 lib libexec lisp localstate man man1 man2 man3
240 man4 man5 man6 man7 man8 man9 oldinclude pdf
241 pkgdatadir pkgincludedir pkglibdir pkglibexecdir
242 ps sbin sharedstate sysconf));
244 # Copyright on generated Makefile.ins.
245 my $gen_copyright = "\
246 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
247 # 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
248 # This Makefile.in is free software; the Free Software Foundation
249 # gives unlimited permission to copy and/or distribute it,
250 # with or without modifications, as long as this notice is preserved.
252 # This program is distributed in the hope that it will be useful,
253 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
254 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
255 # PARTICULAR PURPOSE.
258 # These constants are returned by the lang_*_rewrite functions.
259 # LANG_SUBDIR means that the resulting object file should be in a
260 # subdir if the source file is. In this case the file name cannot
261 # have `..' components.
262 use constant LANG_IGNORE => 0;
263 use constant LANG_PROCESS => 1;
264 use constant LANG_SUBDIR => 2;
266 # These are used when keeping track of whether an object can be built
267 # by two different paths.
268 use constant COMPILE_LIBTOOL => 1;
269 use constant COMPILE_ORDINARY => 2;
271 # We can't always associate a location to a variable or a rule,
272 # when it's defined by Automake. We use INTERNAL in this case.
273 use constant INTERNAL => new Automake::Location;
276 ## ---------------------------------- ##
277 ## Variables related to the options. ##
278 ## ---------------------------------- ##
280 # TRUE if we should always generate Makefile.in.
281 my $force_generation = 1;
283 # From the Perl manual.
284 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
286 # TRUE if missing standard files should be installed.
289 # TRUE if we should copy missing files; otherwise symlink if possible.
290 my $copy_missing = 0;
292 # TRUE if we should always update files that we know about.
293 my $force_missing = 0;
296 ## ---------------------------------------- ##
297 ## Variables filled during files scanning. ##
298 ## ---------------------------------------- ##
300 # Name of the configure.ac file.
303 # Files found by scanning configure.ac for LIBOBJS.
306 # Names used in AC_CONFIG_HEADER call.
307 my @config_headers = ();
309 # Names used in AC_CONFIG_LINKS call.
310 my @config_links = ();
312 # Directory where output files go. Actually, output files are
313 # relative to this directory.
314 my $output_directory;
316 # List of Makefile.am's to process, and their corresponding outputs.
317 my @input_files = ();
318 my %output_files = ();
320 # Complete list of Makefile.am's that exist.
321 my @configure_input_files = ();
323 # List of files in AC_CONFIG_FILES/AC_OUTPUT without Makefile.am's,
325 my @other_input_files = ();
326 # Where each AC_CONFIG_FILES/AC_OUTPUT/AC_CONFIG_LINK/AC_CONFIG_HEADER appears.
327 # The keys are the files created by these macros.
328 my %ac_config_files_location = ();
330 # Directory to search for configure-required files. This
331 # will be computed by &locate_aux_dir and can be set using
332 # AC_CONFIG_AUX_DIR in configure.ac.
333 # $CONFIG_AUX_DIR is the `raw' directory, valid only in the source-tree.
334 my $config_aux_dir = '';
335 my $config_aux_dir_set_in_configure_ac = 0;
336 # $AM_CONFIG_AUX_DIR is prefixed with $(top_srcdir), so it can be used
338 my $am_config_aux_dir = '';
340 # Directory to search for AC_LIBSOURCE files, as set by AC_CONFIG_LIBOBJ_DIR
342 my $config_libobj_dir = '';
344 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
345 my $seen_gettext = 0;
346 # Whether AM_GNU_GETTEXT([external]) is used.
347 my $seen_gettext_external = 0;
348 # Where AM_GNU_GETTEXT appears.
349 my $ac_gettext_location;
350 # Whether AM_GNU_GETTEXT_INTL_SUBDIR has been seen.
351 my $seen_gettext_intl = 0;
353 # Lists of tags supported by Libtool.
354 my %libtool_tags = ();
355 # 1 if Libtool uses LT_SUPPORTED_TAG. If it does, then it also
356 # uses AC_REQUIRE_AUX_FILE.
357 my $libtool_new_api = 0;
359 # Most important AC_CANONICAL_* macro seen so far.
360 my $seen_canonical = 0;
361 # Location of that macro.
362 my $canonical_location;
364 # Where AM_MAINTAINER_MODE appears.
367 # Actual version we've seen.
368 my $package_version = '';
370 # Where version is defined.
371 my $package_version_location;
373 # TRUE if we've seen AM_ENABLE_MULTILIB.
374 my $seen_multilib = 0;
376 # TRUE if we've seen AM_PROG_CC_C_O
379 # Location of AC_REQUIRE_AUX_FILE calls, indexed by their argument.
380 my %required_aux_file = ();
382 # Where AM_INIT_AUTOMAKE is called;
383 my $seen_init_automake = 0;
385 # TRUE if we've seen AM_AUTOMAKE_VERSION.
386 my $seen_automake_version = 0;
388 # Hash table of discovered configure substitutions. Keys are names,
389 # values are `FILE:LINE' strings which are used by error message
391 my %configure_vars = ();
393 # Ignored configure substitutions (i.e., variables not to be output in
395 my %ignored_configure_vars = ();
397 # Files included by $configure_ac.
398 my @configure_deps = ();
400 # Greatest timestamp of configure's dependencies.
401 my $configure_deps_greatest_timestamp = 0;
403 # Hash table of AM_CONDITIONAL variables seen in configure.
404 my %configure_cond = ();
406 # This maps extensions onto language names.
407 my %extension_map = ();
409 # List of the DIST_COMMON files we discovered while reading
411 my $configure_dist_common = '';
413 # This maps languages names onto objects.
415 # Maps each linker variable onto a language object.
416 my %link_languages = ();
418 # maps extensions to needed source flags.
419 my %sourceflags = ();
421 # List of targets we must always output.
422 # FIXME: Complete, and remove falsely required targets.
423 my %required_targets =
436 # FIXME: Not required, temporary hacks.
437 # Well, actually they are sort of required: the -recursive
438 # targets will run them anyway...
443 'install-data-am' => 1,
444 'install-exec-am' => 1,
445 'installcheck-am' => 1,
451 # Set to 1 if this run will create the Makefile.in that distribute
452 # the files in config_aux_dir.
453 my $automake_will_process_aux_dir = 0;
455 # The name of the Makefile currently being processed.
459 ################################################################
461 ## ------------------------------------------ ##
462 ## Variables reset by &initialize_per_input. ##
463 ## ------------------------------------------ ##
465 # Basename and relative dir of the input file.
469 # Same but wrt Makefile.in.
473 # Relative path to the top directory.
476 # Greatest timestamp of the output's dependencies (excluding
477 # configure's dependencies).
478 my $output_deps_greatest_timestamp;
480 # These two variables are used when generating each Makefile.in.
481 # They hold the Makefile.in until it is ready to be printed.
488 # This is the conditional stack, updated on if/else/endif, and
489 # used to build Condition objects.
492 # This holds the set of included files.
495 # List of dependencies for the obvious targets.
500 # Keys in this hash table are files to delete. The associated
501 # value tells when this should happen (MOSTLY_CLEAN, DIST_CLEAN, etc.)
504 # Keys in this hash table are object files or other files in
505 # subdirectories which need to be removed. This only holds files
506 # which are created by compilations. The value in the hash indicates
507 # when the file should be removed.
508 my %compile_clean_files;
510 # Keys in this hash table are directories where we expect to build a
511 # libtool object. We use this information to decide what directories
513 my %libtool_clean_directories;
515 # Value of `$(SOURCES)', used by tags.am.
517 # Sources which go in the distribution.
520 # This hash maps object file names onto their corresponding source
521 # file names. This is used to ensure that each object is created
522 # by a single source file.
525 # This hash maps object file names onto an integer value representing
526 # whether this object has been built via ordinary compilation or
527 # libtool compilation (the COMPILE_* constants).
528 my %object_compilation_map;
531 # This keeps track of the directories for which we've already
532 # created dirstamp code. Keys are directories, values are stamp files.
533 # Several keys can share the same stamp files if they are equivalent
534 # (as are `.//foo' and `foo').
540 # This is a list of all targets to run during "make dist".
543 # Keep track of all programs declared in this Makefile, without
544 # $(EXEEXT). @substitution@ are not listed.
547 # Keys in this hash are the basenames of files which must depend on
548 # ansi2knr. Values are either the empty string, or the directory in
549 # which the ANSI source file appears; the directory must have a
553 # This is the name of the redirect `all' target to use.
556 # This keeps track of which extensions we've seen (that we care
560 # This is random scratch space for the language finish functions.
561 # Don't randomly overwrite it; examine other uses of keys first.
562 my %language_scratch;
564 # We keep track of which objects need special (per-executable)
565 # handling on a per-language basis.
566 my %lang_specific_files;
568 # This is set when `handle_dist' has finished. Once this happens,
569 # we should no longer push on dist_common.
572 # Used to store a set of linkers needed to generate the sources currently
573 # under consideration.
576 # True if we need `LINK' defined. This is a hack.
579 # Was get_object_extension run?
580 # FIXME: This is a hack. a better switch should be found.
581 my $get_object_extension_was_run;
583 # Record each file processed by make_paragraphs.
584 my %transformed_files;
586 # Cache each file processed by make_paragraphs.
587 # (This is different from %transformed_files because
588 # %transformed_files is reset for each file while %am_file_cache
589 # it global to the run.)
592 ################################################################
594 # var_SUFFIXES_trigger ($TYPE, $VALUE)
595 # ------------------------------------
596 # This is called by Automake::Variable::define() when SUFFIXES
597 # is defined ($TYPE eq '') or appended ($TYPE eq '+').
598 # The work here needs to be performed as a side-effect of the
599 # macro_define() call because SUFFIXES definitions impact
600 # on $KNOWN_EXTENSIONS_PATTERN which is used used when parsing
602 sub var_SUFFIXES_trigger ($$)
604 my ($type, $value) = @_;
605 accept_extensions (split (' ', $value));
607 Automake::Variable::hook ('SUFFIXES', \&var_SUFFIXES_trigger);
609 ################################################################
611 ## --------------------------------- ##
612 ## Forward subroutine declarations. ##
613 ## --------------------------------- ##
614 sub register_language (%);
615 sub file_contents_internal ($$$%);
616 sub define_files_variable ($\@$$);
619 # &initialize_per_input ()
620 # ------------------------
621 # (Re)-Initialize per-Makefile.am variables.
622 sub initialize_per_input ()
624 reset_local_duplicates ();
627 $am_relative_dir = '';
632 $output_deps_greatest_timestamp = 0;
636 $output_trailer = '';
640 Automake::Options::reset;
641 Automake::Variable::reset;
642 Automake::Rule::reset;
658 %object_compilation_map = ();
666 %known_programs = ();
672 %extension_seen = ();
674 %language_scratch = ();
676 %lang_specific_files = ();
678 $handle_dist_run = 0;
682 $get_object_extension_was_run = 0;
684 %compile_clean_files = ();
686 # We always include `.'. This isn't strictly correct.
687 %libtool_clean_directories = ('.' => 1);
689 %transformed_files = ();
693 ################################################################
695 # Initialize our list of languages that are internally supported.
698 register_language ('name' => 'c',
700 'config_vars' => ['CC'],
703 'flags' => ['CFLAGS', 'CPPFLAGS'],
704 'compiler' => 'COMPILE',
705 'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
709 'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
710 'compile_flag' => '-c',
711 'libtool_tag' => 'CC',
712 'extensions' => ['.c'],
713 '_finish' => \&lang_c_finish);
716 register_language ('name' => 'cxx',
718 'config_vars' => ['CXX'],
719 'linker' => 'CXXLINK',
720 'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
722 'flags' => ['CXXFLAGS', 'CPPFLAGS'],
723 'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
724 'compiler' => 'CXXCOMPILE',
725 'compile_flag' => '-c',
726 'output_flag' => '-o',
727 'libtool_tag' => 'CXX',
731 'extensions' => ['.c++', '.cc', '.cpp', '.cxx', '.C']);
734 register_language ('name' => 'objc',
735 'Name' => 'Objective C',
736 'config_vars' => ['OBJC'],
737 'linker' => 'OBJCLINK',
738 'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
740 'flags' => ['OBJCFLAGS', 'CPPFLAGS'],
741 'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
742 'compiler' => 'OBJCCOMPILE',
743 'compile_flag' => '-c',
744 'output_flag' => '-o',
748 'extensions' => ['.m']);
750 # Unified Parallel C.
751 register_language ('name' => 'upc',
752 'Name' => 'Unified Parallel C',
753 'config_vars' => ['UPC'],
754 'linker' => 'UPCLINK',
755 'link' => '$(UPCLD) $(AM_UPCFLAGS) $(UPCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
757 'flags' => ['UPCFLAGS', 'CPPFLAGS'],
758 'compile' => '$(UPC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_UPCFLAGS) $(UPCFLAGS)',
759 'compiler' => 'UPCCOMPILE',
760 'compile_flag' => '-c',
761 'output_flag' => '-o',
765 'extensions' => ['.upc']);
768 register_language ('name' => 'header',
770 'extensions' => ['.h', '.H', '.hxx', '.h++', '.hh',
773 'output_extensions' => sub { return () },
775 '_finish' => sub { });
778 register_language ('name' => 'yacc',
780 'config_vars' => ['YACC'],
781 'flags' => ['YFLAGS'],
782 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
783 'compiler' => 'YACCCOMPILE',
784 'extensions' => ['.y'],
785 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
787 'rule_file' => 'yacc',
788 '_finish' => \&lang_yacc_finish,
789 '_target_hook' => \&lang_yacc_target_hook,
790 'nodist_specific' => 1);
791 register_language ('name' => 'yaccxx',
792 'Name' => 'Yacc (C++)',
793 'config_vars' => ['YACC'],
794 'rule_file' => 'yacc',
795 'flags' => ['YFLAGS'],
796 'compiler' => 'YACCCOMPILE',
797 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
798 'extensions' => ['.y++', '.yy', '.yxx', '.ypp'],
799 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
801 '_finish' => \&lang_yacc_finish,
802 '_target_hook' => \&lang_yacc_target_hook,
803 'nodist_specific' => 1);
806 register_language ('name' => 'lex',
808 'config_vars' => ['LEX'],
809 'rule_file' => 'lex',
810 'flags' => ['LFLAGS'],
811 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
812 'compiler' => 'LEXCOMPILE',
813 'extensions' => ['.l'],
814 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
816 '_finish' => \&lang_lex_finish,
817 '_target_hook' => \&lang_lex_target_hook,
818 'nodist_specific' => 1);
819 register_language ('name' => 'lexxx',
820 'Name' => 'Lex (C++)',
821 'config_vars' => ['LEX'],
822 'rule_file' => 'lex',
823 'flags' => ['LFLAGS'],
824 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
825 'compiler' => 'LEXCOMPILE',
826 'extensions' => ['.l++', '.ll', '.lxx', '.lpp'],
827 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
829 '_finish' => \&lang_lex_finish,
830 '_target_hook' => \&lang_lex_target_hook,
831 'nodist_specific' => 1);
834 register_language ('name' => 'asm',
835 'Name' => 'Assembler',
836 'config_vars' => ['CCAS', 'CCASFLAGS'],
838 'flags' => ['CCASFLAGS'],
839 # Users can set AM_CCASFLAGS to include DEFS, INCLUDES,
840 # or anything else required. They can also set CCAS.
841 # Or simply use Preprocessed Assembler.
842 'compile' => '$(CCAS) $(AM_CCASFLAGS) $(CCASFLAGS)',
843 'compiler' => 'CCASCOMPILE',
844 'compile_flag' => '-c',
845 'output_flag' => '-o',
846 'extensions' => ['.s'],
848 # With assembly we still use the C linker.
849 '_finish' => \&lang_c_finish);
851 # Preprocessed Assembler.
852 register_language ('name' => 'cppasm',
853 'Name' => 'Preprocessed Assembler',
854 'config_vars' => ['CCAS', 'CCASFLAGS'],
857 'flags' => ['CCASFLAGS', 'CPPFLAGS'],
858 'compile' => '$(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS)',
859 'compiler' => 'CPPASCOMPILE',
860 'compile_flag' => '-c',
861 'output_flag' => '-o',
862 'extensions' => ['.S', '.sx'],
864 # With assembly we still use the C linker.
865 '_finish' => \&lang_c_finish);
868 register_language ('name' => 'f77',
869 'Name' => 'Fortran 77',
870 'config_vars' => ['F77'],
871 'linker' => 'F77LINK',
872 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
873 'flags' => ['FFLAGS'],
874 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
875 'compiler' => 'F77COMPILE',
876 'compile_flag' => '-c',
877 'output_flag' => '-o',
878 'libtool_tag' => 'F77',
882 'extensions' => ['.f', '.for']);
885 register_language ('name' => 'fc',
887 'config_vars' => ['FC'],
888 'linker' => 'FCLINK',
889 'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
890 'flags' => ['FCFLAGS'],
891 'compile' => '$(FC) $(AM_FCFLAGS) $(FCFLAGS)',
892 'compiler' => 'FCCOMPILE',
893 'compile_flag' => '-c',
894 'output_flag' => '-o',
898 'extensions' => ['.f90', '.f95']);
900 # Preprocessed Fortran
901 register_language ('name' => 'ppfc',
902 'Name' => 'Preprocessed Fortran',
903 'config_vars' => ['FC'],
904 'linker' => 'FCLINK',
905 'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
908 'flags' => ['FCFLAGS', 'CPPFLAGS'],
909 'compiler' => 'PPFCCOMPILE',
910 'compile' => '$(FC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FCFLAGS) $(FCFLAGS)',
911 'compile_flag' => '-c',
912 'output_flag' => '-o',
913 'libtool_tag' => 'FC',
915 'extensions' => ['.F90','.F95']);
917 # Preprocessed Fortran 77
919 # The current support for preprocessing Fortran 77 just involves
920 # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
921 # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
922 # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
923 # for `make' Version 3.76 Beta' (specifically, from info file
924 # `(make)Catalogue of Rules').
926 # A better approach would be to write an Autoconf test
927 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
928 # Fortran 77 compilers know how to do preprocessing. The Autoconf
929 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
930 # preprocessing capabilities, and then fall back on cpp (if cpp were
932 register_language ('name' => 'ppf77',
933 'Name' => 'Preprocessed Fortran 77',
934 'config_vars' => ['F77'],
935 'linker' => 'F77LINK',
936 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
939 'flags' => ['FFLAGS', 'CPPFLAGS'],
940 'compiler' => 'PPF77COMPILE',
941 'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
942 'compile_flag' => '-c',
943 'output_flag' => '-o',
944 'libtool_tag' => 'F77',
946 'extensions' => ['.F']);
949 register_language ('name' => 'ratfor',
951 'config_vars' => ['F77'],
952 'linker' => 'F77LINK',
953 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
956 'flags' => ['RFLAGS', 'FFLAGS'],
958 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
959 'compiler' => 'RCOMPILE',
960 'compile_flag' => '-c',
961 'output_flag' => '-o',
962 'libtool_tag' => 'F77',
964 'extensions' => ['.r']);
967 register_language ('name' => 'java',
969 'config_vars' => ['GCJ'],
970 'linker' => 'GCJLINK',
971 'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
973 'flags' => ['GCJFLAGS'],
974 'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
975 'compiler' => 'GCJCOMPILE',
976 'compile_flag' => '-c',
977 'output_flag' => '-o',
978 'libtool_tag' => 'GCJ',
982 'extensions' => ['.java', '.class', '.zip', '.jar']);
984 ################################################################
986 # Error reporting functions.
988 # err_am ($MESSAGE, [%OPTIONS])
989 # -----------------------------
990 # Uncategorized errors about the current Makefile.am.
993 msg_am ('error', @_);
996 # err_ac ($MESSAGE, [%OPTIONS])
997 # -----------------------------
998 # Uncategorized errors about configure.ac.
1001 msg_ac ('error', @_);
1004 # msg_am ($CHANNEL, $MESSAGE, [%OPTIONS])
1005 # ---------------------------------------
1006 # Messages about about the current Makefile.am.
1009 my ($channel, $msg, %opts) = @_;
1010 msg $channel, "${am_file}.am", $msg, %opts;
1013 # msg_ac ($CHANNEL, $MESSAGE, [%OPTIONS])
1014 # ---------------------------------------
1015 # Messages about about configure.ac.
1018 my ($channel, $msg, %opts) = @_;
1019 msg $channel, $configure_ac, $msg, %opts;
1022 ################################################################
1026 # Return a configure-style substitution using the indicated text.
1027 # We do this to avoid having the substitutions directly in automake.in;
1028 # when we do that they are sometimes removed and this causes confusion
1033 return '@' . $text . '@';
1036 ################################################################
1040 # &backname ($REL-DIR)
1041 # --------------------
1042 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
1043 # For instance `src/foo' => `../..'.
1044 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
1049 foreach (split (/\//, $file))
1051 next if $_ eq '.' || $_ eq '';
1061 return join ('/', @res) || '.';
1064 ################################################################
1067 # Handle AUTOMAKE_OPTIONS variable. Return 1 on error, 0 otherwise.
1070 my $var = var ('AUTOMAKE_OPTIONS');
1073 if ($var->has_conditional_contents)
1075 msg_var ('unsupported', $var,
1076 "`AUTOMAKE_OPTIONS' cannot have conditional contents");
1078 foreach my $locvals ($var->value_as_list_recursive (cond_filter => TRUE,
1081 my ($loc, $value) = @$locvals;
1082 return 1 if (process_option_list ($loc, $value))
1086 if ($strictness == GNITS)
1088 set_option ('readme-alpha', INTERNAL);
1089 set_option ('std-options', INTERNAL);
1090 set_option ('check-news', INTERNAL);
1096 # shadow_unconditionally ($varname, $where)
1097 # -----------------------------------------
1098 # Return a $(variable) that contains all possible values
1099 # $varname can take.
1100 # If the VAR wasn't defined conditionally, return $(VAR).
1101 # Otherwise we create a am__VAR_DIST variable which contains
1102 # all possible values, and return $(am__VAR_DIST).
1103 sub shadow_unconditionally ($$)
1105 my ($varname, $where) = @_;
1106 my $var = var $varname;
1107 if ($var->has_conditional_contents)
1109 $varname = "am__${varname}_DIST";
1110 my @files = uniq ($var->value_as_list_recursive);
1111 define_pretty_variable ($varname, TRUE, $where, @files);
1113 return "\$($varname)"
1116 # get_object_extension ($EXTENSION)
1117 # ---------------------------------
1118 # Prefix $EXTENSION with $U if ansi2knr is in use.
1119 sub get_object_extension ($)
1121 my ($extension) = @_;
1123 # Check for automatic de-ANSI-fication.
1124 $extension = '$U' . $extension
1125 if option 'ansi2knr';
1127 $get_object_extension_was_run = 1;
1132 # check_user_variables (@LIST)
1133 # ----------------------------
1134 # Make sure each variable VAR in @LIST does not exist, suggest using AM_VAR
1136 sub check_user_variables (@)
1138 my @dont_override = @_;
1139 foreach my $flag (@dont_override)
1141 my $var = var $flag;
1144 for my $cond ($var->conditions->conds)
1146 if ($var->rdef ($cond)->owner == VAR_MAKEFILE)
1148 msg_cond_var ('gnu', $cond, $flag,
1149 "`$flag' is a user variable, "
1150 . "you should not override it;\n"
1151 . "use `AM_$flag' instead.");
1158 # Call finish function for each language that was used.
1159 sub handle_languages
1161 if (! option 'no-dependencies')
1163 # Include auto-dep code. Don't include it if DEP_FILES would
1165 if (&saw_sources_p (0) && keys %dep_files)
1167 # Set location of depcomp.
1168 &define_variable ('depcomp',
1169 "\$(SHELL) $am_config_aux_dir/depcomp",
1171 &define_variable ('am__depfiles_maybe', 'depfiles', INTERNAL);
1173 require_conf_file ("$am_file.am", FOREIGN, 'depcomp');
1175 my @deplist = sort keys %dep_files;
1176 # Generate each `include' individually. Irix 6 make will
1177 # not properly include several files resulting from a
1178 # variable expansion; generating many separate includes
1180 $output_rules .= "\n";
1181 foreach my $iter (@deplist)
1183 $output_rules .= (subst ('AMDEP_TRUE')
1184 . subst ('am__include')
1186 . subst ('am__quote')
1188 . subst ('am__quote')
1192 # Compute the set of directories to remove in distclean-depend.
1193 my @depdirs = uniq (map { dirname ($_) } @deplist);
1194 $output_rules .= &file_contents ('depend',
1195 new Automake::Location,
1196 DEPDIRS => "@depdirs");
1201 &define_variable ('depcomp', '', INTERNAL);
1202 &define_variable ('am__depfiles_maybe', '', INTERNAL);
1207 # Is the c linker needed?
1209 foreach my $ext (sort keys %extension_seen)
1211 next unless $extension_map{$ext};
1213 my $lang = $languages{$extension_map{$ext}};
1215 my $rule_file = $lang->rule_file || 'depend2';
1217 # Get information on $LANG.
1218 my $pfx = $lang->autodep;
1219 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1221 my ($AMDEP, $FASTDEP) =
1222 (option 'no-dependencies' || $lang->autodep eq 'no')
1223 ? ('FALSE', 'FALSE') : ('AMDEP', "am__fastdep$fpfx");
1225 my %transform = ('EXT' => $ext,
1229 'FASTDEP' => $FASTDEP,
1230 '-c' => $lang->compile_flag || '',
1231 # These are not used, but they need to be defined
1232 # so &transform do not complain.
1234 'DERIVED-EXT' => 'BUG',
1238 # Generate the appropriate rules for this extension.
1239 if (((! option 'no-dependencies') && $lang->autodep ne 'no')
1240 || defined $lang->compile)
1242 # Some C compilers don't support -c -o. Use it only if really
1244 my $output_flag = $lang->output_flag || '';
1247 && $lang->name eq 'c'
1248 && option 'subdir-objects');
1250 # Compute a possible derived extension.
1251 # This is not used by depend2.am.
1252 my $der_ext = (&{$lang->output_extensions} ($ext))[0];
1254 # When we output an inference rule like `.c.o:' we
1255 # have two cases to consider: either subdir-objects
1256 # is used, or it is not.
1258 # In the latter case the rule is used to build objects
1259 # in the current directory, and dependencies always
1260 # go into `./$(DEPDIR)/'. We can hard-code this value.
1262 # In the former case the rule can be used to build
1263 # objects in sub-directories too. Dependencies should
1264 # go into the appropriate sub-directories, e.g.,
1265 # `sub/$(DEPDIR)/'. The value of this directory
1266 # needs to be computed on-the-fly.
1268 # DEPBASE holds the name of this directory, plus the
1269 # basename part of the object file (extensions Po, TPo,
1270 # Plo, TPlo will be added later as appropriate). It is
1271 # either hardcoded, or a shell variable (`$depbase') that
1272 # will be computed by the rule.
1274 option ('subdir-objects') ? '$$depbase' : '$(DEPDIR)/$*';
1276 file_contents ($rule_file,
1277 new Automake::Location,
1281 'DERIVED-EXT' => $der_ext,
1283 DEPBASE => $depbase,
1286 SOURCEFLAG => $sourceflags{$ext} || '',
1291 COMPILE => '$(' . $lang->compiler . ')',
1292 LTCOMPILE => '$(LT' . $lang->compiler . ')',
1294 SUBDIROBJ => !! option 'subdir-objects');
1297 # Now include code for each specially handled object with this
1299 my %seen_files = ();
1300 foreach my $file (@{$lang_specific_files{$lang->name}})
1302 my ($derived, $source, $obj, $myext, $srcext, %file_transform) = @$file;
1304 # We might see a given object twice, for instance if it is
1305 # used under different conditions.
1306 next if defined $seen_files{$obj};
1307 $seen_files{$obj} = 1;
1309 prog_error ("found " . $lang->name .
1310 " in handle_languages, but compiler not defined")
1311 unless defined $lang->compile;
1313 my $obj_compile = $lang->compile;
1315 # Rewrite each occurrence of `AM_$flag' in the compile
1316 # rule into `${derived}_$flag' if it exists.
1317 for my $flag (@{$lang->flags})
1319 my $val = "${derived}_$flag";
1320 $obj_compile =~ s/\(AM_$flag\)/\($val\)/
1324 my $libtool_tag = '';
1325 if ($lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag})
1327 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
1330 my $ptltflags = "${derived}_LIBTOOLFLAGS";
1331 $ptltflags = 'AM_LIBTOOLFLAGS' unless set_seen $ptltflags;
1334 "\$(LIBTOOL) $libtool_tag\$($ptltflags) \$(LIBTOOLFLAGS) "
1335 . "--mode=compile $obj_compile";
1337 # We _need_ `-o' for per object rules.
1338 my $output_flag = $lang->output_flag || '-o';
1340 my $depbase = dirname ($obj);
1344 unless $depbase eq '';
1345 $depbase .= '$(DEPDIR)/' . basename ($obj);
1347 # Support for deansified files in subdirectories is ugly
1348 # enough to deserve an explanation.
1350 # A Note about normal ansi2knr processing first. On
1352 # AUTOMAKE_OPTIONS = ansi2knr
1353 # bin_PROGRAMS = foo
1354 # foo_SOURCES = foo.c
1356 # we generate rules similar to:
1358 # foo: foo$U.o; link ...
1359 # foo$U.o: foo$U.c; compile ...
1360 # foo_.c: foo.c; ansi2knr ...
1362 # this is fairly compact, and will call ansi2knr depending
1363 # on the value of $U (`' or `_').
1365 # It's harder with subdir sources. On
1367 # AUTOMAKE_OPTIONS = ansi2knr
1368 # bin_PROGRAMS = foo
1369 # foo_SOURCES = sub/foo.c
1371 # we have to create foo_.c in the current directory.
1372 # (Unless the user asks 'subdir-objects'.) This is important
1373 # in case the same file (`foo.c') is compiled from other
1374 # directories with different cpp options: foo_.c would
1375 # be preprocessed for only one set of options if it were
1376 # put in the subdirectory.
1378 # Because foo$U.o must be built from either foo_.c or
1379 # sub/foo.c we can't be as concise as in the first example.
1382 # foo: foo$U.o; link ...
1383 # foo_.o: foo_.c; compile ...
1384 # foo.o: sub/foo.c; compile ...
1385 # foo_.c: foo.c; ansi2knr ...
1387 # This is why we'll now transform $rule_file twice
1388 # if we detect this case.
1389 # A first time we output the compile rule with `$U'
1390 # replaced by `_' and the source directory removed,
1391 # and another time we simply remove `$U'.
1393 # Note that at this point $source (as computed by
1394 # &handle_single_transform) is `sub/foo$U.c'.
1395 # This can be confusing: it can be used as-is when
1396 # subdir-objects is set, otherwise you have to know
1397 # it really means `foo_.c' or `sub/foo.c'.
1398 my $objdir = dirname ($obj);
1399 my $srcdir = dirname ($source);
1400 if ($lang->ansi && $obj =~ /\$U/)
1402 prog_error "`$obj' contains \$U, but `$source' doesn't."
1403 if $source !~ /\$U/;
1405 (my $source_ = $source) =~ s/\$U/_/g;
1406 # Output an additional rule if _.c and .c are not in
1407 # the same directory. (_.c is always in $objdir.)
1408 if ($objdir ne $srcdir)
1410 (my $obj_ = $obj) =~ s/\$U/_/g;
1411 (my $depbase_ = $depbase) =~ s/\$U/_/g;
1412 $source_ = basename ($source_);
1415 file_contents ($rule_file,
1416 new Automake::Location,
1420 DEPBASE => $depbase_,
1423 SOURCEFLAG => $sourceflags{$srcext} || '',
1424 OBJ => "$obj_$myext",
1425 OBJOBJ => "$obj_.obj",
1426 LTOBJ => "$obj_.lo",
1428 COMPILE => $obj_compile,
1429 LTCOMPILE => $obj_ltcompile,
1433 $depbase =~ s/\$U//g;
1434 $source =~ s/\$U//g;
1439 file_contents ($rule_file,
1440 new Automake::Location,
1444 DEPBASE => $depbase,
1447 SOURCEFLAG => $sourceflags{$srcext} || '',
1448 # Use $myext and not `.o' here, in case
1449 # we are actually building a new source
1450 # file -- e.g. via yacc.
1451 OBJ => "$obj$myext",
1452 OBJOBJ => "$obj.obj",
1455 COMPILE => $obj_compile,
1456 LTCOMPILE => $obj_ltcompile,
1461 # The rest of the loop is done once per language.
1462 next if defined $done{$lang};
1465 # Load the language dependent Makefile chunks.
1466 my %lang = map { uc ($_) => 0 } keys %languages;
1467 $lang{uc ($lang->name)} = 1;
1468 $output_rules .= file_contents ('lang-compile',
1469 new Automake::Location,
1472 # If the source to a program consists entirely of code from a
1473 # `pure' language, for instance C++ or Fortran 77, then we
1474 # don't need the C compiler code. However if we run into
1475 # something unusual then we do generate the C code. There are
1476 # probably corner cases here that do not work properly.
1477 # People linking Java code to Fortran code deserve pain.
1478 $needs_c ||= ! $lang->pure;
1480 define_compiler_variable ($lang)
1481 if ($lang->compile);
1483 define_linker_variable ($lang)
1486 require_variables ("$am_file.am", $lang->Name . " source seen",
1487 TRUE, @{$lang->config_vars});
1489 # Call the finisher.
1492 # Flags listed in `->flags' are user variables (per GNU Standards),
1493 # they should not be overridden in the Makefile...
1494 my @dont_override = @{$lang->flags};
1495 # ... and so is LDFLAGS.
1496 push @dont_override, 'LDFLAGS' if $lang->link;
1498 check_user_variables @dont_override;
1501 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1502 # suffix rule was learned), don't bother with the C stuff. But if
1503 # anything else creeps in, then use it.
1505 if $need_link || suffix_rules_count > 1;
1509 &define_compiler_variable ($languages{'c'})
1510 unless defined $done{$languages{'c'}};
1511 define_linker_variable ($languages{'c'});
1516 # append_exeext { PREDICATE } $MACRO
1517 # ----------------------------------
1518 # Append $(EXEEXT) to each filename in $F appearing in the Makefile
1519 # variable $MACRO if &PREDICATE($F) is true. @substitutions@ are
1522 # This is typically used on all filenames of *_PROGRAMS, and filenames
1523 # of TESTS that are programs.
1524 sub append_exeext (&$)
1526 my ($pred, $macro) = @_;
1528 transform_variable_recursively
1529 ($macro, $macro, 'am__EXEEXT', 0, INTERNAL,
1531 my ($subvar, $val, $cond, $full_cond) = @_;
1532 # Append $(EXEEXT) unless the user did it already, or it's a
1535 if $val !~ /(?:\$\(EXEEXT\)$|^[@]\w+[@]$)/ && &$pred ($val);
1541 # Check to make sure a source defined in LIBOBJS is not explicitly
1542 # mentioned. This is a separate function (as opposed to being inlined
1543 # in handle_source_transform) because it isn't always appropriate to
1545 sub check_libobjs_sources
1547 my ($one_file, $unxformed) = @_;
1549 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1550 'dist_EXTRA_', 'nodist_EXTRA_')
1553 my $varname = $prefix . $one_file . '_SOURCES';
1554 my $var = var ($varname);
1557 @files = $var->value_as_list_recursive;
1559 elsif ($prefix eq '')
1561 @files = ($unxformed . '.c');
1568 foreach my $file (@files)
1570 err_var ($prefix . $one_file . '_SOURCES',
1571 "automatically discovered file `$file' should not" .
1572 " be explicitly mentioned")
1573 if defined $libsources{$file};
1580 # handle_single_transform ($VAR, $TOPPARENT, $DERIVED, $OBJ, $FILE, %TRANSFORM)
1581 # -----------------------------------------------------------------------------
1582 # Does much of the actual work for handle_source_transform.
1584 # $VAR is the name of the variable that the source filenames come from
1585 # $TOPPARENT is the name of the _SOURCES variable which is being processed
1586 # $DERIVED is the name of resulting executable or library
1587 # $OBJ is the object extension (e.g., `$U.lo')
1588 # $FILE the source file to transform
1589 # %TRANSFORM contains extras arguments to pass to file_contents
1590 # when producing explicit rules
1591 # Result is a list of the names of objects
1592 # %linkers_used will be updated with any linkers needed
1593 sub handle_single_transform ($$$$$%)
1595 my ($var, $topparent, $derived, $obj, $_file, %transform) = @_;
1596 my @files = ($_file);
1598 my $nonansi_obj = $obj;
1599 $nonansi_obj =~ s/\$U//g;
1601 # Turn sources into objects. We use a while loop like this
1602 # because we might add to @files in the loop.
1603 while (scalar @files > 0)
1607 # Configure substitutions in _SOURCES variables are errors.
1610 my $parent_msg = '';
1611 $parent_msg = "\nand is referred to from `$topparent'"
1612 if $topparent ne $var->name;
1614 "`" . $var->name . "' includes configure substitution `$_'"
1615 . $parent_msg . ";\nconfigure " .
1616 "substitutions are not allowed in _SOURCES variables");
1620 # If the source file is in a subdirectory then the `.o' is put
1621 # into the current directory, unless the subdir-objects option
1624 # Split file name into base and extension.
1625 next if ! /^(?:(.*)\/)?([^\/]*)($KNOWN_EXTENSIONS_PATTERN)$/;
1627 my $directory = $1 || '';
1631 # We must generate a rule for the object if it requires its own flags.
1633 my ($linker, $object);
1635 # This records whether we've seen a derived source file (e.g.
1637 my $derived_source = 0;
1639 # This holds the `aggregate context' of the file we are
1640 # currently examining. If the file is compiled with
1641 # per-object flags, then it will be the name of the object.
1642 # Otherwise it will be `AM'. This is used by the target hook
1643 # language function.
1644 my $aggregate = 'AM';
1646 $extension = &derive_suffix ($extension, $nonansi_obj);
1648 if ($extension_map{$extension} &&
1649 ($lang = $languages{$extension_map{$extension}}))
1651 # Found the language, so see what it says.
1652 &saw_extension ($extension);
1654 # Do we have per-executable flags for this executable?
1655 my $have_per_exec_flags = 0;
1656 my @peflags = @{$lang->flags};
1657 push @peflags, 'LIBTOOLFLAGS' if $nonansi_obj eq '.lo';
1658 foreach my $flag (@peflags)
1660 if (set_seen ("${derived}_$flag"))
1662 $have_per_exec_flags = 1;
1667 # Note: computed subr call. The language rewrite function
1668 # should return one of the LANG_* constants. It could
1669 # also return a list whose first value is such a constant
1670 # and whose second value is a new source extension which
1671 # should be applied. This means this particular language
1672 # generates another source file which we must then process
1674 my $subr = \&{'lang_' . $lang->name . '_rewrite'};
1675 my ($r, $source_extension)
1676 = &$subr ($directory, $base, $extension,
1677 $nonansi_obj, $have_per_exec_flags, $var);
1678 # Skip this entry if we were asked not to process it.
1679 next if $r == LANG_IGNORE;
1681 # Now extract linker and other info.
1682 $linker = $lang->linker;
1685 if (defined $source_extension)
1687 $this_obj_ext = $source_extension;
1688 $derived_source = 1;
1692 $this_obj_ext = $obj;
1696 $this_obj_ext = $nonansi_obj;
1698 $object = $base . $this_obj_ext;
1700 if ($have_per_exec_flags)
1702 # We have a per-executable flag in effect for this
1703 # object. In this case we rewrite the object's
1704 # name to ensure it is unique.
1706 # We choose the name `DERIVED_OBJECT' to ensure
1707 # (1) uniqueness, and (2) continuity between
1708 # invocations. However, this will result in a
1709 # name that is too long for losing systems, in
1710 # some situations. So we provide _SHORTNAME to
1713 my $dname = $derived;
1714 my $var = var ($derived . '_SHORTNAME');
1717 # FIXME: should use the same Condition as
1718 # the _SOURCES variable. But this is really
1719 # silly overkill -- nobody should have
1720 # conditional shortnames.
1721 $dname = $var->variable_value;
1723 $object = $dname . '-' . $object;
1725 prog_error ($lang->name . " flags defined without compiler")
1726 if ! defined $lang->compile;
1731 # If rewrite said it was ok, put the object into a
1733 if ($r == LANG_SUBDIR && $directory ne '')
1735 $object = $directory . '/' . $object;
1738 # If the object file has been renamed (because per-target
1739 # flags are used) we cannot compile the file with an
1740 # inference rule: we need an explicit rule.
1742 # If the source is in a subdirectory and the object is in
1743 # the current directory, we also need an explicit rule.
1745 # If both source and object files are in a subdirectory
1746 # (this happens when the subdir-objects option is used),
1747 # then the inference will work.
1749 # The latter case deserves a historical note. When the
1750 # subdir-objects option was added on 1999-04-11 it was
1751 # thought that inferences rules would work for
1752 # subdirectory objects too. Later, on 1999-11-22,
1753 # automake was changed to output explicit rules even for
1754 # subdir-objects. Nobody remembers why, but this occurred
1755 # soon after the merge of the user-dep-gen-branch so it
1756 # might be related. In late 2003 people complained about
1757 # the size of the generated Makefile.ins (libgcj, with
1758 # 2200+ subdir objects was reported to have a 9MB
1759 # Makefile), so we now rely on inference rules again.
1760 # Maybe we'll run across the same issue as in the past,
1761 # but at least this time we can document it. However since
1762 # dependency tracking has evolved it is possible that
1763 # our old problem no longer exists.
1764 # Using inference rules for subdir-objects has been tested
1765 # with GNU make, Solaris make, Ultrix make, BSD make,
1766 # HP-UX make, and OSF1 make successfully.
1768 || ($directory ne '' && ! option 'subdir-objects')
1769 # We must also use specific rules for a nodist_ source
1770 # if its language requests it.
1771 || ($lang->nodist_specific && ! $transform{'DIST_SOURCE'}))
1773 my $obj_sans_ext = substr ($object, 0,
1774 - length ($this_obj_ext));
1775 my $full_ansi = $full;
1776 if ($lang->ansi && option 'ansi2knr')
1778 $full_ansi =~ s/$KNOWN_EXTENSIONS_PATTERN$/\$U$&/;
1779 $obj_sans_ext .= '$U';
1782 my @specifics = ($full_ansi, $obj_sans_ext,
1783 # Only use $this_obj_ext in the derived
1784 # source case because in the other case we
1785 # *don't* want $(OBJEXT) to appear here.
1786 ($derived_source ? $this_obj_ext : '.o'),
1789 # If we renamed the object then we want to use the
1790 # per-executable flag name. But if this is simply a
1791 # subdir build then we still want to use the AM_ flag
1795 unshift @specifics, $derived;
1796 $aggregate = $derived;
1800 unshift @specifics, 'AM';
1803 # Each item on this list is a reference to a list consisting
1804 # of four values followed by additional transform flags for
1805 # file_contents. The four values are the derived flag prefix
1806 # (e.g. for `foo_CFLAGS', it is `foo'), the name of the
1807 # source file, the base name of the output file, and
1808 # the extension for the object file.
1809 push (@{$lang_specific_files{$lang->name}},
1810 [@specifics, %transform]);
1813 elsif ($extension eq $nonansi_obj)
1815 # This is probably the result of a direct suffix rule.
1816 # In this case we just accept the rewrite.
1817 $object = "$base$extension";
1818 $object = "$directory/$object" if $directory ne '';
1823 # No error message here. Used to have one, but it was
1825 # FIXME: we could potentially do more processing here,
1826 # perhaps treating the new extension as though it were a
1827 # new source extension (as above). This would require
1828 # more restructuring than is appropriate right now.
1832 err_am "object `$object' created by `$full' and `$object_map{$object}'"
1833 if (defined $object_map{$object}
1834 && $object_map{$object} ne $full);
1836 my $comp_val = (($object =~ /\.lo$/)
1837 ? COMPILE_LIBTOOL : COMPILE_ORDINARY);
1838 (my $comp_obj = $object) =~ s/\.lo$/.\$(OBJEXT)/;
1839 if (defined $object_compilation_map{$comp_obj}
1840 && $object_compilation_map{$comp_obj} != 0
1841 # Only see the error once.
1842 && ($object_compilation_map{$comp_obj}
1843 != (COMPILE_LIBTOOL | COMPILE_ORDINARY))
1844 && $object_compilation_map{$comp_obj} != $comp_val)
1846 err_am "object `$comp_obj' created both with libtool and without";
1848 $object_compilation_map{$comp_obj} |= $comp_val;
1852 # Let the language do some special magic if required.
1853 $lang->target_hook ($aggregate, $object, $full, %transform);
1856 if ($derived_source)
1858 prog_error ($lang->name . " has automatic dependency tracking")
1859 if $lang->autodep ne 'no';
1860 # Make sure this new source file is handled next. That will
1861 # make it appear to be at the right place in the list.
1862 unshift (@files, $object);
1863 # Distribute derived sources unless the source they are
1864 # derived from is not.
1865 &push_dist_common ($object)
1866 unless ($topparent =~ /^(?:nobase_)?nodist_/);
1870 $linkers_used{$linker} = 1;
1872 push (@result, $object);
1874 if (! defined $object_map{$object})
1877 $object_map{$object} = $full;
1879 # If resulting object is in subdir, we need to make
1880 # sure the subdir exists at build time.
1881 if ($object =~ /\//)
1883 # FIXME: check that $DIRECTORY is somewhere in the
1886 # For Java, the way we're handling it right now, a
1887 # `..' component doesn't make sense.
1888 if ($lang && $lang->name eq 'java' && $object =~ /(\/|^)\.\.\//)
1890 err_am "`$full' should not contain a `..' component";
1893 # Make sure object is removed by `make mostlyclean'.
1894 $compile_clean_files{$object} = MOSTLY_CLEAN;
1895 # If we have a libtool object then we also must remove
1897 if ($object =~ /\.lo$/)
1899 (my $xobj = $object) =~ s,lo$,\$(OBJEXT),;
1900 $compile_clean_files{$xobj} = MOSTLY_CLEAN;
1902 # Remove any libtool object in this directory.
1903 $libtool_clean_directories{$directory} = 1;
1906 push (@dep_list, require_build_directory ($directory));
1908 # If we're generating dependencies, we also want
1909 # to make sure that the appropriate subdir of the
1910 # .deps directory is created.
1912 require_build_directory ($directory . '/$(DEPDIR)'))
1913 unless option 'no-dependencies';
1916 &pretty_print_rule ($object . ':', "\t", @dep_list)
1917 if scalar @dep_list > 0;
1920 # Transform .o or $o file into .P file (for automatic
1922 if ($lang && $lang->autodep ne 'no')
1924 my $depfile = $object;
1925 $depfile =~ s/\.([^.]*)$/.P$1/;
1926 $depfile =~ s/\$\(OBJEXT\)$/o/;
1927 $dep_files{dirname ($depfile) . '/$(DEPDIR)/'
1928 . basename ($depfile)} = 1;
1937 # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
1938 # $OBJ, $PARENT, $TOPPARENT, $WHERE, %TRANSFORM)
1939 # ---------------------------------------------------------------------------
1940 # Define an _OBJECTS variable for a _SOURCES variable (or subvariable)
1943 # $VAR is the name of the _SOURCES variable
1944 # $OBJVAR is the name of the _OBJECTS variable if known (otherwise
1945 # it will be generated and returned).
1946 # $NODEFINE is a boolean: if true, $OBJVAR will not be defined (but
1947 # work done to determine the linker will be).
1948 # $ONE_FILE is the canonical (transformed) name of object to build
1949 # $OBJ is the object extension (i.e. either `.o' or `.lo').
1950 # $TOPPARENT is the _SOURCES variable being processed.
1951 # $WHERE context into which this definition is done
1952 # %TRANSFORM extra arguments to pass to file_contents when producing
1955 # Result is a pair ($LINKER, $OBJVAR):
1956 # $LINKER is a boolean, true if a linker is needed to deal with the objects
1957 sub define_objects_from_sources ($$$$$$$%)
1959 my ($var, $objvar, $nodefine, $one_file,
1960 $obj, $topparent, $where, %transform) = @_;
1962 my $needlinker = "";
1964 transform_variable_recursively
1965 ($var, $objvar, 'am__objects', $nodefine, $where,
1966 # The transform code to run on each filename.
1968 my ($subvar, $val, $cond, $full_cond) = @_;
1969 my @trans = handle_single_transform ($subvar, $topparent,
1970 $one_file, $obj, $val,
1972 $needlinker = "true" if @trans;
1980 # handle_source_transform ($CANON_TARGET, $TARGET, $OBJEXT, $WHERE, %TRANSFORM)
1981 # -----------------------------------------------------------------------------
1982 # Handle SOURCE->OBJECT transform for one program or library.
1984 # canonical (transformed) name of target to build
1985 # actual target of object to build
1986 # object extension (i.e., either `.o' or `$o')
1987 # location of the source variable
1988 # extra arguments to pass to file_contents when producing rules
1989 # Return the name of the linker variable that must be used.
1990 # Empty return means just use `LINK'.
1991 sub handle_source_transform ($$$$%)
1993 # one_file is canonical name. unxformed is given name. obj is
1995 my ($one_file, $unxformed, $obj, $where, %transform) = @_;
1999 # No point in continuing if _OBJECTS is defined.
2000 return if reject_var ($one_file . '_OBJECTS',
2001 $one_file . '_OBJECTS should not be defined');
2006 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2007 'dist_EXTRA_', 'nodist_EXTRA_')
2009 my $varname = $prefix . $one_file . "_SOURCES";
2010 my $var = var $varname;
2013 # We are going to define _OBJECTS variables using the prefix.
2014 # Then we glom them all together. So we can't use the null
2015 # prefix here as we need it later.
2016 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2018 # Keep track of which prefixes we saw.
2019 $used_pfx{$xpfx} = 1
2020 unless $prefix =~ /EXTRA_/;
2022 push @sources, "\$($varname)";
2023 push @dist_sources, shadow_unconditionally ($varname, $where)
2024 unless (option ('no-dist') || $prefix =~ /^nodist_/);
2027 define_objects_from_sources ($varname,
2028 $xpfx . $one_file . '_OBJECTS',
2029 $prefix =~ /EXTRA_/,
2030 $one_file, $obj, $varname, $where,
2031 DIST_SOURCE => ($prefix !~ /^nodist_/),
2036 $linker ||= &resolve_linker (%linkers_used);
2039 my @keys = sort keys %used_pfx;
2040 if (scalar @keys == 0)
2042 # The default source for libfoo.la is libfoo.c, but for
2043 # backward compatibility we first look at libfoo_la.c
2044 my $old_default_source = "$one_file.c";
2045 (my $default_source = $unxformed) =~ s,(\.[^./\\]*)?$,.c,;
2046 if ($old_default_source ne $default_source
2047 && (rule $old_default_source
2048 || rule '$(srcdir)/' . $old_default_source
2049 || rule '${srcdir}/' . $old_default_source
2050 || -f $old_default_source))
2052 my $loc = $where->clone;
2054 msg ('obsolete', $loc,
2055 "the default source for `$unxformed' has been changed "
2056 . "to `$default_source'.\n(Using `$old_default_source' for "
2057 . "backward compatibility.)");
2058 $default_source = $old_default_source;
2060 # If a rule exists to build this source with a $(srcdir)
2061 # prefix, use that prefix in our variables too. This is for
2062 # the sake of BSD Make.
2063 if (rule '$(srcdir)/' . $default_source
2064 || rule '${srcdir}/' . $default_source)
2066 $default_source = '$(srcdir)/' . $default_source;
2069 &define_variable ($one_file . "_SOURCES", $default_source, $where);
2070 push (@sources, $default_source);
2071 push (@dist_sources, $default_source);
2075 handle_single_transform ($one_file . '_SOURCES',
2076 $one_file . '_SOURCES',
2078 $default_source, %transform);
2079 $linker ||= &resolve_linker (%linkers_used);
2080 define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @result);
2084 @keys = map { '$(' . $_ . $one_file . '_OBJECTS)' } @keys;
2085 define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @keys);
2088 # If we want to use `LINK' we must make sure it is defined.
2098 # handle_lib_objects ($XNAME, $VAR)
2099 # ---------------------------------
2100 # Special-case ALLOCA and LIBOBJS substitutions in _LDADD or _LIBADD variables.
2101 # Also, generate _DEPENDENCIES variable if appropriate.
2103 # transformed name of object being built, or empty string if no object
2104 # name of _LDADD/_LIBADD-type variable to examine
2105 # Returns 1 if LIBOBJS seen, 0 otherwise.
2106 sub handle_lib_objects
2108 my ($xname, $varname) = @_;
2110 my $var = var ($varname);
2111 prog_error "handle_lib_objects: `$varname' undefined"
2113 prog_error "handle_lib_objects: unexpected variable name `$varname'"
2114 unless $varname =~ /^(.*)(?:LIB|LD)ADD$/;
2115 my $prefix = $1 || 'AM_';
2117 my $seen_libobjs = 0;
2120 transform_variable_recursively
2121 ($varname, $xname . '_DEPENDENCIES', 'am__DEPENDENCIES',
2123 # Transformation function, run on each filename.
2125 my ($subvar, $val, $cond, $full_cond) = @_;
2129 # Skip -lfoo and -Ldir silently; these are explicitly allowed.
2130 if ($val !~ /^-[lL]/ &&
2131 # Skip -dlopen and -dlpreopen; these are explicitly allowed
2132 # for Libtool libraries or programs. (Actually we are a bit
2133 # laxe here since this code also applies to non-libtool
2134 # libraries or programs, for which -dlopen and -dlopreopen
2135 # are pure nonsense. Diagnosing this doesn't seem very
2136 # important: the developer will quickly get complaints from
2138 $val !~ /^-dl(?:pre)?open$/ &&
2139 # Only get this error once.
2143 # FIXME: should display a stack of nested variables
2144 # as context when $var != $subvar.
2145 err_var ($var, "linker flags such as `$val' belong in "
2146 . "`${prefix}LDFLAGS");
2150 elsif ($val !~ /^\@.*\@$/)
2152 # Assume we have a file of some sort, and output it into the
2153 # dependency variable. Autoconf substitutions are not output;
2154 # rarely is a new dependency substituted into e.g. foo_LDADD
2155 # -- but bad things (e.g. -lX11) are routinely substituted.
2156 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2157 # and handled specially below.
2160 elsif ($val =~ /^\@(LT)?LIBOBJS\@$/)
2162 handle_LIBOBJS ($subvar, $cond, $1);
2166 elsif ($val =~ /^\@(LT)?ALLOCA\@$/)
2168 handle_ALLOCA ($subvar, $cond, $1);
2177 return $seen_libobjs;
2180 # handle_LIBOBJS_or_ALLOCA ($VAR)
2181 # -------------------------------
2182 # Definitions common to LIBOBJS and ALLOCA.
2183 # VAR should be one of LIBOBJS, LTLIBOBJS, ALLOCA, or LTALLOCA.
2184 sub handle_LIBOBJS_or_ALLOCA ($)
2190 # If LIBOBJS files must be built in another directory we have
2191 # to define LIBOBJDIR and ensure the files get cleaned.
2192 # Otherwise LIBOBJDIR can be left undefined, and the cleaning
2193 # is achieved by `rm -f *.$(OBJEXT)' in compile.am.
2194 if ($config_libobj_dir
2195 && $relative_dir ne $config_libobj_dir)
2197 if (option 'subdir-objects')
2199 # In the top-level Makefile we do not use $(top_builddir), because
2200 # we are already there, and since the targets are built without
2201 # a $(top_builddir), it helps BSD Make to match them with
2203 $dir = "$config_libobj_dir/" if $config_libobj_dir ne '.';
2204 $dir = "$topsrcdir/$dir" if $relative_dir ne '.';
2205 define_variable ('LIBOBJDIR', "$dir", INTERNAL);
2206 $clean_files{"\$($var)"} = MOSTLY_CLEAN;
2207 # If LTLIBOBJS is used, we must also clear LIBOBJS (which might
2208 # be created by libtool as a side-effect of creating LTLIBOBJS).
2209 $clean_files{"\$($var)"} = MOSTLY_CLEAN if $var =~ s/^LT//;
2213 error ("`\$($var)' cannot be used outside `$config_libobj_dir' if"
2214 . " `subdir-objects' is not set");
2221 sub handle_LIBOBJS ($$$)
2223 my ($var, $cond, $lt) = @_;
2224 my $myobjext = $lt ? 'lo' : 'o';
2227 $var->requires_variables ("\@${lt}LIBOBJS\@ used", $lt . 'LIBOBJS')
2228 if ! keys %libsources;
2230 my $dir = handle_LIBOBJS_or_ALLOCA "${lt}LIBOBJS";
2232 foreach my $iter (keys %libsources)
2234 if ($iter =~ /\.[cly]$/)
2236 &saw_extension ($&);
2237 &saw_extension ('.c');
2240 if ($iter =~ /\.h$/)
2242 require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
2244 elsif ($iter ne 'alloca.c')
2246 my $rewrite = $iter;
2247 $rewrite =~ s/\.c$/.P$myobjext/;
2248 $dep_files{$dir . '$(DEPDIR)/' . $rewrite} = 1;
2249 $rewrite = "^" . quotemeta ($iter) . "\$";
2250 # Only require the file if it is not a built source.
2251 my $bs = var ('BUILT_SOURCES');
2252 if (! $bs || ! grep (/$rewrite/, $bs->value_as_list_recursive))
2254 require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
2260 sub handle_ALLOCA ($$$)
2262 my ($var, $cond, $lt) = @_;
2263 my $myobjext = $lt ? 'lo' : 'o';
2265 my $dir = handle_LIBOBJS_or_ALLOCA "${lt}ALLOCA";
2267 $var->requires_variables ("\@${lt}ALLOCA\@ used", $lt . 'ALLOCA');
2268 $dep_files{$dir . '$(DEPDIR)/alloca.P' . $myobjext} = 1;
2269 require_libsource_with_macro ($cond, $var, FOREIGN, 'alloca.c');
2270 &saw_extension ('.c');
2273 # Canonicalize the input parameter
2277 $string =~ tr/A-Za-z0-9_\@/_/c;
2281 # Canonicalize a name, and check to make sure the non-canonical name
2282 # is never used. Returns canonical name. Arguments are name and a
2283 # list of suffixes to check for.
2284 sub check_canonical_spelling
2286 my ($name, @suffixes) = @_;
2288 my $xname = &canonicalize ($name);
2289 if ($xname ne $name)
2291 foreach my $xt (@suffixes)
2293 reject_var ("$name$xt", "use `$xname$xt', not `$name$xt'");
2303 # Set up the compile suite.
2304 sub handle_compile ()
2307 unless $get_object_extension_was_run;
2310 my $default_includes = '';
2311 if (! option 'nostdinc')
2313 my @incs = ('-I.', subst ('am__isrc'));
2315 my $var = var 'CONFIG_HEADER';
2318 foreach my $hdr (split (' ', $var->variable_value))
2320 push @incs, '-I' . dirname ($hdr);
2323 # We want `-I. -I$(srcdir)', but the latter -I is redundant
2324 # and unaesthetic in non-VPATH builds. We use `-I.@am__isrc@`
2325 # instead. It will be replaced by '-I.' or '-I. -I$(srcdir)'.
2326 # Items in CONFIG_HEADER are never in $(srcdir) so it is safe
2327 # to just put @am__isrc@ right after `-I.', without a space.
2328 ($default_includes = ' ' . uniq (@incs)) =~ s/ @/@/;
2331 my (@mostly_rms, @dist_rms);
2332 foreach my $item (sort keys %compile_clean_files)
2334 if ($compile_clean_files{$item} == MOSTLY_CLEAN)
2336 push (@mostly_rms, "\t-rm -f $item");
2338 elsif ($compile_clean_files{$item} == DIST_CLEAN)
2340 push (@dist_rms, "\t-rm -f $item");
2344 prog_error 'invalid entry in %compile_clean_files';
2348 my ($coms, $vars, $rules) =
2349 &file_contents_internal (1, "$libdir/am/compile.am",
2350 new Automake::Location,
2351 ('DEFAULT_INCLUDES' => $default_includes,
2352 'MOSTLYRMS' => join ("\n", @mostly_rms),
2353 'DISTRMS' => join ("\n", @dist_rms)));
2354 $output_vars .= $vars;
2355 $output_rules .= "$coms$rules";
2357 # Check for automatic de-ANSI-fication.
2358 if (option 'ansi2knr')
2360 my ($ansi2knr_filename, $ansi2knr_where) = @{option 'ansi2knr'};
2361 my $ansi2knr_dir = '';
2363 require_variables ($ansi2knr_where, "option `ansi2knr' is used",
2364 TRUE, "ANSI2KNR", "U");
2366 # topdir is where ansi2knr should be.
2367 if ($ansi2knr_filename eq 'ansi2knr')
2369 # Only require ansi2knr files if they should appear in
2371 require_file ($ansi2knr_where, FOREIGN,
2372 'ansi2knr.c', 'ansi2knr.1');
2374 # ansi2knr needs to be built before subdirs, so unshift it.
2375 unshift (@all, '$(ANSI2KNR)');
2379 $ansi2knr_dir = dirname ($ansi2knr_filename);
2382 $output_rules .= &file_contents ('ansi2knr',
2383 new Automake::Location,
2384 'ANSI2KNR-DIR' => $ansi2knr_dir);
2391 # Handle libtool rules.
2394 return unless var ('LIBTOOL');
2396 # Libtool requires some files, but only at top level.
2397 # (Starting with Libtool 2.0 we do not have to bother. These
2398 # requirements are done with AC_REQUIRE_AUX_FILE.)
2399 require_conf_file_with_macro (TRUE, 'LIBTOOL', FOREIGN, @libtool_files)
2400 if $relative_dir eq '.' && ! $libtool_new_api;
2403 foreach my $item (sort keys %libtool_clean_directories)
2405 my $dir = ($item eq '.') ? '' : "$item/";
2406 # .libs is for Unix, _libs for DOS.
2407 push (@libtool_rms, "\t-rm -rf ${dir}.libs ${dir}_libs");
2410 check_user_variables 'LIBTOOLFLAGS';
2412 # Output the libtool compilation rules.
2413 $output_rules .= &file_contents ('libtool',
2414 new Automake::Location,
2415 LTRMS => join ("\n", @libtool_rms));
2418 # handle_programs ()
2419 # ------------------
2420 # Handle C programs.
2423 my @proglist = &am_install_var ('progs', 'PROGRAMS',
2424 'bin', 'sbin', 'libexec', 'pkglib',
2426 return if ! @proglist;
2428 my $seen_global_libobjs =
2429 var ('LDADD') && &handle_lib_objects ('', 'LDADD');
2431 foreach my $pair (@proglist)
2433 my ($where, $one_file) = @$pair;
2435 my $seen_libobjs = 0;
2436 my $obj = get_object_extension '.$(OBJEXT)';
2438 # Strip any $(EXEEXT) suffix the user might have added, or this
2439 # will confuse &handle_source_transform and &check_canonical_spelling.
2440 # We'll add $(EXEEXT) back later anyway.
2441 $one_file =~ s/\$\(EXEEXT\)$//;
2443 $known_programs{$one_file} = $where;
2445 # Canonicalize names and check for misspellings.
2446 my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2447 '_SOURCES', '_OBJECTS',
2450 $where->push_context ("while processing program `$one_file'");
2451 $where->set (INTERNAL->get);
2453 my $linker = &handle_source_transform ($xname, $one_file, $obj, $where,
2454 NONLIBTOOL => 1, LIBTOOL => 0);
2456 if (var ($xname . "_LDADD"))
2458 $seen_libobjs = &handle_lib_objects ($xname, $xname . '_LDADD');
2462 # User didn't define prog_LDADD override. So do it.
2463 &define_variable ($xname . '_LDADD', '$(LDADD)', $where);
2465 # This does a bit too much work. But we need it to
2466 # generate _DEPENDENCIES when appropriate.
2469 $seen_libobjs = &handle_lib_objects ($xname, 'LDADD');
2473 reject_var ($xname . '_LIBADD',
2474 "use `${xname}_LDADD', not `${xname}_LIBADD'");
2476 set_seen ($xname . '_DEPENDENCIES');
2477 set_seen ($xname . '_LDFLAGS');
2479 # Determine program to use for link.
2480 my $xlink = &define_per_target_linker_variable ($linker, $xname);
2482 # If the resulting program lies into a subdirectory,
2483 # make sure this directory will exist.
2484 my $dirstamp = require_build_directory_maybe ($one_file);
2486 $libtool_clean_directories{dirname ($one_file)} = 1;
2488 $output_rules .= &file_contents ('program',
2490 PROGRAM => $one_file,
2493 DIRSTAMP => $dirstamp,
2494 EXEEXT => '$(EXEEXT)');
2496 if ($seen_libobjs || $seen_global_libobjs)
2498 if (var ($xname . '_LDADD'))
2500 &check_libobjs_sources ($xname, $xname . '_LDADD');
2502 elsif (var ('LDADD'))
2504 &check_libobjs_sources ($xname, 'LDADD');
2511 # handle_libraries ()
2512 # -------------------
2514 sub handle_libraries
2516 my @liblist = &am_install_var ('libs', 'LIBRARIES',
2517 'lib', 'pkglib', 'noinst', 'check');
2518 return if ! @liblist;
2520 my @prefix = am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2525 my $var = rvar ($prefix[0] . '_LIBRARIES');
2526 $var->requires_variables ('library used', 'RANLIB');
2529 &define_variable ('AR', 'ar', INTERNAL);
2530 &define_variable ('ARFLAGS', 'cru', INTERNAL);
2532 foreach my $pair (@liblist)
2534 my ($where, $onelib) = @$pair;
2536 my $seen_libobjs = 0;
2537 # Check that the library fits the standard naming convention.
2538 my $bn = basename ($onelib);
2539 if ($bn !~ /^lib.*\.a$/)
2541 $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.a/;
2542 my $suggestion = dirname ($onelib) . "/$bn";
2543 $suggestion =~ s|^\./||g;
2544 msg ('error-gnu/warn', $where,
2545 "`$onelib' is not a standard library name\n"
2546 . "did you mean `$suggestion'?")
2549 $where->push_context ("while processing library `$onelib'");
2550 $where->set (INTERNAL->get);
2552 my $obj = get_object_extension '.$(OBJEXT)';
2554 # Canonicalize names and check for misspellings.
2555 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2556 '_OBJECTS', '_DEPENDENCIES',
2559 if (! var ($xlib . '_AR'))
2561 &define_variable ($xlib . '_AR', '$(AR) $(ARFLAGS)', $where);
2564 # Generate support for conditional object inclusion in
2566 if (var ($xlib . '_LIBADD'))
2568 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2575 &define_variable ($xlib . "_LIBADD", '', $where);
2578 reject_var ($xlib . '_LDADD',
2579 "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
2581 # Make sure we at look at this.
2582 set_seen ($xlib . '_DEPENDENCIES');
2584 &handle_source_transform ($xlib, $onelib, $obj, $where,
2585 NONLIBTOOL => 1, LIBTOOL => 0);
2587 # If the resulting library lies into a subdirectory,
2588 # make sure this directory will exist.
2589 my $dirstamp = require_build_directory_maybe ($onelib);
2591 $output_rules .= &file_contents ('library',
2595 DIRSTAMP => $dirstamp);
2599 if (var ($xlib . '_LIBADD'))
2601 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2608 # handle_ltlibraries ()
2609 # ---------------------
2610 # Handle shared libraries.
2611 sub handle_ltlibraries
2613 my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2614 'noinst', 'lib', 'pkglib', 'check');
2615 return if ! @liblist;
2617 my @prefix = am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2622 my $var = rvar ($prefix[0] . '_LTLIBRARIES');
2623 $var->requires_variables ('Libtool library used', 'LIBTOOL');
2628 my %liblocations = (); # Location (in Makefile.am) of each library.
2630 foreach my $key (@prefix)
2632 # Get the installation directory of each library.
2633 (my $dir = $key) =~ s/^nobase_//;
2634 my $var = rvar ($key . '_LTLIBRARIES');
2636 # We reject libraries which are installed in several places
2637 # in the same condition, because we can only specify one
2639 $var->traverse_recursively
2642 my ($var, $val, $cond, $full_cond) = @_;
2643 my $hcond = $full_cond->human;
2644 my $where = $var->rdef ($cond)->location;
2645 # A library cannot be installed in different directory
2646 # in overlapping conditions.
2647 if (exists $instconds{$val})
2650 $instconds{$val}->ambiguous_p ($val, $full_cond);
2654 error ($where, $msg, partial => 1);
2656 my $dirtxt = "installed in `$dir'";
2657 $dirtxt = "built for `$dir'"
2658 if $dir eq 'EXTRA' || $dir eq 'noinst' || $dir eq 'check';
2660 $full_cond->true ? "" : " in condition $hcond";
2662 error ($where, "`$val' should be $dirtxt$dircond ...",
2665 my $hacond = $acond->human;
2666 my $adir = $instdirs{$val}{$acond};
2667 my $adirtxt = "installed in `$adir'";
2668 $adirtxt = "built for `$adir'"
2669 if ($adir eq 'EXTRA' || $adir eq 'noinst'
2670 || $adir eq 'check');
2671 my $adircond = $acond->true ? "" : " in condition $hacond";
2673 my $onlyone = ($dir ne $adir) ?
2674 ("\nLibtool libraries can be built for only one "
2675 . "destination.") : "";
2677 error ($liblocations{$val}{$acond},
2678 "... and should also be $adirtxt$adircond.$onlyone");
2684 $instconds{$val} = new Automake::DisjConditions;
2686 $instdirs{$val}{$full_cond} = $dir;
2687 $liblocations{$val}{$full_cond} = $where;
2688 $instconds{$val} = $instconds{$val}->merge ($full_cond);
2694 skip_ac_subst => 1);
2697 foreach my $pair (@liblist)
2699 my ($where, $onelib) = @$pair;
2701 my $seen_libobjs = 0;
2702 my $obj = get_object_extension '.lo';
2704 # Canonicalize names and check for misspellings.
2705 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2706 '_SOURCES', '_OBJECTS',
2709 # Check that the library fits the standard naming convention.
2710 my $libname_rx = '^lib.*\.la';
2711 my $ldvar = var ("${xlib}_LDFLAGS") || var ('AM_LDFLAGS');
2712 my $ldvar2 = var ('LDFLAGS');
2713 if (($ldvar && grep (/-module/, $ldvar->value_as_list_recursive))
2714 || ($ldvar2 && grep (/-module/, $ldvar2->value_as_list_recursive)))
2716 # Relax name checking for libtool modules.
2717 $libname_rx = '\.la';
2720 my $bn = basename ($onelib);
2721 if ($bn !~ /$libname_rx$/)
2723 my $type = 'library';
2724 if ($libname_rx eq '\.la')
2726 $bn =~ s/^(lib|)(.*?)(?:\.[^.]*)?$/$1$2.la/;
2731 $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.la/;
2733 my $suggestion = dirname ($onelib) . "/$bn";
2734 $suggestion =~ s|^\./||g;
2735 msg ('error-gnu/warn', $where,
2736 "`$onelib' is not a standard libtool $type name\n"
2737 . "did you mean `$suggestion'?")
2740 $where->push_context ("while processing Libtool library `$onelib'");
2741 $where->set (INTERNAL->get);
2743 # Make sure we look at these.
2744 set_seen ($xlib . '_LDFLAGS');
2745 set_seen ($xlib . '_DEPENDENCIES');
2747 # Generate support for conditional object inclusion in
2749 if (var ($xlib . '_LIBADD'))
2751 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2758 &define_variable ($xlib . "_LIBADD", '', $where);
2761 reject_var ("${xlib}_LDADD",
2762 "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
2765 my $linker = &handle_source_transform ($xlib, $onelib, $obj, $where,
2766 NONLIBTOOL => 0, LIBTOOL => 1);
2768 # Determine program to use for link.
2769 my $xlink = &define_per_target_linker_variable ($linker, $xlib);
2771 my $rpathvar = "am_${xlib}_rpath";
2772 my $rpath = "\$($rpathvar)";
2773 foreach my $rcond ($instconds{$onelib}->conds)
2776 if ($instdirs{$onelib}{$rcond} eq 'EXTRA'
2777 || $instdirs{$onelib}{$rcond} eq 'noinst'
2778 || $instdirs{$onelib}{$rcond} eq 'check')
2780 # It's an EXTRA_ library, so we can't specify -rpath,
2781 # because we don't know where the library will end up.
2782 # The user probably knows, but generally speaking automake
2783 # doesn't -- and in fact configure could decide
2784 # dynamically between two different locations.
2789 $val = ('-rpath $(' . $instdirs{$onelib}{$rcond} . 'dir)');
2793 # If $rcond is true there is only one condition and
2794 # there is no point defining an helper variable.
2799 define_pretty_variable ($rpathvar, $rcond, INTERNAL, $val);
2803 # If the resulting library lies into a subdirectory,
2804 # make sure this directory will exist.
2805 my $dirstamp = require_build_directory_maybe ($onelib);
2807 # Remember to cleanup .libs/ in this directory.
2808 my $dirname = dirname $onelib;
2809 $libtool_clean_directories{$dirname} = 1;
2811 $output_rules .= &file_contents ('ltlibrary',
2813 LTLIBRARY => $onelib,
2814 XLTLIBRARY => $xlib,
2817 DIRSTAMP => $dirstamp);
2820 if (var ($xlib . '_LIBADD'))
2822 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2828 # See if any _SOURCES variable were misspelled.
2831 # It is ok if the user sets this particular variable.
2832 set_seen 'AM_LDFLAGS';
2834 foreach my $primary ('SOURCES', 'LIBADD', 'LDADD', 'LDFLAGS', 'DEPENDENCIES')
2836 foreach my $var (variables $primary)
2838 my $varname = $var->name;
2839 # A configure variable is always legitimate.
2840 next if exists $configure_vars{$varname};
2842 for my $cond ($var->conditions->conds)
2844 $varname =~ /^(?:nobase_)?(?:dist_|nodist_)?(.*)_[[:alnum:]]+$/;
2845 msg_var ('syntax', $var, "variable `$varname' is defined but no"
2846 . " program or\nlibrary has `$1' as canonic name"
2847 . " (possible typo)")
2848 unless $var->rdef ($cond)->seen;
2858 # NOTE we no longer automatically clean SCRIPTS, because it is
2859 # useful to sometimes distribute scripts verbatim. This happens
2860 # e.g. in Automake itself.
2861 &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2862 'bin', 'sbin', 'libexec', 'pkgdata',
2869 ## ------------------------ ##
2870 ## Handling Texinfo files. ##
2871 ## ------------------------ ##
2873 # ($OUTFILE, $VFILE, @CLEAN_FILES)
2874 # &scan_texinfo_file ($FILENAME)
2875 # ------------------------------
2876 # $OUTFILE - name of the info file produced by $FILENAME.
2877 # $VFILE - name of the version.texi file used (undef if none).
2878 # @CLEAN_FILES - list of byproducts (indexes etc.)
2879 sub scan_texinfo_file ($)
2881 my ($filename) = @_;
2883 # Some of the following extensions are always created, no matter
2884 # whether indexes are used or not. Other (like cps, fns, ... pgs)
2885 # are only created when they are used. We used to scan $FILENAME
2886 # for their use, but that is not enough: they could be used in
2887 # included files. We can't scan included files because we don't
2888 # know the include path. Therefore we always erase these files, no
2889 # matter whether they are used or not.
2891 # (tmp is only created if an @macro is used and a certain e-TeX
2892 # feature is not available.)
2893 my %clean_suffixes =
2894 map { $_ => 1 } (qw(aux log toc tmp
2900 pg pgs)); # grep 'new.*index' texinfo.tex
2902 my $texi = new Automake::XFile "< $filename";
2903 verb "reading $filename";
2905 my ($outfile, $vfile);
2906 while ($_ = $texi->getline)
2908 if (/^\@setfilename +(\S+)/)
2910 # Honor only the first @setfilename. (It's possible to have
2911 # more occurrences later if the manual shows examples of how
2912 # to use @setfilename...)
2916 if ($outfile =~ /\.([^.]+)$/ && $1 ne 'info')
2918 error ("$filename:$.",
2919 "output `$outfile' has unrecognized extension");
2923 # A "version.texi" file is actually any file whose name matches
2925 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2930 # Try to find new or unused indexes.
2932 # Creating a new category of index.
2933 elsif (/^\@def(code)?index (\w+)/)
2935 $clean_suffixes{$2} = 1;
2936 $clean_suffixes{"$2s"} = 1;
2939 # Merging an index into an another.
2940 elsif (/^\@syn(code)?index (\w+) (\w+)/)
2942 delete $clean_suffixes{"$2s"};
2943 $clean_suffixes{"$3s"} = 1;
2950 err_am "`$filename' missing \@setfilename";
2954 my $infobase = basename ($filename);
2955 $infobase =~ s/\.te?xi(nfo)?$//;
2956 return ($outfile, $vfile,
2957 map { "$infobase.$_" } (sort keys %clean_suffixes));
2961 # ($DIRSTAMP, @CLEAN_FILES)
2962 # output_texinfo_build_rules ($SOURCE, $DEST, $INSRC, @DEPENDENCIES)
2963 # ------------------------------------------------------------------
2964 # SOURCE - the source Texinfo file
2965 # DEST - the destination Info file
2966 # INSRC - wether DEST should be built in the source tree
2967 # DEPENDENCIES - known dependencies
2968 sub output_texinfo_build_rules ($$$@)
2970 my ($source, $dest, $insrc, @deps) = @_;
2972 # Split `a.texi' into `a' and `.texi'.
2973 my ($spfx, $ssfx) = ($source =~ /^(.*?)(\.[^.]*)?$/);
2974 my ($dpfx, $dsfx) = ($dest =~ /^(.*?)(\.[^.]*)?$/);
2979 # We can output two kinds of rules: the "generic" rules use Make
2980 # suffix rules and are appropriate when $source and $dest do not lie
2981 # in a sub-directory; the "specific" rules are needed in the other
2984 # The former are output only once (this is not really apparent here,
2985 # but just remember that some logic deeper in Automake will not
2986 # output the same rule twice); while the later need to be output for
2987 # each Texinfo source.
2990 my $sdir = dirname $source;
2991 if ($sdir eq '.' && dirname ($dest) eq '.')
2994 $makeinfoflags = '-I $(srcdir)';
2999 $makeinfoflags = "-I $sdir -I \$(srcdir)/$sdir";
3002 # A directory can contain two kinds of info files: some built in the
3003 # source tree, and some built in the build tree. The rules are
3004 # different in each case. However we cannot output two different
3005 # set of generic rules. Because in-source builds are more usual, we
3006 # use generic rules in this case and fall back to "specific" rules
3007 # for build-dir builds. (It should not be a problem to invert this
3009 $generic = 0 unless $insrc;
3011 # We cannot use a suffix rule to build info files with an empty
3012 # extension. Otherwise we would output a single suffix inference
3013 # rule, with separate dependencies, as in
3017 # foo.info: foo.texi
3019 # which confuse Solaris make. (See the Autoconf manual for
3020 # details.) Therefore we use a specific rule in this case. This
3021 # applies to info files only (dvi and pdf files always have an
3023 my $generic_info = ($generic && $dsfx) ? 1 : 0;
3025 # If the resulting file lie into a subdirectory,
3026 # make sure this directory will exist.
3027 my $dirstamp = require_build_directory_maybe ($dest);
3029 my $dipfx = ($insrc ? '$(srcdir)/' : '') . $dpfx;
3031 $output_rules .= file_contents ('texibuild',
3032 new Automake::Location,
3034 DEST_PREFIX => $dpfx,
3035 DEST_INFO_PREFIX => $dipfx,
3036 DEST_SUFFIX => $dsfx,
3037 DIRSTAMP => $dirstamp,
3038 GENERIC => $generic,
3039 GENERIC_INFO => $generic_info,
3041 MAKEINFOFLAGS => $makeinfoflags,
3044 SOURCE_INFO => ($generic_info
3046 SOURCE_REAL => $source,
3047 SOURCE_SUFFIX => $ssfx,
3049 return ($dirstamp, "$dpfx.dvi", "$dpfx.pdf", "$dpfx.ps", "$dpfx.html");
3054 # handle_texinfo_helper ($info_texinfos)
3055 # --------------------------------------
3056 # Handle all Texinfo source; helper for handle_texinfo.
3057 sub handle_texinfo_helper ($)
3059 my ($info_texinfos) = @_;
3060 my (@infobase, @info_deps_list, @texi_deps);
3065 # Build a regex matching user-cleaned files.
3066 my $d = var 'DISTCLEANFILES';
3067 my $c = var 'CLEANFILES';
3069 push @f, $d->value_as_list_recursive (inner_expand => 1) if $d;
3070 push @f, $c->value_as_list_recursive (inner_expand => 1) if $c;
3071 @f = map { s|[^A-Za-z_0-9*\[\]\-]|\\$&|g; s|\*|[^/]*|g; $_; } @f;
3072 my $user_cleaned_files = '^(?:' . join ('|', @f) . ')$';
3075 ($info_texinfos->value_as_list_recursive (inner_expand => 1))
3077 my $infobase = $texi;
3078 $infobase =~ s/\.(txi|texinfo|texi)$//;
3080 if ($infobase eq $texi)
3082 # FIXME: report line number.
3083 err_am "texinfo file `$texi' has unrecognized extension";
3087 push @infobase, $infobase;
3089 # If 'version.texi' is referenced by input file, then include
3090 # automatic versioning capability.
3091 my ($out_file, $vtexi, @clean_files) =
3092 scan_texinfo_file ("$relative_dir/$texi")
3094 push (@texi_cleans, @clean_files);
3096 # If the Texinfo source is in a subdirectory, create the
3097 # resulting info in this subdirectory. If it is in the current
3098 # directory, try hard to not prefix "./" because it breaks the
3100 my $outdir = dirname ($texi) . '/';
3101 $outdir = "" if $outdir eq './';
3102 $out_file = $outdir . $out_file;
3104 # Until Automake 1.6.3, .info files were built in the
3105 # source tree. This was an obstacle to the support of
3106 # non-distributed .info files, and non-distributed .texi
3109 # * Non-distributed .texi files is important in some packages
3110 # where .texi files are built at make time, probably using
3111 # other binaries built in the package itself, maybe using
3112 # tools or information found on the build host. Because
3113 # these files are not distributed they are always rebuilt
3114 # at make time; they should therefore not lie in the source
3115 # directory. One plan was to support this using
3116 # nodist_info_TEXINFOS or something similar. (Doing this
3117 # requires some sanity checks. For instance Automake should
3119 # dist_info_TEXINFOS = foo.texi
3120 # nodist_foo_TEXINFOS = included.texi
3121 # because a distributed file should never depend on a
3122 # non-distributed file.)
3124 # * If .texi files are not distributed, then .info files should
3125 # not be distributed either. There are also cases where one
3126 # wants to distribute .texi files, but does not want to
3127 # distribute the .info files. For instance the Texinfo package
3128 # distributes the tool used to build these files; it would
3129 # be a waste of space to distribute them. It's not clear
3130 # which syntax we should use to indicate that .info files should
3131 # not be distributed. Akim Demaille suggested that eventually
3132 # we switch to a new syntax:
3133 # | Maybe we should take some inspiration from what's already
3134 # | done in the rest of Automake. Maybe there is too much
3135 # | syntactic sugar here, and you want
3136 # | nodist_INFO = bar.info
3137 # | dist_bar_info_SOURCES = bar.texi
3138 # | bar_texi_DEPENDENCIES = foo.texi
3139 # | with a bit of magic to have bar.info represent the whole
3140 # | bar*info set. That's a lot more verbose that the current
3141 # | situation, but it is # not new, hence the user has less
3144 # | But there is still too much room for meaningless specs:
3145 # | nodist_INFO = bar.info
3146 # | dist_bar_info_SOURCES = bar.texi
3147 # | dist_PS = bar.ps something-written-by-hand.ps
3148 # | nodist_bar_ps_SOURCES = bar.texi
3149 # | bar_texi_DEPENDENCIES = foo.texi
3150 # | here bar.texi is dist_ in line 2, and nodist_ in 4.
3152 # Back to the point, it should be clear that in order to support
3153 # non-distributed .info files, we need to build them in the
3154 # build tree, not in the source tree (non-distributed .texi
3155 # files are less of a problem, because we do not output build
3156 # rules for them). In Automake 1.7 .info build rules have been
3157 # largely cleaned up so that .info files get always build in the
3158 # build tree, even when distributed. The idea was that
3159 # (1) if during a VPATH build the .info file was found to be
3160 # absent or out-of-date (in the source tree or in the
3161 # build tree), Make would rebuild it in the build tree.
3162 # If an up-to-date source-tree of the .info file existed,
3163 # make would not rebuild it in the build tree.
3164 # (2) having two copies of .info files, one in the source tree
3165 # and one (newer) in the build tree is not a problem
3166 # because `make dist' always pick files in the build tree
3168 # However it turned out the be a bad idea for several reasons:
3169 # * Tru64, OpenBSD, and FreeBSD (not NetBSD) Make do not behave
3170 # like GNU Make on point (1) above. These implementations
3171 # of Make would always rebuild .info files in the build
3172 # tree, even if such files were up to date in the source
3173 # tree. Consequently, it was impossible to perform a VPATH
3174 # build of a package containing Texinfo files using these
3175 # Make implementations.
3176 # (Refer to the Autoconf Manual, section "Limitation of
3177 # Make", paragraph "VPATH", item "target lookup", for
3178 # an account of the differences between these
3180 # * The GNU Coding Standards require these files to be built
3181 # in the source-tree (when they are distributed, that is).
3182 # * Keeping a fresher copy of distributed files in the
3183 # build tree can be annoying during development because
3184 # - if the files is kept under CVS, you really want it
3185 # to be updated in the source tree
3186 # - it is confusing that `make distclean' does not erase
3187 # all files in the build tree.
3189 # Consequently, starting with Automake 1.8, .info files are
3190 # built in the source tree again. Because we still plan to
3191 # support non-distributed .info files at some point, we
3192 # have a single variable ($INSRC) that controls whether
3193 # the current .info file must be built in the source tree
3194 # or in the build tree. Actually this variable is switched
3195 # off for .info files that appear to be cleaned; this is
3196 # for backward compatibility with package such as Texinfo,
3197 # which do things like
3198 # info_TEXINFOS = texinfo.txi info-stnd.texi info.texi
3199 # DISTCLEANFILES = texinfo texinfo-* info*.info*
3200 # # Do not create info files for distribution.
3202 # in order not to distribute .info files.
3203 my $insrc = ($out_file =~ $user_cleaned_files) ? 0 : 1;
3205 my $soutdir = '$(srcdir)/' . $outdir;
3206 $outdir = $soutdir if $insrc;
3208 # If user specified file_TEXINFOS, then use that as explicit
3211 push (@texi_deps, "$soutdir$vtexi") if $vtexi;
3213 my $canonical = canonicalize ($infobase);
3214 if (var ($canonical . "_TEXINFOS"))
3216 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
3217 push_dist_common ('$(' . $canonical . '_TEXINFOS)');
3220 my ($dirstamp, @cfiles) =
3221 output_texinfo_build_rules ($texi, $out_file, $insrc, @texi_deps);
3222 push (@texi_cleans, @cfiles);
3224 push (@info_deps_list, $out_file);
3226 # If a vers*.texi file is needed, emit the rule.
3229 err_am ("`$vtexi', included in `$texi', "
3230 . "also included in `$versions{$vtexi}'")
3231 if defined $versions{$vtexi};
3232 $versions{$vtexi} = $texi;
3234 # We number the stamp-vti files. This is doable since the
3235 # actual names don't matter much. We only number starting
3236 # with the second one, so that the common case looks nice.
3237 my $vti = ($done ? $done : 'vti');
3240 # This is ugly, but it is our historical practice.
3241 if ($config_aux_dir_set_in_configure_ac)
3243 require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3248 require_file_with_macro (TRUE, 'info_TEXINFOS',
3249 FOREIGN, 'mdate-sh');
3253 if ($config_aux_dir_set_in_configure_ac)
3255 $conf_dir = "$am_config_aux_dir/";
3259 $conf_dir = '$(srcdir)/';
3261 $output_rules .= file_contents ('texi-vers',
3262 new Automake::Location,
3265 STAMPVTI => "${soutdir}stamp-$vti",
3266 VTEXI => "$soutdir$vtexi",
3268 DIRSTAMP => $dirstamp);
3272 # Handle location of texinfo.tex.
3273 my $need_texi_file = 0;
3275 if (var ('TEXINFO_TEX'))
3277 # The user defined TEXINFO_TEX so assume he knows what he is
3279 $texinfodir = ('$(srcdir)/'
3280 . dirname (variable_value ('TEXINFO_TEX')));
3282 elsif (option 'cygnus')
3284 $texinfodir = '$(top_srcdir)/../texinfo';
3285 define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex", INTERNAL);
3287 elsif ($config_aux_dir_set_in_configure_ac)
3289 $texinfodir = $am_config_aux_dir;
3290 define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex", INTERNAL);
3291 $need_texi_file = 2; # so that we require_conf_file later
3295 $texinfodir = '$(srcdir)';
3296 $need_texi_file = 1;
3298 define_variable ('am__TEXINFO_TEX_DIR', $texinfodir, INTERNAL);
3300 push (@dist_targets, 'dist-info');
3302 if (! option 'no-installinfo')
3304 # Make sure documentation is made and installed first. Use
3305 # $(INFO_DEPS), not 'info', because otherwise recursive makes
3306 # get run twice during "make all".
3307 unshift (@all, '$(INFO_DEPS)');
3310 define_files_variable ("DVIS", @infobase, 'dvi', INTERNAL);
3311 define_files_variable ("PDFS", @infobase, 'pdf', INTERNAL);
3312 define_files_variable ("PSS", @infobase, 'ps', INTERNAL);
3313 define_files_variable ("HTMLS", @infobase, 'html', INTERNAL);
3315 # This next isn't strictly needed now -- the places that look here
3316 # could easily be changed to look in info_TEXINFOS. But this is
3317 # probably better, in case noinst_TEXINFOS is ever supported.
3318 define_variable ("TEXINFOS", variable_value ('info_TEXINFOS'), INTERNAL);
3320 # Do some error checking. Note that this file is not required
3321 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3323 if ($need_texi_file && ! option 'no-texinfo.tex')
3325 if ($need_texi_file > 1)
3327 require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3332 require_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3337 return makefile_wrap ("", "\t ", @texi_cleans);
3343 # Handle all Texinfo source.
3344 sub handle_texinfo ()
3346 reject_var 'TEXINFOS', "`TEXINFOS' is an anachronism; use `info_TEXINFOS'";
3347 # FIXME: I think this is an obsolete future feature name.
3348 reject_var 'html_TEXINFOS', "HTML generation not yet supported";
3350 my $info_texinfos = var ('info_TEXINFOS');
3354 $texiclean = handle_texinfo_helper ($info_texinfos);
3356 $output_rules .= file_contents ('texinfos',
3357 new Automake::Location,
3358 TEXICLEAN => $texiclean,
3359 'LOCAL-TEXIS' => !!$info_texinfos);
3363 # Handle any man pages.
3364 sub handle_man_pages
3366 reject_var 'MANS', "`MANS' is an anachronism; use `man_MANS'";
3368 # Find all the sections in use. We do this by first looking for
3369 # "standard" sections, and then looking for any additional
3370 # sections used in man_MANS.
3371 my (%sections, %vlist);
3372 # We handle nodist_ for uniformity. man pages aren't distributed
3373 # by default so it isn't actually very important.
3374 foreach my $pfx ('', 'dist_', 'nodist_')
3376 # Add more sections as needed.
3377 foreach my $section ('0'..'9', 'n', 'l')
3379 my $varname = $pfx . 'man' . $section . '_MANS';
3382 $sections{$section} = 1;
3383 $varname = '$(' . $varname . ')';
3384 $vlist{$varname} = 1;
3386 &push_dist_common ($varname)
3391 my $varname = $pfx . 'man_MANS';
3392 my $var = var ($varname);
3395 foreach ($var->value_as_list_recursive)
3397 # A page like `foo.1c' goes into man1dir.
3398 if (/\.([0-9a-z])([a-z]*)$/)
3404 $varname = '$(' . $varname . ')';
3405 $vlist{$varname} = 1;
3406 &push_dist_common ($varname)
3411 return unless %sections;
3413 # Now for each section, generate an install and uninstall rule.
3414 # Sort sections so output is deterministic.
3415 foreach my $section (sort keys %sections)
3417 $output_rules .= &file_contents ('mans',
3418 new Automake::Location,
3419 SECTION => $section);
3422 my @mans = sort keys %vlist;
3423 $output_vars .= file_contents ('mans-vars',
3424 new Automake::Location,
3427 push (@all, '$(MANS)')
3428 unless option 'no-installman';
3431 # Handle DATA variables.
3434 &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3435 'data', 'dataroot', 'dvi', 'html', 'pdf', 'ps',
3436 'sysconf', 'sharedstate', 'localstate',
3437 'pkgdata', 'lisp', 'noinst', 'check');
3445 if (var ('SUBDIRS'))
3447 $output_rules .= ("tags-recursive:\n"
3448 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3449 # Never fail here if a subdir fails; it
3451 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3452 . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3454 push (@tag_deps, 'tags-recursive');
3455 &depend ('.PHONY', 'tags-recursive');
3457 $output_rules .= ("ctags-recursive:\n"
3458 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3459 # Never fail here if a subdir fails; it
3461 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3462 . " && \$(MAKE) \$(AM_MAKEFLAGS) ctags); \\\n"
3464 push (@ctag_deps, 'ctags-recursive');
3465 &depend ('.PHONY', 'ctags-recursive');
3468 if (&saw_sources_p (1)
3469 || var ('ETAGS_ARGS')
3473 foreach my $spec (@config_headers)
3475 my ($out, @ins) = split_config_file_spec ($spec);
3476 foreach my $in (@ins)
3478 # If the config header source is in this directory,
3480 push @config, basename ($in)
3481 if $relative_dir eq dirname ($in);
3484 $output_rules .= &file_contents ('tags',
3485 new Automake::Location,
3486 CONFIG => "@config",
3487 TAGSDIRS => "@tag_deps",
3488 CTAGSDIRS => "@ctag_deps");
3490 set_seen 'TAGS_DEPENDENCIES';
3492 elsif (reject_var ('TAGS_DEPENDENCIES',
3493 "doesn't make sense to define `TAGS_DEPENDENCIES'"
3494 . "without\nsources or `ETAGS_ARGS'"))
3499 # Every Makefile must define some sort of TAGS rule.
3500 # Otherwise, it would be possible for a top-level "make TAGS"
3501 # to fail because some subdirectory failed.
3502 $output_rules .= "tags: TAGS\nTAGS:\n\n";
3504 $output_rules .= "ctags: CTAGS\nCTAGS:\n\n";
3508 # Handle multilib support.
3511 if ($seen_multilib && $relative_dir eq '.')
3513 $output_rules .= &file_contents ('multilib', new Automake::Location);
3514 push (@all, 'all-multi');
3519 # user_phony_rule ($NAME)
3520 # -----------------------
3521 # Return false if rule $NAME does not exist. Otherwise,
3522 # declare it as phony, complete its definition (in case it is
3523 # conditional), and return its Automake::Rule instance.
3524 sub user_phony_rule ($)
3527 my $rule = rule $name;
3530 depend ('.PHONY', $name);
3531 # Define $NAME in all condition where it is not already defined,
3532 # so that it is always OK to depend on $NAME.
3533 for my $c ($rule->not_always_defined_in_cond (TRUE)->conds)
3535 Automake::Rule::define ($name, 'internal', RULE_AUTOMAKE,
3537 $output_rules .= $c->subst_string . "$name:\n";
3545 # &for_dist_common ($A, $B)
3546 # -------------------------
3547 # Subroutine for &handle_dist: sort files to dist.
3549 # We put README first because it then becomes easier to make a
3550 # Usenet-compliant shar file (in these, README must be first).
3552 # FIXME: do more ordering of files here.
3566 # Handle 'dist' target.
3569 # Substitutions for distdir.am
3572 # Define DIST_SUBDIRS. This must always be done, regardless of the
3573 # no-dist setting: target like `distclean' or `maintainer-clean' use it.
3574 my $subdirs = var ('SUBDIRS');
3577 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3578 # to all possible directories, and use it. If DIST_SUBDIRS is
3579 # defined, just use it.
3581 # Note that we check DIST_SUBDIRS first on purpose, so that
3582 # we don't call has_conditional_contents for now reason.
3583 # (In the past one project used so many conditional subdirectories
3584 # that calling has_conditional_contents on SUBDIRS caused
3585 # automake to grow to 150Mb -- this should not happen with
3586 # the current implementation of has_conditional_contents,
3587 # but it's more efficient to avoid the call anyway.)
3588 if (var ('DIST_SUBDIRS'))
3591 elsif ($subdirs->has_conditional_contents)
3593 define_pretty_variable
3594 ('DIST_SUBDIRS', TRUE, INTERNAL,
3595 uniq ($subdirs->value_as_list_recursive));
3599 # We always define this because that is what `distclean'
3601 define_pretty_variable ('DIST_SUBDIRS', TRUE, INTERNAL,
3606 # The remaining definitions are only required when a dist target is used.
3607 return if option 'no-dist';
3609 # At least one of the archive formats must be enabled.
3610 if ($relative_dir eq '.')
3612 my $archive_defined = option 'no-dist-gzip' ? 0 : 1;
3613 $archive_defined ||=
3614 grep { option "dist-$_" } qw(shar zip tarZ bzip2 lzma);
3615 error (option 'no-dist-gzip',
3616 "no-dist-gzip specified but no dist-* specified, "
3617 . "at least one archive format must be enabled")
3618 unless $archive_defined;
3621 # Look for common files that should be included in distribution.
3622 # If the aux dir is set, and it does not have a Makefile.am, then
3623 # we check for these files there as well.
3625 if ($relative_dir eq '.'
3626 && $config_aux_dir_set_in_configure_ac)
3628 if (! &is_make_dir ($config_aux_dir))
3633 foreach my $cfile (@common_files)
3635 if (dir_has_case_matching_file ($relative_dir, $cfile)
3636 # The file might be absent, but if it can be built it's ok.
3639 &push_dist_common ($cfile);
3642 # Don't use `elsif' here because a file might meaningfully
3643 # appear in both directories.
3644 if ($check_aux && dir_has_case_matching_file ($config_aux_dir, $cfile))
3646 &push_dist_common ("$config_aux_dir/$cfile")
3650 # We might copy elements from $configure_dist_common to
3651 # %dist_common if we think we need to. If the file appears in our
3652 # directory, we would have discovered it already, so we don't
3653 # check that. But if the file is in a subdir without a Makefile,
3654 # we want to distribute it here if we are doing `.'. Ugly!
3655 if ($relative_dir eq '.')
3657 foreach my $file (split (' ' , $configure_dist_common))
3659 push_dist_common ($file)
3660 unless is_make_dir (dirname ($file));
3664 # Files to distributed. Don't use ->value_as_list_recursive
3665 # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3666 my @dist_common = split (' ', rvar ('DIST_COMMON')->variable_value);
3667 @dist_common = uniq (sort for_dist_common (@dist_common));
3668 variable_delete 'DIST_COMMON';
3669 define_pretty_variable ('DIST_COMMON', TRUE, INTERNAL, @dist_common);
3671 # Now that we've processed DIST_COMMON, disallow further attempts
3673 $handle_dist_run = 1;
3675 # Scan EXTRA_DIST to see if we need to distribute anything from a
3676 # subdir. If so, add it to the list. I didn't want to do this
3677 # originally, but there were so many requests that I finally
3679 my $extra_dist = var ('EXTRA_DIST');
3681 $transform{'DISTCHECK-HOOK'} = !! rule 'distcheck-hook';
3682 $transform{'GETTEXT'} = $seen_gettext && !$seen_gettext_external;
3684 # If the target `dist-hook' exists, make sure it is run. This
3685 # allows users to do random weird things to the distribution
3686 # before it is packaged up.
3687 push (@dist_targets, 'dist-hook')
3688 if user_phony_rule 'dist-hook';
3689 $transform{'DIST-TARGETS'} = join (' ', @dist_targets);
3691 my $flm = option ('filename-length-max');
3692 my $filename_filter = $flm ? '.' x $flm->[1] : '';
3694 $output_rules .= &file_contents ('distdir',
3695 new Automake::Location,
3697 FILENAME_FILTER => $filename_filter);
3701 # check_directory ($NAME, $WHERE)
3702 # -------------------------------
3703 # Ensure $NAME is a directory, and that it uses sane name.
3704 # Use $WHERE as a location in the diagnostic, if any.
3705 sub check_directory ($$)
3707 my ($dir, $where) = @_;
3709 error $where, "required directory $relative_dir/$dir does not exist"
3710 unless -d "$relative_dir/$dir";
3712 # If an `obj/' directory exists, BSD make will enter it before
3713 # reading `Makefile'. Hence the `Makefile' in the current directory
3719 # % cat obj/Makefile
3725 # % pmake # BSD make
3728 msg ('portability', $where,
3729 "naming a subdirectory `obj' causes troubles with BSD make")
3732 # `aux' is probably the most important of the following forbidden name,
3733 # since it's tempting to use it as an AC_CONFIG_AUX_DIR.
3734 msg ('portability', $where,
3735 "name `$dir' is reserved on W32 and DOS platforms")
3736 if grep (/^\Q$dir\E$/i, qw/aux lpt1 lpt2 lpt3 com1 com2 com3 com4 con prn/);
3739 # check_directories_in_var ($VARIABLE)
3740 # ------------------------------------
3741 # Recursively check all items in variables $VARIABLE as directories
3742 sub check_directories_in_var ($)
3745 $var->traverse_recursively
3748 my ($var, $val, $cond, $full_cond) = @_;
3749 check_directory ($val, $var->rdef ($cond)->location);
3753 skip_ac_subst => 1);
3756 # &handle_subdirs ()
3757 # ------------------
3758 # Handle subdirectories.
3759 sub handle_subdirs ()
3761 my $subdirs = var ('SUBDIRS');
3765 check_directories_in_var $subdirs;
3767 my $dsubdirs = var ('DIST_SUBDIRS');
3768 check_directories_in_var $dsubdirs
3771 $output_rules .= &file_contents ('subdirs', new Automake::Location);
3772 rvar ('RECURSIVE_TARGETS')->rdef (TRUE)->{'pretty'} = VAR_SORTED; # Gross!
3776 # ($REGEN, @DEPENDENCIES)
3779 # If aclocal.m4 creation is automated, return the list of its dependencies.
3780 sub scan_aclocal_m4 ()
3782 my $regen_aclocal = 0;
3784 set_seen 'CONFIG_STATUS_DEPENDENCIES';
3785 set_seen 'CONFIGURE_DEPENDENCIES';
3787 if (-f 'aclocal.m4')
3789 &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4', INTERNAL);
3791 my $aclocal = new Automake::XFile "< aclocal.m4";
3792 my $line = $aclocal->getline;
3793 $regen_aclocal = $line =~ 'generated automatically by aclocal';
3798 if (set_seen ('ACLOCAL_M4_SOURCES'))
3800 push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3801 msg_var ('obsolete', 'ACLOCAL_M4_SOURCES',
3802 "`ACLOCAL_M4_SOURCES' is obsolete.\n"
3803 . "It should be safe to simply remove it.");
3806 # Note that it might be possible that aclocal.m4 doesn't exist but
3807 # should be auto-generated. This case probably isn't very
3810 return ($regen_aclocal, @ac_deps);
3814 # Helper function for substitute_ac_subst_variables.
3815 sub substitute_ac_subst_variables_worker($)
3818 return "\@$token\@" if var $token;
3819 return "\${$token\}";
3822 # substitute_ac_subst_variables ($TEXT)
3823 # -------------------------------------
3824 # Replace any occurrence of ${FOO} in $TEXT by @FOO@ if FOO is an AC_SUBST
3826 sub substitute_ac_subst_variables ($)
3829 $text =~ s/\${([^ \t=:+{}]+)}/&substitute_ac_subst_variables_worker ($1)/ge;
3834 # &prepend_srcdir (@INPUTS)
3835 # -------------------------
3836 # Prepend $(srcdir) or $(top_srcdir) to all @INPUTS. The idea is that
3837 # if an input file has a directory part the same as the current
3838 # directory, then the directory part is simply replaced by $(srcdir).
3839 # But if the directory part is different, then $(top_srcdir) is
3841 sub prepend_srcdir (@)
3846 foreach my $single (@inputs)
3848 if (dirname ($single) eq $relative_dir)
3850 push (@newinputs, '$(srcdir)/' . basename ($single));
3854 push (@newinputs, '$(top_srcdir)/' . $single);
3861 # rewrite_inputs_into_dependencies ($OUTPUT, @INPUTS)
3862 # ---------------------------------------------------
3863 # Compute a list of dependencies appropriate for the rebuild
3865 # AC_CONFIG_FILES($OUTPUT:$INPUT[0]:$INPUTS[1]:...)
3866 # Also distribute $INPUTs which are not build by another AC_CONFIG_FILES.
3867 sub rewrite_inputs_into_dependencies ($@)
3869 my ($file, @inputs) = @_;
3874 # We cannot create dependencies on shell variables.
3875 next if (substitute_ac_subst_variables $i) =~ /\$/;
3877 if (exists $ac_config_files_location{$i})
3879 my $di = dirname $i;
3880 if ($di eq $relative_dir)
3884 # In the top-level Makefile we do not use $(top_builddir), because
3885 # we are already there, and since the targets are built without
3886 # a $(top_builddir), it helps BSD Make to match them with
3888 elsif ($relative_dir ne '.')
3890 $i = '$(top_builddir)/' . $i;
3895 msg ('error', $ac_config_files_location{$file},
3896 "required file `$i' not found")
3897 unless $i =~ /\$/ || exists $output_files{$i} || -f $i;
3898 ($i) = prepend_srcdir ($i);
3899 push_dist_common ($i);
3908 # &handle_configure ($MAKEFILE_AM, $MAKEFILE_IN, $MAKEFILE, @INPUTS)
3909 # ------------------------------------------------------------------
3910 # Handle remaking and configure stuff.
3911 # We need the name of the input file, to do proper remaking rules.
3912 sub handle_configure ($$$@)
3914 my ($makefile_am, $makefile_in, $makefile, @inputs) = @_;
3916 prog_error 'empty @inputs'
3919 my ($rel_makefile_am, $rel_makefile_in) = prepend_srcdir ($makefile_am,
3921 my $rel_makefile = basename $makefile;
3923 my $colon_infile = ':' . join (':', @inputs);
3924 $colon_infile = '' if $colon_infile eq ":$makefile.in";
3925 my @rewritten = rewrite_inputs_into_dependencies ($makefile, @inputs);
3926 my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4;
3927 define_pretty_variable ('am__aclocal_m4_deps', TRUE, INTERNAL,
3928 @configure_deps, @aclocal_m4_deps,
3929 '$(top_srcdir)/' . $configure_ac);
3930 my @configuredeps = ('$(am__aclocal_m4_deps)', '$(CONFIGURE_DEPENDENCIES)');
3931 push @configuredeps, '$(ACLOCAL_M4)' if -f 'aclocal.m4';
3932 define_pretty_variable ('am__configure_deps', TRUE, INTERNAL,
3935 $output_rules .= file_contents
3937 new Automake::Location,
3938 MAKEFILE => $rel_makefile,
3939 'MAKEFILE-DEPS' => "@rewritten",
3940 'CONFIG-MAKEFILE' => ($relative_dir eq '.') ? '$@' : '$(subdir)/$@',
3941 'MAKEFILE-IN' => $rel_makefile_in,
3942 'MAKEFILE-IN-DEPS' => "@include_stack",
3943 'MAKEFILE-AM' => $rel_makefile_am,
3944 STRICTNESS => global_option 'cygnus'
3945 ? 'cygnus' : $strictness_name,
3946 'USE-DEPS' => global_option 'no-dependencies'
3947 ? ' --ignore-deps' : '',
3948 'MAKEFILE-AM-SOURCES' => "$makefile$colon_infile",
3949 'REGEN-ACLOCAL-M4' => $regen_aclocal_m4);
3951 if ($relative_dir eq '.')
3953 &push_dist_common ('acconfig.h')
3957 # If we have a configure header, require it.
3959 my @distclean_config;
3960 foreach my $spec (@config_headers)
3963 # $CONFIG_H_PATH: config.h from top level.
3964 my ($config_h_path, @ins) = split_config_file_spec ($spec);
3965 my $config_h_dir = dirname ($config_h_path);
3967 # If the header is in the current directory we want to build
3968 # the header here. Otherwise, if we're at the topmost
3969 # directory and the header's directory doesn't have a
3970 # Makefile, then we also want to build the header.
3971 if ($relative_dir eq $config_h_dir
3972 || ($relative_dir eq '.' && ! &is_make_dir ($config_h_dir)))
3974 my ($cn_sans_dir, $stamp_dir);
3975 if ($relative_dir eq $config_h_dir)
3977 $cn_sans_dir = basename ($config_h_path);
3982 $cn_sans_dir = $config_h_path;
3983 if ($config_h_dir eq '.')
3989 $stamp_dir = $config_h_dir . '/';
3993 # This will also distribute all inputs.
3994 @ins = rewrite_inputs_into_dependencies ($config_h_path, @ins);
3996 # Cannot define rebuild rules for filenames with shell variables.
3997 next if (substitute_ac_subst_variables $config_h_path) =~ /\$/;
3999 # Header defined in this directory.
4001 if (-f $config_h_path . '.top')
4003 push (@files, "$cn_sans_dir.top");
4005 if (-f $config_h_path . '.bot')
4007 push (@files, "$cn_sans_dir.bot");
4010 push_dist_common (@files);
4012 # For now, acconfig.h can only appear in the top srcdir.
4013 if (-f 'acconfig.h')
4015 push (@files, '$(top_srcdir)/acconfig.h');
4018 my $stamp = "${stamp_dir}stamp-h${hdr_index}";
4020 file_contents ('remake-hdr',
4021 new Automake::Location,
4023 CONFIG_H => $cn_sans_dir,
4024 CONFIG_HIN => $ins[0],
4025 CONFIG_H_DEPS => "@ins",
4026 CONFIG_H_PATH => $config_h_path,
4029 push @distclean_config, $cn_sans_dir, $stamp;
4033 $output_rules .= file_contents ('clean-hdr',
4034 new Automake::Location,
4035 FILES => "@distclean_config")
4036 if @distclean_config;
4038 # Distribute and define mkinstalldirs only if it is already present
4039 # in the package, for backward compatibility (some people may still
4040 # use $(mkinstalldirs)).
4041 my $mkidpath = "$config_aux_dir/mkinstalldirs";
4044 # Use require_file so that any existing script gets updated
4045 # by --force-missing.
4046 require_conf_file ($mkidpath, FOREIGN, 'mkinstalldirs');
4047 define_variable ('mkinstalldirs',
4048 "\$(SHELL) $am_config_aux_dir/mkinstalldirs", INTERNAL);
4052 # Use $(install_sh), not $(MKDIR_P) because the latter requires
4053 # at least one argument, and $(mkinstalldirs) used to work
4054 # even without arguments (e.g. $(mkinstalldirs) $(conditional_dir)).
4055 define_variable ('mkinstalldirs', '$(install_sh) -d', INTERNAL);
4058 reject_var ('CONFIG_HEADER',
4059 "`CONFIG_HEADER' is an anachronism; now determined "
4060 . "automatically\nfrom `$configure_ac'");
4063 foreach my $spec (@config_headers)
4065 my ($out, @ins) = split_config_file_spec ($spec);
4066 # Generate CONFIG_HEADER define.
4067 if ($relative_dir eq dirname ($out))
4069 push @config_h, basename ($out);
4073 push @config_h, "\$(top_builddir)/$out";
4076 define_variable ("CONFIG_HEADER", "@config_h", INTERNAL)
4079 # Now look for other files in this directory which must be remade
4080 # by config.status, and generate rules for them.
4081 my @actual_other_files = ();
4082 foreach my $lfile (@other_input_files)
4086 if ($lfile =~ /^([^:]*):(.*)$/)
4088 # This is the ":" syntax of AC_OUTPUT.
4090 @inputs = split (':', $2);
4096 @inputs = $file . '.in';
4099 # Automake files should not be stored in here, but in %MAKE_LIST.
4100 prog_error ("$lfile in \@other_input_files\n"
4101 . "\@other_input_files = (@other_input_files)")
4102 if -f $file . '.am';
4104 my $local = basename ($file);
4106 # We skip files that aren't in this directory. However, if
4107 # the file's directory does not have a Makefile, and we are
4108 # currently doing `.', then we create a rule to rebuild the
4109 # file in the subdir.
4110 my $fd = dirname ($file);
4111 if ($fd ne $relative_dir)
4113 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
4123 my @rewritten_inputs = rewrite_inputs_into_dependencies ($file, @inputs);
4125 # Cannot output rules for shell variables.
4126 next if (substitute_ac_subst_variables $local) =~ /\$/;
4128 $output_rules .= ($local . ': '
4129 . '$(top_builddir)/config.status '
4130 . "@rewritten_inputs\n"
4132 . 'cd $(top_builddir) && '
4133 . '$(SHELL) ./config.status '
4134 . ($relative_dir eq '.' ? '' : '$(subdir)/')
4137 push (@actual_other_files, $local);
4140 # For links we should clean destinations and distribute sources.
4141 foreach my $spec (@config_links)
4143 my ($link, $file) = split /:/, $spec;
4144 # Some people do AC_CONFIG_LINKS($computed). We only handle
4145 # the DEST:SRC form.
4147 my $where = $ac_config_files_location{$link};
4149 # Skip destinations that contain shell variables.
4150 if ((substitute_ac_subst_variables $link) !~ /\$/)
4152 # We skip links that aren't in this directory. However, if
4153 # the link's directory does not have a Makefile, and we are
4154 # currently doing `.', then we add the link to CONFIG_CLEAN_FILES
4155 # in `.'s Makefile.in.
4156 my $local = basename ($link);
4157 my $fd = dirname ($link);
4158 if ($fd ne $relative_dir)
4160 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
4169 push @actual_other_files, $local if $local;
4172 # Do not process sources that contain shell variables.
4173 if ((substitute_ac_subst_variables $file) !~ /\$/)
4175 my $fd = dirname ($file);
4177 # We distribute files that are in this directory.
4178 # At the top-level (`.') we also distribute files whose
4179 # directory does not have a Makefile.
4180 if (($fd eq $relative_dir)
4181 || ($relative_dir eq '.' && ! &is_make_dir ($fd)))
4183 # The following will distribute $file as a side-effect when
4184 # it is appropriate (i.e., when $file is not already an output).
4185 # We do not need the result, just the side-effect.
4186 rewrite_inputs_into_dependencies ($link, $file);
4191 # These files get removed by "make distclean".
4192 define_pretty_variable ('CONFIG_CLEAN_FILES', TRUE, INTERNAL,
4193 @actual_other_files);
4199 my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
4200 'oldinclude', 'pkginclude',
4204 next unless $_->[1] =~ /\..*$/;
4205 &saw_extension ($&);
4211 return if ! $seen_gettext || $relative_dir ne '.';
4213 my $subdirs = var 'SUBDIRS';
4217 err_ac "AM_GNU_GETTEXT used but SUBDIRS not defined";
4221 # Perform some sanity checks to help users get the right setup.
4222 # We disable these tests when po/ doesn't exist in order not to disallow
4223 # unusual gettext setups.
4228 # | 1) If a package doesn't have a directory po/ at top level, it
4229 # | will likely have multiple po/ directories in subpackages.
4231 # | 2) It is useful to warn for the absence of intl/ if AM_GNU_GETTEXT
4232 # | is used without 'external'. It is also useful to warn for the
4233 # | presence of intl/ if AM_GNU_GETTEXT([external]) is used. Both
4234 # | warnings apply only to the usual layout of packages, therefore
4235 # | they should both be disabled if no po/ directory is found at
4240 my @subdirs = $subdirs->value_as_list_recursive;
4242 msg_var ('syntax', $subdirs,
4243 "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
4244 if ! grep ($_ eq 'po', @subdirs);
4246 # intl/ is not required when AM_GNU_GETTEXT is called with the
4247 # `external' option and AM_GNU_GETTEXT_INTL_SUBDIR is not called.
4248 msg_var ('syntax', $subdirs,
4249 "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
4250 if (! ($seen_gettext_external && ! $seen_gettext_intl)
4251 && ! grep ($_ eq 'intl', @subdirs));
4253 # intl/ should not be used with AM_GNU_GETTEXT([external]), except
4254 # if AM_GNU_GETTEXT_INTL_SUBDIR is called.
4255 msg_var ('syntax', $subdirs,
4256 "`intl' should not be in SUBDIRS when "
4257 . "AM_GNU_GETTEXT([external]) is used")
4258 if ($seen_gettext_external && ! $seen_gettext_intl
4259 && grep ($_ eq 'intl', @subdirs));
4262 require_file ($ac_gettext_location, GNU, 'ABOUT-NLS');
4265 # Handle footer elements.
4268 reject_rule ('.SUFFIXES',
4269 "use variable `SUFFIXES', not target `.SUFFIXES'");
4271 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
4272 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
4273 # anything else, by sticking it right after the default: target.
4274 $output_header .= ".SUFFIXES:\n";
4275 my $suffixes = var 'SUFFIXES';
4276 my @suffixes = Automake::Rule::suffixes;
4277 if (@suffixes || $suffixes)
4279 # Make sure SUFFIXES has unique elements. Sort them to ensure
4280 # the output remains consistent. However, $(SUFFIXES) is
4281 # always at the start of the list, unsorted. This is done
4282 # because make will choose rules depending on the ordering of
4283 # suffixes, and this lets the user have some control. Push
4284 # actual suffixes, and not $(SUFFIXES). Some versions of make
4285 # do not like variable substitutions on the .SUFFIXES line.
4286 my @user_suffixes = ($suffixes
4287 ? $suffixes->value_as_list_recursive : ());
4289 my %suffixes = map { $_ => 1 } @suffixes;
4290 delete @suffixes{@user_suffixes};
4292 $output_header .= (".SUFFIXES: "
4293 . join (' ', @user_suffixes, sort keys %suffixes)
4297 $output_trailer .= file_contents ('footer', new Automake::Location);
4301 # Generate `make install' rules.
4302 sub handle_install ()
4304 $output_rules .= &file_contents
4306 new Automake::Location,
4307 maybe_BUILT_SOURCES => (set_seen ('BUILT_SOURCES')
4308 ? (" \$(BUILT_SOURCES)\n"
4309 . "\t\$(MAKE) \$(AM_MAKEFLAGS)")
4311 'installdirs-local' => (user_phony_rule 'installdirs-local'
4312 ? ' installdirs-local' : ''),
4313 am__installdirs => variable_value ('am__installdirs') || '');
4317 # Deal with all and all-am.
4320 my ($makefile) = @_;
4324 # Put this at the beginning for the sake of non-GNU makes. This
4325 # is still wrong if these makes can run parallel jobs. But it is
4327 unshift (@all, basename ($makefile));
4329 foreach my $spec (@config_headers)
4331 my ($out, @ins) = split_config_file_spec ($spec);
4332 push (@all, basename ($out))
4333 if dirname ($out) eq $relative_dir;
4336 # Install `all' hooks.
4337 push (@all, "all-local")
4338 if user_phony_rule "all-local";
4340 &pretty_print_rule ("all-am:", "\t\t", @all);
4341 &depend ('.PHONY', 'all-am', 'all');
4346 my @local_headers = ();
4347 push @local_headers, '$(BUILT_SOURCES)'
4348 if var ('BUILT_SOURCES');
4349 foreach my $spec (@config_headers)
4351 my ($out, @ins) = split_config_file_spec ($spec);
4352 push @local_headers, basename ($out)
4353 if dirname ($out) eq $relative_dir;
4358 # We need to make sure config.h is built before we recurse.
4359 # We also want to make sure that built sources are built
4360 # before any ordinary `all' targets are run. We can't do this
4361 # by changing the order of dependencies to the "all" because
4362 # that breaks when using parallel makes. Instead we handle
4363 # things explicitly.
4364 $output_all .= ("all: @local_headers"
4366 . '$(MAKE) $(AM_MAKEFLAGS) '
4367 . (var ('SUBDIRS') ? 'all-recursive' : 'all-am')
4372 $output_all .= "all: " . (var ('SUBDIRS')
4373 ? 'all-recursive' : 'all-am') . "\n\n";
4378 # &do_check_merge_target ()
4379 # -------------------------
4380 # Handle check merge target specially.
4381 sub do_check_merge_target ()
4383 # Include user-defined local form of target.
4384 push @check_tests, 'check-local'
4385 if user_phony_rule 'check-local';
4387 # In --cygnus mode, check doesn't depend on all.
4388 if (option 'cygnus')
4390 # Just run the local check rules.
4391 pretty_print_rule ('check-am:', "\t\t", @check);
4395 # The check target must depend on the local equivalent of
4396 # `all', to ensure all the primary targets are built. Then it
4397 # must build the local check rules.
4398 $output_rules .= "check-am: all-am\n";
4399 pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4403 pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4407 depend '.PHONY', 'check', 'check-am';
4408 # Handle recursion. We have to honor BUILT_SOURCES like for `all:'.
4409 $output_rules .= ("check: "
4410 . (var ('BUILT_SOURCES')
4411 ? "\$(BUILT_SOURCES)\n\t\$(MAKE) \$(AM_MAKEFLAGS) "
4413 . (var ('SUBDIRS') ? 'check-recursive' : 'check-am')
4417 # handle_clean ($MAKEFILE)
4418 # ------------------------
4419 # Handle all 'clean' targets.
4420 sub handle_clean ($)
4422 my ($makefile) = @_;
4424 # Clean the files listed in user variables if they exist.
4425 $clean_files{'$(MOSTLYCLEANFILES)'} = MOSTLY_CLEAN
4426 if var ('MOSTLYCLEANFILES');
4427 $clean_files{'$(CLEANFILES)'} = CLEAN
4428 if var ('CLEANFILES');
4429 $clean_files{'$(DISTCLEANFILES)'} = DIST_CLEAN
4430 if var ('DISTCLEANFILES');
4431 $clean_files{'$(MAINTAINERCLEANFILES)'} = MAINTAINER_CLEAN
4432 if var ('MAINTAINERCLEANFILES');
4434 # Built sources are automatically removed by maintainer-clean.
4435 $clean_files{'$(BUILT_SOURCES)'} = MAINTAINER_CLEAN
4436 if var ('BUILT_SOURCES');
4438 # Compute a list of "rm"s to run for each target.
4439 my %rms = (MOSTLY_CLEAN, [],
4442 MAINTAINER_CLEAN, []);
4444 foreach my $file (keys %clean_files)
4446 my $when = $clean_files{$file};
4447 prog_error 'invalid entry in %clean_files'
4448 unless exists $rms{$when};
4450 my $rm = "rm -f $file";
4451 # If file is a variable, make sure when don't call `rm -f' without args.
4452 $rm ="test -z \"$file\" || $rm"
4453 if ($file =~ /^\s*\$(\(.*\)|\{.*\})\s*$/);
4455 push @{$rms{$when}}, "\t-$rm\n";
4458 $output_rules .= &file_contents
4460 new Automake::Location,
4461 MOSTLYCLEAN_RMS => join ('', sort @{$rms{&MOSTLY_CLEAN}}),
4462 CLEAN_RMS => join ('', sort @{$rms{&CLEAN}}),
4463 DISTCLEAN_RMS => join ('', sort @{$rms{&DIST_CLEAN}}),
4464 MAINTAINER_CLEAN_RMS => join ('', sort @{$rms{&MAINTAINER_CLEAN}}),
4465 MAKEFILE => basename $makefile,
4470 # &target_cmp ($A, $B)
4471 # --------------------
4472 # Subroutine for &handle_factored_dependencies to let `.PHONY' and
4473 # other `.TARGETS' be last.
4476 return 0 if $a eq $b;
4478 my $a1 = substr ($a, 0, 1);
4479 my $b1 = substr ($b, 0, 1);
4482 return -1 if $b1 eq '.';
4483 return 1 if $a1 eq '.';
4489 # &handle_factored_dependencies ()
4490 # --------------------------------
4491 # Handle everything related to gathered targets.
4492 sub handle_factored_dependencies
4495 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4496 'uninstall-exec-local', 'uninstall-exec-hook',
4497 'uninstall-dvi-local',
4498 'uninstall-html-local',
4499 'uninstall-info-local',
4500 'uninstall-pdf-local',
4501 'uninstall-ps-local')
4505 reject_rule ($utarg, "use `$x', not `$utarg'");
4508 reject_rule ('install-local',
4509 "use `install-data-local' or `install-exec-local', "
4510 . "not `install-local'");
4512 reject_rule ('install-hook',
4513 "use `install-data-hook' or `install-exec-hook', "
4514 . "not `install-hook'");
4516 # Install the -local hooks.
4517 foreach (keys %dependencies)
4519 # Hooks are installed on the -am targets.
4521 depend ("$_-am", "$_-local")
4522 if user_phony_rule "$_-local";
4525 # Install the -hook hooks.
4526 # FIXME: Why not be as liberal as we are with -local hooks?
4527 foreach ('install-exec', 'install-data', 'uninstall')
4529 if (user_phony_rule "$_-hook")
4531 depend ('.MAKE', "$_-am");
4532 register_action("$_-am",
4533 ("\t\@\$(NORMAL_INSTALL)\n"
4534 . "\t\$(MAKE) \$(AM_MAKEFLAGS) $_-hook"));
4538 # All the required targets are phony.
4539 depend ('.PHONY', keys %required_targets);
4541 # Actually output gathered targets.
4542 foreach (sort target_cmp keys %dependencies)
4544 # If there is nothing about this guy, skip it.
4546 unless (@{$dependencies{$_}}
4548 || $required_targets{$_});
4550 # Define gathered targets in undefined conditions.
4551 # FIXME: Right now we must handle .PHONY as an exception,
4552 # because people write things like
4553 # .PHONY: myphonytarget
4554 # to append dependencies. This would not work if Automake
4555 # refrained from defining its own .PHONY target as it does
4556 # with other overridden targets.
4557 # Likewise for `.MAKE'.
4558 my @undefined_conds = (TRUE,);
4559 if ($_ ne '.PHONY' && $_ ne '.MAKE')
4562 Automake::Rule::define ($_, 'internal',
4563 RULE_AUTOMAKE, TRUE, INTERNAL);
4565 my @uniq_deps = uniq (sort @{$dependencies{$_}});
4566 foreach my $cond (@undefined_conds)
4568 my $condstr = $cond->subst_string;
4569 &pretty_print_rule ("$condstr$_:", "$condstr\t", @uniq_deps);
4570 $output_rules .= $actions{$_} if defined $actions{$_};
4571 $output_rules .= "\n";
4577 # &handle_tests_dejagnu ()
4578 # ------------------------
4579 sub handle_tests_dejagnu
4581 push (@check_tests, 'check-DEJAGNU');
4582 $output_rules .= file_contents ('dejagnu', new Automake::Location);
4586 # Handle TESTS variable and other checks.
4589 if (option 'dejagnu')
4591 &handle_tests_dejagnu;
4595 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4597 reject_var ($c, "`$c' defined but `dejagnu' not in "
4598 . "`AUTOMAKE_OPTIONS'");
4604 push (@check_tests, 'check-TESTS');
4605 $output_rules .= &file_contents ('check', new Automake::Location,
4606 COLOR => !! option 'color-tests');
4608 # Tests that are known programs should have $(EXEEXT) appended.
4609 # For matching purposes, we need to adjust XFAIL_TESTS as well.
4610 append_exeext { exists $known_programs{$_[0]} } 'TESTS';
4611 append_exeext { exists $known_programs{$_[0]} } 'XFAIL_TESTS'
4612 if (var ('XFAIL_TESTS'));
4616 # Handle Emacs Lisp.
4617 sub handle_emacs_lisp
4619 my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4622 return if ! @elfiles;
4624 define_pretty_variable ('am__ELFILES', TRUE, INTERNAL,
4625 map { $_->[1] } @elfiles);
4626 define_pretty_variable ('am__ELCFILES', TRUE, INTERNAL,
4627 '$(am__ELFILES:.el=.elc)');
4628 # This one can be overridden by users.
4629 define_pretty_variable ('ELCFILES', TRUE, INTERNAL, '$(LISP:.el=.elc)');
4631 push @all, '$(ELCFILES)';
4633 require_variables ($elfiles[0][0], "Emacs Lisp sources seen", TRUE,
4634 'EMACS', 'lispdir');
4635 require_conf_file ($elfiles[0][0], FOREIGN, 'elisp-comp');
4636 &define_variable ('elisp_comp', "$am_config_aux_dir/elisp-comp", INTERNAL);
4642 my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4644 return if ! @pyfiles;
4646 require_variables ($pyfiles[0][0], "Python sources seen", TRUE, 'PYTHON');
4647 require_conf_file ($pyfiles[0][0], FOREIGN, 'py-compile');
4648 &define_variable ('py_compile', "$am_config_aux_dir/py-compile", INTERNAL);
4654 my @sourcelist = &am_install_var ('-candist',
4656 'java', 'noinst', 'check');
4657 return if ! @sourcelist;
4659 my @prefix = am_primary_prefixes ('JAVA', 1,
4660 'java', 'noinst', 'check');
4663 foreach my $curs (@prefix)
4666 if $curs eq 'EXTRA';
4668 err_var "${curs}_JAVA", "multiple _JAVA primaries in use"
4674 push (@all, 'class' . $dir . '.stamp');
4678 # Handle some of the minor options.
4679 sub handle_minor_options
4681 if (option 'readme-alpha')
4683 if ($relative_dir eq '.')
4685 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4687 msg ('error-gnits', $package_version_location,
4688 "version `$package_version' doesn't follow " .
4691 if (defined $1 && -f 'README-alpha')
4693 # This means we have an alpha release. See
4694 # GNITS_VERSION_PATTERN for details.
4695 push_dist_common ('README-alpha');
4701 ################################################################
4703 # ($OUTPUT, @INPUTS)
4704 # &split_config_file_spec ($SPEC)
4705 # -------------------------------
4706 # Decode the Autoconf syntax for config files (files, headers, links
4708 sub split_config_file_spec ($)
4711 my ($output, @inputs) = split (/:/, $spec);
4713 push @inputs, "$output.in"
4716 return ($output, @inputs);
4720 # locate_am (@POSSIBLE_SOURCES)
4721 # -----------------------------
4722 # AC_CONFIG_FILES allow specifications such as Makefile:top.in:mid.in:bot.in
4723 # This functions returns the first *.in file for which a *.am exists.
4724 # It returns undef otherwise.
4729 foreach my $file (@rest)
4731 if (($file =~ /^(.*)\.in$/) && -f "$1.am")
4742 # &scan_autoconf_config_files ($WHERE, $CONFIG-FILES)
4743 # ---------------------------------------------------
4744 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4746 sub scan_autoconf_config_files ($$)
4748 my ($where, $config_files) = @_;
4750 # Look at potential Makefile.am's.
4751 foreach (split ' ', $config_files)
4753 # Must skip empty string for Perl 4.
4754 next if $_ eq "\\" || $_ eq '';
4756 # Handle $local:$input syntax.
4757 my ($local, @rest) = split (/:/);
4758 @rest = ("$local.in",) unless @rest;
4759 msg ('portability', $where,
4760 "Omit leading `./' from config file names such as `$local',"
4761 . "\nas not all make implementations treat `file' and `./file' equally.")
4762 if ($local =~ /^\.\//);
4763 my $input = locate_am @rest;
4766 # We have a file that automake should generate.
4767 $make_list{$input} = join (':', ($local, @rest));
4771 # We have a file that automake should cause to be
4772 # rebuilt, but shouldn't generate itself.
4773 push (@other_input_files, $_);
4775 $ac_config_files_location{$local} = $where;
4780 # &scan_autoconf_traces ($FILENAME)
4781 # ---------------------------------
4782 sub scan_autoconf_traces ($)
4784 my ($filename) = @_;
4786 # Macros to trace, with their minimal number of arguments.
4788 # IMPORTANT: If you add a macro here, you should also add this macro
4789 # ========= to Automake-preselection in autoconf/lib/autom4te.in.
4791 AC_CANONICAL_BUILD => 0,
4792 AC_CANONICAL_HOST => 0,
4793 AC_CANONICAL_TARGET => 0,
4794 AC_CONFIG_AUX_DIR => 1,
4795 AC_CONFIG_FILES => 1,
4796 AC_CONFIG_HEADERS => 1,
4797 AC_CONFIG_LIBOBJ_DIR => 1,
4798 AC_CONFIG_LINKS => 1,
4802 AC_REQUIRE_AUX_FILE => 1,
4803 AC_SUBST_TRACE => 1,
4804 AM_AUTOMAKE_VERSION => 1,
4805 AM_CONDITIONAL => 2,
4806 AM_ENABLE_MULTILIB => 0,
4807 AM_GNU_GETTEXT => 0,
4808 AM_GNU_GETTEXT_INTL_SUBDIR => 0,
4809 AM_INIT_AUTOMAKE => 0,
4810 AM_MAINTAINER_MODE => 0,
4811 AM_PROG_CC_C_O => 0,
4812 _AM_SUBST_NOTMAKE => 1,
4813 LT_SUPPORTED_TAG => 1,
4814 _LT_AC_TAGCONFIG => 0,
4820 my $traces = ($ENV{AUTOCONF} || 'autoconf') . " ";
4822 # Use a separator unlikely to be used, not `:', the default, which
4823 # has a precise meaning for AC_CONFIG_FILES and so on.
4824 $traces .= join (' ',
4825 map { "--trace=$_" . ':\$f:\$l::\$n::\${::}%' }
4828 my $tracefh = new Automake::XFile ("$traces $filename |");
4829 verb "reading $traces";
4831 while ($_ = $tracefh->getline)
4834 my ($here, @args) = split (/::/);
4835 my $where = new Automake::Location $here;
4836 my $macro = $args[0];
4838 prog_error ("unrequested trace `$macro'")
4839 unless exists $traced{$macro};
4841 # Skip and diagnose malformed calls.
4842 if ($#args < $traced{$macro})
4844 msg ('syntax', $where, "not enough arguments for $macro");
4848 # Alphabetical ordering please.
4849 if ($macro eq 'AC_CANONICAL_BUILD')
4851 if ($seen_canonical <= AC_CANONICAL_BUILD)
4853 $seen_canonical = AC_CANONICAL_BUILD;
4854 $canonical_location = $where;
4857 elsif ($macro eq 'AC_CANONICAL_HOST')
4859 if ($seen_canonical <= AC_CANONICAL_HOST)
4861 $seen_canonical = AC_CANONICAL_HOST;
4862 $canonical_location = $where;
4865 elsif ($macro eq 'AC_CANONICAL_TARGET')
4867 $seen_canonical = AC_CANONICAL_TARGET;
4868 $canonical_location = $where;
4870 elsif ($macro eq 'AC_CONFIG_AUX_DIR')
4872 if ($seen_init_automake)
4874 error ($where, "AC_CONFIG_AUX_DIR must be called before "
4875 . "AM_INIT_AUTOMAKE...", partial => 1);
4876 error ($seen_init_automake, "... AM_INIT_AUTOMAKE called here");
4878 $config_aux_dir = $args[1];
4879 $config_aux_dir_set_in_configure_ac = 1;
4880 $relative_dir = '.';
4881 check_directory ($config_aux_dir, $where);
4883 elsif ($macro eq 'AC_CONFIG_FILES')
4885 # Look at potential Makefile.am's.
4886 scan_autoconf_config_files ($where, $args[1]);
4888 elsif ($macro eq 'AC_CONFIG_HEADERS')
4890 foreach my $spec (split (' ', $args[1]))
4892 my ($dest, @src) = split (':', $spec);
4893 $ac_config_files_location{$dest} = $where;
4894 push @config_headers, $spec;
4897 elsif ($macro eq 'AC_CONFIG_LIBOBJ_DIR')
4899 $config_libobj_dir = $args[1];
4900 $relative_dir = '.';
4901 check_directory ($config_libobj_dir, $where);
4903 elsif ($macro eq 'AC_CONFIG_LINKS')
4905 foreach my $spec (split (' ', $args[1]))
4907 my ($dest, $src) = split (':', $spec);
4908 $ac_config_files_location{$dest} = $where;
4909 push @config_links, $spec;
4912 elsif ($macro eq 'AC_FC_SRCEXT')
4914 my $suffix = $args[1];
4915 # These flags are used as %SOURCEFLAG% in depend2.am,
4916 # where the trailing space is important.
4917 $sourceflags{'.' . $suffix} = '$(FCFLAGS_' . $suffix . ') '
4918 if ($suffix eq 'f90' || $suffix eq 'f95');
4920 elsif ($macro eq 'AC_INIT')
4922 if (defined $args[2])
4924 $package_version = $args[2];
4925 $package_version_location = $where;
4928 elsif ($macro eq 'AC_LIBSOURCE')
4930 $libsources{$args[1]} = $here;
4932 elsif ($macro eq 'AC_REQUIRE_AUX_FILE')
4934 # Only remember the first time a file is required.
4935 $required_aux_file{$args[1]} = $where
4936 unless exists $required_aux_file{$args[1]};
4938 elsif ($macro eq 'AC_SUBST_TRACE')
4940 # Just check for alphanumeric in AC_SUBST_TRACE. If you do
4941 # AC_SUBST(5), then too bad.
4942 $configure_vars{$args[1]} = $where
4943 if $args[1] =~ /^\w+$/;
4945 elsif ($macro eq 'AM_AUTOMAKE_VERSION')
4948 "version mismatch. This is Automake $VERSION,\n" .
4949 "but the definition used by this AM_INIT_AUTOMAKE\n" .
4950 "comes from Automake $args[1]. You should recreate\n" .
4951 "aclocal.m4 with aclocal and run automake again.\n",
4952 # $? = 63 is used to indicate version mismatch to missing.
4954 if $VERSION ne $args[1];
4956 $seen_automake_version = 1;
4958 elsif ($macro eq 'AM_CONDITIONAL')
4960 $configure_cond{$args[1]} = $where;
4962 elsif ($macro eq 'AM_ENABLE_MULTILIB')
4964 $seen_multilib = $where;
4966 elsif ($macro eq 'AM_GNU_GETTEXT')
4968 $seen_gettext = $where;
4969 $ac_gettext_location = $where;
4970 $seen_gettext_external = grep ($_ eq 'external', @args);
4972 elsif ($macro eq 'AM_GNU_GETTEXT_INTL_SUBDIR')
4974 $seen_gettext_intl = $where;
4976 elsif ($macro eq 'AM_INIT_AUTOMAKE')
4978 $seen_init_automake = $where;
4979 if (defined $args[2])
4981 $package_version = $args[2];
4982 $package_version_location = $where;
4984 elsif (defined $args[1])
4987 if (process_global_option_list ($where,
4988 split (' ', $args[1])));
4991 elsif ($macro eq 'AM_MAINTAINER_MODE')
4993 $seen_maint_mode = $where;
4995 elsif ($macro eq 'AM_PROG_CC_C_O')
4997 $seen_cc_c_o = $where;
4999 elsif ($macro eq '_AM_SUBST_NOTMAKE')
5001 $ignored_configure_vars{$args[1]} = $where;
5003 elsif ($macro eq 'm4_include'
5004 || $macro eq 'm4_sinclude'
5005 || $macro eq 'sinclude')
5007 # Skip missing `sinclude'd files.
5008 next if $macro ne 'm4_include' && ! -f $args[1];
5010 # Some modified versions of Autoconf don't use
5011 # frozen files. Consequently it's possible that we see all
5012 # m4_include's performed during Autoconf's startup.
5013 # Obviously we don't want to distribute Autoconf's files
5014 # so we skip absolute filenames here.
5015 push @configure_deps, '$(top_srcdir)/' . $args[1]
5016 unless $here =~ m,^(?:\w:)?[\\/],;
5017 # Keep track of the greatest timestamp.
5020 my $mtime = mtime $args[1];
5021 $configure_deps_greatest_timestamp = $mtime
5022 if $mtime > $configure_deps_greatest_timestamp;
5025 elsif ($macro eq 'LT_SUPPORTED_TAG')
5027 $libtool_tags{$args[1]} = 1;
5028 $libtool_new_api = 1;
5030 elsif ($macro eq '_LT_AC_TAGCONFIG')
5032 # _LT_AC_TAGCONFIG is an old macro present in Libtool 1.5.
5033 # We use it to detect whether tags are supported. Our
5034 # preferred interface is LT_SUPPORTED_TAG, but it was
5035 # introduced in Libtool 1.6.
5036 if (0 == keys %libtool_tags)
5038 # Hardcode the tags supported by Libtool 1.5.
5039 %libtool_tags = (CC => 1, CXX => 1, GCJ => 1, F77 => 1);
5048 # &scan_autoconf_files ()
5049 # -----------------------
5050 # Check whether we use `configure.ac' or `configure.in'.
5051 # Scan it (and possibly `aclocal.m4') for interesting things.
5052 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
5053 sub scan_autoconf_files ()
5055 # Reinitialize libsources here. This isn't really necessary,
5056 # since we currently assume there is only one configure.ac. But
5057 # that won't always be the case.
5060 # Keep track of the youngest configure dependency.
5061 $configure_deps_greatest_timestamp = mtime $configure_ac;
5062 if (-e 'aclocal.m4')
5064 my $mtime = mtime 'aclocal.m4';
5065 $configure_deps_greatest_timestamp = $mtime
5066 if $mtime > $configure_deps_greatest_timestamp;
5069 scan_autoconf_traces ($configure_ac);
5071 @configure_input_files = sort keys %make_list;
5072 # Set input and output files if not specified by user.
5075 @input_files = @configure_input_files;
5076 %output_files = %make_list;
5080 if (! $seen_init_automake)
5082 err_ac ("no proper invocation of AM_INIT_AUTOMAKE was found.\nYou "
5083 . "should verify that $configure_ac invokes AM_INIT_AUTOMAKE,"
5084 . "\nthat aclocal.m4 is present in the top-level directory,\n"
5085 . "and that aclocal.m4 was recently regenerated "
5086 . "(using aclocal).");
5090 if (! $seen_automake_version)
5092 if (-f 'aclocal.m4')
5094 error ($seen_init_automake,
5095 "your implementation of AM_INIT_AUTOMAKE comes from " .
5096 "an\nold Automake version. You should recreate " .
5097 "aclocal.m4\nwith aclocal and run automake again.\n",
5098 # $? = 63 is used to indicate version mismatch to missing.
5103 error ($seen_init_automake,
5104 "no proper implementation of AM_INIT_AUTOMAKE was " .
5105 "found,\nprobably because aclocal.m4 is missing...\n" .
5106 "You should run aclocal to create this file, then\n" .
5107 "run automake again.\n");
5114 # Reorder @input_files so that the Makefile that distributes aux
5115 # files is processed last. This is important because each directory
5116 # can require auxiliary scripts and we should wait until they have
5117 # been installed before distributing them.
5119 # The Makefile.in that distribute the aux files is the one in
5120 # $config_aux_dir or the top-level Makefile.
5121 my $auxdirdist = is_make_dir ($config_aux_dir) ? $config_aux_dir : '.';
5122 my @new_input_files = ();
5123 while (@input_files)
5125 my $in = pop @input_files;
5126 my @ins = split (/:/, $output_files{$in});
5127 if (dirname ($ins[0]) eq $auxdirdist)
5129 push @new_input_files, $in;
5130 $automake_will_process_aux_dir = 1;
5134 unshift @new_input_files, $in;
5137 @input_files = @new_input_files;
5139 # If neither the auxdir/Makefile nor the ./Makefile are generated
5140 # by Automake, we won't distribute the aux files anyway. Assume
5141 # the user know what (s)he does, and pretend we will distribute
5142 # them to disable the error in require_file_internal.
5143 $automake_will_process_aux_dir = 1 if ! is_make_dir ($auxdirdist);
5145 # Look for some files we need. Always check for these. This
5146 # check must be done for every run, even those where we are only
5147 # looking at a subdir Makefile. We must set relative_dir for
5148 # maybe_push_required_file to work.
5149 # Sort the files for stable verbose output.
5150 $relative_dir = '.';
5151 foreach my $file (sort keys %required_aux_file)
5153 require_conf_file ($required_aux_file{$file}->get, FOREIGN, $file)
5155 err_am "`install.sh' is an anachronism; use `install-sh' instead"
5156 if -f $config_aux_dir . '/install.sh';
5158 # Preserve dist_common for later.
5159 $configure_dist_common = variable_value ('DIST_COMMON') || '';
5163 ################################################################
5165 # Set up for Cygnus mode.
5168 my $cygnus = option 'cygnus';
5169 return unless $cygnus;
5171 set_strictness ('foreign');
5172 set_option ('no-installinfo', $cygnus);
5173 set_option ('no-dependencies', $cygnus);
5174 set_option ('no-dist', $cygnus);
5176 err_ac "`AM_MAINTAINER_MODE' required when --cygnus specified"
5177 if !$seen_maint_mode;
5180 # Do any extra checking for GNU standards.
5181 sub check_gnu_standards
5183 if ($relative_dir eq '.')
5185 # In top level (or only) directory.
5186 require_file ("$am_file.am", GNU,
5187 qw/INSTALL NEWS README AUTHORS ChangeLog/);
5189 # Accept one of these three licenses; default to COPYING.
5190 # Make sure we do not overwrite an existing license.
5192 foreach (qw /COPYING COPYING.LIB COPYING.LESSER/)
5200 require_file ("$am_file.am", GNU, 'COPYING')
5204 for my $opt ('no-installman', 'no-installinfo')
5206 msg ('error-gnu', option $opt,
5207 "option `$opt' disallowed by GNU standards")
5212 # Do any extra checking for GNITS standards.
5213 sub check_gnits_standards
5215 if ($relative_dir eq '.')
5217 # In top level (or only) directory.
5218 require_file ("$am_file.am", GNITS, 'THANKS');
5222 ################################################################
5224 # Functions to handle files of each language.
5226 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
5227 # simple formula: Return value is LANG_SUBDIR if the resulting object
5228 # file should be in a subdir if the source file is, LANG_PROCESS if
5229 # file is to be dealt with, LANG_IGNORE otherwise.
5231 # Much of the actual processing is handled in
5232 # handle_single_transform. These functions exist so that
5233 # auxiliary information can be recorded for a later cleanup pass.
5234 # Note that the calls to these functions are computed, so don't bother
5235 # searching for their precise names in the source.
5237 # This is just a convenience function that can be used to determine
5238 # when a subdir object should be used.
5241 return option 'subdir-objects' ? LANG_SUBDIR : LANG_PROCESS;
5244 # Rewrite a single C source file.
5247 my ($directory, $base, $ext, $nonansi_obj, $have_per_exec_flags, $var) = @_;
5249 if (option 'ansi2knr' && $base =~ /_$/)
5251 # FIXME: include line number in error.
5252 err_am "C source file `$base.c' would be deleted by ansi2knr rules";
5255 my $r = LANG_PROCESS;
5256 if (option 'subdir-objects')
5259 if ($directory && $directory ne '.')
5261 $base = $directory . '/' . $base;
5263 # libtool is always able to put the object at the proper place,
5264 # so we do not have to require AM_PROG_CC_C_O when building .lo files.
5265 msg_var ('portability', $var,
5266 "compiling `$base.c' in subdir requires "
5267 . "`AM_PROG_CC_C_O' in `$configure_ac'",
5268 uniq_scope => US_GLOBAL,
5269 uniq_part => 'AM_PROG_CC_C_O subdir')
5270 unless $seen_cc_c_o || $nonansi_obj eq '.lo';
5273 # In this case we already have the directory information, so
5274 # don't add it again.
5275 $de_ansi_files{$base} = '';
5279 $de_ansi_files{$base} = (($directory eq '.' || $directory eq '')
5285 && $have_per_exec_flags
5286 && ! option 'subdir-objects'
5287 && $nonansi_obj ne '.lo')
5289 msg_var ('portability',
5290 $var, "compiling `$base.c' with per-target flags requires "
5291 . "`AM_PROG_CC_C_O' in `$configure_ac'",
5292 uniq_scope => US_GLOBAL,
5293 uniq_part => 'AM_PROG_CC_C_O per-target')
5299 # Rewrite a single C++ source file.
5300 sub lang_cxx_rewrite
5302 return &lang_sub_obj;
5305 # Rewrite a single header file.
5306 sub lang_header_rewrite
5308 # Header files are simply ignored.
5312 # Rewrite a single yacc file.
5313 sub lang_yacc_rewrite
5315 my ($directory, $base, $ext) = @_;
5317 my $r = &lang_sub_obj;
5318 (my $newext = $ext) =~ tr/y/c/;
5319 return ($r, $newext);
5322 # Rewrite a single yacc++ file.
5323 sub lang_yaccxx_rewrite
5325 my ($directory, $base, $ext) = @_;
5327 my $r = &lang_sub_obj;
5328 (my $newext = $ext) =~ tr/y/c/;
5329 return ($r, $newext);
5332 # Rewrite a single lex file.
5333 sub lang_lex_rewrite
5335 my ($directory, $base, $ext) = @_;
5337 my $r = &lang_sub_obj;
5338 (my $newext = $ext) =~ tr/l/c/;
5339 return ($r, $newext);
5342 # Rewrite a single lex++ file.
5343 sub lang_lexxx_rewrite
5345 my ($directory, $base, $ext) = @_;
5347 my $r = &lang_sub_obj;
5348 (my $newext = $ext) =~ tr/l/c/;
5349 return ($r, $newext);
5352 # Rewrite a single assembly file.
5353 sub lang_asm_rewrite
5355 return &lang_sub_obj;
5358 # Rewrite a single preprocessed assembly file.
5359 sub lang_cppasm_rewrite
5361 return &lang_sub_obj;
5364 # Rewrite a single Fortran 77 file.
5365 sub lang_f77_rewrite
5367 return &lang_sub_obj;
5370 # Rewrite a single Fortran file.
5373 return &lang_sub_obj;
5376 # Rewrite a single preprocessed Fortran file.
5377 sub lang_ppfc_rewrite
5379 return &lang_sub_obj;
5382 # Rewrite a single preprocessed Fortran 77 file.
5383 sub lang_ppf77_rewrite
5385 return &lang_sub_obj;
5388 # Rewrite a single ratfor file.
5389 sub lang_ratfor_rewrite
5391 return &lang_sub_obj;
5394 # Rewrite a single Objective C file.
5395 sub lang_objc_rewrite
5397 return &lang_sub_obj;
5400 # Rewrite a single Unified Parallel C file.
5401 sub lang_upc_rewrite
5403 return &lang_sub_obj;
5406 # Rewrite a single Java file.
5407 sub lang_java_rewrite
5412 # The lang_X_finish functions are called after all source file
5413 # processing is done. Each should handle defining rules for the
5414 # language, etc. A finish function is only called if a source file of
5415 # the appropriate type has been seen.
5419 # Push all libobjs files onto de_ansi_files. We actually only
5420 # push files which exist in the current directory, and which are
5421 # genuine source files.
5422 foreach my $file (keys %libsources)
5424 if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
5426 $de_ansi_files{$1} = ''
5430 if (option 'ansi2knr' && keys %de_ansi_files)
5432 # Make all _.c files depend on their corresponding .c files.
5434 foreach my $base (sort keys %de_ansi_files)
5436 # Each _.c file must depend on ansi2knr; otherwise it
5437 # might be used in a parallel build before it is built.
5438 # We need to support files in the srcdir and in the build
5439 # dir (because these files might be auto-generated. But
5440 # we can't use $< -- some makes only define $< during a
5442 my $ansfile = $de_ansi_files{$base} . $base . '.c';
5443 $output_rules .= ($base . "_.c: $ansfile \$(ANSI2KNR)\n\t"
5444 . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5445 . '`if test -f $(srcdir)/' . $ansfile
5446 . '; then echo $(srcdir)/' . $ansfile
5447 . '; else echo ' . $ansfile . '; fi` '
5448 . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5449 . '| $(ANSI2KNR) > $@'
5450 # If ansi2knr fails then we shouldn't
5451 # create the _.c file
5452 . " || rm -f \$\@\n");
5453 push (@objects, $base . '_.$(OBJEXT)');
5454 push (@objects, $base . '_.lo')
5457 # Explicitly clean the _.c files if they are in a
5458 # subdirectory. (In the current directory they get erased
5459 # by a `rm -f *_.c' rule.)
5460 $clean_files{$base . '_.c'} = MOSTLY_CLEAN
5461 if dirname ($base) ne '.';
5464 # Make all _.o (and _.lo) files depend on ansi2knr.
5465 # Use a sneaky little hack to make it print nicely.
5466 &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5470 # This is a yacc helper which is called whenever we have decided to
5471 # compile a yacc file.
5472 sub lang_yacc_target_hook
5474 my ($self, $aggregate, $output, $input, %transform) = @_;
5476 my $flag = $aggregate . "_YFLAGS";
5477 my $flagvar = var $flag;
5478 my $YFLAGSvar = var 'YFLAGS';
5479 if (($flagvar && $flagvar->variable_value =~ /$DASH_D_PATTERN/o)
5480 || ($YFLAGSvar && $YFLAGSvar->variable_value =~ /$DASH_D_PATTERN/o))
5482 (my $output_base = $output) =~ s/$KNOWN_EXTENSIONS_PATTERN$//;
5483 my $header = $output_base . '.h';
5485 # Found a `-d' that applies to the compilation of this file.
5486 # Add a dependency for the generated header file, and arrange
5487 # for that file to be included in the distribution.
5488 foreach my $cond (Automake::Rule::define (${header}, 'internal',
5489 RULE_AUTOMAKE, TRUE,
5492 my $condstr = $cond->subst_string;
5494 "$condstr${header}: $output\n"
5495 # Recover from removal of $header
5496 . "$condstr\t\@if test ! -f \$@; then \\\n"
5497 . "$condstr\t rm -f $output; \\\n"
5498 . "$condstr\t \$(MAKE) \$(AM_MAKEFLAGS) $output; \\\n"
5499 . "$condstr\telse :; fi\n";
5501 # Distribute the generated file, unless its .y source was
5502 # listed in a nodist_ variable. (&handle_source_transform
5503 # will set DIST_SOURCE.)
5504 &push_dist_common ($header)
5505 if $transform{'DIST_SOURCE'};
5507 # If the files are built in the build directory, then we want
5508 # to remove them with `make clean'. If they are in srcdir
5509 # they shouldn't be touched. However, we can't determine this
5510 # statically, and the GNU rules say that yacc/lex output files
5511 # should be removed by maintainer-clean. So that's what we
5513 $clean_files{$header} = MAINTAINER_CLEAN;
5515 # Erase $OUTPUT on `make maintainer-clean' (by GNU standards).
5516 # See the comment above for $HEADER.
5517 $clean_files{$output} = MAINTAINER_CLEAN;
5520 # This is a lex helper which is called whenever we have decided to
5521 # compile a lex file.
5522 sub lang_lex_target_hook
5524 my ($self, $aggregate, $output, $input) = @_;
5525 # If the files are built in the build directory, then we want to
5526 # remove them with `make clean'. If they are in srcdir they
5527 # shouldn't be touched. However, we can't determine this
5528 # statically, and the GNU rules say that yacc/lex output files
5529 # should be removed by maintainer-clean. So that's what we do.
5530 $clean_files{$output} = MAINTAINER_CLEAN;
5533 # This is a helper for both lex and yacc.
5534 sub yacc_lex_finish_helper
5536 return if defined $language_scratch{'lex-yacc-done'};
5537 $language_scratch{'lex-yacc-done'} = 1;
5539 # FIXME: for now, no line number.
5540 require_conf_file ($configure_ac, FOREIGN, 'ylwrap');
5541 &define_variable ('YLWRAP', "$am_config_aux_dir/ylwrap", INTERNAL);
5544 sub lang_yacc_finish
5546 return if defined $language_scratch{'yacc-done'};
5547 $language_scratch{'yacc-done'} = 1;
5549 reject_var 'YACCFLAGS', "`YACCFLAGS' obsolete; use `YFLAGS' instead";
5551 yacc_lex_finish_helper;
5557 return if defined $language_scratch{'lex-done'};
5558 $language_scratch{'lex-done'} = 1;
5560 yacc_lex_finish_helper;
5564 # Given a hash table of linker names, pick the name that has the most
5565 # precedence. This is lame, but something has to have global
5566 # knowledge in order to eliminate the conflict. Add more linkers as
5572 foreach my $l (qw(GCJLINK CXXLINK F77LINK FCLINK OBJCLINK UPCLINK))
5574 return $l if defined $linkers{$l};
5579 # Called to indicate that an extension was used.
5583 if (! defined $extension_seen{$ext})
5585 $extension_seen{$ext} = 1;
5589 ++$extension_seen{$ext};
5593 # Return the number of files seen for a given language. Knows about
5594 # special cases we care about. FIXME: this is hideous. We need
5595 # something that involves real language objects. For instance yacc
5596 # and yaccxx could both derive from a common yacc class which would
5597 # know about the strange ylwrap requirement. (Or better yet we could
5598 # just not support legacy yacc!)
5599 sub count_files_for_language
5604 if ($name eq 'yacc' || $name eq 'yaccxx')
5606 @names = ('yacc', 'yaccxx');
5608 elsif ($name eq 'lex' || $name eq 'lexxx')
5610 @names = ('lex', 'lexxx');
5618 foreach $name (@names)
5620 my $lang = $languages{$name};
5621 foreach my $ext (@{$lang->extensions})
5623 $r += $extension_seen{$ext}
5624 if defined $extension_seen{$ext};
5631 # Called to ask whether source files have been seen . If HEADERS is 1,
5632 # headers can be included.
5637 # count all the sources
5639 foreach my $val (values %extension_seen)
5646 $count -= count_files_for_language ('header');
5653 # register_language (%ATTRIBUTE)
5654 # ------------------------------
5655 # Register a single language.
5656 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5657 sub register_language (%)
5663 unless defined $option{'ansi'};
5664 $option{'autodep'} = 'no'
5665 unless defined $option{'autodep'};
5666 $option{'linker'} = ''
5667 unless defined $option{'linker'};
5668 $option{'flags'} = []
5669 unless defined $option{'flags'};
5670 $option{'output_extensions'} = sub { return ( '.$(OBJEXT)', '.lo' ) }
5671 unless defined $option{'output_extensions'};
5672 $option{'nodist_specific'} = 0
5673 unless defined $option{'nodist_specific'};
5675 my $lang = new Language (%option);
5678 $extension_map{$_} = $lang->name foreach @{$lang->extensions};
5679 $languages{$lang->name} = $lang;
5680 my $link = $lang->linker;
5683 if (exists $link_languages{$link})
5685 prog_error ("`$link' has different definitions in "
5686 . $lang->name . " and " . $link_languages{$link}->name)
5687 if $lang->link ne $link_languages{$link}->link;
5691 $link_languages{$link} = $lang;
5695 # Update the pattern of known extensions.
5696 accept_extensions (@{$lang->extensions});
5698 # Upate the $suffix_rule map.
5699 foreach my $suffix (@{$lang->extensions})
5701 foreach my $dest (&{$lang->output_extensions} ($suffix))
5703 register_suffix_rule (INTERNAL, $suffix, $dest);
5708 # derive_suffix ($EXT, $OBJ)
5709 # --------------------------
5710 # This function is used to find a path from a user-specified suffix $EXT
5711 # to $OBJ or to some other suffix we recognize internally, e.g. `cc'.
5712 sub derive_suffix ($$)
5714 my ($source_ext, $obj) = @_;
5716 while (! $extension_map{$source_ext}
5717 && $source_ext ne $obj
5718 && exists $suffix_rules->{$source_ext}
5719 && exists $suffix_rules->{$source_ext}{$obj})
5721 $source_ext = $suffix_rules->{$source_ext}{$obj}[0];
5728 ################################################################
5730 # Pretty-print something and append to output_rules.
5731 sub pretty_print_rule
5733 $output_rules .= &makefile_wrap (@_);
5737 ################################################################
5740 ## -------------------------------- ##
5741 ## Handling the conditional stack. ##
5742 ## -------------------------------- ##
5746 # make_conditional_string ($NEGATE, $COND)
5747 # ----------------------------------------
5748 sub make_conditional_string ($$)
5750 my ($negate, $cond) = @_;
5751 $cond = "${cond}_TRUE"
5752 unless $cond =~ /^TRUE|FALSE$/;
5753 $cond = Automake::Condition::conditional_negate ($cond)
5759 my %_am_macro_for_cond =
5761 AMDEP => "one of the compiler tests\n"
5762 . " AC_PROG_CC, AC_PROG_CXX, AC_PROG_CXX, AC_PROG_OBJC,\n"
5763 . " AM_PROG_AS, AM_PROG_GCJ, AM_PROG_UPC",
5764 am__fastdepCC => 'AC_PROG_CC',
5765 am__fastdepCCAS => 'AM_PROG_AS',
5766 am__fastdepCXX => 'AC_PROG_CXX',
5767 am__fastdepGCJ => 'AM_PROG_GCJ',
5768 am__fastdepOBJC => 'AC_PROG_OBJC',
5769 am__fastdepUPC => 'AM_PROG_UPC'
5773 # cond_stack_if ($NEGATE, $COND, $WHERE)
5774 # --------------------------------------
5775 sub cond_stack_if ($$$)
5777 my ($negate, $cond, $where) = @_;
5779 if (! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/)
5781 my $text = "$cond does not appear in AM_CONDITIONAL";
5782 my $scope = US_LOCAL;
5783 if (exists $_am_macro_for_cond{$cond})
5785 my $mac = $_am_macro_for_cond{$cond};
5786 $text .= "\n The usual way to define `$cond' is to add ";
5787 $text .= ($mac =~ / /) ? $mac : "`$mac'";
5788 $text .= "\n to `$configure_ac' and run `aclocal' and `autoconf' again.";
5789 # These warnings appear in Automake files (depend2.am),
5790 # so there is no need to display them more than once:
5793 error $where, $text, uniq_scope => $scope;
5796 push (@cond_stack, make_conditional_string ($negate, $cond));
5798 return new Automake::Condition (@cond_stack);
5803 # cond_stack_else ($NEGATE, $COND, $WHERE)
5804 # ----------------------------------------
5805 sub cond_stack_else ($$$)
5807 my ($negate, $cond, $where) = @_;
5811 error $where, "else without if";
5815 $cond_stack[$#cond_stack] =
5816 Automake::Condition::conditional_negate ($cond_stack[$#cond_stack]);
5818 # If $COND is given, check against it.
5821 $cond = make_conditional_string ($negate, $cond);
5823 error ($where, "else reminder ($negate$cond) incompatible with "
5824 . "current conditional: $cond_stack[$#cond_stack]")
5825 if $cond_stack[$#cond_stack] ne $cond;
5828 return new Automake::Condition (@cond_stack);
5833 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5834 # -----------------------------------------
5835 sub cond_stack_endif ($$$)
5837 my ($negate, $cond, $where) = @_;
5842 error $where, "endif without if";
5846 # If $COND is given, check against it.
5849 $cond = make_conditional_string ($negate, $cond);
5851 error ($where, "endif reminder ($negate$cond) incompatible with "
5852 . "current conditional: $cond_stack[$#cond_stack]")
5853 if $cond_stack[$#cond_stack] ne $cond;
5858 return new Automake::Condition (@cond_stack);
5865 ## ------------------------ ##
5866 ## Handling the variables. ##
5867 ## ------------------------ ##
5870 # &define_pretty_variable ($VAR, $COND, $WHERE, @VALUE)
5871 # -----------------------------------------------------
5872 # Like define_variable, but the value is a list, and the variable may
5873 # be defined conditionally. The second argument is the Condition
5874 # under which the value should be defined; this should be the empty
5875 # string to define the variable unconditionally. The third argument
5876 # is a list holding the values to use for the variable. The value is
5877 # pretty printed in the output file.
5878 sub define_pretty_variable ($$$@)
5880 my ($var, $cond, $where, @value) = @_;
5882 if (! vardef ($var, $cond))
5884 Automake::Variable::define ($var, VAR_AUTOMAKE, '', $cond, "@value",
5885 '', $where, VAR_PRETTY);
5886 rvar ($var)->rdef ($cond)->set_seen;
5891 # define_variable ($VAR, $VALUE, $WHERE)
5892 # --------------------------------------
5893 # Define a new Automake Makefile variable VAR to VALUE, but only if
5894 # not already defined.
5895 sub define_variable ($$$)
5897 my ($var, $value, $where) = @_;
5898 define_pretty_variable ($var, TRUE, $where, $value);
5902 # define_files_variable ($VAR, \@BASENAME, $EXTENSION, $WHERE)
5903 # -----------------------------------------------------------
5904 # Define the $VAR which content is the list of file names composed of
5905 # a @BASENAME and the $EXTENSION.
5906 sub define_files_variable ($\@$$)
5908 my ($var, $basename, $extension, $where) = @_;
5909 define_variable ($var,
5910 join (' ', map { "$_.$extension" } @$basename),
5915 # Like define_variable, but define a variable to be the configure
5916 # substitution by the same name.
5917 sub define_configure_variable ($)
5921 my $pretty = VAR_ASIS;
5922 my $owner = VAR_CONFIGURE;
5924 # Some variables we do not want to output. For instance it
5925 # would be a bad idea to output `U = @U@` when `@U@` can be
5926 # substituted as `\`.
5927 $pretty = VAR_SILENT if exists $ignored_configure_vars{$var};
5929 # ANSI2KNR is a variable that Automake wants to redefine, so
5930 # it must be owned by Automake. (It is also used as a proof
5931 # that AM_C_PROTOTYPES has been run, that's why we do not simply
5932 # omit the AC_SUBST.)
5933 $owner = VAR_AUTOMAKE if $var eq 'ANSI2KNR';
5935 Automake::Variable::define ($var, $owner, '', TRUE, subst $var,
5936 '', $configure_vars{$var}, $pretty);
5940 # define_compiler_variable ($LANG)
5941 # --------------------------------
5942 # Define a compiler variable. We also handle defining the `LT'
5943 # version of the command when using libtool.
5944 sub define_compiler_variable ($)
5948 my ($var, $value) = ($lang->compiler, $lang->compile);
5949 my $libtool_tag = '';
5950 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
5951 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
5952 &define_variable ($var, $value, INTERNAL);
5953 &define_variable ("LT$var",
5954 "\$(LIBTOOL) $libtool_tag\$(AM_LIBTOOLFLAGS) "
5955 . "\$(LIBTOOLFLAGS) --mode=compile $value",
5961 # define_linker_variable ($LANG)
5962 # ------------------------------
5963 # Define linker variables.
5964 sub define_linker_variable ($)
5968 my $libtool_tag = '';
5969 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
5970 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
5972 &define_variable ($lang->lder, $lang->ld, INTERNAL);
5973 # CCLINK = $(CCLD) blah blah...
5974 &define_variable ($lang->linker,
5976 "\$(LIBTOOL) $libtool_tag\$(AM_LIBTOOLFLAGS) "
5977 . "\$(LIBTOOLFLAGS) --mode=link " : '')
5982 sub define_per_target_linker_variable ($$)
5984 my ($linker, $target) = @_;
5986 # If the user wrote a custom link command, we don't define ours.
5987 return "${target}_LINK"
5988 if set_seen "${target}_LINK";
5990 my $xlink = $linker ? $linker : 'LINK';
5992 my $lang = $link_languages{$xlink};
5993 prog_error "Unknown language for linker variable `$xlink'"
5996 my $link_command = $lang->link;
5999 my $libtool_tag = '';
6000 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
6001 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
6004 "\$(LIBTOOL) $libtool_tag\$(AM_LIBTOOLFLAGS) \$(LIBTOOLFLAGS) "
6005 . "--mode=link " . $link_command;
6008 # Rewrite each occurrence of `AM_$flag' in the link
6009 # command into `${derived}_$flag' if it exists.
6010 my $orig_command = $link_command;
6011 my @flags = (@{$lang->flags}, 'LDFLAGS');
6012 push @flags, 'LIBTOOLFLAGS' if var 'LIBTOOL';
6013 for my $flag (@flags)
6015 my $val = "${target}_$flag";
6016 $link_command =~ s/\(AM_$flag\)/\($val\)/
6020 # If the computed command is the same as the generic command, use
6021 # the command linker variable.
6022 return $lang->linker
6023 if $link_command eq $orig_command;
6025 &define_variable ("${target}_LINK", $link_command, INTERNAL);
6026 return "${target}_LINK";
6029 ################################################################
6031 # &check_trailing_slash ($WHERE, $LINE)
6032 # --------------------------------------
6033 # Return 1 iff $LINE ends with a slash.
6034 # Might modify $LINE.
6035 sub check_trailing_slash ($\$)
6037 my ($where, $line) = @_;
6039 # Ignore `##' lines.
6040 return 0 if $$line =~ /$IGNORE_PATTERN/o;
6042 # Catch and fix a common error.
6043 msg "syntax", $where, "whitespace following trailing backslash"
6044 if $$line =~ s/\\\s+\n$/\\\n/;
6046 return $$line =~ /\\$/;
6050 # &read_am_file ($AMFILE, $WHERE)
6051 # -------------------------------
6052 # Read Makefile.am and set up %contents. Simultaneously copy lines
6053 # from Makefile.am into $output_trailer, or define variables as
6054 # appropriate. NOTE we put rules in the trailer section. We want
6055 # user rules to come after our generated stuff.
6056 sub read_am_file ($$)
6058 my ($amfile, $where) = @_;
6060 my $am_file = new Automake::XFile ("< $amfile");
6061 verb "reading $amfile";
6063 # Keep track of the youngest output dependency.
6064 my $mtime = mtime $amfile;
6065 $output_deps_greatest_timestamp = $mtime
6066 if $mtime > $output_deps_greatest_timestamp;
6072 my $var_look = VAR_ASIS;
6074 use constant IN_VAR_DEF => 0;
6075 use constant IN_RULE_DEF => 1;
6076 use constant IN_COMMENT => 2;
6077 my $prev_state = IN_RULE_DEF;
6079 while ($_ = $am_file->getline)
6081 $where->set ("$amfile:$.");
6082 if (/$IGNORE_PATTERN/o)
6084 # Merely delete comments beginning with two hashes.
6086 elsif (/$WHITE_PATTERN/o)
6088 error $where, "blank line following trailing backslash"
6090 # Stick a single white line before the incoming macro or rule.
6093 # Flush all comments seen so far.
6096 $output_vars .= $comment;
6100 elsif (/$COMMENT_PATTERN/o)
6102 # Stick comments before the incoming macro or rule. Make
6103 # sure a blank line precedes the first block of comments.
6104 $spacing = "\n" unless $blank;
6106 $comment .= $spacing . $_;
6108 $prev_state = IN_COMMENT;
6114 $saw_bk = check_trailing_slash ($where, $_);
6117 # We save the conditional stack on entry, and then check to make
6118 # sure it is the same on exit. This lets us conditionally include
6120 my @saved_cond_stack = @cond_stack;
6121 my $cond = new Automake::Condition (@cond_stack);
6123 my $last_var_name = '';
6124 my $last_var_type = '';
6125 my $last_var_value = '';
6127 # FIXME: shouldn't use $_ in this loop; it is too big.
6130 $where->set ("$amfile:$.");
6132 # Make sure the line is \n-terminated.
6136 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
6137 # used by users. @MAINT@ is an anachronism now.
6138 $_ =~ s/\@MAINT\@//g
6139 unless $seen_maint_mode;
6141 my $new_saw_bk = check_trailing_slash ($where, $_);
6143 if (/$IGNORE_PATTERN/o)
6145 # Merely delete comments beginning with two hashes.
6147 # Keep any backslash from the previous line.
6148 $new_saw_bk = $saw_bk;
6150 elsif (/$WHITE_PATTERN/o)
6152 # Stick a single white line before the incoming macro or rule.
6154 error $where, "blank line following trailing backslash"
6157 elsif (/$COMMENT_PATTERN/o)
6159 error $where, "comment following trailing backslash"
6160 if $saw_bk && $comment eq '';
6162 # Stick comments before the incoming macro or rule.
6163 $comment .= $spacing . $_;
6165 $prev_state = IN_COMMENT;
6169 if ($prev_state == IN_RULE_DEF)
6171 my $cond = new Automake::Condition @cond_stack;
6172 $output_trailer .= $cond->subst_string;
6173 $output_trailer .= $_;
6175 elsif ($prev_state == IN_COMMENT)
6177 # If the line doesn't start with a `#', add it.
6178 # We do this because a continued comment like
6182 # is not portable. BSD make doesn't honor
6183 # escaped newlines in comments.
6185 $comment .= $spacing . $_;
6187 else # $prev_state == IN_VAR_DEF
6189 $last_var_value .= ' '
6190 unless $last_var_value =~ /\s$/;
6191 $last_var_value .= $_;
6195 Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
6196 $last_var_type, $cond,
6197 $last_var_value, $comment,
6198 $last_where, VAR_ASIS)
6200 $comment = $spacing = '';
6205 elsif (/$IF_PATTERN/o)
6207 $cond = cond_stack_if ($1, $2, $where);
6209 elsif (/$ELSE_PATTERN/o)
6211 $cond = cond_stack_else ($1, $2, $where);
6213 elsif (/$ENDIF_PATTERN/o)
6215 $cond = cond_stack_endif ($1, $2, $where);
6218 elsif (/$RULE_PATTERN/o)
6221 $prev_state = IN_RULE_DEF;
6223 # For now we have to output all definitions of user rules
6224 # and can't diagnose duplicates (see the comment in
6225 # Automake::Rule::define). So we go on and ignore the return value.
6226 Automake::Rule::define ($1, $amfile, RULE_USER, $cond, $where);
6228 check_variable_expansions ($_, $where);
6230 $output_trailer .= $comment . $spacing;
6231 my $cond = new Automake::Condition @cond_stack;
6232 $output_trailer .= $cond->subst_string;
6233 $output_trailer .= $_;
6234 $comment = $spacing = '';
6236 elsif (/$ASSIGNMENT_PATTERN/o)
6238 # Found a macro definition.
6239 $prev_state = IN_VAR_DEF;
6240 $last_var_name = $1;
6241 $last_var_type = $2;
6242 $last_var_value = $3;
6243 $last_where = $where->clone;
6244 if ($3 ne '' && substr ($3, -1) eq "\\")
6246 # We preserve the `\' because otherwise the long lines
6247 # that are generated will be truncated by broken
6249 $last_var_value = $3 . "\n";
6251 # Normally we try to output variable definitions in the
6252 # same format they were input. However, POSIX compliant
6253 # systems are not required to support lines longer than
6254 # 2048 bytes (most notably, some sed implementation are
6255 # limited to 4000 bytes, and sed is used by config.status
6256 # to rewrite Makefile.in into Makefile). Moreover nobody
6257 # would really write such long lines by hand since it is
6258 # hardly maintainable. So if a line is longer that 1000
6259 # bytes (an arbitrary limit), assume it has been
6260 # automatically generated by some tools, and flatten the
6261 # variable definition. Otherwise, keep the variable as it
6263 $var_look = VAR_PRETTY if length ($last_var_value) >= 1000;
6267 Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
6268 $last_var_type, $cond,
6269 $last_var_value, $comment,
6270 $last_where, $var_look)
6272 $comment = $spacing = '';
6273 $var_look = VAR_ASIS;
6276 elsif (/$INCLUDE_PATTERN/o)
6280 if ($path =~ s/^\$\(top_srcdir\)\///)
6282 push (@include_stack, "\$\(top_srcdir\)/$path");
6283 # Distribute any included file.
6285 # Always use the $(top_srcdir) prefix in DIST_COMMON,
6286 # otherwise OSF make will implicitly copy the included
6287 # file in the build tree during `make distdir' to satisfy
6289 # (subdircond2.test and subdircond3.test will fail.)
6290 push_dist_common ("\$\(top_srcdir\)/$path");
6294 $path =~ s/\$\(srcdir\)\///;
6295 push (@include_stack, "\$\(srcdir\)/$path");
6296 # Always use the $(srcdir) prefix in DIST_COMMON,
6297 # otherwise OSF make will implicitly copy the included
6298 # file in the build tree during `make distdir' to satisfy
6300 # (subdircond2.test and subdircond3.test will fail.)
6301 push_dist_common ("\$\(srcdir\)/$path");
6302 $path = $relative_dir . "/" . $path if $relative_dir ne '.';
6304 $where->push_context ("`$path' included from here");
6305 &read_am_file ($path, $where);
6306 $where->pop_context;
6310 # This isn't an error; it is probably a continued rule.
6311 # In fact, this is what we assume.
6312 $prev_state = IN_RULE_DEF;
6313 check_variable_expansions ($_, $where);
6314 $output_trailer .= $comment . $spacing;
6315 my $cond = new Automake::Condition @cond_stack;
6316 $output_trailer .= $cond->subst_string;
6317 $output_trailer .= $_;
6318 $comment = $spacing = '';
6319 error $where, "`#' comment at start of rule is unportable"
6320 if $_ =~ /^\t\s*\#/;
6323 $saw_bk = $new_saw_bk;
6324 $_ = $am_file->getline;
6327 $output_trailer .= $comment;
6329 error ($where, "trailing backslash on last line")
6332 error ($where, (@cond_stack ? "unterminated conditionals: @cond_stack"
6333 : "too many conditionals closed in include file"))
6334 if "@saved_cond_stack" ne "@cond_stack";
6338 # define_standard_variables ()
6339 # ----------------------------
6340 # A helper for read_main_am_file which initializes configure variables
6341 # and variables from header-vars.am.
6342 sub define_standard_variables
6344 my $saved_output_vars = $output_vars;
6345 my ($comments, undef, $rules) =
6346 file_contents_internal (1, "$libdir/am/header-vars.am",
6347 new Automake::Location);
6349 foreach my $var (sort keys %configure_vars)
6351 &define_configure_variable ($var);
6354 $output_vars .= $comments . $rules;
6357 # Read main am file.
6358 sub read_main_am_file
6362 # This supports the strange variable tricks we are about to play.
6363 prog_error (macros_dump () . "variable defined before read_main_am_file")
6364 if (scalar (variables) > 0);
6366 # Generate copyright header for generated Makefile.in.
6367 # We do discard the output of predefined variables, handled below.
6368 $output_vars = ("# $in_file_name generated by automake "
6369 . $VERSION . " from $am_file_name.\n");
6370 $output_vars .= '# ' . subst ('configure_input') . "\n";
6371 $output_vars .= $gen_copyright;
6373 # We want to predefine as many variables as possible. This lets
6374 # the user set them with `+=' in Makefile.am.
6375 &define_standard_variables;
6377 # Read user file, which might override some of our values.
6378 &read_am_file ($amfile, new Automake::Location);
6383 ################################################################
6386 # &flatten ($STRING)
6387 # ------------------
6388 # Flatten the $STRING and return the result.
6402 # transform_token ($TOKEN, \%PAIRS, $KEY)
6403 # =======================================
6404 # Return the value associated to $KEY in %PAIRS, as used on $TOKEN
6405 # (which should be ?KEY? or any of the special %% requests)..
6406 sub transform_token ($$$)
6408 my ($token, $transform, $key) = @_;
6409 my $res = $transform->{$key};
6410 prog_error "Unknown key `$key' in `$token'" unless defined $res;
6415 # transform ($TOKEN, \%PAIRS)
6416 # ===========================
6417 # If ($TOKEN, $VAL) is in %PAIRS:
6418 # - replaces %KEY% with $VAL,
6419 # - enables/disables ?KEY? and ?!KEY?,
6420 # - replaces %?KEY% with TRUE or FALSE.
6421 # - replaces %KEY?IFTRUE%, %KEY:IFFALSE%, and %KEY?IFTRUE:IFFALSE% with
6422 # IFTRUE / IFFALSE, as appropriate.
6425 my ($token, $transform) = @_;
6428 # Must be before the following pattern to exclude the case
6429 # when there is neither IFTRUE nor IFFALSE.
6430 if ($token =~ /^%([\w\-]+)%$/)
6432 return transform_token ($token, $transform, $1);
6434 # %KEY?IFTRUE%, %KEY:IFFALSE%, and %KEY?IFTRUE:IFFALSE%.
6435 elsif ($token =~ /^%([\w\-]+)(?:\?([^?:%]+))?(?::([^?:%]+))?%$/)
6437 return transform_token ($token, $transform, $1) ? ($2 || '') : ($3 || '');
6440 elsif ($token =~ /^%\?([\w\-]+)%$/)
6442 return transform_token ($token, $transform, $1) ? 'TRUE' : 'FALSE';
6445 elsif ($token =~ /^ \? (!?) ([\w\-]+) \? $/x)
6447 my $neg = ($1 eq '!') ? 1 : 0;
6448 my $val = transform_token ($token, $transform, $2);
6449 return (!!$val == $neg) ? '##%' : '';
6453 prog_error "Unknown request format: $token";
6459 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
6460 # ------------------------------------------
6461 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6463 sub make_paragraphs ($%)
6465 my ($file, %transform) = @_;
6467 # Complete %transform with global options.
6468 # Note that %transform goes last, so it overrides global options.
6469 %transform = ('CYGNUS' => !! option 'cygnus',
6471 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
6473 'LZMA' => !! option 'dist-lzma',
6474 'BZIP2' => !! option 'dist-bzip2',
6475 'COMPRESS' => !! option 'dist-tarZ',
6476 'GZIP' => ! option 'no-dist-gzip',
6477 'SHAR' => !! option 'dist-shar',
6478 'ZIP' => !! option 'dist-zip',
6480 'INSTALL-INFO' => ! option 'no-installinfo',
6481 'INSTALL-MAN' => ! option 'no-installman',
6482 'CK-NEWS' => !! option 'check-news',
6484 'SUBDIRS' => !! var ('SUBDIRS'),
6485 'TOPDIR_P' => $relative_dir eq '.',
6487 'BUILD' => ($seen_canonical >= AC_CANONICAL_BUILD),
6488 'HOST' => ($seen_canonical >= AC_CANONICAL_HOST),
6489 'TARGET' => ($seen_canonical >= AC_CANONICAL_TARGET),
6491 'LIBTOOL' => !! var ('LIBTOOL'),
6493 'FIRST' => ! $transformed_files{$file},
6496 $transformed_files{$file} = 1;
6497 $_ = $am_file_cache{$file};
6501 verb "reading $file";
6502 # Swallow the whole file.
6503 my $fc_file = new Automake::XFile "< $file";
6504 my $saved_dollar_slash = $/;
6506 $_ = $fc_file->getline;
6507 $/ = $saved_dollar_slash;
6510 # Remove ##-comments.
6511 # Besides we don't need more than two consecutive new-lines.
6512 s/(?:$IGNORE_PATTERN|(?<=\n\n)\n+)//gom;
6514 $am_file_cache{$file} = $_;
6517 # Substitute Automake template tokens.
6518 s/(?: % \?? [\w\-]+ %
6519 | % [\w\-]+ (?:\?[^?:%]+)? (?::[^?:%]+)? %
6521 )/transform($&, \%transform)/gex;
6522 # transform() may have added some ##%-comments to strip.
6523 # (we use `##%' instead of `##' so we can distinguish ##%##%##% from
6524 # ####### and do not remove the latter.)
6525 s/^[ \t]*(?:##%)+.*\n//gm;
6527 # Split at unescaped new lines.
6528 my @lines = split (/(?<!\\)\n/, $_);
6531 while (defined ($_ = shift @lines))
6534 # If we are a rule, eat as long as we start with a tab.
6535 if (/$RULE_PATTERN/smo)
6537 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
6539 $paragraph .= "\n$_";
6541 unshift (@lines, $_);
6544 # If we are a comments, eat as much comments as you can.
6545 elsif (/$COMMENT_PATTERN/smo)
6547 while (defined ($_ = shift @lines)
6548 && $_ =~ /$COMMENT_PATTERN/smo)
6550 $paragraph .= "\n$_";
6552 unshift (@lines, $_);
6555 push @res, $paragraph;
6563 # ($COMMENT, $VARIABLES, $RULES)
6564 # &file_contents_internal ($IS_AM, $FILE, $WHERE, [%TRANSFORM])
6565 # -------------------------------------------------------------
6566 # Return contents of a file from $libdir/am, automatically skipping
6567 # macros or rules which are already known. $IS_AM iff the caller is
6568 # reading an Automake file (as opposed to the user's Makefile.am).
6569 sub file_contents_internal ($$$%)
6571 my ($is_am, $file, $where, %transform) = @_;
6573 $where->set ($file);
6575 my $result_vars = '';
6576 my $result_rules = '';
6580 # The following flags are used to track rules spanning across
6581 # multiple paragraphs.
6582 my $is_rule = 0; # 1 if we are processing a rule.
6583 my $discard_rule = 0; # 1 if the current rule should not be output.
6585 # We save the conditional stack on entry, and then check to make
6586 # sure it is the same on exit. This lets us conditionally include
6588 my @saved_cond_stack = @cond_stack;
6589 my $cond = new Automake::Condition (@cond_stack);
6591 foreach (make_paragraphs ($file, %transform))
6593 # FIXME: no line number available.
6594 $where->set ($file);
6597 error $where, "blank line following trailing backslash:\n$_"
6599 error $where, "comment following trailing backslash:\n$_"
6605 # Stick empty line before the incoming macro or rule.
6608 elsif (/$COMMENT_PATTERN/mso)
6611 # Stick comments before the incoming macro or rule.
6615 # Handle inclusion of other files.
6616 elsif (/$INCLUDE_PATTERN/o)
6620 my $file = ($is_am ? "$libdir/am/" : '') . $1;
6621 $where->push_context ("`$file' included from here");
6623 my ($com, $vars, $rules)
6624 = file_contents_internal ($is_am, $file, $where, %transform);
6625 $where->pop_context;
6627 $result_vars .= $vars;
6628 $result_rules .= $rules;
6632 # Handling the conditionals.
6633 elsif (/$IF_PATTERN/o)
6635 $cond = cond_stack_if ($1, $2, $file);
6637 elsif (/$ELSE_PATTERN/o)
6639 $cond = cond_stack_else ($1, $2, $file);
6641 elsif (/$ENDIF_PATTERN/o)
6643 $cond = cond_stack_endif ($1, $2, $file);
6647 elsif (/$RULE_PATTERN/mso)
6651 # Separate relationship from optional actions: the first
6652 # `new-line tab" not preceded by backslash (continuation
6655 /^(.*?)(?:(?<!\\)\n(\t.*))?$/s;
6656 my ($relationship, $actions) = ($1, $2 || '');
6658 # Separate targets from dependencies: the first colon.
6659 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
6660 my ($targets, $dependencies) = ($1, $2);
6661 # Remove the escaped new lines.
6662 # I don't know why, but I have to use a tmp $flat_deps.
6663 my $flat_deps = &flatten ($dependencies);
6664 my @deps = split (' ', $flat_deps);
6666 foreach (split (' ' , $targets))
6668 # FIXME: 1. We are not robust to people defining several targets
6669 # at once, only some of them being in %dependencies. The
6670 # actions from the targets in %dependencies are usually generated
6671 # from the content of %actions, but if some targets in $targets
6672 # are not in %dependencies the ELSE branch will output
6673 # a rule for all $targets (i.e. the targets which are both
6674 # in %dependencies and $targets will have two rules).
6676 # FIXME: 2. The logic here is not able to output a
6677 # multi-paragraph rule several time (e.g. for each condition
6678 # it is defined for) because it only knows the first paragraph.
6680 # FIXME: 3. We are not robust to people defining a subset
6681 # of a previously defined "multiple-target" rule. E.g.
6682 # `foo:' after `foo bar:'.
6684 # Output only if not in FALSE.
6685 if (defined $dependencies{$_} && $cond != FALSE)
6687 &depend ($_, @deps);
6688 register_action ($_, $actions);
6692 # Free-lance dependency. Output the rule for all the
6693 # targets instead of one by one.
6694 my @undefined_conds =
6695 Automake::Rule::define ($targets, $file,
6696 $is_am ? RULE_AUTOMAKE : RULE_USER,
6698 for my $undefined_cond (@undefined_conds)
6700 my $condparagraph = $paragraph;
6701 $condparagraph =~ s/^/$undefined_cond->subst_string/gme;
6702 $result_rules .= "$spacing$comment$condparagraph\n";
6704 if (scalar @undefined_conds == 0)
6706 # Remember to discard next paragraphs
6707 # if they belong to this rule.
6708 # (but see also FIXME: #2 above.)
6711 $comment = $spacing = '';
6717 elsif (/$ASSIGNMENT_PATTERN/mso)
6719 my ($var, $type, $val) = ($1, $2, $3);
6720 error $where, "variable `$var' with trailing backslash"
6725 Automake::Variable::define ($var,
6726 $is_am ? VAR_AUTOMAKE : VAR_MAKEFILE,
6727 $type, $cond, $val, $comment, $where,
6731 $comment = $spacing = '';
6735 # This isn't an error; it is probably some tokens which
6736 # configure is supposed to replace, such as `@SET-MAKE@',
6737 # or some part of a rule cut by an if/endif.
6738 if (! $cond->false && ! ($is_rule && $discard_rule))
6740 s/^/$cond->subst_string/gme;
6741 $result_rules .= "$spacing$comment$_\n";
6743 $comment = $spacing = '';
6747 error ($where, @cond_stack ?
6748 "unterminated conditionals: @cond_stack" :
6749 "too many conditionals closed in include file")
6750 if "@saved_cond_stack" ne "@cond_stack";
6752 return ($comment, $result_vars, $result_rules);
6757 # &file_contents ($BASENAME, $WHERE, [%TRANSFORM])
6758 # ------------------------------------------------
6759 # Return contents of a file from $libdir/am, automatically skipping
6760 # macros or rules which are already known.
6761 sub file_contents ($$%)
6763 my ($basename, $where, %transform) = @_;
6764 my ($comments, $variables, $rules) =
6765 file_contents_internal (1, "$libdir/am/$basename.am", $where,
6767 return "$comments$variables$rules";
6772 # &am_primary_prefixes ($PRIMARY, $CAN_DIST, @PREFIXES)
6773 # -----------------------------------------------------
6774 # Find all variable prefixes that are used for install directories. A
6775 # prefix `zar' qualifies iff:
6777 # * `zardir' is a variable.
6778 # * `zar_PRIMARY' is a variable.
6780 # As a side effect, it looks for misspellings. It is an error to have
6781 # a variable ending in a "reserved" suffix whose prefix is unknown, e.g.
6782 # "bni_PROGRAMS". However, unusual prefixes are allowed if a variable
6783 # of the same name (with "dir" appended) exists. For instance, if the
6784 # variable "zardir" is defined, then "zar_PROGRAMS" becomes valid.
6785 # This is to provide a little extra flexibility in those cases which
6787 sub am_primary_prefixes ($$@)
6789 my ($primary, $can_dist, @prefixes) = @_;
6792 my %valid = map { $_ => 0 } @prefixes;
6793 $valid{'EXTRA'} = 0;
6794 foreach my $var (variables $primary)
6796 # Automake is allowed to define variables that look like primaries
6797 # but which aren't. E.g. INSTALL_sh_DATA.
6798 # Autoconf can also define variables like INSTALL_DATA, so
6799 # ignore all configure variables (at least those which are not
6800 # redefined in Makefile.am).
6801 # FIXME: We should make sure that these variables are not
6802 # conditionally defined (or else adjust the condition below).
6803 my $def = $var->def (TRUE);
6804 next if $def && $def->owner != VAR_MAKEFILE;
6806 my $varname = $var->name;
6808 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_[[:alnum:]]+$/)
6810 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
6811 if ($dist ne '' && ! $can_dist)
6814 "invalid variable `$varname': `dist' is forbidden");
6816 # Standard directories must be explicitly allowed.
6817 elsif (! defined $valid{$X} && exists $standard_prefix{$X})
6820 "`${X}dir' is not a legitimate directory " .
6823 # A not explicitly valid directory is allowed if Xdir is defined.
6824 elsif (! defined $valid{$X} &&
6825 $var->requires_variables ("`$varname' is used", "${X}dir"))
6827 # Nothing to do. Any error message has been output
6828 # by $var->requires_variables.
6832 # Ensure all extended prefixes are actually used.
6833 $valid{"$base$dist$X"} = 1;
6838 prog_error "unexpected variable name: $varname";
6842 # Return only those which are actually defined.
6843 return sort grep { var ($_ . '_' . $primary) } keys %valid;
6847 # Handle `where_HOW' variable magic. Does all lookups, generates
6848 # install code, and possibly generates code to define the primary
6849 # variable. The first argument is the name of the .am file to munge,
6850 # the second argument is the primary variable (e.g. HEADERS), and all
6851 # subsequent arguments are possible installation locations.
6853 # Returns list of [$location, $value] pairs, where
6854 # $value's are the values in all where_HOW variable, and $location
6855 # there associated location (the place here their parent variables were
6858 # FIXME: this should be rewritten to be cleaner. It should be broken
6859 # up into multiple functions.
6861 # Usage is: am_install_var (OPTION..., file, HOW, where...)
6868 my $default_dist = 0;
6871 if ($args[0] eq '-noextra')
6875 elsif ($args[0] eq '-candist')
6879 elsif ($args[0] eq '-defaultdist')
6884 elsif ($args[0] !~ /^-/)
6891 my ($file, $primary, @prefix) = @args;
6893 # Now that configure substitutions are allowed in where_HOW
6894 # variables, it is an error to actually define the primary. We
6895 # allow `JAVA', as it is customarily used to mean the Java
6896 # interpreter. This is but one of several Java hacks. Similarly,
6897 # `PYTHON' is customarily used to mean the Python interpreter.
6898 reject_var $primary, "`$primary' is an anachronism"
6899 unless $primary eq 'JAVA' || $primary eq 'PYTHON';
6901 # Get the prefixes which are valid and actually used.
6902 @prefix = am_primary_prefixes ($primary, $can_dist, @prefix);
6904 # If a primary includes a configure substitution, then the EXTRA_
6905 # form is required. Otherwise we can't properly do our job.
6911 foreach my $X (@prefix)
6913 my $nodir_name = $X;
6914 my $one_name = $X . '_' . $primary;
6915 my $one_var = var $one_name;
6917 my $strip_subdir = 1;
6918 # If subdir prefix should be preserved, do so.
6919 if ($nodir_name =~ /^nobase_/)
6922 $nodir_name =~ s/^nobase_//;
6925 # If files should be distributed, do so.
6929 $dist_p = (($default_dist && $nodir_name !~ /^nodist_/)
6930 || (! $default_dist && $nodir_name =~ /^dist_/));
6931 $nodir_name =~ s/^(dist|nodist)_//;
6935 # Use the location of the currently processed variable.
6936 # We are not processing a particular condition, so pick the first
6938 my $tmpcond = $one_var->conditions->one_cond;
6939 my $where = $one_var->rdef ($tmpcond)->location->clone;
6941 # Append actual contents of where_PRIMARY variable to
6942 # @result, skipping @substitutions@.
6943 foreach my $locvals ($one_var->value_as_list_recursive (location => 1))
6945 my ($loc, $value) = @$locvals;
6946 # Skip configure substitutions.
6947 if ($value =~ /^\@.*\@$/)
6949 if ($nodir_name eq 'EXTRA')
6952 "`$one_name' contains configure substitution, "
6955 # Check here to make sure variables defined in
6956 # configure.ac do not imply that EXTRA_PRIMARY
6958 elsif (! defined $configure_vars{$one_name})
6960 $require_extra = $one_name
6966 push (@result, $locvals);
6969 # A blatant hack: we rewrite each _PROGRAMS primary to include
6971 append_exeext { 1 } $one_name
6972 if $primary eq 'PROGRAMS';
6973 # "EXTRA" shouldn't be used when generating clean targets,
6974 # all, or install targets. We used to warn if EXTRA_FOO was
6975 # defined uselessly, but this was annoying.
6977 if $nodir_name eq 'EXTRA';
6979 if ($nodir_name eq 'check')
6981 push (@check, '$(' . $one_name . ')');
6985 push (@used, '$(' . $one_name . ')');
6988 # Is this to be installed?
6989 my $install_p = $nodir_name ne 'noinst' && $nodir_name ne 'check';
6991 # If so, with install-exec? (or install-data?).
6992 my $exec_p = ($nodir_name =~ /$EXEC_DIR_PATTERN/o);
6994 my $check_options_p = $install_p && !! option 'std-options';
6996 # Use the location of the currently processed variable as context.
6997 $where->push_context ("while processing `$one_name'");
6999 # The variable containing all file to distribute.
7000 my $distvar = "\$($one_name)";
7001 $distvar = shadow_unconditionally ($one_name, $where)
7002 if ($dist_p && $one_var->has_conditional_contents);
7004 # Singular form of $PRIMARY.
7005 (my $one_primary = $primary) =~ s/S$//;
7006 $output_rules .= &file_contents ($file, $where,
7007 PRIMARY => $primary,
7008 ONE_PRIMARY => $one_primary,
7010 NDIR => $nodir_name,
7011 BASE => $strip_subdir,
7014 INSTALL => $install_p,
7016 DISTVAR => $distvar,
7017 'CK-OPTS' => $check_options_p);
7020 # The JAVA variable is used as the name of the Java interpreter.
7021 # The PYTHON variable is used as the name of the Python interpreter.
7022 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7025 define_pretty_variable ($primary, TRUE, INTERNAL, @used);
7026 $output_vars .= "\n";
7029 err_var ($require_extra,
7030 "`$require_extra' contains configure substitution,\n"
7031 . "but `EXTRA_$primary' not defined")
7032 if ($require_extra && ! var ('EXTRA_' . $primary));
7034 # Push here because PRIMARY might be configure time determined.
7035 push (@all, '$(' . $primary . ')')
7036 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7038 # Make the result unique. This lets the user use conditionals in
7039 # a natural way, but still lets us program lazily -- we don't have
7040 # to worry about handling a particular object more than once.
7041 # We will keep only one location per object.
7043 for my $pair (@result)
7045 my ($loc, $val) = @$pair;
7046 $result{$val} = $loc;
7048 my @l = sort keys %result;
7049 return map { [$result{$_}->clone, $_] } @l;
7053 ################################################################
7055 # Each key in this hash is the name of a directory holding a
7056 # Makefile.in. These variables are local to `is_make_dir'.
7058 my $make_dirs_set = 0;
7063 if (! $make_dirs_set)
7065 foreach my $iter (@configure_input_files)
7067 $make_dirs{dirname ($iter)} = 1;
7069 # We also want to notice Makefile.in's.
7070 foreach my $iter (@other_input_files)
7072 if ($iter =~ /Makefile\.in$/)
7074 $make_dirs{dirname ($iter)} = 1;
7079 return defined $make_dirs{$dir};
7082 ################################################################
7084 # Find the aux dir. This should match the algorithm used by
7085 # ./configure. (See the Autoconf documentation for for
7086 # AC_CONFIG_AUX_DIR.)
7087 sub locate_aux_dir ()
7089 if (! $config_aux_dir_set_in_configure_ac)
7091 # The default auxiliary directory is the first
7092 # of ., .., or ../.. that contains install-sh.
7093 # Assume . if install-sh doesn't exist yet.
7094 for my $dir (qw (. .. ../..))
7096 if (-f "$dir/install-sh")
7098 $config_aux_dir = $dir;
7102 $config_aux_dir = '.' unless $config_aux_dir;
7104 # Avoid unsightly '/.'s.
7105 $am_config_aux_dir =
7106 '$(top_srcdir)' . ($config_aux_dir eq '.' ? "" : "/$config_aux_dir");
7107 $am_config_aux_dir =~ s,/*$,,;
7111 # &maybe_push_required_file ($DIR, $FILE, $FULLFILE)
7112 # --------------------------------------------------
7113 # See if we want to push this file onto dist_common. This function
7114 # encodes the rules for deciding when to do so.
7115 sub maybe_push_required_file
7117 my ($dir, $file, $fullfile) = @_;
7119 if ($dir eq $relative_dir)
7121 push_dist_common ($file);
7124 elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7126 # If we are doing the topmost directory, and the file is in a
7127 # subdir which does not have a Makefile, then we distribute it
7130 # If a required file is above the source tree, it is important
7131 # to prefix it with `$(srcdir)' so that no VPATH search is
7132 # performed. Otherwise problems occur with Make implementations
7133 # that rewrite and simplify rules whose dependencies are found in a
7134 # VPATH location. Here is an example with OSF1/Tru64 Make.
7146 # Dependency `../a' was found in `sub/../a', but this make
7147 # implementation simplified it as `a'. (Note that the sub/
7148 # directory does not even exist.)
7150 # This kind of VPATH rewriting seems hard to cancel. The
7151 # distdir.am hack against VPATH rewriting works only when no
7152 # simplification is done, i.e., for dependencies which are in
7153 # subdirectories, not in enclosing directories. Hence, in
7154 # the latter case we use a full path to make sure no VPATH
7156 $fullfile = '$(srcdir)/' . $fullfile
7157 if $dir =~ m,^\.\.(?:$|/),;
7159 push_dist_common ($fullfile);
7166 # If a file name appears as a key in this hash, then it has already
7167 # been checked for. This allows us not to report the same error more
7169 my %required_file_not_found = ();
7171 # &require_file_internal ($WHERE, $MYSTRICT, $DIRECTORY, @FILES)
7172 # --------------------------------------------------------------
7173 # Verify that the file must exist in $DIRECTORY, or install it.
7174 # $MYSTRICT is the strictness level at which this file becomes required.
7175 sub require_file_internal ($$$@)
7177 my ($where, $mystrict, $dir, @files) = @_;
7179 foreach my $file (@files)
7181 my $fullfile = "$dir/$file";
7183 my $dangling_sym = 0;
7185 if (-l $fullfile && ! -f $fullfile)
7189 elsif (dir_has_case_matching_file ($dir, $file))
7192 maybe_push_required_file ($dir, $file, $fullfile);
7195 # `--force-missing' only has an effect if `--add-missing' is
7197 if ($found_it && (! $add_missing || ! $force_missing))
7203 # If we've already looked for it, we're done. You might
7204 # wonder why we don't do this before searching for the
7205 # file. If we do that, then something like
7206 # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
7210 next if defined $required_file_not_found{$fullfile};
7211 $required_file_not_found{$fullfile} = 1;
7214 if ($strictness >= $mystrict)
7216 if ($dangling_sym && $add_missing)
7224 # Only install missing files according to our desired
7226 my $message = "required file `$fullfile' not found";
7229 if (-f "$libdir/$file")
7233 # Install the missing file. Symlink if we
7234 # can, copy if we must. Note: delete the file
7235 # first, in case it is a dangling symlink.
7236 $message = "installing `$fullfile'";
7237 # Windows Perl will hang if we try to delete a
7238 # file that doesn't exist.
7239 unlink ($fullfile) if -f $fullfile;
7240 if ($symlink_exists && ! $copy_missing)
7242 if (! symlink ("$libdir/$file", $fullfile))
7245 $trailer = "; error while making link: $!";
7248 elsif (system ('cp', "$libdir/$file", $fullfile))
7251 $trailer = "\n error while copying";
7253 reset_dir_cache ($dir);
7256 if (! maybe_push_required_file (dirname ($fullfile),
7259 if (! $found_it && ! $automake_will_process_aux_dir)
7261 # We have added the file but could not push it
7262 # into DIST_COMMON, probably because this is
7263 # an auxiliary file and we are not processing
7264 # the top level Makefile. Furthermore Automake
7265 # hasn't been asked to create the Makefile.in
7266 # that distribute the aux dir files.
7267 error ($where, 'Please make a full run of automake'
7268 . " so $fullfile gets distributed.");
7274 $trailer = "\n `automake --add-missing' can install `$file'"
7275 if -f "$libdir/$file";
7278 # If --force-missing was specified, and we have
7279 # actually found the file, then do nothing.
7281 if $found_it && $force_missing;
7283 # If we couldn't install the file, but it is a target in
7284 # the Makefile, don't print anything. This allows files
7285 # like README, AUTHORS, or THANKS to be generated.
7287 if !$suppress && rule $file;
7289 msg ($suppress ? 'note' : 'error', $where, "$message$trailer");
7295 # &require_file ($WHERE, $MYSTRICT, @FILES)
7296 # -----------------------------------------
7297 sub require_file ($$@)
7299 my ($where, $mystrict, @files) = @_;
7300 require_file_internal ($where, $mystrict, $relative_dir, @files);
7303 # &require_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7304 # -----------------------------------------------------------
7305 sub require_file_with_macro ($$$@)
7307 my ($cond, $macro, $mystrict, @files) = @_;
7308 $macro = rvar ($macro) unless ref $macro;
7309 require_file ($macro->rdef ($cond)->location, $mystrict, @files);
7312 # &require_libsource_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7313 # ----------------------------------------------------------------
7314 # Require an AC_LIBSOURCEd file. If AC_CONFIG_LIBOBJ_DIR was called, it
7315 # must be in that directory. Otherwise expect it in the current directory.
7316 sub require_libsource_with_macro ($$$@)
7318 my ($cond, $macro, $mystrict, @files) = @_;
7319 $macro = rvar ($macro) unless ref $macro;
7320 if ($config_libobj_dir)
7322 require_file_internal ($macro->rdef ($cond)->location, $mystrict,
7323 $config_libobj_dir, @files);
7327 require_file ($macro->rdef ($cond)->location, $mystrict, @files);
7331 # &require_conf_file ($WHERE, $MYSTRICT, @FILES)
7332 # ----------------------------------------------
7333 # Looks in configuration path, as specified by AC_CONFIG_AUX_DIR.
7334 sub require_conf_file ($$@)
7336 my ($where, $mystrict, @files) = @_;
7337 require_file_internal ($where, $mystrict, $config_aux_dir, @files);
7341 # &require_conf_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7342 # ----------------------------------------------------------------
7343 sub require_conf_file_with_macro ($$$@)
7345 my ($cond, $macro, $mystrict, @files) = @_;
7346 require_conf_file (rvar ($macro)->rdef ($cond)->location,
7350 ################################################################
7352 # &require_build_directory ($DIRECTORY)
7353 # ------------------------------------
7354 # Emit rules to create $DIRECTORY if needed, and return
7355 # the file that any target requiring this directory should be made
7357 # We don't want to emit the rule twice, and want to reuse it
7358 # for directories with equivalent names (e.g., `foo/bar' and `./foo//bar').
7359 sub require_build_directory ($)
7361 my $directory = shift;
7363 return $directory_map{$directory} if exists $directory_map{$directory};
7365 my $cdir = File::Spec->canonpath ($directory);
7367 if (exists $directory_map{$cdir})
7369 my $stamp = $directory_map{$cdir};
7370 $directory_map{$directory} = $stamp;
7374 my $dirstamp = "$cdir/\$(am__dirstamp)";
7376 $directory_map{$directory} = $dirstamp;
7377 $directory_map{$cdir} = $dirstamp;
7379 # Set a variable for the dirstamp basename.
7380 define_pretty_variable ('am__dirstamp', TRUE, INTERNAL,
7381 '$(am__leading_dot)dirstamp');
7383 # Directory must be removed by `make distclean'.
7384 $clean_files{$dirstamp} = DIST_CLEAN;
7386 $output_rules .= ("$dirstamp:\n"
7387 . "\t\@\$(MKDIR_P) $directory\n"
7388 . "\t\@: > $dirstamp\n");
7393 # &require_build_directory_maybe ($FILE)
7394 # --------------------------------------
7395 # If $FILE lies in a subdirectory, emit a rule to create this
7396 # directory and return the file that $FILE should be made
7397 # dependent upon. Otherwise, just return the empty string.
7398 sub require_build_directory_maybe ($)
7401 my $directory = dirname ($file);
7403 if ($directory ne '.')
7405 return require_build_directory ($directory);
7413 ################################################################
7415 # Push a list of files onto dist_common.
7416 sub push_dist_common
7418 prog_error "push_dist_common run after handle_dist"
7419 if $handle_dist_run;
7420 Automake::Variable::define ('DIST_COMMON', VAR_AUTOMAKE, '+', TRUE, "@_",
7421 '', INTERNAL, VAR_PRETTY);
7425 ################################################################
7427 # generate_makefile ($MAKEFILE_AM, $MAKEFILE_IN)
7428 # ----------------------------------------------
7429 # Generate a Makefile.in given the name of the corresponding Makefile and
7430 # the name of the file output by config.status.
7431 sub generate_makefile ($$)
7433 my ($makefile_am, $makefile_in) = @_;
7435 # Reset all the Makefile.am related variables.
7436 initialize_per_input;
7438 # AUTOMAKE_OPTIONS can contains -W flags to disable or enable
7439 # warnings for this file. So hold any warning issued before
7440 # we have processed AUTOMAKE_OPTIONS.
7441 buffer_messages ('warning');
7443 # Name of input file ("Makefile.am") and output file
7444 # ("Makefile.in"). These have no directory components.
7445 $am_file_name = basename ($makefile_am);
7446 $in_file_name = basename ($makefile_in);
7448 # $OUTPUT is encoded. If it contains a ":" then the first element
7449 # is the real output file, and all remaining elements are input
7450 # files. We don't scan or otherwise deal with these input files,
7451 # other than to mark them as dependencies. See
7452 # &scan_autoconf_files for details.
7453 my ($makefile, @inputs) = split (/:/, $output_files{$makefile_in});
7455 $relative_dir = dirname ($makefile);
7456 $am_relative_dir = dirname ($makefile_am);
7457 $topsrcdir = backname ($relative_dir);
7459 read_main_am_file ($makefile_am);
7462 # Process buffered warnings.
7464 # Fatal error. Just return, so we can continue with next file.
7467 # Process buffered warnings.
7470 # There are a few install-related variables that you should not define.
7471 foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
7476 my $def = $v->def (TRUE);
7477 prog_error "$var not defined in condition TRUE"
7479 reject_var $var, "`$var' should not be defined"
7480 if $def->owner != VAR_AUTOMAKE;
7484 # Catch some obsolete variables.
7485 msg_var ('obsolete', 'INCLUDES',
7486 "`INCLUDES' is the old name for `AM_CPPFLAGS' (or `*_CPPFLAGS')")
7487 if var ('INCLUDES');
7489 # Must do this after reading .am file.
7490 define_variable ('subdir', $relative_dir, INTERNAL);
7492 # If DIST_SUBDIRS is defined, make sure SUBDIRS is, so that
7493 # recursive rules are enabled.
7494 define_pretty_variable ('SUBDIRS', TRUE, INTERNAL, '')
7495 if var 'DIST_SUBDIRS' && ! var 'SUBDIRS';
7497 # Check first, because we might modify some state.
7499 check_gnu_standards;
7500 check_gnits_standards;
7502 handle_configure ($makefile_am, $makefile_in, $makefile, @inputs);
7509 # These must be run after all the sources are scanned. They
7510 # use variables defined by &handle_libraries, &handle_ltlibraries,
7511 # or &handle_programs.
7516 # Variables used by distdir.am and tags.am.
7517 define_pretty_variable ('SOURCES', TRUE, INTERNAL, @sources);
7518 if (! option 'no-dist')
7520 define_pretty_variable ('DIST_SOURCES', TRUE, INTERNAL, @dist_sources);
7533 handle_minor_options;
7534 # Must come after handle_programs so that %known_programs is up-to-date.
7537 # This must come after most other rules.
7541 do_check_merge_target;
7542 handle_all ($makefile);
7545 if (var ('lib_LTLIBRARIES') && var ('bin_PROGRAMS'))
7547 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
7551 handle_clean ($makefile);
7552 handle_factored_dependencies;
7554 # Comes last, because all the above procedures may have
7555 # defined or overridden variables.
7556 $output_vars .= output_variables;
7560 my ($out_file) = $output_directory . '/' . $makefile_in;
7562 if ($exit_code != 0)
7564 verb "not writing $out_file because of earlier errors";
7568 if (! -d ($output_directory . '/' . $am_relative_dir))
7570 mkdir ($output_directory . '/' . $am_relative_dir, 0755);
7573 # We make sure that `all:' is the first target.
7575 "$output_vars$output_all$output_header$output_rules$output_trailer";
7577 # Decide whether we must update the output file or not.
7578 # We have to update in the following situations.
7579 # * $force_generation is set.
7580 # * any of the output dependencies is younger than the output
7581 # * the contents of the output is different (this can happen
7582 # if the project has been populated with a file listed in
7583 # @common_files since the last run).
7584 # Output's dependencies are split in two sets:
7585 # * dependencies which are also configure dependencies
7586 # These do not change between each Makefile.am
7587 # * other dependencies, specific to the Makefile.am being processed
7588 # (such as the Makefile.am itself, or any Makefile fragment
7590 my $timestamp = mtime $out_file;
7591 if (! $force_generation
7592 && $configure_deps_greatest_timestamp < $timestamp
7593 && $output_deps_greatest_timestamp < $timestamp
7594 && $output eq contents ($out_file))
7596 verb "$out_file unchanged";
7597 # No need to update.
7604 or fatal "cannot remove $out_file: $!\n";
7607 my $gm_file = new Automake::XFile "> $out_file";
7608 verb "creating $out_file";
7609 print $gm_file $output;
7612 ################################################################
7617 ################################################################
7619 # Print usage information.
7622 print "Usage: $0 [OPTION] ... [Makefile]...
7624 Generate Makefile.in for configure from Makefile.am.
7627 --help print this help, then exit
7628 --version print version number, then exit
7629 -v, --verbose verbosely list files processed
7630 --no-force only update Makefile.in's that are out of date
7631 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
7633 Dependency tracking:
7634 -i, --ignore-deps disable dependency tracking code
7635 --include-deps enable dependency tracking code
7638 --cygnus assume program is part of Cygnus-style tree
7639 --foreign set strictness to foreign
7640 --gnits set strictness to gnits
7641 --gnu set strictness to gnu
7644 -a, --add-missing add missing standard files to package
7645 --libdir=DIR directory storing library files
7646 -c, --copy with -a, copy missing files (default is symlink)
7647 -f, --force-missing force update of standard files
7650 Automake::ChannelDefs::usage;
7654 foreach my $iter (sort ((@common_files, @common_sometimes)))
7656 push (@lcomm, $iter) unless $iter eq $last;
7661 print "\nFiles which are automatically distributed, if found:\n";
7662 format USAGE_FORMAT =
7663 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
7664 $four[0], $four[1], $four[2], $four[3]
7666 $~ = "USAGE_FORMAT";
7669 my $rows = int(@lcomm / $cols);
7670 my $rest = @lcomm % $cols;
7681 for (my $y = 0; $y < $rows; $y++)
7683 @four = ("", "", "", "");
7684 for (my $x = 0; $x < $cols; $x++)
7686 last if $y + 1 == $rows && $x == $rest;
7688 my $idx = (($x > $rest)
7689 ? ($rows * $rest + ($rows - 1) * ($x - $rest))
7693 $four[$x] = $lcomm[$idx];
7698 print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7700 # --help always returns 0 per GNU standards.
7707 # Print version information
7711 automake (GNU $PACKAGE) $VERSION
7712 Copyright (C) 2008 Free Software Foundation, Inc.
7713 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
7714 This is free software: you are free to change and redistribute it.
7715 There is NO WARRANTY, to the extent permitted by law.
7717 Written by Tom Tromey <tromey\@redhat.com>
7718 and Alexandre Duret-Lutz <adl\@gnu.org>.
7720 # --version always returns 0 per GNU standards.
7724 ################################################################
7726 # Parse command line.
7727 sub parse_arguments ()
7730 set_strictness ('gnu');
7732 my $cli_where = new Automake::Location;
7735 'libdir=s' => \$libdir,
7736 'gnu' => sub { set_strictness ('gnu'); },
7737 'gnits' => sub { set_strictness ('gnits'); },
7738 'cygnus' => sub { set_global_option ('cygnus', $cli_where); },
7739 'foreign' => sub { set_strictness ('foreign'); },
7740 'include-deps' => sub { unset_global_option ('no-dependencies'); },
7741 'i|ignore-deps' => sub { set_global_option ('no-dependencies',
7743 'no-force' => sub { $force_generation = 0; },
7744 'f|force-missing' => \$force_missing,
7745 'o|output-dir=s' => \$output_directory,
7746 'a|add-missing' => \$add_missing,
7747 'c|copy' => \$copy_missing,
7748 'v|verbose' => sub { setup_channel 'verb', silent => 0; },
7749 'W|warnings=s' => \&parse_warnings,
7750 # These long options (--Werror and --Wno-error) for backward
7751 # compatibility. Use -Werror and -Wno-error today.
7752 'Werror' => sub { parse_warnings 'W', 'error'; },
7753 'Wno-error' => sub { parse_warnings 'W', 'no-error'; },
7756 Getopt::Long::config ("bundling", "pass_through");
7758 # See if --version or --help is used. We want to process these before
7759 # anything else because the GNU Coding Standards require us to
7760 # `exit 0' after processing these options, and we can't guarantee this
7761 # if we treat other options first. (Handling other options first
7762 # could produce error diagnostics, and in this condition it is
7763 # confusing if Automake does `exit 0'.)
7764 my %cli_options_1st_pass =
7766 'version' => \&version,
7768 # Recognize all other options (and their arguments) but do nothing.
7769 map { $_ => sub {} } (keys %cli_options)
7771 my @ARGV_backup = @ARGV;
7772 Getopt::Long::GetOptions %cli_options_1st_pass
7774 @ARGV = @ARGV_backup;
7776 # Now *really* process the options. This time we know that --help
7777 # and --version are not present, but we specify them nonetheless so
7778 # that ambiguous abbreviation are diagnosed.
7779 Getopt::Long::GetOptions %cli_options, 'version' => sub {}, 'help' => sub {}
7782 if (defined $output_directory)
7784 msg 'obsolete', "`--output-dir' is deprecated\n";
7788 # In the next release we'll remove this entirely.
7789 $output_directory = '.';
7792 return unless @ARGV;
7794 if ($ARGV[0] =~ /^-./)
7797 for my $k (keys %cli_options)
7799 if ($k =~ /(.*)=s$/)
7801 map { $argopts{(length ($_) == 1)
7802 ? "-$_" : "--$_" } = 1; } (split (/\|/, $1));
7805 if ($ARGV[0] eq '--')
7809 elsif (exists $argopts{$ARGV[0]})
7811 fatal ("option `$ARGV[0]' requires an argument\n"
7812 . "Try `$0 --help' for more information.");
7816 fatal ("unrecognized option `$ARGV[0]'.\n"
7817 . "Try `$0 --help' for more information.");
7822 foreach my $arg (@ARGV)
7824 fatal ("empty argument\nTry `$0 --help' for more information.")
7827 # Handle $local:$input syntax.
7828 my ($local, @rest) = split (/:/, $arg);
7829 @rest = ("$local.in",) unless @rest;
7830 my $input = locate_am @rest;
7833 push @input_files, $input;
7834 $output_files{$input} = join (':', ($local, @rest));
7838 error "no Automake input file found for `$arg'";
7842 fatal "no input file found among supplied arguments"
7843 if $errspec && ! @input_files;
7846 ################################################################
7848 # Parse the WARNINGS environment variable.
7851 # Parse command line.
7854 $configure_ac = require_configure_ac;
7856 # Do configure.ac scan only once.
7857 scan_autoconf_files;
7862 $msg = "\nDid you forget AC_CONFIG_FILES([Makefile]) in $configure_ac?"
7863 if -f 'Makefile.am';
7864 fatal ("no `Makefile.am' found for any configure output$msg");
7867 # Now do all the work on each file.
7868 foreach my $file (@input_files)
7870 ($am_file = $file) =~ s/\.in$//;
7871 if (! -f ($am_file . '.am'))
7873 error "`$am_file.am' does not exist";
7877 # Any warning setting now local to this Makefile.am.
7880 generate_makefile ($am_file . '.am', $file);
7882 # Back out any warning setting.
7890 ### Setup "GNU" style for perl-mode and cperl-mode.
7892 ## perl-indent-level: 2
7893 ## perl-continued-statement-offset: 2
7894 ## perl-continued-brace-offset: 0
7895 ## perl-brace-offset: 0
7896 ## perl-brace-imaginary-offset: 0
7897 ## perl-label-offset: -2
7898 ## cperl-indent-level: 2
7899 ## cperl-brace-offset: 0
7900 ## cperl-continued-brace-offset: 0
7901 ## cperl-label-offset: -2
7902 ## cperl-extra-newline-before-brace: t
7903 ## cperl-merge-trailing-else: nil
7904 ## cperl-continued-statement-offset: 2