5 eval 'exec @PERL@ -S $0 ${1+"$@"}'
8 # automake - create Makefile.in from Makefile.am
9 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
10 # Free Software Foundation, Inc.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2, or (at your option)
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
28 # Perl reimplementation by Tom Tromey <tromey@redhat.com>.
34 my $prefix = "@prefix@";
35 my $perllibdir = $ENV{'perllibdir'} || "@datadir@/@PACKAGE@-@APIVERSION@";
36 unshift @INC, "$perllibdir";
40 struct (# Short name of the language (c, f77...).
42 # Nice name of the language (C, Fortran 77...).
45 # List of configure variables which must be defined.
49 # `pure' is `1' or `'. A `pure' language is one where, if
50 # all the files in a directory are of that language, then we
51 # do not require the C compiler or any code to call it.
56 # Name of the compiling variable (COMPILE).
58 # Content of the compiling variable.
60 # Flag to require compilation without linking (-c).
61 'compile_flag' => "\$",
64 # Should the flag be defined as a configure variable.
65 # Defaults to true. FIXME: this should go away once
66 # we move to autoconf tracing.
67 'define_flag' => "\$",
69 # The file to use when generating rules for this language.
70 # The default is 'depend2'.
73 # Name of the linking variable (LINK).
75 # Content of the linking variable.
78 # Name of the linker variable (LD).
80 # Content of the linker variable ($(CC)).
83 # Flag to specify the output file (-o).
84 'output_flag' => "\$",
87 # This is a subroutine which is called whenever we finally
88 # determine the context in which a source file will be
90 '_target_hook' => "\$");
96 if (defined $self->_finish)
102 sub target_hook ($$$$)
105 if (defined $self->_target_hook)
107 &{$self->_target_hook} (@_);
113 use strict 'vars', 'subs';
114 use Automake::General;
123 # Parameters set by configure. Not to be changed. NOTE: assign
124 # VERSION as string so that eg version 0.30 will print correctly.
125 my $VERSION = "@VERSION@";
126 my $PACKAGE = "@PACKAGE@";
127 my $prefix = "@prefix@";
128 my $libdir = "@datadir@/@PACKAGE@-@APIVERSION@";
131 my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
132 my $WHITE_PATTERN = '^\s*$';
133 my $COMMENT_PATTERN = '^#';
134 my $TARGET_PATTERN='[$a-zA-Z_.@][-.a-zA-Z0-9_(){}/$+@]*';
135 # A rule has three parts: a list of targets, a list of dependencies,
136 # and optionally actions.
138 "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
140 my $SUFFIX_RULE_PATTERN = '^(\.[a-zA-Z0-9_(){}$+@]+)(\.[a-zA-Z0-9_(){}$+@]+)$';
141 # Only recognize leading spaces, not leading tabs. If we recognize
142 # leading tabs here then we need to make the reader smarter, because
143 # otherwise it will think rules like `foo=bar; \' are errors.
144 my $MACRO_PATTERN = '^[A-Za-z0-9_@]+$';
145 my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)$';
146 # This pattern recognizes a Gnits version id and sets $1 if the
147 # release is an alpha release. We also allow a suffix which can be
148 # used to extend the version number with a "fork" identifier.
149 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
150 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?$';
151 my $ELSE_PATTERN = '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
152 my $ENDIF_PATTERN = '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
153 my $PATH_PATTERN='(\w|[/.-])+';
154 # This will pass through anything not of the prescribed form.
155 my $INCLUDE_PATTERN = ('^include\s+'
156 . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
157 . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
158 . '|([^/\$]' . $PATH_PATTERN. '))\s*(#.*)?$');
160 # Some regular expressions. One reason to put them here is that it
161 # makes indentation work better in Emacs.
162 my $AC_CONFIG_AUX_DIR_PATTERN = 'AC_CONFIG_AUX_DIR\(([^)]+)\)';
163 my $AM_INIT_AUTOMAKE_PATTERN = 'AM_INIT_AUTOMAKE\([^,]*,([^,)]+)[,)]';
164 my $AC_INIT_PATTERN = 'AC_INIT\([^,]*,([^,)]+)[,)]';
165 my $AM_PACKAGE_VERSION_PATTERN = '^\s*\[?([^]\s]+)\]?\s*$';
167 # This handles substitution references like ${foo:.a=.b}.
168 my $SUBST_REF_PATTERN = "^([^:]*):([^=]*)=(.*)\$";
170 # Note that there is no AC_PATH_TOOL. But we don't really care.
171 my $AC_CHECK_PATTERN = 'AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\(\[?(\w+)';
172 my $AM_MISSING_PATTERN = 'AM_MISSING_PROG\(\[?(\w+)';
173 # Just check for alphanumeric in AC_SUBST. If you do AC_SUBST(5),
175 my $AC_SUBST_PATTERN = 'AC_SUBST\(\[?(\w+)';
176 my $AM_CONDITIONAL_PATTERN = 'AM_CONDITIONAL\(\[?(\w+)';
177 # Match `-d' as a command-line argument in a string.
178 my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)";
179 # Directories installed during 'install-exec' phase.
180 my $EXEC_DIR_PATTERN =
181 '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)$'; #'
183 # Constants to define the "strictness" level.
184 use constant FOREIGN => 0;
185 use constant GNU => 1;
186 use constant GNITS => 2;
188 # Values for AC_CANONICAL_*
189 use constant AC_CANONICAL_HOST => 1;
190 use constant AC_CANONICAL_SYSTEM => 2;
192 # Values indicating when something should be cleaned. Right now we
193 # only need to handle `mostly'- and `dist'-clean; add more as
195 use constant MOSTLY_CLEAN => 0;
196 use constant DIST_CLEAN => 1;
199 my @libtool_files = qw(ltmain.sh config.guess config.sub);
200 # ltconfig appears here for compatibility with old versions of libtool.
201 my @libtool_sometimes = qw(ltconfig ltcf-c.sh ltcf-cxx.sh ltcf-gcj.sh);
203 # Commonly found files we look for and automatically include in
206 (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
207 ChangeLog INSTALL NEWS README THANKS TODO acinclude.m4
208 ansi2knr.1 ansi2knr.c compile config.guess config.rpath config.sub
209 configure configure.ac configure.in depcomp elisp-comp
210 install-sh libversion.in mdate-sh missing mkinstalldirs
211 py-compile texinfo.tex ylwrap),
212 @libtool_files, @libtool_sometimes);
214 # Commonly used files we auto-include, but only sometimes.
215 my @common_sometimes =
216 qw(aclocal.m4 acconfig.h config.h.top config.h.bot stamp-vti);
218 # Standard directories from the GNU Coding Standards, and additional
219 # pkg* directories from Automake. Stored in a hash for fast member check.
220 my %standard_prefix =
221 map { $_ => 1 } (qw(bin data exec include info lib libexec lisp
222 localstate man man1 man2 man3 man4 man5 man6
223 man7 man8 man9 oldinclude pkgdatadir
224 pkgincludedir pkglibdir sbin sharedstate
227 # Copyright on generated Makefile.ins.
228 my $gen_copyright = "\
229 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
230 # Free Software Foundation, Inc.
231 # This Makefile.in is free software; the Free Software Foundation
232 # gives unlimited permission to copy and/or distribute it,
233 # with or without modifications, as long as this notice is preserved.
235 # This program is distributed in the hope that it will be useful,
236 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
237 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
238 # PARTICULAR PURPOSE.
241 # These constants are returned by lang_*_rewrite functions.
242 # LANG_SUBDIR means that the resulting object file should be in a
243 # subdir if the source file is. In this case the file name cannot
244 # have `..' components.
246 my $LANG_PROCESS = 1;
249 # These are used when keeping track of whether an object can be built
250 # by two different paths.
251 my $COMPILE_LIBTOOL = 1;
252 my $COMPILE_ORDINARY = 2;
254 # Map from obsolete macros to hints for new macros.
255 # If you change this, change the corresponding list in aclocal.in.
256 # FIXME: should just put this into a single file.
257 my %obsolete_macros =
259 'AC_FEATURE_CTYPE' => "use `AC_HEADER_STDC'",
260 'AC_FEATURE_ERRNO' => "add `strerror' to `AC_REPLACE_FUNCS(...)'",
261 'AC_FEATURE_EXIT' => '',
262 'AC_SYSTEM_HEADER' => '',
264 # Note that we do not handle this one, because it is still run
265 # from AM_CONFIG_HEADER. So we deal with it specially in
266 # &scan_autoconf_files.
267 # 'AC_CONFIG_HEADER' => "use `AM_CONFIG_HEADER'",
269 'fp_C_PROTOTYPES' => "use `AM_C_PROTOTYPES'",
270 'fp_PROG_CC_STDC' => "use `AM_PROG_CC_STDC'",
271 'fp_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
272 'fp_WITH_DMALLOC' => "use `AM_WITH_DMALLOC'",
273 'fp_WITH_REGEX' => "use `AM_WITH_REGEX'",
274 'gm_PROG_LIBTOOL' => "use `AM_PROG_LIBTOOL'",
275 'jm_MAINTAINER_MODE' => "use `AM_MAINTAINER_MODE'",
276 'md_TYPE_PTRDIFF_T' => "add `ptrdiff_t' to `AC_CHECK_TYPES(...)'",
277 'ud_PATH_LISPDIR' => "use `AM_PATH_LISPDIR'",
278 'ud_GNU_GETTEXT' => "use `AM_GNU_GETTEXT'",
280 # Now part of autoconf proper, under a different name.
281 'fp_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
282 'AM_SANITY_CHECK_CC' => "automatically done by `AC_PROG_CC'",
283 'AM_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
284 'AM_EXEEXT' => "automatically done by `AC_PROG_(CC|CXX|F77)'",
285 'AM_CYGWIN32' => "use `AC_CYGWIN'",
286 'AM_MINGW32' => "use `AC_MINGW32'",
287 'AM_FUNC_MKTIME' => "use `AC_FUNC_MKTIME'",
290 # Regexp to match the above macros.
291 my $obsolete_rx = '\b(' . join ('|', keys %obsolete_macros) . ')\b';
295 ## ---------------------------------- ##
296 ## Variables related to the options. ##
297 ## ---------------------------------- ##
299 # TRUE if we should always generate Makefile.in.
300 my $force_generation = 1;
302 # Strictness level as set on command line.
303 my $default_strictness = GNU;
305 # Name of strictness level, as set on command line.
306 my $default_strictness_name = 'gnu';
308 # This is TRUE if automatic dependency generation code should be
309 # included in generated Makefile.in.
310 my $cmdline_use_dependencies = 1;
312 # This holds our (eventual) exit status. We don't actually exit until
313 # we have processed all input files.
316 # From the Perl manual.
317 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
319 # TRUE if missing standard files should be installed.
322 # TRUE if we should copy missing files; otherwise symlink if possible.
323 my $copy_missing = 0;
325 # TRUE if we should always update files that we know about.
326 my $force_missing = 0;
329 ## ---------------------------------------- ##
330 ## Variables filled during files scanning. ##
331 ## ---------------------------------------- ##
333 # Name of the top autoconf input: `configure.ac' or `configure.in'.
334 my $configure_ac = '';
336 # Files found by scanning configure.ac for LIBOBJS.
339 # True if AM_C_PROTOTYPES appears in configure.ac.
340 my $am_c_prototypes = 0;
342 # Names used in AC_CONFIG_HEADER call.
343 my @config_headers = ();
344 # Where AC_CONFIG_HEADER appears.
345 my $config_header_location;
347 # Directory where output files go. Actually, output files are
348 # relative to this directory.
349 my $output_directory;
351 # List of Makefile.am's to process, and their corresponding outputs.
352 my @input_files = ();
353 my %output_files = ();
355 # Complete list of Makefile.am's that exist.
356 my @configure_input_files = ();
358 # List of files in AC_CONFIG_FILES/AC_OUTPUT without Makefile.am's,
360 my @other_input_files = ();
361 # Where the last AC_CONFIG_FILES/AC_OUTPUT appears.
362 my $ac_config_files_location;
364 # List of directories to search for configure-required files. This
365 # can be set by AC_CONFIG_AUX_DIR.
366 my @config_aux_path = qw(. .. ../..);
367 my $config_aux_dir = '';
368 my $config_aux_dir_set_in_configure_in = 0;
370 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
371 my $seen_gettext = 0;
372 # Where AM_GNU_GETTEXT appears.
373 my $ac_gettext_location;
375 # TRUE if AC_PROG_LEX or AM_PROG_LEX were seen.
376 my $seen_prog_lex = 0;
378 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).
379 my $seen_canonical = 0;
380 my $canonical_location;
382 # Where AC_PROG_LIBTOOL appears.
385 # Where AM_MAINTAINER_MODE appears.
388 # Actual version we've seen.
389 my $package_version = '';
391 # Where version is defined.
392 my $package_version_location;
394 # Where AM_PATH_LISPDIR appears.
395 my $am_lispdir_location;
397 # Where AM_PATH_PYTHON appears.
398 my $pythondir_location;
400 # TRUE if we've seen AC_ENABLE_MULTILIB.
401 my $seen_multilib = 0;
403 # TRUE if we've seen AM_PROG_CC_C_O
406 # Where AM_INIT_AUTOMAKE is called;
407 my $seen_init_automake = 0;
409 # TRUE if we've seen AM_AUTOMAKE_VERSION.
410 my $seen_automake_version = 0;
412 # Hash table of discovered configure substitutions. Keys are names,
413 # values are `FILE:LINE' strings which are used by error message
415 my %configure_vars = ();
417 # This is used to keep track of which variable definitions we are
418 # scanning. It is only used in certain limited ways, but it has to be
419 # global. It is declared just for documentation purposes.
420 my %vars_scanned = ();
422 # TRUE if --cygnus seen.
425 # Hash table of AM_CONDITIONAL variables seen in configure.
426 my %configure_cond = ();
428 # This maps extensions onto language names.
429 my %extension_map = ();
431 # List of the DIST_COMMON files we discovered while reading
433 my $configure_dist_common = '';
435 # This maps languages names onto objects.
438 # List of targets we must always output.
439 # FIXME: Complete, and remove falsely required targets.
440 my %required_targets =
451 # FIXME: Not required, temporary hacks.
452 # Well, actually they are sort of required: the -recursive
453 # targets will run them anyway...
456 'install-data-am' => 1,
457 'install-exec-am' => 1,
458 'installcheck-am' => 1,
464 # This is set to 1 when Automake needs to be run again.
465 # (For instance, this happens when an auxiliary file such as
466 # depcomp is added after the toplevel Makefile.in -- which
467 # should distribute depcomp -- has been generated.)
468 my $automake_needs_to_reprocess_all_files = 0;
470 # Options set via AM_INIT_AUTOMAKE.
471 my $global_options = '';
475 ################################################################
477 ## ------------------------------------------ ##
478 ## Variables reset by &initialize_per_input. ##
479 ## ------------------------------------------ ##
481 # Basename and relative dir of the input file.
485 # Same but wrt Makefile.in.
489 # These two variables are used when generating each Makefile.in.
490 # They hold the Makefile.in until it is ready to be printed.
497 # Suffixes found during a run.
500 # Handling the variables.
503 # - $var_value{$VAR}{$COND} is its value associated to $COND,
504 # - $var_location{$VAR} is where it was defined,
505 # - $var_comment{$VAR} are the comments associated to it.
506 # - $var_type{$VAR} is how it has been defined (`', `+', or `:'),
507 # - $var_is_am{$VAR} is true if the variable is owned by Automake.
514 # This holds a 1 if a particular variable was examined.
517 # This holds the names which are targets. These also appear in
521 # Same as %VAR_VALUE, but for targets.
522 my %target_conditional;
524 # This is the conditional stack.
527 # This holds the set of included files.
530 # This holds a list of directories which we must create at `dist'
531 # time. This is used in some strange scenarios involving weird
532 # AC_OUTPUT commands.
535 # List of dependencies for the obvious targets.
540 # Holds the dependencies of targets which dependencies are factored.
541 # Typically, `.PHONY' will appear in plenty of *.am files, but must
542 # be output once. Arguably all pure dependencies could be subject
543 # to this factorization, but it is not unpleasant to have paragraphs
544 # in Makefile: keeping related stuff altogether.
547 # Holds the factored actions. Tied to %DEPENDENCIES, i.e., filled
548 # only when keys exists in %DEPENDENCIES.
551 # A list of files deleted by `maintainer-clean'.
552 my @maintainer_clean_files;
554 # Keys in this hash table are object files or other files in
555 # subdirectories which need to be removed. This only holds files
556 # which are created by compilations. The value in the hash indicates
557 # when the file should be removed.
558 my %compile_clean_files;
560 # Value of `$(SOURCES)', used by tags.am.
562 # Sources which go in the distribution.
565 # This hash maps object file names onto their corresponding source
566 # file names. This is used to ensure that each object is created
567 # by a single source file.
570 # This hash maps object file names onto an integer value representing
571 # whether this object has been built via ordinary compilation or
572 # libtool compilation (the COMPILE_* constants).
573 my %object_compilation_map;
576 # This keeps track of the directories for which we've already
577 # created `.dirstamp' code.
587 # Options from AUTOMAKE_OPTIONS.
590 # Whether or not dependencies are handled. Can be further changed
592 my $use_dependencies;
594 # This is a list of all targets to run during "make dist".
597 # Keys in this hash are the basenames of files which must depend on
598 # ansi2knr. Values are either the empty string, or the directory in
599 # which the ANSI source file appears; the directory must have a
603 # This maps the source extension of a suffix rule to its
604 # corresponding output extension.
605 # FIXME: because this hash maps one input extension to one output
606 # extension, Automake cannot handle two suffix rules with the same
610 # This is the name of the redirect `all' target to use.
613 # This keeps track of which extensions we've seen (that we care
617 # This is random scratch space for the language finish functions.
618 # Don't randomly overwrite it; examine other uses of keys first.
619 my %language_scratch;
621 # We keep track of which objects need special (per-executable)
622 # handling on a per-language basis.
623 my %lang_specific_files;
625 # This is set when `handle_dist' has finished. Once this happens,
626 # we should no longer push on dist_common.
629 # Used to store a set of linkers needed to generate the sources currently
630 # under consideration.
633 # True if we need `LINK' defined. This is a hack.
636 # This is the list of such variables to output.
637 # FIXME: Might be useless actually.
640 # Was get_object_extension run?
641 # FIXME: This is a hack. a better switch should be found.
642 my $get_object_extension_was_run;
644 # Contains a stack of `from' parts of variable substitutions currently in
648 # Contains a stack of `to' parts of variable substitutions currently in
652 # Associates a variable name, together with a list of substitutions to be
653 # performed on it, with a number. Used to provide unique names for generated
657 ## --------------------------------- ##
658 ## Forward subroutine declarations. ##
659 ## --------------------------------- ##
660 sub register_language (%);
661 sub file_contents_internal ($$%);
662 sub define_objects_from_sources ($$$$$$$);
665 # &initialize_per_input ()
666 # ------------------------
667 # (Re)-Initialize per-Makefile.am variables.
668 sub initialize_per_input ()
671 $am_relative_dir = '';
678 $output_trailer = '';
694 %target_conditional = ();
714 # Installing/uninstalling.
715 'install-data-am' => [],
716 'install-exec-am' => [],
717 'uninstall-am' => [],
720 'uninstall-man' => [],
722 'install-info' => [],
723 'install-info-am' => [],
724 'uninstall-info' => [],
726 'installcheck-am' => [],
730 'mostlyclean-am' => [],
731 'maintainer-clean-am' => [],
732 'distclean-am' => [],
735 'maintainer-clean' => [],
746 @maintainer_clean_files = ();
752 %object_compilation_map = ();
758 $strictness = $default_strictness;
759 $strictness_name = $default_strictness_name;
763 $use_dependencies = $cmdline_use_dependencies;
773 %extension_seen = ();
775 %language_scratch = ();
777 %lang_specific_files = ();
779 $handle_dist_run = 0;
785 $get_object_extension_was_run = 0;
787 %compile_clean_files = ();
791 ################################################################
793 # Initialize our list of languages that are internally supported.
796 register_language ('name' => 'c',
798 'config_vars' => ['CC'],
802 'compiler' => 'COMPILE',
803 'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
807 'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
808 'compile_flag' => '-c',
809 'extensions' => ['.c'],
810 '_finish' => \&lang_c_finish);
813 register_language ('name' => 'cxx',
815 'config_vars' => ['CXX'],
816 'linker' => 'CXXLINK',
817 'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
819 'flags' => 'CXXFLAGS',
820 'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
821 'compiler' => 'CXXCOMPILE',
822 'compile_flag' => '-c',
823 'output_flag' => '-o',
827 'extensions' => ['.c++', '.cc', '.cpp', '.cxx', '.C']);
830 register_language ('name' => 'objc',
831 'Name' => 'Objective C',
832 'config_vars' => ['OBJC'],
833 'linker' => 'OBJCLINK',,
834 'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
836 'flags' => 'OBJCFLAGS',
837 'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
838 'compiler' => 'OBJCCOMPILE',
839 'compile_flag' => '-c',
840 'output_flag' => '-o',
844 'extensions' => ['.m']);
847 register_language ('name' => 'header',
849 'extensions' => ['.h', '.H', '.hxx', '.h++', '.hh',
852 '_finish' => sub { });
855 register_language ('name' => 'yacc',
857 'config_vars' => ['YACC'],
860 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
861 'compiler' => 'YACCCOMPILE',
862 'extensions' => ['.y'],
863 'rule_file' => 'yacc',
864 '_finish' => \&lang_yacc_finish,
865 '_target_hook' => \&lang_yacc_target_hook);
866 register_language ('name' => 'yaccxx',
867 'Name' => 'Yacc (C++)',
868 'config_vars' => ['YACC'],
869 'rule_file' => 'yacc',
872 'compiler' => 'YACCCOMPILE',
873 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
874 'extensions' => ['.y++', '.yy', '.yxx', '.ypp'],
875 '_finish' => \&lang_yacc_finish,
876 '_target_hook' => \&lang_yacc_target_hook);
879 register_language ('name' => 'lex',
881 'config_vars' => ['LEX'],
882 'rule_file' => 'lex',
885 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
886 'compiler' => 'LEXCOMPILE',
887 'extensions' => ['.l'],
888 '_finish' => \&lang_lex_finish);
889 register_language ('name' => 'lexxx',
890 'Name' => 'Lex (C++)',
891 'config_vars' => ['LEX'],
892 'rule_file' => 'lex',
895 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
896 'compiler' => 'LEXCOMPILE',
897 'extensions' => ['.l++', '.ll', '.lxx', '.lpp'],
898 '_finish' => \&lang_lex_finish);
901 register_language ('name' => 'asm',
902 'Name' => 'Assembler',
903 'config_vars' => ['CCAS', 'CCASFLAGS'],
905 'flags' => 'CCASFLAGS',
906 # Users can set AM_ASFLAGS to includes DEFS, INCLUDES,
907 # or anything else required. They can also set AS.
908 'compile' => '$(CCAS) $(AM_CCASFLAGS) $(CCASFLAGS)',
909 'compiler' => 'CCASCOMPILE',
910 'compile_flag' => '-c',
911 'extensions' => ['.s', '.S'],
913 # With assembly we still use the C linker.
914 '_finish' => \&lang_c_finish);
917 register_language ('name' => 'f77',
918 'Name' => 'Fortran 77',
919 'linker' => 'F77LINK',
920 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
922 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
923 'compiler' => 'F77COMPILE',
924 'compile_flag' => '-c',
925 'output_flag' => '-o',
929 'extensions' => ['.f', '.for', '.f90']);
931 # Preprocessed Fortran 77
933 # The current support for preprocessing Fortran 77 just involves
934 # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
935 # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
936 # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
937 # for `make' Version 3.76 Beta' (specifically, from info file
938 # `(make)Catalogue of Rules').
940 # A better approach would be to write an Autoconf test
941 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
942 # Fortran 77 compilers know how to do preprocessing. The Autoconf
943 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
944 # preprocessing capabilities, and then fall back on cpp (if cpp were
946 register_language ('name' => 'ppf77',
947 'Name' => 'Preprocessed Fortran 77',
948 'config_vars' => ['F77'],
949 'linker' => 'F77LINK',
950 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
954 'compiler' => 'PPF77COMPILE',
955 'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
956 'compile_flag' => '-c',
957 'output_flag' => '-o',
959 'extensions' => ['.F']);
962 register_language ('name' => 'ratfor',
964 'config_vars' => ['F77'],
965 'linker' => 'F77LINK',
966 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
971 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
972 'compiler' => 'RCOMPILE',
973 'compile_flag' => '-c',
974 'output_flag' => '-o',
976 'extensions' => ['.r']);
979 register_language ('name' => 'java',
981 'config_vars' => ['GCJ'],
982 'linker' => 'GCJLINK',
983 'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
985 'flags' => 'GCJFLAGS',
986 'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
987 'compiler' => 'GCJCOMPILE',
988 'compile_flag' => '-c',
989 'output_flag' => '-o',
993 'extensions' => ['.java', '.class', '.zip', '.jar']);
995 ################################################################
997 # Parse command line.
1000 # Do configure.ac scan only once.
1001 &scan_autoconf_files;
1003 die "$me: no `Makefile.am' found or specified\n"
1006 my $automake_has_run = 0;
1010 if ($automake_has_run)
1012 print "$me: processing Makefiles another time to fix them up.\n";
1013 &prog_error ("running more than two times should never be needed.")
1014 if $automake_has_run >= 2;
1016 $automake_needs_to_reprocess_all_files = 0;
1018 # Now do all the work on each file.
1019 # This guy must be local otherwise it's private to the loop.
1020 use vars '$am_file';
1022 foreach $am_file (@input_files)
1024 if (! -f ($am_file . '.am'))
1026 &am_error ("`" . $am_file . ".am' does not exist");
1030 &generate_makefile ($output_files{$am_file}, $am_file);
1033 ++$automake_has_run;
1035 while ($automake_needs_to_reprocess_all_files);
1039 # FIXME: This should be `my'ed next to its subs.
1040 use vars '%require_file_found';
1042 ################################################################
1044 # prog_error (@PRINT-ME)
1045 # ----------------------
1046 # Signal a programming error, display PRINT-ME, and exit 1.
1049 print STDERR "$me: programming error: @_\n";
1056 # Return a configure-style substitution using the indicated text.
1057 # We do this to avoid having the substitutions directly in automake.in;
1058 # when we do that they are sometimes removed and this causes confusion
1063 return '@' . $text . '@';
1066 ################################################################
1070 # &backname ($REL-DIR)
1071 # --------------------
1072 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
1073 # For instance `src/foo' => `../..'.
1074 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
1079 foreach (split (/\//, $file))
1081 next if $_ eq '.' || $_ eq '';
1091 return join ('/', @res) || '.';
1094 ################################################################
1096 # Pattern that matches all know input extensions (i.e. extensions used
1097 # by the languages supported by Automake). Using this pattern
1098 # (instead of `\..*$') to match extensions allows Automake to support
1099 # dot-less extensions.
1100 my $KNOWN_EXTENSIONS_PATTERN = "";
1101 my @known_extensions_list = ();
1103 # accept_extensions (@EXTS)
1104 # -------------------------
1105 # Update $KNOWN_EXTENSIONS_PATTERN to recognize the extensions
1106 # listed @EXTS. Extensions should contain a dot if needed.
1107 sub accept_extensions (@)
1109 push @known_extensions_list, @_;
1110 $KNOWN_EXTENSIONS_PATTERN =
1111 '(?:' . join ('|', map (quotemeta, @known_extensions_list)) . ')';
1114 # var_SUFFIXES_trigger ($TYPE, $VALUE)
1115 # ------------------------------------
1116 # This is called automagically by define_macro() when SUFFIXES
1117 # is defined ($TYPE eq '') or appended ($TYPE eq '+').
1118 # The work here needs to be performed as a side-effect of the
1119 # define_macro() call because SUFFIXES definitions impact
1120 # on $KNOWN_EXTENSIONS_PATTERN, and $KNOWN_EXTENSIONS_PATTERN
1121 # are used when parsing the input am file.
1122 sub var_SUFFIXES_trigger ($$)
1124 my ($type, $value) = @_;
1125 accept_extensions (split (' ', $value));
1128 ################################################################
1130 # Parse command line.
1131 sub parse_arguments ()
1134 &set_strictness ('gnu');
1137 Getopt::Long::config ("bundling", "pass_through");
1138 Getopt::Long::GetOptions
1140 'version' => \&version,
1142 'libdir:s' => \$libdir,
1143 'gnu' => sub { &set_strictness ('gnu'); },
1144 'gnits' => sub { &set_strictness ('gnits'); },
1145 'cygnus' => \$cygnus_mode,
1146 'foreign' => sub { &set_strictness ('foreign'); },
1147 'include-deps' => sub { $cmdline_use_dependencies = 1; },
1148 'i|ignore-deps' => sub { $cmdline_use_dependencies = 0; },
1149 'no-force' => sub { $force_generation = 0; },
1150 'f|force-missing'=> \$force_missing,
1151 'o|output-dir:s' => \$output_directory,
1152 'a|add-missing' => \$add_missing,
1153 'c|copy' => \$copy_missing,
1154 'v|verbose' => \$verbose,
1155 'Werror' => sub { $SIG{"__WARN__"} = sub { die $_[0] } },
1156 'Wno-error' => sub { $SIG{"__WARN__"} = 'DEFAULT' }
1160 if (defined $output_directory)
1162 print STDERR "$0: `--output-dir' is deprecated\n";
1166 # In the next release we'll remove this entirely.
1167 $output_directory = '.';
1170 foreach my $arg (@ARGV)
1174 print STDERR "$0: unrecognized option `$arg'\n";
1175 print STDERR "Try `$0 --help' for more information.\n";
1179 # Handle $local:$input syntax. Note that we only examine the
1180 # first ":" file to see if it is automake input; the rest are
1181 # just taken verbatim. We still keep all the files around for
1182 # dependency checking, however.
1183 my ($local, $input, @rest) = split (/:/, $arg);
1190 # Strip .in; later on .am is tacked on. That is how the
1191 # automake input file is found. Maybe not the best way, but
1192 # it is easy to explain.
1194 or die "$me: invalid input file name `$arg'\n.";
1196 push (@input_files, $input);
1197 $output_files{$input} = join (':', ($local, @rest));
1200 # Take global strictness from whatever we currently have set.
1201 $default_strictness = $strictness;
1202 $default_strictness_name = $strictness_name;
1205 ################################################################
1207 # Generate a Makefile.in given the name of the corresponding Makefile and
1208 # the name of the file output by config.status.
1209 sub generate_makefile
1211 my ($output, $makefile) = @_;
1213 # Reset all the Makefile.am related variables.
1214 &initialize_per_input;
1216 # Name of input file ("Makefile.am") and output file
1217 # ("Makefile.in"). These have no directory components.
1218 $am_file_name = basename ($makefile) . '.am';
1219 $in_file_name = basename ($makefile) . '.in';
1221 # $OUTPUT is encoded. If it contains a ":" then the first element
1222 # is the real output file, and all remaining elements are input
1223 # files. We don't scan or otherwise deal with these input file,
1224 # other than to mark them as dependencies. See
1225 # &scan_autoconf_files for details.
1226 my (@secondary_inputs);
1227 ($output, @secondary_inputs) = split (/:/, $output);
1229 $relative_dir = dirname ($output);
1230 $am_relative_dir = dirname ($makefile);
1232 &read_main_am_file ($makefile . '.am');
1233 if (&handle_options)
1235 # Fatal error. Just return, so we can continue with next file.
1239 # There are a few install-related variables that you should not define.
1240 foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
1242 if (variable_defined ($var) && !$var_is_am{$var})
1244 macro_error ($var, "`$var' should not be defined");
1250 # At the toplevel directory, we might need config.guess, config.sub
1251 # or libtool scripts (ltconfig and ltmain.sh).
1252 if ($relative_dir eq '.')
1254 # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1256 require_conf_file ($canonical_location, FOREIGN,
1257 'config.guess', 'config.sub')
1261 # We still need Makefile.in here, because sometimes the `dist'
1262 # target doesn't re-run automake.
1263 if ($am_relative_dir eq $relative_dir)
1265 # Only distribute the files if they are in the same subdir as
1266 # the generated makefile.
1267 &push_dist_common ($in_file_name, $am_file_name);
1270 push (@sources, '$(SOURCES)')
1271 if variable_defined ('SOURCES');
1273 # Must do this after reading .am file. See read_main_am_file to
1274 # understand weird tricks we play there with variables.
1275 &define_variable ('subdir', $relative_dir);
1277 # Check first, because we might modify some state.
1279 &check_gnu_standards;
1280 &check_gnits_standards;
1282 &handle_configure ($output, $makefile, @secondary_inputs);
1285 &handle_ltlibraries;
1289 # This must run first so that the ANSI2KNR definition is generated
1290 # before it is used by the _.c rules. We have to do this because
1291 # a variable which is used in a dependency must be defined before
1292 # the target, or else make won't properly see it.
1294 # This must be run after all the sources are scanned.
1297 # Re-init SOURCES. FIXME: other code shouldn't depend on this
1298 # (but currently does).
1299 macro_define ('SOURCES', 1, '', 'TRUE', "@sources", 'internal');
1300 define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
1312 &handle_minor_options;
1315 # This must come after most other rules.
1316 &handle_dist ($makefile);
1319 &do_check_merge_target;
1320 &handle_all ($output);
1323 if (variable_defined ('lib_LTLIBRARIES') &&
1324 variable_defined ('bin_PROGRAMS'))
1326 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
1329 &handle_installdirs;
1331 &handle_factored_dependencies;
1335 if (! -d ($output_directory . '/' . $am_relative_dir))
1337 mkdir ($output_directory . '/' . $am_relative_dir, 0755);
1340 my ($out_file) = $output_directory . '/' . $makefile . ".in";
1341 if (! $force_generation && -e $out_file)
1343 my ($am_time) = (stat ($makefile . '.am'))[9];
1344 my ($in_time) = (stat ($out_file))[9];
1345 # FIXME: should cache these times.
1346 my ($conf_time) = (stat ($configure_ac))[9];
1347 # FIXME: how to do unsigned comparison?
1348 if ($am_time < $in_time || $am_time < $conf_time)
1350 # No need to update.
1353 if (-f 'aclocal.m4')
1355 my ($acl_time) = (stat _)[9];
1356 return if ($am_time < $acl_time);
1363 or die "$me: cannot remove $out_file: $!\n";
1365 my $gm_file = new Automake::XFile "> $out_file";
1366 verbose "creating ", $makefile, ".in";
1368 print $gm_file $output_vars;
1369 # We make sure that `all:' is the first target.
1370 print $gm_file $output_all;
1371 print $gm_file $output_header;
1372 print $gm_file $output_rules;
1373 print $gm_file $output_trailer;
1376 ################################################################
1378 # A helper which handles the logic of requiring a version number in
1379 # AUTOMAKE_OPTIONS. Return 1 on error, 0 on success.
1380 sub version_check ($$$$)
1382 my ($rmajor, $rminor, $ralpha, $rfork) = ($1, $2, $3, $4);
1384 prog_error ("version is incorrect: $VERSION")
1385 if $VERSION !~ /(\d+)\.(\d+)([a-z]?)-?([A-Za-z0-9]+)?/;
1387 my ($tmajor, $tminor, $talpha, $tfork) = ($1, $2, $3, $4);
1392 my $rminorminor = 0;
1393 my $tminorminor = 0;
1395 # Some versions were labelled like `1.4-p3a'. This is the same as
1396 # an alpha release labelled `1.4.3a'. However, a version like
1397 # `1.4g' is the same as `1.4.99g'. Yes, this sucks. Moral:
1398 # always listen to the users.
1399 if ($rfork =~ /p([0-9]+)([a-z]?)/)
1402 # `1.4a-p3b' never existed. But we'll accept it anyway.
1403 $ralpha = $ralpha || $2 || '';
1406 if ($tfork =~ /p([0-9]+)([a-z]?)/)
1409 # `1.4a-p3b' never existed. But we'll accept it anyway.
1410 $talpha = $talpha || $2 || '';
1414 $rminorminor = 99 if $ralpha ne '' && $rminorminor == 0;
1415 $tminorminor = 99 if $talpha ne '' && $tminorminor == 0;
1417 # 2.0 is better than 1.0.
1418 # 1.2 is better than 1.1.
1419 # 1.2a is better than 1.2.
1420 # If we require 3.4n-foo then we require something
1421 # >= 3.4n, with the `foo' fork identifier.
1422 # The $r* variables are what the user specified.
1423 # The $t* variables denote automake itself.
1424 if ($rmajor > $tmajor
1425 || ($rmajor == $tmajor && $rminor > $tminor)
1426 || ($rminor == $tminor && $rminor == $tminor
1427 && $rminorminor > $tminorminor)
1428 || ($rminor == $tminor && $rminor == $tminor
1429 && $rminorminor == $tminorminor
1430 && $ralpha gt $talpha)
1431 || ($rfork ne '' && $rfork ne $tfork))
1440 # process_option_list ($CONFIG, @OPTIONS)
1441 # ------------------------------
1442 # Process a list of options. Return 1 on error, 0 otherwise.
1443 # This is a helper for handle_options. CONFIG is true if we're
1444 # handling global options.
1445 sub process_option_list
1447 my ($config, @list) = @_;
1451 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
1453 &set_strictness ($_);
1455 elsif ($_ eq 'cygnus')
1459 elsif (/^(.*\/)?ansi2knr$/)
1461 # An option like "../lib/ansi2knr" is allowed. With no
1462 # path prefix, we assume the required programs are in this
1463 # directory. We save the actual option for later.
1464 $options{'ansi2knr'} = $_;
1466 elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
1467 || $_ eq 'dist-shar' || $_ eq 'dist-zip'
1468 || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
1469 || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
1470 || $_ eq 'readme-alpha' || $_ eq 'check-news'
1471 || $_ eq 'subdir-objects' || $_ eq 'nostdinc'
1472 || $_ eq 'no-exeext' || $_ eq 'no-define')
1474 # Explicitly recognize these.
1476 elsif ($_ eq 'no-dependencies')
1478 $use_dependencies = 0;
1480 elsif (/(\d+)\.(\d+)([a-z]?)(-[A-Za-z0-9]+)?/)
1482 # Got a version number.
1483 if (version_check ($1, $2, $3, $4))
1487 file_error ($seen_init_automake,
1488 "require version $_, but have $VERSION");
1489 # Arrange to process this global option only once, otherwise
1490 # the error message would be printed for each Makefile.
1491 $global_options =~ s/(?:^| )$_(?: |$)/ /g;
1495 macro_error ('AUTOMAKE_OPTIONS',
1496 "require version $_, but have $VERSION");
1505 file_error ($seen_init_automake,
1506 "option `" . $_ . "\' not recognized");
1510 macro_error ('AUTOMAKE_OPTIONS',
1511 "option `" . $_ . "\' not recognized");
1518 # Handle AUTOMAKE_OPTIONS variable. Return 1 on error, 0 otherwise.
1521 # Process global options first so that more specific options can
1523 if (&process_option_list (1, split (' ', $global_options)))
1528 if (variable_defined ('AUTOMAKE_OPTIONS'))
1530 if (&process_option_list (0, &variable_value_as_list_recursive ('AUTOMAKE_OPTIONS', '')))
1536 if ($strictness == GNITS)
1538 $options{'readme-alpha'} = 1;
1539 $options{'check-news'} = 1;
1546 # get_object_extension ($OUT)
1547 # ---------------------------
1548 # Return object extension. Just once, put some code into the output.
1549 # OUT is the name of the output file
1550 sub get_object_extension
1554 # Maybe require libtool library object files.
1555 my $extension = '.$(OBJEXT)';
1556 $extension = '.lo' if ($out =~ /\.la$/);
1558 # Check for automatic de-ANSI-fication.
1559 $extension = '$U' . $extension
1560 if defined $options{'ansi2knr'};
1562 $get_object_extension_was_run = 1;
1568 # Call finish function for each language that was used.
1569 sub handle_languages
1571 if ($use_dependencies)
1573 # Include auto-dep code. Don't include it if DEP_FILES would
1575 if (&saw_sources_p (0) && keys %dep_files)
1577 # Set location of depcomp.
1578 &define_variable ('depcomp', "\$(SHELL) $config_aux_dir/depcomp");
1579 &define_variable ('am__depfiles_maybe', 'depfiles');
1581 require_conf_file ("$am_file.am", FOREIGN, 'depcomp');
1583 my @deplist = sort keys %dep_files;
1585 # We define this as a conditional variable because BSD
1586 # make can't handle backslashes for continuing comments on
1587 # the following line.
1588 define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
1590 # Generate each `include' individually. Irix 6 make will
1591 # not properly include several files resulting from a
1592 # variable expansion; generating many separate includes
1594 $output_rules .= "\n";
1595 foreach my $iter (@deplist)
1597 $output_rules .= (subst ('AMDEP_TRUE')
1598 . subst ('am__include')
1600 . subst ('am__quote')
1602 . subst ('am__quote')
1606 # Compute the set of directories to remove in distclean-depend.
1607 my @depdirs = uniq (map { dirname ($_) } @deplist);
1608 $output_rules .= &file_contents ('depend',
1609 DEPDIRS => "@depdirs");
1614 &define_variable ('depcomp', '');
1615 &define_variable ('am__depfiles_maybe', '');
1620 # Is the c linker needed?
1622 foreach my $ext (sort keys %extension_seen)
1624 next unless $extension_map{$ext};
1626 my $lang = $languages{$extension_map{$ext}};
1628 my $rule_file = $lang->rule_file || 'depend2';
1630 # Get information on $LANG.
1631 my $pfx = $lang->autodep;
1632 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1634 my $AMDEP = (($use_dependencies && $lang->autodep ne 'no')
1635 ? 'AMDEP' : 'FALSE');
1637 my %transform = ('EXT' => $ext,
1640 'LIBTOOL' => defined $seen_libtool,
1642 '-c' => $lang->compile_flag || '',
1644 => (count_files_for_language ($lang->name) > 1));
1646 # Generate the appropriate rules for this extension.
1647 if (($use_dependencies && $lang->autodep ne 'no')
1648 || defined $lang->compile)
1650 # Some C compilers don't support -c -o. Use it only if really
1652 my $output_flag = $lang->output_flag || '';
1655 && $lang->flags eq 'CFLAGS'
1656 && defined $options{'subdir-objects'});
1658 # FIXME: this is a temporary hack to compute a possible
1659 # derived extension. This is not used by depend2.am.
1660 (my $der_ext = $ext) =~ tr/yl/cc/;
1662 # Another yacc/lex hack.
1663 my $destfile = '$*' . $der_ext;
1666 file_contents ($rule_file,
1670 'DERIVED-EXT' => $der_ext,
1672 # In this situation we know that the
1673 # object is in this directory, so
1674 # $(DEPDIR) is the correct location for
1676 'DEPBASE' => '$(DEPDIR)/$*',
1683 'COMPILE' => '$(' . $lang->compiler . ')',
1684 'LTCOMPILE' => '$(LT' . $lang->compiler . ')',
1685 '-o' => $output_flag);
1688 # Now include code for each specially handled object with this
1690 my %seen_files = ();
1691 foreach my $file (@{$lang_specific_files{$lang->name}})
1693 my ($derived, $source, $obj, $myext) = split (' ', $file);
1695 # For any specially-generated object, we must respect the
1696 # ansi2knr setting so that we don't inadvertently try to
1697 # use the default rule.
1698 if ($lang->ansi && defined $options{'ansi2knr'})
1700 $myext = '$U' . $myext;
1703 # We might see a given object twice, for instance if it is
1704 # used under different conditions.
1705 next if defined $seen_files{$obj};
1706 $seen_files{$obj} = 1;
1708 my $flags = $lang->flags || '';
1709 my $val = "${derived}_${flags}";
1711 prog_error ("found $lang->name in handle_languages, but compiler not defined")
1712 unless defined $lang->compile;
1714 (my $obj_compile = $lang->compile) =~ s/\(AM_$flags/\($val/;
1715 my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
1717 # We _need_ `-o' for per object rules.
1718 my $output_flag = $lang->output_flag || '-o';
1720 my $depbase = dirname ($obj);
1724 unless $depbase eq '';
1725 $depbase .= '$(DEPDIR)/' . basename ($obj);
1727 # Generate a transform which will turn suffix targets in
1728 # depend2.am into real targets for the particular objects we
1731 file_contents ($rule_file,
1735 'DEPBASE' => $depbase,
1737 'SOURCE' => $source,
1738 # Use $myext and not `.o' here, in case
1739 # we are actually building a new source
1740 # file -- e.g. via yacc.
1741 'OBJ' => "$obj$myext",
1742 'OBJOBJ' => "$obj.obj",
1743 'LTOBJ' => "$obj.lo",
1745 'COMPILE' => $obj_compile,
1746 'LTCOMPILE' => $obj_ltcompile,
1747 '-o' => $output_flag));
1750 # The rest of the loop is done once per language.
1751 next if defined $done{$lang};
1754 # Load the language dependent Makefile chunks.
1755 my %lang = map { uc ($_) => 0 } keys %languages;
1756 $lang{uc ($lang->name)} = 1;
1757 $output_rules .= file_contents ('lang-compile', %transform, %lang);
1759 # If the source to a program consists entirely of code from a
1760 # `pure' language, for instance C++ for Fortran 77, then we
1761 # don't need the C compiler code. However if we run into
1762 # something unusual then we do generate the C code. There are
1763 # probably corner cases here that do not work properly.
1764 # People linking Java code to Fortran code deserve pain.
1765 $needs_c ||= ! $lang->pure;
1767 define_compiler_variable ($lang)
1768 if ($lang->compile);
1770 define_linker_variable ($lang)
1773 foreach my $var (@{$lang->config_vars})
1775 am_error ($lang->Name
1776 . " source seen but `$var' not defined in"
1777 . " `$configure_ac'")
1778 if !exists $configure_vars{$var};
1781 # The compiler's flag must be a configure variable.
1782 define_configure_variable ($lang->flags)
1783 if defined $lang->flags && $lang->define_flag;
1785 # Call the finisher.
1789 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1790 # suffix rule was learned), don't bother with the C stuff. But if
1791 # anything else creeps in, then use it.
1793 if $need_link || scalar keys %suffix_rules > 1;
1797 if (! defined $done{$languages{'c'}})
1799 &define_configure_variable ($languages{'c'}->flags);
1800 &define_compiler_variable ($languages{'c'});
1802 define_linker_variable ($languages{'c'});
1806 # Check to make sure a source defined in LIBOBJS is not explicitly
1807 # mentioned. This is a separate function (as opposed to being inlined
1808 # in handle_source_transform) because it isn't always appropriate to
1810 sub check_libobjs_sources
1812 my ($one_file, $unxformed) = @_;
1814 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1815 'dist_EXTRA_', 'nodist_EXTRA_')
1818 if (variable_defined ($prefix . $one_file . '_SOURCES'))
1820 @files = &variable_value_as_list_recursive (
1821 ($prefix . $one_file . '_SOURCES'),
1824 elsif ($prefix eq '')
1826 @files = ($unxformed . '.c');
1833 foreach my $file (@files)
1835 macro_error ($prefix . $one_file . '_SOURCES',
1836 "automatically discovered file `$file' should not be explicitly mentioned")
1837 if defined $libsources{$file};
1844 # handle_single_transform_list ($VAR, $TOPPARENT, $DERIVED, $OBJ, @FILES)
1845 # -----------------------------------------------------------------------
1846 # Does much of the actual work for handle_source_transform.
1848 # $VAR is the name of the variable that the source filenames come from
1849 # $TOPPARENT is the name of the _SOURCES variable which is being processed
1850 # $DERIVED is the name of resulting executable or library
1851 # $OBJ is the object extension (e.g., `$U.lo')
1852 # @FILES is the list of source files to transform
1853 # Result is a list of the names of objects
1854 # %linkers_used will be updated with any linkers needed
1855 sub handle_single_transform_list ($$$$@)
1857 my ($var, $topparent, $derived, $obj, @files) = @_;
1859 my $nonansi_obj = $obj;
1860 $nonansi_obj =~ s/\$U//g;
1862 # Turn sources into objects. We use a while loop like this
1863 # because we might add to @files in the loop.
1864 while (scalar @files > 0)
1868 # Configure substitutions in _SOURCES variables are errors.
1872 "`$var' includes configure substitution `$_', and is referred to from `$topparent': configure substitutions not allowed in _SOURCES variables");
1876 # If the source file is in a subdirectory then the `.o' is put
1877 # into the current directory, unless the subdir-objects option
1880 # Split file name into base and extension.
1881 next if ! /^(?:(.*)\/)?([^\/]*)($KNOWN_EXTENSIONS_PATTERN)$/;
1883 my $directory = $1 || '';
1887 # We must generate a rule for the object if it requires its own flags.
1889 my ($linker, $object);
1891 # This records whether we've seen a derived source file (eg,
1893 my $derived_source = 0;
1895 # This holds the `aggregate context' of the file we are
1896 # currently examining. If the file is compiled with
1897 # per-object flags, then it will be the name of the object.
1898 # Otherwise it will be `AM'. This is used by the target hook
1899 # language function.
1900 my $aggregate = 'AM';
1902 $extension = &derive_suffix ($extension, $nonansi_obj);
1904 if ($extension_map{$extension} &&
1905 ($lang = $languages{$extension_map{$extension}}))
1907 # Found the language, so see what it says.
1908 &saw_extension ($extension);
1910 # Note: computed subr call. The language rewrite function
1911 # should return one of the $LANG_* constants. It could
1912 # also return a list whose first value is such a constant
1913 # and whose second value is a new source extension which
1914 # should be applied. This means this particular language
1915 # generates another source file which we must then process
1917 my $subr = 'lang_' . $lang->name . '_rewrite';
1918 my ($r, $source_extension)
1919 = & $subr ($directory, $base, $extension);
1920 # Skip this entry if we were asked not to process it.
1921 next if $r == $LANG_IGNORE;
1923 # Now extract linker and other info.
1924 $linker = $lang->linker;
1927 if (defined $source_extension)
1929 $this_obj_ext = $source_extension;
1930 $derived_source = 1;
1934 $this_obj_ext = $obj;
1938 $this_obj_ext = $nonansi_obj;
1940 $object = $base . $this_obj_ext;
1942 if (defined $lang->flags
1943 && variable_defined ($derived . '_' . $lang->flags))
1945 # We have a per-executable flag in effect for this
1946 # object. In this case we rewrite the object's
1947 # name to ensure it is unique. We also require
1948 # the `compile' program to deal with compilers
1949 # where `-c -o' does not work.
1951 # We choose the name `DERIVED_OBJECT' to ensure
1952 # (1) uniqueness, and (2) continuity between
1953 # invocations. However, this will result in a
1954 # name that is too long for losing systems, in
1955 # some situations. So we provide _SHORTNAME to
1958 my $dname = $derived;
1959 if (variable_defined ($derived . '_SHORTNAME'))
1961 # FIXME: should use the same conditional as
1962 # the _SOURCES variable. But this is really
1963 # silly overkill -- nobody should have
1964 # conditional shortnames.
1965 $dname = &variable_value ($derived . '_SHORTNAME');
1967 $object = $dname . '-' . $object;
1969 require_conf_file ("$am_file.am", FOREIGN, 'compile')
1970 if $lang->name eq 'c';
1972 prog_error ("$lang->name flags defined without compiler")
1973 if ! defined $lang->compile;
1978 # If rewrite said it was ok, put the object into a
1980 if ($r == $LANG_SUBDIR && $directory ne '')
1982 $object = $directory . '/' . $object;
1985 # If doing dependency tracking, then we can't print
1986 # the rule. If we have a subdir object, we need to
1987 # generate an explicit rule. Actually, in any case
1988 # where the object is not in `.' we need a special
1989 # rule. The per-object rules in this case are
1990 # generated later, by handle_languages.
1991 if ($renamed || $directory ne '')
1993 my $obj_sans_ext = substr ($object, 0,
1994 - length ($this_obj_ext));
1995 my $val = ("$full $obj_sans_ext "
1996 # Only use $this_obj_ext in the derived
1997 # source case because in the other case we
1998 # *don't* want $(OBJEXT) to appear here.
1999 . ($derived_source ? $this_obj_ext : '.o'));
2001 # If we renamed the object then we want to use the
2002 # per-executable flag name. But if this is simply a
2003 # subdir build then we still want to use the AM_ flag
2007 $val = "$derived $val";
2008 $aggregate = $derived;
2015 # Each item on this list is a string consisting of
2016 # four space-separated values: the derived flag prefix
2017 # (eg, for `foo_CFLAGS', it is `foo'), the name of the
2018 # source file, the base name of the output file, and
2019 # the extension for the object file.
2020 push (@{$lang_specific_files{$lang->name}}, $val);
2023 elsif ($extension eq $nonansi_obj)
2025 # This is probably the result of a direct suffix rule.
2026 # In this case we just accept the rewrite.
2027 $object = "$base$extension";
2032 # No error message here. Used to have one, but it was
2034 # FIXME: we could potentially do more processing here,
2035 # perhaps treating the new extension as though it were a
2036 # new source extension (as above). This would require
2037 # more restructuring than is appropriate right now.
2041 if (defined $object_map{$object})
2043 if ($object_map{$object} ne $full)
2045 am_error ("object `$object' created by `$full' and `$object_map{$object}'");
2049 my $comp_val = (($object =~ /\.lo$/)
2050 ? $COMPILE_LIBTOOL : $COMPILE_ORDINARY);
2051 (my $comp_obj = $object) =~ s/\.lo$/.\$(OBJEXT)/;
2052 if (defined $object_compilation_map{$comp_obj}
2053 && $object_compilation_map{$comp_obj} != 0
2054 # Only see the error once.
2055 && ($object_compilation_map{$comp_obj}
2056 != ($COMPILE_LIBTOOL | $COMPILE_ORDINARY))
2057 && $object_compilation_map{$comp_obj} != $comp_val)
2059 am_error ("object `$object' created both with libtool and without");
2061 $object_compilation_map{$comp_obj} |= $comp_val;
2065 # Let the language do some special magic if required.
2066 $lang->target_hook ($aggregate, $object, $full);
2069 if ($derived_source)
2071 prog_error ("$lang->name has automatic dependency tracking")
2072 if $lang->autodep ne 'no';
2073 # Make sure this new source file is handled next. That will
2074 # make it appear to be at the right place in the list.
2075 unshift (@files, $object);
2076 # Distribute derived sources unless the source they are
2077 # derived from is not.
2078 &push_dist_common ($object)
2079 unless ($topparent =~ /^(:?nobase_)?nodist_/);
2083 $linkers_used{$linker} = 1;
2085 push (@result, $object);
2087 if (! defined $object_map{$object})
2090 $object_map{$object} = $full;
2092 # If file is in subdirectory, we need explicit
2094 if ($directory ne '' || $renamed)
2096 push (@dep_list, $full);
2099 # If resulting object is in subdir, we need to make
2100 # sure the subdir exists at build time.
2101 if ($object =~ /\//)
2103 # FIXME: check that $DIRECTORY is somewhere in the
2106 # For Java, the way we're handling it right now, a
2107 # `..' component doesn't make sense.
2108 if ($lang->name eq 'java' && $object =~ /(\/|^)\.\.\//)
2110 am_error ("`$full' contains `..' component but should not");
2113 # Make sure object is removed by `make mostlyclean'.
2114 $compile_clean_files{$object} = MOSTLY_CLEAN;
2116 push (@dep_list, require_build_directory ($directory));
2118 # If we're generating dependencies, we also want
2119 # to make sure that the appropriate subdir of the
2120 # .deps directory is created.
2122 require_build_directory ($directory . '/$(DEPDIR)'))
2123 if $use_dependencies;
2126 &pretty_print_rule ($object . ':', "\t", @dep_list)
2127 if scalar @dep_list > 0;
2130 # Transform .o or $o file into .P file (for automatic
2132 if ($lang && $lang->autodep ne 'no')
2134 my $depfile = $object;
2135 $depfile =~ s/\.([^.]*)$/.P$1/;
2136 $depfile =~ s/\$\(OBJEXT\)$/o/;
2137 $dep_files{dirname ($depfile) . '/$(DEPDIR)/'
2138 . basename ($depfile)} = 1;
2146 # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
2147 # $OBJ, $PARENT, $TOPPARENT)
2148 # ---------------------------------------------------------------------
2149 # Define an _OBJECTS variable for a _SOURCES variable (or subvariable)
2152 # $VAR is the name of the _SOURCES variable
2153 # $OBJVAR is the name of the _OBJECTS
2154 # $NODEFINE is a boolean: if true, $OBJVAR will not be defined (but
2155 # work done to determine the linker will be).
2156 # $ONE_FILE is the canonical (transformed) name of object to build
2157 # $OBJ is the object extension (ie either `.o' or `.lo').
2158 # $PARENT is the variable in which $VAR is used, or $VAR if not applicable.
2159 # $TOPPARENT is the _SOURCES variable being processed.
2161 # Result is a boolean, true if a linker is needed to deal with the objects.
2163 # %linkers_used, %vars_scanned, @substfroms and @substtos should be cleared
2165 # %linkers_used variable will be set to contain the linkers desired.
2166 # %vars_scanned will be used to check for recursive definitions.
2167 # @substfroms and @substtos will be used to keep a stack of variable
2168 # substitutions to be applied.
2170 sub define_objects_from_sources ($$$$$$$)
2172 my ($var, $objvar, $nodefine, $one_file, $obj, $parent, $topparent) = @_;
2174 if (defined $vars_scanned{$var})
2176 macro_error ($var, "variable `$var' recursively defined");
2179 $vars_scanned{$var} = 1;
2181 my $needlinker = "";
2182 foreach my $cond (variable_conditions ($var))
2185 foreach my $val (&variable_value_as_list ($var, $cond, $parent))
2187 # If $val is a variable (i.e. ${foo} or $(bar), not a filename),
2188 # handle the sub variable recursively.
2189 if ($val =~ /^\$\{([^}]*)\}$/ || $val =~ /^\$\(([^)]*)\)$/)
2193 # If the user uses a losing variable name, just ignore it.
2194 # This isn't ideal, but people have requested it.
2195 next if ($subvar =~ /\@.*\@/);
2197 # See if the variable is actually a substitution reference
2200 if ($subvar =~ /$SUBST_REF_PATTERN/o)
2204 $from = quotemeta $2;
2206 push @substfroms, $from;
2207 push @substtos, $to;
2209 my $subobjvar = subobjname ($subvar);
2210 push (@result, '$('. $subobjvar . ')');
2212 my $temp = define_objects_from_sources ($subvar, $subobjvar,
2213 $nodefine, $one_file,
2214 $obj, $var, $topparent);
2215 $needlinker ||= $temp;
2220 else # $var is a filename
2222 my $substnum=$#substfroms;
2223 while ($substnum >= 0)
2225 $val =~ s/$substfroms[$substnum]$/$substtos[$substnum]/
2226 if defined $substfroms[$substnum];
2231 &handle_single_transform_list ($var, $topparent, $one_file, $obj, $val);
2232 push (@result, @transformed);
2233 $needlinker = "true" if @transformed;
2237 # Define _OBJECTS conditionally.
2238 define_pretty_variable ($objvar, $cond, (@result))
2242 delete $vars_scanned{$var};
2248 # subobjname ($VARNAME)
2249 # ---------------------
2250 # Return a name for an object variable.
2253 # $VARNAME is the name of the variable the object variable is being
2256 # This function also looks at @substfroms and @substtos to determine any
2257 # substitutions to be performed on the object variable.
2259 # The name returned is unique for the combination of $varname and
2260 # substitutions to be performed.
2265 my $substnum=$#substfroms;
2266 while ($substnum >= 0)
2268 if (defined $substfroms[$substnum] &&
2269 ($substfroms[$substnum] || $substtos[$substnum]))
2271 $key .= ":" . $substfroms[$substnum] . "=" . $substtos[$substnum];
2276 my $num = $substnums{$key};
2279 $num = keys(%substnums) + 1;
2280 $substnums{$key} = $num;
2283 return "am__objects_$num";
2287 # Handle SOURCE->OBJECT transform for one program or library.
2289 # canonical (transformed) name of object to build
2290 # actual name of object to build
2291 # object extension (ie either `.o' or `$o'.
2292 # Return result is name of linker variable that must be used.
2293 # Empty return means just use `LINK'.
2294 sub handle_source_transform
2296 # one_file is canonical name. unxformed is given name. obj is
2298 my ($one_file, $unxformed, $obj) = @_;
2302 if (variable_defined ($one_file . "_OBJECTS"))
2304 macro_error ($one_file . '_OBJECTS',
2305 $one_file . '_OBJECTS', 'should not be defined');
2306 # No point in continuing.
2313 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2314 'dist_EXTRA_', 'nodist_EXTRA_')
2316 my $var = $prefix . $one_file . "_SOURCES";
2318 if !variable_defined ($var);
2320 # We are going to define _OBJECTS variables using the prefix.
2321 # Then we glom them all together. So we can't use the null
2322 # prefix here as we need it later.
2323 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2325 # Keep track of which prefixes we saw.
2326 $used_pfx{$xpfx} = 1
2327 unless $prefix =~ /EXTRA_/;
2329 push @sources, "\$($var)";
2330 push @dist_sources, "\$($var)"
2331 unless $prefix =~ /^nodist_/;
2336 my $temp = define_objects_from_sources ($var,
2337 $xpfx . $one_file . '_OBJECTS',
2338 $prefix =~ /EXTRA_/,
2339 $one_file, $obj, $var, $var);
2340 $needlinker ||= $temp;
2344 $linker ||= &resolve_linker (%linkers_used);
2347 my @keys = sort keys %used_pfx;
2348 if (scalar @keys == 0)
2350 &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
2351 push (@sources, $unxformed . '.c');
2352 push (@dist_sources, $unxformed . '.c');
2356 &handle_single_transform_list ($one_file . '_SOURCES',
2357 $one_file . '_SOURCES',
2360 $linker ||= &resolve_linker (%linkers_used);
2361 define_pretty_variable ($one_file . "_OBJECTS", '', @result)
2365 grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
2366 define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
2369 # If we want to use `LINK' we must make sure it is defined.
2379 # handle_lib_objects ($XNAME, $VAR)
2380 # ---------------------------------
2381 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
2382 # Also, generate _DEPENDENCIES variable if appropriate.
2384 # transformed name of object being built, or empty string if no object
2385 # name of _LDADD/_LIBADD-type variable to examine
2386 # Returns 1 if LIBOBJS seen, 0 otherwise.
2387 sub handle_lib_objects
2389 my ($xname, $var) = @_;
2391 prog_error ("handle_lib_objects: $var undefined")
2392 if ! variable_defined ($var);
2395 foreach my $cond (variable_conditions_recursive ($var))
2397 if (&handle_lib_objects_cond ($xname, $var, $cond))
2405 # Subroutine of handle_lib_objects: handle a particular condition.
2406 sub handle_lib_objects_cond
2408 my ($xname, $var, $cond) = @_;
2410 # We recognize certain things that are commonly put in LIBADD or
2414 my $seen_libobjs = 0;
2417 foreach my $lsearch (&variable_value_as_list_recursive ($var, $cond))
2419 # Skip -lfoo and -Ldir; these are explicitly allowed.
2420 next if $lsearch =~ /^-[lL]/;
2421 if (! $flagvar && $lsearch =~ /^-/)
2423 if ($var =~ /^(.*)LDADD$/)
2425 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
2426 next if $lsearch =~ /^-dl(pre)?open$/;
2427 my $prefix = $1 || 'AM_';
2429 "linker flags such as `$lsearch' belong in `${prefix}LDFLAGS");
2433 $var =~ /^(.*)LIBADD$/;
2434 # Only get this error once.
2437 "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2441 # Assume we have a file of some sort, and push it onto the
2442 # dependency list. Autoconf substitutions are not pushed;
2443 # rarely is a new dependency substituted into (eg) foo_LDADD
2444 # -- but "bad things (eg -lX11) are routinely substituted.
2445 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2446 # and handled specially below.
2447 push (@dep_list, $lsearch)
2448 unless $lsearch =~ /^\@.*\@$/;
2450 # Automatically handle @LIBOBJS@ and @ALLOCA@. Basically this
2451 # means adding entries to dep_files.
2452 if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
2454 my $lt = $1 ? $1 : '';
2455 my $myobjext = ($1 ? 'l' : '') . 'o';
2457 push (@dep_list, $lsearch);
2459 if (! keys %libsources
2460 && ! variable_defined ($lt . 'LIBOBJS'))
2463 "\@$lt" . "LIBOBJS\@ seen but never set in `$configure_ac'");
2466 foreach my $iter (keys %libsources)
2468 if ($iter =~ /\.[cly]$/)
2470 &saw_extension ($&);
2471 &saw_extension ('.c');
2474 if ($iter =~ /\.h$/)
2476 require_file_with_macro ($var, FOREIGN, $iter);
2478 elsif ($iter ne 'alloca.c')
2480 my $rewrite = $iter;
2481 $rewrite =~ s/\.c$/.P$myobjext/;
2482 $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
2483 $rewrite = "^" . quotemeta ($iter) . "\$";
2484 # Only require the file if it is not a built source.
2485 if (! variable_defined ('BUILT_SOURCES')
2486 || ! grep (/$rewrite/,
2487 &variable_value_as_list_recursive (
2488 'BUILT_SOURCES', 'all')))
2490 require_file_with_macro ($var, FOREIGN, $iter);
2495 elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
2497 my $lt = $1 ? $1 : '';
2498 my $myobjext = ($1 ? 'l' : '') . 'o';
2500 push (@dep_list, $lsearch);
2502 "\@$lt" . "ALLOCA\@ seen but `AC_FUNC_ALLOCA' not in `$configure_ac'")
2503 if ! defined $libsources{'alloca.c'};
2504 $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
2505 require_file_with_macro ($var, FOREIGN, 'alloca.c');
2506 &saw_extension ('c');
2512 if (conditional_ambiguous_p ($xname . '_DEPENDENCIES', $cond) ne '')
2514 # Note that we've examined this.
2515 &examine_variable ($xname . '_DEPENDENCIES');
2519 define_pretty_variable ($xname . '_DEPENDENCIES', $cond,
2524 return $seen_libobjs;
2527 # Canonicalize the input parameter
2531 $string =~ tr/A-Za-z0-9_\@/_/c;
2535 # Canonicalize a name, and check to make sure the non-canonical name
2536 # is never used. Returns canonical name. Arguments are name and a
2537 # list of suffixes to check for.
2538 sub check_canonical_spelling
2540 my ($name, @suffixes) = @_;
2542 my $xname = &canonicalize ($name);
2543 if ($xname ne $name)
2545 foreach my $xt (@suffixes)
2547 macro_error ("$name$xt",
2548 "invalid variable `$name$xt'; should be `$xname$xt'")
2549 if variable_defined ("$name$xt");
2559 # Set up the compile suite.
2560 sub handle_compile ()
2563 unless $get_object_extension_was_run;
2566 my $default_includes = '';
2567 if (! defined $options{'nostdinc'})
2569 $default_includes = ' -I. -I$(srcdir)';
2571 if (variable_defined ('CONFIG_HEADER'))
2573 foreach my $hdr (split (' ', &variable_value ('CONFIG_HEADER')))
2575 $default_includes .= ' -I' . dirname ($hdr);
2580 my (@mostly_rms, @dist_rms);
2581 foreach my $item (sort keys %compile_clean_files)
2583 if ($compile_clean_files{$item} == MOSTLY_CLEAN)
2585 push (@mostly_rms, "\t-rm -f $item");
2587 elsif ($compile_clean_files{$item} == DIST_CLEAN)
2589 push (@dist_rms, "\t-rm -f $item");
2593 prog_error ("invalid entry in \%compile_clean_files");
2597 my ($coms, $vars, $rules) =
2598 &file_contents_internal (1, "$libdir/am/compile.am",
2599 ('DEFAULT_INCLUDES' => $default_includes,
2600 'MOSTLYRMS' => join ("\n", @mostly_rms),
2601 'DISTRMS' => join ("\n", @dist_rms)));
2602 $output_vars .= $vars;
2603 $output_rules .= "$coms$rules";
2605 # Check for automatic de-ANSI-fication.
2606 if (defined $options{'ansi2knr'})
2608 if (! $am_c_prototypes)
2610 macro_error ('AUTOMAKE_OPTIONS',
2611 "option `ansi2knr' in use but `AM_C_PROTOTYPES' not in `$configure_ac'");
2612 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
2613 # Only give this error once.
2614 $am_c_prototypes = 1;
2617 # topdir is where ansi2knr should be.
2618 if ($options{'ansi2knr'} eq 'ansi2knr')
2620 # Only require ansi2knr files if they should appear in
2622 require_file_with_macro ('AUTOMAKE_OPTIONS', FOREIGN,
2623 'ansi2knr.c', 'ansi2knr.1');
2625 # ansi2knr needs to be built before subdirs, so unshift it.
2626 unshift (@all, '$(ANSI2KNR)');
2629 my $ansi2knr_dir = '';
2630 $ansi2knr_dir = dirname ($options{'ansi2knr'})
2631 if $options{'ansi2knr'} ne 'ansi2knr';
2633 $output_rules .= &file_contents ('ansi2knr',
2634 ('ANSI2KNR-DIR' => $ansi2knr_dir));
2641 # Handle libtool rules.
2644 return unless $seen_libtool;
2646 # Libtool requires some files, but only at top level.
2647 require_conf_file ($seen_libtool, FOREIGN, @libtool_files)
2648 if $relative_dir eq '.';
2650 # Output the libtool compilation rules.
2651 $output_rules .= &file_contents ('libtool');
2654 # handle_programs ()
2655 # ------------------
2656 # Handle C programs.
2659 my @proglist = &am_install_var ('progs', 'PROGRAMS',
2660 'bin', 'sbin', 'libexec', 'pkglib',
2662 return if ! @proglist;
2664 my $seen_libobjs = 0;
2665 foreach my $one_file (@proglist)
2667 my $obj = &get_object_extension ($one_file);
2669 # Canonicalize names and check for misspellings.
2670 my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2671 '_SOURCES', '_OBJECTS',
2674 my $linker = &handle_source_transform ($xname, $one_file, $obj);
2677 if (variable_defined ($xname . "_LDADD"))
2679 if (&handle_lib_objects ($xname, $xname . '_LDADD'))
2687 # User didn't define prog_LDADD override. So do it.
2688 &define_variable ($xname . '_LDADD', '$(LDADD)');
2690 # This does a bit too much work. But we need it to
2691 # generate _DEPENDENCIES when appropriate.
2692 if (variable_defined ('LDADD'))
2694 if (&handle_lib_objects ($xname, 'LDADD'))
2699 elsif (! variable_defined ($xname . '_DEPENDENCIES'))
2701 &define_variable ($xname . '_DEPENDENCIES', '');
2706 if (variable_defined ($xname . '_LIBADD'))
2708 macro_error ($xname . '_LIBADD',
2709 "use `" . $xname . "_LDADD', not `"
2710 . $xname . "_LIBADD'");
2713 if (! variable_defined ($xname . '_LDFLAGS'))
2715 # Define the prog_LDFLAGS variable.
2716 &define_variable ($xname . '_LDFLAGS', '');
2719 # Determine program to use for link.
2721 if (variable_defined ($xname . '_LINK'))
2723 $xlink = $xname . '_LINK';
2727 $xlink = $linker ? $linker : 'LINK';
2730 # If the resulting program lies into a subdirectory,
2731 # make sure this directory will exist.
2732 my $dirstamp = require_build_directory_maybe ($one_file);
2734 # Don't add $(EXEEXT) if user already did.
2735 my $extension = ($one_file !~ /\$\(EXEEXT\)$/
2739 $output_rules .= &file_contents ('program',
2740 ('PROGRAM' => $one_file,
2741 'XPROGRAM' => $xname,
2743 'DIRSTAMP' => $dirstamp,
2744 'EXEEXT' => $extension));
2747 if (variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD'))
2754 foreach my $one_file (@proglist)
2756 my $xname = &canonicalize ($one_file);
2758 if (variable_defined ($xname . '_LDADD'))
2760 &check_libobjs_sources ($xname, $xname . '_LDADD');
2762 elsif (variable_defined ('LDADD'))
2764 &check_libobjs_sources ($xname, 'LDADD');
2771 # handle_libraries ()
2772 # -------------------
2774 sub handle_libraries
2776 my @liblist = &am_install_var ('libs', 'LIBRARIES',
2777 'lib', 'pkglib', 'noinst', 'check');
2778 return if ! @liblist;
2780 my @prefix = am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2782 if (! defined $configure_vars{'RANLIB'}
2785 macro_error ($prefix[0] . '_LIBRARIES',
2786 "library used but `RANLIB' not defined in `$configure_ac'");
2787 # Only get this error once. If this is ever printed, we have
2789 $configure_vars{'RANLIB'} = 'BUG';
2792 my $seen_libobjs = 0;
2793 foreach my $onelib (@liblist)
2795 # Check that the library fits the standard naming convention.
2796 if (basename ($onelib) !~ /^lib.*\.a/)
2798 # FIXME should put line number here. That means mapping
2799 # from library name back to variable name.
2800 &am_error ("`$onelib' is not a standard library name");
2803 my $obj = &get_object_extension ($onelib);
2805 # Canonicalize names and check for misspellings.
2806 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2807 '_OBJECTS', '_DEPENDENCIES',
2810 if (! variable_defined ($xlib . '_AR'))
2812 &define_variable ($xlib . '_AR', '$(AR) cru');
2815 if (variable_defined ($xlib . '_LIBADD'))
2817 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2824 # Generate support for conditional object inclusion in
2826 &define_variable ($xlib . "_LIBADD", '');
2829 if (variable_defined ($xlib . '_LDADD'))
2831 macro_error ($xlib . '_LDADD',
2832 "use `" . $xlib . "_LIBADD', not `"
2833 . $xlib . "_LDADD'");
2836 # Make sure we at look at this.
2837 &examine_variable ($xlib . '_DEPENDENCIES');
2839 &handle_source_transform ($xlib, $onelib, $obj);
2841 # If the resulting library lies into a subdirectory,
2842 # make sure this directory will exist.
2843 my $dirstamp = require_build_directory_maybe ($onelib);
2845 $output_rules .= &file_contents ('library',
2846 ('LIBRARY' => $onelib,
2847 'XLIBRARY' => $xlib,
2848 'DIRSTAMP' => $dirstamp));
2853 foreach my $onelib (@liblist)
2855 my $xlib = &canonicalize ($onelib);
2856 if (variable_defined ($xlib . '_LIBADD'))
2858 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2865 # handle_ltlibraries ()
2866 # ---------------------
2867 # Handle shared libraries.
2868 sub handle_ltlibraries
2870 my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2871 'noinst', 'lib', 'pkglib', 'check');
2872 return if ! @liblist;
2875 my @prefix = am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2878 foreach my $key (@prefix)
2882 macro_error ($key . '_LTLIBRARIES',
2883 "library used but `LIBTOOL' not defined in `$configure_ac'");
2884 # Only get this error once. If this is ever printed,
2886 $configure_vars{'LIBTOOL'} = 'BUG';
2887 $seen_libtool = $var_location{$key . '_LTLIBRARIES'};
2890 # Get the installation directory of each library.
2891 (my $dir = $key) =~ s/^nobase_//;
2892 for (variable_value_as_list_recursive ($key . '_LTLIBRARIES', 'all'))
2896 am_error ("`$_' is already going to be installed in `$instdirs{$_}'");
2900 $instdirs{$_} = $dir;
2905 my $seen_libobjs = 0;
2906 foreach my $onelib (@liblist)
2908 my $obj = &get_object_extension ($onelib);
2910 # Canonicalize names and check for misspellings.
2911 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2912 '_SOURCES', '_OBJECTS',
2915 if (! variable_defined ($xlib . '_LDFLAGS'))
2917 # Define the lib_LDFLAGS variable.
2918 &define_variable ($xlib . '_LDFLAGS', '');
2921 # Check that the library fits the standard naming convention.
2922 my $libname_rx = "^lib.*\.la";
2923 if ((variable_defined ($xlib . '_LDFLAGS')
2924 && grep (/-module/, &variable_value_as_list_recursive (
2925 $xlib . '_LDFLAGS', 'all')))
2926 || (variable_defined ('LDFLAGS')
2927 && grep (/-module/, &variable_value_as_list_recursive (
2928 'LDFLAGS', 'all'))))
2930 # Relax name checking for libtool modules.
2931 $libname_rx = "\.la";
2933 if (basename ($onelib) !~ /$libname_rx$/)
2935 # FIXME this should only be a warning for foreign packages
2936 # FIXME should put line number here. That means mapping
2937 # from library name back to variable name.
2938 &am_error ("`$onelib' is not a standard libtool library name");
2941 if (variable_defined ($xlib . '_LIBADD'))
2943 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2950 # Generate support for conditional object inclusion in
2952 &define_variable ($xlib . "_LIBADD", '');
2955 if (variable_defined ($xlib . '_LDADD'))
2957 macro_error ($xlib . '_LDADD',
2958 "use `" . $xlib . "_LIBADD', not `"
2959 . $xlib . "_LDADD'");
2962 # Make sure we at look at this.
2963 &examine_variable ($xlib . '_DEPENDENCIES');
2965 my $linker = &handle_source_transform ($xlib, $onelib, $obj);
2967 # Determine program to use for link.
2969 if (variable_defined ($xlib . '_LINK'))
2971 $xlink = $xlib . '_LINK';
2975 $xlink = $linker ? $linker : 'LINK';
2979 if ($instdirs{$onelib} eq 'EXTRA'
2980 || $instdirs{$onelib} eq 'noinst'
2981 || $instdirs{$onelib} eq 'check')
2983 # It's an EXTRA_ library, so we can't specify -rpath,
2984 # because we don't know where the library will end up.
2985 # The user probably knows, but generally speaking automake
2986 # doesn't -- and in fact configure could decide
2987 # dynamically between two different locations.
2992 $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
2995 # If the resulting library lies into a subdirectory,
2996 # make sure this directory will exist.
2997 my $dirstamp = require_build_directory_maybe ($onelib);
2999 $output_rules .= &file_contents ('ltlibrary',
3000 ('LTLIBRARY' => $onelib,
3001 'XLTLIBRARY' => $xlib,
3004 'DIRSTAMP' => $dirstamp));
3009 foreach my $onelib (@liblist)
3011 my $xlib = &canonicalize ($onelib);
3012 if (variable_defined ($xlib . '_LIBADD'))
3014 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
3020 # See if any _SOURCES variable were misspelled. Also, make sure that
3021 # EXTRA_ variables don't contain configure substitutions.
3024 foreach my $varname (keys %var_value)
3026 foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
3029 macro_error ($varname,
3030 "invalid unused variable name: `$varname'")
3031 # Note that a configure variable is always legitimate.
3032 # It is natural to name such variables after the
3033 # primary, so we explicitly allow it.
3034 if $varname =~ /$primary$/ && ! $content_seen{$varname}
3035 && ! exists $configure_vars{$varname};
3044 # NOTE we no longer automatically clean SCRIPTS, because it is
3045 # useful to sometimes distribute scripts verbatim. This happens
3046 # eg in Automake itself.
3047 &am_install_var ('-candist', 'scripts', 'SCRIPTS',
3048 'bin', 'sbin', 'libexec', 'pkgdata',
3053 # ($OUTFILE, $VFILE, @CLEAN_FILES)
3054 # &scan_texinfo_file ($FILENAME)
3055 # ------------------------------
3056 # $OUTFILE is the name of the info file produced by $FILENAME.
3057 # $VFILE is the name of the version.texi file used (empty if none).
3058 # @CLEAN_FILES is the list of by products (indexes etc.)
3059 sub scan_texinfo_file
3061 my ($filename) = @_;
3063 # These are always created, no matter whether indexes are used or not.
3064 my @clean_suffixes = qw(aux dvi log ps toc
3065 cp fn ky vr tp pg); # grep new.*index texinfo.tex
3067 # There are predefined indexes which don't follow the regular rules.
3068 my %predefined_index = qw(c cps
3075 # There are commands which include a hidden index command.
3076 my %hidden_index = (tp => 'tps');
3077 $hidden_index{$_} = 'fns' foreach qw(fn un typefn typefun max spec
3078 op typeop method typemethod);
3079 $hidden_index{$_} = 'vrs' foreach qw(vr var typevr typevar opt cv
3082 # Indexes stored into another one. In this case, the *.??s file
3084 my @syncodeindexes = ();
3086 my $texi = new Automake::XFile "< $filename";
3087 verbose "reading $filename";
3089 my ($outfile, $vfile);
3090 while ($_ = $texi->getline)
3092 if (/^\@setfilename +(\S+)/)
3095 if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
3097 file_error ("$filename:$.",
3098 "output `$outfile' has unrecognized extension");
3102 # A "version.texi" file is actually any file whose name
3103 # matches "vers*.texi".
3104 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
3109 # Try to find what are the indexes which are used.
3111 # Creating a new category of index.
3112 elsif (/^\@def(code)?index (\w+)/)
3114 push @clean_suffixes, $2;
3117 # Storing in a predefined index.
3118 elsif (/^\@([cfkvtp])index /)
3120 push @clean_suffixes, $predefined_index{$1};
3122 elsif (/^\@def(\w+) /)
3124 push @clean_suffixes, $hidden_index{$1}
3125 if defined $hidden_index{$1};
3128 # Merging an index into an another.
3129 elsif (/^\@syn(code)?index (\w+) (\w+)/)
3131 push @syncodeindexes, "$2s";
3132 push @clean_suffixes, "$3s";
3139 &am_error ("`$filename' missing \@setfilename");
3143 my $infobase = basename ($filename);
3144 $infobase =~ s/\.te?xi(nfo)?$//;
3145 my %clean_files = map { +"$infobase.$_" => 1 } @clean_suffixes;
3146 grep { delete $clean_files{"$infobase.$_"} } @syncodeindexes;
3147 return ($outfile, $vfile, (sort keys %clean_files));
3151 # ($DO-SOMETHING, $TEXICLEANS)
3152 # handle_texinfo_helper ()
3153 # ------------------------
3154 # Handle all Texinfo source; helper for handle_texinfo
3155 sub handle_texinfo_helper
3157 macro_error ('TEXINFOS',
3158 "`TEXINFOS' is an anachronism; use `info_TEXINFOS'")
3159 if variable_defined ('TEXINFOS');
3160 return (0, '') if (! variable_defined ('info_TEXINFOS')
3161 && ! variable_defined ('html_TEXINFOS'));
3163 if (variable_defined ('html_TEXINFOS'))
3165 macro_error ('html_TEXINFOS',
3166 "HTML generation not yet supported");
3170 my @texis = &variable_value_as_list_recursive ('info_TEXINFOS', 'all');
3172 my (@info_deps_list, @dvis_list, @texi_deps);
3179 foreach my $info_cursor (@texis)
3181 my $infobase = $info_cursor;
3182 $infobase =~ s/\.(txi|texinfo|texi)$//;
3184 if ($infobase eq $info_cursor)
3186 # FIXME: report line number.
3187 &am_error ("texinfo file `$info_cursor' has unrecognized extension");
3190 $texi_suffixes{$1} = 1;
3192 # If 'version.texi' is referenced by input file, then include
3193 # automatic versioning capability.
3194 my ($out_file, $vtexi, @clean_files) =
3195 &scan_texinfo_file ("$relative_dir/$info_cursor")
3197 push (@texi_cleans, @clean_files);
3201 &am_error ("`$vtexi', included in `$info_cursor', also included in `$versions{$vtexi}'")
3202 if (defined $versions{$vtexi});
3203 $versions{$vtexi} = $info_cursor;
3205 # We number the stamp-vti files. This is doable since the
3206 # actual names don't matter much. We only number starting
3207 # with the second one, so that the common case looks nice.
3208 my $vti = ($done ? $done : 'vti');
3211 # This is ugly, but it is our historical practice.
3212 if ($config_aux_dir_set_in_configure_in)
3214 require_conf_file_with_macro ('info_TEXINFOS', FOREIGN,
3219 require_file_with_macro ('info_TEXINFOS', FOREIGN,
3224 if ($config_aux_dir_set_in_configure_in)
3226 $conf_dir = $config_aux_dir;
3227 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
3231 $conf_dir = '$(srcdir)/';
3233 $output_rules .= &file_contents ('texi-vers',
3234 ('TEXI' => $info_cursor,
3237 'MDDIR' => $conf_dir));
3240 # If user specified file_TEXINFOS, then use that as explicit
3243 push (@texi_deps, $info_cursor);
3244 # Prefix with $(srcdir) because some version of make won't
3245 # work if the target has it and the dependency doesn't.
3246 push (@texi_deps, '$(srcdir)/' . $vtexi) if $vtexi;
3248 my $canonical = &canonicalize ($infobase);
3249 if (variable_defined ($canonical . "_TEXINFOS"))
3251 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
3252 &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
3255 $output_rules .= ("\n" . $out_file . ": "
3257 . "\n" . $infobase . ".dvi: "
3261 push (@info_deps_list, $out_file);
3262 push (@dvis_list, $infobase . '.dvi');
3265 # Handle location of texinfo.tex.
3266 my $need_texi_file = 0;
3270 $texinfodir = '$(top_srcdir)/../texinfo';
3271 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3273 elsif ($config_aux_dir_set_in_configure_in)
3275 $texinfodir = $config_aux_dir;
3276 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3277 $need_texi_file = 2; # so that we require_conf_file later
3279 elsif (variable_defined ('TEXINFO_TEX'))
3281 # The user defined TEXINFO_TEX so assume he knows what he is
3283 $texinfodir = ('$(srcdir)/'
3284 . dirname (&variable_value ('TEXINFO_TEX')));
3288 $texinfodir = '$(srcdir)';
3289 $need_texi_file = 1;
3292 foreach my $txsfx (sort keys %texi_suffixes)
3294 $output_rules .= &file_contents ('texibuild',
3295 ('TEXINFODIR' => $texinfodir,
3296 'SUFFIX' => $txsfx));
3300 my $texiclean = &pretty_print_internal ("", "\t ", @texi_cleans);
3302 push (@dist_targets, 'dist-info');
3304 if (! defined $options{'no-installinfo'})
3306 # Make sure documentation is made and installed first. Use
3307 # $(INFO_DEPS), not 'info', because otherwise recursive makes
3308 # get run twice during "make all".
3309 unshift (@all, '$(INFO_DEPS)');
3312 &define_variable ("INFO_DEPS", "@info_deps_list");
3313 &define_variable ("DVIS", "@dvis_list");
3314 # This next isn't strictly needed now -- the places that look here
3315 # could easily be changed to look in info_TEXINFOS. But this is
3316 # probably better, in case noinst_TEXINFOS is ever supported.
3317 &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
3319 # Do some error checking. Note that this file is not required
3320 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3322 if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
3324 if ($need_texi_file > 1)
3326 require_conf_file_with_macro ('info_TEXINFOS', FOREIGN,
3331 require_file_with_macro ('info_TEXINFOS', FOREIGN, 'texinfo.tex');
3335 return (1, $texiclean);
3340 # Handle all Texinfo source.
3343 my ($do_something, $texiclean) = handle_texinfo_helper ();
3344 $output_rules .= &file_contents ('texinfos',
3345 ('TEXICLEAN' => $texiclean,
3346 'LOCAL-TEXIS' => $do_something));
3349 # Handle any man pages.
3350 sub handle_man_pages
3352 macro_error ('MANS', "`MANS' is an anachronism; use `man_MANS'")
3353 if variable_defined ('MANS');
3355 # Find all the sections in use. We do this by first looking for
3356 # "standard" sections, and then looking for any additional
3357 # sections used in man_MANS.
3358 my (%sections, %vlist);
3359 # We handle nodist_ for uniformity. man pages aren't distributed
3360 # by default so it isn't actually very important.
3361 foreach my $pfx ('', 'dist_', 'nodist_')
3363 # Add more sections as needed.
3364 foreach my $section ('0'..'9', 'n', 'l')
3366 if (variable_defined ($pfx . 'man' . $section . '_MANS'))
3368 $sections{$section} = 1;
3369 $vlist{'$(' . $pfx . 'man' . $section . '_MANS)'} = 1;
3371 &push_dist_common ('$(' . $pfx . 'man' . $section . '_MANS)')
3376 if (variable_defined ($pfx . 'man_MANS'))
3378 $vlist{'$(' . $pfx . 'man_MANS)'} = 1;
3379 foreach (&variable_value_as_list_recursive ($pfx . 'man_MANS', 'all'))
3381 # A page like `foo.1c' goes into man1dir.
3382 if (/\.([0-9a-z])([a-z]*)$/)
3388 &push_dist_common ('$(' . $pfx . 'man_MANS)')
3393 return unless %sections;
3395 # Now for each section, generate an install and unintall rule.
3396 # Sort sections so output is deterministic.
3397 foreach my $section (sort keys %sections)
3399 $output_rules .= &file_contents ('mans', ('SECTION' => $section));
3402 my @mans = sort keys %vlist;
3403 $output_vars .= file_contents ('mans-vars',
3404 ('MANS' => "@mans"));
3406 if (! defined $options{'no-installman'})
3408 push (@all, '$(MANS)');
3412 # Handle DATA variables.
3415 &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3416 'data', 'sysconf', 'sharedstate', 'localstate',
3417 'pkgdata', 'noinst', 'check');
3424 if (variable_defined ('SUBDIRS'))
3426 $output_rules .= ("tags-recursive:\n"
3427 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3428 # Never fail here if a subdir fails; it
3430 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3431 . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3433 push (@tag_deps, 'tags-recursive');
3434 &depend ('.PHONY', 'tags-recursive');
3437 if (&saw_sources_p (1)
3438 || variable_defined ('ETAGS_ARGS')
3442 foreach my $spec (@config_headers)
3444 my ($out, @ins) = split_config_file_spec ($spec);
3445 foreach my $in (@ins)
3447 # If the config header source is in this directory,
3449 push @config, basename ($in)
3450 if $relative_dir eq dirname ($in);
3453 $output_rules .= &file_contents ('tags',
3454 ('CONFIG' => "@config",
3455 'DIRS' => "@tag_deps"));
3456 &examine_variable ('TAGS_DEPENDENCIES');
3458 elsif (variable_defined ('TAGS_DEPENDENCIES'))
3460 macro_error ('TAGS_DEPENDENCIES',
3461 "doesn't make sense to define `TAGS_DEPENDENCIES' without sources or `ETAGS_ARGS'");
3465 # Every Makefile must define some sort of TAGS rule.
3466 # Otherwise, it would be possible for a top-level "make TAGS"
3467 # to fail because some subdirectory failed.
3468 $output_rules .= "tags: TAGS\nTAGS:\n\n";
3472 # Handle multilib support.
3475 if ($seen_multilib && $relative_dir eq '.')
3477 $output_rules .= &file_contents ('multilib');
3483 # &for_dist_common ($A, $B)
3484 # -------------------------
3485 # Subroutine for &handle_dist: sort files to dist.
3487 # We put README first because it then becomes easier to make a
3488 # Usenet-compliant shar file (in these, README must be first).
3490 # FIXME: do more ordering of files here.
3503 # handle_dist ($MAKEFILE)
3504 # -----------------------
3505 # Handle 'dist' target.
3508 my ($makefile) = @_;
3510 # `make dist' isn't used in a Cygnus-style tree.
3511 # Omit the rules so that people don't try to use them.
3512 return if $cygnus_mode;
3514 # Look for common files that should be included in distribution.
3515 # If the aux dir is set, and it does not have a Makefile.am, then
3516 # we check for these files there as well.
3519 if ($relative_dir eq '.'
3520 && $config_aux_dir_set_in_configure_in)
3522 ($auxdir = $config_aux_dir) =~ s,^\$\(top_srcdir\)/,,;
3523 if (! &is_make_dir ($auxdir))
3528 foreach my $cfile (@common_files)
3530 if (-f ($relative_dir . "/" . $cfile)
3531 # The file might be absent, but if it can be built it's ok.
3532 || exists $targets{$cfile})
3534 &push_dist_common ($cfile);
3537 # Don't use `elsif' here because a file might meaningfully
3538 # appear in both directories.
3539 if ($check_aux && -f ($auxdir . '/' . $cfile))
3541 &push_dist_common ($auxdir . '/' . $cfile);
3545 # We might copy elements from $configure_dist_common to
3546 # %dist_common if we think we need to. If the file appears in our
3547 # directory, we would have discovered it already, so we don't
3548 # check that. But if the file is in a subdir without a Makefile,
3549 # we want to distribute it here if we are doing `.'. Ugly!
3550 if ($relative_dir eq '.')
3552 foreach my $file (split (' ' , $configure_dist_common))
3554 push_dist_common ($file)
3555 unless is_make_dir (dirname ($file));
3561 # Files to distributed. Don't use &variable_value_as_list_recursive
3562 # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3563 check_variable_defined_unconditionally ('DIST_COMMON');
3564 my @dist_common = split (' ', variable_value ('DIST_COMMON', 'TRUE'));
3565 @dist_common = uniq (sort for_dist_common (@dist_common));
3566 pretty_print ('DIST_COMMON = ', "\t", @dist_common);
3568 # Now that we've processed DIST_COMMON, disallow further attempts
3570 $handle_dist_run = 1;
3572 # Scan EXTRA_DIST to see if we need to distribute anything from a
3573 # subdir. If so, add it to the list. I didn't want to do this
3574 # originally, but there were so many requests that I finally
3576 if (variable_defined ('EXTRA_DIST'))
3578 # FIXME: This should be fixed to work with conditionals. That
3579 # will require only making the entries in %dist_dirs under the
3580 # appropriate condition. This is meaningful if the nature of
3581 # the distribution should depend upon the configure options
3583 foreach (&variable_value_as_list_recursive ('EXTRA_DIST', ''))
3586 next unless s,/+[^/]+$,,;
3592 # We have to check DIST_COMMON for extra directories in case the
3593 # user put a source used in AC_OUTPUT into a subdir.
3594 foreach (&variable_value_as_list_recursive ('DIST_COMMON', 'all'))
3597 next unless s,/+[^/]+$,,;
3602 # Rule to check whether a distribution is viable.
3603 my %transform = ('DISTCHECK-HOOK' => &target_defined ('distcheck-hook'),
3604 'GETTEXT' => $seen_gettext);
3606 # Prepend $(distdir) to each directory given.
3607 my %rewritten = map { '$(distdir)/' . "$_" => 1 } keys %dist_dirs;
3608 $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);
3610 # If we have SUBDIRS, create all dist subdirectories and do
3612 if (variable_defined ('SUBDIRS'))
3614 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3615 # to all possible directories, and use it. If DIST_SUBDIRS is
3616 # defined, just use it.
3617 my $dist_subdir_name;
3618 # Note that we check DIST_SUBDIRS first on purpose. At least
3619 # one project uses so many conditional subdirectories that
3620 # calling variable_conditionally_defined on SUBDIRS will cause
3621 # automake to grow to 150Mb. Sigh.
3622 if (variable_defined ('DIST_SUBDIRS')
3623 || variable_conditionally_defined ('SUBDIRS'))
3625 $dist_subdir_name = 'DIST_SUBDIRS';
3626 if (! variable_defined ('DIST_SUBDIRS'))
3628 define_pretty_variable
3629 ('DIST_SUBDIRS', '',
3630 uniq (&variable_value_as_list_recursive ('SUBDIRS', 'all')));
3635 $dist_subdir_name = 'SUBDIRS';
3636 # We always define this because that is what `distclean'
3638 define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
3641 $transform{'DIST_SUBDIR_NAME'} = $dist_subdir_name;
3644 # If the target `dist-hook' exists, make sure it is run. This
3645 # allows users to do random weird things to the distribution
3646 # before it is packaged up.
3647 push (@dist_targets, 'dist-hook')
3648 if &target_defined ('dist-hook');
3649 $transform{'DIST-TARGETS'} = join(' ', @dist_targets);
3651 # Defining $(DISTDIR).
3652 $transform{'DISTDIR'} = !variable_defined('distdir');
3653 $transform{'TOP_DISTDIR'} = backname ($relative_dir);
3655 $output_rules .= &file_contents ('distdir', %transform);
3659 # Handle subdirectories.
3663 unless variable_defined ('SUBDIRS');
3665 # Make sure each directory mentioned in SUBDIRS actually exists.
3666 foreach my $dir (&variable_value_as_list_recursive ('SUBDIRS', 'all'))
3668 # Skip directories substituted by configure.
3669 next if $dir =~ /^\@.*\@$/;
3671 if (! -d $am_relative_dir . '/' . $dir)
3673 macro_error ('SUBDIRS',
3674 "required directory $am_relative_dir/$dir does not exist");
3678 macro_error ('SUBDIRS', "directory should not contain `/'")
3682 $output_rules .= &file_contents ('subdirs');
3683 variable_pretty_output ('RECURSIVE_TARGETS', 'TRUE');
3687 # ($REGEN, @DEPENDENCIES)
3690 # If aclocal.m4 creation is automated, return the list of its dependencies.
3693 my $regen_aclocal = 0;
3696 unless $relative_dir eq '.';
3698 &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3699 &examine_variable ('CONFIGURE_DEPENDENCIES');
3701 if (-f 'aclocal.m4')
3703 &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3704 &push_dist_common ('aclocal.m4');
3706 my $aclocal = new Automake::XFile "< aclocal.m4";
3707 my $line = $aclocal->getline;
3708 $regen_aclocal = $line =~ 'generated automatically by aclocal';
3713 if (-f 'acinclude.m4')
3716 push @ac_deps, 'acinclude.m4';
3719 if (variable_defined ('ACLOCAL_M4_SOURCES'))
3721 push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3723 elsif (variable_defined ('ACLOCAL_AMFLAGS'))
3725 # Scan all -I directories for m4 files. These are our
3727 my $examine_next = 0;
3728 foreach my $amdir (&variable_value_as_list_recursive ('ACLOCAL_AMFLAGS', ''))
3733 if ($amdir !~ /^\// && -d $amdir)
3735 foreach my $ac_dep (&my_glob ($amdir . '/*.m4'))
3737 $ac_dep =~ s/^\.\/+//;
3738 push (@ac_deps, $ac_dep)
3739 unless $ac_dep eq "aclocal.m4"
3740 || $ac_dep eq "acinclude.m4";
3744 elsif ($amdir eq '-I')
3751 # Note that it might be possible that aclocal.m4 doesn't exist but
3752 # should be auto-generated. This case probably isn't very
3755 return ($regen_aclocal, @ac_deps);
3760 # &rewrite_inputs_into_dependencies ($ADD_SRCDIR, @INPUTS)
3761 # --------------------------------------------------------
3762 # Rewrite a list of input files into a form suitable to put on a
3763 # dependency list. The idea is that if an input file has a directory
3764 # part the same as the current directory, then the directory part is
3765 # simply removed. But if the directory part is different, then
3766 # $(top_srcdir) is prepended. Among other things, this is used to
3767 # generate the dependency list for the output files generated by
3768 # AC_OUTPUT. Consider what the dependencies should look like in this
3770 # AC_OUTPUT(src/out:src/in1:lib/in2)
3771 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3772 # If 0 then files that require this addition will simply be ignored.
3773 sub rewrite_inputs_into_dependencies ($@)
3775 my ($add_srcdir, @inputs) = @_;
3778 foreach my $single (@inputs)
3780 if (dirname ($single) eq $relative_dir)
3782 push (@newinputs, basename ($single));
3786 push (@newinputs, '$(top_srcdir)/' . $single);
3793 # Handle remaking and configure stuff.
3794 # We need the name of the input file, to do proper remaking rules.
3795 sub handle_configure
3797 my ($local, $input, @secondary_inputs) = @_;
3799 my $input_base = basename ($input);
3800 my $local_base = basename ($local);
3802 my $amfile = $input_base . '.am';
3803 # We know we can always add '.in' because it really should be an
3804 # error if the .in was missing originally.
3805 my $infile = '$(srcdir)/' . $input_base . '.in';
3806 my $colon_infile = '';
3807 if ($local ne $input || @secondary_inputs)
3809 $colon_infile = ':' . $input . '.in';
3811 $colon_infile .= ':' . join (':', @secondary_inputs)
3812 if @secondary_inputs;
3814 my @rewritten = rewrite_inputs_into_dependencies (1, @secondary_inputs);
3816 my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4 ();
3819 &file_contents ('configure',
3825 => ((($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3830 => "@include_stack",
3834 => $cygnus_mode ? 'cygnus' : $strictness_name,
3836 => $cmdline_use_dependencies ? '' : ' --ignore-deps',
3837 'MAKEFILE-AM-SOURCES'
3838 => "$input$colon_infile",
3840 => $regen_aclocal_m4,
3842 => "@aclocal_m4_deps"));
3844 if ($relative_dir eq '.')
3846 &push_dist_common ('acconfig.h')
3850 # If we have a configure header, require it.
3852 my @distclean_config;
3853 foreach my $spec (@config_headers)
3856 # $CONFIG_H_PATH: config.h from top level.
3857 my ($config_h_path, @ins) = split_config_file_spec ($spec);
3858 my $config_h_dir = dirname ($config_h_path);
3860 # If the header is in the current directory we want to build
3861 # the header here. Otherwise, if we're at the topmost
3862 # directory and the header's directory doesn't have a
3863 # Makefile, then we also want to build the header.
3864 if ($relative_dir eq $config_h_dir
3865 || ($relative_dir eq '.' && ! &is_make_dir ($config_h_dir)))
3867 my ($cn_sans_dir, $stamp_dir);
3868 if ($relative_dir eq $config_h_dir)
3870 $cn_sans_dir = basename ($config_h_path);
3875 $cn_sans_dir = $config_h_path;
3876 if ($config_h_dir eq '.')
3882 $stamp_dir = $config_h_dir . '/';
3886 # Compute relative path from directory holding output
3887 # header to directory holding input header. FIXME:
3888 # doesn't handle case where we have multiple inputs.
3890 if (dirname ($ins[0]) eq $relative_dir)
3892 $in0_sans_dir = basename ($ins[0]);
3896 $in0_sans_dir = backname ($relative_dir) . '/' . $ins[0];
3899 require_file ($config_header_location, FOREIGN, $in0_sans_dir);
3901 # Header defined and in this directory.
3903 if (-f $config_h_path . '.top')
3905 push (@files, "$cn_sans_dir.top");
3907 if (-f $config_h_path . '.bot')
3909 push (@files, "$cn_sans_dir.bot");
3912 push_dist_common (@files);
3914 # For now, acconfig.h can only appear in the top srcdir.
3915 if (-f 'acconfig.h')
3917 push (@files, '$(top_srcdir)/acconfig.h');
3920 my $stamp = "${stamp_dir}stamp-h${hdr_index}";
3922 file_contents ('remake-hdr',
3923 ('FILES' => "@files",
3924 'CONFIG_H' => $cn_sans_dir,
3925 'CONFIG_HIN' => $in0_sans_dir,
3926 'CONFIG_H_PATH' => $config_h_path,
3927 'STAMP' => "$stamp"));
3929 push @distclean_config, $cn_sans_dir;
3933 $output_rules .= file_contents ('clean-hdr',
3934 ('FILES' => "@distclean_config"))
3935 if @distclean_config;
3937 # Set location of mkinstalldirs.
3938 define_variable ('mkinstalldirs',
3939 ('$(SHELL) ' . $config_aux_dir . '/mkinstalldirs'));
3941 macro_error ('CONFIG_HEADER',
3942 "`CONFIG_HEADER' is an anachronism; now determined from `$configure_ac'")
3943 if variable_defined ('CONFIG_HEADER');
3946 foreach my $spec (@config_headers)
3948 my ($out, @ins) = split_config_file_spec ($spec);
3949 # Generate CONFIG_HEADER define.
3950 if ($relative_dir eq dirname ($out))
3952 push @config_h, basename ($out);
3956 push @config_h, "\$(top_builddir)/$out";
3959 define_variable ("CONFIG_HEADER", "@config_h")
3962 # Now look for other files in this directory which must be remade
3963 # by config.status, and generate rules for them.
3964 my @actual_other_files = ();
3965 foreach my $lfile (@other_input_files)
3969 if ($lfile =~ /^([^:]*):(.*)$/)
3971 # This is the ":" syntax of AC_OUTPUT.
3973 @inputs = split (':', $2);
3979 @inputs = $file . '.in';
3982 # Automake files should not be stored in here, but in %MAKE_LIST.
3983 prog_error ("$lfile in \@other_input_files")
3984 if -f $file . '.am';
3986 my $local = basename ($file);
3988 # Make sure the dist directory for each input file is created.
3989 # We only have to do this at the topmost level though. This
3990 # is a bit ugly but it easier than spreading out the logic,
3991 # especially in cases like AC_OUTPUT(foo/out:bar/in), where
3992 # there is no Makefile in bar/.
3993 if ($relative_dir eq '.')
3997 $dist_dirs{dirname ($_)} = 1;
4001 # We skip files that aren't in this directory. However, if
4002 # the file's directory does not have a Makefile, and we are
4003 # currently doing `.', then we create a rule to rebuild the
4004 # file in the subdir.
4005 my $fd = dirname ($file);
4006 if ($fd ne $relative_dir)
4008 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
4018 # Some users have been tempted to put `stamp-h' in the
4019 # AC_OUTPUT line. This won't do the right thing, so we
4020 # explicitly fail here.
4021 if ($local eq 'stamp-h')
4023 # FIXME: allow real filename.
4024 file_error ($ac_config_files_location,
4025 'stamp-h should not appear in AC_OUTPUT');
4029 my @rewritten_inputs = rewrite_inputs_into_dependencies (1, @inputs);
4030 $output_rules .= ($local . ': '
4031 . '$(top_builddir)/config.status '
4032 . "@rewritten_inputs\n"
4034 . 'cd $(top_builddir) && '
4035 . '$(SHELL) ./config.status '
4036 . ($relative_dir eq '.' ? '' : '$(subdir)/')
4039 push (@actual_other_files, $local);
4041 # Require all input files.
4042 require_file ($ac_config_files_location, FOREIGN,
4043 rewrite_inputs_into_dependencies (0, @inputs));
4046 # These files get removed by "make clean".
4047 define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
4053 my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
4054 'oldinclude', 'pkginclude',
4058 next unless /\..*$/;
4059 &saw_extension ($&);
4065 return if ! $seen_gettext || $relative_dir ne '.';
4067 if (! variable_defined ('SUBDIRS'))
4069 conf_error ("AM_GNU_GETTEXT used but SUBDIRS not defined");
4073 my @subdirs = &variable_value_as_list_recursive ('SUBDIRS', 'all');
4074 macro_error ('SUBDIRS',
4075 "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
4076 if ! grep ('po', @subdirs);
4077 macro_error ('SUBDIRS',
4078 "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
4079 if ! grep ('intl', @subdirs);
4081 require_file ($ac_gettext_location, GNU, 'ABOUT-NLS');
4084 # Handle footer elements.
4087 # NOTE don't use define_pretty_variable here, because
4088 # $contents{...} is already defined.
4089 $output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n\n"
4090 if variable_value ('SOURCES');
4093 target_error ('.SUFFIXES',
4094 "use variable `SUFFIXES', not target `.SUFFIXES'")
4095 if target_defined ('.SUFFIXES');
4097 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
4098 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
4099 # anything else, by sticking it right after the default: target.
4100 $output_header .= ".SUFFIXES:\n";
4101 if (@suffixes || variable_defined ('SUFFIXES'))
4103 # Make sure suffixes has unique elements. Sort them to ensure
4104 # the output remains consistent. However, $(SUFFIXES) is
4105 # always at the start of the list, unsorted. This is done
4106 # because make will choose rules depending on the ordering of
4107 # suffixes, and this lets the user have some control. Push
4108 # actual suffixes, and not $(SUFFIXES). Some versions of make
4109 # do not like variable substitutions on the .SUFFIXES line.
4110 my @user_suffixes = (variable_defined ('SUFFIXES')
4111 ? &variable_value_as_list_recursive ('SUFFIXES', '')
4114 my %suffixes = map { $_ => 1 } @suffixes;
4115 delete @suffixes{@user_suffixes};
4117 $output_header .= (".SUFFIXES: "
4118 . join (' ', @user_suffixes, sort keys %suffixes)
4122 $output_trailer .= file_contents ('footer');
4125 # Deal with installdirs target.
4126 sub handle_installdirs ()
4129 &file_contents ('install',
4131 => variable_value ('_am_installdirs') || '',
4133 => (target_defined ('installdirs-local')
4134 ? ' installdirs-local' : '')));
4138 # Deal with all and all-am.
4141 my ($makefile) = @_;
4145 # Put this at the beginning for the sake of non-GNU makes. This
4146 # is still wrong if these makes can run parallel jobs. But it is
4148 unshift (@all, basename ($makefile));
4150 foreach my $spec (@config_headers)
4152 my ($out, @ins) = split_config_file_spec ($spec);
4153 push (@all, basename ($out))
4154 if dirname ($out) eq $relative_dir;
4157 # Install `all' hooks.
4158 if (&target_defined ("all-local"))
4160 push (@all, "all-local");
4161 &depend ('.PHONY', "all-local");
4164 &pretty_print_rule ("all-am:", "\t\t", @all);
4165 &depend ('.PHONY', 'all-am', 'all');
4170 my @local_headers = ();
4171 push @local_headers, '$(BUILT_SOURCES)'
4172 if variable_defined ('BUILT_SOURCES');
4173 foreach my $spec (@config_headers)
4175 my ($out, @ins) = split_config_file_spec ($spec);
4176 push @local_headers, basename ($out)
4177 if dirname ($out) eq $relative_dir;
4182 # We need to make sure config.h is built before we recurse.
4183 # We also want to make sure that built sources are built
4184 # before any ordinary `all' targets are run. We can't do this
4185 # by changing the order of dependencies to the "all" because
4186 # that breaks when using parallel makes. Instead we handle
4187 # things explicitly.
4188 $output_all .= ("all: @local_headers"
4190 . '$(MAKE) $(AM_MAKEFLAGS) '
4191 . (variable_defined ('SUBDIRS')
4192 ? 'all-recursive' : 'all-am')
4197 $output_all .= "all: " . (variable_defined ('SUBDIRS')
4198 ? 'all-recursive' : 'all-am') . "\n\n";
4203 # Handle check merge target specially.
4204 sub do_check_merge_target
4206 if (&target_defined ('check-local'))
4208 # User defined local form of target. So include it.
4209 push (@check_tests, 'check-local');
4210 &depend ('.PHONY', 'check-local');
4213 # In --cygnus mode, check doesn't depend on all.
4216 # Just run the local check rules.
4217 &pretty_print_rule ('check-am:', "\t\t", @check);
4221 # The check target must depend on the local equivalent of
4222 # `all', to ensure all the primary targets are built. Then it
4223 # must build the local check rules.
4224 $output_rules .= "check-am: all-am\n";
4225 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4229 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4233 &depend ('.PHONY', 'check', 'check-am');
4234 $output_rules .= ("check: "
4235 . (variable_defined ('SUBDIRS')
4236 ? 'check-recursive' : 'check-am')
4240 # Handle all 'clean' targets.
4245 # Don't include `MAINTAINER'; it is handled specially below.
4246 foreach my $name ('MOSTLY', '', 'DIST')
4248 $transform{"${name}CLEAN"} = variable_defined ("${name}CLEANFILES");
4251 # Built sources are automatically removed by maintainer-clean.
4252 push (@maintainer_clean_files, '$(BUILT_SOURCES)')
4253 if variable_defined ('BUILT_SOURCES');
4254 push (@maintainer_clean_files, '$(MAINTAINERCLEANFILES)')
4255 if variable_defined ('MAINTAINERCLEANFILES');
4257 $output_rules .= &file_contents ('clean',
4260 # Join with no space to avoid
4261 # spurious `test -z' success at
4263 => join ('', @maintainer_clean_files),
4265 # A space is required in the join here.
4266 => "@maintainer_clean_files"));
4270 # &depend ($CATEGORY, @DEPENDENDEES)
4271 # ----------------------------------
4272 # The target $CATEGORY depends on @DEPENDENDEES.
4275 my ($category, @dependendees) = @_;
4277 push (@{$dependencies{$category}}, @dependendees);
4282 # &target_cmp ($A, $B)
4283 # --------------------
4284 # Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
4297 # &handle_factored_dependencies ()
4298 # --------------------------------
4299 # Handle everything related to gathered targets.
4300 sub handle_factored_dependencies
4303 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4304 'uninstall-exec-local', 'uninstall-exec-hook')
4306 if (&target_defined ($utarg))
4309 $x =~ s/(data|exec)-//;
4310 target_error ($utarg, "use `$x', not `$utarg'");
4314 if (&target_defined ('install-local'))
4316 target_error ('install-local',
4317 "use `install-data-local' or `install-exec-local', "
4318 . "not `install-local'");
4321 if (!defined $options{'no-installinfo'}
4322 && &target_defined ('install-info-local'))
4324 target_error ('install-info-local',
4325 "`install-info-local' target defined but "
4326 . "`no-installinfo' option not in use");
4329 # Install the -local hooks.
4330 foreach (keys %dependencies)
4332 # Hooks are installed on the -am targets.
4334 if (&target_defined ("$_-local"))
4336 depend ("$_-am", "$_-local");
4337 &depend ('.PHONY', "$_-local");
4341 # Install the -hook hooks.
4342 # FIXME: Why not be as liberal as we are with -local hooks?
4343 foreach ('install-exec', 'install-data', 'uninstall')
4345 if (&target_defined ("$_-hook"))
4347 $actions{"$_-am"} .=
4348 ("\t\@\$(NORMAL_INSTALL)\n"
4349 . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
4353 # All the required targets are phony.
4354 depend ('.PHONY', keys %required_targets);
4356 # Actually output gathered targets.
4357 foreach (sort target_cmp keys %dependencies)
4359 # If there is nothing about this guy, skip it.
4361 unless (@{$dependencies{$_}}
4363 || $required_targets{$_});
4364 &pretty_print_rule ("$_:", "\t",
4365 uniq (sort @{$dependencies{$_}}));
4366 $output_rules .= $actions{$_}
4367 if defined $actions{$_};
4368 $output_rules .= "\n";
4373 # &handle_tests_dejagnu ()
4374 # ------------------------
4375 sub handle_tests_dejagnu
4377 push (@check_tests, 'check-DEJAGNU');
4378 $output_rules .= file_contents ('dejagnu');
4382 # Handle TESTS variable and other checks.
4385 if (defined $options{'dejagnu'})
4387 &handle_tests_dejagnu;
4391 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4394 "`$c' defined but `dejagnu' not in `AUTOMAKE_OPTIONS'")
4395 if variable_defined ($c);
4399 if (variable_defined ('TESTS'))
4401 push (@check_tests, 'check-TESTS');
4402 $output_rules .= &file_contents ('check');
4406 # Handle Emacs Lisp.
4407 sub handle_emacs_lisp
4409 my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4412 return if ! @elfiles;
4414 # Generate .elc files.
4415 my @elcfiles = map { $_ . 'c' } @elfiles;
4416 define_pretty_variable ('ELCFILES', '', @elcfiles);
4418 push (@all, '$(ELCFILES)');
4420 &am_error ("`lisp_LISP' defined but `AM_PATH_LISPDIR' not in `$configure_ac'")
4421 if ! $am_lispdir_location && variable_defined ('lisp_LISP');
4423 require_conf_file ($am_lispdir_location, FOREIGN, 'elisp-comp');
4424 &define_variable ('elisp_comp', $config_aux_dir . '/elisp-comp');
4430 my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4431 'python', 'noinst');
4432 return if ! @pyfiles;
4434 # Found some python.
4435 &am_error ("`python_PYTHON' defined but `AM_PATH_PYTHON' not in `$configure_ac'")
4436 if ! $pythondir_location && variable_defined ('python_PYTHON');
4438 require_conf_file ($pythondir_location, FOREIGN, 'py-compile');
4439 &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4445 my @sourcelist = &am_install_var ('-candist',
4447 'java', 'noinst', 'check');
4448 return if ! @sourcelist;
4450 my @prefix = am_primary_prefixes ('JAVA', 1,
4451 'java', 'noinst', 'check');
4454 foreach my $curs (@prefix)
4457 if $curs eq 'EXTRA';
4459 macro_error ($curs . '_JAVA',
4460 "multiple _JAVA primaries in use")
4466 push (@all, 'class' . $dir . '.stamp');
4470 # Handle some of the minor options.
4471 sub handle_minor_options
4473 if (defined $options{'readme-alpha'})
4475 if ($relative_dir eq '.')
4477 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4479 # FIXME: allow real filename.
4480 file_error ($package_version_location,
4481 "version `$package_version' doesn't follow Gnits standards");
4483 elsif (defined $1 && -f 'README-alpha')
4485 # This means we have an alpha release. See
4486 # GNITS_VERSION_PATTERN for details.
4487 require_file_with_macro ('AUTOMAKE_OPTIONS',
4488 FOREIGN, 'README-alpha');
4494 ################################################################
4496 # ($OUTPUT, @INPUTS)
4497 # &split_config_file_spec ($SPEC)
4498 # -------------------------------
4499 # Decode the Autoconf syntax for config files (files, headers, links
4501 sub split_config_file_spec ($)
4504 my ($output, @inputs) = split (/:/, $spec);
4506 push @inputs, "$output.in"
4509 return ($output, @inputs);
4515 # &scan_autoconf_config_files ($CONFIG-FILES)
4516 # -------------------------------------------
4517 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4519 sub scan_autoconf_config_files
4521 my ($config_files) = @_;
4522 # Look at potential Makefile.am's.
4523 foreach (split ' ', $config_files)
4525 # Must skip empty string for Perl 4.
4526 next if $_ eq "\\" || $_ eq '';
4528 # Handle $local:$input syntax. Note that we ignore
4529 # every input file past the first, though we keep
4530 # those around for later.
4531 my ($local, $input, @rest) = split (/:/);
4538 # FIXME: should be error if .in is missing.
4539 $input =~ s/\.in$//;
4542 if (-f $input . '.am')
4544 # We have a file that automake should generate.
4545 $make_list{$input} = join (':', ($local, @rest));
4549 # We have a file that automake should cause to be
4550 # rebuilt, but shouldn't generate itself.
4551 push (@other_input_files, $_);
4557 # &scan_autoconf_traces ($FILENAME)
4558 # ---------------------------------
4559 # FIXME: For the time being, we don't care about the FILENAME.
4560 sub scan_autoconf_traces ($)
4562 my ($filename) = @_;
4564 my @traced = qw(AC_CANONICAL_HOST
4571 AC_PROG_LIBTOOL AM_PROG_LIBTOOL
4584 my $traces = "$ENV{amtraces} ";
4586 # Use a separator unlikely to be used, not `:', the default, which
4587 # has a precise meaning for AC_CONFIG_FILES and so on.
4588 $traces .= join (' ',
4589 map { "--trace=$_" . ':\$f:\$l::\$n::\${::}%' } @traced);
4591 my $tracefh = new Automake::XFile ("$traces |");
4592 verbose "reading $traces";
4594 while ($_ = $tracefh->getline)
4597 my ($here, @args) = split /::/;
4598 my $macro = $args[0];
4600 # Alphabetical ordering please.
4601 if ($macro eq 'AC_CANONICAL_HOST')
4603 if (! $seen_canonical)
4605 $seen_canonical = AC_CANONICAL_HOST;
4606 $canonical_location = $here;
4609 elsif ($macro eq 'AC_CANONICAL_SYSTEM')
4611 $seen_canonical = AC_CANONICAL_SYSTEM;
4612 $canonical_location = $here;
4614 elsif ($macro eq 'AC_CONFIG_AUX_DIR')
4616 @config_aux_path = $args[1];
4617 $config_aux_dir_set_in_configure_in = 1;
4619 elsif ($macro eq 'AC_CONFIG_FILES')
4621 # Look at potential Makefile.am's.
4622 $ac_config_files_location = $here;
4623 &scan_autoconf_config_files ($args[1]);
4625 elsif ($macro eq 'AC_INIT')
4627 if (defined $args[2])
4629 $package_version = $args[2];
4630 $package_version_location = $here;
4633 elsif ($macro eq 'AC_LIBSOURCE')
4635 $libsources{$args[1]} = $here;
4637 elsif ($macro =~ /^A(C|M)_PROG_LIBTOOL$/)
4639 $seen_libtool = $here;
4641 elsif ($macro eq 'AC_PROG_LEX')
4643 $seen_prog_lex = $here;
4645 elsif ($macro eq 'AC_SUBST')
4647 # Just check for alphanumeric in AC_SUBST. If you do
4648 # AC_SUBST(5), then too bad.
4649 $configure_vars{$args[1]} = $here
4650 if $args[1] =~ /^\w+$/;
4652 elsif ($macro eq 'AM_AUTOMAKE_VERSION')
4655 "version mismatch. This is Automake $VERSION,\n" .
4656 "but the definition used by this AM_INIT_AUTOMAKE\n" .
4657 "comes from Automake $args[1]. You should recreate\n" .
4658 "aclocal.m4 with aclocal and run automake again.\n")
4659 if ($VERSION ne $args[1]);
4661 $seen_automake_version = 1;
4663 elsif ($macro eq 'AM_CONDITIONAL')
4665 $configure_cond{$args[1]} = $here;
4667 elsif ($macro eq 'AM_CONFIG_HEADER')
4669 $config_header_location = $here;
4670 push @config_headers, split (' ', $args[1]);
4672 elsif ($macro eq 'AM_C_PROTOTYPES')
4674 $am_c_prototypes = $here;
4676 elsif ($macro eq 'AM_GNU_GETTEXT')
4678 $seen_gettext = $here;
4679 $ac_gettext_location = $here;
4681 elsif ($macro eq 'AM_INIT_AUTOMAKE')
4683 $seen_init_automake = $here;
4684 if (defined $args[2])
4686 $package_version = $args[2];
4687 $package_version_location = $here;
4689 elsif (defined $args[1])
4691 $global_options = $args[1];
4694 elsif ($macro eq 'AM_MAINTAINER_MODE')
4696 $seen_maint_mode = $here;
4698 elsif ($macro eq 'AM_PATH_LISPDIR')
4700 $am_lispdir_location = $here;
4702 elsif ($macro eq 'AM_PATH_PYTHON')
4704 $pythondir_location = $here;
4706 elsif ($macro eq 'AM_PROG_CC_C_O')
4708 $seen_cc_c_o = $here;
4714 # &scan_one_autoconf_file ($FILENAME)
4715 # -----------------------------------
4716 # Scan one file for interesting things. Subroutine of
4717 # &scan_autoconf_files.
4718 sub scan_one_autoconf_file
4720 my ($filename) = @_;
4722 # Some macros already provide the right traces to enable generic
4723 # code and specific arguments, instead of dedicated code. But
4724 # currently we don't handle traces. Rewrite these dedicated
4725 # macros handling into the generic macro invocation, and let our
4726 # generic case handle them.
4730 'AC_FUNC_ALLOCA' => 'AC_LIBSOURCES([alloca.c])',
4731 'AC_FUNC_GETLOADAVG' => 'AC_LIBSOURCES([getloadavg.c])',
4732 'AC_FUNC_MEMCMP' => 'AC_LIBSOURCES([memcmp.c])',
4733 'AC_STRUCT_ST_BLOCKS' => 'AC_LIBSOURCES([fileblocks.c])',
4734 'A[CM]_REPLACE_GNU_GETOPT' => 'AC_LIBSOURCES([getopt.c, getopt1.c])',
4735 'A[CM]_FUNC_STRTOD' => 'AC_LIBSOURCES([strtod.c])',
4736 'AM_WITH_REGEX' => 'AC_LIBSOURCES([rx.c, rx.h, regex.c, regex.h])',
4737 'AC_FUNC_MKTIME' => 'AC_LIBSOURCES([mktime.c])',
4738 'A[CM]_FUNC_ERROR_AT_LINE' => 'AC_LIBSOURCES([error.c, error.h])',
4739 'A[CM]_FUNC_OBSTACK' => 'AC_LIBSOURCES([obstack.c, obstack.h])',
4742 my $configfh = new Automake::XFile ("< $filename");
4743 verbose "reading $filename";
4745 my ($in_ac_output, $in_ac_replace) = (0, 0);
4746 while ($_ = $configfh->getline)
4748 # Remove comments from current line.
4752 # Skip macro definitions. Otherwise we might be confused into
4753 # thinking that a macro that was only defined was actually
4757 # Follow includes. This is a weirdness commonly in use at
4758 # Cygnus and hopefully nowhere else.
4759 if (/sinclude\((.*)\)/ && -f $1)
4761 # $_ being local, if we don't preserve it, when coming
4762 # back we will have $_ undefined, which is bad for the
4763 # the rest of this routine.
4764 my $underscore = $_;
4765 &scan_one_autoconf_file ($1);
4769 for my $generalize (keys %generalize)
4771 s/\b$generalize\b/$generalize{$generalize}/g;
4775 my $here = "$filename:$.";
4777 # Populate libobjs array.
4778 if (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4779 || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4781 foreach my $libobj_iter (split (' ', $1))
4783 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4784 || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4785 || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4787 $libsources{$1 . '.c'} = $here;
4791 elsif (/AC_LIBOBJ\(([^)]+)\)/)
4793 $libsources{unquote_m4_arg ($1) . ".c"} = $here;
4795 elsif (/AC_LIBSOURCE\(([^)]+)\)/)
4797 $libsources{&unquote_m4_arg ($1)} = $here;
4799 elsif (/AC_LIBSOURCES\(([^)]+)\)/)
4801 foreach my $lc_iter (split (/[, ]+/, &unquote_m4_arg ($1)))
4803 $libsources{$lc_iter} = $here;
4807 if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4813 $in_ac_replace = 0 if s/[\]\)].*$//;
4814 # Remove trailing backslash.
4818 # Need to skip empty elements for Perl 4.
4820 $libsources{$_ . '.c'} = $here;
4824 if (/$obsolete_rx/o)
4827 if ($obsolete_macros{$1} ne '')
4829 $hint = '; ' . $obsolete_macros{$1};
4831 file_error ($here, "`$1' is obsolete$hint");
4834 # Process the AC_OUTPUT and AC_CONFIG_FILES macros.
4835 if (! $in_ac_output && s/(AC_(OUTPUT|CONFIG_FILES))\s*\(\[?//)
4838 $ac_config_files_location = $here;
4849 # Look at potential Makefile.am's.
4850 &scan_autoconf_config_files ($_);
4853 && scalar keys %make_list == 0
4854 && @other_input_files == 0)
4856 file_error ($ac_config_files_location,
4857 "no files mentioned in `$in_ac_output'");
4862 if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4864 @config_aux_path = &unquote_m4_arg ($1);
4865 $config_aux_dir_set_in_configure_in = $here;
4868 # Check for ansi2knr.
4869 $am_c_prototypes = $here if /AM_C_PROTOTYPES/;
4871 # Check for `-c -o' code.
4872 $seen_cc_c_o = $here if /AM_PROG_CC_C_O/;
4874 # Check for NLS support.
4875 if (/AM_GNU_GETTEXT/)
4877 $seen_gettext = $here;
4878 $ac_gettext_location = $here;
4881 # Handle configuration headers. A config header of `[$1]'
4882 # means we are actually scanning AM_CONFIG_HEADER from
4883 # aclocal.m4. Same thing with a leading underscore.
4884 if (/(?<!_)A([CM])_CONFIG_HEADERS?\s*\((.*)\)/
4888 "`automake requires `AM_CONFIG_HEADER', not `AC_CONFIG_HEADER'")
4891 $config_header_location = $here;
4892 push @config_headers, split (' ', unquote_m4_arg ($2));
4895 # Handle AC_CANONICAL_*. Always allow upgrading to
4896 # AC_CANONICAL_SYSTEM, but never downgrading.
4897 if (/AC_CANONICAL_HOST/ || /AC_CYGWIN/ || /AC_EMXOS2/ || /AC_MINGW32/)
4899 if (! $seen_canonical)
4901 $seen_canonical = AC_CANONICAL_HOST;
4902 $canonical_location = $here;
4905 if (/AC_CANONICAL_SYSTEM/)
4907 $seen_canonical = AC_CANONICAL_SYSTEM;
4908 $canonical_location = $here;
4911 # If using X, include some extra variable definitions. NOTE
4912 # we don't want to force these into CFLAGS or anything,
4913 # because not all programs will necessarily use X.
4916 foreach my $var (qw(X_CFLAGS X_LIBS X_EXTRA_LIBS X_PRE_LIBS))
4918 $configure_vars{$var} = $here;
4922 # AM_INIT_AUTOMAKE with any number of argument
4923 if (/AM_INIT_AUTOMAKE/)
4925 $seen_init_automake = $here;
4928 # AC_INIT or AM_INIT_AUTOMAKE with two arguments
4929 if (/$AC_INIT_PATTERN/o || /$AM_INIT_AUTOMAKE_PATTERN/o)
4931 if ($1 =~ /$AM_PACKAGE_VERSION_PATTERN/o)
4933 $package_version = $1;
4934 $package_version_location = $here;
4938 # AM_INIT_AUTOMAKE with one argument.
4939 if (/AM_INIT_AUTOMAKE\(([^),]+)\)/)
4941 $global_options = &unquote_m4_arg ($1);
4944 if (/AM_AUTOMAKE_VERSION\(([^)]+)\)/)
4946 my $vers = &unquote_m4_arg ($1);
4948 "version mismatch. This is Automake $VERSION, " .
4949 "but $filename\nwas generated for Automake $vers. " .
4950 "You should recreate\n$filename with aclocal and " .
4951 "run automake again.\n")
4952 if ($VERSION ne $vers);
4954 $seen_automake_version = 1;
4959 $configure_vars{'LEX'} = $here;
4960 $configure_vars{'LEX_OUTPUT_ROOT'} = $here;
4961 $configure_vars{'LEXLIB'} = $here;
4962 $seen_prog_lex = $here;
4964 if (/AC_PROG_LEX/ && $filename =~ /configure\.(ac|in)$/)
4966 $configure_vars{'LEX'} = $here;
4967 $configure_vars{'LEX_OUTPUT_ROOT'} = $here;
4968 $configure_vars{'LEXLIB'} = $here;
4969 $seen_prog_lex = $here;
4970 file_warning ($here,
4971 "automake requires `AM_PROG_LEX', not `AC_PROG_LEX'");
4974 if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4976 $configure_vars{$1} = $here;
4978 if (/$AC_CHECK_PATTERN/o)
4980 $configure_vars{$3} = $here;
4982 if (/$AM_MISSING_PATTERN/o
4986 && $1 ne 'AUTOHEADER'
4987 # AM_INIT_AUTOMAKE is AM_MISSING_PROG'ing MAKEINFO. But
4988 # we handle it elsewhere.
4989 && $1 ne 'MAKEINFO')
4991 $configure_vars{$1} = $here;
4994 # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4995 # but later define it elsewhere. This is pretty hacky. We
4996 # also explicitly avoid INSTALL_SCRIPT and some other
4997 # variables because they are defined in header-vars.am.
4998 # AMDEPBACKSLASH might be subst'd by `\', which certainly would
4999 # not be appreciated by Make.
5000 if (/$AC_SUBST_PATTERN/o
5002 && $1 ne 'INSTALL_SCRIPT'
5003 && $1 ne 'INSTALL_DATA'
5004 && $1 ne 'AMDEPBACKSLASH')
5006 $configure_vars{$1} = $here;
5009 if (/AM_MAINTAINER_MODE/)
5011 $seen_maint_mode = $here;
5012 $configure_cond{'MAINTAINER_MODE'} = $here;
5015 $am_lispdir_location = $here if /AM_PATH_LISPDIR/;
5017 if (/AM_PATH_PYTHON/)
5019 $pythondir_location = $here;
5020 $configure_vars{'pythondir'} = $here;
5021 $configure_vars{'PYTHON'} = $here;
5024 if (/A(C|M)_PROG_LIBTOOL/)
5026 # We're not ready for this yet. People still use a
5027 # libtool with no AC_PROG_LIBTOOL. Once that is the
5028 # dominant version we can reenable this code -- but next
5029 # time by mentioning the macro in %obsolete_macros, both
5030 # here and in aclocal.in.
5032 # if (/AM_PROG_LIBTOOL/)
5034 # file_warning ($here, "`AM_PROG_LIBTOOL' is obsolete, use `AC_PROG_LIBTOOL' instead");
5036 $seen_libtool = $here;
5037 $configure_vars{'LIBTOOL'} = $here;
5038 $configure_vars{'RANLIB'} = $here;
5039 $configure_vars{'CC'} = $here;
5040 # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST. Make sure we
5041 # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
5042 $seen_canonical = AC_CANONICAL_HOST if ! $seen_canonical;
5045 $seen_multilib = $here if (/AM_ENABLE_MULTILIB/);
5047 if (/$AM_CONDITIONAL_PATTERN/o)
5049 $configure_cond{$1} = $here;
5052 # Check for Fortran 77 intrinsic and run-time libraries.
5053 if (/AC_F77_LIBRARY_LDFLAGS/)
5055 $configure_vars{'FLIBS'} = $here;
5061 # &scan_autoconf_files ()
5062 # -----------------------
5063 # Check whether we use `configure.ac' or `configure.in'.
5064 # Scan it (and possibly `aclocal.m4') for interesting things.
5065 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
5066 sub scan_autoconf_files
5068 # Reinitialize libsources here. This isn't really necessary,
5069 # since we currently assume there is only one configure.ac. But
5070 # that won't always be the case.
5073 $configure_ac = find_configure_ac;
5074 die "$me: `configure.ac' or `configure.in' is required\n"
5077 if (defined $ENV{'amtraces'})
5079 print STDERR "$me: Autoconf traces is an experimental feature\n";
5080 print STDERR "$me: use at your own risks\n";
5082 scan_autoconf_traces ($configure_ac);
5086 scan_one_autoconf_file ($configure_ac);
5087 scan_one_autoconf_file ('aclocal.m4')
5091 # Set input and output files if not specified by user.
5094 @input_files = sort keys %make_list;
5095 %output_files = %make_list;
5098 @configure_input_files = sort keys %make_list;
5100 conf_error ("`AM_INIT_AUTOMAKE' must be used")
5101 if ! $seen_init_automake;
5103 if (! $seen_automake_version)
5105 if (-f 'aclocal.m4')
5107 file_error ($seen_init_automake || $me,
5108 "your implementation of AM_INIT_AUTOMAKE comes from " .
5109 "an\nold Automake version. You should recreate " .
5110 "aclocal.m4\nwith aclocal and run automake again.\n");
5114 file_error ($seen_init_automake || $me,
5115 "no proper implementation of AM_INIT_AUTOMAKE was " .
5116 "found,\nprobably because aclocal.m4 is missing...\n" .
5117 "You should run aclocal to create this file, then\n" .
5118 "run automake again.\n");
5122 # Look for some files we need. Always check for these. This
5123 # check must be done for every run, even those where we are only
5124 # looking at a subdir Makefile. We must set relative_dir so that
5125 # the file-finding machinery works.
5126 # FIXME: Is this broken because it needs dynamic scopes.
5127 # My tests seems to show it's not the case.
5128 $relative_dir = '.';
5129 require_conf_file ($configure_ac, FOREIGN,
5130 'install-sh', 'mkinstalldirs', 'missing');
5131 am_error ("`install.sh' is an anachronism; use `install-sh' instead")
5132 if -f $config_aux_path[0] . '/install.sh';
5134 require_conf_file ($pythondir_location, FOREIGN, 'py-compile')
5135 if $pythondir_location;
5137 # Preserve dist_common for later.
5138 $configure_dist_common = variable_value ('DIST_COMMON', 'TRUE') || '';
5141 ################################################################
5143 # Set up for Cygnus mode.
5146 return unless $cygnus_mode;
5148 &set_strictness ('foreign');
5149 $options{'no-installinfo'} = 1;
5150 $options{'no-dependencies'} = 1;
5151 $use_dependencies = 0;
5153 conf_error ("`AM_MAINTAINER_MODE' required when --cygnus specified")
5154 if !$seen_maint_mode;
5157 # Do any extra checking for GNU standards.
5158 sub check_gnu_standards
5160 if ($relative_dir eq '.')
5162 # In top level (or only) directory.
5163 require_file ("$am_file.am", GNU,
5164 qw(INSTALL NEWS README COPYING AUTHORS ChangeLog));
5167 if ($strictness >= GNU
5168 && defined $options{'no-installman'})
5170 macro_error ('AUTOMAKE_OPTIONS',
5171 "option `no-installman' disallowed by GNU standards");
5174 if ($strictness >= GNU
5175 && defined $options{'no-installinfo'})
5177 macro_error ('AUTOMAKE_OPTIONS',
5178 "option `no-installinfo' disallowed by GNU standards");
5182 # Do any extra checking for GNITS standards.
5183 sub check_gnits_standards
5185 if ($relative_dir eq '.')
5187 # In top level (or only) directory.
5188 require_file ("$am_file.am", GNITS, 'THANKS');
5192 ################################################################
5194 # Functions to handle files of each language.
5196 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
5197 # simple formula: Return value is $LANG_SUBDIR if the resulting object
5198 # file should be in a subdir if the source file is, $LANG_PROCESS if
5199 # file is to be dealt with, $LANG_IGNORE otherwise.
5201 # Much of the actual processing is handled in
5202 # handle_single_transform_list. These functions exist so that
5203 # auxiliary information can be recorded for a later cleanup pass.
5204 # Note that the calls to these functions are computed, so don't bother
5205 # searching for their precise names in the source.
5207 # This is just a convenience function that can be used to determine
5208 # when a subdir object should be used.
5211 return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
5214 # Rewrite a single C source file.
5217 my ($directory, $base, $ext) = @_;
5219 if (defined $options{'ansi2knr'} && $base =~ /_$/)
5221 # FIXME: include line number in error.
5222 am_error ("C source file `$base.c' would be deleted by ansi2knr rules");
5225 my $r = $LANG_PROCESS;
5226 if (defined $options{'subdir-objects'})
5229 $base = $directory . '/' . $base
5230 unless $directory eq '.' || $directory eq '';
5234 # Only give error once.
5236 # FIXME: line number.
5237 am_error ("C objects in subdir but `AM_PROG_CC_C_O' not in `$configure_ac'");
5240 require_conf_file ("$am_file.am", FOREIGN, 'compile');
5242 # In this case we already have the directory information, so
5243 # don't add it again.
5244 $de_ansi_files{$base} = '';
5248 $de_ansi_files{$base} = (($directory eq '.' || $directory eq '')
5256 # Rewrite a single C++ source file.
5257 sub lang_cxx_rewrite
5259 return &lang_sub_obj;
5262 # Rewrite a single header file.
5263 sub lang_header_rewrite
5265 # Header files are simply ignored.
5266 return $LANG_IGNORE;
5269 # Rewrite a single yacc file.
5270 sub lang_yacc_rewrite
5272 my ($directory, $base, $ext) = @_;
5274 my $r = &lang_sub_obj;
5275 (my $newext = $ext) =~ tr/y/c/;
5276 return ($r, $newext);
5279 # Rewrite a single yacc++ file.
5280 sub lang_yaccxx_rewrite
5282 my ($directory, $base, $ext) = @_;
5284 my $r = &lang_sub_obj;
5285 (my $newext = $ext) =~ tr/y/c/;
5286 return ($r, $newext);
5289 # Rewrite a single lex file.
5290 sub lang_lex_rewrite
5292 my ($directory, $base, $ext) = @_;
5294 my $r = &lang_sub_obj;
5295 (my $newext = $ext) =~ tr/l/c/;
5296 return ($r, $newext);
5299 # Rewrite a single lex++ file.
5300 sub lang_lexxx_rewrite
5302 my ($directory, $base, $ext) = @_;
5304 my $r = &lang_sub_obj;
5305 (my $newext = $ext) =~ tr/l/c/;
5306 return ($r, $newext);
5309 # Rewrite a single assembly file.
5310 sub lang_asm_rewrite
5312 return &lang_sub_obj;
5315 # Rewrite a single Fortran 77 file.
5316 sub lang_f77_rewrite
5318 return $LANG_PROCESS;
5321 # Rewrite a single preprocessed Fortran 77 file.
5322 sub lang_ppf77_rewrite
5324 return $LANG_PROCESS;
5327 # Rewrite a single ratfor file.
5328 sub lang_ratfor_rewrite
5330 return $LANG_PROCESS;
5333 # Rewrite a single Objective C file.
5334 sub lang_objc_rewrite
5336 return &lang_sub_obj;
5339 # Rewrite a single Java file.
5340 sub lang_java_rewrite
5342 return $LANG_SUBDIR;
5345 # The lang_X_finish functions are called after all source file
5346 # processing is done. Each should handle defining rules for the
5347 # language, etc. A finish function is only called if a source file of
5348 # the appropriate type has been seen.
5352 # Push all libobjs files onto de_ansi_files. We actually only
5353 # push files which exist in the current directory, and which are
5354 # genuine source files.
5355 foreach my $file (keys %libsources)
5357 if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
5359 $de_ansi_files{$1} = (($relative_dir eq '.' || $relative_dir eq '')
5361 : "$relative_dir/");
5365 if (defined $options{'ansi2knr'} && keys %de_ansi_files)
5367 # Make all _.c files depend on their corresponding .c files.
5369 foreach my $base (sort keys %de_ansi_files)
5371 # Each _.c file must depend on ansi2knr; otherwise it
5372 # might be used in a parallel build before it is built.
5373 # We need to support files in the srcdir and in the build
5374 # dir (because these files might be auto-generated. But
5375 # we can't use $< -- some makes only define $< during a
5377 my $ansfile = $de_ansi_files{$base} . $base . '.c';
5378 $output_rules .= ($base . "_.c: $ansfile \$(ANSI2KNR)\n\t"
5379 . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5380 . '`if test -f $(srcdir)/' . $ansfile
5381 . '; then echo $(srcdir)/' . $ansfile
5382 . '; else echo ' . $ansfile . '; fi` '
5383 . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5384 . '| $(ANSI2KNR) > ' . $base . "_.c"
5385 # If ansi2knr fails then we shouldn't
5386 # create the _.c file
5387 . " || rm -f ${base}_.c\n");
5388 push (@objects, $base . '_.$(OBJEXT)');
5389 push (@objects, $base . '_.lo')
5393 # Make all _.o (and _.lo) files depend on ansi2knr.
5394 # Use a sneaky little hack to make it print nicely.
5395 &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5399 # This is a yacc helper which is called whenever we have decided to
5400 # compile a yacc file.
5401 sub lang_yacc_target_hook
5403 my ($self, $aggregate, $output, $input) = @_;
5405 my $flag = $aggregate . "_YFLAGS";
5406 if ((variable_defined ($flag)
5407 && &variable_value ($flag) =~ /$DASH_D_PATTERN/o)
5408 || (variable_defined ('YFLAGS')
5409 && &variable_value ('YFLAGS') =~ /$DASH_D_PATTERN/o))
5411 (my $output_base = $output) =~ s/$KNOWN_EXTENSIONS_PATTERN$//;
5412 my $header = $output_base . '.h';
5414 # Found a `-d' that applies to the compilation of this file.
5415 # Add a dependency for the generated header file, and arrange
5416 # for that file to be included in the distribution.
5417 # FIXME: this fails for `nodist_*_SOURCES'.
5418 $output_rules .= "${header}: $output\n";
5419 &push_dist_common ($header);
5420 # If the files are built in the build directory, then we want
5421 # to remove them with `make clean'. If they are in srcdir
5422 # they shouldn't be touched. However, we can't determine this
5423 # statically, and the GNU rules say that yacc/lex output files
5424 # should be removed by maintainer-clean. So that's what we
5426 push (@maintainer_clean_files, $header);
5430 # This is a helper for both lex and yacc.
5431 sub yacc_lex_finish_helper
5433 return if defined $language_scratch{'lex-yacc-done'};
5434 $language_scratch{'lex-yacc-done'} = 1;
5436 # If there is more than one distinct yacc (resp lex) source file
5437 # in a given directory, then the `ylwrap' program is required to
5438 # allow parallel builds to work correctly. FIXME: for now, no
5440 require_conf_file ($configure_ac, FOREIGN, 'ylwrap');
5441 if ($config_aux_dir_set_in_configure_in)
5443 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5447 &define_variable ('YLWRAP', '$(top_srcdir)/ylwrap');
5451 sub lang_yacc_finish
5453 return if defined $language_scratch{'yacc-done'};
5454 $language_scratch{'yacc-done'} = 1;
5456 macro_error ('YACCFLAGS',
5457 "`YACCFLAGS' obsolete; use `YFLAGS' instead")
5458 if variable_defined ('YACCFLAGS');
5460 if (count_files_for_language ('yacc') > 1)
5462 &yacc_lex_finish_helper;
5469 return if defined $language_scratch{'lex-done'};
5470 $language_scratch{'lex-done'} = 1;
5472 am_error ("lex source seen but `AM_PROG_LEX' not in `$configure_ac'")
5473 unless $seen_prog_lex;
5475 if (count_files_for_language ('lex') > 1)
5477 &yacc_lex_finish_helper;
5482 # Given a hash table of linker names, pick the name that has the most
5483 # precedence. This is lame, but something has to have global
5484 # knowledge in order to eliminate the conflict. Add more linkers as
5490 foreach my $l (qw(GCJLINK CXXLINK F77LINK OBJCLINK))
5492 return $l if defined $linkers{$l};
5497 # Called to indicate that an extension was used.
5501 if (! defined $extension_seen{$ext})
5503 $extension_seen{$ext} = 1;
5507 ++$extension_seen{$ext};
5511 # Return the number of files seen for a given language. Knows about
5512 # special cases we care about. FIXME: this is hideous. We need
5513 # something that involves real language objects. For instance yacc
5514 # and yaccxx could both derive from a common yacc class which would
5515 # know about the strange ylwrap requirement. (Or better yet we could
5516 # just not support legacy yacc!)
5517 sub count_files_for_language
5522 if ($name eq 'yacc' || $name eq 'yaccxx')
5524 @names = ('yacc', 'yaccxx');
5526 elsif ($name eq 'lex' || $name eq 'lexxx')
5528 @names = ('lex', 'lexxx');
5536 foreach $name (@names)
5538 my $lang = $languages{$name};
5539 foreach my $ext (@{$lang->extensions})
5541 $r += $extension_seen{$ext}
5542 if defined $extension_seen{$ext};
5549 # Called to ask whether source files have been seen . If HEADERS is 1,
5550 # headers can be included.
5555 # count all the sources
5557 foreach my $val (values %extension_seen)
5564 $count -= count_files_for_language ('header');
5571 # register_language (%ATTRIBUTE)
5572 # ------------------------------
5573 # Register a single language.
5574 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5575 sub register_language (%)
5581 unless defined $option{'ansi'};
5582 $option{'autodep'} = 'no'
5583 unless defined $option{'autodep'};
5584 $option{'linker'} = ''
5585 unless defined $option{'linker'};
5586 $option{'define_flag'} = 1
5587 unless defined $option{'define_flag'};
5589 my $lang = new Language (%option);
5592 grep ($extension_map{$_} = $lang->name, @{$lang->extensions});
5593 $languages{$lang->name} = $lang;
5595 # Update the pattern of known extensions.
5596 accept_extensions (@{$lang->extensions});
5599 # derive_suffix ($EXT, $OBJ)
5600 # --------------------------
5601 # This function is used to find a path from a user-specified suffix $EXT
5602 # to $OBJ or to some other suffix we recognize internally, eg `cc'.
5603 sub derive_suffix ($$)
5605 my ($source_ext, $obj) = @_;
5607 while (! $extension_map{$source_ext}
5608 && $source_ext ne $obj
5609 && defined $suffix_rules{$source_ext})
5611 $source_ext = $suffix_rules{$source_ext};
5618 ################################################################
5620 # Pretty-print something. HEAD is what should be printed at the
5621 # beginning of the first line, FILL is what should be printed at the
5622 # beginning of every subsequent line.
5623 sub pretty_print_internal
5625 my ($head, $fill, @values) = @_;
5627 my $column = length ($head);
5630 # Fill length is number of characters. However, each Tab
5631 # character counts for eight. So we count the number of Tabs and
5633 my $fill_length = length ($fill);
5634 $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5638 # "71" because we also print a space.
5639 if ($column + length ($_) > 71)
5641 $result .= " \\\n" . $fill;
5642 $column = $fill_length;
5644 $result .= ' ' if $result =~ /\S\z/;
5646 $column += length ($_) + 1;
5653 # Pretty-print something and append to output_vars.
5656 $output_vars .= &pretty_print_internal (@_);
5659 # Pretty-print something and append to output_rules.
5660 sub pretty_print_rule
5662 $output_rules .= &pretty_print_internal (@_);
5666 ################################################################
5670 # &conditional_string(@COND-STACK)
5671 # --------------------------------
5672 # Build a string which denotes the conditional in @COND-STACK. Some
5673 # simplifications are done: `TRUE' entries are elided, and any `FALSE'
5674 # entry results in a return of `FALSE'.
5675 sub conditional_string
5679 if (grep (/^FALSE$/, @stack))
5685 return join (' ', uniq sort grep (!/^TRUE$/, @stack));
5691 # &conditional_true_when ($COND, $WHEN)
5692 # -------------------------------------
5693 # See if a conditional is true. Both arguments are conditional
5694 # strings. This returns true if the first conditional is true when
5695 # the second conditional is true.
5696 # For instance with $COND = `BAR FOO', and $WHEN = `BAR BAZ FOO',
5697 # obviously return 1, and 0 when, for instance, $WHEN = `FOO'.
5698 sub conditional_true_when ($$)
5700 my ($cond, $when) = @_;
5702 # Make a hash holding all the values from $WHEN.
5703 my %cond_vals = map { $_ => 1 } split (' ', $when);
5705 # Check each component of $cond, which looks `COND1 COND2'.
5706 foreach my $comp (split (' ', $cond))
5708 # TRUE is always true.
5709 next if $comp eq 'TRUE';
5710 return 0 if ! defined $cond_vals{$comp};
5718 # &conditional_is_redundant ($COND, @WHENS)
5719 # ----------------------------------------
5720 # Determine whether $COND is redundant with respect to @WHENS.
5722 # Returns true if $COND is true for any of the conditions in @WHENS.
5724 # If there are no @WHENS, then behave as if @WHENS contained a single empty
5726 sub conditional_is_redundant ($@)
5728 my ($cond, @whens) = @_;
5732 return 1 if conditional_true_when ($cond, "");
5736 foreach my $when (@whens)
5738 return 1 if conditional_true_when ($cond, $when);
5747 # condition_negate ($COND)
5748 # ------------------------
5749 sub condition_negate ($)
5753 $cond =~ s/TRUE$/TRUEO/;
5754 $cond =~ s/FALSE$/TRUE/;
5755 $cond =~ s/TRUEO$/FALSE/;
5761 # Compare condition names.
5762 # Issue them in alphabetical order, foo_TRUE before foo_FALSE.
5765 # Be careful we might be comparing `' or `#'.
5766 $a =~ /^(.*)_(TRUE|FALSE)$/;
5767 my ($aname, $abool) = ($1 || '', $2 || '');
5768 $b =~ /^(.*)_(TRUE|FALSE)$/;
5769 my ($bname, $bbool) = ($1 || '', $2 || '');
5770 return ($aname cmp $bname
5771 # Don't bother with IFs, given that TRUE is after FALSE
5772 # just cmp in the reverse order.
5773 || $bbool cmp $abool
5779 # &make_condition (@CONDITIONS)
5780 # -----------------------------
5781 # Transform a list of conditions (themselves can be an internal list
5782 # of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
5783 # Make conditional (a pattern for AC_SUBST).
5784 # Correctly returns the empty string when there are no conditions.
5787 my $res = conditional_string (@_);
5789 # There are no conditions.
5795 elsif ($res eq 'FALSE')
5802 $res = '@' . $res . '@';
5811 ## ------------------------------ ##
5812 ## Handling the condition stack. ##
5813 ## ------------------------------ ##
5817 # cond_stack_if ($NEGATE, $COND, $WHERE)
5818 # --------------------------------------
5819 sub cond_stack_if ($$$)
5821 my ($negate, $cond, $where) = @_;
5823 file_error ($where, "$cond does not appear in AM_CONDITIONAL")
5824 if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
5826 $cond = "${cond}_TRUE"
5827 unless $cond =~ /^TRUE|FALSE$/;
5828 $cond = condition_negate ($cond)
5831 push (@cond_stack, $cond);
5833 return conditional_string (@cond_stack);
5838 # cond_stack_else ($NEGATE, $COND, $WHERE)
5839 # ----------------------------------------
5840 sub cond_stack_else ($$$)
5842 my ($negate, $cond, $where) = @_;
5846 file_error ($where, "else without if");
5850 $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);
5852 # If $COND is given, check against it.
5855 $cond = "${cond}_TRUE"
5856 unless $cond =~ /^TRUE|FALSE$/;
5857 $cond = condition_negate ($cond)
5861 "else reminder ($negate$cond) incompatible with "
5862 . "current conditional: $cond_stack[$#cond_stack]")
5863 if $cond_stack[$#cond_stack] ne $cond;
5866 return conditional_string (@cond_stack);
5871 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5872 # -----------------------------------------
5873 sub cond_stack_endif ($$$)
5875 my ($negate, $cond, $where) = @_;
5880 file_error ($where, "endif without if: $negate$cond");
5885 # If $COND is given, check against it.
5888 $cond = "${cond}_TRUE"
5889 unless $cond =~ /^TRUE|FALSE$/;
5890 $cond = condition_negate ($cond)
5894 "endif reminder ($negate$cond) incompatible with "
5895 . "current conditional: $cond_stack[$#cond_stack]")
5896 if $cond_stack[$#cond_stack] ne $cond;
5901 return conditional_string (@cond_stack);
5908 ## ------------------------ ##
5909 ## Handling the variables. ##
5910 ## ------------------------ ##
5913 # check_ambiguous_conditional ($VAR, $COND)
5914 # -----------------------------------------
5915 # Check for an ambiguous conditional. This is called when a variable
5916 # is being defined conditionally. If we already know about a
5917 # definition that is true under the same conditions, then we have an
5919 sub check_ambiguous_conditional ($$)
5921 my ($var, $cond) = @_;
5922 my $message = conditional_ambiguous_p ($var, $cond);
5925 macro_error ($var, $message);
5931 # conditional_ambiguous_p ($VAR, $COND)
5932 # -------------------------------------
5933 # Check for an ambiguous conditional. Return an error message if we
5934 # have one, the empty string otherwise.
5935 sub conditional_ambiguous_p ($$)
5937 my ($var, $cond) = @_;
5938 foreach my $vcond (keys %{$var_value{$var}})
5941 if ($vcond eq $cond)
5943 return "$var multiply defined in condition $cond";
5945 elsif (&conditional_true_when ($vcond, $cond))
5947 return ("$var was already defined in condition $vcond, "
5948 . "which implies condition $cond");
5950 elsif (&conditional_true_when ($cond, $vcond))
5952 return ("$var was already defined in condition $vcond, "
5953 . "which is implied by condition $cond");
5961 # ¯o_define($VAR, $VAR_IS_AM, $TYPE, $COND, $VALUE, $WHERE)
5962 # -------------------------------------------------------------
5963 # The $VAR can go from Automake to user, but not the converse.
5964 sub macro_define ($$$$$$)
5966 my ($var, $var_is_am, $type, $cond, $value, $where) = @_;
5968 file_error ($where, "bad macro name `$var'")
5969 if $var !~ /$MACRO_PATTERN/o;
5973 # An Automake variable must be consistently defined with the same
5974 # sign by Automake. A user variable must be set by either `=' or
5975 # `:=', and later promoted to `+='.
5978 if (defined $var_type{$var} && $var_type{$var} ne $type)
5981 ("$var was set with `$var_type{$var}=' "
5982 . "and is now set with `$type='"));
5987 if (!defined $var_type{$var} && $type eq '+')
5989 file_error ($where, "$var must be set with `=' before using `+='");
5992 $var_type{$var} = $type;
5994 # When adding, since we rewrite, don't try to preserve the
5995 # Automake continuation backslashes.
5997 if $type eq '+' && $var_is_am;
5999 # Differentiate the first assignment (including with `+=').
6000 if ($type eq '+' && defined $var_value{$var}{$cond})
6002 if (chomp $var_value{$var}{$cond})
6004 # Insert a backslash before a trailing newline.
6005 $var_value{$var}{$cond} .= "\\\n";
6007 elsif ($var_value{$var}{$cond})
6009 # Insert a separator.
6010 $var_value{$var}{$cond} .= ' ';
6012 $var_value{$var}{$cond} .= $value;
6016 # The first assignment to a macro sets its location. Ideally I
6017 # suppose we would associate line numbers with random bits of text.
6018 # FIXME: We sometimes redefine some variables, but we want to keep
6019 # the original location. More subs are needed to handle
6020 # properly variables. Once this done, remove this hack.
6021 $var_location{$var} = $where
6022 unless defined $var_location{$var};
6024 # If Automake tries to override a value specified by the user,
6025 # just don't let it do.
6026 if (defined $var_value{$var}{$cond} && !$var_is_am{$var} && $var_is_am)
6030 print STDERR "$me: refusing to override the user definition of:\n";
6032 print STDERR "$me: with `$cond' => `$value'\n";
6037 # There must be no previous value unless the user is redefining
6038 # an Automake variable or an AC_SUBST variable.
6039 check_ambiguous_conditional ($var, $cond)
6040 unless ($var_is_am{$var} && !$var_is_am
6041 || exists $configure_vars{$var});
6043 $var_value{$var}{$cond} = $value;
6047 # An Automake variable can be given to the user, but not the converse.
6048 if (! defined $var_is_am{$var} || !$var_is_am)
6050 $var_is_am{$var} = $var_is_am;
6053 # Call var_VAR_trigger if it's defined.
6054 # This hook helps to update some internal state *while*
6055 # parsing the file. For instance the handling of SUFFIXES
6056 # requires this (see var_SUFFIXES_trigger).
6057 my $var_trigger = "var_${var}_trigger";
6058 &$var_trigger($type, $value) if defined &$var_trigger;
6062 # ¯o_delete ($VAR, [@CONDS])
6063 # ------------------------------
6064 # Forget about $VAR under the conditions @CONDS, or completely if
6066 sub macro_delete ($@)
6068 my ($var, @conds) = @_;
6072 delete $var_value{$var};
6073 delete $var_location{$var};
6074 delete $var_is_am{$var};
6075 delete $var_comment{$var};
6076 delete $var_type{$var};
6080 foreach my $cond (@conds)
6082 delete $var_value{$var}{$cond};
6088 # ¯o_dump ($VAR)
6089 # ------------------
6094 if (!exists $var_value{$var})
6096 print STDERR " $var does not exist\n";
6100 my $var_is_am = $var_is_am{$var} ? "Automake" : "User";
6101 my $where = (defined $var_location{$var}
6102 ? $var_location{$var} : "undefined");
6103 print STDERR "$var_comment{$var}"
6104 if defined $var_comment{$var};
6105 print STDERR " $var ($var_is_am, where = $where) $var_type{$var}=\n";
6106 print STDERR " {\n";
6107 foreach my $vcond (sort by_condition keys %{$var_value{$var}})
6109 print STDERR " $vcond => $var_value{$var}{$vcond}\n";
6111 print STDERR " }\n";
6122 print STDERR "%var_value =\n";
6124 foreach my $var (sort (keys %var_value))
6133 # variable_defined ($VAR, [$COND])
6134 # ---------------------------------
6135 # See if a variable exists. $VAR is the variable name, and $COND is
6136 # the condition which we should check. If no condition is given, we
6137 # currently return true if the variable is defined under any
6139 sub variable_defined ($;$)
6141 my ($var, $cond) = @_;
6143 # Unfortunately we can't just check for $var_value{VAR}{COND}
6144 # as this would make perl create $condition{VAR}, which we
6146 if (!exists $var_value{$var})
6148 macro_error ($var, "`$var' is a target; expected a variable")
6149 if defined $targets{$var};
6150 # The variable is not defined
6154 # The variable is not defined for the given condition.
6156 if $cond && !exists $var_value{$var}{$cond};
6158 # Even a var_value examination is good enough for us. FIXME:
6159 # really should maintain examined status on a per-condition basis.
6160 $content_seen{$var} = 1;
6166 # variable_assert ($VAR, $WHERE)
6167 # ------------------------------
6168 # Make sure a variable exists. $VAR is the variable name, and $WHERE
6169 # is the name of a macro which refers to $VAR.
6170 sub variable_assert ($$)
6172 my ($var, $where) = @_;
6175 if variable_defined $var;
6177 macro_error ($where, "variable `$var' not defined");
6183 # Mark a variable as examined.
6184 sub examine_variable
6187 variable_defined ($var);
6191 # &variable_conditions_recursive ($VAR)
6192 # -------------------------------------
6193 # Return the set of conditions for which a variable is defined.
6195 # If the variable is not defined conditionally, and is not defined in
6196 # terms of any variables which are defined conditionally, then this
6197 # returns the empty list.
6199 # If the variable is defined conditionally, but is not defined in
6200 # terms of any variables which are defined conditionally, then this
6201 # returns the list of conditions for which the variable is defined.
6203 # If the variable is defined in terms of any variables which are
6204 # defined conditionally, then this returns a full set of permutations
6205 # of the subvariable conditions. For example, if the variable is
6206 # defined in terms of a variable which is defined for COND_TRUE,
6207 # then this returns both COND_TRUE and COND_FALSE. This is
6208 # because we will need to define the variable under both conditions.
6209 sub variable_conditions_recursive ($)
6215 my @new_conds = variable_conditions_recursive_sub ($var, '');
6216 # Now we want to return all permutations of the subvariable
6219 foreach my $item (@new_conds)
6221 foreach (split (' ', $item))
6223 s/^(.*)_(TRUE|FALSE)$/$1_TRUE/;
6227 @new_conds = variable_conditions_permutations (sort keys %allconds);
6230 foreach my $cond (@new_conds)
6232 my $reduce = variable_conditions_reduce (split (' ', $cond));
6234 if $reduce eq 'FALSE';
6235 $uniqify{$cond} = 1;
6238 # Note we cannot just do `return sort keys %uniqify', because this
6239 # function is sometimes used in a scalar context.
6240 my @uniq_list = sort by_condition keys %uniqify;
6246 # variable_conditions ($VAR)
6247 # --------------------------
6248 # Get the list of conditions that a variable is defined with, without
6249 # recursing through the conditions of any subvariables.
6250 # Argument is $VAR: the variable to get the conditions of.
6251 # Returns the list of conditions.
6252 sub variable_conditions ($)
6255 my @conds = keys %{$var_value{$var}};
6256 return sort by_condition @conds;
6261 # &variable_conditionally_defined ($VAR)
6262 # --------------------------------------
6263 sub variable_conditionally_defined ($)
6266 foreach my $cond (variable_conditions_recursive ($var))
6269 unless $cond =~ /^TRUE|FALSE$/;
6276 # &variable_conditions_recursive_sub ($VAR, $PARENT)
6277 # -------------------------------------------------------
6278 # A subroutine of variable_conditions_recursive. This returns all the
6279 # conditions of $VAR, including those of any sub-variables.
6280 sub variable_conditions_recursive_sub
6282 my ($var, $parent) = @_;
6285 if (defined $vars_scanned{$var})
6287 macro_error ($parent, "variable `$var' recursively defined");
6290 $vars_scanned{$var} = 1;
6292 my @this_conds = ();
6293 # Examine every condition under which $VAR is defined.
6294 foreach my $vcond (keys %{$var_value{$var}})
6296 push (@this_conds, $vcond);
6298 # If $VAR references some other variable, then compute the
6299 # conditions for that subvariable.
6300 my @subvar_conds = ();
6301 foreach (split (' ', $var_value{$var}{$vcond}))
6303 # If a comment seen, just leave.
6306 # Handle variable substitutions.
6307 if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
6310 if ($varname =~ /$SUBST_REF_PATTERN/o)
6316 # Here we compute all the conditions under which the
6317 # subvariable is defined. Then we go through and add
6319 my @svc = variable_conditions_recursive_sub ($varname, $var);
6320 foreach my $item (@svc)
6322 my $val = conditional_string ($vcond, split (' ', $item));
6324 push (@subvar_conds, $val);
6329 # If there are no conditional subvariables, then we want to
6330 # return this condition. Otherwise, we want to return the
6331 # permutations of the subvariables, taking into account the
6332 # conditions of $VAR.
6333 if (! @subvar_conds)
6335 push (@new_conds, $vcond);
6339 push (@new_conds, variable_conditions_reduce (@subvar_conds));
6343 # Unset our entry in vars_scanned. We only care about recursive
6345 delete $vars_scanned{$var};
6347 # If we are being called on behalf of another variable, we need to
6348 # return all possible permutations of the conditions. We have
6349 # already handled everything in @this_conds along with their
6350 # subvariables. We now need to add any permutations that are not
6352 foreach my $this_cond (@this_conds)
6355 variable_conditions_permutations (split (' ', $this_cond));
6356 foreach my $perm (@perms)
6359 foreach my $scan (@this_conds)
6361 if (&conditional_true_when ($perm, $scan)
6362 || &conditional_true_when ($scan, $perm))
6370 # This permutation was not already handled, and is valid
6372 push (@new_conds, $perm);
6380 # Filter a list of conditionals so that only the exclusive ones are
6381 # retained. For example, if both `COND1_TRUE COND2_TRUE' and
6382 # `COND1_TRUE' are in the list, discard the latter.
6383 # If the list is empty, return TRUE
6384 sub variable_conditions_reduce
6391 $cond = shift(@conds);
6393 # FALSE is absorbent.
6395 if $cond eq 'FALSE';
6397 if (!conditional_is_redundant ($cond, @ret, @conds))
6403 return "TRUE" if @ret == 0;
6408 # invert_conditions (@CONDS)
6409 # --------------------------
6410 # Invert a list of conditionals. Returns a set of conditionals which
6411 # are never true for any of the input conditionals, and when taken
6412 # together with the input conditionals cover all possible cases.
6414 # For example: invert_conditions("A_TRUE B_TRUE", "A_FALSE B_FALSE") will
6415 # return ("A_FALSE B_TRUE", "A_TRUE B_FALSE")
6416 sub invert_conditions
6421 foreach my $cond (@conds)
6423 foreach my $perm (variable_conditions_permutations (split(' ', $cond)))
6425 push @notconds, $perm
6426 if ! conditional_is_redundant ($perm, @conds);
6429 return variable_conditions_reduce (@notconds);
6432 # Return a list of permutations of a conditional string.
6433 sub variable_conditions_permutations
6438 my $comp = shift (@comps);
6439 return variable_conditions_permutations (@comps)
6441 my $neg = condition_negate ($comp);
6444 foreach my $sub (variable_conditions_permutations (@comps))
6446 push (@ret, "$comp $sub");
6447 push (@ret, "$neg $sub");
6459 # &check_variable_defined_unconditionally($VAR, $PARENT)
6460 # ------------------------------------------------------
6461 # Warn if a variable is conditionally defined. This is called if we
6462 # are using the value of a variable.
6463 sub check_variable_defined_unconditionally ($$)
6465 my ($var, $parent) = @_;
6466 foreach my $cond (keys %{$var_value{$var}})
6469 if $cond =~ /^TRUE|FALSE$/;
6473 macro_error ($parent,
6474 "warning: automake does not support conditional definition of $var in $parent");
6478 macro_error ($parent,
6479 "warning: automake does not support $var being defined conditionally");
6485 # Get the TRUE value of a variable, warn if the variable is
6486 # conditionally defined.
6490 &check_variable_defined_unconditionally ($var);
6491 return $var_value{$var}{'TRUE'};
6496 # &value_to_list ($VAR, $VAL, $COND)
6497 # ----------------------------------
6498 # Convert a variable value to a list, split as whitespace. This will
6499 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6502 # If COND is 'all', then all values under all conditions should be
6503 # returned; if COND is a particular condition (all conditions are
6504 # surrounded by @...@) then only the value for that condition should
6505 # be returned; otherwise, warn if VAR is conditionally defined.
6506 # SCANNED is a global hash listing whose keys are all the variables
6507 # already scanned; it is an error to rescan a variable.
6508 sub value_to_list ($$$)
6510 my ($var, $val, $cond) = @_;
6514 $val =~ s/\\(\n|$)/ /g;
6516 foreach (split (' ', $val))
6518 # If a comment seen, just leave.
6521 # Handle variable substitutions.
6522 if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
6526 # If the user uses a losing variable name, just ignore it.
6527 # This isn't ideal, but people have requested it.
6528 next if ($varname =~ /\@.*\@/);
6532 if ($varname =~ /$SUBST_REF_PATTERN/o)
6536 $from = quotemeta $2;
6541 variable_value_as_list_recursive_worker ($1, $cond, $var);
6543 # Now rewrite the value if appropriate.
6546 grep (s/$from$/$to/, @temp_list);
6549 push (@result, @temp_list);
6562 # variable_value_as_list ($VAR, $COND, $PARENT)
6563 # ---------------------------------------------
6564 # Get the value of a variable given a specified condition. without
6565 # recursing through any subvariables.
6567 # $VAR is the variable
6568 # $COND is the condition. If this is not given, the value for the
6569 # "TRUE" condition will be returned.
6570 # $PARENT is the variable in which the variable is used: this is used
6571 # only for error messages.
6572 # Returns the list of conditions.
6573 # For example, if A is defined as "foo $(B) bar", and B is defined as
6574 # "baz", this will return ("foo", "$(B)", "bar")
6575 sub variable_value_as_list
6577 my ($var, $cond, $parent) = @_;
6582 unless variable_assert $var, $parent;
6584 # Get value for given condition
6587 foreach my $vcond (keys %{$var_value{$var}})
6589 my $val = $var_value{$var}{$vcond};
6591 if (&conditional_true_when ($vcond, $cond))
6593 # Unless variable is not defined conditionally, there should only
6594 # be one value of $vcond true when $cond.
6595 &check_variable_defined_unconditionally ($var, $parent)
6600 $val =~ s/\\(\n|$)/ /g;
6602 foreach (split (' ', $val))
6604 # If a comment seen, just leave.
6617 # &variable_value_as_list_recursive_worker ($VAR, $COND, $PARENT)
6618 # ---------------------------------------------------------------
6619 # Return contents of VAR as a list, split on whitespace. This will
6620 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6621 # substitutions. If COND is 'all', then all values under all
6622 # conditions should be returned; if COND is a particular condition
6623 # (all conditions are surrounded by @...@) then only the value for
6624 # that condition should be returned; otherwise, warn if VAR is
6625 # conditionally defined. If PARENT is specified, it is the name of
6626 # the including variable; this is only used for error reports.
6627 sub variable_value_as_list_recursive_worker ($$$)
6629 my ($var, $cond, $parent) = @_;
6633 unless variable_assert $var, $parent;
6635 if (defined $vars_scanned{$var})
6637 # `vars_scanned' is a global we use to keep track of which
6638 # variables we've already examined.
6639 macro_error ($parent, "variable `$var' recursively defined");
6641 elsif ($cond eq 'all')
6643 $vars_scanned{$var} = 1;
6644 foreach my $vcond (keys %{$var_value{$var}})
6646 my $val = $var_value{$var}{$vcond};
6647 push (@result, &value_to_list ($var, $val, $cond));
6653 $vars_scanned{$var} = 1;
6655 foreach my $vcond (keys %{$var_value{$var}})
6657 my $val = $var_value{$var}{$vcond};
6658 if (&conditional_true_when ($vcond, $cond))
6660 # Warn if we have an ambiguity. It's hard to know how
6661 # to handle this case correctly.
6662 &check_variable_defined_unconditionally ($var, $parent)
6665 push (@result, &value_to_list ($var, $val, $cond));
6670 # Unset our entry in vars_scanned. We only care about recursive
6672 delete $vars_scanned{$var};
6678 # &variable_output ($VAR, [@CONDS])
6679 # ---------------------------------
6680 # Output all the values of $VAR is @COND is not specified, else only
6681 # that corresponding to @COND.
6682 sub variable_output ($@)
6684 my ($var, @conds) = @_;
6686 @conds = keys %{$var_value{$var}}
6689 $output_vars .= $var_comment{$var}
6690 if defined $var_comment{$var};
6692 foreach my $cond (sort by_condition @conds)
6694 my $val = $var_value{$var}{$cond};
6695 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6696 my $output_var = "$var $equals $val";
6697 $output_var =~ s/^/make_condition ($cond)/meg;
6698 $output_vars .= $output_var . "\n";
6703 # &variable_pretty_output ($VAR, [@CONDS])
6704 # ----------------------------------------
6705 # Likewise, but pretty, i.e., we *split* the values at spaces. Use only
6706 # with variables holding filenames.
6707 sub variable_pretty_output ($@)
6709 my ($var, @conds) = @_;
6711 @conds = keys %{$var_value{$var}}
6714 $output_vars .= $var_comment{$var}
6715 if defined $var_comment{$var};
6717 foreach my $cond (sort by_condition @conds)
6719 my $val = $var_value{$var}{$cond};
6720 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6721 my $make_condition = make_condition ($cond);
6722 $output_vars .= pretty_print_internal ("$make_condition$var $equals",
6723 "$make_condition\t",
6724 split (' ' , $val));
6729 # &variable_value_as_list_recursive ($VAR, $COND, $PARENT)
6730 # --------------------------------------------------------
6731 # This is just a wrapper for variable_value_as_list_recursive_worker that
6732 # initializes the global hash `vars_scanned'. This hash is used to
6733 # avoid infinite recursion.
6734 sub variable_value_as_list_recursive ($$@)
6736 my ($var, $cond, $parent) = @_;
6738 return &variable_value_as_list_recursive_worker ($var, $cond, $parent);
6742 # &define_pretty_variable ($VAR, $COND, @VALUE)
6743 # ---------------------------------------------
6744 # Like define_variable, but the value is a list, and the variable may
6745 # be defined conditionally. The second argument is the conditional
6746 # under which the value should be defined; this should be the empty
6747 # string to define the variable unconditionally. The third argument
6748 # is a list holding the values to use for the variable. The value is
6749 # pretty printed in the output file.
6750 sub define_pretty_variable ($$@)
6752 my ($var, $cond, @value) = @_;
6754 # Beware that an empty $cond has a different semantics for
6755 # macro_define and variable_pretty_output.
6758 if (! variable_defined ($var, $cond))
6760 macro_define ($var, 1, '', $cond, "@value", undef);
6761 variable_pretty_output ($var, $cond || 'TRUE');
6762 $content_seen{$var} = 1;
6767 # define_variable ($VAR, $VALUE)
6768 # ------------------------------
6769 # Define a new user variable VAR to VALUE, but only if not already defined.
6770 sub define_variable ($$)
6772 my ($var, $value) = @_;
6773 define_pretty_variable ($var, 'TRUE', $value);
6777 # Like define_variable, but define a variable to be the configure
6778 # substitution by the same name.
6779 sub define_configure_variable ($)
6782 if (! variable_defined ($var, 'TRUE'))
6784 # A macro defined via configure is a `user' macro -- we should not
6786 macro_define ($var, 0, '', 'TRUE', subst $var, $configure_vars{$var});
6787 variable_pretty_output ($var, 'TRUE');
6792 # define_compiler_variable ($LANG)
6793 # --------------------------------
6794 # Define a compiler variable. We also handle defining the `LT'
6795 # version of the command when using libtool.
6796 sub define_compiler_variable ($)
6800 my ($var, $value) = ($lang->compiler, $lang->compile);
6801 &define_variable ($var, $value);
6802 &define_variable ("LT$var", "\$(LIBTOOL) --mode=compile $value")
6807 # define_linker_variable ($LANG)
6808 # ------------------------------
6809 # Define linker variables.
6810 sub define_linker_variable ($)
6814 my ($var, $value) = ($lang->lder, $lang->ld);
6816 &define_variable ($lang->lder, $lang->ld);
6817 # CCLINK = $(CCLD) blah blah...
6818 &define_variable ($lang->linker,
6819 (($seen_libtool ? '$(LIBTOOL) --mode=link ' : '')
6823 ################################################################
6825 ## ---------------- ##
6826 ## Handling rules. ##
6827 ## ---------------- ##
6830 # rule_define ($TARGET, $IS_AM, $COND, $WHERE)
6831 # --------------------------------------------
6832 # Define a new rule. $TARGET is the rule name. $IS_AM is a boolean
6833 # which is true if the new rule is defined by the user. $COND is the
6834 # condition under which the rule is defined. $WHERE is where the rule
6835 # is defined (file name or line number). Returns true if it is ok to
6836 # define the rule, false otherwise.
6837 sub rule_define ($$$$)
6839 my ($target, $rule_is_am, $cond, $where) = @_;
6841 # For now `foo:' will override `foo$(EXEEXT):'. This is temporary,
6842 # though, so we emit a warning.
6843 (my $noexe = $target) =~ s,\$\(EXEEXT\)$,,;
6844 if ($noexe ne $target && defined $targets{$noexe})
6846 # The no-exeext option enables this feature.
6847 if (! defined $options{'no-exeext'})
6849 macro_error ($noexe,
6850 "deprecated feature: `$noexe' overrides `$noexe\$(EXEEXT)'\nchange your target to read `$noexe\$(EXEEXT)'");
6856 if (defined $targets{$target}
6858 ? ! defined $target_conditional{$target}
6859 : defined $target_conditional{$target}))
6861 target_error ($target,
6862 "$target defined both conditionally and unconditionally");
6865 # Value here doesn't matter; for targets we only note existence.
6866 $targets{$target} = $where;
6869 if ($target_conditional{$target})
6871 &check_ambiguous_conditional ($target, $cond);
6873 $target_conditional{$target}{$cond} = $where;
6876 # Check the rule for being a suffix rule. If so, store in a hash.
6877 # Either it's a rule for two known extensions...
6878 if ($target =~ /^($KNOWN_EXTENSIONS_PATTERN)($KNOWN_EXTENSIONS_PATTERN)$/
6879 # ...or it's a rule with unknown extensions (.i.e, the rule looks like
6880 # `.foo.bar:' but `.foo' or `.bar' are not declared in SUFFIXES
6881 # and are not known language extensions).
6882 # Automake will complete SUFFIXES from @suffixes automatically
6883 # (see handle_footer).
6884 || ($target =~ /$SUFFIX_RULE_PATTERN/o && accept_extensions($1)))
6886 my $internal_ext = $2;
6888 # When tranforming sources to objects, Automake uses the
6889 # %suffix_rules to move from each source extension to
6890 # `.$(OBJEXT)', not to `.o' or `.obj'. However some people
6891 # define suffix rules for `.o' or `.obj', so internally we will
6892 # consider these extensions equivalent to `.$(OBJEXT)'. We
6893 # CANNOT rewrite the target (i.e., automagically replace `.o'
6894 # and `.obj' by `.$(OBJEXT)' in the output), or warn the user
6895 # that (s)he'd better use `.$(OBJEXT)', because Automake itself
6896 # output suffix rules for `.o' or `.obj'...
6897 $internal_ext = '.$(OBJEXT)' if ($2 eq '.o' || $2 eq '.obj');
6899 $suffix_rules{$1} = $internal_ext;
6900 verbose "Sources ending in $1 become $2";
6901 push @suffixes, $1, $2;
6908 # See if a target exists.
6912 return defined $targets{$target};
6916 ################################################################
6918 # &append_comments ($VARIABLE, $SPACING, $COMMENT)
6919 # ------------------------------------------------
6920 # Apped $COMMENT to the other comments for $VARIABLE, using
6921 # $SPACING as separator.
6922 sub append_comments ($$$)
6924 my ($var, $spacing, $comment) = @_;
6925 $var_comment{$var} .= $spacing
6926 if (!defined $var_comment{$var} || $var_comment{$var} !~ /\n$/o);
6927 $var_comment{$var} .= $comment;
6931 # &read_am_file ($AMFILE)
6932 # -----------------------
6933 # Read Makefile.am and set up %contents. Simultaneously copy lines
6934 # from Makefile.am into $output_trailer or $output_vars as
6935 # appropriate. NOTE we put rules in the trailer section. We want
6936 # user rules to come after our generated stuff.
6937 sub read_am_file ($)
6941 my $am_file = new Automake::XFile ("< $amfile");
6942 verbose "reading $amfile";
6949 while ($_ = $am_file->getline)
6951 if (/$IGNORE_PATTERN/o)
6953 # Merely delete comments beginning with two hashes.
6955 elsif (/$WHITE_PATTERN/o)
6957 file_error ("$amfile:$.",
6958 "blank line following trailing backslash")
6960 # Stick a single white line before the incoming macro or rule.
6963 # Flush all comments seen so far.
6966 $output_vars .= $comment;
6970 elsif (/$COMMENT_PATTERN/o)
6972 # Stick comments before the incoming macro or rule. Make
6973 # sure a blank line preceeds first block of comments.
6974 $spacing = "\n" unless $blank;
6976 $comment .= $spacing . $_;
6983 $saw_bk = /\\$/ && ! /$IGNORE_PATTERN/o;
6986 # We save the conditional stack on entry, and then check to make
6987 # sure it is the same on exit. This lets us conditonally include
6989 my @saved_cond_stack = @cond_stack;
6990 my $cond = conditional_string (@cond_stack);
6993 my $last_var_name = '';
6994 my $last_var_type = '';
6995 my $last_var_value = '';
6996 # FIXME: shouldn't use $_ in this loop; it is too big.
6999 my $here = "$amfile:$.";
7001 # Make sure the line is \n-terminated.
7005 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
7006 # used by users. @MAINT@ is an anachronism now.
7007 $_ =~ s/\@MAINT\@//g
7008 unless $seen_maint_mode;
7010 my $new_saw_bk = /\\$/ && ! /$IGNORE_PATTERN/o;
7012 if (/$IGNORE_PATTERN/o)
7014 # Merely delete comments beginning with two hashes.
7016 elsif (/$WHITE_PATTERN/o)
7018 # Stick a single white line before the incoming macro or rule.
7020 file_error ($here, "blank line following trailing backslash")
7023 elsif (/$COMMENT_PATTERN/o)
7025 # Stick comments before the incoming macro or rule.
7026 $comment .= $spacing . $_;
7028 file_error ($here, "comment following trailing backslash")
7029 if $saw_bk && $comment eq '';
7035 $output_trailer .= &make_condition (@cond_stack);
7036 $output_trailer .= $_;
7040 $last_var_value .= ' '
7041 unless $last_var_value =~ /\s$/;
7042 $last_var_value .= $_;
7046 append_comments $last_var_name, $spacing, $comment;
7047 $comment = $spacing = '';
7048 macro_define ($last_var_name, 0,
7049 $last_var_type, $cond,
7050 $last_var_value, $here)
7051 if $cond ne 'FALSE';
7052 push (@var_list, $last_var_name);
7057 elsif (/$IF_PATTERN/o)
7059 $cond = cond_stack_if ($1, $2, $here);
7061 elsif (/$ELSE_PATTERN/o)
7063 $cond = cond_stack_else ($1, $2, $here);
7065 elsif (/$ENDIF_PATTERN/o)
7067 $cond = cond_stack_endif ($1, $2, $here);
7070 elsif (/$RULE_PATTERN/o)
7075 rule_define ($1, 0, $cond, $here);
7077 $output_trailer .= $comment . $spacing;
7078 $output_trailer .= &make_condition (@cond_stack);
7079 $output_trailer .= $_;
7080 $comment = $spacing = '';
7082 elsif (/$ASSIGNMENT_PATTERN/o)
7084 # Found a macro definition.
7086 $last_var_name = $1;
7087 $last_var_type = $2;
7088 $last_var_value = $3;
7089 if ($3 ne '' && substr ($3, -1) eq "\\")
7091 # We preserve the `\' because otherwise the long lines
7092 # that are generated will be truncated by broken
7094 $last_var_value = $3 . "\n";
7099 # FIXME: this doesn't always work correctly; it will
7100 # group all comments for a given variable, no matter
7102 # Accumulating variables must not be output.
7103 append_comments $last_var_name, $spacing, $comment;
7104 $comment = $spacing = '';
7106 macro_define ($last_var_name, 0,
7107 $last_var_type, $cond,
7108 $last_var_value, $here)
7109 if $cond ne 'FALSE';
7110 push (@var_list, $last_var_name);
7113 elsif (/$INCLUDE_PATTERN/o)
7117 if ($path =~ s/^\$\(top_srcdir\)\///)
7119 push (@include_stack, "\$\(top_srcdir\)/$path");
7123 $path =~ s/\$\(srcdir\)\///;
7124 push (@include_stack, "\$\(srcdir\)/$path");
7125 $path = $relative_dir . "/" . $path;
7127 &read_am_file ($path);
7131 # This isn't an error; it is probably a continued rule.
7132 # In fact, this is what we assume.
7134 $output_trailer .= $comment . $spacing;
7135 $output_trailer .= &make_condition (@cond_stack);
7136 $output_trailer .= $_;
7137 $comment = $spacing = '';
7138 file_error ($here, "`#' comment at start of rule is unportable")
7139 if $_ =~ /^\t\s*\#/;
7142 $saw_bk = $new_saw_bk;
7143 $_ = $am_file->getline;
7146 $output_trailer .= $comment;
7148 if ("@saved_cond_stack" ne "@cond_stack")
7152 &am_error ("unterminated conditionals: @cond_stack");
7156 # FIXME: better error message here.
7157 &am_error ("conditionals not nested in include file");
7163 # define_standard_variables ()
7164 # ----------------------------
7165 # A helper for read_main_am_file which initializes configure variables
7166 # and variables from header-vars.am. This is a subr so we can call it
7168 sub define_standard_variables
7170 my $saved_output_vars = $output_vars;
7171 my ($comments, undef, $rules) =
7172 file_contents_internal (1, "$libdir/am/header-vars.am");
7174 # This will output the definitions in $output_vars, which we don't
7176 foreach my $var (sort keys %configure_vars)
7178 &define_configure_variable ($var);
7179 push (@var_list, $var);
7182 # ... hence, we restore $output_vars.
7183 $output_vars = $saved_output_vars . $comments . $rules;
7186 # Read main am file.
7187 sub read_main_am_file
7191 # This supports the strange variable tricks we are about to play.
7192 if (scalar keys %var_value > 0)
7195 prog_error ("variable defined before read_main_am_file");
7198 # Generate copyright header for generated Makefile.in.
7199 # We do discard the output of predefined variables, handled below.
7200 $output_vars = ("# $in_file_name generated by automake "
7201 . $VERSION . " from $am_file_name.\n");
7202 $output_vars .= '# ' . subst ('configure_input') . "\n";
7203 $output_vars .= $gen_copyright;
7205 # We want to predefine as many variables as possible. This lets
7206 # the user set them with `+=' in Makefile.am. However, we don't
7207 # want these initial definitions to end up in the output quite
7208 # yet. So we just load them, but output them later.
7209 &define_standard_variables;
7211 # Read user file, which might override some of our values.
7212 &read_am_file ($amfile);
7214 # Output all the Automake variables. If the user changed one,
7215 # then it is now marked as owned by the user.
7216 foreach my $var (uniq @var_list)
7218 # Don't process user variables.
7219 variable_output ($var)
7220 unless !$var_is_am{$var};
7223 # Now dump the user variables that were defined. We do it in the same
7224 # order in which they were defined (skipping duplicates).
7225 foreach my $var (uniq @var_list)
7227 # Don't process Automake variables.
7228 variable_output ($var)
7229 unless $var_is_am{$var};
7233 ################################################################
7236 # &flatten ($STRING)
7237 # ------------------
7238 # Flatten the $STRING and return the result.
7253 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
7254 # ------------------------------------------
7255 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
7257 sub make_paragraphs ($%)
7259 my ($file, %transform) = @_;
7261 # Complete %transform with global options and make it a Perl
7264 "s/$IGNORE_PATTERN//gm;"
7265 . transform (%transform,
7267 'CYGNUS' => $cygnus_mode,
7269 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
7271 'SHAR' => $options{'dist-shar'} || 0,
7272 'BZIP2' => $options{'dist-bzip2'} || 0,
7273 'ZIP' => $options{'dist-zip'} || 0,
7274 'COMPRESS' => $options{'dist-tarZ'} || 0,
7276 'INSTALL-INFO' => !$options{'no-installinfo'},
7277 'INSTALL-MAN' => !$options{'no-installman'},
7278 'CK-NEWS' => $options{'check-news'} || 0,
7280 'SUBDIRS' => variable_defined ('SUBDIRS'),
7281 'TOPDIR' => backname ($relative_dir),
7282 'TOPDIR_P' => $relative_dir eq '.',
7283 'CONFIGURE-AC' => $configure_ac,
7285 'BUILD' => $seen_canonical == AC_CANONICAL_SYSTEM,
7286 'HOST' => $seen_canonical,
7287 'TARGET' => $seen_canonical == AC_CANONICAL_SYSTEM,
7289 'LIBTOOL' => defined $configure_vars{'LIBTOOL'})
7290 # We don't need more than two consecutive new-lines.
7291 . 's/\n{3,}/\n\n/g';
7293 # Swallow the file and apply the COMMAND.
7294 my $fc_file = new Automake::XFile "< $file";
7296 verbose "reading $file";
7297 my $saved_dollar_slash = $/;
7299 $_ = $fc_file->getline;
7300 $/ = $saved_dollar_slash;
7305 # Split at unescaped new lines.
7306 my @lines = split (/(?<!\\)\n/, $content);
7309 while (defined ($_ = shift @lines))
7311 my $paragraph = "$_";
7312 # If we are a rule, eat as long as we start with a tab.
7313 if (/$RULE_PATTERN/smo)
7315 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
7317 $paragraph .= "\n$_";
7319 unshift (@lines, $_);
7322 # If we are a comments, eat as much comments as you can.
7323 elsif (/$COMMENT_PATTERN/smo)
7325 while (defined ($_ = shift @lines)
7326 && $_ =~ /$COMMENT_PATTERN/smo)
7328 $paragraph .= "\n$_";
7330 unshift (@lines, $_);
7333 push @res, $paragraph;
7342 # ($COMMENT, $VARIABLES, $RULES)
7343 # &file_contents_internal ($IS_AM, $FILE, [%TRANSFORM])
7344 # -----------------------------------------------------
7345 # Return contents of a file from $libdir/am, automatically skipping
7346 # macros or rules which are already known. $IS_AM iff the caller is
7347 # reading an Automake file (as opposed to the user's Makefile.am).
7348 sub file_contents_internal ($$%)
7350 my ($is_am, $file, %transform) = @_;
7352 my $result_vars = '';
7353 my $result_rules = '';
7357 # The following flags are used to track rules spanning across
7358 # multiple paragraphs.
7359 my $is_rule = 0; # 1 if we are processing a rule.
7360 my $discard_rule = 0; # 1 if the current rule should not be output.
7362 # We save the conditional stack on entry, and then check to make
7363 # sure it is the same on exit. This lets us conditonally include
7365 my @saved_cond_stack = @cond_stack;
7366 my $cond = conditional_string (@cond_stack);
7368 foreach (make_paragraphs ($file, %transform))
7371 file_error ($file, "blank line following trailing backslash:\n$_")
7373 file_error ($file, "comment following trailing backslash:\n$_")
7379 # Stick empty line before the incoming macro or rule.
7382 elsif (/$COMMENT_PATTERN/mso)
7385 # Stick comments before the incoming macro or rule.
7389 # Handle inclusion of other files.
7390 elsif (/$INCLUDE_PATTERN/o)
7392 if ($cond ne 'FALSE')
7394 my $file = ($is_am ? "$libdir/am/" : '') . $1;
7396 my ($com, $vars, $rules)
7397 = file_contents_internal ($is_am, $file, %transform);
7399 $result_vars .= $vars;
7400 $result_rules .= $rules;
7404 # Handling the conditionals.
7405 elsif (/$IF_PATTERN/o)
7407 $cond = cond_stack_if ($1, $2, $file);
7409 elsif (/$ELSE_PATTERN/o)
7411 $cond = cond_stack_else ($1, $2, $file);
7413 elsif (/$ENDIF_PATTERN/o)
7415 $cond = cond_stack_endif ($1, $2, $file);
7419 elsif (/$RULE_PATTERN/mso)
7423 # Separate relationship from optional actions: the first
7424 # `new-line tab" not preceded by backslash (continuation
7426 # I'm quite shoked! It seems that (\\\n|[^\n]) is not the
7427 # same as `([^\n]|\\\n)!!! Don't swap it, it breaks.
7429 /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
7430 my ($relationship, $actions) = ($1, $2 || '');
7432 # Separate targets from dependencies: the first colon.
7433 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
7434 my ($targets, $dependencies) = ($1, $2);
7435 # Remove the escaped new lines.
7436 # I don't know why, but I have to use a tmp $flat_deps.
7437 my $flat_deps = &flatten ($dependencies);
7438 my @deps = split (' ', $flat_deps);
7440 foreach (split (' ' , $targets))
7442 # FIXME: We are not robust to people defining several targets
7443 # at once, only some of them being in %dependencies. The
7444 # actions from the targets in %dependencies are usually generated
7445 # from the content of %actions, but if some targets in $targets
7446 # are not in %dependencies the ELSE branch will output
7447 # a rule for all $targets (i.e. the targets which are both
7448 # in %dependencies and $targets will have two rules).
7450 # FIXME: The logic here is not able to output a
7451 # multi-paragraph rule several time (e.g. for each conditional
7452 # it is defined for) because it only knows the first paragraph.
7454 # Output only if not in FALSE.
7455 if (defined $dependencies{$_}
7456 && $cond ne 'FALSE')
7458 &depend ($_, @deps);
7459 $actions{$_} .= $actions;
7463 # Free-lance dependency. Output the rule for all the
7464 # targets instead of one by one.
7466 # Work out all the conditions for which the target hasn't
7468 my @undefined_conds;
7469 if (defined $target_conditional{$targets})
7471 my @defined_conds = keys %{$target_conditional{$targets}};
7472 @undefined_conds = invert_conditions(@defined_conds);
7476 if (defined $targets{$targets})
7478 # No conditions for which target hasn't been defined
7479 @undefined_conds = ();
7483 # Target hasn't been defined for any conditions
7484 @undefined_conds = ("");
7488 if ($cond ne 'FALSE')
7490 for my $undefined_cond (@undefined_conds)
7492 my $condparagraph = $paragraph;
7493 $condparagraph =~ s/^/make_condition (@cond_stack, $undefined_cond)/gme;
7494 if (rule_define ($targets, $is_am,
7495 "$cond $undefined_cond", $file))
7498 "$spacing$comment$condparagraph\n"
7502 # Remember to discard next paragraphs
7503 # if they belong to this rule.
7507 if ($#undefined_conds == -1)
7509 # This target has already been defined, the rule
7510 # has not been defined. Remember to discard next
7511 # paragraphs if they belong to this rule.
7515 $comment = $spacing = '';
7521 elsif (/$ASSIGNMENT_PATTERN/mso)
7523 my ($var, $type, $val) = ($1, $2, $3);
7524 file_error ($file, "macro `$var' with trailing backslash")
7529 # Accumulating variables must not be output.
7530 append_comments $var, $spacing, $comment;
7531 macro_define ($var, $is_am, $type, $cond, $val, $file)
7532 if $cond ne 'FALSE';
7533 push (@var_list, $var);
7535 # If the user has set some variables we were in charge
7536 # of (which is detected by the first reading of
7537 # `header-vars.am'), we must not output them.
7538 $result_vars .= "$spacing$comment$_\n"
7539 if $type ne '+' && $var_is_am{$var} && $cond ne 'FALSE';
7541 $comment = $spacing = '';
7545 # This isn't an error; it is probably some tokens which
7546 # configure is supposed to replace, such as `@SET-MAKE@',
7547 # or some part of a rule cut by an if/endif.
7548 if ($cond ne 'FALSE' && ! ($is_rule && $discard_rule))
7550 s/^/make_condition (@cond_stack)/gme;
7551 $result_rules .= "$spacing$comment$_\n";
7553 $comment = $spacing = '';
7557 if ("@saved_cond_stack" ne "@cond_stack")
7561 &am_error ("unterminated conditionals: @cond_stack");
7565 # FIXME: better error message here.
7566 &am_error ("conditionals not nested in include file");
7570 return ($comment, $result_vars, $result_rules);
7575 # &file_contents ($BASENAME, [%TRANSFORM])
7576 # ----------------------------------------
7577 # Return contents of a file from $libdir/am, automatically skipping
7578 # macros or rules which are already known.
7579 sub file_contents ($%)
7581 my ($basename, %transform) = @_;
7582 my ($comments, $variables, $rules) =
7583 file_contents_internal (1, "$libdir/am/$basename.am", %transform);
7584 return "$comments$variables$rules";
7589 # &transform (%PAIRS)
7590 # -------------------
7591 # Foreach ($TOKEN, $VAL) in %PAIRS produce a replacement expression suitable
7592 # for file_contents which:
7593 # - replaces %$TOKEN% with $VAL,
7594 # - enables/disables ?$TOKEN? and ?!$TOKEN?,
7595 # - replaces %?$TOKEN% with TRUE or FALSE.
7601 while (my ($token, $val) = each %pairs)
7603 $result .= "s/\Q%$token%\E/\Q$val\E/gm;";
7606 $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
7607 $result .= "s/\Q%?$token%\E/TRUE/gm;";
7611 $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
7612 $result .= "s/\Q%?$token%\E/FALSE/gm;";
7620 # &append_exeext ($MACRO)
7621 # -----------------------
7622 # Macro is an Automake magic macro which primary is PROGRAMS, e.g.
7623 # bin_PROGRAMS. Make sure these programs have $(EXEEXT) appended.
7624 sub append_exeext ($)
7628 prog_error "append_exeext ($macro)"
7629 unless $macro =~ /_PROGRAMS$/;
7631 my @conds = variable_conditions_recursive ($macro);
7634 foreach my $cond (@conds)
7636 my @one_binlist = ();
7637 my @condval = variable_value_as_list_recursive ($macro, $cond);
7638 foreach my $rcurs (@condval)
7640 # Skip autoconf substs. Also skip if the user
7641 # already applied $(EXEEXT).
7642 if ($rcurs =~ /^\@.*\@$/ || $rcurs =~ /\$\(EXEEXT\)$/)
7644 push (@one_binlist, $rcurs);
7648 push (@one_binlist, $rcurs . '$(EXEEXT)');
7652 push (@condvals, $cond);
7653 push (@condvals, "@one_binlist");
7656 macro_delete ($macro);
7659 my $cond = shift (@condvals);
7660 my @val = split (' ', shift (@condvals));
7661 define_pretty_variable ($macro, $cond, @val);
7667 # &am_primary_prefixes ($PRIMARY, $CAN_DIST, @PREFIXES)
7668 # -----------------------------------------------------
7669 # Find all variable prefixes that are used for install directories. A
7670 # prefix `zar' qualifies iff:
7672 # * `zardir' is a variable.
7673 # * `zar_PRIMARY' is a variable.
7675 # As a side effect, it looks for misspellings. It is an error to have
7676 # a variable ending in a "reserved" suffix whose prefix is unknown, eg
7677 # "bni_PROGRAMS". However, unusual prefixes are allowed if a variable
7678 # of the same name (with "dir" appended) exists. For instance, if the
7679 # variable "zardir" is defined, then "zar_PROGRAMS" becomes valid.
7680 # This is to provide a little extra flexibility in those cases which
7682 sub am_primary_prefixes ($$@)
7684 my ($primary, $can_dist, @prefixes) = @_;
7687 my %valid = map { $_ => 0 } @prefixes;
7688 $valid{'EXTRA'} = 0;
7689 foreach my $varname (keys %var_value)
7691 # Automake is allowed to define variables that look like they
7692 # are magic variables, such as INSTALL_DATA.
7694 if $var_is_am{$varname};
7696 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
7698 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
7699 if ($dist ne '' && ! $can_dist)
7701 # Note that a configure variable is always legitimate.
7702 # It is natural to name such variables after the
7703 # primary, so we explicitly allow it.
7704 macro_error ($varname,
7705 "invalid variable `$varname': `dist' is forbidden")
7706 if ! exists $configure_vars{$varname};
7708 # A not-explicitely-allowed prefix X is allowed if Xdir
7709 # has been defined and X is not a standard prefix.
7710 elsif (! defined $valid{$X} && (! variable_defined ("${X}dir")
7711 || exists $standard_prefix{$X}))
7713 # Note that a configure variable is always legitimate.
7714 # It is natural to name such variables after the
7715 # primary, so we explicitly allow it.
7716 macro_error ($varname, "invalid variable `$varname'")
7717 if ! exists $configure_vars{$varname};
7721 # Ensure all extended prefixes are actually used.
7722 $valid{"$base$dist$X"} = 1;
7727 # Return only those which are actually defined.
7728 return sort grep { variable_defined ($_ . '_' . $primary) } keys %valid;
7732 # Handle `where_HOW' variable magic. Does all lookups, generates
7733 # install code, and possibly generates code to define the primary
7734 # variable. The first argument is the name of the .am file to munge,
7735 # the second argument is the primary variable (eg HEADERS), and all
7736 # subsequent arguments are possible installation locations. Returns
7737 # list of all values of all _HOW targets.
7739 # FIXME: this should be rewritten to be cleaner. It should be broken
7740 # up into multiple functions.
7742 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7749 my $default_dist = 0;
7752 if ($args[0] eq '-noextra')
7756 elsif ($args[0] eq '-candist')
7760 elsif ($args[0] eq '-defaultdist')
7765 elsif ($args[0] !~ /^-/)
7772 my ($file, $primary, @prefix) = @args;
7774 # Now that configure substitutions are allowed in where_HOW
7775 # variables, it is an error to actually define the primary. We
7776 # allow `JAVA', as it is customarily used to mean the Java
7777 # interpreter. This is but one of several Java hacks. Similarly,
7778 # `PYTHON' is customarily used to mean the Python interpreter.
7779 macro_error ($primary, "`$primary' is an anachronism")
7780 if variable_defined ($primary)
7781 && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7784 # Get the prefixes which are valid and actually used.
7785 @prefix = am_primary_prefixes ($primary, $can_dist, @prefix);
7787 # If a primary includes a configure substitution, then the EXTRA_
7788 # form is required. Otherwise we can't properly do our job.
7790 my $warned_about_extra = 0;
7795 # True if the iteration is the first one. Used for instance to
7796 # output parts of the associated file only once.
7798 foreach my $X (@prefix)
7800 my $nodir_name = $X;
7801 my $one_name = $X . '_' . $primary;
7803 my $strip_subdir = 1;
7804 # If subdir prefix should be preserved, do so.
7805 if ($nodir_name =~ /^nobase_/)
7808 $nodir_name =~ s/^nobase_//;
7811 # If files should be distributed, do so.
7815 $dist_p = (($default_dist && $nodir_name !~ /^nodist_/)
7816 || (! $default_dist && $nodir_name =~ /^dist_/));
7817 $nodir_name =~ s/^(dist|nodist)_//;
7820 # Append actual contents of where_PRIMARY variable to
7822 foreach my $rcurs (&variable_value_as_list_recursive ($one_name, 'all'))
7824 # Skip configure substitutions. Possibly bogus.
7825 if ($rcurs =~ /^\@.*\@$/)
7827 if ($nodir_name eq 'EXTRA')
7829 if (! $warned_about_extra)
7831 $warned_about_extra = 1;
7832 macro_error ($one_name,
7833 "`$one_name' contains configure substitution, but shouldn't");
7836 # Check here to make sure variables defined in
7837 # configure.ac do not imply that EXTRA_PRIMARY
7839 elsif (! defined $configure_vars{$one_name})
7841 $require_extra = $one_name
7848 push (@result, $rcurs);
7851 # A blatant hack: we rewrite each _PROGRAMS primary to include
7853 append_exeext ($one_name)
7854 if $primary eq 'PROGRAMS';
7856 # "EXTRA" shouldn't be used when generating clean targets,
7857 # all, or install targets. We used to warn if EXTRA_FOO was
7858 # defined uselessly, but this was annoying.
7860 if $nodir_name eq 'EXTRA';
7862 if ($nodir_name eq 'check')
7864 push (@check, '$(' . $one_name . ')');
7868 push (@used, '$(' . $one_name . ')');
7871 # Is this to be installed?
7872 my $install_p = $nodir_name ne 'noinst' && $nodir_name ne 'check';
7874 # If so, with install-exec? (or install-data?).
7875 my $exec_p = ($nodir_name =~ /$EXEC_DIR_PATTERN/o);
7877 # Singular form of $PRIMARY.
7878 (my $one_primary = $primary) =~ s/S$//;
7879 $output_rules .= &file_contents ($file,
7882 'PRIMARY' => $primary,
7883 'ONE_PRIMARY' => $one_primary,
7885 'NDIR' => $nodir_name,
7886 'BASE' => $strip_subdir,
7889 'INSTALL' => $install_p,
7890 'DIST' => $dist_p));
7895 # The JAVA variable is used as the name of the Java interpreter.
7896 # The PYTHON variable is used as the name of the Python interpreter.
7897 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7900 define_pretty_variable ($primary, '', @used);
7901 $output_vars .= "\n";
7904 if ($require_extra && ! variable_defined ('EXTRA_' . $primary))
7906 macro_error ($require_extra,
7907 "`$require_extra' contains configure substitution, but `EXTRA_$primary' not defined");
7910 # Push here because PRIMARY might be configure time determined.
7911 push (@all, '$(' . $primary . ')')
7912 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7914 # Make the result unique. This lets the user use conditionals in
7915 # a natural way, but still lets us program lazily -- we don't have
7916 # to worry about handling a particular object more than once.
7917 return uniq (sort @result);
7921 ################################################################
7923 # Each key in this hash is the name of a directory holding a
7924 # Makefile.in. These variables are local to `is_make_dir'.
7926 my $make_dirs_set = 0;
7931 if (! $make_dirs_set)
7933 foreach my $iter (@configure_input_files)
7935 $make_dirs{dirname ($iter)} = 1;
7937 # We also want to notice Makefile.in's.
7938 foreach my $iter (@other_input_files)
7940 if ($iter =~ /Makefile\.in$/)
7942 $make_dirs{dirname ($iter)} = 1;
7947 return defined $make_dirs{$dir};
7950 ################################################################
7952 # This variable is local to the "require file" set of functions.
7953 my @require_file_paths = ();
7955 # If a file name appears as a key in this hash, then it has already
7956 # been checked for. This variable is local to the "require file"
7958 %require_file_found = ();
7961 # &maybe_push_required_file ($DIR, $FILE, $FULLFILE)
7962 # --------------------------------------------------
7963 # See if we want to push this file onto dist_common. This function
7964 # encodes the rules for deciding when to do so.
7965 sub maybe_push_required_file
7967 my ($dir, $file, $fullfile) = @_;
7969 if ($dir eq $relative_dir)
7971 push_dist_common ($file);
7974 elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7976 # If we are doing the topmost directory, and the file is in a
7977 # subdir which does not have a Makefile, then we distribute it
7979 push_dist_common ($fullfile);
7986 # &require_file_internal ($WHERE, $MYSTRICT, @FILES)
7987 # --------------------------------------------------
7988 # Verify that the file must exist in the current directory.
7989 # $MYSTRICT is the strictness level at which this file becomes required.
7991 # Must set require_file_paths before calling this function.
7992 # require_file_paths is set to hold a single directory (the one in
7993 # which the first file was found) before return.
7994 sub require_file_internal ($$@)
7996 my ($where, $mystrict, @files) = @_;
7998 foreach my $file (@files)
8006 my $dangling_sym = 0;
8007 foreach my $dir (@require_file_paths)
8009 $fullfile = $dir . "/" . $file;
8010 $errdir = $dir unless $errdir;
8012 # Use different name for "error filename". Otherwise on
8013 # an error the bad file will be reported as eg
8014 # `../../install-sh' when using the default
8016 $errfile = $errdir . '/' . $file;
8018 if (-l $fullfile && ! -f $fullfile)
8023 elsif (-f $fullfile)
8026 maybe_push_required_file ($dir, $file, $fullfile);
8032 # `--force-missing' only has an effect if `--add-missing' is
8034 if ($found_it && (! $add_missing || ! $force_missing))
8036 # Prune the path list.
8037 @require_file_paths = $save_dir;
8041 # If we've already looked for it, we're done. You might
8042 # wonder why we don't do this before searching for the
8043 # file. If we do that, then something like
8044 # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
8048 next if defined $require_file_found{$file};
8049 $require_file_found{$file} = 1;
8052 if ($strictness >= $mystrict)
8054 if ($dangling_sym && $add_missing)
8062 # Only install missing files according to our desired
8064 my $message = "required file `$errfile' not found";
8069 if (-f ("$libdir/$file"))
8071 # Install the missing file. Symlink if we
8072 # can, copy if we must. Note: delete the file
8073 # first, in case it is a dangling symlink.
8074 $message = "installing `$errfile'";
8075 # Windows Perl will hang if we try to delete a
8076 # file that doesn't exist.
8077 unlink ($errfile) if -f $errfile;
8078 if ($symlink_exists && ! $copy_missing)
8080 if (! symlink ("$libdir/$file", $errfile))
8083 $trailer = "; error while making link: $!";
8086 elsif (system ('cp', "$libdir/$file", $errfile))
8089 $trailer = "\n error while copying";
8093 if (! maybe_push_required_file (dirname ($errfile),
8098 # We have added the file but could not push it
8099 # into DIST_COMMON (probably because this is
8100 # an auxiliary file and we are not processing
8101 # the top level Makefile). This is unfortunate,
8102 # since it means we are using a file which is not
8105 # Get Automake to be run again: on the second
8106 # run the file will be found, and pushed into
8107 # the toplevel DIST_COMMON automatically.
8108 $automake_needs_to_reprocess_all_files = 1;
8112 # Prune the path list.
8113 @require_file_paths = &dirname ($errfile);
8116 # If --force-missing was specified, and we have
8117 # actually found the file, then do nothing.
8119 if $found_it && $force_missing;
8123 file_warning ($where, "$message$trailer");
8127 file_error ($where, "$message$trailer");
8134 # &require_file ($WHERE, $MYSTRICT, @FILES)
8135 # -----------------------------------------
8136 sub require_file ($$@)
8138 my ($where, $mystrict, @files) = @_;
8139 @require_file_paths = $relative_dir;
8140 require_file_internal ($where, $mystrict, @files);
8143 # &require_file_with_macro ($MACRO, $MYSTRICT, @FILES)
8144 # ----------------------------------------------------
8145 sub require_file_with_macro ($$@)
8147 my ($macro, $mystrict, @files) = @_;
8148 require_file ($var_location{$macro}, $mystrict, @files);
8152 # &require_conf_file ($WHERE, $MYSTRICT, @FILES)
8153 # ----------------------------------------------
8154 # Looks in configuration path, as specified by AC_CONFIG_AUX_DIR.
8155 sub require_conf_file ($$@)
8157 my ($where, $mystrict, @files) = @_;
8158 @require_file_paths = @config_aux_path;
8159 require_file_internal ($where, $mystrict, @files);
8160 my $dir = $require_file_paths[0];
8161 @config_aux_path = @require_file_paths;
8162 # Avoid unsightly '/.'s.
8163 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
8167 # &require_conf_file_with_macro ($MACRO, $MYSTRICT, @FILES)
8168 # ---------------------------------------------------------
8169 sub require_conf_file_with_macro ($$@)
8171 my ($macro, $mystrict, @files) = @_;
8172 require_conf_file ($var_location{$macro}, $mystrict, @files);
8175 ################################################################
8177 # &require_build_directory ($DIRECTORY)
8178 # ------------------------------------
8179 # Emit rules to create $DIRECTORY if needed, and return
8180 # the file that any target requiring this directory should be made
8182 sub require_build_directory ($)
8184 my $directory = shift;
8185 my $dirstamp = "$directory/.dirstamp";
8187 # Don't emit the rule twice.
8188 if (! defined $directory_map{$directory})
8190 $directory_map{$directory} = 1;
8192 # Directory must be removed by `make distclean'.
8193 $compile_clean_files{$dirstamp} = DIST_CLEAN;
8195 $output_rules .= ("$dirstamp:\n"
8196 . "\t\@\$(mkinstalldirs) $directory\n"
8197 . "\t\@: > $dirstamp\n");
8203 # &require_build_directory_maybe ($FILE)
8204 # --------------------------------------
8205 # If $FILE lies in a subdirectory, emit a rule to create this
8206 # directory and return the file that $FILE should be made
8207 # dependent upon. Otherwise, just return the empty string.
8208 sub require_build_directory_maybe ($)
8211 my $directory = dirname ($file);
8213 if ($directory ne '.')
8215 return require_build_directory ($directory);
8223 ################################################################
8225 # Push a list of files onto dist_common.
8226 sub push_dist_common
8228 prog_error ("push_dist_common run after handle_dist")
8229 if $handle_dist_run;
8230 macro_define ('DIST_COMMON', 1, '+', '', "@_", '');
8237 $strictness_name = $_[0];
8238 if ($strictness_name eq 'gnu')
8242 elsif ($strictness_name eq 'gnits')
8244 $strictness = GNITS;
8246 elsif ($strictness_name eq 'foreign')
8248 $strictness = FOREIGN;
8252 die "$me: level `$strictness_name' not recognized\n";
8257 ################################################################
8259 # Ensure a file exists.
8265 my $touch = new IO::File (">> $file");
8270 # Glob something. Do this to avoid indentation screwups everywhere we
8271 # want to glob. Gross!
8278 # Remove one level of brackets and strip leading spaces,
8279 # as does m4 to function arguments.
8285 my @letters = split //;
8294 next if $depth == 1;
8299 next if $depth == 0;
8300 # don't count orphan right brackets
8301 $depth = 0 if $depth < 0;
8305 return join '', @result;
8308 ################################################################
8310 # print_error ($LEADER, @ARGS)
8311 # ----------------------------
8312 # Do the work of printing the error message. Join @ARGS with spaces,
8313 # then split at newlines and add $LEADER to each line. Uses `warn' to
8314 # print message. Set exit status.
8317 my ($leader, @args) = @_;
8319 @args = split ("\n", $text);
8320 $text = $leader . join ("\n" . $leader, @args) . "\n";
8326 # Print an error message and set exit status.
8329 print_error ("$me: ${am_file}.am: ", @_);
8333 # &file_error ($FILE, @ARGS)
8334 # --------------------------
8337 my ($file, @args) = @_;
8338 print_error ("$file: ", @args);
8342 # ¯o_error ($MACRO, @ARGS)
8343 # ----------------------------
8344 # Report an error, @ARGS, about $MACRO.
8345 sub macro_error ($@)
8347 my ($macro, @args) = @_;
8348 file_error ($var_location{$macro}, @args);
8352 # &target_error ($TARGET, @ARGS)
8353 # ------------------------------
8354 # Report an error, @ARGS, about the rule $TARGET.
8355 sub target_error ($@)
8357 my ($target, @args) = @_;
8358 file_error ($targets{$target}, @args);
8362 # Like am_error, but while scanning configure.ac.
8365 # FIXME: can run in subdirs.
8366 print_error ("$me: $configure_ac: ", @_);
8369 # &file_warning ($FILE, @ARGS)
8370 # ----------------------------
8371 # Warning message with line number referring to configure.ac.
8372 # Does not affect exit_status
8373 sub file_warning ($@)
8375 my ($file, @args) = @_;
8377 my $saved_exit_status = $exit_status;
8378 my $sig = $SIG{'__WARN__'};
8379 $SIG{'__WARN__'} = 'DEFAULT';
8380 file_error ($file, @args);
8381 $exit_status = $saved_exit_status;
8382 $SIG{'__WARN__'} = $sig;
8385 # Tell user where our aclocal.m4 is, but only once.
8386 sub keyed_aclocal_warning ($)
8389 warn "$me: macro `$key' can be generated by `aclocal'\n";
8392 # Print usage information.
8396 Usage: $0 [OPTION] ... [Makefile]...
8398 Generate Makefile.in for configure from Makefile.am.
8401 --help print this help, then exit
8402 --version print version number, then exit
8403 -v, --verbose verbosely list files processed
8404 --no-force only update Makefile.in's that are out of date
8406 Dependency tracking:
8407 -i, --ignore-deps disable dependency tracking code
8408 --include-deps enable dependency tracking code
8411 --cygnus assume program is part of Cygnus-style tree
8412 --foreign set strictness to foreign
8413 --gnits set strictness to gnits
8414 --gnu set strictness to gnu
8417 -a, --add-missing add missing standard files to package
8418 --libdir=DIR directory storing library files
8419 -c, --copy with -a, copy missing files (default is symlink)
8420 -f, --force-missing force update of standard files
8425 foreach my $iter (sort ((@common_files, @common_sometimes)))
8427 push (@lcomm, $iter) unless $iter eq $last;
8432 print "\nFiles which are automatically distributed, if found:\n";
8433 format USAGE_FORMAT =
8434 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
8435 $four[0], $four[1], $four[2], $four[3]
8437 $~ = "USAGE_FORMAT";
8440 my $rows = int(@lcomm / $cols);
8441 my $rest = @lcomm % $cols;
8452 for (my $y = 0; $y < $rows; $y++)
8454 @four = ("", "", "", "");
8455 for (my $x = 0; $x < $cols; $x++)
8457 last if $y + 1 == $rows && $x == $rest;
8459 my $idx = (($x > $rest)
8460 ? ($rows * $rest + ($rows - 1) * ($x - $rest))
8464 $four[$x] = $lcomm[$idx];
8469 print "\nReport bugs to <bug-automake\@gnu.org>.\n";
8477 # Print version information
8481 automake (GNU $PACKAGE) $VERSION
8482 Written by Tom Tromey <tromey\@redhat.com>.
8484 Copyright 2002 Free Software Foundation, Inc.
8485 This is free software; see the source for copying conditions. There is NO
8486 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.