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 Free Software Foundation, Inc.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2, or (at your option)
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
28 # Perl reimplementation by Tom Tromey <tromey@redhat.com>, and
29 # Alexandre Duret-Lutz <adl@gnu.org>.
35 my $perllibdir = $ENV{'perllibdir'} || '@datadir@/@PACKAGE@-@APIVERSION@';
36 unshift @INC, (split '@PATH_SEPARATOR@', $perllibdir);
38 # Override SHELL. This is required on DJGPP so that system() uses
39 # bash, not COMMAND.COM which doesn't quote arguments properly.
40 # Other systems aren't expected to use $SHELL when Automake
41 # runs, but it should be safe to drop the `if DJGPP' guard if
42 # it turns up other systems need the same thing. After all,
43 # if SHELL is used, ./configure's SHELL is always better than
44 # the user's SHELL (which may be something like tcsh).
45 $ENV{'SHELL'} = '@SHELL@' if exists $ENV{'DJGPP'};
49 struct (# Short name of the language (c, f77...).
51 # Nice name of the language (C, Fortran 77...).
54 # List of configure variables which must be defined.
58 # `pure' is `1' or `'. A `pure' language is one where, if
59 # all the files in a directory are of that language, then we
60 # do not require the C compiler or any code to call it.
65 # Name of the compiling variable (COMPILE).
67 # Content of the compiling variable.
69 # Flag to require compilation without linking (-c).
70 'compile_flag' => "\$",
72 # A subroutine to compute a list of possible extensions of
73 # the product given the input extensions.
74 # (defaults to a subroutine which returns ('.$(OBJEXT)', '.lo'))
75 'output_extensions' => "\$",
76 # A list of flag variables used in 'compile'.
80 # Any tag to pass to libtool while compiling.
81 'libtool_tag' => "\$",
83 # The file to use when generating rules for this language.
84 # The default is 'depend2'.
87 # Name of the linking variable (LINK).
89 # Content of the linking variable.
92 # Name of the linker variable (LD).
94 # Content of the linker variable ($(CC)).
97 # Flag to specify the output file (-o).
98 'output_flag' => "\$",
101 # This is a subroutine which is called whenever we finally
102 # determine the context in which a source file will be
104 '_target_hook' => "\$",
106 # If TRUE, nodist_ sources will be compiled using specific rules
107 # (i.e. not inference rules). The default is FALSE.
108 'nodist_specific' => "\$");
114 if (defined $self->_finish)
116 &{$self->_finish} ();
120 sub target_hook ($$$$%)
123 if (defined $self->_target_hook)
125 &{$self->_target_hook} (@_);
132 use Automake::Config;
133 use Automake::General;
135 use Automake::Channels;
136 use Automake::ChannelDefs;
137 use Automake::Configure_ac;
138 use Automake::FileUtils;
139 use Automake::Location;
140 use Automake::Condition qw/TRUE FALSE/;
141 use Automake::DisjConditions;
142 use Automake::Options;
143 use Automake::Version;
144 use Automake::Variable;
145 use Automake::VarDef;
147 use Automake::RuleDef;
148 use Automake::Wrap 'makefile_wrap';
156 # Some regular expressions. One reason to put them here is that it
157 # makes indentation work better in Emacs.
159 # Writing singled-quoted-$-terminated regexes is a pain because
160 # perl-mode thinks of $' as the ${'} variable (instead of a $ followed
161 # by a closing quote. Letting perl-mode think the quote is not closed
162 # leads to all sort of misindentations. On the other hand, defining
163 # regexes as double-quoted strings is far less readable. So usually
166 # $REGEX = '^regex_value' . "\$";
168 my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
169 my $WHITE_PATTERN = '^\s*' . "\$";
170 my $COMMENT_PATTERN = '^#';
171 my $TARGET_PATTERN='[$a-zA-Z_.@%][-.a-zA-Z0-9_(){}/$+@%]*';
172 # A rule has three parts: a list of targets, a list of dependencies,
173 # and optionally actions.
175 "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
177 # Only recognize leading spaces, not leading tabs. If we recognize
178 # leading tabs here then we need to make the reader smarter, because
179 # otherwise it will think rules like `foo=bar; \' are errors.
180 my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)' . "\$";
181 # This pattern recognizes a Gnits version id and sets $1 if the
182 # release is an alpha release. We also allow a suffix which can be
183 # used to extend the version number with a "fork" identifier.
184 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
186 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?' . "\$";
188 '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
190 '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
191 my $PATH_PATTERN = '(\w|[+/.-])+';
192 # This will pass through anything not of the prescribed form.
193 my $INCLUDE_PATTERN = ('^include\s+'
194 . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
195 . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
196 . '|([^/\$]' . $PATH_PATTERN . '))\s*(#.*)?' . "\$");
198 # Match `-d' as a command-line argument in a string.
199 my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)";
200 # Directories installed during 'install-exec' phase.
201 my $EXEC_DIR_PATTERN =
202 '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)' . "\$";
204 # Values for AC_CANONICAL_*
205 use constant AC_CANONICAL_BUILD => 1;
206 use constant AC_CANONICAL_HOST => 2;
207 use constant AC_CANONICAL_TARGET => 3;
209 # Values indicating when something should be cleaned.
210 use constant MOSTLY_CLEAN => 0;
211 use constant CLEAN => 1;
212 use constant DIST_CLEAN => 2;
213 use constant MAINTAINER_CLEAN => 3;
216 my @libtool_files = qw(ltmain.sh config.guess config.sub);
217 # ltconfig appears here for compatibility with old versions of libtool.
218 my @libtool_sometimes = qw(ltconfig ltcf-c.sh ltcf-cxx.sh ltcf-gcj.sh);
220 # Commonly found files we look for and automatically include in
223 (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
224 COPYING.LESSER ChangeLog INSTALL NEWS README THANKS TODO
225 ansi2knr.1 ansi2knr.c compile config.guess config.rpath config.sub
226 depcomp elisp-comp install-sh libversion.in mdate-sh missing
227 mkinstalldirs py-compile texinfo.tex ylwrap),
228 @libtool_files, @libtool_sometimes);
230 # Commonly used files we auto-include, but only sometimes. This list
231 # is used for the --help output only.
232 my @common_sometimes =
233 qw(aclocal.m4 acconfig.h config.h.top config.h.bot configure
234 configure.ac configure.in stamp-vti);
236 # Standard directories from the GNU Coding Standards, and additional
237 # pkg* directories from Automake. Stored in a hash for fast member check.
238 my %standard_prefix =
239 map { $_ => 1 } (qw(bin data dataroot dvi exec html include info
240 lib libexec lisp localstate man man1 man2 man3
241 man4 man5 man6 man7 man8 man9 oldinclude pdf
242 pkgdatadir pkgincludedir pkglibdir ps sbin
243 sharedstate sysconf));
245 # Copyright on generated Makefile.ins.
246 my $gen_copyright = "\
247 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
248 # 2003, 2004, 2005 Free Software Foundation, Inc.
249 # This Makefile.in is free software; the Free Software Foundation
250 # gives unlimited permission to copy and/or distribute it,
251 # with or without modifications, as long as this notice is preserved.
253 # This program is distributed in the hope that it will be useful,
254 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
255 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
256 # PARTICULAR PURPOSE.
259 # These constants are returned by lang_*_rewrite functions.
260 # LANG_SUBDIR means that the resulting object file should be in a
261 # subdir if the source file is. In this case the file name cannot
262 # have `..' components.
263 use constant LANG_IGNORE => 0;
264 use constant LANG_PROCESS => 1;
265 use constant LANG_SUBDIR => 2;
267 # These are used when keeping track of whether an object can be built
268 # by two different paths.
269 use constant COMPILE_LIBTOOL => 1;
270 use constant COMPILE_ORDINARY => 2;
272 # We can't always associate a location to a variable or a rule,
273 # when its defined by Automake. We use INTERNAL in this case.
274 use constant INTERNAL => new Automake::Location;
277 ## ---------------------------------- ##
278 ## Variables related to the options. ##
279 ## ---------------------------------- ##
281 # TRUE if we should always generate Makefile.in.
282 my $force_generation = 1;
284 # From the Perl manual.
285 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
287 # TRUE if missing standard files should be installed.
290 # TRUE if we should copy missing files; otherwise symlink if possible.
291 my $copy_missing = 0;
293 # TRUE if we should always update files that we know about.
294 my $force_missing = 0;
297 ## ---------------------------------------- ##
298 ## Variables filled during files scanning. ##
299 ## ---------------------------------------- ##
301 # Name of the configure.ac file.
304 # Files found by scanning configure.ac for LIBOBJS.
307 # Names used in AC_CONFIG_HEADER call.
308 my @config_headers = ();
310 # Names used in AC_CONFIG_LINKS call.
311 my @config_links = ();
313 # Directory where output files go. Actually, output files are
314 # relative to this directory.
315 my $output_directory;
317 # List of Makefile.am's to process, and their corresponding outputs.
318 my @input_files = ();
319 my %output_files = ();
321 # Complete list of Makefile.am's that exist.
322 my @configure_input_files = ();
324 # List of files in AC_CONFIG_FILES/AC_OUTPUT without Makefile.am's,
326 my @other_input_files = ();
327 # Where each AC_CONFIG_FILES/AC_OUTPUT/AC_CONFIG_LINK/AC_CONFIG_HEADER appears.
328 # The keys are the files created by these macros.
329 my %ac_config_files_location = ();
331 # Directory to search for configure-required files. This
332 # will be computed by &locate_aux_dir and can be set using
333 # AC_CONFIG_AUX_DIR in configure.ac.
334 # $CONFIG_AUX_DIR is the `raw' directory, valid only in the source-tree.
335 my $config_aux_dir = '';
336 my $config_aux_dir_set_in_configure_ac = 0;
337 # $AM_CONFIG_AUX_DIR is prefixed with $(top_srcdir), so it can be used
339 my $am_config_aux_dir = '';
341 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
342 my $seen_gettext = 0;
343 # Whether AM_GNU_GETTEXT([external]) is used.
344 my $seen_gettext_external = 0;
345 # Where AM_GNU_GETTEXT appears.
346 my $ac_gettext_location;
348 # Lists of tags supported by Libtool.
349 my %libtool_tags = ();
350 # 1 if Libtool uses LT_SUPPORTED_TAG. If it does, then it also
351 # use AC_REQUIRE_AUX_FILE.
352 my $libtool_new_api = 0;
354 # Most important AC_CANONICAL_* macro seen so far.
355 my $seen_canonical = 0;
356 # Location of that macro.
357 my $canonical_location;
359 # Where AM_MAINTAINER_MODE appears.
362 # Actual version we've seen.
363 my $package_version = '';
365 # Where version is defined.
366 my $package_version_location;
368 # TRUE if we've seen AC_ENABLE_MULTILIB.
369 my $seen_multilib = 0;
371 # TRUE if we've seen AM_PROG_CC_C_O
374 # Location of AC_REQUIRE_AUX_FILE calls, indexed by their argument.
375 my %required_aux_file = ();
377 # Where AM_INIT_AUTOMAKE is called;
378 my $seen_init_automake = 0;
380 # TRUE if we've seen AM_AUTOMAKE_VERSION.
381 my $seen_automake_version = 0;
383 # Hash table of discovered configure substitutions. Keys are names,
384 # values are `FILE:LINE' strings which are used by error message
386 my %configure_vars = ();
388 # Files included by $configure_ac.
389 my @configure_deps = ();
391 # Greatest timestamp of configure's dependencies.
392 my $configure_deps_greatest_timestamp = 0;
394 # Hash table of AM_CONDITIONAL variables seen in configure.
395 my %configure_cond = ();
397 # This maps extensions onto language names.
398 my %extension_map = ();
400 # List of the DIST_COMMON files we discovered while reading
402 my $configure_dist_common = '';
404 # This maps languages names onto objects.
406 # Maps each linker variable onto a language object.
407 my %link_languages = ();
409 # List of targets we must always output.
410 # FIXME: Complete, and remove falsely required targets.
411 my %required_targets =
424 # FIXME: Not required, temporary hacks.
425 # Well, actually they are sort of required: the -recursive
426 # targets will run them anyway...
431 'install-data-am' => 1,
432 'install-exec-am' => 1,
433 'installcheck-am' => 1,
439 # Set to 1 if this run will create the Makefile.in that distribute
440 # the files in config_aux_dir.
441 my $automake_will_process_aux_dir = 0;
443 # The name of the Makefile currently being processed.
447 ################################################################
449 ## ------------------------------------------ ##
450 ## Variables reset by &initialize_per_input. ##
451 ## ------------------------------------------ ##
453 # Basename and relative dir of the input file.
457 # Same but wrt Makefile.in.
461 # Greatest timestamp of the output's dependencies (excluding
462 # configure's dependencies).
463 my $output_deps_greatest_timestamp;
465 # These two variables are used when generating each Makefile.in.
466 # They hold the Makefile.in until it is ready to be printed.
473 # This is the conditional stack, updated on if/else/endif, and
474 # used to build Condition objects.
477 # This holds the set of included files.
480 # This holds a list of directories which we must create at `dist'
481 # time. This is used in some strange scenarios involving weird
482 # AC_OUTPUT commands.
485 # List of dependencies for the obvious targets.
490 # Keys in this hash table are files to delete. The associated
491 # value tells when this should happen (MOSTLY_CLEAN, DIST_CLEAN, etc.)
494 # Keys in this hash table are object files or other files in
495 # subdirectories which need to be removed. This only holds files
496 # which are created by compilations. The value in the hash indicates
497 # when the file should be removed.
498 my %compile_clean_files;
500 # Keys in this hash table are directories where we expect to build a
501 # libtool object. We use this information to decide what directories
503 my %libtool_clean_directories;
505 # Value of `$(SOURCES)', used by tags.am.
507 # Sources which go in the distribution.
510 # This hash maps object file names onto their corresponding source
511 # file names. This is used to ensure that each object is created
512 # by a single source file.
515 # This hash maps object file names onto an integer value representing
516 # whether this object has been built via ordinary compilation or
517 # libtool compilation (the COMPILE_* constants).
518 my %object_compilation_map;
521 # This keeps track of the directories for which we've already
522 # created dirstamp code.
528 # This is a list of all targets to run during "make dist".
531 # Keys in this hash are the basenames of files which must depend on
532 # ansi2knr. Values are either the empty string, or the directory in
533 # which the ANSI source file appears; the directory must have a
537 # This is the name of the redirect `all' target to use.
540 # This keeps track of which extensions we've seen (that we care
544 # This is random scratch space for the language finish functions.
545 # Don't randomly overwrite it; examine other uses of keys first.
546 my %language_scratch;
548 # We keep track of which objects need special (per-executable)
549 # handling on a per-language basis.
550 my %lang_specific_files;
552 # This is set when `handle_dist' has finished. Once this happens,
553 # we should no longer push on dist_common.
556 # Used to store a set of linkers needed to generate the sources currently
557 # under consideration.
560 # True if we need `LINK' defined. This is a hack.
563 # Was get_object_extension run?
564 # FIXME: This is a hack. a better switch should be found.
565 my $get_object_extension_was_run;
567 # Record each file processed by make_paragraphs.
568 my %transformed_files;
570 # Cache each file processed by make_paragraphs.
571 # (This is different from %transformed_files because
572 # %transformed_files is reset for each file while %am_file_cache
573 # it global to the run.)
576 ################################################################
578 # var_SUFFIXES_trigger ($TYPE, $VALUE)
579 # ------------------------------------
580 # This is called by Automake::Variable::define() when SUFFIXES
581 # is defined ($TYPE eq '') or appended ($TYPE eq '+').
582 # The work here needs to be performed as a side-effect of the
583 # macro_define() call because SUFFIXES definitions impact
584 # on $KNOWN_EXTENSIONS_PATTERN which is used used when parsing
586 sub var_SUFFIXES_trigger ($$)
588 my ($type, $value) = @_;
589 accept_extensions (split (' ', $value));
591 Automake::Variable::hook ('SUFFIXES', \&var_SUFFIXES_trigger);
593 ################################################################
595 ## --------------------------------- ##
596 ## Forward subroutine declarations. ##
597 ## --------------------------------- ##
598 sub register_language (%);
599 sub file_contents_internal ($$$%);
600 sub define_files_variable ($\@$$);
603 # &initialize_per_input ()
604 # ------------------------
605 # (Re)-Initialize per-Makefile.am variables.
606 sub initialize_per_input ()
608 reset_local_duplicates ();
611 $am_relative_dir = '';
616 $output_deps_greatest_timestamp = 0;
620 $output_trailer = '';
624 Automake::Options::reset;
625 Automake::Variable::reset;
626 Automake::Rule::reset;
644 %object_compilation_map = ();
656 %extension_seen = ();
658 %language_scratch = ();
660 %lang_specific_files = ();
662 $handle_dist_run = 0;
666 $get_object_extension_was_run = 0;
668 %compile_clean_files = ();
670 # We always include `.'. This isn't strictly correct.
671 %libtool_clean_directories = ('.' => 1);
673 %transformed_files = ();
677 ################################################################
679 # Initialize our list of languages that are internally supported.
682 register_language ('name' => 'c',
684 'config_vars' => ['CC'],
687 'flags' => ['CFLAGS', 'CPPFLAGS'],
688 'compiler' => 'COMPILE',
689 'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
693 'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
694 'compile_flag' => '-c',
695 'libtool_tag' => 'CC',
696 'extensions' => ['.c'],
697 '_finish' => \&lang_c_finish);
700 register_language ('name' => 'cxx',
702 'config_vars' => ['CXX'],
703 'linker' => 'CXXLINK',
704 'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
706 'flags' => ['CXXFLAGS', 'CPPFLAGS'],
707 'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
708 'compiler' => 'CXXCOMPILE',
709 'compile_flag' => '-c',
710 'output_flag' => '-o',
711 'libtool_tag' => 'CXX',
715 'extensions' => ['.c++', '.cc', '.cpp', '.cxx', '.C']);
718 register_language ('name' => 'objc',
719 'Name' => 'Objective C',
720 'config_vars' => ['OBJC'],
721 'linker' => 'OBJCLINK',,
722 'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
724 'flags' => ['OBJCFLAGS', 'CPPFLAGS'],
725 'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
726 'compiler' => 'OBJCCOMPILE',
727 'compile_flag' => '-c',
728 'output_flag' => '-o',
732 'extensions' => ['.m']);
735 register_language ('name' => 'header',
737 'extensions' => ['.h', '.H', '.hxx', '.h++', '.hh',
740 'output_extensions' => sub { return () },
742 '_finish' => sub { });
745 register_language ('name' => 'yacc',
747 'config_vars' => ['YACC'],
748 'flags' => ['YFLAGS'],
749 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
750 'compiler' => 'YACCCOMPILE',
751 'extensions' => ['.y'],
752 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
754 'rule_file' => 'yacc',
755 '_finish' => \&lang_yacc_finish,
756 '_target_hook' => \&lang_yacc_target_hook,
757 'nodist_specific' => 1);
758 register_language ('name' => 'yaccxx',
759 'Name' => 'Yacc (C++)',
760 'config_vars' => ['YACC'],
761 'rule_file' => 'yacc',
762 'flags' => ['YFLAGS'],
763 'compiler' => 'YACCCOMPILE',
764 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
765 'extensions' => ['.y++', '.yy', '.yxx', '.ypp'],
766 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
768 '_finish' => \&lang_yacc_finish,
769 '_target_hook' => \&lang_yacc_target_hook,
770 'nodist_specific' => 1);
773 register_language ('name' => 'lex',
775 'config_vars' => ['LEX'],
776 'rule_file' => 'lex',
777 'flags' => ['LFLAGS'],
778 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
779 'compiler' => 'LEXCOMPILE',
780 'extensions' => ['.l'],
781 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
783 '_finish' => \&lang_lex_finish,
784 '_target_hook' => \&lang_lex_target_hook,
785 'nodist_specific' => 1);
786 register_language ('name' => 'lexxx',
787 'Name' => 'Lex (C++)',
788 'config_vars' => ['LEX'],
789 'rule_file' => 'lex',
790 'flags' => ['LFLAGS'],
791 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
792 'compiler' => 'LEXCOMPILE',
793 'extensions' => ['.l++', '.ll', '.lxx', '.lpp'],
794 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
796 '_finish' => \&lang_lex_finish,
797 '_target_hook' => \&lang_lex_target_hook,
798 'nodist_specific' => 1);
801 register_language ('name' => 'asm',
802 'Name' => 'Assembler',
803 'config_vars' => ['CCAS', 'CCASFLAGS'],
805 'flags' => ['CCASFLAGS'],
806 # Users can set AM_CCASFLAGS to include DEFS, INCLUDES,
807 # or anything else required. They can also set CCAS.
808 'compile' => '$(CCAS) $(AM_CCASFLAGS) $(CCASFLAGS)',
809 'compiler' => 'CCASCOMPILE',
810 'compile_flag' => '-c',
811 'extensions' => ['.s'],
813 # With assembly we still use the C linker.
814 '_finish' => \&lang_c_finish);
816 # Preprocessed Assembler.
817 register_language ('name' => 'cppasm',
818 'Name' => 'Preprocessed Assembler',
819 'config_vars' => ['CCAS', 'CCASFLAGS'],
822 'flags' => ['CCASFLAGS', 'CPPFLAGS'],
823 # Users can set AM_ASFLAGS to include DEFS, INCLUDES,
824 # or anything else required. They can also set CCAS.
825 'compile' => '$(CCAS) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS)',
826 'compiler' => 'CPPASCOMPILE',
827 'compile_flag' => '-c',
828 'extensions' => ['.S'],
830 # With assembly we still use the C linker.
831 '_finish' => \&lang_c_finish);
834 register_language ('name' => 'f77',
835 'Name' => 'Fortran 77',
836 'linker' => 'F77LINK',
837 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
838 'flags' => ['FFLAGS'],
839 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
840 'compiler' => 'F77COMPILE',
841 'compile_flag' => '-c',
842 'output_flag' => '-o',
843 'libtool_tag' => 'F77',
847 'extensions' => ['.f', '.for']);
850 register_language ('name' => 'fc',
852 'linker' => 'FCLINK',
853 'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
854 'flags' => ['FCFLAGS'],
855 'compile' => '$(FC) $(AM_FCFLAGS) $(FCFLAGS)',
856 'compiler' => 'FCCOMPILE',
857 'compile_flag' => '-c',
858 'output_flag' => '-o',
862 'extensions' => ['.f90', '.f95']);
864 # Preprocessed Fortran
865 register_language ('name' => 'ppfc',
866 'Name' => 'Preprocessed Fortran',
867 'config_vars' => ['FC'],
868 'linker' => 'FCLINK',
869 'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
872 'flags' => ['FCFLAGS', 'CPPFLAGS'],
873 'compiler' => 'PPFCCOMPILE',
874 'compile' => '$(FC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FCFLAGS) $(FCFLAGS)',
875 'compile_flag' => '-c',
876 'output_flag' => '-o',
877 'libtool_tag' => 'FC',
879 'extensions' => ['.F90','.F95']);
881 # Preprocessed Fortran 77
883 # The current support for preprocessing Fortran 77 just involves
884 # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
885 # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
886 # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
887 # for `make' Version 3.76 Beta' (specifically, from info file
888 # `(make)Catalogue of Rules').
890 # A better approach would be to write an Autoconf test
891 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
892 # Fortran 77 compilers know how to do preprocessing. The Autoconf
893 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
894 # preprocessing capabilities, and then fall back on cpp (if cpp were
896 register_language ('name' => 'ppf77',
897 'Name' => 'Preprocessed Fortran 77',
898 'config_vars' => ['F77'],
899 'linker' => 'F77LINK',
900 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
903 'flags' => ['FFLAGS', 'CPPFLAGS'],
904 'compiler' => 'PPF77COMPILE',
905 'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
906 'compile_flag' => '-c',
907 'output_flag' => '-o',
908 'libtool_tag' => 'F77',
910 'extensions' => ['.F']);
913 register_language ('name' => 'ratfor',
915 'config_vars' => ['F77'],
916 'linker' => 'F77LINK',
917 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
920 'flags' => ['RFLAGS', 'FFLAGS'],
922 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
923 'compiler' => 'RCOMPILE',
924 'compile_flag' => '-c',
925 'output_flag' => '-o',
926 'libtool_tag' => 'F77',
928 'extensions' => ['.r']);
931 register_language ('name' => 'java',
933 'config_vars' => ['GCJ'],
934 'linker' => 'GCJLINK',
935 'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
937 'flags' => ['GCJFLAGS'],
938 'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
939 'compiler' => 'GCJCOMPILE',
940 'compile_flag' => '-c',
941 'output_flag' => '-o',
942 'libtool_tag' => 'GCJ',
946 'extensions' => ['.java', '.class', '.zip', '.jar']);
948 ################################################################
950 # Error reporting functions.
952 # err_am ($MESSAGE, [%OPTIONS])
953 # -----------------------------
954 # Uncategorized errors about the current Makefile.am.
957 msg_am ('error', @_);
960 # err_ac ($MESSAGE, [%OPTIONS])
961 # -----------------------------
962 # Uncategorized errors about configure.ac.
965 msg_ac ('error', @_);
968 # msg_am ($CHANNEL, $MESSAGE, [%OPTIONS])
969 # ---------------------------------------
970 # Messages about about the current Makefile.am.
973 my ($channel, $msg, %opts) = @_;
974 msg $channel, "${am_file}.am", $msg, %opts;
977 # msg_ac ($CHANNEL, $MESSAGE, [%OPTIONS])
978 # ---------------------------------------
979 # Messages about about configure.ac.
982 my ($channel, $msg, %opts) = @_;
983 msg $channel, $configure_ac, $msg, %opts;
986 ################################################################
990 # Return a configure-style substitution using the indicated text.
991 # We do this to avoid having the substitutions directly in automake.in;
992 # when we do that they are sometimes removed and this causes confusion
997 return '@' . $text . '@';
1000 ################################################################
1004 # &backname ($REL-DIR)
1005 # --------------------
1006 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
1007 # For instance `src/foo' => `../..'.
1008 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
1013 foreach (split (/\//, $file))
1015 next if $_ eq '.' || $_ eq '';
1025 return join ('/', @res) || '.';
1028 ################################################################
1031 # Handle AUTOMAKE_OPTIONS variable. Return 1 on error, 0 otherwise.
1034 my $var = var ('AUTOMAKE_OPTIONS');
1037 # FIXME: We should disallow conditional definitions of AUTOMAKE_OPTIONS.
1038 if (process_option_list ($var->rdef (TRUE)->location,
1039 $var->value_as_list_recursive (cond_filter =>
1046 if ($strictness == GNITS)
1048 set_option ('readme-alpha', INTERNAL);
1049 set_option ('std-options', INTERNAL);
1050 set_option ('check-news', INTERNAL);
1056 # shadow_unconditionally ($varname, $where)
1057 # -----------------------------------------
1058 # Return a $(variable) that contains all possible values
1059 # $varname can take.
1060 # If the VAR wasn't defined conditionally, return $(VAR).
1061 # Otherwise we create a am__VAR_DIST variable which contains
1062 # all possible values, and return $(am__VAR_DIST).
1063 sub shadow_unconditionally ($$)
1065 my ($varname, $where) = @_;
1066 my $var = var $varname;
1067 if ($var->has_conditional_contents)
1069 $varname = "am__${varname}_DIST";
1070 my @files = uniq ($var->value_as_list_recursive);
1071 define_pretty_variable ($varname, TRUE, $where, @files);
1073 return "\$($varname)"
1076 # get_object_extension ($EXTENSION)
1077 # ---------------------------------
1078 # Prefix $EXTENSION with $U if ansi2knr is in use.
1079 sub get_object_extension ($)
1081 my ($extension) = @_;
1083 # Check for automatic de-ANSI-fication.
1084 $extension = '$U' . $extension
1085 if option 'ansi2knr';
1087 $get_object_extension_was_run = 1;
1092 # check_user_variables (@LIST)
1093 # ----------------------------
1094 # Make sure each variable VAR in @LIST do not exist, suggest using AM_VAR
1096 sub check_user_variables (@)
1098 my @dont_override = @_;
1099 foreach my $flag (@dont_override)
1101 my $var = var $flag;
1104 for my $cond ($var->conditions->conds)
1106 if ($var->rdef ($cond)->owner == VAR_MAKEFILE)
1108 msg_cond_var ('gnu', $cond, $flag,
1109 "`$flag' is a user variable, "
1110 . "you should not override it;\n"
1111 . "use `AM_$flag' instead.");
1118 # Call finish function for each language that was used.
1119 sub handle_languages
1121 if (! option 'no-dependencies')
1123 # Include auto-dep code. Don't include it if DEP_FILES would
1125 if (&saw_sources_p (0) && keys %dep_files)
1127 # Set location of depcomp.
1128 &define_variable ('depcomp',
1129 "\$(SHELL) $am_config_aux_dir/depcomp",
1131 &define_variable ('am__depfiles_maybe', 'depfiles', INTERNAL);
1133 require_conf_file ("$am_file.am", FOREIGN, 'depcomp');
1135 my @deplist = sort keys %dep_files;
1136 # Generate each `include' individually. Irix 6 make will
1137 # not properly include several files resulting from a
1138 # variable expansion; generating many separate includes
1140 $output_rules .= "\n";
1141 foreach my $iter (@deplist)
1143 $output_rules .= (subst ('AMDEP_TRUE')
1144 . subst ('am__include')
1146 . subst ('am__quote')
1148 . subst ('am__quote')
1152 # Compute the set of directories to remove in distclean-depend.
1153 my @depdirs = uniq (map { dirname ($_) } @deplist);
1154 $output_rules .= &file_contents ('depend',
1155 new Automake::Location,
1156 DEPDIRS => "@depdirs");
1161 &define_variable ('depcomp', '', INTERNAL);
1162 &define_variable ('am__depfiles_maybe', '', INTERNAL);
1167 # Is the c linker needed?
1169 foreach my $ext (sort keys %extension_seen)
1171 next unless $extension_map{$ext};
1173 my $lang = $languages{$extension_map{$ext}};
1175 my $rule_file = $lang->rule_file || 'depend2';
1177 # Get information on $LANG.
1178 my $pfx = $lang->autodep;
1179 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1181 my ($AMDEP, $FASTDEP) =
1182 (option 'no-dependencies' || $lang->autodep eq 'no')
1183 ? ('FALSE', 'FALSE') : ('AMDEP', "am__fastdep$fpfx");
1185 my %transform = ('EXT' => $ext,
1189 'FASTDEP' => $FASTDEP,
1190 '-c' => $lang->compile_flag || '',
1192 => (count_files_for_language ($lang->name) > 1),
1193 # These are not used, but they need to be defined
1194 # so &transform do not complain.
1196 'DERIVED-EXT' => 'BUG',
1200 # Generate the appropriate rules for this extension.
1201 if (((! option 'no-dependencies') && $lang->autodep ne 'no')
1202 || defined $lang->compile)
1204 # Some C compilers don't support -c -o. Use it only if really
1206 my $output_flag = $lang->output_flag || '';
1209 && $lang->name eq 'c'
1210 && option 'subdir-objects');
1212 # Compute a possible derived extension.
1213 # This is not used by depend2.am.
1214 my $der_ext = (&{$lang->output_extensions} ($ext))[0];
1216 # When we output an inference rule like `.c.o:' we
1217 # have two cases to consider: either subdir-objects
1218 # is used, or it is not.
1220 # In the latter case the rule is used to build objects
1221 # in the current directory, and dependencies always
1222 # go into `./$(DEPDIR)/'. We can hard-code this value.
1224 # In the former case the rule can be used to build
1225 # objects in sub-directories too. Dependencies should
1226 # go into the appropriate sub-directories, e.g.,
1227 # `sub/$(DEPDIR)/'. The value of this directory
1228 # need the be computed on-the-fly.
1230 # DEPBASE holds the name of this directory, plus the
1231 # basename part of the object file (extensions Po, TPo,
1232 # Plo, TPlo will be added later as appropriate). It is
1233 # either hardcoded, or a shell variable (`$depbase') that
1234 # will be computed by the rule.
1236 option ('subdir-objects') ? '$$depbase' : '$(DEPDIR)/$*';
1238 file_contents ($rule_file,
1239 new Automake::Location,
1243 'DERIVED-EXT' => $der_ext,
1245 DEPBASE => $depbase,
1252 COMPILE => '$(' . $lang->compiler . ')',
1253 LTCOMPILE => '$(LT' . $lang->compiler . ')',
1255 SUBDIROBJ => !! option 'subdir-objects');
1258 # Now include code for each specially handled object with this
1260 my %seen_files = ();
1261 foreach my $file (@{$lang_specific_files{$lang->name}})
1263 my ($derived, $source, $obj, $myext, %file_transform) = @$file;
1265 # We might see a given object twice, for instance if it is
1266 # used under different conditions.
1267 next if defined $seen_files{$obj};
1268 $seen_files{$obj} = 1;
1270 prog_error ("found " . $lang->name .
1271 " in handle_languages, but compiler not defined")
1272 unless defined $lang->compile;
1274 my $obj_compile = $lang->compile;
1276 # Rewrite each occurrence of `AM_$flag' in the compile
1277 # rule into `${derived}_$flag' if it exists.
1278 for my $flag (@{$lang->flags})
1280 my $val = "${derived}_$flag";
1281 $obj_compile =~ s/\(AM_$flag\)/\($val\)/
1285 my $libtool_tag = '';
1286 if ($lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag})
1288 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
1291 my $ptltflags = "${derived}_LIBTOOLFLAGS";
1292 $ptltflags = 'AM_LIBTOOLFLAGS' unless set_seen $ptltflags;
1295 "\$(LIBTOOL) $libtool_tag\$($ptltflags) \$(LIBTOOLFLAGS) "
1296 . "--mode=compile $obj_compile";
1298 # We _need_ `-o' for per object rules.
1299 my $output_flag = $lang->output_flag || '-o';
1301 my $depbase = dirname ($obj);
1305 unless $depbase eq '';
1306 $depbase .= '$(DEPDIR)/' . basename ($obj);
1308 # Support for deansified files in subdirectories is ugly
1309 # enough to deserve an explanation.
1311 # A Note about normal ansi2knr processing first. On
1313 # AUTOMAKE_OPTIONS = ansi2knr
1314 # bin_PROGRAMS = foo
1315 # foo_SOURCES = foo.c
1317 # we generate rules similar to:
1319 # foo: foo$U.o; link ...
1320 # foo$U.o: foo$U.c; compile ...
1321 # foo_.c: foo.c; ansi2knr ...
1323 # this is fairly compact, and will call ansi2knr depending
1324 # on the value of $U (`' or `_').
1326 # It's harder with subdir sources. On
1328 # AUTOMAKE_OPTIONS = ansi2knr
1329 # bin_PROGRAMS = foo
1330 # foo_SOURCES = sub/foo.c
1332 # we have to create foo_.c in the current directory.
1333 # (Unless the user asks 'subdir-objects'.) This is important
1334 # in case the same file (`foo.c') is compiled from other
1335 # directories with different cpp options: foo_.c would
1336 # be preprocessed for only one set of options if it were
1337 # put in the subdirectory.
1339 # Because foo$U.o must be built from either foo_.c or
1340 # sub/foo.c we can't be as concise as in the first example.
1343 # foo: foo$U.o; link ...
1344 # foo_.o: foo_.c; compile ...
1345 # foo.o: sub/foo.c; compile ...
1346 # foo_.c: foo.c; ansi2knr ...
1348 # This is why we'll now transform $rule_file twice
1349 # if we detect this case.
1350 # A first time we output the compile rule with `$U'
1351 # replaced by `_' and the source directory removed,
1352 # and another time we simply remove `$U'.
1354 # Note that at this point $source (as computed by
1355 # &handle_single_transform) is `sub/foo$U.c'.
1356 # This can be confusing: it can be used as-is when
1357 # subdir-objects is set, otherwise you have to know
1358 # it really means `foo_.c' or `sub/foo.c'.
1359 my $objdir = dirname ($obj);
1360 my $srcdir = dirname ($source);
1361 if ($lang->ansi && $obj =~ /\$U/)
1363 prog_error "`$obj' contains \$U, but `$source' doesn't."
1364 if $source !~ /\$U/;
1366 (my $source_ = $source) =~ s/\$U/_/g;
1367 # Output an additional rule if _.c and .c are not in
1368 # the same directory. (_.c is always in $objdir.)
1369 if ($objdir ne $srcdir)
1371 (my $obj_ = $obj) =~ s/\$U/_/g;
1372 (my $depbase_ = $depbase) =~ s/\$U/_/g;
1373 $source_ = basename ($source_);
1376 file_contents ($rule_file,
1377 new Automake::Location,
1381 DEPBASE => $depbase_,
1384 OBJ => "$obj_$myext",
1385 OBJOBJ => "$obj_.obj",
1386 LTOBJ => "$obj_.lo",
1388 COMPILE => $obj_compile,
1389 LTCOMPILE => $obj_ltcompile,
1393 $depbase =~ s/\$U//g;
1394 $source =~ s/\$U//g;
1399 file_contents ($rule_file,
1400 new Automake::Location,
1404 DEPBASE => $depbase,
1407 # Use $myext and not `.o' here, in case
1408 # we are actually building a new source
1409 # file -- e.g. via yacc.
1410 OBJ => "$obj$myext",
1411 OBJOBJ => "$obj.obj",
1414 COMPILE => $obj_compile,
1415 LTCOMPILE => $obj_ltcompile,
1420 # The rest of the loop is done once per language.
1421 next if defined $done{$lang};
1424 # Load the language dependent Makefile chunks.
1425 my %lang = map { uc ($_) => 0 } keys %languages;
1426 $lang{uc ($lang->name)} = 1;
1427 $output_rules .= file_contents ('lang-compile',
1428 new Automake::Location,
1431 # If the source to a program consists entirely of code from a
1432 # `pure' language, for instance C++ or Fortran 77, then we
1433 # don't need the C compiler code. However if we run into
1434 # something unusual then we do generate the C code. There are
1435 # probably corner cases here that do not work properly.
1436 # People linking Java code to Fortran code deserve pain.
1437 $needs_c ||= ! $lang->pure;
1439 define_compiler_variable ($lang)
1440 if ($lang->compile);
1442 define_linker_variable ($lang)
1445 require_variables ("$am_file.am", $lang->Name . " source seen",
1446 TRUE, @{$lang->config_vars});
1448 # Call the finisher.
1451 # Flags listed in `->flags' are user variables (per GNU Standards),
1452 # they should not be overridden in the Makefile...
1453 my @dont_override = @{$lang->flags};
1454 # ... and so is LDFLAGS.
1455 push @dont_override, 'LDFLAGS' if $lang->link;
1457 check_user_variables @dont_override;
1460 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1461 # suffix rule was learned), don't bother with the C stuff. But if
1462 # anything else creeps in, then use it.
1464 if $need_link || suffix_rules_count > 1;
1468 &define_compiler_variable ($languages{'c'})
1469 unless defined $done{$languages{'c'}};
1470 define_linker_variable ($languages{'c'});
1474 # Check to make sure a source defined in LIBOBJS is not explicitly
1475 # mentioned. This is a separate function (as opposed to being inlined
1476 # in handle_source_transform) because it isn't always appropriate to
1478 sub check_libobjs_sources
1480 my ($one_file, $unxformed) = @_;
1482 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1483 'dist_EXTRA_', 'nodist_EXTRA_')
1486 my $varname = $prefix . $one_file . '_SOURCES';
1487 my $var = var ($varname);
1490 @files = $var->value_as_list_recursive;
1492 elsif ($prefix eq '')
1494 @files = ($unxformed . '.c');
1501 foreach my $file (@files)
1503 err_var ($prefix . $one_file . '_SOURCES',
1504 "automatically discovered file `$file' should not" .
1505 " be explicitly mentioned")
1506 if defined $libsources{$file};
1513 # handle_single_transform ($VAR, $TOPPARENT, $DERIVED, $OBJ, $FILE, %TRANSFORM)
1514 # -----------------------------------------------------------------------------
1515 # Does much of the actual work for handle_source_transform.
1517 # $VAR is the name of the variable that the source filenames come from
1518 # $TOPPARENT is the name of the _SOURCES variable which is being processed
1519 # $DERIVED is the name of resulting executable or library
1520 # $OBJ is the object extension (e.g., `$U.lo')
1521 # $FILE the source file to transform
1522 # %TRANSFORM contains extras arguments to pass to file_contents
1523 # when producing explicit rules
1524 # Result is a list of the names of objects
1525 # %linkers_used will be updated with any linkers needed
1526 sub handle_single_transform ($$$$$%)
1528 my ($var, $topparent, $derived, $obj, $_file, %transform) = @_;
1529 my @files = ($_file);
1531 my $nonansi_obj = $obj;
1532 $nonansi_obj =~ s/\$U//g;
1534 # Turn sources into objects. We use a while loop like this
1535 # because we might add to @files in the loop.
1536 while (scalar @files > 0)
1540 # Configure substitutions in _SOURCES variables are errors.
1543 my $parent_msg = '';
1544 $parent_msg = "\nand is referred to from `$topparent'"
1545 if $topparent ne $var->name;
1547 "`" . $var->name . "' includes configure substitution `$_'"
1548 . $parent_msg . ";\nconfigure " .
1549 "substitutions are not allowed in _SOURCES variables");
1553 # If the source file is in a subdirectory then the `.o' is put
1554 # into the current directory, unless the subdir-objects option
1557 # Split file name into base and extension.
1558 next if ! /^(?:(.*)\/)?([^\/]*)($KNOWN_EXTENSIONS_PATTERN)$/;
1560 my $directory = $1 || '';
1564 # We must generate a rule for the object if it requires its own flags.
1566 my ($linker, $object);
1568 # This records whether we've seen a derived source file (e.g.
1570 my $derived_source = 0;
1572 # This holds the `aggregate context' of the file we are
1573 # currently examining. If the file is compiled with
1574 # per-object flags, then it will be the name of the object.
1575 # Otherwise it will be `AM'. This is used by the target hook
1576 # language function.
1577 my $aggregate = 'AM';
1579 $extension = &derive_suffix ($extension, $nonansi_obj);
1581 if ($extension_map{$extension} &&
1582 ($lang = $languages{$extension_map{$extension}}))
1584 # Found the language, so see what it says.
1585 &saw_extension ($extension);
1587 # Do we have per-executable flags for this executable?
1588 my $have_per_exec_flags = 0;
1589 my @peflags = @{$lang->flags};
1590 push @peflags, 'LIBTOOLFLAGS' if $nonansi_obj eq '.lo';
1591 foreach my $flag (@peflags)
1593 if (set_seen ("${derived}_$flag"))
1595 $have_per_exec_flags = 1;
1600 # Note: computed subr call. The language rewrite function
1601 # should return one of the LANG_* constants. It could
1602 # also return a list whose first value is such a constant
1603 # and whose second value is a new source extension which
1604 # should be applied. This means this particular language
1605 # generates another source file which we must then process
1607 my $subr = \&{'lang_' . $lang->name . '_rewrite'};
1608 my ($r, $source_extension)
1609 = &$subr ($directory, $base, $extension,
1610 $nonansi_obj, $have_per_exec_flags, $var);
1611 # Skip this entry if we were asked not to process it.
1612 next if $r == LANG_IGNORE;
1614 # Now extract linker and other info.
1615 $linker = $lang->linker;
1618 if (defined $source_extension)
1620 $this_obj_ext = $source_extension;
1621 $derived_source = 1;
1625 $this_obj_ext = $obj;
1629 $this_obj_ext = $nonansi_obj;
1631 $object = $base . $this_obj_ext;
1633 if ($have_per_exec_flags)
1635 # We have a per-executable flag in effect for this
1636 # object. In this case we rewrite the object's
1637 # name to ensure it is unique.
1639 # We choose the name `DERIVED_OBJECT' to ensure
1640 # (1) uniqueness, and (2) continuity between
1641 # invocations. However, this will result in a
1642 # name that is too long for losing systems, in
1643 # some situations. So we provide _SHORTNAME to
1646 my $dname = $derived;
1647 my $var = var ($derived . '_SHORTNAME');
1650 # FIXME: should use the same Condition as
1651 # the _SOURCES variable. But this is really
1652 # silly overkill -- nobody should have
1653 # conditional shortnames.
1654 $dname = $var->variable_value;
1656 $object = $dname . '-' . $object;
1658 prog_error ($lang->name . " flags defined without compiler")
1659 if ! defined $lang->compile;
1664 # If rewrite said it was ok, put the object into a
1666 if ($r == LANG_SUBDIR && $directory ne '')
1668 $object = $directory . '/' . $object;
1671 # If the object file has been renamed (because per-target
1672 # flags are used) we cannot compile the file with an
1673 # inference rule: we need an explicit rule.
1675 # If the source is in a subdirectory and the object is in
1676 # the current directory, we also need an explicit rule.
1678 # If both source and object files are in a subdirectory
1679 # (this happens when the subdir-objects option is used),
1680 # then the inference will work.
1682 # The latter case deserves a historical note. When the
1683 # subdir-objects option was added on 1999-04-11 it was
1684 # thought that inferences rules would work for
1685 # subdirectory objects too. Later, on 1999-11-22,
1686 # automake was changed to output explicit rules even for
1687 # subdir-objects. Nobody remembers why, but this occured
1688 # soon after the merge of the user-dep-gen-branch so it
1689 # might be related. In late 2003 people complained about
1690 # the size of the generated Makefile.ins (libgcj, with
1691 # 2200+ subdir objects was reported to have a 9MB
1692 # Makefile), so we now rely on inference rules again.
1693 # Maybe we'll run across the same issue as in the past,
1694 # but at least this time we can document it. However since
1695 # dependency tracking has evolved it is possible that
1696 # our old problem no longer exists.
1697 # Using inference rules for subdir-objects has been tested
1698 # with GNU make, Solaris make, Ultrix make, BSD make,
1699 # HP-UX make, and OSF1 make successfully.
1701 || ($directory ne '' && ! option 'subdir-objects')
1702 # We must also use specific rules for a nodist_ source
1703 # if its language requests it.
1704 || ($lang->nodist_specific && ! $transform{'DIST_SOURCE'}))
1706 my $obj_sans_ext = substr ($object, 0,
1707 - length ($this_obj_ext));
1708 my $full_ansi = $full;
1709 if ($lang->ansi && option 'ansi2knr')
1711 $full_ansi =~ s/$KNOWN_EXTENSIONS_PATTERN$/\$U$&/;
1712 $obj_sans_ext .= '$U';
1715 my @specifics = ($full_ansi, $obj_sans_ext,
1716 # Only use $this_obj_ext in the derived
1717 # source case because in the other case we
1718 # *don't* want $(OBJEXT) to appear here.
1719 ($derived_source ? $this_obj_ext : '.o'));
1721 # If we renamed the object then we want to use the
1722 # per-executable flag name. But if this is simply a
1723 # subdir build then we still want to use the AM_ flag
1727 unshift @specifics, $derived;
1728 $aggregate = $derived;
1732 unshift @specifics, 'AM';
1735 # Each item on this list is a reference to a list consisting
1736 # of four values followed by additional transform flags for
1737 # file_contents. The four values are the derived flag prefix
1738 # (e.g. for `foo_CFLAGS', it is `foo'), the name of the
1739 # source file, the base name of the output file, and
1740 # the extension for the object file.
1741 push (@{$lang_specific_files{$lang->name}},
1742 [@specifics, %transform]);
1745 elsif ($extension eq $nonansi_obj)
1747 # This is probably the result of a direct suffix rule.
1748 # In this case we just accept the rewrite.
1749 $object = "$base$extension";
1754 # No error message here. Used to have one, but it was
1756 # FIXME: we could potentially do more processing here,
1757 # perhaps treating the new extension as though it were a
1758 # new source extension (as above). This would require
1759 # more restructuring than is appropriate right now.
1763 err_am "object `$object' created by `$full' and `$object_map{$object}'"
1764 if (defined $object_map{$object}
1765 && $object_map{$object} ne $full);
1767 my $comp_val = (($object =~ /\.lo$/)
1768 ? COMPILE_LIBTOOL : COMPILE_ORDINARY);
1769 (my $comp_obj = $object) =~ s/\.lo$/.\$(OBJEXT)/;
1770 if (defined $object_compilation_map{$comp_obj}
1771 && $object_compilation_map{$comp_obj} != 0
1772 # Only see the error once.
1773 && ($object_compilation_map{$comp_obj}
1774 != (COMPILE_LIBTOOL | COMPILE_ORDINARY))
1775 && $object_compilation_map{$comp_obj} != $comp_val)
1777 err_am "object `$comp_obj' created both with libtool and without";
1779 $object_compilation_map{$comp_obj} |= $comp_val;
1783 # Let the language do some special magic if required.
1784 $lang->target_hook ($aggregate, $object, $full, %transform);
1787 if ($derived_source)
1789 prog_error ($lang->name . " has automatic dependency tracking")
1790 if $lang->autodep ne 'no';
1791 # Make sure this new source file is handled next. That will
1792 # make it appear to be at the right place in the list.
1793 unshift (@files, $object);
1794 # Distribute derived sources unless the source they are
1795 # derived from is not.
1796 &push_dist_common ($object)
1797 unless ($topparent =~ /^(?:nobase_)?nodist_/);
1801 $linkers_used{$linker} = 1;
1803 push (@result, $object);
1805 if (! defined $object_map{$object})
1808 $object_map{$object} = $full;
1810 # If resulting object is in subdir, we need to make
1811 # sure the subdir exists at build time.
1812 if ($object =~ /\//)
1814 # FIXME: check that $DIRECTORY is somewhere in the
1817 # For Java, the way we're handling it right now, a
1818 # `..' component doesn't make sense.
1819 if ($lang->name eq 'java' && $object =~ /(\/|^)\.\.\//)
1821 err_am "`$full' should not contain a `..' component";
1824 # Make sure object is removed by `make mostlyclean'.
1825 $compile_clean_files{$object} = MOSTLY_CLEAN;
1826 # If we have a libtool object then we also must remove
1828 if ($object =~ /\.lo$/)
1830 (my $xobj = $object) =~ s,lo$,\$(OBJEXT),;
1831 $compile_clean_files{$xobj} = MOSTLY_CLEAN;
1833 # Remove any libtool object in this directory.
1834 $libtool_clean_directories{$directory} = 1;
1837 push (@dep_list, require_build_directory ($directory));
1839 # If we're generating dependencies, we also want
1840 # to make sure that the appropriate subdir of the
1841 # .deps directory is created.
1843 require_build_directory ($directory . '/$(DEPDIR)'))
1844 unless option 'no-dependencies';
1847 &pretty_print_rule ($object . ':', "\t", @dep_list)
1848 if scalar @dep_list > 0;
1851 # Transform .o or $o file into .P file (for automatic
1853 if ($lang && $lang->autodep ne 'no')
1855 my $depfile = $object;
1856 $depfile =~ s/\.([^.]*)$/.P$1/;
1857 $depfile =~ s/\$\(OBJEXT\)$/o/;
1858 $dep_files{dirname ($depfile) . '/$(DEPDIR)/'
1859 . basename ($depfile)} = 1;
1868 # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
1869 # $OBJ, $PARENT, $TOPPARENT, $WHERE, %TRANSFORM)
1870 # ---------------------------------------------------------------------------
1871 # Define an _OBJECTS variable for a _SOURCES variable (or subvariable)
1874 # $VAR is the name of the _SOURCES variable
1875 # $OBJVAR is the name of the _OBJECTS variable if known (otherwise
1876 # it will be generated and returned).
1877 # $NODEFINE is a boolean: if true, $OBJVAR will not be defined (but
1878 # work done to determine the linker will be).
1879 # $ONE_FILE is the canonical (transformed) name of object to build
1880 # $OBJ is the object extension (i.e. either `.o' or `.lo').
1881 # $TOPPARENT is the _SOURCES variable being processed.
1882 # $WHERE context into which this definition is done
1883 # %TRANSFORM extra arguments to pass to file_contents when producing
1886 # Result is a pair ($LINKER, $OBJVAR):
1887 # $LINKER is a boolean, true if a linker is needed to deal with the objects
1888 sub define_objects_from_sources ($$$$$$$%)
1890 my ($var, $objvar, $nodefine, $one_file,
1891 $obj, $topparent, $where, %transform) = @_;
1893 my $needlinker = "";
1895 transform_variable_recursively
1896 ($var, $objvar, 'am__objects', $nodefine, $where,
1897 # The transform code to run on each filename.
1899 my ($subvar, $val, $cond, $full_cond) = @_;
1900 my @trans = handle_single_transform ($subvar, $topparent,
1901 $one_file, $obj, $val,
1903 $needlinker = "true" if @trans;
1911 # handle_source_transform ($CANON_TARGET, $TARGET, $OBJEXT, $WHERE, %TRANSFORM)
1912 # -----------------------------------------------------------------------------
1913 # Handle SOURCE->OBJECT transform for one program or library.
1915 # canonical (transformed) name of target to build
1916 # actual target of object to build
1917 # object extension (i.e. either `.o' or `$o'.
1918 # location of the source variable
1919 # extra arguments to pass to file_contents when producing rules
1920 # Return result is name of linker variable that must be used.
1921 # Empty return means just use `LINK'.
1922 sub handle_source_transform ($$$$%)
1924 # one_file is canonical name. unxformed is given name. obj is
1926 my ($one_file, $unxformed, $obj, $where, %transform) = @_;
1930 # No point in continuing if _OBJECTS is defined.
1931 return if reject_var ($one_file . '_OBJECTS',
1932 $one_file . '_OBJECTS should not be defined');
1937 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1938 'dist_EXTRA_', 'nodist_EXTRA_')
1940 my $varname = $prefix . $one_file . "_SOURCES";
1941 my $var = var $varname;
1944 # We are going to define _OBJECTS variables using the prefix.
1945 # Then we glom them all together. So we can't use the null
1946 # prefix here as we need it later.
1947 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
1949 # Keep track of which prefixes we saw.
1950 $used_pfx{$xpfx} = 1
1951 unless $prefix =~ /EXTRA_/;
1953 push @sources, "\$($varname)";
1954 push @dist_sources, shadow_unconditionally ($varname, $where)
1955 unless (option ('no-dist') || $prefix =~ /^nodist_/);
1958 define_objects_from_sources ($varname,
1959 $xpfx . $one_file . '_OBJECTS',
1960 $prefix =~ /EXTRA_/,
1961 $one_file, $obj, $varname, $where,
1962 DIST_SOURCE => ($prefix !~ /^nodist_/),
1967 $linker ||= &resolve_linker (%linkers_used);
1970 my @keys = sort keys %used_pfx;
1971 if (scalar @keys == 0)
1973 # The default source for libfoo.la is libfoo.c, but for
1974 # backward compatibility we first look at libfoo_la.c
1975 my $old_default_source = "$one_file.c";
1976 (my $default_source = $unxformed) =~ s,(\.[^./\\]*)?$,.c,;
1977 if ($old_default_source ne $default_source
1978 && (rule $old_default_source
1979 || rule '$(srcdir)/' . $old_default_source
1980 || rule '${srcdir}/' . $old_default_source
1981 || -f $old_default_source))
1983 my $loc = $where->clone;
1985 msg ('obsolete', $loc,
1986 "the default source for `$unxformed' has been changed "
1987 . "to `$default_source'.\n(Using `$old_default_source' for "
1988 . "backward compatibility.)");
1989 $default_source = $old_default_source;
1991 # If a rule exists to build this source with a $(srcdir)
1992 # prefix, use that prefix in our variables too. This is for
1993 # the sake of BSD Make.
1994 if (rule '$(srcdir)/' . $default_source
1995 || rule '${srcdir}/' . $default_source)
1997 $default_source = '$(srcdir)/' . $default_source;
2000 &define_variable ($one_file . "_SOURCES", $default_source, $where);
2001 push (@sources, $default_source);
2002 push (@dist_sources, $default_source);
2006 handle_single_transform ($one_file . '_SOURCES',
2007 $one_file . '_SOURCES',
2009 $default_source, %transform);
2010 $linker ||= &resolve_linker (%linkers_used);
2011 define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @result);
2015 @keys = map { '$(' . $_ . $one_file . '_OBJECTS)' } @keys;
2016 define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @keys);
2019 # If we want to use `LINK' we must make sure it is defined.
2029 # handle_lib_objects ($XNAME, $VAR)
2030 # ---------------------------------
2031 # Special-case ALLOCA and LIBOBJS substitutions in _LDADD or _LIBADD variables.
2032 # Also, generate _DEPENDENCIES variable if appropriate.
2034 # transformed name of object being built, or empty string if no object
2035 # name of _LDADD/_LIBADD-type variable to examine
2036 # Returns 1 if LIBOBJS seen, 0 otherwise.
2037 sub handle_lib_objects
2039 my ($xname, $varname) = @_;
2041 my $var = var ($varname);
2042 prog_error "handle_lib_objects: `$varname' undefined"
2044 prog_error "handle_lib_objects: unexpected variable name `$varname'"
2045 unless $varname =~ /^(.*)(?:LIB|LD)ADD$/;
2046 my $prefix = $1 || 'AM_';
2048 my $seen_libobjs = 0;
2051 transform_variable_recursively
2052 ($varname, $xname . '_DEPENDENCIES', 'am__DEPENDENCIES',
2054 # Transformation function, run on each filename.
2056 my ($subvar, $val, $cond, $full_cond) = @_;
2060 # Skip -lfoo and -Ldir silently; these are explicitly allowed.
2061 if ($val !~ /^-[lL]/ &&
2062 # Skip -dlopen and -dlpreopen; these are explicitly allowed
2063 # for Libtool libraries or programs. (Actually we are a bit
2064 # laxest here since this code also applies to non-libtool
2065 # libraries or programs, for which -dlopen and -dlopreopen
2066 # are pure non-sence. Diagnosting this doesn't seems very
2067 # important: the developer will quickly get complaints from
2069 $val !~ /^-dl(?:pre)?open$/ &&
2070 # Only get this error once.
2074 # FIXME: should display a stack of nested variables
2075 # as context when $var != $subvar.
2076 err_var ($var, "linker flags such as `$val' belong in "
2077 . "`${prefix}LDFLAGS");
2081 elsif ($val !~ /^\@.*\@$/)
2083 # Assume we have a file of some sort, and output it into the
2084 # dependency variable. Autoconf substitutions are not output;
2085 # rarely is a new dependency substituted into e.g. foo_LDADD
2086 # -- but bad things (e.g. -lX11) are routinely substituted.
2087 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2088 # and handled specially below.
2091 elsif ($val =~ /^\@(LT)?LIBOBJS\@$/)
2093 handle_LIBOBJS ($subvar, $cond, $1);
2097 elsif ($val =~ /^\@(LT)?ALLOCA\@$/)
2099 handle_ALLOCA ($subvar, $cond, $1);
2108 return $seen_libobjs;
2111 sub handle_LIBOBJS ($$$)
2113 my ($var, $cond, $lt) = @_;
2115 my $myobjext = ($1 ? 'l' : '') . 'o';
2117 $var->requires_variables ("\@${lt}LIBOBJS\@ used", $lt . 'LIBOBJS')
2118 if ! keys %libsources;
2120 foreach my $iter (keys %libsources)
2122 if ($iter =~ /\.[cly]$/)
2124 &saw_extension ($&);
2125 &saw_extension ('.c');
2128 if ($iter =~ /\.h$/)
2130 require_file_with_macro ($cond, $var, FOREIGN, $iter);
2132 elsif ($iter ne 'alloca.c')
2134 my $rewrite = $iter;
2135 $rewrite =~ s/\.c$/.P$myobjext/;
2136 $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
2137 $rewrite = "^" . quotemeta ($iter) . "\$";
2138 # Only require the file if it is not a built source.
2139 my $bs = var ('BUILT_SOURCES');
2140 if (! $bs || ! grep (/$rewrite/, $bs->value_as_list_recursive))
2142 require_file_with_macro ($cond, $var, FOREIGN, $iter);
2148 sub handle_ALLOCA ($$$)
2150 my ($var, $cond, $lt) = @_;
2151 my $myobjext = ($lt ? 'l' : '') . 'o';
2153 $var->requires_variables ("\@${lt}ALLOCA\@ used", $lt . 'ALLOCA');
2154 $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
2155 require_file_with_macro ($cond, $var, FOREIGN, 'alloca.c');
2156 &saw_extension ('c');
2159 # Canonicalize the input parameter
2163 $string =~ tr/A-Za-z0-9_\@/_/c;
2167 # Canonicalize a name, and check to make sure the non-canonical name
2168 # is never used. Returns canonical name. Arguments are name and a
2169 # list of suffixes to check for.
2170 sub check_canonical_spelling
2172 my ($name, @suffixes) = @_;
2174 my $xname = &canonicalize ($name);
2175 if ($xname ne $name)
2177 foreach my $xt (@suffixes)
2179 reject_var ("$name$xt", "use `$xname$xt', not `$name$xt'");
2189 # Set up the compile suite.
2190 sub handle_compile ()
2193 unless $get_object_extension_was_run;
2196 my $default_includes = '';
2197 if (! option 'nostdinc')
2199 $default_includes = ' -I. -I$(srcdir)';
2201 my $var = var 'CONFIG_HEADER';
2204 foreach my $hdr (split (' ', $var->variable_value))
2206 $default_includes .= ' -I' . dirname ($hdr);
2211 my (@mostly_rms, @dist_rms);
2212 foreach my $item (sort keys %compile_clean_files)
2214 if ($compile_clean_files{$item} == MOSTLY_CLEAN)
2216 push (@mostly_rms, "\t-rm -f $item");
2218 elsif ($compile_clean_files{$item} == DIST_CLEAN)
2220 push (@dist_rms, "\t-rm -f $item");
2224 prog_error 'invalid entry in %compile_clean_files';
2228 my ($coms, $vars, $rules) =
2229 &file_contents_internal (1, "$libdir/am/compile.am",
2230 new Automake::Location,
2231 ('DEFAULT_INCLUDES' => $default_includes,
2232 'MOSTLYRMS' => join ("\n", @mostly_rms),
2233 'DISTRMS' => join ("\n", @dist_rms)));
2234 $output_vars .= $vars;
2235 $output_rules .= "$coms$rules";
2237 # Check for automatic de-ANSI-fication.
2238 if (option 'ansi2knr')
2240 my ($ansi2knr_filename, $ansi2knr_where) = @{option 'ansi2knr'};
2241 my $ansi2knr_dir = '';
2243 require_variables ($ansi2knr_where, "option `ansi2knr' is used",
2244 TRUE, "ANSI2KNR", "U");
2246 # topdir is where ansi2knr should be.
2247 if ($ansi2knr_filename eq 'ansi2knr')
2249 # Only require ansi2knr files if they should appear in
2251 require_file ($ansi2knr_where, FOREIGN,
2252 'ansi2knr.c', 'ansi2knr.1');
2254 # ansi2knr needs to be built before subdirs, so unshift it.
2255 unshift (@all, '$(ANSI2KNR)');
2259 $ansi2knr_dir = dirname ($ansi2knr_filename);
2262 $output_rules .= &file_contents ('ansi2knr',
2263 new Automake::Location,
2264 'ANSI2KNR-DIR' => $ansi2knr_dir);
2271 # Handle libtool rules.
2274 return unless var ('LIBTOOL');
2276 # Libtool requires some files, but only at top level.
2277 # (Starting with Libtool 2.0 we do not have to bother. These
2278 # requirements are done with AC_REQUIRE_AUX_FILE.)
2279 require_conf_file_with_macro (TRUE, 'LIBTOOL', FOREIGN, @libtool_files)
2280 if $relative_dir eq '.' && ! $libtool_new_api;
2283 foreach my $item (sort keys %libtool_clean_directories)
2285 my $dir = ($item eq '.') ? '' : "$item/";
2286 # .libs is for Unix, _libs for DOS.
2287 push (@libtool_rms, "\t-rm -rf ${dir}.libs ${dir}_libs");
2290 check_user_variables 'LIBTOOLFLAGS';
2292 # Output the libtool compilation rules.
2293 $output_rules .= &file_contents ('libtool',
2294 new Automake::Location,
2295 LTRMS => join ("\n", @libtool_rms));
2298 # handle_programs ()
2299 # ------------------
2300 # Handle C programs.
2303 my @proglist = &am_install_var ('progs', 'PROGRAMS',
2304 'bin', 'sbin', 'libexec', 'pkglib',
2306 return if ! @proglist;
2308 my $seen_global_libobjs =
2309 var ('LDADD') && &handle_lib_objects ('', 'LDADD');
2311 foreach my $pair (@proglist)
2313 my ($where, $one_file) = @$pair;
2315 my $seen_libobjs = 0;
2316 my $obj = get_object_extension '.$(OBJEXT)';
2318 # Strip any $(EXEEXT) suffix the user might have added, or this
2319 # will confuse &handle_source_transform and &check_canonical_spelling.
2320 # We'll add $(EXEEXT) back later anyway.
2321 $one_file =~ s/\$\(EXEEXT\)$//;
2323 # Canonicalize names and check for misspellings.
2324 my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2325 '_SOURCES', '_OBJECTS',
2328 $where->push_context ("while processing program `$one_file'");
2329 $where->set (INTERNAL->get);
2331 my $linker = &handle_source_transform ($xname, $one_file, $obj, $where,
2332 NONLIBTOOL => 1, LIBTOOL => 0);
2334 if (var ($xname . "_LDADD"))
2336 $seen_libobjs = &handle_lib_objects ($xname, $xname . '_LDADD');
2340 # User didn't define prog_LDADD override. So do it.
2341 &define_variable ($xname . '_LDADD', '$(LDADD)', $where);
2343 # This does a bit too much work. But we need it to
2344 # generate _DEPENDENCIES when appropriate.
2347 $seen_libobjs = &handle_lib_objects ($xname, 'LDADD');
2351 reject_var ($xname . '_LIBADD',
2352 "use `${xname}_LDADD', not `${xname}_LIBADD'");
2354 set_seen ($xname . '_DEPENDENCIES');
2355 set_seen ($xname . '_LDFLAGS');
2357 # Determine program to use for link.
2358 my $xlink = &define_per_target_linker_variable ($linker, $xname);
2360 # If the resulting program lies into a subdirectory,
2361 # make sure this directory will exist.
2362 my $dirstamp = require_build_directory_maybe ($one_file);
2364 $output_rules .= &file_contents ('program',
2366 PROGRAM => $one_file,
2369 DIRSTAMP => $dirstamp,
2370 EXEEXT => '$(EXEEXT)');
2372 if ($seen_libobjs || $seen_global_libobjs)
2374 if (var ($xname . '_LDADD'))
2376 &check_libobjs_sources ($xname, $xname . '_LDADD');
2378 elsif (var ('LDADD'))
2380 &check_libobjs_sources ($xname, 'LDADD');
2387 # handle_libraries ()
2388 # -------------------
2390 sub handle_libraries
2392 my @liblist = &am_install_var ('libs', 'LIBRARIES',
2393 'lib', 'pkglib', 'noinst', 'check');
2394 return if ! @liblist;
2396 my @prefix = am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2401 my $var = rvar ($prefix[0] . '_LIBRARIES');
2402 $var->requires_variables ('library used', 'RANLIB');
2405 &define_variable ('AR', 'ar', INTERNAL);
2406 &define_variable ('ARFLAGS', 'cru', INTERNAL);
2408 foreach my $pair (@liblist)
2410 my ($where, $onelib) = @$pair;
2412 my $seen_libobjs = 0;
2413 # Check that the library fits the standard naming convention.
2414 my $bn = basename ($onelib);
2415 if ($bn !~ /^lib.*\.a$/)
2417 $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.a/;
2418 my $suggestion = dirname ($onelib) . "/$bn";
2419 $suggestion =~ s|^\./||g;
2420 msg ('error-gnu/warn', $where,
2421 "`$onelib' is not a standard library name\n"
2422 . "did you mean `$suggestion'?")
2425 $where->push_context ("while processing library `$onelib'");
2426 $where->set (INTERNAL->get);
2428 my $obj = get_object_extension '.$(OBJEXT)';
2430 # Canonicalize names and check for misspellings.
2431 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2432 '_OBJECTS', '_DEPENDENCIES',
2435 if (! var ($xlib . '_AR'))
2437 &define_variable ($xlib . '_AR', '$(AR) $(ARFLAGS)', $where);
2440 # Generate support for conditional object inclusion in
2442 if (var ($xlib . '_LIBADD'))
2444 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2451 &define_variable ($xlib . "_LIBADD", '', $where);
2454 reject_var ($xlib . '_LDADD',
2455 "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
2457 # Make sure we at look at this.
2458 set_seen ($xlib . '_DEPENDENCIES');
2460 &handle_source_transform ($xlib, $onelib, $obj, $where,
2461 NONLIBTOOL => 1, LIBTOOL => 0);
2463 # If the resulting library lies into a subdirectory,
2464 # make sure this directory will exist.
2465 my $dirstamp = require_build_directory_maybe ($onelib);
2467 $output_rules .= &file_contents ('library',
2471 DIRSTAMP => $dirstamp);
2475 if (var ($xlib . '_LIBADD'))
2477 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2484 # handle_ltlibraries ()
2485 # ---------------------
2486 # Handle shared libraries.
2487 sub handle_ltlibraries
2489 my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2490 'noinst', 'lib', 'pkglib', 'check');
2491 return if ! @liblist;
2493 my @prefix = am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2498 my $var = rvar ($prefix[0] . '_LTLIBRARIES');
2499 $var->requires_variables ('Libtool library used', 'LIBTOOL');
2504 my %liblocations = (); # Location (in Makefile.am) of each library.
2506 foreach my $key (@prefix)
2508 # Get the installation directory of each library.
2509 (my $dir = $key) =~ s/^nobase_//;
2510 my $var = rvar ($key . '_LTLIBRARIES');
2512 # We reject libraries which are installed in several places
2513 # in the same condition, because we can only specify one
2515 $var->traverse_recursively
2518 my ($var, $val, $cond, $full_cond) = @_;
2519 my $hcond = $full_cond->human;
2520 my $where = $var->rdef ($cond)->location;
2521 # A library cannot be installed in different directory
2522 # in overlapping conditions.
2523 if (exists $instconds{$val})
2526 $instconds{$val}->ambiguous_p ($val, $full_cond);
2530 error ($where, $msg, partial => 1);
2532 my $dirtxt = "installed in `$dir'";
2533 $dirtxt = "built for `$dir'"
2534 if $dir eq 'EXTRA' || $dir eq 'noinst' || $dir eq 'check';
2536 $full_cond->true ? "" : " in condition $hcond";
2538 error ($where, "`$val' should be $dirtxt$dircond ...",
2541 my $hacond = $acond->human;
2542 my $adir = $instdirs{$val}{$acond};
2543 my $adirtxt = "installed in `$adir'";
2544 $adirtxt = "built for `$adir'"
2545 if ($adir eq 'EXTRA' || $adir eq 'noinst'
2546 || $adir eq 'check');
2547 my $adircond = $acond->true ? "" : " in condition $hacond";
2549 my $onlyone = ($dir ne $adir) ?
2550 ("\nLibtool libraries can be built for only one "
2551 . "destination.") : "";
2553 error ($liblocations{$val}{$acond},
2554 "... and should also be $adirtxt$adircond.$onlyone");
2560 $instconds{$val} = new Automake::DisjConditions;
2562 $instdirs{$val}{$full_cond} = $dir;
2563 $liblocations{$val}{$full_cond} = $where;
2564 $instconds{$val} = $instconds{$val}->merge ($full_cond);
2570 skip_ac_subst => 1);
2573 foreach my $pair (@liblist)
2575 my ($where, $onelib) = @$pair;
2577 my $seen_libobjs = 0;
2578 my $obj = get_object_extension '.lo';
2580 # Canonicalize names and check for misspellings.
2581 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2582 '_SOURCES', '_OBJECTS',
2585 # Check that the library fits the standard naming convention.
2586 my $libname_rx = '^lib.*\.la';
2587 my $ldvar = var ("${xlib}_LDFLAGS") || var ('AM_LDFLAGS');
2588 my $ldvar2 = var ('LDFLAGS');
2589 if (($ldvar && grep (/-module/, $ldvar->value_as_list_recursive))
2590 || ($ldvar2 && grep (/-module/, $ldvar2->value_as_list_recursive)))
2592 # Relax name checking for libtool modules.
2593 $libname_rx = '\.la';
2596 my $bn = basename ($onelib);
2597 if ($bn !~ /$libname_rx$/)
2599 my $type = 'library';
2600 if ($libname_rx eq '\.la')
2602 $bn =~ s/^(lib|)(.*?)(?:\.[^.]*)?$/$1$2.la/;
2607 $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.la/;
2609 my $suggestion = dirname ($onelib) . "/$bn";
2610 $suggestion =~ s|^\./||g;
2611 msg ('error-gnu/warn', $where,
2612 "`$onelib' is not a standard libtool $type name\n"
2613 . "did you mean `$suggestion'?")
2616 $where->push_context ("while processing Libtool library `$onelib'");
2617 $where->set (INTERNAL->get);
2619 # Make sure we look at these.
2620 set_seen ($xlib . '_LDFLAGS');
2621 set_seen ($xlib . '_DEPENDENCIES');
2623 # Generate support for conditional object inclusion in
2625 if (var ($xlib . '_LIBADD'))
2627 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2634 &define_variable ($xlib . "_LIBADD", '', $where);
2637 reject_var ("${xlib}_LDADD",
2638 "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
2641 my $linker = &handle_source_transform ($xlib, $onelib, $obj, $where,
2642 NONLIBTOOL => 0, LIBTOOL => 1);
2644 # Determine program to use for link.
2645 my $xlink = &define_per_target_linker_variable ($linker, $xlib);
2647 my $rpathvar = "am_${xlib}_rpath";
2648 my $rpath = "\$($rpathvar)";
2649 foreach my $rcond ($instconds{$onelib}->conds)
2652 if ($instdirs{$onelib}{$rcond} eq 'EXTRA'
2653 || $instdirs{$onelib}{$rcond} eq 'noinst'
2654 || $instdirs{$onelib}{$rcond} eq 'check')
2656 # It's an EXTRA_ library, so we can't specify -rpath,
2657 # because we don't know where the library will end up.
2658 # The user probably knows, but generally speaking automake
2659 # doesn't -- and in fact configure could decide
2660 # dynamically between two different locations.
2665 $val = ('-rpath $(' . $instdirs{$onelib}{$rcond} . 'dir)');
2669 # If $rcond is true there is only one condition and
2670 # there is no point defining an helper variable.
2675 define_pretty_variable ($rpathvar, $rcond, INTERNAL, $val);
2679 # If the resulting library lies into a subdirectory,
2680 # make sure this directory will exist.
2681 my $dirstamp = require_build_directory_maybe ($onelib);
2683 # Remember to cleanup .libs/ in this directory.
2684 my $dirname = dirname $onelib;
2685 $libtool_clean_directories{$dirname} = 1;
2687 $output_rules .= &file_contents ('ltlibrary',
2689 LTLIBRARY => $onelib,
2690 XLTLIBRARY => $xlib,
2693 DIRSTAMP => $dirstamp);
2696 if (var ($xlib . '_LIBADD'))
2698 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2704 # See if any _SOURCES variable were misspelled.
2707 # It is ok if the user sets this particular variable.
2708 set_seen 'AM_LDFLAGS';
2710 foreach my $primary ('SOURCES', 'LIBADD', 'LDADD', 'LDFLAGS', 'DEPENDENCIES')
2712 foreach my $var (variables $primary)
2714 my $varname = $var->name;
2715 # A configure variable is always legitimate.
2716 next if exists $configure_vars{$varname};
2718 for my $cond ($var->conditions->conds)
2720 $varname =~ /^(?:nobase_)?(?:dist_|nodist_)?(.*)_[[:alnum:]]+$/;
2721 msg_var ('syntax', $var, "variable `$varname' is defined but no"
2722 . " program or\nlibrary has `$1' as canonic name"
2723 . " (possible typo)")
2724 unless $var->rdef ($cond)->seen;
2734 # NOTE we no longer automatically clean SCRIPTS, because it is
2735 # useful to sometimes distribute scripts verbatim. This happens
2736 # e.g. in Automake itself.
2737 &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2738 'bin', 'sbin', 'libexec', 'pkgdata',
2745 ## ------------------------ ##
2746 ## Handling Texinfo files. ##
2747 ## ------------------------ ##
2749 # ($OUTFILE, $VFILE, @CLEAN_FILES)
2750 # &scan_texinfo_file ($FILENAME)
2751 # ------------------------------
2752 # $OUTFILE - name of the info file produced by $FILENAME.
2753 # $VFILE - name of the version.texi file used (undef if none).
2754 # @CLEAN_FILES - list of byproducts (indexes etc.)
2755 sub scan_texinfo_file ($)
2757 my ($filename) = @_;
2759 # Some of the following extensions are always created, no matter
2760 # whether indexes are used or not. Other (like cps, fns, ... pgs)
2761 # are only created when they are used. We used to scan $FILENAME
2762 # for their use, but that is not enough: they could be used in
2763 # included files. We can't scan included files because we don't
2764 # know the include path. Therefore we always erase these files, no
2765 # matter whether they are used or not.
2767 # (tmp is only created if an @macro is used and a certain e-TeX
2768 # feature is not available.)
2769 my %clean_suffixes =
2770 map { $_ => 1 } (qw(aux log toc tmp
2776 pg pgs)); # grep 'new.*index' texinfo.tex
2778 my $texi = new Automake::XFile "< $filename";
2779 verb "reading $filename";
2781 my ($outfile, $vfile);
2782 while ($_ = $texi->getline)
2784 if (/^\@setfilename +(\S+)/)
2786 # Honor only the first @setfilename. (It's possible to have
2787 # more occurrences later if the manual shows examples of how
2788 # to use @setfilename...)
2792 if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
2794 error ("$filename:$.",
2795 "output `$outfile' has unrecognized extension");
2799 # A "version.texi" file is actually any file whose name matches
2801 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2806 # Try to find new or unused indexes.
2808 # Creating a new category of index.
2809 elsif (/^\@def(code)?index (\w+)/)
2811 $clean_suffixes{$2} = 1;
2812 $clean_suffixes{"$2s"} = 1;
2815 # Merging an index into an another.
2816 elsif (/^\@syn(code)?index (\w+) (\w+)/)
2818 delete $clean_suffixes{"$2s"};
2819 $clean_suffixes{"$3s"} = 1;
2826 err_am "`$filename' missing \@setfilename";
2830 my $infobase = basename ($filename);
2831 $infobase =~ s/\.te?xi(nfo)?$//;
2832 return ($outfile, $vfile,
2833 map { "$infobase.$_" } (sort keys %clean_suffixes));
2837 # ($DIRSTAMP, @CLEAN_FILES)
2838 # output_texinfo_build_rules ($SOURCE, $DEST, $INSRC, @DEPENDENCIES)
2839 # ------------------------------------------------------------------
2840 # SOURCE - the source Texinfo file
2841 # DEST - the destination Info file
2842 # INSRC - wether DEST should be built in the source tree
2843 # DEPENDENCIES - known dependencies
2844 sub output_texinfo_build_rules ($$$@)
2846 my ($source, $dest, $insrc, @deps) = @_;
2848 # Split `a.texi' into `a' and `.texi'.
2849 my ($spfx, $ssfx) = ($source =~ /^(.*?)(\.[^.]*)?$/);
2850 my ($dpfx, $dsfx) = ($dest =~ /^(.*?)(\.[^.]*)?$/);
2855 # We can output two kinds of rules: the "generic" rules use Make
2856 # suffix rules and are appropriate when $source and $dest do not lie
2857 # in a sub-directory; the "specific" rules are needed in the other
2860 # The former are output only once (this is not really apparent here,
2861 # but just remember that some logic deeper in Automake will not
2862 # output the same rule twice); while the later need to be output for
2863 # each Texinfo source.
2866 my $sdir = dirname $source;
2867 if ($sdir eq '.' && dirname ($dest) eq '.')
2870 $makeinfoflags = '-I $(srcdir)';
2875 $makeinfoflags = "-I $sdir -I \$(srcdir)/$sdir";
2878 # A directory can contain two kinds of info files: some built in the
2879 # source tree, and some built in the build tree. The rules are
2880 # different in each case. However we cannot output two different
2881 # set of generic rules. Because in-source builds are more usual, we
2882 # use generic rules in this case and fall back to "specific" rules
2883 # for build-dir builds. (It should not be a problem to invert this
2885 $generic = 0 unless $insrc;
2887 # We cannot use a suffix rule to build info files with an empty
2888 # extension. Otherwise we would output a single suffix inference
2889 # rule, with separate dependencies, as in
2893 # foo.info: foo.texi
2895 # which confuse Solaris make. (See the Autoconf manual for
2896 # details.) Therefore we use a specific rule in this case. This
2897 # applies to info files only (dvi and pdf files always have an
2899 my $generic_info = ($generic && $dsfx) ? 1 : 0;
2901 # If the resulting file lie into a subdirectory,
2902 # make sure this directory will exist.
2903 my $dirstamp = require_build_directory_maybe ($dest);
2905 my $dipfx = ($insrc ? '$(srcdir)/' : '') . $dpfx;
2907 $output_rules .= file_contents ('texibuild',
2908 new Automake::Location,
2910 DEST_PREFIX => $dpfx,
2911 DEST_INFO_PREFIX => $dipfx,
2912 DEST_SUFFIX => $dsfx,
2913 DIRSTAMP => $dirstamp,
2914 GENERIC => $generic,
2915 GENERIC_INFO => $generic_info,
2917 MAKEINFOFLAGS => $makeinfoflags,
2920 SOURCE_INFO => ($generic_info
2922 SOURCE_REAL => $source,
2923 SOURCE_SUFFIX => $ssfx,
2925 return ($dirstamp, "$dpfx.dvi", "$dpfx.pdf", "$dpfx.ps", "$dpfx.html");
2930 # handle_texinfo_helper ($info_texinfos)
2931 # --------------------------------------
2932 # Handle all Texinfo source; helper for handle_texinfo.
2933 sub handle_texinfo_helper ($)
2935 my ($info_texinfos) = @_;
2936 my (@infobase, @info_deps_list, @texi_deps);
2941 # Build a regex matching user-cleaned files.
2942 my $d = var 'DISTCLEANFILES';
2943 my $c = var 'CLEANFILES';
2945 push @f, $d->value_as_list_recursive (inner_expand => 1) if $d;
2946 push @f, $c->value_as_list_recursive (inner_expand => 1) if $c;
2947 @f = map { s|[^A-Za-z_0-9*\[\]\-]|\\$&|g; s|\*|[^/]*|g; $_; } @f;
2948 my $user_cleaned_files = '^(?:' . join ('|', @f) . ')$';
2951 ($info_texinfos->value_as_list_recursive (inner_expand => 1))
2953 my $infobase = $texi;
2954 $infobase =~ s/\.(txi|texinfo|texi)$//;
2956 if ($infobase eq $texi)
2958 # FIXME: report line number.
2959 err_am "texinfo file `$texi' has unrecognized extension";
2963 push @infobase, $infobase;
2965 # If 'version.texi' is referenced by input file, then include
2966 # automatic versioning capability.
2967 my ($out_file, $vtexi, @clean_files) =
2968 scan_texinfo_file ("$relative_dir/$texi")
2970 push (@texi_cleans, @clean_files);
2972 # If the Texinfo source is in a subdirectory, create the
2973 # resulting info in this subdirectory. If it is in the current
2974 # directory, try hard to not prefix "./" because it breaks the
2976 my $outdir = dirname ($texi) . '/';
2977 $outdir = "" if $outdir eq './';
2978 $out_file = $outdir . $out_file;
2980 # Until Automake 1.6.3, .info files were built in the
2981 # source tree. This was an obstacle to the support of
2982 # non-distributed .info files, and non-distributed .texi
2985 # * Non-distributed .texi files is important in some packages
2986 # where .texi files are built at make time, probably using
2987 # other binaries built in the package itself, maybe using
2988 # tools or information found on the build host. Because
2989 # these files are not distributed they are always rebuilt
2990 # at make time; they should therefore not lie in the source
2991 # directory. One plan was to support this using
2992 # nodist_info_TEXINFOS or something similar. (Doing this
2993 # requires some sanity checks. For instance Automake should
2995 # dist_info_TEXINFO = foo.texi
2996 # nodist_foo_TEXINFO = included.texi
2997 # because a distributed file should never depend on a
2998 # non-distributed file.)
3000 # * If .texi files are not distributed, then .info files should
3001 # not be distributed either. There are also cases where one
3002 # want to distribute .texi files, but do not want to
3003 # distribute the .info files. For instance the Texinfo package
3004 # distributes the tool used to build these files; it would
3005 # be a waste of space to distribute them. It's not clear
3006 # which syntax we should use to indicate that .info files should
3007 # not be distributed. Akim Demaille suggested that eventually
3008 # we switch to a new syntax:
3009 # | Maybe we should take some inspiration from what's already
3010 # | done in the rest of Automake. Maybe there is too much
3011 # | syntactic sugar here, and you want
3012 # | nodist_INFO = bar.info
3013 # | dist_bar_info_SOURCES = bar.texi
3014 # | bar_texi_DEPENDENCIES = foo.texi
3015 # | with a bit of magic to have bar.info represent the whole
3016 # | bar*info set. That's a lot more verbose that the current
3017 # | situation, but it is # not new, hence the user has less
3020 # | But there is still too much room for meaningless specs:
3021 # | nodist_INFO = bar.info
3022 # | dist_bar_info_SOURCES = bar.texi
3023 # | dist_PS = bar.ps something-written-by-hand.ps
3024 # | nodist_bar_ps_SOURCES = bar.texi
3025 # | bar_texi_DEPENDENCIES = foo.texi
3026 # | here bar.texi is dist_ in line 2, and nodist_ in 4.
3028 # Back to the point, it should be clear that in order to support
3029 # non-distributed .info files, we need to build them in the
3030 # build tree, not in the source tree (non-distributed .texi
3031 # files are less of a problem, because we do not output build
3032 # rules for them). In Automake 1.7 .info build rules have been
3033 # largely cleaned up so that .info files get always build in the
3034 # build tree, even when distributed. The idea was that
3035 # (1) if during a VPATH build the .info file was found to be
3036 # absent or out-of-date (in the source tree or in the
3037 # build tree), Make would rebuild it in the build tree.
3038 # If an up-to-date source-tree of the .info file existed,
3039 # make would not rebuild it in the build tree.
3040 # (2) having two copies of .info files, one in the source tree
3041 # and one (newer) in the build tree is not a problem
3042 # because `make dist' always pick files in the build tree
3044 # However it turned out the be a bad idea for several reasons:
3045 # * Tru64, OpenBSD, and FreeBSD (not NetBSD) Make do not behave
3046 # like GNU Make on point (1) above. These implementations
3047 # of Make would always rebuild .info files in the build
3048 # tree, even if such files were up to date in the source
3049 # tree. Consequently, it was impossible to perform a VPATH
3050 # build of a package containing Texinfo files using these
3051 # Make implementations.
3052 # (Refer to the Autoconf Manual, section "Limitation of
3053 # Make", paragraph "VPATH", item "target lookup", for
3054 # an account of the differences between these
3056 # * The GNU Coding Standards require these files to be built
3057 # in the source-tree (when they are distributed, that is).
3058 # * Keeping a fresher copy of distributed files in the
3059 # build tree can be annoying during development because
3060 # - if the files is kept under CVS, you really want it
3061 # to be updated in the source tree
3062 # - it is confusing that `make distclean' does not erase
3063 # all files in the build tree.
3065 # Consequently, starting with Automake 1.8, .info files are
3066 # built in the source tree again. Because we still plan to
3067 # support non-distributed .info files at some point, we
3068 # have a single variable ($INSRC) that controls whether
3069 # the current .info file must be built in the source tree
3070 # or in the build tree. Actually this variable is switched
3071 # off for .info files that appear to be cleaned; this is
3072 # for backward compatibility with package such as Texinfo,
3073 # which do things like
3074 # info_TEXINFOS = texinfo.txi info-stnd.texi info.texi
3075 # DISTCLEANFILES = texinfo texinfo-* info*.info*
3076 # # Do not create info files for distribution.
3078 # in order not to distribute .info files.
3079 my $insrc = ($out_file =~ $user_cleaned_files) ? 0 : 1;
3081 my $soutdir = '$(srcdir)/' . $outdir;
3082 $outdir = $soutdir if $insrc;
3084 # If user specified file_TEXINFOS, then use that as explicit
3087 push (@texi_deps, "$soutdir$vtexi") if $vtexi;
3089 my $canonical = canonicalize ($infobase);
3090 if (var ($canonical . "_TEXINFOS"))
3092 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
3093 push_dist_common ('$(' . $canonical . '_TEXINFOS)');
3096 my ($dirstamp, @cfiles) =
3097 output_texinfo_build_rules ($texi, $out_file, $insrc, @texi_deps);
3098 push (@texi_cleans, @cfiles);
3100 push (@info_deps_list, $out_file);
3102 # If a vers*.texi file is needed, emit the rule.
3105 err_am ("`$vtexi', included in `$texi', "
3106 . "also included in `$versions{$vtexi}'")
3107 if defined $versions{$vtexi};
3108 $versions{$vtexi} = $texi;
3110 # We number the stamp-vti files. This is doable since the
3111 # actual names don't matter much. We only number starting
3112 # with the second one, so that the common case looks nice.
3113 my $vti = ($done ? $done : 'vti');
3116 # This is ugly, but it is our historical practice.
3117 if ($config_aux_dir_set_in_configure_ac)
3119 require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3124 require_file_with_macro (TRUE, 'info_TEXINFOS',
3125 FOREIGN, 'mdate-sh');
3129 if ($config_aux_dir_set_in_configure_ac)
3131 $conf_dir = "$am_config_aux_dir/";
3135 $conf_dir = '$(srcdir)/';
3137 $output_rules .= file_contents ('texi-vers',
3138 new Automake::Location,
3141 STAMPVTI => "${soutdir}stamp-$vti",
3142 VTEXI => "$soutdir$vtexi",
3144 DIRSTAMP => $dirstamp);
3148 # Handle location of texinfo.tex.
3149 my $need_texi_file = 0;
3151 if (var ('TEXINFO_TEX'))
3153 # The user defined TEXINFO_TEX so assume he knows what he is
3155 $texinfodir = ('$(srcdir)/'
3156 . dirname (variable_value ('TEXINFO_TEX')));
3158 elsif (option 'cygnus')
3160 $texinfodir = '$(top_srcdir)/../texinfo';
3161 define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex", INTERNAL);
3163 elsif ($config_aux_dir_set_in_configure_ac)
3165 $texinfodir = $am_config_aux_dir;
3166 define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex", INTERNAL);
3167 $need_texi_file = 2; # so that we require_conf_file later
3171 $texinfodir = '$(srcdir)';
3172 $need_texi_file = 1;
3174 define_variable ('am__TEXINFO_TEX_DIR', $texinfodir, INTERNAL);
3176 push (@dist_targets, 'dist-info');
3178 if (! option 'no-installinfo')
3180 # Make sure documentation is made and installed first. Use
3181 # $(INFO_DEPS), not 'info', because otherwise recursive makes
3182 # get run twice during "make all".
3183 unshift (@all, '$(INFO_DEPS)');
3186 define_files_variable ("DVIS", @infobase, 'dvi', INTERNAL);
3187 define_files_variable ("PDFS", @infobase, 'pdf', INTERNAL);
3188 define_files_variable ("PSS", @infobase, 'ps', INTERNAL);
3189 define_files_variable ("HTMLS", @infobase, 'html', INTERNAL);
3191 # This next isn't strictly needed now -- the places that look here
3192 # could easily be changed to look in info_TEXINFOS. But this is
3193 # probably better, in case noinst_TEXINFOS is ever supported.
3194 define_variable ("TEXINFOS", variable_value ('info_TEXINFOS'), INTERNAL);
3196 # Do some error checking. Note that this file is not required
3197 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3199 if ($need_texi_file && ! option 'no-texinfo.tex')
3201 if ($need_texi_file > 1)
3203 require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3208 require_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3213 return makefile_wrap ("", "\t ", @texi_cleans);
3219 # Handle all Texinfo source.
3220 sub handle_texinfo ()
3222 reject_var 'TEXINFOS', "`TEXINFOS' is an anachronism; use `info_TEXINFOS'";
3223 # FIXME: I think this is an obsolete future feature name.
3224 reject_var 'html_TEXINFOS', "HTML generation not yet supported";
3226 my $info_texinfos = var ('info_TEXINFOS');
3230 $texiclean = handle_texinfo_helper ($info_texinfos);
3232 $output_rules .= file_contents ('texinfos',
3233 new Automake::Location,
3234 TEXICLEAN => $texiclean,
3235 'LOCAL-TEXIS' => !!$info_texinfos);
3239 # Handle any man pages.
3240 sub handle_man_pages
3242 reject_var 'MANS', "`MANS' is an anachronism; use `man_MANS'";
3244 # Find all the sections in use. We do this by first looking for
3245 # "standard" sections, and then looking for any additional
3246 # sections used in man_MANS.
3247 my (%sections, %vlist);
3248 # We handle nodist_ for uniformity. man pages aren't distributed
3249 # by default so it isn't actually very important.
3250 foreach my $pfx ('', 'dist_', 'nodist_')
3252 # Add more sections as needed.
3253 foreach my $section ('0'..'9', 'n', 'l')
3255 my $varname = $pfx . 'man' . $section . '_MANS';
3258 $sections{$section} = 1;
3259 $varname = '$(' . $varname . ')';
3260 $vlist{$varname} = 1;
3262 &push_dist_common ($varname)
3267 my $varname = $pfx . 'man_MANS';
3268 my $var = var ($varname);
3271 foreach ($var->value_as_list_recursive)
3273 # A page like `foo.1c' goes into man1dir.
3274 if (/\.([0-9a-z])([a-z]*)$/)
3280 $varname = '$(' . $varname . ')';
3281 $vlist{$varname} = 1;
3282 &push_dist_common ($varname)
3287 return unless %sections;
3289 # Now for each section, generate an install and uninstall rule.
3290 # Sort sections so output is deterministic.
3291 foreach my $section (sort keys %sections)
3293 $output_rules .= &file_contents ('mans',
3294 new Automake::Location,
3295 SECTION => $section);
3298 my @mans = sort keys %vlist;
3299 $output_vars .= file_contents ('mans-vars',
3300 new Automake::Location,
3303 push (@all, '$(MANS)')
3304 unless option 'no-installman';
3307 # Handle DATA variables.
3310 &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3311 'data', 'dataroot', 'dvi', 'html', 'pdf', 'ps',
3312 'sysconf', 'sharedstate', 'localstate',
3313 'pkgdata', 'lisp', 'noinst', 'check');
3321 if (var ('SUBDIRS'))
3323 $output_rules .= ("tags-recursive:\n"
3324 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3325 # Never fail here if a subdir fails; it
3327 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3328 . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3330 push (@tag_deps, 'tags-recursive');
3331 &depend ('.PHONY', 'tags-recursive');
3333 $output_rules .= ("ctags-recursive:\n"
3334 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3335 # Never fail here if a subdir fails; it
3337 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3338 . " && \$(MAKE) \$(AM_MAKEFLAGS) ctags); \\\n"
3340 push (@ctag_deps, 'ctags-recursive');
3341 &depend ('.PHONY', 'ctags-recursive');
3344 if (&saw_sources_p (1)
3345 || var ('ETAGS_ARGS')
3349 foreach my $spec (@config_headers)
3351 my ($out, @ins) = split_config_file_spec ($spec);
3352 foreach my $in (@ins)
3354 # If the config header source is in this directory,
3356 push @config, basename ($in)
3357 if $relative_dir eq dirname ($in);
3360 $output_rules .= &file_contents ('tags',
3361 new Automake::Location,
3362 CONFIG => "@config",
3363 TAGSDIRS => "@tag_deps",
3364 CTAGSDIRS => "@ctag_deps");
3366 set_seen 'TAGS_DEPENDENCIES';
3368 elsif (reject_var ('TAGS_DEPENDENCIES',
3369 "doesn't make sense to define `TAGS_DEPENDENCIES'"
3370 . "without\nsources or `ETAGS_ARGS'"))
3375 # Every Makefile must define some sort of TAGS rule.
3376 # Otherwise, it would be possible for a top-level "make TAGS"
3377 # to fail because some subdirectory failed.
3378 $output_rules .= "tags: TAGS\nTAGS:\n\n";
3380 $output_rules .= "ctags: CTAGS\nCTAGS:\n\n";
3384 # Handle multilib support.
3387 if ($seen_multilib && $relative_dir eq '.')
3389 $output_rules .= &file_contents ('multilib', new Automake::Location);
3390 push (@all, 'all-multi');
3395 # user_phony_rule ($NAME)
3396 # -----------------------
3397 # Return false if rule $NAME does not exist. Otherwise,
3398 # declare it as phony, complete its definition (in case it is
3399 # conditional), and return its Automake::Rule instance.
3400 sub user_phony_rule ($)
3403 my $rule = rule $name;
3406 depend ('.PHONY', $name);
3407 # Define $NAME in all condition where it is not already defined,
3408 # so that it is always OK to depend on $NAME.
3409 for my $c ($rule->not_always_defined_in_cond (TRUE)->conds)
3411 Automake::Rule::define ($name, 'internal', RULE_AUTOMAKE,
3413 $output_rules .= $c->subst_string . "$name:\n";
3421 # &for_dist_common ($A, $B)
3422 # -------------------------
3423 # Subroutine for &handle_dist: sort files to dist.
3425 # We put README first because it then becomes easier to make a
3426 # Usenet-compliant shar file (in these, README must be first).
3428 # FIXME: do more ordering of files here.
3443 # Handle 'dist' target.
3446 # Substutions for distdit.am
3449 # Define DIST_SUBDIRS. This must always be done, regardless of the
3450 # no-dist setting: target like `distclean' or `maintainer-clean' use it.
3451 my $subdirs = var ('SUBDIRS');
3454 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3455 # to all possible directories, and use it. If DIST_SUBDIRS is
3456 # defined, just use it.
3458 # Note that we check DIST_SUBDIRS first on purpose, so that
3459 # we don't call has_conditional_contents for now reason.
3460 # (In the past one project used so many conditional subdirectories
3461 # that calling has_conditional_contents on SUBDIRS caused
3462 # automake to grow to 150Mb -- this should not happen with
3463 # the current implementation of has_conditional_contents,
3464 # but it's more efficient to avoid the call anyway.)
3465 if (var ('DIST_SUBDIRS'))
3468 elsif ($subdirs->has_conditional_contents)
3470 define_pretty_variable
3471 ('DIST_SUBDIRS', TRUE, INTERNAL,
3472 uniq ($subdirs->value_as_list_recursive));
3476 # We always define this because that is what `distclean'
3478 define_pretty_variable ('DIST_SUBDIRS', TRUE, INTERNAL,
3483 # The remaining definitions are only required when a dist target is used.
3484 return if option 'no-dist';
3486 # At least one of the archive formats must be enabled.
3487 if ($relative_dir eq '.')
3489 my $archive_defined = option 'no-dist-gzip' ? 0 : 1;
3490 $archive_defined ||=
3491 grep { option "dist-$_" } ('shar', 'zip', 'tarZ', 'bzip2');
3492 error (option 'no-dist-gzip',
3493 "no-dist-gzip specified but no dist-* specified, "
3494 . "at least one archive format must be enabled")
3495 unless $archive_defined;
3498 # Look for common files that should be included in distribution.
3499 # If the aux dir is set, and it does not have a Makefile.am, then
3500 # we check for these files there as well.
3502 if ($relative_dir eq '.'
3503 && $config_aux_dir_set_in_configure_ac)
3505 if (! &is_make_dir ($config_aux_dir))
3510 foreach my $cfile (@common_files)
3512 if (dir_has_case_matching_file ($relative_dir, $cfile)
3513 # The file might be absent, but if it can be built it's ok.
3516 &push_dist_common ($cfile);
3519 # Don't use `elsif' here because a file might meaningfully
3520 # appear in both directories.
3521 if ($check_aux && dir_has_case_matching_file ($config_aux_dir, $cfile))
3523 &push_dist_common ("$config_aux_dir/$cfile")
3527 # We might copy elements from $configure_dist_common to
3528 # %dist_common if we think we need to. If the file appears in our
3529 # directory, we would have discovered it already, so we don't
3530 # check that. But if the file is in a subdir without a Makefile,
3531 # we want to distribute it here if we are doing `.'. Ugly!
3532 if ($relative_dir eq '.')
3534 foreach my $file (split (' ' , $configure_dist_common))
3536 push_dist_common ($file)
3537 unless is_make_dir (dirname ($file));
3541 # Files to distributed. Don't use ->value_as_list_recursive
3542 # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3543 my @dist_common = split (' ', rvar ('DIST_COMMON')->variable_value);
3544 @dist_common = uniq (sort for_dist_common (@dist_common));
3545 variable_delete 'DIST_COMMON';
3546 define_pretty_variable ('DIST_COMMON', TRUE, INTERNAL, @dist_common);
3548 # Now that we've processed DIST_COMMON, disallow further attempts
3550 $handle_dist_run = 1;
3552 # Scan EXTRA_DIST to see if we need to distribute anything from a
3553 # subdir. If so, add it to the list. I didn't want to do this
3554 # originally, but there were so many requests that I finally
3556 my $extra_dist = var ('EXTRA_DIST');
3559 # FIXME: This should be fixed to work with conditions. That
3560 # will require only making the entries in %dist_dirs under the
3561 # appropriate condition. This is meaningful if the nature of
3562 # the distribution should depend upon the configure options
3564 foreach ($extra_dist->value_as_list_recursive (skip_ac_subst => 1))
3566 next unless s,/+[^/]+$,,;
3572 # We have to check DIST_COMMON for extra directories in case the
3573 # user put a source used in AC_OUTPUT into a subdir.
3574 my $topsrcdir = backname ($relative_dir);
3575 foreach (rvar ('DIST_COMMON')->value_as_list_recursive (skip_ac_subst => 1))
3577 s/\$\(top_srcdir\)/$topsrcdir/;
3579 # Strip any leading `./'.
3581 next unless s,/+[^/]+$,,;
3586 $transform{'DISTCHECK-HOOK'} = !! rule 'distcheck-hook';
3587 $transform{'GETTEXT'} = $seen_gettext && !$seen_gettext_external;
3589 # Prepend $(distdir) to each directory given.
3590 my %rewritten = map { '$(distdir)/' . "$_" => 1 } keys %dist_dirs;
3591 $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);
3593 # If the target `dist-hook' exists, make sure it is run. This
3594 # allows users to do random weird things to the distribution
3595 # before it is packaged up.
3596 push (@dist_targets, 'dist-hook')
3597 if user_phony_rule 'dist-hook';
3598 $transform{'DIST-TARGETS'} = join (' ', @dist_targets);
3600 my $flm = option ('filename-length-max');
3601 my $filename_filter = $flm ? '.' x $flm->[1] : '';
3603 $output_rules .= &file_contents ('distdir',
3604 new Automake::Location,
3606 FILENAME_FILTER => $filename_filter);
3610 # check_directory ($NAME, $WHERE)
3611 # -------------------------------
3612 # Ensure $NAME is a directory, and that it uses sane name.
3613 # Use $WHERE as a location in the diagnostic, if any.
3614 sub check_directory ($$)
3616 my ($dir, $where) = @_;
3618 error $where, "required directory $relative_dir/$dir does not exist"
3619 unless -d "$relative_dir/$dir";
3621 # If an `obj/' directory exists, BSD make will enter it before
3622 # reading `Makefile'. Hence the `Makefile' in the current directory
3628 # % cat obj/Makefile
3634 # % pmake # BSD make
3637 msg ('portability', $where,
3638 "naming a subdirectory `obj' causes troubles with BSD make")
3641 # `aux' is probably the most important of the following forbidden name,
3642 # since it's tempting to use it as an AC_CONFIG_AUX_DIR.
3643 msg ('portability', $where,
3644 "name `$dir' is reserved on W32 and DOS platforms")
3645 if grep (/^\Q$dir\E$/i, qw/aux lpt1 lpt2 lpt3 com1 com2 com3 com4 con prn/);
3648 # check_directories_in_var ($VARIABLE)
3649 # ------------------------------------
3650 # Recursively check all items in variables $VARIABLE as directories
3651 sub check_directories_in_var ($)
3654 $var->traverse_recursively
3657 my ($var, $val, $cond, $full_cond) = @_;
3658 check_directory ($val, $var->rdef ($cond)->location);
3662 skip_ac_subst => 1);
3665 # &handle_subdirs ()
3666 # ------------------
3667 # Handle subdirectories.
3668 sub handle_subdirs ()
3670 my $subdirs = var ('SUBDIRS');
3674 check_directories_in_var $subdirs;
3676 my $dsubdirs = var ('DIST_SUBDIRS');
3677 check_directories_in_var $dsubdirs
3680 $output_rules .= &file_contents ('subdirs', new Automake::Location);
3681 rvar ('RECURSIVE_TARGETS')->rdef (TRUE)->{'pretty'} = VAR_SORTED; # Gross!
3685 # ($REGEN, @DEPENDENCIES)
3688 # If aclocal.m4 creation is automated, return the list of its dependencies.
3689 sub scan_aclocal_m4 ()
3691 my $regen_aclocal = 0;
3693 set_seen 'CONFIG_STATUS_DEPENDENCIES';
3694 set_seen 'CONFIGURE_DEPENDENCIES';
3696 if (-f 'aclocal.m4')
3698 &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4', INTERNAL);
3700 my $aclocal = new Automake::XFile "< aclocal.m4";
3701 my $line = $aclocal->getline;
3702 $regen_aclocal = $line =~ 'generated automatically by aclocal';
3707 if (set_seen ('ACLOCAL_M4_SOURCES'))
3709 push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3710 msg_var ('obsolete', 'ACLOCAL_M4_SOURCES',
3711 "`ACLOCAL_M4_SOURCES' is obsolete.\n"
3712 . "It should be safe to simply remove it.");
3715 # Note that it might be possible that aclocal.m4 doesn't exist but
3716 # should be auto-generated. This case probably isn't very
3719 return ($regen_aclocal, @ac_deps);
3723 # Helper function for substitute_ac_subst_variables.
3724 sub substitute_ac_subst_variables_worker($)
3727 return "\@$token\@" if var $token;
3728 return "\${$token\}";
3731 # substitute_ac_subst_variables ($TEXT)
3732 # -------------------------------------
3733 # Replace any occurence of ${FOO} in $TEXT by @FOO@ if FOO is an AC_SUBST
3735 sub substitute_ac_subst_variables ($)
3738 $text =~ s/\${([^ \t=:+{}]+)}/&substitute_ac_subst_variables_worker ($1)/ge;
3743 # &prepend_srcdir (@INPUTS)
3744 # -------------------------
3745 # Prepend $(srcdir) or $(top_srcdir) to all @INPUTS. The idea is that
3746 # if an input file has a directory part the same as the current
3747 # directory, then the directory part is simply replaced by $(srcdir).
3748 # But if the directory part is different, then $(top_srcdir) is
3750 sub prepend_srcdir (@)
3755 foreach my $single (@inputs)
3757 if (dirname ($single) eq $relative_dir)
3759 push (@newinputs, '$(srcdir)/' . basename ($single));
3763 push (@newinputs, '$(top_srcdir)/' . $single);
3770 # rewrite_inputs_into_dependencies ($OUTPUT, @INPUTS)
3771 # ---------------------------------------------------
3772 # Compute a list of dependencies appropriate for the rebuild
3774 # AC_CONFIG_FILES($OUTPUT:$INPUT[0]:$INPUTS[1]:...)
3775 # Also distribute $INPUTs which are not build by another AC_CONFIG_FILES.
3776 sub rewrite_inputs_into_dependencies ($@)
3778 my ($file, @inputs) = @_;
3783 # We cannot create dependencies on shell variables.
3784 next if (substitute_ac_subst_variables $i) =~ /\$/;
3786 if (exists $ac_config_files_location{$i})
3788 my $di = dirname $i;
3789 if ($di eq $relative_dir)
3793 # In the top-level Makefile we do not use $(top_builddir), because
3794 # we are already there, and since the targets are built without
3795 # a $(top_builddir), it helps BSD Make to match them with
3797 elsif ($relative_dir ne '.')
3799 $i = '$(top_builddir)/' . $i;
3804 msg ('error', $ac_config_files_location{$file},
3805 "required file `$i' not found")
3806 unless $i =~ /\$/ || exists $output_files{$i} || -f $i;
3807 ($i) = prepend_srcdir ($i);
3808 push_dist_common ($i);
3817 # &handle_configure ($MAKEFILE_AM, $MAKEFILE_IN, $MAKEFILE, @INPUTS)
3818 # ------------------------------------------------------------------
3819 # Handle remaking and configure stuff.
3820 # We need the name of the input file, to do proper remaking rules.
3821 sub handle_configure ($$$@)
3823 my ($makefile_am, $makefile_in, $makefile, @inputs) = @_;
3825 prog_error 'empty @inputs'
3828 my ($rel_makefile_am, $rel_makefile_in) = prepend_srcdir ($makefile_am,
3830 my $rel_makefile = basename $makefile;
3832 my $colon_infile = ':' . join (':', @inputs);
3833 $colon_infile = '' if $colon_infile eq ":$makefile.in";
3834 my @rewritten = rewrite_inputs_into_dependencies ($makefile, @inputs);
3835 my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4;
3836 define_pretty_variable ('am__aclocal_m4_deps', TRUE, INTERNAL,
3837 @configure_deps, @aclocal_m4_deps,
3838 '$(top_srcdir)/' . $configure_ac);
3839 my @configuredeps = ('$(am__aclocal_m4_deps)', '$(CONFIGURE_DEPENDENCIES)');
3840 push @configuredeps, '$(ACLOCAL_M4)' if -f 'aclocal.m4';
3841 define_pretty_variable ('am__configure_deps', TRUE, INTERNAL,
3844 $output_rules .= file_contents
3846 new Automake::Location,
3847 MAKEFILE => $rel_makefile,
3848 'MAKEFILE-DEPS' => "@rewritten",
3849 'CONFIG-MAKEFILE' => ($relative_dir eq '.') ? '$@' : '$(subdir)/$@',
3850 'MAKEFILE-IN' => $rel_makefile_in,
3851 'MAKEFILE-IN-DEPS' => "@include_stack",
3852 'MAKEFILE-AM' => $rel_makefile_am,
3853 STRICTNESS => global_option 'cygnus'
3854 ? 'cygnus' : $strictness_name,
3855 'USE-DEPS' => global_option 'no-dependencies'
3856 ? ' --ignore-deps' : '',
3857 'MAKEFILE-AM-SOURCES' => "$makefile$colon_infile",
3858 'REGEN-ACLOCAL-M4' => $regen_aclocal_m4);
3860 if ($relative_dir eq '.')
3862 &push_dist_common ('acconfig.h')
3866 # If we have a configure header, require it.
3868 my @distclean_config;
3869 foreach my $spec (@config_headers)
3872 # $CONFIG_H_PATH: config.h from top level.
3873 my ($config_h_path, @ins) = split_config_file_spec ($spec);
3874 my $config_h_dir = dirname ($config_h_path);
3876 # If the header is in the current directory we want to build
3877 # the header here. Otherwise, if we're at the topmost
3878 # directory and the header's directory doesn't have a
3879 # Makefile, then we also want to build the header.
3880 if ($relative_dir eq $config_h_dir
3881 || ($relative_dir eq '.' && ! &is_make_dir ($config_h_dir)))
3883 my ($cn_sans_dir, $stamp_dir);
3884 if ($relative_dir eq $config_h_dir)
3886 $cn_sans_dir = basename ($config_h_path);
3891 $cn_sans_dir = $config_h_path;
3892 if ($config_h_dir eq '.')
3898 $stamp_dir = $config_h_dir . '/';
3902 # This will also distribute all inputs.
3903 @ins = rewrite_inputs_into_dependencies ($config_h_path, @ins);
3905 # Cannot define rebuild rules for filenames with shell variables.
3906 next if (substitute_ac_subst_variables $config_h_path) =~ /\$/;
3908 # Header defined in this directory.
3910 if (-f $config_h_path . '.top')
3912 push (@files, "$cn_sans_dir.top");
3914 if (-f $config_h_path . '.bot')
3916 push (@files, "$cn_sans_dir.bot");
3919 push_dist_common (@files);
3921 # For now, acconfig.h can only appear in the top srcdir.
3922 if (-f 'acconfig.h')
3924 push (@files, '$(top_srcdir)/acconfig.h');
3927 my $stamp = "${stamp_dir}stamp-h${hdr_index}";
3929 file_contents ('remake-hdr',
3930 new Automake::Location,
3932 CONFIG_H => $cn_sans_dir,
3933 CONFIG_HIN => $ins[0],
3934 CONFIG_H_DEPS => "@ins",
3935 CONFIG_H_PATH => $config_h_path,
3938 push @distclean_config, $cn_sans_dir, $stamp;
3942 $output_rules .= file_contents ('clean-hdr',
3943 new Automake::Location,
3944 FILES => "@distclean_config")
3945 if @distclean_config;
3947 # Distribute and define mkinstalldirs only if it is already present
3948 # in the package, for backward compatibility (some people may still
3949 # use $(mkinstalldirs)).
3950 my $mkidpath = "$config_aux_dir/mkinstalldirs";
3953 # Use require_file so that any existing script gets updated
3954 # by --force-missing.
3955 require_conf_file ($mkidpath, FOREIGN, 'mkinstalldirs');
3956 define_variable ('mkinstalldirs',
3957 "\$(SHELL) $am_config_aux_dir/mkinstalldirs", INTERNAL);
3961 # Use $(install_sh), not $(mkdir_p) because the latter requires
3962 # at least one argument, and $(mkinstalldirs) used to work
3963 # even without arguments (e.g. $(mkinstalldirs) $(conditional_dir)).
3964 define_variable ('mkinstalldirs', '$(install_sh) -d', INTERNAL);
3967 reject_var ('CONFIG_HEADER',
3968 "`CONFIG_HEADER' is an anachronism; now determined "
3969 . "automatically\nfrom `$configure_ac'");
3972 foreach my $spec (@config_headers)
3974 my ($out, @ins) = split_config_file_spec ($spec);
3975 # Generate CONFIG_HEADER define.
3976 if ($relative_dir eq dirname ($out))
3978 push @config_h, basename ($out);
3982 push @config_h, "\$(top_builddir)/$out";
3985 define_variable ("CONFIG_HEADER", "@config_h", INTERNAL)
3988 # Now look for other files in this directory which must be remade
3989 # by config.status, and generate rules for them.
3990 my @actual_other_files = ();
3991 foreach my $lfile (@other_input_files)
3995 if ($lfile =~ /^([^:]*):(.*)$/)
3997 # This is the ":" syntax of AC_OUTPUT.
3999 @inputs = split (':', $2);
4005 @inputs = $file . '.in';
4008 # Automake files should not be stored in here, but in %MAKE_LIST.
4009 prog_error ("$lfile in \@other_input_files\n"
4010 . "\@other_input_files = (@other_input_files)")
4011 if -f $file . '.am';
4013 my $local = basename ($file);
4015 # Make sure the dist directory for each input file is created.
4016 # We only have to do this at the topmost level though. This
4017 # is a bit ugly but it easier than spreading out the logic,
4018 # especially in cases like AC_OUTPUT(foo/out:bar/in), where
4019 # there is no Makefile in bar/.
4020 if ($relative_dir eq '.')
4024 $dist_dirs{dirname ($_)} = 1;
4028 # We skip files that aren't in this directory. However, if
4029 # the file's directory does not have a Makefile, and we are
4030 # currently doing `.', then we create a rule to rebuild the
4031 # file in the subdir.
4032 my $fd = dirname ($file);
4033 if ($fd ne $relative_dir)
4035 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
4045 my @rewritten_inputs = rewrite_inputs_into_dependencies ($file, @inputs);
4047 # Cannot output rules for shell variables.
4048 next if (substitute_ac_subst_variables $local) =~ /\$/;
4050 $output_rules .= ($local . ': '
4051 . '$(top_builddir)/config.status '
4052 . "@rewritten_inputs\n"
4054 . 'cd $(top_builddir) && '
4055 . '$(SHELL) ./config.status '
4056 . ($relative_dir eq '.' ? '' : '$(subdir)/')
4059 push (@actual_other_files, $local);
4062 # For links we should clean destinations and distribute sources.
4063 foreach my $spec (@config_links)
4065 my ($link, $file) = split /:/, $spec;
4066 # Some people do AC_CONFIG_LINKS($computed). We only handle
4067 # the DEST:SRC form.
4069 my $where = $ac_config_files_location{$link};
4071 # Skip destinations that contain shell variables.
4072 if ((substitute_ac_subst_variables $link) !~ /\$/)
4074 # We skip links that aren't in this directory. However, if
4075 # the link's directory does not have a Makefile, and we are
4076 # currently doing `.', then we add the link to CONFIG_CLEAN_FILES
4077 # in `.'s Makefile.in.
4078 my $local = basename ($link);
4079 my $fd = dirname ($link);
4080 if ($fd ne $relative_dir)
4082 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
4091 push @actual_other_files, $local if $local;
4094 # Do not process sources that contain shell variables.
4095 if ((substitute_ac_subst_variables $file) !~ /\$/)
4097 my $fd = dirname ($file);
4099 # Make sure the dist directory for each input file is created.
4100 # We only have to do this at the topmost level though.
4101 if ($relative_dir eq '.')
4103 $dist_dirs{$fd} = 1;
4106 # We distribute files that are in this directory.
4107 # At the top-level (`.') we also distribute files whose
4108 # directory does not have a Makefile.
4109 if (($fd eq $relative_dir)
4110 || ($relative_dir eq '.' && ! &is_make_dir ($fd)))
4112 # The following will distribute $file as a side-effect when
4113 # it is appropriate (i.e., when $file is not already an output).
4114 # We do not need the result, just the side-effect.
4115 rewrite_inputs_into_dependencies ($link, $file);
4120 # These files get removed by "make distclean".
4121 define_pretty_variable ('CONFIG_CLEAN_FILES', TRUE, INTERNAL,
4122 @actual_other_files);
4128 my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
4129 'oldinclude', 'pkginclude',
4133 next unless $_->[1] =~ /\..*$/;
4134 &saw_extension ($&);
4140 return if ! $seen_gettext || $relative_dir ne '.';
4142 my $subdirs = var 'SUBDIRS';
4146 err_ac "AM_GNU_GETTEXT used but SUBDIRS not defined";
4150 # Perform some sanity checks to help users get the right setup.
4151 # We disable these tests when po/ doesn't exist in order not to disallow
4152 # unusual gettext setups.
4157 # | 1) If a package doesn't have a directory po/ at top level, it
4158 # | will likely have multiple po/ directories in subpackages.
4160 # | 2) It is useful to warn for the absence of intl/ if AM_GNU_GETTEXT
4161 # | is used without 'external'. It is also useful to warn for the
4162 # | presence of intl/ if AM_GNU_GETTEXT([external]) is used. Both
4163 # | warnings apply only to the usual layout of packages, therefore
4164 # | they should both be disabled if no po/ directory is found at
4169 my @subdirs = $subdirs->value_as_list_recursive;
4171 msg_var ('syntax', $subdirs,
4172 "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
4173 if ! grep ($_ eq 'po', @subdirs);
4175 # intl/ is not required when AM_GNU_GETTEXT is called with
4176 # the `external' option.
4177 msg_var ('syntax', $subdirs,
4178 "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
4179 if (! $seen_gettext_external
4180 && ! grep ($_ eq 'intl', @subdirs));
4182 # intl/ should not be used with AM_GNU_GETTEXT([external])
4183 msg_var ('syntax', $subdirs,
4184 "`intl' should not be in SUBDIRS when "
4185 . "AM_GNU_GETTEXT([external]) is used")
4186 if ($seen_gettext_external && grep ($_ eq 'intl', @subdirs));
4189 require_file ($ac_gettext_location, GNU, 'ABOUT-NLS');
4192 # Handle footer elements.
4195 # NOTE don't use define_pretty_variable here, because
4196 # $contents{...} is already defined.
4197 $output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n\n"
4198 if variable_value ('SOURCES');
4200 reject_rule ('.SUFFIXES',
4201 "use variable `SUFFIXES', not target `.SUFFIXES'");
4203 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
4204 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
4205 # anything else, by sticking it right after the default: target.
4206 $output_header .= ".SUFFIXES:\n";
4207 my $suffixes = var 'SUFFIXES';
4208 my @suffixes = Automake::Rule::suffixes;
4209 if (@suffixes || $suffixes)
4211 # Make sure SUFFIXES has unique elements. Sort them to ensure
4212 # the output remains consistent. However, $(SUFFIXES) is
4213 # always at the start of the list, unsorted. This is done
4214 # because make will choose rules depending on the ordering of
4215 # suffixes, and this lets the user have some control. Push
4216 # actual suffixes, and not $(SUFFIXES). Some versions of make
4217 # do not like variable substitutions on the .SUFFIXES line.
4218 my @user_suffixes = ($suffixes
4219 ? $suffixes->value_as_list_recursive : ());
4221 my %suffixes = map { $_ => 1 } @suffixes;
4222 delete @suffixes{@user_suffixes};
4224 $output_header .= (".SUFFIXES: "
4225 . join (' ', @user_suffixes, sort keys %suffixes)
4229 $output_trailer .= file_contents ('footer', new Automake::Location);
4233 # Generate `make install' rules.
4234 sub handle_install ()
4236 $output_rules .= &file_contents
4238 new Automake::Location,
4239 maybe_BUILT_SOURCES => (set_seen ('BUILT_SOURCES')
4240 ? (" \$(BUILT_SOURCES)\n"
4241 . "\t\$(MAKE) \$(AM_MAKEFLAGS)")
4243 'installdirs-local' => (user_phony_rule 'installdirs-local'
4244 ? ' installdirs-local' : ''),
4245 am__installdirs => variable_value ('am__installdirs') || '');
4249 # Deal with all and all-am.
4252 my ($makefile) = @_;
4256 # Put this at the beginning for the sake of non-GNU makes. This
4257 # is still wrong if these makes can run parallel jobs. But it is
4259 unshift (@all, basename ($makefile));
4261 foreach my $spec (@config_headers)
4263 my ($out, @ins) = split_config_file_spec ($spec);
4264 push (@all, basename ($out))
4265 if dirname ($out) eq $relative_dir;
4268 # Install `all' hooks.
4269 push (@all, "all-local")
4270 if user_phony_rule "all-local";
4272 &pretty_print_rule ("all-am:", "\t\t", @all);
4273 &depend ('.PHONY', 'all-am', 'all');
4278 my @local_headers = ();
4279 push @local_headers, '$(BUILT_SOURCES)'
4280 if var ('BUILT_SOURCES');
4281 foreach my $spec (@config_headers)
4283 my ($out, @ins) = split_config_file_spec ($spec);
4284 push @local_headers, basename ($out)
4285 if dirname ($out) eq $relative_dir;
4290 # We need to make sure config.h is built before we recurse.
4291 # We also want to make sure that built sources are built
4292 # before any ordinary `all' targets are run. We can't do this
4293 # by changing the order of dependencies to the "all" because
4294 # that breaks when using parallel makes. Instead we handle
4295 # things explicitly.
4296 $output_all .= ("all: @local_headers"
4298 . '$(MAKE) $(AM_MAKEFLAGS) '
4299 . (var ('SUBDIRS') ? 'all-recursive' : 'all-am')
4304 $output_all .= "all: " . (var ('SUBDIRS')
4305 ? 'all-recursive' : 'all-am') . "\n\n";
4310 # &do_check_merge_target ()
4311 # -------------------------
4312 # Handle check merge target specially.
4313 sub do_check_merge_target ()
4315 # Include user-defined local form of target.
4316 push @check_tests, 'check-local'
4317 if user_phony_rule 'check-local';
4319 # In --cygnus mode, check doesn't depend on all.
4320 if (option 'cygnus')
4322 # Just run the local check rules.
4323 pretty_print_rule ('check-am:', "\t\t", @check);
4327 # The check target must depend on the local equivalent of
4328 # `all', to ensure all the primary targets are built. Then it
4329 # must build the local check rules.
4330 $output_rules .= "check-am: all-am\n";
4331 pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4335 pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4339 depend '.PHONY', 'check', 'check-am';
4340 # Handle recursion. We have to honor BUILT_SOURCES like for `all:'.
4341 $output_rules .= ("check: "
4342 . (var ('BUILT_SOURCES')
4343 ? "\$(BUILT_SOURCES)\n\t\$(MAKE) \$(AM_MAKEFLAGS) "
4345 . (var ('SUBDIRS') ? 'check-recursive' : 'check-am')
4349 # handle_clean ($MAKEFILE)
4350 # ------------------------
4351 # Handle all 'clean' targets.
4352 sub handle_clean ($)
4354 my ($makefile) = @_;
4356 # Clean the files listed in user variables if they exist.
4357 $clean_files{'$(MOSTLYCLEANFILES)'} = MOSTLY_CLEAN
4358 if var ('MOSTLYCLEANFILES');
4359 $clean_files{'$(CLEANFILES)'} = CLEAN
4360 if var ('CLEANFILES');
4361 $clean_files{'$(DISTCLEANFILES)'} = DIST_CLEAN
4362 if var ('DISTCLEANFILES');
4363 $clean_files{'$(MAINTAINERCLEANFILES)'} = MAINTAINER_CLEAN
4364 if var ('MAINTAINERCLEANFILES');
4366 # Built sources are automatically removed by maintainer-clean.
4367 $clean_files{'$(BUILT_SOURCES)'} = MAINTAINER_CLEAN
4368 if var ('BUILT_SOURCES');
4370 # Compute a list of "rm"s to run for each target.
4371 my %rms = (MOSTLY_CLEAN, [],
4374 MAINTAINER_CLEAN, []);
4376 foreach my $file (keys %clean_files)
4378 my $when = $clean_files{$file};
4379 prog_error 'invalid entry in %clean_files'
4380 unless exists $rms{$when};
4382 my $rm = "rm -f $file";
4383 # If file is a variable, make sure when don't call `rm -f' without args.
4384 $rm ="test -z \"$file\" || $rm"
4385 if ($file =~ /^\s*\$(\(.*\)|\{.*\})\s*$/);
4387 push @{$rms{$when}}, "\t-$rm\n";
4390 $output_rules .= &file_contents
4392 new Automake::Location,
4393 MOSTLYCLEAN_RMS => join ('', sort @{$rms{&MOSTLY_CLEAN}}),
4394 CLEAN_RMS => join ('', sort @{$rms{&CLEAN}}),
4395 DISTCLEAN_RMS => join ('', sort @{$rms{&DIST_CLEAN}}),
4396 MAINTAINER_CLEAN_RMS => join ('', sort @{$rms{&MAINTAINER_CLEAN}}),
4397 MAKEFILE => basename $makefile,
4402 # &target_cmp ($A, $B)
4403 # --------------------
4404 # Subroutine for &handle_factored_dependencies to let `.PHONY' and
4405 # other `.TARGETS' be last.
4408 return 0 if $a eq $b;
4410 my $a1 = substr ($a, 0, 1);
4411 my $b1 = substr ($b, 0, 1);
4414 return -1 if $b1 eq '.';
4415 return 1 if $a1 eq '.';
4421 # &handle_factored_dependencies ()
4422 # --------------------------------
4423 # Handle everything related to gathered targets.
4424 sub handle_factored_dependencies
4427 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4428 'uninstall-exec-local', 'uninstall-exec-hook',
4429 'uninstall-dvi-local',
4430 'uninstall-html-local',
4431 'uninstall-info-local',
4432 'uninstall-pdf-local',
4433 'uninstall-ps-local')
4437 reject_rule ($utarg, "use `$x', not `$utarg'");
4440 reject_rule ('install-local',
4441 "use `install-data-local' or `install-exec-local', "
4442 . "not `install-local'");
4444 # Install the -local hooks.
4445 foreach (keys %dependencies)
4447 # Hooks are installed on the -am targets.
4449 depend ("$_-am", "$_-local")
4450 if user_phony_rule "$_-local";
4453 # Install the -hook hooks.
4454 # FIXME: Why not be as liberal as we are with -local hooks?
4455 foreach ('install-exec', 'install-data', 'uninstall')
4457 if (user_phony_rule "$_-hook")
4459 $actions{"$_-am"} .=
4460 ("\t\@\$(NORMAL_INSTALL)\n"
4461 . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
4462 depend ('.MAKE', "$_-am");
4466 # All the required targets are phony.
4467 depend ('.PHONY', keys %required_targets);
4469 # Actually output gathered targets.
4470 foreach (sort target_cmp keys %dependencies)
4472 # If there is nothing about this guy, skip it.
4474 unless (@{$dependencies{$_}}
4476 || $required_targets{$_});
4478 # Define gathered targets in undefined conditions.
4479 # FIXME: Right now we must handle .PHONY as an exception,
4480 # because people write things like
4481 # .PHONY: myphonytarget
4482 # to append dependencies. This would not work if Automake
4483 # refrained from defining its own .PHONY target as it does
4484 # with other overridden targets.
4485 # Likewise for `.MAKE'.
4486 my @undefined_conds = (TRUE,);
4487 if ($_ ne '.PHONY' && $_ ne '.MAKE')
4490 Automake::Rule::define ($_, 'internal',
4491 RULE_AUTOMAKE, TRUE, INTERNAL);
4493 my @uniq_deps = uniq (sort @{$dependencies{$_}});
4494 foreach my $cond (@undefined_conds)
4496 my $condstr = $cond->subst_string;
4497 &pretty_print_rule ("$condstr$_:", "$condstr\t", @uniq_deps);
4498 $output_rules .= $actions{$_} if defined $actions{$_};
4499 $output_rules .= "\n";
4505 # &handle_tests_dejagnu ()
4506 # ------------------------
4507 sub handle_tests_dejagnu
4509 push (@check_tests, 'check-DEJAGNU');
4510 $output_rules .= file_contents ('dejagnu', new Automake::Location);
4514 # Handle TESTS variable and other checks.
4517 if (option 'dejagnu')
4519 &handle_tests_dejagnu;
4523 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4525 reject_var ($c, "`$c' defined but `dejagnu' not in "
4526 . "`AUTOMAKE_OPTIONS'");
4532 push (@check_tests, 'check-TESTS');
4533 $output_rules .= &file_contents ('check', new Automake::Location);
4537 # Handle Emacs Lisp.
4538 sub handle_emacs_lisp
4540 my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4543 return if ! @elfiles;
4545 define_pretty_variable ('am__ELFILES', TRUE, INTERNAL,
4546 map { $_->[1] } @elfiles);
4547 define_pretty_variable ('am__ELCFILES', TRUE, INTERNAL,
4548 '$(am__ELFILES:.el=.elc)');
4549 # This one can be overridden by users.
4550 define_pretty_variable ('ELCFILES', TRUE, INTERNAL, '$(LISP:.el=.elc)');
4552 push @all, '$(ELCFILES)';
4554 require_variables ($elfiles[0][0], "Emacs Lisp sources seen", TRUE,
4555 'EMACS', 'lispdir');
4556 require_conf_file ($elfiles[0][0], FOREIGN, 'elisp-comp');
4557 &define_variable ('elisp_comp', "$am_config_aux_dir/elisp-comp", INTERNAL);
4563 my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4565 return if ! @pyfiles;
4567 require_variables ($pyfiles[0][0], "Python sources seen", TRUE, 'PYTHON');
4568 require_conf_file ($pyfiles[0][0], FOREIGN, 'py-compile');
4569 &define_variable ('py_compile', "$am_config_aux_dir/py-compile", INTERNAL);
4575 my @sourcelist = &am_install_var ('-candist',
4577 'java', 'noinst', 'check');
4578 return if ! @sourcelist;
4580 my @prefix = am_primary_prefixes ('JAVA', 1,
4581 'java', 'noinst', 'check');
4584 foreach my $curs (@prefix)
4587 if $curs eq 'EXTRA';
4589 err_var "${curs}_JAVA", "multiple _JAVA primaries in use"
4595 push (@all, 'class' . $dir . '.stamp');
4599 # Handle some of the minor options.
4600 sub handle_minor_options
4602 if (option 'readme-alpha')
4604 if ($relative_dir eq '.')
4606 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4608 msg ('error-gnits', $package_version_location,
4609 "version `$package_version' doesn't follow " .
4612 if (defined $1 && -f 'README-alpha')
4614 # This means we have an alpha release. See
4615 # GNITS_VERSION_PATTERN for details.
4616 push_dist_common ('README-alpha');
4622 ################################################################
4624 # ($OUTPUT, @INPUTS)
4625 # &split_config_file_spec ($SPEC)
4626 # -------------------------------
4627 # Decode the Autoconf syntax for config files (files, headers, links
4629 sub split_config_file_spec ($)
4632 my ($output, @inputs) = split (/:/, $spec);
4634 push @inputs, "$output.in"
4637 return ($output, @inputs);
4641 # locate_am (@POSSIBLE_SOURCES)
4642 # -----------------------------
4643 # AC_CONFIG_FILES allow specifications such as Makefile:top.in:mid.in:bot.in
4644 # This functions returns the first *.in file for which a *.am exists.
4645 # It returns undef otherwise.
4650 foreach my $file (@rest)
4652 if (($file =~ /^(.*)\.in$/) && -f "$1.am")
4663 # &scan_autoconf_config_files ($WHERE, $CONFIG-FILES)
4664 # ---------------------------------------------------
4665 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4667 sub scan_autoconf_config_files ($$)
4669 my ($where, $config_files) = @_;
4671 # Look at potential Makefile.am's.
4672 foreach (split ' ', $config_files)
4674 # Must skip empty string for Perl 4.
4675 next if $_ eq "\\" || $_ eq '';
4677 # Handle $local:$input syntax.
4678 my ($local, @rest) = split (/:/);
4679 @rest = ("$local.in",) unless @rest;
4680 my $input = locate_am @rest;
4683 # We have a file that automake should generate.
4684 $make_list{$input} = join (':', ($local, @rest));
4688 # We have a file that automake should cause to be
4689 # rebuilt, but shouldn't generate itself.
4690 push (@other_input_files, $_);
4692 $ac_config_files_location{$local} = $where;
4697 # &scan_autoconf_traces ($FILENAME)
4698 # ---------------------------------
4699 sub scan_autoconf_traces ($)
4701 my ($filename) = @_;
4703 # Macros to trace, with their minimal number of arguments.
4705 # IMPORTANT: If you add a macro here, you should also add this macro
4706 # ========= to Automake-preselection in autoconf/lib/autom4te.in.
4708 AC_CANONICAL_BUILD => 0,
4709 AC_CANONICAL_HOST => 0,
4710 AC_CANONICAL_TARGET => 0,
4711 AC_CONFIG_AUX_DIR => 1,
4712 AC_CONFIG_FILES => 1,
4713 AC_CONFIG_HEADERS => 1,
4714 AC_CONFIG_LINKS => 1,
4717 AC_REQUIRE_AUX_FILE => 1,
4719 AM_AUTOMAKE_VERSION => 1,
4720 AM_CONDITIONAL => 2,
4721 AM_ENABLE_MULTILIB => 0,
4722 AM_GNU_GETTEXT => 0,
4723 AM_INIT_AUTOMAKE => 0,
4724 AM_MAINTAINER_MODE => 0,
4725 AM_PROG_CC_C_O => 0,
4726 LT_SUPPORTED_TAG => 1,
4727 _LT_AC_TAGCONFIG => 0,
4733 my $traces = ($ENV{AUTOCONF} || 'autoconf') . " ";
4735 # Use a separator unlikely to be used, not `:', the default, which
4736 # has a precise meaning for AC_CONFIG_FILES and so on.
4737 $traces .= join (' ',
4738 map { "--trace=$_" . ':\$f:\$l::\$n::\${::}%' }
4741 my $tracefh = new Automake::XFile ("$traces $filename |");
4742 verb "reading $traces";
4744 while ($_ = $tracefh->getline)
4747 my ($here, @args) = split (/::/);
4748 my $where = new Automake::Location $here;
4749 my $macro = $args[0];
4751 prog_error ("unrequested trace `$macro'")
4752 unless exists $traced{$macro};
4754 # Skip and diagnose malformed calls.
4755 if ($#args < $traced{$macro})
4757 msg ('syntax', $where, "not enough arguments for $macro");
4761 # Alphabetical ordering please.
4762 if ($macro eq 'AC_CANONICAL_BUILD')
4764 if ($seen_canonical <= AC_CANONICAL_BUILD)
4766 $seen_canonical = AC_CANONICAL_BUILD;
4767 $canonical_location = $where;
4770 elsif ($macro eq 'AC_CANONICAL_HOST')
4772 if ($seen_canonical <= AC_CANONICAL_HOST)
4774 $seen_canonical = AC_CANONICAL_HOST;
4775 $canonical_location = $where;
4778 elsif ($macro eq 'AC_CANONICAL_TARGET')
4780 $seen_canonical = AC_CANONICAL_TARGET;
4781 $canonical_location = $where;
4783 elsif ($macro eq 'AC_CONFIG_AUX_DIR')
4785 if ($seen_init_automake)
4787 error ($where, "AC_CONFIG_AUX_DIR must be called before "
4788 . "AM_INIT_AUTOMAKE...", partial => 1);
4789 error ($seen_init_automake, "... AM_INIT_AUTOMAKE called here");
4791 $config_aux_dir = $args[1];
4792 $config_aux_dir_set_in_configure_ac = 1;
4793 $relative_dir = '.';
4794 check_directory ($config_aux_dir, $where);
4796 elsif ($macro eq 'AC_CONFIG_FILES')
4798 # Look at potential Makefile.am's.
4799 scan_autoconf_config_files ($where, $args[1]);
4801 elsif ($macro eq 'AC_CONFIG_HEADERS')
4803 foreach my $spec (split (' ', $args[1]))
4805 my ($dest, @src) = split (':', $spec);
4806 $ac_config_files_location{$dest} = $where;
4807 push @config_headers, $spec;
4810 elsif ($macro eq 'AC_CONFIG_LINKS')
4812 foreach my $spec (split (' ', $args[1]))
4814 my ($dest, $src) = split (':', $spec);
4815 $ac_config_files_location{$dest} = $where;
4816 push @config_links, $spec;
4819 elsif ($macro eq 'AC_INIT')
4821 if (defined $args[2])
4823 $package_version = $args[2];
4824 $package_version_location = $where;
4827 elsif ($macro eq 'AC_LIBSOURCE')
4829 $libsources{$args[1]} = $here;
4831 elsif ($macro eq 'AC_SUBST')
4833 # Just check for alphanumeric in AC_SUBST. If you do
4834 # AC_SUBST(5), then too bad.
4835 $configure_vars{$args[1]} = $where
4836 if $args[1] =~ /^\w+$/;
4838 elsif ($macro eq 'AM_AUTOMAKE_VERSION')
4841 "version mismatch. This is Automake $VERSION,\n" .
4842 "but the definition used by this AM_INIT_AUTOMAKE\n" .
4843 "comes from Automake $args[1]. You should recreate\n" .
4844 "aclocal.m4 with aclocal and run automake again.\n",
4845 # $? = 63 is used to indicate version mismatch to missing.
4847 if $VERSION ne $args[1];
4849 $seen_automake_version = 1;
4851 elsif ($macro eq 'AM_CONDITIONAL')
4853 $configure_cond{$args[1]} = $where;
4855 elsif ($macro eq 'AM_ENABLE_MULTILIB')
4857 $seen_multilib = $where;
4859 elsif ($macro eq 'AM_GNU_GETTEXT')
4861 $seen_gettext = $where;
4862 $ac_gettext_location = $where;
4863 $seen_gettext_external = grep ($_ eq 'external', @args);
4865 elsif ($macro eq 'AM_INIT_AUTOMAKE')
4867 $seen_init_automake = $where;
4868 if (defined $args[2])
4870 $package_version = $args[2];
4871 $package_version_location = $where;
4873 elsif (defined $args[1])
4876 if (process_global_option_list ($where,
4877 split (' ', $args[1])));
4880 elsif ($macro eq 'AM_MAINTAINER_MODE')
4882 $seen_maint_mode = $where;
4884 elsif ($macro eq 'AM_PROG_CC_C_O')
4886 $seen_cc_c_o = $where;
4888 elsif ($macro eq 'AC_REQUIRE_AUX_FILE')
4890 # Only remember the first time a file is required.
4891 $required_aux_file{$args[1]} = $where
4892 unless exists $required_aux_file{$args[1]};
4894 elsif ($macro eq 'm4_include'
4895 || $macro eq 'm4_sinclude'
4896 || $macro eq 'sinclude')
4898 # Some modified versions of Autoconf don't use
4899 # forzen files. Consequently it's possible that we see all
4900 # m4_include's performed during Autoconf's startup.
4901 # Obviously we don't want to distribute Autoconf's files
4902 # so we skip absolute filenames here.
4903 push @configure_deps, '$(top_srcdir)/' . $args[1]
4904 unless $here =~ m,^(?:\w:)?[\\/],;
4905 # Keep track of the greatest timestamp.
4908 my $mtime = mtime $args[1];
4909 $configure_deps_greatest_timestamp = $mtime
4910 if $mtime > $configure_deps_greatest_timestamp;
4913 elsif ($macro eq 'LT_SUPPORTED_TAG')
4915 $libtool_tags{$args[1]} = 1;
4916 $libtool_new_api = 1;
4918 elsif ($macro eq '_LT_AC_TAGCONFIG')
4920 # _LT_AC_TAGCONFIG is an old macro present in Libtool 1.5.
4921 # We use it to detect whether tags are supported. Our
4922 # prefered interface is LT_SUPPORTED_TAG, but it was
4923 # introduced in Libtool 1.6.
4924 if (0 == keys %libtool_tags)
4926 # Hardcode the tags supported by Libtool 1.5.
4927 %libtool_tags = (CC => 1, CXX => 1, GCJ => 1, F77 => 1);
4936 # &scan_autoconf_files ()
4937 # -----------------------
4938 # Check whether we use `configure.ac' or `configure.in'.
4939 # Scan it (and possibly `aclocal.m4') for interesting things.
4940 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
4941 sub scan_autoconf_files ()
4943 # Reinitialize libsources here. This isn't really necessary,
4944 # since we currently assume there is only one configure.ac. But
4945 # that won't always be the case.
4948 # Keep track of the youngest configure dependency.
4949 $configure_deps_greatest_timestamp = mtime $configure_ac;
4950 if (-e 'aclocal.m4')
4952 my $mtime = mtime 'aclocal.m4';
4953 $configure_deps_greatest_timestamp = $mtime
4954 if $mtime > $configure_deps_greatest_timestamp;
4957 scan_autoconf_traces ($configure_ac);
4959 @configure_input_files = sort keys %make_list;
4960 # Set input and output files if not specified by user.
4963 @input_files = @configure_input_files;
4964 %output_files = %make_list;
4968 if (! $seen_init_automake)
4970 err_ac ("no proper invocation of AM_INIT_AUTOMAKE was found.\nYou "
4971 . "should verify that $configure_ac invokes AM_INIT_AUTOMAKE,"
4972 . "\nthat aclocal.m4 is present in the top-level directory,\n"
4973 . "and that aclocal.m4 was recently regenerated "
4974 . "(using aclocal).");
4978 if (! $seen_automake_version)
4980 if (-f 'aclocal.m4')
4982 error ($seen_init_automake,
4983 "your implementation of AM_INIT_AUTOMAKE comes from " .
4984 "an\nold Automake version. You should recreate " .
4985 "aclocal.m4\nwith aclocal and run automake again.\n",
4986 # $? = 63 is used to indicate version mismatch to missing.
4991 error ($seen_init_automake,
4992 "no proper implementation of AM_INIT_AUTOMAKE was " .
4993 "found,\nprobably because aclocal.m4 is missing...\n" .
4994 "You should run aclocal to create this file, then\n" .
4995 "run automake again.\n");
5002 # Reorder @input_files so that the Makefile that distributes aux
5003 # files is processed last. This is important because each directory
5004 # can require auxiliary scripts and we should wait until they have
5005 # been installed before distributing them.
5007 # The Makefile.in that distribute the aux files is the one in
5008 # $config_aux_dir or the top-level Makefile.
5009 my $auxdirdist = is_make_dir ($config_aux_dir) ? $config_aux_dir : '.';
5010 my @new_input_files = ();
5011 while (@input_files)
5013 my $in = pop @input_files;
5014 my @ins = split (/:/, $output_files{$in});
5015 if (dirname ($ins[0]) eq $auxdirdist)
5017 push @new_input_files, $in;
5018 $automake_will_process_aux_dir = 1;
5022 unshift @new_input_files, $in;
5025 @input_files = @new_input_files;
5027 # If neither the auxdir/Makefile nor the ./Makefile are generated
5028 # by Automake, we won't distribute the aux files anyway. Assume
5029 # the user know what (s)he does, and pretend we will distribute
5030 # them to disable the error in require_file_internal.
5031 $automake_will_process_aux_dir = 1 if ! is_make_dir ($auxdirdist);
5033 # Look for some files we need. Always check for these. This
5034 # check must be done for every run, even those where we are only
5035 # looking at a subdir Makefile. We must set relative_dir for
5036 # maybe_push_required_file to work.
5037 $relative_dir = '.';
5038 foreach my $file (keys %required_aux_file)
5040 require_conf_file ($required_aux_file{$file}->get, FOREIGN, $file)
5042 err_am "`install.sh' is an anachronism; use `install-sh' instead"
5043 if -f $config_aux_dir . '/install.sh';
5045 # Preserve dist_common for later.
5046 $configure_dist_common = variable_value ('DIST_COMMON') || '';
5050 ################################################################
5052 # Set up for Cygnus mode.
5055 my $cygnus = option 'cygnus';
5056 return unless $cygnus;
5058 set_strictness ('foreign');
5059 set_option ('no-installinfo', $cygnus);
5060 set_option ('no-dependencies', $cygnus);
5061 set_option ('no-dist', $cygnus);
5063 err_ac "`AM_MAINTAINER_MODE' required when --cygnus specified"
5064 if !$seen_maint_mode;
5067 # Do any extra checking for GNU standards.
5068 sub check_gnu_standards
5070 if ($relative_dir eq '.')
5072 # In top level (or only) directory.
5073 require_file ("$am_file.am", GNU,
5074 qw/INSTALL NEWS README AUTHORS ChangeLog/);
5076 # Accept one of these three licenses; default to COPYING.
5077 # Make sure we do not overwrite an existing license.
5079 foreach (qw /COPYING COPYING.LIB COPYING.LESSER/)
5087 require_file ("$am_file.am", GNU, 'COPYING')
5091 for my $opt ('no-installman', 'no-installinfo')
5093 msg ('error-gnu', option $opt,
5094 "option `$opt' disallowed by GNU standards")
5099 # Do any extra checking for GNITS standards.
5100 sub check_gnits_standards
5102 if ($relative_dir eq '.')
5104 # In top level (or only) directory.
5105 require_file ("$am_file.am", GNITS, 'THANKS');
5109 ################################################################
5111 # Functions to handle files of each language.
5113 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
5114 # simple formula: Return value is LANG_SUBDIR if the resulting object
5115 # file should be in a subdir if the source file is, LANG_PROCESS if
5116 # file is to be dealt with, LANG_IGNORE otherwise.
5118 # Much of the actual processing is handled in
5119 # handle_single_transform. These functions exist so that
5120 # auxiliary information can be recorded for a later cleanup pass.
5121 # Note that the calls to these functions are computed, so don't bother
5122 # searching for their precise names in the source.
5124 # This is just a convenience function that can be used to determine
5125 # when a subdir object should be used.
5128 return option 'subdir-objects' ? LANG_SUBDIR : LANG_PROCESS;
5131 # Rewrite a single C source file.
5134 my ($directory, $base, $ext, $nonansi_obj, $have_per_exec_flags, $var) = @_;
5136 if (option 'ansi2knr' && $base =~ /_$/)
5138 # FIXME: include line number in error.
5139 err_am "C source file `$base.c' would be deleted by ansi2knr rules";
5142 my $r = LANG_PROCESS;
5143 if (option 'subdir-objects')
5146 if ($directory && $directory ne '.')
5148 $base = $directory . '/' . $base;
5150 # libtool is always able to put the object at the proper place,
5151 # so we do not have to require AM_PROG_CC_C_O when building .lo files.
5152 err_var ($var, "compiling `$base.c' in subdir requires "
5153 . "`AM_PROG_CC_C_O' in `$configure_ac'",
5154 uniq_scope => US_GLOBAL,
5155 uniq_part => 'AM_PROG_CC_C_O subdir')
5156 unless $seen_cc_c_o || $nonansi_obj eq '.lo';
5159 # In this case we already have the directory information, so
5160 # don't add it again.
5161 $de_ansi_files{$base} = '';
5165 $de_ansi_files{$base} = (($directory eq '.' || $directory eq '')
5171 && $have_per_exec_flags
5172 && ! option 'subdir-objects'
5173 && $nonansi_obj ne '.lo')
5175 err_var ($var, "compiling `$base.c' with per-target flags requires "
5176 . "`AM_PROG_CC_C_O' in `$configure_ac'",
5177 uniq_scope => US_GLOBAL,
5178 uniq_part => 'AM_PROG_CC_C_O per-target')
5184 # Rewrite a single C++ source file.
5185 sub lang_cxx_rewrite
5187 return &lang_sub_obj;
5190 # Rewrite a single header file.
5191 sub lang_header_rewrite
5193 # Header files are simply ignored.
5197 # Rewrite a single yacc file.
5198 sub lang_yacc_rewrite
5200 my ($directory, $base, $ext) = @_;
5202 my $r = &lang_sub_obj;
5203 (my $newext = $ext) =~ tr/y/c/;
5204 return ($r, $newext);
5207 # Rewrite a single yacc++ file.
5208 sub lang_yaccxx_rewrite
5210 my ($directory, $base, $ext) = @_;
5212 my $r = &lang_sub_obj;
5213 (my $newext = $ext) =~ tr/y/c/;
5214 return ($r, $newext);
5217 # Rewrite a single lex file.
5218 sub lang_lex_rewrite
5220 my ($directory, $base, $ext) = @_;
5222 my $r = &lang_sub_obj;
5223 (my $newext = $ext) =~ tr/l/c/;
5224 return ($r, $newext);
5227 # Rewrite a single lex++ file.
5228 sub lang_lexxx_rewrite
5230 my ($directory, $base, $ext) = @_;
5232 my $r = &lang_sub_obj;
5233 (my $newext = $ext) =~ tr/l/c/;
5234 return ($r, $newext);
5237 # Rewrite a single assembly file.
5238 sub lang_asm_rewrite
5240 return &lang_sub_obj;
5243 # Rewrite a single preprocessed assembly file.
5244 sub lang_cppasm_rewrite
5246 return &lang_sub_obj;
5249 # Rewrite a single Fortran 77 file.
5250 sub lang_f77_rewrite
5252 return LANG_PROCESS;
5255 # Rewrite a single Fortran file.
5258 return LANG_PROCESS;
5261 # Rewrite a single preprocessed Fortran file.
5262 sub lang_ppfc_rewrite
5264 return LANG_PROCESS;
5267 # Rewrite a single preprocessed Fortran 77 file.
5268 sub lang_ppf77_rewrite
5270 return LANG_PROCESS;
5273 # Rewrite a single ratfor file.
5274 sub lang_ratfor_rewrite
5276 return LANG_PROCESS;
5279 # Rewrite a single Objective C file.
5280 sub lang_objc_rewrite
5282 return &lang_sub_obj;
5285 # Rewrite a single Java file.
5286 sub lang_java_rewrite
5291 # The lang_X_finish functions are called after all source file
5292 # processing is done. Each should handle defining rules for the
5293 # language, etc. A finish function is only called if a source file of
5294 # the appropriate type has been seen.
5298 # Push all libobjs files onto de_ansi_files. We actually only
5299 # push files which exist in the current directory, and which are
5300 # genuine source files.
5301 foreach my $file (keys %libsources)
5303 if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
5305 $de_ansi_files{$1} = ''
5309 if (option 'ansi2knr' && keys %de_ansi_files)
5311 # Make all _.c files depend on their corresponding .c files.
5313 foreach my $base (sort keys %de_ansi_files)
5315 # Each _.c file must depend on ansi2knr; otherwise it
5316 # might be used in a parallel build before it is built.
5317 # We need to support files in the srcdir and in the build
5318 # dir (because these files might be auto-generated. But
5319 # we can't use $< -- some makes only define $< during a
5321 my $ansfile = $de_ansi_files{$base} . $base . '.c';
5322 $output_rules .= ($base . "_.c: $ansfile \$(ANSI2KNR)\n\t"
5323 . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5324 . '`if test -f $(srcdir)/' . $ansfile
5325 . '; then echo $(srcdir)/' . $ansfile
5326 . '; else echo ' . $ansfile . '; fi` '
5327 . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5328 . '| $(ANSI2KNR) > $@'
5329 # If ansi2knr fails then we shouldn't
5330 # create the _.c file
5331 . " || rm -f \$\@\n");
5332 push (@objects, $base . '_.$(OBJEXT)');
5333 push (@objects, $base . '_.lo')
5336 # Explicitly clean the _.c files if they are in a
5337 # subdirectory. (In the current directory they get erased
5338 # by a `rm -f *_.c' rule.)
5339 $clean_files{$base . '_.c'} = MOSTLY_CLEAN
5340 if dirname ($base) ne '.';
5343 # Make all _.o (and _.lo) files depend on ansi2knr.
5344 # Use a sneaky little hack to make it print nicely.
5345 &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5349 # This is a yacc helper which is called whenever we have decided to
5350 # compile a yacc file.
5351 sub lang_yacc_target_hook
5353 my ($self, $aggregate, $output, $input, %transform) = @_;
5355 my $flag = $aggregate . "_YFLAGS";
5356 my $flagvar = var $flag;
5357 my $YFLAGSvar = var 'YFLAGS';
5358 if (($flagvar && $flagvar->variable_value =~ /$DASH_D_PATTERN/o)
5359 || ($YFLAGSvar && $YFLAGSvar->variable_value =~ /$DASH_D_PATTERN/o))
5361 (my $output_base = $output) =~ s/$KNOWN_EXTENSIONS_PATTERN$//;
5362 my $header = $output_base . '.h';
5364 # Found a `-d' that applies to the compilation of this file.
5365 # Add a dependency for the generated header file, and arrange
5366 # for that file to be included in the distribution.
5367 foreach my $cond (Automake::Rule::define (${header}, 'internal',
5368 RULE_AUTOMAKE, TRUE,
5371 my $condstr = $cond->subst_string;
5372 $output_rules .= ("$condstr${header}: $output\n"
5373 # Recover from removal of $header
5374 . "$condstr\t\@if test ! -f \$@; then \\\n"
5375 . "$condstr\t rm -f $output; \\\n"
5376 . "$condstr\t \$(MAKE) $output; \\\n"
5377 . "$condstr\telse :; fi\n");
5379 # Distribute the generated file, unless its .y source was
5380 # listed in a nodist_ variable. (&handle_source_transform
5381 # will set DIST_SOURCE.)
5382 &push_dist_common ($header)
5383 if $transform{'DIST_SOURCE'};
5385 # If the files are built in the build directory, then we want
5386 # to remove them with `make clean'. If they are in srcdir
5387 # they shouldn't be touched. However, we can't determine this
5388 # statically, and the GNU rules say that yacc/lex output files
5389 # should be removed by maintainer-clean. So that's what we
5391 $clean_files{$header} = MAINTAINER_CLEAN;
5393 # Erase $OUTPUT on `make maintainer-clean' (by GNU standards).
5394 # See the comment above for $HEADER.
5395 $clean_files{$output} = MAINTAINER_CLEAN;
5398 # This is a lex helper which is called whenever we have decided to
5399 # compile a lex file.
5400 sub lang_lex_target_hook
5402 my ($self, $aggregate, $output, $input) = @_;
5403 # If the files are built in the build directory, then we want to
5404 # remove them with `make clean'. If they are in srcdir they
5405 # shouldn't be touched. However, we can't determine this
5406 # statically, and the GNU rules say that yacc/lex output files
5407 # should be removed by maintainer-clean. So that's what we do.
5408 $clean_files{$output} = MAINTAINER_CLEAN;
5411 # This is a helper for both lex and yacc.
5412 sub yacc_lex_finish_helper
5414 return if defined $language_scratch{'lex-yacc-done'};
5415 $language_scratch{'lex-yacc-done'} = 1;
5417 # If there is more than one distinct yacc (resp lex) source file
5418 # in a given directory, then the `ylwrap' program is required to
5419 # allow parallel builds to work correctly. FIXME: for now, no
5421 require_conf_file ($configure_ac, FOREIGN, 'ylwrap');
5422 &define_variable ('YLWRAP', "$am_config_aux_dir/ylwrap", INTERNAL);
5425 sub lang_yacc_finish
5427 return if defined $language_scratch{'yacc-done'};
5428 $language_scratch{'yacc-done'} = 1;
5430 reject_var 'YACCFLAGS', "`YACCFLAGS' obsolete; use `YFLAGS' instead";
5432 &yacc_lex_finish_helper
5433 if count_files_for_language ('yacc') > 1;
5439 return if defined $language_scratch{'lex-done'};
5440 $language_scratch{'lex-done'} = 1;
5442 &yacc_lex_finish_helper
5443 if count_files_for_language ('lex') > 1;
5447 # Given a hash table of linker names, pick the name that has the most
5448 # precedence. This is lame, but something has to have global
5449 # knowledge in order to eliminate the conflict. Add more linkers as
5455 foreach my $l (qw(GCJLINK CXXLINK F77LINK FCLINK OBJCLINK))
5457 return $l if defined $linkers{$l};
5462 # Called to indicate that an extension was used.
5466 if (! defined $extension_seen{$ext})
5468 $extension_seen{$ext} = 1;
5472 ++$extension_seen{$ext};
5476 # Return the number of files seen for a given language. Knows about
5477 # special cases we care about. FIXME: this is hideous. We need
5478 # something that involves real language objects. For instance yacc
5479 # and yaccxx could both derive from a common yacc class which would
5480 # know about the strange ylwrap requirement. (Or better yet we could
5481 # just not support legacy yacc!)
5482 sub count_files_for_language
5487 if ($name eq 'yacc' || $name eq 'yaccxx')
5489 @names = ('yacc', 'yaccxx');
5491 elsif ($name eq 'lex' || $name eq 'lexxx')
5493 @names = ('lex', 'lexxx');
5501 foreach $name (@names)
5503 my $lang = $languages{$name};
5504 foreach my $ext (@{$lang->extensions})
5506 $r += $extension_seen{$ext}
5507 if defined $extension_seen{$ext};
5514 # Called to ask whether source files have been seen . If HEADERS is 1,
5515 # headers can be included.
5520 # count all the sources
5522 foreach my $val (values %extension_seen)
5529 $count -= count_files_for_language ('header');
5536 # register_language (%ATTRIBUTE)
5537 # ------------------------------
5538 # Register a single language.
5539 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5540 sub register_language (%)
5546 unless defined $option{'ansi'};
5547 $option{'autodep'} = 'no'
5548 unless defined $option{'autodep'};
5549 $option{'linker'} = ''
5550 unless defined $option{'linker'};
5551 $option{'flags'} = []
5552 unless defined $option{'flags'};
5553 $option{'output_extensions'} = sub { return ( '.$(OBJEXT)', '.lo' ) }
5554 unless defined $option{'output_extensions'};
5555 $option{'nodist_specific'} = 0
5556 unless defined $option{'nodist_specific'};
5558 my $lang = new Language (%option);
5561 $extension_map{$_} = $lang->name foreach @{$lang->extensions};
5562 $languages{$lang->name} = $lang;
5563 my $link = $lang->linker;
5566 if (exists $link_languages{$link})
5568 prog_error ("`$link' has different definitions in "
5569 . $lang->name . " and " . $link_languages{$link}->name)
5570 if $lang->link ne $link_languages{$link}->link;
5574 $link_languages{$link} = $lang;
5578 # Update the pattern of known extensions.
5579 accept_extensions (@{$lang->extensions});
5581 # Upate the $suffix_rule map.
5582 foreach my $suffix (@{$lang->extensions})
5584 foreach my $dest (&{$lang->output_extensions} ($suffix))
5586 register_suffix_rule (INTERNAL, $suffix, $dest);
5591 # derive_suffix ($EXT, $OBJ)
5592 # --------------------------
5593 # This function is used to find a path from a user-specified suffix $EXT
5594 # to $OBJ or to some other suffix we recognize internally, e.g. `cc'.
5595 sub derive_suffix ($$)
5597 my ($source_ext, $obj) = @_;
5599 while (! $extension_map{$source_ext}
5600 && $source_ext ne $obj
5601 && exists $suffix_rules->{$source_ext}
5602 && exists $suffix_rules->{$source_ext}{$obj})
5604 $source_ext = $suffix_rules->{$source_ext}{$obj}[0];
5611 ################################################################
5613 # Pretty-print something and append to output_rules.
5614 sub pretty_print_rule
5616 $output_rules .= &makefile_wrap (@_);
5620 ################################################################
5623 ## -------------------------------- ##
5624 ## Handling the conditional stack. ##
5625 ## -------------------------------- ##
5629 # make_conditional_string ($NEGATE, $COND)
5630 # ----------------------------------------
5631 sub make_conditional_string ($$)
5633 my ($negate, $cond) = @_;
5634 $cond = "${cond}_TRUE"
5635 unless $cond =~ /^TRUE|FALSE$/;
5636 $cond = Automake::Condition::conditional_negate ($cond)
5643 # cond_stack_if ($NEGATE, $COND, $WHERE)
5644 # --------------------------------------
5645 sub cond_stack_if ($$$)
5647 my ($negate, $cond, $where) = @_;
5649 error $where, "$cond does not appear in AM_CONDITIONAL"
5650 if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
5652 push (@cond_stack, make_conditional_string ($negate, $cond));
5654 return new Automake::Condition (@cond_stack);
5659 # cond_stack_else ($NEGATE, $COND, $WHERE)
5660 # ----------------------------------------
5661 sub cond_stack_else ($$$)
5663 my ($negate, $cond, $where) = @_;
5667 error $where, "else without if";
5671 $cond_stack[$#cond_stack] =
5672 Automake::Condition::conditional_negate ($cond_stack[$#cond_stack]);
5674 # If $COND is given, check against it.
5677 $cond = make_conditional_string ($negate, $cond);
5679 error ($where, "else reminder ($negate$cond) incompatible with "
5680 . "current conditional: $cond_stack[$#cond_stack]")
5681 if $cond_stack[$#cond_stack] ne $cond;
5684 return new Automake::Condition (@cond_stack);
5689 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5690 # -----------------------------------------
5691 sub cond_stack_endif ($$$)
5693 my ($negate, $cond, $where) = @_;
5698 error $where, "endif without if";
5702 # If $COND is given, check against it.
5705 $cond = make_conditional_string ($negate, $cond);
5707 error ($where, "endif reminder ($negate$cond) incompatible with "
5708 . "current conditional: $cond_stack[$#cond_stack]")
5709 if $cond_stack[$#cond_stack] ne $cond;
5714 return new Automake::Condition (@cond_stack);
5721 ## ------------------------ ##
5722 ## Handling the variables. ##
5723 ## ------------------------ ##
5726 # &define_pretty_variable ($VAR, $COND, $WHERE, @VALUE)
5727 # -----------------------------------------------------
5728 # Like define_variable, but the value is a list, and the variable may
5729 # be defined conditionally. The second argument is the Condition
5730 # under which the value should be defined; this should be the empty
5731 # string to define the variable unconditionally. The third argument
5732 # is a list holding the values to use for the variable. The value is
5733 # pretty printed in the output file.
5734 sub define_pretty_variable ($$$@)
5736 my ($var, $cond, $where, @value) = @_;
5738 if (! vardef ($var, $cond))
5740 Automake::Variable::define ($var, VAR_AUTOMAKE, '', $cond, "@value",
5741 '', $where, VAR_PRETTY);
5742 rvar ($var)->rdef ($cond)->set_seen;
5747 # define_variable ($VAR, $VALUE, $WHERE)
5748 # --------------------------------------
5749 # Define a new Automake Makefile variable VAR to VALUE, but only if
5750 # not already defined.
5751 sub define_variable ($$$)
5753 my ($var, $value, $where) = @_;
5754 define_pretty_variable ($var, TRUE, $where, $value);
5758 # define_files_variable ($VAR, \@BASENAME, $EXTENSION, $WHERE)
5759 # -----------------------------------------------------------
5760 # Define the $VAR which content is the list of file names composed of
5761 # a @BASENAME and the $EXTENSION.
5762 sub define_files_variable ($\@$$)
5764 my ($var, $basename, $extension, $where) = @_;
5765 define_variable ($var,
5766 join (' ', map { "$_.$extension" } @$basename),
5771 # Like define_variable, but define a variable to be the configure
5772 # substitution by the same name.
5773 sub define_configure_variable ($)
5777 my $pretty = VAR_ASIS;
5778 my $owner = VAR_CONFIGURE;
5780 # Do not output the ANSI2KNR configure variable -- we AC_SUBST
5781 # it in protos.m4, but later redefine it elsewhere. This is
5782 # pretty hacky. We also don't output AMDEPBACKSLASH: it might
5783 # be subst'd by `\', which certainly would not be appreciated by
5785 if ($var eq 'ANSI2KNR' || $var eq 'AMDEPBACKSLASH')
5787 $pretty = VAR_SILENT;
5788 $owner = VAR_AUTOMAKE;
5791 Automake::Variable::define ($var, $owner, '', TRUE, subst $var,
5792 '', $configure_vars{$var}, $pretty);
5796 # define_compiler_variable ($LANG)
5797 # --------------------------------
5798 # Define a compiler variable. We also handle defining the `LT'
5799 # version of the command when using libtool.
5800 sub define_compiler_variable ($)
5804 my ($var, $value) = ($lang->compiler, $lang->compile);
5805 my $libtool_tag = '';
5806 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
5807 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
5808 &define_variable ($var, $value, INTERNAL);
5809 &define_variable ("LT$var",
5810 "\$(LIBTOOL) $libtool_tag\$(AM_LIBTOOLFLAGS) "
5811 . "\$(LIBTOOLFLAGS) --mode=compile $value",
5817 # define_linker_variable ($LANG)
5818 # ------------------------------
5819 # Define linker variables.
5820 sub define_linker_variable ($)
5824 my $libtool_tag = '';
5825 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
5826 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
5828 &define_variable ($lang->lder, $lang->ld, INTERNAL);
5829 # CCLINK = $(CCLD) blah blah...
5830 &define_variable ($lang->linker,
5832 "\$(LIBTOOL) $libtool_tag\$(AM_LIBTOOLFLAGS) "
5833 . "\$(LIBTOOLFLAGS) --mode=link " : '')
5838 sub define_per_target_linker_variable ($$)
5840 my ($linker, $target) = @_;
5842 # If the user wrote a custom link command, we don't define ours.
5843 return "${target}_LINK"
5844 if set_seen "${target}_LINK";
5846 my $xlink = $linker ? $linker : 'LINK';
5848 my $lang = $link_languages{$xlink};
5849 prog_error "Unknown language for linker variable `$xlink'"
5852 my $link_command = $lang->link;
5855 my $libtool_tag = '';
5856 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
5857 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
5860 "\$(LIBTOOL) $libtool_tag\$(AM_LIBTOOLFLAGS) \$(LIBTOOLFLAGS) "
5861 . "--mode=link " . $link_command;
5864 # Rewrite each occurrence of `AM_$flag' in the link
5865 # command into `${derived}_$flag' if it exists.
5866 my $orig_command = $link_command;
5867 my @flags = (@{$lang->flags}, 'LDFLAGS');
5868 push @flags, 'LIBTOOLFLAGS' if var 'LIBTOOL';
5869 for my $flag (@flags)
5871 my $val = "${target}_$flag";
5872 $link_command =~ s/\(AM_$flag\)/\($val\)/
5876 # If the computed command is the same as the generic command, use
5877 # the command linker variable.
5878 return $lang->linker
5879 if $link_command eq $orig_command;
5881 &define_variable ("${target}_LINK", $link_command, INTERNAL);
5882 return "${target}_LINK";
5885 ################################################################
5887 # &check_trailing_slash ($WHERE, $LINE)
5888 # --------------------------------------
5889 # Return 1 iff $LINE ends with a slash.
5890 # Might modify $LINE.
5891 sub check_trailing_slash ($\$)
5893 my ($where, $line) = @_;
5895 # Ignore `##' lines.
5896 return 0 if $$line =~ /$IGNORE_PATTERN/o;
5898 # Catch and fix a common error.
5899 msg "syntax", $where, "whitespace following trailing backslash"
5900 if $$line =~ s/\\\s+\n$/\\\n/;
5902 return $$line =~ /\\$/;
5906 # &read_am_file ($AMFILE, $WHERE)
5907 # -------------------------------
5908 # Read Makefile.am and set up %contents. Simultaneously copy lines
5909 # from Makefile.am into $output_trailer, or define variables as
5910 # appropriate. NOTE we put rules in the trailer section. We want
5911 # user rules to come after our generated stuff.
5912 sub read_am_file ($$)
5914 my ($amfile, $where) = @_;
5916 my $am_file = new Automake::XFile ("< $amfile");
5917 verb "reading $amfile";
5919 # Keep track of the youngest output dependency.
5920 my $mtime = mtime $amfile;
5921 $output_deps_greatest_timestamp = $mtime
5922 if $mtime > $output_deps_greatest_timestamp;
5928 my $var_look = VAR_ASIS;
5930 use constant IN_VAR_DEF => 0;
5931 use constant IN_RULE_DEF => 1;
5932 use constant IN_COMMENT => 2;
5933 my $prev_state = IN_RULE_DEF;
5935 while ($_ = $am_file->getline)
5937 $where->set ("$amfile:$.");
5938 if (/$IGNORE_PATTERN/o)
5940 # Merely delete comments beginning with two hashes.
5942 elsif (/$WHITE_PATTERN/o)
5944 error $where, "blank line following trailing backslash"
5946 # Stick a single white line before the incoming macro or rule.
5949 # Flush all comments seen so far.
5952 $output_vars .= $comment;
5956 elsif (/$COMMENT_PATTERN/o)
5958 # Stick comments before the incoming macro or rule. Make
5959 # sure a blank line precedes the first block of comments.
5960 $spacing = "\n" unless $blank;
5962 $comment .= $spacing . $_;
5964 $prev_state = IN_COMMENT;
5970 $saw_bk = check_trailing_slash ($where, $_);
5973 # We save the conditional stack on entry, and then check to make
5974 # sure it is the same on exit. This lets us conditionally include
5976 my @saved_cond_stack = @cond_stack;
5977 my $cond = new Automake::Condition (@cond_stack);
5979 my $last_var_name = '';
5980 my $last_var_type = '';
5981 my $last_var_value = '';
5983 # FIXME: shouldn't use $_ in this loop; it is too big.
5986 $where->set ("$amfile:$.");
5988 # Make sure the line is \n-terminated.
5992 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
5993 # used by users. @MAINT@ is an anachronism now.
5994 $_ =~ s/\@MAINT\@//g
5995 unless $seen_maint_mode;
5997 my $new_saw_bk = check_trailing_slash ($where, $_);
5999 if (/$IGNORE_PATTERN/o)
6001 # Merely delete comments beginning with two hashes.
6003 elsif (/$WHITE_PATTERN/o)
6005 # Stick a single white line before the incoming macro or rule.
6007 error $where, "blank line following trailing backslash"
6010 elsif (/$COMMENT_PATTERN/o)
6012 # Stick comments before the incoming macro or rule.
6013 $comment .= $spacing . $_;
6015 error $where, "comment following trailing backslash"
6016 if $saw_bk && $comment eq '';
6017 $prev_state = IN_COMMENT;
6021 if ($prev_state == IN_RULE_DEF)
6023 my $cond = new Automake::Condition @cond_stack;
6024 $output_trailer .= $cond->subst_string;
6025 $output_trailer .= $_;
6027 elsif ($prev_state == IN_COMMENT)
6029 # If the line doesn't start with a `#', add it.
6030 # We do this because a continued comment like
6034 # is not portable. BSD make doesn't honor
6035 # escaped newlines in comments.
6037 $comment .= $spacing . $_;
6039 else # $prev_state == IN_VAR_DEF
6041 $last_var_value .= ' '
6042 unless $last_var_value =~ /\s$/;
6043 $last_var_value .= $_;
6047 Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
6048 $last_var_type, $cond,
6049 $last_var_value, $comment,
6050 $last_where, VAR_ASIS)
6052 $comment = $spacing = '';
6057 elsif (/$IF_PATTERN/o)
6059 $cond = cond_stack_if ($1, $2, $where);
6061 elsif (/$ELSE_PATTERN/o)
6063 $cond = cond_stack_else ($1, $2, $where);
6065 elsif (/$ENDIF_PATTERN/o)
6067 $cond = cond_stack_endif ($1, $2, $where);
6070 elsif (/$RULE_PATTERN/o)
6073 $prev_state = IN_RULE_DEF;
6075 # For now we have to output all definitions of user rules
6076 # and can't diagnose duplicates (see the comment in
6077 # rule_define). So we go on and ignore the return value.
6078 Automake::Rule::define ($1, $amfile, RULE_USER, $cond, $where);
6080 check_variable_expansions ($_, $where);
6082 $output_trailer .= $comment . $spacing;
6083 my $cond = new Automake::Condition @cond_stack;
6084 $output_trailer .= $cond->subst_string;
6085 $output_trailer .= $_;
6086 $comment = $spacing = '';
6088 elsif (/$ASSIGNMENT_PATTERN/o)
6090 # Found a macro definition.
6091 $prev_state = IN_VAR_DEF;
6092 $last_var_name = $1;
6093 $last_var_type = $2;
6094 $last_var_value = $3;
6095 $last_where = $where->clone;
6096 if ($3 ne '' && substr ($3, -1) eq "\\")
6098 # We preserve the `\' because otherwise the long lines
6099 # that are generated will be truncated by broken
6101 $last_var_value = $3 . "\n";
6103 # Normally we try to output variable definitions in the
6104 # same format they were input. However, POSIX compliant
6105 # systems are not required to support lines longer than
6106 # 2048 bytes (most notably, some sed implementation are
6107 # limited to 4000 bytes, and sed is used by config.status
6108 # to rewrite Makefile.in into Makefile). Moreover nobody
6109 # would really write such long lines by hand since it is
6110 # hardly maintainable. So if a line is longer that 1000
6111 # bytes (an arbitrary limit), assume it has been
6112 # automatically generated by some tools, and flatten the
6113 # variable definition. Otherwise, keep the variable as it
6115 $var_look = VAR_PRETTY if length ($last_var_value) >= 1000;
6119 Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
6120 $last_var_type, $cond,
6121 $last_var_value, $comment,
6122 $last_where, $var_look)
6124 $comment = $spacing = '';
6125 $var_look = VAR_ASIS;
6128 elsif (/$INCLUDE_PATTERN/o)
6132 if ($path =~ s/^\$\(top_srcdir\)\///)
6134 push (@include_stack, "\$\(top_srcdir\)/$path");
6135 # Distribute any included file.
6137 # Always use the $(top_srcdir) prefix in DIST_COMMON,
6138 # otherwise OSF make will implicitly copy the included
6139 # file in the build tree during `make distdir' to satisfy
6141 # (subdircond2.test and subdircond3.test will fail.)
6142 push_dist_common ("\$\(top_srcdir\)/$path");
6146 $path =~ s/\$\(srcdir\)\///;
6147 push (@include_stack, "\$\(srcdir\)/$path");
6148 # Always use the $(srcdir) prefix in DIST_COMMON,
6149 # otherwise OSF make will implicitly copy the included
6150 # file in the build tree during `make distdir' to satisfy
6152 # (subdircond2.test and subdircond3.test will fail.)
6153 push_dist_common ("\$\(srcdir\)/$path");
6154 $path = $relative_dir . "/" . $path if $relative_dir ne '.';
6156 $where->push_context ("`$path' included from here");
6157 &read_am_file ($path, $where);
6158 $where->pop_context;
6162 # This isn't an error; it is probably a continued rule.
6163 # In fact, this is what we assume.
6164 $prev_state = IN_RULE_DEF;
6165 check_variable_expansions ($_, $where);
6166 $output_trailer .= $comment . $spacing;
6167 my $cond = new Automake::Condition @cond_stack;
6168 $output_trailer .= $cond->subst_string;
6169 $output_trailer .= $_;
6170 $comment = $spacing = '';
6171 error $where, "`#' comment at start of rule is unportable"
6172 if $_ =~ /^\t\s*\#/;
6175 $saw_bk = $new_saw_bk;
6176 $_ = $am_file->getline;
6179 $output_trailer .= $comment;
6181 error ($where, "trailing backslash on last line")
6184 error ($where, (@cond_stack ? "unterminated conditionals: @cond_stack"
6185 : "too many conditionals closed in include file"))
6186 if "@saved_cond_stack" ne "@cond_stack";
6190 # define_standard_variables ()
6191 # ----------------------------
6192 # A helper for read_main_am_file which initializes configure variables
6193 # and variables from header-vars.am.
6194 sub define_standard_variables
6196 my $saved_output_vars = $output_vars;
6197 my ($comments, undef, $rules) =
6198 file_contents_internal (1, "$libdir/am/header-vars.am",
6199 new Automake::Location);
6201 foreach my $var (sort keys %configure_vars)
6203 &define_configure_variable ($var);
6206 $output_vars .= $comments . $rules;
6209 # Read main am file.
6210 sub read_main_am_file
6214 # This supports the strange variable tricks we are about to play.
6215 prog_error (macros_dump () . "variable defined before read_main_am_file")
6216 if (scalar (variables) > 0);
6218 # Generate copyright header for generated Makefile.in.
6219 # We do discard the output of predefined variables, handled below.
6220 $output_vars = ("# $in_file_name generated by automake "
6221 . $VERSION . " from $am_file_name.\n");
6222 $output_vars .= '# ' . subst ('configure_input') . "\n";
6223 $output_vars .= $gen_copyright;
6225 # We want to predefine as many variables as possible. This lets
6226 # the user set them with `+=' in Makefile.am.
6227 &define_standard_variables;
6229 # Read user file, which might override some of our values.
6230 &read_am_file ($amfile, new Automake::Location);
6235 ################################################################
6238 # &flatten ($STRING)
6239 # ------------------
6240 # Flatten the $STRING and return the result.
6253 # transform($TOKEN, \%PAIRS)
6254 # ==========================
6255 # If ($TOKEN, $VAL) is in %PAIRS:
6256 # - replaces %$TOKEN% with $VAL,
6257 # - enables/disables ?$TOKEN? and ?!$TOKEN?,
6258 # - replaces %?$TOKEN% with TRUE or FALSE.
6261 my ($token, $transform) = @_;
6263 if (substr ($token, 0, 1) eq '%')
6265 my $cond = (substr ($token, 1, 1) eq '?') ? 1 : 0;
6266 $token = substr ($token, 1 + $cond, -1);
6267 my $val = $transform->{$token};
6268 prog_error "Unknown %token% `$token'" unless defined $val;
6271 return $val ? 'TRUE' : 'FALSE';
6278 # Now $token is '?xxx?' or '?!xxx?'.
6279 my $neg = (substr ($token, 1, 1) eq '!') ? 1 : 0;
6280 $token = substr ($token, 1 + $neg, -1);
6281 my $val = $transform->{$token};
6282 prog_error "Unknown ?token? `$token' (neg = $neg)" unless defined $val;
6283 return (!!$val == $neg) ? '##%' : '';
6287 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
6288 # ------------------------------------------
6289 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6291 sub make_paragraphs ($%)
6293 my ($file, %transform) = @_;
6295 # Complete %transform with global options.
6296 # Note that %transform goes last, so it overrides global options.
6297 %transform = ('CYGNUS' => !! option 'cygnus',
6299 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
6301 'BZIP2' => !! option 'dist-bzip2',
6302 'COMPRESS' => !! option 'dist-tarZ',
6303 'GZIP' => ! option 'no-dist-gzip',
6304 'SHAR' => !! option 'dist-shar',
6305 'ZIP' => !! option 'dist-zip',
6307 'INSTALL-INFO' => ! option 'no-installinfo',
6308 'INSTALL-MAN' => ! option 'no-installman',
6309 'CK-NEWS' => !! option 'check-news',
6311 'SUBDIRS' => !! var ('SUBDIRS'),
6312 'TOPDIR' => backname ($relative_dir),
6313 'TOPDIR_P' => $relative_dir eq '.',
6315 'BUILD' => ($seen_canonical >= AC_CANONICAL_BUILD),
6316 'HOST' => ($seen_canonical >= AC_CANONICAL_HOST),
6317 'TARGET' => ($seen_canonical >= AC_CANONICAL_TARGET),
6319 'LIBTOOL' => !! var ('LIBTOOL'),
6321 'FIRST' => ! $transformed_files{$file},
6324 $transformed_files{$file} = 1;
6325 $_ = $am_file_cache{$file};
6329 verb "reading $file";
6330 # Swallow the whole file.
6331 my $fc_file = new Automake::XFile "< $file";
6332 my $saved_dollar_slash = $/;
6334 $_ = $fc_file->getline;
6335 $/ = $saved_dollar_slash;
6338 # Remove ##-comments.
6339 # Besides we don't need more than two consecutive new-lines.
6340 s/(?:$IGNORE_PATTERN|(?<=\n\n)\n+)//gom;
6342 $am_file_cache{$file} = $_;
6345 # Substitute Automake template tokens.
6346 s/(?:%\??[\w\-]+%|\?!?[\w\-]+\?)/transform($&, \%transform)/ge;
6347 # transform() may have added some ##%-comments to strip.
6348 # (we use `##%' instead of `##' so we can distinguish ##%##%##% from
6349 # ####### and do not remove the latter.)
6350 s/^[ \t]*(?:##%)+.*\n//gm;
6352 # Split at unescaped new lines.
6353 my @lines = split (/(?<!\\)\n/, $_);
6356 while (defined ($_ = shift @lines))
6359 # If we are a rule, eat as long as we start with a tab.
6360 if (/$RULE_PATTERN/smo)
6362 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
6364 $paragraph .= "\n$_";
6366 unshift (@lines, $_);
6369 # If we are a comments, eat as much comments as you can.
6370 elsif (/$COMMENT_PATTERN/smo)
6372 while (defined ($_ = shift @lines)
6373 && $_ =~ /$COMMENT_PATTERN/smo)
6375 $paragraph .= "\n$_";
6377 unshift (@lines, $_);
6380 push @res, $paragraph;
6388 # ($COMMENT, $VARIABLES, $RULES)
6389 # &file_contents_internal ($IS_AM, $FILE, $WHERE, [%TRANSFORM])
6390 # -------------------------------------------------------------
6391 # Return contents of a file from $libdir/am, automatically skipping
6392 # macros or rules which are already known. $IS_AM iff the caller is
6393 # reading an Automake file (as opposed to the user's Makefile.am).
6394 sub file_contents_internal ($$$%)
6396 my ($is_am, $file, $where, %transform) = @_;
6398 $where->set ($file);
6400 my $result_vars = '';
6401 my $result_rules = '';
6405 # The following flags are used to track rules spanning across
6406 # multiple paragraphs.
6407 my $is_rule = 0; # 1 if we are processing a rule.
6408 my $discard_rule = 0; # 1 if the current rule should not be output.
6410 # We save the conditional stack on entry, and then check to make
6411 # sure it is the same on exit. This lets us conditionally include
6413 my @saved_cond_stack = @cond_stack;
6414 my $cond = new Automake::Condition (@cond_stack);
6416 foreach (make_paragraphs ($file, %transform))
6418 # FIXME: no line number available.
6419 $where->set ($file);
6422 error $where, "blank line following trailing backslash:\n$_"
6424 error $where, "comment following trailing backslash:\n$_"
6430 # Stick empty line before the incoming macro or rule.
6433 elsif (/$COMMENT_PATTERN/mso)
6436 # Stick comments before the incoming macro or rule.
6440 # Handle inclusion of other files.
6441 elsif (/$INCLUDE_PATTERN/o)
6445 my $file = ($is_am ? "$libdir/am/" : '') . $1;
6446 $where->push_context ("`$file' included from here");
6448 my ($com, $vars, $rules)
6449 = file_contents_internal ($is_am, $file, $where, %transform);
6450 $where->pop_context;
6452 $result_vars .= $vars;
6453 $result_rules .= $rules;
6457 # Handling the conditionals.
6458 elsif (/$IF_PATTERN/o)
6460 $cond = cond_stack_if ($1, $2, $file);
6462 elsif (/$ELSE_PATTERN/o)
6464 $cond = cond_stack_else ($1, $2, $file);
6466 elsif (/$ENDIF_PATTERN/o)
6468 $cond = cond_stack_endif ($1, $2, $file);
6472 elsif (/$RULE_PATTERN/mso)
6476 # Separate relationship from optional actions: the first
6477 # `new-line tab" not preceded by backslash (continuation
6480 /^(.*?)(?:(?<!\\)\n(\t.*))?$/s;
6481 my ($relationship, $actions) = ($1, $2 || '');
6483 # Separate targets from dependencies: the first colon.
6484 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
6485 my ($targets, $dependencies) = ($1, $2);
6486 # Remove the escaped new lines.
6487 # I don't know why, but I have to use a tmp $flat_deps.
6488 my $flat_deps = &flatten ($dependencies);
6489 my @deps = split (' ', $flat_deps);
6491 foreach (split (' ' , $targets))
6493 # FIXME: 1. We are not robust to people defining several targets
6494 # at once, only some of them being in %dependencies. The
6495 # actions from the targets in %dependencies are usually generated
6496 # from the content of %actions, but if some targets in $targets
6497 # are not in %dependencies the ELSE branch will output
6498 # a rule for all $targets (i.e. the targets which are both
6499 # in %dependencies and $targets will have two rules).
6501 # FIXME: 2. The logic here is not able to output a
6502 # multi-paragraph rule several time (e.g. for each condition
6503 # it is defined for) because it only knows the first paragraph.
6505 # FIXME: 3. We are not robust to people defining a subset
6506 # of a previously defined "multiple-target" rule. E.g.
6507 # `foo:' after `foo bar:'.
6509 # Output only if not in FALSE.
6510 if (defined $dependencies{$_} && $cond != FALSE)
6512 &depend ($_, @deps);
6515 $actions{$_} .= "\n$actions" if $actions;
6519 $actions{$_} = $actions;
6524 # Free-lance dependency. Output the rule for all the
6525 # targets instead of one by one.
6526 my @undefined_conds =
6527 Automake::Rule::define ($targets, $file,
6528 $is_am ? RULE_AUTOMAKE : RULE_USER,
6530 for my $undefined_cond (@undefined_conds)
6532 my $condparagraph = $paragraph;
6533 $condparagraph =~ s/^/$undefined_cond->subst_string/gme;
6534 $result_rules .= "$spacing$comment$condparagraph\n";
6536 if (scalar @undefined_conds == 0)
6538 # Remember to discard next paragraphs
6539 # if they belong to this rule.
6540 # (but see also FIXME: #2 above.)
6543 $comment = $spacing = '';
6549 elsif (/$ASSIGNMENT_PATTERN/mso)
6551 my ($var, $type, $val) = ($1, $2, $3);
6552 error $where, "variable `$var' with trailing backslash"
6557 Automake::Variable::define ($var,
6558 $is_am ? VAR_AUTOMAKE : VAR_MAKEFILE,
6559 $type, $cond, $val, $comment, $where,
6563 $comment = $spacing = '';
6567 # This isn't an error; it is probably some tokens which
6568 # configure is supposed to replace, such as `@SET-MAKE@',
6569 # or some part of a rule cut by an if/endif.
6570 if (! $cond->false && ! ($is_rule && $discard_rule))
6572 s/^/$cond->subst_string/gme;
6573 $result_rules .= "$spacing$comment$_\n";
6575 $comment = $spacing = '';
6579 error ($where, @cond_stack ?
6580 "unterminated conditionals: @cond_stack" :
6581 "too many conditionals closed in include file")
6582 if "@saved_cond_stack" ne "@cond_stack";
6584 return ($comment, $result_vars, $result_rules);
6589 # &file_contents ($BASENAME, $WHERE, [%TRANSFORM])
6590 # ------------------------------------------------
6591 # Return contents of a file from $libdir/am, automatically skipping
6592 # macros or rules which are already known.
6593 sub file_contents ($$%)
6595 my ($basename, $where, %transform) = @_;
6596 my ($comments, $variables, $rules) =
6597 file_contents_internal (1, "$libdir/am/$basename.am", $where,
6599 return "$comments$variables$rules";
6603 # &append_exeext ($MACRO)
6604 # -----------------------
6605 # Macro is an Automake magic macro which primary is PROGRAMS, e.g.
6606 # bin_PROGRAMS. Make sure these programs have $(EXEEXT) appended.
6607 sub append_exeext ($)
6611 prog_error "append_exeext ($macro)"
6612 unless $macro =~ /_PROGRAMS$/;
6614 transform_variable_recursively
6615 ($macro, $macro, 'am__EXEEXT', 0, INTERNAL,
6617 my ($subvar, $val, $cond, $full_cond) = @_;
6618 # Append $(EXEEXT) unless the user did it already, or it's a
6620 $val .= '$(EXEEXT)' unless $val =~ /(?:\$\(EXEEXT\)$|^[@]\w+[@]$)/;
6627 # &am_primary_prefixes ($PRIMARY, $CAN_DIST, @PREFIXES)
6628 # -----------------------------------------------------
6629 # Find all variable prefixes that are used for install directories. A
6630 # prefix `zar' qualifies iff:
6632 # * `zardir' is a variable.
6633 # * `zar_PRIMARY' is a variable.
6635 # As a side effect, it looks for misspellings. It is an error to have
6636 # a variable ending in a "reserved" suffix whose prefix is unknown, e.g.
6637 # "bin_PROGRAMS". However, unusual prefixes are allowed if a variable
6638 # of the same name (with "dir" appended) exists. For instance, if the
6639 # variable "zardir" is defined, then "zar_PROGRAMS" becomes valid.
6640 # This is to provide a little extra flexibility in those cases which
6642 sub am_primary_prefixes ($$@)
6644 my ($primary, $can_dist, @prefixes) = @_;
6647 my %valid = map { $_ => 0 } @prefixes;
6648 $valid{'EXTRA'} = 0;
6649 foreach my $var (variables $primary)
6651 # Automake is allowed to define variables that look like primaries
6652 # but which aren't. E.g. INSTALL_sh_DATA.
6653 # Autoconf can also define variables like INSTALL_DATA, so
6654 # ignore all configure variables (at least those which are not
6655 # redefined in Makefile.am).
6656 # FIXME: We should make sure that these variables are not
6657 # conditionally defined (or else adjust the condition below).
6658 my $def = $var->def (TRUE);
6659 next if $def && $def->owner != VAR_MAKEFILE;
6661 my $varname = $var->name;
6663 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_[[:alnum:]]+$/)
6665 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
6666 if ($dist ne '' && ! $can_dist)
6669 "invalid variable `$varname': `dist' is forbidden");
6671 # Standard directories must be explicitly allowed.
6672 elsif (! defined $valid{$X} && exists $standard_prefix{$X})
6675 "`${X}dir' is not a legitimate directory " .
6678 # A not explicitly valid directory is allowed if Xdir is defined.
6679 elsif (! defined $valid{$X} &&
6680 $var->requires_variables ("`$varname' is used", "${X}dir"))
6682 # Nothing to do. Any error message has been output
6683 # by $var->requires_variables.
6687 # Ensure all extended prefixes are actually used.
6688 $valid{"$base$dist$X"} = 1;
6693 prog_error "unexpected variable name: $varname";
6697 # Return only those which are actually defined.
6698 return sort grep { var ($_ . '_' . $primary) } keys %valid;
6702 # Handle `where_HOW' variable magic. Does all lookups, generates
6703 # install code, and possibly generates code to define the primary
6704 # variable. The first argument is the name of the .am file to munge,
6705 # the second argument is the primary variable (e.g. HEADERS), and all
6706 # subsequent arguments are possible installation locations.
6708 # Returns list of [$location, $value] pairs, where
6709 # $value's are the values in all where_HOW variable, and $location
6710 # there associated location (the place here their parent variables were
6713 # FIXME: this should be rewritten to be cleaner. It should be broken
6714 # up into multiple functions.
6716 # Usage is: am_install_var (OPTION..., file, HOW, where...)
6723 my $default_dist = 0;
6726 if ($args[0] eq '-noextra')
6730 elsif ($args[0] eq '-candist')
6734 elsif ($args[0] eq '-defaultdist')
6739 elsif ($args[0] !~ /^-/)
6746 my ($file, $primary, @prefix) = @args;
6748 # Now that configure substitutions are allowed in where_HOW
6749 # variables, it is an error to actually define the primary. We
6750 # allow `JAVA', as it is customarily used to mean the Java
6751 # interpreter. This is but one of several Java hacks. Similarly,
6752 # `PYTHON' is customarily used to mean the Python interpreter.
6753 reject_var $primary, "`$primary' is an anachronism"
6754 unless $primary eq 'JAVA' || $primary eq 'PYTHON';
6756 # Get the prefixes which are valid and actually used.
6757 @prefix = am_primary_prefixes ($primary, $can_dist, @prefix);
6759 # If a primary includes a configure substitution, then the EXTRA_
6760 # form is required. Otherwise we can't properly do our job.
6766 foreach my $X (@prefix)
6768 my $nodir_name = $X;
6769 my $one_name = $X . '_' . $primary;
6770 my $one_var = var $one_name;
6772 my $strip_subdir = 1;
6773 # If subdir prefix should be preserved, do so.
6774 if ($nodir_name =~ /^nobase_/)
6777 $nodir_name =~ s/^nobase_//;
6780 # If files should be distributed, do so.
6784 $dist_p = (($default_dist && $nodir_name !~ /^nodist_/)
6785 || (! $default_dist && $nodir_name =~ /^dist_/));
6786 $nodir_name =~ s/^(dist|nodist)_//;
6790 # Use the location of the currently processed variable.
6791 # We are not processing a particular condition, so pick the first
6793 my $tmpcond = $one_var->conditions->one_cond;
6794 my $where = $one_var->rdef ($tmpcond)->location->clone;
6796 # Append actual contents of where_PRIMARY variable to
6797 # @result, skipping @substitutions@.
6798 foreach my $locvals ($one_var->value_as_list_recursive (location => 1))
6800 my ($loc, $value) = @$locvals;
6801 # Skip configure substitutions.
6802 if ($value =~ /^\@.*\@$/)
6804 if ($nodir_name eq 'EXTRA')
6807 "`$one_name' contains configure substitution, "
6810 # Check here to make sure variables defined in
6811 # configure.ac do not imply that EXTRA_PRIMARY
6813 elsif (! defined $configure_vars{$one_name})
6815 $require_extra = $one_name
6821 push (@result, $locvals);
6824 # A blatant hack: we rewrite each _PROGRAMS primary to include
6826 append_exeext ($one_name)
6827 if $primary eq 'PROGRAMS';
6828 # "EXTRA" shouldn't be used when generating clean targets,
6829 # all, or install targets. We used to warn if EXTRA_FOO was
6830 # defined uselessly, but this was annoying.
6832 if $nodir_name eq 'EXTRA';
6834 if ($nodir_name eq 'check')
6836 push (@check, '$(' . $one_name . ')');
6840 push (@used, '$(' . $one_name . ')');
6843 # Is this to be installed?
6844 my $install_p = $nodir_name ne 'noinst' && $nodir_name ne 'check';
6846 # If so, with install-exec? (or install-data?).
6847 my $exec_p = ($nodir_name =~ /$EXEC_DIR_PATTERN/o);
6849 my $check_options_p = $install_p && !! option 'std-options';
6851 # Use the location of the currently processed variable as context.
6852 $where->push_context ("while processing `$one_name'");
6854 # The variable containing all file to distribute.
6855 my $distvar = "\$($one_name)";
6856 $distvar = shadow_unconditionally ($one_name, $where)
6857 if ($dist_p && $one_var->has_conditional_contents);
6859 # Singular form of $PRIMARY.
6860 (my $one_primary = $primary) =~ s/S$//;
6861 $output_rules .= &file_contents ($file, $where,
6862 PRIMARY => $primary,
6863 ONE_PRIMARY => $one_primary,
6865 NDIR => $nodir_name,
6866 BASE => $strip_subdir,
6869 INSTALL => $install_p,
6871 DISTVAR => $distvar,
6872 'CK-OPTS' => $check_options_p);
6875 # The JAVA variable is used as the name of the Java interpreter.
6876 # The PYTHON variable is used as the name of the Python interpreter.
6877 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
6880 define_pretty_variable ($primary, TRUE, INTERNAL, @used);
6881 $output_vars .= "\n";
6884 err_var ($require_extra,
6885 "`$require_extra' contains configure substitution,\n"
6886 . "but `EXTRA_$primary' not defined")
6887 if ($require_extra && ! var ('EXTRA_' . $primary));
6889 # Push here because PRIMARY might be configure time determined.
6890 push (@all, '$(' . $primary . ')')
6891 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
6893 # Make the result unique. This lets the user use conditionals in
6894 # a natural way, but still lets us program lazily -- we don't have
6895 # to worry about handling a particular object more than once.
6896 # We will keep only one location per object.
6898 for my $pair (@result)
6900 my ($loc, $val) = @$pair;
6901 $result{$val} = $loc;
6903 my @l = sort keys %result;
6904 return map { [$result{$_}->clone, $_] } @l;
6908 ################################################################
6910 # Each key in this hash is the name of a directory holding a
6911 # Makefile.in. These variables are local to `is_make_dir'.
6913 my $make_dirs_set = 0;
6918 if (! $make_dirs_set)
6920 foreach my $iter (@configure_input_files)
6922 $make_dirs{dirname ($iter)} = 1;
6924 # We also want to notice Makefile.in's.
6925 foreach my $iter (@other_input_files)
6927 if ($iter =~ /Makefile\.in$/)
6929 $make_dirs{dirname ($iter)} = 1;
6934 return defined $make_dirs{$dir};
6937 ################################################################
6939 # Find the aux dir. This should match the algorithm used by
6940 # ./configure. (See the Autoconf documentation for for
6941 # AC_CONFIG_AUX_DIR.)
6942 sub locate_aux_dir ()
6944 if (! $config_aux_dir_set_in_configure_ac)
6946 # The default auxiliary directory is the first
6947 # of ., .., or ../.. that contains install-sh.
6948 # Assume . if install-sh doesn't exist yet.
6949 for my $dir (qw (. .. ../..))
6951 if (-f "$dir/install-sh")
6953 $config_aux_dir = $dir;
6957 $config_aux_dir = '.' unless $config_aux_dir;
6959 # Avoid unsightly '/.'s.
6960 $am_config_aux_dir =
6961 '$(top_srcdir)' . ($config_aux_dir eq '.' ? "" : "/$config_aux_dir");
6962 $am_config_aux_dir =~ s,/*$,,;
6966 # &maybe_push_required_file ($DIR, $FILE, $FULLFILE)
6967 # --------------------------------------------------
6968 # See if we want to push this file onto dist_common. This function
6969 # encodes the rules for deciding when to do so.
6970 sub maybe_push_required_file
6972 my ($dir, $file, $fullfile) = @_;
6974 if ($dir eq $relative_dir)
6976 push_dist_common ($file);
6979 elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
6981 # If we are doing the topmost directory, and the file is in a
6982 # subdir which does not have a Makefile, then we distribute it
6985 # If a required file is above the source tree, it is important
6986 # to prefix it with `$(srcdir)' so that no VPATH search is
6987 # performed. Otherwise problems occur with Make implementations
6988 # that rewrite and simplify rules whose dependencies are found in a
6989 # VPATH location. Here is an example with OSF1/Tru64 Make.
7001 # Dependency `../a' was found in `sub/../a', but this make
7002 # implementation simplified it as `a'. (Note that the sub/
7003 # directory does not even exist.)
7005 # This kind of VPATH rewriting seems hard to cancel. The
7006 # distdir.am hack against VPATH rewriting works only when no
7007 # simplification is done, i.e., for dependencies which are in
7008 # subdirectories, not in enclosing directories. Hence, in
7009 # the latter case we use a full path to make sure no VPATH
7011 $fullfile = '$(srcdir)/' . $fullfile
7012 if $dir =~ m,^\.\.(?:$|/),;
7014 push_dist_common ($fullfile);
7021 # If a file name appears as a key in this hash, then it has already
7022 # been checked for. This allows us not to report the same error more
7024 my %required_file_not_found = ();
7026 # &require_file_internal ($WHERE, $MYSTRICT, $DIRECTORY, @FILES)
7027 # --------------------------------------------------------------
7028 # Verify that the file must exist in $DIRECTORY, or install it.
7029 # $MYSTRICT is the strictness level at which this file becomes required.
7030 sub require_file_internal ($$$@)
7032 my ($where, $mystrict, $dir, @files) = @_;
7034 foreach my $file (@files)
7036 my $fullfile = "$dir/$file";
7038 my $dangling_sym = 0;
7040 if (-l $fullfile && ! -f $fullfile)
7044 elsif (dir_has_case_matching_file ($dir, $file))
7047 maybe_push_required_file ($dir, $file, $fullfile);
7050 # `--force-missing' only has an effect if `--add-missing' is
7052 if ($found_it && (! $add_missing || ! $force_missing))
7058 # If we've already looked for it, we're done. You might
7059 # wonder why we don't do this before searching for the
7060 # file. If we do that, then something like
7061 # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
7065 next if defined $required_file_not_found{$fullfile};
7066 $required_file_not_found{$fullfile} = 1;
7069 if ($strictness >= $mystrict)
7071 if ($dangling_sym && $add_missing)
7079 # Only install missing files according to our desired
7081 my $message = "required file `$fullfile' not found";
7084 if (-f ("$libdir/$file"))
7088 # Install the missing file. Symlink if we
7089 # can, copy if we must. Note: delete the file
7090 # first, in case it is a dangling symlink.
7091 $message = "installing `$fullfile'";
7092 # Windows Perl will hang if we try to delete a
7093 # file that doesn't exist.
7094 unlink ($fullfile) if -f $fullfile;
7095 if ($symlink_exists && ! $copy_missing)
7097 if (! symlink ("$libdir/$file", $fullfile))
7100 $trailer = "; error while making link: $!";
7103 elsif (system ('cp', "$libdir/$file", $fullfile))
7106 $trailer = "\n error while copying";
7108 reset_dir_cache ($dir);
7111 if (! maybe_push_required_file (dirname ($fullfile),
7114 if (! $found_it && ! $automake_will_process_aux_dir)
7116 # We have added the file but could not push it
7117 # into DIST_COMMON, probably because this is
7118 # an auxiliary file and we are not processing
7119 # the top level Makefile. Furthermore Automake
7120 # hasn't been asked to create the Makefile.in
7121 # that distribute the aux dir files.
7122 error ($where, 'Please make a full run of automake'
7123 . " so $fullfile gets distributed.");
7128 # If --force-missing was specified, and we have
7129 # actually found the file, then do nothing.
7131 if $found_it && $force_missing;
7133 # If we couldn' install the file, but it is a target in
7134 # the Makefile, don't print anything. This allows files
7135 # like README, AUTHORS, or THANKS to be generated.
7137 if !$suppress && rule $file;
7139 msg ($suppress ? 'note' : 'error', $where, "$message$trailer");
7145 # &require_file ($WHERE, $MYSTRICT, @FILES)
7146 # -----------------------------------------
7147 sub require_file ($$@)
7149 my ($where, $mystrict, @files) = @_;
7150 require_file_internal ($where, $mystrict, $relative_dir, @files);
7153 # &require_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7154 # -----------------------------------------------------------
7155 sub require_file_with_macro ($$$@)
7157 my ($cond, $macro, $mystrict, @files) = @_;
7158 $macro = rvar ($macro) unless ref $macro;
7159 require_file ($macro->rdef ($cond)->location, $mystrict, @files);
7163 # &require_conf_file ($WHERE, $MYSTRICT, @FILES)
7164 # ----------------------------------------------
7165 # Looks in configuration path, as specified by AC_CONFIG_AUX_DIR.
7166 sub require_conf_file ($$@)
7168 my ($where, $mystrict, @files) = @_;
7169 require_file_internal ($where, $mystrict, $config_aux_dir, @files);
7173 # &require_conf_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7174 # ----------------------------------------------------------------
7175 sub require_conf_file_with_macro ($$$@)
7177 my ($cond, $macro, $mystrict, @files) = @_;
7178 require_conf_file (rvar ($macro)->rdef ($cond)->location,
7182 ################################################################
7184 # &require_build_directory ($DIRECTORY)
7185 # ------------------------------------
7186 # Emit rules to create $DIRECTORY if needed, and return
7187 # the file that any target requiring this directory should be made
7189 sub require_build_directory ($)
7191 my $directory = shift;
7192 my $dirstamp = "$directory/\$(am__dirstamp)";
7194 # Don't emit the rule twice.
7195 if (! defined $directory_map{$directory})
7197 $directory_map{$directory} = 1;
7199 # Set a variable for the dirstamp basename.
7200 define_pretty_variable ('am__dirstamp', TRUE, INTERNAL,
7201 '$(am__leading_dot)dirstamp');
7203 # Directory must be removed by `make distclean'.
7204 $clean_files{$dirstamp} = DIST_CLEAN;
7206 $output_rules .= ("$dirstamp:\n"
7207 . "\t\@\$(mkdir_p) $directory\n"
7208 . "\t\@: > $dirstamp\n");
7214 # &require_build_directory_maybe ($FILE)
7215 # --------------------------------------
7216 # If $FILE lies in a subdirectory, emit a rule to create this
7217 # directory and return the file that $FILE should be made
7218 # dependent upon. Otherwise, just return the empty string.
7219 sub require_build_directory_maybe ($)
7222 my $directory = dirname ($file);
7224 if ($directory ne '.')
7226 return require_build_directory ($directory);
7234 ################################################################
7236 # Push a list of files onto dist_common.
7237 sub push_dist_common
7239 prog_error "push_dist_common run after handle_dist"
7240 if $handle_dist_run;
7241 Automake::Variable::define ('DIST_COMMON', VAR_AUTOMAKE, '+', TRUE, "@_",
7242 '', INTERNAL, VAR_PRETTY);
7246 ################################################################
7248 # generate_makefile ($MAKEFILE_AM, $MAKEFILE_IN)
7249 # ----------------------------------------------
7250 # Generate a Makefile.in given the name of the corresponding Makefile and
7251 # the name of the file output by config.status.
7252 sub generate_makefile ($$)
7254 my ($makefile_am, $makefile_in) = @_;
7256 # Reset all the Makefile.am related variables.
7257 initialize_per_input;
7259 # AUTOMAKE_OPTIONS can contains -W flags to disable or enable
7260 # warnings for this file. So hold any warning issued before
7261 # we have processed AUTOMAKE_OPTIONS.
7262 buffer_messages ('warning');
7264 # Name of input file ("Makefile.am") and output file
7265 # ("Makefile.in"). These have no directory components.
7266 $am_file_name = basename ($makefile_am);
7267 $in_file_name = basename ($makefile_in);
7269 # $OUTPUT is encoded. If it contains a ":" then the first element
7270 # is the real output file, and all remaining elements are input
7271 # files. We don't scan or otherwise deal with these input files,
7272 # other than to mark them as dependencies. See
7273 # &scan_autoconf_files for details.
7274 my ($makefile, @inputs) = split (/:/, $output_files{$makefile_in});
7276 $relative_dir = dirname ($makefile);
7277 $am_relative_dir = dirname ($makefile_am);
7279 read_main_am_file ($makefile_am);
7282 # Process buffered warnings.
7284 # Fatal error. Just return, so we can continue with next file.
7287 # Process buffered warnings.
7290 # There are a few install-related variables that you should not define.
7291 foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
7296 my $def = $v->def (TRUE);
7297 prog_error "$var not defined in condition TRUE"
7299 reject_var $var, "`$var' should not be defined"
7300 if $def->owner != VAR_AUTOMAKE;
7304 # Catch some obsolete variables.
7305 msg_var ('obsolete', 'INCLUDES',
7306 "`INCLUDES' is the old name for `AM_CPPFLAGS' (or `*_CPPFLAGS')")
7307 if var ('INCLUDES');
7309 # Must do this after reading .am file.
7310 define_variable ('subdir', $relative_dir, INTERNAL);
7312 # If DIST_SUBDIRS is defined, make sure SUBDIRS is, so that
7313 # recursive rules are enabled.
7314 define_pretty_variable ('SUBDIRS', TRUE, INTERNAL, '')
7315 if var 'DIST_SUBDIRS' && ! var 'SUBDIRS';
7317 # Check first, because we might modify some state.
7319 check_gnu_standards;
7320 check_gnits_standards;
7322 handle_configure ($makefile_am, $makefile_in, $makefile, @inputs);
7329 # These must be run after all the sources are scanned. They
7330 # use variables defined by &handle_libraries, &handle_ltlibraries,
7331 # or &handle_programs.
7336 # Variables used by distdir.am and tags.am.
7337 define_pretty_variable ('SOURCES', TRUE, INTERNAL, @sources);
7338 if (! option 'no-dist')
7340 define_pretty_variable ('DIST_SOURCES', TRUE, INTERNAL, @dist_sources);
7353 handle_minor_options;
7356 # This must come after most other rules.
7360 do_check_merge_target;
7361 handle_all ($makefile);
7364 if (var ('lib_LTLIBRARIES') && var ('bin_PROGRAMS'))
7366 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
7370 handle_clean ($makefile);
7371 handle_factored_dependencies;
7373 # Comes last, because all the above procedures may have
7374 # defined or overridden variables.
7375 $output_vars .= output_variables;
7379 my ($out_file) = $output_directory . '/' . $makefile_in;
7381 if ($exit_code != 0)
7383 verb "not writing $out_file because of earlier errors";
7387 if (! -d ($output_directory . '/' . $am_relative_dir))
7389 mkdir ($output_directory . '/' . $am_relative_dir, 0755);
7392 # We make sure that `all:' is the first target.
7394 "$output_vars$output_all$output_header$output_rules$output_trailer";
7396 # Decide whether we must update the output file or not.
7397 # We have to update in the following situations.
7398 # * $force_generation is set.
7399 # * any of the output dependencies is younger than the output
7400 # * the contents of the output is different (this can happen
7401 # if the project has been populated with a file listed in
7402 # @common_files since the last run).
7403 # Output's dependencies are split in two sets:
7404 # * dependencies which are also configure dependencies
7405 # These do not change between each Makefile.am
7406 # * other dependencies, specific to the Makefile.am being processed
7407 # (such as the Makefile.am itself, or any Makefile fragment
7409 my $timestamp = mtime $out_file;
7410 if (! $force_generation
7411 && $configure_deps_greatest_timestamp < $timestamp
7412 && $output_deps_greatest_timestamp < $timestamp
7413 && $output eq contents ($out_file))
7415 verb "$out_file unchanged";
7416 # No need to update.
7423 or fatal "cannot remove $out_file: $!\n";
7426 my $gm_file = new Automake::XFile "> $out_file";
7427 verb "creating $out_file";
7428 print $gm_file $output;
7431 ################################################################
7436 ################################################################
7438 # Print usage information.
7441 print "Usage: $0 [OPTION] ... [Makefile]...
7443 Generate Makefile.in for configure from Makefile.am.
7446 --help print this help, then exit
7447 --version print version number, then exit
7448 -v, --verbose verbosely list files processed
7449 --no-force only update Makefile.in's that are out of date
7450 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
7452 Dependency tracking:
7453 -i, --ignore-deps disable dependency tracking code
7454 --include-deps enable dependency tracking code
7457 --cygnus assume program is part of Cygnus-style tree
7458 --foreign set strictness to foreign
7459 --gnits set strictness to gnits
7460 --gnu set strictness to gnu
7463 -a, --add-missing add missing standard files to package
7464 --libdir=DIR directory storing library files
7465 -c, --copy with -a, copy missing files (default is symlink)
7466 -f, --force-missing force update of standard files
7469 Automake::ChannelDefs::usage;
7473 foreach my $iter (sort ((@common_files, @common_sometimes)))
7475 push (@lcomm, $iter) unless $iter eq $last;
7480 print "\nFiles which are automatically distributed, if found:\n";
7481 format USAGE_FORMAT =
7482 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
7483 $four[0], $four[1], $four[2], $four[3]
7485 $~ = "USAGE_FORMAT";
7488 my $rows = int(@lcomm / $cols);
7489 my $rest = @lcomm % $cols;
7500 for (my $y = 0; $y < $rows; $y++)
7502 @four = ("", "", "", "");
7503 for (my $x = 0; $x < $cols; $x++)
7505 last if $y + 1 == $rows && $x == $rest;
7507 my $idx = (($x > $rest)
7508 ? ($rows * $rest + ($rows - 1) * ($x - $rest))
7512 $four[$x] = $lcomm[$idx];
7517 print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7519 # --help always returns 0 per GNU standards.
7526 # Print version information
7530 automake (GNU $PACKAGE) $VERSION
7531 Written by Tom Tromey <tromey\@redhat.com>
7532 and Alexandre Duret-Lutz <adl\@gnu.org>.
7534 Copyright 2005 Free Software Foundation, Inc.
7535 This is free software; see the source for copying conditions. There is NO
7536 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7538 # --version always returns 0 per GNU standards.
7542 ################################################################
7544 # Parse command line.
7545 sub parse_arguments ()
7548 set_strictness ('gnu');
7550 my $cli_where = new Automake::Location;
7553 'libdir=s' => \$libdir,
7554 'gnu' => sub { set_strictness ('gnu'); },
7555 'gnits' => sub { set_strictness ('gnits'); },
7556 'cygnus' => sub { set_global_option ('cygnus', $cli_where); },
7557 'foreign' => sub { set_strictness ('foreign'); },
7558 'include-deps' => sub { unset_global_option ('no-dependencies'); },
7559 'i|ignore-deps' => sub { set_global_option ('no-dependencies',
7561 'no-force' => sub { $force_generation = 0; },
7562 'f|force-missing' => \$force_missing,
7563 'o|output-dir=s' => \$output_directory,
7564 'a|add-missing' => \$add_missing,
7565 'c|copy' => \$copy_missing,
7566 'v|verbose' => sub { setup_channel 'verb', silent => 0; },
7567 'W|warnings=s' => \&parse_warnings,
7568 # These long options (--Werror and --Wno-error) for backward
7569 # compatibility. Use -Werror and -Wno-error today.
7570 'Werror' => sub { parse_warnings 'W', 'error'; },
7571 'Wno-error' => sub { parse_warnings 'W', 'no-error'; },
7574 Getopt::Long::config ("bundling", "pass_through");
7576 # See if --version or --help is used. We want to process these before
7577 # anything else because the GNU Coding Standards require us to
7578 # `exit 0' after processing these options, and we can't guarantee this
7579 # if we treat other options first. (Handling other options first
7580 # could produce error diagnostics, and in this condition it is
7581 # confusing if Automake does `exit 0'.)
7582 my %cli_options_1st_pass =
7584 'version' => \&version,
7586 # Recognize all other options (and their arguments) but do nothing.
7587 map { $_ => sub {} } (keys %cli_options)
7589 my @ARGV_backup = @ARGV;
7590 Getopt::Long::GetOptions %cli_options_1st_pass
7592 @ARGV = @ARGV_backup;
7594 # Now *really* process the options. This time we know that --help
7595 # and --version are not present, but we specify them nonetheless so
7596 # that ambiguous abbreviation are diagnosed.
7597 Getopt::Long::GetOptions %cli_options, 'version' => sub {}, 'help' => sub {}
7600 if (defined $output_directory)
7602 msg 'obsolete', "`--output-dir' is deprecated\n";
7606 # In the next release we'll remove this entirely.
7607 $output_directory = '.';
7610 return unless @ARGV;
7612 if ($ARGV[0] =~ /^-./)
7615 for my $k (keys %cli_options)
7617 if ($k =~ /(.*)=s$/)
7619 map { $argopts{(length ($_) == 1)
7620 ? "-$_" : "--$_" } = 1; } (split (/\|/, $1));
7623 if ($ARGV[0] eq '--')
7627 elsif (exists $argopts{$ARGV[0]})
7629 fatal ("option `$ARGV[0]' requires an argument\n"
7630 . "Try `$0 --help' for more information.");
7634 fatal ("unrecognized option `$ARGV[0]'.\n"
7635 . "Try `$0 --help' for more information.");
7640 foreach my $arg (@ARGV)
7642 fatal ("empty argument\nTry `$0 --help' for more information.")
7645 # Handle $local:$input syntax.
7646 my ($local, @rest) = split (/:/, $arg);
7647 @rest = ("$local.in",) unless @rest;
7648 my $input = locate_am @rest;
7651 push @input_files, $input;
7652 $output_files{$input} = join (':', ($local, @rest));
7656 error "no Automake input file found for `$arg'";
7660 fatal "no input file found among supplied arguments"
7661 if $errspec && ! @input_files;
7664 ################################################################
7666 # Parse the WARNINGS environment variable.
7669 # Parse command line.
7672 $configure_ac = require_configure_ac;
7674 # Do configure.ac scan only once.
7675 scan_autoconf_files;
7680 $msg = "\nDid you forget AC_CONFIG_FILES([Makefile]) in $configure_ac?"
7681 if -f 'Makefile.am';
7682 fatal ("no `Makefile.am' found for any configure output$msg");
7685 # Now do all the work on each file.
7686 foreach my $file (@input_files)
7688 ($am_file = $file) =~ s/\.in$//;
7689 if (! -f ($am_file . '.am'))
7691 error "`$am_file.am' does not exist";
7695 # Any warning setting now local to this Makefile.am.
7698 generate_makefile ($am_file . '.am', $file);
7700 # Back out any warning setting.
7708 ### Setup "GNU" style for perl-mode and cperl-mode.
7710 ## perl-indent-level: 2
7711 ## perl-continued-statement-offset: 2
7712 ## perl-continued-brace-offset: 0
7713 ## perl-brace-offset: 0
7714 ## perl-brace-imaginary-offset: 0
7715 ## perl-label-offset: -2
7716 ## cperl-indent-level: 2
7717 ## cperl-brace-offset: 0
7718 ## cperl-continued-brace-offset: 0
7719 ## cperl-label-offset: -2
7720 ## cperl-extra-newline-before-brace: t
7721 ## cperl-merge-trailing-else: nil
7722 ## cperl-continued-statement-offset: 2