2 # automake - create Makefile.in from Makefile.am -*- perl -*-
4 # Copyright (C) 1994-2018 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
20 # Perl reimplementation by Tom Tromey <tromey@redhat.com>, and
21 # Alexandre Duret-Lutz <adl@gnu.org>.
29 unshift (@INC, '@datadir@/@PACKAGE@-@APIVERSION@')
30 unless $ENV{AUTOMAKE_UNINSTALLED};
32 # Override SHELL. This is required on DJGPP so that system() uses
33 # bash, not COMMAND.COM which doesn't quote arguments properly.
34 # Other systems aren't expected to use $SHELL when Automake
35 # runs, but it should be safe to drop the "if DJGPP" guard if
36 # it turns up other systems need the same thing. After all,
37 # if SHELL is used, ./configure's SHELL is always better than
38 # the user's SHELL (which may be something like tcsh).
39 $ENV{'SHELL'} = '@SHELL@' if exists $ENV{'DJDIR'};
49 require Thread::Queue;
53 use Automake::General;
55 use Automake::Channels;
56 use Automake::ChannelDefs;
57 use Automake::Configure_ac;
58 use Automake::FileUtils;
59 use Automake::Location;
60 use Automake::Condition qw/TRUE FALSE/;
61 use Automake::DisjConditions;
62 use Automake::Options;
63 use Automake::Variable;
66 use Automake::RuleDef;
67 use Automake::Wrap 'makefile_wrap';
68 use Automake::Language;
73 ## ----------------------- ##
74 ## Subroutine prototypes. ##
75 ## ----------------------- ##
77 sub append_exeext (&$);
78 sub check_gnits_standards ();
79 sub check_gnu_standards ();
80 sub check_trailing_slash ($\$);
82 sub define_files_variable ($\@$$);
83 sub define_standard_variables ();
84 sub define_verbose_libtool ();
85 sub define_verbose_texinfo ();
86 sub do_check_merge_target ();
87 sub get_number_of_threads ();
88 sub handle_compile ();
91 sub handle_emacs_lisp ();
92 sub handle_factored_dependencies ();
94 sub handle_gettext ();
95 sub handle_headers ();
96 sub handle_install ();
98 sub handle_languages ();
99 sub handle_libraries ();
100 sub handle_libtool ();
101 sub handle_ltlibraries ();
102 sub handle_makefiles_serial ();
103 sub handle_man_pages ();
104 sub handle_minor_options ();
105 sub handle_options ();
106 sub handle_programs ();
107 sub handle_python ();
108 sub handle_scripts ();
109 sub handle_silent ();
110 sub handle_subdirs ();
112 sub handle_targets ();
114 sub handle_tests_dejagnu ();
115 sub handle_texinfo ();
116 sub handle_user_recursion ();
117 sub initialize_per_input ();
118 sub lang_lex_finish ();
120 sub lang_vala_finish ();
121 sub lang_yacc_finish ();
122 sub locate_aux_dir ();
123 sub parse_arguments ();
124 sub scan_aclocal_m4 ();
125 sub scan_autoconf_files ();
128 sub transform_token ($\%$);
131 sub yacc_lex_finish_helper ();
137 # Some regular expressions. One reason to put them here is that it
138 # makes indentation work better in Emacs.
140 # Writing singled-quoted-$-terminated regexes is a pain because
141 # perl-mode thinks of $' as the ${'} variable (instead of a $ followed
142 # by a closing quote. Letting perl-mode think the quote is not closed
143 # leads to all sort of misindentations. On the other hand, defining
144 # regexes as double-quoted strings is far less readable. So usually
147 # $REGEX = '^regex_value' . "\$";
149 my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
150 my $WHITE_PATTERN = '^\s*' . "\$";
151 my $COMMENT_PATTERN = '^#';
152 my $TARGET_PATTERN='[$a-zA-Z0-9_.@%][-.a-zA-Z0-9_(){}/$+@%]*';
153 # A rule has three parts: a list of targets, a list of dependencies,
154 # and optionally actions.
156 "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
158 # Only recognize leading spaces, not leading tabs. If we recognize
159 # leading tabs here then we need to make the reader smarter, because
160 # otherwise it will think rules like 'foo=bar; \' are errors.
161 my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)' . "\$";
162 # This pattern recognizes a Gnits version id and sets $1 if the
163 # release is an alpha release. We also allow a suffix which can be
164 # used to extend the version number with a "fork" identifier.
165 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
167 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?' . "\$";
169 '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
171 '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
172 my $PATH_PATTERN = '(\w|[+/.-])+';
173 # This will pass through anything not of the prescribed form.
174 my $INCLUDE_PATTERN = ('^include\s+'
175 . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
176 . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
177 . '|([^/\$]' . $PATH_PATTERN . '))\s*(#.*)?' . "\$");
179 # Directories installed during 'install-exec' phase.
180 my $EXEC_DIR_PATTERN =
181 '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)' . "\$";
183 # Values for AC_CANONICAL_*
184 use constant AC_CANONICAL_BUILD => 1;
185 use constant AC_CANONICAL_HOST => 2;
186 use constant AC_CANONICAL_TARGET => 3;
188 # Values indicating when something should be cleaned.
189 use constant MOSTLY_CLEAN => 0;
190 use constant CLEAN => 1;
191 use constant DIST_CLEAN => 2;
192 use constant MAINTAINER_CLEAN => 3;
195 my @libtool_files = qw(ltmain.sh config.guess config.sub);
196 # ltconfig appears here for compatibility with old versions of libtool.
197 my @libtool_sometimes = qw(ltconfig ltcf-c.sh ltcf-cxx.sh ltcf-gcj.sh);
199 # Commonly found files we look for and automatically include in
202 (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
203 COPYING.LESSER ChangeLog INSTALL NEWS README THANKS TODO
204 ar-lib compile config.guess config.rpath
205 config.sub depcomp install-sh libversion.in mdate-sh
206 missing mkinstalldirs py-compile texinfo.tex ylwrap),
207 @libtool_files, @libtool_sometimes);
209 # Commonly used files we auto-include, but only sometimes. This list
210 # is used for the --help output only.
211 my @common_sometimes =
212 qw(aclocal.m4 acconfig.h config.h.top config.h.bot configure
213 configure.ac configure.in stamp-vti);
215 # Standard directories from the GNU Coding Standards, and additional
216 # pkg* directories from Automake. Stored in a hash for fast member check.
217 my %standard_prefix =
218 map { $_ => 1 } (qw(bin data dataroot doc dvi exec html include info
219 lib libexec lisp locale localstate man man1 man2
220 man3 man4 man5 man6 man7 man8 man9 oldinclude pdf
221 pkgdata pkginclude pkglib pkglibexec ps sbin
222 sharedstate sysconf));
224 # Copyright on generated Makefile.ins.
225 my $gen_copyright = "\
226 # Copyright (C) 1994-$RELEASE_YEAR Free Software Foundation, Inc.
228 # This Makefile.in is free software; the Free Software Foundation
229 # gives unlimited permission to copy and/or distribute it,
230 # with or without modifications, as long as this notice is preserved.
232 # This program is distributed in the hope that it will be useful,
233 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
234 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
235 # PARTICULAR PURPOSE.
238 # These constants are returned by the lang_*_rewrite functions.
239 # LANG_SUBDIR means that the resulting object file should be in a
240 # subdir if the source file is. In this case the file name cannot
241 # have '..' components.
242 use constant LANG_IGNORE => 0;
243 use constant LANG_PROCESS => 1;
244 use constant LANG_SUBDIR => 2;
246 # These are used when keeping track of whether an object can be built
247 # by two different paths.
248 use constant COMPILE_LIBTOOL => 1;
249 use constant COMPILE_ORDINARY => 2;
251 # We can't always associate a location to a variable or a rule,
252 # when it's defined by Automake. We use INTERNAL in this case.
253 use constant INTERNAL => new Automake::Location;
255 # Serialization keys for message queues.
256 use constant QUEUE_MESSAGE => "msg";
257 use constant QUEUE_CONF_FILE => "conf file";
258 use constant QUEUE_LOCATION => "location";
259 use constant QUEUE_STRING => "string";
261 ## ---------------------------------- ##
262 ## Variables related to the options. ##
263 ## ---------------------------------- ##
265 # TRUE if we should always generate Makefile.in.
266 my $force_generation = 1;
268 # From the Perl manual.
269 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
271 # TRUE if missing standard files should be installed.
274 # TRUE if we should copy missing files; otherwise symlink if possible.
275 my $copy_missing = 0;
277 # TRUE if we should always update files that we know about.
278 my $force_missing = 0;
281 ## ---------------------------------------- ##
282 ## Variables filled during files scanning. ##
283 ## ---------------------------------------- ##
285 # Name of the configure.ac file.
288 # Files found by scanning configure.ac for LIBOBJS.
291 # Names used in AC_CONFIG_HEADERS call.
292 my @config_headers = ();
294 # Names used in AC_CONFIG_LINKS call.
295 my @config_links = ();
297 # List of Makefile.am's to process, and their corresponding outputs.
298 my @input_files = ();
299 my %output_files = ();
301 # Complete list of Makefile.am's that exist.
302 my @configure_input_files = ();
304 # List of files in AC_CONFIG_FILES/AC_OUTPUT without Makefile.am's,
306 my @other_input_files = ();
307 # Where each AC_CONFIG_FILES/AC_OUTPUT/AC_CONFIG_LINK/AC_CONFIG_HEADERS
308 # appears. The keys are the files created by these macros.
309 my %ac_config_files_location = ();
310 # The condition under which AC_CONFIG_FOOS appears.
311 my %ac_config_files_condition = ();
313 # Directory to search for configure-required files. This
314 # will be computed by locate_aux_dir() and can be set using
315 # AC_CONFIG_AUX_DIR in configure.ac.
316 # $CONFIG_AUX_DIR is the 'raw' directory, valid only in the source-tree.
317 my $config_aux_dir = '';
318 my $config_aux_dir_set_in_configure_ac = 0;
319 # $AM_CONFIG_AUX_DIR is prefixed with $(top_srcdir), so it can be used
321 my $am_config_aux_dir = '';
323 # Directory to search for AC_LIBSOURCE files, as set by AC_CONFIG_LIBOBJ_DIR
325 my $config_libobj_dir = '';
327 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
328 my $seen_gettext = 0;
329 # Whether AM_GNU_GETTEXT([external]) is used.
330 my $seen_gettext_external = 0;
331 # Where AM_GNU_GETTEXT appears.
332 my $ac_gettext_location;
333 # Whether AM_GNU_GETTEXT_INTL_SUBDIR has been seen.
334 my $seen_gettext_intl = 0;
336 # The arguments of the AM_EXTRA_RECURSIVE_TARGETS call (if any).
337 my @extra_recursive_targets = ();
339 # Lists of tags supported by Libtool.
340 my %libtool_tags = ();
341 # 1 if Libtool uses LT_SUPPORTED_TAG. If it does, then it also
342 # uses AC_REQUIRE_AUX_FILE.
343 my $libtool_new_api = 0;
345 # Most important AC_CANONICAL_* macro seen so far.
346 my $seen_canonical = 0;
348 # Where AM_MAINTAINER_MODE appears.
351 # Actual version we've seen.
352 my $package_version = '';
354 # Where version is defined.
355 my $package_version_location;
357 # TRUE if we've seen AM_PROG_AR
360 # Location of AC_REQUIRE_AUX_FILE calls, indexed by their argument.
361 my %required_aux_file = ();
363 # Where AM_INIT_AUTOMAKE is called.
364 my $seen_init_automake = 0;
366 # TRUE if we've seen AM_AUTOMAKE_VERSION.
367 my $seen_automake_version = 0;
369 # Hash table of discovered configure substitutions. Keys are names,
370 # values are 'FILE:LINE' strings which are used by error message
372 my %configure_vars = ();
374 # Ignored configure substitutions (i.e., variables not to be output in
376 my %ignored_configure_vars = ();
378 # Files included by $configure_ac.
379 my @configure_deps = ();
381 # Greatest timestamp of configure's dependencies.
382 my $configure_deps_greatest_timestamp = 0;
384 # Hash table of AM_CONDITIONAL variables seen in configure.
385 my %configure_cond = ();
387 # This maps extensions onto language names.
388 my %extension_map = ();
390 # List of the DIST_COMMON files we discovered while reading
392 my @configure_dist_common = ();
394 # This maps languages names onto objects.
396 # Maps each linker variable onto a language object.
397 my %link_languages = ();
399 # maps extensions to needed source flags.
400 my %sourceflags = ();
402 # List of targets we must always output.
403 # FIXME: Complete, and remove falsely required targets.
404 my %required_targets =
417 # FIXME: Not required, temporary hacks.
418 # Well, actually they are sort of required: the -recursive
419 # targets will run them anyway...
425 'install-data-am' => 1,
426 'install-exec-am' => 1,
427 'install-html-am' => 1,
428 'install-dvi-am' => 1,
429 'install-pdf-am' => 1,
430 'install-ps-am' => 1,
431 'install-info-am' => 1,
432 'installcheck-am' => 1,
436 'cscopelist-am' => 1,
440 # Queue to push require_conf_file requirements to.
441 my $required_conf_file_queue;
443 # The name of the Makefile currently being processed.
446 ################################################################
448 ## ------------------------------------------ ##
449 ## Variables reset by &initialize_per_input. ##
450 ## ------------------------------------------ ##
452 # Relative dir of the output makefile.
455 # Greatest timestamp of the output's dependencies (excluding
456 # configure's dependencies).
457 my $output_deps_greatest_timestamp;
459 # These variables are used when generating each Makefile.in.
460 # They hold the Makefile.in until it is ready to be printed.
467 # This is the conditional stack, updated on if/else/endif, and
468 # used to build Condition objects.
471 # This holds the set of included files.
474 # List of dependencies for the obvious targets.
479 # Keys in this hash table are files to delete. The associated
480 # value tells when this should happen (MOSTLY_CLEAN, DIST_CLEAN, etc.)
483 # Keys in this hash table are object files or other files in
484 # subdirectories which need to be removed. This only holds files
485 # which are created by compilations. The value in the hash indicates
486 # when the file should be removed.
487 my %compile_clean_files;
489 # Keys in this hash table are directories where we expect to build a
490 # libtool object. We use this information to decide what directories
492 my %libtool_clean_directories;
494 # Value of $(SOURCES), used by tags.am.
496 # Sources which go in the distribution.
499 # This hash maps object file names onto their corresponding source
500 # file names. This is used to ensure that each object is created
501 # by a single source file.
504 # This hash maps object file names onto an integer value representing
505 # whether this object has been built via ordinary compilation or
506 # libtool compilation (the COMPILE_* constants).
507 my %object_compilation_map;
510 # This keeps track of the directories for which we've already
511 # created dirstamp code. Keys are directories, values are stamp files.
512 # Several keys can share the same stamp files if they are equivalent
513 # (as are './/foo' and 'foo').
519 # This is a list of all targets to run during "make dist".
522 # List of all programs, libraries and ltlibraries as returned
527 # Blacklist of targets (as canonical base name) for which object file names
528 # may not be automatically shortened
531 # Keep track of all programs declared in this Makefile, without
532 # $(EXEEXT). @substitutions@ are not listed.
536 # This keeps track of which extensions we've seen (that we care
540 # This is random scratch space for the language finish functions.
541 # Don't randomly overwrite it; examine other uses of keys first.
542 my %language_scratch;
544 # We keep track of which objects need special (per-executable)
545 # handling on a per-language basis.
546 my %lang_specific_files;
548 # List of distributed files to be put in DIST_COMMON.
551 # This is set when 'handle_dist' has finished. Once this happens,
552 # we should no longer push on dist_common.
555 # Used to store a set of linkers needed to generate the sources currently
556 # under consideration.
559 # True if we need 'LINK' defined. This is a hack.
562 # Does the generated Makefile have to build some compiled object
563 # (for binary programs, or plain or libtool libraries)?
564 my $must_handle_compiled_objects;
566 # Record each file processed by make_paragraphs.
567 my %transformed_files;
569 ################################################################
571 ## ---------------------------------------------- ##
572 ## Variables not reset by &initialize_per_input. ##
573 ## ---------------------------------------------- ##
575 # Cache each file processed by make_paragraphs.
576 # (This is different from %transformed_files because
577 # %transformed_files is reset for each file while %am_file_cache
578 # it global to the run.)
581 ################################################################
583 # var_SUFFIXES_trigger ($TYPE, $VALUE)
584 # ------------------------------------
585 # This is called by Automake::Variable::define() when SUFFIXES
586 # is defined ($TYPE eq '') or appended ($TYPE eq '+').
587 # The work here needs to be performed as a side-effect of the
588 # macro_define() call because SUFFIXES definitions impact
589 # on $KNOWN_EXTENSIONS_PATTERN which is used used when parsing
591 sub var_SUFFIXES_trigger
593 my ($type, $value) = @_;
594 accept_extensions (split (' ', $value));
596 Automake::Variable::hook ('SUFFIXES', \&var_SUFFIXES_trigger);
598 ################################################################
601 # initialize_per_input ()
602 # -----------------------
603 # (Re)-Initialize per-Makefile.am variables.
604 sub initialize_per_input ()
606 reset_local_duplicates ();
608 $relative_dir = undef;
610 $output_deps_greatest_timestamp = 0;
616 $output_trailer = '';
618 Automake::Options::reset;
619 Automake::Variable::reset;
620 Automake::Rule::reset;
631 %compile_clean_files = ();
633 # We always include '.'. This isn't strictly correct.
634 %libtool_clean_directories = ('.' => 1);
640 %object_compilation_map = ();
649 $handle_dist_run = 0;
654 @dup_shortnames = ();
656 %known_programs = ();
657 %known_libraries = ();
659 %extension_seen = ();
661 %language_scratch = ();
663 %lang_specific_files = ();
667 $must_handle_compiled_objects = 0;
669 %transformed_files = ();
673 ################################################################
675 # Initialize our list of languages that are internally supported.
687 register_language ('name' => 'c',
689 'config_vars' => ['CC'],
691 'flags' => ['CFLAGS', 'CPPFLAGS'],
693 'compiler' => 'COMPILE',
694 'compile' => "\$(CC) @cpplike_flags \$(AM_CFLAGS) \$(CFLAGS)",
698 'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
699 'compile_flag' => '-c',
700 'output_flag' => '-o',
701 'libtool_tag' => 'CC',
702 'extensions' => ['.c']);
705 register_language ('name' => 'cxx',
707 'config_vars' => ['CXX'],
708 'linker' => 'CXXLINK',
709 'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
711 'flags' => ['CXXFLAGS', 'CPPFLAGS'],
712 'compile' => "\$(CXX) @cpplike_flags \$(AM_CXXFLAGS) \$(CXXFLAGS)",
714 'compiler' => 'CXXCOMPILE',
715 'compile_flag' => '-c',
716 'output_flag' => '-o',
717 'libtool_tag' => 'CXX',
721 'extensions' => ['.c++', '.cc', '.cpp', '.cxx', '.C']);
724 register_language ('name' => 'objc',
725 'Name' => 'Objective C',
726 'config_vars' => ['OBJC'],
727 'linker' => 'OBJCLINK',
728 'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
730 'flags' => ['OBJCFLAGS', 'CPPFLAGS'],
731 'compile' => "\$(OBJC) @cpplike_flags \$(AM_OBJCFLAGS) \$(OBJCFLAGS)",
733 'compiler' => 'OBJCCOMPILE',
734 'compile_flag' => '-c',
735 'output_flag' => '-o',
739 'extensions' => ['.m']);
742 register_language ('name' => 'objcxx',
743 'Name' => 'Objective C++',
744 'config_vars' => ['OBJCXX'],
745 'linker' => 'OBJCXXLINK',
746 'link' => '$(OBJCXXLD) $(AM_OBJCXXFLAGS) $(OBJCXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
747 'autodep' => 'OBJCXX',
748 'flags' => ['OBJCXXFLAGS', 'CPPFLAGS'],
749 'compile' => "\$(OBJCXX) @cpplike_flags \$(AM_OBJCXXFLAGS) \$(OBJCXXFLAGS)",
751 'compiler' => 'OBJCXXCOMPILE',
752 'compile_flag' => '-c',
753 'output_flag' => '-o',
754 'lder' => 'OBJCXXLD',
757 'extensions' => ['.mm']);
759 # Unified Parallel C.
760 register_language ('name' => 'upc',
761 'Name' => 'Unified Parallel C',
762 'config_vars' => ['UPC'],
763 'linker' => 'UPCLINK',
764 'link' => '$(UPCLD) $(AM_UPCFLAGS) $(UPCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
766 'flags' => ['UPCFLAGS', 'CPPFLAGS'],
767 'compile' => "\$(UPC) @cpplike_flags \$(AM_UPCFLAGS) \$(UPCFLAGS)",
769 'compiler' => 'UPCCOMPILE',
770 'compile_flag' => '-c',
771 'output_flag' => '-o',
775 'extensions' => ['.upc']);
778 register_language ('name' => 'header',
780 'extensions' => ['.h', '.H', '.hxx', '.h++', '.hh',
783 'output_extensions' => sub { return () },
785 '_finish' => sub { });
788 register_language ('name' => 'vala',
790 'config_vars' => ['VALAC'],
792 'compile' => '$(VALAC) $(AM_VALAFLAGS) $(VALAFLAGS)',
794 'compiler' => 'VALACOMPILE',
795 'extensions' => ['.vala'],
796 'output_extensions' => sub { (my $ext = $_[0]) =~ s/vala$/c/;
798 'rule_file' => 'vala',
799 '_finish' => \&lang_vala_finish,
800 '_target_hook' => \&lang_vala_target_hook,
801 'nodist_specific' => 1);
804 register_language ('name' => 'yacc',
806 'config_vars' => ['YACC'],
807 'flags' => ['YFLAGS'],
808 'compile' => '$(YACC) $(AM_YFLAGS) $(YFLAGS)',
810 'compiler' => 'YACCCOMPILE',
811 'extensions' => ['.y'],
812 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
814 'rule_file' => 'yacc',
815 '_finish' => \&lang_yacc_finish,
816 '_target_hook' => \&lang_yacc_target_hook,
817 'nodist_specific' => 1);
818 register_language ('name' => 'yaccxx',
819 'Name' => 'Yacc (C++)',
820 'config_vars' => ['YACC'],
821 'rule_file' => 'yacc',
822 'flags' => ['YFLAGS'],
824 'compiler' => 'YACCCOMPILE',
825 'compile' => '$(YACC) $(AM_YFLAGS) $(YFLAGS)',
826 'extensions' => ['.y++', '.yy', '.yxx', '.ypp'],
827 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
829 '_finish' => \&lang_yacc_finish,
830 '_target_hook' => \&lang_yacc_target_hook,
831 'nodist_specific' => 1);
834 register_language ('name' => 'lex',
836 'config_vars' => ['LEX'],
837 'rule_file' => 'lex',
838 'flags' => ['LFLAGS'],
839 'compile' => '$(LEX) $(AM_LFLAGS) $(LFLAGS)',
841 'compiler' => 'LEXCOMPILE',
842 'extensions' => ['.l'],
843 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
845 '_finish' => \&lang_lex_finish,
846 '_target_hook' => \&lang_lex_target_hook,
847 'nodist_specific' => 1);
848 register_language ('name' => 'lexxx',
849 'Name' => 'Lex (C++)',
850 'config_vars' => ['LEX'],
851 'rule_file' => 'lex',
852 'flags' => ['LFLAGS'],
853 'compile' => '$(LEX) $(AM_LFLAGS) $(LFLAGS)',
855 'compiler' => 'LEXCOMPILE',
856 'extensions' => ['.l++', '.ll', '.lxx', '.lpp'],
857 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
859 '_finish' => \&lang_lex_finish,
860 '_target_hook' => \&lang_lex_target_hook,
861 'nodist_specific' => 1);
864 register_language ('name' => 'asm',
865 'Name' => 'Assembler',
866 'config_vars' => ['CCAS', 'CCASFLAGS'],
868 'flags' => ['CCASFLAGS'],
869 # Users can set AM_CCASFLAGS to include DEFS, INCLUDES,
870 # or anything else required. They can also set CCAS.
871 # Or simply use Preprocessed Assembler.
872 'compile' => '$(CCAS) $(AM_CCASFLAGS) $(CCASFLAGS)',
874 'compiler' => 'CCASCOMPILE',
875 'compile_flag' => '-c',
876 'output_flag' => '-o',
877 'extensions' => ['.s']);
879 # Preprocessed Assembler.
880 register_language ('name' => 'cppasm',
881 'Name' => 'Preprocessed Assembler',
882 'config_vars' => ['CCAS', 'CCASFLAGS'],
885 'flags' => ['CCASFLAGS', 'CPPFLAGS'],
886 'compile' => "\$(CCAS) @cpplike_flags \$(AM_CCASFLAGS) \$(CCASFLAGS)",
888 'compiler' => 'CPPASCOMPILE',
889 'libtool_tag' => 'CC',
890 'compile_flag' => '-c',
891 'output_flag' => '-o',
892 'extensions' => ['.S', '.sx']);
895 register_language ('name' => 'f77',
896 'Name' => 'Fortran 77',
897 'config_vars' => ['F77'],
898 'linker' => 'F77LINK',
899 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
900 'flags' => ['FFLAGS'],
901 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
903 'compiler' => 'F77COMPILE',
904 'compile_flag' => '-c',
905 'output_flag' => '-o',
906 'libtool_tag' => 'F77',
910 'extensions' => ['.f', '.for']);
913 register_language ('name' => 'fc',
915 'config_vars' => ['FC'],
916 'linker' => 'FCLINK',
917 'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
918 'flags' => ['FCFLAGS'],
919 'compile' => '$(FC) $(AM_FCFLAGS) $(FCFLAGS)',
921 'compiler' => 'FCCOMPILE',
922 'compile_flag' => '-c',
923 'output_flag' => '-o',
924 'libtool_tag' => 'FC',
928 'extensions' => ['.f90', '.f95', '.f03', '.f08']);
930 # Preprocessed Fortran
931 register_language ('name' => 'ppfc',
932 'Name' => 'Preprocessed Fortran',
933 'config_vars' => ['FC'],
934 'linker' => 'FCLINK',
935 'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
938 'flags' => ['FCFLAGS', 'CPPFLAGS'],
940 'compiler' => 'PPFCCOMPILE',
941 'compile' => "\$(FC) @cpplike_flags \$(AM_FCFLAGS) \$(FCFLAGS)",
942 'compile_flag' => '-c',
943 'output_flag' => '-o',
944 'libtool_tag' => 'FC',
946 'extensions' => ['.F90','.F95', '.F03', '.F08']);
948 # Preprocessed Fortran 77
950 # The current support for preprocessing Fortran 77 just involves
951 # passing "$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
952 # $(CPPFLAGS)" as additional flags to the Fortran 77 compiler, since
953 # this is how GNU Make does it; see the "GNU Make Manual, Edition 0.51
954 # for 'make' Version 3.76 Beta" (specifically, from info file
955 # '(make)Catalogue of Rules').
957 # A better approach would be to write an Autoconf test
958 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
959 # Fortran 77 compilers know how to do preprocessing. The Autoconf
960 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
961 # preprocessing capabilities, and then fall back on cpp (if cpp were
963 register_language ('name' => 'ppf77',
964 'Name' => 'Preprocessed Fortran 77',
965 'config_vars' => ['F77'],
966 'linker' => 'F77LINK',
967 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
970 'flags' => ['FFLAGS', 'CPPFLAGS'],
972 'compiler' => 'PPF77COMPILE',
973 'compile' => "\$(F77) @cpplike_flags \$(AM_FFLAGS) \$(FFLAGS)",
974 'compile_flag' => '-c',
975 'output_flag' => '-o',
976 'libtool_tag' => 'F77',
978 'extensions' => ['.F']);
981 register_language ('name' => 'ratfor',
983 'config_vars' => ['F77'],
984 'linker' => 'F77LINK',
985 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
988 'flags' => ['RFLAGS', 'FFLAGS'],
990 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
992 'compiler' => 'RCOMPILE',
993 'compile_flag' => '-c',
994 'output_flag' => '-o',
995 'libtool_tag' => 'F77',
997 'extensions' => ['.r']);
1000 register_language ('name' => 'java',
1002 'config_vars' => ['GCJ'],
1003 'linker' => 'GCJLINK',
1004 'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
1006 'flags' => ['GCJFLAGS'],
1007 'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
1009 'compiler' => 'GCJCOMPILE',
1010 'compile_flag' => '-c',
1011 'output_flag' => '-o',
1012 'libtool_tag' => 'GCJ',
1016 'extensions' => ['.java', '.class', '.zip', '.jar']);
1018 ################################################################
1020 # Error reporting functions.
1022 # err_am ($MESSAGE, [%OPTIONS])
1023 # -----------------------------
1024 # Uncategorized errors about the current Makefile.am.
1027 msg_am ('error', @_);
1030 # err_ac ($MESSAGE, [%OPTIONS])
1031 # -----------------------------
1032 # Uncategorized errors about configure.ac.
1035 msg_ac ('error', @_);
1038 # msg_am ($CHANNEL, $MESSAGE, [%OPTIONS])
1039 # ---------------------------------------
1040 # Messages about about the current Makefile.am.
1043 my ($channel, $msg, %opts) = @_;
1044 msg $channel, "${am_file}.am", $msg, %opts;
1047 # msg_ac ($CHANNEL, $MESSAGE, [%OPTIONS])
1048 # ---------------------------------------
1049 # Messages about about configure.ac.
1052 my ($channel, $msg, %opts) = @_;
1053 msg $channel, $configure_ac, $msg, %opts;
1056 ################################################################
1060 # Return a configure-style substitution using the indicated text.
1061 # We do this to avoid having the substitutions directly in automake.in;
1062 # when we do that they are sometimes removed and this causes confusion
1067 return '@' . $text . '@';
1070 ################################################################
1074 # backname ($RELDIR)
1075 # -------------------
1076 # If I "cd $RELDIR", then to come back, I should "cd $BACKPATH".
1077 # For instance 'src/foo' => '../..'.
1078 # Works with non strictly increasing paths, i.e., 'src/../lib' => '..'.
1083 foreach (split (/\//, $file))
1085 next if $_ eq '.' || $_ eq '';
1089 or prog_error ("trying to reverse path '$file' pointing outside tree");
1096 return join ('/', @res) || '.';
1099 ################################################################
1101 # Silent rules handling functions.
1103 # verbose_var (NAME)
1104 # ------------------
1105 # The public variable stem used to implement silent rules.
1109 return 'AM_V_' . $name;
1112 # verbose_private_var (NAME)
1113 # --------------------------
1114 # The naming policy for the private variables for silent rules.
1115 sub verbose_private_var
1118 return 'am__v_' . $name;
1121 # define_verbose_var (NAME, VAL-IF-SILENT, [VAL-IF-VERBOSE])
1122 # ----------------------------------------------------------
1123 # For silent rules, setup VAR and dispatcher, to expand to
1124 # VAL-IF-SILENT if silent, to VAL-IF-VERBOSE (defaulting to
1126 sub define_verbose_var
1128 my ($name, $silent_val, $verbose_val) = @_;
1129 $verbose_val = '' unless defined $verbose_val;
1130 my $var = verbose_var ($name);
1131 my $pvar = verbose_private_var ($name);
1132 my $silent_var = $pvar . '_0';
1133 my $verbose_var = $pvar . '_1';
1134 # For typical 'make's, 'configure' replaces AM_V (inside @@) with $(V)
1135 # and AM_DEFAULT_V (inside @@) with $(AM_DEFAULT_VERBOSITY).
1136 # For strict POSIX 2008 'make's, it replaces them with 0 or 1 instead.
1137 # See AM_SILENT_RULES in m4/silent.m4.
1138 define_variable ($var, '$(' . $pvar . '_@'.'AM_V'.'@)', INTERNAL);
1139 define_variable ($pvar . '_', '$(' . $pvar . '_@'.'AM_DEFAULT_V'.'@)',
1141 Automake::Variable::define ($silent_var, VAR_AUTOMAKE, '', TRUE,
1142 $silent_val, '', INTERNAL, VAR_ASIS)
1143 if (! vardef ($silent_var, TRUE));
1144 Automake::Variable::define ($verbose_var, VAR_AUTOMAKE, '', TRUE,
1145 $verbose_val, '', INTERNAL, VAR_ASIS)
1146 if (! vardef ($verbose_var, TRUE));
1149 # verbose_flag (NAME)
1150 # -------------------
1151 # Contents of '%VERBOSE%' variable to expand before rule command.
1155 return '$(' . verbose_var ($name) . ')';
1158 sub verbose_nodep_flag
1161 return '$(' . verbose_var ($name) . subst ('am__nodep') . ')';
1166 # Contents of %SILENT%: variable to expand to '@' when silent.
1169 return verbose_flag ('at');
1172 # define_verbose_tagvar (NAME)
1173 # ----------------------------
1174 # Engage the needed silent rules machinery for tag NAME.
1175 sub define_verbose_tagvar
1178 define_verbose_var ($name, '@echo " '. $name . ' ' x (8 - length ($name)) . '" $@;');
1181 # Engage the needed silent rules machinery for assorted texinfo commands.
1182 sub define_verbose_texinfo ()
1184 my @tagvars = ('DVIPS', 'MAKEINFO', 'INFOHTML', 'TEXI2DVI', 'TEXI2PDF');
1185 foreach my $tag (@tagvars)
1187 define_verbose_tagvar($tag);
1189 define_verbose_var('texinfo', '-q');
1190 define_verbose_var('texidevnull', '> /dev/null');
1193 # Engage the needed silent rules machinery for 'libtool --silent'.
1194 sub define_verbose_libtool ()
1196 define_verbose_var ('lt', '--silent');
1197 return verbose_flag ('lt');
1200 sub handle_silent ()
1202 # Define "$(AM_V_P)", expanding to a shell conditional that can be
1203 # used in make recipes to determine whether we are being run in
1204 # silent mode or not. The choice of the name derives from the LISP
1205 # convention of appending the letter 'P' to denote a predicate (see
1206 # also "the '-P' convention" in the Jargon File); we do so for lack
1207 # of a better convention.
1208 define_verbose_var ('P', 'false', ':');
1209 # *Always* provide the user with '$(AM_V_GEN)', unconditionally.
1210 define_verbose_tagvar ('GEN');
1211 define_verbose_var ('at', '@');
1215 ################################################################
1218 # Handle AUTOMAKE_OPTIONS variable. Return 0 on error, 1 otherwise.
1219 sub handle_options ()
1221 my $var = var ('AUTOMAKE_OPTIONS');
1224 if ($var->has_conditional_contents)
1226 msg_var ('unsupported', $var,
1227 "'AUTOMAKE_OPTIONS' cannot have conditional contents");
1229 my @options = map { { option => $_->[1], where => $_->[0] } }
1230 $var->value_as_list_recursive (cond_filter => TRUE,
1232 return 0 unless process_option_list (@options);
1235 if ($strictness == GNITS)
1237 set_option ('readme-alpha', INTERNAL);
1238 set_option ('std-options', INTERNAL);
1239 set_option ('check-news', INTERNAL);
1245 # shadow_unconditionally ($varname, $where)
1246 # -----------------------------------------
1247 # Return a $(variable) that contains all possible values
1248 # $varname can take.
1249 # If the VAR wasn't defined conditionally, return $(VAR).
1250 # Otherwise we create an am__VAR_DIST variable which contains
1251 # all possible values, and return $(am__VAR_DIST).
1252 sub shadow_unconditionally
1254 my ($varname, $where) = @_;
1255 my $var = var $varname;
1256 if ($var->has_conditional_contents)
1258 $varname = "am__${varname}_DIST";
1259 my @files = uniq ($var->value_as_list_recursive);
1260 define_pretty_variable ($varname, TRUE, $where, @files);
1262 return "\$($varname)"
1265 # check_user_variables (@LIST)
1266 # ----------------------------
1267 # Make sure each variable VAR in @LIST does not exist, suggest using AM_VAR
1269 sub check_user_variables
1271 my @dont_override = @_;
1272 foreach my $flag (@dont_override)
1274 my $var = var $flag;
1277 for my $cond ($var->conditions->conds)
1279 if ($var->rdef ($cond)->owner == VAR_MAKEFILE)
1281 msg_cond_var ('gnu', $cond, $flag,
1282 "'$flag' is a user variable, "
1283 . "you should not override it;\n"
1284 . "use 'AM_$flag' instead");
1291 # Call finish function for each language that was used.
1292 sub handle_languages ()
1294 if (! option 'no-dependencies')
1296 # Include auto-dep code. Don't include it if DEP_FILES would
1298 if (keys %extension_seen && keys %dep_files)
1300 my @dep_files = sort keys %dep_files;
1301 # Set location of depcomp.
1302 define_variable ('depcomp',
1303 "\$(SHELL) $am_config_aux_dir/depcomp",
1305 define_variable ('am__maybe_remake_depfiles', 'depfiles', INTERNAL);
1306 define_variable ('am__depfiles_remade', "@dep_files", INTERNAL);
1307 $output_rules .= "\n";
1309 foreach my $depfile (@dep_files)
1311 push @dist_rms, "\t-rm -f $depfile";
1312 # Generate each 'include' directive individually. Several
1313 # make implementations (IRIX 6, Solaris 10, FreeBSD 8) will
1314 # fail to properly include several files resulting from a
1315 # variable expansion. Just Generating many separate includes
1316 # seems thus safest.
1317 $output_rules .= subst ('AMDEP_TRUE') .
1318 subst ('am__include') .
1320 subst('am__quote') .
1322 subst('am__quote') .
1324 "# am--include-marker\n";
1327 require_conf_file ("$am_file.am", FOREIGN, 'depcomp');
1329 $output_rules .= file_contents (
1330 'depend', new Automake::Location,
1331 'DISTRMS' => join ("\n", @dist_rms));
1336 define_variable ('depcomp', '', INTERNAL);
1337 define_variable ('am__maybe_remake_depfiles', '', INTERNAL);
1342 # Is the C linker needed?
1344 foreach my $ext (sort keys %extension_seen)
1346 next unless $extension_map{$ext};
1348 my $lang = $languages{$extension_map{$ext}};
1350 my $rule_file = $lang->rule_file || 'depend2';
1352 # Get information on $LANG.
1353 my $pfx = $lang->autodep;
1354 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1356 my ($AMDEP, $FASTDEP) =
1357 (option 'no-dependencies' || $lang->autodep eq 'no')
1358 ? ('FALSE', 'FALSE') : ('AMDEP', "am__fastdep$fpfx");
1360 my $verbose = verbose_flag ($lang->ccer || 'GEN');
1361 my $verbose_nodep = ($AMDEP eq 'FALSE')
1362 ? $verbose : verbose_nodep_flag ($lang->ccer || 'GEN');
1363 my $silent = silent_flag ();
1365 my %transform = ('EXT' => $ext,
1369 'FASTDEP' => $FASTDEP,
1370 '-c' => $lang->compile_flag || '',
1371 # These are not used, but they need to be defined
1372 # so transform() do not complain.
1374 'DERIVED-EXT' => 'BUG',
1376 VERBOSE => $verbose,
1377 'VERBOSE-NODEP' => $verbose_nodep,
1381 # Generate the appropriate rules for this extension.
1382 if (((! option 'no-dependencies') && $lang->autodep ne 'no')
1383 || defined $lang->compile)
1385 # Compute a possible derived extension.
1386 # This is not used by depend2.am.
1387 my $der_ext = ($lang->output_extensions->($ext))[0];
1389 # When we output an inference rule like '.c.o:' we
1390 # have two cases to consider: either subdir-objects
1391 # is used, or it is not.
1393 # In the latter case the rule is used to build objects
1394 # in the current directory, and dependencies always
1395 # go into './$(DEPDIR)/'. We can hard-code this value.
1397 # In the former case the rule can be used to build
1398 # objects in sub-directories too. Dependencies should
1399 # go into the appropriate sub-directories, e.g.,
1400 # 'sub/$(DEPDIR)/'. The value of this directory
1401 # needs to be computed on-the-fly.
1403 # DEPBASE holds the name of this directory, plus the
1404 # basename part of the object file (extensions Po, TPo,
1405 # Plo, TPlo will be added later as appropriate). It is
1406 # either hardcoded, or a shell variable ('$depbase') that
1407 # will be computed by the rule.
1409 option ('subdir-objects') ? '$$depbase' : '$(DEPDIR)/$*';
1411 file_contents ($rule_file,
1412 new Automake::Location,
1416 'DERIVED-EXT' => $der_ext,
1418 DEPBASE => $depbase,
1421 SOURCEFLAG => $sourceflags{$ext} || '',
1426 COMPILE => '$(' . $lang->compiler . ')',
1427 LTCOMPILE => '$(LT' . $lang->compiler . ')',
1428 -o => $lang->output_flag,
1429 SUBDIROBJ => !! option 'subdir-objects');
1432 # Now include code for each specially handled object with this
1434 my %seen_files = ();
1435 foreach my $file (@{$lang_specific_files{$lang->name}})
1437 my ($derived, $source, $obj, $myext, $srcext, %file_transform) = @$file;
1439 # We might see a given object twice, for instance if it is
1440 # used under different conditions.
1441 next if defined $seen_files{$obj};
1442 $seen_files{$obj} = 1;
1444 prog_error ("found " . $lang->name .
1445 " in handle_languages, but compiler not defined")
1446 unless defined $lang->compile;
1448 my $obj_compile = $lang->compile;
1450 # Rewrite each occurrence of 'AM_$flag' in the compile
1451 # rule into '${derived}_$flag' if it exists.
1452 for my $flag (@{$lang->flags})
1454 my $val = "${derived}_$flag";
1455 $obj_compile =~ s/\(AM_$flag\)/\($val\)/
1459 my $libtool_tag = '';
1460 if ($lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag})
1462 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
1465 my $ptltflags = "${derived}_LIBTOOLFLAGS";
1466 $ptltflags = 'AM_LIBTOOLFLAGS' unless set_seen $ptltflags;
1468 my $ltverbose = define_verbose_libtool ();
1470 "\$(LIBTOOL) $ltverbose $libtool_tag\$($ptltflags) \$(LIBTOOLFLAGS) "
1471 . "--mode=compile $obj_compile";
1473 # We _need_ '-o' for per object rules.
1474 my $output_flag = $lang->output_flag || '-o';
1476 my $depbase = dirname ($obj);
1480 unless $depbase eq '';
1481 $depbase .= '$(DEPDIR)/' . basename ($obj);
1484 file_contents ($rule_file,
1485 new Automake::Location,
1489 DEPBASE => $depbase,
1492 SOURCEFLAG => $sourceflags{$srcext} || '',
1493 # Use $myext and not '.o' here, in case
1494 # we are actually building a new source
1495 # file -- e.g. via yacc.
1496 OBJ => "$obj$myext",
1497 OBJOBJ => "$obj.obj",
1500 VERBOSE => $verbose,
1501 'VERBOSE-NODEP' => $verbose_nodep,
1503 COMPILE => $obj_compile,
1504 LTCOMPILE => $obj_ltcompile,
1509 # The rest of the loop is done once per language.
1510 next if defined $done{$lang};
1513 # Load the language dependent Makefile chunks.
1514 my %lang = map { uc ($_) => 0 } keys %languages;
1515 $lang{uc ($lang->name)} = 1;
1516 $output_rules .= file_contents ('lang-compile',
1517 new Automake::Location,
1520 # If the source to a program consists entirely of code from a
1521 # 'pure' language, for instance C++ or Fortran 77, then we
1522 # don't need the C compiler code. However if we run into
1523 # something unusual then we do generate the C code. There are
1524 # probably corner cases here that do not work properly.
1525 # People linking Java code to Fortran code deserve pain.
1526 $needs_c ||= ! $lang->pure;
1528 define_compiler_variable ($lang)
1529 if ($lang->compile);
1531 define_linker_variable ($lang)
1534 require_variables ("$am_file.am", $lang->Name . " source seen",
1535 TRUE, @{$lang->config_vars});
1537 # Call the finisher.
1540 # Flags listed in '->flags' are user variables (per GNU Standards),
1541 # they should not be overridden in the Makefile...
1542 my @dont_override = @{$lang->flags};
1543 # ... and so is LDFLAGS.
1544 push @dont_override, 'LDFLAGS' if $lang->link;
1546 check_user_variables @dont_override;
1549 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1550 # suffix rule was learned), don't bother with the C stuff. But if
1551 # anything else creeps in, then use it.
1552 my @languages_seen = map { $languages{$extension_map{$_}}->name }
1553 (keys %extension_seen);
1554 @languages_seen = uniq (@languages_seen);
1555 $needs_c = 1 if @languages_seen > 1;
1556 if ($need_link || $needs_c)
1558 define_compiler_variable ($languages{'c'})
1559 unless defined $done{$languages{'c'}};
1560 define_linker_variable ($languages{'c'});
1565 # append_exeext { PREDICATE } $MACRO
1566 # ----------------------------------
1567 # Append $(EXEEXT) to each filename in $F appearing in the Makefile
1568 # variable $MACRO if &PREDICATE($F) is true. @substitutions@ are
1571 # This is typically used on all filenames of *_PROGRAMS, and filenames
1572 # of TESTS that are programs.
1573 sub append_exeext (&$)
1575 my ($pred, $macro) = @_;
1577 transform_variable_recursively
1578 ($macro, $macro, 'am__EXEEXT', 0, INTERNAL,
1580 my ($subvar, $val, $cond, $full_cond) = @_;
1581 # Append $(EXEEXT) unless the user did it already, or it's a
1584 if $val !~ /(?:\$\(EXEEXT\)$|^[@]\w+[@]$)/ && &$pred ($val);
1590 # Check to make sure a source defined in LIBOBJS is not explicitly
1591 # mentioned. This is a separate function (as opposed to being inlined
1592 # in handle_source_transform) because it isn't always appropriate to
1594 sub check_libobjs_sources
1596 my ($one_file, $unxformed) = @_;
1598 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1599 'dist_EXTRA_', 'nodist_EXTRA_')
1602 my $varname = $prefix . $one_file . '_SOURCES';
1603 my $var = var ($varname);
1606 @files = $var->value_as_list_recursive;
1608 elsif ($prefix eq '')
1610 @files = ($unxformed . '.c');
1617 foreach my $file (@files)
1619 err_var ($prefix . $one_file . '_SOURCES',
1620 "automatically discovered file '$file' should not" .
1621 " be explicitly mentioned")
1622 if defined $libsources{$file};
1629 # handle_single_transform ($VAR, $TOPPARENT, $DERIVED, $OBJ, $FILE, %TRANSFORM)
1630 # -----------------------------------------------------------------------------
1631 # Does much of the actual work for handle_source_transform.
1633 # $VAR is the name of the variable that the source filenames come from
1634 # $TOPPARENT is the name of the _SOURCES variable which is being processed
1635 # $DERIVED is the name of resulting executable or library
1636 # $OBJ is the object extension (e.g., '.lo')
1637 # $FILE the source file to transform
1638 # %TRANSFORM contains extras arguments to pass to file_contents
1639 # when producing explicit rules
1640 # Result is a list of the names of objects
1641 # %linkers_used will be updated with any linkers needed
1642 sub handle_single_transform
1644 my ($var, $topparent, $derived, $obj, $_file, %transform) = @_;
1645 my @files = ($_file);
1648 # Turn sources into objects. We use a while loop like this
1649 # because we might add to @files in the loop.
1650 while (scalar @files > 0)
1654 # Configure substitutions in _SOURCES variables are errors.
1657 my $parent_msg = '';
1658 $parent_msg = "\nand is referred to from '$topparent'"
1659 if $topparent ne $var->name;
1661 "'" . $var->name . "' includes configure substitution '$_'"
1662 . $parent_msg . ";\nconfigure " .
1663 "substitutions are not allowed in _SOURCES variables");
1667 # If the source file is in a subdirectory then the '.o' is put
1668 # into the current directory, unless the subdir-objects option
1671 # Split file name into base and extension.
1672 next if ! /^(?:(.*)\/)?([^\/]*)($KNOWN_EXTENSIONS_PATTERN)$/;
1674 my $directory = $1 || '';
1678 # We must generate a rule for the object if it requires its own flags.
1680 my ($linker, $object);
1682 # This records whether we've seen a derived source file (e.g., yacc
1686 # This holds the 'aggregate context' of the file we are
1687 # currently examining. If the file is compiled with
1688 # per-object flags, then it will be the name of the object.
1689 # Otherwise it will be 'AM'. This is used by the target hook
1690 # language function.
1691 my $aggregate = 'AM';
1693 $extension = derive_suffix ($extension, $obj);
1695 if ($extension_map{$extension} &&
1696 ($lang = $languages{$extension_map{$extension}}))
1698 # Found the language, so see what it says.
1699 saw_extension ($extension);
1701 # Do we have per-executable flags for this executable?
1702 my $have_per_exec_flags = 0;
1703 my @peflags = @{$lang->flags};
1704 push @peflags, 'LIBTOOLFLAGS' if $obj eq '.lo';
1705 foreach my $flag (@peflags)
1707 if (set_seen ("${derived}_$flag"))
1709 $have_per_exec_flags = 1;
1714 # Note: computed subr call. The language rewrite function
1715 # should return one of the LANG_* constants. It could
1716 # also return a list whose first value is such a constant
1717 # and whose second value is a new source extension which
1718 # should be applied. This means this particular language
1719 # generates another source file which we must then process
1721 my $subr = \&{'lang_' . $lang->name . '_rewrite'};
1722 defined &$subr or $subr = \&lang_sub_obj;
1723 my ($r, $source_extension)
1724 = &$subr ($directory, $base, $extension,
1725 $obj, $have_per_exec_flags, $var);
1726 # Skip this entry if we were asked not to process it.
1727 next if $r == LANG_IGNORE;
1729 # Now extract linker and other info.
1730 $linker = $lang->linker;
1733 if (defined $source_extension)
1735 $this_obj_ext = $source_extension;
1736 $derived_source = 1;
1740 $this_obj_ext = $obj;
1741 $derived_source = 0;
1742 # Don't ever place built object files in $(srcdir),
1743 # even when sources are specified explicitly as (say)
1744 # '$(srcdir)/foo.c' or '$(top_srcdir)/foo.c'.
1745 # See automake bug#13928.
1746 my @d = split '/', $directory;
1747 if (@d > 0 && option 'subdir-objects')
1750 if ($d eq '$(srcdir)' or $d eq '${srcdir}')
1754 elsif ($d eq '$(top_srcdir)' or $d eq '${top_srcdir}')
1756 $d[0] = '$(top_builddir)';
1758 $directory = join '/', @d;
1761 $object = $base . $this_obj_ext;
1763 if ($have_per_exec_flags)
1765 # We have a per-executable flag in effect for this
1766 # object. In this case we rewrite the object's
1767 # name to ensure it is unique.
1769 # We choose the name 'DERIVED_OBJECT' to ensure (1) uniqueness,
1770 # and (2) continuity between invocations. However, this will
1771 # result in a name that is too long for losing systems, in some
1772 # situations. So we attempt to shorten automatically under
1773 # subdir-objects, and provide _SHORTNAME to override as a last
1774 # resort. If subdir-object is in effect, it's usually
1775 # unnecessary to use the complete 'DERIVED_OBJECT' (that is
1776 # often the result from %canon_reldir%/%C% usage) since objects
1777 # are placed next to their source file. Generally, this means
1778 # it is already unique within that directory (see below for an
1779 # exception). Thus, we try to avoid unnecessarily long file
1780 # names by stripping the directory components of
1781 # 'DERIVED_OBJECT'. This allows avoiding explicit _SHORTNAME
1782 # usage in many cases. EXCEPTION: If two (or more) targets in
1783 # different directories but with the same base name (after
1784 # canonicalization), using target-specific FLAGS, link the same
1785 # object, then this logic clashes. Thus, we don't strip if
1787 my $dname = $derived;
1788 if ($directory ne ''
1789 && option 'subdir-objects'
1790 && none { $dname =~ /$_[0]$/ } @dup_shortnames)
1792 # At this point, we don't clear information about what
1793 # parts of $derived are truly file name components. We can
1794 # determine that by comparing against the canonicalization
1796 my $dir = $directory . "/";
1797 my $cdir = canonicalize ($dir);
1798 my $dir_len = length ($dir);
1799 # Make sure we only strip full file name components. This
1800 # is done by repeatedly trying to find cdir at the
1801 # beginning. Each iteration removes one file name
1802 # component from the end of cdir.
1803 while ($dir_len > 0 && index ($derived, $cdir) != 0)
1805 # Eventually $dir_len becomes 0.
1806 $dir_len = rindex ($dir, "/", $dir_len - 2) + 1;
1807 $cdir = substr ($cdir, 0, $dir_len);
1809 $dname = substr ($derived, $dir_len);
1811 my $var = var ($derived . '_SHORTNAME');
1814 # FIXME: should use the same Condition as
1815 # the _SOURCES variable. But this is really
1816 # silly overkill -- nobody should have
1817 # conditional shortnames.
1818 $dname = $var->variable_value;
1820 $object = $dname . '-' . $object;
1822 prog_error ($lang->name . " flags defined without compiler")
1823 if ! defined $lang->compile;
1828 # If rewrite said it was ok, put the object into a subdir.
1829 if ($directory ne '')
1831 if ($r == LANG_SUBDIR)
1833 $object = $directory . '/' . $object;
1837 # Since the next major version of automake (2.0) will
1838 # make the behaviour so far only activated with the
1839 # 'subdir-object' option mandatory, it's better if we
1840 # start warning users not using that option.
1841 # As suggested by Peter Johansson, we strive to avoid
1842 # the warning when it would be irrelevant, i.e., if
1843 # all source files sit in "current" directory.
1844 msg_var 'unsupported', $var,
1845 "source file '$full' is in a subdirectory,"
1846 . "\nbut option 'subdir-objects' is disabled";
1847 msg 'unsupported', INTERNAL, <<'EOF', uniq_scope => US_GLOBAL;
1848 possible forward-incompatibility.
1849 At least a source file is in a subdirectory, but the 'subdir-objects'
1850 automake option hasn't been enabled. For now, the corresponding output
1851 object file(s) will be placed in the top-level directory. However,
1852 this behaviour will change in future Automake versions: they will
1853 unconditionally cause object files to be placed in the same subdirectory
1854 of the corresponding sources.
1855 You are advised to start using 'subdir-objects' option throughout your
1856 project, to avoid future incompatibilities.
1861 # If the object file has been renamed (because per-target
1862 # flags are used) we cannot compile the file with an
1863 # inference rule: we need an explicit rule.
1865 # If the source is in a subdirectory and the object is in
1866 # the current directory, we also need an explicit rule.
1868 # If both source and object files are in a subdirectory
1869 # (this happens when the subdir-objects option is used),
1870 # then the inference will work.
1872 # The latter case deserves a historical note. When the
1873 # subdir-objects option was added on 1999-04-11 it was
1874 # thought that inferences rules would work for
1875 # subdirectory objects too. Later, on 1999-11-22,
1876 # automake was changed to output explicit rules even for
1877 # subdir-objects. Nobody remembers why, but this occurred
1878 # soon after the merge of the user-dep-gen-branch so it
1879 # might be related. In late 2003 people complained about
1880 # the size of the generated Makefile.ins (libgcj, with
1881 # 2200+ subdir objects was reported to have a 9MB
1882 # Makefile), so we now rely on inference rules again.
1883 # Maybe we'll run across the same issue as in the past,
1884 # but at least this time we can document it. However since
1885 # dependency tracking has evolved it is possible that
1886 # our old problem no longer exists.
1887 # Using inference rules for subdir-objects has been tested
1888 # with GNU make, Solaris make, Ultrix make, BSD make,
1889 # HP-UX make, and OSF1 make successfully.
1891 || ($directory ne '' && ! option 'subdir-objects')
1892 # We must also use specific rules for a nodist_ source
1893 # if its language requests it.
1894 || ($lang->nodist_specific && ! $transform{'DIST_SOURCE'}))
1896 my $obj_sans_ext = substr ($object, 0,
1897 - length ($this_obj_ext));
1899 if ($directory ne '')
1901 $full_ansi = $directory . '/' . $base . $extension;
1905 $full_ansi = $base . $extension;
1908 my @specifics = ($full_ansi, $obj_sans_ext,
1909 # Only use $this_obj_ext in the derived
1910 # source case because in the other case we
1911 # *don't* want $(OBJEXT) to appear here.
1912 ($derived_source ? $this_obj_ext : '.o'),
1915 # If we renamed the object then we want to use the
1916 # per-executable flag name. But if this is simply a
1917 # subdir build then we still want to use the AM_ flag
1921 unshift @specifics, $derived;
1922 $aggregate = $derived;
1926 unshift @specifics, 'AM';
1929 # Each item on this list is a reference to a list consisting
1930 # of four values followed by additional transform flags for
1931 # file_contents. The four values are the derived flag prefix
1932 # (e.g. for 'foo_CFLAGS', it is 'foo'), the name of the
1933 # source file, the base name of the output file, and
1934 # the extension for the object file.
1935 push (@{$lang_specific_files{$lang->name}},
1936 [@specifics, %transform]);
1939 elsif ($extension eq $obj)
1941 # This is probably the result of a direct suffix rule.
1942 # In this case we just accept the rewrite.
1943 $object = "$base$extension";
1944 $object = "$directory/$object" if $directory ne '';
1949 # No error message here. Used to have one, but it was
1951 # FIXME: we could potentially do more processing here,
1952 # perhaps treating the new extension as though it were a
1953 # new source extension (as above). This would require
1954 # more restructuring than is appropriate right now.
1958 err_am "object '$object' created by '$full' and '$object_map{$object}'"
1959 if (defined $object_map{$object}
1960 && $object_map{$object} ne $full);
1962 my $comp_val = (($object =~ /\.lo$/)
1963 ? COMPILE_LIBTOOL : COMPILE_ORDINARY);
1964 (my $comp_obj = $object) =~ s/\.lo$/.\$(OBJEXT)/;
1965 if (defined $object_compilation_map{$comp_obj}
1966 && $object_compilation_map{$comp_obj} != 0
1967 # Only see the error once.
1968 && ($object_compilation_map{$comp_obj}
1969 != (COMPILE_LIBTOOL | COMPILE_ORDINARY))
1970 && $object_compilation_map{$comp_obj} != $comp_val)
1972 err_am "object '$comp_obj' created both with libtool and without";
1974 $object_compilation_map{$comp_obj} |= $comp_val;
1978 # Let the language do some special magic if required.
1979 $lang->target_hook ($aggregate, $object, $full, %transform);
1982 if ($derived_source)
1984 prog_error ($lang->name . " has automatic dependency tracking")
1985 if $lang->autodep ne 'no';
1986 # Make sure this new source file is handled next. That will
1987 # make it appear to be at the right place in the list.
1988 unshift (@files, $object);
1989 # Distribute derived sources unless the source they are
1990 # derived from is not.
1991 push_dist_common ($object)
1992 unless ($topparent =~ /^(?:nobase_)?nodist_/);
1996 $linkers_used{$linker} = 1;
1998 push (@result, $object);
2000 if (! defined $object_map{$object})
2003 $object_map{$object} = $full;
2005 # If resulting object is in subdir, we need to make
2006 # sure the subdir exists at build time.
2007 if ($object =~ /\//)
2009 # FIXME: check that $DIRECTORY is somewhere in the
2012 # For Java, the way we're handling it right now, a
2013 # '..' component doesn't make sense.
2014 if ($lang && $lang->name eq 'java' && $object =~ /(\/|^)\.\.\//)
2016 err_am "'$full' should not contain a '..' component";
2019 # Make sure *all* objects files in the subdirectory are
2020 # removed by "make mostlyclean". Not only this is more
2021 # efficient than listing the object files to be removed
2022 # individually (which would cause an 'rm' invocation for
2023 # each of them -- very inefficient, see bug#10697), it
2024 # would also leave stale object files in the subdirectory
2025 # whenever a source file there is removed or renamed.
2026 $compile_clean_files{"$directory/*.\$(OBJEXT)"} = MOSTLY_CLEAN;
2027 if ($object =~ /\.lo$/)
2029 # If we have a libtool object, then we also must remove
2030 # any '.lo' objects in its same subdirectory.
2031 $compile_clean_files{"$directory/*.lo"} = MOSTLY_CLEAN;
2032 # Remember to cleanup .libs/ in this directory.
2033 $libtool_clean_directories{$directory} = 1;
2036 push (@dep_list, require_build_directory ($directory));
2038 # If we're generating dependencies, we also want
2039 # to make sure that the appropriate subdir of the
2040 # .deps directory is created.
2042 require_build_directory ($directory . '/$(DEPDIR)'))
2043 unless option 'no-dependencies';
2046 pretty_print_rule ($object . ':', "\t", @dep_list)
2047 if scalar @dep_list > 0;
2050 # Transform .o or $o file into .P file (for automatic
2052 # Properly flatten multiple adjacent slashes, as Solaris 10 make
2053 # might fail over them in an include statement.
2054 # Leading double slashes may be special, as per Posix, so deal
2055 # with them carefully.
2056 if ($lang && $lang->autodep ne 'no')
2058 my $depfile = $object;
2059 $depfile =~ s/\.([^.]*)$/.P$1/;
2060 $depfile =~ s/\$\(OBJEXT\)$/o/;
2061 my $maybe_extra_leading_slash = '';
2062 $maybe_extra_leading_slash = '/' if $depfile =~ m,^//[^/],;
2063 $depfile =~ s,/+,/,g;
2064 my $basename = basename ($depfile);
2065 # This might make $dirname empty, but we account for that below.
2066 (my $dirname = dirname ($depfile)) =~ s/\/*$//;
2067 $dirname = $maybe_extra_leading_slash . $dirname;
2068 $dep_files{$dirname . '/$(DEPDIR)/' . $basename} = 1;
2077 # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
2078 # $OBJ, $PARENT, $TOPPARENT, $WHERE, %TRANSFORM)
2079 # ---------------------------------------------------------------------------
2080 # Define an _OBJECTS variable for a _SOURCES variable (or subvariable)
2083 # $VAR is the name of the _SOURCES variable
2084 # $OBJVAR is the name of the _OBJECTS variable if known (otherwise
2085 # it will be generated and returned).
2086 # $NODEFINE is a boolean: if true, $OBJVAR will not be defined (but
2087 # work done to determine the linker will be).
2088 # $ONE_FILE is the canonical (transformed) name of object to build
2089 # $OBJ is the object extension (i.e. either '.o' or '.lo').
2090 # $TOPPARENT is the _SOURCES variable being processed.
2091 # $WHERE context into which this definition is done
2092 # %TRANSFORM extra arguments to pass to file_contents when producing
2095 # Result is a pair ($LINKER, $OBJVAR):
2096 # $LINKER is a boolean, true if a linker is needed to deal with the objects
2097 sub define_objects_from_sources
2099 my ($var, $objvar, $nodefine, $one_file,
2100 $obj, $topparent, $where, %transform) = @_;
2102 my $needlinker = "";
2104 transform_variable_recursively
2105 ($var, $objvar, 'am__objects', $nodefine, $where,
2106 # The transform code to run on each filename.
2108 my ($subvar, $val, $cond, $full_cond) = @_;
2109 my @trans = handle_single_transform ($subvar, $topparent,
2110 $one_file, $obj, $val,
2112 $needlinker = "true" if @trans;
2120 # handle_source_transform ($CANON_TARGET, $TARGET, $OBJEXT, $WHERE, %TRANSFORM)
2121 # -----------------------------------------------------------------------------
2122 # Handle SOURCE->OBJECT transform for one program or library.
2124 # canonical (transformed) name of target to build
2125 # actual target of object to build
2126 # object extension (i.e., either '.o' or '$o')
2127 # location of the source variable
2128 # extra arguments to pass to file_contents when producing rules
2129 # Return the name of the linker variable that must be used.
2130 # Empty return means just use 'LINK'.
2131 sub handle_source_transform
2133 # one_file is canonical name. unxformed is given name. obj is
2135 my ($one_file, $unxformed, $obj, $where, %transform) = @_;
2139 # No point in continuing if _OBJECTS is defined.
2140 return if reject_var ($one_file . '_OBJECTS',
2141 $one_file . '_OBJECTS should not be defined');
2146 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2147 'dist_EXTRA_', 'nodist_EXTRA_')
2149 my $varname = $prefix . $one_file . "_SOURCES";
2150 my $var = var $varname;
2153 # We are going to define _OBJECTS variables using the prefix.
2154 # Then we glom them all together. So we can't use the null
2155 # prefix here as we need it later.
2156 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2158 # Keep track of which prefixes we saw.
2159 $used_pfx{$xpfx} = 1
2160 unless $prefix =~ /EXTRA_/;
2162 push @sources, "\$($varname)";
2163 push @dist_sources, shadow_unconditionally ($varname, $where)
2164 unless (option ('no-dist') || $prefix =~ /^nodist_/);
2167 define_objects_from_sources ($varname,
2168 $xpfx . $one_file . '_OBJECTS',
2169 !!($prefix =~ /EXTRA_/),
2170 $one_file, $obj, $varname, $where,
2171 DIST_SOURCE => ($prefix !~ /^nodist_/),
2176 $linker ||= resolve_linker (%linkers_used);
2179 my @keys = sort keys %used_pfx;
2180 if (scalar @keys == 0)
2182 # The default source for libfoo.la is libfoo.c, but for
2183 # backward compatibility we first look at libfoo_la.c,
2184 # if no default source suffix is given.
2185 my $old_default_source = "$one_file.c";
2186 my $ext_var = var ('AM_DEFAULT_SOURCE_EXT');
2187 my $default_source_ext = $ext_var ? variable_value ($ext_var) : '.c';
2188 msg_var ('unsupported', $ext_var, $ext_var->name . " can assume at most one value")
2189 if $default_source_ext =~ /[\t ]/;
2190 (my $default_source = $unxformed) =~ s,(\.[^./\\]*)?$,$default_source_ext,;
2191 # TODO: Remove this backward-compatibility hack in Automake 2.0.
2192 if ($old_default_source ne $default_source
2194 && (rule $old_default_source
2195 || rule '$(srcdir)/' . $old_default_source
2196 || rule '${srcdir}/' . $old_default_source
2197 || -f $old_default_source))
2199 my $loc = $where->clone;
2201 msg ('obsolete', $loc,
2202 "the default source for '$unxformed' has been changed "
2203 . "to '$default_source'.\n(Using '$old_default_source' for "
2204 . "backward compatibility.)");
2205 $default_source = $old_default_source;
2207 # If a rule exists to build this source with a $(srcdir)
2208 # prefix, use that prefix in our variables too. This is for
2209 # the sake of BSD Make.
2210 if (rule '$(srcdir)/' . $default_source
2211 || rule '${srcdir}/' . $default_source)
2213 $default_source = '$(srcdir)/' . $default_source;
2216 define_variable ($one_file . "_SOURCES", $default_source, $where);
2217 push (@sources, $default_source);
2218 push (@dist_sources, $default_source);
2222 handle_single_transform ($one_file . '_SOURCES',
2223 $one_file . '_SOURCES',
2225 $default_source, %transform);
2226 $linker ||= resolve_linker (%linkers_used);
2227 define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @result);
2231 @keys = map { '$(' . $_ . $one_file . '_OBJECTS)' } @keys;
2232 define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @keys);
2235 # If we want to use 'LINK' we must make sure it is defined.
2245 # handle_lib_objects ($XNAME, $VAR)
2246 # ---------------------------------
2247 # Special-case ALLOCA and LIBOBJS substitutions in _LDADD or _LIBADD variables.
2248 # Also, generate _DEPENDENCIES variable if appropriate.
2250 # transformed name of object being built, or empty string if no object
2251 # name of _LDADD/_LIBADD-type variable to examine
2252 # Returns 1 if LIBOBJS seen, 0 otherwise.
2253 sub handle_lib_objects
2255 my ($xname, $varname) = @_;
2257 my $var = var ($varname);
2258 prog_error "'$varname' undefined"
2260 prog_error "unexpected variable name '$varname'"
2261 unless $varname =~ /^(.*)(?:LIB|LD)ADD$/;
2262 my $prefix = $1 || 'AM_';
2264 my $seen_libobjs = 0;
2267 transform_variable_recursively
2268 ($varname, $xname . '_DEPENDENCIES', 'am__DEPENDENCIES',
2270 # Transformation function, run on each filename.
2272 my ($subvar, $val, $cond, $full_cond) = @_;
2276 # Skip -lfoo and -Ldir silently; these are explicitly allowed.
2277 if ($val !~ /^-[lL]/ &&
2278 # Skip -dlopen and -dlpreopen; these are explicitly allowed
2279 # for Libtool libraries or programs. (Actually we are a bit
2280 # lax here since this code also applies to non-libtool
2281 # libraries or programs, for which -dlopen and -dlopreopen
2282 # are pure nonsense. Diagnosing this doesn't seem very
2283 # important: the developer will quickly get complaints from
2285 $val !~ /^-dl(?:pre)?open$/ &&
2286 # Only get this error once.
2290 # FIXME: should display a stack of nested variables
2291 # as context when $var != $subvar.
2292 err_var ($var, "linker flags such as '$val' belong in "
2293 . "'${prefix}LDFLAGS'");
2297 elsif ($val !~ /^\@.*\@$/)
2299 # Assume we have a file of some sort, and output it into the
2300 # dependency variable. Autoconf substitutions are not output;
2301 # rarely is a new dependency substituted into e.g. foo_LDADD
2302 # -- but bad things (e.g. -lX11) are routinely substituted.
2303 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2304 # and handled specially below.
2307 elsif ($val =~ /^\@(LT)?LIBOBJS\@$/)
2309 handle_LIBOBJS ($subvar, $cond, $1);
2313 elsif ($val =~ /^\@(LT)?ALLOCA\@$/)
2315 handle_ALLOCA ($subvar, $cond, $1);
2324 return $seen_libobjs;
2327 # handle_LIBOBJS_or_ALLOCA ($VAR, $BASE)
2328 # --------------------------------------
2329 # Definitions common to LIBOBJS and ALLOCA.
2330 # VAR should be one of LIBOBJS, LTLIBOBJS, ALLOCA, or LTALLOCA.
2331 # BASE should be one base file name from AC_LIBSOURCE, or alloca.
2332 sub handle_LIBOBJS_or_ALLOCA
2334 my ($var, $base) = @_;
2338 # If LIBOBJS files must be built in another directory we have
2339 # to define LIBOBJDIR and ensure the files get cleaned.
2340 # Otherwise LIBOBJDIR can be left undefined, and the cleaning
2341 # is achieved by 'rm -f *.$(OBJEXT)' in compile.am.
2342 if ($config_libobj_dir
2343 && $relative_dir ne $config_libobj_dir)
2345 if (option 'subdir-objects')
2347 # In the top-level Makefile we do not use $(top_builddir), because
2348 # we are already there, and since the targets are built without
2349 # a $(top_builddir), it helps BSD Make to match them with
2351 $dir = "$config_libobj_dir/"
2352 if $config_libobj_dir ne '.';
2353 $dir = backname ($relative_dir) . "/$dir"
2354 if $relative_dir ne '.';
2355 define_variable ('LIBOBJDIR', "$dir", INTERNAL);
2356 if ($dir && !defined $clean_files{"$dir$base.\$(OBJEXT)"})
2358 my $dirstamp = require_build_directory ($dir);
2359 $output_rules .= "$dir$base.\$(OBJEXT): $dirstamp\n";
2360 $output_rules .= "$dir$base.lo: $dirstamp\n"
2363 # libtool might create .$(OBJEXT) as a side-effect of using
2364 # LTLIBOBJS or LTALLOCA.
2365 $clean_files{"$dir$base.\$(OBJEXT)"} = MOSTLY_CLEAN;
2366 $clean_files{"$dir$base.lo"} = MOSTLY_CLEAN
2371 error ("'\$($var)' cannot be used outside '$config_libobj_dir' if"
2372 . " 'subdir-objects' is not set");
2381 my ($var, $cond, $lt) = @_;
2382 my $myobjext = $lt ? 'lo' : 'o';
2385 $var->requires_variables ("\@${lt}LIBOBJS\@ used", $lt . 'LIBOBJS')
2386 if ! keys %libsources;
2388 foreach my $iter (keys %libsources)
2391 if ($iter =~ /^(.*)(\.[cly])$/)
2394 saw_extension ('.c');
2395 $dir = handle_LIBOBJS_or_ALLOCA ("${lt}LIBOBJS", $1);
2398 if ($iter =~ /\.h$/)
2400 require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
2402 elsif ($iter ne 'alloca.c')
2404 my $rewrite = $iter;
2405 $rewrite =~ s/\.c$/.P$myobjext/;
2406 $dep_files{$dir . '$(DEPDIR)/' . $rewrite} = 1;
2407 $rewrite = "^" . quotemeta ($iter) . "\$";
2408 # Only require the file if it is not a built source.
2409 my $bs = var ('BUILT_SOURCES');
2410 if (! $bs || ! grep (/$rewrite/, $bs->value_as_list_recursive))
2412 require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
2420 my ($var, $cond, $lt) = @_;
2421 my $myobjext = $lt ? 'lo' : 'o';
2423 my $dir = handle_LIBOBJS_or_ALLOCA ("${lt}ALLOCA", "alloca");
2425 $dir eq '' and $dir = './';
2426 $var->requires_variables ("\@${lt}ALLOCA\@ used", $lt . 'ALLOCA');
2427 $dep_files{$dir . '$(DEPDIR)/alloca.P' . $myobjext} = 1;
2428 require_libsource_with_macro ($cond, $var, FOREIGN, 'alloca.c');
2429 saw_extension ('.c');
2432 # Canonicalize the input parameter.
2436 $string =~ tr/A-Za-z0-9_\@/_/c;
2440 # Canonicalize a name, and check to make sure the non-canonical name
2441 # is never used. Returns canonical name. Arguments are name and a
2442 # list of suffixes to check for.
2443 sub check_canonical_spelling
2445 my ($name, @suffixes) = @_;
2447 my $xname = canonicalize ($name);
2448 if ($xname ne $name)
2450 foreach my $xt (@suffixes)
2452 reject_var ("$name$xt", "use '$xname$xt', not '$name$xt'");
2459 # Set up the compile suite.
2460 sub handle_compile ()
2462 return if ! $must_handle_compiled_objects;
2465 my $default_includes = '';
2466 if (! option 'nostdinc')
2468 my @incs = ('-I.', subst ('am__isrc'));
2470 my $var = var 'CONFIG_HEADER';
2473 foreach my $hdr (split (' ', $var->variable_value))
2475 push @incs, '-I' . dirname ($hdr);
2478 # We want '-I. -I$(srcdir)', but the latter -I is redundant
2479 # and unaesthetic in non-VPATH builds. We use `-I.@am__isrc@`
2480 # instead. It will be replaced by '-I.' or '-I. -I$(srcdir)'.
2481 # Items in CONFIG_HEADER are never in $(srcdir) so it is safe
2482 # to just put @am__isrc@ right after '-I.', without a space.
2483 ($default_includes = ' ' . uniq (@incs)) =~ s/ @/@/;
2486 my (@mostly_rms, @dist_rms);
2487 foreach my $item (sort keys %compile_clean_files)
2489 if ($compile_clean_files{$item} == MOSTLY_CLEAN)
2491 push (@mostly_rms, "\t-rm -f $item");
2493 elsif ($compile_clean_files{$item} == DIST_CLEAN)
2495 push (@dist_rms, "\t-rm -f $item");
2499 prog_error 'invalid entry in %compile_clean_files';
2503 my ($coms, $vars, $rules) =
2504 file_contents_internal (1, "$libdir/am/compile.am",
2505 new Automake::Location,
2506 'DEFAULT_INCLUDES' => $default_includes,
2507 'MOSTLYRMS' => join ("\n", @mostly_rms),
2508 'DISTRMS' => join ("\n", @dist_rms));
2509 $output_vars .= $vars;
2510 $output_rules .= "$coms$rules";
2513 # Handle libtool rules.
2514 sub handle_libtool ()
2516 return unless var ('LIBTOOL');
2518 # Libtool requires some files, but only at top level.
2519 # (Starting with Libtool 2.0 we do not have to bother. These
2520 # requirements are done with AC_REQUIRE_AUX_FILE.)
2521 require_conf_file_with_macro (TRUE, 'LIBTOOL', FOREIGN, @libtool_files)
2522 if $relative_dir eq '.' && ! $libtool_new_api;
2525 foreach my $item (sort keys %libtool_clean_directories)
2527 my $dir = ($item eq '.') ? '' : "$item/";
2528 # .libs is for Unix, _libs for DOS.
2529 push (@libtool_rms, "\t-rm -rf ${dir}.libs ${dir}_libs");
2532 check_user_variables 'LIBTOOLFLAGS';
2534 # Output the libtool compilation rules.
2535 $output_rules .= file_contents ('libtool',
2536 new Automake::Location,
2537 LTRMS => join ("\n", @libtool_rms));
2540 # Check for duplicate targets
2541 sub handle_targets ()
2545 @proglist = am_install_var ('progs', 'PROGRAMS',
2546 'bin', 'sbin', 'libexec', 'pkglibexec',
2548 @liblist = am_install_var ('libs', 'LIBRARIES',
2549 'lib', 'pkglib', 'noinst', 'check');
2550 @ltliblist = am_install_var ('ltlib', 'LTLIBRARIES',
2551 'noinst', 'lib', 'pkglib', 'check');
2553 # Record duplications that may arise after canonicalization of the
2554 # base names, in order to prevent object file clashes in the presence
2555 # of target-specific *FLAGS
2556 my @targetlist = (@proglist, @liblist, @ltliblist);
2557 foreach my $pair (@targetlist)
2559 my $base = canonicalize (basename (@$pair[1]));
2560 push (@dup_shortnames, $base) if ($seen{$base});
2561 $seen{$base} = $base;
2565 sub handle_programs ()
2567 return if ! @proglist;
2568 $must_handle_compiled_objects = 1;
2570 my $seen_global_libobjs =
2571 var ('LDADD') && handle_lib_objects ('', 'LDADD');
2573 foreach my $pair (@proglist)
2575 my ($where, $one_file) = @$pair;
2577 my $seen_libobjs = 0;
2578 my $obj = '.$(OBJEXT)';
2580 $known_programs{$one_file} = $where;
2582 # Canonicalize names and check for misspellings.
2583 my $xname = check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2584 '_SOURCES', '_OBJECTS',
2587 $where->push_context ("while processing program '$one_file'");
2588 $where->set (INTERNAL->get);
2590 my $linker = handle_source_transform ($xname, $one_file, $obj, $where,
2591 NONLIBTOOL => 1, LIBTOOL => 0);
2593 if (var ($xname . "_LDADD"))
2595 $seen_libobjs = handle_lib_objects ($xname, $xname . '_LDADD');
2599 # User didn't define prog_LDADD override. So do it.
2600 define_variable ($xname . '_LDADD', '$(LDADD)', $where);
2602 # This does a bit too much work. But we need it to
2603 # generate _DEPENDENCIES when appropriate.
2606 $seen_libobjs = handle_lib_objects ($xname, 'LDADD');
2610 reject_var ($xname . '_LIBADD',
2611 "use '${xname}_LDADD', not '${xname}_LIBADD'");
2613 set_seen ($xname . '_DEPENDENCIES');
2614 set_seen ('EXTRA_' . $xname . '_DEPENDENCIES');
2615 set_seen ($xname . '_LDFLAGS');
2617 # Determine program to use for link.
2618 my($xlink, $vlink) = define_per_target_linker_variable ($linker, $xname);
2619 $vlink = verbose_flag ($vlink || 'GEN');
2621 # If the resulting program lies in a subdirectory,
2622 # ensure that the directory exists before we need it.
2623 my $dirstamp = require_build_directory_maybe ($one_file);
2625 $libtool_clean_directories{dirname ($one_file)} = 1;
2627 $output_rules .= file_contents ('program',
2629 PROGRAM => $one_file,
2633 DIRSTAMP => $dirstamp,
2634 EXEEXT => '$(EXEEXT)');
2636 if ($seen_libobjs || $seen_global_libobjs)
2638 if (var ($xname . '_LDADD'))
2640 check_libobjs_sources ($xname, $xname . '_LDADD');
2642 elsif (var ('LDADD'))
2644 check_libobjs_sources ($xname, 'LDADD');
2651 sub handle_libraries ()
2653 return if ! @liblist;
2654 $must_handle_compiled_objects = 1;
2656 my @prefix = am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2661 my $var = rvar ($prefix[0] . '_LIBRARIES');
2662 $var->requires_variables ('library used', 'RANLIB');
2665 define_variable ('AR', 'ar', INTERNAL);
2666 define_variable ('ARFLAGS', 'cru', INTERNAL);
2667 define_verbose_tagvar ('AR');
2669 foreach my $pair (@liblist)
2671 my ($where, $onelib) = @$pair;
2673 my $seen_libobjs = 0;
2674 # Check that the library fits the standard naming convention.
2675 my $bn = basename ($onelib);
2676 if ($bn !~ /^lib.*\.a$/)
2678 $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.a/;
2679 my $suggestion = dirname ($onelib) . "/$bn";
2680 $suggestion =~ s|^\./||g;
2681 msg ('error-gnu/warn', $where,
2682 "'$onelib' is not a standard library name\n"
2683 . "did you mean '$suggestion'?")
2686 ($known_libraries{$onelib} = $bn) =~ s/\.a$//;
2688 $where->push_context ("while processing library '$onelib'");
2689 $where->set (INTERNAL->get);
2691 my $obj = '.$(OBJEXT)';
2693 # Canonicalize names and check for misspellings.
2694 my $xlib = check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2695 '_OBJECTS', '_DEPENDENCIES',
2698 if (! var ($xlib . '_AR'))
2700 define_variable ($xlib . '_AR', '$(AR) $(ARFLAGS)', $where);
2703 # Generate support for conditional object inclusion in
2705 if (var ($xlib . '_LIBADD'))
2707 if (handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2714 define_variable ($xlib . "_LIBADD", '', $where);
2717 reject_var ($xlib . '_LDADD',
2718 "use '${xlib}_LIBADD', not '${xlib}_LDADD'");
2720 # Make sure we at look at this.
2721 set_seen ($xlib . '_DEPENDENCIES');
2722 set_seen ('EXTRA_' . $xlib . '_DEPENDENCIES');
2724 handle_source_transform ($xlib, $onelib, $obj, $where,
2725 NONLIBTOOL => 1, LIBTOOL => 0);
2727 # If the resulting library lies in a subdirectory,
2728 # make sure this directory will exist.
2729 my $dirstamp = require_build_directory_maybe ($onelib);
2730 my $verbose = verbose_flag ('AR');
2731 my $silent = silent_flag ();
2733 $output_rules .= file_contents ('library',
2735 VERBOSE => $verbose,
2739 DIRSTAMP => $dirstamp);
2743 if (var ($xlib . '_LIBADD'))
2745 check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2751 msg ('extra-portability', $where,
2752 "'$onelib': linking libraries using a non-POSIX\n"
2753 . "archiver requires 'AM_PROG_AR' in '$configure_ac'")
2759 sub handle_ltlibraries ()
2761 return if ! @ltliblist;
2762 $must_handle_compiled_objects = 1;
2764 my @prefix = am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2769 my $var = rvar ($prefix[0] . '_LTLIBRARIES');
2770 $var->requires_variables ('Libtool library used', 'LIBTOOL');
2774 my %instsubdirs = ();
2776 my %liblocations = (); # Location (in Makefile.am) of each library.
2778 foreach my $key (@prefix)
2780 # Get the installation directory of each library.
2782 my $strip_subdir = 1;
2783 if ($dir =~ /^nobase_/)
2785 $dir =~ s/^nobase_//;
2788 my $var = rvar ($key . '_LTLIBRARIES');
2790 # We reject libraries which are installed in several places
2791 # in the same condition, because we can only specify one
2793 $var->traverse_recursively
2796 my ($var, $val, $cond, $full_cond) = @_;
2797 my $hcond = $full_cond->human;
2798 my $where = $var->rdef ($cond)->location;
2800 $ldir = '/' . dirname ($val)
2801 if (!$strip_subdir);
2802 # A library cannot be installed in different directories
2803 # in overlapping conditions.
2804 if (exists $instconds{$val})
2807 $instconds{$val}->ambiguous_p ($val, $full_cond);
2811 error ($where, $msg, partial => 1);
2812 my $dirtxt = "installed " . ($strip_subdir ? "in" : "below") . " '$dir'";
2813 $dirtxt = "built for '$dir'"
2814 if $dir eq 'EXTRA' || $dir eq 'noinst' || $dir eq 'check';
2816 $full_cond->true ? "" : " in condition $hcond";
2818 error ($where, "'$val' should be $dirtxt$dircond ...",
2821 my $hacond = $acond->human;
2822 my $adir = $instdirs{$val}{$acond};
2823 my $adirtxt = "installed in '$adir'";
2824 $adirtxt = "built for '$adir'"
2825 if ($adir eq 'EXTRA' || $adir eq 'noinst'
2826 || $adir eq 'check');
2827 my $adircond = $acond->true ? "" : " in condition $hacond";
2829 my $onlyone = ($dir ne $adir) ?
2830 ("\nLibtool libraries can be built for only one "
2831 . "destination") : "";
2833 error ($liblocations{$val}{$acond},
2834 "... and should also be $adirtxt$adircond.$onlyone");
2840 $instconds{$val} = new Automake::DisjConditions;
2842 $instdirs{$val}{$full_cond} = $dir;
2843 $instsubdirs{$val}{$full_cond} = $ldir;
2844 $liblocations{$val}{$full_cond} = $where;
2845 $instconds{$val} = $instconds{$val}->merge ($full_cond);
2851 skip_ac_subst => 1);
2854 foreach my $pair (@ltliblist)
2856 my ($where, $onelib) = @$pair;
2858 my $seen_libobjs = 0;
2861 # Canonicalize names and check for misspellings.
2862 my $xlib = check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2863 '_SOURCES', '_OBJECTS',
2866 # Check that the library fits the standard naming convention.
2867 my $libname_rx = '^lib.*\.la';
2868 my $ldvar = var ("${xlib}_LDFLAGS") || var ('AM_LDFLAGS');
2869 my $ldvar2 = var ('LDFLAGS');
2870 if (($ldvar && grep (/-module/, $ldvar->value_as_list_recursive))
2871 || ($ldvar2 && grep (/-module/, $ldvar2->value_as_list_recursive)))
2873 # Relax name checking for libtool modules.
2874 $libname_rx = '\.la';
2877 my $bn = basename ($onelib);
2878 if ($bn !~ /$libname_rx$/)
2880 my $type = 'library';
2881 if ($libname_rx eq '\.la')
2883 $bn =~ s/^(lib|)(.*?)(?:\.[^.]*)?$/$1$2.la/;
2888 $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.la/;
2890 my $suggestion = dirname ($onelib) . "/$bn";
2891 $suggestion =~ s|^\./||g;
2892 msg ('error-gnu/warn', $where,
2893 "'$onelib' is not a standard libtool $type name\n"
2894 . "did you mean '$suggestion'?")
2897 ($known_libraries{$onelib} = $bn) =~ s/\.la$//;
2899 $where->push_context ("while processing Libtool library '$onelib'");
2900 $where->set (INTERNAL->get);
2902 # Make sure we look at these.
2903 set_seen ($xlib . '_LDFLAGS');
2904 set_seen ($xlib . '_DEPENDENCIES');
2905 set_seen ('EXTRA_' . $xlib . '_DEPENDENCIES');
2907 # Generate support for conditional object inclusion in
2909 if (var ($xlib . '_LIBADD'))
2911 if (handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2918 define_variable ($xlib . "_LIBADD", '', $where);
2921 reject_var ("${xlib}_LDADD",
2922 "use '${xlib}_LIBADD', not '${xlib}_LDADD'");
2925 my $linker = handle_source_transform ($xlib, $onelib, $obj, $where,
2926 NONLIBTOOL => 0, LIBTOOL => 1);
2928 # Determine program to use for link.
2929 my($xlink, $vlink) = define_per_target_linker_variable ($linker, $xlib);
2930 $vlink = verbose_flag ($vlink || 'GEN');
2932 my $rpathvar = "am_${xlib}_rpath";
2933 my $rpath = "\$($rpathvar)";
2934 foreach my $rcond ($instconds{$onelib}->conds)
2937 if ($instdirs{$onelib}{$rcond} eq 'EXTRA'
2938 || $instdirs{$onelib}{$rcond} eq 'noinst'
2939 || $instdirs{$onelib}{$rcond} eq 'check')
2941 # It's an EXTRA_ library, so we can't specify -rpath,
2942 # because we don't know where the library will end up.
2943 # The user probably knows, but generally speaking automake
2944 # doesn't -- and in fact configure could decide
2945 # dynamically between two different locations.
2950 $val = ('-rpath $(' . $instdirs{$onelib}{$rcond} . 'dir)');
2951 $val .= $instsubdirs{$onelib}{$rcond}
2952 if defined $instsubdirs{$onelib}{$rcond};
2956 # If $rcond is true there is only one condition and
2957 # there is no point defining an helper variable.
2962 define_pretty_variable ($rpathvar, $rcond, INTERNAL, $val);
2966 # If the resulting library lies in a subdirectory,
2967 # make sure this directory will exist.
2968 my $dirstamp = require_build_directory_maybe ($onelib);
2970 # Remember to cleanup .libs/ in this directory.
2971 my $dirname = dirname $onelib;
2972 $libtool_clean_directories{$dirname} = 1;
2974 $output_rules .= file_contents ('ltlibrary',
2976 LTLIBRARY => $onelib,
2977 XLTLIBRARY => $xlib,
2981 DIRSTAMP => $dirstamp);
2984 if (var ($xlib . '_LIBADD'))
2986 check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2992 msg ('extra-portability', $where,
2993 "'$onelib': linking libtool libraries using a non-POSIX\n"
2994 . "archiver requires 'AM_PROG_AR' in '$configure_ac'")
2999 # See if any _SOURCES variable were misspelled.
3002 # It is ok if the user sets this particular variable.
3003 set_seen 'AM_LDFLAGS';
3005 foreach my $primary ('SOURCES', 'LIBADD', 'LDADD', 'LDFLAGS', 'DEPENDENCIES')
3007 foreach my $var (variables $primary)
3009 my $varname = $var->name;
3010 # A configure variable is always legitimate.
3011 next if exists $configure_vars{$varname};
3013 for my $cond ($var->conditions->conds)
3015 $varname =~ /^(?:EXTRA_)?(?:nobase_)?(?:dist_|nodist_)?(.*)_[[:alnum:]]+$/;
3016 msg_var ('syntax', $var, "variable '$varname' is defined but no"
3017 . " program or\nlibrary has '$1' as canonical name"
3018 . " (possible typo)")
3019 unless $var->rdef ($cond)->seen;
3026 sub handle_scripts ()
3028 # NOTE we no longer automatically clean SCRIPTS, because it is
3029 # useful to sometimes distribute scripts verbatim. This happens
3030 # e.g. in Automake itself.
3031 am_install_var ('-candist', 'scripts', 'SCRIPTS',
3032 'bin', 'sbin', 'libexec', 'pkglibexec', 'pkgdata',
3037 ## ------------------------ ##
3038 ## Handling Texinfo files. ##
3039 ## ------------------------ ##
3041 # ($OUTFILE, $VFILE)
3042 # scan_texinfo_file ($FILENAME)
3043 # -----------------------------
3044 # $OUTFILE - name of the info file produced by $FILENAME.
3045 # $VFILE - name of the version.texi file used (undef if none).
3046 sub scan_texinfo_file
3048 my ($filename) = @_;
3050 my $texi = new Automake::XFile "< $filename";
3051 verb "reading $filename";
3053 my ($outfile, $vfile);
3054 while ($_ = $texi->getline)
3056 if (/^\@setfilename +(\S+)/)
3058 # Honor only the first @setfilename. (It's possible to have
3059 # more occurrences later if the manual shows examples of how
3060 # to use @setfilename...)
3064 if (index ($outfile, '.') < 0)
3066 msg 'obsolete', "$filename:$.",
3067 "use of suffix-less info files is discouraged"
3069 elsif ($outfile !~ /\.info$/)
3071 error ("$filename:$.",
3072 "output '$outfile' has unrecognized extension");
3076 # A "version.texi" file is actually any file whose name matches
3078 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
3086 err_am "'$filename' missing \@setfilename";
3090 return ($outfile, $vfile);
3094 # ($DIRSTAMP, @CLEAN_FILES)
3095 # output_texinfo_build_rules ($SOURCE, $DEST, $INSRC, @DEPENDENCIES)
3096 # ------------------------------------------------------------------
3097 # SOURCE - the source Texinfo file
3098 # DEST - the destination Info file
3099 # INSRC - whether DEST should be built in the source tree
3100 # DEPENDENCIES - known dependencies
3101 sub output_texinfo_build_rules
3103 my ($source, $dest, $insrc, @deps) = @_;
3105 # Split 'a.texi' into 'a' and '.texi'.
3106 my ($spfx, $ssfx) = ($source =~ /^(.*?)(\.[^.]*)?$/);
3107 my ($dpfx, $dsfx) = ($dest =~ /^(.*?)(\.[^.]*)?$/);
3112 # We can output two kinds of rules: the "generic" rules use Make
3113 # suffix rules and are appropriate when $source and $dest do not lie
3114 # in a sub-directory; the "specific" rules are needed in the other
3117 # The former are output only once (this is not really apparent here,
3118 # but just remember that some logic deeper in Automake will not
3119 # output the same rule twice); while the later need to be output for
3120 # each Texinfo source.
3123 my $sdir = dirname $source;
3124 if ($sdir eq '.' && dirname ($dest) eq '.')
3127 $makeinfoflags = '-I $(srcdir)';
3132 $makeinfoflags = "-I $sdir -I \$(srcdir)/$sdir";
3135 # A directory can contain two kinds of info files: some built in the
3136 # source tree, and some built in the build tree. The rules are
3137 # different in each case. However we cannot output two different
3138 # set of generic rules. Because in-source builds are more usual, we
3139 # use generic rules in this case and fall back to "specific" rules
3140 # for build-dir builds. (It should not be a problem to invert this
3142 $generic = 0 unless $insrc;
3144 # We cannot use a suffix rule to build info files with an empty
3145 # extension. Otherwise we would output a single suffix inference
3146 # rule, with separate dependencies, as in
3150 # foo.info: foo.texi
3152 # which confuse Solaris make. (See the Autoconf manual for
3153 # details.) Therefore we use a specific rule in this case. This
3154 # applies to info files only (dvi and pdf files always have an
3156 my $generic_info = ($generic && $dsfx) ? 1 : 0;
3158 # If the resulting file lies in a subdirectory,
3159 # make sure this directory will exist.
3160 my $dirstamp = require_build_directory_maybe ($dest);
3162 my $dipfx = ($insrc ? '$(srcdir)/' : '') . $dpfx;
3164 $output_rules .= file_contents ('texibuild',
3165 new Automake::Location,
3166 AM_V_MAKEINFO => verbose_flag('MAKEINFO'),
3167 AM_V_TEXI2DVI => verbose_flag('TEXI2DVI'),
3168 AM_V_TEXI2PDF => verbose_flag('TEXI2PDF'),
3170 DEST_PREFIX => $dpfx,
3171 DEST_INFO_PREFIX => $dipfx,
3172 DEST_SUFFIX => $dsfx,
3173 DIRSTAMP => $dirstamp,
3174 GENERIC => $generic,
3175 GENERIC_INFO => $generic_info,
3177 MAKEINFOFLAGS => $makeinfoflags,
3178 SILENT => silent_flag(),
3181 SOURCE_INFO => ($generic_info
3183 SOURCE_REAL => $source,
3184 SOURCE_SUFFIX => $ssfx,
3185 TEXIQUIET => verbose_flag('texinfo'),
3186 TEXIDEVNULL => verbose_flag('texidevnull'),
3188 return ($dirstamp, "$dpfx.dvi", "$dpfx.pdf", "$dpfx.ps", "$dpfx.html");
3192 # ($MOSTLYCLEAN, $TEXICLEAN, $MAINTCLEAN)
3193 # handle_texinfo_helper ($info_texinfos)
3194 # --------------------------------------
3195 # Handle all Texinfo source; helper for 'handle_texinfo'.
3196 sub handle_texinfo_helper
3198 my ($info_texinfos) = @_;
3199 my (@infobase, @info_deps_list, @texi_deps);
3202 my (@mostly_cleans, @texi_cleans, @maint_cleans) = ('', '', '');
3204 # Build a regex matching user-cleaned files.
3205 my $d = var 'DISTCLEANFILES';
3206 my $c = var 'CLEANFILES';
3208 push @f, $d->value_as_list_recursive (inner_expand => 1) if $d;
3209 push @f, $c->value_as_list_recursive (inner_expand => 1) if $c;
3210 @f = map { s|[^A-Za-z_0-9*\[\]\-]|\\$&|g; s|\*|[^/]*|g; $_; } @f;
3211 my $user_cleaned_files = '^(?:' . join ('|', @f) . ')$';
3214 ($info_texinfos->value_as_list_recursive (inner_expand => 1))
3216 my $infobase = $texi;
3217 if ($infobase =~ s/\.texi$//)
3219 1; # Nothing more to do.
3221 elsif ($infobase =~ s/\.(txi|texinfo)$//)
3223 msg_var 'obsolete', $info_texinfos,
3224 "suffix '.$1' for Texinfo files is discouraged;" .
3225 " use '.texi' instead";
3229 # FIXME: report line number.
3230 err_am "texinfo file '$texi' has unrecognized extension";
3234 push @infobase, $infobase;
3236 # If 'version.texi' is referenced by input file, then include
3237 # automatic versioning capability.
3238 my ($out_file, $vtexi) =
3239 scan_texinfo_file ("$relative_dir/$texi")
3241 # Directory of auxiliary files and build by-products used by texi2dvi
3243 push @mostly_cleans, "$infobase.t2d";
3244 push @mostly_cleans, "$infobase.t2p";
3246 # If the Texinfo source is in a subdirectory, create the
3247 # resulting info in this subdirectory. If it is in the current
3248 # directory, try hard to not prefix "./" because it breaks the
3250 my $outdir = dirname ($texi) . '/';
3251 $outdir = "" if $outdir eq './';
3252 $out_file = $outdir . $out_file;
3254 # Until Automake 1.6.3, .info files were built in the
3255 # source tree. This was an obstacle to the support of
3256 # non-distributed .info files, and non-distributed .texi
3259 # * Non-distributed .texi files is important in some packages
3260 # where .texi files are built at make time, probably using
3261 # other binaries built in the package itself, maybe using
3262 # tools or information found on the build host. Because
3263 # these files are not distributed they are always rebuilt
3264 # at make time; they should therefore not lie in the source
3265 # directory. One plan was to support this using
3266 # nodist_info_TEXINFOS or something similar. (Doing this
3267 # requires some sanity checks. For instance Automake should
3269 # dist_info_TEXINFOS = foo.texi
3270 # nodist_foo_TEXINFOS = included.texi
3271 # because a distributed file should never depend on a
3272 # non-distributed file.)
3274 # * If .texi files are not distributed, then .info files should
3275 # not be distributed either. There are also cases where one
3276 # wants to distribute .texi files, but does not want to
3277 # distribute the .info files. For instance the Texinfo package
3278 # distributes the tool used to build these files; it would
3279 # be a waste of space to distribute them. It's not clear
3280 # which syntax we should use to indicate that .info files should
3281 # not be distributed. Akim Demaille suggested that eventually
3282 # we switch to a new syntax:
3283 # | Maybe we should take some inspiration from what's already
3284 # | done in the rest of Automake. Maybe there is too much
3285 # | syntactic sugar here, and you want
3286 # | nodist_INFO = bar.info
3287 # | dist_bar_info_SOURCES = bar.texi
3288 # | bar_texi_DEPENDENCIES = foo.texi
3289 # | with a bit of magic to have bar.info represent the whole
3290 # | bar*info set. That's a lot more verbose that the current
3291 # | situation, but it is # not new, hence the user has less
3294 # | But there is still too much room for meaningless specs:
3295 # | nodist_INFO = bar.info
3296 # | dist_bar_info_SOURCES = bar.texi
3297 # | dist_PS = bar.ps something-written-by-hand.ps
3298 # | nodist_bar_ps_SOURCES = bar.texi
3299 # | bar_texi_DEPENDENCIES = foo.texi
3300 # | here bar.texi is dist_ in line 2, and nodist_ in 4.
3302 # Back to the point, it should be clear that in order to support
3303 # non-distributed .info files, we need to build them in the
3304 # build tree, not in the source tree (non-distributed .texi
3305 # files are less of a problem, because we do not output build
3306 # rules for them). In Automake 1.7 .info build rules have been
3307 # largely cleaned up so that .info files get always build in the
3308 # build tree, even when distributed. The idea was that
3309 # (1) if during a VPATH build the .info file was found to be
3310 # absent or out-of-date (in the source tree or in the
3311 # build tree), Make would rebuild it in the build tree.
3312 # If an up-to-date source-tree of the .info file existed,
3313 # make would not rebuild it in the build tree.
3314 # (2) having two copies of .info files, one in the source tree
3315 # and one (newer) in the build tree is not a problem
3316 # because 'make dist' always pick files in the build tree
3318 # However it turned out the be a bad idea for several reasons:
3319 # * Tru64, OpenBSD, and FreeBSD (not NetBSD) Make do not behave
3320 # like GNU Make on point (1) above. These implementations
3321 # of Make would always rebuild .info files in the build
3322 # tree, even if such files were up to date in the source
3323 # tree. Consequently, it was impossible to perform a VPATH
3324 # build of a package containing Texinfo files using these
3325 # Make implementations.
3326 # (Refer to the Autoconf Manual, section "Limitation of
3327 # Make", paragraph "VPATH", item "target lookup", for
3328 # an account of the differences between these
3330 # * The GNU Coding Standards require these files to be built
3331 # in the source-tree (when they are distributed, that is).
3332 # * Keeping a fresher copy of distributed files in the
3333 # build tree can be annoying during development because
3334 # - if the files is kept under CVS, you really want it
3335 # to be updated in the source tree
3336 # - it is confusing that 'make distclean' does not erase
3337 # all files in the build tree.
3339 # Consequently, starting with Automake 1.8, .info files are
3340 # built in the source tree again. Because we still plan to
3341 # support non-distributed .info files at some point, we
3342 # have a single variable ($INSRC) that controls whether
3343 # the current .info file must be built in the source tree
3344 # or in the build tree. Actually this variable is switched
3346 # (1) For '.info' files that appear to be cleaned; this is for
3347 # backward compatibility with package such as Texinfo,
3348 # which do things like
3349 # info_TEXINFOS = texinfo.txi info-stnd.texi info.texi
3350 # DISTCLEANFILES = texinfo texinfo-* info*.info*
3351 # # Do not create info files for distribution.
3353 # in order not to distribute .info files.
3354 # (2) When the undocumented option 'info-in-builddir' is given.
3355 # This is done to allow the developers of GCC, GDB, GNU
3356 # binutils and the GNU bfd library to force the '.info' files
3357 # to be generated in the builddir rather than the srcdir, as
3358 # was once done when the (now removed) 'cygnus' option was
3359 # given. See automake bug#11034 for more discussion.
3361 my $soutdir = '$(srcdir)/' . $outdir;
3363 if (option 'info-in-builddir')
3367 elsif ($out_file =~ $user_cleaned_files)
3370 msg 'obsolete', "$am_file.am", <<EOF;
3372 It appears this file (or files included by it) are triggering
3373 an undocumented, soon-to-be-removed automake hack.
3374 Future automake versions will no longer place in the builddir
3375 (rather than in the srcdir) the generated '.info' files that
3376 appear to be cleaned, by e.g. being listed in CLEANFILES or
3378 If you want your '.info' files to be placed in the builddir
3379 rather than in the srcdir, you have to use the shiny new
3380 'info-in-builddir' automake option.
3384 $outdir = $soutdir if $insrc;
3386 # If user specified file_TEXINFOS, then use that as explicit
3389 push (@texi_deps, "${soutdir}${vtexi}") if $vtexi;
3391 my $canonical = canonicalize ($infobase);
3392 if (var ($canonical . "_TEXINFOS"))
3394 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
3395 push_dist_common ('$(' . $canonical . '_TEXINFOS)');
3398 my ($dirstamp, @cfiles) =
3399 output_texinfo_build_rules ($texi, $out_file, $insrc, @texi_deps);
3400 push (@texi_cleans, @cfiles);
3402 push (@info_deps_list, $out_file);
3404 # If a vers*.texi file is needed, emit the rule.
3407 err_am ("'$vtexi', included in '$texi', "
3408 . "also included in '$versions{$vtexi}'")
3409 if defined $versions{$vtexi};
3410 $versions{$vtexi} = $texi;
3412 # We number the stamp-vti files. This is doable since the
3413 # actual names don't matter much. We only number starting
3414 # with the second one, so that the common case looks nice.
3415 my $vti = ($done ? $done : 'vti');
3418 # This is ugly, but it is our historical practice.
3419 if ($config_aux_dir_set_in_configure_ac)
3421 require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3426 require_file_with_macro (TRUE, 'info_TEXINFOS',
3427 FOREIGN, 'mdate-sh');
3431 if ($config_aux_dir_set_in_configure_ac)
3433 $conf_dir = "$am_config_aux_dir/";
3437 $conf_dir = '$(srcdir)/';
3439 $output_rules .= file_contents ('texi-vers',
3440 new Automake::Location,
3443 STAMPVTI => "${soutdir}stamp-$vti",
3444 VTEXI => "$soutdir$vtexi",
3446 DIRSTAMP => $dirstamp);
3450 # Handle location of texinfo.tex.
3451 my $need_texi_file = 0;
3453 if (var ('TEXINFO_TEX'))
3455 # The user defined TEXINFO_TEX so assume he knows what he is
3457 $texinfodir = ('$(srcdir)/'
3458 . dirname (variable_value ('TEXINFO_TEX')));
3460 elsif ($config_aux_dir_set_in_configure_ac)
3462 $texinfodir = $am_config_aux_dir;
3463 define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex", INTERNAL);
3464 $need_texi_file = 2; # so that we require_conf_file later
3468 $texinfodir = '$(srcdir)';
3469 $need_texi_file = 1;
3471 define_variable ('am__TEXINFO_TEX_DIR', $texinfodir, INTERNAL);
3473 push (@dist_targets, 'dist-info');
3475 if (! option 'no-installinfo')
3477 # Make sure documentation is made and installed first. Use
3478 # $(INFO_DEPS), not 'info', because otherwise recursive makes
3479 # get run twice during "make all".
3480 unshift (@all, '$(INFO_DEPS)');
3483 define_files_variable ("DVIS", @infobase, 'dvi', INTERNAL);
3484 define_files_variable ("PDFS", @infobase, 'pdf', INTERNAL);
3485 define_files_variable ("PSS", @infobase, 'ps', INTERNAL);
3486 define_files_variable ("HTMLS", @infobase, 'html', INTERNAL);
3488 # This next isn't strictly needed now -- the places that look here
3489 # could easily be changed to look in info_TEXINFOS. But this is
3490 # probably better, in case noinst_TEXINFOS is ever supported.
3491 define_variable ("TEXINFOS", variable_value ('info_TEXINFOS'), INTERNAL);
3493 # Do some error checking. Note that this file is not required
3494 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3496 if ($need_texi_file && ! option 'no-texinfo.tex')
3498 if ($need_texi_file > 1)
3500 require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3505 require_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3510 return (makefile_wrap ("", "\t ", @mostly_cleans),
3511 makefile_wrap ("", "\t ", @texi_cleans),
3512 makefile_wrap ("", "\t ", @maint_cleans));
3516 sub handle_texinfo ()
3518 reject_var 'TEXINFOS', "'TEXINFOS' is an anachronism; use 'info_TEXINFOS'";
3519 # FIXME: I think this is an obsolete future feature name.
3520 reject_var 'html_TEXINFOS', "HTML generation not yet supported";
3522 my $info_texinfos = var ('info_TEXINFOS');
3523 my ($mostlyclean, $clean, $maintclean) = ('', '', '');
3526 define_verbose_texinfo;
3527 ($mostlyclean, $clean, $maintclean) = handle_texinfo_helper ($info_texinfos);
3533 $output_rules .= file_contents ('texinfos',
3534 new Automake::Location,
3535 AM_V_DVIPS => verbose_flag('DVIPS'),
3536 MOSTLYCLEAN => $mostlyclean,
3537 TEXICLEAN => $clean,
3538 MAINTCLEAN => $maintclean,
3539 'LOCAL-TEXIS' => !!$info_texinfos,
3540 TEXIQUIET => verbose_flag('texinfo'));
3544 sub handle_man_pages ()
3546 reject_var 'MANS', "'MANS' is an anachronism; use 'man_MANS'";
3548 # Find all the sections in use. We do this by first looking for
3549 # "standard" sections, and then looking for any additional
3550 # sections used in man_MANS.
3551 my (%sections, %notrans_sections, %trans_sections,
3552 %notrans_vars, %trans_vars, %notrans_sect_vars, %trans_sect_vars);
3553 # We handle nodist_ for uniformity. man pages aren't distributed
3554 # by default so it isn't actually very important.
3555 foreach my $npfx ('', 'notrans_')
3557 foreach my $pfx ('', 'dist_', 'nodist_')
3559 # Add more sections as needed.
3560 foreach my $section ('0'..'9', 'n', 'l')
3562 my $varname = $npfx . $pfx . 'man' . $section . '_MANS';
3565 $sections{$section} = 1;
3566 $varname = '$(' . $varname . ')';
3567 if ($npfx eq 'notrans_')
3569 $notrans_sections{$section} = 1;
3570 $notrans_sect_vars{$varname} = 1;
3574 $trans_sections{$section} = 1;
3575 $trans_sect_vars{$varname} = 1;
3578 push_dist_common ($varname)
3583 my $varname = $npfx . $pfx . 'man_MANS';
3584 my $var = var ($varname);
3587 foreach ($var->value_as_list_recursive)
3589 # A page like 'foo.1c' goes into man1dir.
3590 if (/\.([0-9a-z])([a-z]*)$/)
3593 if ($npfx eq 'notrans_')
3595 $notrans_sections{$1} = 1;
3599 $trans_sections{$1} = 1;
3604 $varname = '$(' . $varname . ')';
3605 if ($npfx eq 'notrans_')
3607 $notrans_vars{$varname} = 1;
3611 $trans_vars{$varname} = 1;
3613 push_dist_common ($varname)
3619 return unless %sections;
3623 # Build section independent variables.
3624 my $have_notrans = %notrans_vars;
3625 my @notrans_list = sort keys %notrans_vars;
3626 my $have_trans = %trans_vars;
3627 my @trans_list = sort keys %trans_vars;
3629 # Now for each section, generate an install and uninstall rule.
3630 # Sort sections so output is deterministic.
3631 foreach my $section (sort keys %sections)
3633 # Build section dependent variables.
3634 my $notrans_mans = $have_notrans || exists $notrans_sections{$section};
3635 my $trans_mans = $have_trans || exists $trans_sections{$section};
3636 my (%notrans_this_sect, %trans_this_sect);
3637 my $expr = 'man' . $section . '_MANS';
3638 foreach my $varname (keys %notrans_sect_vars)
3640 if ($varname =~ /$expr/)
3642 $notrans_this_sect{$varname} = 1;
3645 foreach my $varname (keys %trans_sect_vars)
3647 if ($varname =~ /$expr/)
3649 $trans_this_sect{$varname} = 1;
3652 my @notrans_sect_list = sort keys %notrans_this_sect;
3653 my @trans_sect_list = sort keys %trans_this_sect;
3654 @unsorted_deps = (keys %notrans_vars, keys %trans_vars,
3655 keys %notrans_this_sect, keys %trans_this_sect);
3656 my @deps = sort @unsorted_deps;
3657 $output_rules .= file_contents ('mans',
3658 new Automake::Location,
3659 SECTION => $section,
3661 NOTRANS_MANS => $notrans_mans,
3662 NOTRANS_SECT_LIST => "@notrans_sect_list",
3663 HAVE_NOTRANS => $have_notrans,
3664 NOTRANS_LIST => "@notrans_list",
3665 TRANS_MANS => $trans_mans,
3666 TRANS_SECT_LIST => "@trans_sect_list",
3667 HAVE_TRANS => $have_trans,
3668 TRANS_LIST => "@trans_list");
3671 @unsorted_deps = (keys %notrans_vars, keys %trans_vars,
3672 keys %notrans_sect_vars, keys %trans_sect_vars);
3673 my @mans = sort @unsorted_deps;
3674 $output_vars .= file_contents ('mans-vars',
3675 new Automake::Location,
3678 push (@all, '$(MANS)')
3679 unless option 'no-installman';
3685 am_install_var ('-noextra', '-candist', 'data', 'DATA',
3686 'data', 'dataroot', 'doc', 'dvi', 'html', 'pdf',
3687 'ps', 'sysconf', 'sharedstate', 'localstate',
3688 'pkgdata', 'lisp', 'noinst', 'check');
3695 foreach my $spec (@config_headers)
3697 my ($out, @ins) = split_config_file_spec ($spec);
3698 foreach my $in (@ins)
3700 # If the config header source is in this directory,
3702 push @config, basename ($in)
3703 if $relative_dir eq dirname ($in);
3707 define_variable ('am__tagged_files',
3708 '$(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)'
3709 . "@config", INTERNAL);
3711 if (rvar('am__tagged_files')->value_as_list_recursive
3712 || var ('ETAGS_ARGS') || var ('SUBDIRS'))
3714 $output_rules .= file_contents ('tags', new Automake::Location);
3715 set_seen 'TAGS_DEPENDENCIES';
3719 reject_var ('TAGS_DEPENDENCIES',
3720 "it doesn't make sense to define 'TAGS_DEPENDENCIES'"
3721 . " without\nsources or 'ETAGS_ARGS'");
3722 # Every Makefile must define some sort of TAGS rule.
3723 # Otherwise, it would be possible for a top-level "make TAGS"
3724 # to fail because some subdirectory failed. Ditto ctags and
3728 "ctags CTAGS:\n\n" .
3729 "cscope cscopelist:\n\n";
3734 # user_phony_rule ($NAME)
3735 # -----------------------
3736 # Return false if rule $NAME does not exist. Otherwise,
3737 # declare it as phony, complete its definition (in case it is
3738 # conditional), and return its Automake::Rule instance.
3742 my $rule = rule $name;
3745 depend ('.PHONY', $name);
3746 # Define $NAME in all condition where it is not already defined,
3747 # so that it is always OK to depend on $NAME.
3748 for my $c ($rule->not_always_defined_in_cond (TRUE)->conds)
3750 Automake::Rule::define ($name, 'internal', RULE_AUTOMAKE,
3752 $output_rules .= $c->subst_string . "$name:\n";
3759 # Handle 'dist' target.
3762 # Substitutions for distdir.am
3765 # Define DIST_SUBDIRS. This must always be done, regardless of the
3766 # no-dist setting: target like 'distclean' or 'maintainer-clean' use it.
3767 my $subdirs = var ('SUBDIRS');
3770 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3771 # to all possible directories, and use it. If DIST_SUBDIRS is
3772 # defined, just use it.
3774 # Note that we check DIST_SUBDIRS first on purpose, so that
3775 # we don't call has_conditional_contents for now reason.
3776 # (In the past one project used so many conditional subdirectories
3777 # that calling has_conditional_contents on SUBDIRS caused
3778 # automake to grow to 150Mb -- this should not happen with
3779 # the current implementation of has_conditional_contents,
3780 # but it's more efficient to avoid the call anyway.)
3781 if (var ('DIST_SUBDIRS'))
3784 elsif ($subdirs->has_conditional_contents)
3786 define_pretty_variable
3787 ('DIST_SUBDIRS', TRUE, INTERNAL,
3788 uniq ($subdirs->value_as_list_recursive));
3792 # We always define this because that is what 'distclean'
3794 define_pretty_variable ('DIST_SUBDIRS', TRUE, INTERNAL,
3799 # The remaining definitions are only required when a dist target is used.
3800 return if option 'no-dist';
3802 # At least one of the archive formats must be enabled.
3803 if ($relative_dir eq '.')
3805 my $archive_defined = option 'no-dist-gzip' ? 0 : 1;
3806 $archive_defined ||=
3807 grep { option "dist-$_" } qw(shar zip tarZ bzip2 lzip xz);
3808 error (option 'no-dist-gzip',
3809 "no-dist-gzip specified but no dist-* specified,\n"
3810 . "at least one archive format must be enabled")
3811 unless $archive_defined;
3814 # Look for common files that should be included in distribution.
3815 # If the aux dir is set, and it does not have a Makefile.am, then
3816 # we check for these files there as well.
3818 if ($relative_dir eq '.'
3819 && $config_aux_dir_set_in_configure_ac)
3821 if (! is_make_dir ($config_aux_dir))
3826 foreach my $cfile (@common_files)
3828 if (dir_has_case_matching_file ($relative_dir, $cfile)
3829 # The file might be absent, but if it can be built it's ok.
3832 push_dist_common ($cfile);
3835 # Don't use 'elsif' here because a file might meaningfully
3836 # appear in both directories.
3837 if ($check_aux && dir_has_case_matching_file ($config_aux_dir, $cfile))
3839 push_dist_common ("$config_aux_dir/$cfile")
3843 # We might copy elements from @configure_dist_common to
3844 # @dist_common if we think we need to. If the file appears in our
3845 # directory, we would have discovered it already, so we don't
3846 # check that. But if the file is in a subdir without a Makefile,
3847 # we want to distribute it here if we are doing '.'. Ugly!
3848 # Also, in some corner cases, it's possible that the following code
3849 # will cause the same file to appear in the $(DIST_COMMON) variables
3850 # of two distinct Makefiles; but this is not a problem, since the
3851 # 'distdir' target in 'lib/am/distdir.am' can deal with the same
3852 # file being distributed multiple times.
3853 # See also automake bug#9651.
3854 if ($relative_dir eq '.')
3856 foreach my $file (@configure_dist_common)
3858 my $dir = dirname ($file);
3859 push_dist_common ($file)
3860 if ($dir eq '.' || ! is_make_dir ($dir));
3862 @configure_dist_common = ();
3865 # $(am__DIST_COMMON): files to be distributed automatically. Will be
3866 # appended to $(DIST_COMMON) in the generated Makefile.
3867 # Use 'sort' so that the expansion of $(DIST_COMMON) in the generated
3868 # Makefile is deterministic, in face of m4 and/or perl randomizations
3869 # (see automake bug#17908).
3870 define_pretty_variable ('am__DIST_COMMON', TRUE, INTERNAL,
3871 uniq (sort @dist_common));
3873 # Now that we've processed @dist_common, disallow further attempts
3875 $handle_dist_run = 1;
3877 $transform{'DISTCHECK-HOOK'} = !! rule 'distcheck-hook';
3878 $transform{'GETTEXT'} = $seen_gettext && !$seen_gettext_external;
3880 # If the target 'dist-hook' exists, make sure it is run. This
3881 # allows users to do random weird things to the distribution
3882 # before it is packaged up.
3883 push (@dist_targets, 'dist-hook')
3884 if user_phony_rule 'dist-hook';
3885 $transform{'DIST-TARGETS'} = join (' ', @dist_targets);
3887 my $flm = option ('filename-length-max');
3888 my $filename_filter = $flm ? '.' x $flm->[1] : '';
3890 $output_rules .= file_contents ('distdir',
3891 new Automake::Location,
3893 FILENAME_FILTER => $filename_filter);
3897 # check_directory ($NAME, $WHERE [, $RELATIVE_DIR = "."])
3898 # -------------------------------------------------------
3899 # Ensure $NAME is a directory (in $RELATIVE_DIR), and that it uses a sane
3900 # name. Use $WHERE as a location in the diagnostic, if any.
3903 my ($dir, $where, $reldir) = @_;
3904 $reldir = '.' unless defined $reldir;
3906 error $where, "required directory $reldir/$dir does not exist"
3907 unless -d "$reldir/$dir";
3909 # If an 'obj/' directory exists, BSD make will enter it before
3910 # reading 'Makefile'. Hence the 'Makefile' in the current directory
3916 # % cat obj/Makefile
3922 # % pmake # BSD make
3925 msg ('portability', $where,
3926 "naming a subdirectory 'obj' causes troubles with BSD make")
3929 # 'aux' is probably the most important of the following forbidden name,
3930 # since it's tempting to use it as an AC_CONFIG_AUX_DIR.
3931 msg ('portability', $where,
3932 "name '$dir' is reserved on W32 and DOS platforms")
3933 if grep (/^\Q$dir\E$/i, qw/aux lpt1 lpt2 lpt3 com1 com2 com3 com4 con prn/);
3936 # check_directories_in_var ($VARIABLE)
3937 # ------------------------------------
3938 # Recursively check all items in variables $VARIABLE as directories
3939 sub check_directories_in_var
3942 $var->traverse_recursively
3945 my ($var, $val, $cond, $full_cond) = @_;
3946 check_directory ($val, $var->rdef ($cond)->location, $relative_dir);
3950 skip_ac_subst => 1);
3954 sub handle_subdirs ()
3956 my $subdirs = var ('SUBDIRS');
3960 check_directories_in_var $subdirs;
3962 my $dsubdirs = var ('DIST_SUBDIRS');
3963 check_directories_in_var $dsubdirs
3966 $output_rules .= file_contents ('subdirs', new Automake::Location);
3967 rvar ('RECURSIVE_TARGETS')->rdef (TRUE)->{'pretty'} = VAR_SORTED; # Gross!
3971 # ($REGEN, @DEPENDENCIES)
3974 # If aclocal.m4 creation is automated, return the list of its dependencies.
3975 sub scan_aclocal_m4 ()
3977 my $regen_aclocal = 0;
3979 set_seen 'CONFIG_STATUS_DEPENDENCIES';
3980 set_seen 'CONFIGURE_DEPENDENCIES';
3982 if (-f 'aclocal.m4')
3984 define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4', INTERNAL);
3986 my $aclocal = new Automake::XFile "< aclocal.m4";
3987 my $line = $aclocal->getline;
3988 $regen_aclocal = $line =~ 'generated automatically by aclocal';
3993 if (set_seen ('ACLOCAL_M4_SOURCES'))
3995 push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3996 msg_var ('obsolete', 'ACLOCAL_M4_SOURCES',
3997 "'ACLOCAL_M4_SOURCES' is obsolete.\n"
3998 . "It should be safe to simply remove it");
4001 # Note that it might be possible that aclocal.m4 doesn't exist but
4002 # should be auto-generated. This case probably isn't very
4005 return ($regen_aclocal, @ac_deps);
4009 # Helper function for 'substitute_ac_subst_variables'.
4010 sub substitute_ac_subst_variables_worker
4013 return "\@$token\@" if var $token;
4014 return "\${$token\}";
4017 # substitute_ac_subst_variables ($TEXT)
4018 # -------------------------------------
4019 # Replace any occurrence of ${FOO} in $TEXT by @FOO@ if FOO is an AC_SUBST
4021 sub substitute_ac_subst_variables
4024 $text =~ s/\$[{]([^ \t=:+{}]+)}/substitute_ac_subst_variables_worker ($1)/ge;
4029 # prepend_srcdir (@INPUTS)
4030 # ------------------------
4031 # Prepend $(srcdir) or $(top_srcdir) to all @INPUTS. The idea is that
4032 # if an input file has a directory part the same as the current
4033 # directory, then the directory part is simply replaced by $(srcdir).
4034 # But if the directory part is different, then $(top_srcdir) is
4041 foreach my $single (@inputs)
4043 if (dirname ($single) eq $relative_dir)
4045 push (@newinputs, '$(srcdir)/' . basename ($single));
4049 push (@newinputs, '$(top_srcdir)/' . $single);
4056 # rewrite_inputs_into_dependencies ($OUTPUT, @INPUTS)
4057 # ---------------------------------------------------
4058 # Compute a list of dependencies appropriate for the rebuild
4060 # AC_CONFIG_FILES($OUTPUT:$INPUT[0]:$INPUTS[1]:...)
4061 # Also distribute $INPUTs which are not built by another AC_CONFIG_FOOs.
4062 sub rewrite_inputs_into_dependencies
4064 my ($file, @inputs) = @_;
4069 # We cannot create dependencies on shell variables.
4070 next if (substitute_ac_subst_variables $i) =~ /\$/;
4072 if (exists $ac_config_files_location{$i} && $i ne $file)
4074 my $di = dirname $i;
4075 if ($di eq $relative_dir)
4079 # In the top-level Makefile we do not use $(top_builddir), because
4080 # we are already there, and since the targets are built without
4081 # a $(top_builddir), it helps BSD Make to match them with
4083 elsif ($relative_dir ne '.')
4085 $i = '$(top_builddir)/' . $i;
4090 msg ('error', $ac_config_files_location{$file},
4091 "required file '$i' not found")
4092 unless $i =~ /\$/ || exists $output_files{$i} || -f $i;
4093 ($i) = prepend_srcdir ($i);
4094 push_dist_common ($i);
4103 # handle_configure ($MAKEFILE_AM, $MAKEFILE_IN, $MAKEFILE, @INPUTS)
4104 # -----------------------------------------------------------------
4105 # Handle remaking and configure stuff.
4106 # We need the name of the input file, to do proper remaking rules.
4107 sub handle_configure
4109 my ($makefile_am, $makefile_in, $makefile, @inputs) = @_;
4111 prog_error 'empty @inputs'
4114 my ($rel_makefile_am, $rel_makefile_in) = prepend_srcdir ($makefile_am,
4116 my $rel_makefile = basename $makefile;
4118 my $colon_infile = ':' . join (':', @inputs);
4119 $colon_infile = '' if $colon_infile eq ":$makefile.in";
4120 my @rewritten = rewrite_inputs_into_dependencies ($makefile, @inputs);
4121 my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4;
4122 define_pretty_variable ('am__aclocal_m4_deps', TRUE, INTERNAL,
4123 @configure_deps, @aclocal_m4_deps,
4124 '$(top_srcdir)/' . $configure_ac);
4125 my @configuredeps = ('$(am__aclocal_m4_deps)', '$(CONFIGURE_DEPENDENCIES)');
4126 push @configuredeps, '$(ACLOCAL_M4)' if -f 'aclocal.m4';
4127 define_pretty_variable ('am__configure_deps', TRUE, INTERNAL,
4130 my $automake_options = '--' . $strictness_name .
4131 (global_option 'no-dependencies' ? ' --ignore-deps' : '');
4133 $output_rules .= file_contents
4135 new Automake::Location,
4136 MAKEFILE => $rel_makefile,
4137 'MAKEFILE-DEPS' => "@rewritten",
4138 'CONFIG-MAKEFILE' => ($relative_dir eq '.') ? '$@' : '$(subdir)/$@',
4139 'MAKEFILE-IN' => $rel_makefile_in,
4140 'HAVE-MAKEFILE-IN-DEPS' => (@include_stack > 0),
4141 'MAKEFILE-IN-DEPS' => "@include_stack",
4142 'MAKEFILE-AM' => $rel_makefile_am,
4143 'AUTOMAKE-OPTIONS' => $automake_options,
4144 'MAKEFILE-AM-SOURCES' => "$makefile$colon_infile",
4145 'REGEN-ACLOCAL-M4' => $regen_aclocal_m4,
4146 VERBOSE => verbose_flag ('GEN'));
4148 if ($relative_dir eq '.')
4150 push_dist_common ('acconfig.h')
4154 # If we have a configure header, require it.
4156 my @distclean_config;
4157 foreach my $spec (@config_headers)
4160 # $CONFIG_H_PATH: config.h from top level.
4161 my ($config_h_path, @ins) = split_config_file_spec ($spec);
4162 my $config_h_dir = dirname ($config_h_path);
4164 # If the header is in the current directory we want to build
4165 # the header here. Otherwise, if we're at the topmost
4166 # directory and the header's directory doesn't have a
4167 # Makefile, then we also want to build the header.
4168 if ($relative_dir eq $config_h_dir
4169 || ($relative_dir eq '.' && ! is_make_dir ($config_h_dir)))
4171 my ($cn_sans_dir, $stamp_dir);
4172 if ($relative_dir eq $config_h_dir)
4174 $cn_sans_dir = basename ($config_h_path);
4179 $cn_sans_dir = $config_h_path;
4180 if ($config_h_dir eq '.')
4186 $stamp_dir = $config_h_dir . '/';
4190 # This will also distribute all inputs.
4191 @ins = rewrite_inputs_into_dependencies ($config_h_path, @ins);
4193 # Cannot define rebuild rules for filenames with shell variables.
4194 next if (substitute_ac_subst_variables $config_h_path) =~ /\$/;
4196 # Header defined in this directory.
4198 if (-f $config_h_path . '.top')
4200 push (@files, "$cn_sans_dir.top");
4202 if (-f $config_h_path . '.bot')
4204 push (@files, "$cn_sans_dir.bot");
4207 push_dist_common (@files);
4209 # For now, acconfig.h can only appear in the top srcdir.
4210 if (-f 'acconfig.h')
4212 push (@files, '$(top_srcdir)/acconfig.h');
4215 my $stamp = "${stamp_dir}stamp-h${hdr_index}";
4217 file_contents ('remake-hdr',
4218 new Automake::Location,
4220 'FIRST-HDR' => ($hdr_index == 1),
4221 CONFIG_H => $cn_sans_dir,
4222 CONFIG_HIN => $ins[0],
4223 CONFIG_H_DEPS => "@ins",
4224 CONFIG_H_PATH => $config_h_path,
4227 push @distclean_config, $cn_sans_dir, $stamp;
4231 $output_rules .= file_contents ('clean-hdr',
4232 new Automake::Location,
4233 FILES => "@distclean_config")
4234 if @distclean_config;
4236 # Distribute and define mkinstalldirs only if it is already present
4237 # in the package, for backward compatibility (some people may still
4238 # use $(mkinstalldirs)).
4239 # TODO: start warning about this in Automake 1.14, and have
4240 # TODO: Automake 2.0 drop it (and the mkinstalldirs script
4242 my $mkidpath = "$config_aux_dir/mkinstalldirs";
4245 # Use require_file so that any existing script gets updated
4246 # by --force-missing.
4247 require_conf_file ($mkidpath, FOREIGN, 'mkinstalldirs');
4248 define_variable ('mkinstalldirs',
4249 "\$(SHELL) $am_config_aux_dir/mkinstalldirs", INTERNAL);
4253 # Use $(install_sh), not $(MKDIR_P) because the latter requires
4254 # at least one argument, and $(mkinstalldirs) used to work
4255 # even without arguments (e.g. $(mkinstalldirs) $(conditional_dir)).
4256 define_variable ('mkinstalldirs', '$(install_sh) -d', INTERNAL);
4259 reject_var ('CONFIG_HEADER',
4260 "'CONFIG_HEADER' is an anachronism; now determined "
4261 . "automatically\nfrom '$configure_ac'");
4264 foreach my $spec (@config_headers)
4266 my ($out, @ins) = split_config_file_spec ($spec);
4267 # Generate CONFIG_HEADER define.
4268 if ($relative_dir eq dirname ($out))
4270 push @config_h, basename ($out);
4274 push @config_h, "\$(top_builddir)/$out";
4277 define_variable ("CONFIG_HEADER", "@config_h", INTERNAL)
4280 # Now look for other files in this directory which must be remade
4281 # by config.status, and generate rules for them.
4282 my @actual_other_files = ();
4283 # These get cleaned only in a VPATH build.
4284 my @actual_other_vpath_files = ();
4285 foreach my $lfile (@other_input_files)
4289 if ($lfile =~ /^([^:]*):(.*)$/)
4291 # This is the ":" syntax of AC_OUTPUT.
4293 @inputs = split (':', $2);
4299 @inputs = $file . '.in';
4302 # Automake files should not be stored in here, but in %MAKE_LIST.
4303 prog_error ("$lfile in \@other_input_files\n"
4304 . "\@other_input_files = (@other_input_files)")
4305 if -f $file . '.am';
4307 my $local = basename ($file);
4309 # We skip files that aren't in this directory. However, if
4310 # the file's directory does not have a Makefile, and we are
4311 # currently doing '.', then we create a rule to rebuild the
4312 # file in the subdir.
4313 my $fd = dirname ($file);
4314 if ($fd ne $relative_dir)
4316 if ($relative_dir eq '.' && ! is_make_dir ($fd))
4326 my @rewritten_inputs = rewrite_inputs_into_dependencies ($file, @inputs);
4328 # Cannot output rules for shell variables.
4329 next if (substitute_ac_subst_variables $local) =~ /\$/;
4332 my $cond = $ac_config_files_condition{$lfile};
4335 $condstr = $cond->subst_string;
4336 Automake::Rule::define ($local, $configure_ac, RULE_AUTOMAKE, $cond,
4337 $ac_config_files_location{$file});
4339 $output_rules .= ($condstr . $local . ': '
4340 . '$(top_builddir)/config.status '
4341 . "@rewritten_inputs\n"
4343 . 'cd $(top_builddir) && '
4344 . '$(SHELL) ./config.status '
4345 . ($relative_dir eq '.' ? '' : '$(subdir)/')
4348 push (@actual_other_files, $local);
4351 # For links we should clean destinations and distribute sources.
4352 foreach my $spec (@config_links)
4354 my ($link, $file) = split /:/, $spec;
4355 # Some people do AC_CONFIG_LINKS($computed). We only handle
4356 # the DEST:SRC form.
4358 my $where = $ac_config_files_location{$link};
4360 # Skip destinations that contain shell variables.
4361 if ((substitute_ac_subst_variables $link) !~ /\$/)
4363 # We skip links that aren't in this directory. However, if
4364 # the link's directory does not have a Makefile, and we are
4365 # currently doing '.', then we add the link to CONFIG_CLEAN_FILES
4366 # in '.'s Makefile.in.
4367 my $local = basename ($link);
4368 my $fd = dirname ($link);
4369 if ($fd ne $relative_dir)
4371 if ($relative_dir eq '.' && ! is_make_dir ($fd))
4382 push @actual_other_files, $local if $local;
4386 push @actual_other_vpath_files, $local if $local;
4390 # Do not process sources that contain shell variables.
4391 if ((substitute_ac_subst_variables $file) !~ /\$/)
4393 my $fd = dirname ($file);
4395 # We distribute files that are in this directory.
4396 # At the top-level ('.') we also distribute files whose
4397 # directory does not have a Makefile.
4398 if (($fd eq $relative_dir)
4399 || ($relative_dir eq '.' && ! is_make_dir ($fd)))
4401 # The following will distribute $file as a side-effect when
4402 # it is appropriate (i.e., when $file is not already an output).
4403 # We do not need the result, just the side-effect.
4404 rewrite_inputs_into_dependencies ($link, $file);
4409 # These files get removed by "make distclean".
4410 define_pretty_variable ('CONFIG_CLEAN_FILES', TRUE, INTERNAL,
4411 @actual_other_files);
4412 define_pretty_variable ('CONFIG_CLEAN_VPATH_FILES', TRUE, INTERNAL,
4413 @actual_other_vpath_files);
4416 sub handle_headers ()
4418 my @r = am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
4419 'oldinclude', 'pkginclude',
4423 next unless $_->[1] =~ /\..*$/;
4428 sub handle_gettext ()
4430 return if ! $seen_gettext || $relative_dir ne '.';
4432 my $subdirs = var 'SUBDIRS';
4436 err_ac "AM_GNU_GETTEXT used but SUBDIRS not defined";
4440 # Perform some sanity checks to help users get the right setup.
4441 # We disable these tests when po/ doesn't exist in order not to disallow
4442 # unusual gettext setups.
4447 # | 1) If a package doesn't have a directory po/ at top level, it
4448 # | will likely have multiple po/ directories in subpackages.
4450 # | 2) It is useful to warn for the absence of intl/ if AM_GNU_GETTEXT
4451 # | is used without 'external'. It is also useful to warn for the
4452 # | presence of intl/ if AM_GNU_GETTEXT([external]) is used. Both
4453 # | warnings apply only to the usual layout of packages, therefore
4454 # | they should both be disabled if no po/ directory is found at
4459 my @subdirs = $subdirs->value_as_list_recursive;
4461 msg_var ('syntax', $subdirs,
4462 "AM_GNU_GETTEXT used but 'po' not in SUBDIRS")
4463 if ! grep ($_ eq 'po', @subdirs);
4465 # intl/ is not required when AM_GNU_GETTEXT is called with the
4466 # 'external' option and AM_GNU_GETTEXT_INTL_SUBDIR is not called.
4467 msg_var ('syntax', $subdirs,
4468 "AM_GNU_GETTEXT used but 'intl' not in SUBDIRS")
4469 if (! ($seen_gettext_external && ! $seen_gettext_intl)
4470 && ! grep ($_ eq 'intl', @subdirs));
4472 # intl/ should not be used with AM_GNU_GETTEXT([external]), except
4473 # if AM_GNU_GETTEXT_INTL_SUBDIR is called.
4474 msg_var ('syntax', $subdirs,
4475 "'intl' should not be in SUBDIRS when "
4476 . "AM_GNU_GETTEXT([external]) is used")
4477 if ($seen_gettext_external && ! $seen_gettext_intl
4478 && grep ($_ eq 'intl', @subdirs));
4481 require_file ($ac_gettext_location, GNU, 'ABOUT-NLS');
4484 # Emit makefile footer.
4485 sub handle_footer ()
4487 reject_rule ('.SUFFIXES',
4488 "use variable 'SUFFIXES', not target '.SUFFIXES'");
4490 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
4491 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
4492 # anything else, by sticking it right after the default: target.
4493 $output_header .= ".SUFFIXES:\n";
4494 my $suffixes = var 'SUFFIXES';
4495 my @suffixes = Automake::Rule::suffixes;
4496 if (@suffixes || $suffixes)
4498 # Make sure SUFFIXES has unique elements. Sort them to ensure
4499 # the output remains consistent. However, $(SUFFIXES) is
4500 # always at the start of the list, unsorted. This is done
4501 # because make will choose rules depending on the ordering of
4502 # suffixes, and this lets the user have some control. Push
4503 # actual suffixes, and not $(SUFFIXES). Some versions of make
4504 # do not like variable substitutions on the .SUFFIXES line.
4505 my @user_suffixes = ($suffixes
4506 ? $suffixes->value_as_list_recursive : ());
4508 my %suffixes = map { $_ => 1 } @suffixes;
4509 delete @suffixes{@user_suffixes};
4511 $output_header .= (".SUFFIXES: "
4512 . join (' ', @user_suffixes, sort keys %suffixes)
4516 $output_trailer .= file_contents ('footer', new Automake::Location);
4520 # Generate 'make install' rules.
4521 sub handle_install ()
4523 $output_rules .= file_contents
4525 new Automake::Location,
4526 maybe_BUILT_SOURCES => (set_seen ('BUILT_SOURCES')
4527 ? (" \$(BUILT_SOURCES)\n"
4528 . "\t\$(MAKE) \$(AM_MAKEFLAGS)")
4530 'installdirs-local' => (user_phony_rule ('installdirs-local')
4531 ? ' installdirs-local' : ''),
4532 am__installdirs => variable_value ('am__installdirs') || '');
4536 # handle_all ($MAKEFILE)
4537 #-----------------------
4538 # Deal with 'all' and 'all-am'.
4541 my ($makefile) = @_;
4545 # Put this at the beginning for the sake of non-GNU makes. This
4546 # is still wrong if these makes can run parallel jobs. But it is
4548 unshift (@all, basename ($makefile));
4550 foreach my $spec (@config_headers)
4552 my ($out, @ins) = split_config_file_spec ($spec);
4553 push (@all, basename ($out))
4554 if dirname ($out) eq $relative_dir;
4557 # Install 'all' hooks.
4558 push (@all, "all-local")
4559 if user_phony_rule "all-local";
4561 pretty_print_rule ("all-am:", "\t\t", @all);
4562 depend ('.PHONY', 'all-am', 'all');
4567 my @local_headers = ();
4568 push @local_headers, '$(BUILT_SOURCES)'
4569 if var ('BUILT_SOURCES');
4570 foreach my $spec (@config_headers)
4572 my ($out, @ins) = split_config_file_spec ($spec);
4573 push @local_headers, basename ($out)
4574 if dirname ($out) eq $relative_dir;
4579 # We need to make sure config.h is built before we recurse.
4580 # We also want to make sure that built sources are built
4581 # before any ordinary 'all' targets are run. We can't do this
4582 # by changing the order of dependencies to the "all" because
4583 # that breaks when using parallel makes. Instead we handle
4584 # things explicitly.
4585 $output_all .= ("all: @local_headers"
4587 . '$(MAKE) $(AM_MAKEFLAGS) '
4588 . (var ('SUBDIRS') ? 'all-recursive' : 'all-am')
4590 depend ('.MAKE', 'all');
4594 $output_all .= "all: " . (var ('SUBDIRS')
4595 ? 'all-recursive' : 'all-am') . "\n\n";
4599 # Generate helper targets for user-defined recursive targets, where needed.
4600 sub handle_user_recursion ()
4602 return unless @extra_recursive_targets;
4604 define_pretty_variable ('am__extra_recursive_targets', TRUE, INTERNAL,
4605 map { "$_-recursive" } @extra_recursive_targets);
4606 my $aux = var ('SUBDIRS') ? 'recursive' : 'am';
4607 foreach my $target (@extra_recursive_targets)
4609 # This allows the default target's rules to be overridden in
4611 user_phony_rule ($target);
4612 depend ("$target", "$target-$aux");
4613 depend ("$target-am", "$target-local");
4614 # Every user-defined recursive target 'foo' *must* have a valid
4615 # associated 'foo-local' rule; we define it as an empty rule by
4616 # default, so that the user can transparently extend it in his
4618 pretty_print_rule ("$target-local:", '', '');
4619 # $target-recursive might as well be undefined, so do not add
4620 # it here; it's taken care of in subdirs.am anyway.
4621 depend (".PHONY", "$target-am", "$target-local");
4626 # Handle check merge target specially.
4627 sub do_check_merge_target ()
4629 # Include user-defined local form of target.
4630 push @check_tests, 'check-local'
4631 if user_phony_rule 'check-local';
4633 # The check target must depend on the local equivalent of
4634 # 'all', to ensure all the primary targets are built. Then it
4635 # must build the local check rules.
4636 $output_rules .= "check-am: all-am\n";
4639 pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @check);
4640 depend ('.MAKE', 'check-am');
4645 pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4647 depend ('.MAKE', 'check-am');
4650 depend '.PHONY', 'check', 'check-am';
4651 # Handle recursion. We have to honor BUILT_SOURCES like for 'all:'.
4652 $output_rules .= ("check: "
4653 . (var ('BUILT_SOURCES')
4654 ? "\$(BUILT_SOURCES)\n\t\$(MAKE) \$(AM_MAKEFLAGS) "
4656 . (var ('SUBDIRS') ? 'check-recursive' : 'check-am')
4658 depend ('.MAKE', 'check')
4659 if var ('BUILT_SOURCES');
4662 # Handle all 'clean' targets.
4665 my ($makefile) = @_;
4667 # Clean the files listed in user variables if they exist.
4668 $clean_files{'$(MOSTLYCLEANFILES)'} = MOSTLY_CLEAN
4669 if var ('MOSTLYCLEANFILES');
4670 $clean_files{'$(CLEANFILES)'} = CLEAN
4671 if var ('CLEANFILES');
4672 $clean_files{'$(DISTCLEANFILES)'} = DIST_CLEAN
4673 if var ('DISTCLEANFILES');
4674 $clean_files{'$(MAINTAINERCLEANFILES)'} = MAINTAINER_CLEAN
4675 if var ('MAINTAINERCLEANFILES');
4677 # Built sources are automatically removed by maintainer-clean.
4678 $clean_files{'$(BUILT_SOURCES)'} = MAINTAINER_CLEAN
4679 if var ('BUILT_SOURCES');
4681 # Compute a list of "rm"s to run for each target.
4682 my %rms = (MOSTLY_CLEAN, [],
4685 MAINTAINER_CLEAN, []);
4687 foreach my $file (keys %clean_files)
4689 my $when = $clean_files{$file};
4690 prog_error 'invalid entry in %clean_files'
4691 unless exists $rms{$when};
4693 my $rm = "rm -f $file";
4694 # If file is a variable, make sure when don't call 'rm -f' without args.
4695 $rm ="test -z \"$file\" || $rm"
4696 if ($file =~ /^\s*\$(\(.*\)|\{.*\})\s*$/);
4698 push @{$rms{$when}}, "\t-$rm\n";
4701 $output_rules .= file_contents
4703 new Automake::Location,
4704 MOSTLYCLEAN_RMS => join ('', sort @{$rms{&MOSTLY_CLEAN}}),
4705 CLEAN_RMS => join ('', sort @{$rms{&CLEAN}}),
4706 DISTCLEAN_RMS => join ('', sort @{$rms{&DIST_CLEAN}}),
4707 MAINTAINER_CLEAN_RMS => join ('', sort @{$rms{&MAINTAINER_CLEAN}}),
4708 MAKEFILE => basename $makefile,
4713 # Subroutine for handle_factored_dependencies() to let '.PHONY' and
4714 # other '.TARGETS' be last. This is meant to be used as a comparison
4715 # subroutine passed to the sort built-int.
4718 return 0 if $a eq $b;
4720 my $a1 = substr ($a, 0, 1);
4721 my $b1 = substr ($b, 0, 1);
4724 return -1 if $b1 eq '.';
4725 return 1 if $a1 eq '.';
4731 # Handle everything related to gathered targets.
4732 sub handle_factored_dependencies ()
4735 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4736 'uninstall-exec-local', 'uninstall-exec-hook',
4737 'uninstall-dvi-local',
4738 'uninstall-html-local',
4739 'uninstall-info-local',
4740 'uninstall-pdf-local',
4741 'uninstall-ps-local')
4745 reject_rule ($utarg, "use '$x', not '$utarg'");
4748 reject_rule ('install-local',
4749 "use 'install-data-local' or 'install-exec-local', "
4750 . "not 'install-local'");
4752 reject_rule ('install-hook',
4753 "use 'install-data-hook' or 'install-exec-hook', "
4754 . "not 'install-hook'");
4756 # Install the -local hooks.
4757 foreach (keys %dependencies)
4759 # Hooks are installed on the -am targets.
4761 depend ("$_-am", "$_-local")
4762 if user_phony_rule "$_-local";
4765 # Install the -hook hooks.
4766 # FIXME: Why not be as liberal as we are with -local hooks?
4767 foreach ('install-exec', 'install-data', 'uninstall')
4769 if (user_phony_rule "$_-hook")
4771 depend ('.MAKE', "$_-am");
4772 register_action("$_-am",
4773 ("\t\@\$(NORMAL_INSTALL)\n"
4774 . "\t\$(MAKE) \$(AM_MAKEFLAGS) $_-hook"));
4778 # All the required targets are phony.
4779 depend ('.PHONY', keys %required_targets);
4781 # Actually output gathered targets.
4782 foreach (sort target_cmp keys %dependencies)
4784 # If there is nothing about this guy, skip it.
4786 unless (@{$dependencies{$_}}
4788 || $required_targets{$_});
4790 # Define gathered targets in undefined conditions.
4791 # FIXME: Right now we must handle .PHONY as an exception,
4792 # because people write things like
4793 # .PHONY: myphonytarget
4794 # to append dependencies. This would not work if Automake
4795 # refrained from defining its own .PHONY target as it does
4796 # with other overridden targets.
4797 # Likewise for '.MAKE' and '.PRECIOUS'.
4798 my @undefined_conds = (TRUE,);
4799 if ($_ ne '.PHONY' && $_ ne '.MAKE' && $_ ne '.PRECIOUS')
4802 Automake::Rule::define ($_, 'internal',
4803 RULE_AUTOMAKE, TRUE, INTERNAL);
4805 my @uniq_deps = uniq (sort @{$dependencies{$_}});
4806 foreach my $cond (@undefined_conds)
4808 my $condstr = $cond->subst_string;
4809 pretty_print_rule ("$condstr$_:", "$condstr\t", @uniq_deps);
4810 $output_rules .= $actions{$_} if defined $actions{$_};
4811 $output_rules .= "\n";
4817 sub handle_tests_dejagnu ()
4819 push (@check_tests, 'check-DEJAGNU');
4820 $output_rules .= file_contents ('dejagnu', new Automake::Location);
4823 # handle_per_suffix_test ($TEST_SUFFIX, [%TRANSFORM])
4824 #----------------------------------------------------
4825 sub handle_per_suffix_test
4827 my ($test_suffix, %transform) = @_;
4828 my ($pfx, $generic, $am_exeext);
4829 if ($test_suffix eq '')
4833 $am_exeext = 'FALSE';
4837 prog_error ("test suffix '$test_suffix' lacks leading dot")
4838 unless $test_suffix =~ m/^\.(.*)/;
4839 $pfx = uc ($1) . '_';
4841 $am_exeext = exists $configure_vars{'EXEEXT'} ? 'am__EXEEXT'
4844 # The "test driver" program, deputed to handle tests protocol used by
4845 # test scripts. By default, it's assumed that no protocol is used, so
4846 # we fall back to the old behaviour, implemented by the 'test-driver'
4848 if (! var "${pfx}LOG_DRIVER")
4850 require_conf_file ("parallel-tests", FOREIGN, 'test-driver');
4851 define_variable ("${pfx}LOG_DRIVER",
4852 "\$(SHELL) $am_config_aux_dir/test-driver",
4855 my $driver = '$(' . $pfx . 'LOG_DRIVER)';
4856 my $driver_flags = '$(AM_' . $pfx . 'LOG_DRIVER_FLAGS)'
4857 . ' $(' . $pfx . 'LOG_DRIVER_FLAGS)';
4858 my $compile = "${pfx}LOG_COMPILE";
4859 define_variable ($compile,
4860 '$(' . $pfx . 'LOG_COMPILER)'
4861 . ' $(AM_' . $pfx . 'LOG_FLAGS)'
4862 . ' $(' . $pfx . 'LOG_FLAGS)',
4864 $output_rules .= file_contents ('check2', new Automake::Location,
4865 GENERIC => $generic,
4867 DRIVER_FLAGS => $driver_flags,
4868 COMPILE => '$(' . $compile . ')',
4869 EXT => $test_suffix,
4870 am__EXEEXT => $am_exeext,
4874 # is_valid_test_extension ($EXT)
4875 # ------------------------------
4876 # Return true if $EXT can appear in $(TEST_EXTENSIONS), return false
4878 sub is_valid_test_extension
4882 if ($ext =~ /^\.[a-zA-Z_][a-zA-Z0-9_]*$/);
4884 if (exists $configure_vars{'EXEEXT'} && $ext eq subst ('EXEEXT'));
4891 if (option 'dejagnu')
4893 handle_tests_dejagnu;
4897 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4899 reject_var ($c, "'$c' defined but 'dejagnu' not in "
4900 . "'AUTOMAKE_OPTIONS'");
4906 push (@check_tests, 'check-TESTS');
4907 my $check_deps = "@check";
4908 $output_rules .= file_contents ('check', new Automake::Location,
4909 SERIAL_TESTS => !! option 'serial-tests',
4910 CHECK_DEPS => $check_deps);
4912 # Tests that are known programs should have $(EXEEXT) appended.
4913 # For matching purposes, we need to adjust XFAIL_TESTS as well.
4914 append_exeext { exists $known_programs{$_[0]} } 'TESTS';
4915 append_exeext { exists $known_programs{$_[0]} } 'XFAIL_TESTS'
4916 if (var ('XFAIL_TESTS'));
4918 if (! option 'serial-tests')
4920 define_variable ('TEST_SUITE_LOG', 'test-suite.log', INTERNAL);
4923 my $handle_exeext = exists $configure_vars{'EXEEXT'};
4926 $at_exeext = subst ('EXEEXT');
4927 $suff = $at_exeext . ' ' . $suff;
4929 if (! var 'TEST_EXTENSIONS')
4931 define_variable ('TEST_EXTENSIONS', $suff, INTERNAL);
4933 my $var = var 'TEST_EXTENSIONS';
4934 # Currently, we are not able to deal with conditional contents
4935 # in TEST_EXTENSIONS.
4936 if ($var->has_conditional_contents)
4938 msg_var 'unsupported', $var,
4939 "'TEST_EXTENSIONS' cannot have conditional contents";
4941 my @test_suffixes = $var->value_as_list_recursive;
4942 if ((my @invalid_test_suffixes =
4943 grep { !is_valid_test_extension $_ } @test_suffixes) > 0)
4945 error $var->rdef (TRUE)->location,
4946 "invalid test extensions: @invalid_test_suffixes";
4948 @test_suffixes = grep { is_valid_test_extension $_ } @test_suffixes;
4951 unshift (@test_suffixes, $at_exeext)
4952 unless $test_suffixes[0] eq $at_exeext;
4954 unshift (@test_suffixes, '');
4956 transform_variable_recursively
4957 ('TESTS', 'TEST_LOGS', 'am__testlogs', 1, INTERNAL,
4959 my ($subvar, $val, $cond, $full_cond) = @_;
4962 if $val =~ /^\@.*\@$/;
4963 $obj =~ s/\$\(EXEEXT\)$//o;
4965 if ($val =~ /(\$\((top_)?srcdir\))\//o)
4967 msg ('error', $subvar->rdef ($cond)->location,
4968 "using '$1' in TESTS is currently broken: '$val'");
4971 foreach my $test_suffix (@test_suffixes)
4974 if $test_suffix eq $at_exeext || $test_suffix eq '';
4975 return substr ($obj, 0, length ($obj) - length ($test_suffix)) . '.log'
4976 if substr ($obj, - length ($test_suffix)) eq $test_suffix;
4980 handle_per_suffix_test ('',
4990 my $last_suffix = $test_suffixes[$#test_suffixes];
4992 foreach my $test_suffix (@test_suffixes)
4994 if ($test_suffix eq $last_suffix)
5000 $cur = 'am__test_logs' . $nhelper;
5002 define_variable ($cur,
5003 '$(' . $prev . ':' . $test_suffix . $post . '=.log)', INTERNAL);
5007 if ($test_suffix ne $at_exeext && $test_suffix ne '')
5009 handle_per_suffix_test ($test_suffix,
5015 $clean_files{'$(TEST_LOGS)'} = MOSTLY_CLEAN;
5016 $clean_files{'$(TEST_LOGS:.log=.trs)'} = MOSTLY_CLEAN;
5017 $clean_files{'$(TEST_SUITE_LOG)'} = MOSTLY_CLEAN;
5022 sub handle_emacs_lisp ()
5024 my @elfiles = am_install_var ('-candist', 'lisp', 'LISP',
5027 return if ! @elfiles;
5029 define_pretty_variable ('am__ELFILES', TRUE, INTERNAL,
5030 map { $_->[1] } @elfiles);
5031 define_pretty_variable ('am__ELCFILES', TRUE, INTERNAL,
5032 '$(am__ELFILES:.el=.elc)');
5033 # This one can be overridden by users.
5034 define_pretty_variable ('ELCFILES', TRUE, INTERNAL, '$(LISP:.el=.elc)');
5036 push @all, '$(ELCFILES)';
5038 require_variables ($elfiles[0][0], "Emacs Lisp sources seen", TRUE,
5039 'EMACS', 'lispdir');
5042 sub handle_python ()
5044 my @pyfiles = am_install_var ('-defaultdist', 'python', 'PYTHON',
5046 return if ! @pyfiles;
5048 require_variables ($pyfiles[0][0], "Python sources seen", TRUE, 'PYTHON');
5049 require_conf_file ($pyfiles[0][0], FOREIGN, 'py-compile');
5050 define_variable ('py_compile', "$am_config_aux_dir/py-compile", INTERNAL);
5055 my @sourcelist = am_install_var ('-candist',
5058 return if ! @sourcelist;
5060 my @prefixes = am_primary_prefixes ('JAVA', 1,
5064 my @java_sources = ();
5065 foreach my $prefix (@prefixes)
5067 (my $curs = $prefix) =~ s/^(?:nobase_)?(?:dist_|nodist_)?//;
5070 if $curs eq 'EXTRA';
5072 push @java_sources, '$(' . $prefix . '_JAVA' . ')';
5076 err_var "${curs}_JAVA", "multiple _JAVA primaries in use"
5077 unless $curs eq $dir;
5083 define_pretty_variable ('am__java_sources', TRUE, INTERNAL,
5086 if ($dir eq 'check')
5088 push (@check, "class$dir.stamp");
5092 push (@all, "class$dir.stamp");
5097 sub handle_minor_options ()
5099 if (option 'readme-alpha')
5101 if ($relative_dir eq '.')
5103 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
5105 msg ('error-gnits', $package_version_location,
5106 "version '$package_version' doesn't follow " .
5109 if (defined $1 && -f 'README-alpha')
5111 # This means we have an alpha release. See
5112 # GNITS_VERSION_PATTERN for details.
5113 push_dist_common ('README-alpha');
5119 ################################################################
5121 # ($OUTPUT, @INPUTS)
5122 # split_config_file_spec ($SPEC)
5123 # ------------------------------
5124 # Decode the Autoconf syntax for config files (files, headers, links
5126 sub split_config_file_spec
5129 my ($output, @inputs) = split (/:/, $spec);
5131 push @inputs, "$output.in"
5134 return ($output, @inputs);
5138 # locate_am (@POSSIBLE_SOURCES)
5139 # -----------------------------
5140 # AC_CONFIG_FILES allow specifications such as Makefile:top.in:mid.in:bot.in
5141 # This functions returns the first *.in file for which a *.am exists.
5142 # It returns undef otherwise.
5147 foreach my $file (@rest)
5149 if (($file =~ /^(.*)\.in$/) && -f "$1.am")
5160 # scan_autoconf_config_files ($WHERE, $CONFIG-FILES)
5161 # --------------------------------------------------
5162 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
5164 sub scan_autoconf_config_files
5166 my ($where, $config_files) = @_;
5168 # Look at potential Makefile.am's.
5169 foreach (split ' ', $config_files)
5171 # Must skip empty string for Perl 4.
5172 next if $_ eq "\\" || $_ eq '';
5174 # Handle $local:$input syntax.
5175 my ($local, @rest) = split (/:/);
5176 @rest = ("$local.in",) unless @rest;
5177 # Keep in sync with test 'conffile-leading-dot.sh'.
5178 msg ('unsupported', $where,
5179 "omit leading './' from config file names such as '$local';"
5180 . "\nremake rules might be subtly broken otherwise")
5181 if ($local =~ /^\.\//);
5182 my $input = locate_am @rest;
5185 # We have a file that automake should generate.
5186 $make_list{$input} = join (':', ($local, @rest));
5190 # We have a file that automake should cause to be
5191 # rebuilt, but shouldn't generate itself.
5192 push (@other_input_files, $_);
5194 $ac_config_files_location{$local} = $where;
5195 $ac_config_files_condition{$local} =
5196 new Automake::Condition (@cond_stack)
5202 sub scan_autoconf_traces
5204 my ($filename) = @_;
5206 # Macros to trace, with their minimal number of arguments.
5208 # IMPORTANT: If you add a macro here, you should also add this macro
5209 # ========= to Automake-preselection in autoconf/lib/autom4te.in.
5211 AC_CANONICAL_BUILD => 0,
5212 AC_CANONICAL_HOST => 0,
5213 AC_CANONICAL_TARGET => 0,
5214 AC_CONFIG_AUX_DIR => 1,
5215 AC_CONFIG_FILES => 1,
5216 AC_CONFIG_HEADERS => 1,
5217 AC_CONFIG_LIBOBJ_DIR => 1,
5218 AC_CONFIG_LINKS => 1,
5222 AC_REQUIRE_AUX_FILE => 1,
5223 AC_SUBST_TRACE => 1,
5224 AM_AUTOMAKE_VERSION => 1,
5225 AM_PROG_MKDIR_P => 0,
5226 AM_CONDITIONAL => 2,
5227 AM_EXTRA_RECURSIVE_TARGETS => 1,
5228 AM_GNU_GETTEXT => 0,
5229 AM_GNU_GETTEXT_INTL_SUBDIR => 0,
5230 AM_INIT_AUTOMAKE => 0,
5231 AM_MAINTAINER_MODE => 0,
5233 _AM_SUBST_NOTMAKE => 1,
5236 _AM_COND_ENDIF => 1,
5237 LT_SUPPORTED_TAG => 1,
5238 _LT_AC_TAGCONFIG => 0,
5244 my $traces = ($ENV{AUTOCONF} || '@am_AUTOCONF@') . " ";
5246 # Use a separator unlikely to be used, not ':', the default, which
5247 # has a precise meaning for AC_CONFIG_FILES and so on.
5248 $traces .= join (' ',
5249 map { "--trace=$_" . ':\$f:\$l::\$d::\$n::\${::}%' }
5252 my $tracefh = new Automake::XFile ("$traces $filename |");
5253 verb "reading $traces";
5258 while ($_ = $tracefh->getline)
5261 my ($here, $depth, @args) = split (/::/);
5262 $where = new Automake::Location $here;
5263 my $macro = $args[0];
5265 prog_error ("unrequested trace '$macro'")
5266 unless exists $traced{$macro};
5268 # Skip and diagnose malformed calls.
5269 if ($#args < $traced{$macro})
5271 msg ('syntax', $where, "not enough arguments for $macro");
5275 # Alphabetical ordering please.
5276 if ($macro eq 'AC_CANONICAL_BUILD')
5278 if ($seen_canonical <= AC_CANONICAL_BUILD)
5280 $seen_canonical = AC_CANONICAL_BUILD;
5283 elsif ($macro eq 'AC_CANONICAL_HOST')
5285 if ($seen_canonical <= AC_CANONICAL_HOST)
5287 $seen_canonical = AC_CANONICAL_HOST;
5290 elsif ($macro eq 'AC_CANONICAL_TARGET')
5292 $seen_canonical = AC_CANONICAL_TARGET;
5294 elsif ($macro eq 'AC_CONFIG_AUX_DIR')
5296 if ($seen_init_automake)
5298 error ($where, "AC_CONFIG_AUX_DIR must be called before "
5299 . "AM_INIT_AUTOMAKE ...", partial => 1);
5300 error ($seen_init_automake, "... AM_INIT_AUTOMAKE called here");
5302 $config_aux_dir = $args[1];
5303 $config_aux_dir_set_in_configure_ac = 1;
5304 check_directory ($config_aux_dir, $where);
5306 elsif ($macro eq 'AC_CONFIG_FILES')
5308 # Look at potential Makefile.am's.
5309 scan_autoconf_config_files ($where, $args[1]);
5311 elsif ($macro eq 'AC_CONFIG_HEADERS')
5313 foreach my $spec (split (' ', $args[1]))
5315 my ($dest, @src) = split (':', $spec);
5316 $ac_config_files_location{$dest} = $where;
5317 push @config_headers, $spec;
5320 elsif ($macro eq 'AC_CONFIG_LIBOBJ_DIR')
5322 $config_libobj_dir = $args[1];
5323 check_directory ($config_libobj_dir, $where);
5325 elsif ($macro eq 'AC_CONFIG_LINKS')
5327 foreach my $spec (split (' ', $args[1]))
5329 my ($dest, $src) = split (':', $spec);
5330 $ac_config_files_location{$dest} = $where;
5331 push @config_links, $spec;
5334 elsif ($macro eq 'AC_FC_SRCEXT')
5336 my $suffix = $args[1];
5337 # These flags are used as %SOURCEFLAG% in depend2.am,
5338 # where the trailing space is important.
5339 $sourceflags{'.' . $suffix} = '$(FCFLAGS_' . $suffix . ') '
5340 if ($suffix eq 'f90' || $suffix eq 'f95' || $suffix eq 'f03' || $suffix eq 'f08');
5342 elsif ($macro eq 'AC_INIT')
5344 if (defined $args[2])
5346 $package_version = $args[2];
5347 $package_version_location = $where;
5350 elsif ($macro eq 'AC_LIBSOURCE')
5352 $libsources{$args[1]} = $here;
5354 elsif ($macro eq 'AC_REQUIRE_AUX_FILE')
5356 # Only remember the first time a file is required.
5357 $required_aux_file{$args[1]} = $where
5358 unless exists $required_aux_file{$args[1]};
5360 elsif ($macro eq 'AC_SUBST_TRACE')
5362 # Just check for alphanumeric in AC_SUBST_TRACE. If you do
5363 # AC_SUBST(5), then too bad.
5364 $configure_vars{$args[1]} = $where
5365 if $args[1] =~ /^\w+$/;
5367 elsif ($macro eq 'AM_AUTOMAKE_VERSION')
5370 "version mismatch. This is Automake $VERSION,\n" .
5371 "but the definition used by this AM_INIT_AUTOMAKE\n" .
5372 "comes from Automake $args[1]. You should recreate\n" .
5373 "aclocal.m4 with aclocal and run automake again.\n",
5374 # $? = 63 is used to indicate version mismatch to missing.
5376 if $VERSION ne $args[1];
5378 $seen_automake_version = 1;
5380 elsif ($macro eq 'AM_PROG_MKDIR_P')
5382 msg 'obsolete', $where, <<'EOF';
5383 The 'AM_PROG_MKDIR_P' macro is deprecated, and its use is discouraged.
5384 You should use the Autoconf-provided 'AC_PROG_MKDIR_P' macro instead,
5385 and use '$(MKDIR_P)' instead of '$(mkdir_p)'in your Makefile.am files.
5388 elsif ($macro eq 'AM_CONDITIONAL')
5390 $configure_cond{$args[1]} = $where;
5392 elsif ($macro eq 'AM_EXTRA_RECURSIVE_TARGETS')
5394 # Empty leading/trailing fields might be produced by split,
5395 # hence the grep is really needed.
5396 push @extra_recursive_targets,
5397 grep (/./, (split /\s+/, $args[1]));
5399 elsif ($macro eq 'AM_GNU_GETTEXT')
5401 $seen_gettext = $where;
5402 $ac_gettext_location = $where;
5403 $seen_gettext_external = grep ($_ eq 'external', @args);
5405 elsif ($macro eq 'AM_GNU_GETTEXT_INTL_SUBDIR')
5407 $seen_gettext_intl = $where;
5409 elsif ($macro eq 'AM_INIT_AUTOMAKE')
5411 $seen_init_automake = $where;
5412 if (defined $args[2])
5414 msg 'obsolete', $where, <<'EOF';
5415 AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:
5416 https://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
5418 $package_version = $args[2];
5419 $package_version_location = $where;
5421 elsif (defined $args[1])
5423 my @opts = split (' ', $args[1]);
5424 @opts = map { { option => $_, where => $where } } @opts;
5425 exit $exit_code unless process_global_option_list (@opts);
5428 elsif ($macro eq 'AM_MAINTAINER_MODE')
5430 $seen_maint_mode = $where;
5432 elsif ($macro eq 'AM_PROG_AR')
5436 elsif ($macro eq '_AM_COND_IF')
5438 cond_stack_if ('', $args[1], $where);
5439 error ($where, "missing m4 quoting, macro depth $depth")
5442 elsif ($macro eq '_AM_COND_ELSE')
5444 cond_stack_else ('!', $args[1], $where);
5445 error ($where, "missing m4 quoting, macro depth $depth")
5448 elsif ($macro eq '_AM_COND_ENDIF')
5450 cond_stack_endif (undef, undef, $where);
5451 error ($where, "missing m4 quoting, macro depth $depth")
5454 elsif ($macro eq '_AM_SUBST_NOTMAKE')
5456 $ignored_configure_vars{$args[1]} = $where;
5458 elsif ($macro eq 'm4_include'
5459 || $macro eq 'm4_sinclude'
5460 || $macro eq 'sinclude')
5462 # Skip missing 'sinclude'd files.
5463 next if $macro ne 'm4_include' && ! -f $args[1];
5465 # Some modified versions of Autoconf don't use
5466 # frozen files. Consequently it's possible that we see all
5467 # m4_include's performed during Autoconf's startup.
5468 # Obviously we don't want to distribute Autoconf's files
5469 # so we skip absolute filenames here.
5470 push @configure_deps, '$(top_srcdir)/' . $args[1]
5471 unless $here =~ m,^(?:\w:)?[\\/],;
5472 # Keep track of the greatest timestamp.
5475 my $mtime = mtime $args[1];
5476 $configure_deps_greatest_timestamp = $mtime
5477 if $mtime > $configure_deps_greatest_timestamp;
5480 elsif ($macro eq 'LT_SUPPORTED_TAG')
5482 $libtool_tags{$args[1]} = 1;
5483 $libtool_new_api = 1;
5485 elsif ($macro eq '_LT_AC_TAGCONFIG')
5487 # _LT_AC_TAGCONFIG is an old macro present in Libtool 1.5.
5488 # We use it to detect whether tags are supported. Our
5489 # preferred interface is LT_SUPPORTED_TAG, but it was
5490 # introduced in Libtool 1.6.
5491 if (0 == keys %libtool_tags)
5493 # Hardcode the tags supported by Libtool 1.5.
5494 %libtool_tags = (CC => 1, CXX => 1, GCJ => 1, F77 => 1);
5499 error ($where, "condition stack not properly closed")
5506 # Check whether we use 'configure.ac' or 'configure.in'.
5507 # Scan it (and possibly 'aclocal.m4') for interesting things.
5508 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
5509 sub scan_autoconf_files ()
5511 # Reinitialize libsources here. This isn't really necessary,
5512 # since we currently assume there is only one configure.ac. But
5513 # that won't always be the case.
5516 # Keep track of the youngest configure dependency.
5517 $configure_deps_greatest_timestamp = mtime $configure_ac;
5518 if (-e 'aclocal.m4')
5520 my $mtime = mtime 'aclocal.m4';
5521 $configure_deps_greatest_timestamp = $mtime
5522 if $mtime > $configure_deps_greatest_timestamp;
5525 scan_autoconf_traces ($configure_ac);
5527 @configure_input_files = sort keys %make_list;
5528 # Set input and output files if not specified by user.
5531 @input_files = @configure_input_files;
5532 %output_files = %make_list;
5536 if (! $seen_init_automake)
5538 err_ac ("no proper invocation of AM_INIT_AUTOMAKE was found.\nYou "
5539 . "should verify that $configure_ac invokes AM_INIT_AUTOMAKE,"
5540 . "\nthat aclocal.m4 is present in the top-level directory,\n"
5541 . "and that aclocal.m4 was recently regenerated "
5542 . "(using aclocal)");
5546 if (! $seen_automake_version)
5548 if (-f 'aclocal.m4')
5550 error ($seen_init_automake,
5551 "your implementation of AM_INIT_AUTOMAKE comes from " .
5552 "an\nold Automake version. You should recreate " .
5553 "aclocal.m4\nwith aclocal and run automake again",
5554 # $? = 63 is used to indicate version mismatch to missing.
5559 error ($seen_init_automake,
5560 "no proper implementation of AM_INIT_AUTOMAKE was " .
5561 "found,\nprobably because aclocal.m4 is missing.\n" .
5562 "You should run aclocal to create this file, then\n" .
5563 "run automake again");
5570 # Look for some files we need. Always check for these. This
5571 # check must be done for every run, even those where we are only
5572 # looking at a subdir Makefile. We must set relative_dir for
5573 # push_required_file to work.
5574 # Sort the files for stable verbose output.
5575 $relative_dir = '.';
5576 foreach my $file (sort keys %required_aux_file)
5578 require_conf_file ($required_aux_file{$file}->get, FOREIGN, $file)
5580 err_am "'install.sh' is an anachronism; use 'install-sh' instead"
5581 if -f $config_aux_dir . '/install.sh';
5583 # Preserve dist_common for later.
5584 @configure_dist_common = @dist_common;
5587 ################################################################
5589 # Do any extra checking for GNU standards.
5590 sub check_gnu_standards ()
5592 if ($relative_dir eq '.')
5594 # In top level (or only) directory.
5595 require_file ("$am_file.am", GNU,
5596 qw/INSTALL NEWS README AUTHORS ChangeLog/);
5598 # Accept one of these three licenses; default to COPYING.
5599 # Make sure we do not overwrite an existing license.
5601 foreach (qw /COPYING COPYING.LIB COPYING.LESSER/)
5609 require_file ("$am_file.am", GNU, 'COPYING')
5613 for my $opt ('no-installman', 'no-installinfo')
5615 msg ('error-gnu', option $opt,
5616 "option '$opt' disallowed by GNU standards")
5621 # Do any extra checking for GNITS standards.
5622 sub check_gnits_standards ()
5624 if ($relative_dir eq '.')
5626 # In top level (or only) directory.
5627 require_file ("$am_file.am", GNITS, 'THANKS');
5631 ################################################################
5633 # Functions to handle files of each language.
5635 # Each 'lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
5636 # simple formula: Return value is LANG_SUBDIR if the resulting object
5637 # file should be in a subdir if the source file is, LANG_PROCESS if
5638 # file is to be dealt with, LANG_IGNORE otherwise.
5640 # Much of the actual processing is handled in
5641 # handle_single_transform. These functions exist so that
5642 # auxiliary information can be recorded for a later cleanup pass.
5643 # Note that the calls to these functions are computed, so don't bother
5644 # searching for their precise names in the source.
5646 # This is just a convenience function that can be used to determine
5647 # when a subdir object should be used.
5650 return option 'subdir-objects' ? LANG_SUBDIR : LANG_PROCESS;
5653 # Rewrite a single header file.
5654 sub lang_header_rewrite
5656 # Header files are simply ignored.
5660 # Rewrite a single Vala source file.
5661 sub lang_vala_rewrite
5663 my ($directory, $base, $ext) = @_;
5665 (my $newext = $ext) =~ s/vala$/c/;
5666 return (LANG_SUBDIR, $newext);
5669 # Rewrite a single yacc/yacc++ file.
5670 sub lang_yacc_rewrite
5672 my ($directory, $base, $ext) = @_;
5674 my $r = lang_sub_obj;
5675 (my $newext = $ext) =~ tr/y/c/;
5676 return ($r, $newext);
5678 sub lang_yaccxx_rewrite { lang_yacc_rewrite (@_); };
5680 # Rewrite a single lex/lex++ file.
5681 sub lang_lex_rewrite
5683 my ($directory, $base, $ext) = @_;
5685 my $r = lang_sub_obj;
5686 (my $newext = $ext) =~ tr/l/c/;
5687 return ($r, $newext);
5689 sub lang_lexxx_rewrite { lang_lex_rewrite (@_); };
5691 # Rewrite a single Java file.
5692 sub lang_java_rewrite
5697 # The lang_X_finish functions are called after all source file
5698 # processing is done. Each should handle defining rules for the
5699 # language, etc. A finish function is only called if a source file of
5700 # the appropriate type has been seen.
5702 sub lang_vala_finish_target
5704 my ($self, $name) = @_;
5706 my $derived = canonicalize ($name);
5707 my $var = var "${derived}_SOURCES";
5710 my @vala_sources = grep { /\.(vala|vapi)$/ } ($var->value_as_list_recursive);
5712 # For automake bug#11229.
5713 return unless @vala_sources;
5715 foreach my $vala_file (@vala_sources)
5717 my $c_file = $vala_file;
5718 if ($c_file =~ s/(.*)\.vala$/$1.c/)
5720 $c_file = "\$(srcdir)/$c_file";
5721 $output_rules .= "$c_file: \$(srcdir)/${derived}_vala.stamp\n"
5722 . "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n"
5723 . "\t\@if test -f \$@; then :; else \\\n"
5724 . "\t \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n"
5726 $clean_files{$c_file} = MAINTAINER_CLEAN;
5730 # Add rebuild rules for generated header and vapi files
5731 my $flags = var ($derived . '_VALAFLAGS');
5735 foreach my $flag ($flags->value_as_list_recursive)
5737 if (grep (/$lastflag/, ('-H', '-h', '--header', '--internal-header',
5738 '--vapi', '--internal-vapi', '--gir')))
5740 my $headerfile = "\$(srcdir)/$flag";
5741 $output_rules .= "$headerfile: \$(srcdir)/${derived}_vala.stamp\n"
5742 . "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n"
5743 . "\t\@if test -f \$@; then :; else \\\n"
5744 . "\t \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n"
5747 # valac is not used when building from dist tarballs
5748 # distribute the generated files
5749 push_dist_common ($headerfile);
5750 $clean_files{$headerfile} = MAINTAINER_CLEAN;
5756 my $compile = $self->compile;
5758 # Rewrite each occurrence of 'AM_VALAFLAGS' in the compile
5759 # rule into '${derived}_VALAFLAGS' if it exists.
5760 my $val = "${derived}_VALAFLAGS";
5761 $compile =~ s/\(AM_VALAFLAGS\)/\($val\)/
5764 # VALAFLAGS is a user variable (per GNU Standards),
5765 # it should not be overridden in the Makefile...
5766 check_user_variables 'VALAFLAGS';
5768 my $dirname = dirname ($name);
5770 # Only generate C code, do not run C compiler
5773 my $verbose = verbose_flag ('VALAC');
5774 my $silent = silent_flag ();
5775 my $stampfile = "\$(srcdir)/${derived}_vala.stamp";
5778 "\$(srcdir)/${derived}_vala.stamp: @vala_sources\n".
5779 # Since the C files generated from the vala sources depend on the
5780 # ${derived}_vala.stamp file, we must ensure its timestamp is older than
5781 # those of the C files generated by the valac invocation below (this is
5782 # especially important on systems with sub-second timestamp resolution).
5783 # Thus we need to create the stamp file *before* invoking valac, and to
5784 # move it to its final location only after valac has been invoked.
5785 "\t${silent}rm -f \$\@ && echo stamp > \$\@-t\n".
5786 "\t${verbose}\$(am__cd) \$(srcdir) && $compile @vala_sources\n".
5787 "\t${silent}mv -f \$\@-t \$\@\n";
5789 push_dist_common ($stampfile);
5791 $clean_files{$stampfile} = MAINTAINER_CLEAN;
5794 # Add output rules to invoke valac and create stamp file as a witness
5795 # to handle multiple outputs. This function is called after all source
5796 # file processing is done.
5797 sub lang_vala_finish ()
5801 foreach my $prog (keys %known_programs)
5803 lang_vala_finish_target ($self, $prog);
5806 while (my ($name) = each %known_libraries)
5808 lang_vala_finish_target ($self, $name);
5812 # The built .c files should be cleaned only on maintainer-clean
5813 # as the .c files are distributed. This function is called for each
5814 # .vala source file.
5815 sub lang_vala_target_hook
5817 my ($self, $aggregate, $output, $input, %transform) = @_;
5819 $clean_files{$output} = MAINTAINER_CLEAN;
5822 # This is a yacc helper which is called whenever we have decided to
5823 # compile a yacc file.
5824 sub lang_yacc_target_hook
5826 my ($self, $aggregate, $output, $input, %transform) = @_;
5828 # If some relevant *YFLAGS variable contains the '-d' flag, we'll
5829 # have to to generate special code.
5830 my $yflags_contains_minus_d = 0;
5832 foreach my $pfx ("", "${aggregate}_")
5834 my $yflagsvar = var ("${pfx}YFLAGS");
5835 next unless $yflagsvar;
5836 # We cannot work reliably with conditionally-defined YFLAGS.
5837 if ($yflagsvar->has_conditional_contents)
5839 msg_var ('unsupported', $yflagsvar,
5840 "'${pfx}YFLAGS' cannot have conditional contents");
5844 $yflags_contains_minus_d = 1
5845 if grep (/^-d$/, $yflagsvar->value_as_list_recursive);
5849 if ($yflags_contains_minus_d)
5851 # Found a '-d' that applies to the compilation of this file.
5852 # Add a dependency for the generated header file, and arrange
5853 # for that file to be included in the distribution.
5855 # The extension of the output file (e.g., '.c' or '.cxx').
5856 # We'll need it to compute the name of the generated header file.
5857 (my $output_ext = basename ($output)) =~ s/.*(\.[^.]+)$/$1/;
5859 # We know that a yacc input should be turned into either a C or
5860 # C++ output file. We depend on this fact (here and in yacc.am),
5861 # so check that it really holds.
5862 my $lang = $languages{$extension_map{$output_ext}};
5863 prog_error "invalid output name '$output' for yacc file '$input'"
5864 if (!$lang || ($lang->name ne 'c' && $lang->name ne 'cxx'));
5866 (my $header_ext = $output_ext) =~ s/c/h/g;
5867 # Quote $output_ext in the regexp, so that dots in it are taken
5868 # as literal dots, not as metacharacters.
5869 (my $header = $output) =~ s/\Q$output_ext\E$/$header_ext/;
5871 foreach my $cond (Automake::Rule::define (${header}, 'internal',
5872 RULE_AUTOMAKE, TRUE,
5875 my $condstr = $cond->subst_string;
5877 "$condstr${header}: $output\n"
5878 # Recover from removal of $header
5879 . "$condstr\t\@if test ! -f \$@; then rm -f $output; else :; fi\n"
5880 . "$condstr\t\@if test ! -f \$@; then \$(MAKE) \$(AM_MAKEFLAGS) $output; else :; fi\n";
5882 # Distribute the generated file, unless its .y source was
5883 # listed in a nodist_ variable. (handle_source_transform()
5884 # will set DIST_SOURCE.)
5885 push_dist_common ($header)
5886 if $transform{'DIST_SOURCE'};
5888 # The GNU rules say that yacc/lex output files should be removed
5889 # by maintainer-clean. However, if the files are not distributed,
5890 # then we want to remove them with "make clean"; otherwise,
5891 # "make distcheck" will fail.
5892 $clean_files{$header} = $transform{'DIST_SOURCE'} ? MAINTAINER_CLEAN : CLEAN;
5894 # See the comment above for $HEADER.
5895 $clean_files{$output} = $transform{'DIST_SOURCE'} ? MAINTAINER_CLEAN : CLEAN;
5898 # This is a lex helper which is called whenever we have decided to
5899 # compile a lex file.
5900 sub lang_lex_target_hook
5902 my ($self, $aggregate, $output, $input, %transform) = @_;
5903 # The GNU rules say that yacc/lex output files should be removed
5904 # by maintainer-clean. However, if the files are not distributed,
5905 # then we want to remove them with "make clean"; otherwise,
5906 # "make distcheck" will fail.
5907 $clean_files{$output} = $transform{'DIST_SOURCE'} ? MAINTAINER_CLEAN : CLEAN;
5910 # This is a helper for both lex and yacc.
5911 sub yacc_lex_finish_helper ()
5913 return if defined $language_scratch{'lex-yacc-done'};
5914 $language_scratch{'lex-yacc-done'} = 1;
5916 # FIXME: for now, no line number.
5917 require_conf_file ($configure_ac, FOREIGN, 'ylwrap');
5918 define_variable ('YLWRAP', "$am_config_aux_dir/ylwrap", INTERNAL);
5921 sub lang_yacc_finish ()
5923 return if defined $language_scratch{'yacc-done'};
5924 $language_scratch{'yacc-done'} = 1;
5926 reject_var 'YACCFLAGS', "'YACCFLAGS' obsolete; use 'YFLAGS' instead";
5928 yacc_lex_finish_helper;
5932 sub lang_lex_finish ()
5934 return if defined $language_scratch{'lex-done'};
5935 $language_scratch{'lex-done'} = 1;
5937 yacc_lex_finish_helper;
5941 # Given a hash table of linker names, pick the name that has the most
5942 # precedence. This is lame, but something has to have global
5943 # knowledge in order to eliminate the conflict. Add more linkers as
5949 foreach my $l (qw(GCJLINK OBJCXXLINK CXXLINK F77LINK FCLINK OBJCLINK UPCLINK))
5951 return $l if defined $linkers{$l};
5956 # Called to indicate that an extension was used.
5960 $extension_seen{$ext} = 1;
5963 # register_language (%ATTRIBUTE)
5964 # ------------------------------
5965 # Register a single language.
5966 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5967 sub register_language
5972 $option{'autodep'} = 'no'
5973 unless defined $option{'autodep'};
5974 $option{'linker'} = ''
5975 unless defined $option{'linker'};
5976 $option{'flags'} = []
5977 unless defined $option{'flags'};
5978 $option{'output_extensions'} = sub { return ( '.$(OBJEXT)', '.lo' ) }
5979 unless defined $option{'output_extensions'};
5980 $option{'nodist_specific'} = 0
5981 unless defined $option{'nodist_specific'};
5983 my $lang = new Automake::Language (%option);
5986 $extension_map{$_} = $lang->name foreach @{$lang->extensions};
5987 $languages{$lang->name} = $lang;
5988 my $link = $lang->linker;
5991 if (exists $link_languages{$link})
5993 prog_error ("'$link' has different definitions in "
5994 . $lang->name . " and " . $link_languages{$link}->name)
5995 if $lang->link ne $link_languages{$link}->link;
5999 $link_languages{$link} = $lang;
6003 # Update the pattern of known extensions.
6004 accept_extensions (@{$lang->extensions});
6006 # Update the suffix rules map.
6007 foreach my $suffix (@{$lang->extensions})
6009 foreach my $dest ($lang->output_extensions->($suffix))
6011 register_suffix_rule (INTERNAL, $suffix, $dest);
6016 # derive_suffix ($EXT, $OBJ)
6017 # --------------------------
6018 # This function is used to find a path from a user-specified suffix $EXT
6019 # to $OBJ or to some other suffix we recognize internally, e.g. 'cc'.
6022 my ($source_ext, $obj) = @_;
6024 while (!$extension_map{$source_ext} && $source_ext ne $obj)
6026 my $new_source_ext = next_in_suffix_chain ($source_ext, $obj);
6027 last if not defined $new_source_ext;
6028 $source_ext = $new_source_ext;
6035 # Pretty-print something and append to '$output_rules'.
6036 sub pretty_print_rule
6038 $output_rules .= makefile_wrap (shift, shift, @_);
6042 ################################################################
6045 ## -------------------------------- ##
6046 ## Handling the conditional stack. ##
6047 ## -------------------------------- ##
6051 # make_conditional_string ($NEGATE, $COND)
6052 # ----------------------------------------
6053 sub make_conditional_string
6055 my ($negate, $cond) = @_;
6056 $cond = "${cond}_TRUE"
6057 unless $cond =~ /^TRUE|FALSE$/;
6058 $cond = Automake::Condition::conditional_negate ($cond)
6064 my %_am_macro_for_cond =
6066 AMDEP => "one of the compiler tests\n"
6067 . " AC_PROG_CC, AC_PROG_CXX, AC_PROG_OBJC, AC_PROG_OBJCXX,\n"
6068 . " AM_PROG_AS, AM_PROG_GCJ, AM_PROG_UPC",
6069 am__fastdepCC => 'AC_PROG_CC',
6070 am__fastdepCCAS => 'AM_PROG_AS',
6071 am__fastdepCXX => 'AC_PROG_CXX',
6072 am__fastdepGCJ => 'AM_PROG_GCJ',
6073 am__fastdepOBJC => 'AC_PROG_OBJC',
6074 am__fastdepOBJCXX => 'AC_PROG_OBJCXX',
6075 am__fastdepUPC => 'AM_PROG_UPC'
6079 # cond_stack_if ($NEGATE, $COND, $WHERE)
6080 # --------------------------------------
6083 my ($negate, $cond, $where) = @_;
6085 if (! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/)
6087 my $text = "$cond does not appear in AM_CONDITIONAL";
6088 my $scope = US_LOCAL;
6089 if (exists $_am_macro_for_cond{$cond})
6091 my $mac = $_am_macro_for_cond{$cond};
6092 $text .= "\n The usual way to define '$cond' is to add ";
6093 $text .= ($mac =~ / /) ? $mac : "'$mac'";
6094 $text .= "\n to '$configure_ac' and run 'aclocal' and 'autoconf' again";
6095 # These warnings appear in Automake files (depend2.am),
6096 # so there is no need to display them more than once:
6099 error $where, $text, uniq_scope => $scope;
6102 push (@cond_stack, make_conditional_string ($negate, $cond));
6104 return new Automake::Condition (@cond_stack);
6109 # cond_stack_else ($NEGATE, $COND, $WHERE)
6110 # ----------------------------------------
6113 my ($negate, $cond, $where) = @_;
6117 error $where, "else without if";
6121 $cond_stack[$#cond_stack] =
6122 Automake::Condition::conditional_negate ($cond_stack[$#cond_stack]);
6124 # If $COND is given, check against it.
6127 $cond = make_conditional_string ($negate, $cond);
6129 error ($where, "else reminder ($negate$cond) incompatible with "
6130 . "current conditional: $cond_stack[$#cond_stack]")
6131 if $cond_stack[$#cond_stack] ne $cond;
6134 return new Automake::Condition (@cond_stack);
6139 # cond_stack_endif ($NEGATE, $COND, $WHERE)
6140 # -----------------------------------------
6141 sub cond_stack_endif
6143 my ($negate, $cond, $where) = @_;
6148 error $where, "endif without if";
6152 # If $COND is given, check against it.
6155 $cond = make_conditional_string ($negate, $cond);
6157 error ($where, "endif reminder ($negate$cond) incompatible with "
6158 . "current conditional: $cond_stack[$#cond_stack]")
6159 if $cond_stack[$#cond_stack] ne $cond;
6164 return new Automake::Condition (@cond_stack);
6171 ## ------------------------ ##
6172 ## Handling the variables. ##
6173 ## ------------------------ ##
6176 # define_pretty_variable ($VAR, $COND, $WHERE, @VALUE)
6177 # ----------------------------------------------------
6178 # Like define_variable, but the value is a list, and the variable may
6179 # be defined conditionally. The second argument is the condition
6180 # under which the value should be defined; this should be the empty
6181 # string to define the variable unconditionally. The third argument
6182 # is a list holding the values to use for the variable. The value is
6183 # pretty printed in the output file.
6184 sub define_pretty_variable
6186 my ($var, $cond, $where, @value) = @_;
6188 if (! vardef ($var, $cond))
6190 Automake::Variable::define ($var, VAR_AUTOMAKE, '', $cond, "@value",
6191 '', $where, VAR_PRETTY);
6192 rvar ($var)->rdef ($cond)->set_seen;
6197 # define_variable ($VAR, $VALUE, $WHERE)
6198 # --------------------------------------
6199 # Define a new Automake Makefile variable VAR to VALUE, but only if
6200 # not already defined.
6203 my ($var, $value, $where) = @_;
6204 define_pretty_variable ($var, TRUE, $where, $value);
6208 # define_files_variable ($VAR, \@BASENAME, $EXTENSION, $WHERE)
6209 # ------------------------------------------------------------
6210 # Define the $VAR which content is the list of file names composed of
6211 # a @BASENAME and the $EXTENSION.
6212 sub define_files_variable ($\@$$)
6214 my ($var, $basename, $extension, $where) = @_;
6215 define_variable ($var,
6216 join (' ', map { "$_.$extension" } @$basename),
6221 # Like define_variable, but define a variable to be the configure
6222 # substitution by the same name.
6223 sub define_configure_variable
6226 # Some variables we do not want to output. For instance it
6227 # would be a bad idea to output `U = @U@` when `@U@` can be
6228 # substituted as `\`.
6229 my $pretty = exists $ignored_configure_vars{$var} ? VAR_SILENT : VAR_ASIS;
6230 Automake::Variable::define ($var, VAR_CONFIGURE, '', TRUE, subst ($var),
6231 '', $configure_vars{$var}, $pretty);
6235 # define_compiler_variable ($LANG)
6236 # --------------------------------
6237 # Define a compiler variable. We also handle defining the 'LT'
6238 # version of the command when using libtool.
6239 sub define_compiler_variable
6243 my ($var, $value) = ($lang->compiler, $lang->compile);
6244 my $libtool_tag = '';
6245 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
6246 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
6247 define_variable ($var, $value, INTERNAL);
6248 if (var ('LIBTOOL'))
6250 my $verbose = define_verbose_libtool ();
6251 define_variable ("LT$var",
6252 "\$(LIBTOOL) $verbose $libtool_tag\$(AM_LIBTOOLFLAGS)"
6253 . " \$(LIBTOOLFLAGS) --mode=compile $value",
6256 define_verbose_tagvar ($lang->ccer || 'GEN');
6260 sub define_linker_variable
6264 my $libtool_tag = '';
6265 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
6266 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
6268 define_variable ($lang->lder, $lang->ld, INTERNAL);
6269 # CCLINK = $(CCLD) blah blah...
6271 if (var ('LIBTOOL'))
6273 my $verbose = define_verbose_libtool ();
6274 $link = "\$(LIBTOOL) $verbose $libtool_tag\$(AM_LIBTOOLFLAGS) "
6275 . "\$(LIBTOOLFLAGS) --mode=link ";
6277 define_variable ($lang->linker, $link . $lang->link, INTERNAL);
6278 define_variable ($lang->compiler, $lang, INTERNAL);
6279 define_verbose_tagvar ($lang->lder || 'GEN');
6282 sub define_per_target_linker_variable
6284 my ($linker, $target) = @_;
6286 # If the user wrote a custom link command, we don't define ours.
6287 return "${target}_LINK"
6288 if set_seen "${target}_LINK";
6290 my $xlink = $linker ? $linker : 'LINK';
6292 my $lang = $link_languages{$xlink};
6293 prog_error "Unknown language for linker variable '$xlink'"
6296 my $link_command = $lang->link;
6299 my $libtool_tag = '';
6300 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
6301 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
6303 my $verbose = define_verbose_libtool ();
6305 "\$(LIBTOOL) $verbose $libtool_tag\$(AM_LIBTOOLFLAGS) \$(LIBTOOLFLAGS) "
6306 . "--mode=link " . $link_command;
6309 # Rewrite each occurrence of 'AM_$flag' in the link
6310 # command into '${derived}_$flag' if it exists.
6311 my $orig_command = $link_command;
6312 my @flags = (@{$lang->flags}, 'LDFLAGS');
6313 push @flags, 'LIBTOOLFLAGS' if var 'LIBTOOL';
6314 for my $flag (@flags)
6316 my $val = "${target}_$flag";
6317 $link_command =~ s/\(AM_$flag\)/\($val\)/
6321 # If the computed command is the same as the generic command, use
6322 # the command linker variable.
6323 return ($lang->linker, $lang->lder)
6324 if $link_command eq $orig_command;
6326 define_variable ("${target}_LINK", $link_command, INTERNAL);
6327 return ("${target}_LINK", $lang->lder);
6330 ################################################################
6332 # check_trailing_slash ($WHERE, $LINE)
6333 # ------------------------------------
6334 # Return 1 iff $LINE ends with a slash.
6335 # Might modify $LINE.
6336 sub check_trailing_slash ($\$)
6338 my ($where, $line) = @_;
6340 # Ignore '##' lines.
6341 return 0 if $$line =~ /$IGNORE_PATTERN/o;
6343 # Catch and fix a common error.
6344 msg "syntax", $where, "whitespace following trailing backslash"
6345 if $$line =~ s/\\\s+\n$/\\\n/;
6347 return $$line =~ /\\$/;
6351 # read_am_file ($AMFILE, $WHERE, $RELDIR)
6352 # ---------------------------------------
6353 # Read $AMFILE file name which is located in $RELDIR, and set up
6354 # global variables resetted by '&generate_makefile'. Simultaneously
6355 # copy lines from $AMFILE into '$output_trailer', or define variables
6358 # NOTE: We put rules in the trailer section. We want user rules to
6359 # come after our generated stuff.
6362 my ($amfile, $where, $reldir) = @_;
6363 my $canon_reldir = &canonicalize ($reldir);
6365 my $am_file = new Automake::XFile ("< $amfile");
6366 verb "reading $amfile";
6368 # Keep track of the youngest output dependency.
6369 my $mtime = mtime $amfile;
6370 $output_deps_greatest_timestamp = $mtime
6371 if $mtime > $output_deps_greatest_timestamp;
6377 my $var_look = VAR_ASIS;
6379 use constant IN_VAR_DEF => 0;
6380 use constant IN_RULE_DEF => 1;
6381 use constant IN_COMMENT => 2;
6382 my $prev_state = IN_RULE_DEF;
6384 while ($_ = $am_file->getline)
6386 $where->set ("$amfile:$.");
6387 if (/$IGNORE_PATTERN/o)
6389 # Merely delete comments beginning with two hashes.
6391 elsif (/$WHITE_PATTERN/o)
6393 error $where, "blank line following trailing backslash"
6395 # Stick a single white line before the incoming macro or rule.
6398 # Flush all comments seen so far.
6401 $output_vars .= $comment;
6405 elsif (/$COMMENT_PATTERN/o)
6407 # Stick comments before the incoming macro or rule. Make
6408 # sure a blank line precedes the first block of comments.
6409 $spacing = "\n" unless $blank;
6411 $comment .= $spacing . $_;
6413 $prev_state = IN_COMMENT;
6419 $saw_bk = check_trailing_slash ($where, $_);
6422 # We save the conditional stack on entry, and then check to make
6423 # sure it is the same on exit. This lets us conditionally include
6425 my @saved_cond_stack = @cond_stack;
6426 my $cond = new Automake::Condition (@cond_stack);
6428 my $last_var_name = '';
6429 my $last_var_type = '';
6430 my $last_var_value = '';
6432 # FIXME: shouldn't use $_ in this loop; it is too big.
6435 $where->set ("$amfile:$.");
6437 # Make sure the line is \n-terminated.
6441 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
6442 # used by users. @MAINT@ is an anachronism now.
6443 $_ =~ s/\@MAINT\@//g
6444 unless $seen_maint_mode;
6446 my $new_saw_bk = check_trailing_slash ($where, $_);
6450 # If present, eat the following '_' or '/', converting
6451 # "%reldir%/foo" and "%canon_reldir%_foo" into plain "foo"
6452 # when $reldir is '.'.
6453 $_ =~ s,%(D|reldir)%/,,g;
6454 $_ =~ s,%(C|canon_reldir)%_,,g;
6456 $_ =~ s/%(D|reldir)%/${reldir}/g;
6457 $_ =~ s/%(C|canon_reldir)%/${canon_reldir}/g;
6459 if (/$IGNORE_PATTERN/o)
6461 # Merely delete comments beginning with two hashes.
6463 # Keep any backslash from the previous line.
6464 $new_saw_bk = $saw_bk;
6466 elsif (/$WHITE_PATTERN/o)
6468 # Stick a single white line before the incoming macro or rule.
6470 error $where, "blank line following trailing backslash"
6473 elsif (/$COMMENT_PATTERN/o)
6475 error $where, "comment following trailing backslash"
6476 if $saw_bk && $prev_state != IN_COMMENT;
6478 # Stick comments before the incoming macro or rule.
6479 $comment .= $spacing . $_;
6481 $prev_state = IN_COMMENT;
6485 if ($prev_state == IN_RULE_DEF)
6487 my $cond = new Automake::Condition @cond_stack;
6488 $output_trailer .= $cond->subst_string;
6489 $output_trailer .= $_;
6491 elsif ($prev_state == IN_COMMENT)
6493 # If the line doesn't start with a '#', add it.
6494 # We do this because a continued comment like
6498 # is not portable. BSD make doesn't honor
6499 # escaped newlines in comments.
6501 $comment .= $spacing . $_;
6503 else # $prev_state == IN_VAR_DEF
6505 $last_var_value .= ' '
6506 unless $last_var_value =~ /\s$/;
6507 $last_var_value .= $_;
6511 Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
6512 $last_var_type, $cond,
6513 $last_var_value, $comment,
6514 $last_where, VAR_ASIS)
6516 $comment = $spacing = '';
6521 elsif (/$IF_PATTERN/o)
6523 $cond = cond_stack_if ($1, $2, $where);
6525 elsif (/$ELSE_PATTERN/o)
6527 $cond = cond_stack_else ($1, $2, $where);
6529 elsif (/$ENDIF_PATTERN/o)
6531 $cond = cond_stack_endif ($1, $2, $where);
6534 elsif (/$RULE_PATTERN/o)
6537 $prev_state = IN_RULE_DEF;
6539 # For now we have to output all definitions of user rules
6540 # and can't diagnose duplicates (see the comment in
6541 # Automake::Rule::define). So we go on and ignore the return value.
6542 Automake::Rule::define ($1, $amfile, RULE_USER, $cond, $where);
6544 check_variable_expansions ($_, $where);
6546 $output_trailer .= $comment . $spacing;
6547 my $cond = new Automake::Condition @cond_stack;
6548 $output_trailer .= $cond->subst_string;
6549 $output_trailer .= $_;
6550 $comment = $spacing = '';
6552 elsif (/$ASSIGNMENT_PATTERN/o)
6554 # Found a macro definition.
6555 $prev_state = IN_VAR_DEF;
6556 $last_var_name = $1;
6557 $last_var_type = $2;
6558 $last_var_value = $3;
6559 $last_where = $where->clone;
6560 if ($3 ne '' && substr ($3, -1) eq "\\")
6562 # We preserve the '\' because otherwise the long lines
6563 # that are generated will be truncated by broken
6565 $last_var_value = $3 . "\n";
6567 # Normally we try to output variable definitions in the
6568 # same format they were input. However, POSIX compliant
6569 # systems are not required to support lines longer than
6570 # 2048 bytes (most notably, some sed implementation are
6571 # limited to 4000 bytes, and sed is used by config.status
6572 # to rewrite Makefile.in into Makefile). Moreover nobody
6573 # would really write such long lines by hand since it is
6574 # hardly maintainable. So if a line is longer that 1000
6575 # bytes (an arbitrary limit), assume it has been
6576 # automatically generated by some tools, and flatten the
6577 # variable definition. Otherwise, keep the variable as it
6579 $var_look = VAR_PRETTY if length ($last_var_value) >= 1000;
6583 Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
6584 $last_var_type, $cond,
6585 $last_var_value, $comment,
6586 $last_where, $var_look)
6588 $comment = $spacing = '';
6589 $var_look = VAR_ASIS;
6592 elsif (/$INCLUDE_PATTERN/o)
6596 if ($path =~ s/^\$\(top_srcdir\)\///)
6598 push (@include_stack, "\$\(top_srcdir\)/$path");
6599 # Distribute any included file.
6601 # Always use the $(top_srcdir) prefix in DIST_COMMON,
6602 # otherwise OSF make will implicitly copy the included
6603 # file in the build tree during "make distdir" to satisfy
6605 # (subdir-am-cond.sh and subdir-ac-cond.sh will fail)
6606 push_dist_common ("\$\(top_srcdir\)/$path");
6610 $path =~ s/\$\(srcdir\)\///;
6611 push (@include_stack, "\$\(srcdir\)/$path");
6612 # Always use the $(srcdir) prefix in DIST_COMMON,
6613 # otherwise OSF make will implicitly copy the included
6614 # file in the build tree during "make distdir" to satisfy
6616 # (subdir-am-cond.sh and subdir-ac-cond.sh will fail)
6617 push_dist_common ("\$\(srcdir\)/$path");
6618 $path = $relative_dir . "/" . $path if $relative_dir ne '.';
6620 my $new_reldir = File::Spec->abs2rel ($path, $relative_dir);
6621 $new_reldir = '.' if $new_reldir !~ s,/[^/]*$,,;
6622 $where->push_context ("'$path' included from here");
6623 read_am_file ($path, $where, $new_reldir);
6624 $where->pop_context;
6628 # This isn't an error; it is probably a continued rule.
6629 # In fact, this is what we assume.
6630 $prev_state = IN_RULE_DEF;
6631 check_variable_expansions ($_, $where);
6632 $output_trailer .= $comment . $spacing;
6633 my $cond = new Automake::Condition @cond_stack;
6634 $output_trailer .= $cond->subst_string;
6635 $output_trailer .= $_;
6636 $comment = $spacing = '';
6637 error $where, "'#' comment at start of rule is unportable"
6638 if $_ =~ /^\t\s*\#/;
6641 $saw_bk = $new_saw_bk;
6642 $_ = $am_file->getline;
6645 $output_trailer .= $comment;
6647 error ($where, "trailing backslash on last line")
6650 error ($where, (@cond_stack ? "unterminated conditionals: @cond_stack"
6651 : "too many conditionals closed in include file"))
6652 if "@saved_cond_stack" ne "@cond_stack";
6656 # A helper for read_main_am_file which initializes configure variables
6657 # and variables from header-vars.am.
6658 sub define_standard_variables ()
6660 my $saved_output_vars = $output_vars;
6661 my ($comments, undef, $rules) =
6662 file_contents_internal (1, "$libdir/am/header-vars.am",
6663 new Automake::Location);
6665 foreach my $var (sort keys %configure_vars)
6667 define_configure_variable ($var);
6670 $output_vars .= $comments . $rules;
6674 # read_main_am_file ($MAKEFILE_AM, $MAKEFILE_IN)
6675 # ----------------------------------------------
6676 sub read_main_am_file
6678 my ($amfile, $infile) = @_;
6680 # This supports the strange variable tricks we are about to play.
6681 prog_error ("variable defined before read_main_am_file\n" . variables_dump ())
6682 if (scalar (variables) > 0);
6684 # Generate copyright header for generated Makefile.in.
6685 # We do discard the output of predefined variables, handled below.
6686 $output_vars = ("# " . basename ($infile) . " generated by automake "
6687 . $VERSION . " from " . basename ($amfile) . ".\n");
6688 $output_vars .= '# ' . subst ('configure_input') . "\n";
6689 $output_vars .= $gen_copyright;
6691 # We want to predefine as many variables as possible. This lets
6692 # the user set them with '+=' in Makefile.am.
6693 define_standard_variables;
6695 # Read user file, which might override some of our values.
6696 read_am_file ($amfile, new Automake::Location, '.');
6701 ################################################################
6704 # flatten ($ORIGINAL_STRING)
6705 # --------------------------
6719 # transform_token ($TOKEN, \%PAIRS, $KEY)
6720 # ---------------------------------------
6721 # Return the value associated to $KEY in %PAIRS, as used on $TOKEN
6722 # (which should be ?KEY? or any of the special %% requests)..
6723 sub transform_token ($\%$)
6725 my ($token, $transform, $key) = @_;
6726 my $res = $transform->{$key};
6727 prog_error "Unknown key '$key' in '$token'" unless defined $res;
6732 # transform ($TOKEN, \%PAIRS)
6733 # ---------------------------
6734 # If ($TOKEN, $VAL) is in %PAIRS:
6735 # - replaces %KEY% with $VAL,
6736 # - enables/disables ?KEY? and ?!KEY?,
6737 # - replaces %?KEY% with TRUE or FALSE.
6740 my ($token, $transform) = @_;
6743 # Must be before the following pattern to exclude the case
6744 # when there is neither IFTRUE nor IFFALSE.
6745 if ($token =~ /^%([\w\-]+)%$/)
6747 return transform_token ($token, %$transform, $1);
6750 elsif ($token =~ /^%\?([\w\-]+)%$/)
6752 return transform_token ($token, %$transform, $1) ? 'TRUE' : 'FALSE';
6755 elsif ($token =~ /^ \? (!?) ([\w\-]+) \? $/x)
6757 my $neg = ($1 eq '!') ? 1 : 0;
6758 my $val = transform_token ($token, %$transform, $2);
6759 return (!!$val == $neg) ? '##%' : '';
6763 prog_error "Unknown request format: $token";
6768 # preprocess_file ($MAKEFILE, [%TRANSFORM])
6769 # -----------------------------------------
6770 # Load a $MAKEFILE, apply the %TRANSFORM, and return the result.
6771 # No extra parsing or post-processing is done (i.e., recognition of
6772 # rules declaration or of make variables definitions).
6775 my ($file, %transform) = @_;
6777 # Complete %transform with global options.
6778 # Note that %transform goes last, so it overrides global options.
6779 %transform = ( 'MAINTAINER-MODE'
6780 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
6782 'XZ' => !! option 'dist-xz',
6783 'LZIP' => !! option 'dist-lzip',
6784 'BZIP2' => !! option 'dist-bzip2',
6785 'COMPRESS' => !! option 'dist-tarZ',
6786 'GZIP' => ! option 'no-dist-gzip',
6787 'SHAR' => !! option 'dist-shar',
6788 'ZIP' => !! option 'dist-zip',
6790 'INSTALL-INFO' => ! option 'no-installinfo',
6791 'INSTALL-MAN' => ! option 'no-installman',
6792 'CK-NEWS' => !! option 'check-news',
6794 'SUBDIRS' => !! var ('SUBDIRS'),
6795 'TOPDIR_P' => $relative_dir eq '.',
6797 'BUILD' => ($seen_canonical >= AC_CANONICAL_BUILD),
6798 'HOST' => ($seen_canonical >= AC_CANONICAL_HOST),
6799 'TARGET' => ($seen_canonical >= AC_CANONICAL_TARGET),
6801 'LIBTOOL' => !! var ('LIBTOOL'),
6805 if (! defined ($_ = $am_file_cache{$file}))
6807 verb "reading $file";
6808 # Swallow the whole file.
6809 my $fc_file = new Automake::XFile "< $file";
6810 my $saved_dollar_slash = $/;
6812 $_ = $fc_file->getline;
6813 $/ = $saved_dollar_slash;
6815 # Remove ##-comments.
6816 # Besides we don't need more than two consecutive new-lines.
6817 s/(?:$IGNORE_PATTERN|(?<=\n\n)\n+)//gom;
6818 # Remember the contents of the just-read file.
6819 $am_file_cache{$file} = $_;
6822 # Substitute Automake template tokens.
6823 s/(?: % \?? [\w\-]+ %
6825 )/transform($&, %transform)/gex;
6826 # transform() may have added some ##%-comments to strip.
6827 # (we use '##%' instead of '##' so we can distinguish ##%##%##% from
6828 # ####### and do not remove the latter.)
6829 s/^[ \t]*(?:##%)+.*\n//gm;
6836 # make_paragraphs ($MAKEFILE, [%TRANSFORM])
6837 # -----------------------------------------
6838 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6842 my ($file, %transform) = @_;
6843 $transform{FIRST} = !$transformed_files{$file};
6844 $transformed_files{$file} = 1;
6846 my @lines = split /(?<!\\)\n/, preprocess_file ($file, %transform);
6849 while (defined ($_ = shift @lines))
6852 # If we are a rule, eat as long as we start with a tab.
6853 if (/$RULE_PATTERN/smo)
6855 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
6857 $paragraph .= "\n$_";
6859 unshift (@lines, $_);
6862 # If we are a comments, eat as much comments as you can.
6863 elsif (/$COMMENT_PATTERN/smo)
6865 while (defined ($_ = shift @lines)
6866 && $_ =~ /$COMMENT_PATTERN/smo)
6868 $paragraph .= "\n$_";
6870 unshift (@lines, $_);
6873 push @res, $paragraph;
6881 # ($COMMENT, $VARIABLES, $RULES)
6882 # file_contents_internal ($IS_AM, $FILE, $WHERE, [%TRANSFORM])
6883 # ------------------------------------------------------------
6884 # Return contents of a file from $libdir/am, automatically skipping
6885 # macros or rules which are already known. $IS_AM iff the caller is
6886 # reading an Automake file (as opposed to the user's Makefile.am).
6887 sub file_contents_internal
6889 my ($is_am, $file, $where, %transform) = @_;
6891 $where->set ($file);
6893 my $result_vars = '';
6894 my $result_rules = '';
6898 # The following flags are used to track rules spanning across
6899 # multiple paragraphs.
6900 my $is_rule = 0; # 1 if we are processing a rule.
6901 my $discard_rule = 0; # 1 if the current rule should not be output.
6903 # We save the conditional stack on entry, and then check to make
6904 # sure it is the same on exit. This lets us conditionally include
6906 my @saved_cond_stack = @cond_stack;
6907 my $cond = new Automake::Condition (@cond_stack);
6909 foreach (make_paragraphs ($file, %transform))
6911 # FIXME: no line number available.
6912 $where->set ($file);
6915 error $where, "blank line following trailing backslash:\n$_"
6917 error $where, "comment following trailing backslash:\n$_"
6923 # Stick empty line before the incoming macro or rule.
6926 elsif (/$COMMENT_PATTERN/mso)
6929 # Stick comments before the incoming macro or rule.
6933 # Handle inclusion of other files.
6934 elsif (/$INCLUDE_PATTERN/o)
6938 my $file = ($is_am ? "$libdir/am/" : '') . $1;
6939 $where->push_context ("'$file' included from here");
6941 my ($com, $vars, $rules)
6942 = file_contents_internal ($is_am, $file, $where, %transform);
6943 $where->pop_context;
6945 $result_vars .= $vars;
6946 $result_rules .= $rules;
6950 # Handling the conditionals.
6951 elsif (/$IF_PATTERN/o)
6953 $cond = cond_stack_if ($1, $2, $file);
6955 elsif (/$ELSE_PATTERN/o)
6957 $cond = cond_stack_else ($1, $2, $file);
6959 elsif (/$ENDIF_PATTERN/o)
6961 $cond = cond_stack_endif ($1, $2, $file);
6965 elsif (/$RULE_PATTERN/mso)
6969 # Separate relationship from optional actions: the first
6970 # `new-line tab" not preceded by backslash (continuation
6973 /^(.*?)(?:(?<!\\)\n(\t.*))?$/s;
6974 my ($relationship, $actions) = ($1, $2 || '');
6976 # Separate targets from dependencies: the first colon.
6977 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
6978 my ($targets, $dependencies) = ($1, $2);
6979 # Remove the escaped new lines.
6980 # I don't know why, but I have to use a tmp $flat_deps.
6981 my $flat_deps = flatten ($dependencies);
6982 my @deps = split (' ', $flat_deps);
6984 foreach (split (' ', $targets))
6986 # FIXME: 1. We are not robust to people defining several targets
6987 # at once, only some of them being in %dependencies. The
6988 # actions from the targets in %dependencies are usually generated
6989 # from the content of %actions, but if some targets in $targets
6990 # are not in %dependencies the ELSE branch will output
6991 # a rule for all $targets (i.e. the targets which are both
6992 # in %dependencies and $targets will have two rules).
6994 # FIXME: 2. The logic here is not able to output a
6995 # multi-paragraph rule several time (e.g. for each condition
6996 # it is defined for) because it only knows the first paragraph.
6998 # FIXME: 3. We are not robust to people defining a subset
6999 # of a previously defined "multiple-target" rule. E.g.
7000 # 'foo:' after 'foo bar:'.
7002 # Output only if not in FALSE.
7003 if (defined $dependencies{$_} && $cond != FALSE)
7006 register_action ($_, $actions);
7010 # Free-lance dependency. Output the rule for all the
7011 # targets instead of one by one.
7012 my @undefined_conds =
7013 Automake::Rule::define ($targets, $file,
7014 $is_am ? RULE_AUTOMAKE : RULE_USER,
7016 for my $undefined_cond (@undefined_conds)
7018 my $condparagraph = $paragraph;
7019 $condparagraph =~ s/^/$undefined_cond->subst_string/gme;
7020 $result_rules .= "$spacing$comment$condparagraph\n";
7022 if (scalar @undefined_conds == 0)
7024 # Remember to discard next paragraphs
7025 # if they belong to this rule.
7026 # (but see also FIXME: #2 above.)
7029 $comment = $spacing = '';
7035 elsif (/$ASSIGNMENT_PATTERN/mso)
7037 my ($var, $type, $val) = ($1, $2, $3);
7038 error $where, "variable '$var' with trailing backslash"
7043 Automake::Variable::define ($var,
7044 $is_am ? VAR_AUTOMAKE : VAR_MAKEFILE,
7045 $type, $cond, $val, $comment, $where,
7049 $comment = $spacing = '';
7053 # This isn't an error; it is probably some tokens which
7054 # configure is supposed to replace, such as '@SET-MAKE@',
7055 # or some part of a rule cut by an if/endif.
7056 if (! $cond->false && ! ($is_rule && $discard_rule))
7058 s/^/$cond->subst_string/gme;
7059 $result_rules .= "$spacing$comment$_\n";
7061 $comment = $spacing = '';
7065 error ($where, @cond_stack ?
7066 "unterminated conditionals: @cond_stack" :
7067 "too many conditionals closed in include file")
7068 if "@saved_cond_stack" ne "@cond_stack";
7070 return ($comment, $result_vars, $result_rules);
7075 # file_contents ($BASENAME, $WHERE, [%TRANSFORM])
7076 # -----------------------------------------------
7077 # Return contents of a file from $libdir/am, automatically skipping
7078 # macros or rules which are already known.
7081 my ($basename, $where, %transform) = @_;
7082 my ($comments, $variables, $rules) =
7083 file_contents_internal (1, "$libdir/am/$basename.am", $where,
7085 return "$comments$variables$rules";
7090 # am_primary_prefixes ($PRIMARY, $CAN_DIST, @PREFIXES)
7091 # ----------------------------------------------------
7092 # Find all variable prefixes that are used for install directories. A
7093 # prefix 'zar' qualifies iff:
7095 # * 'zardir' is a variable.
7096 # * 'zar_PRIMARY' is a variable.
7098 # As a side effect, it looks for misspellings. It is an error to have
7099 # a variable ending in a "reserved" suffix whose prefix is unknown, e.g.
7100 # "bni_PROGRAMS". However, unusual prefixes are allowed if a variable
7101 # of the same name (with "dir" appended) exists. For instance, if the
7102 # variable "zardir" is defined, then "zar_PROGRAMS" becomes valid.
7103 # This is to provide a little extra flexibility in those cases which
7105 sub am_primary_prefixes
7107 my ($primary, $can_dist, @prefixes) = @_;
7110 my %valid = map { $_ => 0 } @prefixes;
7111 $valid{'EXTRA'} = 0;
7112 foreach my $var (variables $primary)
7114 # Automake is allowed to define variables that look like primaries
7115 # but which aren't. E.g. INSTALL_sh_DATA.
7116 # Autoconf can also define variables like INSTALL_DATA, so
7117 # ignore all configure variables (at least those which are not
7118 # redefined in Makefile.am).
7119 # FIXME: We should make sure that these variables are not
7120 # conditionally defined (or else adjust the condition below).
7121 my $def = $var->def (TRUE);
7122 next if $def && $def->owner != VAR_MAKEFILE;
7124 my $varname = $var->name;
7126 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_[[:alnum:]]+$/)
7128 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
7129 if ($dist ne '' && ! $can_dist)
7132 "invalid variable '$varname': 'dist' is forbidden");
7134 # Standard directories must be explicitly allowed.
7135 elsif (! defined $valid{$X} && exists $standard_prefix{$X})
7138 "'${X}dir' is not a legitimate directory " .
7141 # A not explicitly valid directory is allowed if Xdir is defined.
7142 elsif (! defined $valid{$X} &&
7143 $var->requires_variables ("'$varname' is used", "${X}dir"))
7145 # Nothing to do. Any error message has been output
7146 # by $var->requires_variables.
7150 # Ensure all extended prefixes are actually used.
7151 $valid{"$base$dist$X"} = 1;
7156 prog_error "unexpected variable name: $varname";
7160 # Return only those which are actually defined.
7161 return sort grep { var ($_ . '_' . $primary) } keys %valid;
7165 # am_install_var (-OPTION..., file, HOW, where...)
7166 # ------------------------------------------------
7168 # Handle 'where_HOW' variable magic. Does all lookups, generates
7169 # install code, and possibly generates code to define the primary
7170 # variable. The first argument is the name of the .am file to munge,
7171 # the second argument is the primary variable (e.g. HEADERS), and all
7172 # subsequent arguments are possible installation locations.
7174 # Returns list of [$location, $value] pairs, where
7175 # $value's are the values in all where_HOW variable, and $location
7176 # there associated location (the place here their parent variables were
7179 # FIXME: this should be rewritten to be cleaner. It should be broken
7180 # up into multiple functions.
7188 my $default_dist = 0;
7191 if ($args[0] eq '-noextra')
7195 elsif ($args[0] eq '-candist')
7199 elsif ($args[0] eq '-defaultdist')
7204 elsif ($args[0] !~ /^-/)
7211 my ($file, $primary, @prefix) = @args;
7213 # Now that configure substitutions are allowed in where_HOW
7214 # variables, it is an error to actually define the primary. We
7215 # allow 'JAVA', as it is customarily used to mean the Java
7216 # interpreter. This is but one of several Java hacks. Similarly,
7217 # 'PYTHON' is customarily used to mean the Python interpreter.
7218 reject_var $primary, "'$primary' is an anachronism"
7219 unless $primary eq 'JAVA' || $primary eq 'PYTHON';
7221 # Get the prefixes which are valid and actually used.
7222 @prefix = am_primary_prefixes ($primary, $can_dist, @prefix);
7224 # If a primary includes a configure substitution, then the EXTRA_
7225 # form is required. Otherwise we can't properly do our job.
7231 foreach my $X (@prefix)
7233 my $nodir_name = $X;
7234 my $one_name = $X . '_' . $primary;
7235 my $one_var = var $one_name;
7237 my $strip_subdir = 1;
7238 # If subdir prefix should be preserved, do so.
7239 if ($nodir_name =~ /^nobase_/)
7242 $nodir_name =~ s/^nobase_//;
7245 # If files should be distributed, do so.
7249 $dist_p = (($default_dist && $nodir_name !~ /^nodist_/)
7250 || (! $default_dist && $nodir_name =~ /^dist_/));
7251 $nodir_name =~ s/^(dist|nodist)_//;
7255 # Use the location of the currently processed variable.
7256 # We are not processing a particular condition, so pick the first
7258 my $tmpcond = $one_var->conditions->one_cond;
7259 my $where = $one_var->rdef ($tmpcond)->location->clone;
7261 # Append actual contents of where_PRIMARY variable to
7262 # @result, skipping @substitutions@.
7263 foreach my $locvals ($one_var->value_as_list_recursive (location => 1))
7265 my ($loc, $value) = @$locvals;
7266 # Skip configure substitutions.
7267 if ($value =~ /^\@.*\@$/)
7269 if ($nodir_name eq 'EXTRA')
7272 "'$one_name' contains configure substitution, "
7275 # Check here to make sure variables defined in
7276 # configure.ac do not imply that EXTRA_PRIMARY
7278 elsif (! defined $configure_vars{$one_name})
7280 $require_extra = $one_name
7286 # Strip any $(EXEEXT) suffix the user might have added,
7287 # or this will confuse handle_source_transform() and
7288 # check_canonical_spelling().
7289 # We'll add $(EXEEXT) back later anyway.
7290 # Do it here rather than in handle_programs so the
7291 # uniquifying at the end of this function works.
7292 ${$locvals}[1] =~ s/\$\(EXEEXT\)$//
7293 if $primary eq 'PROGRAMS';
7295 push (@result, $locvals);
7298 # A blatant hack: we rewrite each _PROGRAMS primary to include
7300 append_exeext { 1 } $one_name
7301 if $primary eq 'PROGRAMS';
7302 # "EXTRA" shouldn't be used when generating clean targets,
7303 # all, or install targets. We used to warn if EXTRA_FOO was
7304 # defined uselessly, but this was annoying.
7306 if $nodir_name eq 'EXTRA';
7308 if ($nodir_name eq 'check')
7310 push (@check, '$(' . $one_name . ')');
7314 push (@used, '$(' . $one_name . ')');
7317 # Is this to be installed?
7318 my $install_p = $nodir_name ne 'noinst' && $nodir_name ne 'check';
7320 # If so, with install-exec? (or install-data?).
7321 my $exec_p = ($nodir_name =~ /$EXEC_DIR_PATTERN/o);
7323 my $check_options_p = $install_p && !! option 'std-options';
7325 # Use the location of the currently processed variable as context.
7326 $where->push_context ("while processing '$one_name'");
7328 # The variable containing all files to distribute.
7329 my $distvar = "\$($one_name)";
7330 $distvar = shadow_unconditionally ($one_name, $where)
7331 if ($dist_p && $one_var->has_conditional_contents);
7333 # Singular form of $PRIMARY.
7334 (my $one_primary = $primary) =~ s/S$//;
7335 $output_rules .= file_contents ($file, $where,
7336 PRIMARY => $primary,
7337 ONE_PRIMARY => $one_primary,
7339 NDIR => $nodir_name,
7340 BASE => $strip_subdir,
7342 INSTALL => $install_p,
7344 DISTVAR => $distvar,
7345 'CK-OPTS' => $check_options_p);
7348 # The JAVA variable is used as the name of the Java interpreter.
7349 # The PYTHON variable is used as the name of the Python interpreter.
7350 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7353 define_pretty_variable ($primary, TRUE, INTERNAL, @used);
7354 $output_vars .= "\n";
7357 err_var ($require_extra,
7358 "'$require_extra' contains configure substitution,\n"
7359 . "but 'EXTRA_$primary' not defined")
7360 if ($require_extra && ! var ('EXTRA_' . $primary));
7362 # Push here because PRIMARY might be configure time determined.
7363 push (@all, '$(' . $primary . ')')
7364 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7366 # Make the result unique. This lets the user use conditionals in
7367 # a natural way, but still lets us program lazily -- we don't have
7368 # to worry about handling a particular object more than once.
7369 # We will keep only one location per object.
7371 for my $pair (@result)
7373 my ($loc, $val) = @$pair;
7374 $result{$val} = $loc;
7376 my @l = sort keys %result;
7377 return map { [$result{$_}->clone, $_] } @l;
7381 ################################################################
7383 # Each key in this hash is the name of a directory holding a
7384 # Makefile.in. These variables are local to 'is_make_dir'.
7386 my $make_dirs_set = 0;
7388 # is_make_dir ($DIRECTORY)
7389 # ------------------------
7393 if (! $make_dirs_set)
7395 foreach my $iter (@configure_input_files)
7397 $make_dirs{dirname ($iter)} = 1;
7399 # We also want to notice Makefile.in's.
7400 foreach my $iter (@other_input_files)
7402 if ($iter =~ /Makefile\.in$/)
7404 $make_dirs{dirname ($iter)} = 1;
7409 return defined $make_dirs{$dir};
7412 ################################################################
7414 # Find the aux dir. This should match the algorithm used by
7415 # ./configure. (See the Autoconf documentation for for
7416 # AC_CONFIG_AUX_DIR.)
7417 sub locate_aux_dir ()
7419 if (! $config_aux_dir_set_in_configure_ac)
7421 # The default auxiliary directory is the first
7422 # of ., .., or ../.. that contains install-sh.
7423 # Assume . if install-sh doesn't exist yet.
7424 for my $dir (qw (. .. ../..))
7426 if (-f "$dir/install-sh")
7428 $config_aux_dir = $dir;
7432 $config_aux_dir = '.' unless $config_aux_dir;
7434 # Avoid unsightly '/.'s.
7435 $am_config_aux_dir =
7436 '$(top_srcdir)' . ($config_aux_dir eq '.' ? "" : "/$config_aux_dir");
7437 $am_config_aux_dir =~ s,/*$,,;
7441 # push_required_file ($DIR, $FILE, $FULLFILE)
7442 # -------------------------------------------
7443 # Push the given file onto DIST_COMMON.
7444 sub push_required_file
7446 my ($dir, $file, $fullfile) = @_;
7448 # If the file to be distributed is in the same directory of the
7449 # currently processed Makefile.am, then we want to distribute it
7450 # from this same Makefile.am.
7451 if ($dir eq $relative_dir)
7453 push_dist_common ($file);
7455 # This is needed to allow a construct in a non-top-level Makefile.am
7456 # to require a file in the build-aux directory (see at least the test
7457 # script 'test-driver-is-distributed.sh'). This is related to the
7458 # automake bug#9546. Note that the use of $config_aux_dir instead
7459 # of $am_config_aux_dir here is deliberate and necessary.
7460 elsif ($dir eq $config_aux_dir)
7462 push_dist_common ("$am_config_aux_dir/$file");
7464 # FIXME: another spacial case, for AC_LIBOBJ/AC_LIBSOURCE support.
7465 # We probably need some refactoring of this function and its callers,
7466 # to have a more explicit and systematic handling of all the special
7467 # cases; but, since there are only two of them, this is low-priority
7469 elsif ($config_libobj_dir && $dir eq $config_libobj_dir)
7471 # Avoid unsightly '/.'s.
7472 my $am_config_libobj_dir =
7474 ($config_libobj_dir eq '.' ? "" : "/$config_libobj_dir");
7475 $am_config_libobj_dir =~ s|/*$||;
7476 push_dist_common ("$am_config_libobj_dir/$file");
7478 elsif ($relative_dir eq '.' && ! is_make_dir ($dir))
7480 # If we are doing the topmost directory, and the file is in a
7481 # subdir which does not have a Makefile, then we distribute it
7484 # If a required file is above the source tree, it is important
7485 # to prefix it with '$(srcdir)' so that no VPATH search is
7486 # performed. Otherwise problems occur with Make implementations
7487 # that rewrite and simplify rules whose dependencies are found in a
7488 # VPATH location. Here is an example with OSF1/Tru64 Make.
7500 # Dependency '../a' was found in 'sub/../a', but this make
7501 # implementation simplified it as 'a'. (Note that the sub/
7502 # directory does not even exist.)
7504 # This kind of VPATH rewriting seems hard to cancel. The
7505 # distdir.am hack against VPATH rewriting works only when no
7506 # simplification is done, i.e., for dependencies which are in
7507 # subdirectories, not in enclosing directories. Hence, in
7508 # the latter case we use a full path to make sure no VPATH
7510 $fullfile = '$(srcdir)/' . $fullfile
7511 if $dir =~ m,^\.\.(?:$|/),;
7513 push_dist_common ($fullfile);
7517 prog_error "a Makefile in relative directory $relative_dir " .
7518 "can't add files in directory $dir to DIST_COMMON";
7523 # If a file name appears as a key in this hash, then it has already
7524 # been checked for. This allows us not to report the same error more
7526 my %required_file_not_found = ();
7528 # required_file_check_or_copy ($WHERE, $DIRECTORY, $FILE)
7529 # -------------------------------------------------------
7530 # Verify that the file must exist in $DIRECTORY, or install it.
7531 sub required_file_check_or_copy
7533 my ($where, $dir, $file) = @_;
7535 my $fullfile = "$dir/$file";
7537 my $dangling_sym = 0;
7539 if (-l $fullfile && ! -f $fullfile)
7543 elsif (dir_has_case_matching_file ($dir, $file))
7548 # '--force-missing' only has an effect if '--add-missing' is
7551 if $found_it && (! $add_missing || ! $force_missing);
7553 # If we've already looked for it, we're done. You might wonder why we
7554 # don't do this before searching for the file. If we do that, then
7555 # something like AC_OUTPUT([subdir/foo foo]) will fail to put 'foo.in'
7556 # into $(DIST_COMMON).
7559 return if defined $required_file_not_found{$fullfile};
7560 $required_file_not_found{$fullfile} = 1;
7562 if ($dangling_sym && $add_missing)
7571 # Only install missing files according to our desired
7573 my $message = "required file '$fullfile' not found";
7576 if (-f "$libdir/$file")
7580 # Install the missing file. Symlink if we
7581 # can, copy if we must. Note: delete the file
7582 # first, in case it is a dangling symlink.
7583 $message = "installing '$fullfile'";
7585 # The license file should not be volatile.
7586 if ($file eq "COPYING")
7588 $message .= " using GNU General Public License v3 file";
7589 $trailer2 = "\n Consider adding the COPYING file"
7590 . " to the version control system"
7591 . "\n for your code, to avoid questions"
7592 . " about which license your project uses";
7595 # Windows Perl will hang if we try to delete a
7596 # file that doesn't exist.
7597 unlink ($fullfile) if -f $fullfile;
7598 if ($symlink_exists && ! $copy_missing)
7600 if (! symlink ("$libdir/$file", $fullfile)
7604 $trailer = "; error while making link: $!";
7607 elsif (system ('cp', "$libdir/$file", $fullfile))
7610 $trailer = "\n error while copying";
7612 set_dir_cache_file ($dir, $file);
7617 $trailer = "\n 'automake --add-missing' can install '$file'"
7618 if -f "$libdir/$file";
7621 # If --force-missing was specified, and we have
7622 # actually found the file, then do nothing.
7624 if $found_it && $force_missing;
7626 # If we couldn't install the file, but it is a target in
7627 # the Makefile, don't print anything. This allows files
7628 # like README, AUTHORS, or THANKS to be generated.
7630 if !$suppress && rule $file;
7632 msg ($suppress ? 'note' : 'error', $where, "$message$trailer$trailer2");
7636 # require_file_internal ($WHERE, $MYSTRICT, $DIRECTORY, $QUEUE, @FILES)
7637 # ---------------------------------------------------------------------
7638 # Verify that the file must exist in $DIRECTORY, or install it.
7639 # $MYSTRICT is the strictness level at which this file becomes required.
7640 # Worker threads may queue up the action to be serialized by the master,
7642 sub require_file_internal
7644 my ($where, $mystrict, $dir, $queue, @files) = @_;
7647 unless $strictness >= $mystrict;
7649 foreach my $file (@files)
7651 push_required_file ($dir, $file, "$dir/$file");
7654 queue_required_file_check_or_copy ($required_conf_file_queue,
7655 QUEUE_CONF_FILE, $relative_dir,
7656 $where, $mystrict, @files);
7660 required_file_check_or_copy ($where, $dir, $file);
7665 # require_file ($WHERE, $MYSTRICT, @FILES)
7666 # ----------------------------------------
7669 my ($where, $mystrict, @files) = @_;
7670 require_file_internal ($where, $mystrict, $relative_dir, 0, @files);
7673 # require_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7674 # ----------------------------------------------------------
7675 sub require_file_with_macro
7677 my ($cond, $macro, $mystrict, @files) = @_;
7678 $macro = rvar ($macro) unless ref $macro;
7679 require_file ($macro->rdef ($cond)->location, $mystrict, @files);
7682 # require_libsource_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7683 # ---------------------------------------------------------------
7684 # Require an AC_LIBSOURCEd file. If AC_CONFIG_LIBOBJ_DIR was called, it
7685 # must be in that directory. Otherwise expect it in the current directory.
7686 sub require_libsource_with_macro
7688 my ($cond, $macro, $mystrict, @files) = @_;
7689 $macro = rvar ($macro) unless ref $macro;
7690 if ($config_libobj_dir)
7692 require_file_internal ($macro->rdef ($cond)->location, $mystrict,
7693 $config_libobj_dir, 0, @files);
7697 require_file ($macro->rdef ($cond)->location, $mystrict, @files);
7701 # queue_required_file_check_or_copy ($QUEUE, $KEY, $DIR, $WHERE,
7702 # $MYSTRICT, @FILES)
7703 # --------------------------------------------------------------
7704 sub queue_required_file_check_or_copy
7706 my ($queue, $key, $dir, $where, $mystrict, @files) = @_;
7710 @serial_loc = (QUEUE_LOCATION, $where->serialize ());
7714 @serial_loc = (QUEUE_STRING, $where);
7716 $queue->enqueue ($key, $dir, @serial_loc, $mystrict, 0 + @files, @files);
7719 # require_queued_file_check_or_copy ($QUEUE)
7720 # ------------------------------------------
7721 sub require_queued_file_check_or_copy
7725 my $dir = $queue->dequeue ();
7726 my $loc_key = $queue->dequeue ();
7727 if ($loc_key eq QUEUE_LOCATION)
7729 $where = Automake::Location::deserialize ($queue);
7731 elsif ($loc_key eq QUEUE_STRING)
7733 $where = $queue->dequeue ();
7737 prog_error "unexpected key $loc_key";
7739 my $mystrict = $queue->dequeue ();
7740 my $nfiles = $queue->dequeue ();
7742 push @files, $queue->dequeue ()
7743 foreach (1 .. $nfiles);
7745 unless $strictness >= $mystrict;
7746 foreach my $file (@files)
7748 required_file_check_or_copy ($where, $config_aux_dir, $file);
7752 # require_conf_file ($WHERE, $MYSTRICT, @FILES)
7753 # ---------------------------------------------
7754 # Looks in configuration path, as specified by AC_CONFIG_AUX_DIR.
7755 sub require_conf_file
7757 my ($where, $mystrict, @files) = @_;
7758 my $queue = defined $required_conf_file_queue ? 1 : 0;
7759 require_file_internal ($where, $mystrict, $config_aux_dir,
7764 # require_conf_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7765 # ---------------------------------------------------------------
7766 sub require_conf_file_with_macro
7768 my ($cond, $macro, $mystrict, @files) = @_;
7769 require_conf_file (rvar ($macro)->rdef ($cond)->location,
7773 ################################################################
7775 # require_build_directory ($DIRECTORY)
7776 # ------------------------------------
7777 # Emit rules to create $DIRECTORY if needed, and return
7778 # the file that any target requiring this directory should be made
7780 # We don't want to emit the rule twice, and want to reuse it
7781 # for directories with equivalent names (e.g., 'foo/bar' and './foo//bar').
7782 sub require_build_directory
7784 my $directory = shift;
7786 return $directory_map{$directory} if exists $directory_map{$directory};
7788 my $cdir = File::Spec->canonpath ($directory);
7790 if (exists $directory_map{$cdir})
7792 my $stamp = $directory_map{$cdir};
7793 $directory_map{$directory} = $stamp;
7797 my $dirstamp = "$cdir/\$(am__dirstamp)";
7799 $directory_map{$directory} = $dirstamp;
7800 $directory_map{$cdir} = $dirstamp;
7802 # Set a variable for the dirstamp basename.
7803 define_pretty_variable ('am__dirstamp', TRUE, INTERNAL,
7804 '$(am__leading_dot)dirstamp');
7806 # Directory must be removed by 'make distclean'.
7807 $clean_files{$dirstamp} = DIST_CLEAN;
7809 $output_rules .= ("$dirstamp:\n"
7810 . "\t\@\$(MKDIR_P) $directory\n"
7811 . "\t\@: > $dirstamp\n");
7816 # require_build_directory_maybe ($FILE)
7817 # -------------------------------------
7818 # If $FILE lies in a subdirectory, emit a rule to create this
7819 # directory and return the file that $FILE should be made
7820 # dependent upon. Otherwise, just return the empty string.
7821 sub require_build_directory_maybe
7824 my $directory = dirname ($file);
7826 if ($directory ne '.')
7828 return require_build_directory ($directory);
7836 ################################################################
7838 # Push a list of files onto '@dist_common'.
7839 sub push_dist_common
7841 prog_error "push_dist_common run after handle_dist"
7842 if $handle_dist_run;
7843 push @dist_common, @_;
7847 ################################################################
7849 # generate_makefile ($MAKEFILE_AM, $MAKEFILE_IN)
7850 # ----------------------------------------------
7851 # Generate a Makefile.in given the name of the corresponding Makefile and
7852 # the name of the file output by config.status.
7853 sub generate_makefile
7855 my ($makefile_am, $makefile_in) = @_;
7857 # Reset all the Makefile.am related variables.
7858 initialize_per_input;
7860 # AUTOMAKE_OPTIONS can contains -W flags to disable or enable
7861 # warnings for this file. So hold any warning issued before
7862 # we have processed AUTOMAKE_OPTIONS.
7863 buffer_messages ('warning');
7865 # $OUTPUT is encoded. If it contains a ":" then the first element
7866 # is the real output file, and all remaining elements are input
7867 # files. We don't scan or otherwise deal with these input files,
7868 # other than to mark them as dependencies. See the subroutine
7869 # 'scan_autoconf_files' for details.
7870 my ($makefile, @inputs) = split (/:/, $output_files{$makefile_in});
7872 $relative_dir = dirname ($makefile);
7874 read_main_am_file ($makefile_am, $makefile_in);
7875 if (not handle_options)
7877 # Process buffered warnings.
7879 # Fatal error. Just return, so we can continue with next file.
7882 # Process buffered warnings.
7885 # There are a few install-related variables that you should not define.
7886 foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
7891 my $def = $v->def (TRUE);
7892 prog_error "$var not defined in condition TRUE"
7894 reject_var $var, "'$var' should not be defined"
7895 if $def->owner != VAR_AUTOMAKE;
7899 # Catch some obsolete variables.
7900 msg_var ('obsolete', 'INCLUDES',
7901 "'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')")
7902 if var ('INCLUDES');
7904 # Must do this after reading .am file.
7905 define_variable ('subdir', $relative_dir, INTERNAL);
7907 # If DIST_SUBDIRS is defined, make sure SUBDIRS is, so that
7908 # recursive rules are enabled.
7909 define_pretty_variable ('SUBDIRS', TRUE, INTERNAL, '')
7910 if var 'DIST_SUBDIRS' && ! var 'SUBDIRS';
7912 # Check first, because we might modify some state.
7913 check_gnu_standards;
7914 check_gnits_standards;
7916 handle_configure ($makefile_am, $makefile_in, $makefile, @inputs);
7927 # These must be run after all the sources are scanned. They use
7928 # variables defined by handle_libraries(), handle_ltlibraries(),
7929 # or handle_programs().
7934 # Variables used by distdir.am and tags.am.
7935 define_pretty_variable ('SOURCES', TRUE, INTERNAL, @sources);
7936 if (! option 'no-dist')
7938 define_pretty_variable ('DIST_SOURCES', TRUE, INTERNAL, @dist_sources);
7949 handle_user_recursion;
7951 handle_minor_options;
7952 # Must come after handle_programs so that %known_programs is up-to-date.
7955 # This must come after most other rules.
7959 do_check_merge_target;
7960 handle_all ($makefile);
7963 if (var ('lib_LTLIBRARIES') && var ('bin_PROGRAMS'))
7965 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
7967 if (var ('nobase_lib_LTLIBRARIES') && var ('bin_PROGRAMS'))
7969 $output_rules .= "install-binPROGRAMS: install-nobase_libLTLIBRARIES\n\n";
7973 handle_clean ($makefile);
7974 handle_factored_dependencies;
7976 # Comes last, because all the above procedures may have
7977 # defined or overridden variables.
7978 $output_vars .= output_variables;
7982 if ($exit_code != 0)
7984 verb "not writing $makefile_in because of earlier errors";
7988 my $am_relative_dir = dirname ($makefile_am);
7989 mkdir ($am_relative_dir, 0755) if ! -d $am_relative_dir;
7991 # We make sure that 'all:' is the first target.
7993 "$output_vars$output_all$output_header$output_rules$output_trailer";
7995 # Decide whether we must update the output file or not.
7996 # We have to update in the following situations.
7997 # * $force_generation is set.
7998 # * any of the output dependencies is younger than the output
7999 # * the contents of the output is different (this can happen
8000 # if the project has been populated with a file listed in
8001 # @common_files since the last run).
8002 # Output's dependencies are split in two sets:
8003 # * dependencies which are also configure dependencies
8004 # These do not change between each Makefile.am
8005 # * other dependencies, specific to the Makefile.am being processed
8006 # (such as the Makefile.am itself, or any Makefile fragment
8008 my $timestamp = mtime $makefile_in;
8009 if (! $force_generation
8010 && $configure_deps_greatest_timestamp < $timestamp
8011 && $output_deps_greatest_timestamp < $timestamp
8012 && $output eq contents ($makefile_in))
8014 verb "$makefile_in unchanged";
8015 # No need to update.
8019 if (-e $makefile_in)
8021 unlink ($makefile_in)
8022 or fatal "cannot remove $makefile_in: $!";
8025 my $gm_file = new Automake::XFile "> $makefile_in";
8026 verb "creating $makefile_in";
8027 print $gm_file $output;
8031 ################################################################
8034 # Helper function for usage().
8035 sub print_autodist_files
8037 my @lcomm = uniq (sort @_);
8040 format USAGE_FORMAT =
8041 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
8042 $four[0], $four[1], $four[2], $four[3]
8044 local $~ = "USAGE_FORMAT";
8047 my $rows = int(@lcomm / $cols);
8048 my $rest = @lcomm % $cols;
8059 for (my $y = 0; $y < $rows; $y++)
8061 @four = ("", "", "", "");
8062 for (my $x = 0; $x < $cols; $x++)
8064 last if $y + 1 == $rows && $x == $rest;
8066 my $idx = (($x > $rest)
8067 ? ($rows * $rest + ($rows - 1) * ($x - $rest))
8071 $four[$x] = $lcomm[$idx];
8080 print "Usage: $0 [OPTION]... [Makefile]...
8082 Generate Makefile.in for configure from Makefile.am.
8085 --help print this help, then exit
8086 --version print version number, then exit
8087 -v, --verbose verbosely list files processed
8088 --no-force only update Makefile.in's that are out of date
8089 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
8091 Dependency tracking:
8092 -i, --ignore-deps disable dependency tracking code
8093 --include-deps enable dependency tracking code
8096 --foreign set strictness to foreign
8097 --gnits set strictness to gnits
8098 --gnu set strictness to gnu
8101 -a, --add-missing add missing standard files to package
8102 --libdir=DIR set directory storing library files
8103 --print-libdir print directory storing library files
8104 -c, --copy with -a, copy missing files (default is symlink)
8105 -f, --force-missing force update of standard files
8108 Automake::ChannelDefs::usage;
8110 print "\nFiles automatically distributed if found " .
8112 print_autodist_files @common_files;
8113 print "\nFiles automatically distributed if found " .
8114 "(under certain conditions):\n";
8115 print_autodist_files @common_sometimes;
8118 Report bugs to <@PACKAGE_BUGREPORT@>.
8119 GNU Automake home page: <@PACKAGE_URL@>.
8120 General help using GNU software: <https://www.gnu.org/gethelp/>.
8123 # --help always returns 0 per GNU standards.
8131 automake (GNU $PACKAGE) $VERSION
8132 Copyright (C) $RELEASE_YEAR Free Software Foundation, Inc.
8133 License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl-2.0.html>
8134 This is free software: you are free to change and redistribute it.
8135 There is NO WARRANTY, to the extent permitted by law.
8137 Written by Tom Tromey <tromey\@redhat.com>
8138 and Alexandre Duret-Lutz <adl\@gnu.org>.
8140 # --version always returns 0 per GNU standards.
8144 ################################################################
8146 # Parse command line.
8147 sub parse_arguments ()
8150 my $ignore_deps = 0;
8155 'version' => \&version,
8157 'libdir=s' => \$libdir,
8158 'print-libdir' => sub { print "$libdir\n"; exit 0; },
8159 'gnu' => sub { $strict = 'gnu'; },
8160 'gnits' => sub { $strict = 'gnits'; },
8161 'foreign' => sub { $strict = 'foreign'; },
8162 'include-deps' => sub { $ignore_deps = 0; },
8163 'i|ignore-deps' => sub { $ignore_deps = 1; },
8164 'no-force' => sub { $force_generation = 0; },
8165 'f|force-missing' => \$force_missing,
8166 'a|add-missing' => \$add_missing,
8167 'c|copy' => \$copy_missing,
8168 'v|verbose' => sub { setup_channel 'verb', silent => 0; },
8169 'W|warnings=s' => \@warnings,
8172 use Automake::Getopt ();
8173 Automake::Getopt::parse_options %cli_options;
8175 set_strictness ($strict);
8176 my $cli_where = new Automake::Location;
8177 set_global_option ('no-dependencies', $cli_where) if $ignore_deps;
8178 for my $warning (@warnings)
8180 parse_warnings ('-W', $warning);
8183 return unless @ARGV;
8186 foreach my $arg (@ARGV)
8188 fatal ("empty argument\nTry '$0 --help' for more information")
8191 # Handle $local:$input syntax.
8192 my ($local, @rest) = split (/:/, $arg);
8193 @rest = ("$local.in",) unless @rest;
8194 my $input = locate_am @rest;
8197 push @input_files, $input;
8198 $output_files{$input} = join (':', ($local, @rest));
8202 error "no Automake input file found for '$arg'";
8206 fatal "no input file found among supplied arguments"
8207 if $errspec && ! @input_files;
8211 # handle_makefile ($MAKEFILE)
8212 # ---------------------------
8216 ($am_file = $file) =~ s/\.in$//;
8217 if (! -f ($am_file . '.am'))
8219 error "'$am_file.am' does not exist";
8223 # Any warning setting now local to this Makefile.am.
8226 generate_makefile ($am_file . '.am', $file);
8228 # Back out any warning setting.
8233 # Deal with all makefiles, without threads.
8234 sub handle_makefiles_serial ()
8236 foreach my $file (@input_files)
8238 handle_makefile ($file);
8242 # Logic for deciding how many worker threads to use.
8243 sub get_number_of_threads ()
8245 my $nthreads = $ENV{'AUTOMAKE_JOBS'} || 0;
8248 unless $nthreads =~ /^[0-9]+$/;
8250 # It doesn't make sense to use more threads than makefiles,
8251 my $max_threads = @input_files;
8253 if ($nthreads > $max_threads)
8255 $nthreads = $max_threads;
8260 # handle_makefiles_threaded ($NTHREADS)
8261 # -------------------------------------
8262 # Deal with all makefiles, using threads. The general strategy is to
8263 # spawn NTHREADS worker threads, dispatch makefiles to them, and let the
8264 # worker threads push back everything that needs serialization:
8265 # * warning and (normal) error messages, for stable stderr output
8266 # order and content (avoiding duplicates, for example),
8267 # * races when installing aux files (and respective messages),
8268 # * races when collecting aux files for distribution.
8270 # The latter requires that the makefile that deals with the aux dir
8271 # files be handled last, done by the master thread.
8272 sub handle_makefiles_threaded
8274 my ($nthreads) = @_;
8276 # The file queue distributes all makefiles, the message queues
8277 # collect all serializations needed for respective files.
8278 my $file_queue = Thread::Queue->new;
8280 foreach my $file (@input_files)
8282 $msg_queues{$file} = Thread::Queue->new;
8285 verb "spawning $nthreads worker threads";
8286 my @threads = (1 .. $nthreads);
8287 foreach my $t (@threads)
8289 $t = threads->new (sub
8291 while (my $file = $file_queue->dequeue)
8293 verb "handling $file";
8294 my $queue = $msg_queues{$file};
8295 setup_channel_queue ($queue, QUEUE_MESSAGE);
8296 $required_conf_file_queue = $queue;
8297 handle_makefile ($file);
8298 $queue->enqueue (undef);
8299 setup_channel_queue (undef, undef);
8300 $required_conf_file_queue = undef;
8306 # Queue all makefiles.
8307 verb "queuing " . @input_files . " input files";
8308 $file_queue->enqueue (@input_files, (undef) x @threads);
8310 # Collect and process serializations.
8311 foreach my $file (@input_files)
8313 verb "dequeuing messages for " . $file;
8314 reset_local_duplicates ();
8315 my $queue = $msg_queues{$file};
8316 while (my $key = $queue->dequeue)
8318 if ($key eq QUEUE_MESSAGE)
8320 pop_channel_queue ($queue);
8322 elsif ($key eq QUEUE_CONF_FILE)
8324 require_queued_file_check_or_copy ($queue);
8328 prog_error "unexpected key $key";
8333 foreach my $t (@threads)
8335 my @exit_thread = $t->join;
8336 $exit_code = $exit_thread[0]
8337 if ($exit_thread[0] > $exit_code);
8341 ################################################################
8343 # Parse the WARNINGS environment variable.
8346 # Parse command line.
8349 $configure_ac = require_configure_ac;
8351 # Do configure.ac scan only once.
8352 scan_autoconf_files;
8357 $msg = "\nDid you forget AC_CONFIG_FILES([Makefile]) in $configure_ac?"
8358 if -f 'Makefile.am';
8359 fatal ("no 'Makefile.am' found for any configure output$msg");
8362 my $nthreads = get_number_of_threads ();
8364 if ($perl_threads && $nthreads >= 1)
8366 handle_makefiles_threaded ($nthreads);
8370 handle_makefiles_serial ();