5 eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
8 # automake - create Makefile.in from Makefile.am
9 # Copyright (C) 1994-2017 Free Software Foundation, Inc.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <https://www.gnu.org/licenses/>.
24 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
25 # Perl reimplementation by Tom Tromey <tromey@redhat.com>, and
26 # Alexandre Duret-Lutz <adl@gnu.org>.
34 unshift (@INC, '@datadir@/@PACKAGE@-@APIVERSION@')
35 unless $ENV{AUTOMAKE_UNINSTALLED};
45 require Thread::Queue;
49 use Automake::General;
51 use Automake::Channels;
52 use Automake::ChannelDefs;
53 use Automake::FileUtils;
54 use Automake::Location;
55 use Automake::Condition qw/TRUE FALSE/;
56 use Automake::DisjConditions;
57 use Automake::Options;
58 use Automake::Variable;
61 use Automake::RuleDef;
62 use Automake::Wrap 'makefile_wrap';
63 use Automake::Language;
66 use List::Util 'none';
69 ## ----------------------- ##
70 ## Subroutine prototypes. ##
71 ## ----------------------- ##
73 sub append_exeext (&$);
74 sub check_gnits_standards ();
75 sub check_gnu_standards ();
76 sub check_trailing_slash ($\$);
78 sub define_files_variable ($\@$$);
79 sub define_standard_variables ();
80 sub define_verbose_libtool ();
81 sub define_verbose_texinfo ();
82 sub do_check_merge_target ();
83 sub get_number_of_threads ();
84 sub handle_compile ();
87 sub handle_emacs_lisp ();
88 sub handle_factored_dependencies ();
90 sub handle_gettext ();
91 sub handle_headers ();
92 sub handle_install ();
94 sub handle_languages ();
95 sub handle_libraries ();
96 sub handle_libtool ();
97 sub handle_ltlibraries ();
98 sub handle_makefiles_serial ();
99 sub handle_man_pages ();
100 sub handle_minor_options ();
101 sub handle_options ();
102 sub handle_programs ();
103 sub handle_python ();
104 sub handle_scripts ();
105 sub handle_silent ();
106 sub handle_subdirs ();
108 sub handle_targets ();
110 sub handle_tests_dejagnu ();
111 sub handle_texinfo ();
112 sub handle_user_recursion ();
113 sub initialize_per_input ();
114 sub lang_lex_finish ();
116 sub lang_vala_finish ();
117 sub lang_yacc_finish ();
118 sub locate_aux_dir ();
119 sub parse_arguments ();
120 sub scan_aclocal_m4 ();
121 sub scan_autoconf_files ();
124 sub transform_token ($\%$);
127 sub yacc_lex_finish_helper ();
133 # Some regular expressions. One reason to put them here is that it
134 # makes indentation work better in Emacs.
136 # Writing singled-quoted-$-terminated regexes is a pain because
137 # perl-mode thinks of $' as the ${'} variable (instead of a $ followed
138 # by a closing quote. Letting perl-mode think the quote is not closed
139 # leads to all sort of misindentations. On the other hand, defining
140 # regexes as double-quoted strings is far less readable. So usually
143 # $REGEX = '^regex_value' . "\$";
145 my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
146 my $WHITE_PATTERN = '^\s*' . "\$";
147 my $COMMENT_PATTERN = '^#';
148 my $TARGET_PATTERN='[$a-zA-Z0-9_.@%][-.a-zA-Z0-9_(){}/$+@%]*';
149 # A rule has three parts: a list of targets, a list of dependencies,
150 # and optionally actions.
152 "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
154 # Only recognize leading spaces, not leading tabs. If we recognize
155 # leading tabs here then we need to make the reader smarter, because
156 # otherwise it will think rules like 'foo=bar; \' are errors.
157 my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)' . "\$";
158 # This pattern recognizes a Gnits version id and sets $1 if the
159 # release is an alpha release. We also allow a suffix which can be
160 # used to extend the version number with a "fork" identifier.
161 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
163 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?' . "\$";
165 '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
167 '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?' . "\$";
168 my $PATH_PATTERN = '(\w|[+/.-])+';
169 # This will pass through anything not of the prescribed form.
170 my $INCLUDE_PATTERN = ('^include\s+'
171 . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
172 . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
173 . '|([^/\$]' . $PATH_PATTERN . '))\s*(#.*)?' . "\$");
175 # Directories installed during 'install-exec' phase.
176 my $EXEC_DIR_PATTERN =
177 '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)' . "\$";
179 # Values for AC_CANONICAL_*
180 use constant AC_CANONICAL_BUILD => 1;
181 use constant AC_CANONICAL_HOST => 2;
182 use constant AC_CANONICAL_TARGET => 3;
184 # Values indicating when something should be cleaned.
185 use constant MOSTLY_CLEAN => 0;
186 use constant CLEAN => 1;
187 use constant DIST_CLEAN => 2;
188 use constant MAINTAINER_CLEAN => 3;
191 my @libtool_files = qw(ltmain.sh config.guess config.sub);
192 # ltconfig appears here for compatibility with old versions of libtool.
193 my @libtool_sometimes = qw(ltconfig ltcf-c.sh ltcf-cxx.sh ltcf-gcj.sh);
195 # Commonly found files we look for and automatically include in
198 (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
199 COPYING.LESSER ChangeLog INSTALL NEWS README THANKS TODO
200 ar-lib compile config.guess config.rpath
201 config.sub depcomp install-sh libversion.in mdate-sh
202 missing mkinstalldirs py-compile texinfo.tex ylwrap),
203 @libtool_files, @libtool_sometimes);
205 # Commonly used files we auto-include, but only sometimes. This list
206 # is used for the --help output only.
207 my @common_sometimes =
208 qw(aclocal.m4 acconfig.h config.h.top config.h.bot configure
209 configure.ac stamp-vti);
211 # Standard directories from the GNU Coding Standards, and additional
212 # pkg* directories from Automake. Stored in a hash for fast member check.
213 my %standard_prefix =
214 map { $_ => 1 } (qw(bin data dataroot doc dvi exec html include info
215 lib libexec lisp locale localstate man man1 man2
216 man3 man4 man5 man6 man7 man8 man9 oldinclude pdf
217 pkgdata pkginclude pkglib pkglibexec ps sbin
218 sharedstate sysconf));
220 # Copyright on generated Makefile.ins.
221 my $gen_copyright = "\
222 # Copyright (C) 1994-$RELEASE_YEAR Free Software Foundation, Inc.
224 # This Makefile.in is free software; the Free Software Foundation
225 # gives unlimited permission to copy and/or distribute it,
226 # with or without modifications, as long as this notice is preserved.
228 # This program is distributed in the hope that it will be useful,
229 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
230 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
231 # PARTICULAR PURPOSE.
234 # These are used when keeping track of whether an object can be built
235 # by two different paths.
236 use constant COMPILE_LIBTOOL => 1;
237 use constant COMPILE_ORDINARY => 2;
239 # We can't always associate a location to a variable or a rule,
240 # when it's defined by Automake. We use INTERNAL in this case.
241 use constant INTERNAL => new Automake::Location;
243 # Serialization keys for message queues.
244 use constant QUEUE_MESSAGE => "msg";
245 use constant QUEUE_CONF_FILE => "conf file";
246 use constant QUEUE_LOCATION => "location";
247 use constant QUEUE_STRING => "string";
249 ## ---------------------------------- ##
250 ## Variables related to the options. ##
251 ## ---------------------------------- ##
253 # TRUE if we should always generate Makefile.in.
254 my $force_generation = 1;
256 # From the Perl manual.
257 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
259 # TRUE if missing standard files should be installed.
262 # TRUE if we should copy missing files; otherwise symlink if possible.
263 my $copy_missing = 0;
265 # TRUE if we should always update files that we know about.
266 my $force_missing = 0;
269 ## ---------------------------------------- ##
270 ## Variables filled during files scanning. ##
271 ## ---------------------------------------- ##
273 # Name of the Autoconf input file. We used to support 'configure.in'
274 # as well once, that that is long obsolete now.
275 my $configure_ac = 'configure.ac';
277 # Files found by scanning configure.ac for LIBOBJS.
280 # Names used in AC_CONFIG_HEADERS call.
281 my @config_headers = ();
283 # Names used in AC_CONFIG_LINKS call.
284 my @config_links = ();
286 # List of Makefile.am's to process, and their corresponding outputs.
287 my @input_files = ();
288 my %output_files = ();
290 # Complete list of Makefile.am's that exist.
291 my @configure_input_files = ();
293 # List of files in AC_CONFIG_FILES/AC_OUTPUT without Makefile.am's,
295 my @other_input_files = ();
296 # Where each AC_CONFIG_FILES/AC_OUTPUT/AC_CONFIG_LINK/AC_CONFIG_HEADERS
297 # appears. The keys are the files created by these macros.
298 my %ac_config_files_location = ();
299 # The condition under which AC_CONFIG_FOOS appears.
300 my %ac_config_files_condition = ();
302 # Directory to search for configure-required files. This
303 # will be computed by locate_aux_dir() and can be set using
304 # AC_CONFIG_AUX_DIR in configure.ac.
305 # $CONFIG_AUX_DIR is the 'raw' directory, valid only in the source-tree.
306 my $config_aux_dir = '';
307 my $config_aux_dir_set_in_configure_ac = 0;
308 # $AM_CONFIG_AUX_DIR is prefixed with $(top_srcdir), so it can be used
310 my $am_config_aux_dir = '';
312 # Directory to search for AC_LIBSOURCE files, as set by AC_CONFIG_LIBOBJ_DIR
314 my $config_libobj_dir = '';
316 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
317 my $seen_gettext = 0;
318 # Whether AM_GNU_GETTEXT([external]) is used.
319 my $seen_gettext_external = 0;
320 # Where AM_GNU_GETTEXT appears.
321 my $ac_gettext_location;
322 # Whether AM_GNU_GETTEXT_INTL_SUBDIR has been seen.
323 my $seen_gettext_intl = 0;
325 # The arguments of the AM_EXTRA_RECURSIVE_TARGETS call (if any).
326 my @extra_recursive_targets = ();
328 # Lists of tags supported by Libtool.
329 my %libtool_tags = ();
330 # 1 if Libtool uses LT_SUPPORTED_TAG. If it does, then it also
331 # uses AC_REQUIRE_AUX_FILE.
332 my $libtool_new_api = 0;
334 # Most important AC_CANONICAL_* macro seen so far.
335 my $seen_canonical = 0;
337 # Where AM_MAINTAINER_MODE appears.
340 # Actual version we've seen.
341 my $package_version = '';
343 # Where version is defined.
344 my $package_version_location;
346 # TRUE if we've seen AM_PROG_AR
349 # Location of AC_REQUIRE_AUX_FILE calls, indexed by their argument.
350 my %required_aux_file = ();
352 # Where AM_INIT_AUTOMAKE is called.
353 my $seen_init_automake = 0;
355 # TRUE if we've seen AM_AUTOMAKE_VERSION.
356 my $seen_automake_version = 0;
358 # Hash table of discovered configure substitutions. Keys are names,
359 # values are 'FILE:LINE' strings which are used by error message
361 my %configure_vars = ();
363 # Ignored configure substitutions (i.e., variables not to be output in
365 my %ignored_configure_vars = ();
367 # Files included by $configure_ac.
368 my @configure_deps = ();
370 # Greatest timestamp of configure's dependencies.
371 my $configure_deps_greatest_timestamp = 0;
373 # Hash table of AM_CONDITIONAL variables seen in configure.
374 my %configure_cond = ();
376 # This maps extensions onto language names.
377 my %extension_map = ();
379 # List of the DIST_COMMON files we discovered while reading
381 my @configure_dist_common = ();
383 # This maps languages names onto objects.
385 # Maps each linker variable onto a language object.
386 my %link_languages = ();
388 # maps extensions to needed source flags.
389 my %sourceflags = ();
391 # List of targets we must always output.
392 # FIXME: Complete, and remove falsely required targets.
393 my %required_targets =
406 # FIXME: Not required, temporary hacks.
407 # Well, actually they are sort of required: the -recursive
408 # targets will run them anyway...
414 'install-data-am' => 1,
415 'install-exec-am' => 1,
416 'install-html-am' => 1,
417 'install-dvi-am' => 1,
418 'install-pdf-am' => 1,
419 'install-ps-am' => 1,
420 'install-info-am' => 1,
421 'installcheck-am' => 1,
425 'cscopelist-am' => 1,
429 # Queue to push require_conf_file requirements to.
430 my $required_conf_file_queue;
432 # The name of the Makefile currently being processed.
435 ################################################################
437 ## ------------------------------------------ ##
438 ## Variables reset by &initialize_per_input. ##
439 ## ------------------------------------------ ##
441 # Relative dir of the output makefile.
444 # Greatest timestamp of the output's dependencies (excluding
445 # configure's dependencies).
446 my $output_deps_greatest_timestamp;
448 # These variables are used when generating each Makefile.in.
449 # They hold the Makefile.in until it is ready to be printed.
456 # This is the conditional stack, updated on if/else/endif, and
457 # used to build Condition objects.
460 # This holds the set of included files.
463 # List of dependencies for the obvious targets.
468 # Keys in this hash table are files to delete. The associated
469 # value tells when this should happen (MOSTLY_CLEAN, DIST_CLEAN, etc.)
472 # Keys in this hash table are object files or other files in
473 # subdirectories which need to be removed. This only holds files
474 # which are created by compilations. The value in the hash indicates
475 # when the file should be removed.
476 my %compile_clean_files;
478 # Keys in this hash table are directories where we expect to build a
479 # libtool object. We use this information to decide what directories
481 my %libtool_clean_directories;
483 # Value of $(SOURCES), used by tags.am.
485 # Sources which go in the distribution.
488 # This hash maps object file names onto their corresponding source
489 # file names. This is used to ensure that each object is created
490 # by a single source file.
493 # This hash maps object file names onto an integer value representing
494 # whether this object has been built via ordinary compilation or
495 # libtool compilation (the COMPILE_* constants).
496 my %object_compilation_map;
499 # This keeps track of the directories for which we've already
500 # created dirstamp code. Keys are directories, values are stamp files.
501 # Several keys can share the same stamp files if they are equivalent
502 # (as are './/foo' and 'foo').
508 # This is a list of all targets to run during "make dist".
511 # List of all programs, libraries and ltlibraries as returned
516 # Blacklist of targets (as canonical base name) for which object file names
517 # may not be automatically shortened
520 # Keep track of all programs declared in this Makefile, without
521 # $(EXEEXT). @substitutions@ are not listed.
525 # This keeps track of which extensions we've seen (that we care
529 # This is random scratch space for the language finish functions.
530 # Don't randomly overwrite it; examine other uses of keys first.
531 my %language_scratch;
533 # We keep track of which objects need special (per-executable)
534 # handling on a per-language basis.
535 my %lang_specific_files;
537 # List of distributed files to be put in DIST_COMMON.
540 # This is set when 'handle_dist' has finished. Once this happens,
541 # we should no longer push on dist_common.
544 # Used to store a set of linkers needed to generate the sources currently
545 # under consideration.
548 # True if we need 'LINK' defined. This is a hack.
551 # Does the generated Makefile have to build some compiled object
552 # (for binary programs, or plain or libtool libraries)?
553 my $must_handle_compiled_objects;
555 # Record each file processed by make_paragraphs.
556 my %transformed_files;
558 ################################################################
560 ## ---------------------------------------------- ##
561 ## Variables not reset by &initialize_per_input. ##
562 ## ---------------------------------------------- ##
564 # Cache each file processed by make_paragraphs.
565 # (This is different from %transformed_files because
566 # %transformed_files is reset for each file while %am_file_cache
567 # it global to the run.)
570 ################################################################
572 # var_SUFFIXES_trigger ($TYPE, $VALUE)
573 # ------------------------------------
574 # This is called by Automake::Variable::define() when SUFFIXES
575 # is defined ($TYPE eq '') or appended ($TYPE eq '+').
576 # The work here needs to be performed as a side-effect of the
577 # macro_define() call because SUFFIXES definitions impact
578 # on $KNOWN_EXTENSIONS_PATTERN which is used used when parsing
580 sub var_SUFFIXES_trigger
582 my ($type, $value) = @_;
583 accept_extensions (split (' ', $value));
585 Automake::Variable::hook ('SUFFIXES', \&var_SUFFIXES_trigger);
587 ################################################################
590 # initialize_per_input ()
591 # -----------------------
592 # (Re)-Initialize per-Makefile.am variables.
593 sub initialize_per_input ()
595 reset_local_duplicates ();
597 $relative_dir = undef;
599 $output_deps_greatest_timestamp = 0;
605 $output_trailer = '';
607 Automake::Options::reset;
608 Automake::Variable::reset;
609 Automake::Rule::reset;
620 %compile_clean_files = ();
622 # We always include '.'. This isn't strictly correct.
623 %libtool_clean_directories = ('.' => 1);
629 %object_compilation_map = ();
638 $handle_dist_run = 0;
643 @dup_shortnames = ();
645 %known_programs = ();
646 %known_libraries = ();
648 %extension_seen = ();
650 %language_scratch = ();
652 %lang_specific_files = ();
656 $must_handle_compiled_objects = 0;
658 %transformed_files = ();
662 ################################################################
664 # Initialize our list of languages that are internally supported.
676 register_language ('name' => 'c',
678 'config_vars' => ['CC'],
680 'flags' => ['CFLAGS', 'CPPFLAGS'],
682 'compiler' => 'COMPILE',
683 'compile' => "\$(CC) @cpplike_flags \$(AM_CFLAGS) \$(CFLAGS)",
687 'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
688 'libtool_tag' => 'CC',
689 'extensions' => ['.c']);
692 register_language ('name' => 'cxx',
694 'config_vars' => ['CXX'],
695 'linker' => 'CXXLINK',
696 'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
698 'flags' => ['CXXFLAGS', 'CPPFLAGS'],
699 'compile' => "\$(CXX) @cpplike_flags \$(AM_CXXFLAGS) \$(CXXFLAGS)",
701 'compiler' => 'CXXCOMPILE',
702 'libtool_tag' => 'CXX',
706 'extensions' => ['.c++', '.cc', '.cpp', '.cxx', '.C']);
709 register_language ('name' => 'objc',
710 'Name' => 'Objective C',
711 'config_vars' => ['OBJC'],
712 'linker' => 'OBJCLINK',
713 'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
715 'flags' => ['OBJCFLAGS', 'CPPFLAGS'],
716 'compile' => "\$(OBJC) @cpplike_flags \$(AM_OBJCFLAGS) \$(OBJCFLAGS)",
718 'compiler' => 'OBJCCOMPILE',
722 'extensions' => ['.m']);
725 register_language ('name' => 'objcxx',
726 'Name' => 'Objective C++',
727 'config_vars' => ['OBJCXX'],
728 'linker' => 'OBJCXXLINK',
729 'link' => '$(OBJCXXLD) $(AM_OBJCXXFLAGS) $(OBJCXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
730 'autodep' => 'OBJCXX',
731 'flags' => ['OBJCXXFLAGS', 'CPPFLAGS'],
732 'compile' => "\$(OBJCXX) @cpplike_flags \$(AM_OBJCXXFLAGS) \$(OBJCXXFLAGS)",
734 'compiler' => 'OBJCXXCOMPILE',
735 'lder' => 'OBJCXXLD',
738 'extensions' => ['.mm']);
740 # Unified Parallel C.
741 register_language ('name' => 'upc',
742 'Name' => 'Unified Parallel C',
743 'config_vars' => ['UPC'],
744 'linker' => 'UPCLINK',
745 'link' => '$(UPCLD) $(AM_UPCFLAGS) $(UPCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
747 'flags' => ['UPCFLAGS', 'CPPFLAGS'],
748 'compile' => "\$(UPC) @cpplike_flags \$(AM_UPCFLAGS) \$(UPCFLAGS)",
750 'compiler' => 'UPCCOMPILE',
754 'extensions' => ['.upc']);
757 register_language ('name' => 'header',
759 'extensions' => ['.h', '.H', '.hxx', '.h++', '.hh',
762 'output_extensions' => sub { return () },
764 '_finish' => sub { });
767 register_language ('name' => 'vala',
769 'config_vars' => ['VALAC'],
771 'compile' => '$(VALAC) $(AM_VALAFLAGS) $(VALAFLAGS)',
773 'compiler' => 'VALACOMPILE',
774 'extensions' => ['.vala', '.vapi'],
775 # Vala compilation must be handled in a special way, so
776 # nothing to do or return here.
777 'output_extensions' => sub { },
778 'rule_file' => 'vala',
779 '_finish' => \&lang_vala_finish,
780 '_target_hook' => \&lang_vala_target_hook,
781 'nodist_specific' => 1);
784 register_language ('name' => 'yacc',
786 'config_vars' => ['YACC'],
787 'flags' => ['YFLAGS'],
788 'compile' => '$(YACC) $(AM_YFLAGS) $(YFLAGS)',
790 'compiler' => 'YACCCOMPILE',
791 'extensions' => ['.y'],
792 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
794 'rule_file' => 'yacc',
795 '_finish' => \&lang_yacc_finish,
796 '_target_hook' => \&lang_yacc_target_hook,
797 'nodist_specific' => 1);
798 register_language ('name' => 'yaccxx',
799 'Name' => 'Yacc (C++)',
800 'config_vars' => ['YACC'],
801 'rule_file' => 'yacc',
802 'flags' => ['YFLAGS'],
804 'compiler' => 'YACCCOMPILE',
805 'compile' => '$(YACC) $(AM_YFLAGS) $(YFLAGS)',
806 'extensions' => ['.y++', '.yy', '.yxx', '.ypp'],
807 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/;
809 '_finish' => \&lang_yacc_finish,
810 '_target_hook' => \&lang_yacc_target_hook,
811 'nodist_specific' => 1);
814 register_language ('name' => 'lex',
816 'config_vars' => ['LEX'],
817 'rule_file' => 'lex',
818 'flags' => ['LFLAGS'],
819 'compile' => '$(LEX) $(AM_LFLAGS) $(LFLAGS)',
821 'compiler' => 'LEXCOMPILE',
822 'extensions' => ['.l'],
823 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
825 '_finish' => \&lang_lex_finish,
826 '_target_hook' => \&lang_lex_target_hook,
827 'nodist_specific' => 1);
828 register_language ('name' => 'lexxx',
829 'Name' => 'Lex (C++)',
830 'config_vars' => ['LEX'],
831 'rule_file' => 'lex',
832 'flags' => ['LFLAGS'],
833 'compile' => '$(LEX) $(AM_LFLAGS) $(LFLAGS)',
835 'compiler' => 'LEXCOMPILE',
836 'extensions' => ['.l++', '.ll', '.lxx', '.lpp'],
837 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/;
839 '_finish' => \&lang_lex_finish,
840 '_target_hook' => \&lang_lex_target_hook,
841 'nodist_specific' => 1);
844 register_language ('name' => 'asm',
845 'Name' => 'Assembler',
846 'config_vars' => ['CCAS', 'CCASFLAGS'],
848 'flags' => ['CCASFLAGS'],
849 # Users can set AM_CCASFLAGS to include $(DEFS),
850 # $(INCLUDES), or anything else required. They can also
851 # set CCAS. Or simply use Preprocessed Assembler.
852 'compile' => '$(CCAS) $(AM_CCASFLAGS) $(CCASFLAGS)',
854 'compiler' => 'CCASCOMPILE',
855 'extensions' => ['.s']);
857 # Preprocessed Assembler.
858 register_language ('name' => 'cppasm',
859 'Name' => 'Preprocessed Assembler',
860 'config_vars' => ['CCAS', 'CCASFLAGS'],
863 'flags' => ['CCASFLAGS', 'CPPFLAGS'],
864 'compile' => "\$(CCAS) @cpplike_flags \$(AM_CCASFLAGS) \$(CCASFLAGS)",
866 'compiler' => 'CPPASCOMPILE',
867 'extensions' => ['.S', '.sx']);
870 register_language ('name' => 'f77',
871 'Name' => 'Fortran 77',
872 'config_vars' => ['F77'],
873 'linker' => 'F77LINK',
874 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
875 'flags' => ['FFLAGS'],
876 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
878 'compiler' => 'F77COMPILE',
879 'libtool_tag' => 'F77',
883 'extensions' => ['.f', '.for']);
886 register_language ('name' => 'fc',
888 'config_vars' => ['FC'],
889 'linker' => 'FCLINK',
890 'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
891 'flags' => ['FCFLAGS'],
892 'compile' => '$(FC) $(AM_FCFLAGS) $(FCFLAGS)',
894 'compiler' => 'FCCOMPILE',
895 'libtool_tag' => 'FC',
899 'extensions' => ['.f90', '.f95', '.f03', '.f08']);
901 # Preprocessed Fortran
902 register_language ('name' => 'ppfc',
903 'Name' => 'Preprocessed Fortran',
904 'config_vars' => ['FC'],
905 'linker' => 'FCLINK',
906 'link' => '$(FCLD) $(AM_FCFLAGS) $(FCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
909 'flags' => ['FCFLAGS', 'CPPFLAGS'],
911 'compiler' => 'PPFCCOMPILE',
912 'compile' => "\$(FC) @cpplike_flags \$(AM_FCFLAGS) \$(FCFLAGS)",
913 'libtool_tag' => 'FC',
915 'extensions' => ['.F90','.F95', '.F03', '.F08']);
917 # Preprocessed Fortran 77
919 # The current support for preprocessing Fortran 77 just involves
920 # passing "$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
921 # $(CPPFLAGS)" as additional flags to the Fortran 77 compiler, since
922 # this is how GNU Make does it; see the "GNU Make Manual, Edition 0.51
923 # for 'make' Version 3.76 Beta" (specifically, from info file
924 # '(make)Catalogue of Rules').
926 # A better approach would be to write an Autoconf test
927 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
928 # Fortran 77 compilers know how to do preprocessing. The Autoconf
929 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
930 # preprocessing capabilities, and then fall back on cpp (if cpp were
932 register_language ('name' => 'ppf77',
933 'Name' => 'Preprocessed Fortran 77',
934 'config_vars' => ['F77'],
935 'linker' => 'F77LINK',
936 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
939 'flags' => ['FFLAGS', 'CPPFLAGS'],
941 'compiler' => 'PPF77COMPILE',
942 'compile' => "\$(F77) @cpplike_flags \$(AM_FFLAGS) \$(FFLAGS)",
943 'libtool_tag' => 'F77',
945 'extensions' => ['.F']);
948 register_language ('name' => 'ratfor',
950 'config_vars' => ['F77'],
951 'linker' => 'F77LINK',
952 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
955 'flags' => ['RFLAGS', 'FFLAGS'],
957 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
959 'compiler' => 'RCOMPILE',
960 'libtool_tag' => 'F77',
962 'extensions' => ['.r']);
965 register_language ('name' => 'java',
967 'config_vars' => ['GCJ'],
968 'linker' => 'GCJLINK',
969 'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
971 'flags' => ['GCJFLAGS'],
972 'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
974 'compiler' => 'GCJCOMPILE',
975 'libtool_tag' => 'GCJ',
979 'extensions' => ['.java', '.class', '.zip', '.jar']);
981 ################################################################
983 # Error reporting functions.
985 # err_am ($MESSAGE, [%OPTIONS])
986 # -----------------------------
987 # Uncategorized errors about the current Makefile.am.
990 msg_am ('error', @_);
993 # err_ac ($MESSAGE, [%OPTIONS])
994 # -----------------------------
995 # Uncategorized errors about configure.ac.
998 msg_ac ('error', @_);
1001 # msg_am ($CHANNEL, $MESSAGE, [%OPTIONS])
1002 # ---------------------------------------
1003 # Messages about about the current Makefile.am.
1006 my ($channel, $msg, %opts) = @_;
1007 msg $channel, "${am_file}.am", $msg, %opts;
1010 # msg_ac ($CHANNEL, $MESSAGE, [%OPTIONS])
1011 # ---------------------------------------
1012 # Messages about about configure.ac.
1015 my ($channel, $msg, %opts) = @_;
1016 msg $channel, $configure_ac, $msg, %opts;
1019 ################################################################
1023 # Return a configure-style substitution using the indicated text.
1024 # We do this to avoid having the substitutions directly in automake.in;
1025 # when we do that they are sometimes removed and this causes confusion
1030 return '@' . $text . '@';
1033 ################################################################
1037 # backname ($RELDIR)
1038 # -------------------
1039 # If I "cd $RELDIR", then to come back, I should "cd $BACKPATH".
1040 # For instance 'src/foo' => '../..'.
1041 # Works with non strictly increasing paths, i.e., 'src/../lib' => '..'.
1046 foreach (split (/\//, $file))
1048 next if $_ eq '.' || $_ eq '';
1052 or prog_error ("trying to reverse path '$file' pointing outside tree");
1059 return join ('/', @res) || '.';
1062 ################################################################
1064 # Silent rules handling functions.
1066 # verbose_var (NAME)
1067 # ------------------
1068 # The public variable stem used to implement silent rules.
1072 return 'AM_V_' . $name;
1075 # verbose_private_var (NAME)
1076 # --------------------------
1077 # The naming policy for the private variables for silent rules.
1078 sub verbose_private_var
1081 return 'am__v_' . $name;
1084 # define_verbose_var (NAME, VAL-IF-SILENT, [VAL-IF-VERBOSE])
1085 # ----------------------------------------------------------
1086 # For silent rules, setup VAR and dispatcher, to expand to
1087 # VAL-IF-SILENT if silent, to VAL-IF-VERBOSE (defaulting to
1089 sub define_verbose_var
1091 my ($name, $silent_val, $verbose_val) = @_;
1092 $verbose_val = '' unless defined $verbose_val;
1093 my $var = verbose_var ($name);
1094 my $pvar = verbose_private_var ($name);
1095 my $silent_var = $pvar . '_0';
1096 my $verbose_var = $pvar . '_1';
1097 # For typical 'make's, 'configure' replaces AM_V (inside @@) with $(V)
1098 # and AM_DEFAULT_V (inside @@) with $(AM_DEFAULT_VERBOSITY).
1099 # For strict POSIX 2008 'make's, it replaces them with 0 or 1 instead.
1100 # See AM_SILENT_RULES in m4/silent.m4.
1101 define_variable ($var, '$(' . $pvar . '_@'.'AM_V'.'@)', INTERNAL);
1102 define_variable ($pvar . '_', '$(' . $pvar . '_@'.'AM_DEFAULT_V'.'@)',
1104 Automake::Variable::define ($silent_var, VAR_AUTOMAKE, '', TRUE,
1105 $silent_val, '', INTERNAL, VAR_ASIS)
1106 if (! vardef ($silent_var, TRUE));
1107 Automake::Variable::define ($verbose_var, VAR_AUTOMAKE, '', TRUE,
1108 $verbose_val, '', INTERNAL, VAR_ASIS)
1109 if (! vardef ($verbose_var, TRUE));
1112 # verbose_flag (NAME)
1113 # -------------------
1114 # Contents of '%VERBOSE%' variable to expand before rule command.
1118 return '$(' . verbose_var ($name) . ')';
1121 sub verbose_nodep_flag
1124 return '$(' . verbose_var ($name) . subst ('am__nodep') . ')';
1129 # Contents of %SILENT%: variable to expand to '@' when silent.
1132 return verbose_flag ('at');
1135 # define_verbose_tagvar (NAME)
1136 # ----------------------------
1137 # Engage the needed silent rules machinery for tag NAME.
1138 sub define_verbose_tagvar
1141 define_verbose_var ($name, '@echo " '. $name . ' ' x (8 - length ($name)) . '" $@;');
1144 # Engage the needed silent rules machinery for assorted texinfo commands.
1145 sub define_verbose_texinfo ()
1147 my @tagvars = ('DVIPS', 'MAKEINFO', 'INFOHTML', 'TEXI2DVI', 'TEXI2PDF');
1148 foreach my $tag (@tagvars)
1150 define_verbose_tagvar($tag);
1152 define_verbose_var('texinfo', '-q');
1153 define_verbose_var('texidevnull', '> /dev/null');
1156 # Engage the needed silent rules machinery for 'libtool --silent'.
1157 sub define_verbose_libtool ()
1159 define_verbose_var ('lt', '--silent');
1160 return verbose_flag ('lt');
1163 sub handle_silent ()
1165 # Define "$(AM_V_P)", expanding to a shell conditional that can be
1166 # used in make recipes to determine whether we are being run in
1167 # silent mode or not. The choice of the name derives from the LISP
1168 # convention of appending the letter 'P' to denote a predicate (see
1169 # also "the '-P' convention" in the Jargon File); we do so for lack
1170 # of a better convention.
1171 define_verbose_var ('P', 'false', ':');
1172 # *Always* provide the user with '$(AM_V_GEN)', unconditionally.
1173 define_verbose_tagvar ('GEN');
1174 define_verbose_var ('at', '@');
1178 ################################################################
1181 # Handle AUTOMAKE_OPTIONS variable. Return 0 on error, 1 otherwise.
1182 sub handle_options ()
1184 my $var = var ('AUTOMAKE_OPTIONS');
1187 if ($var->has_conditional_contents)
1189 msg_var ('unsupported', $var,
1190 "'AUTOMAKE_OPTIONS' cannot have conditional contents");
1192 my @options = map { { option => $_->[1], where => $_->[0] } }
1193 $var->value_as_list_recursive (cond_filter => TRUE,
1195 return 0 unless process_option_list (@options);
1198 if ($strictness == GNITS)
1200 set_option ('readme-alpha', INTERNAL);
1201 set_option ('std-options', INTERNAL);
1202 set_option ('check-news', INTERNAL);
1208 # shadow_unconditionally ($varname, $where)
1209 # -----------------------------------------
1210 # Return a $(variable) that contains all possible values
1211 # $varname can take.
1212 # If the VAR wasn't defined conditionally, return $(VAR).
1213 # Otherwise we create an am__VAR_DIST variable which contains
1214 # all possible values, and return $(am__VAR_DIST).
1215 sub shadow_unconditionally
1217 my ($varname, $where) = @_;
1218 my $var = var $varname;
1219 if ($var->has_conditional_contents)
1221 $varname = "am__${varname}_DIST";
1222 my @files = uniq ($var->value_as_list_recursive);
1223 define_pretty_variable ($varname, TRUE, $where, @files);
1225 return "\$($varname)"
1228 # check_user_variables (@LIST)
1229 # ----------------------------
1230 # Make sure each variable VAR in @LIST does not exist, suggest using AM_VAR
1232 sub check_user_variables
1234 my @dont_override = @_;
1235 foreach my $flag (@dont_override)
1237 my $var = var $flag;
1240 for my $cond ($var->conditions->conds)
1242 if ($var->rdef ($cond)->owner == VAR_MAKEFILE)
1244 msg_cond_var ('gnu', $cond, $flag,
1245 "'$flag' is a user variable, "
1246 . "you should not override it;\n"
1247 . "use 'AM_$flag' instead");
1254 # Call finish function for each language that was used.
1255 sub handle_languages ()
1257 if (! option 'no-dependencies')
1259 # Include auto-dep code. Don't include it if DEP_FILES would
1261 if (keys %extension_seen && keys %dep_files)
1263 my @dep_files = sort keys %dep_files;
1264 # Set location of depcomp.
1265 define_variable ('depcomp',
1266 "\$(SHELL) $am_config_aux_dir/depcomp",
1268 define_variable ('am__maybe_remake_depfiles', 'depfiles', INTERNAL);
1269 define_variable ('am__depfiles_remade', "@dep_files", INTERNAL);
1270 $output_rules .= "\n";
1272 foreach my $depfile (@dep_files)
1274 push @dist_rms, "\t-rm -f $depfile";
1275 # Generate each 'include' directive individually. Several
1276 # make implementations (IRIX 6, Solaris 10, FreeBSD 8) will
1277 # fail to properly include several files resulting from a
1278 # variable expansion. Just Generating many separate includes
1279 # seems thus safest.
1280 $output_rules .= subst ('AMDEP_TRUE') .
1281 subst ('am__include') .
1283 subst('am__quote') .
1285 subst('am__quote') .
1287 "# am--include-marker\n";
1290 require_conf_file ("$am_file.am", FOREIGN, 'depcomp');
1292 $output_rules .= file_contents (
1293 'depend', new Automake::Location,
1294 'DISTRMS' => join ("\n", @dist_rms));
1299 define_variable ('depcomp', '', INTERNAL);
1300 define_variable ('am__maybe_remake_depfiles', '', INTERNAL);
1305 # Is the C linker needed?
1307 foreach my $ext (sort keys %extension_seen)
1309 next unless $extension_map{$ext};
1311 my $lang = $languages{$extension_map{$ext}};
1313 my $rule_file = $lang->rule_file || 'depend2';
1315 # Get information on $LANG.
1316 my $pfx = $lang->autodep;
1317 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1319 my ($AMDEP, $FASTDEP) =
1320 (option 'no-dependencies' || $lang->autodep eq 'no')
1321 ? ('FALSE', 'FALSE') : ('AMDEP', "am__fastdep$fpfx");
1323 my $verbose = verbose_flag ($lang->ccer || 'GEN');
1324 my $verbose_nodep = ($AMDEP eq 'FALSE')
1325 ? $verbose : verbose_nodep_flag ($lang->ccer || 'GEN');
1326 my $silent = silent_flag ();
1328 my %transform = ('EXT' => $ext,
1332 'FASTDEP' => $FASTDEP,
1333 # These are not used, but they need to be defined
1334 # so transform() does not complain.
1335 'DERIVED-EXT' => 'BUG',
1337 VERBOSE => $verbose,
1338 'VERBOSE-NODEP' => $verbose_nodep,
1342 # Generate the appropriate rules for this extension.
1343 if (((! option 'no-dependencies') && $lang->autodep ne 'no')
1344 || defined $lang->compile)
1346 # Compute a possible derived extension.
1347 # This is not used by depend2.am.
1348 my $der_ext = ($lang->output_extensions->($ext))[0];
1350 # Even when subdir sources are present, an inference rule
1351 # like '.c.o:' can be used to build corresponding objects
1352 # in the sane subdirectory too. We should be careful to also
1353 # place dependency files into the appropriate subdirectory,
1354 # e.g., 'sub/$(DEPDIR)/'. The value of this directory needs
1355 # to be computed on-the-fly (that is done by our makefile
1356 # recipes in 'depend2.am').
1358 file_contents ($rule_file,
1359 new Automake::Location,
1363 'DERIVED-EXT' => $der_ext,
1368 SOURCEFLAG => $sourceflags{$ext} || '',
1373 COMPILE => '$(' . $lang->compiler . ')',
1374 LTCOMPILE => '$(LT' . $lang->compiler . ')',
1378 # Now include code for each specially handled object with this
1380 my %seen_files = ();
1381 foreach my $file (@{$lang_specific_files{$lang->name}})
1383 my ($derived, $source, $obj, $myext, $srcext, %file_transform) = @$file;
1385 # We might see a given object twice, for instance if it is
1386 # used under different conditions.
1387 next if defined $seen_files{$obj};
1388 $seen_files{$obj} = 1;
1390 prog_error ("found " . $lang->name .
1391 " in handle_languages, but compiler not defined")
1392 unless defined $lang->compile;
1394 my $obj_compile = $lang->compile;
1396 # Rewrite each occurrence of 'AM_$flag' in the compile
1397 # rule into '${derived}_$flag' if it exists.
1398 for my $flag (@{$lang->flags})
1400 my $val = "${derived}_$flag";
1401 $obj_compile =~ s/\(AM_$flag\)/\($val\)/
1405 my $libtool_tag = '';
1406 if ($lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag})
1408 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
1411 my $ptltflags = "${derived}_LIBTOOLFLAGS";
1412 $ptltflags = 'AM_LIBTOOLFLAGS' unless set_seen $ptltflags;
1414 my $ltverbose = define_verbose_libtool ();
1416 "\$(LIBTOOL) $ltverbose $libtool_tag\$($ptltflags) \$(LIBTOOLFLAGS) "
1417 . "--mode=compile $obj_compile";
1419 # For non-suffix rules, we must emulate a VPATH search.
1420 my $xsource = "`test -f '$source' || echo '\$(srcdir)/'`$source";
1423 file_contents ($rule_file,
1424 new Automake::Location,
1430 XSOURCE => $xsource,
1431 SOURCEFLAG => $sourceflags{$srcext} || '',
1432 # Use $myext and not '.o' here, in case
1433 # we are actually building a new source
1434 # file -- e.g. via yacc.
1435 OBJ => "$obj$myext",
1436 OBJOBJ => "$obj.obj",
1439 VERBOSE => $verbose,
1440 'VERBOSE-NODEP' => $verbose_nodep,
1442 COMPILE => $obj_compile,
1443 LTCOMPILE => $obj_ltcompile,
1447 # The rest of the loop is done once per language.
1448 next if defined $done{$lang};
1451 # Load the language dependent Makefile chunks.
1452 my %lang = map { uc ($_) => 0 } keys %languages;
1453 $lang{uc ($lang->name)} = 1;
1454 $output_rules .= file_contents ('lang-compile',
1455 new Automake::Location,
1458 # If the source to a program consists entirely of code from a
1459 # 'pure' language, for instance C++ or Fortran 77, then we
1460 # don't need the C compiler code. However if we run into
1461 # something unusual then we do generate the C code. There are
1462 # probably corner cases here that do not work properly.
1463 # People linking Java code to Fortran code deserve pain.
1464 $needs_c ||= ! $lang->pure;
1466 define_compiler_variable ($lang)
1467 if ($lang->compile);
1469 define_linker_variable ($lang)
1472 require_variables ("$am_file.am", $lang->Name . " source seen",
1473 TRUE, @{$lang->config_vars});
1475 # Call the finisher.
1478 # Flags listed in '->flags' are user variables (per GNU Standards),
1479 # they should not be overridden in the Makefile...
1480 my @dont_override = @{$lang->flags};
1481 # ... and so is LDFLAGS.
1482 push @dont_override, 'LDFLAGS' if $lang->link;
1484 check_user_variables @dont_override;
1487 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1488 # suffix rule was learned), don't bother with the C stuff. But if
1489 # anything else creeps in, then use it.
1490 my @languages_seen = map { $languages{$extension_map{$_}}->name }
1491 (keys %extension_seen);
1492 @languages_seen = uniq (@languages_seen);
1493 $needs_c = 1 if @languages_seen > 1;
1494 if ($need_link || $needs_c)
1496 define_compiler_variable ($languages{'c'})
1497 unless defined $done{$languages{'c'}};
1498 define_linker_variable ($languages{'c'});
1503 # append_exeext { PREDICATE } $MACRO
1504 # ----------------------------------
1505 # Append $(EXEEXT) to each filename in $F appearing in the Makefile
1506 # variable $MACRO if &PREDICATE($F) is true. @substitutions@ are
1509 # This is typically used on all filenames of *_PROGRAMS, and filenames
1510 # of TESTS that are programs.
1511 sub append_exeext (&$)
1513 my ($pred, $macro) = @_;
1515 transform_variable_recursively
1516 ($macro, $macro, 'am__EXEEXT', 0, INTERNAL,
1518 my ($subvar, $val, $cond, $full_cond) = @_;
1519 # Append $(EXEEXT) unless the user did it already, or it's a
1522 if $val !~ /(?:\$\(EXEEXT\)$|^[@]\w+[@]$)/ && &$pred ($val);
1528 # Check to make sure a source defined in LIBOBJS is not explicitly
1529 # mentioned. This is a separate function (as opposed to being inlined
1530 # in handle_source_transform) because it isn't always appropriate to
1532 sub check_libobjs_sources
1534 my ($one_file, $unxformed) = @_;
1536 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1537 'dist_EXTRA_', 'nodist_EXTRA_')
1540 my $varname = $prefix . $one_file . '_SOURCES';
1541 my $var = var ($varname);
1544 @files = $var->value_as_list_recursive;
1546 elsif ($prefix eq '')
1548 @files = ($unxformed . '.c');
1555 foreach my $file (@files)
1557 err_var ($prefix . $one_file . '_SOURCES',
1558 "automatically discovered file '$file' should not" .
1559 " be explicitly mentioned")
1560 if defined $libsources{$file};
1567 # handle_single_transform ($VAR, $TOPPARENT, $DERIVED, $OBJ, $FILE, %TRANSFORM)
1568 # -----------------------------------------------------------------------------
1569 # Does much of the actual work for handle_source_transform.
1571 # $VAR is the name of the variable that the source filenames come from
1572 # $TOPPARENT is the name of the _SOURCES variable which is being processed
1573 # $DERIVED is the name of resulting executable or library
1574 # $OBJ is the object extension (e.g., '.lo')
1575 # $FILE the source file to transform
1576 # %TRANSFORM contains extras arguments to pass to file_contents
1577 # when producing explicit rules
1578 # Result is a list of the names of objects
1579 # %linkers_used will be updated with any linkers needed
1580 sub handle_single_transform
1582 my ($var, $topparent, $derived, $obj, $_file, %transform) = @_;
1583 my @files = ($_file);
1586 # Turn sources into objects. We use a while loop like this
1587 # because we might add to @files in the loop.
1588 while (scalar @files > 0)
1592 # Configure substitutions in _SOURCES variables are errors.
1595 my $parent_msg = '';
1596 $parent_msg = "\nand is referred to from '$topparent'"
1597 if $topparent ne $var->name;
1599 "'" . $var->name . "' includes configure substitution '$_'"
1600 . $parent_msg . ";\nconfigure " .
1601 "substitutions are not allowed in _SOURCES variables");
1605 # Split file name into base and extension.
1606 next if ! /^(?:(.*)\/)?([^\/]*)($KNOWN_EXTENSIONS_PATTERN)$/;
1608 my $directory = $1 || '';
1612 # We must generate a rule for the object if it requires its own flags.
1614 my ($linker, $object);
1616 # This records whether we've seen a derived source file (e.g., yacc
1620 # This holds the 'aggregate context' of the file we are
1621 # currently examining. If the file is compiled with
1622 # per-object flags, then it will be the name of the object.
1623 # Otherwise it will be 'AM'. This is used by the target hook
1624 # language function.
1625 my $aggregate = 'AM';
1627 $extension = derive_suffix ($extension, $obj);
1629 if ($extension_map{$extension} &&
1630 ($lang = $languages{$extension_map{$extension}}))
1632 # Found the language, so see what it says.
1633 saw_extension ($extension);
1635 # Do we have per-executable flags for this executable?
1636 my $have_per_exec_flags = 0;
1637 my @peflags = @{$lang->flags};
1638 push @peflags, 'LIBTOOLFLAGS' if $obj eq '.lo';
1639 foreach my $flag (@peflags)
1641 if (set_seen ("${derived}_$flag"))
1643 $have_per_exec_flags = 1;
1648 # NOTE: computed subr calls here.
1650 # The language ignore function can ask not to preprocess
1651 # a source file further.
1652 my $subr_ignore = \&{'lang_' . $lang->name . '_ignore'};
1653 next if defined &$subr_ignore
1654 and &$subr_ignore ($directory, $base, $extension);
1655 # The language rewrite function can return a new source
1656 # extension which should be applied. This means this
1657 # particular language generates another source file which
1658 # we must then process further. This happens, for example,
1659 # with yacc and lex.
1660 my $subr_rewrite = \&{'lang_' . $lang->name . '_rewrite'};
1661 $subr_rewrite = sub { } unless defined &$subr_rewrite;
1662 my $source_extension = &$subr_rewrite ($directory, $base,
1664 $have_per_exec_flags,
1667 # Now extract linker and other info.
1668 $linker = $lang->linker;
1671 if (defined $source_extension)
1673 $this_obj_ext = $source_extension;
1674 $derived_source = 1;
1678 $this_obj_ext = $obj;
1679 $derived_source = 0;
1680 # Don't ever place built object files in $(srcdir),
1681 # even when sources are specified explicitly as (say)
1682 # '$(srcdir)/foo.c' or '$(top_srcdir)/foo.c'.
1683 # See automake bug#13928.
1684 my @d = split '/', $directory;
1685 if (@d > 0 && option 'subdir-objects')
1688 if ($d eq '$(srcdir)' or $d eq '${srcdir}')
1692 elsif ($d eq '$(top_srcdir)' or $d eq '${top_srcdir}')
1694 $d[0] = '$(top_builddir)';
1696 $directory = join '/', @d;
1699 $object = $base . $this_obj_ext;
1701 if ($have_per_exec_flags)
1703 # We have a per-executable flag in effect for this
1704 # object. In this case we rewrite the object's
1705 # name to ensure it is unique.
1707 # We choose the name 'DERIVED_OBJECT' to ensure (1) uniqueness,
1708 # and (2) continuity between invocations. However, this will
1709 # result in a name that is too long for losing systems, in some
1710 # situations. So we attempt to shorten automatically, and
1711 # provide _SHORTNAME to override as a last resort. If
1712 # subdir-object is in effect, it's usually unnecessary to use
1713 # the complete 'DERIVED_OBJECT' (that is often the result from
1714 # %canon_reldir%/%C% usage) since objects are placed next to
1715 # their source file. Generally, this means it is already
1716 # unique within that directory (see below for an exception).
1717 # Thus, we try to avoid unnecessarily long file names by
1718 # stripping the directory components of 'DERIVED_OBJECT'.
1719 # This allows avoiding explicit _SHORTNAME usage in many
1720 # cases. EXCEPTION: If two (or more) targets in different
1721 # directories but with the same base name (after
1722 # canonicalization), using target-specific FLAGS, link the
1723 # same object, then this logic clashes. Thus, we don't strip
1724 # if this is detected.
1725 my $dname = $derived;
1726 if ($directory ne ''
1727 && none { $dname =~ /$_$/ } @dup_shortnames)
1729 # At this point, we don't clear information about what
1730 # parts of $derived are truly file name components. We can
1731 # determine that by comparing against the canonicalization
1733 my $dir = $directory . "/";
1734 my $cdir = canonicalize ($dir);
1735 my $dir_len = length ($dir);
1736 # Make sure we only strip full file name components. This
1737 # is done by repeatedly trying to find cdir at the
1738 # beginning. Each iteration removes one file name
1739 # component from the end of cdir.
1740 while ($dir_len > 0 && index ($derived, $cdir) != 0)
1742 # Eventually $dir_len becomes 0.
1743 $dir_len = rindex ($dir, "/", $dir_len - 2) + 1;
1744 $cdir = substr ($cdir, 0, $dir_len);
1746 $dname = substr ($derived, $dir_len);
1748 my $var = var ($derived . '_SHORTNAME');
1751 # FIXME: should use the same Condition as
1752 # the _SOURCES variable. But this is really
1753 # silly overkill -- nobody should have
1754 # conditional shortnames.
1755 $dname = $var->variable_value;
1757 $object = $dname . '-' . $object;
1759 prog_error ($lang->name . " flags defined without compiler")
1760 if ! defined $lang->compile;
1765 # If rewrite said it was ok, put the object into a subdir.
1766 $object = $directory . '/' . $object
1767 unless $directory eq '';
1769 # If the object file has been renamed (because per-target
1770 # flags are used) we cannot compile the file with an
1771 # inference rule: we need an explicit rule.
1773 # If both source and object files are in a subdirectory
1774 # then the inference will work.
1776 # The latter case deserves a historical note. When the
1777 # subdir-objects option was added on 1999-04-11 it was
1778 # thought that inferences rules would work for
1779 # subdirectory objects too. Later, on 1999-11-22,
1780 # automake was changed to output explicit rules even for
1781 # subdir-objects. Nobody remembers why, but this occurred
1782 # soon after the merge of the user-dep-gen-branch so it
1783 # might be related. In late 2003 people complained about
1784 # the size of the generated Makefile.ins (libgcj, with
1785 # 2200+ subdir objects was reported to have a 9MB
1786 # Makefile), so we now rely on inference rules again.
1787 # Maybe we'll run across the same issue as in the past,
1788 # but at least this time we can document it. However since
1789 # dependency tracking has evolved it is possible that
1790 # our old problem no longer exists.
1791 # Using inference rules for subdir-objects has been tested
1792 # with GNU make, Solaris make, Ultrix make, BSD make,
1793 # HP-UX make, and OSF1 make successfully.
1795 # We must also use specific rules for a nodist_ source
1796 # if its language requests it.
1797 || ($lang->nodist_specific && ! $transform{'DIST_SOURCE'}))
1799 my $obj_sans_ext = substr ($object, 0,
1800 - length ($this_obj_ext));
1802 if ($directory ne '')
1804 $full_ansi = $directory . '/' . $base . $extension;
1808 $full_ansi = $base . $extension;
1811 my @specifics = ($full_ansi, $obj_sans_ext,
1812 # Only use $this_obj_ext in the derived
1813 # source case because in the other case we
1814 # *don't* want $(OBJEXT) to appear here.
1815 ($derived_source ? $this_obj_ext : '.o'),
1818 # If we renamed the object then we want to use the
1819 # per-executable flag name. But if this is simply a
1820 # subdir build then we still want to use the AM_ flag
1824 unshift @specifics, $derived;
1825 $aggregate = $derived;
1829 unshift @specifics, 'AM';
1832 # Each item on this list is a reference to a list consisting
1833 # of four values followed by additional transform flags for
1834 # file_contents. The four values are the derived flag prefix
1835 # (e.g. for 'foo_CFLAGS', it is 'foo'), the name of the
1836 # source file, the base name of the output file, and
1837 # the extension for the object file.
1838 push (@{$lang_specific_files{$lang->name}},
1839 [@specifics, %transform]);
1842 elsif ($extension eq $obj)
1844 # This is probably the result of a direct suffix rule.
1845 # In this case we just accept the rewrite.
1846 $object = "$base$extension";
1847 $object = "$directory/$object" if $directory ne '';
1852 # No error message here. Used to have one, but it was
1854 # FIXME: we could potentially do more processing here,
1855 # perhaps treating the new extension as though it were a
1856 # new source extension (as above). This would require
1857 # more restructuring than is appropriate right now.
1861 # FIXME: this is likely an internal error now that we use
1862 # FIXME: subdir-objects unconditionally ...
1863 err_am "object '$object' created by '$full' and '$object_map{$object}'"
1864 if (defined $object_map{$object}
1865 && $object_map{$object} ne $full);
1867 my $comp_val = (($object =~ /\.lo$/)
1868 ? COMPILE_LIBTOOL : COMPILE_ORDINARY);
1869 (my $comp_obj = $object) =~ s/\.lo$/.\$(OBJEXT)/;
1870 if (defined $object_compilation_map{$comp_obj}
1871 && $object_compilation_map{$comp_obj} != 0
1872 # Only see the error once.
1873 && ($object_compilation_map{$comp_obj}
1874 != (COMPILE_LIBTOOL | COMPILE_ORDINARY))
1875 && $object_compilation_map{$comp_obj} != $comp_val)
1877 err_am "object '$comp_obj' created both with libtool and without";
1879 $object_compilation_map{$comp_obj} |= $comp_val;
1883 # Let the language do some special magic if required.
1884 $lang->target_hook ($aggregate, $object, $full, %transform);
1887 if ($derived_source)
1889 prog_error ($lang->name . " has automatic dependency tracking")
1890 if $lang->autodep ne 'no';
1891 # Make sure this new source file is handled next. That will
1892 # make it appear to be at the right place in the list.
1893 unshift (@files, $object);
1894 # Distribute derived sources unless the source they are
1895 # derived from is not.
1896 push_dist_common ($object)
1897 unless ($topparent =~ /^(?:nobase_)?nodist_/);
1901 $linkers_used{$linker} = 1;
1903 push (@result, $object);
1905 if (! defined $object_map{$object})
1908 $object_map{$object} = $full;
1910 # If resulting object is in subdir, we need to make
1911 # sure the subdir exists at build time.
1912 if ($object =~ /\//)
1914 # FIXME: check that $DIRECTORY is somewhere in the
1917 # For Java, the way we're handling it right now, a
1918 # '..' component doesn't make sense.
1919 if ($lang && $lang->name eq 'java' && $object =~ /(\/|^)\.\.\//)
1921 err_am "'$full' should not contain a '..' component";
1924 # Make sure *all* objects files in the subdirectory are
1925 # removed by "make mostlyclean". Not only this is more
1926 # efficient than listing the object files to be removed
1927 # individually (which would cause an 'rm' invocation for
1928 # each of them -- very inefficient, see bug#10697), it
1929 # would also leave stale object files in the subdirectory
1930 # whenever a source file there is removed or renamed.
1931 $compile_clean_files{"$directory/*.\$(OBJEXT)"} = MOSTLY_CLEAN;
1932 if ($object =~ /\.lo$/)
1934 # If we have a libtool object, then we also must remove
1935 # any '.lo' objects in its same subdirectory.
1936 $compile_clean_files{"$directory/*.lo"} = MOSTLY_CLEAN;
1937 # Remember to cleanup .libs/ in this directory.
1938 $libtool_clean_directories{$directory} = 1;
1941 push (@dep_list, require_build_directory ($directory));
1943 # If we're generating dependencies, we also want
1944 # to make sure that the appropriate subdir of the
1945 # .deps directory is created.
1947 require_build_directory ($directory . '/$(DEPDIR)'))
1948 unless option 'no-dependencies';
1951 pretty_print_rule ($object . ':', "\t", @dep_list)
1952 if scalar @dep_list > 0;
1955 # Transform .o or $o file into .P file (for automatic
1957 # Properly flatten multiple adjacent slashes, as Solaris 10 make
1958 # might fail over them in an include statement.
1959 # Leading double slashes may be special, as per Posix, so deal
1960 # with them carefully.
1961 if ($lang && $lang->autodep ne 'no')
1963 my $depfile = $object;
1964 $depfile =~ s/\.([^.]*)$/.P$1/;
1965 $depfile =~ s/\$\(OBJEXT\)$/o/;
1966 my $maybe_extra_leading_slash = '';
1967 $maybe_extra_leading_slash = '/' if $depfile =~ m,^//[^/],;
1968 $depfile =~ s,/+,/,g;
1969 my $basename = basename ($depfile);
1970 # This might make $dirname empty, but we account for that below.
1971 (my $dirname = dirname ($depfile)) =~ s/\/*$//;
1972 $dirname = $maybe_extra_leading_slash . $dirname;
1973 $dep_files{$dirname . '/$(DEPDIR)/' . $basename} = 1;
1982 # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
1983 # $OBJ, $PARENT, $TOPPARENT, $WHERE, %TRANSFORM)
1984 # ---------------------------------------------------------------------------
1985 # Define an _OBJECTS variable for a _SOURCES variable (or subvariable)
1988 # $VAR is the name of the _SOURCES variable
1989 # $OBJVAR is the name of the _OBJECTS variable if known (otherwise
1990 # it will be generated and returned).
1991 # $NODEFINE is a boolean: if true, $OBJVAR will not be defined (but
1992 # work done to determine the linker will be).
1993 # $ONE_FILE is the canonical (transformed) name of object to build
1994 # $OBJ is the object extension (i.e. either '.o' or '.lo').
1995 # $TOPPARENT is the _SOURCES variable being processed.
1996 # $WHERE context into which this definition is done
1997 # %TRANSFORM extra arguments to pass to file_contents when producing
2000 # Result is a pair ($LINKER, $OBJVAR):
2001 # $LINKER is a boolean, true if a linker is needed to deal with the objects
2002 sub define_objects_from_sources
2004 my ($var, $objvar, $nodefine, $one_file,
2005 $obj, $topparent, $where, %transform) = @_;
2007 my $needlinker = "";
2009 transform_variable_recursively
2010 ($var, $objvar, 'am__objects', $nodefine, $where,
2011 # The transform code to run on each filename.
2013 my ($subvar, $val, $cond, $full_cond) = @_;
2014 my @trans = handle_single_transform ($subvar, $topparent,
2015 $one_file, $obj, $val,
2017 $needlinker = "true" if @trans;
2025 # handle_source_transform ($CANON_TARGET, $TARGET, $OBJEXT, $WHERE, %TRANSFORM)
2026 # -----------------------------------------------------------------------------
2027 # Handle SOURCE->OBJECT transform for one program or library.
2029 # canonical (transformed) name of target to build
2030 # actual target of object to build
2031 # object extension (i.e., either '.o' or '$o')
2032 # location of the source variable
2033 # extra arguments to pass to file_contents when producing rules
2034 # Return the name of the linker variable that must be used.
2035 # Empty return means just use 'LINK'.
2036 sub handle_source_transform
2038 # one_file is canonical name. unxformed is given name. obj is
2040 my ($one_file, $unxformed, $obj, $where, %transform) = @_;
2044 # No point in continuing if _OBJECTS is defined.
2045 return if reject_var ($one_file . '_OBJECTS',
2046 $one_file . '_OBJECTS should not be defined');
2051 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2052 'dist_EXTRA_', 'nodist_EXTRA_')
2054 my $varname = $prefix . $one_file . "_SOURCES";
2055 my $var = var $varname;
2058 # We are going to define _OBJECTS variables using the prefix.
2059 # Then we glom them all together. So we can't use the null
2060 # prefix here as we need it later.
2061 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2063 # Keep track of which prefixes we saw.
2064 $used_pfx{$xpfx} = 1
2065 unless $prefix =~ /EXTRA_/;
2067 push @sources, "\$($varname)";
2068 push @dist_sources, shadow_unconditionally ($varname, $where)
2069 unless (option ('no-dist') || $prefix =~ /^nodist_/);
2072 define_objects_from_sources ($varname,
2073 $xpfx . $one_file . '_OBJECTS',
2074 !!($prefix =~ /EXTRA_/),
2075 $one_file, $obj, $varname, $where,
2076 DIST_SOURCE => ($prefix !~ /^nodist_/),
2081 $linker ||= resolve_linker (%linkers_used);
2084 my @keys = sort keys %used_pfx;
2085 if (scalar @keys == 0)
2087 # The default source for libfoo.la is libfoo.c, but for
2088 # backward compatibility we first look at libfoo_la.c,
2089 # if no default source suffix is given.
2090 my $old_default_source = "$one_file.c";
2091 my $ext_var = var ('AM_DEFAULT_SOURCE_EXT');
2092 my $default_source_ext = $ext_var ? variable_value ($ext_var) : '.c';
2093 msg_var ('unsupported', $ext_var, $ext_var->name . " can assume at most one value")
2094 if $default_source_ext =~ /[\t ]/;
2095 (my $default_source = $unxformed) =~ s,(\.[^./\\]*)?$,$default_source_ext,;
2096 # TODO: Remove this backward-compatibility hack in Automake 2.0.
2097 if ($old_default_source ne $default_source
2099 && (rule $old_default_source
2100 || rule '$(srcdir)/' . $old_default_source
2101 || rule '${srcdir}/' . $old_default_source
2102 || -f $old_default_source))
2104 my $loc = $where->clone;
2106 msg ('obsolete', $loc,
2107 "the default source for '$unxformed' has been changed "
2108 . "to '$default_source'.\n(Using '$old_default_source' for "
2109 . "backward compatibility.)");
2110 $default_source = $old_default_source;
2112 # If a rule exists to build this source with a $(srcdir)
2113 # prefix, use that prefix in our variables too. This is for
2114 # the sake of BSD Make.
2115 if (rule '$(srcdir)/' . $default_source
2116 || rule '${srcdir}/' . $default_source)
2118 $default_source = '$(srcdir)/' . $default_source;
2121 define_variable ($one_file . "_SOURCES", $default_source, $where);
2122 push (@sources, $default_source);
2123 push (@dist_sources, $default_source);
2127 handle_single_transform ($one_file . '_SOURCES',
2128 $one_file . '_SOURCES',
2130 $default_source, %transform);
2131 $linker ||= resolve_linker (%linkers_used);
2132 define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @result);
2136 @keys = map { '$(' . $_ . $one_file . '_OBJECTS)' } @keys;
2137 define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @keys);
2140 # If we want to use 'LINK' we must make sure it is defined.
2150 # handle_lib_objects ($XNAME, $VAR)
2151 # ---------------------------------
2152 # Special-case ALLOCA and LIBOBJS substitutions in _LDADD or _LIBADD variables.
2153 # Also, generate _DEPENDENCIES variable if appropriate.
2155 # transformed name of object being built, or empty string if no object
2156 # name of _LDADD/_LIBADD-type variable to examine
2157 # Returns 1 if LIBOBJS seen, 0 otherwise.
2158 sub handle_lib_objects
2160 my ($xname, $varname) = @_;
2162 my $var = var ($varname);
2163 prog_error "'$varname' undefined"
2165 prog_error "unexpected variable name '$varname'"
2166 unless $varname =~ /^(.*)(?:LIB|LD)ADD$/;
2167 my $prefix = $1 || 'AM_';
2169 my $seen_libobjs = 0;
2172 transform_variable_recursively
2173 ($varname, $xname . '_DEPENDENCIES', 'am__DEPENDENCIES',
2175 # Transformation function, run on each filename.
2177 my ($subvar, $val, $cond, $full_cond) = @_;
2181 # Skip -lfoo and -Ldir silently; these are explicitly allowed.
2182 if ($val !~ /^-[lL]/ &&
2183 # Skip -dlopen and -dlpreopen; these are explicitly allowed
2184 # for Libtool libraries or programs. (Actually we are a bit
2185 # lax here since this code also applies to non-libtool
2186 # libraries or programs, for which -dlopen and -dlopreopen
2187 # are pure nonsense. Diagnosing this doesn't seem very
2188 # important: the developer will quickly get complaints from
2190 $val !~ /^-dl(?:pre)?open$/ &&
2191 # Only get this error once.
2195 # FIXME: should display a stack of nested variables
2196 # as context when $var != $subvar.
2197 err_var ($var, "linker flags such as '$val' belong in "
2198 . "'${prefix}LDFLAGS'");
2202 elsif ($val !~ /^\@.*\@$/)
2204 # Assume we have a file of some sort, and output it into the
2205 # dependency variable. Autoconf substitutions are not output;
2206 # rarely is a new dependency substituted into e.g. foo_LDADD
2207 # -- but bad things (e.g. -lX11) are routinely substituted.
2208 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2209 # and handled specially below.
2212 elsif ($val =~ /^\@(LT)?LIBOBJS\@$/)
2214 handle_LIBOBJS ($subvar, $cond, $1);
2218 elsif ($val =~ /^\@(LT)?ALLOCA\@$/)
2220 handle_ALLOCA ($subvar, $cond, $1);
2229 return $seen_libobjs;
2232 # handle_LIBOBJS_or_ALLOCA ($VAR)
2233 # -------------------------------
2234 # Definitions common to LIBOBJS and ALLOCA.
2235 # VAR should be one of LIBOBJS, LTLIBOBJS, ALLOCA, or LTALLOCA.
2236 sub handle_LIBOBJS_or_ALLOCA
2241 # If LIBOBJS files must be built in another directory we have
2242 # to define LIBOBJDIR and ensure the files get cleaned.
2243 # Otherwise LIBOBJDIR can be left undefined, and the cleaning
2244 # is achieved by 'rm -f *.$(OBJEXT)' in compile.am.
2245 if ($config_libobj_dir && $relative_dir ne $config_libobj_dir)
2247 # In the top-level Makefile we do not use $(top_builddir), because
2248 # we are already there, and since the targets are built without
2249 # a $(top_builddir), it helps BSD Make to match them with
2251 $dir = "$config_libobj_dir/"
2252 if $config_libobj_dir ne '.';
2253 $dir = backname ($relative_dir) . "/$dir"
2254 if $relative_dir ne '.';
2255 define_variable ('LIBOBJDIR', "$dir", INTERNAL);
2256 $clean_files{"\$($var)"} = MOSTLY_CLEAN;
2257 # libtool might create LIBOBJS as a side-effect of using LTLIBOBJS.
2258 $clean_files{"\$(LIBOBJS)"} = MOSTLY_CLEAN if $var eq "LTLIBOBJS";
2266 my ($var, $cond, $lt) = @_;
2267 my $myobjext = $lt ? 'lo' : 'o';
2270 $var->requires_variables ("\@${lt}LIBOBJS\@ used", $lt . 'LIBOBJS')
2271 if ! keys %libsources;
2273 my $dir = handle_LIBOBJS_or_ALLOCA "${lt}LIBOBJS";
2275 foreach my $iter (keys %libsources)
2277 if ($iter =~ /\.[cly]$/)
2280 saw_extension ('.c');
2283 if ($iter =~ /\.h$/)
2285 require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
2287 elsif ($iter ne 'alloca.c')
2289 my $rewrite = $iter;
2290 $rewrite =~ s/\.c$/.P$myobjext/;
2291 $dep_files{$dir . '$(DEPDIR)/' . $rewrite} = 1;
2292 $rewrite = "^" . quotemeta ($iter) . "\$";
2293 # Only require the file if it is not a built source.
2294 my $bs = var ('BUILT_SOURCES');
2295 if (! $bs || ! grep (/$rewrite/, $bs->value_as_list_recursive))
2297 require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
2305 my ($var, $cond, $lt) = @_;
2306 my $myobjext = $lt ? 'lo' : 'o';
2308 my $dir = handle_LIBOBJS_or_ALLOCA "${lt}ALLOCA";
2310 $dir eq '' and $dir = './';
2311 $var->requires_variables ("\@${lt}ALLOCA\@ used", $lt . 'ALLOCA');
2312 $dep_files{$dir . '$(DEPDIR)/alloca.P' . $myobjext} = 1;
2313 require_libsource_with_macro ($cond, $var, FOREIGN, 'alloca.c');
2314 saw_extension ('.c');
2317 # Canonicalize the input parameter.
2321 $string =~ tr/A-Za-z0-9_\@/_/c;
2325 # Canonicalize a name, and check to make sure the non-canonical name
2326 # is never used. Returns canonical name. Arguments are name and a
2327 # list of suffixes to check for.
2328 sub check_canonical_spelling
2330 my ($name, @suffixes) = @_;
2332 my $xname = canonicalize ($name);
2333 if ($xname ne $name)
2335 foreach my $xt (@suffixes)
2337 reject_var ("$name$xt", "use '$xname$xt', not '$name$xt'");
2344 # Set up the compile suite.
2345 sub handle_compile ()
2347 return if ! $must_handle_compiled_objects;
2350 my $default_includes = '';
2351 if (! option 'nostdinc')
2353 my @incs = ('-I.', subst ('am__isrc'));
2355 my $var = var 'CONFIG_HEADER';
2358 foreach my $hdr (split (' ', $var->variable_value))
2360 push @incs, '-I' . dirname ($hdr);
2363 # We want '-I. -I$(srcdir)', but the latter -I is redundant
2364 # and unaesthetic in non-VPATH builds. We use `-I.@am__isrc@`
2365 # instead. It will be replaced by '-I.' or '-I. -I$(srcdir)'.
2366 # Items in CONFIG_HEADER are never in $(srcdir) so it is safe
2367 # to just put @am__isrc@ right after '-I.', without a space.
2368 ($default_includes = ' ' . uniq (@incs)) =~ s/ @/@/;
2371 my (@mostly_rms, @dist_rms);
2372 foreach my $item (sort keys %compile_clean_files)
2374 if ($compile_clean_files{$item} == MOSTLY_CLEAN)
2376 push (@mostly_rms, "\t-rm -f $item");
2378 elsif ($compile_clean_files{$item} == DIST_CLEAN)
2380 push (@dist_rms, "\t-rm -f $item");
2384 prog_error 'invalid entry in %compile_clean_files';
2388 my ($coms, $vars, $rules) =
2389 file_contents_internal (1, "$libdir/am/compile.am",
2390 new Automake::Location,
2391 'DEFAULT_INCLUDES' => $default_includes,
2392 'MOSTLYRMS' => join ("\n", @mostly_rms),
2393 'DISTRMS' => join ("\n", @dist_rms));
2394 $output_vars .= $vars;
2395 $output_rules .= "$coms$rules";
2398 # Handle libtool rules.
2399 sub handle_libtool ()
2401 return unless var ('LIBTOOL');
2403 # Libtool requires some files, but only at top level.
2404 # (Starting with Libtool 2.0 we do not have to bother. These
2405 # requirements are done with AC_REQUIRE_AUX_FILE.)
2406 require_conf_file_with_macro (TRUE, 'LIBTOOL', FOREIGN, @libtool_files)
2407 if $relative_dir eq '.' && ! $libtool_new_api;
2410 foreach my $item (sort keys %libtool_clean_directories)
2412 my $dir = ($item eq '.') ? '' : "$item/";
2413 # .libs is for Unix, _libs for DOS.
2414 push (@libtool_rms, "\t-rm -rf ${dir}.libs");
2417 check_user_variables 'LIBTOOLFLAGS';
2419 # Output the libtool compilation rules.
2420 $output_rules .= file_contents ('libtool',
2421 new Automake::Location,
2422 LTRMS => join ("\n", @libtool_rms));
2425 # Check for duplicate targets
2426 sub handle_targets ()
2430 @proglist = am_install_var ('progs', 'PROGRAMS',
2431 'bin', 'sbin', 'libexec', 'pkglibexec',
2433 @liblist = am_install_var ('libs', 'LIBRARIES',
2434 'lib', 'pkglib', 'noinst', 'check');
2435 @ltliblist = am_install_var ('ltlib', 'LTLIBRARIES',
2436 'noinst', 'lib', 'pkglib', 'check');
2438 # Record duplications that may arise after canonicalization of the
2439 # base names, in order to prevent object file clashes in the presence
2440 # of target-specific *FLAGS
2441 my @targetlist = (@proglist, @liblist, @ltliblist);
2442 foreach my $pair (@targetlist)
2444 my $base = canonicalize (basename (@$pair[1]));
2445 push (@dup_shortnames, $base) if ($seen{$base});
2446 $seen{$base} = $base;
2450 sub handle_programs ()
2452 return if ! @proglist;
2453 $must_handle_compiled_objects = 1;
2455 my $seen_global_libobjs =
2456 var ('LDADD') && handle_lib_objects ('', 'LDADD');
2458 foreach my $pair (@proglist)
2460 my ($where, $one_file) = @$pair;
2462 my $seen_libobjs = 0;
2463 my $obj = '.$(OBJEXT)';
2465 $known_programs{$one_file} = $where;
2467 # Canonicalize names and check for misspellings.
2468 my $xname = check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2469 '_SOURCES', '_OBJECTS',
2472 $where->push_context ("while processing program '$one_file'");
2473 $where->set (INTERNAL->get);
2475 my $linker = handle_source_transform ($xname, $one_file, $obj, $where,
2476 NONLIBTOOL => 1, LIBTOOL => 0);
2478 if (var ($xname . "_LDADD"))
2480 $seen_libobjs = handle_lib_objects ($xname, $xname . '_LDADD');
2484 # User didn't define prog_LDADD override. So do it.
2485 define_variable ($xname . '_LDADD', '$(LDADD)', $where);
2487 # This does a bit too much work. But we need it to
2488 # generate _DEPENDENCIES when appropriate.
2491 $seen_libobjs = handle_lib_objects ($xname, 'LDADD');
2495 reject_var ($xname . '_LIBADD',
2496 "use '${xname}_LDADD', not '${xname}_LIBADD'");
2498 set_seen ($xname . '_DEPENDENCIES');
2499 set_seen ('EXTRA_' . $xname . '_DEPENDENCIES');
2500 set_seen ($xname . '_LDFLAGS');
2502 # Determine program to use for link.
2503 my($xlink, $vlink) = define_per_target_linker_variable ($linker, $xname);
2504 $vlink = verbose_flag ($vlink || 'GEN');
2506 # If the resulting program lies in a subdirectory,
2507 # ensure that the directory exists before we need it.
2508 my $dirstamp = require_build_directory_maybe ($one_file);
2510 $libtool_clean_directories{dirname ($one_file)} = 1;
2512 $output_rules .= file_contents ('program',
2514 PROGRAM => $one_file,
2518 DIRSTAMP => $dirstamp,
2519 EXEEXT => '$(EXEEXT)');
2521 if ($seen_libobjs || $seen_global_libobjs)
2523 if (var ($xname . '_LDADD'))
2525 check_libobjs_sources ($xname, $xname . '_LDADD');
2527 elsif (var ('LDADD'))
2529 check_libobjs_sources ($xname, 'LDADD');
2536 sub handle_libraries ()
2538 return if ! @liblist;
2539 $must_handle_compiled_objects = 1;
2541 my @prefix = am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2546 my $var = rvar ($prefix[0] . '_LIBRARIES');
2547 $var->requires_variables ('library used', 'RANLIB');
2550 define_variable ('AR', 'ar', INTERNAL);
2551 define_variable ('ARFLAGS', 'cru', INTERNAL);
2552 define_verbose_tagvar ('AR');
2554 foreach my $pair (@liblist)
2556 my ($where, $onelib) = @$pair;
2558 my $seen_libobjs = 0;
2559 # Check that the library fits the standard naming convention.
2560 my $bn = basename ($onelib);
2561 if ($bn !~ /^lib.*\.a$/)
2563 $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.a/;
2564 my $suggestion = dirname ($onelib) . "/$bn";
2565 $suggestion =~ s|^\./||g;
2566 msg ('error-gnu/warn', $where,
2567 "'$onelib' is not a standard library name\n"
2568 . "did you mean '$suggestion'?")
2571 ($known_libraries{$onelib} = $bn) =~ s/\.a$//;
2573 $where->push_context ("while processing library '$onelib'");
2574 $where->set (INTERNAL->get);
2576 my $obj = '.$(OBJEXT)';
2578 # Canonicalize names and check for misspellings.
2579 my $xlib = check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2580 '_OBJECTS', '_DEPENDENCIES',
2583 if (! var ($xlib . '_AR'))
2585 define_variable ($xlib . '_AR', '$(AR) $(ARFLAGS)', $where);
2588 # Generate support for conditional object inclusion in
2590 if (var ($xlib . '_LIBADD'))
2592 if (handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2599 define_variable ($xlib . "_LIBADD", '', $where);
2602 reject_var ($xlib . '_LDADD',
2603 "use '${xlib}_LIBADD', not '${xlib}_LDADD'");
2605 # Make sure we at look at this.
2606 set_seen ($xlib . '_DEPENDENCIES');
2607 set_seen ('EXTRA_' . $xlib . '_DEPENDENCIES');
2609 handle_source_transform ($xlib, $onelib, $obj, $where,
2610 NONLIBTOOL => 1, LIBTOOL => 0);
2612 # If the resulting library lies in a subdirectory,
2613 # make sure this directory will exist.
2614 my $dirstamp = require_build_directory_maybe ($onelib);
2615 my $verbose = verbose_flag ('AR');
2616 my $silent = silent_flag ();
2618 $output_rules .= file_contents ('library',
2620 VERBOSE => $verbose,
2624 DIRSTAMP => $dirstamp);
2628 if (var ($xlib . '_LIBADD'))
2630 check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2636 msg ('extra-portability', $where,
2637 "'$onelib': linking libraries using a non-POSIX\n"
2638 . "archiver requires 'AM_PROG_AR' in '$configure_ac'")
2644 sub handle_ltlibraries ()
2646 return if ! @ltliblist;
2647 $must_handle_compiled_objects = 1;
2649 my @prefix = am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2654 my $var = rvar ($prefix[0] . '_LTLIBRARIES');
2655 $var->requires_variables ('Libtool library used', 'LIBTOOL');
2659 my %instsubdirs = ();
2661 my %liblocations = (); # Location (in Makefile.am) of each library.
2663 foreach my $key (@prefix)
2665 # Get the installation directory of each library.
2667 my $strip_subdir = 1;
2668 if ($dir =~ /^nobase_/)
2670 $dir =~ s/^nobase_//;
2673 my $var = rvar ($key . '_LTLIBRARIES');
2675 # We reject libraries which are installed in several places
2676 # in the same condition, because we can only specify one
2678 $var->traverse_recursively
2681 my ($var, $val, $cond, $full_cond) = @_;
2682 my $hcond = $full_cond->human;
2683 my $where = $var->rdef ($cond)->location;
2685 $ldir = '/' . dirname ($val)
2686 if (!$strip_subdir);
2687 # A library cannot be installed in different directories
2688 # in overlapping conditions.
2689 if (exists $instconds{$val})
2692 $instconds{$val}->ambiguous_p ($val, $full_cond);
2696 error ($where, $msg, partial => 1);
2697 my $dirtxt = "installed " . ($strip_subdir ? "in" : "below") . " '$dir'";
2698 $dirtxt = "built for '$dir'"
2699 if $dir eq 'EXTRA' || $dir eq 'noinst' || $dir eq 'check';
2701 $full_cond->true ? "" : " in condition $hcond";
2703 error ($where, "'$val' should be $dirtxt$dircond ...",
2706 my $hacond = $acond->human;
2707 my $adir = $instdirs{$val}{$acond};
2708 my $adirtxt = "installed in '$adir'";
2709 $adirtxt = "built for '$adir'"
2710 if ($adir eq 'EXTRA' || $adir eq 'noinst'
2711 || $adir eq 'check');
2712 my $adircond = $acond->true ? "" : " in condition $hacond";
2714 my $onlyone = ($dir ne $adir) ?
2715 ("\nLibtool libraries can be built for only one "
2716 . "destination") : "";
2718 error ($liblocations{$val}{$acond},
2719 "... and should also be $adirtxt$adircond.$onlyone");
2725 $instconds{$val} = new Automake::DisjConditions;
2727 $instdirs{$val}{$full_cond} = $dir;
2728 $instsubdirs{$val}{$full_cond} = $ldir;
2729 $liblocations{$val}{$full_cond} = $where;
2730 $instconds{$val} = $instconds{$val}->merge ($full_cond);
2736 skip_ac_subst => 1);
2739 foreach my $pair (@ltliblist)
2741 my ($where, $onelib) = @$pair;
2743 my $seen_libobjs = 0;
2746 # Canonicalize names and check for misspellings.
2747 my $xlib = check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2748 '_SOURCES', '_OBJECTS',
2751 # Check that the library fits the standard naming convention.
2752 my $libname_rx = '^lib.*\.la';
2753 my $ldvar = var ("${xlib}_LDFLAGS") || var ('AM_LDFLAGS');
2754 my $ldvar2 = var ('LDFLAGS');
2755 if (($ldvar && grep (/-module/, $ldvar->value_as_list_recursive))
2756 || ($ldvar2 && grep (/-module/, $ldvar2->value_as_list_recursive)))
2758 # Relax name checking for libtool modules.
2759 $libname_rx = '\.la';
2762 my $bn = basename ($onelib);
2763 if ($bn !~ /$libname_rx$/)
2765 my $type = 'library';
2766 if ($libname_rx eq '\.la')
2768 $bn =~ s/^(lib|)(.*?)(?:\.[^.]*)?$/$1$2.la/;
2773 $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/lib$1.la/;
2775 my $suggestion = dirname ($onelib) . "/$bn";
2776 $suggestion =~ s|^\./||g;
2777 msg ('error-gnu/warn', $where,
2778 "'$onelib' is not a standard libtool $type name\n"
2779 . "did you mean '$suggestion'?")
2782 ($known_libraries{$onelib} = $bn) =~ s/\.la$//;
2784 $where->push_context ("while processing Libtool library '$onelib'");
2785 $where->set (INTERNAL->get);
2787 # Make sure we look at these.
2788 set_seen ($xlib . '_LDFLAGS');
2789 set_seen ($xlib . '_DEPENDENCIES');
2790 set_seen ('EXTRA_' . $xlib . '_DEPENDENCIES');
2792 # Generate support for conditional object inclusion in
2794 if (var ($xlib . '_LIBADD'))
2796 if (handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2803 define_variable ($xlib . "_LIBADD", '', $where);
2806 reject_var ("${xlib}_LDADD",
2807 "use '${xlib}_LIBADD', not '${xlib}_LDADD'");
2810 my $linker = handle_source_transform ($xlib, $onelib, $obj, $where,
2811 NONLIBTOOL => 0, LIBTOOL => 1);
2813 # Determine program to use for link.
2814 my($xlink, $vlink) = define_per_target_linker_variable ($linker, $xlib);
2815 $vlink = verbose_flag ($vlink || 'GEN');
2817 my $rpathvar = "am_${xlib}_rpath";
2818 my $rpath = "\$($rpathvar)";
2819 foreach my $rcond ($instconds{$onelib}->conds)
2822 if ($instdirs{$onelib}{$rcond} eq 'EXTRA'
2823 || $instdirs{$onelib}{$rcond} eq 'noinst'
2824 || $instdirs{$onelib}{$rcond} eq 'check')
2826 # It's an EXTRA_ library, so we can't specify -rpath,
2827 # because we don't know where the library will end up.
2828 # The user probably knows, but generally speaking automake
2829 # doesn't -- and in fact configure could decide
2830 # dynamically between two different locations.
2835 $val = ('-rpath $(' . $instdirs{$onelib}{$rcond} . 'dir)');
2836 $val .= $instsubdirs{$onelib}{$rcond}
2837 if defined $instsubdirs{$onelib}{$rcond};
2841 # If $rcond is true there is only one condition and
2842 # there is no point defining an helper variable.
2847 define_pretty_variable ($rpathvar, $rcond, INTERNAL, $val);
2851 # If the resulting library lies in a subdirectory,
2852 # make sure this directory will exist.
2853 my $dirstamp = require_build_directory_maybe ($onelib);
2855 # Remember to cleanup .libs/ in this directory.
2856 my $dirname = dirname $onelib;
2857 $libtool_clean_directories{$dirname} = 1;
2859 $output_rules .= file_contents ('ltlibrary',
2861 LTLIBRARY => $onelib,
2862 XLTLIBRARY => $xlib,
2866 DIRSTAMP => $dirstamp);
2869 if (var ($xlib . '_LIBADD'))
2871 check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2877 msg ('extra-portability', $where,
2878 "'$onelib': linking libtool libraries using a non-POSIX\n"
2879 . "archiver requires 'AM_PROG_AR' in '$configure_ac'")
2884 # See if any _SOURCES variable were misspelled.
2887 # It is ok if the user sets this particular variable.
2888 set_seen 'AM_LDFLAGS';
2890 foreach my $primary ('SOURCES', 'LIBADD', 'LDADD', 'LDFLAGS', 'DEPENDENCIES')
2892 foreach my $var (variables $primary)
2894 my $varname = $var->name;
2895 # A configure variable is always legitimate.
2896 next if exists $configure_vars{$varname};
2898 for my $cond ($var->conditions->conds)
2900 $varname =~ /^(?:EXTRA_)?(?:nobase_)?(?:dist_|nodist_)?(.*)_[[:alnum:]]+$/;
2901 msg_var ('syntax', $var, "variable '$varname' is defined but no"
2902 . " program or\nlibrary has '$1' as canonical name"
2903 . " (possible typo)")
2904 unless $var->rdef ($cond)->seen;
2911 sub handle_scripts ()
2913 # NOTE we no longer automatically clean SCRIPTS, because it is
2914 # useful to sometimes distribute scripts verbatim. This happens
2915 # e.g. in Automake itself.
2916 am_install_var ('-candist', 'scripts', 'SCRIPTS',
2917 'bin', 'sbin', 'libexec', 'pkglibexec', 'pkgdata',
2922 ## ------------------------ ##
2923 ## Handling Texinfo files. ##
2924 ## ------------------------ ##
2926 # ($OUTFILE, $VFILE)
2927 # scan_texinfo_file ($FILENAME)
2928 # -----------------------------
2929 # $OUTFILE - name of the info file produced by $FILENAME.
2930 # $VFILE - name of the version.texi file used (undef if none).
2931 sub scan_texinfo_file
2933 my ($filename) = @_;
2935 my $texi = new Automake::XFile "< $filename";
2936 verb "reading $filename";
2938 my ($outfile, $vfile);
2939 while ($_ = $texi->getline)
2941 if (/^\@setfilename +(\S+)/)
2943 # Honor only the first @setfilename. (It's possible to have
2944 # more occurrences later if the manual shows examples of how
2945 # to use @setfilename...)
2949 if (index ($outfile, '.') < 0)
2951 msg 'obsolete', "$filename:$.",
2952 "use of suffix-less info files is discouraged"
2954 elsif ($outfile !~ /\.info$/)
2956 error ("$filename:$.",
2957 "output '$outfile' has unrecognized extension");
2961 # A "version.texi" file is actually any file whose name matches
2963 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2971 err_am "'$filename' missing \@setfilename";
2975 return ($outfile, $vfile);
2979 # ($DIRSTAMP, @CLEAN_FILES)
2980 # output_texinfo_build_rules ($SOURCE, $DEST, $INSRC, @DEPENDENCIES)
2981 # ------------------------------------------------------------------
2982 # SOURCE - the source Texinfo file
2983 # DEST - the destination Info file
2984 # INSRC - whether DEST should be built in the source tree
2985 # DEPENDENCIES - known dependencies
2986 sub output_texinfo_build_rules
2988 my ($source, $dest, $insrc, @deps) = @_;
2990 # Split 'a.texi' into 'a' and '.texi'.
2991 my ($spfx, $ssfx) = ($source =~ /^(.*?)(\.[^.]*)?$/);
2992 my ($dpfx, $dsfx) = ($dest =~ /^(.*?)(\.[^.]*)?$/);
2997 # We can output two kinds of rules: the "generic" rules use Make
2998 # suffix rules and are appropriate when $source and $dest do not lie
2999 # in a sub-directory; the "specific" rules are needed in the other
3002 # The former are output only once (this is not really apparent here,
3003 # but just remember that some logic deeper in Automake will not
3004 # output the same rule twice); while the later need to be output for
3005 # each Texinfo source.
3008 my $sdir = dirname $source;
3009 if ($sdir eq '.' && dirname ($dest) eq '.')
3012 $makeinfoflags = '-I $(srcdir)';
3017 $makeinfoflags = "-I $sdir -I \$(srcdir)/$sdir";
3020 # A directory can contain two kinds of info files: some built in the
3021 # source tree, and some built in the build tree. The rules are
3022 # different in each case. However we cannot output two different
3023 # set of generic rules. Because in-source builds are more usual, we
3024 # use generic rules in this case and fall back to "specific" rules
3025 # for build-dir builds. (It should not be a problem to invert this
3027 $generic = 0 unless $insrc;
3029 # We cannot use a suffix rule to build info files with an empty
3030 # extension. Otherwise we would output a single suffix inference
3031 # rule, with separate dependencies, as in
3035 # foo.info: foo.texi
3037 # which confuse Solaris make. (See the Autoconf manual for
3038 # details.) Therefore we use a specific rule in this case. This
3039 # applies to info files only (dvi and pdf files always have an
3041 my $generic_info = ($generic && $dsfx) ? 1 : 0;
3043 # If the resulting file lies in a subdirectory,
3044 # make sure this directory will exist.
3045 my $dirstamp = require_build_directory_maybe ($dest);
3047 my $dipfx = ($insrc ? '$(srcdir)/' : '') . $dpfx;
3049 $output_rules .= file_contents ('texibuild',
3050 new Automake::Location,
3051 AM_V_MAKEINFO => verbose_flag('MAKEINFO'),
3052 AM_V_TEXI2DVI => verbose_flag('TEXI2DVI'),
3053 AM_V_TEXI2PDF => verbose_flag('TEXI2PDF'),
3055 DEST_PREFIX => $dpfx,
3056 DEST_INFO_PREFIX => $dipfx,
3057 DEST_SUFFIX => $dsfx,
3058 DIRSTAMP => $dirstamp,
3059 GENERIC => $generic,
3060 GENERIC_INFO => $generic_info,
3062 MAKEINFOFLAGS => $makeinfoflags,
3063 SILENT => silent_flag(),
3066 SOURCE_INFO => ($generic_info
3068 SOURCE_REAL => $source,
3069 SOURCE_SUFFIX => $ssfx,
3070 TEXIQUIET => verbose_flag('texinfo'),
3071 TEXIDEVNULL => verbose_flag('texidevnull'),
3073 return ($dirstamp, "$dpfx.dvi", "$dpfx.pdf", "$dpfx.ps", "$dpfx.html");
3077 # ($MOSTLYCLEAN, $TEXICLEAN, $MAINTCLEAN)
3078 # handle_texinfo_helper ($info_texinfos)
3079 # --------------------------------------
3080 # Handle all Texinfo source; helper for 'handle_texinfo'.
3081 sub handle_texinfo_helper
3083 my ($info_texinfos) = @_;
3084 my (@infobase, @info_deps_list, @texi_deps);
3087 my (@mostly_cleans, @texi_cleans, @maint_cleans) = ('', '', '');
3090 ($info_texinfos->value_as_list_recursive (inner_expand => 1))
3092 my $infobase = $texi;
3093 if ($infobase =~ s/\.texi$//)
3095 1; # Nothing more to do.
3097 elsif ($infobase =~ s/\.(txi|texinfo)$//)
3099 msg_var 'obsolete', $info_texinfos,
3100 "suffix '.$1' for Texinfo files is discouraged;" .
3101 " use '.texi' instead";
3105 # FIXME: report line number.
3106 err_am "texinfo file '$texi' has unrecognized extension";
3110 push @infobase, $infobase;
3112 # If 'version.texi' is referenced by input file, then include
3113 # automatic versioning capability.
3114 my ($out_file, $vtexi) =
3115 scan_texinfo_file ("$relative_dir/$texi")
3117 # Directory of auxiliary files and build by-products used by texi2dvi
3119 push @mostly_cleans, "$infobase.t2d";
3120 push @mostly_cleans, "$infobase.t2p";
3122 # If the Texinfo source is in a subdirectory, create the
3123 # resulting info in this subdirectory. If it is in the current
3124 # directory, try hard to not prefix "./" because it breaks the
3126 my $outdir = dirname ($texi) . '/';
3127 $outdir = "" if $outdir eq './';
3128 my $src_outdir = '$(srcdir)/'. $outdir;
3129 $out_file = $outdir . $out_file;
3131 # Until Automake 1.6.3, .info files were built in the
3132 # source tree. This was an obstacle to the support of
3133 # non-distributed .info files, and non-distributed .texi
3136 # * Non-distributed .texi files is important in some packages
3137 # where .texi files are built at make time, probably using
3138 # other binaries built in the package itself, maybe using
3139 # tools or information found on the build host. Because
3140 # these files are not distributed they are always rebuilt
3141 # at make time; they should therefore not lie in the source
3142 # directory. One plan was to support this using
3143 # nodist_info_TEXINFOS or something similar. (Doing this
3144 # requires some sanity checks. For instance Automake should
3146 # dist_info_TEXINFOS = foo.texi
3147 # nodist_foo_TEXINFOS = included.texi
3148 # because a distributed file should never depend on a
3149 # non-distributed file.)
3151 # * If .texi files are not distributed, then .info files should
3152 # not be distributed either. There are also cases where one
3153 # wants to distribute .texi files, but does not want to
3154 # distribute the .info files. For instance the Texinfo package
3155 # distributes the tool used to build these files; it would
3156 # be a waste of space to distribute them. It's not clear
3157 # which syntax we should use to indicate that .info files should
3158 # not be distributed. Akim Demaille suggested that eventually
3159 # we switch to a new syntax:
3160 # | Maybe we should take some inspiration from what's already
3161 # | done in the rest of Automake. Maybe there is too much
3162 # | syntactic sugar here, and you want
3163 # | nodist_INFO = bar.info
3164 # | dist_bar_info_SOURCES = bar.texi
3165 # | bar_texi_DEPENDENCIES = foo.texi
3166 # | with a bit of magic to have bar.info represent the whole
3167 # | bar*info set. That's a lot more verbose that the current
3168 # | situation, but it is # not new, hence the user has less
3171 # | But there is still too much room for meaningless specs:
3172 # | nodist_INFO = bar.info
3173 # | dist_bar_info_SOURCES = bar.texi
3174 # | dist_PS = bar.ps something-written-by-hand.ps
3175 # | nodist_bar_ps_SOURCES = bar.texi
3176 # | bar_texi_DEPENDENCIES = foo.texi
3177 # | here bar.texi is dist_ in line 2, and nodist_ in 4.
3179 # Back to the point, it should be clear that in order to support
3180 # non-distributed .info files, we need to build them in the
3181 # build tree, not in the source tree (non-distributed .texi
3182 # files are less of a problem, because we do not output build
3183 # rules for them). In Automake 1.7 .info build rules have been
3184 # largely cleaned up so that .info files get always build in the
3185 # build tree, even when distributed. The idea was that
3186 # (1) if during a VPATH build the .info file was found to be
3187 # absent or out-of-date (in the source tree or in the
3188 # build tree), Make would rebuild it in the build tree.
3189 # If an up-to-date source-tree of the .info file existed,
3190 # make would not rebuild it in the build tree.
3191 # (2) having two copies of .info files, one in the source tree
3192 # and one (newer) in the build tree is not a problem
3193 # because 'make dist' always pick files in the build tree
3195 # However it turned out the be a bad idea for several reasons:
3196 # * Tru64, OpenBSD, and FreeBSD (not NetBSD) Make do not behave
3197 # like GNU Make on point (1) above. These implementations
3198 # of Make would always rebuild .info files in the build
3199 # tree, even if such files were up to date in the source
3200 # tree. Consequently, it was impossible to perform a VPATH
3201 # build of a package containing Texinfo files using these
3202 # Make implementations.
3203 # (Refer to the Autoconf Manual, section "Limitation of
3204 # Make", paragraph "VPATH", item "target lookup", for
3205 # an account of the differences between these
3207 # * The GNU Coding Standards require these files to be built
3208 # in the source-tree (when they are distributed, that is).
3209 # * Keeping a fresher copy of distributed files in the
3210 # build tree can be annoying during development because
3211 # - if the files is kept under CVS, you really want it
3212 # to be updated in the source tree
3213 # - it is confusing that 'make distclean' does not erase
3214 # all files in the build tree.
3216 # Consequently, starting with Automake 1.8, .info files are
3217 # built in the source tree again. Because we still plan to
3218 # support non-distributed .info files at some point, we
3219 # have a single variable ('$insrc') that controls whether
3220 # the current .info file must be built in the source tree
3221 # or in the build tree. Actually this variable is switched
3222 # off when the automake option 'info-in-builddir' is given.
3223 # This is done to allow the developers of GCC, GDB, GNU
3224 # binutils and the GNU bfd library to force the '.info' files
3225 # to be generated in the builddir rather than the srcdir, as
3226 # was once done when the (now removed) 'cygnus' option was
3227 # given. See automake bug#11034 for more discussion.
3228 my $insrc = ! option 'info-in-builddir';
3229 $outdir = $src_outdir if $insrc;
3231 # If user specified file_TEXINFOS, then use that as explicit
3234 push (@texi_deps, "${src_outdir}${vtexi}") if $vtexi;
3236 my $canonical = canonicalize ($infobase);
3237 if (var ($canonical . "_TEXINFOS"))
3239 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
3240 push_dist_common ('$(' . $canonical . '_TEXINFOS)');
3243 my ($dirstamp, @cfiles) =
3244 output_texinfo_build_rules ($texi, $out_file, $insrc, @texi_deps);
3245 push (@texi_cleans, @cfiles);
3247 push (@info_deps_list, $out_file);
3249 # If a vers*.texi file is needed, emit the rule.
3252 err_am ("'$vtexi', included in '$texi', "
3253 . "also included in '$versions{$vtexi}'")
3254 if defined $versions{$vtexi};
3255 $versions{$vtexi} = $texi;
3257 # We number the stamp-vti files. This is doable since the
3258 # actual names don't matter much. We only number starting
3259 # with the second one, so that the common case looks nice.
3260 my $vti = ($done ? $done : 'vti');
3263 # This is ugly, but it is our historical practice.
3264 if ($config_aux_dir_set_in_configure_ac)
3266 require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3271 require_file_with_macro (TRUE, 'info_TEXINFOS',
3272 FOREIGN, 'mdate-sh');
3276 if ($config_aux_dir_set_in_configure_ac)
3278 $conf_dir = "$am_config_aux_dir/";
3282 $conf_dir = '$(srcdir)/';
3284 $output_rules .= file_contents ('texi-vers',
3285 new Automake::Location,
3288 STAMPVTI => "${src_outdir}stamp-$vti",
3289 VTEXI => "${src_outdir}$vtexi",
3291 DIRSTAMP => $dirstamp);
3295 # Handle location of texinfo.tex.
3296 my $need_texi_file = 0;
3298 if (var ('TEXINFO_TEX'))
3300 # The user defined TEXINFO_TEX so assume he knows what he is
3302 $texinfodir = ('$(srcdir)/'
3303 . dirname (variable_value ('TEXINFO_TEX')));
3305 elsif ($config_aux_dir_set_in_configure_ac)
3307 $texinfodir = $am_config_aux_dir;
3308 define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex", INTERNAL);
3309 $need_texi_file = 2; # so that we require_conf_file later
3313 $texinfodir = '$(srcdir)';
3314 $need_texi_file = 1;
3316 define_variable ('am__TEXINFO_TEX_DIR', $texinfodir, INTERNAL);
3318 push (@dist_targets, 'dist-info');
3320 if (! option 'no-installinfo')
3322 # Make sure documentation is made and installed first. Use
3323 # $(INFO_DEPS), not 'info', because otherwise recursive makes
3324 # get run twice during "make all".
3325 unshift (@all, '$(INFO_DEPS)');
3328 define_files_variable ("DVIS", @infobase, 'dvi', INTERNAL);
3329 define_files_variable ("PDFS", @infobase, 'pdf', INTERNAL);
3330 define_files_variable ("PSS", @infobase, 'ps', INTERNAL);
3331 define_files_variable ("HTMLS", @infobase, 'html', INTERNAL);
3333 # This next isn't strictly needed now -- the places that look here
3334 # could easily be changed to look in info_TEXINFOS. But this is
3335 # probably better, in case noinst_TEXINFOS is ever supported.
3336 define_variable ("TEXINFOS", variable_value ('info_TEXINFOS'), INTERNAL);
3338 # Do some error checking. Note that this file is not required
3339 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3341 if ($need_texi_file && ! option 'no-texinfo.tex')
3343 if ($need_texi_file > 1)
3345 require_conf_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3350 require_file_with_macro (TRUE, 'info_TEXINFOS', FOREIGN,
3355 return (makefile_wrap ("", "\t ", @mostly_cleans),
3356 makefile_wrap ("", "\t ", @texi_cleans),
3357 makefile_wrap ("", "\t ", @maint_cleans));
3361 sub handle_texinfo ()
3363 reject_var 'TEXINFOS', "'TEXINFOS' is an anachronism; use 'info_TEXINFOS'";
3364 # FIXME: I think this is an obsolete future feature name.
3365 reject_var 'html_TEXINFOS', "HTML generation not yet supported";
3367 my $info_texinfos = var ('info_TEXINFOS');
3368 my ($mostlyclean, $clean, $maintclean) = ('', '', '');
3371 define_verbose_texinfo;
3372 ($mostlyclean, $clean, $maintclean) = handle_texinfo_helper ($info_texinfos);
3378 $output_rules .= file_contents ('texinfos',
3379 new Automake::Location,
3380 AM_V_DVIPS => verbose_flag('DVIPS'),
3381 MOSTLYCLEAN => $mostlyclean,
3382 TEXICLEAN => $clean,
3383 MAINTCLEAN => $maintclean,
3384 'LOCAL-TEXIS' => !!$info_texinfos,
3385 TEXIQUIET => verbose_flag('texinfo'));
3389 sub handle_man_pages ()
3391 reject_var 'MANS', "'MANS' is an anachronism; use 'man_MANS'";
3393 # Find all the sections in use. We do this by first looking for
3394 # "standard" sections, and then looking for any additional
3395 # sections used in man_MANS.
3396 my (%sections, %notrans_sections, %trans_sections,
3397 %notrans_vars, %trans_vars, %notrans_sect_vars, %trans_sect_vars);
3398 # We handle nodist_ for uniformity. man pages aren't distributed
3399 # by default so it isn't actually very important.
3400 foreach my $npfx ('', 'notrans_')
3402 foreach my $pfx ('', 'dist_', 'nodist_')
3404 # Add more sections as needed.
3405 foreach my $section ('0'..'9', 'n', 'l')
3407 my $varname = $npfx . $pfx . 'man' . $section . '_MANS';
3410 $sections{$section} = 1;
3411 $varname = '$(' . $varname . ')';
3412 if ($npfx eq 'notrans_')
3414 $notrans_sections{$section} = 1;
3415 $notrans_sect_vars{$varname} = 1;
3419 $trans_sections{$section} = 1;
3420 $trans_sect_vars{$varname} = 1;
3423 push_dist_common ($varname)
3428 my $varname = $npfx . $pfx . 'man_MANS';
3429 my $var = var ($varname);
3432 foreach ($var->value_as_list_recursive)
3434 # A page like 'foo.1c' goes into man1dir.
3435 if (/\.([0-9a-z])([a-z]*)$/)
3438 if ($npfx eq 'notrans_')
3440 $notrans_sections{$1} = 1;
3444 $trans_sections{$1} = 1;
3449 $varname = '$(' . $varname . ')';
3450 if ($npfx eq 'notrans_')
3452 $notrans_vars{$varname} = 1;
3456 $trans_vars{$varname} = 1;
3458 push_dist_common ($varname)
3464 return unless %sections;
3468 # Build section independent variables.
3469 my $have_notrans = %notrans_vars;
3470 my @notrans_list = sort keys %notrans_vars;
3471 my $have_trans = %trans_vars;
3472 my @trans_list = sort keys %trans_vars;
3474 # Now for each section, generate an install and uninstall rule.
3475 # Sort sections so output is deterministic.
3476 foreach my $section (sort keys %sections)
3478 # Build section dependent variables.
3479 my $notrans_mans = $have_notrans || exists $notrans_sections{$section};
3480 my $trans_mans = $have_trans || exists $trans_sections{$section};
3481 my (%notrans_this_sect, %trans_this_sect);
3482 my $expr = 'man' . $section . '_MANS';
3483 foreach my $varname (keys %notrans_sect_vars)
3485 if ($varname =~ /$expr/)
3487 $notrans_this_sect{$varname} = 1;
3490 foreach my $varname (keys %trans_sect_vars)
3492 if ($varname =~ /$expr/)
3494 $trans_this_sect{$varname} = 1;
3497 my @notrans_sect_list = sort keys %notrans_this_sect;
3498 my @trans_sect_list = sort keys %trans_this_sect;
3499 @unsorted_deps = (keys %notrans_vars, keys %trans_vars,
3500 keys %notrans_this_sect, keys %trans_this_sect);
3501 my @deps = sort @unsorted_deps;
3502 $output_rules .= file_contents ('mans',
3503 new Automake::Location,
3504 SECTION => $section,
3506 NOTRANS_MANS => $notrans_mans,
3507 NOTRANS_SECT_LIST => "@notrans_sect_list",
3508 HAVE_NOTRANS => $have_notrans,
3509 NOTRANS_LIST => "@notrans_list",
3510 TRANS_MANS => $trans_mans,
3511 TRANS_SECT_LIST => "@trans_sect_list",
3512 HAVE_TRANS => $have_trans,
3513 TRANS_LIST => "@trans_list");
3516 @unsorted_deps = (keys %notrans_vars, keys %trans_vars,
3517 keys %notrans_sect_vars, keys %trans_sect_vars);
3518 my @mans = sort @unsorted_deps;
3519 $output_vars .= file_contents ('mans-vars',
3520 new Automake::Location,
3523 push (@all, '$(MANS)')
3524 unless option 'no-installman';
3530 am_install_var ('-noextra', '-candist', 'data', 'DATA',
3531 'data', 'dataroot', 'doc', 'dvi', 'html', 'pdf',
3532 'ps', 'sysconf', 'sharedstate', 'localstate',
3533 'pkgdata', 'lisp', 'noinst', 'check');
3540 foreach my $spec (@config_headers)
3542 my ($out, @ins) = split_config_file_spec ($spec);
3543 foreach my $in (@ins)
3545 # If the config header source is in this directory,
3547 push @config, basename ($in)
3548 if $relative_dir eq dirname ($in);
3552 define_variable ('am__tagged_files',
3553 '$(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)'
3554 . "@config", INTERNAL);
3556 if (rvar('am__tagged_files')->value_as_list_recursive
3557 || var ('ETAGS_ARGS') || var ('SUBDIRS'))
3559 $output_rules .= file_contents ('tags', new Automake::Location);
3560 set_seen 'TAGS_DEPENDENCIES';
3564 reject_var ('TAGS_DEPENDENCIES',
3565 "it doesn't make sense to define 'TAGS_DEPENDENCIES'"
3566 . " without\nsources or 'ETAGS_ARGS'");
3567 # Every Makefile must define some sort of TAGS rule.
3568 # Otherwise, it would be possible for a top-level "make TAGS"
3569 # to fail because some subdirectory failed. Ditto ctags and
3573 "ctags CTAGS:\n\n" .
3574 "cscope cscopelist:\n\n";
3579 # user_phony_rule ($NAME)
3580 # -----------------------
3581 # Return false if rule $NAME does not exist. Otherwise,
3582 # declare it as phony, complete its definition (in case it is
3583 # conditional), and return its Automake::Rule instance.
3587 my $rule = rule $name;
3590 depend ('.PHONY', $name);
3591 # Define $NAME in all condition where it is not already defined,
3592 # so that it is always OK to depend on $NAME.
3593 for my $c ($rule->not_always_defined_in_cond (TRUE)->conds)
3595 Automake::Rule::define ($name, 'internal', RULE_AUTOMAKE,
3597 $output_rules .= $c->subst_string . "$name:\n";
3604 # Handle 'dist' target.
3607 # Substitutions for distdir.am
3610 # Define DIST_SUBDIRS. This must always be done, regardless of the
3611 # no-dist setting: target like 'distclean' or 'maintainer-clean' use it.
3612 my $subdirs = var ('SUBDIRS');
3615 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3616 # to all possible directories, and use it. If DIST_SUBDIRS is
3617 # defined, just use it.
3619 # Note that we check DIST_SUBDIRS first on purpose, so that
3620 # we don't call has_conditional_contents for now reason.
3621 # (In the past one project used so many conditional subdirectories
3622 # that calling has_conditional_contents on SUBDIRS caused
3623 # automake to grow to 150Mb -- this should not happen with
3624 # the current implementation of has_conditional_contents,
3625 # but it's more efficient to avoid the call anyway.)
3626 if (var ('DIST_SUBDIRS'))
3629 elsif ($subdirs->has_conditional_contents)
3631 define_pretty_variable
3632 ('DIST_SUBDIRS', TRUE, INTERNAL,
3633 uniq ($subdirs->value_as_list_recursive));
3637 # We always define this because that is what 'distclean'
3639 define_pretty_variable ('DIST_SUBDIRS', TRUE, INTERNAL,
3644 # The remaining definitions are only required when a dist target is used.
3645 return if option 'no-dist';
3647 # At least one of the archive formats must be enabled.
3648 if ($relative_dir eq '.')
3650 my $archive_defined = option 'no-dist-gzip' ? 0 : 1;
3651 $archive_defined ||=
3652 grep { option "dist-$_" } qw(zip bzip2 lzip xz);
3653 error (option 'no-dist-gzip',
3654 "no-dist-gzip specified but no dist-* specified,\n"
3655 . "at least one archive format must be enabled")
3656 unless $archive_defined;
3659 # Look for common files that should be included in distribution.
3660 # If the aux dir is set, and it does not have a Makefile.am, then
3661 # we check for these files there as well.
3663 if ($relative_dir eq '.'
3664 && $config_aux_dir_set_in_configure_ac)
3666 if (! is_make_dir ($config_aux_dir))
3671 foreach my $cfile (@common_files)
3673 if (dir_has_case_matching_file ($relative_dir, $cfile)
3674 # The file might be absent, but if it can be built it's ok.
3677 push_dist_common ($cfile);
3680 # Don't use 'elsif' here because a file might meaningfully
3681 # appear in both directories.
3682 if ($check_aux && dir_has_case_matching_file ($config_aux_dir, $cfile))
3684 push_dist_common ("$config_aux_dir/$cfile")
3688 # We might copy elements from @configure_dist_common to
3689 # @dist_common if we think we need to. If the file appears in our
3690 # directory, we would have discovered it already, so we don't
3691 # check that. But if the file is in a subdir without a Makefile,
3692 # we want to distribute it here if we are doing '.'. Ugly!
3693 # Also, in some corner cases, it's possible that the following code
3694 # will cause the same file to appear in the $(DIST_COMMON) variables
3695 # of two distinct Makefiles; but this is not a problem, since the
3696 # 'distdir' target in 'lib/am/distdir.am' can deal with the same
3697 # file being distributed multiple times.
3698 # See also automake bug#9651.
3699 if ($relative_dir eq '.')
3701 foreach my $file (@configure_dist_common)
3703 my $dir = dirname ($file);
3704 push_dist_common ($file)
3705 if ($dir eq '.' || ! is_make_dir ($dir));
3707 @configure_dist_common = ();
3710 # $(am__DIST_COMMON): files to be distributed automatically. Will be
3711 # appended to $(DIST_COMMON) in the generated Makefile.
3712 # Use 'sort' so that the expansion of $(DIST_COMMON) in the generated
3713 # Makefile is deterministic, in face of m4 and/or perl randomizations
3714 # (see automake bug#17908).
3715 define_pretty_variable ('am__DIST_COMMON', TRUE, INTERNAL,
3716 uniq (sort @dist_common));
3718 # Now that we've processed @dist_common, disallow further attempts
3720 $handle_dist_run = 1;
3722 $transform{'DISTCHECK-HOOK'} = !! rule 'distcheck-hook';
3723 $transform{'GETTEXT'} = $seen_gettext && !$seen_gettext_external;
3725 # If the target 'dist-hook' exists, make sure it is run. This
3726 # allows users to do random weird things to the distribution
3727 # before it is packaged up.
3728 push (@dist_targets, 'dist-hook')
3729 if user_phony_rule 'dist-hook';
3730 $transform{'DIST-TARGETS'} = join (' ', @dist_targets);
3732 my $flm = option ('filename-length-max');
3733 my $filename_filter = $flm ? '.' x $flm->[1] : '';
3735 $output_rules .= file_contents ('distdir',
3736 new Automake::Location,
3738 FILENAME_FILTER => $filename_filter);
3742 # check_directory ($NAME, $WHERE [, $RELATIVE_DIR = "."])
3743 # -------------------------------------------------------
3744 # Ensure $NAME is a directory (in $RELATIVE_DIR), and that it uses a sane
3745 # name. Use $WHERE as a location in the diagnostic, if any.
3748 my ($dir, $where, $reldir) = @_;
3749 $reldir = '.' unless defined $reldir;
3751 error $where, "required directory $reldir/$dir does not exist"
3752 unless -d "$reldir/$dir";
3754 # If an 'obj/' directory exists, BSD make will enter it before
3755 # reading 'Makefile'. Hence the 'Makefile' in the current directory
3761 # % cat obj/Makefile
3767 # % pmake # BSD make
3770 msg ('portability', $where,
3771 "naming a subdirectory 'obj' causes troubles with BSD make")
3774 # 'aux' is probably the most important of the following forbidden name,
3775 # since it's tempting to use it as an AC_CONFIG_AUX_DIR.
3776 msg ('portability', $where,
3777 "name '$dir' is reserved on W32 and DOS platforms")
3778 if grep (/^\Q$dir\E$/i, qw/aux lpt1 lpt2 lpt3 com1 com2 com3 com4 con prn/);
3781 # check_directories_in_var ($VARIABLE)
3782 # ------------------------------------
3783 # Recursively check all items in variables $VARIABLE as directories
3784 sub check_directories_in_var
3787 $var->traverse_recursively
3790 my ($var, $val, $cond, $full_cond) = @_;
3791 check_directory ($val, $var->rdef ($cond)->location, $relative_dir);
3795 skip_ac_subst => 1);
3799 sub handle_subdirs ()
3801 my $subdirs = var ('SUBDIRS');
3805 check_directories_in_var $subdirs;
3807 my $dsubdirs = var ('DIST_SUBDIRS');
3808 check_directories_in_var $dsubdirs
3811 $output_rules .= file_contents ('subdirs', new Automake::Location);
3812 rvar ('RECURSIVE_TARGETS')->rdef (TRUE)->{'pretty'} = VAR_SORTED; # Gross!
3816 # ($REGEN, @DEPENDENCIES)
3819 # If aclocal.m4 creation is automated, return the list of its dependencies.
3820 sub scan_aclocal_m4 ()
3822 my $regen_aclocal = 0;
3824 set_seen 'CONFIG_STATUS_DEPENDENCIES';
3825 set_seen 'CONFIGURE_DEPENDENCIES';
3827 if (-f 'aclocal.m4')
3829 define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4', INTERNAL);
3831 my $aclocal = new Automake::XFile "< aclocal.m4";
3832 my $line = $aclocal->getline;
3833 $regen_aclocal = $line =~ 'generated automatically by aclocal';
3836 reject_var ('ACLOCAL_M4_SOURCES',
3837 "'ACLOCAL_M4_SOURCES' is obsolete; just remove it");
3839 # Note that it might be possible that aclocal.m4 doesn't exist but
3840 # should be auto-generated. This case probably isn't very
3842 return $regen_aclocal;
3846 # Helper function for 'substitute_ac_subst_variables'.
3847 sub substitute_ac_subst_variables_worker
3850 return "\@$token\@" if var $token;
3851 return "\${$token\}";
3854 # substitute_ac_subst_variables ($TEXT)
3855 # -------------------------------------
3856 # Replace any occurrence of ${FOO} in $TEXT by @FOO@ if FOO is an AC_SUBST
3858 sub substitute_ac_subst_variables
3861 $text =~ s/\$[{]([^ \t=:+{}]+)}/substitute_ac_subst_variables_worker ($1)/ge;
3866 # prepend_srcdir (@INPUTS)
3867 # ------------------------
3868 # Prepend $(srcdir) or $(top_srcdir) to all @INPUTS. The idea is that
3869 # if an input file has a directory part the same as the current
3870 # directory, then the directory part is simply replaced by $(srcdir).
3871 # But if the directory part is different, then $(top_srcdir) is
3878 foreach my $single (@inputs)
3880 if (dirname ($single) eq $relative_dir)
3882 push (@newinputs, '$(srcdir)/' . basename ($single));
3886 push (@newinputs, '$(top_srcdir)/' . $single);
3893 # rewrite_inputs_into_dependencies ($OUTPUT, @INPUTS)
3894 # ---------------------------------------------------
3895 # Compute a list of dependencies appropriate for the rebuild
3897 # AC_CONFIG_FILES($OUTPUT:$INPUT[0]:$INPUTS[1]:...)
3898 # Also distribute $INPUTs which are not built by another AC_CONFIG_FOOs.
3899 sub rewrite_inputs_into_dependencies
3901 my ($file, @inputs) = @_;
3906 # We cannot create dependencies on shell variables.
3907 next if (substitute_ac_subst_variables $i) =~ /\$/;
3909 if (exists $ac_config_files_location{$i} && $i ne $file)
3911 my $di = dirname $i;
3912 if ($di eq $relative_dir)
3916 # In the top-level Makefile we do not use $(top_builddir), because
3917 # we are already there, and since the targets are built without
3918 # a $(top_builddir), it helps BSD Make to match them with
3920 elsif ($relative_dir ne '.')
3922 $i = '$(top_builddir)/' . $i;
3927 msg ('error', $ac_config_files_location{$file},
3928 "required file '$i' not found")
3929 unless $i =~ /\$/ || exists $output_files{$i} || -f $i;
3930 ($i) = prepend_srcdir ($i);
3931 push_dist_common ($i);
3940 # handle_configure ($MAKEFILE_AM, $MAKEFILE_IN, $MAKEFILE, @INPUTS)
3941 # -----------------------------------------------------------------
3942 # Handle remaking and configure stuff.
3943 # We need the name of the input file, to do proper remaking rules.
3944 sub handle_configure
3946 my ($makefile_am, $makefile_in, $makefile, @inputs) = @_;
3948 prog_error 'empty @inputs'
3951 my ($rel_makefile_am, $rel_makefile_in) = prepend_srcdir ($makefile_am,
3953 my $rel_makefile = basename $makefile;
3955 my $colon_infile = ':' . join (':', @inputs);
3956 $colon_infile = '' if $colon_infile eq ":$makefile.in";
3957 my @rewritten = rewrite_inputs_into_dependencies ($makefile, @inputs);
3958 my $regen_aclocal_m4 = scan_aclocal_m4;
3959 define_pretty_variable ('am__aclocal_m4_deps', TRUE, INTERNAL,
3960 @configure_deps, "\$(top_srcdir)/$configure_ac");
3961 my @configuredeps = ('$(am__aclocal_m4_deps)', '$(CONFIGURE_DEPENDENCIES)');
3962 push @configuredeps, '$(ACLOCAL_M4)' if -f 'aclocal.m4';
3963 define_pretty_variable ('am__configure_deps', TRUE, INTERNAL,
3966 my $automake_options = '--' . $strictness_name .
3967 (global_option 'no-dependencies' ? ' --ignore-deps' : '');
3969 $output_rules .= file_contents
3971 new Automake::Location,
3972 MAKEFILE => $rel_makefile,
3973 'MAKEFILE-DEPS' => "@rewritten",
3974 'CONFIG-MAKEFILE' => ($relative_dir eq '.') ? '$@' : '$(subdir)/$@',
3975 'MAKEFILE-IN' => $rel_makefile_in,
3976 'HAVE-MAKEFILE-IN-DEPS' => (@include_stack > 0),
3977 'MAKEFILE-IN-DEPS' => "@include_stack",
3978 'MAKEFILE-AM' => $rel_makefile_am,
3979 'AUTOMAKE-OPTIONS' => $automake_options,
3980 'MAKEFILE-AM-SOURCES' => "$makefile$colon_infile",
3981 'REGEN-ACLOCAL-M4' => $regen_aclocal_m4,
3982 VERBOSE => verbose_flag ('GEN'));
3984 if ($relative_dir eq '.')
3986 push_dist_common ('acconfig.h')
3990 # If we have a configure header, require it.
3992 my @distclean_config;
3993 foreach my $spec (@config_headers)
3996 # $CONFIG_H_PATH: config.h from top level.
3997 my ($config_h_path, @ins) = split_config_file_spec ($spec);
3998 my $config_h_dir = dirname ($config_h_path);
4000 # If the header is in the current directory we want to build
4001 # the header here. Otherwise, if we're at the topmost
4002 # directory and the header's directory doesn't have a
4003 # Makefile, then we also want to build the header.
4004 if ($relative_dir eq $config_h_dir
4005 || ($relative_dir eq '.' && ! is_make_dir ($config_h_dir)))
4007 my ($cn_sans_dir, $stamp_dir);
4008 if ($relative_dir eq $config_h_dir)
4010 $cn_sans_dir = basename ($config_h_path);
4015 $cn_sans_dir = $config_h_path;
4016 if ($config_h_dir eq '.')
4022 $stamp_dir = $config_h_dir . '/';
4026 # This will also distribute all inputs.
4027 @ins = rewrite_inputs_into_dependencies ($config_h_path, @ins);
4029 # Cannot define rebuild rules for filenames with shell variables.
4030 next if (substitute_ac_subst_variables $config_h_path) =~ /\$/;
4032 # Header defined in this directory.
4034 if (-f $config_h_path . '.top')
4036 push (@files, "$cn_sans_dir.top");
4038 if (-f $config_h_path . '.bot')
4040 push (@files, "$cn_sans_dir.bot");
4043 push_dist_common (@files);
4045 # For now, acconfig.h can only appear in the top srcdir.
4046 if (-f 'acconfig.h')
4048 push (@files, '$(top_srcdir)/acconfig.h');
4051 my $stamp = "${stamp_dir}stamp-h${hdr_index}";
4053 file_contents ('remake-hdr',
4054 new Automake::Location,
4056 'FIRST-HDR' => ($hdr_index == 1),
4057 CONFIG_H => $cn_sans_dir,
4058 CONFIG_HIN => $ins[0],
4059 CONFIG_H_DEPS => "@ins",
4060 CONFIG_H_PATH => $config_h_path,
4063 push @distclean_config, $cn_sans_dir, $stamp;
4067 $output_rules .= file_contents ('clean-hdr',
4068 new Automake::Location,
4069 FILES => "@distclean_config")
4070 if @distclean_config;
4072 # Distribute and define mkinstalldirs only if it is already present
4073 # in the package, for backward compatibility (some people may still
4074 # use $(mkinstalldirs)).
4075 # TODO: start warning about this in Automake 1.14, and have
4076 # TODO: Automake 2.0 drop it (and the mkinstalldirs script
4078 my $mkidpath = "$config_aux_dir/mkinstalldirs";
4081 # Use require_file so that any existing script gets updated
4082 # by --force-missing.
4083 require_conf_file ($mkidpath, FOREIGN, 'mkinstalldirs');
4084 define_variable ('mkinstalldirs',
4085 "\$(SHELL) $am_config_aux_dir/mkinstalldirs", INTERNAL);
4089 # Use $(install_sh), not $(MKDIR_P) because the latter requires
4090 # at least one argument, and $(mkinstalldirs) used to work
4091 # even without arguments (e.g. $(mkinstalldirs) $(conditional_dir)).
4092 define_variable ('mkinstalldirs', '$(install_sh) -d', INTERNAL);
4095 reject_var ('CONFIG_HEADER',
4096 "'CONFIG_HEADER' is an anachronism; now determined "
4097 . "automatically\nfrom '$configure_ac'");
4100 foreach my $spec (@config_headers)
4102 my ($out, @ins) = split_config_file_spec ($spec);
4103 # Generate CONFIG_HEADER define.
4104 if ($relative_dir eq dirname ($out))
4106 push @config_h, basename ($out);
4110 push @config_h, "\$(top_builddir)/$out";
4113 define_variable ("CONFIG_HEADER", "@config_h", INTERNAL)
4116 # Now look for other files in this directory which must be remade
4117 # by config.status, and generate rules for them.
4118 my @actual_other_files = ();
4119 # These get cleaned only in a VPATH build.
4120 my @actual_other_vpath_files = ();
4121 foreach my $lfile (@other_input_files)
4125 if ($lfile =~ /^([^:]*):(.*)$/)
4127 # This is the ":" syntax of AC_OUTPUT.
4129 @inputs = split (':', $2);
4135 @inputs = $file . '.in';
4138 # Automake files should not be stored in here, but in %MAKE_LIST.
4139 prog_error ("$lfile in \@other_input_files\n"
4140 . "\@other_input_files = (@other_input_files)")
4141 if -f $file . '.am';
4143 my $local = basename ($file);
4145 # We skip files that aren't in this directory. However, if
4146 # the file's directory does not have a Makefile, and we are
4147 # currently doing '.', then we create a rule to rebuild the
4148 # file in the subdir.
4149 my $fd = dirname ($file);
4150 if ($fd ne $relative_dir)
4152 if ($relative_dir eq '.' && ! is_make_dir ($fd))
4162 my @rewritten_inputs = rewrite_inputs_into_dependencies ($file, @inputs);
4164 # Cannot output rules for shell variables.
4165 next if (substitute_ac_subst_variables $local) =~ /\$/;
4168 my $cond = $ac_config_files_condition{$lfile};
4171 $condstr = $cond->subst_string;
4172 Automake::Rule::define ($local, $configure_ac, RULE_AUTOMAKE, $cond,
4173 $ac_config_files_location{$file});
4175 $output_rules .= ($condstr . $local . ': '
4176 . '$(top_builddir)/config.status '
4177 . "@rewritten_inputs\n"
4179 . 'cd $(top_builddir) && '
4180 . '$(SHELL) ./config.status '
4181 . ($relative_dir eq '.' ? '' : '$(subdir)/')
4184 push (@actual_other_files, $local);
4187 # For links we should clean destinations and distribute sources.
4188 foreach my $spec (@config_links)
4190 my ($link, $file) = split /:/, $spec;
4191 # Some people do AC_CONFIG_LINKS($computed). We only handle
4192 # the DEST:SRC form.
4194 my $where = $ac_config_files_location{$link};
4196 # Skip destinations that contain shell variables.
4197 if ((substitute_ac_subst_variables $link) !~ /\$/)
4199 # We skip links that aren't in this directory. However, if
4200 # the link's directory does not have a Makefile, and we are
4201 # currently doing '.', then we add the link to CONFIG_CLEAN_FILES
4202 # in '.'s Makefile.in.
4203 my $local = basename ($link);
4204 my $fd = dirname ($link);
4205 if ($fd ne $relative_dir)
4207 if ($relative_dir eq '.' && ! is_make_dir ($fd))
4218 push @actual_other_files, $local if $local;
4222 push @actual_other_vpath_files, $local if $local;
4226 # Do not process sources that contain shell variables.
4227 if ((substitute_ac_subst_variables $file) !~ /\$/)
4229 my $fd = dirname ($file);
4231 # We distribute files that are in this directory.
4232 # At the top-level ('.') we also distribute files whose
4233 # directory does not have a Makefile.
4234 if (($fd eq $relative_dir)
4235 || ($relative_dir eq '.' && ! is_make_dir ($fd)))
4237 # The following will distribute $file as a side-effect when
4238 # it is appropriate (i.e., when $file is not already an output).
4239 # We do not need the result, just the side-effect.
4240 rewrite_inputs_into_dependencies ($link, $file);
4245 # These files get removed by "make distclean".
4246 define_pretty_variable ('CONFIG_CLEAN_FILES', TRUE, INTERNAL,
4247 @actual_other_files);
4248 define_pretty_variable ('CONFIG_CLEAN_VPATH_FILES', TRUE, INTERNAL,
4249 @actual_other_vpath_files);
4252 sub handle_headers ()
4254 my @r = am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
4255 'oldinclude', 'pkginclude',
4259 next unless $_->[1] =~ /\..*$/;
4264 sub handle_gettext ()
4266 return if ! $seen_gettext || $relative_dir ne '.';
4268 my $subdirs = var 'SUBDIRS';
4272 err_ac "AM_GNU_GETTEXT used but SUBDIRS not defined";
4276 # Perform some sanity checks to help users get the right setup.
4277 # We disable these tests when po/ doesn't exist in order not to disallow
4278 # unusual gettext setups.
4283 # | 1) If a package doesn't have a directory po/ at top level, it
4284 # | will likely have multiple po/ directories in subpackages.
4286 # | 2) It is useful to warn for the absence of intl/ if AM_GNU_GETTEXT
4287 # | is used without 'external'. It is also useful to warn for the
4288 # | presence of intl/ if AM_GNU_GETTEXT([external]) is used. Both
4289 # | warnings apply only to the usual layout of packages, therefore
4290 # | they should both be disabled if no po/ directory is found at
4295 my @subdirs = $subdirs->value_as_list_recursive;
4297 msg_var ('syntax', $subdirs,
4298 "AM_GNU_GETTEXT used but 'po' not in SUBDIRS")
4299 if ! grep ($_ eq 'po', @subdirs);
4301 # intl/ is not required when AM_GNU_GETTEXT is called with the
4302 # 'external' option and AM_GNU_GETTEXT_INTL_SUBDIR is not called.
4303 msg_var ('syntax', $subdirs,
4304 "AM_GNU_GETTEXT used but 'intl' not in SUBDIRS")
4305 if (! ($seen_gettext_external && ! $seen_gettext_intl)
4306 && ! grep ($_ eq 'intl', @subdirs));
4308 # intl/ should not be used with AM_GNU_GETTEXT([external]), except
4309 # if AM_GNU_GETTEXT_INTL_SUBDIR is called.
4310 msg_var ('syntax', $subdirs,
4311 "'intl' should not be in SUBDIRS when "
4312 . "AM_GNU_GETTEXT([external]) is used")
4313 if ($seen_gettext_external && ! $seen_gettext_intl
4314 && grep ($_ eq 'intl', @subdirs));
4317 require_file ($ac_gettext_location, GNU, 'ABOUT-NLS');
4320 # Emit makefile footer.
4321 sub handle_footer ()
4323 reject_rule ('.SUFFIXES',
4324 "use variable 'SUFFIXES', not target '.SUFFIXES'");
4326 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
4327 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
4328 # anything else, by sticking it right after the default: target.
4329 $output_header .= ".SUFFIXES:\n";
4330 my $suffixes = var 'SUFFIXES';
4331 my @suffixes = Automake::Rule::suffixes;
4332 if (@suffixes || $suffixes)
4334 # Make sure SUFFIXES has unique elements. Sort them to ensure
4335 # the output remains consistent. However, $(SUFFIXES) is
4336 # always at the start of the list, unsorted. This is done
4337 # because make will choose rules depending on the ordering of
4338 # suffixes, and this lets the user have some control. Push
4339 # actual suffixes, and not $(SUFFIXES). Some versions of make
4340 # do not like variable substitutions on the .SUFFIXES line.
4341 my @user_suffixes = ($suffixes
4342 ? $suffixes->value_as_list_recursive : ());
4344 my %suffixes = map { $_ => 1 } @suffixes;
4345 delete @suffixes{@user_suffixes};
4347 $output_header .= (".SUFFIXES: "
4348 . join (' ', @user_suffixes, sort keys %suffixes)
4352 $output_trailer .= file_contents ('footer', new Automake::Location);
4356 # Generate 'make install' rules.
4357 sub handle_install ()
4359 $output_rules .= file_contents
4361 new Automake::Location,
4362 maybe_BUILT_SOURCES => (set_seen ('BUILT_SOURCES')
4363 ? (" \$(BUILT_SOURCES)\n"
4364 . "\t\$(MAKE) \$(AM_MAKEFLAGS)")
4366 'installdirs-local' => (user_phony_rule ('installdirs-local')
4367 ? ' installdirs-local' : ''),
4368 am__installdirs => variable_value ('am__installdirs') || '');
4372 # handle_all ($MAKEFILE)
4373 #-----------------------
4374 # Deal with 'all' and 'all-am'.
4377 my ($makefile) = @_;
4381 # Put this at the beginning for the sake of non-GNU makes. This
4382 # is still wrong if these makes can run parallel jobs. But it is
4384 unshift (@all, basename ($makefile));
4386 foreach my $spec (@config_headers)
4388 my ($out, @ins) = split_config_file_spec ($spec);
4389 push (@all, basename ($out))
4390 if dirname ($out) eq $relative_dir;
4393 # Install 'all' hooks.
4394 push (@all, "all-local")
4395 if user_phony_rule "all-local";
4397 pretty_print_rule ("all-am:", "\t\t", @all);
4398 depend ('.PHONY', 'all-am', 'all');
4403 my @local_headers = ();
4404 push @local_headers, '$(BUILT_SOURCES)'
4405 if var ('BUILT_SOURCES');
4406 foreach my $spec (@config_headers)
4408 my ($out, @ins) = split_config_file_spec ($spec);
4409 push @local_headers, basename ($out)
4410 if dirname ($out) eq $relative_dir;
4415 # We need to make sure config.h is built before we recurse.
4416 # We also want to make sure that built sources are built
4417 # before any ordinary 'all' targets are run. We can't do this
4418 # by changing the order of dependencies to the "all" because
4419 # that breaks when using parallel makes. Instead we handle
4420 # things explicitly.
4421 $output_all .= ("all: @local_headers"
4423 . '$(MAKE) $(AM_MAKEFLAGS) '
4424 . (var ('SUBDIRS') ? 'all-recursive' : 'all-am')
4426 depend ('.MAKE', 'all');
4430 $output_all .= "all: " . (var ('SUBDIRS')
4431 ? 'all-recursive' : 'all-am') . "\n\n";
4435 # Generate helper targets for user-defined recursive targets, where needed.
4436 sub handle_user_recursion ()
4438 return unless @extra_recursive_targets;
4440 define_pretty_variable ('am__extra_recursive_targets', TRUE, INTERNAL,
4441 map { "$_-recursive" } @extra_recursive_targets);
4442 my $aux = var ('SUBDIRS') ? 'recursive' : 'am';
4443 foreach my $target (@extra_recursive_targets)
4445 # This allows the default target's rules to be overridden in
4447 user_phony_rule ($target);
4448 depend ("$target", "$target-$aux");
4449 depend ("$target-am", "$target-local");
4450 # Every user-defined recursive target 'foo' *must* have a valid
4451 # associated 'foo-local' rule; we define it as an empty rule by
4452 # default, so that the user can transparently extend it in his
4454 pretty_print_rule ("$target-local:", '', '');
4455 # $target-recursive might as well be undefined, so do not add
4456 # it here; it's taken care of in subdirs.am anyway.
4457 depend (".PHONY", "$target-am", "$target-local");
4462 # Handle check merge target specially.
4463 sub do_check_merge_target ()
4465 # Include user-defined local form of target.
4466 push @check_tests, 'check-local'
4467 if user_phony_rule 'check-local';
4469 # The check target must depend on the local equivalent of
4470 # 'all', to ensure all the primary targets are built. Then it
4471 # must build the local check rules.
4472 $output_rules .= "check-am: all-am\n";
4475 pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @check);
4476 depend ('.MAKE', 'check-am');
4481 pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4483 depend ('.MAKE', 'check-am');
4486 depend '.PHONY', 'check', 'check-am';
4487 # Handle recursion. We have to honor BUILT_SOURCES like for 'all:'.
4488 $output_rules .= ("check: "
4489 . (var ('BUILT_SOURCES')
4490 ? "\$(BUILT_SOURCES)\n\t\$(MAKE) \$(AM_MAKEFLAGS) "
4492 . (var ('SUBDIRS') ? 'check-recursive' : 'check-am')
4494 depend ('.MAKE', 'check')
4495 if var ('BUILT_SOURCES');
4498 # Handle all 'clean' targets.
4501 my ($makefile) = @_;
4503 # Clean the files listed in user variables if they exist.
4504 $clean_files{'$(MOSTLYCLEANFILES)'} = MOSTLY_CLEAN
4505 if var ('MOSTLYCLEANFILES');
4506 $clean_files{'$(CLEANFILES)'} = CLEAN
4507 if var ('CLEANFILES');
4508 $clean_files{'$(DISTCLEANFILES)'} = DIST_CLEAN
4509 if var ('DISTCLEANFILES');
4510 $clean_files{'$(MAINTAINERCLEANFILES)'} = MAINTAINER_CLEAN
4511 if var ('MAINTAINERCLEANFILES');
4513 # Built sources are automatically removed by maintainer-clean.
4514 $clean_files{'$(BUILT_SOURCES)'} = MAINTAINER_CLEAN
4515 if var ('BUILT_SOURCES');
4517 # Compute a list of "rm"s to run for each target.
4518 my %rms = (MOSTLY_CLEAN, [],
4521 MAINTAINER_CLEAN, []);
4523 foreach my $file (keys %clean_files)
4525 my $when = $clean_files{$file};
4526 prog_error 'invalid entry in %clean_files'
4527 unless exists $rms{$when};
4529 my $rm = "rm -f $file";
4530 # If file is a variable, make sure when don't call 'rm -f' without args.
4531 $rm ="test -z \"$file\" || $rm"
4532 if ($file =~ /^\s*\$(\(.*\)|\{.*\})\s*$/);
4534 push @{$rms{$when}}, "\t-$rm\n";
4537 $output_rules .= file_contents
4539 new Automake::Location,
4540 MOSTLYCLEAN_RMS => join ('', sort @{$rms{&MOSTLY_CLEAN}}),
4541 CLEAN_RMS => join ('', sort @{$rms{&CLEAN}}),
4542 DISTCLEAN_RMS => join ('', sort @{$rms{&DIST_CLEAN}}),
4543 MAINTAINER_CLEAN_RMS => join ('', sort @{$rms{&MAINTAINER_CLEAN}}),
4544 MAKEFILE => basename $makefile,
4549 # Subroutine for handle_factored_dependencies() to let '.PHONY' and
4550 # other '.TARGETS' be last. This is meant to be used as a comparison
4551 # subroutine passed to the sort built-int.
4554 return 0 if $a eq $b;
4556 my $a1 = substr ($a, 0, 1);
4557 my $b1 = substr ($b, 0, 1);
4560 return -1 if $b1 eq '.';
4561 return 1 if $a1 eq '.';
4567 # Handle everything related to gathered targets.
4568 sub handle_factored_dependencies ()
4571 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4572 'uninstall-exec-local', 'uninstall-exec-hook',
4573 'uninstall-dvi-local',
4574 'uninstall-html-local',
4575 'uninstall-info-local',
4576 'uninstall-pdf-local',
4577 'uninstall-ps-local')
4581 reject_rule ($utarg, "use '$x', not '$utarg'");
4584 reject_rule ('install-local',
4585 "use 'install-data-local' or 'install-exec-local', "
4586 . "not 'install-local'");
4588 reject_rule ('install-hook',
4589 "use 'install-data-hook' or 'install-exec-hook', "
4590 . "not 'install-hook'");
4592 # Install the -local hooks.
4593 foreach (keys %dependencies)
4595 # Hooks are installed on the -am targets.
4597 depend ("$_-am", "$_-local")
4598 if user_phony_rule "$_-local";
4601 # Install the -hook hooks.
4602 # FIXME: Why not be as liberal as we are with -local hooks?
4603 foreach ('install-exec', 'install-data', 'uninstall')
4605 if (user_phony_rule "$_-hook")
4607 depend ('.MAKE', "$_-am");
4608 register_action("$_-am",
4609 ("\t\@\$(NORMAL_INSTALL)\n"
4610 . "\t\$(MAKE) \$(AM_MAKEFLAGS) $_-hook"));
4614 # All the required targets are phony.
4615 depend ('.PHONY', keys %required_targets);
4617 # Actually output gathered targets.
4618 foreach (sort target_cmp keys %dependencies)
4620 # If there is nothing about this guy, skip it.
4622 unless (@{$dependencies{$_}}
4624 || $required_targets{$_});
4626 # Define gathered targets in undefined conditions.
4627 # FIXME: Right now we must handle .PHONY as an exception,
4628 # because people write things like
4629 # .PHONY: myphonytarget
4630 # to append dependencies. This would not work if Automake
4631 # refrained from defining its own .PHONY target as it does
4632 # with other overridden targets.
4633 # Likewise for '.MAKE' and '.PRECIOUS'.
4634 my @undefined_conds = (TRUE,);
4635 if ($_ ne '.PHONY' && $_ ne '.MAKE' && $_ ne '.PRECIOUS')
4638 Automake::Rule::define ($_, 'internal',
4639 RULE_AUTOMAKE, TRUE, INTERNAL);
4641 my @uniq_deps = uniq (sort @{$dependencies{$_}});
4642 foreach my $cond (@undefined_conds)
4644 my $condstr = $cond->subst_string;
4645 pretty_print_rule ("$condstr$_:", "$condstr\t", @uniq_deps);
4646 $output_rules .= $actions{$_} if defined $actions{$_};
4647 $output_rules .= "\n";
4653 sub handle_tests_dejagnu ()
4655 push (@check_tests, 'check-DEJAGNU');
4656 $output_rules .= file_contents ('dejagnu', new Automake::Location);
4659 # handle_per_suffix_test ($TEST_SUFFIX, [%TRANSFORM])
4660 #----------------------------------------------------
4661 sub handle_per_suffix_test
4663 my ($test_suffix, %transform) = @_;
4664 my ($pfx, $generic, $am_exeext);
4665 if ($test_suffix eq '')
4669 $am_exeext = 'FALSE';
4673 prog_error ("test suffix '$test_suffix' lacks leading dot")
4674 unless $test_suffix =~ m/^\.(.*)/;
4675 $pfx = uc ($1) . '_';
4677 $am_exeext = exists $configure_vars{'EXEEXT'} ? 'am__EXEEXT'
4680 # The "test driver" program, deputed to handle tests protocol used by
4681 # test scripts. By default, it's assumed that no protocol is used, so
4682 # we fall back to the old behaviour, implemented by the 'test-driver'
4684 if (! var "${pfx}LOG_DRIVER")
4686 require_conf_file ("parallel-tests", FOREIGN, 'test-driver');
4687 define_variable ("${pfx}LOG_DRIVER",
4688 "\$(SHELL) $am_config_aux_dir/test-driver",
4691 my $driver = '$(' . $pfx . 'LOG_DRIVER)';
4692 my $driver_flags = '$(AM_' . $pfx . 'LOG_DRIVER_FLAGS)'
4693 . ' $(' . $pfx . 'LOG_DRIVER_FLAGS)';
4694 my $compile = "${pfx}LOG_COMPILE";
4695 define_variable ($compile,
4696 '$(' . $pfx . 'LOG_COMPILER)'
4697 . ' $(AM_' . $pfx . 'LOG_FLAGS)'
4698 . ' $(' . $pfx . 'LOG_FLAGS)',
4700 $output_rules .= file_contents ('check2', new Automake::Location,
4701 GENERIC => $generic,
4703 DRIVER_FLAGS => $driver_flags,
4704 COMPILE => '$(' . $compile . ')',
4705 EXT => $test_suffix,
4706 am__EXEEXT => $am_exeext,
4710 # is_valid_test_extension ($EXT)
4711 # ------------------------------
4712 # Return true if $EXT can appear in $(TEST_EXTENSIONS), return false
4714 sub is_valid_test_extension
4718 if ($ext =~ /^\.[a-zA-Z_][a-zA-Z0-9_]*$/);
4720 if (exists $configure_vars{'EXEEXT'} && $ext eq subst ('EXEEXT'));
4727 if (option 'dejagnu')
4729 handle_tests_dejagnu;
4733 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4735 reject_var ($c, "'$c' defined but 'dejagnu' not in "
4736 . "'AUTOMAKE_OPTIONS'");
4742 push (@check_tests, 'check-TESTS');
4743 my $check_deps = "@check";
4744 $output_rules .= file_contents ('check', new Automake::Location,
4745 SERIAL_TESTS => !! option 'serial-tests',
4746 CHECK_DEPS => $check_deps);
4748 # Tests that are known programs should have $(EXEEXT) appended.
4749 # For matching purposes, we need to adjust XFAIL_TESTS as well.
4750 append_exeext { exists $known_programs{$_[0]} } 'TESTS';
4751 append_exeext { exists $known_programs{$_[0]} } 'XFAIL_TESTS'
4752 if (var ('XFAIL_TESTS'));
4754 if (! option 'serial-tests')
4756 define_variable ('TEST_SUITE_LOG', 'test-suite.log', INTERNAL);
4759 my $handle_exeext = exists $configure_vars{'EXEEXT'};
4762 $at_exeext = subst ('EXEEXT');
4763 $suff = $at_exeext . ' ' . $suff;
4765 if (! var 'TEST_EXTENSIONS')
4767 define_variable ('TEST_EXTENSIONS', $suff, INTERNAL);
4769 my $var = var 'TEST_EXTENSIONS';
4770 # Currently, we are not able to deal with conditional contents
4771 # in TEST_EXTENSIONS.
4772 if ($var->has_conditional_contents)
4774 msg_var 'unsupported', $var,
4775 "'TEST_EXTENSIONS' cannot have conditional contents";
4777 my @test_suffixes = $var->value_as_list_recursive;
4778 if ((my @invalid_test_suffixes =
4779 grep { !is_valid_test_extension $_ } @test_suffixes) > 0)
4781 error $var->rdef (TRUE)->location,
4782 "invalid test extensions: @invalid_test_suffixes";
4784 @test_suffixes = grep { is_valid_test_extension $_ } @test_suffixes;
4787 unshift (@test_suffixes, $at_exeext)
4788 unless $test_suffixes[0] eq $at_exeext;
4790 unshift (@test_suffixes, '');
4792 transform_variable_recursively
4793 ('TESTS', 'TEST_LOGS', 'am__testlogs', 1, INTERNAL,
4795 my ($subvar, $val, $cond, $full_cond) = @_;
4798 if $val =~ /^\@.*\@$/;
4799 $obj =~ s/\$\(EXEEXT\)$//o;
4801 if ($val =~ /(\$\((top_)?srcdir\))\//o)
4803 msg ('error', $subvar->rdef ($cond)->location,
4804 "using '$1' in TESTS is currently broken: '$val'");
4807 foreach my $test_suffix (@test_suffixes)
4810 if $test_suffix eq $at_exeext || $test_suffix eq '';
4811 return substr ($obj, 0, length ($obj) - length ($test_suffix)) . '.log'
4812 if substr ($obj, - length ($test_suffix)) eq $test_suffix;
4816 handle_per_suffix_test ('',
4826 my $last_suffix = $test_suffixes[$#test_suffixes];
4828 foreach my $test_suffix (@test_suffixes)
4830 if ($test_suffix eq $last_suffix)
4836 $cur = 'am__test_logs' . $nhelper;
4838 define_variable ($cur,
4839 '$(' . $prev . ':' . $test_suffix . $post . '=.log)', INTERNAL);
4843 if ($test_suffix ne $at_exeext && $test_suffix ne '')
4845 handle_per_suffix_test ($test_suffix,
4851 $clean_files{'$(TEST_LOGS)'} = MOSTLY_CLEAN;
4852 $clean_files{'$(TEST_LOGS:.log=.trs)'} = MOSTLY_CLEAN;
4853 $clean_files{'$(TEST_SUITE_LOG)'} = MOSTLY_CLEAN;
4858 sub handle_emacs_lisp ()
4860 my @elfiles = am_install_var ('-candist', 'lisp', 'LISP',
4863 return if ! @elfiles;
4865 define_pretty_variable ('am__ELFILES', TRUE, INTERNAL,
4866 map { $_->[1] } @elfiles);
4867 define_pretty_variable ('am__ELCFILES', TRUE, INTERNAL,
4868 '$(am__ELFILES:.el=.elc)');
4869 # This one can be overridden by users.
4870 define_pretty_variable ('ELCFILES', TRUE, INTERNAL, '$(LISP:.el=.elc)');
4872 push @all, '$(ELCFILES)';
4874 require_variables ($elfiles[0][0], "Emacs Lisp sources seen", TRUE,
4875 'EMACS', 'lispdir');
4878 sub handle_python ()
4880 my @pyfiles = am_install_var ('-defaultdist', 'python', 'PYTHON',
4882 return if ! @pyfiles;
4884 require_variables ($pyfiles[0][0], "Python sources seen", TRUE, 'PYTHON');
4885 require_conf_file ($pyfiles[0][0], FOREIGN, 'py-compile');
4886 define_variable ('py_compile', "$am_config_aux_dir/py-compile", INTERNAL);
4891 my @sourcelist = am_install_var ('-candist',
4894 return if ! @sourcelist;
4896 my @prefixes = am_primary_prefixes ('JAVA', 1,
4900 my @java_sources = ();
4901 foreach my $prefix (@prefixes)
4903 (my $curs = $prefix) =~ s/^(?:nobase_)?(?:dist_|nodist_)?//;
4906 if $curs eq 'EXTRA';
4908 push @java_sources, '$(' . $prefix . '_JAVA' . ')';
4912 err_var "${curs}_JAVA", "multiple _JAVA primaries in use"
4913 unless $curs eq $dir;
4919 define_pretty_variable ('am__java_sources', TRUE, INTERNAL,
4922 if ($dir eq 'check')
4924 push (@check, "class$dir.stamp");
4928 push (@all, "class$dir.stamp");
4933 sub handle_minor_options ()
4935 if (option 'readme-alpha')
4937 if ($relative_dir eq '.')
4939 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4941 msg ('error-gnits', $package_version_location,
4942 "version '$package_version' doesn't follow " .
4945 if (defined $1 && -f 'README-alpha')
4947 # This means we have an alpha release. See
4948 # GNITS_VERSION_PATTERN for details.
4949 push_dist_common ('README-alpha');
4955 ################################################################
4957 # ($OUTPUT, @INPUTS)
4958 # split_config_file_spec ($SPEC)
4959 # ------------------------------
4960 # Decode the Autoconf syntax for config files (files, headers, links
4962 sub split_config_file_spec
4965 my ($output, @inputs) = split (/:/, $spec);
4967 push @inputs, "$output.in"
4970 return ($output, @inputs);
4974 # locate_am (@POSSIBLE_SOURCES)
4975 # -----------------------------
4976 # AC_CONFIG_FILES allow specifications such as Makefile:top.in:mid.in:bot.in
4977 # This functions returns the first *.in file for which a *.am exists.
4978 # It returns undef otherwise.
4983 foreach my $file (@rest)
4985 if (($file =~ /^(.*)\.in$/) && -f "$1.am")
4996 # scan_autoconf_config_files ($WHERE, $CONFIG-FILES)
4997 # --------------------------------------------------
4998 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
5000 sub scan_autoconf_config_files
5002 my ($where, $config_files) = @_;
5004 # Look at potential Makefile.am's.
5005 foreach (split ' ', $config_files)
5007 # Must skip empty string for Perl 4.
5008 next if $_ eq "\\" || $_ eq '';
5010 # Handle $local:$input syntax.
5011 my ($local, @rest) = split (/:/);
5012 @rest = ("$local.in",) unless @rest;
5013 # Keep in sync with test 'conffile-leading-dot.sh'.
5014 msg ('unsupported', $where,
5015 "omit leading './' from config file names such as '$local';"
5016 . "\nremake rules might be subtly broken otherwise")
5017 if ($local =~ /^\.\//);
5018 my $input = locate_am @rest;
5021 # We have a file that automake should generate.
5022 $make_list{$input} = join (':', ($local, @rest));
5026 # We have a file that automake should cause to be
5027 # rebuilt, but shouldn't generate itself.
5028 push (@other_input_files, $_);
5030 $ac_config_files_location{$local} = $where;
5031 $ac_config_files_condition{$local} =
5032 new Automake::Condition (@cond_stack)
5038 sub scan_autoconf_traces
5040 my ($filename) = @_;
5042 # Macros to trace, with their minimal number of arguments.
5044 # IMPORTANT: If you add a macro here, you should also add this macro
5045 # ========= to Automake-preselection in autoconf/lib/autom4te.in.
5047 AC_CANONICAL_BUILD => 0,
5048 AC_CANONICAL_HOST => 0,
5049 AC_CANONICAL_TARGET => 0,
5050 AC_CONFIG_AUX_DIR => 1,
5051 AC_CONFIG_FILES => 1,
5052 AC_CONFIG_HEADERS => 1,
5053 AC_CONFIG_LIBOBJ_DIR => 1,
5054 AC_CONFIG_LINKS => 1,
5058 AC_REQUIRE_AUX_FILE => 1,
5059 AC_SUBST_TRACE => 1,
5060 AM_AUTOMAKE_VERSION => 1,
5061 AM_CONDITIONAL => 2,
5062 AM_EXTRA_RECURSIVE_TARGETS => 1,
5063 AM_GNU_GETTEXT => 0,
5064 AM_GNU_GETTEXT_INTL_SUBDIR => 0,
5065 AM_INIT_AUTOMAKE => 0,
5066 AM_MAINTAINER_MODE => 0,
5068 _AM_SUBST_NOTMAKE => 1,
5071 _AM_COND_ENDIF => 1,
5072 LT_SUPPORTED_TAG => 1,
5073 _LT_AC_TAGCONFIG => 0,
5079 my $traces = ($ENV{AUTOCONF} || '@am_AUTOCONF@') . " ";
5081 # Use a separator unlikely to be used, not ':', the default, which
5082 # has a precise meaning for AC_CONFIG_FILES and so on.
5083 $traces .= join (' ',
5084 map { "--trace=$_" . ':\$f:\$l::\$d::\$n::\${::}%' }
5087 my $tracefh = new Automake::XFile ("$traces $filename |");
5088 verb "reading $traces";
5093 while ($_ = $tracefh->getline)
5096 my ($here, $depth, @args) = split (/::/);
5097 $where = new Automake::Location $here;
5098 my $macro = $args[0];
5100 prog_error ("unrequested trace '$macro'")
5101 unless exists $traced{$macro};
5103 # Skip and diagnose malformed calls.
5104 if ($#args < $traced{$macro})
5106 msg ('syntax', $where, "not enough arguments for $macro");
5110 # Alphabetical ordering please.
5111 if ($macro eq 'AC_CANONICAL_BUILD')
5113 if ($seen_canonical <= AC_CANONICAL_BUILD)
5115 $seen_canonical = AC_CANONICAL_BUILD;
5118 elsif ($macro eq 'AC_CANONICAL_HOST')
5120 if ($seen_canonical <= AC_CANONICAL_HOST)
5122 $seen_canonical = AC_CANONICAL_HOST;
5125 elsif ($macro eq 'AC_CANONICAL_TARGET')
5127 $seen_canonical = AC_CANONICAL_TARGET;
5129 elsif ($macro eq 'AC_CONFIG_AUX_DIR')
5131 if ($seen_init_automake)
5133 error ($where, "AC_CONFIG_AUX_DIR must be called before "
5134 . "AM_INIT_AUTOMAKE ...", partial => 1);
5135 error ($seen_init_automake, "... AM_INIT_AUTOMAKE called here");
5137 $config_aux_dir = $args[1];
5138 $config_aux_dir_set_in_configure_ac = 1;
5139 check_directory ($config_aux_dir, $where);
5141 elsif ($macro eq 'AC_CONFIG_FILES')
5143 # Look at potential Makefile.am's.
5144 scan_autoconf_config_files ($where, $args[1]);
5146 elsif ($macro eq 'AC_CONFIG_HEADERS')
5148 foreach my $spec (split (' ', $args[1]))
5150 my ($dest, @src) = split (':', $spec);
5151 $ac_config_files_location{$dest} = $where;
5152 push @config_headers, $spec;
5155 elsif ($macro eq 'AC_CONFIG_LIBOBJ_DIR')
5157 $config_libobj_dir = $args[1];
5158 check_directory ($config_libobj_dir, $where);
5160 elsif ($macro eq 'AC_CONFIG_LINKS')
5162 foreach my $spec (split (' ', $args[1]))
5164 my ($dest, $src) = split (':', $spec);
5165 $ac_config_files_location{$dest} = $where;
5166 push @config_links, $spec;
5169 elsif ($macro eq 'AC_FC_SRCEXT')
5171 my $suffix = $args[1];
5172 $sourceflags{'.' . $suffix} = '$(FCFLAGS_' . $suffix . ')'
5173 if ($suffix eq 'f90' || $suffix eq 'f95' || $suffix eq 'f03' || $suffix eq 'f08');
5175 elsif ($macro eq 'AC_INIT')
5177 if (defined $args[2])
5179 $package_version = $args[2];
5180 $package_version_location = $where;
5183 elsif ($macro eq 'AC_LIBSOURCE')
5185 $libsources{$args[1]} = $here;
5187 elsif ($macro eq 'AC_REQUIRE_AUX_FILE')
5189 # Only remember the first time a file is required.
5190 $required_aux_file{$args[1]} = $where
5191 unless exists $required_aux_file{$args[1]};
5193 elsif ($macro eq 'AC_SUBST_TRACE')
5195 # Just check for alphanumeric in AC_SUBST_TRACE. If you do
5196 # AC_SUBST(5), then too bad.
5197 $configure_vars{$args[1]} = $where
5198 if $args[1] =~ /^\w+$/;
5200 elsif ($macro eq 'AM_AUTOMAKE_VERSION')
5203 "version mismatch. This is Automake $VERSION,\n" .
5204 "but the definition used by this AM_INIT_AUTOMAKE\n" .
5205 "comes from Automake $args[1]. You should recreate\n" .
5206 "aclocal.m4 with aclocal and run automake again.\n",
5207 # $? = 63 is used to indicate version mismatch to missing.
5209 if $VERSION ne $args[1];
5211 $seen_automake_version = 1;
5213 elsif ($macro eq 'AM_CONDITIONAL')
5215 $configure_cond{$args[1]} = $where;
5217 elsif ($macro eq 'AM_EXTRA_RECURSIVE_TARGETS')
5219 # Empty leading/trailing fields might be produced by split,
5220 # hence the grep is really needed.
5221 push @extra_recursive_targets,
5222 grep (/./, (split /\s+/, $args[1]));
5224 elsif ($macro eq 'AM_GNU_GETTEXT')
5226 $seen_gettext = $where;
5227 $ac_gettext_location = $where;
5228 $seen_gettext_external = grep ($_ eq 'external', @args);
5230 elsif ($macro eq 'AM_GNU_GETTEXT_INTL_SUBDIR')
5232 $seen_gettext_intl = $where;
5234 elsif ($macro eq 'AM_INIT_AUTOMAKE')
5236 $seen_init_automake = $where;
5237 if (defined $args[2])
5239 msg 'obsolete', $where, <<'EOF';
5240 AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:
5241 https://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
5243 $package_version = $args[2];
5244 $package_version_location = $where;
5246 elsif (defined $args[1])
5248 my @opts = split (' ', $args[1]);
5249 @opts = map { { option => $_, where => $where } } @opts;
5250 exit $exit_code unless process_global_option_list (@opts);
5253 elsif ($macro eq 'AM_MAINTAINER_MODE')
5255 $seen_maint_mode = $where;
5257 elsif ($macro eq 'AM_PROG_AR')
5261 elsif ($macro eq '_AM_COND_IF')
5263 cond_stack_if ('', $args[1], $where);
5264 error ($where, "missing m4 quoting, macro depth $depth")
5267 elsif ($macro eq '_AM_COND_ELSE')
5269 cond_stack_else ('!', $args[1], $where);
5270 error ($where, "missing m4 quoting, macro depth $depth")
5273 elsif ($macro eq '_AM_COND_ENDIF')
5275 cond_stack_endif (undef, undef, $where);
5276 error ($where, "missing m4 quoting, macro depth $depth")
5279 elsif ($macro eq '_AM_SUBST_NOTMAKE')
5281 $ignored_configure_vars{$args[1]} = $where;
5283 elsif ($macro eq 'm4_include'
5284 || $macro eq 'm4_sinclude'
5285 || $macro eq 'sinclude')
5287 # Skip missing 'sinclude'd files.
5288 next if $macro ne 'm4_include' && ! -f $args[1];
5290 # Some modified versions of Autoconf don't use
5291 # frozen files. Consequently it's possible that we see all
5292 # m4_include's performed during Autoconf's startup.
5293 # Obviously we don't want to distribute Autoconf's files
5294 # so we skip absolute filenames here.
5295 push @configure_deps, '$(top_srcdir)/' . $args[1]
5296 unless $here =~ m,^(?:\w:)?[\\/],;
5297 # Keep track of the greatest timestamp.
5300 my $mtime = mtime $args[1];
5301 $configure_deps_greatest_timestamp = $mtime
5302 if $mtime > $configure_deps_greatest_timestamp;
5305 elsif ($macro eq 'LT_SUPPORTED_TAG')
5307 $libtool_tags{$args[1]} = 1;
5308 $libtool_new_api = 1;
5310 elsif ($macro eq '_LT_AC_TAGCONFIG')
5312 # _LT_AC_TAGCONFIG is an old macro present in Libtool 1.5.
5313 # We use it to detect whether tags are supported. Our
5314 # preferred interface is LT_SUPPORTED_TAG, but it was
5315 # introduced in Libtool 1.6.
5316 if (0 == keys %libtool_tags)
5318 # Hardcode the tags supported by Libtool 1.5.
5319 %libtool_tags = (CC => 1, CXX => 1, GCJ => 1, F77 => 1);
5324 error ($where, "condition stack not properly closed")
5331 # Scan 'configure.ac' (and possibly 'aclocal.m4') for interesting things.
5332 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
5333 sub scan_autoconf_files ()
5335 # Reinitialize libsources here. This isn't really necessary,
5336 # since we currently assume there is only one configure.ac. But
5337 # that won't always be the case.
5340 # Keep track of the youngest configure dependency.
5341 $configure_deps_greatest_timestamp = mtime $configure_ac;
5342 if (-e 'aclocal.m4')
5344 my $mtime = mtime 'aclocal.m4';
5345 $configure_deps_greatest_timestamp = $mtime
5346 if $mtime > $configure_deps_greatest_timestamp;
5349 scan_autoconf_traces ($configure_ac);
5351 @configure_input_files = sort keys %make_list;
5352 # Set input and output files if not specified by user.
5355 @input_files = @configure_input_files;
5356 %output_files = %make_list;
5360 if (! $seen_init_automake)
5362 err_ac ("no proper invocation of AM_INIT_AUTOMAKE was found.\nYou "
5363 . "should verify that $configure_ac invokes AM_INIT_AUTOMAKE,"
5364 . "\nthat aclocal.m4 is present in the top-level directory,\n"
5365 . "and that aclocal.m4 was recently regenerated "
5366 . "(using aclocal)");
5370 if (! $seen_automake_version)
5372 if (-f 'aclocal.m4')
5374 error ($seen_init_automake,
5375 "your implementation of AM_INIT_AUTOMAKE comes from " .
5376 "an\nold Automake version. You should recreate " .
5377 "aclocal.m4\nwith aclocal and run automake again",
5378 # $? = 63 is used to indicate version mismatch to missing.
5383 error ($seen_init_automake,
5384 "no proper implementation of AM_INIT_AUTOMAKE was " .
5385 "found,\nprobably because aclocal.m4 is missing.\n" .
5386 "You should run aclocal to create this file, then\n" .
5387 "run automake again");
5394 # Look for some files we need. Always check for these. This
5395 # check must be done for every run, even those where we are only
5396 # looking at a subdir Makefile. We must set relative_dir for
5397 # push_required_file to work.
5398 # Sort the files for stable verbose output.
5399 $relative_dir = '.';
5400 foreach my $file (sort keys %required_aux_file)
5402 require_conf_file ($required_aux_file{$file}->get, FOREIGN, $file)
5404 err_am "'install.sh' is an anachronism; use 'install-sh' instead"
5405 if -f $config_aux_dir . '/install.sh';
5407 # Preserve dist_common for later.
5408 @configure_dist_common = @dist_common;
5411 ################################################################
5413 # Do any extra checking for GNU standards.
5414 sub check_gnu_standards ()
5416 if ($relative_dir eq '.')
5418 # In top level (or only) directory.
5419 require_file ("$am_file.am", GNU,
5420 qw/INSTALL NEWS README AUTHORS ChangeLog/);
5422 # Accept one of these three licenses; default to COPYING.
5423 # Make sure we do not overwrite an existing license.
5425 foreach (qw /COPYING COPYING.LIB COPYING.LESSER/)
5433 require_file ("$am_file.am", GNU, 'COPYING')
5437 for my $opt ('no-installman', 'no-installinfo')
5439 msg ('error-gnu', option $opt,
5440 "option '$opt' disallowed by GNU standards")
5445 # Do any extra checking for GNITS standards.
5446 sub check_gnits_standards ()
5448 if ($relative_dir eq '.')
5450 # In top level (or only) directory.
5451 require_file ("$am_file.am", GNITS, 'THANKS');
5455 ################################################################
5457 # Functions to handle files of each language.
5459 # Much of the actual processing is handled in
5460 # handle_single_transform. These functions exist so that
5461 # auxiliary information can be recorded for a later cleanup pass.
5462 # Note that the calls to these functions are computed, so don't bother
5463 # searching for their precise names in the source.
5465 # Header files are simply ignored.
5466 sub lang_header_ignore { 1; }
5468 # Vala '.vapi' are a kind of header files as well, and should
5469 # not be processed into compilation rules.
5470 sub lang_vala_ignore
5472 my ($directory, $base, $ext) = @_;
5473 return ($ext =~ m/\.vapi$/ ? 1 : 0);
5476 # Rewrite a single Vala source file.
5477 sub lang_vala_rewrite
5479 my ($directory, $base, $ext) = @_;
5484 # Rewrite a single yacc/yacc++ file.
5485 sub lang_yacc_rewrite
5487 my ($directory, $base, $ext) = @_;
5491 sub lang_yaccxx_rewrite { lang_yacc_rewrite (@_); };
5493 # Rewrite a single lex/lex++ file.
5494 sub lang_lex_rewrite
5496 my ($directory, $base, $ext) = @_;
5500 sub lang_lexxx_rewrite { lang_lex_rewrite (@_); };
5502 # The lang_X_finish functions are called after all source file
5503 # processing is done. Each should handle defining rules for the
5504 # language, etc. A finish function is only called if a source file of
5505 # the appropriate type has been seen.
5507 sub lang_vala_finish_target
5509 my ($self, $name) = @_;
5511 my $derived = canonicalize ($name);
5512 my $var = var "${derived}_SOURCES";
5515 my @vala_sources = grep { /\.(vala|vapi)$/ } ($var->value_as_list_recursive);
5517 # For automake bug#11229.
5518 return unless @vala_sources;
5520 foreach my $vala_file (@vala_sources)
5522 my $c_file = $vala_file;
5523 if ($c_file =~ s/(.*)\.vala$/$1.c/)
5525 $c_file = "\$(srcdir)/$c_file";
5526 $output_rules .= "$c_file: \$(srcdir)/${derived}_vala.stamp\n"
5527 . "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n"
5528 . "\t\@if test -f \$@; then :; else \\\n"
5529 . "\t \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n"
5531 $clean_files{$c_file} = MAINTAINER_CLEAN;
5535 # Add rebuild rules for generated header and vapi files
5536 my $flags = var ($derived . '_VALAFLAGS');
5540 foreach my $flag ($flags->value_as_list_recursive)
5542 if (grep (/$lastflag/, ('-H', '-h', '--header', '--internal-header',
5543 '--vapi', '--internal-vapi', '--gir')))
5545 my $headerfile = "\$(srcdir)/$flag";
5546 $output_rules .= "$headerfile: \$(srcdir)/${derived}_vala.stamp\n"
5547 . "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n"
5548 . "\t\@if test -f \$@; then :; else \\\n"
5549 . "\t \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n"
5552 # valac is not used when building from dist tarballs
5553 # distribute the generated files
5554 push_dist_common ($headerfile);
5555 $clean_files{$headerfile} = MAINTAINER_CLEAN;
5561 my $compile = $self->compile;
5563 # Rewrite each occurrence of 'AM_VALAFLAGS' in the compile
5564 # rule into '${derived}_VALAFLAGS' if it exists.
5565 my $val = "${derived}_VALAFLAGS";
5566 $compile =~ s/\(AM_VALAFLAGS\)/\($val\)/
5569 # VALAFLAGS is a user variable (per GNU Standards),
5570 # it should not be overridden in the Makefile...
5571 check_user_variables 'VALAFLAGS';
5573 my $dirname = dirname ($name);
5575 # Only generate C code, do not run C compiler
5578 my $verbose = verbose_flag ('VALAC');
5579 my $silent = silent_flag ();
5580 my $stampfile = "\$(srcdir)/${derived}_vala.stamp";
5583 "\$(srcdir)/${derived}_vala.stamp: @vala_sources\n".
5584 # Since the C files generated from the vala sources depend on the
5585 # ${derived}_vala.stamp file, we must ensure its timestamp is older than
5586 # those of the C files generated by the valac invocation below (this is
5587 # especially important on systems with sub-second timestamp resolution).
5588 # Thus we need to create the stamp file *before* invoking valac, and to
5589 # move it to its final location only after valac has been invoked.
5590 "\t${silent}rm -f \$\@ && echo stamp > \$\@-t\n".
5591 "\t${verbose}\$(am__cd) \$(srcdir) && $compile @vala_sources\n".
5592 "\t${silent}mv -f \$\@-t \$\@\n";
5594 push_dist_common ($stampfile);
5596 $clean_files{$stampfile} = MAINTAINER_CLEAN;
5599 # Add output rules to invoke valac and create stamp file as a witness
5600 # to handle multiple outputs. This function is called after all source
5601 # file processing is done.
5602 sub lang_vala_finish ()
5606 foreach my $prog (keys %known_programs)
5608 lang_vala_finish_target ($self, $prog);
5611 while (my ($name) = each %known_libraries)
5613 lang_vala_finish_target ($self, $name);
5617 # The built .c files should be cleaned only on maintainer-clean
5618 # as the .c files are distributed. This function is called for each
5619 # .vala source file.
5620 sub lang_vala_target_hook
5622 my ($self, $aggregate, $output, $input, %transform) = @_;
5624 $clean_files{$output} = MAINTAINER_CLEAN;
5627 # This is a yacc helper which is called whenever we have decided to
5628 # compile a yacc file.
5629 sub lang_yacc_target_hook
5631 my ($self, $aggregate, $output, $input, %transform) = @_;
5633 # If some relevant *YFLAGS variable contains the '-d' flag, we'll
5634 # have to to generate special code.
5635 my $yflags_contains_minus_d = 0;
5637 foreach my $pfx ("", "${aggregate}_")
5639 my $yflagsvar = var ("${pfx}YFLAGS");
5640 next unless $yflagsvar;
5641 # We cannot work reliably with conditionally-defined YFLAGS.
5642 if ($yflagsvar->has_conditional_contents)
5644 msg_var ('unsupported', $yflagsvar,
5645 "'${pfx}YFLAGS' cannot have conditional contents");
5649 $yflags_contains_minus_d = 1
5650 if grep (/^-d$/, $yflagsvar->value_as_list_recursive);
5654 if ($yflags_contains_minus_d)
5656 # Found a '-d' that applies to the compilation of this file.
5657 # Add a dependency for the generated header file, and arrange
5658 # for that file to be included in the distribution.
5660 # The extension of the output file (e.g., '.c' or '.cxx').
5661 # We'll need it to compute the name of the generated header file.
5662 (my $output_ext = basename ($output)) =~ s/.*(\.[^.]+)$/$1/;
5664 # We know that a yacc input should be turned into either a C or
5665 # C++ output file. We depend on this fact (here and in yacc.am),
5666 # so check that it really holds.
5667 my $lang = $languages{$extension_map{$output_ext}};
5668 prog_error "invalid output name '$output' for yacc file '$input'"
5669 if (!$lang || ($lang->name ne 'c' && $lang->name ne 'cxx'));
5671 (my $header_ext = $output_ext) =~ s/c/h/g;
5672 # Quote $output_ext in the regexp, so that dots in it are taken
5673 # as literal dots, not as metacharacters.
5674 (my $header = $output) =~ s/\Q$output_ext\E$/$header_ext/;
5676 foreach my $cond (Automake::Rule::define (${header}, 'internal',
5677 RULE_AUTOMAKE, TRUE,
5680 my $condstr = $cond->subst_string;
5682 "$condstr${header}: $output\n"
5683 # Recover from removal of $header
5684 . "$condstr\t\@if test ! -f \$@; then rm -f $output; else :; fi\n"
5685 . "$condstr\t\@if test ! -f \$@; then \$(MAKE) \$(AM_MAKEFLAGS) $output; else :; fi\n";
5687 # Distribute the generated file, unless its .y source was
5688 # listed in a nodist_ variable. (handle_source_transform()
5689 # will set DIST_SOURCE.)
5690 push_dist_common ($header)
5691 if $transform{'DIST_SOURCE'};
5693 # The GNU rules say that yacc/lex output files should be removed
5694 # by maintainer-clean. However, if the files are not distributed,
5695 # then we want to remove them with "make clean"; otherwise,
5696 # "make distcheck" will fail.
5697 $clean_files{$header} = $transform{'DIST_SOURCE'} ? MAINTAINER_CLEAN : CLEAN;
5699 # See the comment above for $HEADER.
5700 $clean_files{$output} = $transform{'DIST_SOURCE'} ? MAINTAINER_CLEAN : CLEAN;
5703 # This is a lex helper which is called whenever we have decided to
5704 # compile a lex file.
5705 sub lang_lex_target_hook
5707 my ($self, $aggregate, $output, $input, %transform) = @_;
5708 # The GNU rules say that yacc/lex output files should be removed
5709 # by maintainer-clean. However, if the files are not distributed,
5710 # then we want to remove them with "make clean"; otherwise,
5711 # "make distcheck" will fail.
5712 $clean_files{$output} = $transform{'DIST_SOURCE'} ? MAINTAINER_CLEAN : CLEAN;
5715 # This is a helper for both lex and yacc.
5716 sub yacc_lex_finish_helper ()
5718 return if defined $language_scratch{'lex-yacc-done'};
5719 $language_scratch{'lex-yacc-done'} = 1;
5721 # FIXME: for now, no line number.
5722 require_conf_file ($configure_ac, FOREIGN, 'ylwrap');
5723 define_variable ('YLWRAP', "$am_config_aux_dir/ylwrap", INTERNAL);
5726 sub lang_yacc_finish ()
5728 return if defined $language_scratch{'yacc-done'};
5729 $language_scratch{'yacc-done'} = 1;
5731 reject_var 'YACCFLAGS', "'YACCFLAGS' obsolete; use 'YFLAGS' instead";
5733 yacc_lex_finish_helper;
5737 sub lang_lex_finish ()
5739 return if defined $language_scratch{'lex-done'};
5740 $language_scratch{'lex-done'} = 1;
5742 yacc_lex_finish_helper;
5746 # Given a hash table of linker names, pick the name that has the most
5747 # precedence. This is lame, but something has to have global
5748 # knowledge in order to eliminate the conflict. Add more linkers as
5754 foreach my $l (qw(GCJLINK OBJCXXLINK CXXLINK F77LINK FCLINK OBJCLINK UPCLINK))
5756 return $l if defined $linkers{$l};
5761 # Called to indicate that an extension was used.
5765 $extension_seen{$ext} = 1;
5768 # register_language (%ATTRIBUTE)
5769 # ------------------------------
5770 # Register a single language.
5771 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5772 sub register_language
5777 $option{'autodep'} = 'no'
5778 unless defined $option{'autodep'};
5779 $option{'linker'} = ''
5780 unless defined $option{'linker'};
5781 $option{'flags'} = []
5782 unless defined $option{'flags'};
5783 $option{'output_extensions'} = sub { return ( '.$(OBJEXT)', '.lo' ) }
5784 unless defined $option{'output_extensions'};
5785 $option{'nodist_specific'} = 0
5786 unless defined $option{'nodist_specific'};
5788 my $lang = new Automake::Language (%option);
5791 $extension_map{$_} = $lang->name foreach @{$lang->extensions};
5792 $languages{$lang->name} = $lang;
5793 my $link = $lang->linker;
5796 if (exists $link_languages{$link})
5798 prog_error ("'$link' has different definitions in "
5799 . $lang->name . " and " . $link_languages{$link}->name)
5800 if $lang->link ne $link_languages{$link}->link;
5804 $link_languages{$link} = $lang;
5808 # Update the pattern of known extensions.
5809 accept_extensions (@{$lang->extensions});
5811 # Update the suffix rules map.
5812 foreach my $suffix (@{$lang->extensions})
5814 foreach my $dest ($lang->output_extensions->($suffix))
5816 register_suffix_rule (INTERNAL, $suffix, $dest);
5821 # derive_suffix ($EXT, $OBJ)
5822 # --------------------------
5823 # This function is used to find a path from a user-specified suffix $EXT
5824 # to $OBJ or to some other suffix we recognize internally, e.g. 'cc'.
5827 my ($source_ext, $obj) = @_;
5829 while (!$extension_map{$source_ext} && $source_ext ne $obj)
5831 my $new_source_ext = next_in_suffix_chain ($source_ext, $obj);
5832 last if not defined $new_source_ext;
5833 $source_ext = $new_source_ext;
5840 # Pretty-print something and append to '$output_rules'.
5841 sub pretty_print_rule
5843 $output_rules .= makefile_wrap (shift, shift, @_);
5847 ################################################################
5850 ## -------------------------------- ##
5851 ## Handling the conditional stack. ##
5852 ## -------------------------------- ##
5856 # make_conditional_string ($NEGATE, $COND)
5857 # ----------------------------------------
5858 sub make_conditional_string
5860 my ($negate, $cond) = @_;
5861 $cond = "${cond}_TRUE"
5862 unless $cond =~ /^TRUE|FALSE$/;
5863 $cond = Automake::Condition::conditional_negate ($cond)
5869 my %_am_macro_for_cond =
5871 AMDEP => "one of the compiler tests\n"
5872 . " AC_PROG_CC, AC_PROG_CXX, AC_PROG_OBJC, AC_PROG_OBJCXX,\n"
5873 . " AM_PROG_AS, AM_PROG_GCJ, AM_PROG_UPC",
5874 am__fastdepCC => 'AC_PROG_CC',
5875 am__fastdepCCAS => 'AM_PROG_AS',
5876 am__fastdepCXX => 'AC_PROG_CXX',
5877 am__fastdepGCJ => 'AM_PROG_GCJ',
5878 am__fastdepOBJC => 'AC_PROG_OBJC',
5879 am__fastdepOBJCXX => 'AC_PROG_OBJCXX',
5880 am__fastdepUPC => 'AM_PROG_UPC'
5884 # cond_stack_if ($NEGATE, $COND, $WHERE)
5885 # --------------------------------------
5888 my ($negate, $cond, $where) = @_;
5890 if (! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/)
5892 my $text = "$cond does not appear in AM_CONDITIONAL";
5893 my $scope = US_LOCAL;
5894 if (exists $_am_macro_for_cond{$cond})
5896 my $mac = $_am_macro_for_cond{$cond};
5897 $text .= "\n The usual way to define '$cond' is to add ";
5898 $text .= ($mac =~ / /) ? $mac : "'$mac'";
5899 $text .= "\n to '$configure_ac' and run 'aclocal' and 'autoconf' again";
5900 # These warnings appear in Automake files (depend2.am),
5901 # so there is no need to display them more than once:
5904 error $where, $text, uniq_scope => $scope;
5907 push (@cond_stack, make_conditional_string ($negate, $cond));
5909 return new Automake::Condition (@cond_stack);
5914 # cond_stack_else ($NEGATE, $COND, $WHERE)
5915 # ----------------------------------------
5918 my ($negate, $cond, $where) = @_;
5922 error $where, "else without if";
5926 $cond_stack[$#cond_stack] =
5927 Automake::Condition::conditional_negate ($cond_stack[$#cond_stack]);
5929 # If $COND is given, check against it.
5932 $cond = make_conditional_string ($negate, $cond);
5934 error ($where, "else reminder ($negate$cond) incompatible with "
5935 . "current conditional: $cond_stack[$#cond_stack]")
5936 if $cond_stack[$#cond_stack] ne $cond;
5939 return new Automake::Condition (@cond_stack);
5944 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5945 # -----------------------------------------
5946 sub cond_stack_endif
5948 my ($negate, $cond, $where) = @_;
5953 error $where, "endif without if";
5957 # If $COND is given, check against it.
5960 $cond = make_conditional_string ($negate, $cond);
5962 error ($where, "endif reminder ($negate$cond) incompatible with "
5963 . "current conditional: $cond_stack[$#cond_stack]")
5964 if $cond_stack[$#cond_stack] ne $cond;
5969 return new Automake::Condition (@cond_stack);
5976 ## ------------------------ ##
5977 ## Handling the variables. ##
5978 ## ------------------------ ##
5981 # define_pretty_variable ($VAR, $COND, $WHERE, @VALUE)
5982 # ----------------------------------------------------
5983 # Like define_variable, but the value is a list, and the variable may
5984 # be defined conditionally. The second argument is the condition
5985 # under which the value should be defined; this should be the empty
5986 # string to define the variable unconditionally. The third argument
5987 # is a list holding the values to use for the variable. The value is
5988 # pretty printed in the output file.
5989 sub define_pretty_variable
5991 my ($var, $cond, $where, @value) = @_;
5993 if (! vardef ($var, $cond))
5995 Automake::Variable::define ($var, VAR_AUTOMAKE, '', $cond, "@value",
5996 '', $where, VAR_PRETTY);
5997 rvar ($var)->rdef ($cond)->set_seen;
6002 # define_variable ($VAR, $VALUE, $WHERE)
6003 # --------------------------------------
6004 # Define a new Automake Makefile variable VAR to VALUE, but only if
6005 # not already defined.
6008 my ($var, $value, $where) = @_;
6009 define_pretty_variable ($var, TRUE, $where, $value);
6013 # define_files_variable ($VAR, \@BASENAME, $EXTENSION, $WHERE)
6014 # ------------------------------------------------------------
6015 # Define the $VAR which content is the list of file names composed of
6016 # a @BASENAME and the $EXTENSION.
6017 sub define_files_variable ($\@$$)
6019 my ($var, $basename, $extension, $where) = @_;
6020 define_variable ($var,
6021 join (' ', map { "$_.$extension" } @$basename),
6026 # Like define_variable, but define a variable to be the configure
6027 # substitution by the same name.
6028 sub define_configure_variable
6031 # Some variables we do not want to output. For instance it
6032 # would be a bad idea to output `U = @U@` when `@U@` can be
6033 # substituted as `\`.
6034 my $pretty = exists $ignored_configure_vars{$var} ? VAR_SILENT : VAR_ASIS;
6035 Automake::Variable::define ($var, VAR_CONFIGURE, '', TRUE, subst ($var),
6036 '', $configure_vars{$var}, $pretty);
6040 # define_compiler_variable ($LANG)
6041 # --------------------------------
6042 # Define a compiler variable. We also handle defining the 'LT'
6043 # version of the command when using libtool.
6044 sub define_compiler_variable
6048 my ($var, $value) = ($lang->compiler, $lang->compile);
6049 my $libtool_tag = '';
6050 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
6051 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
6052 define_variable ($var, $value, INTERNAL);
6053 if (var ('LIBTOOL'))
6055 my $verbose = define_verbose_libtool ();
6056 define_variable ("LT$var",
6057 "\$(LIBTOOL) $verbose $libtool_tag\$(AM_LIBTOOLFLAGS)"
6058 . " \$(LIBTOOLFLAGS) --mode=compile $value",
6061 define_verbose_tagvar ($lang->ccer || 'GEN');
6065 sub define_linker_variable
6069 my $libtool_tag = '';
6070 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
6071 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
6073 define_variable ($lang->lder, $lang->ld, INTERNAL);
6074 # CCLINK = $(CCLD) blah blah...
6076 if (var ('LIBTOOL'))
6078 my $verbose = define_verbose_libtool ();
6079 $link = "\$(LIBTOOL) $verbose $libtool_tag\$(AM_LIBTOOLFLAGS) "
6080 . "\$(LIBTOOLFLAGS) --mode=link ";
6082 define_variable ($lang->linker, $link . $lang->link, INTERNAL);
6083 define_variable ($lang->compiler, $lang, INTERNAL);
6084 define_verbose_tagvar ($lang->lder || 'GEN');
6087 sub define_per_target_linker_variable
6089 my ($linker, $target) = @_;
6091 # If the user wrote a custom link command, we don't define ours.
6092 return "${target}_LINK"
6093 if set_seen "${target}_LINK";
6095 my $xlink = $linker ? $linker : 'LINK';
6097 my $lang = $link_languages{$xlink};
6098 prog_error "Unknown language for linker variable '$xlink'"
6101 my $link_command = $lang->link;
6104 my $libtool_tag = '';
6105 $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
6106 if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
6108 my $verbose = define_verbose_libtool ();
6110 "\$(LIBTOOL) $verbose $libtool_tag\$(AM_LIBTOOLFLAGS) \$(LIBTOOLFLAGS) "
6111 . "--mode=link " . $link_command;
6114 # Rewrite each occurrence of 'AM_$flag' in the link
6115 # command into '${derived}_$flag' if it exists.
6116 my $orig_command = $link_command;
6117 my @flags = (@{$lang->flags}, 'LDFLAGS');
6118 push @flags, 'LIBTOOLFLAGS' if var 'LIBTOOL';
6119 for my $flag (@flags)
6121 my $val = "${target}_$flag";
6122 $link_command =~ s/\(AM_$flag\)/\($val\)/
6126 # If the computed command is the same as the generic command, use
6127 # the command linker variable.
6128 return ($lang->linker, $lang->lder)
6129 if $link_command eq $orig_command;
6131 define_variable ("${target}_LINK", $link_command, INTERNAL);
6132 return ("${target}_LINK", $lang->lder);
6135 ################################################################
6137 # check_trailing_slash ($WHERE, $LINE)
6138 # ------------------------------------
6139 # Return 1 iff $LINE ends with a slash.
6140 # Might modify $LINE.
6141 sub check_trailing_slash ($\$)
6143 my ($where, $line) = @_;
6145 # Ignore '##' lines.
6146 return 0 if $$line =~ /$IGNORE_PATTERN/o;
6148 # Catch and fix a common error.
6149 msg "syntax", $where, "whitespace following trailing backslash"
6150 if $$line =~ s/\\\s+\n$/\\\n/;
6152 return $$line =~ /\\$/;
6156 # read_am_file ($AMFILE, $WHERE, $RELDIR)
6157 # ---------------------------------------
6158 # Read $AMFILE file name which is located in $RELDIR, and set up
6159 # global variables resetted by '&generate_makefile'. Simultaneously
6160 # copy lines from $AMFILE into '$output_trailer', or define variables
6163 # NOTE: We put rules in the trailer section. We want user rules to
6164 # come after our generated stuff.
6167 my ($amfile, $where, $reldir) = @_;
6168 my $canon_reldir = &canonicalize ($reldir);
6170 my $am_file = new Automake::XFile ("< $amfile");
6171 verb "reading $amfile";
6173 # Keep track of the youngest output dependency.
6174 my $mtime = mtime $amfile;
6175 $output_deps_greatest_timestamp = $mtime
6176 if $mtime > $output_deps_greatest_timestamp;
6182 my $var_look = VAR_ASIS;
6184 use constant IN_VAR_DEF => 0;
6185 use constant IN_RULE_DEF => 1;
6186 use constant IN_COMMENT => 2;
6187 my $prev_state = IN_RULE_DEF;
6189 while ($_ = $am_file->getline)
6191 $where->set ("$amfile:$.");
6192 if (/$IGNORE_PATTERN/o)
6194 # Merely delete comments beginning with two hashes.
6196 elsif (/$WHITE_PATTERN/o)
6198 error $where, "blank line following trailing backslash"
6200 # Stick a single white line before the incoming macro or rule.
6203 # Flush all comments seen so far.
6206 $output_vars .= $comment;
6210 elsif (/$COMMENT_PATTERN/o)
6212 # Stick comments before the incoming macro or rule. Make
6213 # sure a blank line precedes the first block of comments.
6214 $spacing = "\n" unless $blank;
6216 $comment .= $spacing . $_;
6218 $prev_state = IN_COMMENT;
6224 $saw_bk = check_trailing_slash ($where, $_);
6227 # We save the conditional stack on entry, and then check to make
6228 # sure it is the same on exit. This lets us conditionally include
6230 my @saved_cond_stack = @cond_stack;
6231 my $cond = new Automake::Condition (@cond_stack);
6233 my $last_var_name = '';
6234 my $last_var_type = '';
6235 my $last_var_value = '';
6237 # FIXME: shouldn't use $_ in this loop; it is too big.
6240 $where->set ("$amfile:$.");
6242 # Make sure the line is \n-terminated.
6246 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
6247 # used by users. @MAINT@ is an anachronism now.
6248 $_ =~ s/\@MAINT\@//g
6249 unless $seen_maint_mode;
6251 my $new_saw_bk = check_trailing_slash ($where, $_);
6255 # If present, eat the following '_' or '/', converting
6256 # "%reldir%/foo" and "%canon_reldir%_foo" into plain "foo"
6257 # when $reldir is '.'.
6258 $_ =~ s,%(D|reldir)%/,,g;
6259 $_ =~ s,%(C|canon_reldir)%_,,g;
6261 $_ =~ s/%(D|reldir)%/${reldir}/g;
6262 $_ =~ s/%(C|canon_reldir)%/${canon_reldir}/g;
6264 if (/$IGNORE_PATTERN/o)
6266 # Merely delete comments beginning with two hashes.
6268 # Keep any backslash from the previous line.
6269 $new_saw_bk = $saw_bk;
6271 elsif (/$WHITE_PATTERN/o)
6273 # Stick a single white line before the incoming macro or rule.
6275 error $where, "blank line following trailing backslash"
6278 elsif (/$COMMENT_PATTERN/o)
6280 error $where, "comment following trailing backslash"
6281 if $saw_bk && $prev_state != IN_COMMENT;
6283 # Stick comments before the incoming macro or rule.
6284 $comment .= $spacing . $_;
6286 $prev_state = IN_COMMENT;
6290 if ($prev_state == IN_RULE_DEF)
6292 my $cond = new Automake::Condition @cond_stack;
6293 $output_trailer .= $cond->subst_string;
6294 $output_trailer .= $_;
6296 elsif ($prev_state == IN_COMMENT)
6298 # If the line doesn't start with a '#', add it.
6299 # We do this because a continued comment like
6303 # is not portable. BSD make doesn't honor
6304 # escaped newlines in comments.
6306 $comment .= $spacing . $_;
6308 else # $prev_state == IN_VAR_DEF
6310 $last_var_value .= ' '
6311 unless $last_var_value =~ /\s$/;
6312 $last_var_value .= $_;
6316 Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
6317 $last_var_type, $cond,
6318 $last_var_value, $comment,
6319 $last_where, VAR_ASIS)
6321 $comment = $spacing = '';
6326 elsif (/$IF_PATTERN/o)
6328 $cond = cond_stack_if ($1, $2, $where);
6330 elsif (/$ELSE_PATTERN/o)
6332 $cond = cond_stack_else ($1, $2, $where);
6334 elsif (/$ENDIF_PATTERN/o)
6336 $cond = cond_stack_endif ($1, $2, $where);
6339 elsif (/$RULE_PATTERN/o)
6342 $prev_state = IN_RULE_DEF;
6344 # For now we have to output all definitions of user rules
6345 # and can't diagnose duplicates (see the comment in
6346 # Automake::Rule::define). So we go on and ignore the return value.
6347 Automake::Rule::define ($1, $amfile, RULE_USER, $cond, $where);
6349 check_variable_expansions ($_, $where);
6351 $output_trailer .= $comment . $spacing;
6352 my $cond = new Automake::Condition @cond_stack;
6353 $output_trailer .= $cond->subst_string;
6354 $output_trailer .= $_;
6355 $comment = $spacing = '';
6357 elsif (/$ASSIGNMENT_PATTERN/o)
6359 # Found a macro definition.
6360 $prev_state = IN_VAR_DEF;
6361 $last_var_name = $1;
6362 $last_var_type = $2;
6363 $last_var_value = $3;
6364 $last_where = $where->clone;
6365 if ($3 ne '' && substr ($3, -1) eq "\\")
6367 # We preserve the '\' because otherwise the long lines
6368 # that are generated will be truncated by broken
6370 $last_var_value = $3 . "\n";
6372 # Normally we try to output variable definitions in the
6373 # same format they were input. However, POSIX compliant
6374 # systems are not required to support lines longer than
6375 # 2048 bytes (most notably, some sed implementation are
6376 # limited to 4000 bytes, and sed is used by config.status
6377 # to rewrite Makefile.in into Makefile). Moreover nobody
6378 # would really write such long lines by hand since it is
6379 # hardly maintainable. So if a line is longer that 1000
6380 # bytes (an arbitrary limit), assume it has been
6381 # automatically generated by some tools, and flatten the
6382 # variable definition. Otherwise, keep the variable as it
6384 $var_look = VAR_PRETTY if length ($last_var_value) >= 1000;
6388 Automake::Variable::define ($last_var_name, VAR_MAKEFILE,
6389 $last_var_type, $cond,
6390 $last_var_value, $comment,
6391 $last_where, $var_look)
6393 $comment = $spacing = '';
6394 $var_look = VAR_ASIS;
6397 elsif (/$INCLUDE_PATTERN/o)
6401 if ($path =~ s/^\$\(top_srcdir\)\///)
6403 push (@include_stack, "\$\(top_srcdir\)/$path");
6404 # Distribute any included file.
6406 # Always use the $(top_srcdir) prefix in DIST_COMMON,
6407 # otherwise OSF make will implicitly copy the included
6408 # file in the build tree during "make distdir" to satisfy
6410 # (subdir-am-cond.sh and subdir-ac-cond.sh will fail)
6411 push_dist_common ("\$\(top_srcdir\)/$path");
6415 $path =~ s/\$\(srcdir\)\///;
6416 push (@include_stack, "\$\(srcdir\)/$path");
6417 # Always use the $(srcdir) prefix in DIST_COMMON,
6418 # otherwise OSF make will implicitly copy the included
6419 # file in the build tree during "make distdir" to satisfy
6421 # (subdir-am-cond.sh and subdir-ac-cond.sh will fail)
6422 push_dist_common ("\$\(srcdir\)/$path");
6423 $path = $relative_dir . "/" . $path if $relative_dir ne '.';
6425 my $new_reldir = File::Spec->abs2rel ($path, $relative_dir);
6426 $new_reldir = '.' if $new_reldir !~ s,/[^/]*$,,;
6427 $where->push_context ("'$path' included from here");
6428 read_am_file ($path, $where, $new_reldir);
6429 $where->pop_context;
6433 # This isn't an error; it is probably a continued rule.
6434 # In fact, this is what we assume.
6435 $prev_state = IN_RULE_DEF;
6436 check_variable_expansions ($_, $where);
6437 $output_trailer .= $comment . $spacing;
6438 my $cond = new Automake::Condition @cond_stack;
6439 $output_trailer .= $cond->subst_string;
6440 $output_trailer .= $_;
6441 $comment = $spacing = '';
6442 error $where, "'#' comment at start of rule is unportable"
6443 if $_ =~ /^\t\s*\#/;
6446 $saw_bk = $new_saw_bk;
6447 $_ = $am_file->getline;
6450 $output_trailer .= $comment;
6452 error ($where, "trailing backslash on last line")
6455 error ($where, (@cond_stack ? "unterminated conditionals: @cond_stack"
6456 : "too many conditionals closed in include file"))
6457 if "@saved_cond_stack" ne "@cond_stack";
6461 # A helper for read_main_am_file which initializes configure variables
6462 # and variables from header-vars.am.
6463 sub define_standard_variables ()
6465 my $saved_output_vars = $output_vars;
6466 my ($comments, undef, $rules) =
6467 file_contents_internal (1, "$libdir/am/header-vars.am",
6468 new Automake::Location);
6470 foreach my $var (sort keys %configure_vars)
6472 define_configure_variable ($var);
6475 $output_vars .= $comments . $rules;
6479 # read_main_am_file ($MAKEFILE_AM, $MAKEFILE_IN)
6480 # ----------------------------------------------
6481 sub read_main_am_file
6483 my ($amfile, $infile) = @_;
6485 # This supports the strange variable tricks we are about to play.
6486 prog_error ("variable defined before read_main_am_file\n" . variables_dump ())
6487 if (scalar (variables) > 0);
6489 # Generate copyright header for generated Makefile.in.
6490 # We do discard the output of predefined variables, handled below.
6491 $output_vars = ("# " . basename ($infile) . " generated by automake "
6492 . $VERSION . " from " . basename ($amfile) . ".\n");
6493 $output_vars .= '# ' . subst ('configure_input') . "\n";
6494 $output_vars .= $gen_copyright;
6496 # We want to predefine as many variables as possible. This lets
6497 # the user set them with '+=' in Makefile.am.
6498 define_standard_variables;
6500 # Read user file, which might override some of our values.
6501 read_am_file ($amfile, new Automake::Location, '.');
6506 ################################################################
6509 # flatten ($ORIGINAL_STRING)
6510 # --------------------------
6524 # transform_token ($TOKEN, \%PAIRS, $KEY)
6525 # ---------------------------------------
6526 # Return the value associated to $KEY in %PAIRS, as used on $TOKEN
6527 # (which should be ?KEY? or any of the special %% requests)..
6528 sub transform_token ($\%$)
6530 my ($token, $transform, $key) = @_;
6531 my $res = $transform->{$key};
6532 prog_error "Unknown key '$key' in '$token'" unless defined $res;
6537 # transform ($TOKEN, \%PAIRS)
6538 # ---------------------------
6539 # If ($TOKEN, $VAL) is in %PAIRS:
6540 # - replaces %KEY% with $VAL,
6541 # - enables/disables ?KEY? and ?!KEY?,
6542 # - replaces %?KEY% with TRUE or FALSE.
6545 my ($token, $transform) = @_;
6548 # Must be before the following pattern to exclude the case
6549 # when there is neither IFTRUE nor IFFALSE.
6550 if ($token =~ /^%([\w\-]+)%$/)
6552 return transform_token ($token, %$transform, $1);
6555 elsif ($token =~ /^%\?([\w\-]+)%$/)
6557 return transform_token ($token, %$transform, $1) ? 'TRUE' : 'FALSE';
6560 elsif ($token =~ /^ \? (!?) ([\w\-]+) \? $/x)
6562 my $neg = ($1 eq '!') ? 1 : 0;
6563 my $val = transform_token ($token, %$transform, $2);
6564 return (!!$val == $neg) ? '##%' : '';
6568 prog_error "Unknown request format: $token";
6573 # preprocess_file ($MAKEFILE, [%TRANSFORM])
6574 # -----------------------------------------
6575 # Load a $MAKEFILE, apply the %TRANSFORM, and return the result.
6576 # No extra parsing or post-processing is done (i.e., recognition of
6577 # rules declaration or of make variables definitions).
6580 my ($file, %transform) = @_;
6582 # Complete %transform with global options.
6583 # Note that %transform goes last, so it overrides global options.
6584 %transform = ( 'MAINTAINER-MODE'
6585 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
6587 'XZ' => !! option 'dist-xz',
6588 'LZIP' => !! option 'dist-lzip',
6589 'BZIP2' => !! option 'dist-bzip2',
6590 'GZIP' => ! option 'no-dist-gzip',
6591 'ZIP' => !! option 'dist-zip',
6593 'INSTALL-INFO' => ! option 'no-installinfo',
6594 'INSTALL-MAN' => ! option 'no-installman',
6595 'CK-NEWS' => !! option 'check-news',
6597 'SUBDIRS' => !! var ('SUBDIRS'),
6598 'TOPDIR_P' => $relative_dir eq '.',
6600 'BUILD' => ($seen_canonical >= AC_CANONICAL_BUILD),
6601 'HOST' => ($seen_canonical >= AC_CANONICAL_HOST),
6602 'TARGET' => ($seen_canonical >= AC_CANONICAL_TARGET),
6604 'LIBTOOL' => !! var ('LIBTOOL'),
6608 if (! defined ($_ = $am_file_cache{$file}))
6610 verb "reading $file";
6611 # Swallow the whole file.
6612 my $fc_file = new Automake::XFile "< $file";
6613 my $saved_dollar_slash = $/;
6615 $_ = $fc_file->getline;
6616 $/ = $saved_dollar_slash;
6618 # Remove ##-comments.
6619 # Besides we don't need more than two consecutive new-lines.
6620 s/(?:$IGNORE_PATTERN|(?<=\n\n)\n+)//gom;
6621 # Remember the contents of the just-read file.
6622 $am_file_cache{$file} = $_;
6625 # Substitute Automake template tokens.
6626 s/(?: % \?? [\w\-]+ %
6628 )/transform($&, %transform)/gex;
6629 # transform() may have added some ##%-comments to strip.
6630 # (we use '##%' instead of '##' so we can distinguish ##%##%##% from
6631 # ####### and do not remove the latter.)
6632 s/^[ \t]*(?:##%)+.*\n//gm;
6639 # make_paragraphs ($MAKEFILE, [%TRANSFORM])
6640 # -----------------------------------------
6641 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6645 my ($file, %transform) = @_;
6646 $transform{FIRST} = !$transformed_files{$file};
6647 $transformed_files{$file} = 1;
6649 my @lines = split /(?<!\\)\n/, preprocess_file ($file, %transform);
6652 while (defined ($_ = shift @lines))
6655 # If we are a rule, eat as long as we start with a tab.
6656 if (/$RULE_PATTERN/smo)
6658 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
6660 $paragraph .= "\n$_";
6662 unshift (@lines, $_);
6665 # If we are a comments, eat as much comments as you can.
6666 elsif (/$COMMENT_PATTERN/smo)
6668 while (defined ($_ = shift @lines)
6669 && $_ =~ /$COMMENT_PATTERN/smo)
6671 $paragraph .= "\n$_";
6673 unshift (@lines, $_);
6676 push @res, $paragraph;
6684 # ($COMMENT, $VARIABLES, $RULES)
6685 # file_contents_internal ($IS_AM, $FILE, $WHERE, [%TRANSFORM])
6686 # ------------------------------------------------------------
6687 # Return contents of a file from $libdir/am, automatically skipping
6688 # macros or rules which are already known. $IS_AM iff the caller is
6689 # reading an Automake file (as opposed to the user's Makefile.am).
6690 sub file_contents_internal
6692 my ($is_am, $file, $where, %transform) = @_;
6694 $where->set ($file);
6696 my $result_vars = '';
6697 my $result_rules = '';
6701 # The following flags are used to track rules spanning across
6702 # multiple paragraphs.
6703 my $is_rule = 0; # 1 if we are processing a rule.
6704 my $discard_rule = 0; # 1 if the current rule should not be output.
6706 # We save the conditional stack on entry, and then check to make
6707 # sure it is the same on exit. This lets us conditionally include
6709 my @saved_cond_stack = @cond_stack;
6710 my $cond = new Automake::Condition (@cond_stack);
6712 foreach (make_paragraphs ($file, %transform))
6714 # FIXME: no line number available.
6715 $where->set ($file);
6718 error $where, "blank line following trailing backslash:\n$_"
6720 error $where, "comment following trailing backslash:\n$_"
6726 # Stick empty line before the incoming macro or rule.
6729 elsif (/$COMMENT_PATTERN/mso)
6732 # Stick comments before the incoming macro or rule.
6736 # Handle inclusion of other files.
6737 elsif (/$INCLUDE_PATTERN/o)
6741 my $file = ($is_am ? "$libdir/am/" : '') . $1;
6742 $where->push_context ("'$file' included from here");
6744 my ($com, $vars, $rules)
6745 = file_contents_internal ($is_am, $file, $where, %transform);
6746 $where->pop_context;
6748 $result_vars .= $vars;
6749 $result_rules .= $rules;
6753 # Handling the conditionals.
6754 elsif (/$IF_PATTERN/o)
6756 $cond = cond_stack_if ($1, $2, $file);
6758 elsif (/$ELSE_PATTERN/o)
6760 $cond = cond_stack_else ($1, $2, $file);
6762 elsif (/$ENDIF_PATTERN/o)
6764 $cond = cond_stack_endif ($1, $2, $file);
6768 elsif (/$RULE_PATTERN/mso)
6772 # Separate relationship from optional actions: the first
6773 # `new-line tab" not preceded by backslash (continuation
6776 /^(.*?)(?:(?<!\\)\n(\t.*))?$/s;
6777 my ($relationship, $actions) = ($1, $2 || '');
6779 # Separate targets from dependencies: the first colon.
6780 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
6781 my ($targets, $dependencies) = ($1, $2);
6782 # Remove the escaped new lines.
6783 # I don't know why, but I have to use a tmp $flat_deps.
6784 my $flat_deps = flatten ($dependencies);
6785 my @deps = split (' ', $flat_deps);
6787 foreach (split (' ', $targets))
6789 # FIXME: 1. We are not robust to people defining several targets
6790 # at once, only some of them being in %dependencies. The
6791 # actions from the targets in %dependencies are usually generated
6792 # from the content of %actions, but if some targets in $targets
6793 # are not in %dependencies the ELSE branch will output
6794 # a rule for all $targets (i.e. the targets which are both
6795 # in %dependencies and $targets will have two rules).
6797 # FIXME: 2. The logic here is not able to output a
6798 # multi-paragraph rule several time (e.g. for each condition
6799 # it is defined for) because it only knows the first paragraph.
6801 # FIXME: 3. We are not robust to people defining a subset
6802 # of a previously defined "multiple-target" rule. E.g.
6803 # 'foo:' after 'foo bar:'.
6805 # Output only if not in FALSE.
6806 if (defined $dependencies{$_} && $cond != FALSE)
6809 register_action ($_, $actions);
6813 # Free-lance dependency. Output the rule for all the
6814 # targets instead of one by one.
6815 my @undefined_conds =
6816 Automake::Rule::define ($targets, $file,
6817 $is_am ? RULE_AUTOMAKE : RULE_USER,
6819 for my $undefined_cond (@undefined_conds)
6821 my $condparagraph = $paragraph;
6822 $condparagraph =~ s/^/$undefined_cond->subst_string/gme;
6823 $result_rules .= "$spacing$comment$condparagraph\n";
6825 if (scalar @undefined_conds == 0)
6827 # Remember to discard next paragraphs
6828 # if they belong to this rule.
6829 # (but see also FIXME: #2 above.)
6832 $comment = $spacing = '';
6838 elsif (/$ASSIGNMENT_PATTERN/mso)
6840 my ($var, $type, $val) = ($1, $2, $3);
6841 error $where, "variable '$var' with trailing backslash"
6846 Automake::Variable::define ($var,
6847 $is_am ? VAR_AUTOMAKE : VAR_MAKEFILE,
6848 $type, $cond, $val, $comment, $where,
6852 $comment = $spacing = '';
6856 # This isn't an error; it is probably some tokens which
6857 # configure is supposed to replace, such as '@SET-MAKE@',
6858 # or some part of a rule cut by an if/endif.
6859 if (! $cond->false && ! ($is_rule && $discard_rule))
6861 s/^/$cond->subst_string/gme;
6862 $result_rules .= "$spacing$comment$_\n";
6864 $comment = $spacing = '';
6868 error ($where, @cond_stack ?
6869 "unterminated conditionals: @cond_stack" :
6870 "too many conditionals closed in include file")
6871 if "@saved_cond_stack" ne "@cond_stack";
6873 return ($comment, $result_vars, $result_rules);
6878 # file_contents ($BASENAME, $WHERE, [%TRANSFORM])
6879 # -----------------------------------------------
6880 # Return contents of a file from $libdir/am, automatically skipping
6881 # macros or rules which are already known.
6884 my ($basename, $where, %transform) = @_;
6885 my ($comments, $variables, $rules) =
6886 file_contents_internal (1, "$libdir/am/$basename.am", $where,
6888 return "$comments$variables$rules";
6893 # am_primary_prefixes ($PRIMARY, $CAN_DIST, @PREFIXES)
6894 # ----------------------------------------------------
6895 # Find all variable prefixes that are used for install directories. A
6896 # prefix 'zar' qualifies iff:
6898 # * 'zardir' is a variable.
6899 # * 'zar_PRIMARY' is a variable.
6901 # As a side effect, it looks for misspellings. It is an error to have
6902 # a variable ending in a "reserved" suffix whose prefix is unknown, e.g.
6903 # "bni_PROGRAMS". However, unusual prefixes are allowed if a variable
6904 # of the same name (with "dir" appended) exists. For instance, if the
6905 # variable "zardir" is defined, then "zar_PROGRAMS" becomes valid.
6906 # This is to provide a little extra flexibility in those cases which
6908 sub am_primary_prefixes
6910 my ($primary, $can_dist, @prefixes) = @_;
6913 my %valid = map { $_ => 0 } @prefixes;
6914 $valid{'EXTRA'} = 0;
6915 foreach my $var (variables $primary)
6917 # Automake is allowed to define variables that look like primaries
6918 # but which aren't. E.g. INSTALL_sh_DATA.
6919 # Autoconf can also define variables like INSTALL_DATA, so
6920 # ignore all configure variables (at least those which are not
6921 # redefined in Makefile.am).
6922 # FIXME: We should make sure that these variables are not
6923 # conditionally defined (or else adjust the condition below).
6924 my $def = $var->def (TRUE);
6925 next if $def && $def->owner != VAR_MAKEFILE;
6927 my $varname = $var->name;
6929 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_[[:alnum:]]+$/)
6931 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
6932 if ($dist ne '' && ! $can_dist)
6935 "invalid variable '$varname': 'dist' is forbidden");
6937 # Standard directories must be explicitly allowed.
6938 elsif (! defined $valid{$X} && exists $standard_prefix{$X})
6941 "'${X}dir' is not a legitimate directory " .
6944 # A not explicitly valid directory is allowed if Xdir is defined.
6945 elsif (! defined $valid{$X} &&
6946 $var->requires_variables ("'$varname' is used", "${X}dir"))
6948 # Nothing to do. Any error message has been output
6949 # by $var->requires_variables.
6953 # Ensure all extended prefixes are actually used.
6954 $valid{"$base$dist$X"} = 1;
6959 prog_error "unexpected variable name: $varname";
6963 # Return only those which are actually defined.
6964 return sort grep { var ($_ . '_' . $primary) } keys %valid;
6968 # am_install_var (-OPTION..., file, HOW, where...)
6969 # ------------------------------------------------
6971 # Handle 'where_HOW' variable magic. Does all lookups, generates
6972 # install code, and possibly generates code to define the primary
6973 # variable. The first argument is the name of the .am file to munge,
6974 # the second argument is the primary variable (e.g. HEADERS), and all
6975 # subsequent arguments are possible installation locations.
6977 # Returns list of [$location, $value] pairs, where
6978 # $value's are the values in all where_HOW variable, and $location
6979 # there associated location (the place here their parent variables were
6982 # FIXME: this should be rewritten to be cleaner. It should be broken
6983 # up into multiple functions.
6991 my $default_dist = 0;
6994 if ($args[0] eq '-noextra')
6998 elsif ($args[0] eq '-candist')
7002 elsif ($args[0] eq '-defaultdist')
7007 elsif ($args[0] !~ /^-/)
7014 my ($file, $primary, @prefix) = @args;
7016 # Now that configure substitutions are allowed in where_HOW
7017 # variables, it is an error to actually define the primary. We
7018 # allow 'JAVA', as it is customarily used to mean the Java
7019 # interpreter. This is but one of several Java hacks. Similarly,
7020 # 'PYTHON' is customarily used to mean the Python interpreter.
7021 reject_var $primary, "'$primary' is an anachronism"
7022 unless $primary eq 'JAVA' || $primary eq 'PYTHON';
7024 # Get the prefixes which are valid and actually used.
7025 @prefix = am_primary_prefixes ($primary, $can_dist, @prefix);
7027 # If a primary includes a configure substitution, then the EXTRA_
7028 # form is required. Otherwise we can't properly do our job.
7034 foreach my $X (@prefix)
7036 my $nodir_name = $X;
7037 my $one_name = $X . '_' . $primary;
7038 my $one_var = var $one_name;
7040 my $strip_subdir = 1;
7041 # If subdir prefix should be preserved, do so.
7042 if ($nodir_name =~ /^nobase_/)
7045 $nodir_name =~ s/^nobase_//;
7048 # If files should be distributed, do so.
7052 $dist_p = (($default_dist && $nodir_name !~ /^nodist_/)
7053 || (! $default_dist && $nodir_name =~ /^dist_/));
7054 $nodir_name =~ s/^(dist|nodist)_//;
7058 # Use the location of the currently processed variable.
7059 # We are not processing a particular condition, so pick the first
7061 my $tmpcond = $one_var->conditions->one_cond;
7062 my $where = $one_var->rdef ($tmpcond)->location->clone;
7064 # Append actual contents of where_PRIMARY variable to
7065 # @result, skipping @substitutions@.
7066 foreach my $locvals ($one_var->value_as_list_recursive (location => 1))
7068 my ($loc, $value) = @$locvals;
7069 # Skip configure substitutions.
7070 if ($value =~ /^\@.*\@$/)
7072 if ($nodir_name eq 'EXTRA')
7075 "'$one_name' contains configure substitution, "
7078 # Check here to make sure variables defined in
7079 # configure.ac do not imply that EXTRA_PRIMARY
7081 elsif (! defined $configure_vars{$one_name})
7083 $require_extra = $one_name
7089 # Strip any $(EXEEXT) suffix the user might have added,
7090 # or this will confuse handle_source_transform() and
7091 # check_canonical_spelling().
7092 # We'll add $(EXEEXT) back later anyway.
7093 # Do it here rather than in handle_programs so the
7094 # uniquifying at the end of this function works.
7095 ${$locvals}[1] =~ s/\$\(EXEEXT\)$//
7096 if $primary eq 'PROGRAMS';
7098 push (@result, $locvals);
7101 # A blatant hack: we rewrite each _PROGRAMS primary to include
7103 append_exeext { 1 } $one_name
7104 if $primary eq 'PROGRAMS';
7105 # "EXTRA" shouldn't be used when generating clean targets,
7106 # all, or install targets. We used to warn if EXTRA_FOO was
7107 # defined uselessly, but this was annoying.
7109 if $nodir_name eq 'EXTRA';
7111 if ($nodir_name eq 'check')
7113 push (@check, '$(' . $one_name . ')');
7117 push (@used, '$(' . $one_name . ')');
7120 # Is this to be installed?
7121 my $install_p = $nodir_name ne 'noinst' && $nodir_name ne 'check';
7123 # If so, with install-exec? (or install-data?).
7124 my $exec_p = ($nodir_name =~ /$EXEC_DIR_PATTERN/o);
7126 my $check_options_p = $install_p && !! option 'std-options';
7128 # Use the location of the currently processed variable as context.
7129 $where->push_context ("while processing '$one_name'");
7131 # The variable containing all files to distribute.
7132 my $distvar = "\$($one_name)";
7133 $distvar = shadow_unconditionally ($one_name, $where)
7134 if ($dist_p && $one_var->has_conditional_contents);
7136 # Singular form of $PRIMARY.
7137 (my $one_primary = $primary) =~ s/S$//;
7138 $output_rules .= file_contents ($file, $where,
7139 PRIMARY => $primary,
7140 ONE_PRIMARY => $one_primary,
7142 NDIR => $nodir_name,
7143 BASE => $strip_subdir,
7145 INSTALL => $install_p,
7147 DISTVAR => $distvar,
7148 'CK-OPTS' => $check_options_p);
7151 # The JAVA variable is used as the name of the Java interpreter.
7152 # The PYTHON variable is used as the name of the Python interpreter.
7153 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7156 define_pretty_variable ($primary, TRUE, INTERNAL, @used);
7157 $output_vars .= "\n";
7160 err_var ($require_extra,
7161 "'$require_extra' contains configure substitution,\n"
7162 . "but 'EXTRA_$primary' not defined")
7163 if ($require_extra && ! var ('EXTRA_' . $primary));
7165 # Push here because PRIMARY might be configure time determined.
7166 push (@all, '$(' . $primary . ')')
7167 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7169 # Make the result unique. This lets the user use conditionals in
7170 # a natural way, but still lets us program lazily -- we don't have
7171 # to worry about handling a particular object more than once.
7172 # We will keep only one location per object.
7174 for my $pair (@result)
7176 my ($loc, $val) = @$pair;
7177 $result{$val} = $loc;
7179 my @l = sort keys %result;
7180 return map { [$result{$_}->clone, $_] } @l;
7184 ################################################################
7186 # Each key in this hash is the name of a directory holding a
7187 # Makefile.in. These variables are local to 'is_make_dir'.
7189 my $make_dirs_set = 0;
7191 # is_make_dir ($DIRECTORY)
7192 # ------------------------
7196 if (! $make_dirs_set)
7198 foreach my $iter (@configure_input_files)
7200 $make_dirs{dirname ($iter)} = 1;
7202 # We also want to notice Makefile.in's.
7203 foreach my $iter (@other_input_files)
7205 if ($iter =~ /Makefile\.in$/)
7207 $make_dirs{dirname ($iter)} = 1;
7212 return defined $make_dirs{$dir};
7215 ################################################################
7217 # Find the aux dir. This should match the algorithm used by
7218 # ./configure. (See the Autoconf documentation for for
7219 # AC_CONFIG_AUX_DIR.)
7220 sub locate_aux_dir ()
7222 if (! $config_aux_dir_set_in_configure_ac)
7224 # The default auxiliary directory is the first
7225 # of ., .., or ../.. that contains install-sh.
7226 # Assume . if install-sh doesn't exist yet.
7227 for my $dir (qw (. .. ../..))
7229 if (-f "$dir/install-sh")
7231 $config_aux_dir = $dir;
7235 $config_aux_dir = '.' unless $config_aux_dir;
7237 # Avoid unsightly '/.'s.
7238 $am_config_aux_dir =
7239 '$(top_srcdir)' . ($config_aux_dir eq '.' ? "" : "/$config_aux_dir");
7240 $am_config_aux_dir =~ s,/*$,,;
7244 # push_required_file ($DIR, $FILE, $FULLFILE)
7245 # -------------------------------------------
7246 # Push the given file onto DIST_COMMON.
7247 sub push_required_file
7249 my ($dir, $file, $fullfile) = @_;
7251 # If the file to be distributed is in the same directory of the
7252 # currently processed Makefile.am, then we want to distribute it
7253 # from this same Makefile.am.
7254 if ($dir eq $relative_dir)
7256 push_dist_common ($file);
7258 # This is needed to allow a construct in a non-top-level Makefile.am
7259 # to require a file in the build-aux directory (see at least the test
7260 # script 'test-driver-is-distributed.sh'). This is related to the
7261 # automake bug#9546. Note that the use of $config_aux_dir instead
7262 # of $am_config_aux_dir here is deliberate and necessary.
7263 elsif ($dir eq $config_aux_dir)
7265 push_dist_common ("$am_config_aux_dir/$file");
7267 # FIXME: another spacial case, for AC_LIBOBJ/AC_LIBSOURCE support.
7268 # We probably need some refactoring of this function and its callers,
7269 # to have a more explicit and systematic handling of all the special
7270 # cases; but, since there are only two of them, this is low-priority
7272 elsif ($config_libobj_dir && $dir eq $config_libobj_dir)
7274 # Avoid unsightly '/.'s.
7275 my $am_config_libobj_dir =
7277 ($config_libobj_dir eq '.' ? "" : "/$config_libobj_dir");
7278 $am_config_libobj_dir =~ s|/*$||;
7279 push_dist_common ("$am_config_libobj_dir/$file");
7281 elsif ($relative_dir eq '.' && ! is_make_dir ($dir))
7283 # If we are doing the topmost directory, and the file is in a
7284 # subdir which does not have a Makefile, then we distribute it
7287 # If a required file is above the source tree, it is important
7288 # to prefix it with '$(srcdir)' so that no VPATH search is
7289 # performed. Otherwise problems occur with Make implementations
7290 # that rewrite and simplify rules whose dependencies are found in a
7291 # VPATH location. Here is an example with OSF1/Tru64 Make.
7303 # Dependency '../a' was found in 'sub/../a', but this make
7304 # implementation simplified it as 'a'. (Note that the sub/
7305 # directory does not even exist.)
7307 # This kind of VPATH rewriting seems hard to cancel. The
7308 # distdir.am hack against VPATH rewriting works only when no
7309 # simplification is done, i.e., for dependencies which are in
7310 # subdirectories, not in enclosing directories. Hence, in
7311 # the latter case we use a full path to make sure no VPATH
7313 $fullfile = '$(srcdir)/' . $fullfile
7314 if $dir =~ m,^\.\.(?:$|/),;
7316 push_dist_common ($fullfile);
7320 prog_error "a Makefile in relative directory $relative_dir " .
7321 "can't add files in directory $dir to DIST_COMMON";
7326 # If a file name appears as a key in this hash, then it has already
7327 # been checked for. This allows us not to report the same error more
7329 my %required_file_not_found = ();
7331 # required_file_check_or_copy ($WHERE, $DIRECTORY, $FILE)
7332 # -------------------------------------------------------
7333 # Verify that the file must exist in $DIRECTORY, or install it.
7334 sub required_file_check_or_copy
7336 my ($where, $dir, $file) = @_;
7338 my $fullfile = "$dir/$file";
7340 my $dangling_sym = 0;
7342 if (-l $fullfile && ! -f $fullfile)
7346 elsif (dir_has_case_matching_file ($dir, $file))
7351 # '--force-missing' only has an effect if '--add-missing' is
7354 if $found_it && (! $add_missing || ! $force_missing);
7356 # If we've already looked for it, we're done. You might wonder why we
7357 # don't do this before searching for the file. If we do that, then
7358 # something like AC_OUTPUT([subdir/foo foo]) will fail to put 'foo.in'
7359 # into $(DIST_COMMON).
7362 return if defined $required_file_not_found{$fullfile};
7363 $required_file_not_found{$fullfile} = 1;
7365 if ($dangling_sym && $add_missing)
7374 # Only install missing files according to our desired
7376 my $message = "required file '$fullfile' not found";
7379 if (-f "$libdir/$file")
7383 # Install the missing file. Symlink if we
7384 # can, copy if we must. Note: delete the file
7385 # first, in case it is a dangling symlink.
7386 $message = "installing '$fullfile'";
7388 # The license file should not be volatile.
7389 if ($file eq "COPYING")
7391 $message .= " using GNU General Public License v3 file";
7392 $trailer2 = "\n Consider adding the COPYING file"
7393 . " to the version control system"
7394 . "\n for your code, to avoid questions"
7395 . " about which license your project uses";
7398 # Windows Perl will hang if we try to delete a
7399 # file that doesn't exist.
7400 unlink ($fullfile) if -f $fullfile;
7401 if ($symlink_exists && ! $copy_missing)
7403 if (! symlink ("$libdir/$file", $fullfile)
7407 $trailer = "; error while making link: $!";
7410 elsif (system ('cp', "$libdir/$file", $fullfile))
7413 $trailer = "\n error while copying";
7415 set_dir_cache_file ($dir, $file);
7420 $trailer = "\n 'automake --add-missing' can install '$file'"
7421 if -f "$libdir/$file";
7424 # If --force-missing was specified, and we have
7425 # actually found the file, then do nothing.
7427 if $found_it && $force_missing;
7429 # If we couldn't install the file, but it is a target in
7430 # the Makefile, don't print anything. This allows files
7431 # like README, AUTHORS, or THANKS to be generated.
7433 if !$suppress && rule $file;
7435 msg ($suppress ? 'note' : 'error', $where, "$message$trailer$trailer2");
7439 # require_file_internal ($WHERE, $MYSTRICT, $DIRECTORY, $QUEUE, @FILES)
7440 # ---------------------------------------------------------------------
7441 # Verify that the file must exist in $DIRECTORY, or install it.
7442 # $MYSTRICT is the strictness level at which this file becomes required.
7443 # Worker threads may queue up the action to be serialized by the master,
7445 sub require_file_internal
7447 my ($where, $mystrict, $dir, $queue, @files) = @_;
7450 unless $strictness >= $mystrict;
7452 foreach my $file (@files)
7454 push_required_file ($dir, $file, "$dir/$file");
7457 queue_required_file_check_or_copy ($required_conf_file_queue,
7458 QUEUE_CONF_FILE, $relative_dir,
7459 $where, $mystrict, @files);
7463 required_file_check_or_copy ($where, $dir, $file);
7468 # require_file ($WHERE, $MYSTRICT, @FILES)
7469 # ----------------------------------------
7472 my ($where, $mystrict, @files) = @_;
7473 require_file_internal ($where, $mystrict, $relative_dir, 0, @files);
7476 # require_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7477 # ----------------------------------------------------------
7478 sub require_file_with_macro
7480 my ($cond, $macro, $mystrict, @files) = @_;
7481 $macro = rvar ($macro) unless ref $macro;
7482 require_file ($macro->rdef ($cond)->location, $mystrict, @files);
7485 # require_libsource_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7486 # ---------------------------------------------------------------
7487 # Require an AC_LIBSOURCEd file. If AC_CONFIG_LIBOBJ_DIR was called, it
7488 # must be in that directory. Otherwise expect it in the current directory.
7489 sub require_libsource_with_macro
7491 my ($cond, $macro, $mystrict, @files) = @_;
7492 $macro = rvar ($macro) unless ref $macro;
7493 if ($config_libobj_dir)
7495 require_file_internal ($macro->rdef ($cond)->location, $mystrict,
7496 $config_libobj_dir, 0, @files);
7500 require_file ($macro->rdef ($cond)->location, $mystrict, @files);
7504 # queue_required_file_check_or_copy ($QUEUE, $KEY, $DIR, $WHERE,
7505 # $MYSTRICT, @FILES)
7506 # --------------------------------------------------------------
7507 sub queue_required_file_check_or_copy
7509 my ($queue, $key, $dir, $where, $mystrict, @files) = @_;
7513 @serial_loc = (QUEUE_LOCATION, $where->serialize ());
7517 @serial_loc = (QUEUE_STRING, $where);
7519 $queue->enqueue ($key, $dir, @serial_loc, $mystrict, 0 + @files, @files);
7522 # require_queued_file_check_or_copy ($QUEUE)
7523 # ------------------------------------------
7524 sub require_queued_file_check_or_copy
7528 my $dir = $queue->dequeue ();
7529 my $loc_key = $queue->dequeue ();
7530 if ($loc_key eq QUEUE_LOCATION)
7532 $where = Automake::Location::deserialize ($queue);
7534 elsif ($loc_key eq QUEUE_STRING)
7536 $where = $queue->dequeue ();
7540 prog_error "unexpected key $loc_key";
7542 my $mystrict = $queue->dequeue ();
7543 my $nfiles = $queue->dequeue ();
7545 push @files, $queue->dequeue ()
7546 foreach (1 .. $nfiles);
7548 unless $strictness >= $mystrict;
7549 foreach my $file (@files)
7551 required_file_check_or_copy ($where, $config_aux_dir, $file);
7555 # require_conf_file ($WHERE, $MYSTRICT, @FILES)
7556 # ---------------------------------------------
7557 # Looks in configuration path, as specified by AC_CONFIG_AUX_DIR.
7558 sub require_conf_file
7560 my ($where, $mystrict, @files) = @_;
7561 my $queue = defined $required_conf_file_queue ? 1 : 0;
7562 require_file_internal ($where, $mystrict, $config_aux_dir,
7567 # require_conf_file_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
7568 # ---------------------------------------------------------------
7569 sub require_conf_file_with_macro
7571 my ($cond, $macro, $mystrict, @files) = @_;
7572 require_conf_file (rvar ($macro)->rdef ($cond)->location,
7576 ################################################################
7578 # require_build_directory ($DIRECTORY)
7579 # ------------------------------------
7580 # Emit rules to create $DIRECTORY if needed, and return
7581 # the file that any target requiring this directory should be made
7583 # We don't want to emit the rule twice, and want to reuse it
7584 # for directories with equivalent names (e.g., 'foo/bar' and './foo//bar').
7585 sub require_build_directory
7587 my $directory = shift;
7589 return $directory_map{$directory} if exists $directory_map{$directory};
7591 my $cdir = File::Spec->canonpath ($directory);
7593 if (exists $directory_map{$cdir})
7595 my $stamp = $directory_map{$cdir};
7596 $directory_map{$directory} = $stamp;
7600 my $dirstamp = "$cdir/\$(am__dirstamp)";
7602 $directory_map{$directory} = $dirstamp;
7603 $directory_map{$cdir} = $dirstamp;
7605 # Set a variable for the dirstamp basename.
7606 define_pretty_variable ('am__dirstamp', TRUE, INTERNAL, '.dirstamp');
7608 # Directory must be removed by 'make distclean'.
7609 $clean_files{$dirstamp} = DIST_CLEAN;
7611 $output_rules .= ("$dirstamp:\n"
7612 . "\t\@\$(MKDIR_P) $directory\n"
7613 . "\t\@: > $dirstamp\n");
7618 # require_build_directory_maybe ($FILE)
7619 # -------------------------------------
7620 # If $FILE lies in a subdirectory, emit a rule to create this
7621 # directory and return the file that $FILE should be made
7622 # dependent upon. Otherwise, just return the empty string.
7623 sub require_build_directory_maybe
7626 my $directory = dirname ($file);
7628 if ($directory ne '.')
7630 return require_build_directory ($directory);
7638 ################################################################
7640 # Push a list of files onto '@dist_common'.
7641 sub push_dist_common
7643 prog_error "push_dist_common run after handle_dist"
7644 if $handle_dist_run;
7645 push @dist_common, @_;
7649 ################################################################
7651 # generate_makefile ($MAKEFILE_AM, $MAKEFILE_IN)
7652 # ----------------------------------------------
7653 # Generate a Makefile.in given the name of the corresponding Makefile and
7654 # the name of the file output by config.status.
7655 sub generate_makefile
7657 my ($makefile_am, $makefile_in) = @_;
7659 # Reset all the Makefile.am related variables.
7660 initialize_per_input;
7662 # AUTOMAKE_OPTIONS can contains -W flags to disable or enable
7663 # warnings for this file. So hold any warning issued before
7664 # we have processed AUTOMAKE_OPTIONS.
7665 buffer_messages ('warning');
7667 # $OUTPUT is encoded. If it contains a ":" then the first element
7668 # is the real output file, and all remaining elements are input
7669 # files. We don't scan or otherwise deal with these input files,
7670 # other than to mark them as dependencies. See the subroutine
7671 # 'scan_autoconf_files' for details.
7672 my ($makefile, @inputs) = split (/:/, $output_files{$makefile_in});
7674 $relative_dir = dirname ($makefile);
7676 read_main_am_file ($makefile_am, $makefile_in);
7677 if (not handle_options)
7679 # Process buffered warnings.
7681 # Fatal error. Just return, so we can continue with next file.
7684 # Process buffered warnings.
7687 # There are a few install-related variables that you should not define.
7688 foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
7693 my $def = $v->def (TRUE);
7694 prog_error "$var not defined in condition TRUE"
7696 reject_var $var, "'$var' should not be defined"
7697 if $def->owner != VAR_AUTOMAKE;
7701 # Catch some obsolete variables.
7702 if (my $ovar = var ('ACLOCAL_AMFLAGS'))
7704 msg_var 'obsolete', $ovar,
7705 "'ACLOCAL_AMFLAGS' is deprecated; use 'AC_CONFIG_MACRO_DIRS'"
7706 . " in configure.ac instead";
7708 if (my $ovar = var ('INCLUDES'))
7710 msg_var 'obsolete', $ovar,
7711 "'INCLUDES' is deprecated; you should use 'AM_CPPFLAGS'"
7712 . " (or '*_CPPFLAGS') instead"
7715 # Must do this after reading .am file.
7716 define_variable ('subdir', $relative_dir, INTERNAL);
7718 # If DIST_SUBDIRS is defined, make sure SUBDIRS is, so that
7719 # recursive rules are enabled.
7720 define_pretty_variable ('SUBDIRS', TRUE, INTERNAL, '')
7721 if var 'DIST_SUBDIRS' && ! var 'SUBDIRS';
7723 # Check first, because we might modify some state.
7724 check_gnu_standards;
7725 check_gnits_standards;
7727 handle_configure ($makefile_am, $makefile_in, $makefile, @inputs);
7738 # These must be run after all the sources are scanned. They use
7739 # variables defined by handle_libraries(), handle_ltlibraries(),
7740 # or handle_programs().
7745 # Variables used by distdir.am and tags.am.
7746 define_pretty_variable ('SOURCES', TRUE, INTERNAL, @sources);
7747 if (! option 'no-dist')
7749 define_pretty_variable ('DIST_SOURCES', TRUE, INTERNAL, @dist_sources);
7760 handle_user_recursion;
7762 handle_minor_options;
7763 # Must come after handle_programs so that %known_programs is up-to-date.
7766 # This must come after most other rules.
7770 do_check_merge_target;
7771 handle_all ($makefile);
7774 if (var ('lib_LTLIBRARIES') && var ('bin_PROGRAMS'))
7776 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
7778 if (var ('nobase_lib_LTLIBRARIES') && var ('bin_PROGRAMS'))
7780 $output_rules .= "install-binPROGRAMS: install-nobase_libLTLIBRARIES\n\n";
7784 handle_clean ($makefile);
7785 handle_factored_dependencies;
7787 # Comes last, because all the above procedures may have
7788 # defined or overridden variables.
7789 $output_vars .= output_variables;
7793 if ($exit_code != 0)
7795 verb "not writing $makefile_in because of earlier errors";
7799 my $am_relative_dir = dirname ($makefile_am);
7800 mkdir ($am_relative_dir, 0755) if ! -d $am_relative_dir;
7802 # We make sure that 'all:' is the first target.
7804 "$output_vars$output_all$output_header$output_rules$output_trailer";
7806 # Decide whether we must update the output file or not.
7807 # We have to update in the following situations.
7808 # * $force_generation is set.
7809 # * any of the output dependencies is younger than the output
7810 # * the contents of the output is different (this can happen
7811 # if the project has been populated with a file listed in
7812 # @common_files since the last run).
7813 # Output's dependencies are split in two sets:
7814 # * dependencies which are also configure dependencies
7815 # These do not change between each Makefile.am
7816 # * other dependencies, specific to the Makefile.am being processed
7817 # (such as the Makefile.am itself, or any Makefile fragment
7819 my $timestamp = mtime $makefile_in;
7820 if (! $force_generation
7821 && $configure_deps_greatest_timestamp < $timestamp
7822 && $output_deps_greatest_timestamp < $timestamp
7823 && $output eq contents ($makefile_in))
7825 verb "$makefile_in unchanged";
7826 # No need to update.
7830 if (-e $makefile_in)
7832 unlink ($makefile_in)
7833 or fatal "cannot remove $makefile_in: $!";
7836 my $gm_file = new Automake::XFile "> $makefile_in";
7837 verb "creating $makefile_in";
7838 print $gm_file $output;
7842 ################################################################
7845 # Helper function for usage().
7846 sub print_autodist_files
7848 my @lcomm = uniq (sort @_);
7851 format USAGE_FORMAT =
7852 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
7853 $four[0], $four[1], $four[2], $four[3]
7855 local $~ = "USAGE_FORMAT";
7858 my $rows = int(@lcomm / $cols);
7859 my $rest = @lcomm % $cols;
7870 for (my $y = 0; $y < $rows; $y++)
7872 @four = ("", "", "", "");
7873 for (my $x = 0; $x < $cols; $x++)
7875 last if $y + 1 == $rows && $x == $rest;
7877 my $idx = (($x > $rest)
7878 ? ($rows * $rest + ($rows - 1) * ($x - $rest))
7882 $four[$x] = $lcomm[$idx];
7891 print "Usage: $0 [OPTION]... [Makefile]...
7893 Generate Makefile.in for configure from Makefile.am.
7896 --help print this help, then exit
7897 --version print version number, then exit
7898 -v, --verbose verbosely list files processed
7899 --no-force only update Makefile.in's that are out of date
7900 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
7902 Dependency tracking:
7903 -i, --ignore-deps disable dependency tracking code
7904 --include-deps enable dependency tracking code
7907 --foreign set strictness to foreign
7908 --gnits set strictness to gnits
7909 --gnu set strictness to gnu
7912 -a, --add-missing add missing standard files to package
7913 --libdir=DIR set directory storing library files
7914 --print-libdir print directory storing library files
7915 -c, --copy with -a, copy missing files (default is symlink)
7916 -f, --force-missing force update of standard files
7919 Automake::ChannelDefs::usage;
7921 print "\nFiles automatically distributed if found " .
7923 print_autodist_files @common_files;
7924 print "\nFiles automatically distributed if found " .
7925 "(under certain conditions):\n";
7926 print_autodist_files @common_sometimes;
7929 Report bugs to <@PACKAGE_BUGREPORT@>.
7930 GNU Automake home page: <@PACKAGE_URL@>.
7931 General help using GNU software: <https://www.gnu.org/gethelp/>.
7934 # --help always returns 0 per GNU standards.
7942 automake (GNU $PACKAGE) $VERSION
7943 Copyright (C) $RELEASE_YEAR Free Software Foundation, Inc.
7944 License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl-2.0.html>
7945 This is free software: you are free to change and redistribute it.
7946 There is NO WARRANTY, to the extent permitted by law.
7948 Written by Tom Tromey <tromey\@redhat.com>
7949 and Alexandre Duret-Lutz <adl\@gnu.org>.
7951 # --version always returns 0 per GNU standards.
7955 ################################################################
7957 # Parse command line.
7958 sub parse_arguments ()
7961 my $ignore_deps = 0;
7966 'version' => \&version,
7968 'libdir=s' => \$libdir,
7969 'print-libdir' => sub { print "$libdir\n"; exit 0; },
7970 'gnu' => sub { $strict = 'gnu'; },
7971 'gnits' => sub { $strict = 'gnits'; },
7972 'foreign' => sub { $strict = 'foreign'; },
7973 'include-deps' => sub { $ignore_deps = 0; },
7974 'i|ignore-deps' => sub { $ignore_deps = 1; },
7975 'no-force' => sub { $force_generation = 0; },
7976 'f|force-missing' => \$force_missing,
7977 'a|add-missing' => \$add_missing,
7978 'c|copy' => \$copy_missing,
7979 'v|verbose' => sub { setup_channel 'verb', silent => 0; },
7980 'W|warnings=s' => \@warnings,
7983 use Automake::Getopt ();
7984 Automake::Getopt::parse_options %cli_options;
7986 set_strictness ($strict);
7987 my $cli_where = new Automake::Location;
7988 set_global_option ('no-dependencies', $cli_where) if $ignore_deps;
7989 for my $warning (@warnings)
7991 parse_warnings ('-W', $warning);
7994 return unless @ARGV;
7997 foreach my $arg (@ARGV)
7999 fatal ("empty argument\nTry '$0 --help' for more information")
8002 # Handle $local:$input syntax.
8003 my ($local, @rest) = split (/:/, $arg);
8004 @rest = ("$local.in",) unless @rest;
8005 my $input = locate_am @rest;
8008 push @input_files, $input;
8009 $output_files{$input} = join (':', ($local, @rest));
8013 error "no Automake input file found for '$arg'";
8017 fatal "no input file found among supplied arguments"
8018 if $errspec && ! @input_files;
8022 # handle_makefile ($MAKEFILE)
8023 # ---------------------------
8027 ($am_file = $file) =~ s/\.in$//;
8028 if (! -f ($am_file . '.am'))
8030 error "'$am_file.am' does not exist";
8034 # Any warning setting now local to this Makefile.am.
8037 generate_makefile ($am_file . '.am', $file);
8039 # Back out any warning setting.
8044 # Deal with all makefiles, without threads.
8045 sub handle_makefiles_serial ()
8047 foreach my $file (@input_files)
8049 handle_makefile ($file);
8053 # Logic for deciding how many worker threads to use.
8054 sub get_number_of_threads ()
8056 my $nthreads = $ENV{'AUTOMAKE_JOBS'} || 0;
8059 unless $nthreads =~ /^[0-9]+$/;
8061 # It doesn't make sense to use more threads than makefiles,
8062 my $max_threads = @input_files;
8064 if ($nthreads > $max_threads)
8066 $nthreads = $max_threads;
8071 # handle_makefiles_threaded ($NTHREADS)
8072 # -------------------------------------
8073 # Deal with all makefiles, using threads. The general strategy is to
8074 # spawn NTHREADS worker threads, dispatch makefiles to them, and let the
8075 # worker threads push back everything that needs serialization:
8076 # * warning and (normal) error messages, for stable stderr output
8077 # order and content (avoiding duplicates, for example),
8078 # * races when installing aux files (and respective messages),
8079 # * races when collecting aux files for distribution.
8081 # The latter requires that the makefile that deals with the aux dir
8082 # files be handled last, done by the master thread.
8083 sub handle_makefiles_threaded
8085 my ($nthreads) = @_;
8087 # The file queue distributes all makefiles, the message queues
8088 # collect all serializations needed for respective files.
8089 my $file_queue = Thread::Queue->new;
8091 foreach my $file (@input_files)
8093 $msg_queues{$file} = Thread::Queue->new;
8096 verb "spawning $nthreads worker threads";
8097 my @threads = (1 .. $nthreads);
8098 foreach my $t (@threads)
8100 $t = threads->new (sub
8102 while (my $file = $file_queue->dequeue)
8104 verb "handling $file";
8105 my $queue = $msg_queues{$file};
8106 setup_channel_queue ($queue, QUEUE_MESSAGE);
8107 $required_conf_file_queue = $queue;
8108 handle_makefile ($file);
8109 $queue->enqueue (undef);
8110 setup_channel_queue (undef, undef);
8111 $required_conf_file_queue = undef;
8117 # Queue all makefiles.
8118 verb "queuing " . @input_files . " input files";
8119 $file_queue->enqueue (@input_files, (undef) x @threads);
8121 # Collect and process serializations.
8122 foreach my $file (@input_files)
8124 verb "dequeuing messages for " . $file;
8125 reset_local_duplicates ();
8126 my $queue = $msg_queues{$file};
8127 while (my $key = $queue->dequeue)
8129 if ($key eq QUEUE_MESSAGE)
8131 pop_channel_queue ($queue);
8133 elsif ($key eq QUEUE_CONF_FILE)
8135 require_queued_file_check_or_copy ($queue);
8139 prog_error "unexpected key $key";
8144 foreach my $t (@threads)
8146 my @exit_thread = $t->join;
8147 $exit_code = $exit_thread[0]
8148 if ($exit_thread[0] > $exit_code);
8152 ################################################################
8154 # Parse the WARNINGS environment variable.
8157 # Parse command line.
8160 fatal "$configure_ac is required" unless -f $configure_ac;
8162 # Do configure.ac scan only once.
8163 scan_autoconf_files;
8168 $msg = "\nDid you forget AC_CONFIG_FILES([Makefile]) in $configure_ac?"
8169 if -f 'Makefile.am';
8170 fatal ("no 'Makefile.am' found for any configure output$msg");
8173 my $nthreads = get_number_of_threads ();
8175 if ($perl_threads && $nthreads >= 1)
8177 handle_makefiles_threaded ($nthreads);
8181 handle_makefiles_serial ();
8187 ### Setup "GNU" style for perl-mode and cperl-mode.
8189 ## perl-indent-level: 2
8190 ## perl-continued-statement-offset: 2
8191 ## perl-continued-brace-offset: 0
8192 ## perl-brace-offset: 0
8193 ## perl-brace-imaginary-offset: 0
8194 ## perl-label-offset: -2
8195 ## cperl-indent-level: 2
8196 ## cperl-brace-offset: 0
8197 ## cperl-continued-brace-offset: 0
8198 ## cperl-label-offset: -2
8199 ## cperl-extra-newline-before-brace: t
8200 ## cperl-merge-trailing-else: nil
8201 ## cperl-continued-statement-offset: 2