5 eval 'exec @PERL@ -S $0 ${1+"$@"}'
8 # automake - create Makefile.in from Makefile.am
9 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
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@cygnus.com>.
34 my $prefix = "@prefix@";
35 my $perllibdir = $ENV{'perllibdir'} || "@datadir@/@PACKAGE@";
36 unshift @INC, "$perllibdir";
40 struct (# Short name of the language (c, f77...).
42 # Nice name of the language (C, Fortran 77...).
45 # List of configure variables which must be defined.
49 # `pure' is `1' or `'. A `pure' language is one where, if
50 # all the files in a directory are of that language, then we
51 # do not require the C compiler or any code to call it.
56 # Name of the compiling variable (COMPILE).
58 # Content of the compiling variable.
60 # Flag to require compilation without linking (-c).
61 'compile_flag' => "\$",
64 # Should the flag be defined as a configure variable.
65 # Defaults to true. FIXME: this should go away once
66 # we move to autoconf tracing.
67 'define_flag' => "\$",
69 # The file to use when generating rules for this language.
70 # The default is 'depend2'.
73 # Name of the linking variable (LINK).
75 # Content of the linking variable.
78 # Name of the linker variable (LD).
80 # Content of the linker variable ($(CC)).
83 # Flag to specify the output file (-o).
84 'output_flag' => "\$",
87 # This is a subroutine which is called whenever we finally
88 # determine the context in which a source file will be
90 '_target_hook' => "\$");
96 if (defined $self->_finish)
102 sub target_hook ($$$$)
105 if (defined $self->_target_hook)
107 &{$self->_target_hook} (@_);
114 use strict 'vars', 'subs';
118 my $me = basename ($0);
125 # Parameters set by configure. Not to be changed. NOTE: assign
126 # VERSION as string so that eg version 0.30 will print correctly.
127 my $VERSION = "@VERSION@";
128 my $PACKAGE = "@PACKAGE@";
129 my $prefix = "@prefix@";
130 my $libdir = "@datadir@/@PACKAGE@";
133 my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
134 my $WHITE_PATTERN = '^\s*$';
135 my $COMMENT_PATTERN = '^#';
136 my $TARGET_PATTERN='[$a-zA-Z_.@][-.a-zA-Z0-9_(){}/$+@]*';
137 # A rule has three parts: a list of targets, a list of dependencies,
138 # and optionally actions.
140 "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
142 my $SUFFIX_RULE_PATTERN = '^\.([a-zA-Z0-9+]+)\.([a-zA-Z0-9+]+)$';
143 # Only recognize leading spaces, not leading tabs. If we recognize
144 # leading tabs here then we need to make the reader smarter, because
145 # otherwise it will think rules like `foo=bar; \' are errors.
146 my $MACRO_PATTERN = '^[A-Za-z0-9_@]+$';
147 my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)$';
148 # This pattern recognizes a Gnits version id and sets $1 if the
149 # release is an alpha release. We also allow a suffix which can be
150 # used to extend the version number with a "fork" identifier.
151 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
152 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?$';
153 my $ELSE_PATTERN = '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
154 my $ENDIF_PATTERN = '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
155 my $PATH_PATTERN='(\w|[/.-])+';
156 # This will pass through anything not of the prescribed form.
157 my $INCLUDE_PATTERN = ('^include\s+'
158 . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
159 . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
160 . '|([^/\$]' . $PATH_PATTERN. '))\s*(#.*)?$');
162 # Some regular expressions. One reason to put them here is that it
163 # makes indentation work better in Emacs.
164 my $AC_CONFIG_AUX_DIR_PATTERN = 'AC_CONFIG_AUX_DIR\(([^)]+)\)';
165 my $AM_INIT_AUTOMAKE_PATTERN = 'AM_INIT_AUTOMAKE\([^,]*,([^,)]+)[,)]';
166 my $AM_PACKAGE_VERSION_PATTERN = '^\s*\[?([^]\s]+)\]?\s*$';
167 # Note that there is no AC_PATH_TOOL. But we don't really care.
168 my $AC_CHECK_PATTERN = 'AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\(\[?(\w+)';
169 my $AM_MISSING_PATTERN = 'AM_MISSING_PROG\(\[?(\w+)';
170 # Just check for alphanumeric in AC_SUBST. If you do AC_SUBST(5),
172 my $AC_SUBST_PATTERN = 'AC_SUBST\(\[?(\w+)';
173 my $AM_CONDITIONAL_PATTERN = 'AM_CONDITIONAL\(\[?(\w+)';
174 # Match `-d' as a command-line argument in a string.
175 my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)";
177 # Constants to define the "strictness" level.
182 # Values for AC_CANONICAL_*
183 my $AC_CANONICAL_HOST = 1;
184 my $AC_CANONICAL_SYSTEM = 2;
186 # Values indicating when something should be cleaned. Right now we
187 # only need to handle `mostly'- and `dist'-clean; add more as
189 my $MOSTLY_CLEAN = 0;
192 # Files installed by libtoolize.
193 my @libtoolize_files = ('ltmain.sh', 'config.guess', 'config.sub');
194 # ltconfig appears here for compatibility with old versions of libtool.
195 my @libtoolize_sometimes = ('ltconfig', 'ltcf-c.sh', 'ltcf-cxx.sh',
198 # Commonly found files we look for and automatically include in
202 'README', 'THANKS', 'TODO', 'NEWS', 'COPYING', 'COPYING.LIB',
203 'INSTALL', 'ABOUT-NLS', 'ChangeLog', 'configure.ac',
204 'configure.in', 'configure', 'config.guess', 'config.sub',
205 'AUTHORS', 'BACKLOG', 'ABOUT-GNU', 'libversion.in',
206 'mdate-sh', 'mkinstalldirs', 'install-sh', 'texinfo.tex',
207 'ansi2knr.c', 'ansi2knr.1', 'elisp-comp',
208 # ltconfig appears here for compatibility with old versions
210 'ylwrap', 'acinclude.m4', @libtoolize_files, @libtoolize_sometimes,
211 'missing', 'depcomp', 'compile', 'py-compile'
214 # Commonly used files we auto-include, but only sometimes.
215 my @common_sometimes =
217 'aclocal.m4', 'acconfig.h', 'config.h.top',
218 'config.h.bot', 'stamp-h.in', 'stamp-vti'
221 # Copyright on generated Makefile.ins.
222 my $gen_copyright = "\
223 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
224 # Free Software Foundation, Inc.
225 # This Makefile.in is free software; the Free Software Foundation
226 # gives unlimited permission to copy and/or distribute it,
227 # with or without modifications, as long as this notice is preserved.
229 # This program is distributed in the hope that it will be useful,
230 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
231 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
232 # PARTICULAR PURPOSE.
235 # These constants are returned by lang_*_rewrite functions.
236 # LANG_SUBDIR means that the resulting object file should be in a
237 # subdir if the source file is. In this case the file name cannot
238 # have `..' components.
240 my $LANG_PROCESS = 1;
243 # Directories installed during 'install-exec' phase.
262 # Map from obsolete macros to hints for new macros.
263 # If you change this, change the corresponding list in aclocal.in.
264 # FIXME: should just put this into a single file.
265 my %obsolete_macros =
267 'AC_FEATURE_CTYPE' => "use `AC_HEADER_STDC'",
268 'AC_FEATURE_ERRNO' => "add `strerror' to `AC_REPLACE_FUNCS(...)'",
269 'AC_FEATURE_EXIT' => '',
270 'AC_SYSTEM_HEADER' => '',
272 # Note that we do not handle this one, because it is still run
273 # from AM_CONFIG_HEADER. So we deal with it specially in
274 # &scan_autoconf_files.
275 # 'AC_CONFIG_HEADER' => "use `AM_CONFIG_HEADER'",
277 'fp_C_PROTOTYPES' => "use `AM_C_PROTOTYPES'",
278 'fp_PROG_CC_STDC' => "use `AM_PROG_CC_STDC'",
279 'fp_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
280 'fp_WITH_DMALLOC' => "use `AM_WITH_DMALLOC'",
281 'fp_WITH_REGEX' => "use `AM_WITH_REGEX'",
282 'gm_PROG_LIBTOOL' => "use `AM_PROG_LIBTOOL'",
283 'jm_MAINTAINER_MODE' => "use `AM_MAINTAINER_MODE'",
284 'md_TYPE_PTRDIFF_T' => "use `AM_TYPE_PTRDIFF_T'",
285 'ud_PATH_LISPDIR' => "use `AM_PATH_LISPDIR'",
286 'ud_GNU_GETTEXT' => "use `AM_GNU_GETTEXT'",
288 # Now part of autoconf proper, under a different name.
289 'AM_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
290 'fp_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
291 'AM_SANITY_CHECK_CC' => "automatically done by `AC_PROG_CC'",
292 'AM_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
293 'AM_EXEEXT' => "use `AC_EXEEXT'",
294 'AM_CYGWIN32' => "use `AC_CYGWIN'",
295 'AM_MINGW32' => "use `AC_MINGW32'",
296 'AM_FUNC_MKTIME' => "use `AC_FUNC_MKTIME'",
298 # These aren't quite obsolete.
302 # Regexp to match the above macros.
303 my $obsolete_rx = '\b(' . join ('|', keys %obsolete_macros) . ')\b';
307 ## ---------------------------------- ##
308 ## Variables related to the options. ##
309 ## ---------------------------------- ##
311 # TRUE if we should always generate Makefile.in.
312 my $force_generation = 1;
314 # Strictness level as set on command line.
315 my $default_strictness = $GNU;
317 # Name of strictness level, as set on command line.
318 my $default_strictness_name = 'gnu';
320 # This is TRUE if automatic dependency generation code should be
321 # included in generated Makefile.in.
322 my $cmdline_use_dependencies = 1;
324 # TRUE if in verbose mode.
327 # This holds our (eventual) exit status. We don't actually exit until
328 # we have processed all input files.
331 # From the Perl manual.
332 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
334 # TRUE if missing standard files should be installed.
337 # TRUE if we should copy missing files; otherwise symlink if possible.
338 my $copy_missing = 0;
340 # TRUE if we should always update files that we know about.
341 my $force_missing = 0;
344 ## ---------------------------------------- ##
345 ## Variables filled during files scanning. ##
346 ## ---------------------------------------- ##
348 # Name of the top autoconf input: `configure.ac' or `configure.in'.
349 my $configure_ac = '';
351 # Files found by scanning configure.ac for LIBOBJS.
354 # True if AM_C_PROTOTYPES appears in configure.ac.
355 my $am_c_prototypes = 0;
357 # Names used in AC_CONFIG_HEADER call. @config_fullnames holds the
358 # name which appears in AC_CONFIG_HEADER, colon and all.
359 # @config_names holds the file names. @config_headers holds the '.in'
360 # files. Ordinarily these are similar, but they can be different if
361 # the weird "NAME:FILE" syntax is used.
362 my @config_fullnames = ();
363 my @config_names = ();
364 my @config_headers = ();
365 # Line number at which AC_CONFIG_HEADER appears in configure.ac.
366 my $config_header_line = 0;
368 # Directory where output files go. Actually, output files are
369 # relative to this directory.
370 my $output_directory = '.';
372 # List of Makefile.am's to process, and their corresponding outputs.
373 my @input_files = ();
374 my %output_files = ();
376 # Complete list of Makefile.am's that exist.
377 my @configure_input_files = ();
379 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
380 my @other_input_files = ();
381 # Line number at which AC_OUTPUT seen.
382 my $ac_output_line = 0;
384 # List of directories to search for configure-required files. This
385 # can be set by AC_CONFIG_AUX_DIR.
386 my @config_aux_path = ('.', '..', '../..');
387 my $config_aux_dir = '';
388 my $config_aux_dir_set_in_configure_in = 0;
390 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
391 my $seen_gettext = 0;
392 # Line number at which AM_GNU_GETTEXT seen.
393 my $ac_gettext_line = 0;
395 # Whether ALL_LINGUAS has been seen.
396 my $seen_linguas = '';
398 my $all_linguas = '';
399 # Line number at which it appears.
400 my $all_linguas_line = 0;
402 # TRUE if AC_DECL_YYTEXT was seen.
403 my $seen_decl_yytext = 0;
405 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM). The presence of
406 # AC_CHECK_TOOL also sets this.
407 my $seen_canonical = 0;
409 # TRUE if we've seen AC_PROG_LIBTOOL.
410 my $seen_libtool = 0;
411 my $libtool_line = 0;
413 # TRUE if we've seen AM_MAINTAINER_MODE.
414 my $seen_maint_mode = 0;
416 # Actual version we've seen.
417 my $package_version = '';
419 # Line number where we saw version definition.
420 my $package_version_line = 0;
422 # TRUE if we've seen AM_PATH_LISPDIR.
423 my $seen_lispdir = 0;
425 # TRUE if we've seen AM_PATH_PYTHON.
426 my $seen_pythondir = 0;
428 # TRUE if we've seen AC_EXEEXT.
431 # TRUE if we've seen AC_OBJEXT.
434 # TRUE if we've seen AC_ENABLE_MULTILIB.
435 my $seen_multilib = 0;
437 # TRUE if we've seen AM_PROG_CC_C_O
440 # TRUE if we've seen AM_INIT_AUTOMAKE.
441 my $seen_init_automake = 0;
443 # Hash table of discovered configure substitutions. Keys are names,
444 # values are `FILE:LINE' strings which are used by error message
446 my %configure_vars = ();
448 # This is used to keep track of which variable definitions we are
449 # scanning. It is only used in certain limited ways, but it has to be
450 # global. It is declared just for documentation purposes.
451 my %vars_scanned = ();
453 # TRUE if --cygnus seen.
456 # Hash table of AM_CONDITIONAL variables seen in configure.
457 my %configure_cond = ();
459 # This maps extensions onto language names.
460 my %extension_map = ();
462 # List of the DIST_COMMON files we discovered while reading
464 my $configure_dist_common = '';
466 # This maps languages names onto objects.
469 # List of targets we must always output.
470 # FIXME: Complete, and remove falsely required targets.
471 my %required_targets =
482 # FIXME: Not required, temporary hacks.
483 # Well, actually they are sort of required: the -recursive
484 # targets will run them anyway...
487 'install-data-am' => 1,
488 'install-exec-am' => 1,
489 'installcheck-am' => 1,
497 ################################################################
499 ## ------------------------------------------ ##
500 ## Variables reset by &initialize_per_input. ##
501 ## ------------------------------------------ ##
503 # Basename and relative dir of the input file.
507 # Same but wrt Makefile.in.
511 # These two variables are used when generating each Makefile.in.
512 # They hold the Makefile.in until it is ready to be printed.
519 # Suffixes found during a run.
522 # Handling the variables.
525 # - $var_value{$VAR}{$COND} is its value associated to $COND,
526 # - $var_line{$VAR} is where it has been defined,
527 # - $var_comment{$VAR} are the comments associated to it.
528 # - $var_type{$VAR} is how it has been defined (`', `+', or `:'),
529 # - $var_is_am{$VAR} is true if the variable is owned by Automake.
536 # This holds a 1 if a particular variable was examined.
539 # This holds the names which are targets. These also appear in
543 # Same as %VAR_VALUE, but for targets.
544 my %target_conditional;
546 # This is the conditional stack.
549 # This holds the set of included files.
552 # This holds a list of directories which we must create at `dist'
553 # time. This is used in some strange scenarios involving weird
554 # AC_OUTPUT commands.
557 # List of dependencies for the obvious targets.
562 # Holds the dependencies of targets which dependencies are factored.
563 # Typically, `.PHONY' will appear in plenty of *.am files, but must
564 # be output once. Arguably all pure dependencies could be subject
565 # to this factorization, but it is not unpleasant to have paragraphs
566 # in Makefile: keeping related stuff altogether.
569 # Holds the factored actions. Tied to %DEPENDENCIES, i.e., filled
570 # only when keys exists in %DEPENDENCIES.
573 # A list of files deleted by `maintainer-clean'.
574 my @maintainer_clean_files;
576 # Keys in this hash table are object files or other files in
577 # subdirectories which need to be removed. This only holds files
578 # which are created by compilations. The value in the hash indicates
579 # when the file should be removed.
580 my %compile_clean_files;
582 # Value of `$(SOURCES)', used by tags.am.
584 # Sources which go in the distribution.
587 # This hash maps object file names onto their corresponding source
588 # file names. This is used to ensure that each object is created
589 # by a single source file.
592 # This keeps track of the directories for which we've already
593 # created `.dirstamp' code.
603 # Options from AUTOMAKE_OPTIONS.
606 # Whether or not dependencies are handled. Can be further changed
608 my $use_dependencies;
610 # This is a list of all targets to run during "make dist".
613 # Keys in this hash are the basenames of files which must depend
617 # This maps the source extension of a suffix rule to its
618 # corresponding output extension.
621 # This is the name of the redirect `all' target to use.
624 # This keeps track of which extensions we've seen (that we care
628 # This is random scratch space for the language finish functions.
629 # Don't randomly overwrite it; examine other uses of keys first.
630 my %language_scratch;
632 # We keep track of which objects need special (per-executable)
633 # handling on a per-language basis.
634 my %lang_specific_files;
636 # This is set when `handle_dist' has finished. Once this happens,
637 # we should no longer push on dist_common.
640 # True if we need `LINK' defined. This is a hack.
643 # This is the list of such variables to output.
644 # FIXME: Might be useless actually.
647 # Was get_object_extension run?
648 # FIXME: This is a hack. a better switch should be found.
649 my $get_object_extension_was_run;
652 ## --------------------------------- ##
653 ## Forward subroutine declarations. ##
654 ## --------------------------------- ##
655 sub register_language (%);
656 sub file_contents_internal ($$%);
659 # &initialize_per_input ()
660 # ------------------------
661 # (Re)-Initialize per-Makefile.am variables.
662 sub initialize_per_input ()
665 $am_relative_dir = '';
672 $output_trailer = '';
688 %target_conditional = ();
696 $am_relative_dir = '';
712 # Installing/uninstalling.
713 'install-data-am' => [],
714 'install-exec-am' => [],
715 'uninstall-am' => [],
718 'uninstall-man' => [],
720 'install-info' => [],
721 'install-info-am' => [],
722 'uninstall-info' => [],
724 'installcheck-am' => [],
728 'mostlyclean-am' => [],
729 'maintainer-clean-am' => [],
730 'distclean-am' => [],
733 'maintainer-clean' => [],
744 @maintainer_clean_files = ();
755 $strictness = $default_strictness;
756 $strictness_name = $default_strictness_name;
760 $use_dependencies = $cmdline_use_dependencies;
770 %extension_seen = ();
772 %language_scratch = ();
774 %lang_specific_files = ();
776 $handle_dist_run = 0;
782 $get_object_extension_was_run = 0;
784 %compile_clean_files = ();
788 ################################################################
790 # Initialize our list of languages that are internally supported.
793 register_language ('name' => 'c',
795 'config_vars' => ['CC'],
799 'compiler' => 'COMPILE',
800 'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
804 'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
805 'compile_flag' => '-c',
806 'extensions' => ['c'],
807 '_finish' => \&lang_c_finish);
810 register_language ('name' => 'cxx',
812 'config_vars' => ['CXX'],
813 'linker' => 'CXXLINK',
814 'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
816 'flags' => 'CXXFLAGS',
817 'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
818 'compiler' => 'CXXCOMPILE',
819 'compile_flag' => '-c',
820 'output_flag' => '-o',
824 'extensions' => ['c++', 'cc', 'cpp', 'cxx', 'C']);
827 register_language ('name' => 'objc',
828 'Name' => 'Objective C',
829 'config_vars' => ['OBJC'],
830 'linker' => 'OBJCLINK',,
831 'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
833 'flags' => 'OBJCFLAGS',
834 'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
835 'compiler' => 'OBJCCOMPILE',
836 'compile_flag' => '-c',
837 'output_flag' => '-o',
841 'extensions' => ['m']);
844 register_language ('name' => 'header',
846 'extensions' => ['h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc'],
848 '_finish' => sub { });
851 register_language ('name' => 'yacc',
853 'config_vars' => ['YACC'],
856 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
857 'compiler' => 'YACCCOMPILE',
858 'extensions' => ['y'],
859 'rule_file' => 'yacc',
860 '_finish' => \&lang_yacc_finish,
861 '_target_hook' => \&lang_yacc_target_hook);
862 register_language ('name' => 'yaccxx',
863 'Name' => 'Yacc (C++)',
864 'config_vars' => ['YACC'],
865 'rule_file' => 'yacc',
868 'compiler' => 'YACCCOMPILE',
869 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
870 'extensions' => ['y++', 'yy', 'yxx', 'ypp'],
871 '_finish' => \&lang_yacc_finish,
872 '_target_hook' => \&lang_yacc_target_hook);
875 register_language ('name' => 'lex',
877 'config_vars' => ['LEX'],
878 'rule_file' => 'lex',
881 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
882 'compiler' => 'LEXCOMPILE',
883 'extensions' => ['l'],
884 '_finish' => \&lang_lex_finish);
885 register_language ('name' => 'lexxx',
886 'Name' => 'Lex (C++)',
887 'config_vars' => ['LEX'],
888 'rule_file' => 'lex',
891 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
892 'compiler' => 'LEXCOMPILE',
893 'extensions' => ['l++', 'll', 'lxx', 'lpp'],
894 '_finish' => \&lang_lex_finish);
897 register_language ('name' => 'asm',
898 'Name' => 'Assembler',
899 'config_vars' => ['AS', 'ASFLAGS'],
901 'flags' => 'ASFLAGS',
902 # Users can set AM_ASFLAGS to includes DEFS, INCLUDES,
903 # or anything else required. They can also set AS.
904 'compile' => '$(AS) $(AM_ASFLAGS) $(ASFLAGS)',
905 'compiler' => 'ASCOMPILE',
906 'compile_flag' => '-c',
907 'extensions' => ['s', 'S'],
909 # With assembly we still use the C linker.
910 '_finish' => \&lang_c_finish);
913 register_language ('name' => 'f77',
914 'Name' => 'Fortran 77',
915 'linker' => 'F77LINK',
916 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
918 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
919 'compiler' => 'F77COMPILE',
920 'compile_flag' => '-c',
921 'output_flag' => '-o',
925 'extensions' => ['f', 'for', 'f90']);
927 # Preprocessed Fortran 77
929 # The current support for preprocessing Fortran 77 just involves
930 # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
931 # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
932 # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
933 # for `make' Version 3.76 Beta' (specifically, from info file
934 # `(make)Catalogue of Rules').
936 # A better approach would be to write an Autoconf test
937 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
938 # Fortran 77 compilers know how to do preprocessing. The Autoconf
939 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
940 # preprocessing capabilities, and then fall back on cpp (if cpp were
942 register_language ('name' => 'ppf77',
943 'Name' => 'Preprocessed Fortran 77',
944 'config_vars' => ['F77'],
945 'linker' => 'F77LINK',
946 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
950 'compiler' => 'PPF77COMPILE',
951 'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
952 'compile_flag' => '-c',
953 'output_flag' => '-o',
955 'extensions' => ['F']);
958 register_language ('name' => 'ratfor',
960 'config_vars' => ['F77'],
961 'linker' => 'F77LINK',
962 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
967 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
968 'compiler' => 'RCOMPILE',
969 'compile_flag' => '-c',
970 'output_flag' => '-o',
972 'extensions' => ['r']);
975 register_language ('name' => 'java',
977 'config_vars' => ['GCJ'],
978 'linker' => 'GCJLINK',
979 'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
981 'flags' => 'GCJFLAGS',
982 'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
983 'compiler' => 'GCJCOMPILE',
984 'compile_flag' => '-c',
985 'output_flag' => '-o',
989 'extensions' => ['java', 'class', 'zip', 'jar']);
991 ################################################################
993 # Parse command line.
996 # Do configure.ac scan only once.
997 &scan_autoconf_files;
999 die "$me: no `Makefile.am' found or specified\n"
1002 # Now do all the work on each file.
1003 # This guy must be local otherwise it's private to the loop.
1004 use vars '$am_file';
1006 foreach $am_file (@input_files)
1008 if (! -f ($am_file . '.am'))
1010 &am_error ("`" . $am_file . ".am' does not exist");
1014 &generate_makefile ($output_files{$am_file}, $am_file);
1020 # FIXME: This should be `my'ed next to its subs.
1021 use vars '%require_file_found';
1023 ################################################################
1025 # prog_error (@PRINT-ME)
1026 # ----------------------
1027 # Signal a programming error, display PRINT-ME, and exit 1.
1030 print STDERR "$me: programming error: @_\n";
1038 # Return LIST with no duplicates.
1043 foreach my $item (@_)
1045 if (! defined $seen{$item})
1056 # Return a configure-style substitution using the indicated text.
1057 # We do this to avoid having the substitutions directly in automake.in;
1058 # when we do that they are sometimes removed and this causes confusion
1063 return '@' . $text . '@';
1066 ################################################################
1070 # &backname ($REL-DIR)
1071 # --------------------
1072 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
1073 # For instance `src/foo' => `../..'.
1074 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
1079 foreach (split (/\//, $file))
1081 next if $_ eq '.' || $_ eq '';
1091 return join ('/', @res) || '.';
1094 ################################################################
1096 # Parse command line.
1097 sub parse_arguments ()
1100 &set_strictness ('gnu');
1103 Getopt::Long::config ("bundling");
1104 Getopt::Long::GetOptions
1106 'version' => \&version,
1108 'libdir:s' => \$libdir,
1109 'gnu' => sub { &set_strictness ('gnu'); },
1110 'gnits' => sub { &set_strictness ('gnits'); },
1111 'cygnus' => \$cygnus_mode,
1112 'foreign' => sub { &set_strictness ('foreign'); },
1113 'include-deps' => sub { $cmdline_use_dependencies = 1; },
1114 'i|ignore-deps' => sub { $cmdline_use_dependencies = 0; },
1115 'no-force' => sub { $force_generation = 0; },
1116 'f|force-missing'=> \$force_missing,
1117 'o|output-dir:s' => \$output_directory,
1118 'a|add-missing' => \$add_missing,
1119 'c|copy' => \$copy_missing,
1120 'v|verbose' => \$verbose,
1121 'Werror' => sub { $SIG{"__WARN__"} = sub { die $_[0] } },
1122 'Wno-error' => sub { $SIG{"__WARN__"} = 'DEFAULT' }
1126 foreach my $arg (@ARGV)
1128 # Handle $local:$input syntax. Note that we only examine the
1129 # first ":" file to see if it is automake input; the rest are
1130 # just taken verbatim. We still keep all the files around for
1131 # dependency checking, however.
1132 my ($local, $input, @rest) = split (/:/, $arg);
1139 # Strip .in; later on .am is tacked on. That is how the
1140 # automake input file is found. Maybe not the best way, but
1141 # it is easy to explain.
1143 or die "$me: invalid input file name `$arg'\n.";
1145 push (@input_files, $input);
1146 $output_files{$input} = join (':', ($local, @rest));
1149 # Take global strictness from whatever we currently have set.
1150 $default_strictness = $strictness;
1151 $default_strictness_name = $strictness_name;
1154 ################################################################
1156 # Generate a Makefile.in given the name of the corresponding Makefile and
1157 # the name of the file output by config.status.
1158 sub generate_makefile
1160 my ($output, $makefile) = @_;
1162 # Reset all the Makefile.am related variables.
1163 &initialize_per_input;
1165 # Name of input file ("Makefile.am") and output file
1166 # ("Makefile.in"). These have no directory components.
1167 $am_file_name = basename ($makefile) . '.am';
1168 $in_file_name = basename ($makefile) . '.in';
1170 # $OUTPUT is encoded. If it contains a ":" then the first element
1171 # is the real output file, and all remaining elements are input
1172 # files. We don't scan or otherwise deal with these input file,
1173 # other than to mark them as dependencies. See
1174 # &scan_autoconf_files for details.
1175 my (@secondary_inputs);
1176 ($output, @secondary_inputs) = split (/:/, $output);
1178 $relative_dir = dirname ($output);
1179 $am_relative_dir = dirname ($makefile);
1181 &read_main_am_file ($makefile . '.am');
1182 if (&handle_options)
1184 # Fatal error. Just return, so we can continue with next file.
1188 # There are a few install-related variables that you should not define.
1189 foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
1191 if (&variable_defined ($var) && !$var_is_am{$var})
1193 &am_line_error ($var, "`$var' should not be defined");
1199 # At the toplevel directory, we might need config.guess, config.sub
1200 # or libtool scripts (ltconfig and ltmain.sh).
1201 if ($relative_dir eq '.')
1203 # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1205 &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
1209 # We still need Makefile.in here, because sometimes the `dist'
1210 # target doesn't re-run automake.
1211 if ($am_relative_dir eq $relative_dir)
1213 # Only distribute the files if they are in the same subdir as
1214 # the generated makefile.
1215 &push_dist_common ($in_file_name, $am_file_name);
1218 push (@sources, '$(SOURCES)')
1219 if &variable_defined ('SOURCES');
1221 # If OBJEXT/EXEEXT were not set in configure.in, do it, it
1222 # simplifies our task, and anyway starting with Autoconf 2.50, it
1223 # will always be defined, and this code will be dead.
1224 $output_vars .= "EXEEXT =\n"
1225 unless $seen_exeext;
1226 $output_vars .= "OBJEXT = o\n"
1227 unless $seen_objext;
1229 # Must do this after reading .am file. See read_main_am_file to
1230 # understand weird tricks we play there with variables.
1231 &define_variable ('subdir', $relative_dir);
1233 # Check first, because we might modify some state.
1235 &check_gnu_standards;
1236 &check_gnits_standards;
1238 &handle_configure ($output, $makefile, @secondary_inputs);
1241 &handle_ltlibraries;
1245 # This must run first so that the ANSI2KNR definition is generated
1246 # before it is used by the _.c rules. We have to do this because
1247 # a variable which is used in a dependency must be defined before
1248 # the target, or else make won't properly see it.
1250 # This must be run after all the sources are scanned.
1253 # Re-init SOURCES. FIXME: other code shouldn't depend on this
1254 # (but currently does).
1255 macro_define ('SOURCES', 1, '', 'TRUE',
1256 join (' ', @sources), 'internal');
1257 &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
1269 &handle_minor_options;
1272 # This must come after most other rules.
1273 &handle_dist ($makefile);
1276 &do_check_merge_target;
1277 &handle_all ($output);
1280 if (&variable_defined('lib_LTLIBRARIES') &&
1281 &variable_defined('bin_PROGRAMS'))
1283 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
1286 &handle_installdirs;
1288 &handle_factored_dependencies;
1292 if (! -d ($output_directory . '/' . $am_relative_dir))
1294 mkdir ($output_directory . '/' . $am_relative_dir, 0755);
1297 my ($out_file) = $output_directory . '/' . $makefile . ".in";
1298 if (! $force_generation && -e $out_file)
1300 my ($am_time) = (stat ($makefile . '.am'))[9];
1301 my ($in_time) = (stat ($out_file))[9];
1302 # FIXME: should cache these times.
1303 my ($conf_time) = (stat ($configure_ac))[9];
1304 # FIXME: how to do unsigned comparison?
1305 if ($am_time < $in_time || $am_time < $conf_time)
1307 # No need to update.
1310 if (-f 'aclocal.m4')
1312 my ($acl_time) = (stat _)[9];
1313 return if ($am_time < $acl_time);
1317 my $gm_file = new IO::File "> $out_file";
1320 warn "$me: ${am_file}.in: cannot write: $!\n";
1324 print "$me: creating ", $makefile, ".in\n" if $verbose;
1326 # In case we're running under MSWindows, don't write with CRLF
1327 # (as it causes problems for the dependency-file extraction in
1328 # AM_OUTPUT_DEPENDENCY_COMMANDS).
1331 print $gm_file $output_vars;
1332 # We make sure that `all:' is the first target.
1333 print $gm_file $output_all;
1334 print $gm_file $output_header;
1335 print $gm_file $output_rules;
1336 print $gm_file $output_trailer;
1338 if (! $gm_file->close)
1340 warn "$me: $am_file.in: cannot close: $!\n";
1346 ################################################################
1348 # A helper which handles the logic of requiring a version number in
1349 # AUTOMAKE_OPTIONS. Return 1 on error, 0 on success.
1350 sub version_check ($$$$)
1352 my ($rmajor, $rminor, $ralpha, $rfork) = ($1, $2, $3, $4);
1354 &prog_error ("version is incorrect: $VERSION")
1355 if $VERSION !~ /(\d+)\.(\d+)([a-z]?)-?([A-Za-z0-9]+)?/;
1357 my ($tmajor, $tminor, $talpha, $tfork) = ($1, $2, $3, $4);
1362 my $rminorminor = 0;
1363 my $tminorminor = 0;
1365 # Some versions were labelled like `1.4-p3a'. This is the same as
1366 # an alpha release labelled `1.4.3a'. However, a version like
1367 # `1.4g' is the same as `1.4.99g'. Yes, this sucks. Moral:
1368 # always listen to the users.
1369 if ($rfork =~ /p([0-9]+)([a-z]?)/)
1372 # `1.4a-p3b' never existed. But we'll accept it anyway.
1373 $ralpha = $ralpha || $2 || '';
1376 if ($tfork =~ /p([0-9]+)([a-z]?)/)
1379 # `1.4a-p3b' never existed. But we'll accept it anyway.
1380 $talpha = $talpha || $2 || '';
1384 $rminorminor = 99 if $ralpha ne '' && $rminorminor == 0;
1385 $tminorminor = 99 if $talpha ne '' && $tminorminor == 0;
1387 # 2.0 is better than 1.0.
1388 # 1.2 is better than 1.1.
1389 # 1.2a is better than 1.2.
1390 # If we require 3.4n-foo then we require something
1391 # >= 3.4n, with the `foo' fork identifier.
1392 # The $r* variables are what the user specified.
1393 # The $t* variables denote automake itself.
1394 if ($rmajor > $tmajor
1395 || ($rmajor == $tmajor && $rminor > $tminor)
1396 || ($rminor == $tminor && $rminor == $tminor
1397 && $rminorminor > $tminorminor)
1398 || ($rminor == $tminor && $rminor == $tminor
1399 && $rminorminor == $tminorminor
1400 && $ralpha gt $talpha)
1401 || ($rfork ne '' && $rfork ne $tfork))
1403 &am_line_error ('AUTOMAKE_OPTIONS',
1404 "require version $_, but have $VERSION");
1411 # Handle AUTOMAKE_OPTIONS variable. Return 1 on error, 0 otherwise.
1414 if (&variable_defined ('AUTOMAKE_OPTIONS'))
1416 foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
1419 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
1421 &set_strictness ($_);
1423 elsif ($_ eq 'cygnus')
1429 # An option like "../lib/ansi2knr" is allowed. With
1430 # no path prefix, we assume the required programs are
1431 # in this directory. We save the actual option for
1433 $options{'ansi2knr'} = $_;
1435 elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
1436 || $_ eq 'dist-shar' || $_ eq 'dist-zip'
1437 || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
1438 || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
1439 || $_ eq 'readme-alpha' || $_ eq 'check-news'
1440 || $_ eq 'subdir-objects' || $_ eq 'nostdinc')
1442 # Explicitly recognize these.
1444 elsif ($_ eq 'no-dependencies')
1446 $use_dependencies = 0;
1448 elsif (/(\d+)\.(\d+)([a-z]?)(-[A-Za-z0-9]+)?/)
1450 # Got a version number.
1451 if (version_check ($1, $2, $3, $4))
1458 &am_line_error ('AUTOMAKE_OPTIONS',
1459 "option `" . $_ . "\' not recognized");
1464 if ($strictness == $GNITS)
1466 $options{'readme-alpha'} = 1;
1467 $options{'check-news'} = 1;
1474 # get_object_extension ($OUT)
1475 # ---------------------------
1476 # Return object extension. Just once, put some code into the output.
1477 # OUT is the name of the output file
1478 sub get_object_extension
1482 # Maybe require libtool library object files.
1483 my $extension = '.$(OBJEXT)';
1484 $extension = '.lo' if ($out =~ /\.la$/);
1486 # Check for automatic de-ANSI-fication.
1487 $extension = '$U' . $extension
1488 if defined $options{'ansi2knr'};
1490 $get_object_extension_was_run = 1;
1496 # Call finish function for each language that was used.
1497 sub handle_languages
1499 if ($use_dependencies)
1501 # Include auto-dep code. Don't include it if DEP_FILES would
1503 if (&saw_sources_p (0) && keys %dep_files)
1505 # Set location of depcomp.
1506 &define_variable ('depcomp', "\$(SHELL) $config_aux_dir/depcomp");
1508 &require_config_file ($FOREIGN, 'depcomp');
1510 my @deplist = sort keys %dep_files;
1512 # We define this as a conditional variable because BSD
1513 # make can't handle backslashes for continuing comments on
1514 # the following line.
1515 &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
1517 # Generate each `include' individually. Irix 6 make will
1518 # not properly include several files resulting from a
1519 # variable expansion; generating many separate includes
1521 $output_rules .= "\n";
1522 foreach my $iter (@deplist)
1524 $output_rules .= (subst ('AMDEP_TRUE')
1525 . subst ('am__include')
1527 . subst ('am__quote')
1529 . subst ('am__quote')
1533 $output_rules .= &file_contents ('depend');
1538 &define_variable ('depcomp', '');
1543 # Is the c linker needed?
1545 foreach my $ext (sort keys %extension_seen)
1547 next unless $extension_map{$ext};
1549 my $lang = $languages{$extension_map{$ext}};
1551 my $rule_file = $lang->rule_file || 'depend2';
1553 # Get information on $LANG.
1554 my $pfx = $lang->autodep;
1555 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1557 my $AMDEP = (($use_dependencies && $lang->autodep ne 'no')
1558 ? 'AMDEP' : 'FALSE');
1560 my %transform = ('EXT' => $ext,
1563 'LIBTOOL' => $seen_libtool,
1565 '-c' => $lang->compile_flag || '',
1567 => (count_files_for_language ($lang->name) > 1));
1569 # Generate the appropriate rules for this extension.
1570 if (($use_dependencies && $lang->autodep ne 'no')
1571 || defined $lang->compile)
1573 # Some C compilers don't support -c -o. Use it only if really
1575 my $output_flag = $lang->output_flag || '';
1578 && $lang->flags eq 'CFLAGS'
1579 && defined $options{'subdir-objects'});
1581 # FIXME: this is a temporary hack to compute a possible
1582 # derived extension. This is not used by depend2.am.
1583 (my $der_ext = $ext) =~ tr/yl/cc/;
1585 # Another yacc/lex hack.
1586 my $destfile = '$*.' . $der_ext;
1589 file_contents ($rule_file,
1593 'DERIVED-EXT' => $der_ext,
1601 'COMPILE' => '$(' . $lang->compiler . ')',
1602 'LTCOMPILE' => '$(LT' . $lang->compiler . ')',
1603 '-o' => $output_flag);
1606 # Now include code for each specially handled object with this
1608 my %seen_files = ();
1609 foreach my $file (@{$lang_specific_files{$lang->name}})
1611 my ($derived, $source, $obj, $myext) = split (' ', $file);
1613 # We might see a given object twice, for instance if it is
1614 # used under different conditions.
1615 next if defined $seen_files{$obj};
1616 $seen_files{$obj} = 1;
1618 my $flags = $lang->flags || '';
1619 my $val = "${derived}_${flags}";
1621 &prog_error ("found $lang->name in handle_languages, but compiler not defined")
1622 unless defined $lang->compile;
1624 (my $obj_compile = $lang->compile) =~ s/\(AM_$flags/\($val/;
1625 my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
1627 # We _need_ `-o' for per object rules.
1628 my $output_flag = $lang->output_flag || '-o';
1630 # Generate a transform which will turn suffix targets in
1631 # depend2.am into real targets for the particular objects we
1634 file_contents ($rule_file,
1639 'SOURCE' => $source,
1640 # Use $myext and not `.o' here, in case
1641 # we are actually building a new source
1642 # file -- e.g. via yacc.
1643 'OBJ' => "$obj$myext",
1644 'OBJOBJ' => "$obj.obj",
1645 'LTOBJ' => "$obj.lo",
1647 'COMPILE' => $obj_compile,
1648 'LTCOMPILE' => $obj_ltcompile,
1649 '-o' => $output_flag));
1652 # The rest of the loop is done once per language.
1653 next if defined $done{$lang};
1656 # Load the language dependent Makefile chunks.
1657 my %lang = map { uc ($_) => 0 } keys %languages;
1658 $lang{uc ($lang->name)} = 1;
1659 $output_rules .= file_contents ('lang-compile', %transform, %lang);
1661 # If the source to a program consists entirely of code from a
1662 # `pure' language, for instance C++ for Fortran 77, then we
1663 # don't need the C compiler code. However if we run into
1664 # something unusual then we do generate the C code. There are
1665 # probably corner cases here that do not work properly.
1666 # People linking Java code to Fortran code deserve pain.
1667 $needs_c ||= ! $lang->pure;
1669 define_compiler_variable ($lang)
1670 if ($lang->compile);
1672 define_linker_variable ($lang)
1675 foreach my $var (@{$lang->config_vars})
1677 am_error ($lang->Name
1678 . " source seen but `$var' not defined in"
1679 . " `$configure_ac'")
1680 if !exists $configure_vars{$var};
1683 # The compiler's flag must be a configure variable.
1684 define_configure_variable ($lang->flags)
1685 if defined $lang->flags && $lang->define_flag;
1687 # Call the finisher.
1691 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1692 # suffix rule was learned), don't bother with the C stuff. But if
1693 # anything else creeps in, then use it.
1695 if $need_link || scalar keys %suffix_rules > 1;
1699 if (! defined $done{$languages{'c'}})
1701 &define_configure_variable ($languages{'c'}->flags);
1702 &define_compiler_variable ($languages{'c'});
1704 define_linker_variable ($languages{'c'});
1708 # Check to make sure a source defined in LIBOBJS is not explicitly
1709 # mentioned. This is a separate function (as opposed to being inlined
1710 # in handle_source_transform) because it isn't always appropriate to
1712 sub check_libobjs_sources
1714 my ($one_file, $unxformed) = @_;
1716 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1717 'dist_EXTRA_', 'nodist_EXTRA_')
1720 if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1722 @files = &variable_value_as_list (($prefix
1723 . $one_file . '_SOURCES'),
1726 elsif ($prefix eq '')
1728 @files = ($unxformed . '.c');
1735 foreach my $file (@files)
1737 if (defined $libsources{$file})
1739 &am_line_error ($prefix . $one_file . '_SOURCES',
1740 "automatically discovered file `$file' should not be explicitly mentioned");
1747 # ($LINKER, @OBJECTS)
1748 # handle_single_transform_list ($VAR, $DERIVED, $OBJ, @FILES)
1749 # -----------------------------------------------------------
1750 # Does much of the actual work for handle_source_transform.
1752 # $DERIVED is the name of resulting executable or library
1753 # $OBJ is the object extension (e.g., `$U.lo')
1754 # @FILES is the list of source files to transform
1756 # $LINKER is name of linker to use (empty string for default linker)
1757 # @OBJECTS are names of objects
1758 sub handle_single_transform_list ($$$@)
1760 my ($var, $derived, $obj, @files) = @_;
1762 my $nonansi_obj = $obj;
1763 $nonansi_obj =~ s/\$U//g;
1764 my %linkers_used = ();
1766 # Turn sources into objects. We use a while loop like this
1767 # because we might add to @files in the loop.
1768 while (scalar @files > 0)
1772 # Configure substitutions in _SOURCES variables are errors.
1775 &am_line_error ($var, "$var includes configure substitution `$_'");
1779 # If the source file is in a subdirectory then the `.o' is put
1780 # into the current directory, unless the subdir-objects option
1783 # Split file name into base and extension.
1784 next if ! /^(?:(.*)\/)?([^\/]*)\.(.*)$/;
1786 my $directory = $1 || '';
1790 # We must generate a rule for the object if it requires its own flags.
1792 my ($linker, $object);
1794 # This records whether we've seen a derived source file (eg,
1796 my $derived_source = 0;
1798 # This holds the `aggregate context' of the file we are
1799 # currently examining. If the file is compiled with
1800 # per-object flags, then it will be the name of the object.
1801 # Otherwise it will be `AM'. This is used by the target hook
1802 # language function.
1803 my $aggregate = 'AM';
1805 $extension = &derive_suffix ($extension);
1807 if ($extension_map{$extension} &&
1808 ($lang = $languages{$extension_map{$extension}}))
1810 # Found the language, so see what it says.
1811 &saw_extension ($extension);
1813 # Note: computed subr call. The language rewrite function
1814 # should return one of the $LANG_* constants. It could
1815 # also return a list whose first value is such a constant
1816 # and whose second value is a new source extension which
1817 # should be applied. This means this particular language
1818 # generates another source file which we must then process
1820 my $subr = 'lang_' . $lang->name . '_rewrite';
1821 my ($r, $source_extension)
1822 = & $subr ($directory, $base, $extension);
1823 # Skip this entry if we were asked not to process it.
1824 next if $r == $LANG_IGNORE;
1826 # Now extract linker and other info.
1827 $linker = $lang->linker;
1830 if (defined $source_extension)
1832 $this_obj_ext = '.' . $source_extension;
1833 $derived_source = 1;
1837 $this_obj_ext = $obj;
1841 $this_obj_ext = $nonansi_obj;
1843 $object = $base . $this_obj_ext;
1845 if (defined $lang->flags
1846 && &variable_defined ($derived . '_' . $lang->flags))
1848 # We have a per-executable flag in effect for this
1849 # object. In this case we rewrite the object's
1850 # name to ensure it is unique. We also require
1851 # the `compile' program to deal with compilers
1852 # where `-c -o' does not work.
1854 # We choose the name `DERIVED_OBJECT' to ensure
1855 # (1) uniqueness, and (2) continuity between
1856 # invocations. However, this will result in a
1857 # name that is too long for losing systems, in
1858 # some situations. So we provide _SHORTNAME to
1861 my $dname = $derived;
1862 if (&variable_defined ($derived . '_SHORTNAME'))
1864 # FIXME: should use the same conditional as
1865 # the _SOURCES variable. But this is really
1866 # silly overkill -- nobody should have
1867 # conditional shortnames.
1868 $dname = &variable_value ($derived . '_SHORTNAME');
1870 $object = $dname . '-' . $object;
1872 &require_config_file ($FOREIGN, 'compile')
1873 if $lang->name eq 'c';
1875 &prog_error ("$lang->name flags defined without compiler")
1876 if ! defined $lang->compile;
1881 # If rewrite said it was ok, put the object into a
1883 if ($r == $LANG_SUBDIR && $directory ne '')
1885 $object = $directory . '/' . $object;
1888 # If doing dependency tracking, then we can't print
1889 # the rule. If we have a subdir object, we need to
1890 # generate an explicit rule. Actually, in any case
1891 # where the object is not in `.' we need a special
1892 # rule. The per-object rules in this case are
1893 # generated later, by handle_languages.
1894 if ($renamed || $directory ne '')
1896 my $obj_sans_ext = substr ($object, 0,
1897 - length ($this_obj_ext));
1898 my $val = ("$full $obj_sans_ext "
1899 # Only use $this_obj_ext in the derived
1900 # source case because in the other case we
1901 # *don't* want $(OBJEXT) to appear here.
1902 . ($derived_source ? $this_obj_ext : '.o'));
1904 # If we renamed the object then we want to use the
1905 # per-executable flag name. But if this is simply a
1906 # subdir build then we still want to use the AM_ flag
1910 $val = "$derived $val";
1911 $aggregate = $derived;
1918 # Each item on this list is a string consisting of
1919 # four space-separated values: the derived flag prefix
1920 # (eg, for `foo_CFLAGS', it is `foo'), the name of the
1921 # source file, the base name of the output file, and
1922 # the extension for the object file.
1923 push (@{$lang_specific_files{$lang->name}}, $val);
1926 elsif ($extension eq 'o')
1928 # This is probably the result of a direct suffix rule.
1929 # In this case we just accept the rewrite. FIXME:
1930 # this fails if we want libtool objects.
1931 $object = $base . '.' . $extension;
1936 # No error message here. Used to have one, but it was
1938 # FIXME: we could potentially do more processing here,
1939 # perhaps treating the new extension as though it were a
1940 # new source extension (as above). This would require
1941 # more restructuring than is appropriate right now.
1945 if (defined $object_map{$object})
1947 if ($object_map{$object} ne $full)
1949 &am_error ("object `$object' created by `$full' and `$object_map{$object}'");
1953 # Let the language do some special magic if required.
1954 $lang->target_hook ($aggregate, $object, $full);
1956 if ($derived_source)
1958 &prog_error ("$lang->name has automatic dependency tracking")
1959 if $lang->autodep ne 'no';
1960 # Make sure this new source file is handled next. That will
1961 # make it appear to be at the right place in the list.
1962 unshift (@files, $object);
1964 &push_dist_common ($object);
1968 $linkers_used{$linker} = 1;
1970 push (@result, $object);
1972 if (! defined $object_map{$object})
1975 $object_map{$object} = $full;
1977 # If file is in subdirectory, we need explicit
1979 if ($directory ne '' || $renamed)
1981 push (@dep_list, $full);
1984 # If resulting object is in subdir, we need to make
1985 # sure the subdir exists at build time.
1986 if ($object =~ /\//)
1988 # FIXME: check that $DIRECTORY is somewhere in the
1991 # We don't allow `..' in object file names for
1992 # *any* source, not just Java. For Java it just
1993 # doesn't make sense, but in general it is
1994 # a problem because we can't pick a good name for
1996 if ($object =~ /(\/|^)\.\.\//)
1998 &am_error ("`$full' contains `..' component but should not");
2001 # Make sure object is removed by `make mostlyclean'.
2002 $compile_clean_files{$object} = $MOSTLY_CLEAN;
2004 push (@dep_list, &require_build_directory ($directory));
2006 # If we're generating dependencies, we also want
2007 # to make sure that the appropriate subdir of the
2008 # .deps directory is created.
2009 push (@dep_list, &require_build_directory ('$(DEPDIR)/' . $directory))
2010 if ($use_dependencies);
2013 &pretty_print_rule ($object . ':', "\t", @dep_list)
2014 if scalar @dep_list > 0;
2017 # Transform .o or $o file into .P file (for automatic
2019 if ($lang && $lang->autodep ne 'no')
2021 my $depfile = $object;
2022 $depfile =~ s/\.([^.]*)$/.P$1/;
2023 $depfile =~ s/\$\(OBJEXT\)$/o/;
2024 $dep_files{'$(DEPDIR)/' . $depfile} = 1;
2028 return (&resolve_linker (%linkers_used), @result);
2033 # Handle SOURCE->OBJECT transform for one program or library.
2035 # canonical (transformed) name of object to build
2036 # actual name of object to build
2037 # object extension (ie either `.o' or `$o'.
2038 # Return result is name of linker variable that must be used.
2039 # Empty return means just use `LINK'.
2040 sub handle_source_transform
2042 # one_file is canonical name. unxformed is given name. obj is
2044 my ($one_file, $unxformed, $obj) = @_;
2048 if (&variable_defined ($one_file . "_OBJECTS"))
2050 &am_line_error ($one_file . '_OBJECTS',
2051 $one_file . '_OBJECTS', 'should not be defined');
2052 # No point in continuing.
2057 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2058 'dist_EXTRA_', 'nodist_EXTRA_')
2060 my $var = $prefix . $one_file . "_SOURCES";
2062 if !variable_defined ($var);
2064 # We are going to define _OBJECTS variables using the prefix.
2065 # Then we glom them all together. So we can't use the null
2066 # prefix here as we need it later.
2067 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2069 # Keep track of which prefixes we saw.
2070 $used_pfx{$xpfx} = 1
2071 unless $prefix =~ /EXTRA_/;
2073 push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
2074 push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
2075 unless $prefix =~ /^nodist_/;
2076 foreach my $cond (variable_conditions ($var))
2078 my @files = &variable_value_as_list ($var, $cond);
2079 my ($temp, @result) =
2080 &handle_single_transform_list ($var, $one_file, $obj,
2082 # If there are no files to compile, don't require a linker (yet).
2086 # Define _OBJECTS conditionally.
2087 &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
2089 unless $prefix =~ /EXTRA_/;
2093 my @keys = sort keys %used_pfx;
2094 if (scalar @keys == 0)
2096 &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
2097 push (@sources, $unxformed . '.c');
2098 push (@dist_sources, $unxformed . '.c');
2100 my ($temp, @result) =
2101 &handle_single_transform_list ($one_file . '_SOURCES',
2104 $linker = $temp if $linker eq '';
2105 &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
2109 grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
2110 &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
2113 # If we want to use `LINK' we must make sure it is defined.
2123 # handle_lib_objects ($XNAME, $VAR)
2124 # ---------------------------------
2125 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
2126 # Also, generate _DEPENDENCIES variable if appropriate.
2128 # transformed name of object being built, or empty string if no object
2129 # name of _LDADD/_LIBADD-type variable to examine
2130 # Returns 1 if LIBOBJS seen, 0 otherwise.
2131 sub handle_lib_objects
2133 my ($xname, $var) = @_;
2135 &prog_error ("handle_lib_objects: $var undefined")
2136 if ! &variable_defined ($var);
2139 foreach my $cond (&variable_conditions ($var))
2141 if (&handle_lib_objects_cond ($xname, $var, $cond))
2149 # Subroutine of handle_lib_objects: handle a particular condition.
2150 sub handle_lib_objects_cond
2152 my ($xname, $var, $cond) = @_;
2154 # We recognize certain things that are commonly put in LIBADD or
2158 my $seen_libobjs = 0;
2161 foreach my $lsearch (&variable_value_as_list ($var, $cond))
2163 # Skip -lfoo and -Ldir; these are explicitly allowed.
2164 next if $lsearch =~ /^-[lL]/;
2165 if (! $flagvar && $lsearch =~ /^-/)
2167 if ($var =~ /^(.*)LDADD$/)
2169 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
2170 next if $lsearch =~ /^-dl(pre)?open$/;
2171 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2175 # Only get this error once.
2177 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2181 # Assume we have a file of some sort, and push it onto the
2182 # dependency list. Autoconf substitutions are not pushed;
2183 # rarely is a new dependency substituted into (eg) foo_LDADD
2184 # -- but "bad things (eg -lX11) are routinely substituted.
2185 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2186 # and handled specially below.
2187 push (@dep_list, $lsearch)
2188 unless $lsearch =~ /^\@.*\@$/;
2190 # Automatically handle @LIBOBJS@ and @ALLOCA@. Basically this
2191 # means adding entries to dep_files.
2192 if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
2194 my $myobjext = ($1 ? 'l' : '') . 'o';
2196 push (@dep_list, $lsearch);
2198 if (! keys %libsources
2199 && ! &variable_defined ($1 . 'LIBOBJS'))
2201 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in `$configure_ac'");
2204 foreach my $iter (keys %libsources)
2206 if ($iter =~ /\.([cly])$/)
2208 &saw_extension ($1);
2209 &saw_extension ('c');
2212 if ($iter =~ /\.h$/)
2214 &require_file_with_line ($var, $FOREIGN, $iter);
2216 elsif ($iter ne 'alloca.c')
2218 my $rewrite = $iter;
2219 $rewrite =~ s/\.c$/.P$myobjext/;
2220 $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
2221 ($rewrite = $iter) =~ s/(\W)/\\$1/g;
2222 $rewrite = "^" . $rewrite . "\$";
2223 # Only require the file if it is not a built source.
2224 if (! &variable_defined ('BUILT_SOURCES')
2225 || ! grep (/$rewrite/,
2226 &variable_value_as_list ('BUILT_SOURCES',
2229 &require_file_with_line ($var, $FOREIGN, $iter);
2234 elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
2236 my $myobjext = ($1 ? 'l' : '') . 'o';
2238 push (@dep_list, $lsearch);
2239 &am_line_error ($var,
2240 "\@$1" . "ALLOCA\@ seen but `AC_FUNC_ALLOCA' not in `$configure_ac'")
2241 if ! defined $libsources{'alloca.c'};
2242 $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
2243 &require_file_with_line ($var, $FOREIGN, 'alloca.c');
2244 &saw_extension ('c');
2248 if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
2250 &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
2253 return $seen_libobjs;
2256 # Canonicalize the input parameter
2260 $string =~ tr/A-Za-z0-9_\@/_/c;
2264 # Canonicalize a name, and check to make sure the non-canonical name
2265 # is never used. Returns canonical name. Arguments are name and a
2266 # list of suffixes to check for.
2267 sub check_canonical_spelling
2269 my ($name, @suffixes) = @_;
2271 my $xname = &canonicalize ($name);
2272 if ($xname ne $name)
2274 foreach my $xt (@suffixes)
2276 &am_line_error ("$name$xt",
2277 "invalid variable `$name$xt'; "
2278 . "should be `$xname$xt'")
2279 if &variable_defined ("$name$xt");
2289 # Set up the compile suite.
2290 sub handle_compile ()
2293 unless $get_object_extension_was_run;
2296 my $default_includes = '';
2297 if (! defined $options{'nostdinc'})
2299 $default_includes = ' -I. -I$(srcdir)';
2301 if (&variable_defined ('CONFIG_HEADER'))
2303 foreach my $hdr (split (' ', &variable_value ('CONFIG_HEADER')))
2305 $default_includes .= ' -I' . dirname ($hdr);
2310 my (@mostly_rms, @dist_rms);
2311 foreach my $item (sort keys %compile_clean_files)
2313 if ($compile_clean_files{$item} == $MOSTLY_CLEAN)
2315 push (@mostly_rms, "\t-rm -f $item");
2317 elsif ($compile_clean_files{$item} == $DIST_CLEAN)
2319 push (@dist_rms, "\t-rm -f $item");
2323 &prog_error ("invalid entry in \%compile_clean_files");
2327 my ($coms, $vars, $rules) =
2328 &file_contents_internal (1, "$libdir/am/compile.am",
2329 ('DEFAULT_INCLUDES' => $default_includes,
2330 'MOSTLYRMS' => join ("\n", @mostly_rms),
2331 'DISTRMS' => join ("\n", @dist_rms)));
2332 $output_vars .= $vars;
2333 $output_rules .= "$coms$rules";
2335 # Check for automatic de-ANSI-fication.
2336 if (defined $options{'ansi2knr'})
2338 if (! $am_c_prototypes)
2340 &am_line_error ('AUTOMAKE_OPTIONS',
2341 "option `ansi2knr' in use but `AM_C_PROTOTYPES' not in `$configure_ac'");
2342 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
2343 # Only give this error once.
2344 $am_c_prototypes = 1;
2347 # topdir is where ansi2knr should be.
2348 if ($options{'ansi2knr'} eq 'ansi2knr')
2350 # Only require ansi2knr files if they should appear in
2352 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
2353 'ansi2knr.c', 'ansi2knr.1');
2355 # ansi2knr needs to be built before subdirs, so unshift it.
2356 unshift (@all, '$(ANSI2KNR)');
2359 my $ansi2knr_dir = '';
2360 $ansi2knr_dir = dirname ($options{'ansi2knr'})
2361 if $options{'ansi2knr'} ne 'ansi2knr';
2363 $output_rules .= &file_contents ('ansi2knr',
2364 ('ANSI2KNR-DIR' => $ansi2knr_dir));
2371 # Handle libtool rules.
2374 return unless $seen_libtool;
2376 # libtool requires some files, but only at top level.
2377 &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
2379 if $relative_dir eq '.';
2381 # Output the libtool compilation rules.
2382 $output_rules .= &file_contents ('libtool');
2385 # handle_programs ()
2386 # ------------------
2387 # Handle C programs.
2390 my @proglist = &am_install_var ('progs', 'PROGRAMS',
2391 'bin', 'sbin', 'libexec', 'pkglib',
2393 return if ! @proglist;
2395 my $seen_libobjs = 0;
2396 foreach my $one_file (@proglist)
2398 my $obj = &get_object_extension ($one_file);
2400 # Canonicalize names and check for misspellings.
2401 my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2402 '_SOURCES', '_OBJECTS',
2405 my $linker = &handle_source_transform ($xname, $one_file, $obj);
2408 if (&variable_defined ($xname . "_LDADD"))
2410 if (&handle_lib_objects ($xname, $xname . '_LDADD'))
2418 # User didn't define prog_LDADD override. So do it.
2419 &define_variable ($xname . '_LDADD', '$(LDADD)');
2421 # This does a bit too much work. But we need it to
2422 # generate _DEPENDENCIES when appropriate.
2423 if (&variable_defined ('LDADD'))
2425 if (&handle_lib_objects ($xname, 'LDADD'))
2430 elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
2432 &define_variable ($xname . '_DEPENDENCIES', '');
2437 if (&variable_defined ($xname . '_LIBADD'))
2439 &am_line_error ($xname . '_LIBADD',
2440 "use `" . $xname . "_LDADD', not `"
2441 . $xname . "_LIBADD'");
2444 if (! &variable_defined ($xname . '_LDFLAGS'))
2446 # Define the prog_LDFLAGS variable.
2447 &define_variable ($xname . '_LDFLAGS', '');
2450 # Determine program to use for link.
2452 if (&variable_defined ($xname . '_LINK'))
2454 $xlink = $xname . '_LINK';
2458 $xlink = $linker ? $linker : 'LINK';
2461 # If the resulting program lies into a subdirectory,
2462 # make sure this directory will exist.
2463 my $dirstamp = &require_build_directory_maybe ($one_file);
2465 # Don't add $(EXEEXT) if user already did.
2466 my $extension = (($seen_exeext && $one_file !~ /\$\(EXEEXT\)$/)
2470 $output_rules .= &file_contents ('program',
2471 ('PROGRAM' => $one_file,
2472 'XPROGRAM' => $xname,
2474 'DIRSTAMP' => $dirstamp,
2475 'EXEEXT' => $extension));
2478 if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD'))
2485 foreach my $one_file (@proglist)
2487 my $xname = &canonicalize ($one_file);
2489 if (&variable_defined ($xname . '_LDADD'))
2491 &check_libobjs_sources ($xname, $xname . '_LDADD');
2493 elsif (&variable_defined ('LDADD'))
2495 &check_libobjs_sources ($xname, 'LDADD');
2502 # handle_libraries ()
2503 # -------------------
2505 sub handle_libraries
2507 my @liblist = &am_install_var ('libs', 'LIBRARIES',
2508 'lib', 'pkglib', 'noinst', 'check');
2509 return if ! @liblist;
2511 my %valid = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2513 if (! defined $configure_vars{'RANLIB'})
2515 foreach my $key (keys %valid)
2517 if (&variable_defined ($key . '_LIBRARIES'))
2519 &am_line_error ($key . '_LIBRARIES', "library used but `RANLIB' not defined in `$configure_ac'");
2520 # Only get this error once. If this is ever printed,
2522 $configure_vars{'RANLIB'} = 'BUG';
2528 my $seen_libobjs = 0;
2529 foreach my $onelib (@liblist)
2531 # Check that the library fits the standard naming convention.
2532 if (basename ($onelib) !~ /^lib.*\.a/)
2534 # FIXME should put line number here. That means mapping
2535 # from library name back to variable name.
2536 &am_error ("`$onelib' is not a standard library name");
2539 my $obj = &get_object_extension ($onelib);
2541 # Canonicalize names and check for misspellings.
2542 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2543 '_OBJECTS', '_DEPENDENCIES',
2546 if (! &variable_defined ($xlib . '_AR'))
2548 &define_variable ($xlib . '_AR', '$(AR) cru');
2551 if (&variable_defined ($xlib . '_LIBADD'))
2553 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2560 # Generate support for conditional object inclusion in
2562 &define_variable ($xlib . "_LIBADD", '');
2565 if (&variable_defined ($xlib . '_LDADD'))
2567 &am_line_error ($xlib . '_LDADD',
2568 "use `" . $xlib . "_LIBADD', not `"
2569 . $xlib . "_LDADD'");
2572 # Make sure we at look at this.
2573 &examine_variable ($xlib . '_DEPENDENCIES');
2575 &handle_source_transform ($xlib, $onelib, $obj);
2577 # If the resulting library lies into a subdirectory,
2578 # make sure this directory will exist.
2579 my $dirstamp = &require_build_directory_maybe ($onelib);
2581 $output_rules .= &file_contents ('library',
2582 ('LIBRARY' => $onelib,
2583 'XLIBRARY' => $xlib,
2584 'DIRSTAMP' => $dirstamp));
2589 foreach my $onelib (@liblist)
2591 my $xlib = &canonicalize ($onelib);
2592 if (&variable_defined ($xlib . '_LIBADD'))
2594 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2601 # handle_ltlibraries ()
2602 # ---------------------
2603 # Handle shared libraries.
2604 sub handle_ltlibraries
2606 my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2607 'noinst', 'lib', 'pkglib', 'check');
2608 return if ! @liblist;
2611 my %valid = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2614 foreach my $key (keys %valid)
2616 if (&variable_defined ($key . '_LTLIBRARIES'))
2620 &am_line_error ($key . '_LTLIBRARIES', "library used but `LIBTOOL' not defined in `$configure_ac'");
2621 # Only get this error once. If this is ever printed,
2623 $configure_vars{'LIBTOOL'} = 'BUG';
2627 # Get the installation directory of each library.
2628 for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
2632 &am_error ("`$_' is already going to be installed in `$instdirs{$_}'");
2636 $instdirs{$_} = $key;
2642 my $seen_libobjs = 0;
2643 foreach my $onelib (@liblist)
2645 my $obj = &get_object_extension ($onelib);
2647 # Canonicalize names and check for misspellings.
2648 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2649 '_SOURCES', '_OBJECTS',
2652 if (! &variable_defined ($xlib . '_LDFLAGS'))
2654 # Define the lib_LDFLAGS variable.
2655 &define_variable ($xlib . '_LDFLAGS', '');
2658 # Check that the library fits the standard naming convention.
2659 my $libname_rx = "^lib.*\.la";
2660 if ((&variable_defined ($xlib . '_LDFLAGS')
2661 && grep (/-module/, &variable_value_as_list ($xlib . '_LDFLAGS',
2663 || (&variable_defined ('LDFLAGS')
2664 && grep (/-module/, &variable_value_as_list ('LDFLAGS',
2667 # Relax name checking for libtool modules.
2668 $libname_rx = "\.la";
2670 if (basename ($onelib) !~ /$libname_rx$/)
2672 # FIXME this should only be a warning for foreign packages
2673 # FIXME should put line number here. That means mapping
2674 # from library name back to variable name.
2675 &am_error ("`$onelib' is not a standard libtool library name");
2678 if (&variable_defined ($xlib . '_LIBADD'))
2680 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2687 # Generate support for conditional object inclusion in
2689 &define_variable ($xlib . "_LIBADD", '');
2692 if (&variable_defined ($xlib . '_LDADD'))
2694 &am_line_error ($xlib . '_LDADD',
2695 "use `" . $xlib . "_LIBADD', not `"
2696 . $xlib . "_LDADD'");
2699 # Make sure we at look at this.
2700 &examine_variable ($xlib . '_DEPENDENCIES');
2702 my $linker = &handle_source_transform ($xlib, $onelib, $obj);
2704 # Determine program to use for link.
2706 if (&variable_defined ($xlib . '_LINK'))
2708 $xlink = $xlib . '_LINK';
2712 $xlink = $linker ? $linker : 'LINK';
2716 if ($instdirs{$onelib} eq 'EXTRA'
2717 || $instdirs{$onelib} eq 'noinst'
2718 || $instdirs{$onelib} eq 'check')
2720 # It's an EXTRA_ library, so we can't specify -rpath,
2721 # because we don't know where the library will end up.
2722 # The user probably knows, but generally speaking automake
2723 # doesn't -- and in fact configure could decide
2724 # dynamically between two different locations.
2729 $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
2732 # If the resulting library lies into a subdirectory,
2733 # make sure this directory will exist.
2734 my $dirstamp = &require_build_directory_maybe ($onelib);
2736 $output_rules .= &file_contents ('ltlibrary',
2737 ('LTLIBRARY' => $onelib,
2738 'XLTLIBRARY' => $xlib,
2741 'DIRSTAMP' => $dirstamp));
2746 foreach my $onelib (@liblist)
2748 my $xlib = &canonicalize ($onelib);
2749 if (&variable_defined ($xlib . '_LIBADD'))
2751 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2757 # See if any _SOURCES variable were misspelled. Also, make sure that
2758 # EXTRA_ variables don't contain configure substitutions.
2761 foreach my $varname (keys %var_value)
2763 foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
2766 if ($varname =~ /$primary$/ && ! $content_seen{$varname})
2768 &am_line_error ($varname,
2769 "invalid unused variable name: `$varname'");
2778 # NOTE we no longer automatically clean SCRIPTS, because it is
2779 # useful to sometimes distribute scripts verbatim. This happens
2780 # eg in Automake itself.
2781 &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2782 'bin', 'sbin', 'libexec', 'pkgdata',
2785 my $scripts_installed = 0;
2786 # Set $scripts_installed if appropriate. Make sure we only find
2787 # scripts which are actually installed -- this is why we can't
2788 # simply use the return value of am_install_var.
2789 my %valid = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
2790 'libexec', 'pkgdata',
2792 foreach my $key (keys %valid)
2794 if ($key ne 'noinst'
2796 && &variable_defined ($key . '_SCRIPTS'))
2798 $scripts_installed = 1;
2799 # push (@check_tests, 'check-' . $key . 'SCRIPTS');
2805 # ($OUTFILE, $VFILE, @CLEAN_FILES)
2806 # &scan_texinfo_file ($FILENAME)
2807 # ------------------------------
2808 # $OUTFILE is the name of the info file produced by $FILENAME.
2809 # $VFILE is the name of the version.texi file used (empty if none).
2810 # @CLEAN_FILES is the list of by products (indexes etc.)
2811 sub scan_texinfo_file
2813 my ($filename) = @_;
2815 # These are always created, no matter whether indexes are used or not.
2816 my @clean_suffixes = ('aux', 'dvi', 'log', 'ps', 'toc',
2817 # grep new.*index texinfo.tex
2818 'cp', 'fn', 'ky', 'vr', 'tp', 'pg');
2820 # There are predefined indexes which don't follow the regular rules.
2821 my %predefined_index =
2824 'c' => 'cps', 'f' => 'fns', 'k' => 'kys',
2825 'v' => 'vrs', 't' => 'tps', 'p' => 'pgs'
2828 # There are commands which include a hidden index command.
2832 'fn' => 'fns', 'un' => 'fns',
2833 'typefn' => 'fns', 'typefun' => 'fns',
2834 'mac' => 'fns', 'spec' => 'fns',
2835 'op' => 'fns', 'typeop' => 'fns',
2836 'method' => 'fns', 'typemethod' => 'fns',
2838 'vr' => 'vrs', 'var' => 'vrs',
2839 'typevr' => 'vrs', 'typevar' => 'vrs',
2842 'ivar' => 'vrs', 'typeivar' => 'vrs',
2847 # Indexes stored into another one. In this case, the *.??s file
2849 my @syncodeindexes = ();
2851 my $texi = new IO::File ("< $filename");
2854 &am_error ("couldn't open `$filename': $!");
2857 print "$me: reading $filename\n" if $verbose;
2859 my ($outfile, $vfile);
2860 while ($_ = $texi->getline)
2862 if (/^\@setfilename +(\S+)/)
2865 if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
2867 &am_file_error ($filename, "$.: ",
2868 "output `$outfile' has unrecognized extension");
2872 # A "version.texi" file is actually any file whose name
2873 # matches "vers*.texi".
2874 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2879 # Try to find what are the indexes which are used.
2881 # Creating a new category of index.
2882 elsif (/^\@def(code)?index (\w+)/)
2884 push @clean_suffixes, $2;
2887 # Storing in a predefined index.
2888 elsif (/^\@([cfkvtp])index /)
2890 push @clean_suffixes, $predefined_index{$1};
2892 elsif (/^\@def(\w+) /)
2894 push @clean_suffixes, $hidden_index{$1}
2895 if defined $hidden_index{$1};
2898 # Merging an index into an another.
2899 elsif (/^\@syn(code)?index (\w+) (\w+)/)
2901 push @syncodeindexes, "$2s";
2902 push @clean_suffixes, "$3s";
2910 &am_error ("`$filename' missing \@setfilename");
2914 my $infobase = basename ($filename);
2915 $infobase =~ s/\.te?xi(nfo)?$//;
2916 # FIXME: I don't understand why, but I can't use "$infobase.$_" => 1.
2917 my %clean_files = map { "$infobase" . ".$_" => 1 } @clean_suffixes;
2918 grep { delete $clean_files{"$infobase.$_"} } @syncodeindexes;
2919 return ($outfile, $vfile, (sort keys %clean_files));
2923 # ($DO-SOMETHING, $TEXICLEANS)
2924 # handle_texinfo_helper ()
2926 # Handle all Texinfo source; helper for handle_texinfo
2927 sub handle_texinfo_helper
2929 &am_line_error ('TEXINFOS',
2930 "`TEXINFOS' is an anachronism; use `info_TEXINFOS'")
2931 if &variable_defined ('TEXINFOS');
2932 return (0, '') if (! &variable_defined ('info_TEXINFOS')
2933 && ! &variable_defined ('html_TEXINFOS'));
2935 if (&variable_defined ('html_TEXINFOS'))
2937 &am_line_error ('html_TEXINFOS',
2938 "HTML generation not yet supported");
2942 my @texis = &variable_value_as_list ('info_TEXINFOS', 'all');
2944 my (@info_deps_list, @dvis_list, @texi_deps);
2951 foreach my $info_cursor (@texis)
2953 my $infobase = $info_cursor;
2954 $infobase =~ s/\.(txi|texinfo|texi)$//;
2956 if ($infobase eq $info_cursor)
2958 # FIXME: report line number.
2959 &am_error ("texinfo file `$info_cursor' has unrecognized extension");
2962 $texi_suffixes{$1} = 1;
2964 # If 'version.texi' is referenced by input file, then include
2965 # automatic versioning capability.
2966 my ($out_file, $vtexi, @clean_files) =
2967 &scan_texinfo_file ("$relative_dir/$info_cursor")
2969 push (@texi_cleans, @clean_files);
2973 &am_error ("`$vtexi', included in `$info_cursor', also included in `$versions{$vtexi}'")
2974 if (defined $versions{$vtexi});
2975 $versions{$vtexi} = $info_cursor;
2977 # We number the stamp-vti files. This is doable since the
2978 # actual names don't matter much. We only number starting
2979 # with the second one, so that the common case looks nice.
2980 my $vti = ($done ? $done : 'vti');
2983 # This is ugly, but it is our historical practice.
2984 if ($config_aux_dir_set_in_configure_in)
2986 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2991 &require_file_with_line ('info_TEXINFOS', $FOREIGN,
2996 if ($config_aux_dir_set_in_configure_in)
2998 $conf_dir = $config_aux_dir;
2999 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
3003 $conf_dir = '$(srcdir)/';
3005 $output_rules .= &file_contents ('texi-vers',
3006 ('TEXI' => $info_cursor,
3009 'MDDIR' => $conf_dir));
3012 # If user specified file_TEXINFOS, then use that as explicit
3015 push (@texi_deps, $info_cursor);
3016 # Prefix with $(srcdir) because some version of make won't
3017 # work if the target has it and the dependency doesn't.
3018 push (@texi_deps, '$(srcdir)/' . $vtexi) if $vtexi;
3020 my $canonical = &canonicalize ($infobase);
3021 if (&variable_defined ($canonical . "_TEXINFOS"))
3023 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
3024 &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
3027 $output_rules .= ("\n" . $out_file . ": "
3028 . join (' ', @texi_deps)
3029 . "\n" . $infobase . ".dvi: "
3030 . join (' ', @texi_deps)
3033 push (@info_deps_list, $out_file);
3034 push (@dvis_list, $infobase . '.dvi');
3037 # Handle location of texinfo.tex.
3038 my $need_texi_file = 0;
3042 $texinfodir = '$(top_srcdir)/../texinfo';
3043 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3045 elsif ($config_aux_dir_set_in_configure_in)
3047 $texinfodir = $config_aux_dir;
3048 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3049 $need_texi_file = 2; # so that we require_conf_file later
3051 elsif (&variable_defined ('TEXINFO_TEX'))
3053 # The user defined TEXINFO_TEX so assume he knows what he is
3055 $texinfodir = ('$(srcdir)/'
3056 . dirname (&variable_value ('TEXINFO_TEX')));
3060 $texinfodir = '$(srcdir)';
3061 $need_texi_file = 1;
3064 foreach my $txsfx (sort keys %texi_suffixes)
3066 $output_rules .= &file_contents ('texibuild',
3067 ('TEXINFODIR' => $texinfodir,
3068 'SUFFIX' => $txsfx));
3072 my $texiclean = &pretty_print_internal ("", "\t ", @texi_cleans);
3074 push (@dist_targets, 'dist-info');
3076 if (! defined $options{'no-installinfo'})
3078 # Make sure documentation is made and installed first. Use
3079 # $(INFO_DEPS), not 'info', because otherwise recursive makes
3080 # get run twice during "make all".
3081 unshift (@all, '$(INFO_DEPS)');
3084 &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
3085 &define_variable ("DVIS", join (' ', @dvis_list));
3086 # This next isn't strictly needed now -- the places that look here
3087 # could easily be changed to look in info_TEXINFOS. But this is
3088 # probably better, in case noinst_TEXINFOS is ever supported.
3089 &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
3091 # Do some error checking. Note that this file is not required
3092 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3094 if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
3096 if ($need_texi_file > 1)
3098 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
3103 &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
3107 return (1, $texiclean);
3112 # Handle all Texinfo source.
3115 my ($do_something, $texiclean) = handle_texinfo_helper ();
3116 $output_rules .= &file_contents ('texinfos',
3117 ('TEXICLEAN' => $texiclean,
3118 'LOCAL-TEXIS' => $do_something));
3121 # Handle any man pages.
3122 sub handle_man_pages
3124 &am_line_error ('MANS', "`MANS' is an anachronism; use `man_MANS'")
3125 if &variable_defined ('MANS');
3127 # Find all the sections in use. We do this by first looking for
3128 # "standard" sections, and then looking for any additional
3129 # sections used in man_MANS.
3130 my (%sections, %vlist);
3131 # We handle nodist_ for uniformity. man pages aren't distributed
3132 # by default so it isn't actually very important.
3133 foreach my $pfx ('', 'dist_', 'nodist_')
3135 # Add more sections as needed.
3136 foreach my $section ('0'..'9', 'n', 'l')
3138 if (&variable_defined ($pfx . 'man' . $section . '_MANS'))
3140 $sections{$section} = 1;
3141 $vlist{'$(' . $pfx . 'man' . $section . '_MANS)'} = 1;
3143 &push_dist_common ('$(' . $pfx . 'man' . $section . '_MANS)')
3148 if (&variable_defined ($pfx . 'man_MANS'))
3150 $vlist{'$(' . $pfx . 'man_MANS)'} = 1;
3151 foreach (&variable_value_as_list ($pfx . 'man_MANS', 'all'))
3153 # A page like `foo.1c' goes into man1dir.
3154 if (/\.([0-9a-z])([a-z]*)$/)
3160 &push_dist_common ('$(' . $pfx . 'man_MANS)')
3165 return unless %sections;
3167 # Now for each section, generate an install and unintall rule.
3168 # Sort sections so output is deterministic.
3169 foreach my $section (sort keys %sections)
3171 $output_rules .= &file_contents ('mans', ('SECTION' => $section));
3174 $output_vars .= &file_contents ('mans-vars',
3175 ('MANS' => join (' ', sort keys %vlist)));
3177 if (! defined $options{'no-installman'})
3179 push (@all, '$(MANS)');
3183 # Handle DATA variables.
3186 &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3187 'data', 'sysconf', 'sharedstate', 'localstate',
3188 'pkgdata', 'noinst', 'check');
3195 if (&variable_defined ('SUBDIRS'))
3197 $output_rules .= ("tags-recursive:\n"
3198 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3199 # Never fail here if a subdir fails; it
3201 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3202 . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3204 push (@tag_deps, 'tags-recursive');
3205 &depend ('.PHONY', 'tags-recursive');
3208 if (&saw_sources_p (1)
3209 || &variable_defined ('ETAGS_ARGS')
3213 foreach my $one_hdr (@config_headers)
3215 if ($relative_dir eq dirname ($one_hdr))
3217 # The config header is in this directory. So require it.
3218 $config .= ' ' if $config;
3219 $config .= basename ($one_hdr);
3222 $output_rules .= &file_contents ('tags',
3223 ('CONFIG' => $config,
3224 'DIRS' => join (' ', @tag_deps)));
3225 &examine_variable ('TAGS_DEPENDENCIES');
3227 elsif (&variable_defined ('TAGS_DEPENDENCIES'))
3229 &am_line_error ('TAGS_DEPENDENCIES',
3230 "doesn't make sense to define `TAGS_DEPENDENCIES' without sources or `ETAGS_ARGS'");
3234 # Every Makefile must define some sort of TAGS rule.
3235 # Otherwise, it would be possible for a top-level "make TAGS"
3236 # to fail because some subdirectory failed.
3237 $output_rules .= "tags: TAGS\nTAGS:\n\n";
3241 # Handle multilib support.
3244 if ($seen_multilib && $relative_dir eq '.')
3246 $output_rules .= &file_contents ('multilib');
3252 # &for_dist_common ($A, $B)
3253 # -------------------------
3254 # Subroutine for &handle_dist: sort files to dist.
3256 # We put README first because it then becomes easier to make a
3257 # Usenet-compliant shar file (in these, README must be first).
3259 # FIXME: do more ordering of files here.
3272 # handle_dist ($MAKEFILE)
3273 # -----------------------
3274 # Handle 'dist' target.
3277 my ($makefile) = @_;
3279 # `make dist' isn't used in a Cygnus-style tree.
3280 # Omit the rules so that people don't try to use them.
3281 return if $cygnus_mode;
3283 # Look for common files that should be included in distribution.
3284 # If the aux dir is set, and it does not have a Makefile.am, then
3285 # we check for these files there as well.
3288 if ($relative_dir eq '.'
3289 && $config_aux_dir_set_in_configure_in)
3291 ($auxdir = $config_aux_dir) =~ s,^\$\(top_srcdir\)/,,;
3292 if (! &is_make_dir ($auxdir))
3297 foreach my $cfile (@common_files)
3299 if (-f ($relative_dir . "/" . $cfile))
3301 &push_dist_common ($cfile);
3304 # Don't use `elsif' here because a file might meaningfully
3305 # appear in both directories.
3306 if ($check_aux && -f ($auxdir . '/' . $cfile))
3308 &push_dist_common ($auxdir . '/' . $cfile);
3312 # We might copy elements from $configure_dist_common to
3313 # %dist_common if we think we need to. If the file appears in our
3314 # directory, we would have discovered it already, so we don't
3315 # check that. But if the file is in a subdir without a Makefile,
3316 # we want to distribute it here if we are doing `.'. Ugly!
3317 if ($relative_dir eq '.')
3319 foreach my $file (split (' ' , $configure_dist_common))
3321 if (! &is_make_dir (dirname ($file)))
3323 &push_dist_common ($file);
3330 # Files to distributed. Don't use &variable_value_as_list
3331 # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3332 check_variable_defined_unconditionally ('DIST_COMMON');
3333 my @dist_common = split (' ', variable_value ('DIST_COMMON', 'TRUE'));
3334 @dist_common = uniq (sort for_dist_common (@dist_common));
3335 pretty_print ('DIST_COMMON = ', "\t", @dist_common);
3337 # Now that we've processed DIST_COMMON, disallow further attempts
3339 $handle_dist_run = 1;
3341 # Scan EXTRA_DIST to see if we need to distribute anything from a
3342 # subdir. If so, add it to the list. I didn't want to do this
3343 # originally, but there were so many requests that I finally
3345 if (&variable_defined ('EXTRA_DIST'))
3347 # FIXME: This should be fixed to work with conditionals. That
3348 # will require only making the entries in %dist_dirs under the
3349 # appropriate condition. This is meaningful if the nature of
3350 # the distribution should depend upon the configure options
3352 foreach (&variable_value_as_list ('EXTRA_DIST', ''))
3355 next unless s,/+[^/]+$,,;
3361 # We have to check DIST_COMMON for extra directories in case the
3362 # user put a source used in AC_OUTPUT into a subdir.
3363 foreach (&variable_value_as_list ('DIST_COMMON', 'all'))
3366 next unless s,/+[^/]+$,,;
3371 # Rule to check whether a distribution is viable.
3372 my %transform = ('DISTCHECK-HOOK' => &target_defined ('distcheck-hook'),
3373 'GETTEXT' => $seen_gettext);
3375 # Prepend $(distdir) to each directory given.
3376 my %rewritten = map { '$(distdir)/' . "$_" => 1 } keys %dist_dirs;
3377 $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);
3379 # If we have SUBDIRS, create all dist subdirectories and do
3381 if (&variable_defined ('SUBDIRS'))
3383 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3384 # to all possible directories, and use it. If DIST_SUBDIRS is
3385 # defined, just use it.
3386 my $dist_subdir_name;
3387 # Note that we check DIST_SUBDIRS first on purpose. At least
3388 # one project uses so many conditional subdirectories that
3389 # calling variable_conditionally_defined on SUBDIRS will cause
3390 # automake to grow to 150Mb. Sigh.
3391 if (&variable_defined ('DIST_SUBDIRS')
3392 || variable_conditionally_defined ('SUBDIRS'))
3394 $dist_subdir_name = 'DIST_SUBDIRS';
3395 if (! &variable_defined ('DIST_SUBDIRS'))
3397 &define_pretty_variable
3398 ('DIST_SUBDIRS', '',
3399 uniq (&variable_value_as_list ('SUBDIRS', 'all')));
3404 $dist_subdir_name = 'SUBDIRS';
3405 # We always define this because that is what `distclean'
3407 &define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
3410 $transform{'DIST_SUBDIR_NAME'} = $dist_subdir_name;
3413 # If the target `dist-hook' exists, make sure it is run. This
3414 # allows users to do random weird things to the distribution
3415 # before it is packaged up.
3416 push (@dist_targets, 'dist-hook')
3417 if &target_defined ('dist-hook');
3418 $transform{'DIST-TARGETS'} = join(' ', @dist_targets);
3420 # Defining $(DISTDIR).
3421 $transform{'DISTDIR'} = !&variable_defined('distdir');
3422 $transform{'TOP_DISTDIR'} = backname ($relative_dir);
3424 $output_rules .= &file_contents ('distdir', %transform);
3428 # Handle subdirectories.
3432 unless &variable_defined ('SUBDIRS');
3434 # Make sure each directory mentioned in SUBDIRS actually exists.
3435 foreach my $dir (&variable_value_as_list ('SUBDIRS', 'all'))
3437 # Skip directories substituted by configure.
3438 next if $dir =~ /^\@.*\@$/;
3440 if (! -d $am_relative_dir . '/' . $dir)
3442 &am_line_error ('SUBDIRS',
3443 "required directory $am_relative_dir/$dir does not exist");
3447 &am_line_error ('SUBDIRS', "directory should not contain `/'")
3451 $output_rules .= &file_contents ('subdirs');
3452 variable_pretty_output ('RECURSIVE_TARGETS', 'TRUE');
3456 # ($REGEN, @DEPENDENCIES)
3459 # If aclocal.m4 creation is automated, return the list of its dependencies.
3462 my $regen_aclocal = 0;
3465 unless $relative_dir eq '.';
3467 &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3468 &examine_variable ('CONFIGURE_DEPENDENCIES');
3470 if (-f 'aclocal.m4')
3472 &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3473 &push_dist_common ('aclocal.m4');
3475 my $aclocal = new IO::File ("< aclocal.m4");
3478 my $line = $aclocal->getline;
3481 if ($line =~ 'generated automatically by aclocal')
3490 if (-f 'acinclude.m4')
3493 push @ac_deps, 'acinclude.m4';
3496 if (&variable_defined ('ACLOCAL_M4_SOURCES'))
3498 push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3500 elsif (&variable_defined ('ACLOCAL_AMFLAGS'))
3502 # Scan all -I directories for m4 files. These are our
3504 my $examine_next = 0;
3505 foreach my $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
3510 if ($amdir !~ /^\// && -d $amdir)
3512 foreach my $ac_dep (&my_glob ($amdir . '/*.m4'))
3514 $ac_dep =~ s/^\.\/+//;
3515 push (@ac_deps, $ac_dep)
3516 unless $ac_dep eq "aclocal.m4"
3517 || $ac_dep eq "acinclude.m4";
3521 elsif ($amdir eq '-I')
3528 # Note that it might be possible that aclocal.m4 doesn't exist but
3529 # should be auto-generated. This case probably isn't very
3532 return ($regen_aclocal, @ac_deps);
3535 # Rewrite a list of input files into a form suitable to put on a
3536 # dependency list. The idea is that if an input file has a directory
3537 # part the same as the current directory, then the directory part is
3538 # simply removed. But if the directory part is different, then
3539 # $(top_srcdir) is prepended. Among other things, this is used to
3540 # generate the dependency list for the output files generated by
3541 # AC_OUTPUT. Consider what the dependencies should look like in this
3543 # AC_OUTPUT(src/out:src/in1:lib/in2)
3544 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3545 # If 0 then files that require this addition will simply be ignored.
3546 sub rewrite_inputs_into_dependencies
3548 my ($add_srcdir, @inputs) = @_;
3551 foreach my $single (@inputs)
3553 if (dirname ($single) eq $relative_dir)
3555 push (@newinputs, basename ($single));
3559 push (@newinputs, '$(top_srcdir)/' . $single);
3566 # Handle remaking and configure stuff.
3567 # We need the name of the input file, to do proper remaking rules.
3568 sub handle_configure
3570 my ($local, $input, @secondary_inputs) = @_;
3572 my $input_base = basename ($input);
3573 my $local_base = basename ($local);
3575 my $amfile = $input_base . '.am';
3576 # We know we can always add '.in' because it really should be an
3577 # error if the .in was missing originally.
3578 my $infile = '$(srcdir)/' . $input_base . '.in';
3579 my $colon_infile = '';
3580 if ($local ne $input || @secondary_inputs)
3582 $colon_infile = ':' . $input . '.in';
3584 $colon_infile .= ':' . join (':', @secondary_inputs)
3585 if @secondary_inputs;
3587 my @rewritten = &rewrite_inputs_into_dependencies (1, @secondary_inputs);
3589 my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4 ();
3592 &file_contents ('configure',
3596 => join (' ', @rewritten),
3598 => ((($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3603 => join (' ', @include_stack),
3607 => $cygnus_mode ? 'cygnus' : $strictness_name,
3609 => $cmdline_use_dependencies ? '' : ' --ignore-deps',
3610 'MAKEFILE-AM-SOURCES'
3611 => "$input$colon_infile",
3613 => $regen_aclocal_m4,
3615 => join (' ', @aclocal_m4_deps)));
3617 if ($relative_dir eq '.')
3619 &push_dist_common ('acconfig.h')
3623 # If we have a configure header, require it.
3624 my @local_fullnames = @config_fullnames;
3625 my @local_names = @config_names;
3627 my $distclean_config = '';
3628 foreach my $one_hdr (@config_headers)
3630 my $one_fullname = shift (@local_fullnames);
3631 my $one_name = shift (@local_names);
3633 my $header_dir = dirname ($one_name);
3635 # If the header is in the current directory we want to build
3636 # the header here. Otherwise, if we're at the topmost
3637 # directory and the header's directory doesn't have a
3638 # Makefile, then we also want to build the header.
3639 if ($relative_dir eq $header_dir
3640 || ($relative_dir eq '.' && ! &is_make_dir ($header_dir)))
3642 my ($cn_sans_dir, $stamp_dir);
3643 if ($relative_dir eq $header_dir)
3645 $cn_sans_dir = basename ($one_name);
3650 $cn_sans_dir = $one_name;
3651 if ($header_dir eq '.')
3657 $stamp_dir = $header_dir . '/';
3661 # Compute relative path from directory holding output
3662 # header to directory holding input header. FIXME:
3663 # doesn't handle case where we have multiple inputs.
3665 if (dirname ($one_hdr) eq $relative_dir)
3667 $ch_sans_dir = basename ($one_hdr);
3671 $ch_sans_dir = backname ($relative_dir) . '/' . $one_hdr;
3674 &require_file_with_conf_line ($config_header_line,
3675 $FOREIGN, $ch_sans_dir);
3677 # Header defined and in this directory.
3679 if (-f $one_name . '.top')
3681 push (@files, "${cn_sans_dir}.top");
3683 if (-f $one_name . '.bot')
3685 push (@files, "${cn_sans_dir}.bot");
3688 &push_dist_common (@files);
3690 # For now, acconfig.h can only appear in the top srcdir.
3691 if (-f 'acconfig.h')
3693 push (@files, '$(top_srcdir)/acconfig.h');
3696 my $stamp_name = 'stamp-h';
3697 $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3699 my $out_dir = dirname ($ch_sans_dir);
3702 &file_contents ('remake-hdr',
3703 ('FILES' => join (' ', @files),
3704 'CONFIG_HEADER' => $cn_sans_dir,
3705 'CONFIG_HEADER_IN' => $ch_sans_dir,
3706 'CONFIG_HEADER_FULL' => $one_fullname,
3707 'STAMP' => "$stamp_dir$stamp_name",
3708 'SRC_STAMP' => "$out_dir/$stamp_name"));
3710 &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3711 &require_file_with_conf_line ($config_header_line, $FOREIGN,
3712 "${out_dir}/${stamp_name}.in");
3714 $distclean_config .= ' ' if $distclean_config;
3715 $distclean_config .= $cn_sans_dir;
3719 if ($distclean_config)
3721 $output_rules .= &file_contents ('clean-hdr',
3722 ('FILES' => $distclean_config));
3725 # Set location of mkinstalldirs.
3726 &define_variable ('mkinstalldirs',
3727 ('$(SHELL) ' . $config_aux_dir . '/mkinstalldirs'));
3729 &am_line_error ('CONFIG_HEADER',
3730 "`CONFIG_HEADER' is an anachronism; now determined from `$configure_ac'")
3731 if &variable_defined ('CONFIG_HEADER');
3733 my $config_header = '';
3734 foreach my $one_name (@config_names)
3736 # Generate CONFIG_HEADER define.
3738 if ($relative_dir eq dirname ($one_name))
3740 $one_hdr = basename ($one_name);
3744 $one_hdr = "\$(top_builddir)/${one_name}";
3747 $config_header .= ' ' if $config_header;
3748 $config_header .= $one_hdr;
3752 &define_variable ("CONFIG_HEADER", $config_header);
3755 # Now look for other files in this directory which must be remade
3756 # by config.status, and generate rules for them.
3757 my @actual_other_files = ();
3758 foreach my $lfile (@other_input_files)
3761 my (@inputs, @rewritten_inputs);
3762 my ($need_rewritten);
3763 if ($lfile =~ /^([^:]*):(.*)$/)
3765 # This is the ":" syntax of AC_OUTPUT.
3767 $local = basename ($file);
3768 @inputs = split (':', $2);
3769 @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3770 $need_rewritten = 1;
3776 $local = basename ($file);
3777 @inputs = ($file . '.in');
3779 &rewrite_inputs_into_dependencies (1, @inputs);
3780 $need_rewritten = 0;
3783 # Make sure the dist directory for each input file is created.
3784 # We only have to do this at the topmost level though. This
3785 # is a bit ugly but it easier than spreading out the logic,
3786 # especially in cases like AC_OUTPUT(foo/out:bar/in), where
3787 # there is no Makefile in bar/.
3788 if ($relative_dir eq '.')
3792 $dist_dirs{dirname ($_)} = 1;
3796 # We skip any automake input files, as they are handled
3797 # elsewhere. We also skip files that aren't in this
3798 # directory. However, if the file's directory does not have a
3799 # Makefile, and we are currently doing `.', then we create a
3800 # rule to rebuild the file in the subdir.
3801 next if -f $file . '.am';
3802 my $fd = dirname ($file);
3803 if ($fd ne $relative_dir)
3805 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
3815 # Some users have been tempted to put `stamp-h' in the
3816 # AC_OUTPUT line. This won't do the right thing, so we
3817 # explicitly fail here.
3818 if ($local eq 'stamp-h')
3820 # FIXME: allow real filename.
3821 &am_conf_error ($configure_ac, $ac_output_line,
3822 'stamp-h should not appear in AC_OUTPUT');
3826 $output_rules .= ($local . ': '
3827 . '$(top_builddir)/config.status '
3828 . join (' ', @rewritten_inputs) . "\n"
3830 . 'cd $(top_builddir) && CONFIG_FILES='
3831 . ($relative_dir eq '.' ? '' : '$(subdir)/')
3832 . '$@' . ($need_rewritten
3833 ? (':' . join (':', @inputs))
3835 . ' CONFIG_HEADERS= CONFIG_LINKS= $(SHELL) ./config.status'
3837 push (@actual_other_files, $local);
3839 # Require all input files.
3840 &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3841 &rewrite_inputs_into_dependencies (0, @inputs));
3844 # These files get removed by "make clean".
3845 &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3851 my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3852 'oldinclude', 'pkginclude',
3856 next unless /\.(.*)$/;
3857 &saw_extension ($1);
3863 return if ! $seen_gettext || $relative_dir ne '.';
3865 if (! &variable_defined ('SUBDIRS'))
3868 ("AM_GNU_GETTEXT used but SUBDIRS not defined");
3872 my @subdirs = &variable_value_as_list ('SUBDIRS', 'all');
3873 &am_line_error ('SUBDIRS',
3874 "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
3875 if ! grep ('po', @subdirs);
3876 &am_line_error ('SUBDIRS',
3877 "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
3878 if ! grep ('intl', @subdirs);
3880 &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3882 # Ensure that each language in ALL_LINGUAS has a .po file, and
3883 # each po file is mentioned in ALL_LINGUAS.
3886 my %linguas = map { $_ => 1 } split (' ', $all_linguas);
3893 &am_line_error ($all_linguas_line,
3894 ("po/$_.po exists but `$_' not in `ALL_LINGUAS'"))
3898 foreach (keys %linguas)
3900 &am_line_error ($all_linguas_line,
3901 "$_ in `ALL_LINGUAS' but po/$_.po does not exist")
3907 &am_error ("AM_GNU_GETTEXT in `$configure_ac' but `ALL_LINGUAS' not defined");
3911 # Handle footer elements.
3914 # NOTE don't use define_pretty_variable here, because
3915 # $contents{...} is already defined.
3916 $output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n\n"
3917 if variable_value ('SOURCES');
3920 &am_line_error ('.SUFFIXES',
3921 "use variable `SUFFIXES', not target `.SUFFIXES'")
3922 if target_defined ('.SUFFIXES');
3924 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3925 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
3926 # anything else, by sticking it right after the default: target.
3927 $output_header .= ".SUFFIXES:\n";
3928 if (@suffixes || &variable_defined ('SUFFIXES'))
3930 # Make sure suffixes has unique elements. Sort them to ensure
3931 # the output remains consistent. However, $(SUFFIXES) is
3932 # always at the start of the list, unsorted. This is done
3933 # because make will choose rules depending on the ordering of
3934 # suffixes, and this lets the user have some control. Push
3935 # actual suffixes, and not $(SUFFIXES). Some versions of make
3936 # do not like variable substitutions on the .SUFFIXES line.
3937 my @user_suffixes = (&variable_defined ('SUFFIXES')
3938 ? &variable_value_as_list ('SUFFIXES', '')
3941 my %suffixes = map { $_ => 1 } @suffixes;
3942 delete @suffixes{@user_suffixes};
3944 $output_header .= (".SUFFIXES: "
3945 . join (' ', @user_suffixes, sort keys %suffixes)
3949 $output_trailer .= file_contents ('footer');
3952 # Deal with installdirs target.
3953 sub handle_installdirs ()
3956 &file_contents ('install',
3958 => variable_value ('_am_installdirs') || ''));
3962 # Deal with all and all-am.
3965 my ($makefile) = @_;
3969 # Put this at the beginning for the sake of non-GNU makes. This
3970 # is still wrong if these makes can run parallel jobs. But it is
3972 unshift (@all, basename ($makefile));
3974 foreach my $one_name (@config_names)
3976 push (@all, basename ($one_name))
3977 if dirname ($one_name) eq $relative_dir;
3980 # Install `all' hooks.
3981 if (&target_defined ("all-local"))
3983 push (@all, "all-local");
3984 &depend ('.PHONY', "all-local");
3987 &pretty_print_rule ("all-am:", "\t\t", @all);
3988 &depend ('.PHONY', 'all-am', 'all');
3993 my @local_headers = ();
3994 push @local_headers, '$(BUILT_SOURCES)'
3995 if &variable_defined ('BUILT_SOURCES');
3996 foreach my $one_name (@config_names)
3998 push @local_headers, basename ($one_name)
3999 if dirname ($one_name) eq $relative_dir;
4004 # We need to make sure config.h is built before we recurse.
4005 # We also want to make sure that built sources are built
4006 # before any ordinary `all' targets are run. We can't do this
4007 # by changing the order of dependencies to the "all" because
4008 # that breaks when using parallel makes. Instead we handle
4009 # things explicitly.
4010 $output_all .= ("all: " . join (' ', @local_headers)
4012 . '$(MAKE) $(AM_MAKEFLAGS) '
4013 . (&variable_defined ('SUBDIRS')
4014 ? 'all-recursive' : 'all-am')
4019 $output_all .= "all: " . (&variable_defined ('SUBDIRS')
4020 ? 'all-recursive' : 'all-am') . "\n\n";
4025 # Handle check merge target specially.
4026 sub do_check_merge_target
4028 if (&target_defined ('check-local'))
4030 # User defined local form of target. So include it.
4031 push (@check_tests, 'check-local');
4032 &depend ('.PHONY', 'check-local');
4035 # In --cygnus mode, check doesn't depend on all.
4038 # Just run the local check rules.
4039 &pretty_print_rule ('check-am:', "\t\t", @check);
4043 # The check target must depend on the local equivalent of
4044 # `all', to ensure all the primary targets are built. Then it
4045 # must build the local check rules.
4046 $output_rules .= "check-am: all-am\n";
4047 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4051 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4055 &depend ('.PHONY', 'check', 'check-am');
4056 $output_rules .= ("check: "
4057 . (&variable_defined ('SUBDIRS')
4058 ? 'check-recursive' : 'check-am')
4062 # Handle all 'clean' targets.
4067 # Don't include `MAINTAINER'; it is handled specially below.
4068 foreach my $name ('MOSTLY', '', 'DIST')
4070 $transform{"${name}CLEAN"} = &variable_defined ("${name}CLEANFILES");
4073 # Built sources are automatically removed by maintainer-clean.
4074 push (@maintainer_clean_files, '$(BUILT_SOURCES)')
4075 if &variable_defined ('BUILT_SOURCES');
4076 push (@maintainer_clean_files, '$(MAINTAINERCLEANFILES)')
4077 if &variable_defined ('MAINTAINERCLEANFILES');
4079 $output_rules .= &file_contents ('clean',
4082 # Join with no space to avoid
4083 # spurious `test -z' success at
4085 => join ('', @maintainer_clean_files),
4087 # A space is required in the join here.
4088 => join (' ', @maintainer_clean_files)));
4092 # &depend ($CATEGORY, @DEPENDENDEES)
4093 # ----------------------------------
4094 # The target $CATEGORY depends on @DEPENDENDEES.
4097 my ($category, @dependendees) = @_;
4099 push (@{$dependencies{$category}}, @dependendees);
4104 # &target_cmp ($A, $B)
4105 # --------------------
4106 # Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
4119 # &handle_factored_dependencies ()
4120 # --------------------------------
4121 # Handle everything related to gathered targets.
4122 sub handle_factored_dependencies
4125 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4126 'uninstall-exec-local', 'uninstall-exec-hook')
4128 if (&target_defined ($utarg))
4131 $x =~ s/(data|exec)-//;
4132 &am_line_error ($utarg, "use `$x', not `$utarg'");
4136 if (&target_defined ('install-local'))
4138 &am_line_error ('install-local',
4139 "use `install-data-local' or `install-exec-local', "
4140 . "not `install-local'");
4143 if (!defined $options{'no-installinfo'}
4144 && &target_defined ('install-info-local'))
4146 &am_line_error ('install-info-local',
4147 "`install-info-local' target defined but "
4148 . "`no-installinfo' option not in use");
4151 # Install the -local hooks.
4152 foreach (keys %dependencies)
4154 # Hooks are installed on the -am targets.
4156 if (&target_defined ("$_-local"))
4158 depend ("$_-am", "$_-local");
4159 &depend ('.PHONY', "$_-local");
4163 # Install the -hook hooks.
4164 # FIXME: Why not be as liberal as we are with -local hooks?
4165 foreach ('install-exec', 'install-data')
4167 if (&target_defined ("$_-hook"))
4169 $actions{"$_-am"} .=
4170 ("\t\@\$(NORMAL_INSTALL)\n"
4171 . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
4175 # All the required targets are phony.
4176 depend ('.PHONY', keys %required_targets);
4178 # Actually output gathered targets.
4179 foreach (sort target_cmp keys %dependencies)
4181 # If there is nothing about this guy, skip it.
4183 unless (@{$dependencies{$_}}
4185 || $required_targets{$_});
4186 &pretty_print_rule ("$_:", "\t",
4187 uniq (sort @{$dependencies{$_}}));
4188 $output_rules .= $actions{$_}
4189 if defined $actions{$_};
4190 $output_rules .= "\n";
4195 # &handle_tests_dejagnu ()
4196 # ------------------------
4197 sub handle_tests_dejagnu
4199 push (@check_tests, 'check-DEJAGNU');
4201 # Only create site.exp rule if user hasn't already written one.
4203 file_contents ('dejagnu', ('SITE-EXP' => ! target_defined ('site.exp')));
4207 # Handle TESTS variable and other checks.
4210 if (defined $options{'dejagnu'})
4212 &handle_tests_dejagnu;
4216 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4219 "`$c' defined but `dejagnu' not in `AUTOMAKE_OPTIONS'")
4220 if &variable_defined ($c);
4224 if (&variable_defined ('TESTS'))
4226 push (@check_tests, 'check-TESTS');
4227 $output_rules .= &file_contents ('check');
4231 # Handle Emacs Lisp.
4232 sub handle_emacs_lisp
4234 my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4237 return if ! @elfiles;
4239 # Generate .elc files.
4240 my @elcfiles = map { $_ . 'c' } @elfiles;
4241 &define_pretty_variable ('ELCFILES', '', @elcfiles);
4243 push (@all, '$(ELCFILES)');
4245 &am_error ("`lisp_LISP' defined but `AM_PATH_LISPDIR' not in `$configure_ac'")
4246 if ! $seen_lispdir && &variable_defined ('lisp_LISP');
4248 &require_file_with_conf_line ('AM_PATH_LISPDIR', $FOREIGN, 'elisp-comp');
4254 my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4255 'python', 'noinst');
4256 return if ! @pyfiles;
4258 # Found some python.
4259 &am_error ("`python_PYTHON' defined but `AM_PATH_PYTHON' not in `$configure_ac'")
4260 if ! $seen_pythondir && &variable_defined ('python_PYTHON');
4262 &require_file_with_conf_line ('AM_PATH_PYTHON', $FOREIGN, 'py-compile');
4263 &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4269 my @sourcelist = &am_install_var ('-candist',
4271 'java', 'noinst', 'check');
4272 return if ! @sourcelist;
4274 my %valid = &am_primary_prefixes ('JAVA', 1,
4275 'java', 'noinst', 'check');
4278 foreach my $curs (keys %valid)
4280 if (! &variable_defined ($curs . '_JAVA') || $curs eq 'EXTRA')
4287 &am_line_error ($curs . '_JAVA',
4288 "multiple _JAVA primaries in use");
4293 push (@all, 'class' . $dir . '.stamp');
4297 # Handle some of the minor options.
4298 sub handle_minor_options
4300 if (defined $options{'readme-alpha'})
4302 if ($relative_dir eq '.')
4304 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4306 # FIXME: allow real filename.
4307 &am_conf_line_error ($configure_ac,
4308 $package_version_line,
4309 "version `$package_version' doesn't follow Gnits standards");
4311 elsif (defined $1 && -f 'README-alpha')
4313 # This means we have an alpha release. See
4314 # GNITS_VERSION_PATTERN for details.
4315 &require_file ($FOREIGN, 'README-alpha');
4321 ################################################################
4324 my @make_input_list;
4325 # &scan_autoconf_config_files ($CONFIG-FILES)
4326 # -------------------------------------------
4327 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4329 sub scan_autoconf_config_files
4331 my ($config_files) = @_;
4332 # Look at potential Makefile.am's.
4333 foreach (split ' ', $config_files)
4335 # Must skip empty string for Perl 4.
4336 next if $_ eq "\\" || $_ eq '';
4338 # Handle $local:$input syntax. Note that we ignore
4339 # every input file past the first, though we keep
4340 # those around for later.
4341 my ($local, $input, @rest) = split (/:/);
4348 # FIXME: should be error if .in is missing.
4349 $input =~ s/\.in$//;
4352 if (-f $input . '.am')
4354 # We have a file that automake should generate.
4355 push (@make_input_list, $input);
4356 $make_list{$input} = join (':', ($local, @rest));
4360 # We have a file that automake should cause to be
4361 # rebuilt, but shouldn't generate itself.
4362 push (@other_input_files, $_);
4368 # &scan_autoconf_traces ($FILENAME)
4369 # ---------------------------------
4370 # FIXME: For the time being, we don't care about the FILENAME.
4371 sub scan_autoconf_traces
4373 my ($filename) = @_;
4375 my $traces = "$ENV{amtraces} ";
4377 $traces .= ' -t AC_CONFIG_FILES';
4378 $traces .= ' -t AC_LIBSOURCE';
4379 $traces .= ' -t AC_SUBST';
4381 my $tracefh = new IO::File ("$traces |");
4384 die "$me: couldn't open `$traces': $!\n";
4386 print "$me: reading $traces\n" if $verbose;
4388 while ($_ = $tracefh->getline)
4391 my ($file, $line, $macro, @args) = split /:/;
4392 my $here = "$file:$line";
4394 # Alphabetical ordering please.
4395 if ($macro eq 'AC_CONFIG_FILES')
4397 # Look at potential Makefile.am's.
4398 &scan_autoconf_config_files ($args[0]);
4400 elsif ($macro eq 'AC_LIBSOURCE')
4402 my $source = "$args[0].c";
4403 # We should actually also `close' the sources: getopt.c
4404 # wants getopt.h etc. But actually it should be done in the
4405 # macro itself, i.e., we have to first fix Autoconf to extend
4406 # _AC_LIBOBJ_DECL and use it the in various macros.
4407 if (!defined $libsources{$source})
4409 print STDERR "traces: discovered $source\n";
4410 $libsources{$source} = $here;
4413 elsif ($macro eq 'AC_SUBST')
4415 if (!defined $configure_vars{$args[0]})
4417 print STDERR "traces: discovered AC_SUBST($args[0])\n";
4418 $configure_vars{$args[0]} = $here;
4424 || die "$me: close: $traces: $!\n";
4428 # &scan_one_autoconf_file ($FILENAME)
4429 # -----------------------------------
4430 # Scan one file for interesting things. Subroutine of
4431 # &scan_autoconf_files.
4432 sub scan_one_autoconf_file
4434 my ($filename) = @_;
4436 my $configfh = new IO::File ("< $filename");
4439 die "$me: couldn't open `$filename': $!\n";
4441 print "$me: reading $filename\n" if $verbose;
4443 my ($in_ac_output, $in_ac_replace) = (0, 0);
4444 while ($_ = $configfh->getline)
4446 # Remove comments from current line.
4450 # Skip macro definitions. Otherwise we might be confused into
4451 # thinking that a macro that was only defined was actually
4455 # Follow includes. This is a weirdness commonly in use at
4456 # Cygnus and hopefully nowhere else.
4457 if (/sinclude\((.*)\)/ && -f $1)
4459 # $_ being local, if we don't preserve it, when coming
4460 # back we will have $_ undefined, which is bad for the
4461 # the rest of this routine.
4462 my $underscore = $_;
4463 &scan_one_autoconf_file ($1);
4467 # Populate libobjs array.
4468 if (/AC_FUNC_ALLOCA/)
4470 $libsources{'alloca.c'} = 1;
4472 elsif (/AC_FUNC_GETLOADAVG/)
4474 $libsources{'getloadavg.c'} = 1;
4476 elsif (/AC_FUNC_MEMCMP/)
4478 $libsources{'memcmp.c'} = 1;
4480 elsif (/AC_STRUCT_ST_BLOCKS/)
4482 $libsources{'fileblocks.c'} = 1;
4484 elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4486 $libsources{'getopt.c'} = 1;
4487 $libsources{'getopt1.c'} = 1;
4489 elsif (/AM_FUNC_STRTOD/)
4491 $libsources{'strtod.c'} = 1;
4493 elsif (/AM_WITH_REGEX/)
4495 $libsources{'rx.c'} = 1;
4496 $libsources{'rx.h'} = 1;
4497 $libsources{'regex.c'} = 1;
4498 $libsources{'regex.h'} = 1;
4500 elsif (/AC_FUNC_MKTIME/)
4502 $libsources{'mktime.c'} = 1;
4504 elsif (/AM_FUNC_ERROR_AT_LINE/)
4506 $libsources{'error.c'} = 1;
4507 $libsources{'error.h'} = 1;
4509 elsif (/AM_FUNC_OBSTACK/)
4511 $libsources{'obstack.c'} = 1;
4512 $libsources{'obstack.h'} = 1;
4514 elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4515 || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4517 foreach my $libobj_iter (split (' ', $1))
4519 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4520 || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4521 || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4523 $libsources{$1 . '.c'} = 1;
4527 elsif (/AC_LIBOBJ\(([^)]+)\)/)
4529 $libsources{"$1.c"} = 1;
4532 if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4538 $in_ac_replace = 0 if s/[\]\)].*$//;
4539 # Remove trailing backslash.
4543 # Need to skip empty elements for Perl 4.
4545 $libsources{$_ . '.c'} = 1;
4549 if (/$obsolete_rx/o)
4552 if ($obsolete_macros{$1} ne '')
4554 $hint = '; ' . $obsolete_macros{$1};
4556 &am_conf_line_error ($filename, $., "`$1' is obsolete$hint");
4559 # Process the AC_OUTPUT and AC_CONFIG_FILES macros.
4560 if (! $in_ac_output && s/AC_(OUTPUT|CONFIG_FILES)\s*\(\[?//)
4563 $ac_output_line = $.;
4574 # Look at potential Makefile.am's.
4575 &scan_autoconf_config_files ($_);
4577 if ($closing && @make_input_list == 0 && @other_input_files == 0)
4579 &am_conf_line_error ($filename, $ac_output_line,
4580 "No files mentioned in `AC_OUTPUT'");
4585 if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4587 @config_aux_path = &unquote_m4_arg ($1);
4588 $config_aux_dir_set_in_configure_in = 1;
4591 # Check for ansi2knr.
4592 $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4594 # Check for exe extension stuff.
4598 $configure_vars{'EXEEXT'} = $filename . ':' . $.;
4604 $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4607 # Check for `-c -o' code.
4608 $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4610 # Check for NLS support.
4611 if (/AM_GNU_GETTEXT/)
4614 $ac_gettext_line = $.;
4617 # Look for ALL_LINGUAS.
4618 if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4622 $all_linguas_line = $.;
4625 # Handle configuration headers. A config header of `[$1]'
4626 # means we are actually scanning AM_CONFIG_HEADER from
4628 if (/A([CM])_CONFIG_HEADERS?\s*\((.*)\)/
4632 ($filename, $., "`automake requires `AM_CONFIG_HEADER', not `AC_CONFIG_HEADER'")
4635 $config_header_line = $.;
4636 foreach my $one_hdr (split (' ', &unquote_m4_arg ($2)))
4638 push (@config_fullnames, $one_hdr);
4639 if ($one_hdr =~ /^([^:]+):(.+)$/)
4641 push (@config_names, $1);
4642 push (@config_headers, $2);
4646 push (@config_names, $one_hdr);
4647 push (@config_headers, $one_hdr . '.in');
4652 # Handle AC_CANONICAL_*. Always allow upgrading to
4653 # AC_CANONICAL_SYSTEM, but never downgrading.
4654 $seen_canonical = $AC_CANONICAL_HOST
4655 if ! $seen_canonical
4656 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4657 $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4659 # If using X, include some extra variable definitions. NOTE
4660 # we don't want to force these into CFLAGS or anything,
4661 # because not all programs will necessarily use X.
4664 foreach my $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS',
4667 $configure_vars{$var} = $filename . ':' . $.
4671 # This macro handles several different things.
4672 if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4674 ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4675 $package_version_line = $.;
4676 $seen_init_automake = 1;
4681 $configure_vars{'LEX'} = $filename . ':' . $.;
4682 $seen_decl_yytext = 1;
4684 if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.(ac|in)$/)
4686 &am_conf_line_warning ($filename, $., "`AC_DECL_YYTEXT' is covered by `AM_PROG_LEX'");
4688 if (/AC_PROG_LEX/ && $filename =~ /configure\.(ac|in)$/)
4690 &am_conf_line_warning ($filename, $., "automake requires `AM_PROG_LEX', not `AC_PROG_LEX'");
4693 if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4695 $configure_vars{$1} = $filename . ':' . $.;
4697 if (/$AC_CHECK_PATTERN/o)
4699 $configure_vars{$3} = $filename . ':' . $.;
4701 if (/$AM_MISSING_PATTERN/o
4705 && $1 ne 'AUTOHEADER'
4706 # AM_INIT_AUTOMAKE is AM_MISSING_PROG'ing MAKEINFO. But
4707 # we handle it elsewhere.
4708 && $1 ne 'MAKEINFO')
4710 $configure_vars{$1} = $filename . ':' . $.;
4713 # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4714 # but later define it elsewhere. This is pretty hacky. We
4715 # also explicitly avoid INSTALL_SCRIPT and some other
4716 # variables because they are defined in header-vars.am.
4718 if (/$AC_SUBST_PATTERN/o
4720 && $1 ne 'INSTALL_SCRIPT'
4721 && $1 ne 'INSTALL_DATA')
4723 $configure_vars{$1} = $filename . ':' . $.;
4726 $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4727 if (/AM_MAINTAINER_MODE/)
4729 $seen_maint_mode = 1;
4730 $configure_cond{'MAINTAINER_MODE'} = 1;
4733 $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4735 if (/AM_PATH_PYTHON/)
4737 $seen_pythondir = 1;
4738 $configure_vars{'pythondir'} = $filename . ':' . $.;
4739 $configure_vars{'PYTHON'} = $filename . ':' . $.;
4742 if (/A(C|M)_PROG_LIBTOOL/)
4744 # We're not ready for this yet. People still use a
4745 # libtool with no AC_PROG_LIBTOOL. Once that is the
4746 # dominant version we can reenable this code -- but next
4747 # time by mentioning the macro in %obsolete_macros, both
4748 # here and in aclocal.in.
4750 # if (/AM_PROG_LIBTOOL/)
4752 # &am_conf_line_warning ($filename, $., "`AM_PROG_LIBTOOL' is obsolete, use `AC_PROG_LIBTOOL' instead");
4756 $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4757 $configure_vars{'RANLIB'} = $filename . ':' . $.;
4758 $configure_vars{'CC'} = $filename . ':' . $.;
4759 # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST. Make sure we
4760 # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4761 $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4764 $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4766 if (/$AM_CONDITIONAL_PATTERN/o)
4768 $configure_cond{$1} = 1;
4771 # Check for Fortran 77 intrinsic and run-time libraries.
4772 if (/AC_F77_LIBRARY_LDFLAGS/)
4774 $configure_vars{'FLIBS'} = $filename . ':' . $.;
4782 # &scan_autoconf_files ()
4783 # -----------------------
4784 # Check whether we use `configure.ac' or `configure.in'.
4785 # Scan it (and possibly `aclocal.m4') for interesting things.
4786 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
4787 sub scan_autoconf_files
4789 # Reinitialize libsources here. This isn't really necessary,
4790 # since we currently assume there is only one configure.ac. But
4791 # that won't always be the case.
4794 warn "$me: both `configure.ac' and `configure.in' present:"
4795 . " ignoring `configure.in'\n"
4796 if -f 'configure.ac' && -f 'configure.in';
4797 $configure_ac = 'configure.in'
4798 if -f 'configure.in';
4799 $configure_ac = 'configure.ac'
4800 if -f 'configure.ac';
4801 die "$me: `configure.ac' or `configure.in' is required\n"
4804 &scan_one_autoconf_file ($configure_ac);
4805 &scan_one_autoconf_file ('aclocal.m4')
4808 if (defined $ENV{'amtraces'})
4810 warn '$me: Autoconf traces is an experimental feature';
4811 warn '$me: use at your own risks';
4813 &scan_autoconf_traces ($configure_ac);
4816 # Set input and output files if not specified by user.
4819 @input_files = @make_input_list;
4820 %output_files = %make_list;
4823 @configure_input_files = @make_input_list;
4825 &am_conf_error ("`AM_INIT_AUTOMAKE' must be used")
4826 if ! $seen_init_automake;
4828 # Look for some files we need. Always check for these. This
4829 # check must be done for every run, even those where we are only
4830 # looking at a subdir Makefile. We must set relative_dir so that
4831 # the file-finding machinery works.
4832 # FIXME: Is this broken because it needs dynamic scopes.
4833 # My tests seems to show it's not the case.
4834 $relative_dir = '.';
4835 &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4836 &am_error ("`install.sh' is an anachronism; use `install-sh' instead")
4837 if -f $config_aux_path[0] . '/install.sh';
4839 &require_config_file ($FOREIGN, 'py-compile')
4842 # Preserve dist_common for later.
4843 $configure_dist_common = variable_value ('DIST_COMMON', 'TRUE') || '';
4846 ################################################################
4848 # Set up for Cygnus mode.
4851 return unless $cygnus_mode;
4853 &set_strictness ('foreign');
4854 $options{'no-installinfo'} = 1;
4855 $options{'no-dependencies'} = 1;
4856 $use_dependencies = 0;
4858 if (! $seen_maint_mode)
4860 &am_conf_error ("`AM_MAINTAINER_MODE' required when --cygnus specified");
4864 # Do any extra checking for GNU standards.
4865 sub check_gnu_standards
4867 if ($relative_dir eq '.')
4869 # In top level (or only) directory.
4870 &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4871 'AUTHORS', 'ChangeLog');
4874 if ($strictness >= $GNU
4875 && defined $options{'no-installman'})
4877 &am_line_error ('AUTOMAKE_OPTIONS',
4878 "option `no-installman' disallowed by GNU standards");
4881 if ($strictness >= $GNU
4882 && defined $options{'no-installinfo'})
4884 &am_line_error ('AUTOMAKE_OPTIONS',
4885 "option `no-installinfo' disallowed by GNU standards");
4889 # Do any extra checking for GNITS standards.
4890 sub check_gnits_standards
4892 if ($relative_dir eq '.')
4894 # In top level (or only) directory.
4895 &require_file ($GNITS, 'THANKS');
4899 ################################################################
4901 # Functions to handle files of each language.
4903 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
4904 # simple formula: Return value is $LANG_SUBDIR if the resulting object
4905 # file should be in a subdir if the source file is, $LANG_PROCESS if
4906 # file is to be dealt with, $LANG_IGNORE otherwise.
4908 # Much of the actual processing is handled in
4909 # handle_single_transform_list. These functions exist so that
4910 # auxiliary information can be recorded for a later cleanup pass.
4911 # Note that the calls to these functions are computed, so don't bother
4912 # searching for their precise names in the source.
4914 # This is just a convenience function that can be used to determine
4915 # when a subdir object should be used.
4918 return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4921 # Rewrite a single C source file.
4924 my ($directory, $base, $ext) = @_;
4926 if (defined $options{'ansi2knr'} && $base =~ /_$/)
4928 # FIXME: include line number in error.
4929 &am_error ("C source file `$base.c' would be deleted by ansi2knr rules");
4932 my $r = $LANG_PROCESS;
4933 if (defined $options{'subdir-objects'})
4936 $base = $directory . '/' . $base;
4940 # Only give error once.
4942 # FIXME: line number.
4943 &am_error ("C objects in subdir but `AM_PROG_CC_C_O' not in `$configure_ac'");
4946 &require_config_file ($FOREIGN, 'compile');
4949 $de_ansi_files{$base} = 1;
4953 # Rewrite a single C++ source file.
4954 sub lang_cxx_rewrite
4956 return &lang_sub_obj;
4959 # Rewrite a single header file.
4960 sub lang_header_rewrite
4962 # Header files are simply ignored.
4963 return $LANG_IGNORE;
4966 # Rewrite a single yacc file.
4967 sub lang_yacc_rewrite
4969 my ($directory, $base, $ext) = @_;
4971 my $r = &lang_sub_obj;
4972 (my $newext = $ext) =~ tr/y/c/;
4973 return ($r, $newext);
4976 # Rewrite a single yacc++ file.
4977 sub lang_yaccxx_rewrite
4979 my ($directory, $base, $ext) = @_;
4981 my $r = &lang_sub_obj;
4982 (my $newext = $ext) =~ tr/y/c/;
4983 return ($r, $newext);
4986 # Rewrite a single lex file.
4987 sub lang_lex_rewrite
4989 my ($directory, $base, $ext) = @_;
4991 my $r = &lang_sub_obj;
4992 (my $newext = $ext) =~ tr/l/c/;
4993 return ($r, $newext);
4996 # Rewrite a single lex++ file.
4997 sub lang_lexxx_rewrite
4999 my ($directory, $base, $ext) = @_;
5001 my $r = &lang_sub_obj;
5002 (my $newext = $ext) =~ tr/l/c/;
5003 return ($r, $newext);
5006 # Rewrite a single assembly file.
5007 sub lang_asm_rewrite
5009 return &lang_sub_obj;
5012 # Rewrite a single Fortran 77 file.
5013 sub lang_f77_rewrite
5015 return $LANG_PROCESS;
5018 # Rewrite a single preprocessed Fortran 77 file.
5019 sub lang_ppf77_rewrite
5021 return $LANG_PROCESS;
5024 # Rewrite a single ratfor file.
5025 sub lang_ratfor_rewrite
5027 return $LANG_PROCESS;
5030 # Rewrite a single Objective C file.
5031 sub lang_objc_rewrite
5033 return &lang_sub_obj;
5036 # Rewrite a single Java file.
5037 sub lang_java_rewrite
5039 return $LANG_SUBDIR;
5042 # The lang_X_finish functions are called after all source file
5043 # processing is done. Each should handle defining rules for the
5044 # language, etc. A finish function is only called if a source file of
5045 # the appropriate type has been seen.
5049 # Push all libobjs files onto de_ansi_files. We actually only
5050 # push files which exist in the current directory, and which are
5051 # genuine source files.
5052 foreach my $file (keys %libsources)
5054 if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
5056 $de_ansi_files{$1} = 1;
5060 if (defined $options{'ansi2knr'} && keys %de_ansi_files)
5062 # Make all _.c files depend on their corresponding .c files.
5064 foreach my $base (sort keys %de_ansi_files)
5066 # Each _.c file must depend on ansi2knr; otherwise it
5067 # might be used in a parallel build before it is built.
5068 # We need to support files in the srcdir and in the build
5069 # dir (because these files might be auto-generated. But
5070 # we can't use $< -- some makes only define $< during a
5072 $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
5073 . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5074 . '`if test -f $(srcdir)/' . $base . '.c'
5075 . '; then echo $(srcdir)/' . $base . '.c'
5076 . '; else echo ' . $base . '.c; fi` '
5077 . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5078 . '| $(ANSI2KNR) > ' . $base . "_.c"
5079 # If ansi2knr fails then we shouldn't
5080 # create the _.c file
5081 . " || rm -f ${base}_.c\n");
5082 push (@objects, $base . '_.$(OBJEXT)');
5083 push (@objects, $base . '_.lo')
5087 # Make all _.o (and _.lo) files depend on ansi2knr.
5088 # Use a sneaky little hack to make it print nicely.
5089 &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5093 # This is a yacc helper which is called whenever we have decided to
5094 # compile a yacc file.
5095 sub lang_yacc_target_hook
5097 my ($self, $aggregate, $output, $input) = @_;
5099 my $flag = $aggregate . "_YFLAGS";
5100 if ((&variable_defined ($flag)
5101 && &variable_value ($flag) =~ /$DASH_D_PATTERN/o)
5102 || (&variable_defined ('YFLAGS')
5103 && &variable_value ('YFLAGS') =~ /$DASH_D_PATTERN/o))
5105 (my $output_base = $output) =~ s/\..*$//;
5106 my $header = $output_base . '.h';
5108 # Found a `-d' that applies to the compilation of this file.
5109 # Add a dependency for the generated header file, and arrange
5110 # for that file to be included in the distribution.
5111 # FIXME: this fails for `nodist_*_SOURCES'.
5112 $output_rules .= "${header}: $input\n";
5113 &push_dist_common ($header);
5114 # If the files are built in the build directory, then we want
5115 # to remove them with `make clean'. If they are in srcdir
5116 # they shouldn't be touched. However, we can't determine this
5117 # statically, and the GNU rules say that yacc/lex output files
5118 # should be removed by maintainer-clean. So that's what we
5120 push (@maintainer_clean_files, $header);
5124 # This is a helper for both lex and yacc.
5125 sub yacc_lex_finish_helper
5127 return if defined $language_scratch{'lex-yacc-done'};
5128 $language_scratch{'lex-yacc-done'} = 1;
5130 # If there is more than one distinct yacc (resp lex) source file
5131 # in a given directory, then the `ylwrap' program is required to
5132 # allow parallel builds to work correctly. FIXME: for now, no
5134 &require_config_file ($FOREIGN, 'ylwrap');
5135 if ($config_aux_dir_set_in_configure_in)
5137 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5141 &define_variable ('YLWRAP', '$(top_srcdir)/ylwrap');
5145 sub lang_yacc_finish
5147 return if defined $language_scratch{'yacc-done'};
5148 $language_scratch{'yacc-done'} = 1;
5150 if (&variable_defined ('YACCFLAGS'))
5152 &am_line_error ('YACCFLAGS',
5153 "`YACCFLAGS' obsolete; use `YFLAGS' instead");
5156 if (count_files_for_language ('yacc') > 1)
5158 &yacc_lex_finish_helper;
5165 return if defined $language_scratch{'lex-done'};
5166 $language_scratch{'lex-done'} = 1;
5168 if (! $seen_decl_yytext)
5170 &am_error ("lex source seen but `AC_DECL_YYTEXT' not in `$configure_ac'");
5173 if (count_files_for_language ('lex') > 1)
5175 &yacc_lex_finish_helper;
5180 # Given a hash table of linker names, pick the name that has the most
5181 # precedence. This is lame, but something has to have global
5182 # knowledge in order to eliminate the conflict. Add more linkers as
5189 if defined $linkers{'GCJLINK'};
5191 if defined $linkers{'CXXLINK'};
5193 if defined $linkers{'F77LINK'};
5195 if defined $linkers{'OBJCLINK'};
5199 # Called to indicate that an extension was used.
5203 if (! defined $extension_seen{$ext})
5205 $extension_seen{$ext} = 1;
5209 ++$extension_seen{$ext};
5213 # Return the number of files seen for a given language. Knows about
5214 # special cases we care about. FIXME: this is hideous. We need
5215 # something that involves real language objects. For instance yacc
5216 # and yaccxx could both derive from a common yacc class which would
5217 # know about the strange ylwrap requirement. (Or better yet we could
5218 # just not support legacy yacc!)
5219 sub count_files_for_language
5224 if ($name eq 'yacc' || $name eq 'yaccxx')
5226 @names = ('yacc', 'yaccxx');
5228 elsif ($name eq 'lex' || $name eq 'lexxx')
5230 @names = ('lex', 'lexxx');
5238 foreach $name (@names)
5240 my $lang = $languages{$name};
5241 foreach my $ext (@{$lang->extensions})
5243 $r += $extension_seen{$ext}
5244 if defined $extension_seen{$ext};
5251 # Called to ask whether source files have been seen . If HEADERS is 1,
5252 # headers can be included.
5257 # count all the sources
5259 foreach my $val (values %extension_seen)
5266 $count -= count_files_for_language ('header');
5273 # register_language (%ATTRIBUTE)
5274 # ------------------------------
5275 # Register a single language.
5276 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5277 sub register_language (%)
5283 unless defined $option{'ansi'};
5284 $option{'autodep'} = 'no'
5285 unless defined $option{'autodep'};
5286 $option{'linker'} = ''
5287 unless defined $option{'linker'};
5288 $option{'define_flag'} = 1
5289 unless defined $option{'define_flag'};
5291 my $lang = new Language (%option);
5294 grep ($extension_map{$_} = $lang->name, @{$lang->extensions});
5295 $languages{$lang->name} = $lang;
5298 # This function is used to find a path from a user-specified suffix to
5299 # `o' or to some other suffix we recognize internally, eg `cc'.
5302 my ($source_ext) = @_;
5304 # FIXME: hard-coding `o' is a mistake. Doing something
5305 # intelligent is harder.
5306 while (! $extension_map{$source_ext}
5307 && $source_ext ne 'o'
5308 && defined $suffix_rules{$source_ext})
5310 $source_ext = $suffix_rules{$source_ext};
5317 ################################################################
5319 # Pretty-print something. HEAD is what should be printed at the
5320 # beginning of the first line, FILL is what should be printed at the
5321 # beginning of every subsequent line.
5322 sub pretty_print_internal
5324 my ($head, $fill, @values) = @_;
5326 my $column = length ($head);
5329 # Fill length is number of characters. However, each Tab
5330 # character counts for eight. So we count the number of Tabs and
5332 my $fill_length = length ($fill);
5333 $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5337 # "71" because we also print a space.
5338 if ($column + length ($_) > 71)
5340 $result .= " \\\n" . $fill;
5341 $column = $fill_length;
5343 $result .= ' ' if $result =~ /\S\z/;
5345 $column += length ($_) + 1;
5352 # Pretty-print something and append to output_vars.
5355 $output_vars .= &pretty_print_internal (@_);
5358 # Pretty-print something and append to output_rules.
5359 sub pretty_print_rule
5361 $output_rules .= &pretty_print_internal (@_);
5365 ################################################################
5369 # &conditional_string(@COND-STACK)
5370 # --------------------------------
5371 # Build a string which denotes the conditional in @COND-STACK. Some
5372 # simplifications are done: `TRUE' entries are elided, and any `FALSE'
5373 # entry results in a return of `FALSE'.
5374 sub conditional_string
5378 if (grep (/^FALSE$/, @stack))
5384 return join (' ', uniq sort grep (!/^TRUE$/, @stack));
5390 # &conditional_true_when ($COND, $WHEN)
5391 # -------------------------------------
5392 # See if a conditional is true. Both arguments are conditional
5393 # strings. This returns true if the first conditional is true when
5394 # the second conditional is true.
5395 # For instance with $COND = `BAR FOO', and $WHEN = `BAR BAZ FOO',
5396 # obviously return 1, and 0 when, for instance, $WHEN = `FOO'.
5397 sub conditional_true_when ($$)
5399 my ($cond, $when) = @_;
5401 # Make a hash holding all the values from $WHEN.
5402 my %cond_vals = map { $_ => 1 } split (' ', $when);
5404 # Check each component of $cond, which looks `COND1 COND2'.
5405 foreach my $comp (split (' ', $cond))
5407 # TRUE is always true.
5408 next if $comp eq 'TRUE';
5409 return 0 if ! defined $cond_vals{$comp};
5417 # &conditionals_true_when (\@CONDS, $WHEN)
5418 # ----------------------------------------
5419 # Same as above, but true only if all the @CONDS are true when $WHEN is true.
5421 # If there are no @CONDS, then return true.
5422 sub conditionals_true_when (\@$)
5424 my ($condsref, $when) = @_;
5426 foreach my $cond (@$condsref)
5428 return 0 unless conditional_true_when ($cond, $when);
5435 # &conditional_is_redundant ($COND, @WHENS)
5436 # ----------------------------------------
5437 # Determine whether $COND is redundant with respect to @WHENS.
5439 # Returns true if $COND is true for any of the conditions in @WHENS.
5441 # If there are no @WHENS, then behave as if @WHENS contained a single empty
5443 sub conditional_is_redundant ($@)
5445 my ($cond, @whens) = @_;
5449 return 1 if conditional_true_when ($cond, "");
5453 foreach my $when (@whens)
5455 return 1 if conditional_true_when ($cond, $when);
5464 # condition_negate ($COND)
5465 # ------------------------
5466 sub condition_negate ($)
5470 $cond =~ s/TRUE$/TRUEO/;
5471 $cond =~ s/FALSE$/TRUE/;
5472 $cond =~ s/TRUEO$/FALSE/;
5478 # Compare condition names.
5479 # Issue them in alphabetical order, foo_TRUE before foo_FALSE.
5482 # Be careful we might be comparing `' or `#'.
5483 $a =~ /^(.*)_(TRUE|FALSE)$/;
5484 my ($aname, $abool) = ($1 || '', $2 || '');
5485 $b =~ /^(.*)_(TRUE|FALSE)$/;
5486 my ($bname, $bbool) = ($1 || '', $2 || '');
5487 return ($aname cmp $bname
5488 # Don't bother with IFs, given that TRUE is after FALSE
5489 # just cmp in the reverse order.
5490 || $bbool cmp $abool
5496 # &make_condition (@CONDITIONS)
5497 # -----------------------------
5498 # Transform a list of conditions (themselves can be an internal list
5499 # of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
5500 # Make conditional (a pattern for AC_SUBST).
5501 # Correctly returns the empty string when there are no conditions.
5504 my $res = conditional_string (@_);
5506 # There are no conditions.
5512 elsif ($res eq 'FALSE')
5519 $res = '@' . $res . '@';
5528 ## ------------------------------ ##
5529 ## Handling the condition stack. ##
5530 ## ------------------------------ ##
5534 # cond_stack_if ($NEGATE, $COND, $WHERE)
5535 # --------------------------------------
5536 sub cond_stack_if ($$$)
5538 my ($negate, $cond, $where) = @_;
5540 &am_file_error ($where, "$cond does not appear in AM_CONDITIONAL")
5541 if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
5543 $cond = "${cond}_TRUE"
5544 unless $cond =~ /^TRUE|FALSE$/;
5545 $cond = condition_negate ($cond)
5548 push (@cond_stack, $cond);
5550 return conditional_string (@cond_stack);
5555 # cond_stack_else ($NEGATE, $COND, $WHERE)
5556 # ----------------------------------------
5557 sub cond_stack_else ($$$)
5559 my ($negate, $cond, $where) = @_;
5563 &am_file_error ($where, "else without if");
5567 $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);
5569 # If $COND is given, check against it.
5572 $cond = "${cond}_TRUE"
5573 unless $cond =~ /^TRUE|FALSE$/;
5574 $cond = condition_negate ($cond)
5577 &am_file_error ($where,
5578 "else reminder ($negate$cond) incompatible with "
5579 . "current conditional: $cond_stack[$#cond_stack]")
5580 if $cond_stack[$#cond_stack] ne $cond;
5583 return conditional_string (@cond_stack);
5588 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5589 # -----------------------------------------
5590 sub cond_stack_endif ($$$)
5592 my ($negate, $cond, $where) = @_;
5597 &am_file_error ($where, "endif without if: $negate$cond");
5602 # If $COND is given, check against it.
5605 $cond = "${cond}_TRUE"
5606 unless $cond =~ /^TRUE|FALSE$/;
5607 $cond = condition_negate ($cond)
5610 &am_file_error ($where,
5611 "endif reminder ($negate$cond) incompatible with "
5612 . "current conditional: $cond_stack[$#cond_stack]")
5613 if $cond_stack[$#cond_stack] ne $cond;
5618 return conditional_string (@cond_stack);
5625 ## ------------------------ ##
5626 ## Handling the variables. ##
5627 ## ------------------------ ##
5630 # check_ambiguous_conditional ($VAR, $COND)
5631 # -----------------------------------------
5632 # Check for an ambiguous conditional. This is called when a variable
5633 # is being defined conditionally. If we already know about a
5634 # definition that is true under the same conditions, then we have an
5636 sub check_ambiguous_conditional ($$)
5638 my ($var, $cond) = @_;
5639 foreach my $vcond (keys %{$var_value{$var}})
5642 if ($vcond eq $cond)
5644 $message = "$var multiply defined in condition $cond";
5646 elsif (&conditional_true_when ($vcond, $cond))
5648 $message = ("$var was already defined in condition $vcond, "
5649 . "which implies condition $cond");
5651 elsif (&conditional_true_when ($cond, $vcond))
5653 $message = ("$var was already defined in condition $vcond, "
5654 . "which is implied by condition $cond");
5658 &am_line_error ($var, $message);
5665 # ¯o_define($VAR, $VAR_IS_AM, $TYPE, $COND, $VALUE, $WHERE)
5666 # -------------------------------------------------------------
5667 # The $VAR can go from Automake to user, but not the converse.
5668 sub macro_define ($$$$$$)
5670 my ($var, $var_is_am, $type, $cond, $value, $where) = @_;
5672 am_file_error ($where, "bad macro name `$var'")
5673 if $var !~ /$MACRO_PATTERN/o;
5677 # An Automake variable must be consistently defined with the same
5678 # sign by Automake. A user variable must be set by either `=' or
5679 # `:=', and later promoted to `+='.
5682 if (defined $var_type{$var} && $var_type{$var} ne $type)
5684 am_line_error ($var,
5685 ("$var was set with `$var_type{$var}=' "
5686 . "and is now set with `$type='"));
5691 if (!defined $var_type{$var} && $type eq '+')
5693 am_line_error ($var, "$var must be set with `=' before using `+='");
5696 $var_type{$var} = $type;
5698 # When adding, since we rewrite, don't try to preserve the
5699 # Automake continuation backslashes.
5701 if $type eq '+' && $var_is_am;
5703 # Differentiate the first assignment (including with `+=').
5704 if ($type eq '+' && defined $var_value{$var}{$cond})
5706 if (substr ($var_value{$var}{$cond}, -1) eq "\n")
5708 # Insert a backslash before a trailing newline.
5709 $var_value{$var}{$cond} =
5710 substr ($var_value{$var}{$cond}, 0, -1) . "\\\n";
5712 elsif ($var_value{$var}{$cond})
5714 # Insert a separator.
5715 $var_value{$var}{$cond} .= ' ';
5717 $var_value{$var}{$cond} .= $value;
5721 # The first assignment to a macro sets the line number. Ideally I
5722 # suppose we would associate line numbers with random bits of text.
5723 # FIXME: We sometimes redefine some variables, but we want to keep
5724 # the original location. More subs are needed to handle
5725 # properly variables. Once this done, remove this hack.
5726 $var_line{$var} = $where
5727 unless defined $var_line{$var};
5729 # If Automake tries to override a value specified by the user,
5730 # just don't let it do.
5731 if (defined $var_value{$var}{$cond} && !$var_is_am{$var} && $var_is_am)
5735 print STDERR "$me: refusing to override the user definition of:\n";
5737 print STDERR "$me: with `$cond' => `$value'\n";
5742 # There must be no previous value unless the user is redefining
5743 # an Automake variable or an AC_SUBST variable.
5744 check_ambiguous_conditional ($var, $cond)
5745 unless ($var_is_am{$var} && !$var_is_am
5746 || exists $configure_vars{$var});
5748 $var_value{$var}{$cond} = $value;
5752 # An Automake variable can be given to the user, but not the converse.
5753 if (! defined $var_is_am{$var} || !$var_is_am)
5755 $var_is_am{$var} = $var_is_am;
5760 # &variable_delete ($VAR, [@CONDS])
5761 # ---------------------------------
5762 # Forget about $VAR under the conditions @CONDS, or completely if
5764 sub variable_delete ($@)
5766 my ($var, @conds) = @_;
5770 delete $var_value{$var};
5771 delete $var_line{$var};
5772 delete $var_is_am{$var};
5773 delete $var_comment{$var};
5774 delete $var_type{$var};
5778 foreach my $cond (@conds)
5780 delete $var_value{$var}{$cond};
5786 # ¯o_dump ($VAR)
5787 # ------------------
5792 if (!exists $var_value{$var})
5794 print STDERR " $var does not exist\n";
5798 my $var_is_am = $var_is_am{$var} ? "Automake" : "User";
5799 my $where = (defined $var_line{$var}
5800 ? $var_line{$var} : "undefined");
5801 print STDERR "$var_comment{$var}"
5802 if defined $var_comment{$var};
5803 print STDERR " $var ($var_is_am, where = $where) $var_type{$var}=\n";
5804 print STDERR " {\n";
5805 foreach my $vcond (sort by_condition keys %{$var_value{$var}})
5807 print STDERR " $vcond => $var_value{$var}{$vcond}\n";
5809 print STDERR " }\n";
5820 print STDERR "%var_value =\n";
5822 foreach my $var (sort (keys %var_value))
5831 # &variable_defined ($VAR, [$COND])
5832 # ---------------------------------
5833 # See if a variable exists. $VAR is the variable name, and $COND is
5834 # the condition which we should check. If no condition is given, we
5835 # currently return true if the variable is defined under any
5837 sub variable_defined ($$)
5839 my ($var, $cond) = @_;
5841 # Unfortunately we can't just check for $var_value{VAR}{COND}
5842 # as this would make perl create $condition{VAR}, which we
5844 if (!exists $var_value{$var})
5846 if (defined $targets{$var})
5848 &am_line_error ($var, "`$var' is a target; expected a variable")
5850 # The variable is not defined
5854 if ($cond && !exists $var_value{$var}{$cond})
5856 # The variable is not defined for the given condition.
5860 # Even a var_value examination is good enough for us. FIXME:
5861 # really should maintain examined status on a per-condition basis.
5862 $content_seen{$var} = 1;
5866 # Mark a variable as examined.
5867 sub examine_variable
5870 &variable_defined ($var);
5873 # Return the set of conditions for which a variable is defined.
5875 # If the variable is not defined conditionally, and is not defined in
5876 # terms of any variables which are defined conditionally, then this
5877 # returns the empty list.
5879 # If the variable is defined conditionally, but is not defined in
5880 # terms of any variables which are defined conditionally, then this
5881 # returns the list of conditions for which the variable is defined.
5883 # If the variable is defined in terms of any variables which are
5884 # defined conditionally, then this returns a full set of permutations
5885 # of the subvariable conditions. For example, if the variable is
5886 # defined in terms of a variable which is defined for COND_TRUE,
5887 # then this returns both COND_TRUE and COND_FALSE. This is
5888 # because we will need to define the variable under both conditions.
5890 sub variable_conditions ($)
5898 my @new_conds = &variable_conditions_sub ($var, '', ());
5899 # Now we want to return all permutations of the subvariable
5902 foreach my $item (@new_conds)
5904 foreach (split (' ', $item))
5906 s/^(.*)_(TRUE|FALSE)$/$1_TRUE/;
5910 @new_conds = &variable_conditions_permutations (sort keys %allconds);
5912 foreach my $cond (@new_conds)
5914 my $reduce = &variable_conditions_reduce (split (' ', $cond));
5916 if $reduce eq 'FALSE';
5917 $uniqify{$cond} = 1;
5920 @uniq_list = sort by_condition keys %uniqify;
5921 # Note we cannot just do `return sort keys %uniqify', because this
5922 # function is sometimes used in a scalar context.
5928 # &variable_conditionally_defined ($VAR)
5929 # --------------------------------------
5930 sub variable_conditionally_defined ($)
5933 foreach my $cond (variable_conditions ($var))
5936 unless $cond =~ /^TRUE|FALSE$/;
5943 # &variable_conditions_sub ($VAR, $PARENT, @PARENT_CONDS)
5944 # -------------------------------------------------------
5945 # A subroutine of variable_conditions. This returns all the
5946 # conditions of $VAR which are satisfiable when all of @PARENT_CONDS
5948 sub variable_conditions_sub
5950 my ($var, $parent, @parent_conds) = @_;
5953 if (defined $vars_scanned{$var})
5955 &am_line_error ($parent, "variable `$var' recursively defined");
5958 $vars_scanned{$var} = 1;
5960 my @this_conds = ();
5961 # Examine every condition under which $VAR is defined.
5962 foreach my $vcond (keys %{$var_value{$var}})
5964 # If this condition cannot be true when the parent conditions
5965 # are true, then skip it.
5967 if ! conditionals_true_when (@parent_conds, $vcond);
5969 push (@this_conds, $vcond);
5971 # If $VAR references some other variable, then compute the
5972 # conditions for that subvariable.
5973 push (@parent_conds, $vcond);
5974 my @subvar_conds = ();
5975 foreach (split (' ', $var_value{$var}{$vcond}))
5977 # If a comment seen, just leave.
5980 # Handle variable substitutions.
5981 if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5984 # Here we compute all the conditions under which the
5985 # subvariable is defined. Then we go through and add
5987 my @svc = &variable_conditions_sub ($1, $var, @parent_conds);
5988 foreach my $item (@svc)
5990 my $val = conditional_string ($vcond, split (' ', $item));
5992 push (@subvar_conds, $val);
5996 pop (@parent_conds);
5998 # If there are no conditional subvariables, then we want to
5999 # return this condition. Otherwise, we want to return the
6000 # permutations of the subvariables, taking into account the
6001 # conditions of $VAR.
6002 if (! @subvar_conds)
6004 push (@new_conds, $vcond);
6008 push (@new_conds, &variable_conditions_reduce (@subvar_conds));
6012 # Unset our entry in vars_scanned. We only care about recursive
6014 delete $vars_scanned{$var};
6016 # If we are being called on behalf of another variable, we need to
6017 # return all possible permutations of the conditions. We have
6018 # already handled everything in @this_conds along with their
6019 # subvariables. We now need to add any permutations that are not
6021 foreach my $this_cond (@this_conds)
6024 &variable_conditions_permutations (split(' ', $this_cond));
6025 foreach my $perm (@perms)
6028 foreach my $scan (@this_conds)
6030 if (&conditional_true_when ($perm, $scan)
6031 || &conditional_true_when ($scan, $perm))
6040 if ! conditionals_true_when (@parent_conds, $perm);
6042 # This permutation was not already handled, and is valid
6044 push (@new_conds, $perm);
6052 # Filter a list of conditionals so that only the exclusive ones are
6053 # retained. For example, if both `COND1_TRUE COND2_TRUE' and
6054 # `COND1_TRUE' are in the list, discard the latter.
6055 # If the list is empty, return TRUE
6056 sub variable_conditions_reduce
6063 $cond = shift(@conds);
6065 # FALSE is absorbent.
6066 if ($cond eq 'FALSE')
6070 elsif (!conditional_is_redundant ($cond, @ret, @conds))
6076 return "TRUE" if @ret == 0;
6080 # Return a list of permutations of a conditional string.
6081 sub variable_conditions_permutations
6086 my $comp = shift (@comps);
6087 return &variable_conditions_permutations (@comps)
6089 my $neg = condition_negate ($comp);
6092 foreach my $sub (&variable_conditions_permutations (@comps))
6094 push (@ret, "$comp $sub");
6095 push (@ret, "$neg $sub");
6107 # &check_variable_defined_unconditionally($VAR, $PARENT)
6108 # ------------------------------------------------------
6109 # Warn if a variable is conditionally defined. This is called if we
6110 # are using the value of a variable.
6111 sub check_variable_defined_unconditionally ($$)
6113 my ($var, $parent) = @_;
6114 foreach my $cond (keys %{$var_value{$var}})
6117 if $cond =~ /^TRUE|FALSE$/;
6121 &am_line_error ($parent,
6122 "warning: automake does not support conditional definition of $var in $parent");
6126 &am_line_error ($parent,
6127 "warning: automake does not support $var being defined conditionally");
6135 # Get the TRUE value of a variable, warn if the variable is
6136 # conditionally defined.
6140 &check_variable_defined_unconditionally ($var);
6141 return $var_value{$var}{'TRUE'};
6146 # &value_to_list ($VAR, $VAL, $COND)
6147 # ----------------------------------
6148 # Convert a variable value to a list, split as whitespace. This will
6149 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6152 # If COND is 'all', then all values under all conditions should be
6153 # returned; if COND is a particular condition (all conditions are
6154 # surrounded by @...@) then only the value for that condition should
6155 # be returned; otherwise, warn if VAR is conditionally defined.
6156 # SCANNED is a global hash listing whose keys are all the variables
6157 # already scanned; it is an error to rescan a variable.
6160 my ($var, $val, $cond) = @_;
6164 $val =~ s/\\(\n|$)/ /g;
6166 foreach (split (' ', $val))
6168 # If a comment seen, just leave.
6171 # Handle variable substitutions.
6172 if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
6176 # If the user uses a losing variable name, just ignore it.
6177 # This isn't ideal, but people have requested it.
6178 next if ($varname =~ /\@.*\@/);
6182 if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
6186 ($from = $2) =~ s/(\W)/\\$1/g;
6190 @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
6192 # Now rewrite the value if appropriate.
6195 grep (s/$from$/$to/, @temp_list);
6198 push (@result, @temp_list);
6209 # Return contents of variable as list, split as whitespace. This will
6210 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6211 # substitutions. If COND is 'all', then all values under all
6212 # conditions should be returned; if COND is a particular condition
6213 # (all conditions are surrounded by @...@) then only the value for
6214 # that condition should be returned; otherwise, warn if VAR is
6215 # conditionally defined. If PARENT is specified, it is the name of
6216 # the including variable; this is only used for error reports.
6217 sub variable_value_as_list_worker
6219 my ($var, $cond, $parent) = @_;
6222 if (! defined $var_value{$var})
6224 if (defined $targets{$var})
6226 &am_line_error ($var, "`$var' is a target; expected a variable");
6230 &am_line_error ($parent, "variable `$var' not defined");
6233 elsif (defined $vars_scanned{$var})
6235 # `vars_scanned' is a global we use to keep track of which
6236 # variables we've already examined.
6237 &am_line_error ($parent, "variable `$var' recursively defined");
6239 elsif ($cond eq 'all')
6241 $vars_scanned{$var} = 1;
6242 foreach my $vcond (keys %{$var_value{$var}})
6244 my $val = $var_value{$var}{$vcond};
6245 push (@result, &value_to_list ($var, $val, $cond));
6251 $vars_scanned{$var} = 1;
6253 foreach my $vcond (keys %{$var_value{$var}})
6255 my $val = $var_value{$var}{$vcond};
6256 if (&conditional_true_when ($vcond, $cond))
6258 # Warn if we have an ambiguity. It's hard to know how
6259 # to handle this case correctly.
6260 &check_variable_defined_unconditionally ($var, $parent)
6263 push (@result, &value_to_list ($var, $val, $cond));
6268 # Unset our entry in vars_scanned. We only care about recursive
6270 delete $vars_scanned{$var};
6276 # &variable_output ($VAR, [@CONDS])
6277 # ---------------------------------
6278 # Output all the values of $VAR is @COND is not specified, else only
6279 # that corresponding to @COND.
6280 sub variable_output ($@)
6282 my ($var, @conds) = @_;
6284 @conds = sort by_condition keys %{$var_value{$var}}
6287 $output_vars .= $var_comment{$var}
6288 if defined $var_comment{$var};
6290 foreach my $cond (@conds)
6292 my $val = $var_value{$var}{$cond};
6293 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6294 my $output_var = "$var $equals $val";
6295 $output_var =~ s/^/make_condition ($cond)/meg;
6296 $output_vars .= $output_var . "\n";
6301 # &variable_pretty_output ($VAR, [@CONDS])
6302 # ----------------------------------------
6303 # Likewise, but pretty, i.e., we *split* the values at spaces. Use only
6304 # with variables holding filenames.
6305 sub variable_pretty_output ($@)
6307 my ($var, @conds) = @_;
6309 @conds = sort by_condition keys %{$var_value{$var}}
6312 $output_vars .= $var_comment{$var}
6313 if defined $var_comment{$var};
6315 foreach my $cond (@conds)
6317 my $val = $var_value{$var}{$cond};
6318 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6319 my $make_condition = make_condition ($cond);
6320 $output_vars .= pretty_print_internal ("$make_condition$var $equals",
6321 "$make_condition\t",
6322 split (' ' , $val));
6327 # This is just a wrapper for variable_value_as_list_worker that
6328 # initializes the global hash `vars_scanned'. This hash is used to
6329 # avoid infinite recursion.
6330 sub variable_value_as_list
6332 my ($var, $cond, $parent) = @_;
6334 return &variable_value_as_list_worker ($var, $cond, $parent);
6338 # Like define_variable, but the value is a list, and the variable may
6339 # be defined conditionally. The second argument is the conditional
6340 # under which the value should be defined; this should be the empty
6341 # string to define the variable unconditionally. The third argument
6342 # is a list holding the values to use for the variable. The value is
6343 # pretty printed in the output file.
6344 sub define_pretty_variable
6346 my ($var, $cond, @value) = @_;
6348 # Beware that an empty $cond has a different semantics for
6349 # macro_define and variable_pretty_output.
6352 if (! &variable_defined ($var, $cond))
6354 macro_define ($var, 1, '', $cond, join (' ', @value), undef);
6355 variable_pretty_output ($var, $cond || 'TRUE');
6356 $content_seen{$var} = 1;
6361 # define_variable ($VAR, $VALUE)
6362 # ------------------------------
6363 # Define a new user variable VAR to VALUE, but only if not already defined.
6366 my ($var, $value) = @_;
6368 define_pretty_variable ($var, 'TRUE', $value);
6372 # Like define_variable, but define a variable to be the configure
6373 # substitution by the same name.
6374 sub define_configure_variable
6377 my $value = '@' . $var . '@';
6378 &define_variable ($var, $value);
6382 # define_compiler_variable ($LANG)
6383 # --------------------------------
6384 # Define a compiler variable. We also handle defining the `LT'
6385 # version of the command when using libtool.
6386 sub define_compiler_variable ($)
6390 my ($var, $value) = ($lang->compiler, $lang->compile);
6391 &define_variable ($var, $value);
6392 &define_variable ("LT$var", "\$(LIBTOOL) --mode=compile $value")
6397 # define_linker_variable ($LANG)
6398 # ------------------------------
6399 # Define linker variables.
6400 sub define_linker_variable ($)
6404 my ($var, $value) = ($lang->lder, $lang->ld);
6406 &define_variable ($lang->lder, $lang->ld);
6407 # CCLINK = $(CCLD) blah blah...
6408 &define_variable ($lang->linker,
6409 (($seen_libtool ? '$(LIBTOOL) --mode=link ' : '')
6413 ################################################################
6415 ## ---------------- ##
6416 ## Handling rules. ##
6417 ## ---------------- ##
6419 sub rule_define ($$$$)
6421 my ($target, $rule_is_am, $cond, $where) = @_;
6423 if (defined $targets{$target}
6425 ? ! defined $target_conditional{$target}
6426 : defined $target_conditional{$target}))
6428 &am_line_error ($target,
6429 "$target defined both conditionally and unconditionally");
6432 # Value here doesn't matter; for targets we only note existence.
6433 $targets{$target} = $where;
6436 if ($target_conditional{$target})
6438 &check_ambiguous_conditional ($target, $cond);
6440 $target_conditional{$target}{$cond} = $where;
6444 # Check the rule for being a suffix rule. If so, store in a hash.
6446 if ((my ($source_suffix, $object_suffix)) = ($target =~ $SUFFIX_RULE_PATTERN))
6448 $suffix_rules{$source_suffix} = $object_suffix;
6449 print "Sources ending in .$source_suffix become .$object_suffix\n"
6451 # Set SUFFIXES from suffix_rules.
6452 push @suffixes, ".$source_suffix", ".$object_suffix";
6457 # See if a target exists.
6461 return defined $targets{$target};
6465 ################################################################
6467 # Read Makefile.am and set up %contents. Simultaneously copy lines
6468 # from Makefile.am into $output_trailer or $output_vars as
6469 # appropriate. NOTE we put rules in the trailer section. We want
6470 # user rules to come after our generated stuff.
6475 my $am_file = new IO::File ("< $amfile");
6478 die "$me: couldn't open `$amfile': $!\n";
6480 print "$me: reading $amfile\n" if $verbose;
6486 while ($_ = $am_file->getline)
6488 if (/$IGNORE_PATTERN/o)
6490 # Merely delete comments beginning with two hashes.
6492 elsif (/$WHITE_PATTERN/o)
6494 # Stick a single white line before the incoming macro or rule.
6498 elsif (/$COMMENT_PATTERN/o)
6500 # Stick comments before the incoming macro or rule. Make
6501 # sure a blank line preceeds first block of comments.
6502 $spacing = "\n" unless $blank;
6504 $comment .= $spacing . $_;
6513 $output_vars .= $comment . "\n";
6517 # We save the conditional stack on entry, and then check to make
6518 # sure it is the same on exit. This lets us conditonally include
6520 my @saved_cond_stack = @cond_stack;
6521 my $cond = conditional_string (@cond_stack);
6525 my $last_var_name = '';
6526 my $last_var_type = '';
6527 my $last_var_value = '';
6528 # FIXME: shouldn't use $_ in this loop; it is too big.
6532 unless substr ($_, -1, 1) eq "\n";
6534 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
6535 # used by users. @MAINT@ is an anachronism now.
6536 $_ =~ s/\@MAINT\@//g
6537 unless $seen_maint_mode;
6539 my $new_saw_bk = /\\$/ && ! /$COMMENT_PATTERN/o;
6541 if (/$IGNORE_PATTERN/o)
6543 # Merely delete comments beginning with two hashes.
6545 elsif (/$WHITE_PATTERN/o)
6547 # Stick a single white line before the incoming macro or rule.
6549 &am_line_error ($., "blank line following trailing backslash")
6552 elsif (/$COMMENT_PATTERN/o)
6554 # Stick comments before the incoming macro or rule.
6555 $comment .= $spacing . $_;
6557 &am_line_error ($., "comment following trailing backslash")
6564 $output_trailer .= &make_condition (@cond_stack);
6565 $output_trailer .= $_;
6569 $last_var_value .= ' '
6570 unless $last_var_value =~ /\s$/;
6571 $last_var_value .= $_;
6575 $var_comment{$last_var_name} .= "$spacing"
6576 if (!defined $var_comment{$last_var_name}
6577 || substr ($var_comment{$last_var_name}, -1) ne "\n");
6578 $var_comment{$last_var_name} .= "$comment";
6579 $comment = $spacing = '';
6580 macro_define ($last_var_name, 0,
6581 $last_var_type, $cond,
6582 $last_var_value, $.)
6583 if $cond ne 'FALSE';
6584 push (@var_list, $last_var_name);
6589 elsif (/$IF_PATTERN/o)
6591 $cond = cond_stack_if ($1, $2, "$amfile:$.");
6593 elsif (/$ELSE_PATTERN/o)
6595 $cond = cond_stack_else ($1, $2, "$amfile:$.");
6597 elsif (/$ENDIF_PATTERN/o)
6599 $cond = cond_stack_endif ($1, $2, "$amfile:$.");
6602 elsif (/$RULE_PATTERN/o)
6607 rule_define ($1, 0, $cond, $.);
6610 $output_trailer .= $comment . $spacing;
6611 $output_trailer .= &make_condition (@cond_stack);
6612 $output_trailer .= $_;
6613 $comment = $spacing = '';
6615 elsif (/$ASSIGNMENT_PATTERN/o)
6617 # Found a macro definition.
6619 $last_var_name = $1;
6620 $last_var_type = $2;
6621 $last_var_value = $3;
6622 if ($3 ne '' && substr ($3, -1) eq "\\")
6624 # We preserve the `\' because otherwise the long lines
6625 # that are generated will be truncated by broken
6627 $last_var_value = $3 . "\n";
6632 # FIXME: this doesn't always work correctly; it will
6633 # group all comments for a given variable, no matter
6635 # Accumulating variables must not be output.
6636 $var_comment{$last_var_name} .= "$spacing"
6637 if (!defined $var_comment{$last_var_name}
6638 || substr ($var_comment{$last_var_name}, -1) ne "\n");
6639 $var_comment{$last_var_name} .= "$comment";
6640 $comment = $spacing = '';
6642 macro_define ($last_var_name, 0,
6643 $last_var_type, $cond,
6644 $last_var_value, $.)
6645 if $cond ne 'FALSE';
6646 push (@var_list, $last_var_name);
6649 elsif (/$INCLUDE_PATTERN/o)
6653 if ($path =~ s/^\$\(top_srcdir\)\///)
6655 push (@include_stack, "\$\(top_srcdir\)/$path");
6659 $path =~ s/\$\(srcdir\)\///;
6660 push (@include_stack, "\$\(srcdir\)/$path");
6661 $path = $relative_dir . "/" . $path;
6663 &read_am_file ($path);
6667 # This isn't an error; it is probably a continued rule.
6668 # In fact, this is what we assume.
6670 $output_trailer .= $comment . $spacing;
6671 $output_trailer .= &make_condition (@cond_stack);
6672 $output_trailer .= $_;
6673 $comment = $spacing = '';
6674 &am_line_error ($., "`#' comment at start of rule is unportable")
6675 if $_ =~ /^\t\s*\#/;
6678 $saw_bk = $new_saw_bk;
6679 $_ = $am_file->getline;
6682 $output_trailer .= $comment;
6684 if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
6688 &am_error ("unterminated conditionals: @cond_stack");
6692 # FIXME: better error message here.
6693 &am_error ("conditionals not nested in include file");
6699 # define_standard_variables ()
6700 # ----------------------------
6701 # A helper for read_main_am_file which initializes configure variables
6702 # and variables from header-vars.am. This is a subr so we can call it
6704 sub define_standard_variables
6706 my $saved_output_vars = $output_vars;
6707 my ($comments, undef, $rules) =
6708 file_contents_internal (1, "$libdir/am/header-vars.am");
6710 # This will output the definitions in $output_vars, which we don't
6712 foreach my $var (sort keys %configure_vars)
6714 &define_configure_variable ($var);
6715 push (@var_list, $var);
6718 # ... hence, we restore $output_vars.
6719 $output_vars = $saved_output_vars . $comments . $rules;
6722 # Read main am file.
6723 sub read_main_am_file
6727 # This supports the strange variable tricks we are about to play.
6728 if (scalar keys %var_value > 0)
6731 &prog_error ("variable defined before read_main_am_file");
6734 # Generate copyright header for generated Makefile.in.
6735 # We do discard the output of predefined variables, handled below.
6736 $output_vars = ("# $in_file_name generated automatically by automake "
6737 . $VERSION . " from $am_file_name.\n");
6738 $output_vars .= $gen_copyright;
6740 # We want to predefine as many variables as possible. This lets
6741 # the user set them with `+=' in Makefile.am. However, we don't
6742 # want these initial definitions to end up in the output quite
6743 # yet. So we just load them, but output them later.
6744 &define_standard_variables;
6746 # Read user file, which might override some of our values.
6747 &read_am_file ($amfile);
6749 # Ouput all the Automake variables. If the user changed one, then
6750 # it is now marked as owned by the user.
6751 foreach my $var (uniq @var_list)
6753 # Don't process user variables.
6754 variable_output ($var)
6755 unless !$var_is_am{$var};
6758 # Now dump the user variables that were defined. We do it in the same
6759 # order in which they were defined (skipping duplicates).
6760 foreach my $var (uniq @var_list)
6762 # Don't process Automake variables.
6763 variable_output ($var)
6764 unless $var_is_am{$var};
6768 ################################################################
6771 # &flatten ($STRING)
6772 # ------------------
6773 # Flatten the $STRING and return the result.
6788 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
6789 # ------------------------------------------
6790 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6792 sub make_paragraphs ($%)
6794 my ($file, %transform) = @_;
6796 # Complete %transform with global options and make it a Perl
6799 "s/$IGNORE_PATTERN//gm;"
6800 . transform (%transform,
6802 'CYGNUS' => $cygnus_mode,
6804 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
6806 'SHAR' => $options{'dist-shar'} || 0,
6807 'BZIP2' => $options{'dist-bzip2'} || 0,
6808 'ZIP' => $options{'dist-zip'} || 0,
6809 'COMPRESS' => $options{'dist-tarZ'} || 0,
6811 'INSTALL-INFO' => !$options{'no-installinfo'},
6812 'INSTALL-MAN' => !$options{'no-installman'},
6813 'CK-NEWS' => $options{'check-news'} || 0,
6815 'SUBDIRS' => &variable_defined ('SUBDIRS'),
6816 'TOPDIR' => backname ($relative_dir),
6817 'TOPDIR_P' => $relative_dir eq '.',
6818 'CONFIGURE-AC' => $configure_ac,
6820 'BUILD' => $seen_canonical == $AC_CANONICAL_SYSTEM,
6821 'HOST' => $seen_canonical,
6822 'TARGET' => $seen_canonical == $AC_CANONICAL_SYSTEM,
6824 'LIBTOOL' => defined $configure_vars{'LIBTOOL'})
6825 # We don't need more than two consecutive new-lines.
6826 . 's/\n{3,}/\n\n/g';
6828 # Swallow the file and apply the COMMAND.
6829 my $fc_file = new IO::File ("< $file");
6832 die "$me: installation error: cannot open `$file'\n";
6835 print "$me: reading $file\n"
6837 my $saved_dollar_slash = $/;
6839 $_ = $fc_file->getline;
6840 $/ = $saved_dollar_slash;
6845 # Split at unescaped new lines.
6846 my @lines = split (/(?<!\\)\n/, $content);
6849 while (defined ($_ = shift @lines))
6851 my $paragraph = "$_";
6852 # If we are a rule, eat as long as we start with a tab.
6853 if (/$RULE_PATTERN/smo)
6855 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
6857 $paragraph .= "\n$_";
6859 unshift (@lines, $_);
6862 # If we are a comments, eat as much comments as you can.
6863 elsif (/$COMMENT_PATTERN/smo)
6865 while (defined ($_ = shift @lines)
6866 && $_ =~ /$COMMENT_PATTERN/smo)
6868 $paragraph .= "\n$_";
6870 unshift (@lines, $_);
6873 push @res, $paragraph;
6882 # ($COMMENT, $VARIABLES, $RULES)
6883 # &file_contents_internal ($IS_AM, $FILE, [%TRANSFORM])
6884 # -----------------------------------------------------
6885 # Return contents of a file from $libdir/am, automatically skipping
6886 # macros or rules which are already known. $IS_AM iff the caller is
6887 # reading an Automake file (as opposed to the user's Makefile.am).
6888 sub file_contents_internal ($$%)
6890 my ($is_am, $file, %transform) = @_;
6892 my $result_vars = '';
6893 my $result_rules = '';
6897 # We save the conditional stack on entry, and then check to make
6898 # sure it is the same on exit. This lets us conditonally include
6900 my @saved_cond_stack = @cond_stack;
6901 my $cond = conditional_string (@cond_stack);
6903 foreach (make_paragraphs ($file, %transform))
6906 &am_file_error ($file, "blank line following trailing backslash:\n$_")
6908 &am_file_error ($file, "comment following trailing backslash:\n$_")
6913 # Stick empty line before the incoming macro or rule.
6916 elsif (/$COMMENT_PATTERN/mso)
6918 # Stick comments before the incoming macro or rule.
6922 # Handle inclusion of other files.
6923 elsif (/$INCLUDE_PATTERN/o)
6925 if ($cond ne 'FALSE')
6927 my $file = ($is_am ? "$libdir/am/" : '') . $1;
6929 my ($com, $vars, $rules)
6930 = file_contents_internal ($is_am, $file, %transform);
6932 $result_vars .= $vars;
6933 $result_rules .= $rules;
6937 # Handling the conditionals.
6938 elsif (/$IF_PATTERN/o)
6940 $cond = cond_stack_if ($1, $2, $file);
6942 elsif (/$ELSE_PATTERN/o)
6944 $cond = cond_stack_else ($1, $2, $file);
6946 elsif (/$ENDIF_PATTERN/o)
6948 $cond = cond_stack_endif ($1, $2, $file);
6952 elsif (/$RULE_PATTERN/mso)
6954 # Separate relationship from optional actions: the first
6955 # `new-line tab" not preceded by backslash (continuation
6957 # I'm quite shoked! It seems that (\\\n|[^\n]) is not the
6958 # same as `([^\n]|\\\n)!!! Don't swap it, it breaks.
6960 /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
6961 my ($relationship, $actions) = ($1, $2 || '');
6963 # Separate targets from dependencies: the first colon.
6964 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
6965 my ($targets, $dependencies) = ($1, $2);
6966 # Remove the escaped new lines.
6967 # I don't know why, but I have to use a tmp $flat_deps.
6968 my $flat_deps = &flatten ($dependencies);
6969 my @deps = split (' ', $flat_deps);
6971 foreach (split (' ' , $targets))
6973 # FIXME: We are not robust to people defining several targets
6974 # at once, only some of them being in %dependencies.
6976 # Output only if not in FALSE.
6977 if (defined $dependencies{$_}
6978 && $cond ne 'FALSE')
6980 &depend ($_, @deps);
6981 $actions{$_} .= $actions;
6985 # Free lance dependency. Output the rule for all the
6986 # targets instead of one by one.
6987 if (!defined $targets{$targets}
6988 && $cond ne 'FALSE')
6990 $paragraph =~ s/^/make_condition (@cond_stack)/gme;
6991 $result_rules .= "$spacing$comment$paragraph\n";
6992 rule_define ($targets, $is_am, $cond, $file);
6994 $comment = $spacing = '';
7000 elsif (/$ASSIGNMENT_PATTERN/mso)
7002 my ($var, $type, $val) = ($1, $2, $3);
7003 &am_file_error ($file, "macro `$var' with trailing backslash")
7006 # Accumulating variables must not be output.
7007 $var_comment{$var} .= "$spacing"
7008 if (!defined $var_comment{$var}
7009 || substr ($var_comment{$var}, -1) ne "\n");
7010 $var_comment{$var} .= "$comment";
7011 macro_define ($var, $is_am, $type, $cond, $val, $file)
7012 if $cond ne 'FALSE';
7013 push (@var_list, $var);
7015 # If the user has set some variables we were in charge
7016 # of (which is detected by the first reading of
7017 # `header-vars.am'), we must not output them.
7018 $result_vars .= "$spacing$comment$_\n"
7019 if $type ne '+' && $var_is_am{$var} && $cond ne 'FALSE';
7021 $comment = $spacing = '';
7025 # This isn't an error; it is probably some tokens which
7026 # configure is supposed to replace, such as `@SET-MAKE@',
7027 # or some part of a rule cut by an if/endif.
7028 if ($cond ne 'FALSE')
7030 s/^/make_condition (@cond_stack)/gme;
7031 $result_rules .= "$spacing$comment$_\n";
7033 $comment = $spacing = '';
7037 if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
7041 &am_error ("unterminated conditionals: @cond_stack");
7045 # FIXME: better error message here.
7046 &am_error ("conditionals not nested in include file");
7050 return ($comment, $result_vars, $result_rules);
7055 # &file_contents ($BASENAME, [%TRANSFORM])
7056 # ----------------------------------------
7057 # Return contents of a file from $libdir/am, automatically skipping
7058 # macros or rules which are already known.
7059 sub file_contents ($%)
7061 my ($basename, %transform) = @_;
7062 my ($comments, $variables, $rules) =
7063 file_contents_internal (1, "$libdir/am/$basename.am", %transform);
7064 return "$comments$variables$rules";
7069 # &transform (%PAIRS)
7070 # -------------------
7071 # Foreach ($TOKEN, $VAL) in %PAIRS produce a replacement expression suitable
7072 # for file_contents which:
7073 # - replaces @$TOKEN@ with $VALUE,
7074 # - enables/disables ?$TOKEN?.
7080 while (my ($token, $val) = each %pairs)
7082 $result .= "s/\Q%$token%\E/\Q$val\E/gm;";
7085 $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
7086 $result .= "s/\Q%?$token%\E/TRUE/gm;";
7090 $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
7091 $result .= "s/\Q%?$token%\E/FALSE/gm;";
7099 # Find all variable prefixes that are used for install directories. A
7100 # prefix `zar' qualifies iff:
7101 # * `zardir' is a variable.
7102 # * `zar_PRIMARY' is a variable.
7103 sub am_primary_prefixes
7105 my ($primary, $can_dist, @prefixes) = @_;
7107 my %valid = map { $_ => 0 } @prefixes;
7108 $valid{'EXTRA'} = 0;
7109 foreach my $varname (keys %var_value)
7111 # Automake is allowed to define variables that look like they
7112 # are magic variables, such as INSTALL_DATA.
7114 if $var_is_am{$varname};
7116 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
7118 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
7119 if ($dist ne '' && ! $can_dist)
7121 # Note that a configure variable is always legitimate.
7122 # It is natural to name such variables after the
7123 # primary, so we explicitly allow it.
7124 if (! defined $configure_vars{$varname})
7126 &am_line_error ($varname,
7127 "invalid variable `$varname': `dist' is forbidden");
7130 elsif (! defined $valid{$X} && ! &variable_defined ("${X}dir"))
7132 # Note that a configure variable is always legitimate.
7133 # It is natural to name such variables after the
7134 # primary, so we explicitly allow it.
7135 if (! defined $configure_vars{$varname})
7137 &am_line_error ($varname,
7138 "invalid variable `$varname'");
7143 # Ensure all extended prefixes are actually used.
7144 $valid{"$base$dist$X"} = 1;
7152 # Handle `where_HOW' variable magic. Does all lookups, generates
7153 # install code, and possibly generates code to define the primary
7154 # variable. The first argument is the name of the .am file to munge,
7155 # the second argument is the primary variable (eg HEADERS), and all
7156 # subsequent arguments are possible installation locations. Returns
7157 # list of all values of all _HOW targets.
7159 # FIXME: this should be rewritten to be cleaner. It should be broken
7160 # up into multiple functions.
7162 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7169 my $default_dist = 0;
7172 if ($args[0] eq '-noextra')
7176 elsif ($args[0] eq '-candist')
7180 elsif ($args[0] eq '-defaultdist')
7185 elsif ($args[0] !~ /^-/)
7192 my ($file, $primary, @prefixes) = @args;
7194 # Now that configure substitutions are allowed in where_HOW
7195 # variables, it is an error to actually define the primary. We
7196 # allow `JAVA', as it is customarily used to mean the Java
7197 # interpreter. This is but one of several Java hacks. Similarly,
7198 # `PYTHON' is customarily used to mean the Python interpreter.
7199 &am_line_error ($primary, "`$primary' is an anachronism")
7200 if &variable_defined ($primary)
7201 && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7204 # Look for misspellings. It is an error to have a variable ending
7205 # in a "reserved" suffix whose prefix is unknown, eg
7206 # "bni_PROGRAMS". However, unusual prefixes are allowed if a
7207 # variable of the same name (with "dir" appended) exists. For
7208 # instance, if the variable "zardir" is defined, then
7209 # "zar_PROGRAMS" becomes valid. This is to provide a little extra
7210 # flexibility in those cases which need it.
7211 my %valid = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7213 # If a primary includes a configure substitution, then the EXTRA_
7214 # form is required. Otherwise we can't properly do our job.
7216 my $warned_about_extra = 0;
7221 # True if the iteration is the first one. Used for instance to
7222 # output parts of the associated file only once.
7224 foreach my $X (sort keys %valid)
7226 my $one_name = $X . '_' . $primary;
7228 unless (&variable_defined ($one_name));
7230 my $strip_subdir = 1;
7231 # If subdir prefix should be preserved, do so.
7232 if ($X =~ /^nobase_/)
7238 my $nodir_name = $X;
7239 # If files should be distributed, do so.
7243 $dist_p = (($default_dist && $one_name !~ /^nodist_/)
7244 || (! $default_dist && $one_name =~ /^dist_/));
7245 $nodir_name =~ s/^(dist|nodist)_//;
7248 # Append actual contents of where_PRIMARY variable to
7250 foreach my $rcurs (&variable_value_as_list ($one_name, 'all'))
7252 # Skip configure substitutions. Possibly bogus.
7253 if ($rcurs =~ /^\@.*\@$/)
7257 if (! $warned_about_extra)
7259 $warned_about_extra = 1;
7260 &am_line_error ($one_name,
7261 "`$one_name' contains configure substitution, but shouldn't");
7264 # Check here to make sure variables defined in
7265 # configure.ac do not imply that EXTRA_PRIMARY
7267 elsif (! defined $configure_vars{$one_name})
7269 $require_extra = $one_name
7276 push (@result, $rcurs);
7279 # A blatant hack: we rewrite each _PROGRAMS primary to include
7280 # EXEEXT when in Cygwin32 mode. You might think we could
7281 # simply always use $(EXEEXT), since we define it as empty
7282 # when it isn't available. However, it isn't that simple.
7284 if ($seen_exeext && $primary eq 'PROGRAMS')
7286 my @conds = &variable_conditions ($one_name);
7289 foreach my $cond (@conds)
7291 my @one_binlist = ();
7292 my @condval = &variable_value_as_list ($one_name,
7294 foreach my $rcurs (@condval)
7296 # Skip autoconf substs. Also skip if the user
7297 # already applied $(EXEEXT).
7298 if ($rcurs =~ /^\@.*\@$/ || $rcurs =~ /\$\(EXEEXT\)$/)
7300 push (@one_binlist, $rcurs);
7304 push (@one_binlist, $rcurs . '$(EXEEXT)');
7308 push (@condvals, $cond);
7309 push (@condvals, join (' ', @one_binlist));
7312 variable_delete ($one_name);
7315 my $cond = shift (@condvals);
7316 my @val = split (' ', shift (@condvals));
7317 &define_pretty_variable ($one_name, $cond, @val);
7321 # "EXTRA" shouldn't be used when generating clean targets,
7322 # all, or install targets.
7325 # We used to warn if EXTRA_FOO was defined uselessly,
7326 # but this was annoying.
7332 push (@check, '$(' . $one_name . ')');
7336 push (@used, '$(' . $one_name . ')');
7339 # Is this to be installed?
7340 my $install_p = $X ne 'noinst' && $X ne 'check';
7342 # If so, with install-exec? (or install-data?).
7343 my $exec_p = (defined $exec_dir_p {$X}
7347 # Singular form of $PRIMARY.
7348 (my $one_primary = $primary) =~ s/S$//;
7349 $output_rules .= &file_contents ($file,
7352 'PRIMARY' => $primary,
7353 'ONE_PRIMARY' => $one_primary,
7355 'NDIR' => $nodir_name,
7356 'BASE' => $strip_subdir,
7359 'INSTALL' => $install_p,
7360 'DIST' => $dist_p));
7365 # The JAVA variable is used as the name of the Java interpreter.
7366 # The PYTHON variable is used as the name of the Python interpreter.
7367 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7370 &define_pretty_variable ($primary, '', @used);
7371 $output_vars .= "\n";
7374 if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7376 &am_line_error ($require_extra,
7377 "`$require_extra' contains configure substitution, but `EXTRA_$primary' not defined");
7380 # Push here because PRIMARY might be configure time determined.
7381 push (@all, '$(' . $primary . ')')
7382 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7384 # Make the result unique. This lets the user use conditionals in
7385 # a natural way, but still lets us program lazily -- we don't have
7386 # to worry about handling a particular object more than once.
7387 return uniq (sort @result);
7391 ################################################################
7393 # Each key in this hash is the name of a directory holding a
7394 # Makefile.in. These variables are local to `is_make_dir'.
7396 my $make_dirs_set = 0;
7401 if (! $make_dirs_set)
7403 foreach my $iter (@configure_input_files)
7405 $make_dirs{dirname ($iter)} = 1;
7407 # We also want to notice Makefile.in's.
7408 foreach my $iter (@other_input_files)
7410 if ($iter =~ /Makefile\.in$/)
7412 $make_dirs{dirname ($iter)} = 1;
7417 return defined $make_dirs{$dir};
7420 ################################################################
7422 # This variable is local to the "require file" set of functions.
7423 my @require_file_paths = ();
7425 # If a file name appears as a key in this hash, then it has already
7426 # been checked for. This variable is local to the "require file"
7428 %require_file_found = ();
7430 # See if we want to push this file onto dist_common. This function
7431 # encodes the rules for deciding when to do so.
7432 sub maybe_push_required_file
7434 my ($dir, $file, $fullfile) = @_;
7436 if ($dir eq $relative_dir)
7438 &push_dist_common ($file);
7440 elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7442 # If we are doing the topmost directory, and the file is in a
7443 # subdir which does not have a Makefile, then we distribute it
7445 &push_dist_common ($fullfile);
7450 # &require_file_internal ($IS_CONFIGURE, $LINE, $MYSTRICT, @FILES)
7451 # ----------------------------------------------------------------
7452 # Verify that the file must exist in the current directory.
7453 # $MYSTRICT is the strictness level at which this file becomes required.
7455 # Must set require_file_paths before calling this function.
7456 # require_file_paths is set to hold a single directory (the one in
7457 # which the first file was found) before return.
7458 sub require_file_internal
7460 my ($is_configure, $line, $mystrict, @files) = @_;
7462 foreach my $file (@files)
7470 my $dangling_sym = 0;
7471 foreach my $dir (@require_file_paths)
7473 $fullfile = $dir . "/" . $file;
7474 $errdir = $dir unless $errdir;
7476 # Use different name for "error filename". Otherwise on
7477 # an error the bad file will be reported as eg
7478 # `../../install-sh' when using the default
7480 $errfile = $errdir . '/' . $file;
7482 if (-l $fullfile && ! -f $fullfile)
7487 elsif (-f $fullfile)
7490 &maybe_push_required_file ($dir, $file, $fullfile);
7496 # `--force-missing' only has an effect if `--add-missing' is
7498 if ($found_it && (! $add_missing || ! $force_missing))
7500 # Prune the path list.
7501 @require_file_paths = $save_dir;
7505 # If we've already looked for it, we're done. You might
7506 # wonder why we don't do this before searching for the
7507 # file. If we do that, then something like
7508 # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
7512 next if defined $require_file_found{$file};
7513 $require_file_found{$file} = 1;
7516 if ($strictness >= $mystrict)
7518 if ($dangling_sym && $add_missing)
7526 # Only install missing files according to our desired
7528 my $message = "required file `$errfile' not found";
7533 # Maybe run libtoolize.
7534 my @syslist = ('libtoolize', '--automake');
7535 push @syslist, '--copy'
7538 && grep ($_ eq $file, @libtoolize_files)
7539 && system (@syslist))
7541 $message = "installing `$errfile'";
7543 $trailer = "; cannot run `libtoolize': $!";
7545 elsif (-f ("$libdir/$file"))
7547 # Install the missing file. Symlink if we
7548 # can, copy if we must. Note: delete the file
7549 # first, in case it is a dangling symlink.
7550 $message = "installing `$errfile'";
7551 # Windows Perl will hang if we try to delete a
7552 # file that doesn't exist.
7553 unlink ($errfile) if -f $errfile;
7554 if ($symlink_exists && ! $copy_missing)
7556 if (! symlink ("$libdir/$file", $errfile))
7559 $trailer = "; error while making link: $!";
7562 elsif (system ('cp', "$libdir/$file", $errfile))
7565 $trailer = "\n error while copying";
7569 &maybe_push_required_file (dirname ($errfile),
7572 # Prune the path list.
7573 @require_file_paths = &dirname ($errfile);
7576 # If --force-missing was specified, and we have
7577 # actually found the file, then do nothing.
7579 if $found_it && $force_missing;
7585 # FIXME: allow actual file to be specified.
7586 &am_conf_line_warning ($configure_ac, $line,
7587 "$message$trailer");
7591 &am_line_warning ($line, "$message$trailer");
7598 # FIXME: allow actual file to be specified.
7599 &am_conf_line_error ($configure_ac, $line,
7600 "$message$trailer");
7604 &am_line_error ($line, "$message$trailer");
7612 # Like require_file_with_line, but error messages refer to
7613 # configure.ac, not the current Makefile.am.
7614 sub require_file_with_conf_line
7616 @require_file_paths = $relative_dir;
7617 &require_file_internal (1, @_);
7620 sub require_file_with_line
7622 @require_file_paths = $relative_dir;
7623 &require_file_internal (0, @_);
7628 @require_file_paths = $relative_dir;
7629 &require_file_internal (0, '', @_);
7632 # Require a file that is also required by Autoconf. Looks in
7633 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7634 sub require_config_file
7636 @require_file_paths = @config_aux_path;
7637 &require_file_internal (1, '', @_);
7638 my $dir = $require_file_paths[0];
7639 @config_aux_path = @require_file_paths;
7640 # Avoid unsightly '/.'s.
7641 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7644 # Assumes that the line number is in Makefile.am.
7645 sub require_conf_file_with_line
7647 @require_file_paths = @config_aux_path;
7648 &require_file_internal (0, @_);
7649 my $dir = $require_file_paths[0];
7650 @config_aux_path = @require_file_paths;
7651 # Avoid unsightly '/.'s.
7652 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7655 # Assumes that the line number is in configure.ac.
7656 sub require_conf_file_with_conf_line
7658 @require_file_paths = @config_aux_path;
7659 &require_file_internal (1, @_);
7660 my $dir = $require_file_paths[0];
7661 @config_aux_path = @require_file_paths;
7662 # avoid unsightly '/.'s.
7663 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7666 ################################################################
7668 # &require_build_directory ($DIRECTORY)
7669 # ------------------------------------
7670 # Emit rules to create $DIRECTORY if needed, and return
7671 # the file that any target requiring this directory should be made
7673 sub require_build_directory ($)
7675 my $directory = shift;
7676 my $dirstamp = "$directory/.dirstamp";
7678 # Don't emit the rule twice.
7679 if (! defined $directory_map{$directory})
7681 $directory_map{$directory} = 1;
7683 # Directory must be removed by `make distclean'.
7684 $compile_clean_files{$dirstamp} = $DIST_CLEAN;
7686 $output_rules .= ("$dirstamp:\n"
7687 . "\t\@\$(mkinstalldirs) $directory\n"
7688 . "\t\@: > $dirstamp\n");
7694 # &require_build_directory_maybe ($FILE)
7695 # --------------------------------------
7696 # If $FILE lies in a subdirectory, emit a rule to create this
7697 # directory and return the file that $FILE should be made
7698 # dependent upon. Otherwise, just return the empty string.
7699 sub require_build_directory_maybe ($)
7702 my $directory = dirname ($file);
7704 if ($directory ne '.')
7706 return &require_build_directory ($directory);
7714 ################################################################
7716 # Push a list of files onto dist_common.
7717 sub push_dist_common
7719 &prog_error ("push_dist_common run after handle_dist")
7720 if $handle_dist_run;
7721 macro_define ('DIST_COMMON', 1, '+', '', join (' ', @_), '');
7728 $strictness_name = $_[0];
7729 if ($strictness_name eq 'gnu')
7733 elsif ($strictness_name eq 'gnits')
7735 $strictness = $GNITS;
7737 elsif ($strictness_name eq 'foreign')
7739 $strictness = $FOREIGN;
7743 die "$me: level `$strictness_name' not recognized\n";
7748 ################################################################
7750 # Ensure a file exists.
7755 my $touch = new IO::File (">> $file");
7759 # Glob something. Do this to avoid indentation screwups everywhere we
7760 # want to glob. Gross!
7767 # Remove one level of brackets and strip leading spaces,
7768 # as does m4 to function arguments.
7774 my @letters = split //;
7783 next if $depth == 1;
7788 next if $depth == 0;
7789 # don't count orphan right brackets
7790 $depth = 0 if $depth < 0;
7794 return join '', @result;
7797 ################################################################
7799 # Print an error message and set exit status.
7802 warn "$me: ${am_file}.am: @_\n";
7806 # am_file_error ($FILE, @ARGS)
7807 # ----------------------------
7810 my ($file, @args) = @_;
7812 warn "$file: @args\n";
7818 my ($symbol, @args) = @_;
7820 if ($symbol && "$symbol" ne '-1')
7822 my $file = "${am_file}.am";
7824 if ($symbol =~ /^\d+$/)
7826 # SYMBOL is a line number, so just add the colon.
7827 $file .= ':' . $symbol;
7829 elsif (defined $var_line{$symbol})
7831 # SYMBOL is a variable defined in Makefile.am, so add the
7832 # line number we saved from there.
7833 $file .= ':' . $var_line{$symbol};
7835 elsif (defined $configure_vars{$symbol})
7837 # SYMBOL is a variable defined in configure.ac, so add the
7838 # appropriate line number.
7839 $file = $configure_vars{$symbol};
7843 # Couldn't find the line number.
7845 warn $file, ": @args\n";
7854 # Like am_error, but while scanning configure.ac.
7857 # FIXME: can run in subdirs.
7858 warn "$me: $configure_ac: @_\n";
7862 # Error message with line number referring to configure.ac.
7863 sub am_conf_line_error
7865 my ($file, $line, @args) = @_;
7869 warn "$file: $line: @args\n";
7874 &am_conf_error (@args);
7878 # Warning message with line number referring to configure.ac.
7879 # Does not affect exit_status
7880 sub am_conf_line_warning
7882 my $saved_exit_status = $exit_status;
7883 my $sig = $SIG{'__WARN__'};
7884 $SIG{'__WARN__'} = 'DEFAULT';
7885 am_conf_line_error (@_);
7886 $exit_status = $saved_exit_status;
7887 $SIG{'__WARN__'} = $sig;
7890 # Like am_line_error, but doesn't affect exit status.
7893 my $saved_exit_status = $exit_status;
7894 my $sig = $SIG{'__WARN__'};
7895 $SIG{'__WARN__'} = 'DEFAULT';
7897 $exit_status = $saved_exit_status;
7898 $SIG{'__WARN__'} = $sig;
7901 # Tell user where our aclocal.m4 is, but only once.
7902 sub keyed_aclocal_warning
7905 warn "$me: macro `$key' can be generated by `aclocal'\n";
7908 # Print usage information.
7912 Usage: $0 [OPTION] ... [Makefile]...
7914 Generate Makefile.in for configure from Makefile.am.
7917 --help print this help, then exit
7918 --version print version number, then exit
7919 -v, --verbose verbosely list files processed
7920 -o, --output-dir=DIR put generated Makefile.in's into DIR
7921 --no-force only update Makefile.in's that are out of date
7923 Dependency tracking:
7924 -i, --ignore-deps disable dependency tracking code
7925 --include-deps enable dependency tracking code
7928 --cygnus assume program is part of Cygnus-style tree
7929 --foreign set strictness to foreign
7930 --gnits set strictness to gnits
7931 --gnu set strictness to gnu
7934 -a, --add-missing add missing standard files to package
7935 --libdir=DIR directory storing library files
7936 -c, --copy with -a, copy missing files (default is symlink)
7937 -f, --force-missing force update of standard files
7942 foreach my $iter (sort ((@common_files, @common_sometimes)))
7944 push (@lcomm, $iter) unless $iter eq $last;
7949 print "\nFiles which are automatically distributed, if found:\n";
7950 format USAGE_FORMAT =
7951 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
7952 $four[0], $four[1], $four[2], $four[3]
7954 $~ = "USAGE_FORMAT";
7957 my $rows = int(@lcomm / $cols);
7958 my $rest = @lcomm % $cols;
7969 for (my $y = 0; $y < $rows; $y++)
7971 @four = ("", "", "", "");
7972 for (my $x = 0; $x < $cols; $x++)
7974 last if $y + 1 == $rows && $x == $rest;
7976 my $idx = (($x > $rest)
7977 ? ($rows * $rest + ($rows - 1) * ($x - $rest))
7981 $four[$x] = $lcomm[$idx];
7986 print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7993 # Print version information
7997 automake (GNU $PACKAGE) $VERSION
7998 Written by Tom Tromey <tromey\@cygnus.com>.
8000 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
8001 Free Software Foundation, Inc.
8002 This is free software; see the source for copying conditions. There is NO
8003 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.