5 eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
8 # automake - create Makefile.in from Makefile.am
9 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
10 # 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' => "\$",
65 # The file to use when generating rules for this language.
66 # The default is 'depend2'.
69 # Name of the linking variable (LINK).
71 # Content of the linking variable.
74 # Name of the linker variable (LD).
76 # Content of the linker variable ($(CC)).
79 # Flag to specify the output file (-o).
80 'output_flag' => "\$",
83 # This is a subroutine which is called whenever we finally
84 # determine the context in which a source file will be
86 '_target_hook' => "\$");
92 if (defined $self->_finish)
98 sub target_hook ($$$$)
101 if (defined $self->_target_hook)
103 &{$self->_target_hook} (@_);
109 use strict 'vars', 'subs';
110 use Automake::General;
119 # Parameters set by configure. Not to be changed. NOTE: assign
120 # VERSION as string so that eg version 0.30 will print correctly.
121 my $VERSION = "@VERSION@";
122 my $PACKAGE = "@PACKAGE@";
123 my $prefix = "@prefix@";
124 my $libdir = "@datadir@/@PACKAGE@-@APIVERSION@";
126 # Some regular expressions. One reason to put them here is that it
127 # makes indentation work better in Emacs.
129 my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
130 my $WHITE_PATTERN = '^\s*$';
131 my $COMMENT_PATTERN = '^#';
132 my $TARGET_PATTERN='[$a-zA-Z_.@][-.a-zA-Z0-9_(){}/$+@]*';
133 # A rule has three parts: a list of targets, a list of dependencies,
134 # and optionally actions.
136 "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
138 my $SUFFIX_RULE_PATTERN = '^(\.[a-zA-Z0-9_(){}$+@]+)(\.[a-zA-Z0-9_(){}$+@]+)$';
139 # Only recognize leading spaces, not leading tabs. If we recognize
140 # leading tabs here then we need to make the reader smarter, because
141 # otherwise it will think rules like `foo=bar; \' are errors.
142 my $MACRO_PATTERN = '^[A-Za-z0-9_@]+$';
143 my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)$';
144 # This pattern recognizes a Gnits version id and sets $1 if the
145 # release is an alpha release. We also allow a suffix which can be
146 # used to extend the version number with a "fork" identifier.
147 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
148 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?$';
149 my $ELSE_PATTERN = '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
150 my $ENDIF_PATTERN = '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
151 my $PATH_PATTERN='(\w|[/.-])+';
152 # This will pass through anything not of the prescribed form.
153 my $INCLUDE_PATTERN = ('^include\s+'
154 . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
155 . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
156 . '|([^/\$]' . $PATH_PATTERN. '))\s*(#.*)?$');
158 # This handles substitution references like ${foo:.a=.b}.
159 my $SUBST_REF_PATTERN = "^([^:]*):([^=]*)=(.*)\$";
161 # Match `-d' as a command-line argument in a string.
162 my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)";
163 # Directories installed during 'install-exec' phase.
164 my $EXEC_DIR_PATTERN =
165 '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)$'; #'
167 # Constants to define the "strictness" level.
168 use constant FOREIGN => 0;
169 use constant GNU => 1;
170 use constant GNITS => 2;
172 # Values for AC_CANONICAL_*
173 use constant AC_CANONICAL_HOST => 1;
174 use constant AC_CANONICAL_SYSTEM => 2;
176 # Values indicating when something should be cleaned. Right now we
177 # only need to handle `mostly'- and `dist'-clean; add more as
179 use constant MOSTLY_CLEAN => 0;
180 use constant DIST_CLEAN => 1;
183 my @libtool_files = qw(ltmain.sh config.guess config.sub);
184 # ltconfig appears here for compatibility with old versions of libtool.
185 my @libtool_sometimes = qw(ltconfig ltcf-c.sh ltcf-cxx.sh ltcf-gcj.sh);
187 # Commonly found files we look for and automatically include in
190 (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
191 COPYING.LESSER ChangeLog INSTALL NEWS README THANKS TODO acinclude.m4
192 ansi2knr.1 ansi2knr.c compile config.guess config.rpath config.sub
193 configure configure.ac configure.in depcomp elisp-comp
194 install-sh libversion.in mdate-sh missing mkinstalldirs
195 py-compile texinfo.tex ylwrap),
196 @libtool_files, @libtool_sometimes);
198 # Commonly used files we auto-include, but only sometimes.
199 my @common_sometimes =
200 qw(aclocal.m4 acconfig.h config.h.top config.h.bot stamp-vti);
202 # Standard directories from the GNU Coding Standards, and additional
203 # pkg* directories from Automake. Stored in a hash for fast member check.
204 my %standard_prefix =
205 map { $_ => 1 } (qw(bin data exec include info lib libexec lisp
206 localstate man man1 man2 man3 man4 man5 man6
207 man7 man8 man9 oldinclude pkgdatadir
208 pkgincludedir pkglibdir sbin sharedstate
211 # Copyright on generated Makefile.ins.
212 my $gen_copyright = "\
213 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
214 # Free Software Foundation, Inc.
215 # This Makefile.in is free software; the Free Software Foundation
216 # gives unlimited permission to copy and/or distribute it,
217 # with or without modifications, as long as this notice is preserved.
219 # This program is distributed in the hope that it will be useful,
220 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
221 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
222 # PARTICULAR PURPOSE.
225 # These constants are returned by lang_*_rewrite functions.
226 # LANG_SUBDIR means that the resulting object file should be in a
227 # subdir if the source file is. In this case the file name cannot
228 # have `..' components.
230 my $LANG_PROCESS = 1;
233 # These are used when keeping track of whether an object can be built
234 # by two different paths.
235 my $COMPILE_LIBTOOL = 1;
236 my $COMPILE_ORDINARY = 2;
240 ## ---------------------------------- ##
241 ## Variables related to the options. ##
242 ## ---------------------------------- ##
244 # TRUE if we should always generate Makefile.in.
245 my $force_generation = 1;
247 # Strictness level as set on command line.
248 my $default_strictness = GNU;
250 # Name of strictness level, as set on command line.
251 my $default_strictness_name = 'gnu';
253 # This is TRUE if automatic dependency generation code should be
254 # included in generated Makefile.in.
255 my $cmdline_use_dependencies = 1;
257 # This holds our (eventual) exit status. We don't actually exit until
258 # we have processed all input files.
261 # From the Perl manual.
262 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
264 # TRUE if missing standard files should be installed.
267 # TRUE if we should copy missing files; otherwise symlink if possible.
268 my $copy_missing = 0;
270 # TRUE if we should always update files that we know about.
271 my $force_missing = 0;
274 ## ---------------------------------------- ##
275 ## Variables filled during files scanning. ##
276 ## ---------------------------------------- ##
278 # Name of the top autoconf input: `configure.ac' or `configure.in'.
279 my $configure_ac = '';
281 # Files found by scanning configure.ac for LIBOBJS.
284 # True if AM_C_PROTOTYPES appears in configure.ac.
285 my $am_c_prototypes = 0;
287 # Names used in AC_CONFIG_HEADER call.
288 my @config_headers = ();
289 # Where AC_CONFIG_HEADER appears.
290 my $config_header_location;
292 # Directory where output files go. Actually, output files are
293 # relative to this directory.
294 my $output_directory;
296 # List of Makefile.am's to process, and their corresponding outputs.
297 my @input_files = ();
298 my %output_files = ();
300 # Complete list of Makefile.am's that exist.
301 my @configure_input_files = ();
303 # List of files in AC_CONFIG_FILES/AC_OUTPUT without Makefile.am's,
305 my @other_input_files = ();
306 # Where the last AC_CONFIG_FILES/AC_OUTPUT appears.
307 my $ac_config_files_location;
309 # List of directories to search for configure-required files. This
310 # can be set by AC_CONFIG_AUX_DIR.
311 my @config_aux_path = qw(. .. ../..);
312 my $config_aux_dir = '';
313 my $config_aux_dir_set_in_configure_in = 0;
315 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
316 my $seen_gettext = 0;
317 # Where AM_GNU_GETTEXT appears.
318 my $ac_gettext_location;
320 # TRUE if AC_PROG_LEX or AM_PROG_LEX were seen.
321 my $seen_prog_lex = 0;
323 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).
324 my $seen_canonical = 0;
325 my $canonical_location;
327 # Where AC_PROG_LIBTOOL appears.
330 # Where AM_MAINTAINER_MODE appears.
333 # Actual version we've seen.
334 my $package_version = '';
336 # Where version is defined.
337 my $package_version_location;
339 # Where AM_PATH_LISPDIR appears.
340 my $am_lispdir_location;
342 # Where AM_PATH_PYTHON appears.
343 my $pythondir_location;
345 # TRUE if we've seen AC_ENABLE_MULTILIB.
346 my $seen_multilib = 0;
348 # TRUE if we've seen AM_PROG_CC_C_O
351 # Where AM_INIT_AUTOMAKE is called;
352 my $seen_init_automake = 0;
354 # TRUE if we've seen AM_AUTOMAKE_VERSION.
355 my $seen_automake_version = 0;
357 # Hash table of discovered configure substitutions. Keys are names,
358 # values are `FILE:LINE' strings which are used by error message
360 my %configure_vars = ();
362 # This is used to keep track of which variable definitions we are
363 # scanning. It is only used in certain limited ways, but it has to be
364 # global. It is declared just for documentation purposes.
365 my %vars_scanned = ();
367 # TRUE if --cygnus seen.
370 # Hash table of AM_CONDITIONAL variables seen in configure.
371 my %configure_cond = ();
373 # This maps extensions onto language names.
374 my %extension_map = ();
376 # List of the DIST_COMMON files we discovered while reading
378 my $configure_dist_common = '';
380 # This maps languages names onto objects.
383 # List of targets we must always output.
384 # FIXME: Complete, and remove falsely required targets.
385 my %required_targets =
397 # FIXME: Not required, temporary hacks.
398 # Well, actually they are sort of required: the -recursive
399 # targets will run them anyway...
403 'install-data-am' => 1,
404 'install-exec-am' => 1,
405 'installcheck-am' => 1,
411 # This is set to 1 when Automake needs to be run again.
412 # (For instance, this happens when an auxiliary file such as
413 # depcomp is added after the toplevel Makefile.in -- which
414 # should distribute depcomp -- has been generated.)
415 my $automake_needs_to_reprocess_all_files = 0;
417 # Options set via AM_INIT_AUTOMAKE.
418 my $global_options = '';
422 ################################################################
424 ## ------------------------------------------ ##
425 ## Variables reset by &initialize_per_input. ##
426 ## ------------------------------------------ ##
428 # Basename and relative dir of the input file.
432 # Same but wrt Makefile.in.
436 # These two variables are used when generating each Makefile.in.
437 # They hold the Makefile.in until it is ready to be printed.
444 # Suffixes found during a run.
447 # Handling the variables.
450 # - $var_value{$VAR}{$COND} is its value associated to $COND,
451 # - $var_location{$VAR} is where it was defined,
452 # - $var_comment{$VAR} are the comments associated to it.
453 # - $var_type{$VAR} is how it has been defined (`', `+', or `:'),
454 # - $var_is_am{$VAR} is true if the variable is owned by Automake.
461 # This holds a 1 if a particular variable was examined.
464 # This holds the names which are targets. These also appear in
468 # Same as %VAR_VALUE, but for targets.
469 my %target_conditional;
471 # This is the conditional stack.
474 # This holds the set of included files.
477 # This holds a list of directories which we must create at `dist'
478 # time. This is used in some strange scenarios involving weird
479 # AC_OUTPUT commands.
482 # List of dependencies for the obvious targets.
487 # Holds the dependencies of targets which dependencies are factored.
488 # Typically, `.PHONY' will appear in plenty of *.am files, but must
489 # be output once. Arguably all pure dependencies could be subject
490 # to this factorization, but it is not unpleasant to have paragraphs
491 # in Makefile: keeping related stuff altogether.
494 # Holds the factored actions. Tied to %DEPENDENCIES, i.e., filled
495 # only when keys exists in %DEPENDENCIES.
498 # A list of files deleted by `maintainer-clean'.
499 my @maintainer_clean_files;
501 # Keys in this hash table are object files or other files in
502 # subdirectories which need to be removed. This only holds files
503 # which are created by compilations. The value in the hash indicates
504 # when the file should be removed.
505 my %compile_clean_files;
507 # Keys in this hash table are directories where we expect to build a
508 # libtool object. We use this information to decide what directories
510 my %libtool_clean_directories;
512 # Value of `$(SOURCES)', used by tags.am.
514 # Sources which go in the distribution.
517 # This hash maps object file names onto their corresponding source
518 # file names. This is used to ensure that each object is created
519 # by a single source file.
522 # This hash maps object file names onto an integer value representing
523 # whether this object has been built via ordinary compilation or
524 # libtool compilation (the COMPILE_* constants).
525 my %object_compilation_map;
528 # This keeps track of the directories for which we've already
529 # created `.dirstamp' code.
539 # Options from AUTOMAKE_OPTIONS.
542 # Whether or not dependencies are handled. Can be further changed
544 my $use_dependencies;
546 # This is a list of all targets to run during "make dist".
549 # Keys in this hash are the basenames of files which must depend on
550 # ansi2knr. Values are either the empty string, or the directory in
551 # which the ANSI source file appears; the directory must have a
555 # This maps the source extension of a suffix rule to its
556 # corresponding output extension.
557 # FIXME: because this hash maps one input extension to one output
558 # extension, Automake cannot handle two suffix rules with the same
562 # This is the name of the redirect `all' target to use.
565 # This keeps track of which extensions we've seen (that we care
569 # This is random scratch space for the language finish functions.
570 # Don't randomly overwrite it; examine other uses of keys first.
571 my %language_scratch;
573 # We keep track of which objects need special (per-executable)
574 # handling on a per-language basis.
575 my %lang_specific_files;
577 # This is set when `handle_dist' has finished. Once this happens,
578 # we should no longer push on dist_common.
581 # Used to store a set of linkers needed to generate the sources currently
582 # under consideration.
585 # True if we need `LINK' defined. This is a hack.
588 # This is the list of such variables to output.
589 # FIXME: Might be useless actually.
592 # Was get_object_extension run?
593 # FIXME: This is a hack. a better switch should be found.
594 my $get_object_extension_was_run;
596 # Contains a stack of `from' parts of variable substitutions currently in
600 # Contains a stack of `to' parts of variable substitutions currently in
604 # If a file name appears as a key in this hash, then it has already
605 # been checked for. This variable is local to the "require file"
607 my %require_file_found = ();
609 # This keeps track of all variables defined by subobjname.
610 # The value stored is the variable names.
611 # The key has the form "(COND1)VAL1(COND2)VAL2..." where VAL1 and VAL2
612 # are the values of the variable for condition COND1 and COND2.
615 # This hash records helper variables used to implement '+=' in conditionals.
616 # Keys have the form "VAR:CONDITIONS". The value associated to a key is
617 # the named of the helper variable used to append to VAR in CONDITIONS.
620 ## --------------------------------- ##
621 ## Forward subroutine declarations. ##
622 ## --------------------------------- ##
623 sub register_language (%);
624 sub file_contents_internal ($$%);
625 sub define_objects_from_sources ($$$$$$$);
628 # &initialize_per_input ()
629 # ------------------------
630 # (Re)-Initialize per-Makefile.am variables.
631 sub initialize_per_input ()
634 $am_relative_dir = '';
641 $output_trailer = '';
657 %target_conditional = ();
679 # Installing/uninstalling.
680 'install-data-am' => [],
681 'install-exec-am' => [],
682 'uninstall-am' => [],
685 'uninstall-man' => [],
687 'install-info' => [],
688 'install-info-am' => [],
689 'uninstall-info' => [],
691 'installcheck-am' => [],
695 'mostlyclean-am' => [],
696 'maintainer-clean-am' => [],
697 'distclean-am' => [],
700 'maintainer-clean' => [],
711 @maintainer_clean_files = ();
717 %object_compilation_map = ();
723 $strictness = $default_strictness;
724 $strictness_name = $default_strictness_name;
728 $use_dependencies = $cmdline_use_dependencies;
738 %extension_seen = ();
740 %language_scratch = ();
742 %lang_specific_files = ();
744 $handle_dist_run = 0;
750 $get_object_extension_was_run = 0;
752 %compile_clean_files = ();
754 # We always include `.'. This isn't strictly correct.
755 %libtool_clean_directories = ('.' => 1);
757 %require_file_found = ();
765 ################################################################
767 # Initialize our list of languages that are internally supported.
770 register_language ('name' => 'c',
772 'config_vars' => ['CC'],
776 'compiler' => 'COMPILE',
777 'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
781 'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
782 'compile_flag' => '-c',
783 'extensions' => ['.c'],
784 '_finish' => \&lang_c_finish);
787 register_language ('name' => 'cxx',
789 'config_vars' => ['CXX'],
790 'linker' => 'CXXLINK',
791 'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
793 'flags' => 'CXXFLAGS',
794 'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
795 'compiler' => 'CXXCOMPILE',
796 'compile_flag' => '-c',
797 'output_flag' => '-o',
801 'extensions' => ['.c++', '.cc', '.cpp', '.cxx', '.C']);
804 register_language ('name' => 'objc',
805 'Name' => 'Objective C',
806 'config_vars' => ['OBJC'],
807 'linker' => 'OBJCLINK',,
808 'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
810 'flags' => 'OBJCFLAGS',
811 'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
812 'compiler' => 'OBJCCOMPILE',
813 'compile_flag' => '-c',
814 'output_flag' => '-o',
818 'extensions' => ['.m']);
821 register_language ('name' => 'header',
823 'extensions' => ['.h', '.H', '.hxx', '.h++', '.hh',
826 '_finish' => sub { });
829 register_language ('name' => 'yacc',
831 'config_vars' => ['YACC'],
833 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
834 'compiler' => 'YACCCOMPILE',
835 'extensions' => ['.y'],
836 'rule_file' => 'yacc',
837 '_finish' => \&lang_yacc_finish,
838 '_target_hook' => \&lang_yacc_target_hook);
839 register_language ('name' => 'yaccxx',
840 'Name' => 'Yacc (C++)',
841 'config_vars' => ['YACC'],
842 'rule_file' => 'yacc',
844 'compiler' => 'YACCCOMPILE',
845 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
846 'extensions' => ['.y++', '.yy', '.yxx', '.ypp'],
847 '_finish' => \&lang_yacc_finish,
848 '_target_hook' => \&lang_yacc_target_hook);
851 register_language ('name' => 'lex',
853 'config_vars' => ['LEX'],
854 'rule_file' => 'lex',
856 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
857 'compiler' => 'LEXCOMPILE',
858 'extensions' => ['.l'],
859 '_finish' => \&lang_lex_finish);
860 register_language ('name' => 'lexxx',
861 'Name' => 'Lex (C++)',
862 'config_vars' => ['LEX'],
863 'rule_file' => 'lex',
865 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
866 'compiler' => 'LEXCOMPILE',
867 'extensions' => ['.l++', '.ll', '.lxx', '.lpp'],
868 '_finish' => \&lang_lex_finish);
871 register_language ('name' => 'asm',
872 'Name' => 'Assembler',
873 'config_vars' => ['CCAS', 'CCASFLAGS'],
875 'flags' => 'CCASFLAGS',
876 # Users can set AM_ASFLAGS to includes DEFS, INCLUDES,
877 # or anything else required. They can also set AS.
878 'compile' => '$(CCAS) $(AM_CCASFLAGS) $(CCASFLAGS)',
879 'compiler' => 'CCASCOMPILE',
880 'compile_flag' => '-c',
881 'extensions' => ['.s', '.S'],
883 # With assembly we still use the C linker.
884 '_finish' => \&lang_c_finish);
887 register_language ('name' => 'f77',
888 'Name' => 'Fortran 77',
889 'linker' => 'F77LINK',
890 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
892 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
893 'compiler' => 'F77COMPILE',
894 'compile_flag' => '-c',
895 'output_flag' => '-o',
899 'extensions' => ['.f', '.for', '.f90']);
901 # Preprocessed Fortran 77
903 # The current support for preprocessing Fortran 77 just involves
904 # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
905 # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
906 # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
907 # for `make' Version 3.76 Beta' (specifically, from info file
908 # `(make)Catalogue of Rules').
910 # A better approach would be to write an Autoconf test
911 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
912 # Fortran 77 compilers know how to do preprocessing. The Autoconf
913 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
914 # preprocessing capabilities, and then fall back on cpp (if cpp were
916 register_language ('name' => 'ppf77',
917 'Name' => 'Preprocessed Fortran 77',
918 'config_vars' => ['F77'],
919 'linker' => 'F77LINK',
920 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
924 'compiler' => 'PPF77COMPILE',
925 'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
926 'compile_flag' => '-c',
927 'output_flag' => '-o',
929 'extensions' => ['.F']);
932 register_language ('name' => 'ratfor',
934 'config_vars' => ['F77'],
935 'linker' => 'F77LINK',
936 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
941 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
942 'compiler' => 'RCOMPILE',
943 'compile_flag' => '-c',
944 'output_flag' => '-o',
946 'extensions' => ['.r']);
949 register_language ('name' => 'java',
951 'config_vars' => ['GCJ'],
952 'linker' => 'GCJLINK',
953 'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
955 'flags' => 'GCJFLAGS',
956 'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
957 'compiler' => 'GCJCOMPILE',
958 'compile_flag' => '-c',
959 'output_flag' => '-o',
963 'extensions' => ['.java', '.class', '.zip', '.jar']);
965 ################################################################
967 # Parse command line.
970 # Do configure.ac scan only once.
971 &scan_autoconf_files;
973 die "$me: no `Makefile.am' found or specified\n"
976 my $automake_has_run = 0;
980 if ($automake_has_run)
982 print "$me: processing Makefiles another time to fix them up.\n";
983 &prog_error ("running more than two times should never be needed.")
984 if $automake_has_run >= 2;
986 $automake_needs_to_reprocess_all_files = 0;
988 # Now do all the work on each file.
989 # This guy must be local otherwise it's private to the loop.
992 foreach $am_file (@input_files)
994 if (! -f ($am_file . '.am'))
996 &am_error ("`" . $am_file . ".am' does not exist");
1000 &generate_makefile ($output_files{$am_file}, $am_file);
1003 ++$automake_has_run;
1005 while ($automake_needs_to_reprocess_all_files);
1009 ################################################################
1011 # prog_error (@PRINT-ME)
1012 # ----------------------
1013 # Signal a programming error, display PRINT-ME, and exit 1.
1016 print STDERR "$me: programming error: @_\n";
1023 # Return a configure-style substitution using the indicated text.
1024 # We do this to avoid having the substitutions directly in automake.in;
1025 # when we do that they are sometimes removed and this causes confusion
1030 return '@' . $text . '@';
1033 ################################################################
1037 # &backname ($REL-DIR)
1038 # --------------------
1039 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
1040 # For instance `src/foo' => `../..'.
1041 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
1046 foreach (split (/\//, $file))
1048 next if $_ eq '.' || $_ eq '';
1058 return join ('/', @res) || '.';
1061 ################################################################
1063 # Pattern that matches all know input extensions (i.e. extensions used
1064 # by the languages supported by Automake). Using this pattern
1065 # (instead of `\..*$') to match extensions allows Automake to support
1066 # dot-less extensions.
1067 my $KNOWN_EXTENSIONS_PATTERN = "";
1068 my @known_extensions_list = ();
1070 # accept_extensions (@EXTS)
1071 # -------------------------
1072 # Update $KNOWN_EXTENSIONS_PATTERN to recognize the extensions
1073 # listed @EXTS. Extensions should contain a dot if needed.
1074 sub accept_extensions (@)
1076 push @known_extensions_list, @_;
1077 $KNOWN_EXTENSIONS_PATTERN =
1078 '(?:' . join ('|', map (quotemeta, @known_extensions_list)) . ')';
1081 # var_SUFFIXES_trigger ($TYPE, $VALUE)
1082 # ------------------------------------
1083 # This is called automagically by define_macro() when SUFFIXES
1084 # is defined ($TYPE eq '') or appended ($TYPE eq '+').
1085 # The work here needs to be performed as a side-effect of the
1086 # define_macro() call because SUFFIXES definitions impact
1087 # on $KNOWN_EXTENSIONS_PATTERN, and $KNOWN_EXTENSIONS_PATTERN
1088 # are used when parsing the input am file.
1089 sub var_SUFFIXES_trigger ($$)
1091 my ($type, $value) = @_;
1092 accept_extensions (split (' ', $value));
1095 ################################################################
1097 # Parse command line.
1098 sub parse_arguments ()
1101 &set_strictness ('gnu');
1104 Getopt::Long::config ("bundling", "pass_through");
1105 Getopt::Long::GetOptions
1107 'version' => \&version,
1109 'libdir:s' => \$libdir,
1110 'gnu' => sub { &set_strictness ('gnu'); },
1111 'gnits' => sub { &set_strictness ('gnits'); },
1112 'cygnus' => \$cygnus_mode,
1113 'foreign' => sub { &set_strictness ('foreign'); },
1114 'include-deps' => sub { $cmdline_use_dependencies = 1; },
1115 'i|ignore-deps' => sub { $cmdline_use_dependencies = 0; },
1116 'no-force' => sub { $force_generation = 0; },
1117 'f|force-missing'=> \$force_missing,
1118 'o|output-dir:s' => \$output_directory,
1119 'a|add-missing' => \$add_missing,
1120 'c|copy' => \$copy_missing,
1121 'v|verbose' => \$verbose,
1122 'Werror' => sub { $SIG{"__WARN__"} = sub { die $_[0] } },
1123 'Wno-error' => sub { $SIG{"__WARN__"} = 'DEFAULT' }
1127 if (defined $output_directory)
1129 print STDERR "$0: `--output-dir' is deprecated\n";
1133 # In the next release we'll remove this entirely.
1134 $output_directory = '.';
1137 foreach my $arg (@ARGV)
1141 print STDERR "$0: unrecognized option `$arg'\n";
1142 print STDERR "Try `$0 --help' for more information.\n";
1146 # Handle $local:$input syntax. Note that we only examine the
1147 # first ":" file to see if it is automake input; the rest are
1148 # just taken verbatim. We still keep all the files around for
1149 # dependency checking, however.
1150 my ($local, $input, @rest) = split (/:/, $arg);
1157 # Strip .in; later on .am is tacked on. That is how the
1158 # automake input file is found. Maybe not the best way, but
1159 # it is easy to explain.
1161 or die "$me: invalid input file name `$arg'\n.";
1163 push (@input_files, $input);
1164 $output_files{$input} = join (':', ($local, @rest));
1167 # Take global strictness from whatever we currently have set.
1168 $default_strictness = $strictness;
1169 $default_strictness_name = $strictness_name;
1172 ################################################################
1174 # Generate a Makefile.in given the name of the corresponding Makefile and
1175 # the name of the file output by config.status.
1176 sub generate_makefile
1178 my ($output, $makefile) = @_;
1180 # Reset all the Makefile.am related variables.
1181 &initialize_per_input;
1183 # Name of input file ("Makefile.am") and output file
1184 # ("Makefile.in"). These have no directory components.
1185 $am_file_name = basename ($makefile) . '.am';
1186 $in_file_name = basename ($makefile) . '.in';
1188 # $OUTPUT is encoded. If it contains a ":" then the first element
1189 # is the real output file, and all remaining elements are input
1190 # files. We don't scan or otherwise deal with these input file,
1191 # other than to mark them as dependencies. See
1192 # &scan_autoconf_files for details.
1193 my (@secondary_inputs);
1194 ($output, @secondary_inputs) = split (/:/, $output);
1196 $relative_dir = dirname ($output);
1197 $am_relative_dir = dirname ($makefile);
1199 &read_main_am_file ($makefile . '.am');
1200 if (&handle_options)
1202 # Fatal error. Just return, so we can continue with next file.
1206 # There are a few install-related variables that you should not define.
1207 foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
1209 if (variable_defined ($var) && !$var_is_am{$var})
1211 macro_error ($var, "`$var' should not be defined");
1215 # At the toplevel directory, we might need config.guess, config.sub
1216 # or libtool scripts (ltconfig and ltmain.sh).
1217 if ($relative_dir eq '.')
1219 # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1221 require_conf_file ($canonical_location, FOREIGN,
1222 'config.guess', 'config.sub')
1226 # We still need Makefile.in here, because sometimes the `dist'
1227 # target doesn't re-run automake.
1228 if ($am_relative_dir eq $relative_dir)
1230 # Only distribute the files if they are in the same subdir as
1231 # the generated makefile.
1232 &push_dist_common ($in_file_name, $am_file_name);
1235 push (@sources, '$(SOURCES)')
1236 if variable_defined ('SOURCES');
1238 # Must do this after reading .am file. See read_main_am_file to
1239 # understand weird tricks we play there with variables.
1240 &define_variable ('subdir', $relative_dir);
1242 # Check first, because we might modify some state.
1244 &check_gnu_standards;
1245 &check_gnits_standards;
1247 &handle_configure ($output, $makefile, @secondary_inputs);
1250 &handle_ltlibraries;
1254 # This must run first so that the ANSI2KNR definition is generated
1255 # before it is used by the _.c rules. We have to do this because
1256 # a variable which is used in a dependency must be defined before
1257 # the target, or else make won't properly see it.
1259 # This must be run after all the sources are scanned.
1262 # We have to run this after dealing with all the programs.
1265 # Re-init SOURCES. FIXME: other code shouldn't depend on this
1266 # (but currently does).
1267 macro_define ('SOURCES', 1, '', 'TRUE', "@sources", 'internal');
1268 define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
1280 &handle_minor_options;
1283 # This must come after most other rules.
1284 &handle_dist ($makefile);
1287 &do_check_merge_target;
1288 &handle_all ($output);
1291 if (variable_defined ('lib_LTLIBRARIES') &&
1292 variable_defined ('bin_PROGRAMS'))
1294 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
1297 &handle_installdirs;
1299 &handle_factored_dependencies;
1303 if (! -d ($output_directory . '/' . $am_relative_dir))
1305 mkdir ($output_directory . '/' . $am_relative_dir, 0755);
1308 my ($out_file) = $output_directory . '/' . $makefile . ".in";
1309 if (! $force_generation && -e $out_file)
1311 my ($am_time) = (stat ($makefile . '.am'))[9];
1312 my ($in_time) = (stat ($out_file))[9];
1313 # FIXME: should cache these times.
1314 my ($conf_time) = (stat ($configure_ac))[9];
1315 # FIXME: how to do unsigned comparison?
1316 if ($am_time < $in_time || $am_time < $conf_time)
1318 # No need to update.
1321 if (-f 'aclocal.m4')
1323 my ($acl_time) = (stat _)[9];
1324 return if ($am_time < $acl_time);
1331 or die "$me: cannot remove $out_file: $!\n";
1333 my $gm_file = new Automake::XFile "> $out_file";
1334 verbose "creating ", $makefile, ".in";
1336 print $gm_file $output_vars;
1337 # We make sure that `all:' is the first target.
1338 print $gm_file $output_all;
1339 print $gm_file $output_header;
1340 print $gm_file $output_rules;
1341 print $gm_file $output_trailer;
1344 ################################################################
1346 # A version is a string that looks like
1347 # MAJOR.MINOR[.MICRO][ALPHA][-FORK]
1349 # MAJOR, MINOR, and MICRO are digits, ALPHA is a character, and
1350 # FORK any alphanumeric word.
1351 # Usually, ALPHA is used to label alpha releases or intermediate snapshots,
1352 # FORK is used for CVS branches or patched releases, and MICRO is used
1353 # for bug fixes releases on the MAJOR.MINOR branch.
1355 # For the purpose of ordering, 1.4 is the same as 1.4.0, but 1.4g is
1356 # the same as 1.4.99g. The FORK identifier is ignored in the
1357 # ordering, except when it looks like -pMINOR[ALPHA]: some versions
1358 # were labelled like 1.4-p3a, this is the same as an alpha release
1359 # labelled 1.4.3a. Yes it's horrible, but Automake did not support
1360 # two-dot versions in the past.
1362 # version_split (VERSION)
1363 # -----------------------
1364 # Split a version string into the corresponding (MAJOR, MINOR, MICRO,
1365 # ALPHA, FORK) tuple. For instance "1.4g" would be split into
1366 # (1, 4, 99, 'g', '').
1367 # Return () on error.
1368 sub version_split ($)
1372 # Special case for versions like 1.4-p2a.
1373 if ($ver =~ /^(\d+)\.(\d+)(?:-p(\d+)([a-z]+)?)$/)
1375 return ($1, $2, $3, $4 || '', '');
1378 elsif ($ver =~ /^(\d+)\.(\d+)(?:\.(\d+))?([a-z])?(?:-([A-Za-z0-9]+))?$/)
1380 return ($1, $2, $3 || (defined $4 ? 99 : 0), $4 || '', $5 || '');
1385 # version_compare (\@LVERSION, \@RVERSION)
1386 # ----------------------------------------
1387 # Return 1 if LVERSION > RVERSION,
1388 # -1 if LVERSION < RVERSION,
1389 # 0 if LVERSION = RVERSION.
1390 sub version_compare (\@\@)
1397 return 1 if ($l[$i] > $r[$i]);
1398 return -1 if ($l[$i] < $r[$i]);
1402 return 1 if ($l[$i] gt $r[$i]);
1403 return -1 if ($l[$i] lt $r[$i]);
1408 # Handles the logic of requiring a version number in AUTOMAKE_OPTIONS.
1409 # Return 0 if the required version is satisfied, 1 otherwise.
1410 sub version_check ($)
1412 my ($required) = @_;
1413 my @version = version_split $VERSION;
1414 my @required = version_split $required;
1416 prog_error ("version is incorrect: $VERSION")
1419 # This should not happen, because process_option_list and split_version
1420 # use similar regexes.
1421 prog_error ("required version is incorrect: $required")
1422 if $#required == -1;
1424 # If we require 3.4n-foo then we require something
1425 # >= 3.4n, with the `foo' fork identifier.
1427 if ($required[4] ne '' && $required[4] ne $version[4]);
1429 return 0 > version_compare @version, @required;
1433 # process_option_list ($CONFIG, @OPTIONS)
1434 # ------------------------------
1435 # Process a list of options. Return 1 on error, 0 otherwise.
1436 # This is a helper for handle_options. CONFIG is true if we're
1437 # handling global options.
1438 sub process_option_list
1440 my ($config, @list) = @_;
1444 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
1446 &set_strictness ($_);
1448 elsif ($_ eq 'cygnus')
1452 elsif (/^(.*\/)?ansi2knr$/)
1454 # An option like "../lib/ansi2knr" is allowed. With no
1455 # path prefix, we assume the required programs are in this
1456 # directory. We save the actual option for later.
1457 $options{'ansi2knr'} = $_;
1459 elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
1460 || $_ eq 'dist-shar' || $_ eq 'dist-zip'
1461 || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
1462 || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
1463 || $_ eq 'readme-alpha' || $_ eq 'check-news'
1464 || $_ eq 'subdir-objects' || $_ eq 'nostdinc'
1465 || $_ eq 'no-exeext' || $_ eq 'no-define')
1467 # Explicitly recognize these.
1469 elsif ($_ eq 'no-dependencies')
1471 $use_dependencies = 0;
1473 elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/)
1475 # Got a version number.
1476 if (version_check $&)
1480 file_error ($seen_init_automake,
1481 "require version $_, but have $VERSION");
1482 # Arrange to process this global option only once, otherwise
1483 # the error message would be printed for each Makefile.
1484 $global_options =~ s/(?:^| )$_(?: |$)/ /g;
1488 macro_error ('AUTOMAKE_OPTIONS',
1489 "require version $_, but have $VERSION");
1498 file_error ($seen_init_automake,
1499 "option `" . $_ . "\' not recognized");
1503 macro_error ('AUTOMAKE_OPTIONS',
1504 "option `" . $_ . "\' not recognized");
1511 # Handle AUTOMAKE_OPTIONS variable. Return 1 on error, 0 otherwise.
1514 # Process global options first so that more specific options can
1516 if (&process_option_list (1, split (' ', $global_options)))
1521 if (variable_defined ('AUTOMAKE_OPTIONS'))
1523 if (&process_option_list (0, &variable_value_as_list_recursive ('AUTOMAKE_OPTIONS', '')))
1529 if ($strictness == GNITS)
1531 $options{'readme-alpha'} = 1;
1532 $options{'check-news'} = 1;
1539 # get_object_extension ($OUT)
1540 # ---------------------------
1541 # Return object extension. Just once, put some code into the output.
1542 # OUT is the name of the output file
1543 sub get_object_extension
1547 # Maybe require libtool library object files.
1548 my $extension = '.$(OBJEXT)';
1549 $extension = '.lo' if ($out =~ /\.la$/);
1551 # Check for automatic de-ANSI-fication.
1552 $extension = '$U' . $extension
1553 if defined $options{'ansi2knr'};
1555 $get_object_extension_was_run = 1;
1561 # Call finish function for each language that was used.
1562 sub handle_languages
1564 if ($use_dependencies)
1566 # Include auto-dep code. Don't include it if DEP_FILES would
1568 if (&saw_sources_p (0) && keys %dep_files)
1570 # Set location of depcomp.
1571 &define_variable ('depcomp', "\$(SHELL) $config_aux_dir/depcomp");
1572 &define_variable ('am__depfiles_maybe', 'depfiles');
1574 require_conf_file ("$am_file.am", FOREIGN, 'depcomp');
1576 my @deplist = sort keys %dep_files;
1578 # We define this as a conditional variable because BSD
1579 # make can't handle backslashes for continuing comments on
1580 # the following line.
1581 define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
1583 # Generate each `include' individually. Irix 6 make will
1584 # not properly include several files resulting from a
1585 # variable expansion; generating many separate includes
1587 $output_rules .= "\n";
1588 foreach my $iter (@deplist)
1590 $output_rules .= (subst ('AMDEP_TRUE')
1591 . subst ('am__include')
1593 . subst ('am__quote')
1595 . subst ('am__quote')
1599 # Compute the set of directories to remove in distclean-depend.
1600 my @depdirs = uniq (map { dirname ($_) } @deplist);
1601 $output_rules .= &file_contents ('depend',
1602 DEPDIRS => "@depdirs");
1607 &define_variable ('depcomp', '');
1608 &define_variable ('am__depfiles_maybe', '');
1613 # Is the c linker needed?
1615 foreach my $ext (sort keys %extension_seen)
1617 next unless $extension_map{$ext};
1619 my $lang = $languages{$extension_map{$ext}};
1621 my $rule_file = $lang->rule_file || 'depend2';
1623 # Get information on $LANG.
1624 my $pfx = $lang->autodep;
1625 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1627 my $AMDEP = (($use_dependencies && $lang->autodep ne 'no')
1628 ? 'AMDEP' : 'FALSE');
1630 my %transform = ('EXT' => $ext,
1633 'LIBTOOL' => defined $seen_libtool,
1635 '-c' => $lang->compile_flag || '',
1637 => (count_files_for_language ($lang->name) > 1));
1639 # Generate the appropriate rules for this extension.
1640 if (($use_dependencies && $lang->autodep ne 'no')
1641 || defined $lang->compile)
1643 # Some C compilers don't support -c -o. Use it only if really
1645 my $output_flag = $lang->output_flag || '';
1648 && $lang->flags eq 'CFLAGS'
1649 && defined $options{'subdir-objects'});
1651 # FIXME: this is a temporary hack to compute a possible
1652 # derived extension. This is not used by depend2.am.
1653 (my $der_ext = $ext) =~ tr/yl/cc/;
1655 # Another yacc/lex hack.
1656 my $destfile = '$*' . $der_ext;
1659 file_contents ($rule_file,
1663 'DERIVED-EXT' => $der_ext,
1665 # In this situation we know that the
1666 # object is in this directory, so
1667 # $(DEPDIR) is the correct location for
1669 'DEPBASE' => '$(DEPDIR)/$*',
1676 'COMPILE' => '$(' . $lang->compiler . ')',
1677 'LTCOMPILE' => '$(LT' . $lang->compiler . ')',
1678 '-o' => $output_flag);
1681 # Now include code for each specially handled object with this
1683 my %seen_files = ();
1684 foreach my $file (@{$lang_specific_files{$lang->name}})
1686 my ($derived, $source, $obj, $myext) = split (' ', $file);
1688 # For any specially-generated object, we must respect the
1689 # ansi2knr setting so that we don't inadvertently try to
1690 # use the default rule.
1691 if ($lang->ansi && defined $options{'ansi2knr'})
1693 $myext = '$U' . $myext;
1696 # We might see a given object twice, for instance if it is
1697 # used under different conditions.
1698 next if defined $seen_files{$obj};
1699 $seen_files{$obj} = 1;
1701 my $flags = $lang->flags || '';
1702 my $val = "${derived}_${flags}";
1704 prog_error ("found $lang->name in handle_languages, but compiler not defined")
1705 unless defined $lang->compile;
1707 (my $obj_compile = $lang->compile) =~ s/\(AM_$flags/\($val/;
1708 my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
1710 # We _need_ `-o' for per object rules.
1711 my $output_flag = $lang->output_flag || '-o';
1713 my $depbase = dirname ($obj);
1717 unless $depbase eq '';
1718 $depbase .= '$(DEPDIR)/' . basename ($obj);
1720 # Generate a transform which will turn suffix targets in
1721 # depend2.am into real targets for the particular objects we
1724 file_contents ($rule_file,
1728 'DEPBASE' => $depbase,
1730 'SOURCE' => $source,
1731 # Use $myext and not `.o' here, in case
1732 # we are actually building a new source
1733 # file -- e.g. via yacc.
1734 'OBJ' => "$obj$myext",
1735 'OBJOBJ' => "$obj.obj",
1736 'LTOBJ' => "$obj.lo",
1738 'COMPILE' => $obj_compile,
1739 'LTCOMPILE' => $obj_ltcompile,
1740 '-o' => $output_flag));
1743 # The rest of the loop is done once per language.
1744 next if defined $done{$lang};
1747 # Load the language dependent Makefile chunks.
1748 my %lang = map { uc ($_) => 0 } keys %languages;
1749 $lang{uc ($lang->name)} = 1;
1750 $output_rules .= file_contents ('lang-compile', %transform, %lang);
1752 # If the source to a program consists entirely of code from a
1753 # `pure' language, for instance C++ for Fortran 77, then we
1754 # don't need the C compiler code. However if we run into
1755 # something unusual then we do generate the C code. There are
1756 # probably corner cases here that do not work properly.
1757 # People linking Java code to Fortran code deserve pain.
1758 $needs_c ||= ! $lang->pure;
1760 define_compiler_variable ($lang)
1761 if ($lang->compile);
1763 define_linker_variable ($lang)
1766 foreach my $var (@{$lang->config_vars})
1768 am_error ($lang->Name
1769 . " source seen but `$var' not defined in"
1770 . " `$configure_ac'")
1771 if !exists $configure_vars{$var};
1774 # Call the finisher.
1778 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1779 # suffix rule was learned), don't bother with the C stuff. But if
1780 # anything else creeps in, then use it.
1782 if $need_link || scalar keys %suffix_rules > 1;
1786 if (! defined $done{$languages{'c'}})
1788 &define_configure_variable ($languages{'c'}->flags);
1789 &define_compiler_variable ($languages{'c'});
1791 define_linker_variable ($languages{'c'});
1795 # Check to make sure a source defined in LIBOBJS is not explicitly
1796 # mentioned. This is a separate function (as opposed to being inlined
1797 # in handle_source_transform) because it isn't always appropriate to
1799 sub check_libobjs_sources
1801 my ($one_file, $unxformed) = @_;
1803 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1804 'dist_EXTRA_', 'nodist_EXTRA_')
1807 if (variable_defined ($prefix . $one_file . '_SOURCES'))
1809 @files = &variable_value_as_list_recursive (
1810 ($prefix . $one_file . '_SOURCES'),
1813 elsif ($prefix eq '')
1815 @files = ($unxformed . '.c');
1822 foreach my $file (@files)
1824 macro_error ($prefix . $one_file . '_SOURCES',
1825 "automatically discovered file `$file' should not be explicitly mentioned")
1826 if defined $libsources{$file};
1833 # handle_single_transform_list ($VAR, $TOPPARENT, $DERIVED, $OBJ, @FILES)
1834 # -----------------------------------------------------------------------
1835 # Does much of the actual work for handle_source_transform.
1837 # $VAR is the name of the variable that the source filenames come from
1838 # $TOPPARENT is the name of the _SOURCES variable which is being processed
1839 # $DERIVED is the name of resulting executable or library
1840 # $OBJ is the object extension (e.g., `$U.lo')
1841 # @FILES is the list of source files to transform
1842 # Result is a list of the names of objects
1843 # %linkers_used will be updated with any linkers needed
1844 sub handle_single_transform_list ($$$$@)
1846 my ($var, $topparent, $derived, $obj, @files) = @_;
1848 my $nonansi_obj = $obj;
1849 $nonansi_obj =~ s/\$U//g;
1851 # Turn sources into objects. We use a while loop like this
1852 # because we might add to @files in the loop.
1853 while (scalar @files > 0)
1857 # Configure substitutions in _SOURCES variables are errors.
1861 "`$var' includes configure substitution `$_', and is referred to from `$topparent': configure substitutions not allowed in _SOURCES variables");
1865 # If the source file is in a subdirectory then the `.o' is put
1866 # into the current directory, unless the subdir-objects option
1869 # Split file name into base and extension.
1870 next if ! /^(?:(.*)\/)?([^\/]*)($KNOWN_EXTENSIONS_PATTERN)$/;
1872 my $directory = $1 || '';
1876 # We must generate a rule for the object if it requires its own flags.
1878 my ($linker, $object);
1880 # This records whether we've seen a derived source file (eg,
1882 my $derived_source = 0;
1884 # This holds the `aggregate context' of the file we are
1885 # currently examining. If the file is compiled with
1886 # per-object flags, then it will be the name of the object.
1887 # Otherwise it will be `AM'. This is used by the target hook
1888 # language function.
1889 my $aggregate = 'AM';
1891 $extension = &derive_suffix ($extension, $nonansi_obj);
1893 if ($extension_map{$extension} &&
1894 ($lang = $languages{$extension_map{$extension}}))
1896 # Found the language, so see what it says.
1897 &saw_extension ($extension);
1899 # Note: computed subr call. The language rewrite function
1900 # should return one of the $LANG_* constants. It could
1901 # also return a list whose first value is such a constant
1902 # and whose second value is a new source extension which
1903 # should be applied. This means this particular language
1904 # generates another source file which we must then process
1906 my $subr = 'lang_' . $lang->name . '_rewrite';
1907 my ($r, $source_extension)
1908 = & $subr ($directory, $base, $extension);
1909 # Skip this entry if we were asked not to process it.
1910 next if $r == $LANG_IGNORE;
1912 # Now extract linker and other info.
1913 $linker = $lang->linker;
1916 if (defined $source_extension)
1918 $this_obj_ext = $source_extension;
1919 $derived_source = 1;
1923 $this_obj_ext = $obj;
1927 $this_obj_ext = $nonansi_obj;
1929 $object = $base . $this_obj_ext;
1931 if (defined $lang->flags
1932 && variable_defined ($derived . '_' . $lang->flags))
1934 # We have a per-executable flag in effect for this
1935 # object. In this case we rewrite the object's
1936 # name to ensure it is unique. We also require
1937 # the `compile' program to deal with compilers
1938 # where `-c -o' does not work.
1940 # We choose the name `DERIVED_OBJECT' to ensure
1941 # (1) uniqueness, and (2) continuity between
1942 # invocations. However, this will result in a
1943 # name that is too long for losing systems, in
1944 # some situations. So we provide _SHORTNAME to
1947 my $dname = $derived;
1948 if (variable_defined ($derived . '_SHORTNAME'))
1950 # FIXME: should use the same conditional as
1951 # the _SOURCES variable. But this is really
1952 # silly overkill -- nobody should have
1953 # conditional shortnames.
1954 $dname = &variable_value ($derived . '_SHORTNAME');
1956 $object = $dname . '-' . $object;
1958 require_conf_file ("$am_file.am", FOREIGN, 'compile')
1959 if $lang->name eq 'c';
1961 prog_error ("$lang->name flags defined without compiler")
1962 if ! defined $lang->compile;
1967 # If rewrite said it was ok, put the object into a
1969 if ($r == $LANG_SUBDIR && $directory ne '')
1971 $object = $directory . '/' . $object;
1974 # If doing dependency tracking, then we can't print
1975 # the rule. If we have a subdir object, we need to
1976 # generate an explicit rule. Actually, in any case
1977 # where the object is not in `.' we need a special
1978 # rule. The per-object rules in this case are
1979 # generated later, by handle_languages.
1980 if ($renamed || $directory ne '')
1982 my $obj_sans_ext = substr ($object, 0,
1983 - length ($this_obj_ext));
1984 my $val = ("$full $obj_sans_ext "
1985 # Only use $this_obj_ext in the derived
1986 # source case because in the other case we
1987 # *don't* want $(OBJEXT) to appear here.
1988 . ($derived_source ? $this_obj_ext : '.o'));
1990 # If we renamed the object then we want to use the
1991 # per-executable flag name. But if this is simply a
1992 # subdir build then we still want to use the AM_ flag
1996 $val = "$derived $val";
1997 $aggregate = $derived;
2004 # Each item on this list is a string consisting of
2005 # four space-separated values: the derived flag prefix
2006 # (eg, for `foo_CFLAGS', it is `foo'), the name of the
2007 # source file, the base name of the output file, and
2008 # the extension for the object file.
2009 push (@{$lang_specific_files{$lang->name}}, $val);
2012 elsif ($extension eq $nonansi_obj)
2014 # This is probably the result of a direct suffix rule.
2015 # In this case we just accept the rewrite.
2016 $object = "$base$extension";
2021 # No error message here. Used to have one, but it was
2023 # FIXME: we could potentially do more processing here,
2024 # perhaps treating the new extension as though it were a
2025 # new source extension (as above). This would require
2026 # more restructuring than is appropriate right now.
2030 if (defined $object_map{$object})
2032 if ($object_map{$object} ne $full)
2034 am_error ("object `$object' created by `$full' and `$object_map{$object}'");
2038 my $comp_val = (($object =~ /\.lo$/)
2039 ? $COMPILE_LIBTOOL : $COMPILE_ORDINARY);
2040 (my $comp_obj = $object) =~ s/\.lo$/.\$(OBJEXT)/;
2041 if (defined $object_compilation_map{$comp_obj}
2042 && $object_compilation_map{$comp_obj} != 0
2043 # Only see the error once.
2044 && ($object_compilation_map{$comp_obj}
2045 != ($COMPILE_LIBTOOL | $COMPILE_ORDINARY))
2046 && $object_compilation_map{$comp_obj} != $comp_val)
2048 am_error ("object `$object' created both with libtool and without");
2050 $object_compilation_map{$comp_obj} |= $comp_val;
2054 # Let the language do some special magic if required.
2055 $lang->target_hook ($aggregate, $object, $full);
2058 if ($derived_source)
2060 prog_error ("$lang->name has automatic dependency tracking")
2061 if $lang->autodep ne 'no';
2062 # Make sure this new source file is handled next. That will
2063 # make it appear to be at the right place in the list.
2064 unshift (@files, $object);
2065 # Distribute derived sources unless the source they are
2066 # derived from is not.
2067 &push_dist_common ($object)
2068 unless ($topparent =~ /^(:?nobase_)?nodist_/);
2072 $linkers_used{$linker} = 1;
2074 push (@result, $object);
2076 if (! defined $object_map{$object})
2079 $object_map{$object} = $full;
2081 # If file is in subdirectory, we need explicit
2083 if ($directory ne '' || $renamed)
2085 push (@dep_list, $full);
2088 # If resulting object is in subdir, we need to make
2089 # sure the subdir exists at build time.
2090 if ($object =~ /\//)
2092 # FIXME: check that $DIRECTORY is somewhere in the
2095 # For Java, the way we're handling it right now, a
2096 # `..' component doesn't make sense.
2097 if ($lang->name eq 'java' && $object =~ /(\/|^)\.\.\//)
2099 am_error ("`$full' contains `..' component but should not");
2102 # Make sure object is removed by `make mostlyclean'.
2103 $compile_clean_files{$object} = MOSTLY_CLEAN;
2104 # If we have a libtool object then we also must remove
2106 if ($object =~ /\.lo$/)
2108 (my $xobj = $object) =~ s,lo$,\$(OBJEXT),;
2109 $compile_clean_files{$xobj} = MOSTLY_CLEAN;
2111 $libtool_clean_directories{$directory} = 1;
2114 push (@dep_list, require_build_directory ($directory));
2116 # If we're generating dependencies, we also want
2117 # to make sure that the appropriate subdir of the
2118 # .deps directory is created.
2120 require_build_directory ($directory . '/$(DEPDIR)'))
2121 if $use_dependencies;
2124 &pretty_print_rule ($object . ':', "\t", @dep_list)
2125 if scalar @dep_list > 0;
2128 # Transform .o or $o file into .P file (for automatic
2130 if ($lang && $lang->autodep ne 'no')
2132 my $depfile = $object;
2133 $depfile =~ s/\.([^.]*)$/.P$1/;
2134 $depfile =~ s/\$\(OBJEXT\)$/o/;
2135 $dep_files{dirname ($depfile) . '/$(DEPDIR)/'
2136 . basename ($depfile)} = 1;
2143 # ($LINKER, $OBJVAR)
2144 # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
2145 # $OBJ, $PARENT, $TOPPARENT)
2146 # ---------------------------------------------------------------------
2147 # Define an _OBJECTS variable for a _SOURCES variable (or subvariable)
2150 # $VAR is the name of the _SOURCES variable
2151 # $OBJVAR is the name of the _OBJECTS variable if known (otherwise
2152 # it will be generated and returned).
2153 # $NODEFINE is a boolean: if true, $OBJVAR will not be defined (but
2154 # work done to determine the linker will be).
2155 # $ONE_FILE is the canonical (transformed) name of object to build
2156 # $OBJ is the object extension (ie either `.o' or `.lo').
2157 # $PARENT is the variable in which $VAR is used, or $VAR if not applicable.
2158 # $TOPPARENT is the _SOURCES variable being processed.
2160 # Result is a pair ($LINKER, $OBJVAR):
2161 # $LINKER is a boolean, true if a linker is needed to deal with the objects,
2162 # $OBJVAR is the name of the variable defined to hold the objects.
2164 # %linkers_used, %vars_scanned, @substfroms and @substtos should be cleared
2166 # %linkers_used variable will be set to contain the linkers desired.
2167 # %vars_scanned will be used to check for recursive definitions.
2168 # @substfroms and @substtos will be used to keep a stack of variable
2169 # substitutions to be applied.
2171 sub define_objects_from_sources ($$$$$$$)
2173 my ($var, $objvar, $nodefine, $one_file, $obj, $parent, $topparent) = @_;
2175 if (defined $vars_scanned{$var})
2177 macro_error ($var, "variable `$var' recursively defined");
2180 $vars_scanned{$var} = 1;
2182 my $needlinker = "";
2183 my @allresults = ();
2184 foreach my $cond (variable_conditions ($var))
2187 foreach my $val (&variable_value_as_list ($var, $cond, $parent))
2189 # If $val is a variable (i.e. ${foo} or $(bar), not a filename),
2190 # handle the sub variable recursively.
2191 if ($val =~ /^\$\{([^}]*)\}$/ || $val =~ /^\$\(([^)]*)\)$/)
2195 # If the user uses a losing variable name, just ignore it.
2196 # This isn't ideal, but people have requested it.
2197 next if ($subvar =~ /\@.*\@/);
2199 # See if the variable is actually a substitution reference
2202 if ($subvar =~ /$SUBST_REF_PATTERN/o)
2206 $from = quotemeta $2;
2208 push @substfroms, $from;
2209 push @substtos, $to;
2211 my ($temp, $varname)
2212 = define_objects_from_sources ($subvar, undef,
2213 $nodefine, $one_file,
2214 $obj, $var, $topparent);
2216 push (@result, '$('. $varname . ')');
2217 $needlinker ||= $temp;
2222 else # $var is a filename
2224 my $substnum=$#substfroms;
2225 while ($substnum >= 0)
2227 $val =~ s/$substfroms[$substnum]$/$substtos[$substnum]/
2228 if defined $substfroms[$substnum];
2233 &handle_single_transform_list ($var, $topparent, $one_file, $obj, $val);
2234 push (@result, @transformed);
2235 $needlinker = "true" if @transformed;
2238 push (@allresults, [$cond, @result]);
2240 # Find a name for the variable, unless imposed.
2241 $objvar = subobjname (@allresults) unless defined $objvar;
2242 # Define _OBJECTS conditionally
2245 foreach my $pair (@allresults)
2247 my ($cond, @result) = @$pair;
2248 define_pretty_variable ($objvar, $cond, @result);
2252 delete $vars_scanned{$var};
2253 return ($needlinker, $objvar);
2258 # subobjname (@DEFINITIONS)
2259 # -------------------------
2260 # Return a name for an object variable that with definitions @DEFINITIONS.
2261 # @DEFINITIONS is a list of pair [$COND, @OBJECTS].
2263 # If we already have an object variable containing @DEFINITIONS, reuse it.
2264 # This way, we avoid combinatorial explosion of the generated
2265 # variables. Especially, in a Makefile such as:
2281 # | B=$(A1) $(A2) ... $(AN)
2286 # The generated c_OBJECTS and d_OBJECTS will share the same variable
2289 # This setup can be the case of a testsuite containing lots (>100) of
2290 # small C programs, all testing the same set of source files.
2294 foreach my $pair (@_)
2296 my ($cond, @values) = @$pair;
2297 $key .= "($cond)@values";
2300 return $subobjvar{$key} if exists $subobjvar{$key};
2302 my $num = 1 + keys (%subobjvar);
2303 my $name = "am__objects_${num}";
2304 $subobjvar{$key} = $name;
2309 # Handle SOURCE->OBJECT transform for one program or library.
2311 # canonical (transformed) name of object to build
2312 # actual name of object to build
2313 # object extension (ie either `.o' or `$o'.
2314 # Return result is name of linker variable that must be used.
2315 # Empty return means just use `LINK'.
2316 sub handle_source_transform
2318 # one_file is canonical name. unxformed is given name. obj is
2320 my ($one_file, $unxformed, $obj) = @_;
2324 if (variable_defined ($one_file . "_OBJECTS"))
2326 macro_error ($one_file . '_OBJECTS',
2327 $one_file . '_OBJECTS', 'should not be defined');
2328 # No point in continuing.
2335 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2336 'dist_EXTRA_', 'nodist_EXTRA_')
2338 my $var = $prefix . $one_file . "_SOURCES";
2340 if !variable_defined ($var);
2342 # We are going to define _OBJECTS variables using the prefix.
2343 # Then we glom them all together. So we can't use the null
2344 # prefix here as we need it later.
2345 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2347 # Keep track of which prefixes we saw.
2348 $used_pfx{$xpfx} = 1
2349 unless $prefix =~ /EXTRA_/;
2351 push @sources, "\$($var)";
2352 push @dist_sources, "\$($var)"
2353 unless $prefix =~ /^nodist_/;
2358 my ($temp, $objvar) =
2359 define_objects_from_sources ($var,
2360 $xpfx . $one_file . '_OBJECTS',
2361 $prefix =~ /EXTRA_/,
2362 $one_file, $obj, $var, $var);
2363 $needlinker ||= $temp;
2367 $linker ||= &resolve_linker (%linkers_used);
2370 my @keys = sort keys %used_pfx;
2371 if (scalar @keys == 0)
2373 &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
2374 push (@sources, $unxformed . '.c');
2375 push (@dist_sources, $unxformed . '.c');
2379 &handle_single_transform_list ($one_file . '_SOURCES',
2380 $one_file . '_SOURCES',
2383 $linker ||= &resolve_linker (%linkers_used);
2384 define_pretty_variable ($one_file . "_OBJECTS", '', @result)
2388 grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
2389 define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
2392 # If we want to use `LINK' we must make sure it is defined.
2402 # handle_lib_objects ($XNAME, $VAR)
2403 # ---------------------------------
2404 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
2405 # Also, generate _DEPENDENCIES variable if appropriate.
2407 # transformed name of object being built, or empty string if no object
2408 # name of _LDADD/_LIBADD-type variable to examine
2409 # Returns 1 if LIBOBJS seen, 0 otherwise.
2410 sub handle_lib_objects
2412 my ($xname, $var) = @_;
2414 prog_error ("handle_lib_objects: $var undefined")
2415 if ! variable_defined ($var);
2418 foreach my $cond (variable_conditions_recursive ($var))
2420 if (&handle_lib_objects_cond ($xname, $var, $cond))
2428 # Subroutine of handle_lib_objects: handle a particular condition.
2429 sub handle_lib_objects_cond
2431 my ($xname, $var, $cond) = @_;
2433 # We recognize certain things that are commonly put in LIBADD or
2437 my $seen_libobjs = 0;
2440 foreach my $lsearch (&variable_value_as_list_recursive ($var, $cond))
2442 # Skip -lfoo and -Ldir; these are explicitly allowed.
2443 next if $lsearch =~ /^-[lL]/;
2444 if (! $flagvar && $lsearch =~ /^-/)
2446 if ($var =~ /^(.*)LDADD$/)
2448 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
2449 next if $lsearch =~ /^-dl(pre)?open$/;
2450 my $prefix = $1 || 'AM_';
2452 "linker flags such as `$lsearch' belong in `${prefix}LDFLAGS");
2456 $var =~ /^(.*)LIBADD$/;
2457 # Only get this error once.
2460 "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2464 # Assume we have a file of some sort, and push it onto the
2465 # dependency list. Autoconf substitutions are not pushed;
2466 # rarely is a new dependency substituted into (eg) foo_LDADD
2467 # -- but "bad things (eg -lX11) are routinely substituted.
2468 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2469 # and handled specially below.
2470 push (@dep_list, $lsearch)
2471 unless $lsearch =~ /^\@.*\@$/;
2473 # Automatically handle @LIBOBJS@ and @ALLOCA@. Basically this
2474 # means adding entries to dep_files.
2475 if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
2477 my $lt = $1 ? $1 : '';
2478 my $myobjext = ($1 ? 'l' : '') . 'o';
2480 push (@dep_list, $lsearch);
2482 if (! keys %libsources
2483 && ! variable_defined ($lt . 'LIBOBJS'))
2486 "\@$lt" . "LIBOBJS\@ seen but never set in `$configure_ac'");
2489 foreach my $iter (keys %libsources)
2491 if ($iter =~ /\.[cly]$/)
2493 &saw_extension ($&);
2494 &saw_extension ('.c');
2497 if ($iter =~ /\.h$/)
2499 require_file_with_macro ($var, FOREIGN, $iter);
2501 elsif ($iter ne 'alloca.c')
2503 my $rewrite = $iter;
2504 $rewrite =~ s/\.c$/.P$myobjext/;
2505 $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
2506 $rewrite = "^" . quotemeta ($iter) . "\$";
2507 # Only require the file if it is not a built source.
2508 if (! variable_defined ('BUILT_SOURCES')
2509 || ! grep (/$rewrite/,
2510 &variable_value_as_list_recursive (
2511 'BUILT_SOURCES', 'all')))
2513 require_file_with_macro ($var, FOREIGN, $iter);
2518 elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
2520 my $lt = $1 ? $1 : '';
2521 my $myobjext = ($1 ? 'l' : '') . 'o';
2523 push (@dep_list, $lsearch);
2525 "\@$lt" . "ALLOCA\@ seen but `AC_FUNC_ALLOCA' not in `$configure_ac'")
2526 if ! defined $libsources{'alloca.c'};
2527 $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
2528 require_file_with_macro ($var, FOREIGN, 'alloca.c');
2529 &saw_extension ('c');
2535 if (conditional_ambiguous_p ($xname . '_DEPENDENCIES', $cond) ne '')
2537 # Note that we've examined this.
2538 &examine_variable ($xname . '_DEPENDENCIES');
2542 define_pretty_variable ($xname . '_DEPENDENCIES', $cond,
2547 return $seen_libobjs;
2550 # Canonicalize the input parameter
2554 $string =~ tr/A-Za-z0-9_\@/_/c;
2558 # Canonicalize a name, and check to make sure the non-canonical name
2559 # is never used. Returns canonical name. Arguments are name and a
2560 # list of suffixes to check for.
2561 sub check_canonical_spelling
2563 my ($name, @suffixes) = @_;
2565 my $xname = &canonicalize ($name);
2566 if ($xname ne $name)
2568 foreach my $xt (@suffixes)
2570 macro_error ("$name$xt",
2571 "invalid variable `$name$xt'; should be `$xname$xt'")
2572 if variable_defined ("$name$xt");
2582 # Set up the compile suite.
2583 sub handle_compile ()
2586 unless $get_object_extension_was_run;
2589 my $default_includes = '';
2590 if (! defined $options{'nostdinc'})
2592 $default_includes = ' -I. -I$(srcdir)';
2594 if (variable_defined ('CONFIG_HEADER'))
2596 foreach my $hdr (split (' ', &variable_value ('CONFIG_HEADER')))
2598 $default_includes .= ' -I' . dirname ($hdr);
2603 my (@mostly_rms, @dist_rms);
2604 foreach my $item (sort keys %compile_clean_files)
2606 if ($compile_clean_files{$item} == MOSTLY_CLEAN)
2608 push (@mostly_rms, "\t-rm -f $item");
2610 elsif ($compile_clean_files{$item} == DIST_CLEAN)
2612 push (@dist_rms, "\t-rm -f $item");
2616 prog_error ("invalid entry in \%compile_clean_files");
2620 my ($coms, $vars, $rules) =
2621 &file_contents_internal (1, "$libdir/am/compile.am",
2622 ('DEFAULT_INCLUDES' => $default_includes,
2623 'MOSTLYRMS' => join ("\n", @mostly_rms),
2624 'DISTRMS' => join ("\n", @dist_rms)));
2625 $output_vars .= $vars;
2626 $output_rules .= "$coms$rules";
2628 # Check for automatic de-ANSI-fication.
2629 if (defined $options{'ansi2knr'})
2631 if (! $am_c_prototypes)
2633 macro_error ('AUTOMAKE_OPTIONS',
2634 "option `ansi2knr' in use but `AM_C_PROTOTYPES' not in `$configure_ac'");
2635 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
2636 # Only give this error once.
2637 $am_c_prototypes = 1;
2640 # topdir is where ansi2knr should be.
2641 if ($options{'ansi2knr'} eq 'ansi2knr')
2643 # Only require ansi2knr files if they should appear in
2645 require_file_with_macro ('AUTOMAKE_OPTIONS', FOREIGN,
2646 'ansi2knr.c', 'ansi2knr.1');
2648 # ansi2knr needs to be built before subdirs, so unshift it.
2649 unshift (@all, '$(ANSI2KNR)');
2652 my $ansi2knr_dir = '';
2653 $ansi2knr_dir = dirname ($options{'ansi2knr'})
2654 if $options{'ansi2knr'} ne 'ansi2knr';
2656 $output_rules .= &file_contents ('ansi2knr',
2657 ('ANSI2KNR-DIR' => $ansi2knr_dir));
2664 # Handle libtool rules.
2667 return unless $seen_libtool;
2669 # Libtool requires some files, but only at top level.
2670 require_conf_file ($seen_libtool, FOREIGN, @libtool_files)
2671 if $relative_dir eq '.';
2674 foreach my $item (sort keys %libtool_clean_directories)
2676 my $dir = ($item eq '.') ? '' : "$item/";
2677 # .libs is for Unix, _libs for DOS.
2678 push (@libtool_rms, "\t-rm -rf ${dir}.libs ${dir}_libs");
2681 # Output the libtool compilation rules.
2682 $output_rules .= &file_contents ('libtool',
2683 ('LTRMS' => join ("\n", @libtool_rms)));
2686 # handle_programs ()
2687 # ------------------
2688 # Handle C programs.
2691 my @proglist = &am_install_var ('progs', 'PROGRAMS',
2692 'bin', 'sbin', 'libexec', 'pkglib',
2694 return if ! @proglist;
2696 my $seen_libobjs = 0;
2697 foreach my $one_file (@proglist)
2699 my $obj = &get_object_extension ($one_file);
2701 # Canonicalize names and check for misspellings.
2702 my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2703 '_SOURCES', '_OBJECTS',
2706 my $linker = &handle_source_transform ($xname, $one_file, $obj);
2709 if (variable_defined ($xname . "_LDADD"))
2711 if (&handle_lib_objects ($xname, $xname . '_LDADD'))
2719 # User didn't define prog_LDADD override. So do it.
2720 &define_variable ($xname . '_LDADD', '$(LDADD)');
2722 # This does a bit too much work. But we need it to
2723 # generate _DEPENDENCIES when appropriate.
2724 if (variable_defined ('LDADD'))
2726 if (&handle_lib_objects ($xname, 'LDADD'))
2731 elsif (! variable_defined ($xname . '_DEPENDENCIES'))
2733 &define_variable ($xname . '_DEPENDENCIES', '');
2738 if (variable_defined ($xname . '_LIBADD'))
2740 macro_error ($xname . '_LIBADD',
2741 "use `" . $xname . "_LDADD', not `"
2742 . $xname . "_LIBADD'");
2745 if (! variable_defined ($xname . '_LDFLAGS'))
2747 # Define the prog_LDFLAGS variable.
2748 &define_variable ($xname . '_LDFLAGS', '');
2751 # Determine program to use for link.
2753 if (variable_defined ($xname . '_LINK'))
2755 $xlink = $xname . '_LINK';
2759 $xlink = $linker ? $linker : 'LINK';
2762 # If the resulting program lies into a subdirectory,
2763 # make sure this directory will exist.
2764 my $dirstamp = require_build_directory_maybe ($one_file);
2766 # Don't add $(EXEEXT) if user already did.
2767 my $extension = ($one_file !~ /\$\(EXEEXT\)$/
2771 $output_rules .= &file_contents ('program',
2772 ('PROGRAM' => $one_file,
2773 'XPROGRAM' => $xname,
2775 'DIRSTAMP' => $dirstamp,
2776 'EXEEXT' => $extension));
2779 if (variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD'))
2786 foreach my $one_file (@proglist)
2788 my $xname = &canonicalize ($one_file);
2790 if (variable_defined ($xname . '_LDADD'))
2792 &check_libobjs_sources ($xname, $xname . '_LDADD');
2794 elsif (variable_defined ('LDADD'))
2796 &check_libobjs_sources ($xname, 'LDADD');
2803 # handle_libraries ()
2804 # -------------------
2806 sub handle_libraries
2808 my @liblist = &am_install_var ('libs', 'LIBRARIES',
2809 'lib', 'pkglib', 'noinst', 'check');
2810 return if ! @liblist;
2812 my @prefix = am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2814 if (! defined $configure_vars{'RANLIB'}
2817 macro_error ($prefix[0] . '_LIBRARIES',
2818 "library used but `RANLIB' not defined in `$configure_ac'");
2819 # Only get this error once. If this is ever printed, we have
2821 $configure_vars{'RANLIB'} = 'BUG';
2824 my $seen_libobjs = 0;
2825 foreach my $onelib (@liblist)
2827 # Check that the library fits the standard naming convention.
2828 if (basename ($onelib) !~ /^lib.*\.a/)
2830 # FIXME should put line number here. That means mapping
2831 # from library name back to variable name.
2832 &am_error ("`$onelib' is not a standard library name");
2835 my $obj = &get_object_extension ($onelib);
2837 # Canonicalize names and check for misspellings.
2838 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2839 '_OBJECTS', '_DEPENDENCIES',
2842 if (! variable_defined ($xlib . '_AR'))
2844 &define_variable ($xlib . '_AR', '$(AR) cru');
2847 if (variable_defined ($xlib . '_LIBADD'))
2849 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2856 # Generate support for conditional object inclusion in
2858 &define_variable ($xlib . "_LIBADD", '');
2861 if (variable_defined ($xlib . '_LDADD'))
2863 macro_error ($xlib . '_LDADD',
2864 "use `" . $xlib . "_LIBADD', not `"
2865 . $xlib . "_LDADD'");
2868 # Make sure we at look at this.
2869 &examine_variable ($xlib . '_DEPENDENCIES');
2871 &handle_source_transform ($xlib, $onelib, $obj);
2873 # If the resulting library lies into a subdirectory,
2874 # make sure this directory will exist.
2875 my $dirstamp = require_build_directory_maybe ($onelib);
2877 $output_rules .= &file_contents ('library',
2878 ('LIBRARY' => $onelib,
2879 'XLIBRARY' => $xlib,
2880 'DIRSTAMP' => $dirstamp));
2885 foreach my $onelib (@liblist)
2887 my $xlib = &canonicalize ($onelib);
2888 if (variable_defined ($xlib . '_LIBADD'))
2890 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2897 # handle_ltlibraries ()
2898 # ---------------------
2899 # Handle shared libraries.
2900 sub handle_ltlibraries
2902 my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2903 'noinst', 'lib', 'pkglib', 'check');
2904 return if ! @liblist;
2907 my @prefix = am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2910 foreach my $key (@prefix)
2914 macro_error ($key . '_LTLIBRARIES',
2915 "library used but `LIBTOOL' not defined in `$configure_ac'");
2916 # Only get this error once. If this is ever printed,
2918 $configure_vars{'LIBTOOL'} = 'BUG';
2919 $seen_libtool = $var_location{$key . '_LTLIBRARIES'};
2922 # Get the installation directory of each library.
2923 (my $dir = $key) =~ s/^nobase_//;
2924 for (variable_value_as_list_recursive ($key . '_LTLIBRARIES', 'all'))
2928 am_error ("`$_' is already going to be installed in `$instdirs{$_}'");
2932 $instdirs{$_} = $dir;
2937 my $seen_libobjs = 0;
2938 foreach my $onelib (@liblist)
2940 my $obj = &get_object_extension ($onelib);
2942 # Canonicalize names and check for misspellings.
2943 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2944 '_SOURCES', '_OBJECTS',
2947 if (! variable_defined ($xlib . '_LDFLAGS'))
2949 # Define the lib_LDFLAGS variable.
2950 &define_variable ($xlib . '_LDFLAGS', '');
2953 # Check that the library fits the standard naming convention.
2954 my $libname_rx = "^lib.*\.la";
2955 if ((variable_defined ($xlib . '_LDFLAGS')
2956 && grep (/-module/, &variable_value_as_list_recursive (
2957 $xlib . '_LDFLAGS', 'all')))
2958 || (variable_defined ('LDFLAGS')
2959 && grep (/-module/, &variable_value_as_list_recursive (
2960 'LDFLAGS', 'all'))))
2962 # Relax name checking for libtool modules.
2963 $libname_rx = "\.la";
2965 if (basename ($onelib) !~ /$libname_rx$/)
2967 # FIXME this should only be a warning for foreign packages
2968 # FIXME should put line number here. That means mapping
2969 # from library name back to variable name.
2970 &am_error ("`$onelib' is not a standard libtool library name");
2973 if (variable_defined ($xlib . '_LIBADD'))
2975 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2982 # Generate support for conditional object inclusion in
2984 &define_variable ($xlib . "_LIBADD", '');
2987 if (variable_defined ($xlib . '_LDADD'))
2989 macro_error ($xlib . '_LDADD',
2990 "use `" . $xlib . "_LIBADD', not `"
2991 . $xlib . "_LDADD'");
2994 # Make sure we at look at this.
2995 &examine_variable ($xlib . '_DEPENDENCIES');
2997 my $linker = &handle_source_transform ($xlib, $onelib, $obj);
2999 # Determine program to use for link.
3001 if (variable_defined ($xlib . '_LINK'))
3003 $xlink = $xlib . '_LINK';
3007 $xlink = $linker ? $linker : 'LINK';
3011 if ($instdirs{$onelib} eq 'EXTRA'
3012 || $instdirs{$onelib} eq 'noinst'
3013 || $instdirs{$onelib} eq 'check')
3015 # It's an EXTRA_ library, so we can't specify -rpath,
3016 # because we don't know where the library will end up.
3017 # The user probably knows, but generally speaking automake
3018 # doesn't -- and in fact configure could decide
3019 # dynamically between two different locations.
3024 $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
3027 # If the resulting library lies into a subdirectory,
3028 # make sure this directory will exist.
3029 my $dirstamp = require_build_directory_maybe ($onelib);
3031 $output_rules .= &file_contents ('ltlibrary',
3032 ('LTLIBRARY' => $onelib,
3033 'XLTLIBRARY' => $xlib,
3036 'DIRSTAMP' => $dirstamp));
3041 foreach my $onelib (@liblist)
3043 my $xlib = &canonicalize ($onelib);
3044 if (variable_defined ($xlib . '_LIBADD'))
3046 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
3052 # See if any _SOURCES variable were misspelled. Also, make sure that
3053 # EXTRA_ variables don't contain configure substitutions.
3056 # It is ok if the user sets this particular variable.
3057 &examine_variable ('AM_LDFLAGS');
3059 foreach my $varname (keys %var_value)
3061 foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
3064 macro_error ($varname,
3065 "invalid unused variable name: `$varname'")
3066 # Note that a configure variable is always legitimate.
3067 # It is natural to name such variables after the
3068 # primary, so we explicitly allow it.
3069 if $varname =~ /$primary$/ && ! $content_seen{$varname}
3070 && ! exists $configure_vars{$varname};
3079 # NOTE we no longer automatically clean SCRIPTS, because it is
3080 # useful to sometimes distribute scripts verbatim. This happens
3081 # eg in Automake itself.
3082 &am_install_var ('-candist', 'scripts', 'SCRIPTS',
3083 'bin', 'sbin', 'libexec', 'pkgdata',
3088 # ($OUTFILE, $VFILE, @CLEAN_FILES)
3089 # &scan_texinfo_file ($FILENAME)
3090 # ------------------------------
3091 # $OUTFILE is the name of the info file produced by $FILENAME.
3092 # $VFILE is the name of the version.texi file used (empty if none).
3093 # @CLEAN_FILES is the list of by products (indexes etc.)
3094 sub scan_texinfo_file
3096 my ($filename) = @_;
3098 # These are always created, no matter whether indexes are used or not.
3099 my @clean_suffixes = qw(aux dvi log pdf ps toc
3100 cp fn ky vr tp pg); # grep new.*index texinfo.tex
3102 # There are predefined indexes which don't follow the regular rules.
3103 my %predefined_index = qw(c cps
3110 # There are commands which include a hidden index command.
3111 my %hidden_index = (tp => 'tps');
3112 $hidden_index{$_} = 'fns' foreach qw(fn un typefn typefun max spec
3113 op typeop method typemethod);
3114 $hidden_index{$_} = 'vrs' foreach qw(vr var typevr typevar opt cv
3117 # Indexes stored into another one. In this case, the *.??s file
3119 my @syncodeindexes = ();
3121 my $texi = new Automake::XFile "< $filename";
3122 verbose "reading $filename";
3124 my ($outfile, $vfile);
3125 while ($_ = $texi->getline)
3127 if (/^\@setfilename +(\S+)/)
3130 if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
3132 file_error ("$filename:$.",
3133 "output `$outfile' has unrecognized extension");
3137 # A "version.texi" file is actually any file whose name
3138 # matches "vers*.texi".
3139 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
3144 # Try to find what are the indexes which are used.
3146 # Creating a new category of index.
3147 elsif (/^\@def(code)?index (\w+)/)
3149 push @clean_suffixes, $2;
3152 # Storing in a predefined index.
3153 elsif (/^\@([cfkvtp])index /)
3155 push @clean_suffixes, $predefined_index{$1};
3157 elsif (/^\@def(\w+) /)
3159 push @clean_suffixes, $hidden_index{$1}
3160 if defined $hidden_index{$1};
3163 # Merging an index into an another.
3164 elsif (/^\@syn(code)?index (\w+) (\w+)/)
3166 push @syncodeindexes, "$2s";
3167 push @clean_suffixes, "$3s";
3174 &am_error ("`$filename' missing \@setfilename");
3178 my $infobase = basename ($filename);
3179 $infobase =~ s/\.te?xi(nfo)?$//;
3180 my %clean_files = map { +"$infobase.$_" => 1 } @clean_suffixes;
3181 grep { delete $clean_files{"$infobase.$_"} } @syncodeindexes;
3182 return ($outfile, $vfile, (sort keys %clean_files));
3186 # ($DO-SOMETHING, $TEXICLEANS)
3187 # handle_texinfo_helper ()
3188 # ------------------------
3189 # Handle all Texinfo source; helper for handle_texinfo
3190 sub handle_texinfo_helper
3192 macro_error ('TEXINFOS',
3193 "`TEXINFOS' is an anachronism; use `info_TEXINFOS'")
3194 if variable_defined ('TEXINFOS');
3195 return (0, '') if (! variable_defined ('info_TEXINFOS')
3196 && ! variable_defined ('html_TEXINFOS'));
3198 if (variable_defined ('html_TEXINFOS'))
3200 macro_error ('html_TEXINFOS',
3201 "HTML generation not yet supported");
3205 my @texis = &variable_value_as_list_recursive ('info_TEXINFOS', 'all');
3207 my (@info_deps_list, @dvis_list, @pdfs_list, @texi_deps);
3214 foreach my $info_cursor (@texis)
3216 my $infobase = $info_cursor;
3217 $infobase =~ s/\.(txi|texinfo|texi)$//;
3219 if ($infobase eq $info_cursor)
3221 # FIXME: report line number.
3222 &am_error ("texinfo file `$info_cursor' has unrecognized extension");
3225 $texi_suffixes{$1} = 1;
3227 # If 'version.texi' is referenced by input file, then include
3228 # automatic versioning capability.
3229 my ($out_file, $vtexi, @clean_files) =
3230 &scan_texinfo_file ("$relative_dir/$info_cursor")
3232 push (@texi_cleans, @clean_files);
3236 &am_error ("`$vtexi', included in `$info_cursor', also included in `$versions{$vtexi}'")
3237 if (defined $versions{$vtexi});
3238 $versions{$vtexi} = $info_cursor;
3240 # We number the stamp-vti files. This is doable since the
3241 # actual names don't matter much. We only number starting
3242 # with the second one, so that the common case looks nice.
3243 my $vti = ($done ? $done : 'vti');
3246 # This is ugly, but it is our historical practice.
3247 if ($config_aux_dir_set_in_configure_in)
3249 require_conf_file_with_macro ('info_TEXINFOS', FOREIGN,
3254 require_file_with_macro ('info_TEXINFOS', FOREIGN,
3259 if ($config_aux_dir_set_in_configure_in)
3261 $conf_dir = $config_aux_dir;
3262 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
3266 $conf_dir = '$(srcdir)/';
3268 $output_rules .= &file_contents ('texi-vers',
3269 ('TEXI' => $info_cursor,
3272 'MDDIR' => $conf_dir));
3275 # If user specified file_TEXINFOS, then use that as explicit
3278 push (@texi_deps, $info_cursor);
3279 # Prefix with $(srcdir) because some version of make won't
3280 # work if the target has it and the dependency doesn't.
3281 push (@texi_deps, '$(srcdir)/' . $vtexi) if $vtexi;
3283 my $canonical = &canonicalize ($infobase);
3284 if (variable_defined ($canonical . "_TEXINFOS"))
3286 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
3287 &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
3290 $output_rules .= ("\n" . $out_file . ": "
3292 . "\n" . $infobase . ".dvi: "
3294 . "\n" . $infobase . ".pdf: "
3298 push (@info_deps_list, $out_file);
3299 push (@dvis_list, $infobase . '.dvi');
3300 push (@pdfs_list, $infobase . '.pdf');
3303 # Handle location of texinfo.tex.
3304 my $need_texi_file = 0;
3308 $texinfodir = '$(top_srcdir)/../texinfo';
3309 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3311 elsif ($config_aux_dir_set_in_configure_in)
3313 $texinfodir = $config_aux_dir;
3314 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3315 $need_texi_file = 2; # so that we require_conf_file later
3317 elsif (variable_defined ('TEXINFO_TEX'))
3319 # The user defined TEXINFO_TEX so assume he knows what he is
3321 $texinfodir = ('$(srcdir)/'
3322 . dirname (&variable_value ('TEXINFO_TEX')));
3326 $texinfodir = '$(srcdir)';
3327 $need_texi_file = 1;
3330 foreach my $txsfx (sort keys %texi_suffixes)
3332 $output_rules .= &file_contents ('texibuild',
3333 ('TEXINFODIR' => $texinfodir,
3334 'SUFFIX' => $txsfx));
3338 my $texiclean = &pretty_print_internal ("", "\t ", @texi_cleans);
3340 push (@dist_targets, 'dist-info');
3342 if (! defined $options{'no-installinfo'})
3344 # Make sure documentation is made and installed first. Use
3345 # $(INFO_DEPS), not 'info', because otherwise recursive makes
3346 # get run twice during "make all".
3347 unshift (@all, '$(INFO_DEPS)');
3350 &define_variable ("INFO_DEPS", "@info_deps_list");
3351 &define_variable ("DVIS", "@dvis_list");
3352 &define_variable ("PDFS", "@pdfs_list");
3353 # This next isn't strictly needed now -- the places that look here
3354 # could easily be changed to look in info_TEXINFOS. But this is
3355 # probably better, in case noinst_TEXINFOS is ever supported.
3356 &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
3358 # Do some error checking. Note that this file is not required
3359 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3361 if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
3363 if ($need_texi_file > 1)
3365 require_conf_file_with_macro ('info_TEXINFOS', FOREIGN,
3370 require_file_with_macro ('info_TEXINFOS', FOREIGN, 'texinfo.tex');
3374 return (1, $texiclean);
3379 # Handle all Texinfo source.
3382 my ($do_something, $texiclean) = handle_texinfo_helper ();
3383 $output_rules .= &file_contents ('texinfos',
3384 ('TEXICLEAN' => $texiclean,
3385 'LOCAL-TEXIS' => $do_something));
3388 # Handle any man pages.
3389 sub handle_man_pages
3391 macro_error ('MANS', "`MANS' is an anachronism; use `man_MANS'")
3392 if variable_defined ('MANS');
3394 # Find all the sections in use. We do this by first looking for
3395 # "standard" sections, and then looking for any additional
3396 # sections used in man_MANS.
3397 my (%sections, %vlist);
3398 # We handle nodist_ for uniformity. man pages aren't distributed
3399 # by default so it isn't actually very important.
3400 foreach my $pfx ('', 'dist_', 'nodist_')
3402 # Add more sections as needed.
3403 foreach my $section ('0'..'9', 'n', 'l')
3405 if (variable_defined ($pfx . 'man' . $section . '_MANS'))
3407 $sections{$section} = 1;
3408 $vlist{'$(' . $pfx . 'man' . $section . '_MANS)'} = 1;
3410 &push_dist_common ('$(' . $pfx . 'man' . $section . '_MANS)')
3415 if (variable_defined ($pfx . 'man_MANS'))
3417 $vlist{'$(' . $pfx . 'man_MANS)'} = 1;
3418 foreach (&variable_value_as_list_recursive ($pfx . 'man_MANS', 'all'))
3420 # A page like `foo.1c' goes into man1dir.
3421 if (/\.([0-9a-z])([a-z]*)$/)
3427 &push_dist_common ('$(' . $pfx . 'man_MANS)')
3432 return unless %sections;
3434 # Now for each section, generate an install and unintall rule.
3435 # Sort sections so output is deterministic.
3436 foreach my $section (sort keys %sections)
3438 $output_rules .= &file_contents ('mans', ('SECTION' => $section));
3441 my @mans = sort keys %vlist;
3442 $output_vars .= file_contents ('mans-vars',
3443 ('MANS' => "@mans"));
3445 if (! defined $options{'no-installman'})
3447 push (@all, '$(MANS)');
3451 # Handle DATA variables.
3454 &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3455 'data', 'sysconf', 'sharedstate', 'localstate',
3456 'pkgdata', 'noinst', 'check');
3463 if (variable_defined ('SUBDIRS'))
3465 $output_rules .= ("tags-recursive:\n"
3466 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3467 # Never fail here if a subdir fails; it
3469 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3470 . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3472 push (@tag_deps, 'tags-recursive');
3473 &depend ('.PHONY', 'tags-recursive');
3476 if (&saw_sources_p (1)
3477 || variable_defined ('ETAGS_ARGS')
3481 foreach my $spec (@config_headers)
3483 my ($out, @ins) = split_config_file_spec ($spec);
3484 foreach my $in (@ins)
3486 # If the config header source is in this directory,
3488 push @config, basename ($in)
3489 if $relative_dir eq dirname ($in);
3492 $output_rules .= &file_contents ('tags',
3493 ('CONFIG' => "@config",
3494 'DIRS' => "@tag_deps"));
3495 &examine_variable ('TAGS_DEPENDENCIES');
3497 elsif (variable_defined ('TAGS_DEPENDENCIES'))
3499 macro_error ('TAGS_DEPENDENCIES',
3500 "doesn't make sense to define `TAGS_DEPENDENCIES' without sources or `ETAGS_ARGS'");
3504 # Every Makefile must define some sort of TAGS rule.
3505 # Otherwise, it would be possible for a top-level "make TAGS"
3506 # to fail because some subdirectory failed.
3507 $output_rules .= "tags: TAGS\nTAGS:\n\n";
3511 # Handle multilib support.
3514 if ($seen_multilib && $relative_dir eq '.')
3516 $output_rules .= &file_contents ('multilib');
3522 # &for_dist_common ($A, $B)
3523 # -------------------------
3524 # Subroutine for &handle_dist: sort files to dist.
3526 # We put README first because it then becomes easier to make a
3527 # Usenet-compliant shar file (in these, README must be first).
3529 # FIXME: do more ordering of files here.
3542 # handle_dist ($MAKEFILE)
3543 # -----------------------
3544 # Handle 'dist' target.
3547 my ($makefile) = @_;
3549 # `make dist' isn't used in a Cygnus-style tree.
3550 # Omit the rules so that people don't try to use them.
3551 return if $cygnus_mode;
3553 # Look for common files that should be included in distribution.
3554 # If the aux dir is set, and it does not have a Makefile.am, then
3555 # we check for these files there as well.
3558 if ($relative_dir eq '.'
3559 && $config_aux_dir_set_in_configure_in)
3561 ($auxdir = $config_aux_dir) =~ s,^\$\(top_srcdir\)/,,;
3562 if (! &is_make_dir ($auxdir))
3567 foreach my $cfile (@common_files)
3569 if (-f ($relative_dir . "/" . $cfile)
3570 # The file might be absent, but if it can be built it's ok.
3571 || exists $targets{$cfile})
3573 &push_dist_common ($cfile);
3576 # Don't use `elsif' here because a file might meaningfully
3577 # appear in both directories.
3578 if ($check_aux && -f ($auxdir . '/' . $cfile))
3580 &push_dist_common ($auxdir . '/' . $cfile);
3584 # We might copy elements from $configure_dist_common to
3585 # %dist_common if we think we need to. If the file appears in our
3586 # directory, we would have discovered it already, so we don't
3587 # check that. But if the file is in a subdir without a Makefile,
3588 # we want to distribute it here if we are doing `.'. Ugly!
3589 if ($relative_dir eq '.')
3591 foreach my $file (split (' ' , $configure_dist_common))
3593 push_dist_common ($file)
3594 unless is_make_dir (dirname ($file));
3600 # Files to distributed. Don't use &variable_value_as_list_recursive
3601 # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3602 check_variable_defined_unconditionally ('DIST_COMMON');
3603 my @dist_common = split (' ', variable_value ('DIST_COMMON', 'TRUE'));
3604 @dist_common = uniq (sort for_dist_common (@dist_common));
3605 pretty_print ('DIST_COMMON = ', "\t", @dist_common);
3607 # Now that we've processed DIST_COMMON, disallow further attempts
3609 $handle_dist_run = 1;
3611 # Scan EXTRA_DIST to see if we need to distribute anything from a
3612 # subdir. If so, add it to the list. I didn't want to do this
3613 # originally, but there were so many requests that I finally
3615 if (variable_defined ('EXTRA_DIST'))
3617 # FIXME: This should be fixed to work with conditionals. That
3618 # will require only making the entries in %dist_dirs under the
3619 # appropriate condition. This is meaningful if the nature of
3620 # the distribution should depend upon the configure options
3622 foreach (&variable_value_as_list_recursive ('EXTRA_DIST', ''))
3625 next unless s,/+[^/]+$,,;
3631 # We have to check DIST_COMMON for extra directories in case the
3632 # user put a source used in AC_OUTPUT into a subdir.
3633 foreach (&variable_value_as_list_recursive ('DIST_COMMON', 'all'))
3636 next unless s,/+[^/]+$,,;
3641 # Rule to check whether a distribution is viable.
3642 my %transform = ('DISTCHECK-HOOK' => &target_defined ('distcheck-hook'),
3643 'GETTEXT' => $seen_gettext);
3645 # Prepend $(distdir) to each directory given.
3646 my %rewritten = map { '$(distdir)/' . "$_" => 1 } keys %dist_dirs;
3647 $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);
3649 # If we have SUBDIRS, create all dist subdirectories and do
3651 if (variable_defined ('SUBDIRS'))
3653 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3654 # to all possible directories, and use it. If DIST_SUBDIRS is
3655 # defined, just use it.
3656 my $dist_subdir_name;
3657 # Note that we check DIST_SUBDIRS first on purpose. At least
3658 # one project uses so many conditional subdirectories that
3659 # calling variable_conditionally_defined on SUBDIRS will cause
3660 # automake to grow to 150Mb. Sigh.
3661 if (variable_defined ('DIST_SUBDIRS')
3662 || variable_conditionally_defined ('SUBDIRS'))
3664 $dist_subdir_name = 'DIST_SUBDIRS';
3665 if (! variable_defined ('DIST_SUBDIRS'))
3667 define_pretty_variable
3668 ('DIST_SUBDIRS', '',
3669 uniq (&variable_value_as_list_recursive ('SUBDIRS', 'all')));
3674 $dist_subdir_name = 'SUBDIRS';
3675 # We always define this because that is what `distclean'
3677 define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
3680 $transform{'DIST_SUBDIR_NAME'} = $dist_subdir_name;
3683 # If the target `dist-hook' exists, make sure it is run. This
3684 # allows users to do random weird things to the distribution
3685 # before it is packaged up.
3686 push (@dist_targets, 'dist-hook')
3687 if &target_defined ('dist-hook');
3688 $transform{'DIST-TARGETS'} = join(' ', @dist_targets);
3690 # Defining $(DISTDIR).
3691 $transform{'DISTDIR'} = !variable_defined('distdir');
3692 $transform{'TOP_DISTDIR'} = backname ($relative_dir);
3694 $output_rules .= &file_contents ('distdir', %transform);
3698 # Handle subdirectories.
3702 unless variable_defined ('SUBDIRS');
3704 # Make sure each directory mentioned in SUBDIRS actually exists.
3705 foreach my $dir (&variable_value_as_list_recursive ('SUBDIRS', 'all'))
3707 # Skip directories substituted by configure.
3708 next if $dir =~ /^\@.*\@$/;
3710 if (! -d $am_relative_dir . '/' . $dir)
3712 macro_error ('SUBDIRS',
3713 "required directory $am_relative_dir/$dir does not exist");
3717 macro_error ('SUBDIRS', "directory should not contain `/'")
3721 $output_rules .= &file_contents ('subdirs');
3722 variable_pretty_output ('RECURSIVE_TARGETS', 'TRUE');
3726 # ($REGEN, @DEPENDENCIES)
3729 # If aclocal.m4 creation is automated, return the list of its dependencies.
3732 my $regen_aclocal = 0;
3735 unless $relative_dir eq '.';
3737 &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3738 &examine_variable ('CONFIGURE_DEPENDENCIES');
3740 if (-f 'aclocal.m4')
3742 &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3743 &push_dist_common ('aclocal.m4');
3745 my $aclocal = new Automake::XFile "< aclocal.m4";
3746 my $line = $aclocal->getline;
3747 $regen_aclocal = $line =~ 'generated automatically by aclocal';
3752 if (-f 'acinclude.m4')
3755 push @ac_deps, 'acinclude.m4';
3758 if (variable_defined ('ACLOCAL_M4_SOURCES'))
3760 push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3762 elsif (variable_defined ('ACLOCAL_AMFLAGS'))
3764 # Scan all -I directories for m4 files. These are our
3766 my $examine_next = 0;
3767 foreach my $amdir (&variable_value_as_list_recursive ('ACLOCAL_AMFLAGS', ''))
3772 if ($amdir !~ /^\// && -d $amdir)
3774 foreach my $ac_dep (&my_glob ($amdir . '/*.m4'))
3776 $ac_dep =~ s/^\.\/+//;
3777 push (@ac_deps, $ac_dep)
3778 unless $ac_dep eq "aclocal.m4"
3779 || $ac_dep eq "acinclude.m4";
3783 elsif ($amdir eq '-I')
3790 # Note that it might be possible that aclocal.m4 doesn't exist but
3791 # should be auto-generated. This case probably isn't very
3794 return ($regen_aclocal, @ac_deps);
3799 # &rewrite_inputs_into_dependencies ($ADD_SRCDIR, @INPUTS)
3800 # --------------------------------------------------------
3801 # Rewrite a list of input files into a form suitable to put on a
3802 # dependency list. The idea is that if an input file has a directory
3803 # part the same as the current directory, then the directory part is
3804 # simply removed. But if the directory part is different, then
3805 # $(top_srcdir) is prepended. Among other things, this is used to
3806 # generate the dependency list for the output files generated by
3807 # AC_OUTPUT. Consider what the dependencies should look like in this
3809 # AC_OUTPUT(src/out:src/in1:lib/in2)
3810 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3811 # If 0 then files that require this addition will simply be ignored.
3812 sub rewrite_inputs_into_dependencies ($@)
3814 my ($add_srcdir, @inputs) = @_;
3817 foreach my $single (@inputs)
3819 if (dirname ($single) eq $relative_dir)
3821 push (@newinputs, basename ($single));
3825 push (@newinputs, '$(top_srcdir)/' . $single);
3832 # Handle remaking and configure stuff.
3833 # We need the name of the input file, to do proper remaking rules.
3834 sub handle_configure
3836 my ($local, $input, @secondary_inputs) = @_;
3838 my $input_base = basename ($input);
3839 my $local_base = basename ($local);
3841 my $amfile = $input_base . '.am';
3842 # We know we can always add '.in' because it really should be an
3843 # error if the .in was missing originally.
3844 my $infile = '$(srcdir)/' . $input_base . '.in';
3845 my $colon_infile = '';
3846 if ($local ne $input || @secondary_inputs)
3848 $colon_infile = ':' . $input . '.in';
3850 $colon_infile .= ':' . join (':', @secondary_inputs)
3851 if @secondary_inputs;
3853 my @rewritten = rewrite_inputs_into_dependencies (1, @secondary_inputs);
3855 my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4 ();
3858 &file_contents ('configure',
3864 => ((($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3869 => "@include_stack",
3873 => $cygnus_mode ? 'cygnus' : $strictness_name,
3875 => $cmdline_use_dependencies ? '' : ' --ignore-deps',
3876 'MAKEFILE-AM-SOURCES'
3877 => "$input$colon_infile",
3879 => $regen_aclocal_m4,
3881 => "@aclocal_m4_deps"));
3883 if ($relative_dir eq '.')
3885 &push_dist_common ('acconfig.h')
3889 # If we have a configure header, require it.
3891 my @distclean_config;
3892 foreach my $spec (@config_headers)
3895 # $CONFIG_H_PATH: config.h from top level.
3896 my ($config_h_path, @ins) = split_config_file_spec ($spec);
3897 my $config_h_dir = dirname ($config_h_path);
3899 # If the header is in the current directory we want to build
3900 # the header here. Otherwise, if we're at the topmost
3901 # directory and the header's directory doesn't have a
3902 # Makefile, then we also want to build the header.
3903 if ($relative_dir eq $config_h_dir
3904 || ($relative_dir eq '.' && ! &is_make_dir ($config_h_dir)))
3906 my ($cn_sans_dir, $stamp_dir);
3907 if ($relative_dir eq $config_h_dir)
3909 $cn_sans_dir = basename ($config_h_path);
3914 $cn_sans_dir = $config_h_path;
3915 if ($config_h_dir eq '.')
3921 $stamp_dir = $config_h_dir . '/';
3925 # Compute relative path from directory holding output
3926 # header to directory holding input header. FIXME:
3927 # doesn't handle case where we have multiple inputs.
3929 if (dirname ($ins[0]) eq $relative_dir)
3931 $in0_sans_dir = basename ($ins[0]);
3935 $in0_sans_dir = backname ($relative_dir) . '/' . $ins[0];
3938 require_file ($config_header_location, FOREIGN, $in0_sans_dir);
3940 # Header defined and in this directory.
3942 if (-f $config_h_path . '.top')
3944 push (@files, "$cn_sans_dir.top");
3946 if (-f $config_h_path . '.bot')
3948 push (@files, "$cn_sans_dir.bot");
3951 push_dist_common (@files);
3953 # For now, acconfig.h can only appear in the top srcdir.
3954 if (-f 'acconfig.h')
3956 push (@files, '$(top_srcdir)/acconfig.h');
3959 my $stamp = "${stamp_dir}stamp-h${hdr_index}";
3961 file_contents ('remake-hdr',
3962 ('FILES' => "@files",
3963 'CONFIG_H' => $cn_sans_dir,
3964 'CONFIG_HIN' => $in0_sans_dir,
3965 'CONFIG_H_PATH' => $config_h_path,
3966 'STAMP' => "$stamp"));
3968 push @distclean_config, $cn_sans_dir, $stamp;
3972 $output_rules .= file_contents ('clean-hdr',
3973 ('FILES' => "@distclean_config"))
3974 if @distclean_config;
3976 # Set location of mkinstalldirs.
3977 define_variable ('mkinstalldirs',
3978 ('$(SHELL) ' . $config_aux_dir . '/mkinstalldirs'));
3980 macro_error ('CONFIG_HEADER',
3981 "`CONFIG_HEADER' is an anachronism; now determined from `$configure_ac'")
3982 if variable_defined ('CONFIG_HEADER');
3985 foreach my $spec (@config_headers)
3987 my ($out, @ins) = split_config_file_spec ($spec);
3988 # Generate CONFIG_HEADER define.
3989 if ($relative_dir eq dirname ($out))
3991 push @config_h, basename ($out);
3995 push @config_h, "\$(top_builddir)/$out";
3998 define_variable ("CONFIG_HEADER", "@config_h")
4001 # Now look for other files in this directory which must be remade
4002 # by config.status, and generate rules for them.
4003 my @actual_other_files = ();
4004 foreach my $lfile (@other_input_files)
4008 if ($lfile =~ /^([^:]*):(.*)$/)
4010 # This is the ":" syntax of AC_OUTPUT.
4012 @inputs = split (':', $2);
4018 @inputs = $file . '.in';
4021 # Automake files should not be stored in here, but in %MAKE_LIST.
4022 prog_error ("$lfile in \@other_input_files")
4023 if -f $file . '.am';
4025 my $local = basename ($file);
4027 # Make sure the dist directory for each input file is created.
4028 # We only have to do this at the topmost level though. This
4029 # is a bit ugly but it easier than spreading out the logic,
4030 # especially in cases like AC_OUTPUT(foo/out:bar/in), where
4031 # there is no Makefile in bar/.
4032 if ($relative_dir eq '.')
4036 $dist_dirs{dirname ($_)} = 1;
4040 # We skip files that aren't in this directory. However, if
4041 # the file's directory does not have a Makefile, and we are
4042 # currently doing `.', then we create a rule to rebuild the
4043 # file in the subdir.
4044 my $fd = dirname ($file);
4045 if ($fd ne $relative_dir)
4047 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
4057 my @rewritten_inputs = rewrite_inputs_into_dependencies (1, @inputs);
4058 $output_rules .= ($local . ': '
4059 . '$(top_builddir)/config.status '
4060 . "@rewritten_inputs\n"
4062 . 'cd $(top_builddir) && '
4063 . '$(SHELL) ./config.status '
4064 . ($relative_dir eq '.' ? '' : '$(subdir)/')
4067 push (@actual_other_files, $local);
4069 # Require all input files.
4070 require_file ($ac_config_files_location, FOREIGN,
4071 rewrite_inputs_into_dependencies (0, @inputs));
4074 # These files get removed by "make clean".
4075 define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
4081 my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
4082 'oldinclude', 'pkginclude',
4086 next unless /\..*$/;
4087 &saw_extension ($&);
4093 return if ! $seen_gettext || $relative_dir ne '.';
4095 if (! variable_defined ('SUBDIRS'))
4097 conf_error ("AM_GNU_GETTEXT used but SUBDIRS not defined");
4101 my @subdirs = &variable_value_as_list_recursive ('SUBDIRS', 'all');
4102 macro_error ('SUBDIRS',
4103 "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
4104 if ! grep ('po', @subdirs);
4105 macro_error ('SUBDIRS',
4106 "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
4107 if ! grep ('intl', @subdirs);
4109 require_file ($ac_gettext_location, GNU, 'ABOUT-NLS');
4112 # Handle footer elements.
4115 # NOTE don't use define_pretty_variable here, because
4116 # $contents{...} is already defined.
4117 $output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n\n"
4118 if variable_value ('SOURCES');
4121 target_error ('.SUFFIXES',
4122 "use variable `SUFFIXES', not target `.SUFFIXES'")
4123 if target_defined ('.SUFFIXES');
4125 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
4126 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
4127 # anything else, by sticking it right after the default: target.
4128 $output_header .= ".SUFFIXES:\n";
4129 if (@suffixes || variable_defined ('SUFFIXES'))
4131 # Make sure suffixes has unique elements. Sort them to ensure
4132 # the output remains consistent. However, $(SUFFIXES) is
4133 # always at the start of the list, unsorted. This is done
4134 # because make will choose rules depending on the ordering of
4135 # suffixes, and this lets the user have some control. Push
4136 # actual suffixes, and not $(SUFFIXES). Some versions of make
4137 # do not like variable substitutions on the .SUFFIXES line.
4138 my @user_suffixes = (variable_defined ('SUFFIXES')
4139 ? &variable_value_as_list_recursive ('SUFFIXES', '')
4142 my %suffixes = map { $_ => 1 } @suffixes;
4143 delete @suffixes{@user_suffixes};
4145 $output_header .= (".SUFFIXES: "
4146 . join (' ', @user_suffixes, sort keys %suffixes)
4150 $output_trailer .= file_contents ('footer');
4153 # Deal with installdirs target.
4154 sub handle_installdirs ()
4157 &file_contents ('install',
4159 => variable_value ('_am_installdirs') || '',
4161 => (target_defined ('installdirs-local')
4162 ? ' installdirs-local' : '')));
4166 # Deal with all and all-am.
4169 my ($makefile) = @_;
4173 # Put this at the beginning for the sake of non-GNU makes. This
4174 # is still wrong if these makes can run parallel jobs. But it is
4176 unshift (@all, basename ($makefile));
4178 foreach my $spec (@config_headers)
4180 my ($out, @ins) = split_config_file_spec ($spec);
4181 push (@all, basename ($out))
4182 if dirname ($out) eq $relative_dir;
4185 # Install `all' hooks.
4186 if (&target_defined ("all-local"))
4188 push (@all, "all-local");
4189 &depend ('.PHONY', "all-local");
4192 &pretty_print_rule ("all-am:", "\t\t", @all);
4193 &depend ('.PHONY', 'all-am', 'all');
4198 my @local_headers = ();
4199 push @local_headers, '$(BUILT_SOURCES)'
4200 if variable_defined ('BUILT_SOURCES');
4201 foreach my $spec (@config_headers)
4203 my ($out, @ins) = split_config_file_spec ($spec);
4204 push @local_headers, basename ($out)
4205 if dirname ($out) eq $relative_dir;
4210 # We need to make sure config.h is built before we recurse.
4211 # We also want to make sure that built sources are built
4212 # before any ordinary `all' targets are run. We can't do this
4213 # by changing the order of dependencies to the "all" because
4214 # that breaks when using parallel makes. Instead we handle
4215 # things explicitly.
4216 $output_all .= ("all: @local_headers"
4218 . '$(MAKE) $(AM_MAKEFLAGS) '
4219 . (variable_defined ('SUBDIRS')
4220 ? 'all-recursive' : 'all-am')
4225 $output_all .= "all: " . (variable_defined ('SUBDIRS')
4226 ? 'all-recursive' : 'all-am') . "\n\n";
4231 # Handle check merge target specially.
4232 sub do_check_merge_target
4234 if (&target_defined ('check-local'))
4236 # User defined local form of target. So include it.
4237 push (@check_tests, 'check-local');
4238 &depend ('.PHONY', 'check-local');
4241 # In --cygnus mode, check doesn't depend on all.
4244 # Just run the local check rules.
4245 &pretty_print_rule ('check-am:', "\t\t", @check);
4249 # The check target must depend on the local equivalent of
4250 # `all', to ensure all the primary targets are built. Then it
4251 # must build the local check rules.
4252 $output_rules .= "check-am: all-am\n";
4253 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4257 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4261 &depend ('.PHONY', 'check', 'check-am');
4262 $output_rules .= ("check: "
4263 . (variable_defined ('SUBDIRS')
4264 ? 'check-recursive' : 'check-am')
4268 # Handle all 'clean' targets.
4273 # Don't include `MAINTAINER'; it is handled specially below.
4274 foreach my $name ('MOSTLY', '', 'DIST')
4276 $transform{"${name}CLEAN"} = variable_defined ("${name}CLEANFILES");
4279 # Built sources are automatically removed by maintainer-clean.
4280 push (@maintainer_clean_files, '$(BUILT_SOURCES)')
4281 if variable_defined ('BUILT_SOURCES');
4282 push (@maintainer_clean_files, '$(MAINTAINERCLEANFILES)')
4283 if variable_defined ('MAINTAINERCLEANFILES');
4285 $output_rules .= &file_contents ('clean',
4288 # Join with no space to avoid
4289 # spurious `test -z' success at
4291 => join ('', @maintainer_clean_files),
4293 # A space is required in the join here.
4294 => "@maintainer_clean_files"));
4298 # &depend ($CATEGORY, @DEPENDENDEES)
4299 # ----------------------------------
4300 # The target $CATEGORY depends on @DEPENDENDEES.
4303 my ($category, @dependendees) = @_;
4305 push (@{$dependencies{$category}}, @dependendees);
4310 # &target_cmp ($A, $B)
4311 # --------------------
4312 # Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
4325 # &handle_factored_dependencies ()
4326 # --------------------------------
4327 # Handle everything related to gathered targets.
4328 sub handle_factored_dependencies
4331 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4332 'uninstall-exec-local', 'uninstall-exec-hook')
4334 if (&target_defined ($utarg))
4337 $x =~ s/(data|exec)-//;
4338 target_error ($utarg, "use `$x', not `$utarg'");
4342 if (&target_defined ('install-local'))
4344 target_error ('install-local',
4345 "use `install-data-local' or `install-exec-local', "
4346 . "not `install-local'");
4349 if (!defined $options{'no-installinfo'}
4350 && &target_defined ('install-info-local'))
4352 target_error ('install-info-local',
4353 "`install-info-local' target defined but "
4354 . "`no-installinfo' option not in use");
4357 # Install the -local hooks.
4358 foreach (keys %dependencies)
4360 # Hooks are installed on the -am targets.
4362 if (&target_defined ("$_-local"))
4364 depend ("$_-am", "$_-local");
4365 &depend ('.PHONY', "$_-local");
4369 # Install the -hook hooks.
4370 # FIXME: Why not be as liberal as we are with -local hooks?
4371 foreach ('install-exec', 'install-data', 'uninstall')
4373 if (&target_defined ("$_-hook"))
4375 $actions{"$_-am"} .=
4376 ("\t\@\$(NORMAL_INSTALL)\n"
4377 . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
4381 # All the required targets are phony.
4382 depend ('.PHONY', keys %required_targets);
4384 # Actually output gathered targets.
4385 foreach (sort target_cmp keys %dependencies)
4387 # If there is nothing about this guy, skip it.
4389 unless (@{$dependencies{$_}}
4391 || $required_targets{$_});
4392 &pretty_print_rule ("$_:", "\t",
4393 uniq (sort @{$dependencies{$_}}));
4394 $output_rules .= $actions{$_}
4395 if defined $actions{$_};
4396 $output_rules .= "\n";
4401 # &handle_tests_dejagnu ()
4402 # ------------------------
4403 sub handle_tests_dejagnu
4405 push (@check_tests, 'check-DEJAGNU');
4406 $output_rules .= file_contents ('dejagnu');
4410 # Handle TESTS variable and other checks.
4413 if (defined $options{'dejagnu'})
4415 &handle_tests_dejagnu;
4419 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4422 "`$c' defined but `dejagnu' not in `AUTOMAKE_OPTIONS'")
4423 if variable_defined ($c);
4427 if (variable_defined ('TESTS'))
4429 push (@check_tests, 'check-TESTS');
4430 $output_rules .= &file_contents ('check');
4434 # Handle Emacs Lisp.
4435 sub handle_emacs_lisp
4437 my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4440 return if ! @elfiles;
4442 # Generate .elc files.
4443 my @elcfiles = map { $_ . 'c' } @elfiles;
4444 define_pretty_variable ('ELCFILES', '', @elcfiles);
4446 push (@all, '$(ELCFILES)');
4448 &am_error ("`lisp_LISP' defined but `AM_PATH_LISPDIR' not in `$configure_ac'")
4449 if ! $am_lispdir_location && variable_defined ('lisp_LISP');
4451 require_conf_file ($am_lispdir_location, FOREIGN, 'elisp-comp');
4452 &define_variable ('elisp_comp', $config_aux_dir . '/elisp-comp');
4458 my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4459 'python', 'noinst');
4460 return if ! @pyfiles;
4462 # Found some python.
4463 &am_error ("`python_PYTHON' defined but `AM_PATH_PYTHON' not in `$configure_ac'")
4464 if ! $pythondir_location && variable_defined ('python_PYTHON');
4466 require_conf_file ($pythondir_location, FOREIGN, 'py-compile');
4467 &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4473 my @sourcelist = &am_install_var ('-candist',
4475 'java', 'noinst', 'check');
4476 return if ! @sourcelist;
4478 my @prefix = am_primary_prefixes ('JAVA', 1,
4479 'java', 'noinst', 'check');
4482 foreach my $curs (@prefix)
4485 if $curs eq 'EXTRA';
4487 macro_error ($curs . '_JAVA',
4488 "multiple _JAVA primaries in use")
4494 push (@all, 'class' . $dir . '.stamp');
4498 # Handle some of the minor options.
4499 sub handle_minor_options
4501 if (defined $options{'readme-alpha'})
4503 if ($relative_dir eq '.')
4505 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4507 # FIXME: allow real filename.
4508 file_error ($package_version_location,
4509 "version `$package_version' doesn't follow Gnits standards");
4511 elsif (defined $1 && -f 'README-alpha')
4513 # This means we have an alpha release. See
4514 # GNITS_VERSION_PATTERN for details.
4515 require_file_with_macro ('AUTOMAKE_OPTIONS',
4516 FOREIGN, 'README-alpha');
4522 ################################################################
4524 # ($OUTPUT, @INPUTS)
4525 # &split_config_file_spec ($SPEC)
4526 # -------------------------------
4527 # Decode the Autoconf syntax for config files (files, headers, links
4529 sub split_config_file_spec ($)
4532 my ($output, @inputs) = split (/:/, $spec);
4534 push @inputs, "$output.in"
4537 return ($output, @inputs);
4543 # &scan_autoconf_config_files ($CONFIG-FILES)
4544 # -------------------------------------------
4545 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4547 sub scan_autoconf_config_files
4549 my ($config_files) = @_;
4550 # Look at potential Makefile.am's.
4551 foreach (split ' ', $config_files)
4553 # Must skip empty string for Perl 4.
4554 next if $_ eq "\\" || $_ eq '';
4556 # Handle $local:$input syntax. Note that we ignore
4557 # every input file past the first, though we keep
4558 # those around for later.
4559 my ($local, $input, @rest) = split (/:/);
4566 # FIXME: should be error if .in is missing.
4567 $input =~ s/\.in$//;
4570 if (-f $input . '.am')
4572 # We have a file that automake should generate.
4573 $make_list{$input} = join (':', ($local, @rest));
4577 # We have a file that automake should cause to be
4578 # rebuilt, but shouldn't generate itself.
4579 push (@other_input_files, $_);
4585 # &scan_autoconf_traces ($FILENAME)
4586 # ---------------------------------
4587 sub scan_autoconf_traces ($)
4589 my ($filename) = @_;
4591 my @traced = qw(AC_CANONICAL_HOST
4598 AC_PROG_LIBTOOL AM_PROG_LIBTOOL
4611 my $traces = ($ENV{AUTOCONF} || 'autoconf') . " ";
4613 # Use a separator unlikely to be used, not `:', the default, which
4614 # has a precise meaning for AC_CONFIG_FILES and so on.
4615 $traces .= join (' ',
4616 map { "--trace=$_" . ':\$f:\$l::\$n::\${::}%' } @traced);
4618 my $tracefh = new Automake::XFile ("$traces $filename |");
4619 verbose "reading $traces";
4621 while ($_ = $tracefh->getline)
4624 my ($here, @args) = split /::/;
4625 my $macro = $args[0];
4627 # Alphabetical ordering please.
4628 if ($macro eq 'AC_CANONICAL_HOST')
4630 if (! $seen_canonical)
4632 $seen_canonical = AC_CANONICAL_HOST;
4633 $canonical_location = $here;
4636 elsif ($macro eq 'AC_CANONICAL_SYSTEM')
4638 $seen_canonical = AC_CANONICAL_SYSTEM;
4639 $canonical_location = $here;
4641 elsif ($macro eq 'AC_CONFIG_AUX_DIR')
4643 @config_aux_path = $args[1];
4644 $config_aux_dir_set_in_configure_in = 1;
4646 elsif ($macro eq 'AC_CONFIG_FILES')
4648 # Look at potential Makefile.am's.
4649 $ac_config_files_location = $here;
4650 &scan_autoconf_config_files ($args[1]);
4652 elsif ($macro eq 'AC_INIT')
4654 if (defined $args[2])
4656 $package_version = $args[2];
4657 $package_version_location = $here;
4660 elsif ($macro eq 'AC_LIBSOURCE')
4662 $libsources{$args[1]} = $here;
4664 elsif ($macro =~ /^A(C|M)_PROG_LIBTOOL$/)
4666 $seen_libtool = $here;
4668 elsif ($macro eq 'AC_PROG_LEX')
4670 $seen_prog_lex = $here;
4672 elsif ($macro eq 'AC_SUBST'
4673 # Explicitly avoid ANSI2KNR -- we AC_SUBST that in
4674 # protos.m4, but later define it elsewhere. This is
4675 # pretty hacky. We also explicitly avoid AMDEPBACKSLASH:
4676 # it might be subst'd by `\', which certainly would not be
4677 # appreciated by Make.
4678 && ! grep { $_ eq $args[1] } (qw(ANSI2KNR AMDEPBACKSLASH)))
4680 # Just check for alphanumeric in AC_SUBST. If you do
4681 # AC_SUBST(5), then too bad.
4682 $configure_vars{$args[1]} = $here
4683 if $args[1] =~ /^\w+$/;
4685 elsif ($macro eq 'AM_AUTOMAKE_VERSION')
4688 "version mismatch. This is Automake $VERSION,\n" .
4689 "but the definition used by this AM_INIT_AUTOMAKE\n" .
4690 "comes from Automake $args[1]. You should recreate\n" .
4691 "aclocal.m4 with aclocal and run automake again.\n")
4692 if ($VERSION ne $args[1]);
4694 $seen_automake_version = 1;
4696 elsif ($macro eq 'AM_CONDITIONAL')
4698 $configure_cond{$args[1]} = $here;
4700 elsif ($macro eq 'AM_CONFIG_HEADER')
4702 $config_header_location = $here;
4703 push @config_headers, split (' ', $args[1]);
4705 elsif ($macro eq 'AM_C_PROTOTYPES')
4707 $am_c_prototypes = $here;
4709 elsif ($macro eq 'AM_GNU_GETTEXT')
4711 $seen_gettext = $here;
4712 $ac_gettext_location = $here;
4714 elsif ($macro eq 'AM_INIT_AUTOMAKE')
4716 $seen_init_automake = $here;
4717 if (defined $args[2])
4719 $package_version = $args[2];
4720 $package_version_location = $here;
4722 elsif (defined $args[1])
4724 $global_options = $args[1];
4727 elsif ($macro eq 'AM_MAINTAINER_MODE')
4729 $seen_maint_mode = $here;
4731 elsif ($macro eq 'AM_PATH_LISPDIR')
4733 $am_lispdir_location = $here;
4735 elsif ($macro eq 'AM_PATH_PYTHON')
4737 $pythondir_location = $here;
4739 elsif ($macro eq 'AM_PROG_CC_C_O')
4741 $seen_cc_c_o = $here;
4747 # &scan_autoconf_files ()
4748 # -----------------------
4749 # Check whether we use `configure.ac' or `configure.in'.
4750 # Scan it (and possibly `aclocal.m4') for interesting things.
4751 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
4752 sub scan_autoconf_files
4754 # Reinitialize libsources here. This isn't really necessary,
4755 # since we currently assume there is only one configure.ac. But
4756 # that won't always be the case.
4759 $configure_ac = find_configure_ac;
4760 die "$me: `configure.ac' or `configure.in' is required\n"
4763 scan_autoconf_traces ($configure_ac);
4765 # Set input and output files if not specified by user.
4768 @input_files = sort keys %make_list;
4769 %output_files = %make_list;
4772 @configure_input_files = sort keys %make_list;
4774 conf_error ("`AM_INIT_AUTOMAKE' must be used")
4775 if ! $seen_init_automake;
4777 if (! $seen_automake_version)
4779 if (-f 'aclocal.m4')
4781 file_error ($seen_init_automake || $me,
4782 "your implementation of AM_INIT_AUTOMAKE comes from " .
4783 "an\nold Automake version. You should recreate " .
4784 "aclocal.m4\nwith aclocal and run automake again.\n");
4788 file_error ($seen_init_automake || $me,
4789 "no proper implementation of AM_INIT_AUTOMAKE was " .
4790 "found,\nprobably because aclocal.m4 is missing...\n" .
4791 "You should run aclocal to create this file, then\n" .
4792 "run automake again.\n");
4796 # Look for some files we need. Always check for these. This
4797 # check must be done for every run, even those where we are only
4798 # looking at a subdir Makefile. We must set relative_dir so that
4799 # the file-finding machinery works.
4800 # FIXME: Is this broken because it needs dynamic scopes.
4801 # My tests seems to show it's not the case.
4802 $relative_dir = '.';
4803 require_conf_file ($configure_ac, FOREIGN,
4804 'install-sh', 'mkinstalldirs', 'missing');
4805 am_error ("`install.sh' is an anachronism; use `install-sh' instead")
4806 if -f $config_aux_path[0] . '/install.sh';
4808 require_conf_file ($pythondir_location, FOREIGN, 'py-compile')
4809 if $pythondir_location;
4811 # Preserve dist_common for later.
4812 $configure_dist_common = variable_value ('DIST_COMMON', 'TRUE') || '';
4815 ################################################################
4817 # Set up for Cygnus mode.
4820 return unless $cygnus_mode;
4822 &set_strictness ('foreign');
4823 $options{'no-installinfo'} = 1;
4824 $options{'no-dependencies'} = 1;
4825 $use_dependencies = 0;
4827 conf_error ("`AM_MAINTAINER_MODE' required when --cygnus specified")
4828 if !$seen_maint_mode;
4831 # Do any extra checking for GNU standards.
4832 sub check_gnu_standards
4834 if ($relative_dir eq '.')
4836 # In top level (or only) directory.
4838 # Accept one of these three licenses; default to COPYING.
4839 my $license = 'COPYING';
4840 foreach (qw /COPYING.LIB COPYING.LESSER/)
4842 $license = $_ if -f $_;
4844 require_file ("$am_file.am", GNU, $license,
4845 qw/INSTALL NEWS README AUTHORS ChangeLog/);
4848 if ($strictness >= GNU
4849 && defined $options{'no-installman'})
4851 macro_error ('AUTOMAKE_OPTIONS',
4852 "option `no-installman' disallowed by GNU standards");
4855 if ($strictness >= GNU
4856 && defined $options{'no-installinfo'})
4858 macro_error ('AUTOMAKE_OPTIONS',
4859 "option `no-installinfo' disallowed by GNU standards");
4863 # Do any extra checking for GNITS standards.
4864 sub check_gnits_standards
4866 if ($relative_dir eq '.')
4868 # In top level (or only) directory.
4869 require_file ("$am_file.am", GNITS, 'THANKS');
4873 ################################################################
4875 # Functions to handle files of each language.
4877 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
4878 # simple formula: Return value is $LANG_SUBDIR if the resulting object
4879 # file should be in a subdir if the source file is, $LANG_PROCESS if
4880 # file is to be dealt with, $LANG_IGNORE otherwise.
4882 # Much of the actual processing is handled in
4883 # handle_single_transform_list. These functions exist so that
4884 # auxiliary information can be recorded for a later cleanup pass.
4885 # Note that the calls to these functions are computed, so don't bother
4886 # searching for their precise names in the source.
4888 # This is just a convenience function that can be used to determine
4889 # when a subdir object should be used.
4892 return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4895 # Rewrite a single C source file.
4898 my ($directory, $base, $ext) = @_;
4900 if (defined $options{'ansi2knr'} && $base =~ /_$/)
4902 # FIXME: include line number in error.
4903 am_error ("C source file `$base.c' would be deleted by ansi2knr rules");
4906 my $r = $LANG_PROCESS;
4907 if (defined $options{'subdir-objects'})
4910 $base = $directory . '/' . $base
4911 unless $directory eq '.' || $directory eq '';
4915 # Only give error once.
4917 # FIXME: line number.
4918 am_error ("C objects in subdir but `AM_PROG_CC_C_O' not in `$configure_ac'");
4921 require_conf_file ("$am_file.am", FOREIGN, 'compile');
4923 # In this case we already have the directory information, so
4924 # don't add it again.
4925 $de_ansi_files{$base} = '';
4929 $de_ansi_files{$base} = (($directory eq '.' || $directory eq '')
4937 # Rewrite a single C++ source file.
4938 sub lang_cxx_rewrite
4940 return &lang_sub_obj;
4943 # Rewrite a single header file.
4944 sub lang_header_rewrite
4946 # Header files are simply ignored.
4947 return $LANG_IGNORE;
4950 # Rewrite a single yacc file.
4951 sub lang_yacc_rewrite
4953 my ($directory, $base, $ext) = @_;
4955 my $r = &lang_sub_obj;
4956 (my $newext = $ext) =~ tr/y/c/;
4957 return ($r, $newext);
4960 # Rewrite a single yacc++ file.
4961 sub lang_yaccxx_rewrite
4963 my ($directory, $base, $ext) = @_;
4965 my $r = &lang_sub_obj;
4966 (my $newext = $ext) =~ tr/y/c/;
4967 return ($r, $newext);
4970 # Rewrite a single lex file.
4971 sub lang_lex_rewrite
4973 my ($directory, $base, $ext) = @_;
4975 my $r = &lang_sub_obj;
4976 (my $newext = $ext) =~ tr/l/c/;
4977 return ($r, $newext);
4980 # Rewrite a single lex++ file.
4981 sub lang_lexxx_rewrite
4983 my ($directory, $base, $ext) = @_;
4985 my $r = &lang_sub_obj;
4986 (my $newext = $ext) =~ tr/l/c/;
4987 return ($r, $newext);
4990 # Rewrite a single assembly file.
4991 sub lang_asm_rewrite
4993 return &lang_sub_obj;
4996 # Rewrite a single Fortran 77 file.
4997 sub lang_f77_rewrite
4999 return $LANG_PROCESS;
5002 # Rewrite a single preprocessed Fortran 77 file.
5003 sub lang_ppf77_rewrite
5005 return $LANG_PROCESS;
5008 # Rewrite a single ratfor file.
5009 sub lang_ratfor_rewrite
5011 return $LANG_PROCESS;
5014 # Rewrite a single Objective C file.
5015 sub lang_objc_rewrite
5017 return &lang_sub_obj;
5020 # Rewrite a single Java file.
5021 sub lang_java_rewrite
5023 return $LANG_SUBDIR;
5026 # The lang_X_finish functions are called after all source file
5027 # processing is done. Each should handle defining rules for the
5028 # language, etc. A finish function is only called if a source file of
5029 # the appropriate type has been seen.
5033 # Push all libobjs files onto de_ansi_files. We actually only
5034 # push files which exist in the current directory, and which are
5035 # genuine source files.
5036 foreach my $file (keys %libsources)
5038 if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
5040 $de_ansi_files{$1} = (($relative_dir eq '.' || $relative_dir eq '')
5042 : "$relative_dir/");
5046 if (defined $options{'ansi2knr'} && keys %de_ansi_files)
5048 # Make all _.c files depend on their corresponding .c files.
5050 foreach my $base (sort keys %de_ansi_files)
5052 # Each _.c file must depend on ansi2knr; otherwise it
5053 # might be used in a parallel build before it is built.
5054 # We need to support files in the srcdir and in the build
5055 # dir (because these files might be auto-generated. But
5056 # we can't use $< -- some makes only define $< during a
5058 my $ansfile = $de_ansi_files{$base} . $base . '.c';
5059 $output_rules .= ($base . "_.c: $ansfile \$(ANSI2KNR)\n\t"
5060 . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5061 . '`if test -f $(srcdir)/' . $ansfile
5062 . '; then echo $(srcdir)/' . $ansfile
5063 . '; else echo ' . $ansfile . '; fi` '
5064 . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5065 . '| $(ANSI2KNR) > ' . $base . "_.c"
5066 # If ansi2knr fails then we shouldn't
5067 # create the _.c file
5068 . " || rm -f ${base}_.c\n");
5069 push (@objects, $base . '_.$(OBJEXT)');
5070 push (@objects, $base . '_.lo')
5074 # Make all _.o (and _.lo) files depend on ansi2knr.
5075 # Use a sneaky little hack to make it print nicely.
5076 &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5080 # This is a yacc helper which is called whenever we have decided to
5081 # compile a yacc file.
5082 sub lang_yacc_target_hook
5084 my ($self, $aggregate, $output, $input) = @_;
5086 my $flag = $aggregate . "_YFLAGS";
5087 if ((variable_defined ($flag)
5088 && &variable_value ($flag) =~ /$DASH_D_PATTERN/o)
5089 || (variable_defined ('YFLAGS')
5090 && &variable_value ('YFLAGS') =~ /$DASH_D_PATTERN/o))
5092 (my $output_base = $output) =~ s/$KNOWN_EXTENSIONS_PATTERN$//;
5093 my $header = $output_base . '.h';
5095 # Found a `-d' that applies to the compilation of this file.
5096 # Add a dependency for the generated header file, and arrange
5097 # for that file to be included in the distribution.
5098 # FIXME: this fails for `nodist_*_SOURCES'.
5099 $output_rules .= ("${header}: $output\n"
5100 # Recover from removal of $header
5101 . "\t\@if test ! -f \$@; then \\\n"
5102 . "\t rm -f $output; \\\n"
5103 . "\t \$(MAKE) $output; \\\n"
5104 . "\telse :; fi\n");
5105 &push_dist_common ($header);
5106 # If the files are built in the build directory, then we want
5107 # to remove them with `make clean'. If they are in srcdir
5108 # they shouldn't be touched. However, we can't determine this
5109 # statically, and the GNU rules say that yacc/lex output files
5110 # should be removed by maintainer-clean. So that's what we
5112 push (@maintainer_clean_files, $header);
5116 # This is a helper for both lex and yacc.
5117 sub yacc_lex_finish_helper
5119 return if defined $language_scratch{'lex-yacc-done'};
5120 $language_scratch{'lex-yacc-done'} = 1;
5122 # If there is more than one distinct yacc (resp lex) source file
5123 # in a given directory, then the `ylwrap' program is required to
5124 # allow parallel builds to work correctly. FIXME: for now, no
5126 require_conf_file ($configure_ac, FOREIGN, 'ylwrap');
5127 if ($config_aux_dir_set_in_configure_in)
5129 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5133 &define_variable ('YLWRAP', '$(top_srcdir)/ylwrap');
5137 sub lang_yacc_finish
5139 return if defined $language_scratch{'yacc-done'};
5140 $language_scratch{'yacc-done'} = 1;
5142 macro_error ('YACCFLAGS',
5143 "`YACCFLAGS' obsolete; use `YFLAGS' instead")
5144 if variable_defined ('YACCFLAGS');
5146 if (count_files_for_language ('yacc') > 1)
5148 &yacc_lex_finish_helper;
5155 return if defined $language_scratch{'lex-done'};
5156 $language_scratch{'lex-done'} = 1;
5158 am_error ("lex source seen but `AM_PROG_LEX' not in `$configure_ac'")
5159 unless $seen_prog_lex;
5161 if (count_files_for_language ('lex') > 1)
5163 &yacc_lex_finish_helper;
5168 # Given a hash table of linker names, pick the name that has the most
5169 # precedence. This is lame, but something has to have global
5170 # knowledge in order to eliminate the conflict. Add more linkers as
5176 foreach my $l (qw(GCJLINK CXXLINK F77LINK OBJCLINK))
5178 return $l if defined $linkers{$l};
5183 # Called to indicate that an extension was used.
5187 if (! defined $extension_seen{$ext})
5189 $extension_seen{$ext} = 1;
5193 ++$extension_seen{$ext};
5197 # Return the number of files seen for a given language. Knows about
5198 # special cases we care about. FIXME: this is hideous. We need
5199 # something that involves real language objects. For instance yacc
5200 # and yaccxx could both derive from a common yacc class which would
5201 # know about the strange ylwrap requirement. (Or better yet we could
5202 # just not support legacy yacc!)
5203 sub count_files_for_language
5208 if ($name eq 'yacc' || $name eq 'yaccxx')
5210 @names = ('yacc', 'yaccxx');
5212 elsif ($name eq 'lex' || $name eq 'lexxx')
5214 @names = ('lex', 'lexxx');
5222 foreach $name (@names)
5224 my $lang = $languages{$name};
5225 foreach my $ext (@{$lang->extensions})
5227 $r += $extension_seen{$ext}
5228 if defined $extension_seen{$ext};
5235 # Called to ask whether source files have been seen . If HEADERS is 1,
5236 # headers can be included.
5241 # count all the sources
5243 foreach my $val (values %extension_seen)
5250 $count -= count_files_for_language ('header');
5257 # register_language (%ATTRIBUTE)
5258 # ------------------------------
5259 # Register a single language.
5260 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5261 sub register_language (%)
5267 unless defined $option{'ansi'};
5268 $option{'autodep'} = 'no'
5269 unless defined $option{'autodep'};
5270 $option{'linker'} = ''
5271 unless defined $option{'linker'};
5273 my $lang = new Language (%option);
5276 grep ($extension_map{$_} = $lang->name, @{$lang->extensions});
5277 $languages{$lang->name} = $lang;
5279 # Update the pattern of known extensions.
5280 accept_extensions (@{$lang->extensions});
5283 # derive_suffix ($EXT, $OBJ)
5284 # --------------------------
5285 # This function is used to find a path from a user-specified suffix $EXT
5286 # to $OBJ or to some other suffix we recognize internally, eg `cc'.
5287 sub derive_suffix ($$)
5289 my ($source_ext, $obj) = @_;
5291 while (! $extension_map{$source_ext}
5292 && $source_ext ne $obj
5293 && defined $suffix_rules{$source_ext})
5295 $source_ext = $suffix_rules{$source_ext};
5302 ################################################################
5304 # Pretty-print something. HEAD is what should be printed at the
5305 # beginning of the first line, FILL is what should be printed at the
5306 # beginning of every subsequent line.
5307 sub pretty_print_internal
5309 my ($head, $fill, @values) = @_;
5311 my $column = length ($head);
5314 # Fill length is number of characters. However, each Tab
5315 # character counts for eight. So we count the number of Tabs and
5317 my $fill_length = length ($fill);
5318 $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5322 # "71" because we also print a space.
5323 if ($column + length ($_) > 71)
5325 $result .= " \\\n" . $fill;
5326 $column = $fill_length;
5328 $result .= ' ' if $result =~ /\S\z/;
5330 $column += length ($_) + 1;
5337 # Pretty-print something and append to output_vars.
5340 $output_vars .= &pretty_print_internal (@_);
5343 # Pretty-print something and append to output_rules.
5344 sub pretty_print_rule
5346 $output_rules .= &pretty_print_internal (@_);
5350 ################################################################
5354 # &conditional_string(@COND-STACK)
5355 # --------------------------------
5356 # Build a string which denotes the conditional in @COND-STACK. Some
5357 # simplifications are done: `TRUE' entries are elided, and any `FALSE'
5358 # entry results in a return of `FALSE'.
5359 sub conditional_string
5363 if (grep (/^FALSE$/, @stack))
5369 return join (' ', uniq sort grep (!/^TRUE$/, @stack));
5375 # &conditional_true_when ($COND, $WHEN)
5376 # -------------------------------------
5377 # See if a conditional is true. Both arguments are conditional
5378 # strings. This returns true if the first conditional is true when
5379 # the second conditional is true.
5380 # For instance with $COND = `BAR FOO', and $WHEN = `BAR BAZ FOO',
5381 # obviously return 1, and 0 when, for instance, $WHEN = `FOO'.
5382 sub conditional_true_when ($$)
5384 my ($cond, $when) = @_;
5386 # Make a hash holding all the values from $WHEN.
5387 my %cond_vals = map { $_ => 1 } split (' ', $when);
5389 # Nothing is true when FALSE (not even FALSE itself, but it
5390 # shouldn't hurt if you decide to change that).
5391 return 0 if exists $cond_vals{'FALSE'};
5393 # Check each component of $cond, which looks `COND1 COND2'.
5394 foreach my $comp (split (' ', $cond))
5396 # TRUE is always true.
5397 next if $comp eq 'TRUE';
5398 return 0 if ! defined $cond_vals{$comp};
5406 # &conditional_is_redundant ($COND, @WHENS)
5407 # ----------------------------------------
5408 # Determine whether $COND is redundant with respect to @WHENS.
5410 # Returns true if $COND is true for any of the conditions in @WHENS.
5412 # If there are no @WHENS, then behave as if @WHENS contained a single empty
5414 sub conditional_is_redundant ($@)
5416 my ($cond, @whens) = @_;
5418 @whens = ("") if @whens == 0;
5420 foreach my $when (@whens)
5422 return 1 if conditional_true_when ($cond, $when);
5429 # &conditional_implies_any ($COND, @CONDS)
5430 # ----------------------------------------
5431 # Returns true iff $COND implies any of the conditions in @CONDS.
5432 sub conditional_implies_any ($@)
5434 my ($cond, @conds) = @_;
5436 @conds = ("") if @conds == 0;
5438 foreach my $c (@conds)
5440 return 1 if conditional_true_when ($c, $cond);
5447 # condition_negate ($COND)
5448 # ------------------------
5449 sub condition_negate ($)
5453 $cond =~ s/TRUE$/TRUEO/;
5454 $cond =~ s/FALSE$/TRUE/;
5455 $cond =~ s/TRUEO$/FALSE/;
5461 # Compare condition names.
5462 # Issue them in alphabetical order, foo_TRUE before foo_FALSE.
5465 # Be careful we might be comparing `' or `#'.
5466 $a =~ /^(.*)_(TRUE|FALSE)$/;
5467 my ($aname, $abool) = ($1 || '', $2 || '');
5468 $b =~ /^(.*)_(TRUE|FALSE)$/;
5469 my ($bname, $bbool) = ($1 || '', $2 || '');
5470 return ($aname cmp $bname
5471 # Don't bother with IFs, given that TRUE is after FALSE
5472 # just cmp in the reverse order.
5473 || $bbool cmp $abool
5479 # &make_condition (@CONDITIONS)
5480 # -----------------------------
5481 # Transform a list of conditions (themselves can be an internal list
5482 # of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
5483 # Make conditional (a pattern for AC_SUBST).
5484 # Correctly returns the empty string when there are no conditions.
5487 my $res = conditional_string (@_);
5489 # There are no conditions.
5495 elsif ($res eq 'FALSE')
5502 $res = '@' . $res . '@';
5511 ## ------------------------------ ##
5512 ## Handling the condition stack. ##
5513 ## ------------------------------ ##
5517 # cond_stack_if ($NEGATE, $COND, $WHERE)
5518 # --------------------------------------
5519 sub cond_stack_if ($$$)
5521 my ($negate, $cond, $where) = @_;
5523 file_error ($where, "$cond does not appear in AM_CONDITIONAL")
5524 if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
5526 $cond = "${cond}_TRUE"
5527 unless $cond =~ /^TRUE|FALSE$/;
5528 $cond = condition_negate ($cond)
5531 push (@cond_stack, $cond);
5533 return conditional_string (@cond_stack);
5538 # cond_stack_else ($NEGATE, $COND, $WHERE)
5539 # ----------------------------------------
5540 sub cond_stack_else ($$$)
5542 my ($negate, $cond, $where) = @_;
5546 file_error ($where, "else without if");
5550 $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);
5552 # If $COND is given, check against it.
5555 $cond = "${cond}_TRUE"
5556 unless $cond =~ /^TRUE|FALSE$/;
5557 $cond = condition_negate ($cond)
5561 "else reminder ($negate$cond) incompatible with "
5562 . "current conditional: $cond_stack[$#cond_stack]")
5563 if $cond_stack[$#cond_stack] ne $cond;
5566 return conditional_string (@cond_stack);
5571 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5572 # -----------------------------------------
5573 sub cond_stack_endif ($$$)
5575 my ($negate, $cond, $where) = @_;
5580 file_error ($where, "endif without if: $negate$cond");
5585 # If $COND is given, check against it.
5588 $cond = "${cond}_TRUE"
5589 unless $cond =~ /^TRUE|FALSE$/;
5590 $cond = condition_negate ($cond)
5594 "endif reminder ($negate$cond) incompatible with "
5595 . "current conditional: $cond_stack[$#cond_stack]")
5596 if $cond_stack[$#cond_stack] ne $cond;
5601 return conditional_string (@cond_stack);
5608 ## ------------------------ ##
5609 ## Handling the variables. ##
5610 ## ------------------------ ##
5613 # check_ambiguous_conditional ($VAR, $COND)
5614 # -----------------------------------------
5615 # Check for an ambiguous conditional. This is called when a variable
5616 # is being defined conditionally. If we already know about a
5617 # definition that is true under the same conditions, then we have an
5619 sub check_ambiguous_conditional ($$)
5621 my ($var, $cond) = @_;
5622 my $message = conditional_ambiguous_p ($var, $cond);
5625 macro_error ($var, $message);
5631 # conditional_ambiguous_p ($VAR, $COND)
5632 # -------------------------------------
5633 # Check for an ambiguous conditional. Return an error message if we
5634 # have one, the empty string otherwise.
5635 sub conditional_ambiguous_p ($$)
5637 my ($var, $cond) = @_;
5638 foreach my $vcond (keys %{$var_value{$var}})
5640 # Note that these rules doesn't consider the following
5641 # example as ambiguous.
5650 # It's up to the user to not define COND1 and COND2
5653 if ($vcond eq $cond)
5655 return "$var multiply defined in condition $cond";
5657 elsif (&conditional_true_when ($vcond, $cond))
5659 return ("$var was already defined in condition $vcond, "
5660 . "which implies condition $cond");
5662 elsif (&conditional_true_when ($cond, $vcond))
5664 return ("$var was already defined in condition $vcond, "
5665 . "which is implied by condition $cond");
5673 # variable_not_always_defined_in_cond ($VAR, $COND)
5674 # ---------------------------------------------
5675 # Check whether $VAR is always defined for condition $COND.
5676 # Return a list of conditions where the definition is missing.
5678 # For instance, given
5698 # variable_not_always_defined_in_cond ('A', 'COND1_TRUE COND2_TRUE')
5700 # variable_not_always_defined_in_cond ('A', 'COND1_TRUE')
5702 # variable_not_always_defined_in_cond ('A', 'TRUE')
5703 # => ("COND1_FALSE COND2_FALSE COND3_FALSE",
5704 # "COND1_FALSE COND2_TRUE COND3_FALSE",
5705 # "COND1_TRUE COND2_FALSE COND3_FALSE",
5706 # "COND1_TRUE COND2_TRUE COND3_FALSE")
5707 # variable_not_always_defined_in_cond ('B', 'COND1_TRUE')
5708 # => ("COND3_FALSE")
5709 # variable_not_always_defined_in_cond ('C', 'COND1_TRUE')
5711 # variable_not_always_defined_in_cond ('D', 'TRUE')
5713 # variable_not_always_defined_in_cond ('Z', 'TRUE')
5716 sub variable_not_always_defined_in_cond ($$)
5718 my ($var, $cond) = @_;
5720 # It's easy to answer if the variable is not defined.
5721 return ("TRUE",) unless exists $var_value{$var};
5723 # How does it work? Let's take the second example:
5725 # variable_not_always_defined_in_cond ('A', 'COND1_TRUE')
5727 # (1) First, we get the list of conditions where A is defined:
5729 # ("COND1_TRUE COND2_TRUE", "COND1_TRUE COND2_FALSE", "COND3_TRUE")
5731 # (2) Then we generate the set of inverted conditions:
5733 # ("COND1_FALSE COND2_TRUE COND3_FALSE",
5734 # "COND1_FALSE COND2_FALSE COND3_FALSE")
5736 # (3) Finally we remove these conditions which are not implied by
5737 # COND1_TRUE. This yields an empty list and we are done.
5740 my @cond_defs = keys %{$var_value{$var}}; # (1)
5741 foreach my $icond (invert_conditions (@cond_defs)) # (2)
5743 prog_error ("invert_conditions returned an input condition")
5744 if exists $var_value{$var}{$icond};
5747 if (conditional_true_when ($cond, $icond)); # (3)
5752 # ¯o_define($VAR, $VAR_IS_AM, $TYPE, $COND, $VALUE, $WHERE)
5753 # -------------------------------------------------------------
5754 # The $VAR can go from Automake to user, but not the converse.
5755 sub macro_define ($$$$$$)
5757 my ($var, $var_is_am, $type, $cond, $value, $where) = @_;
5759 file_error ($where, "bad macro name `$var'")
5760 if $var !~ /$MACRO_PATTERN/o;
5764 # An Automake variable must be consistently defined with the same
5765 # sign by Automake. A user variable must be set by either `=' or
5766 # `:=', and later promoted to `+='.
5769 if (defined $var_type{$var} && $var_type{$var} ne $type)
5772 ("$var was set with `$var_type{$var}=' "
5773 . "and is now set with `$type='"));
5778 if (!defined $var_type{$var} && $type eq '+')
5780 file_error ($where, "$var must be set with `=' before using `+='");
5783 $var_type{$var} = $type;
5785 # When adding, since we rewrite, don't try to preserve the
5786 # Automake continuation backslashes.
5788 if $type eq '+' && $var_is_am;
5790 # Differentiate assignment types.
5792 # 1. append (+=) to a variable defined for current condition
5793 if ($type eq '+' && defined $var_value{$var}{$cond})
5795 if (chomp $var_value{$var}{$cond})
5797 # Insert a backslash before a trailing newline.
5798 $var_value{$var}{$cond} .= "\\\n";
5800 elsif ($var_value{$var}{$cond})
5802 # Insert a separator.
5803 $var_value{$var}{$cond} .= ' ';
5805 $var_value{$var}{$cond} .= $value;
5807 # 2. append (+=) to a variable defined for *another* condition
5808 elsif ($type eq '+' && keys %{$var_value{$var}})
5810 # * Generally, $cond is not TRUE. For instance:
5815 # In this case, we declare an helper variable conditionally,
5816 # and append it to FOO:
5817 # FOO = foo $(am__append_1)
5818 # @COND_TRUE@am__append_1 = bar
5819 # Of course if FOO is defined under several conditions, we add
5820 # $(am__append_1) to each definitions.
5822 # * If $cond is TRUE, we don't need the helper variable. E.g., in
5829 # we can add bar directly to all definition of FOO, and output
5830 # @COND_TRUE@FOO = foo1 bar
5831 # @COND_FALSE@FOO = foo2 bar
5833 # Do we need an helper variable?
5834 if ($cond ne 'TRUE')
5836 # Does the helper variable already exists?
5837 my $key = "$var:$cond";
5838 if (exists $appendvar{$key})
5840 # Yes, let's simply append to it.
5841 $var = $appendvar{$key};
5847 my $num = 1 + keys (%appendvar);
5848 my $hvar = "am__append_$num";
5849 $appendvar{$key} = $hvar;
5850 ¯o_define ($hvar, 1, '+', $cond, $value, $where);
5851 push @var_list, $hvar;
5852 # Now HVAR is to be added to VAR.
5853 $value = "\$($hvar)";
5857 # Add VALUE to all definitions of VAR.
5858 foreach my $vcond (keys %{$var_value{$var}})
5860 # We have a bit of error detection to do here.
5866 # should be rejected because X is not defined for all conditions
5867 # where `+=' applies.
5868 my @undef_cond = variable_not_always_defined_in_cond $var, $cond;
5869 if (@undef_cond != 0)
5872 "Cannot apply `+=' because `$var' is not defined "
5873 . "in\nthe following conditions:\n "
5874 . join ("\n ", @undef_cond)
5875 . "\nEither define `$var' in these conditions,"
5876 . " or use\n`+=' in the same conditions as"
5877 . " the definitions.");
5881 ¯o_define ($var, $var_is_am, '+', $vcond, $value, $where);
5885 # 3. first assignment (=, :=, or +=)
5888 # The first assignment to a macro sets its location. Ideally I
5889 # suppose we would associate line numbers with random bits of text.
5890 # FIXME: We sometimes redefine some variables, but we want to keep
5891 # the original location. More subs are needed to handle
5892 # properly variables. Once this done, remove this hack.
5893 $var_location{$var} = $where
5894 unless defined $var_location{$var};
5896 # If Automake tries to override a value specified by the user,
5897 # just don't let it do.
5898 if (defined $var_value{$var}{$cond} && !$var_is_am{$var} && $var_is_am)
5902 print STDERR "$me: refusing to override the user definition of:\n";
5904 print STDERR "$me: with `$cond' => `$value'\n";
5909 # There must be no previous value unless the user is redefining
5910 # an Automake variable or an AC_SUBST variable.
5911 check_ambiguous_conditional ($var, $cond)
5912 unless ($var_is_am{$var} && !$var_is_am
5913 || exists $configure_vars{$var});
5915 $var_value{$var}{$cond} = $value;
5919 # An Automake variable can be given to the user, but not the converse.
5920 if (! defined $var_is_am{$var} || !$var_is_am)
5922 $var_is_am{$var} = $var_is_am;
5925 # Call var_VAR_trigger if it's defined.
5926 # This hook helps to update some internal state *while*
5927 # parsing the file. For instance the handling of SUFFIXES
5928 # requires this (see var_SUFFIXES_trigger).
5929 my $var_trigger = "var_${var}_trigger";
5930 &$var_trigger($type, $value) if defined &$var_trigger;
5934 # ¯o_delete ($VAR, [@CONDS])
5935 # ------------------------------
5936 # Forget about $VAR under the conditions @CONDS, or completely if
5938 sub macro_delete ($@)
5940 my ($var, @conds) = @_;
5944 delete $var_value{$var};
5945 delete $var_location{$var};
5946 delete $var_is_am{$var};
5947 delete $var_comment{$var};
5948 delete $var_type{$var};
5952 foreach my $cond (@conds)
5954 delete $var_value{$var}{$cond};
5960 # ¯o_dump ($VAR)
5961 # ------------------
5966 if (!exists $var_value{$var})
5968 print STDERR " $var does not exist\n";
5972 my $var_is_am = $var_is_am{$var} ? "Automake" : "User";
5973 my $where = (defined $var_location{$var}
5974 ? $var_location{$var} : "undefined");
5975 print STDERR "$var_comment{$var}"
5976 if defined $var_comment{$var};
5977 print STDERR " $var ($var_is_am, where = $where) $var_type{$var}=\n";
5978 print STDERR " {\n";
5979 foreach my $vcond (sort by_condition keys %{$var_value{$var}})
5981 print STDERR " $vcond => $var_value{$var}{$vcond}\n";
5983 print STDERR " }\n";
5994 print STDERR "%var_value =\n";
5996 foreach my $var (sort (keys %var_value))
6005 # variable_defined ($VAR, [$COND])
6006 # ---------------------------------
6007 # See if a variable exists. $VAR is the variable name, and $COND is
6008 # the condition which we should check. If no condition is given, we
6009 # currently return true if the variable is defined under any
6011 sub variable_defined ($;$)
6013 my ($var, $cond) = @_;
6015 # Unfortunately we can't just check for $var_value{VAR}{COND}
6016 # as this would make perl create $condition{VAR}, which we
6018 if (!exists $var_value{$var})
6020 macro_error ($var, "`$var' is a target; expected a variable")
6021 if defined $targets{$var};
6022 # The variable is not defined
6026 # The variable is not defined for the given condition.
6028 if $cond && !exists $var_value{$var}{$cond};
6030 # Even a var_value examination is good enough for us. FIXME:
6031 # really should maintain examined status on a per-condition basis.
6032 $content_seen{$var} = 1;
6038 # variable_assert ($VAR, $WHERE)
6039 # ------------------------------
6040 # Make sure a variable exists. $VAR is the variable name, and $WHERE
6041 # is the name of a macro which refers to $VAR.
6042 sub variable_assert ($$)
6044 my ($var, $where) = @_;
6047 if variable_defined $var;
6049 macro_error ($where, "variable `$var' not defined");
6055 # Mark a variable as examined.
6056 sub examine_variable
6059 variable_defined ($var);
6063 # &variable_conditions_recursive ($VAR)
6064 # -------------------------------------
6065 # Return the set of conditions for which a variable is defined.
6067 # If the variable is not defined conditionally, and is not defined in
6068 # terms of any variables which are defined conditionally, then this
6069 # returns the empty list.
6071 # If the variable is defined conditionally, but is not defined in
6072 # terms of any variables which are defined conditionally, then this
6073 # returns the list of conditions for which the variable is defined.
6075 # If the variable is defined in terms of any variables which are
6076 # defined conditionally, then this returns a full set of permutations
6077 # of the subvariable conditions. For example, if the variable is
6078 # defined in terms of a variable which is defined for COND_TRUE,
6079 # then this returns both COND_TRUE and COND_FALSE. This is
6080 # because we will need to define the variable under both conditions.
6081 sub variable_conditions_recursive ($)
6087 my @new_conds = variable_conditions_recursive_sub ($var, '');
6089 # Now we want to return all permutations of the subvariable
6092 foreach my $item (@new_conds)
6094 foreach (split (' ', $item))
6096 s/^(.*)_(TRUE|FALSE)$/$1_TRUE/;
6100 @new_conds = variable_conditions_permutations (sort keys %allconds);
6103 foreach my $cond (@new_conds)
6105 my $reduce = variable_conditions_reduce (split (' ', $cond));
6107 if $reduce eq 'FALSE';
6108 $uniqify{$cond} = 1;
6111 # Note we cannot just do `return sort keys %uniqify', because this
6112 # function is sometimes used in a scalar context.
6113 my @uniq_list = sort by_condition keys %uniqify;
6119 # variable_conditions ($VAR)
6120 # --------------------------
6121 # Get the list of conditions that a variable is defined with, without
6122 # recursing through the conditions of any subvariables.
6123 # Argument is $VAR: the variable to get the conditions of.
6124 # Returns the list of conditions.
6125 sub variable_conditions ($)
6128 my @conds = keys %{$var_value{$var}};
6129 return sort by_condition @conds;
6134 # &variable_conditionally_defined ($VAR)
6135 # --------------------------------------
6136 sub variable_conditionally_defined ($)
6139 foreach my $cond (variable_conditions_recursive ($var))
6142 unless $cond =~ /^TRUE|FALSE$/;
6149 # &variable_conditions_recursive_sub ($VAR, $PARENT)
6150 # -------------------------------------------------------
6151 # A subroutine of variable_conditions_recursive. This returns all the
6152 # conditions of $VAR, including those of any sub-variables.
6153 sub variable_conditions_recursive_sub
6155 my ($var, $parent) = @_;
6158 if (defined $vars_scanned{$var})
6160 macro_error ($parent, "variable `$var' recursively defined");
6163 $vars_scanned{$var} = 1;
6165 my @this_conds = ();
6166 # Examine every condition under which $VAR is defined.
6167 foreach my $vcond (keys %{$var_value{$var}})
6169 push (@this_conds, $vcond);
6171 # If $VAR references some other variable, then compute the
6172 # conditions for that subvariable.
6173 my @subvar_conds = ();
6174 foreach (split (' ', $var_value{$var}{$vcond}))
6176 # If a comment seen, just leave.
6179 # Handle variable substitutions.
6180 if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
6183 if ($varname =~ /$SUBST_REF_PATTERN/o)
6189 # Here we compute all the conditions under which the
6190 # subvariable is defined. Then we go through and add
6192 my @svc = variable_conditions_recursive_sub ($varname, $var);
6193 foreach my $item (@svc)
6195 my $val = conditional_string ($vcond, split (' ', $item));
6197 push (@subvar_conds, $val);
6202 # If there are no conditional subvariables, then we want to
6203 # return this condition. Otherwise, we want to return the
6204 # permutations of the subvariables, taking into account the
6205 # conditions of $VAR.
6206 if (! @subvar_conds)
6208 push (@new_conds, $vcond);
6212 push (@new_conds, variable_conditions_reduce (@subvar_conds));
6216 # Unset our entry in vars_scanned. We only care about recursive
6218 delete $vars_scanned{$var};
6220 # If we are being called on behalf of another variable, we need to
6221 # return all possible permutations of the conditions. We have
6222 # already handled everything in @this_conds along with their
6223 # subvariables. We now need to add any permutations that are not
6225 foreach my $this_cond (@this_conds)
6228 variable_conditions_permutations (split (' ', $this_cond));
6229 foreach my $perm (@perms)
6232 foreach my $scan (@this_conds)
6234 if (&conditional_true_when ($perm, $scan)
6235 || &conditional_true_when ($scan, $perm))
6243 # This permutation was not already handled, and is valid
6245 push (@new_conds, $perm);
6253 # Filter a list of conditionals so that only the exclusive ones are
6254 # retained. For example, if both `COND1_TRUE COND2_TRUE' and
6255 # `COND1_TRUE' are in the list, discard the latter.
6256 # If the list is empty, return TRUE
6257 sub variable_conditions_reduce
6264 $cond = shift(@conds);
6266 # FALSE is absorbent.
6268 if $cond eq 'FALSE';
6270 if (!conditional_is_redundant ($cond, @ret, @conds))
6276 return "TRUE" if @ret == 0;
6281 # invert_conditions (@CONDS)
6282 # --------------------------
6283 # Invert a list of conditionals. Returns a set of conditionals which
6284 # are never true for any of the input conditionals, and when taken
6285 # together with the input conditionals cover all possible cases.
6288 # invert_conditions("A_TRUE B_TRUE", "A_FALSE B_FALSE")
6289 # => ("A_FALSE B_TRUE", "A_TRUE B_FALSE")
6291 # invert_conditions("A_TRUE B_TRUE", "A_TRUE B_FALSE", "A_FALSE")
6293 sub invert_conditions
6299 # Generate all permutation for all inputs.
6301 map { variable_conditions_permutations (split(' ', $_)); } @conds;
6302 # Remove redundant conditions.
6303 @perm = variable_conditions_reduce @perm;
6305 # Now remove all conditions which imply one of the input conditions.
6306 foreach my $perm (@perm)
6308 push @notconds, $perm
6309 if ! conditional_implies_any ($perm, @conds);
6314 # Return a list of permutations of a conditional string.
6315 # (But never output FALSE conditions, they are useless.)
6318 # variable_conditions_permutations ("FOO_FALSE", "BAR_TRUE")
6319 # => ("FOO_FALSE BAR_FALSE",
6320 # "FOO_FALSE BAR_TRUE",
6321 # "FOO_TRUE BAR_FALSE",
6322 # "FOO_TRUE BAR_TRUE")
6323 # variable_conditions_permutations ("FOO_FALSE", "TRUE")
6324 # => ("FOO_FALSE TRUE",
6326 # variable_conditions_permutations ("TRUE")
6328 # variable_conditions_permutations ("FALSE")
6330 sub variable_conditions_permutations
6335 my $comp = shift (@comps);
6336 return variable_conditions_permutations (@comps)
6338 my $neg = condition_negate ($comp);
6341 foreach my $sub (variable_conditions_permutations (@comps))
6343 push (@ret, "$comp $sub") if $comp ne 'FALSE';
6344 push (@ret, "$neg $sub") if $neg ne 'FALSE';
6348 push (@ret, $comp) if $comp ne 'FALSE';
6349 push (@ret, $neg) if $neg ne 'FALSE';
6356 # &check_variable_defined_unconditionally($VAR, $PARENT)
6357 # ------------------------------------------------------
6358 # Warn if a variable is conditionally defined. This is called if we
6359 # are using the value of a variable.
6360 sub check_variable_defined_unconditionally ($$)
6362 my ($var, $parent) = @_;
6363 foreach my $cond (keys %{$var_value{$var}})
6366 if $cond =~ /^TRUE|FALSE$/;
6370 macro_error ($parent,
6371 "warning: automake does not support conditional definition of $var in $parent");
6375 macro_error ($parent,
6376 "warning: automake does not support $var being defined conditionally");
6382 # Get the TRUE value of a variable, warn if the variable is
6383 # conditionally defined.
6387 &check_variable_defined_unconditionally ($var);
6388 return $var_value{$var}{'TRUE'};
6393 # &value_to_list ($VAR, $VAL, $COND)
6394 # ----------------------------------
6395 # Convert a variable value to a list, split as whitespace. This will
6396 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6399 # If COND is 'all', then all values under all conditions should be
6400 # returned; if COND is a particular condition (all conditions are
6401 # surrounded by @...@) then only the value for that condition should
6402 # be returned; otherwise, warn if VAR is conditionally defined.
6403 # SCANNED is a global hash listing whose keys are all the variables
6404 # already scanned; it is an error to rescan a variable.
6405 sub value_to_list ($$$)
6407 my ($var, $val, $cond) = @_;
6411 $val =~ s/\\(\n|$)/ /g;
6413 foreach (split (' ', $val))
6415 # If a comment seen, just leave.
6418 # Handle variable substitutions.
6419 if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
6423 # If the user uses a losing variable name, just ignore it.
6424 # This isn't ideal, but people have requested it.
6425 next if ($varname =~ /\@.*\@/);
6429 if ($varname =~ /$SUBST_REF_PATTERN/o)
6433 $from = quotemeta $2;
6438 variable_value_as_list_recursive_worker ($1, $cond, $var);
6440 # Now rewrite the value if appropriate.
6443 grep (s/$from$/$to/, @temp_list);
6446 push (@result, @temp_list);
6459 # variable_value_as_list ($VAR, $COND, $PARENT)
6460 # ---------------------------------------------
6461 # Get the value of a variable given a specified condition. without
6462 # recursing through any subvariables.
6464 # $VAR is the variable
6465 # $COND is the condition. If this is not given, the value for the
6466 # "TRUE" condition will be returned.
6467 # $PARENT is the variable in which the variable is used: this is used
6468 # only for error messages.
6469 # Returns the list of conditions.
6470 # For example, if A is defined as "foo $(B) bar", and B is defined as
6471 # "baz", this will return ("foo", "$(B)", "bar")
6472 sub variable_value_as_list
6474 my ($var, $cond, $parent) = @_;
6479 unless variable_assert $var, $parent;
6481 # Get value for given condition
6484 foreach my $vcond (keys %{$var_value{$var}})
6486 my $val = $var_value{$var}{$vcond};
6488 if (&conditional_true_when ($vcond, $cond))
6490 # Unless variable is not defined conditionally, there should only
6491 # be one value of $vcond true when $cond.
6492 &check_variable_defined_unconditionally ($var, $parent)
6497 $val =~ s/\\(\n|$)/ /g;
6499 foreach (split (' ', $val))
6501 # If a comment seen, just leave.
6514 # &variable_value_as_list_recursive_worker ($VAR, $COND, $PARENT)
6515 # ---------------------------------------------------------------
6516 # Return contents of VAR as a list, split on whitespace. This will
6517 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6518 # substitutions. If COND is 'all', then all values under all
6519 # conditions should be returned; if COND is a particular condition
6520 # (all conditions are surrounded by @...@) then only the value for
6521 # that condition should be returned; otherwise, warn if VAR is
6522 # conditionally defined. If PARENT is specified, it is the name of
6523 # the including variable; this is only used for error reports.
6524 sub variable_value_as_list_recursive_worker ($$$)
6526 my ($var, $cond, $parent) = @_;
6530 unless variable_assert $var, $parent;
6532 if (defined $vars_scanned{$var})
6534 # `vars_scanned' is a global we use to keep track of which
6535 # variables we've already examined.
6536 macro_error ($parent, "variable `$var' recursively defined");
6538 elsif ($cond eq 'all')
6540 $vars_scanned{$var} = 1;
6541 foreach my $vcond (keys %{$var_value{$var}})
6543 my $val = $var_value{$var}{$vcond};
6544 push (@result, &value_to_list ($var, $val, $cond));
6550 $vars_scanned{$var} = 1;
6552 foreach my $vcond (keys %{$var_value{$var}})
6554 my $val = $var_value{$var}{$vcond};
6555 if (&conditional_true_when ($vcond, $cond))
6557 # Warn if we have an ambiguity. It's hard to know how
6558 # to handle this case correctly.
6559 &check_variable_defined_unconditionally ($var, $parent)
6562 push (@result, &value_to_list ($var, $val, $cond));
6567 # Unset our entry in vars_scanned. We only care about recursive
6569 delete $vars_scanned{$var};
6575 # &variable_output ($VAR, [@CONDS])
6576 # ---------------------------------
6577 # Output all the values of $VAR is @COND is not specified, else only
6578 # that corresponding to @COND.
6579 sub variable_output ($@)
6581 my ($var, @conds) = @_;
6583 @conds = keys %{$var_value{$var}}
6586 $output_vars .= $var_comment{$var}
6587 if defined $var_comment{$var};
6589 foreach my $cond (sort by_condition @conds)
6591 my $val = $var_value{$var}{$cond};
6592 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6593 my $output_var = "$var $equals $val";
6594 $output_var =~ s/^/make_condition ($cond)/meg;
6595 $output_vars .= $output_var . "\n";
6600 # &variable_pretty_output ($VAR, [@CONDS])
6601 # ----------------------------------------
6602 # Likewise, but pretty, i.e., we *split* the values at spaces. Use only
6603 # with variables holding filenames.
6604 sub variable_pretty_output ($@)
6606 my ($var, @conds) = @_;
6608 @conds = keys %{$var_value{$var}}
6611 $output_vars .= $var_comment{$var}
6612 if defined $var_comment{$var};
6614 foreach my $cond (sort by_condition @conds)
6616 my $val = $var_value{$var}{$cond};
6617 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6618 my $make_condition = make_condition ($cond);
6619 $output_vars .= pretty_print_internal ("$make_condition$var $equals",
6620 "$make_condition\t",
6621 split (' ' , $val));
6626 # &variable_value_as_list_recursive ($VAR, $COND, $PARENT)
6627 # --------------------------------------------------------
6628 # This is just a wrapper for variable_value_as_list_recursive_worker that
6629 # initializes the global hash `vars_scanned'. This hash is used to
6630 # avoid infinite recursion.
6631 sub variable_value_as_list_recursive ($$@)
6633 my ($var, $cond, $parent) = @_;
6635 return &variable_value_as_list_recursive_worker ($var, $cond, $parent);
6639 # &define_pretty_variable ($VAR, $COND, @VALUE)
6640 # ---------------------------------------------
6641 # Like define_variable, but the value is a list, and the variable may
6642 # be defined conditionally. The second argument is the conditional
6643 # under which the value should be defined; this should be the empty
6644 # string to define the variable unconditionally. The third argument
6645 # is a list holding the values to use for the variable. The value is
6646 # pretty printed in the output file.
6647 sub define_pretty_variable ($$@)
6649 my ($var, $cond, @value) = @_;
6651 # Beware that an empty $cond has a different semantics for
6652 # macro_define and variable_pretty_output.
6655 if (! variable_defined ($var, $cond))
6657 macro_define ($var, 1, '', $cond, "@value", undef);
6658 variable_pretty_output ($var, $cond || 'TRUE');
6659 $content_seen{$var} = 1;
6664 # define_variable ($VAR, $VALUE)
6665 # ------------------------------
6666 # Define a new user variable VAR to VALUE, but only if not already defined.
6667 sub define_variable ($$)
6669 my ($var, $value) = @_;
6670 define_pretty_variable ($var, 'TRUE', $value);
6674 # Like define_variable, but define a variable to be the configure
6675 # substitution by the same name.
6676 sub define_configure_variable ($)
6679 if (! variable_defined ($var, 'TRUE'))
6681 # A macro defined via configure is a `user' macro -- we should not
6683 macro_define ($var, 0, '', 'TRUE', subst $var, $configure_vars{$var});
6684 variable_pretty_output ($var, 'TRUE');
6689 # define_compiler_variable ($LANG)
6690 # --------------------------------
6691 # Define a compiler variable. We also handle defining the `LT'
6692 # version of the command when using libtool.
6693 sub define_compiler_variable ($)
6697 my ($var, $value) = ($lang->compiler, $lang->compile);
6698 &define_variable ($var, $value);
6699 &define_variable ("LT$var", "\$(LIBTOOL) --mode=compile $value")
6704 # define_linker_variable ($LANG)
6705 # ------------------------------
6706 # Define linker variables.
6707 sub define_linker_variable ($)
6711 my ($var, $value) = ($lang->lder, $lang->ld);
6713 &define_variable ($lang->lder, $lang->ld);
6714 # CCLINK = $(CCLD) blah blah...
6715 &define_variable ($lang->linker,
6716 (($seen_libtool ? '$(LIBTOOL) --mode=link ' : '')
6720 ################################################################
6722 ## ---------------- ##
6723 ## Handling rules. ##
6724 ## ---------------- ##
6727 # rule_define ($TARGET, $IS_AM, $COND, $WHERE)
6728 # --------------------------------------------
6729 # Define a new rule. $TARGET is the rule name. $IS_AM is a boolean
6730 # which is true if the new rule is defined by the user. $COND is the
6731 # condition under which the rule is defined. $WHERE is where the rule
6732 # is defined (file name or line number). Returns true if it is ok to
6733 # define the rule, false otherwise.
6734 sub rule_define ($$$$)
6736 my ($target, $rule_is_am, $cond, $where) = @_;
6738 # For now `foo:' will override `foo$(EXEEXT):'. This is temporary,
6739 # though, so we emit a warning.
6740 (my $noexe = $target) =~ s,\$\(EXEEXT\)$,,;
6741 if ($noexe ne $target && defined $targets{$noexe})
6743 # The no-exeext option enables this feature.
6744 if (! defined $options{'no-exeext'})
6746 macro_error ($noexe,
6747 "deprecated feature: `$noexe' overrides `$noexe\$(EXEEXT)'\nchange your target to read `$noexe\$(EXEEXT)'");
6753 if (defined $targets{$target}
6755 ? ! defined $target_conditional{$target}
6756 : defined $target_conditional{$target}))
6758 target_error ($target,
6759 "$target defined both conditionally and unconditionally");
6762 # Value here doesn't matter; for targets we only note existence.
6763 $targets{$target} = $where;
6766 if ($target_conditional{$target})
6768 &check_ambiguous_conditional ($target, $cond);
6770 $target_conditional{$target}{$cond} = $where;
6773 # Check the rule for being a suffix rule. If so, store in a hash.
6774 # Either it's a rule for two known extensions...
6775 if ($target =~ /^($KNOWN_EXTENSIONS_PATTERN)($KNOWN_EXTENSIONS_PATTERN)$/
6776 # ...or it's a rule with unknown extensions (.i.e, the rule looks like
6777 # `.foo.bar:' but `.foo' or `.bar' are not declared in SUFFIXES
6778 # and are not known language extensions).
6779 # Automake will complete SUFFIXES from @suffixes automatically
6780 # (see handle_footer).
6781 || ($target =~ /$SUFFIX_RULE_PATTERN/o && accept_extensions($1)))
6783 my $internal_ext = $2;
6785 # When tranforming sources to objects, Automake uses the
6786 # %suffix_rules to move from each source extension to
6787 # `.$(OBJEXT)', not to `.o' or `.obj'. However some people
6788 # define suffix rules for `.o' or `.obj', so internally we will
6789 # consider these extensions equivalent to `.$(OBJEXT)'. We
6790 # CANNOT rewrite the target (i.e., automagically replace `.o'
6791 # and `.obj' by `.$(OBJEXT)' in the output), or warn the user
6792 # that (s)he'd better use `.$(OBJEXT)', because Automake itself
6793 # output suffix rules for `.o' or `.obj'...
6794 $internal_ext = '.$(OBJEXT)' if ($2 eq '.o' || $2 eq '.obj');
6796 $suffix_rules{$1} = $internal_ext;
6797 verbose "Sources ending in $1 become $2";
6798 push @suffixes, $1, $2;
6805 # See if a target exists.
6809 return defined $targets{$target};
6813 ################################################################
6815 # &append_comments ($VARIABLE, $SPACING, $COMMENT)
6816 # ------------------------------------------------
6817 # Apped $COMMENT to the other comments for $VARIABLE, using
6818 # $SPACING as separator.
6819 sub append_comments ($$$)
6821 my ($var, $spacing, $comment) = @_;
6822 $var_comment{$var} .= $spacing
6823 if (!defined $var_comment{$var} || $var_comment{$var} !~ /\n$/o);
6824 $var_comment{$var} .= $comment;
6828 # &read_am_file ($AMFILE)
6829 # -----------------------
6830 # Read Makefile.am and set up %contents. Simultaneously copy lines
6831 # from Makefile.am into $output_trailer or $output_vars as
6832 # appropriate. NOTE we put rules in the trailer section. We want
6833 # user rules to come after our generated stuff.
6834 sub read_am_file ($)
6838 my $am_file = new Automake::XFile ("< $amfile");
6839 verbose "reading $amfile";
6846 use constant IN_VAR_DEF => 0;
6847 use constant IN_RULE_DEF => 1;
6848 use constant IN_COMMENT => 2;
6849 my $prev_state = IN_RULE_DEF;
6851 while ($_ = $am_file->getline)
6853 if (/$IGNORE_PATTERN/o)
6855 # Merely delete comments beginning with two hashes.
6857 elsif (/$WHITE_PATTERN/o)
6859 file_error ("$amfile:$.",
6860 "blank line following trailing backslash")
6862 # Stick a single white line before the incoming macro or rule.
6865 # Flush all comments seen so far.
6868 $output_vars .= $comment;
6872 elsif (/$COMMENT_PATTERN/o)
6874 # Stick comments before the incoming macro or rule. Make
6875 # sure a blank line preceeds first block of comments.
6876 $spacing = "\n" unless $blank;
6878 $comment .= $spacing . $_;
6880 $prev_state = IN_COMMENT;
6886 $saw_bk = /\\$/ && ! /$IGNORE_PATTERN/o;
6889 # We save the conditional stack on entry, and then check to make
6890 # sure it is the same on exit. This lets us conditonally include
6892 my @saved_cond_stack = @cond_stack;
6893 my $cond = conditional_string (@cond_stack);
6895 my $last_var_name = '';
6896 my $last_var_type = '';
6897 my $last_var_value = '';
6898 # FIXME: shouldn't use $_ in this loop; it is too big.
6901 my $here = "$amfile:$.";
6903 # Make sure the line is \n-terminated.
6907 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
6908 # used by users. @MAINT@ is an anachronism now.
6909 $_ =~ s/\@MAINT\@//g
6910 unless $seen_maint_mode;
6912 my $new_saw_bk = /\\$/ && ! /$IGNORE_PATTERN/o;
6914 if (/$IGNORE_PATTERN/o)
6916 # Merely delete comments beginning with two hashes.
6918 elsif (/$WHITE_PATTERN/o)
6920 # Stick a single white line before the incoming macro or rule.
6922 file_error ($here, "blank line following trailing backslash")
6925 elsif (/$COMMENT_PATTERN/o)
6927 # Stick comments before the incoming macro or rule.
6928 $comment .= $spacing . $_;
6930 file_error ($here, "comment following trailing backslash")
6931 if $saw_bk && $comment eq '';
6932 $prev_state = IN_COMMENT;
6936 if ($prev_state == IN_RULE_DEF)
6938 $output_trailer .= &make_condition (@cond_stack);
6939 $output_trailer .= $_;
6941 elsif ($prev_state == IN_COMMENT)
6943 $comment .= $spacing . $_;
6945 else # $prev_state == IN_VAR_DEF
6947 $last_var_value .= ' '
6948 unless $last_var_value =~ /\s$/;
6949 $last_var_value .= $_;
6953 append_comments $last_var_name, $spacing, $comment;
6954 $comment = $spacing = '';
6955 macro_define ($last_var_name, 0,
6956 $last_var_type, $cond,
6957 $last_var_value, $here)
6958 if $cond ne 'FALSE';
6959 push (@var_list, $last_var_name);
6964 elsif (/$IF_PATTERN/o)
6966 $cond = cond_stack_if ($1, $2, $here);
6968 elsif (/$ELSE_PATTERN/o)
6970 $cond = cond_stack_else ($1, $2, $here);
6972 elsif (/$ENDIF_PATTERN/o)
6974 $cond = cond_stack_endif ($1, $2, $here);
6977 elsif (/$RULE_PATTERN/o)
6980 $prev_state = IN_RULE_DEF;
6982 rule_define ($1, 0, $cond, $here);
6984 $output_trailer .= $comment . $spacing;
6985 $output_trailer .= &make_condition (@cond_stack);
6986 $output_trailer .= $_;
6987 $comment = $spacing = '';
6989 elsif (/$ASSIGNMENT_PATTERN/o)
6991 # Found a macro definition.
6992 $prev_state = IN_VAR_DEF;
6993 $last_var_name = $1;
6994 $last_var_type = $2;
6995 $last_var_value = $3;
6996 if ($3 ne '' && substr ($3, -1) eq "\\")
6998 # We preserve the `\' because otherwise the long lines
6999 # that are generated will be truncated by broken
7001 $last_var_value = $3 . "\n";
7006 # FIXME: this doesn't always work correctly; it will
7007 # group all comments for a given variable, no matter
7009 # Accumulating variables must not be output.
7010 append_comments $last_var_name, $spacing, $comment;
7011 $comment = $spacing = '';
7013 macro_define ($last_var_name, 0,
7014 $last_var_type, $cond,
7015 $last_var_value, $here)
7016 if $cond ne 'FALSE';
7017 push (@var_list, $last_var_name);
7020 elsif (/$INCLUDE_PATTERN/o)
7024 if ($path =~ s/^\$\(top_srcdir\)\///)
7026 push (@include_stack, "\$\(top_srcdir\)/$path");
7030 $path =~ s/\$\(srcdir\)\///;
7031 push (@include_stack, "\$\(srcdir\)/$path");
7032 $path = $relative_dir . "/" . $path;
7034 &read_am_file ($path);
7038 # This isn't an error; it is probably a continued rule.
7039 # In fact, this is what we assume.
7040 $prev_state = IN_RULE_DEF;
7041 $output_trailer .= $comment . $spacing;
7042 $output_trailer .= &make_condition (@cond_stack);
7043 $output_trailer .= $_;
7044 $comment = $spacing = '';
7045 file_error ($here, "`#' comment at start of rule is unportable")
7046 if $_ =~ /^\t\s*\#/;
7049 $saw_bk = $new_saw_bk;
7050 $_ = $am_file->getline;
7053 $output_trailer .= $comment;
7055 if ("@saved_cond_stack" ne "@cond_stack")
7059 &am_error ("unterminated conditionals: @cond_stack");
7063 # FIXME: better error message here.
7064 &am_error ("conditionals not nested in include file");
7070 # define_standard_variables ()
7071 # ----------------------------
7072 # A helper for read_main_am_file which initializes configure variables
7073 # and variables from header-vars.am.
7074 sub define_standard_variables
7076 my $saved_output_vars = $output_vars;
7077 my ($comments, undef, $rules) =
7078 file_contents_internal (1, "$libdir/am/header-vars.am");
7080 # This will output the definitions in $output_vars, which we don't
7082 foreach my $var (sort keys %configure_vars)
7084 &define_configure_variable ($var);
7085 push (@var_list, $var);
7088 # ... hence, we restore $output_vars.
7089 $output_vars = $saved_output_vars . $comments . $rules;
7092 # Read main am file.
7093 sub read_main_am_file
7097 # This supports the strange variable tricks we are about to play.
7098 if (scalar keys %var_value > 0)
7101 prog_error ("variable defined before read_main_am_file");
7104 # Generate copyright header for generated Makefile.in.
7105 # We do discard the output of predefined variables, handled below.
7106 $output_vars = ("# $in_file_name generated by automake "
7107 . $VERSION . " from $am_file_name.\n");
7108 $output_vars .= '# ' . subst ('configure_input') . "\n";
7109 $output_vars .= $gen_copyright;
7111 # We want to predefine as many variables as possible. This lets
7112 # the user set them with `+=' in Makefile.am. However, we don't
7113 # want these initial definitions to end up in the output quite
7114 # yet. So we just load them, but output them later.
7115 &define_standard_variables;
7117 # Read user file, which might override some of our values.
7118 &read_am_file ($amfile);
7120 # Output all the Automake variables. If the user changed one,
7121 # then it is now marked as owned by the user.
7122 foreach my $var (uniq @var_list)
7124 # Don't process user variables.
7125 variable_output ($var)
7126 unless !$var_is_am{$var};
7129 # Now dump the user variables that were defined. We do it in the same
7130 # order in which they were defined (skipping duplicates).
7131 foreach my $var (uniq @var_list)
7133 # Don't process Automake variables.
7134 variable_output ($var)
7135 unless $var_is_am{$var};
7139 ################################################################
7142 # &flatten ($STRING)
7143 # ------------------
7144 # Flatten the $STRING and return the result.
7159 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
7160 # ------------------------------------------
7161 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
7163 sub make_paragraphs ($%)
7165 my ($file, %transform) = @_;
7167 # Complete %transform with global options and make it a Perl
7170 "s/$IGNORE_PATTERN//gm;"
7171 . transform (%transform,
7173 'CYGNUS' => $cygnus_mode,
7175 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
7177 'SHAR' => $options{'dist-shar'} || 0,
7178 'BZIP2' => $options{'dist-bzip2'} || 0,
7179 'ZIP' => $options{'dist-zip'} || 0,
7180 'COMPRESS' => $options{'dist-tarZ'} || 0,
7182 'INSTALL-INFO' => !$options{'no-installinfo'},
7183 'INSTALL-MAN' => !$options{'no-installman'},
7184 'CK-NEWS' => $options{'check-news'} || 0,
7186 'SUBDIRS' => variable_defined ('SUBDIRS'),
7187 'TOPDIR' => backname ($relative_dir),
7188 'TOPDIR_P' => $relative_dir eq '.',
7189 'CONFIGURE-AC' => $configure_ac,
7191 'BUILD' => $seen_canonical == AC_CANONICAL_SYSTEM,
7192 'HOST' => $seen_canonical,
7193 'TARGET' => $seen_canonical == AC_CANONICAL_SYSTEM,
7195 'LIBTOOL' => defined $configure_vars{'LIBTOOL'})
7196 # We don't need more than two consecutive new-lines.
7197 . 's/\n{3,}/\n\n/g';
7199 # Swallow the file and apply the COMMAND.
7200 my $fc_file = new Automake::XFile "< $file";
7202 verbose "reading $file";
7203 my $saved_dollar_slash = $/;
7205 $_ = $fc_file->getline;
7206 $/ = $saved_dollar_slash;
7211 # Split at unescaped new lines.
7212 my @lines = split (/(?<!\\)\n/, $content);
7215 while (defined ($_ = shift @lines))
7217 my $paragraph = "$_";
7218 # If we are a rule, eat as long as we start with a tab.
7219 if (/$RULE_PATTERN/smo)
7221 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
7223 $paragraph .= "\n$_";
7225 unshift (@lines, $_);
7228 # If we are a comments, eat as much comments as you can.
7229 elsif (/$COMMENT_PATTERN/smo)
7231 while (defined ($_ = shift @lines)
7232 && $_ =~ /$COMMENT_PATTERN/smo)
7234 $paragraph .= "\n$_";
7236 unshift (@lines, $_);
7239 push @res, $paragraph;
7248 # ($COMMENT, $VARIABLES, $RULES)
7249 # &file_contents_internal ($IS_AM, $FILE, [%TRANSFORM])
7250 # -----------------------------------------------------
7251 # Return contents of a file from $libdir/am, automatically skipping
7252 # macros or rules which are already known. $IS_AM iff the caller is
7253 # reading an Automake file (as opposed to the user's Makefile.am).
7254 sub file_contents_internal ($$%)
7256 my ($is_am, $file, %transform) = @_;
7258 my $result_vars = '';
7259 my $result_rules = '';
7263 # The following flags are used to track rules spanning across
7264 # multiple paragraphs.
7265 my $is_rule = 0; # 1 if we are processing a rule.
7266 my $discard_rule = 0; # 1 if the current rule should not be output.
7268 # We save the conditional stack on entry, and then check to make
7269 # sure it is the same on exit. This lets us conditonally include
7271 my @saved_cond_stack = @cond_stack;
7272 my $cond = conditional_string (@cond_stack);
7274 foreach (make_paragraphs ($file, %transform))
7277 file_error ($file, "blank line following trailing backslash:\n$_")
7279 file_error ($file, "comment following trailing backslash:\n$_")
7285 # Stick empty line before the incoming macro or rule.
7288 elsif (/$COMMENT_PATTERN/mso)
7291 # Stick comments before the incoming macro or rule.
7295 # Handle inclusion of other files.
7296 elsif (/$INCLUDE_PATTERN/o)
7298 if ($cond ne 'FALSE')
7300 my $file = ($is_am ? "$libdir/am/" : '') . $1;
7302 my ($com, $vars, $rules)
7303 = file_contents_internal ($is_am, $file, %transform);
7305 $result_vars .= $vars;
7306 $result_rules .= $rules;
7310 # Handling the conditionals.
7311 elsif (/$IF_PATTERN/o)
7313 $cond = cond_stack_if ($1, $2, $file);
7315 elsif (/$ELSE_PATTERN/o)
7317 $cond = cond_stack_else ($1, $2, $file);
7319 elsif (/$ENDIF_PATTERN/o)
7321 $cond = cond_stack_endif ($1, $2, $file);
7325 elsif (/$RULE_PATTERN/mso)
7329 # Separate relationship from optional actions: the first
7330 # `new-line tab" not preceded by backslash (continuation
7332 # I'm quite shoked! It seems that (\\\n|[^\n]) is not the
7333 # same as `([^\n]|\\\n)!!! Don't swap it, it breaks.
7335 /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
7336 my ($relationship, $actions) = ($1, $2 || '');
7338 # Separate targets from dependencies: the first colon.
7339 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
7340 my ($targets, $dependencies) = ($1, $2);
7341 # Remove the escaped new lines.
7342 # I don't know why, but I have to use a tmp $flat_deps.
7343 my $flat_deps = &flatten ($dependencies);
7344 my @deps = split (' ', $flat_deps);
7346 foreach (split (' ' , $targets))
7348 # FIXME: We are not robust to people defining several targets
7349 # at once, only some of them being in %dependencies. The
7350 # actions from the targets in %dependencies are usually generated
7351 # from the content of %actions, but if some targets in $targets
7352 # are not in %dependencies the ELSE branch will output
7353 # a rule for all $targets (i.e. the targets which are both
7354 # in %dependencies and $targets will have two rules).
7356 # FIXME: The logic here is not able to output a
7357 # multi-paragraph rule several time (e.g. for each conditional
7358 # it is defined for) because it only knows the first paragraph.
7360 # Output only if not in FALSE.
7361 if (defined $dependencies{$_}
7362 && $cond ne 'FALSE')
7364 &depend ($_, @deps);
7365 $actions{$_} .= $actions;
7369 # Free-lance dependency. Output the rule for all the
7370 # targets instead of one by one.
7372 # Work out all the conditions for which the target hasn't
7374 my @undefined_conds;
7375 if (defined $target_conditional{$targets})
7377 my @defined_conds = keys %{$target_conditional{$targets}};
7378 @undefined_conds = invert_conditions(@defined_conds);
7382 if (defined $targets{$targets})
7384 # No conditions for which target hasn't been defined
7385 @undefined_conds = ();
7389 # Target hasn't been defined for any conditions
7390 @undefined_conds = ("");
7394 if ($cond ne 'FALSE')
7396 for my $undefined_cond (@undefined_conds)
7398 my $condparagraph = $paragraph;
7399 $condparagraph =~ s/^/make_condition (@cond_stack, $undefined_cond)/gme;
7400 if (rule_define ($targets, $is_am,
7401 "$cond $undefined_cond", $file))
7404 "$spacing$comment$condparagraph\n"
7408 # Remember to discard next paragraphs
7409 # if they belong to this rule.
7413 if ($#undefined_conds == -1)
7415 # This target has already been defined, the rule
7416 # has not been defined. Remember to discard next
7417 # paragraphs if they belong to this rule.
7421 $comment = $spacing = '';
7427 elsif (/$ASSIGNMENT_PATTERN/mso)
7429 my ($var, $type, $val) = ($1, $2, $3);
7430 file_error ($file, "macro `$var' with trailing backslash")
7435 # Accumulating variables must not be output.
7436 append_comments $var, $spacing, $comment;
7437 macro_define ($var, $is_am, $type, $cond, $val, $file)
7438 if $cond ne 'FALSE';
7439 push (@var_list, $var);
7441 # If the user has set some variables we were in charge
7442 # of (which is detected by the first reading of
7443 # `header-vars.am'), we must not output them.
7444 $result_vars .= "$spacing$comment$_\n"
7445 if $type ne '+' && $var_is_am{$var} && $cond ne 'FALSE';
7447 $comment = $spacing = '';
7451 # This isn't an error; it is probably some tokens which
7452 # configure is supposed to replace, such as `@SET-MAKE@',
7453 # or some part of a rule cut by an if/endif.
7454 if ($cond ne 'FALSE' && ! ($is_rule && $discard_rule))
7456 s/^/make_condition (@cond_stack)/gme;
7457 $result_rules .= "$spacing$comment$_\n";
7459 $comment = $spacing = '';
7463 if ("@saved_cond_stack" ne "@cond_stack")
7467 &am_error ("unterminated conditionals: @cond_stack");
7471 # FIXME: better error message here.
7472 &am_error ("conditionals not nested in include file");
7476 return ($comment, $result_vars, $result_rules);
7481 # &file_contents ($BASENAME, [%TRANSFORM])
7482 # ----------------------------------------
7483 # Return contents of a file from $libdir/am, automatically skipping
7484 # macros or rules which are already known.
7485 sub file_contents ($%)
7487 my ($basename, %transform) = @_;
7488 my ($comments, $variables, $rules) =
7489 file_contents_internal (1, "$libdir/am/$basename.am", %transform);
7490 return "$comments$variables$rules";
7495 # &transform (%PAIRS)
7496 # -------------------
7497 # Foreach ($TOKEN, $VAL) in %PAIRS produce a replacement expression suitable
7498 # for file_contents which:
7499 # - replaces %$TOKEN% with $VAL,
7500 # - enables/disables ?$TOKEN? and ?!$TOKEN?,
7501 # - replaces %?$TOKEN% with TRUE or FALSE.
7507 while (my ($token, $val) = each %pairs)
7509 $result .= "s/\Q%$token%\E/\Q$val\E/gm;";
7512 $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
7513 $result .= "s/\Q%?$token%\E/TRUE/gm;";
7517 $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
7518 $result .= "s/\Q%?$token%\E/FALSE/gm;";
7526 # &append_exeext ($MACRO)
7527 # -----------------------
7528 # Macro is an Automake magic macro which primary is PROGRAMS, e.g.
7529 # bin_PROGRAMS. Make sure these programs have $(EXEEXT) appended.
7530 sub append_exeext ($)
7534 prog_error "append_exeext ($macro)"
7535 unless $macro =~ /_PROGRAMS$/;
7537 my @conds = variable_conditions_recursive ($macro);
7540 foreach my $cond (@conds)
7542 my @one_binlist = ();
7543 my @condval = variable_value_as_list_recursive ($macro, $cond);
7544 foreach my $rcurs (@condval)
7546 # Skip autoconf substs. Also skip if the user
7547 # already applied $(EXEEXT).
7548 if ($rcurs =~ /^\@.*\@$/ || $rcurs =~ /\$\(EXEEXT\)$/)
7550 push (@one_binlist, $rcurs);
7554 push (@one_binlist, $rcurs . '$(EXEEXT)');
7558 push (@condvals, $cond);
7559 push (@condvals, "@one_binlist");
7562 macro_delete ($macro);
7565 my $cond = shift (@condvals);
7566 my @val = split (' ', shift (@condvals));
7567 define_pretty_variable ($macro, $cond, @val);
7573 # &am_primary_prefixes ($PRIMARY, $CAN_DIST, @PREFIXES)
7574 # -----------------------------------------------------
7575 # Find all variable prefixes that are used for install directories. A
7576 # prefix `zar' qualifies iff:
7578 # * `zardir' is a variable.
7579 # * `zar_PRIMARY' is a variable.
7581 # As a side effect, it looks for misspellings. It is an error to have
7582 # a variable ending in a "reserved" suffix whose prefix is unknown, eg
7583 # "bni_PROGRAMS". However, unusual prefixes are allowed if a variable
7584 # of the same name (with "dir" appended) exists. For instance, if the
7585 # variable "zardir" is defined, then "zar_PROGRAMS" becomes valid.
7586 # This is to provide a little extra flexibility in those cases which
7588 sub am_primary_prefixes ($$@)
7590 my ($primary, $can_dist, @prefixes) = @_;
7593 my %valid = map { $_ => 0 } @prefixes;
7594 $valid{'EXTRA'} = 0;
7595 foreach my $varname (keys %var_value)
7597 # Automake is allowed to define variables that look like they
7598 # are magic variables, such as INSTALL_DATA.
7600 if $var_is_am{$varname};
7602 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
7604 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
7605 if ($dist ne '' && ! $can_dist)
7607 # Note that a configure variable is always legitimate.
7608 # It is natural to name such variables after the
7609 # primary, so we explicitly allow it.
7610 macro_error ($varname,
7611 "invalid variable `$varname': `dist' is forbidden")
7612 if ! exists $configure_vars{$varname};
7614 # A not-explicitely-allowed prefix X is allowed if Xdir
7615 # has been defined and X is not a standard prefix.
7616 elsif (! defined $valid{$X} && (! variable_defined ("${X}dir")
7617 || exists $standard_prefix{$X}))
7619 # Note that a configure variable is always legitimate.
7620 # It is natural to name such variables after the
7621 # primary, so we explicitly allow it.
7622 macro_error ($varname, "invalid variable `$varname'")
7623 if ! exists $configure_vars{$varname};
7627 # Ensure all extended prefixes are actually used.
7628 $valid{"$base$dist$X"} = 1;
7633 # Return only those which are actually defined.
7634 return sort grep { variable_defined ($_ . '_' . $primary) } keys %valid;
7638 # Handle `where_HOW' variable magic. Does all lookups, generates
7639 # install code, and possibly generates code to define the primary
7640 # variable. The first argument is the name of the .am file to munge,
7641 # the second argument is the primary variable (eg HEADERS), and all
7642 # subsequent arguments are possible installation locations. Returns
7643 # list of all values of all _HOW targets.
7645 # FIXME: this should be rewritten to be cleaner. It should be broken
7646 # up into multiple functions.
7648 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7655 my $default_dist = 0;
7658 if ($args[0] eq '-noextra')
7662 elsif ($args[0] eq '-candist')
7666 elsif ($args[0] eq '-defaultdist')
7671 elsif ($args[0] !~ /^-/)
7678 my ($file, $primary, @prefix) = @args;
7680 # Now that configure substitutions are allowed in where_HOW
7681 # variables, it is an error to actually define the primary. We
7682 # allow `JAVA', as it is customarily used to mean the Java
7683 # interpreter. This is but one of several Java hacks. Similarly,
7684 # `PYTHON' is customarily used to mean the Python interpreter.
7685 macro_error ($primary, "`$primary' is an anachronism")
7686 if variable_defined ($primary)
7687 && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7690 # Get the prefixes which are valid and actually used.
7691 @prefix = am_primary_prefixes ($primary, $can_dist, @prefix);
7693 # If a primary includes a configure substitution, then the EXTRA_
7694 # form is required. Otherwise we can't properly do our job.
7696 my $warned_about_extra = 0;
7701 # True if the iteration is the first one. Used for instance to
7702 # output parts of the associated file only once.
7704 foreach my $X (@prefix)
7706 my $nodir_name = $X;
7707 my $one_name = $X . '_' . $primary;
7709 my $strip_subdir = 1;
7710 # If subdir prefix should be preserved, do so.
7711 if ($nodir_name =~ /^nobase_/)
7714 $nodir_name =~ s/^nobase_//;
7717 # If files should be distributed, do so.
7721 $dist_p = (($default_dist && $nodir_name !~ /^nodist_/)
7722 || (! $default_dist && $nodir_name =~ /^dist_/));
7723 $nodir_name =~ s/^(dist|nodist)_//;
7726 # Append actual contents of where_PRIMARY variable to
7728 foreach my $rcurs (&variable_value_as_list_recursive ($one_name, 'all'))
7730 # Skip configure substitutions. Possibly bogus.
7731 if ($rcurs =~ /^\@.*\@$/)
7733 if ($nodir_name eq 'EXTRA')
7735 if (! $warned_about_extra)
7737 $warned_about_extra = 1;
7738 macro_error ($one_name,
7739 "`$one_name' contains configure substitution, but shouldn't");
7742 # Check here to make sure variables defined in
7743 # configure.ac do not imply that EXTRA_PRIMARY
7745 elsif (! defined $configure_vars{$one_name})
7747 $require_extra = $one_name
7754 push (@result, $rcurs);
7757 # A blatant hack: we rewrite each _PROGRAMS primary to include
7759 append_exeext ($one_name)
7760 if $primary eq 'PROGRAMS';
7762 # "EXTRA" shouldn't be used when generating clean targets,
7763 # all, or install targets. We used to warn if EXTRA_FOO was
7764 # defined uselessly, but this was annoying.
7766 if $nodir_name eq 'EXTRA';
7768 if ($nodir_name eq 'check')
7770 push (@check, '$(' . $one_name . ')');
7774 push (@used, '$(' . $one_name . ')');
7777 # Is this to be installed?
7778 my $install_p = $nodir_name ne 'noinst' && $nodir_name ne 'check';
7780 # If so, with install-exec? (or install-data?).
7781 my $exec_p = ($nodir_name =~ /$EXEC_DIR_PATTERN/o);
7783 # Singular form of $PRIMARY.
7784 (my $one_primary = $primary) =~ s/S$//;
7785 $output_rules .= &file_contents ($file,
7788 'PRIMARY' => $primary,
7789 'ONE_PRIMARY' => $one_primary,
7791 'NDIR' => $nodir_name,
7792 'BASE' => $strip_subdir,
7795 'INSTALL' => $install_p,
7796 'DIST' => $dist_p));
7801 # The JAVA variable is used as the name of the Java interpreter.
7802 # The PYTHON variable is used as the name of the Python interpreter.
7803 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7806 define_pretty_variable ($primary, '', @used);
7807 $output_vars .= "\n";
7810 if ($require_extra && ! variable_defined ('EXTRA_' . $primary))
7812 macro_error ($require_extra,
7813 "`$require_extra' contains configure substitution, but `EXTRA_$primary' not defined");
7816 # Push here because PRIMARY might be configure time determined.
7817 push (@all, '$(' . $primary . ')')
7818 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7820 # Make the result unique. This lets the user use conditionals in
7821 # a natural way, but still lets us program lazily -- we don't have
7822 # to worry about handling a particular object more than once.
7823 return uniq (sort @result);
7827 ################################################################
7829 # Each key in this hash is the name of a directory holding a
7830 # Makefile.in. These variables are local to `is_make_dir'.
7832 my $make_dirs_set = 0;
7837 if (! $make_dirs_set)
7839 foreach my $iter (@configure_input_files)
7841 $make_dirs{dirname ($iter)} = 1;
7843 # We also want to notice Makefile.in's.
7844 foreach my $iter (@other_input_files)
7846 if ($iter =~ /Makefile\.in$/)
7848 $make_dirs{dirname ($iter)} = 1;
7853 return defined $make_dirs{$dir};
7856 ################################################################
7858 # This variable is local to the "require file" set of functions.
7859 my @require_file_paths = ();
7862 # &maybe_push_required_file ($DIR, $FILE, $FULLFILE)
7863 # --------------------------------------------------
7864 # See if we want to push this file onto dist_common. This function
7865 # encodes the rules for deciding when to do so.
7866 sub maybe_push_required_file
7868 my ($dir, $file, $fullfile) = @_;
7870 if ($dir eq $relative_dir)
7872 push_dist_common ($file);
7875 elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7877 # If we are doing the topmost directory, and the file is in a
7878 # subdir which does not have a Makefile, then we distribute it
7880 push_dist_common ($fullfile);
7887 # &require_file_internal ($WHERE, $MYSTRICT, @FILES)
7888 # --------------------------------------------------
7889 # Verify that the file must exist in the current directory.
7890 # $MYSTRICT is the strictness level at which this file becomes required.
7892 # Must set require_file_paths before calling this function.
7893 # require_file_paths is set to hold a single directory (the one in
7894 # which the first file was found) before return.
7895 sub require_file_internal ($$@)
7897 my ($where, $mystrict, @files) = @_;
7899 foreach my $file (@files)
7907 my $dangling_sym = 0;
7908 foreach my $dir (@require_file_paths)
7910 $fullfile = $dir . "/" . $file;
7911 $errdir = $dir unless $errdir;
7913 # Use different name for "error filename". Otherwise on
7914 # an error the bad file will be reported as eg
7915 # `../../install-sh' when using the default
7917 $errfile = $errdir . '/' . $file;
7919 if (-l $fullfile && ! -f $fullfile)
7924 elsif (-f $fullfile)
7927 maybe_push_required_file ($dir, $file, $fullfile);
7933 # `--force-missing' only has an effect if `--add-missing' is
7935 if ($found_it && (! $add_missing || ! $force_missing))
7937 # Prune the path list.
7938 @require_file_paths = $save_dir;
7942 # If we've already looked for it, we're done. You might
7943 # wonder why we don't do this before searching for the
7944 # file. If we do that, then something like
7945 # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
7949 next if defined $require_file_found{$file};
7950 $require_file_found{$file} = 1;
7953 if ($strictness >= $mystrict)
7955 if ($dangling_sym && $add_missing)
7963 # Only install missing files according to our desired
7965 my $message = "required file `$errfile' not found";
7970 if (-f ("$libdir/$file"))
7972 # Install the missing file. Symlink if we
7973 # can, copy if we must. Note: delete the file
7974 # first, in case it is a dangling symlink.
7975 $message = "installing `$errfile'";
7976 # Windows Perl will hang if we try to delete a
7977 # file that doesn't exist.
7978 unlink ($errfile) if -f $errfile;
7979 if ($symlink_exists && ! $copy_missing)
7981 if (! symlink ("$libdir/$file", $errfile))
7984 $trailer = "; error while making link: $!";
7987 elsif (system ('cp', "$libdir/$file", $errfile))
7990 $trailer = "\n error while copying";
7994 if (! maybe_push_required_file (dirname ($errfile),
7999 # We have added the file but could not push it
8000 # into DIST_COMMON (probably because this is
8001 # an auxiliary file and we are not processing
8002 # the top level Makefile). This is unfortunate,
8003 # since it means we are using a file which is not
8006 # Get Automake to be run again: on the second
8007 # run the file will be found, and pushed into
8008 # the toplevel DIST_COMMON automatically.
8009 $automake_needs_to_reprocess_all_files = 1;
8013 # Prune the path list.
8014 @require_file_paths = &dirname ($errfile);
8017 # If --force-missing was specified, and we have
8018 # actually found the file, then do nothing.
8020 if $found_it && $force_missing;
8024 file_warning ($where, "$message$trailer");
8028 file_error ($where, "$message$trailer");
8035 # &require_file ($WHERE, $MYSTRICT, @FILES)
8036 # -----------------------------------------
8037 sub require_file ($$@)
8039 my ($where, $mystrict, @files) = @_;
8040 @require_file_paths = $relative_dir;
8041 require_file_internal ($where, $mystrict, @files);
8044 # &require_file_with_macro ($MACRO, $MYSTRICT, @FILES)
8045 # ----------------------------------------------------
8046 sub require_file_with_macro ($$@)
8048 my ($macro, $mystrict, @files) = @_;
8049 require_file ($var_location{$macro}, $mystrict, @files);
8053 # &require_conf_file ($WHERE, $MYSTRICT, @FILES)
8054 # ----------------------------------------------
8055 # Looks in configuration path, as specified by AC_CONFIG_AUX_DIR.
8056 sub require_conf_file ($$@)
8058 my ($where, $mystrict, @files) = @_;
8059 @require_file_paths = @config_aux_path;
8060 require_file_internal ($where, $mystrict, @files);
8061 my $dir = $require_file_paths[0];
8062 @config_aux_path = @require_file_paths;
8063 # Avoid unsightly '/.'s.
8064 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
8068 # &require_conf_file_with_macro ($MACRO, $MYSTRICT, @FILES)
8069 # ---------------------------------------------------------
8070 sub require_conf_file_with_macro ($$@)
8072 my ($macro, $mystrict, @files) = @_;
8073 require_conf_file ($var_location{$macro}, $mystrict, @files);
8076 ################################################################
8078 # &require_build_directory ($DIRECTORY)
8079 # ------------------------------------
8080 # Emit rules to create $DIRECTORY if needed, and return
8081 # the file that any target requiring this directory should be made
8083 sub require_build_directory ($)
8085 my $directory = shift;
8086 my $dirstamp = "$directory/.dirstamp";
8088 # Don't emit the rule twice.
8089 if (! defined $directory_map{$directory})
8091 $directory_map{$directory} = 1;
8093 # Directory must be removed by `make distclean'.
8094 $compile_clean_files{$dirstamp} = DIST_CLEAN;
8096 $output_rules .= ("$dirstamp:\n"
8097 . "\t\@\$(mkinstalldirs) $directory\n"
8098 . "\t\@: > $dirstamp\n");
8104 # &require_build_directory_maybe ($FILE)
8105 # --------------------------------------
8106 # If $FILE lies in a subdirectory, emit a rule to create this
8107 # directory and return the file that $FILE should be made
8108 # dependent upon. Otherwise, just return the empty string.
8109 sub require_build_directory_maybe ($)
8112 my $directory = dirname ($file);
8114 if ($directory ne '.')
8116 return require_build_directory ($directory);
8124 ################################################################
8126 # Push a list of files onto dist_common.
8127 sub push_dist_common
8129 prog_error ("push_dist_common run after handle_dist")
8130 if $handle_dist_run;
8131 macro_define ('DIST_COMMON', 1, '+', '', "@_", '');
8138 $strictness_name = $_[0];
8139 if ($strictness_name eq 'gnu')
8143 elsif ($strictness_name eq 'gnits')
8145 $strictness = GNITS;
8147 elsif ($strictness_name eq 'foreign')
8149 $strictness = FOREIGN;
8153 die "$me: level `$strictness_name' not recognized\n";
8158 ################################################################
8160 # Ensure a file exists.
8166 my $touch = new IO::File (">> $file");
8171 # Glob something. Do this to avoid indentation screwups everywhere we
8172 # want to glob. Gross!
8179 ################################################################
8181 # print_error ($LEADER, @ARGS)
8182 # ----------------------------
8183 # Do the work of printing the error message. Join @ARGS with spaces,
8184 # then split at newlines and add $LEADER to each line. Uses `warn' to
8185 # print message. Set exit status.
8188 my ($leader, @args) = @_;
8190 @args = split ("\n", $text);
8191 $text = $leader . join ("\n" . $leader, @args) . "\n";
8197 # Print an error message and set exit status.
8200 print_error ("$me: ${am_file}.am: ", @_);
8204 # &file_error ($FILE, @ARGS)
8205 # --------------------------
8208 my ($file, @args) = @_;
8209 print_error ("$file: ", @args);
8213 # ¯o_error ($MACRO, @ARGS)
8214 # ----------------------------
8215 # Report an error, @ARGS, about $MACRO.
8216 sub macro_error ($@)
8218 my ($macro, @args) = @_;
8219 file_error ($var_location{$macro}, @args);
8223 # &target_error ($TARGET, @ARGS)
8224 # ------------------------------
8225 # Report an error, @ARGS, about the rule $TARGET.
8226 sub target_error ($@)
8228 my ($target, @args) = @_;
8229 file_error ($targets{$target}, @args);
8233 # Like am_error, but while scanning configure.ac.
8236 # FIXME: can run in subdirs.
8237 print_error ("$me: $configure_ac: ", @_);
8240 # &file_warning ($FILE, @ARGS)
8241 # ----------------------------
8242 # Warning message with line number referring to configure.ac.
8243 # Does not affect exit_status
8244 sub file_warning ($@)
8246 my ($file, @args) = @_;
8248 my $saved_exit_status = $exit_status;
8249 my $sig = $SIG{'__WARN__'};
8250 $SIG{'__WARN__'} = 'DEFAULT';
8251 file_error ($file, @args);
8252 $exit_status = $saved_exit_status;
8253 $SIG{'__WARN__'} = $sig;
8256 # Tell user where our aclocal.m4 is, but only once.
8257 sub keyed_aclocal_warning ($)
8260 warn "$me: macro `$key' can be generated by `aclocal'\n";
8263 # Print usage information.
8267 Usage: $0 [OPTION] ... [Makefile]...
8269 Generate Makefile.in for configure from Makefile.am.
8272 --help print this help, then exit
8273 --version print version number, then exit
8274 -v, --verbose verbosely list files processed
8275 --no-force only update Makefile.in's that are out of date
8277 Dependency tracking:
8278 -i, --ignore-deps disable dependency tracking code
8279 --include-deps enable dependency tracking code
8282 --cygnus assume program is part of Cygnus-style tree
8283 --foreign set strictness to foreign
8284 --gnits set strictness to gnits
8285 --gnu set strictness to gnu
8288 -a, --add-missing add missing standard files to package
8289 --libdir=DIR directory storing library files
8290 -c, --copy with -a, copy missing files (default is symlink)
8291 -f, --force-missing force update of standard files
8296 foreach my $iter (sort ((@common_files, @common_sometimes)))
8298 push (@lcomm, $iter) unless $iter eq $last;
8303 print "\nFiles which are automatically distributed, if found:\n";
8304 format USAGE_FORMAT =
8305 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
8306 $four[0], $four[1], $four[2], $four[3]
8308 $~ = "USAGE_FORMAT";
8311 my $rows = int(@lcomm / $cols);
8312 my $rest = @lcomm % $cols;
8323 for (my $y = 0; $y < $rows; $y++)
8325 @four = ("", "", "", "");
8326 for (my $x = 0; $x < $cols; $x++)
8328 last if $y + 1 == $rows && $x == $rest;
8330 my $idx = (($x > $rest)
8331 ? ($rows * $rest + ($rows - 1) * ($x - $rest))
8335 $four[$x] = $lcomm[$idx];
8340 print "\nReport bugs to <bug-automake\@gnu.org>.\n";
8348 # Print version information
8352 automake (GNU $PACKAGE) $VERSION
8353 Written by Tom Tromey <tromey\@redhat.com>.
8355 Copyright 2002 Free Software Foundation, Inc.
8356 This is free software; see the source for copying conditions. There is NO
8357 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.