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*$';
168 # This handles substitution references like ${foo:.a=.b}.
169 my $SUBST_REF_PATTERN = "^([^:]*):([^=]*)=(.*)\$";
171 # Note that there is no AC_PATH_TOOL. But we don't really care.
172 my $AC_CHECK_PATTERN = 'AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\(\[?(\w+)';
173 my $AM_MISSING_PATTERN = 'AM_MISSING_PROG\(\[?(\w+)';
174 # Just check for alphanumeric in AC_SUBST. If you do AC_SUBST(5),
176 my $AC_SUBST_PATTERN = 'AC_SUBST\(\[?(\w+)';
177 my $AM_CONDITIONAL_PATTERN = 'AM_CONDITIONAL\(\[?(\w+)';
178 # Match `-d' as a command-line argument in a string.
179 my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)";
181 # Constants to define the "strictness" level.
186 # Values for AC_CANONICAL_*
187 my $AC_CANONICAL_HOST = 1;
188 my $AC_CANONICAL_SYSTEM = 2;
190 # Values indicating when something should be cleaned. Right now we
191 # only need to handle `mostly'- and `dist'-clean; add more as
193 my $MOSTLY_CLEAN = 0;
196 # Files installed by libtoolize.
197 my @libtoolize_files = ('ltmain.sh', 'config.guess', 'config.sub');
198 # ltconfig appears here for compatibility with old versions of libtool.
199 my @libtoolize_sometimes = ('ltconfig', 'ltcf-c.sh', 'ltcf-cxx.sh',
202 # Commonly found files we look for and automatically include in
206 'README', 'THANKS', 'TODO', 'NEWS', 'COPYING', 'COPYING.LIB',
207 'INSTALL', 'ABOUT-NLS', 'ChangeLog', 'configure.ac',
208 'configure.in', 'configure', 'config.guess', 'config.sub',
209 'AUTHORS', 'BACKLOG', 'ABOUT-GNU', 'libversion.in',
210 'mdate-sh', 'mkinstalldirs', 'install-sh', 'texinfo.tex',
211 'ansi2knr.c', 'ansi2knr.1', 'elisp-comp',
212 # ltconfig appears here for compatibility with old versions
214 'ylwrap', 'acinclude.m4', @libtoolize_files, @libtoolize_sometimes,
215 'missing', 'depcomp', 'compile', 'py-compile'
218 # Commonly used files we auto-include, but only sometimes.
219 my @common_sometimes =
221 'aclocal.m4', 'acconfig.h', 'config.h.top',
222 'config.h.bot', 'stamp-h.in', 'stamp-vti'
225 # Copyright on generated Makefile.ins.
226 my $gen_copyright = "\
227 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
228 # Free Software Foundation, Inc.
229 # This Makefile.in is free software; the Free Software Foundation
230 # gives unlimited permission to copy and/or distribute it,
231 # with or without modifications, as long as this notice is preserved.
233 # This program is distributed in the hope that it will be useful,
234 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
235 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
236 # PARTICULAR PURPOSE.
239 # These constants are returned by lang_*_rewrite functions.
240 # LANG_SUBDIR means that the resulting object file should be in a
241 # subdir if the source file is. In this case the file name cannot
242 # have `..' components.
244 my $LANG_PROCESS = 1;
247 # Directories installed during 'install-exec' phase.
266 # Map from obsolete macros to hints for new macros.
267 # If you change this, change the corresponding list in aclocal.in.
268 # FIXME: should just put this into a single file.
269 my %obsolete_macros =
271 'AC_FEATURE_CTYPE' => "use `AC_HEADER_STDC'",
272 'AC_FEATURE_ERRNO' => "add `strerror' to `AC_REPLACE_FUNCS(...)'",
273 'AC_FEATURE_EXIT' => '',
274 'AC_SYSTEM_HEADER' => '',
276 # Note that we do not handle this one, because it is still run
277 # from AM_CONFIG_HEADER. So we deal with it specially in
278 # &scan_autoconf_files.
279 # 'AC_CONFIG_HEADER' => "use `AM_CONFIG_HEADER'",
281 'fp_C_PROTOTYPES' => "use `AM_C_PROTOTYPES'",
282 'fp_PROG_CC_STDC' => "use `AM_PROG_CC_STDC'",
283 'fp_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
284 'fp_WITH_DMALLOC' => "use `AM_WITH_DMALLOC'",
285 'fp_WITH_REGEX' => "use `AM_WITH_REGEX'",
286 'gm_PROG_LIBTOOL' => "use `AM_PROG_LIBTOOL'",
287 'jm_MAINTAINER_MODE' => "use `AM_MAINTAINER_MODE'",
288 'md_TYPE_PTRDIFF_T' => "use `AM_TYPE_PTRDIFF_T'",
289 'ud_PATH_LISPDIR' => "use `AM_PATH_LISPDIR'",
290 'ud_GNU_GETTEXT' => "use `AM_GNU_GETTEXT'",
292 # Now part of autoconf proper, under a different name.
293 'AM_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
294 'fp_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
295 'AM_SANITY_CHECK_CC' => "automatically done by `AC_PROG_CC'",
296 'AM_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
297 'AM_EXEEXT' => "use `AC_EXEEXT'",
298 'AM_CYGWIN32' => "use `AC_CYGWIN'",
299 'AM_MINGW32' => "use `AC_MINGW32'",
300 'AM_FUNC_MKTIME' => "use `AC_FUNC_MKTIME'",
302 # These aren't quite obsolete.
306 # Regexp to match the above macros.
307 my $obsolete_rx = '\b(' . join ('|', keys %obsolete_macros) . ')\b';
311 ## ---------------------------------- ##
312 ## Variables related to the options. ##
313 ## ---------------------------------- ##
315 # TRUE if we should always generate Makefile.in.
316 my $force_generation = 1;
318 # Strictness level as set on command line.
319 my $default_strictness = $GNU;
321 # Name of strictness level, as set on command line.
322 my $default_strictness_name = 'gnu';
324 # This is TRUE if automatic dependency generation code should be
325 # included in generated Makefile.in.
326 my $cmdline_use_dependencies = 1;
328 # TRUE if in verbose mode.
331 # This holds our (eventual) exit status. We don't actually exit until
332 # we have processed all input files.
335 # From the Perl manual.
336 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
338 # TRUE if missing standard files should be installed.
341 # TRUE if we should copy missing files; otherwise symlink if possible.
342 my $copy_missing = 0;
344 # TRUE if we should always update files that we know about.
345 my $force_missing = 0;
348 ## ---------------------------------------- ##
349 ## Variables filled during files scanning. ##
350 ## ---------------------------------------- ##
352 # Name of the top autoconf input: `configure.ac' or `configure.in'.
353 my $configure_ac = '';
355 # Files found by scanning configure.ac for LIBOBJS.
358 # True if AM_C_PROTOTYPES appears in configure.ac.
359 my $am_c_prototypes = 0;
361 # Names used in AC_CONFIG_HEADER call. @config_fullnames holds the
362 # name which appears in AC_CONFIG_HEADER, colon and all.
363 # @config_names holds the file names. @config_headers holds the '.in'
364 # files. Ordinarily these are similar, but they can be different if
365 # the weird "NAME:FILE" syntax is used.
366 my @config_fullnames = ();
367 my @config_names = ();
368 my @config_headers = ();
369 # Line number at which AC_CONFIG_HEADER appears in configure.ac.
370 my $config_header_line = 0;
372 # Directory where output files go. Actually, output files are
373 # relative to this directory.
374 my $output_directory = '.';
376 # List of Makefile.am's to process, and their corresponding outputs.
377 my @input_files = ();
378 my %output_files = ();
380 # Complete list of Makefile.am's that exist.
381 my @configure_input_files = ();
383 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
384 my @other_input_files = ();
385 # Line number at which AC_OUTPUT seen.
386 my $ac_output_line = 0;
388 # List of directories to search for configure-required files. This
389 # can be set by AC_CONFIG_AUX_DIR.
390 my @config_aux_path = ('.', '..', '../..');
391 my $config_aux_dir = '';
392 my $config_aux_dir_set_in_configure_in = 0;
394 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
395 my $seen_gettext = 0;
396 # Line number at which AM_GNU_GETTEXT seen.
397 my $ac_gettext_line = 0;
399 # TRUE if AC_DECL_YYTEXT was seen.
400 my $seen_decl_yytext = 0;
402 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM). The presence of
403 # AC_CHECK_TOOL also sets this.
404 my $seen_canonical = 0;
406 # TRUE if we've seen AC_PROG_LIBTOOL.
407 my $seen_libtool = 0;
408 my $libtool_line = 0;
410 # TRUE if we've seen AM_MAINTAINER_MODE.
411 my $seen_maint_mode = 0;
413 # Actual version we've seen.
414 my $package_version = '';
416 # Line number where we saw version definition.
417 my $package_version_line = 0;
419 # TRUE if we've seen AM_PATH_LISPDIR.
420 my $seen_lispdir = 0;
422 # TRUE if we've seen AM_PATH_PYTHON.
423 my $seen_pythondir = 0;
425 # TRUE if we've seen AC_OBJEXT.
428 # TRUE if we've seen AC_ENABLE_MULTILIB.
429 my $seen_multilib = 0;
431 # TRUE if we've seen AM_PROG_CC_C_O
434 # TRUE if we've seen AM_INIT_AUTOMAKE.
435 my $seen_init_automake = 0;
437 # Hash table of discovered configure substitutions. Keys are names,
438 # values are `FILE:LINE' strings which are used by error message
440 my %configure_vars = ();
442 # This is used to keep track of which variable definitions we are
443 # scanning. It is only used in certain limited ways, but it has to be
444 # global. It is declared just for documentation purposes.
445 my %vars_scanned = ();
447 # TRUE if --cygnus seen.
450 # Hash table of AM_CONDITIONAL variables seen in configure.
451 my %configure_cond = ();
453 # This maps extensions onto language names.
454 my %extension_map = ();
456 # List of the DIST_COMMON files we discovered while reading
458 my $configure_dist_common = '';
460 # This maps languages names onto objects.
463 # List of targets we must always output.
464 # FIXME: Complete, and remove falsely required targets.
465 my %required_targets =
476 # FIXME: Not required, temporary hacks.
477 # Well, actually they are sort of required: the -recursive
478 # targets will run them anyway...
481 'install-data-am' => 1,
482 'install-exec-am' => 1,
483 'installcheck-am' => 1,
491 ################################################################
493 ## ------------------------------------------ ##
494 ## Variables reset by &initialize_per_input. ##
495 ## ------------------------------------------ ##
497 # Basename and relative dir of the input file.
501 # Same but wrt Makefile.in.
505 # These two variables are used when generating each Makefile.in.
506 # They hold the Makefile.in until it is ready to be printed.
513 # Suffixes found during a run.
516 # Handling the variables.
519 # - $var_value{$VAR}{$COND} is its value associated to $COND,
520 # - $var_line{$VAR} is where it has been defined,
521 # - $var_comment{$VAR} are the comments associated to it.
522 # - $var_type{$VAR} is how it has been defined (`', `+', or `:'),
523 # - $var_is_am{$VAR} is true if the variable is owned by Automake.
530 # This holds a 1 if a particular variable was examined.
533 # This holds the names which are targets. These also appear in
537 # Same as %VAR_VALUE, but for targets.
538 my %target_conditional;
540 # This is the conditional stack.
543 # This holds the set of included files.
546 # This holds a list of directories which we must create at `dist'
547 # time. This is used in some strange scenarios involving weird
548 # AC_OUTPUT commands.
551 # List of dependencies for the obvious targets.
556 # Holds the dependencies of targets which dependencies are factored.
557 # Typically, `.PHONY' will appear in plenty of *.am files, but must
558 # be output once. Arguably all pure dependencies could be subject
559 # to this factorization, but it is not unpleasant to have paragraphs
560 # in Makefile: keeping related stuff altogether.
563 # Holds the factored actions. Tied to %DEPENDENCIES, i.e., filled
564 # only when keys exists in %DEPENDENCIES.
567 # A list of files deleted by `maintainer-clean'.
568 my @maintainer_clean_files;
570 # Keys in this hash table are object files or other files in
571 # subdirectories which need to be removed. This only holds files
572 # which are created by compilations. The value in the hash indicates
573 # when the file should be removed.
574 my %compile_clean_files;
576 # Value of `$(SOURCES)', used by tags.am.
578 # Sources which go in the distribution.
581 # This hash maps object file names onto their corresponding source
582 # file names. This is used to ensure that each object is created
583 # by a single source file.
586 # This keeps track of the directories for which we've already
587 # created `.dirstamp' code.
597 # Options from AUTOMAKE_OPTIONS.
600 # Whether or not dependencies are handled. Can be further changed
602 my $use_dependencies;
604 # This is a list of all targets to run during "make dist".
607 # Keys in this hash are the basenames of files which must depend
611 # This maps the source extension of a suffix rule to its
612 # corresponding output extension.
615 # This is the name of the redirect `all' target to use.
618 # This keeps track of which extensions we've seen (that we care
622 # This is random scratch space for the language finish functions.
623 # Don't randomly overwrite it; examine other uses of keys first.
624 my %language_scratch;
626 # We keep track of which objects need special (per-executable)
627 # handling on a per-language basis.
628 my %lang_specific_files;
630 # This is set when `handle_dist' has finished. Once this happens,
631 # we should no longer push on dist_common.
634 # True if we need `LINK' defined. This is a hack.
637 # This is the list of such variables to output.
638 # FIXME: Might be useless actually.
641 # Was get_object_extension run?
642 # FIXME: This is a hack. a better switch should be found.
643 my $get_object_extension_was_run;
646 ## --------------------------------- ##
647 ## Forward subroutine declarations. ##
648 ## --------------------------------- ##
649 sub register_language (%);
650 sub file_contents_internal ($$%);
653 # &initialize_per_input ()
654 # ------------------------
655 # (Re)-Initialize per-Makefile.am variables.
656 sub initialize_per_input ()
659 $am_relative_dir = '';
666 $output_trailer = '';
682 %target_conditional = ();
690 $am_relative_dir = '';
706 # Installing/uninstalling.
707 'install-data-am' => [],
708 'install-exec-am' => [],
709 'uninstall-am' => [],
712 'uninstall-man' => [],
714 'install-info' => [],
715 'install-info-am' => [],
716 'uninstall-info' => [],
718 'installcheck-am' => [],
722 'mostlyclean-am' => [],
723 'maintainer-clean-am' => [],
724 'distclean-am' => [],
727 'maintainer-clean' => [],
738 @maintainer_clean_files = ();
749 $strictness = $default_strictness;
750 $strictness_name = $default_strictness_name;
754 $use_dependencies = $cmdline_use_dependencies;
764 %extension_seen = ();
766 %language_scratch = ();
768 %lang_specific_files = ();
770 $handle_dist_run = 0;
776 $get_object_extension_was_run = 0;
778 %compile_clean_files = ();
782 ################################################################
784 # Initialize our list of languages that are internally supported.
787 register_language ('name' => 'c',
789 'config_vars' => ['CC'],
793 'compiler' => 'COMPILE',
794 'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
798 'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
799 'compile_flag' => '-c',
800 'extensions' => ['c'],
801 '_finish' => \&lang_c_finish);
804 register_language ('name' => 'cxx',
806 'config_vars' => ['CXX'],
807 'linker' => 'CXXLINK',
808 'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
810 'flags' => 'CXXFLAGS',
811 'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
812 'compiler' => 'CXXCOMPILE',
813 'compile_flag' => '-c',
814 'output_flag' => '-o',
818 'extensions' => ['c++', 'cc', 'cpp', 'cxx', 'C']);
821 register_language ('name' => 'objc',
822 'Name' => 'Objective C',
823 'config_vars' => ['OBJC'],
824 'linker' => 'OBJCLINK',,
825 'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
827 'flags' => 'OBJCFLAGS',
828 'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
829 'compiler' => 'OBJCCOMPILE',
830 'compile_flag' => '-c',
831 'output_flag' => '-o',
835 'extensions' => ['m']);
838 register_language ('name' => 'header',
840 'extensions' => ['h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc'],
842 '_finish' => sub { });
845 register_language ('name' => 'yacc',
847 'config_vars' => ['YACC'],
850 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
851 'compiler' => 'YACCCOMPILE',
852 'extensions' => ['y'],
853 'rule_file' => 'yacc',
854 '_finish' => \&lang_yacc_finish,
855 '_target_hook' => \&lang_yacc_target_hook);
856 register_language ('name' => 'yaccxx',
857 'Name' => 'Yacc (C++)',
858 'config_vars' => ['YACC'],
859 'rule_file' => 'yacc',
862 'compiler' => 'YACCCOMPILE',
863 'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
864 'extensions' => ['y++', 'yy', 'yxx', 'ypp'],
865 '_finish' => \&lang_yacc_finish,
866 '_target_hook' => \&lang_yacc_target_hook);
869 register_language ('name' => 'lex',
871 'config_vars' => ['LEX'],
872 'rule_file' => 'lex',
875 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
876 'compiler' => 'LEXCOMPILE',
877 'extensions' => ['l'],
878 '_finish' => \&lang_lex_finish);
879 register_language ('name' => 'lexxx',
880 'Name' => 'Lex (C++)',
881 'config_vars' => ['LEX'],
882 'rule_file' => 'lex',
885 'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
886 'compiler' => 'LEXCOMPILE',
887 'extensions' => ['l++', 'll', 'lxx', 'lpp'],
888 '_finish' => \&lang_lex_finish);
891 register_language ('name' => 'asm',
892 'Name' => 'Assembler',
893 'config_vars' => ['AS', 'ASFLAGS'],
895 'flags' => 'ASFLAGS',
896 # Users can set AM_ASFLAGS to includes DEFS, INCLUDES,
897 # or anything else required. They can also set AS.
898 'compile' => '$(AS) $(AM_ASFLAGS) $(ASFLAGS)',
899 'compiler' => 'ASCOMPILE',
900 'compile_flag' => '-c',
901 'extensions' => ['s', 'S'],
903 # With assembly we still use the C linker.
904 '_finish' => \&lang_c_finish);
907 register_language ('name' => 'f77',
908 'Name' => 'Fortran 77',
909 'linker' => 'F77LINK',
910 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
912 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
913 'compiler' => 'F77COMPILE',
914 'compile_flag' => '-c',
915 'output_flag' => '-o',
919 'extensions' => ['f', 'for', 'f90']);
921 # Preprocessed Fortran 77
923 # The current support for preprocessing Fortran 77 just involves
924 # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
925 # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
926 # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
927 # for `make' Version 3.76 Beta' (specifically, from info file
928 # `(make)Catalogue of Rules').
930 # A better approach would be to write an Autoconf test
931 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
932 # Fortran 77 compilers know how to do preprocessing. The Autoconf
933 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
934 # preprocessing capabilities, and then fall back on cpp (if cpp were
936 register_language ('name' => 'ppf77',
937 'Name' => 'Preprocessed Fortran 77',
938 'config_vars' => ['F77'],
939 'linker' => 'F77LINK',
940 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
944 'compiler' => 'PPF77COMPILE',
945 'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
946 'compile_flag' => '-c',
947 'output_flag' => '-o',
949 'extensions' => ['F']);
952 register_language ('name' => 'ratfor',
954 'config_vars' => ['F77'],
955 'linker' => 'F77LINK',
956 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
961 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
962 'compiler' => 'RCOMPILE',
963 'compile_flag' => '-c',
964 'output_flag' => '-o',
966 'extensions' => ['r']);
969 register_language ('name' => 'java',
971 'config_vars' => ['GCJ'],
972 'linker' => 'GCJLINK',
973 'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
975 'flags' => 'GCJFLAGS',
976 'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
977 'compiler' => 'GCJCOMPILE',
978 'compile_flag' => '-c',
979 'output_flag' => '-o',
983 'extensions' => ['java', 'class', 'zip', 'jar']);
985 ################################################################
987 # Parse command line.
990 # Do configure.ac scan only once.
991 &scan_autoconf_files;
993 die "$me: no `Makefile.am' found or specified\n"
996 # Now do all the work on each file.
997 # This guy must be local otherwise it's private to the loop.
1000 foreach $am_file (@input_files)
1002 if (! -f ($am_file . '.am'))
1004 &am_error ("`" . $am_file . ".am' does not exist");
1008 &generate_makefile ($output_files{$am_file}, $am_file);
1014 # FIXME: This should be `my'ed next to its subs.
1015 use vars '%require_file_found';
1017 ################################################################
1019 # prog_error (@PRINT-ME)
1020 # ----------------------
1021 # Signal a programming error, display PRINT-ME, and exit 1.
1024 print STDERR "$me: programming error: @_\n";
1032 # Return LIST with no duplicates.
1037 foreach my $item (@_)
1039 if (! defined $seen{$item})
1050 # Return a configure-style substitution using the indicated text.
1051 # We do this to avoid having the substitutions directly in automake.in;
1052 # when we do that they are sometimes removed and this causes confusion
1057 return '@' . $text . '@';
1060 ################################################################
1064 # &backname ($REL-DIR)
1065 # --------------------
1066 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
1067 # For instance `src/foo' => `../..'.
1068 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
1073 foreach (split (/\//, $file))
1075 next if $_ eq '.' || $_ eq '';
1085 return join ('/', @res) || '.';
1088 ################################################################
1090 # Parse command line.
1091 sub parse_arguments ()
1094 &set_strictness ('gnu');
1097 Getopt::Long::config ("bundling");
1098 Getopt::Long::GetOptions
1100 'version' => \&version,
1102 'libdir:s' => \$libdir,
1103 'gnu' => sub { &set_strictness ('gnu'); },
1104 'gnits' => sub { &set_strictness ('gnits'); },
1105 'cygnus' => \$cygnus_mode,
1106 'foreign' => sub { &set_strictness ('foreign'); },
1107 'include-deps' => sub { $cmdline_use_dependencies = 1; },
1108 'i|ignore-deps' => sub { $cmdline_use_dependencies = 0; },
1109 'no-force' => sub { $force_generation = 0; },
1110 'f|force-missing'=> \$force_missing,
1111 'o|output-dir:s' => \$output_directory,
1112 'a|add-missing' => \$add_missing,
1113 'c|copy' => \$copy_missing,
1114 'v|verbose' => \$verbose,
1115 'Werror' => sub { $SIG{"__WARN__"} = sub { die $_[0] } },
1116 'Wno-error' => sub { $SIG{"__WARN__"} = 'DEFAULT' }
1120 foreach my $arg (@ARGV)
1122 # Handle $local:$input syntax. Note that we only examine the
1123 # first ":" file to see if it is automake input; the rest are
1124 # just taken verbatim. We still keep all the files around for
1125 # dependency checking, however.
1126 my ($local, $input, @rest) = split (/:/, $arg);
1133 # Strip .in; later on .am is tacked on. That is how the
1134 # automake input file is found. Maybe not the best way, but
1135 # it is easy to explain.
1137 or die "$me: invalid input file name `$arg'\n.";
1139 push (@input_files, $input);
1140 $output_files{$input} = join (':', ($local, @rest));
1143 # Take global strictness from whatever we currently have set.
1144 $default_strictness = $strictness;
1145 $default_strictness_name = $strictness_name;
1148 ################################################################
1150 # Generate a Makefile.in given the name of the corresponding Makefile and
1151 # the name of the file output by config.status.
1152 sub generate_makefile
1154 my ($output, $makefile) = @_;
1156 # Reset all the Makefile.am related variables.
1157 &initialize_per_input;
1159 # Name of input file ("Makefile.am") and output file
1160 # ("Makefile.in"). These have no directory components.
1161 $am_file_name = basename ($makefile) . '.am';
1162 $in_file_name = basename ($makefile) . '.in';
1164 # $OUTPUT is encoded. If it contains a ":" then the first element
1165 # is the real output file, and all remaining elements are input
1166 # files. We don't scan or otherwise deal with these input file,
1167 # other than to mark them as dependencies. See
1168 # &scan_autoconf_files for details.
1169 my (@secondary_inputs);
1170 ($output, @secondary_inputs) = split (/:/, $output);
1172 $relative_dir = dirname ($output);
1173 $am_relative_dir = dirname ($makefile);
1175 &read_main_am_file ($makefile . '.am');
1176 if (&handle_options)
1178 # Fatal error. Just return, so we can continue with next file.
1182 # There are a few install-related variables that you should not define.
1183 foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
1185 if (&variable_defined ($var) && !$var_is_am{$var})
1187 &am_line_error ($var, "`$var' should not be defined");
1193 # At the toplevel directory, we might need config.guess, config.sub
1194 # or libtool scripts (ltconfig and ltmain.sh).
1195 if ($relative_dir eq '.')
1197 # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1199 &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
1203 # We still need Makefile.in here, because sometimes the `dist'
1204 # target doesn't re-run automake.
1205 if ($am_relative_dir eq $relative_dir)
1207 # Only distribute the files if they are in the same subdir as
1208 # the generated makefile.
1209 &push_dist_common ($in_file_name, $am_file_name);
1212 push (@sources, '$(SOURCES)')
1213 if &variable_defined ('SOURCES');
1215 # Must do this after reading .am file. See read_main_am_file to
1216 # understand weird tricks we play there with variables.
1217 &define_variable ('subdir', $relative_dir);
1219 # Check first, because we might modify some state.
1221 &check_gnu_standards;
1222 &check_gnits_standards;
1224 &handle_configure ($output, $makefile, @secondary_inputs);
1227 &handle_ltlibraries;
1231 # This must run first so that the ANSI2KNR definition is generated
1232 # before it is used by the _.c rules. We have to do this because
1233 # a variable which is used in a dependency must be defined before
1234 # the target, or else make won't properly see it.
1236 # This must be run after all the sources are scanned.
1239 # Re-init SOURCES. FIXME: other code shouldn't depend on this
1240 # (but currently does).
1241 macro_define ('SOURCES', 1, '', 'TRUE',
1242 join (' ', @sources), 'internal');
1243 &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
1255 &handle_minor_options;
1258 # This must come after most other rules.
1259 &handle_dist ($makefile);
1262 &do_check_merge_target;
1263 &handle_all ($output);
1266 if (&variable_defined('lib_LTLIBRARIES') &&
1267 &variable_defined('bin_PROGRAMS'))
1269 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
1272 &handle_installdirs;
1274 &handle_factored_dependencies;
1278 if (! -d ($output_directory . '/' . $am_relative_dir))
1280 mkdir ($output_directory . '/' . $am_relative_dir, 0755);
1283 my ($out_file) = $output_directory . '/' . $makefile . ".in";
1284 if (! $force_generation && -e $out_file)
1286 my ($am_time) = (stat ($makefile . '.am'))[9];
1287 my ($in_time) = (stat ($out_file))[9];
1288 # FIXME: should cache these times.
1289 my ($conf_time) = (stat ($configure_ac))[9];
1290 # FIXME: how to do unsigned comparison?
1291 if ($am_time < $in_time || $am_time < $conf_time)
1293 # No need to update.
1296 if (-f 'aclocal.m4')
1298 my ($acl_time) = (stat _)[9];
1299 return if ($am_time < $acl_time);
1303 my $gm_file = new IO::File "> $out_file";
1306 warn "$me: ${am_file}.in: cannot write: $!\n";
1310 print "$me: creating ", $makefile, ".in\n" if $verbose;
1312 # In case we're running under MSWindows, don't write with CRLF
1313 # (as it causes problems for the dependency-file extraction in
1314 # AM_OUTPUT_DEPENDENCY_COMMANDS).
1317 print $gm_file $output_vars;
1318 # We make sure that `all:' is the first target.
1319 print $gm_file $output_all;
1320 print $gm_file $output_header;
1321 print $gm_file $output_rules;
1322 print $gm_file $output_trailer;
1324 if (! $gm_file->close)
1326 warn "$me: $am_file.in: cannot close: $!\n";
1332 ################################################################
1334 # A helper which handles the logic of requiring a version number in
1335 # AUTOMAKE_OPTIONS. Return 1 on error, 0 on success.
1336 sub version_check ($$$$)
1338 my ($rmajor, $rminor, $ralpha, $rfork) = ($1, $2, $3, $4);
1340 &prog_error ("version is incorrect: $VERSION")
1341 if $VERSION !~ /(\d+)\.(\d+)([a-z]?)-?([A-Za-z0-9]+)?/;
1343 my ($tmajor, $tminor, $talpha, $tfork) = ($1, $2, $3, $4);
1348 my $rminorminor = 0;
1349 my $tminorminor = 0;
1351 # Some versions were labelled like `1.4-p3a'. This is the same as
1352 # an alpha release labelled `1.4.3a'. However, a version like
1353 # `1.4g' is the same as `1.4.99g'. Yes, this sucks. Moral:
1354 # always listen to the users.
1355 if ($rfork =~ /p([0-9]+)([a-z]?)/)
1358 # `1.4a-p3b' never existed. But we'll accept it anyway.
1359 $ralpha = $ralpha || $2 || '';
1362 if ($tfork =~ /p([0-9]+)([a-z]?)/)
1365 # `1.4a-p3b' never existed. But we'll accept it anyway.
1366 $talpha = $talpha || $2 || '';
1370 $rminorminor = 99 if $ralpha ne '' && $rminorminor == 0;
1371 $tminorminor = 99 if $talpha ne '' && $tminorminor == 0;
1373 # 2.0 is better than 1.0.
1374 # 1.2 is better than 1.1.
1375 # 1.2a is better than 1.2.
1376 # If we require 3.4n-foo then we require something
1377 # >= 3.4n, with the `foo' fork identifier.
1378 # The $r* variables are what the user specified.
1379 # The $t* variables denote automake itself.
1380 if ($rmajor > $tmajor
1381 || ($rmajor == $tmajor && $rminor > $tminor)
1382 || ($rminor == $tminor && $rminor == $tminor
1383 && $rminorminor > $tminorminor)
1384 || ($rminor == $tminor && $rminor == $tminor
1385 && $rminorminor == $tminorminor
1386 && $ralpha gt $talpha)
1387 || ($rfork ne '' && $rfork ne $tfork))
1389 &am_line_error ('AUTOMAKE_OPTIONS',
1390 "require version $_, but have $VERSION");
1397 # Handle AUTOMAKE_OPTIONS variable. Return 1 on error, 0 otherwise.
1400 if (&variable_defined ('AUTOMAKE_OPTIONS'))
1402 foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
1405 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
1407 &set_strictness ($_);
1409 elsif ($_ eq 'cygnus')
1415 # An option like "../lib/ansi2knr" is allowed. With
1416 # no path prefix, we assume the required programs are
1417 # in this directory. We save the actual option for
1419 $options{'ansi2knr'} = $_;
1421 elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
1422 || $_ eq 'dist-shar' || $_ eq 'dist-zip'
1423 || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
1424 || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
1425 || $_ eq 'readme-alpha' || $_ eq 'check-news'
1426 || $_ eq 'subdir-objects' || $_ eq 'nostdinc'
1427 || $_ eq 'no-exeext')
1429 # Explicitly recognize these.
1431 elsif ($_ eq 'no-dependencies')
1433 $use_dependencies = 0;
1435 elsif (/(\d+)\.(\d+)([a-z]?)(-[A-Za-z0-9]+)?/)
1437 # Got a version number.
1438 if (version_check ($1, $2, $3, $4))
1445 &am_line_error ('AUTOMAKE_OPTIONS',
1446 "option `" . $_ . "\' not recognized");
1451 if ($strictness == $GNITS)
1453 $options{'readme-alpha'} = 1;
1454 $options{'check-news'} = 1;
1461 # get_object_extension ($OUT)
1462 # ---------------------------
1463 # Return object extension. Just once, put some code into the output.
1464 # OUT is the name of the output file
1465 sub get_object_extension
1469 # Maybe require libtool library object files.
1470 my $extension = '.$(OBJEXT)';
1471 $extension = '.lo' if ($out =~ /\.la$/);
1473 # Check for automatic de-ANSI-fication.
1474 $extension = '$U' . $extension
1475 if defined $options{'ansi2knr'};
1477 $get_object_extension_was_run = 1;
1483 # Call finish function for each language that was used.
1484 sub handle_languages
1486 if ($use_dependencies)
1488 # Include auto-dep code. Don't include it if DEP_FILES would
1490 if (&saw_sources_p (0) && keys %dep_files)
1492 # Set location of depcomp.
1493 &define_variable ('depcomp', "\$(SHELL) $config_aux_dir/depcomp");
1495 &require_config_file ($FOREIGN, 'depcomp');
1497 my @deplist = sort keys %dep_files;
1499 # We define this as a conditional variable because BSD
1500 # make can't handle backslashes for continuing comments on
1501 # the following line.
1502 &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
1504 # Generate each `include' individually. Irix 6 make will
1505 # not properly include several files resulting from a
1506 # variable expansion; generating many separate includes
1508 $output_rules .= "\n";
1509 foreach my $iter (@deplist)
1511 $output_rules .= (subst ('AMDEP_TRUE')
1512 . subst ('am__include')
1514 . subst ('am__quote')
1516 . subst ('am__quote')
1520 $output_rules .= &file_contents ('depend');
1525 &define_variable ('depcomp', '');
1530 # Is the c linker needed?
1532 foreach my $ext (sort keys %extension_seen)
1534 next unless $extension_map{$ext};
1536 my $lang = $languages{$extension_map{$ext}};
1538 my $rule_file = $lang->rule_file || 'depend2';
1540 # Get information on $LANG.
1541 my $pfx = $lang->autodep;
1542 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1544 my $AMDEP = (($use_dependencies && $lang->autodep ne 'no')
1545 ? 'AMDEP' : 'FALSE');
1547 my %transform = ('EXT' => $ext,
1550 'LIBTOOL' => $seen_libtool,
1552 '-c' => $lang->compile_flag || '',
1554 => (count_files_for_language ($lang->name) > 1));
1556 # Generate the appropriate rules for this extension.
1557 if (($use_dependencies && $lang->autodep ne 'no')
1558 || defined $lang->compile)
1560 # Some C compilers don't support -c -o. Use it only if really
1562 my $output_flag = $lang->output_flag || '';
1565 && $lang->flags eq 'CFLAGS'
1566 && defined $options{'subdir-objects'});
1568 # FIXME: this is a temporary hack to compute a possible
1569 # derived extension. This is not used by depend2.am.
1570 (my $der_ext = $ext) =~ tr/yl/cc/;
1572 # Another yacc/lex hack.
1573 my $destfile = '$*.' . $der_ext;
1576 file_contents ($rule_file,
1580 'DERIVED-EXT' => $der_ext,
1588 'COMPILE' => '$(' . $lang->compiler . ')',
1589 'LTCOMPILE' => '$(LT' . $lang->compiler . ')',
1590 '-o' => $output_flag);
1593 # Now include code for each specially handled object with this
1595 my %seen_files = ();
1596 foreach my $file (@{$lang_specific_files{$lang->name}})
1598 my ($derived, $source, $obj, $myext) = split (' ', $file);
1600 # We might see a given object twice, for instance if it is
1601 # used under different conditions.
1602 next if defined $seen_files{$obj};
1603 $seen_files{$obj} = 1;
1605 my $flags = $lang->flags || '';
1606 my $val = "${derived}_${flags}";
1608 &prog_error ("found $lang->name in handle_languages, but compiler not defined")
1609 unless defined $lang->compile;
1611 (my $obj_compile = $lang->compile) =~ s/\(AM_$flags/\($val/;
1612 my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
1614 # We _need_ `-o' for per object rules.
1615 my $output_flag = $lang->output_flag || '-o';
1617 # Generate a transform which will turn suffix targets in
1618 # depend2.am into real targets for the particular objects we
1621 file_contents ($rule_file,
1626 'SOURCE' => $source,
1627 # Use $myext and not `.o' here, in case
1628 # we are actually building a new source
1629 # file -- e.g. via yacc.
1630 'OBJ' => "$obj$myext",
1631 'OBJOBJ' => "$obj.obj",
1632 'LTOBJ' => "$obj.lo",
1634 'COMPILE' => $obj_compile,
1635 'LTCOMPILE' => $obj_ltcompile,
1636 '-o' => $output_flag));
1639 # The rest of the loop is done once per language.
1640 next if defined $done{$lang};
1643 # Load the language dependent Makefile chunks.
1644 my %lang = map { uc ($_) => 0 } keys %languages;
1645 $lang{uc ($lang->name)} = 1;
1646 $output_rules .= file_contents ('lang-compile', %transform, %lang);
1648 # If the source to a program consists entirely of code from a
1649 # `pure' language, for instance C++ for Fortran 77, then we
1650 # don't need the C compiler code. However if we run into
1651 # something unusual then we do generate the C code. There are
1652 # probably corner cases here that do not work properly.
1653 # People linking Java code to Fortran code deserve pain.
1654 $needs_c ||= ! $lang->pure;
1656 define_compiler_variable ($lang)
1657 if ($lang->compile);
1659 define_linker_variable ($lang)
1662 foreach my $var (@{$lang->config_vars})
1664 am_error ($lang->Name
1665 . " source seen but `$var' not defined in"
1666 . " `$configure_ac'")
1667 if !exists $configure_vars{$var};
1670 # The compiler's flag must be a configure variable.
1671 define_configure_variable ($lang->flags)
1672 if defined $lang->flags && $lang->define_flag;
1674 # Call the finisher.
1678 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1679 # suffix rule was learned), don't bother with the C stuff. But if
1680 # anything else creeps in, then use it.
1682 if $need_link || scalar keys %suffix_rules > 1;
1686 if (! defined $done{$languages{'c'}})
1688 &define_configure_variable ($languages{'c'}->flags);
1689 &define_compiler_variable ($languages{'c'});
1691 define_linker_variable ($languages{'c'});
1695 # Check to make sure a source defined in LIBOBJS is not explicitly
1696 # mentioned. This is a separate function (as opposed to being inlined
1697 # in handle_source_transform) because it isn't always appropriate to
1699 sub check_libobjs_sources
1701 my ($one_file, $unxformed) = @_;
1703 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1704 'dist_EXTRA_', 'nodist_EXTRA_')
1707 if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1709 @files = &variable_value_as_list (($prefix
1710 . $one_file . '_SOURCES'),
1713 elsif ($prefix eq '')
1715 @files = ($unxformed . '.c');
1722 foreach my $file (@files)
1724 if (defined $libsources{$file})
1726 &am_line_error ($prefix . $one_file . '_SOURCES',
1727 "automatically discovered file `$file' should not be explicitly mentioned");
1734 # ($LINKER, @OBJECTS)
1735 # handle_single_transform_list ($VAR, $DERIVED, $OBJ, @FILES)
1736 # -----------------------------------------------------------
1737 # Does much of the actual work for handle_source_transform.
1739 # $DERIVED is the name of resulting executable or library
1740 # $OBJ is the object extension (e.g., `$U.lo')
1741 # @FILES is the list of source files to transform
1743 # $LINKER is name of linker to use (empty string for default linker)
1744 # @OBJECTS are names of objects
1745 sub handle_single_transform_list ($$$@)
1747 my ($var, $derived, $obj, @files) = @_;
1749 my $nonansi_obj = $obj;
1750 $nonansi_obj =~ s/\$U//g;
1751 my %linkers_used = ();
1753 # Turn sources into objects. We use a while loop like this
1754 # because we might add to @files in the loop.
1755 while (scalar @files > 0)
1759 # Configure substitutions in _SOURCES variables are errors.
1762 &am_line_error ($var, "$var includes configure substitution `$_'");
1766 # If the source file is in a subdirectory then the `.o' is put
1767 # into the current directory, unless the subdir-objects option
1770 # Split file name into base and extension.
1771 next if ! /^(?:(.*)\/)?([^\/]*)\.(.*)$/;
1773 my $directory = $1 || '';
1777 # We must generate a rule for the object if it requires its own flags.
1779 my ($linker, $object);
1781 # This records whether we've seen a derived source file (eg,
1783 my $derived_source = 0;
1785 # This holds the `aggregate context' of the file we are
1786 # currently examining. If the file is compiled with
1787 # per-object flags, then it will be the name of the object.
1788 # Otherwise it will be `AM'. This is used by the target hook
1789 # language function.
1790 my $aggregate = 'AM';
1792 $extension = &derive_suffix ($extension);
1794 if ($extension_map{$extension} &&
1795 ($lang = $languages{$extension_map{$extension}}))
1797 # Found the language, so see what it says.
1798 &saw_extension ($extension);
1800 # Note: computed subr call. The language rewrite function
1801 # should return one of the $LANG_* constants. It could
1802 # also return a list whose first value is such a constant
1803 # and whose second value is a new source extension which
1804 # should be applied. This means this particular language
1805 # generates another source file which we must then process
1807 my $subr = 'lang_' . $lang->name . '_rewrite';
1808 my ($r, $source_extension)
1809 = & $subr ($directory, $base, $extension);
1810 # Skip this entry if we were asked not to process it.
1811 next if $r == $LANG_IGNORE;
1813 # Now extract linker and other info.
1814 $linker = $lang->linker;
1817 if (defined $source_extension)
1819 $this_obj_ext = '.' . $source_extension;
1820 $derived_source = 1;
1824 $this_obj_ext = $obj;
1828 $this_obj_ext = $nonansi_obj;
1830 $object = $base . $this_obj_ext;
1832 if (defined $lang->flags
1833 && &variable_defined ($derived . '_' . $lang->flags))
1835 # We have a per-executable flag in effect for this
1836 # object. In this case we rewrite the object's
1837 # name to ensure it is unique. We also require
1838 # the `compile' program to deal with compilers
1839 # where `-c -o' does not work.
1841 # We choose the name `DERIVED_OBJECT' to ensure
1842 # (1) uniqueness, and (2) continuity between
1843 # invocations. However, this will result in a
1844 # name that is too long for losing systems, in
1845 # some situations. So we provide _SHORTNAME to
1848 my $dname = $derived;
1849 if (&variable_defined ($derived . '_SHORTNAME'))
1851 # FIXME: should use the same conditional as
1852 # the _SOURCES variable. But this is really
1853 # silly overkill -- nobody should have
1854 # conditional shortnames.
1855 $dname = &variable_value ($derived . '_SHORTNAME');
1857 $object = $dname . '-' . $object;
1859 &require_config_file ($FOREIGN, 'compile')
1860 if $lang->name eq 'c';
1862 &prog_error ("$lang->name flags defined without compiler")
1863 if ! defined $lang->compile;
1868 # If rewrite said it was ok, put the object into a
1870 if ($r == $LANG_SUBDIR && $directory ne '')
1872 $object = $directory . '/' . $object;
1875 # If doing dependency tracking, then we can't print
1876 # the rule. If we have a subdir object, we need to
1877 # generate an explicit rule. Actually, in any case
1878 # where the object is not in `.' we need a special
1879 # rule. The per-object rules in this case are
1880 # generated later, by handle_languages.
1881 if ($renamed || $directory ne '')
1883 my $obj_sans_ext = substr ($object, 0,
1884 - length ($this_obj_ext));
1885 my $val = ("$full $obj_sans_ext "
1886 # Only use $this_obj_ext in the derived
1887 # source case because in the other case we
1888 # *don't* want $(OBJEXT) to appear here.
1889 . ($derived_source ? $this_obj_ext : '.o'));
1891 # If we renamed the object then we want to use the
1892 # per-executable flag name. But if this is simply a
1893 # subdir build then we still want to use the AM_ flag
1897 $val = "$derived $val";
1898 $aggregate = $derived;
1905 # Each item on this list is a string consisting of
1906 # four space-separated values: the derived flag prefix
1907 # (eg, for `foo_CFLAGS', it is `foo'), the name of the
1908 # source file, the base name of the output file, and
1909 # the extension for the object file.
1910 push (@{$lang_specific_files{$lang->name}}, $val);
1913 elsif ($extension eq 'o')
1915 # This is probably the result of a direct suffix rule.
1916 # In this case we just accept the rewrite. FIXME:
1917 # this fails if we want libtool objects.
1918 $object = $base . '.' . $extension;
1923 # No error message here. Used to have one, but it was
1925 # FIXME: we could potentially do more processing here,
1926 # perhaps treating the new extension as though it were a
1927 # new source extension (as above). This would require
1928 # more restructuring than is appropriate right now.
1932 if (defined $object_map{$object})
1934 if ($object_map{$object} ne $full)
1936 &am_error ("object `$object' created by `$full' and `$object_map{$object}'");
1940 # Let the language do some special magic if required.
1941 $lang->target_hook ($aggregate, $object, $full);
1943 if ($derived_source)
1945 &prog_error ("$lang->name has automatic dependency tracking")
1946 if $lang->autodep ne 'no';
1947 # Make sure this new source file is handled next. That will
1948 # make it appear to be at the right place in the list.
1949 unshift (@files, $object);
1951 &push_dist_common ($object);
1955 $linkers_used{$linker} = 1;
1957 push (@result, $object);
1959 if (! defined $object_map{$object})
1962 $object_map{$object} = $full;
1964 # If file is in subdirectory, we need explicit
1966 if ($directory ne '' || $renamed)
1968 push (@dep_list, $full);
1971 # If resulting object is in subdir, we need to make
1972 # sure the subdir exists at build time.
1973 if ($object =~ /\//)
1975 # FIXME: check that $DIRECTORY is somewhere in the
1978 # We don't allow `..' in object file names for
1979 # *any* source, not just Java. For Java it just
1980 # doesn't make sense, but in general it is
1981 # a problem because we can't pick a good name for
1983 if ($object =~ /(\/|^)\.\.\//)
1985 &am_error ("`$full' contains `..' component but should not");
1988 # Make sure object is removed by `make mostlyclean'.
1989 $compile_clean_files{$object} = $MOSTLY_CLEAN;
1991 push (@dep_list, &require_build_directory ($directory));
1993 # If we're generating dependencies, we also want
1994 # to make sure that the appropriate subdir of the
1995 # .deps directory is created.
1996 push (@dep_list, &require_build_directory ('$(DEPDIR)/' . $directory))
1997 if ($use_dependencies);
2000 &pretty_print_rule ($object . ':', "\t", @dep_list)
2001 if scalar @dep_list > 0;
2004 # Transform .o or $o file into .P file (for automatic
2006 if ($lang && $lang->autodep ne 'no')
2008 my $depfile = $object;
2009 $depfile =~ s/\.([^.]*)$/.P$1/;
2010 $depfile =~ s/\$\(OBJEXT\)$/o/;
2011 $dep_files{'$(DEPDIR)/' . $depfile} = 1;
2015 return (&resolve_linker (%linkers_used), @result);
2020 # Handle SOURCE->OBJECT transform for one program or library.
2022 # canonical (transformed) name of object to build
2023 # actual name of object to build
2024 # object extension (ie either `.o' or `$o'.
2025 # Return result is name of linker variable that must be used.
2026 # Empty return means just use `LINK'.
2027 sub handle_source_transform
2029 # one_file is canonical name. unxformed is given name. obj is
2031 my ($one_file, $unxformed, $obj) = @_;
2035 if (&variable_defined ($one_file . "_OBJECTS"))
2037 &am_line_error ($one_file . '_OBJECTS',
2038 $one_file . '_OBJECTS', 'should not be defined');
2039 # No point in continuing.
2044 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2045 'dist_EXTRA_', 'nodist_EXTRA_')
2047 my $var = $prefix . $one_file . "_SOURCES";
2049 if !variable_defined ($var);
2051 # We are going to define _OBJECTS variables using the prefix.
2052 # Then we glom them all together. So we can't use the null
2053 # prefix here as we need it later.
2054 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2056 # Keep track of which prefixes we saw.
2057 $used_pfx{$xpfx} = 1
2058 unless $prefix =~ /EXTRA_/;
2060 push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
2061 push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
2062 unless $prefix =~ /^nodist_/;
2063 foreach my $cond (variable_conditions ($var))
2065 my @files = &variable_value_as_list ($var, $cond);
2066 my ($temp, @result) =
2067 &handle_single_transform_list ($var, $one_file, $obj,
2069 # If there are no files to compile, don't require a linker (yet).
2073 # Define _OBJECTS conditionally.
2074 &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
2076 unless $prefix =~ /EXTRA_/;
2080 my @keys = sort keys %used_pfx;
2081 if (scalar @keys == 0)
2083 &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
2084 push (@sources, $unxformed . '.c');
2085 push (@dist_sources, $unxformed . '.c');
2087 my ($temp, @result) =
2088 &handle_single_transform_list ($one_file . '_SOURCES',
2091 $linker = $temp if $linker eq '';
2092 &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
2096 grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
2097 &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
2100 # If we want to use `LINK' we must make sure it is defined.
2110 # handle_lib_objects ($XNAME, $VAR)
2111 # ---------------------------------
2112 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
2113 # Also, generate _DEPENDENCIES variable if appropriate.
2115 # transformed name of object being built, or empty string if no object
2116 # name of _LDADD/_LIBADD-type variable to examine
2117 # Returns 1 if LIBOBJS seen, 0 otherwise.
2118 sub handle_lib_objects
2120 my ($xname, $var) = @_;
2122 &prog_error ("handle_lib_objects: $var undefined")
2123 if ! &variable_defined ($var);
2126 foreach my $cond (&variable_conditions ($var))
2128 if (&handle_lib_objects_cond ($xname, $var, $cond))
2136 # Subroutine of handle_lib_objects: handle a particular condition.
2137 sub handle_lib_objects_cond
2139 my ($xname, $var, $cond) = @_;
2141 # We recognize certain things that are commonly put in LIBADD or
2145 my $seen_libobjs = 0;
2148 foreach my $lsearch (&variable_value_as_list ($var, $cond))
2150 # Skip -lfoo and -Ldir; these are explicitly allowed.
2151 next if $lsearch =~ /^-[lL]/;
2152 if (! $flagvar && $lsearch =~ /^-/)
2154 if ($var =~ /^(.*)LDADD$/)
2156 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
2157 next if $lsearch =~ /^-dl(pre)?open$/;
2158 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2162 # Only get this error once.
2164 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2168 # Assume we have a file of some sort, and push it onto the
2169 # dependency list. Autoconf substitutions are not pushed;
2170 # rarely is a new dependency substituted into (eg) foo_LDADD
2171 # -- but "bad things (eg -lX11) are routinely substituted.
2172 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2173 # and handled specially below.
2174 push (@dep_list, $lsearch)
2175 unless $lsearch =~ /^\@.*\@$/;
2177 # Automatically handle @LIBOBJS@ and @ALLOCA@. Basically this
2178 # means adding entries to dep_files.
2179 if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
2181 my $lt = $1 ? $1 : '';
2182 my $myobjext = ($1 ? 'l' : '') . 'o';
2184 push (@dep_list, $lsearch);
2186 if (! keys %libsources
2187 && ! &variable_defined ($lt . 'LIBOBJS'))
2189 &am_line_error ($var, "\@$lt" . "LIBOBJS\@ seen but never set in `$configure_ac'");
2192 foreach my $iter (keys %libsources)
2194 if ($iter =~ /\.([cly])$/)
2196 &saw_extension ($1);
2197 &saw_extension ('c');
2200 if ($iter =~ /\.h$/)
2202 &require_file_with_line ($var, $FOREIGN, $iter);
2204 elsif ($iter ne 'alloca.c')
2206 my $rewrite = $iter;
2207 $rewrite =~ s/\.c$/.P$myobjext/;
2208 $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
2209 ($rewrite = $iter) =~ s/(\W)/\\$1/g;
2210 $rewrite = "^" . $rewrite . "\$";
2211 # Only require the file if it is not a built source.
2212 if (! &variable_defined ('BUILT_SOURCES')
2213 || ! grep (/$rewrite/,
2214 &variable_value_as_list ('BUILT_SOURCES',
2217 &require_file_with_line ($var, $FOREIGN, $iter);
2222 elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
2224 my $lt = $1 ? $1 : '';
2225 my $myobjext = ($1 ? 'l' : '') . 'o';
2227 push (@dep_list, $lsearch);
2228 &am_line_error ($var,
2229 "\@$lt" . "ALLOCA\@ seen but `AC_FUNC_ALLOCA' not in `$configure_ac'")
2230 if ! defined $libsources{'alloca.c'};
2231 $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
2232 &require_file_with_line ($var, $FOREIGN, 'alloca.c');
2233 &saw_extension ('c');
2237 if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
2239 &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
2242 return $seen_libobjs;
2245 # Canonicalize the input parameter
2249 $string =~ tr/A-Za-z0-9_\@/_/c;
2253 # Canonicalize a name, and check to make sure the non-canonical name
2254 # is never used. Returns canonical name. Arguments are name and a
2255 # list of suffixes to check for.
2256 sub check_canonical_spelling
2258 my ($name, @suffixes) = @_;
2260 my $xname = &canonicalize ($name);
2261 if ($xname ne $name)
2263 foreach my $xt (@suffixes)
2265 &am_line_error ("$name$xt",
2266 "invalid variable `$name$xt'; "
2267 . "should be `$xname$xt'")
2268 if &variable_defined ("$name$xt");
2278 # Set up the compile suite.
2279 sub handle_compile ()
2282 unless $get_object_extension_was_run;
2285 my $default_includes = '';
2286 if (! defined $options{'nostdinc'})
2288 $default_includes = ' -I. -I$(srcdir)';
2290 if (&variable_defined ('CONFIG_HEADER'))
2292 foreach my $hdr (split (' ', &variable_value ('CONFIG_HEADER')))
2294 $default_includes .= ' -I' . dirname ($hdr);
2299 my (@mostly_rms, @dist_rms);
2300 foreach my $item (sort keys %compile_clean_files)
2302 if ($compile_clean_files{$item} == $MOSTLY_CLEAN)
2304 push (@mostly_rms, "\t-rm -f $item");
2306 elsif ($compile_clean_files{$item} == $DIST_CLEAN)
2308 push (@dist_rms, "\t-rm -f $item");
2312 &prog_error ("invalid entry in \%compile_clean_files");
2316 my ($coms, $vars, $rules) =
2317 &file_contents_internal (1, "$libdir/am/compile.am",
2318 ('DEFAULT_INCLUDES' => $default_includes,
2319 'MOSTLYRMS' => join ("\n", @mostly_rms),
2320 'DISTRMS' => join ("\n", @dist_rms)));
2321 $output_vars .= $vars;
2322 $output_rules .= "$coms$rules";
2324 # Check for automatic de-ANSI-fication.
2325 if (defined $options{'ansi2knr'})
2327 if (! $am_c_prototypes)
2329 &am_line_error ('AUTOMAKE_OPTIONS',
2330 "option `ansi2knr' in use but `AM_C_PROTOTYPES' not in `$configure_ac'");
2331 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
2332 # Only give this error once.
2333 $am_c_prototypes = 1;
2336 # topdir is where ansi2knr should be.
2337 if ($options{'ansi2knr'} eq 'ansi2knr')
2339 # Only require ansi2knr files if they should appear in
2341 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
2342 'ansi2knr.c', 'ansi2knr.1');
2344 # ansi2knr needs to be built before subdirs, so unshift it.
2345 unshift (@all, '$(ANSI2KNR)');
2348 my $ansi2knr_dir = '';
2349 $ansi2knr_dir = dirname ($options{'ansi2knr'})
2350 if $options{'ansi2knr'} ne 'ansi2knr';
2352 $output_rules .= &file_contents ('ansi2knr',
2353 ('ANSI2KNR-DIR' => $ansi2knr_dir));
2360 # Handle libtool rules.
2363 return unless $seen_libtool;
2365 # libtool requires some files, but only at top level.
2366 &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
2368 if $relative_dir eq '.';
2370 # Output the libtool compilation rules.
2371 $output_rules .= &file_contents ('libtool');
2374 # handle_programs ()
2375 # ------------------
2376 # Handle C programs.
2379 my @proglist = &am_install_var ('progs', 'PROGRAMS',
2380 'bin', 'sbin', 'libexec', 'pkglib',
2382 return if ! @proglist;
2384 my $seen_libobjs = 0;
2385 foreach my $one_file (@proglist)
2387 my $obj = &get_object_extension ($one_file);
2389 # Canonicalize names and check for misspellings.
2390 my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2391 '_SOURCES', '_OBJECTS',
2394 my $linker = &handle_source_transform ($xname, $one_file, $obj);
2397 if (&variable_defined ($xname . "_LDADD"))
2399 if (&handle_lib_objects ($xname, $xname . '_LDADD'))
2407 # User didn't define prog_LDADD override. So do it.
2408 &define_variable ($xname . '_LDADD', '$(LDADD)');
2410 # This does a bit too much work. But we need it to
2411 # generate _DEPENDENCIES when appropriate.
2412 if (&variable_defined ('LDADD'))
2414 if (&handle_lib_objects ($xname, 'LDADD'))
2419 elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
2421 &define_variable ($xname . '_DEPENDENCIES', '');
2426 if (&variable_defined ($xname . '_LIBADD'))
2428 &am_line_error ($xname . '_LIBADD',
2429 "use `" . $xname . "_LDADD', not `"
2430 . $xname . "_LIBADD'");
2433 if (! &variable_defined ($xname . '_LDFLAGS'))
2435 # Define the prog_LDFLAGS variable.
2436 &define_variable ($xname . '_LDFLAGS', '');
2439 # Determine program to use for link.
2441 if (&variable_defined ($xname . '_LINK'))
2443 $xlink = $xname . '_LINK';
2447 $xlink = $linker ? $linker : 'LINK';
2450 # If the resulting program lies into a subdirectory,
2451 # make sure this directory will exist.
2452 my $dirstamp = &require_build_directory_maybe ($one_file);
2454 # Don't add $(EXEEXT) if user already did.
2455 my $extension = ($one_file !~ /\$\(EXEEXT\)$/
2459 $output_rules .= &file_contents ('program',
2460 ('PROGRAM' => $one_file,
2461 'XPROGRAM' => $xname,
2463 'DIRSTAMP' => $dirstamp,
2464 'EXEEXT' => $extension));
2467 if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD'))
2474 foreach my $one_file (@proglist)
2476 my $xname = &canonicalize ($one_file);
2478 if (&variable_defined ($xname . '_LDADD'))
2480 &check_libobjs_sources ($xname, $xname . '_LDADD');
2482 elsif (&variable_defined ('LDADD'))
2484 &check_libobjs_sources ($xname, 'LDADD');
2491 # handle_libraries ()
2492 # -------------------
2494 sub handle_libraries
2496 my @liblist = &am_install_var ('libs', 'LIBRARIES',
2497 'lib', 'pkglib', 'noinst', 'check');
2498 return if ! @liblist;
2500 my %valid = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2502 if (! defined $configure_vars{'RANLIB'})
2504 foreach my $key (keys %valid)
2506 if (&variable_defined ($key . '_LIBRARIES'))
2508 &am_line_error ($key . '_LIBRARIES', "library used but `RANLIB' not defined in `$configure_ac'");
2509 # Only get this error once. If this is ever printed,
2511 $configure_vars{'RANLIB'} = 'BUG';
2517 my $seen_libobjs = 0;
2518 foreach my $onelib (@liblist)
2520 # Check that the library fits the standard naming convention.
2521 if (basename ($onelib) !~ /^lib.*\.a/)
2523 # FIXME should put line number here. That means mapping
2524 # from library name back to variable name.
2525 &am_error ("`$onelib' is not a standard library name");
2528 my $obj = &get_object_extension ($onelib);
2530 # Canonicalize names and check for misspellings.
2531 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2532 '_OBJECTS', '_DEPENDENCIES',
2535 if (! &variable_defined ($xlib . '_AR'))
2537 &define_variable ($xlib . '_AR', '$(AR) cru');
2540 if (&variable_defined ($xlib . '_LIBADD'))
2542 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2549 # Generate support for conditional object inclusion in
2551 &define_variable ($xlib . "_LIBADD", '');
2554 if (&variable_defined ($xlib . '_LDADD'))
2556 &am_line_error ($xlib . '_LDADD',
2557 "use `" . $xlib . "_LIBADD', not `"
2558 . $xlib . "_LDADD'");
2561 # Make sure we at look at this.
2562 &examine_variable ($xlib . '_DEPENDENCIES');
2564 &handle_source_transform ($xlib, $onelib, $obj);
2566 # If the resulting library lies into a subdirectory,
2567 # make sure this directory will exist.
2568 my $dirstamp = &require_build_directory_maybe ($onelib);
2570 $output_rules .= &file_contents ('library',
2571 ('LIBRARY' => $onelib,
2572 'XLIBRARY' => $xlib,
2573 'DIRSTAMP' => $dirstamp));
2578 foreach my $onelib (@liblist)
2580 my $xlib = &canonicalize ($onelib);
2581 if (&variable_defined ($xlib . '_LIBADD'))
2583 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2590 # handle_ltlibraries ()
2591 # ---------------------
2592 # Handle shared libraries.
2593 sub handle_ltlibraries
2595 my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2596 'noinst', 'lib', 'pkglib', 'check');
2597 return if ! @liblist;
2600 my %valid = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2603 foreach my $key (keys %valid)
2605 if (&variable_defined ($key . '_LTLIBRARIES'))
2609 &am_line_error ($key . '_LTLIBRARIES', "library used but `LIBTOOL' not defined in `$configure_ac'");
2610 # Only get this error once. If this is ever printed,
2612 $configure_vars{'LIBTOOL'} = 'BUG';
2616 # Get the installation directory of each library.
2617 for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
2621 &am_error ("`$_' is already going to be installed in `$instdirs{$_}'");
2625 $instdirs{$_} = $key;
2631 my $seen_libobjs = 0;
2632 foreach my $onelib (@liblist)
2634 my $obj = &get_object_extension ($onelib);
2636 # Canonicalize names and check for misspellings.
2637 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2638 '_SOURCES', '_OBJECTS',
2641 if (! &variable_defined ($xlib . '_LDFLAGS'))
2643 # Define the lib_LDFLAGS variable.
2644 &define_variable ($xlib . '_LDFLAGS', '');
2647 # Check that the library fits the standard naming convention.
2648 my $libname_rx = "^lib.*\.la";
2649 if ((&variable_defined ($xlib . '_LDFLAGS')
2650 && grep (/-module/, &variable_value_as_list ($xlib . '_LDFLAGS',
2652 || (&variable_defined ('LDFLAGS')
2653 && grep (/-module/, &variable_value_as_list ('LDFLAGS',
2656 # Relax name checking for libtool modules.
2657 $libname_rx = "\.la";
2659 if (basename ($onelib) !~ /$libname_rx$/)
2661 # FIXME this should only be a warning for foreign packages
2662 # FIXME should put line number here. That means mapping
2663 # from library name back to variable name.
2664 &am_error ("`$onelib' is not a standard libtool library name");
2667 if (&variable_defined ($xlib . '_LIBADD'))
2669 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2676 # Generate support for conditional object inclusion in
2678 &define_variable ($xlib . "_LIBADD", '');
2681 if (&variable_defined ($xlib . '_LDADD'))
2683 &am_line_error ($xlib . '_LDADD',
2684 "use `" . $xlib . "_LIBADD', not `"
2685 . $xlib . "_LDADD'");
2688 # Make sure we at look at this.
2689 &examine_variable ($xlib . '_DEPENDENCIES');
2691 my $linker = &handle_source_transform ($xlib, $onelib, $obj);
2693 # Determine program to use for link.
2695 if (&variable_defined ($xlib . '_LINK'))
2697 $xlink = $xlib . '_LINK';
2701 $xlink = $linker ? $linker : 'LINK';
2705 if ($instdirs{$onelib} eq 'EXTRA'
2706 || $instdirs{$onelib} eq 'noinst'
2707 || $instdirs{$onelib} eq 'check')
2709 # It's an EXTRA_ library, so we can't specify -rpath,
2710 # because we don't know where the library will end up.
2711 # The user probably knows, but generally speaking automake
2712 # doesn't -- and in fact configure could decide
2713 # dynamically between two different locations.
2718 $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
2721 # If the resulting library lies into a subdirectory,
2722 # make sure this directory will exist.
2723 my $dirstamp = &require_build_directory_maybe ($onelib);
2725 $output_rules .= &file_contents ('ltlibrary',
2726 ('LTLIBRARY' => $onelib,
2727 'XLTLIBRARY' => $xlib,
2730 'DIRSTAMP' => $dirstamp));
2735 foreach my $onelib (@liblist)
2737 my $xlib = &canonicalize ($onelib);
2738 if (&variable_defined ($xlib . '_LIBADD'))
2740 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2746 # See if any _SOURCES variable were misspelled. Also, make sure that
2747 # EXTRA_ variables don't contain configure substitutions.
2750 foreach my $varname (keys %var_value)
2752 foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
2755 if ($varname =~ /$primary$/ && ! $content_seen{$varname})
2757 &am_line_error ($varname,
2758 "invalid unused variable name: `$varname'");
2767 # NOTE we no longer automatically clean SCRIPTS, because it is
2768 # useful to sometimes distribute scripts verbatim. This happens
2769 # eg in Automake itself.
2770 &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2771 'bin', 'sbin', 'libexec', 'pkgdata',
2776 # ($OUTFILE, $VFILE, @CLEAN_FILES)
2777 # &scan_texinfo_file ($FILENAME)
2778 # ------------------------------
2779 # $OUTFILE is the name of the info file produced by $FILENAME.
2780 # $VFILE is the name of the version.texi file used (empty if none).
2781 # @CLEAN_FILES is the list of by products (indexes etc.)
2782 sub scan_texinfo_file
2784 my ($filename) = @_;
2786 # These are always created, no matter whether indexes are used or not.
2787 my @clean_suffixes = ('aux', 'dvi', 'log', 'ps', 'toc',
2788 # grep new.*index texinfo.tex
2789 'cp', 'fn', 'ky', 'vr', 'tp', 'pg');
2791 # There are predefined indexes which don't follow the regular rules.
2792 my %predefined_index =
2795 'c' => 'cps', 'f' => 'fns', 'k' => 'kys',
2796 'v' => 'vrs', 't' => 'tps', 'p' => 'pgs'
2799 # There are commands which include a hidden index command.
2803 'fn' => 'fns', 'un' => 'fns',
2804 'typefn' => 'fns', 'typefun' => 'fns',
2805 'mac' => 'fns', 'spec' => 'fns',
2806 'op' => 'fns', 'typeop' => 'fns',
2807 'method' => 'fns', 'typemethod' => 'fns',
2809 'vr' => 'vrs', 'var' => 'vrs',
2810 'typevr' => 'vrs', 'typevar' => 'vrs',
2813 'ivar' => 'vrs', 'typeivar' => 'vrs',
2818 # Indexes stored into another one. In this case, the *.??s file
2820 my @syncodeindexes = ();
2822 my $texi = new IO::File ("< $filename");
2825 &am_error ("couldn't open `$filename': $!");
2828 print "$me: reading $filename\n" if $verbose;
2830 my ($outfile, $vfile);
2831 while ($_ = $texi->getline)
2833 if (/^\@setfilename +(\S+)/)
2836 if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
2838 &am_file_error ($filename, "$.: ",
2839 "output `$outfile' has unrecognized extension");
2843 # A "version.texi" file is actually any file whose name
2844 # matches "vers*.texi".
2845 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2850 # Try to find what are the indexes which are used.
2852 # Creating a new category of index.
2853 elsif (/^\@def(code)?index (\w+)/)
2855 push @clean_suffixes, $2;
2858 # Storing in a predefined index.
2859 elsif (/^\@([cfkvtp])index /)
2861 push @clean_suffixes, $predefined_index{$1};
2863 elsif (/^\@def(\w+) /)
2865 push @clean_suffixes, $hidden_index{$1}
2866 if defined $hidden_index{$1};
2869 # Merging an index into an another.
2870 elsif (/^\@syn(code)?index (\w+) (\w+)/)
2872 push @syncodeindexes, "$2s";
2873 push @clean_suffixes, "$3s";
2881 &am_error ("`$filename' missing \@setfilename");
2885 my $infobase = basename ($filename);
2886 $infobase =~ s/\.te?xi(nfo)?$//;
2887 # FIXME: I don't understand why, but I can't use "$infobase.$_" => 1.
2888 my %clean_files = map { "$infobase" . ".$_" => 1 } @clean_suffixes;
2889 grep { delete $clean_files{"$infobase.$_"} } @syncodeindexes;
2890 return ($outfile, $vfile, (sort keys %clean_files));
2894 # ($DO-SOMETHING, $TEXICLEANS)
2895 # handle_texinfo_helper ()
2897 # Handle all Texinfo source; helper for handle_texinfo
2898 sub handle_texinfo_helper
2900 &am_line_error ('TEXINFOS',
2901 "`TEXINFOS' is an anachronism; use `info_TEXINFOS'")
2902 if &variable_defined ('TEXINFOS');
2903 return (0, '') if (! &variable_defined ('info_TEXINFOS')
2904 && ! &variable_defined ('html_TEXINFOS'));
2906 if (&variable_defined ('html_TEXINFOS'))
2908 &am_line_error ('html_TEXINFOS',
2909 "HTML generation not yet supported");
2913 my @texis = &variable_value_as_list ('info_TEXINFOS', 'all');
2915 my (@info_deps_list, @dvis_list, @texi_deps);
2922 foreach my $info_cursor (@texis)
2924 my $infobase = $info_cursor;
2925 $infobase =~ s/\.(txi|texinfo|texi)$//;
2927 if ($infobase eq $info_cursor)
2929 # FIXME: report line number.
2930 &am_error ("texinfo file `$info_cursor' has unrecognized extension");
2933 $texi_suffixes{$1} = 1;
2935 # If 'version.texi' is referenced by input file, then include
2936 # automatic versioning capability.
2937 my ($out_file, $vtexi, @clean_files) =
2938 &scan_texinfo_file ("$relative_dir/$info_cursor")
2940 push (@texi_cleans, @clean_files);
2944 &am_error ("`$vtexi', included in `$info_cursor', also included in `$versions{$vtexi}'")
2945 if (defined $versions{$vtexi});
2946 $versions{$vtexi} = $info_cursor;
2948 # We number the stamp-vti files. This is doable since the
2949 # actual names don't matter much. We only number starting
2950 # with the second one, so that the common case looks nice.
2951 my $vti = ($done ? $done : 'vti');
2954 # This is ugly, but it is our historical practice.
2955 if ($config_aux_dir_set_in_configure_in)
2957 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2962 &require_file_with_line ('info_TEXINFOS', $FOREIGN,
2967 if ($config_aux_dir_set_in_configure_in)
2969 $conf_dir = $config_aux_dir;
2970 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
2974 $conf_dir = '$(srcdir)/';
2976 $output_rules .= &file_contents ('texi-vers',
2977 ('TEXI' => $info_cursor,
2980 'MDDIR' => $conf_dir));
2983 # If user specified file_TEXINFOS, then use that as explicit
2986 push (@texi_deps, $info_cursor);
2987 # Prefix with $(srcdir) because some version of make won't
2988 # work if the target has it and the dependency doesn't.
2989 push (@texi_deps, '$(srcdir)/' . $vtexi) if $vtexi;
2991 my $canonical = &canonicalize ($infobase);
2992 if (&variable_defined ($canonical . "_TEXINFOS"))
2994 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
2995 &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
2998 $output_rules .= ("\n" . $out_file . ": "
2999 . join (' ', @texi_deps)
3000 . "\n" . $infobase . ".dvi: "
3001 . join (' ', @texi_deps)
3004 push (@info_deps_list, $out_file);
3005 push (@dvis_list, $infobase . '.dvi');
3008 # Handle location of texinfo.tex.
3009 my $need_texi_file = 0;
3013 $texinfodir = '$(top_srcdir)/../texinfo';
3014 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3016 elsif ($config_aux_dir_set_in_configure_in)
3018 $texinfodir = $config_aux_dir;
3019 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
3020 $need_texi_file = 2; # so that we require_conf_file later
3022 elsif (&variable_defined ('TEXINFO_TEX'))
3024 # The user defined TEXINFO_TEX so assume he knows what he is
3026 $texinfodir = ('$(srcdir)/'
3027 . dirname (&variable_value ('TEXINFO_TEX')));
3031 $texinfodir = '$(srcdir)';
3032 $need_texi_file = 1;
3035 foreach my $txsfx (sort keys %texi_suffixes)
3037 $output_rules .= &file_contents ('texibuild',
3038 ('TEXINFODIR' => $texinfodir,
3039 'SUFFIX' => $txsfx));
3043 my $texiclean = &pretty_print_internal ("", "\t ", @texi_cleans);
3045 push (@dist_targets, 'dist-info');
3047 if (! defined $options{'no-installinfo'})
3049 # Make sure documentation is made and installed first. Use
3050 # $(INFO_DEPS), not 'info', because otherwise recursive makes
3051 # get run twice during "make all".
3052 unshift (@all, '$(INFO_DEPS)');
3055 &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
3056 &define_variable ("DVIS", join (' ', @dvis_list));
3057 # This next isn't strictly needed now -- the places that look here
3058 # could easily be changed to look in info_TEXINFOS. But this is
3059 # probably better, in case noinst_TEXINFOS is ever supported.
3060 &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
3062 # Do some error checking. Note that this file is not required
3063 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3065 if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
3067 if ($need_texi_file > 1)
3069 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
3074 &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
3078 return (1, $texiclean);
3083 # Handle all Texinfo source.
3086 my ($do_something, $texiclean) = handle_texinfo_helper ();
3087 $output_rules .= &file_contents ('texinfos',
3088 ('TEXICLEAN' => $texiclean,
3089 'LOCAL-TEXIS' => $do_something));
3092 # Handle any man pages.
3093 sub handle_man_pages
3095 &am_line_error ('MANS', "`MANS' is an anachronism; use `man_MANS'")
3096 if &variable_defined ('MANS');
3098 # Find all the sections in use. We do this by first looking for
3099 # "standard" sections, and then looking for any additional
3100 # sections used in man_MANS.
3101 my (%sections, %vlist);
3102 # We handle nodist_ for uniformity. man pages aren't distributed
3103 # by default so it isn't actually very important.
3104 foreach my $pfx ('', 'dist_', 'nodist_')
3106 # Add more sections as needed.
3107 foreach my $section ('0'..'9', 'n', 'l')
3109 if (&variable_defined ($pfx . 'man' . $section . '_MANS'))
3111 $sections{$section} = 1;
3112 $vlist{'$(' . $pfx . 'man' . $section . '_MANS)'} = 1;
3114 &push_dist_common ('$(' . $pfx . 'man' . $section . '_MANS)')
3119 if (&variable_defined ($pfx . 'man_MANS'))
3121 $vlist{'$(' . $pfx . 'man_MANS)'} = 1;
3122 foreach (&variable_value_as_list ($pfx . 'man_MANS', 'all'))
3124 # A page like `foo.1c' goes into man1dir.
3125 if (/\.([0-9a-z])([a-z]*)$/)
3131 &push_dist_common ('$(' . $pfx . 'man_MANS)')
3136 return unless %sections;
3138 # Now for each section, generate an install and unintall rule.
3139 # Sort sections so output is deterministic.
3140 foreach my $section (sort keys %sections)
3142 $output_rules .= &file_contents ('mans', ('SECTION' => $section));
3145 $output_vars .= &file_contents ('mans-vars',
3146 ('MANS' => join (' ', sort keys %vlist)));
3148 if (! defined $options{'no-installman'})
3150 push (@all, '$(MANS)');
3154 # Handle DATA variables.
3157 &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3158 'data', 'sysconf', 'sharedstate', 'localstate',
3159 'pkgdata', 'noinst', 'check');
3166 if (&variable_defined ('SUBDIRS'))
3168 $output_rules .= ("tags-recursive:\n"
3169 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3170 # Never fail here if a subdir fails; it
3172 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3173 . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3175 push (@tag_deps, 'tags-recursive');
3176 &depend ('.PHONY', 'tags-recursive');
3179 if (&saw_sources_p (1)
3180 || &variable_defined ('ETAGS_ARGS')
3184 foreach my $one_hdr (@config_headers)
3186 if ($relative_dir eq dirname ($one_hdr))
3188 # The config header is in this directory. So require it.
3189 $config .= ' ' if $config;
3190 $config .= basename ($one_hdr);
3193 $output_rules .= &file_contents ('tags',
3194 ('CONFIG' => $config,
3195 'DIRS' => join (' ', @tag_deps)));
3196 &examine_variable ('TAGS_DEPENDENCIES');
3198 elsif (&variable_defined ('TAGS_DEPENDENCIES'))
3200 &am_line_error ('TAGS_DEPENDENCIES',
3201 "doesn't make sense to define `TAGS_DEPENDENCIES' without sources or `ETAGS_ARGS'");
3205 # Every Makefile must define some sort of TAGS rule.
3206 # Otherwise, it would be possible for a top-level "make TAGS"
3207 # to fail because some subdirectory failed.
3208 $output_rules .= "tags: TAGS\nTAGS:\n\n";
3212 # Handle multilib support.
3215 if ($seen_multilib && $relative_dir eq '.')
3217 $output_rules .= &file_contents ('multilib');
3223 # &for_dist_common ($A, $B)
3224 # -------------------------
3225 # Subroutine for &handle_dist: sort files to dist.
3227 # We put README first because it then becomes easier to make a
3228 # Usenet-compliant shar file (in these, README must be first).
3230 # FIXME: do more ordering of files here.
3243 # handle_dist ($MAKEFILE)
3244 # -----------------------
3245 # Handle 'dist' target.
3248 my ($makefile) = @_;
3250 # `make dist' isn't used in a Cygnus-style tree.
3251 # Omit the rules so that people don't try to use them.
3252 return if $cygnus_mode;
3254 # Look for common files that should be included in distribution.
3255 # If the aux dir is set, and it does not have a Makefile.am, then
3256 # we check for these files there as well.
3259 if ($relative_dir eq '.'
3260 && $config_aux_dir_set_in_configure_in)
3262 ($auxdir = $config_aux_dir) =~ s,^\$\(top_srcdir\)/,,;
3263 if (! &is_make_dir ($auxdir))
3268 foreach my $cfile (@common_files)
3270 if (-f ($relative_dir . "/" . $cfile))
3272 &push_dist_common ($cfile);
3275 # Don't use `elsif' here because a file might meaningfully
3276 # appear in both directories.
3277 if ($check_aux && -f ($auxdir . '/' . $cfile))
3279 &push_dist_common ($auxdir . '/' . $cfile);
3283 # We might copy elements from $configure_dist_common to
3284 # %dist_common if we think we need to. If the file appears in our
3285 # directory, we would have discovered it already, so we don't
3286 # check that. But if the file is in a subdir without a Makefile,
3287 # we want to distribute it here if we are doing `.'. Ugly!
3288 if ($relative_dir eq '.')
3290 foreach my $file (split (' ' , $configure_dist_common))
3292 if (! &is_make_dir (dirname ($file)))
3294 &push_dist_common ($file);
3301 # Files to distributed. Don't use &variable_value_as_list
3302 # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3303 check_variable_defined_unconditionally ('DIST_COMMON');
3304 my @dist_common = split (' ', variable_value ('DIST_COMMON', 'TRUE'));
3305 @dist_common = uniq (sort for_dist_common (@dist_common));
3306 pretty_print ('DIST_COMMON = ', "\t", @dist_common);
3308 # Now that we've processed DIST_COMMON, disallow further attempts
3310 $handle_dist_run = 1;
3312 # Scan EXTRA_DIST to see if we need to distribute anything from a
3313 # subdir. If so, add it to the list. I didn't want to do this
3314 # originally, but there were so many requests that I finally
3316 if (&variable_defined ('EXTRA_DIST'))
3318 # FIXME: This should be fixed to work with conditionals. That
3319 # will require only making the entries in %dist_dirs under the
3320 # appropriate condition. This is meaningful if the nature of
3321 # the distribution should depend upon the configure options
3323 foreach (&variable_value_as_list ('EXTRA_DIST', ''))
3326 next unless s,/+[^/]+$,,;
3332 # We have to check DIST_COMMON for extra directories in case the
3333 # user put a source used in AC_OUTPUT into a subdir.
3334 foreach (&variable_value_as_list ('DIST_COMMON', 'all'))
3337 next unless s,/+[^/]+$,,;
3342 # Rule to check whether a distribution is viable.
3343 my %transform = ('DISTCHECK-HOOK' => &target_defined ('distcheck-hook'),
3344 'GETTEXT' => $seen_gettext);
3346 # Prepend $(distdir) to each directory given.
3347 my %rewritten = map { '$(distdir)/' . "$_" => 1 } keys %dist_dirs;
3348 $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);
3350 # If we have SUBDIRS, create all dist subdirectories and do
3352 if (&variable_defined ('SUBDIRS'))
3354 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3355 # to all possible directories, and use it. If DIST_SUBDIRS is
3356 # defined, just use it.
3357 my $dist_subdir_name;
3358 # Note that we check DIST_SUBDIRS first on purpose. At least
3359 # one project uses so many conditional subdirectories that
3360 # calling variable_conditionally_defined on SUBDIRS will cause
3361 # automake to grow to 150Mb. Sigh.
3362 if (&variable_defined ('DIST_SUBDIRS')
3363 || variable_conditionally_defined ('SUBDIRS'))
3365 $dist_subdir_name = 'DIST_SUBDIRS';
3366 if (! &variable_defined ('DIST_SUBDIRS'))
3368 &define_pretty_variable
3369 ('DIST_SUBDIRS', '',
3370 uniq (&variable_value_as_list ('SUBDIRS', 'all')));
3375 $dist_subdir_name = 'SUBDIRS';
3376 # We always define this because that is what `distclean'
3378 &define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
3381 $transform{'DIST_SUBDIR_NAME'} = $dist_subdir_name;
3384 # If the target `dist-hook' exists, make sure it is run. This
3385 # allows users to do random weird things to the distribution
3386 # before it is packaged up.
3387 push (@dist_targets, 'dist-hook')
3388 if &target_defined ('dist-hook');
3389 $transform{'DIST-TARGETS'} = join(' ', @dist_targets);
3391 # Defining $(DISTDIR).
3392 $transform{'DISTDIR'} = !&variable_defined('distdir');
3393 $transform{'TOP_DISTDIR'} = backname ($relative_dir);
3395 $output_rules .= &file_contents ('distdir', %transform);
3399 # Handle subdirectories.
3403 unless &variable_defined ('SUBDIRS');
3405 # Make sure each directory mentioned in SUBDIRS actually exists.
3406 foreach my $dir (&variable_value_as_list ('SUBDIRS', 'all'))
3408 # Skip directories substituted by configure.
3409 next if $dir =~ /^\@.*\@$/;
3411 if (! -d $am_relative_dir . '/' . $dir)
3413 &am_line_error ('SUBDIRS',
3414 "required directory $am_relative_dir/$dir does not exist");
3418 &am_line_error ('SUBDIRS', "directory should not contain `/'")
3422 $output_rules .= &file_contents ('subdirs');
3423 variable_pretty_output ('RECURSIVE_TARGETS', 'TRUE');
3427 # ($REGEN, @DEPENDENCIES)
3430 # If aclocal.m4 creation is automated, return the list of its dependencies.
3433 my $regen_aclocal = 0;
3436 unless $relative_dir eq '.';
3438 &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3439 &examine_variable ('CONFIGURE_DEPENDENCIES');
3441 if (-f 'aclocal.m4')
3443 &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3444 &push_dist_common ('aclocal.m4');
3446 my $aclocal = new IO::File ("< aclocal.m4");
3449 my $line = $aclocal->getline;
3452 if ($line =~ 'generated automatically by aclocal')
3461 if (-f 'acinclude.m4')
3464 push @ac_deps, 'acinclude.m4';
3467 if (&variable_defined ('ACLOCAL_M4_SOURCES'))
3469 push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3471 elsif (&variable_defined ('ACLOCAL_AMFLAGS'))
3473 # Scan all -I directories for m4 files. These are our
3475 my $examine_next = 0;
3476 foreach my $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
3481 if ($amdir !~ /^\// && -d $amdir)
3483 foreach my $ac_dep (&my_glob ($amdir . '/*.m4'))
3485 $ac_dep =~ s/^\.\/+//;
3486 push (@ac_deps, $ac_dep)
3487 unless $ac_dep eq "aclocal.m4"
3488 || $ac_dep eq "acinclude.m4";
3492 elsif ($amdir eq '-I')
3499 # Note that it might be possible that aclocal.m4 doesn't exist but
3500 # should be auto-generated. This case probably isn't very
3503 return ($regen_aclocal, @ac_deps);
3506 # Rewrite a list of input files into a form suitable to put on a
3507 # dependency list. The idea is that if an input file has a directory
3508 # part the same as the current directory, then the directory part is
3509 # simply removed. But if the directory part is different, then
3510 # $(top_srcdir) is prepended. Among other things, this is used to
3511 # generate the dependency list for the output files generated by
3512 # AC_OUTPUT. Consider what the dependencies should look like in this
3514 # AC_OUTPUT(src/out:src/in1:lib/in2)
3515 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3516 # If 0 then files that require this addition will simply be ignored.
3517 sub rewrite_inputs_into_dependencies
3519 my ($add_srcdir, @inputs) = @_;
3522 foreach my $single (@inputs)
3524 if (dirname ($single) eq $relative_dir)
3526 push (@newinputs, basename ($single));
3530 push (@newinputs, '$(top_srcdir)/' . $single);
3537 # Handle remaking and configure stuff.
3538 # We need the name of the input file, to do proper remaking rules.
3539 sub handle_configure
3541 my ($local, $input, @secondary_inputs) = @_;
3543 my $input_base = basename ($input);
3544 my $local_base = basename ($local);
3546 my $amfile = $input_base . '.am';
3547 # We know we can always add '.in' because it really should be an
3548 # error if the .in was missing originally.
3549 my $infile = '$(srcdir)/' . $input_base . '.in';
3550 my $colon_infile = '';
3551 if ($local ne $input || @secondary_inputs)
3553 $colon_infile = ':' . $input . '.in';
3555 $colon_infile .= ':' . join (':', @secondary_inputs)
3556 if @secondary_inputs;
3558 my @rewritten = &rewrite_inputs_into_dependencies (1, @secondary_inputs);
3560 my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4 ();
3563 &file_contents ('configure',
3567 => join (' ', @rewritten),
3569 => ((($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3574 => join (' ', @include_stack),
3578 => $cygnus_mode ? 'cygnus' : $strictness_name,
3580 => $cmdline_use_dependencies ? '' : ' --ignore-deps',
3581 'MAKEFILE-AM-SOURCES'
3582 => "$input$colon_infile",
3584 => $regen_aclocal_m4,
3586 => join (' ', @aclocal_m4_deps)));
3588 if ($relative_dir eq '.')
3590 &push_dist_common ('acconfig.h')
3594 # If we have a configure header, require it.
3595 my @local_fullnames = @config_fullnames;
3596 my @local_names = @config_names;
3598 my $distclean_config = '';
3599 foreach my $one_hdr (@config_headers)
3601 my $one_fullname = shift (@local_fullnames);
3602 my $one_name = shift (@local_names);
3604 my $header_dir = dirname ($one_name);
3606 # If the header is in the current directory we want to build
3607 # the header here. Otherwise, if we're at the topmost
3608 # directory and the header's directory doesn't have a
3609 # Makefile, then we also want to build the header.
3610 if ($relative_dir eq $header_dir
3611 || ($relative_dir eq '.' && ! &is_make_dir ($header_dir)))
3613 my ($cn_sans_dir, $stamp_dir);
3614 if ($relative_dir eq $header_dir)
3616 $cn_sans_dir = basename ($one_name);
3621 $cn_sans_dir = $one_name;
3622 if ($header_dir eq '.')
3628 $stamp_dir = $header_dir . '/';
3632 # Compute relative path from directory holding output
3633 # header to directory holding input header. FIXME:
3634 # doesn't handle case where we have multiple inputs.
3636 if (dirname ($one_hdr) eq $relative_dir)
3638 $ch_sans_dir = basename ($one_hdr);
3642 $ch_sans_dir = backname ($relative_dir) . '/' . $one_hdr;
3645 &require_file_with_conf_line ($config_header_line,
3646 $FOREIGN, $ch_sans_dir);
3648 # Header defined and in this directory.
3650 if (-f $one_name . '.top')
3652 push (@files, "${cn_sans_dir}.top");
3654 if (-f $one_name . '.bot')
3656 push (@files, "${cn_sans_dir}.bot");
3659 &push_dist_common (@files);
3661 # For now, acconfig.h can only appear in the top srcdir.
3662 if (-f 'acconfig.h')
3664 push (@files, '$(top_srcdir)/acconfig.h');
3667 my $stamp_name = 'stamp-h';
3668 $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3670 my $out_dir = dirname ($ch_sans_dir);
3673 &file_contents ('remake-hdr',
3674 ('FILES' => join (' ', @files),
3675 'CONFIG_HEADER' => $cn_sans_dir,
3676 'CONFIG_HEADER_IN' => $ch_sans_dir,
3677 'CONFIG_HEADER_FULL' => $one_fullname,
3678 'STAMP' => "$stamp_dir$stamp_name",
3679 'SRC_STAMP' => "$out_dir/$stamp_name"));
3681 &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3682 &require_file_with_conf_line ($config_header_line, $FOREIGN,
3683 "${out_dir}/${stamp_name}.in");
3685 $distclean_config .= ' ' if $distclean_config;
3686 $distclean_config .= $cn_sans_dir;
3690 if ($distclean_config)
3692 $output_rules .= &file_contents ('clean-hdr',
3693 ('FILES' => $distclean_config));
3696 # Set location of mkinstalldirs.
3697 &define_variable ('mkinstalldirs',
3698 ('$(SHELL) ' . $config_aux_dir . '/mkinstalldirs'));
3700 &am_line_error ('CONFIG_HEADER',
3701 "`CONFIG_HEADER' is an anachronism; now determined from `$configure_ac'")
3702 if &variable_defined ('CONFIG_HEADER');
3704 my $config_header = '';
3705 foreach my $one_name (@config_names)
3707 # Generate CONFIG_HEADER define.
3709 if ($relative_dir eq dirname ($one_name))
3711 $one_hdr = basename ($one_name);
3715 $one_hdr = "\$(top_builddir)/${one_name}";
3718 $config_header .= ' ' if $config_header;
3719 $config_header .= $one_hdr;
3723 &define_variable ("CONFIG_HEADER", $config_header);
3726 # Now look for other files in this directory which must be remade
3727 # by config.status, and generate rules for them.
3728 my @actual_other_files = ();
3729 foreach my $lfile (@other_input_files)
3732 my (@inputs, @rewritten_inputs);
3733 my ($need_rewritten);
3734 if ($lfile =~ /^([^:]*):(.*)$/)
3736 # This is the ":" syntax of AC_OUTPUT.
3738 $local = basename ($file);
3739 @inputs = split (':', $2);
3740 @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3741 $need_rewritten = 1;
3747 $local = basename ($file);
3748 @inputs = ($file . '.in');
3750 &rewrite_inputs_into_dependencies (1, @inputs);
3751 $need_rewritten = 0;
3754 # Make sure the dist directory for each input file is created.
3755 # We only have to do this at the topmost level though. This
3756 # is a bit ugly but it easier than spreading out the logic,
3757 # especially in cases like AC_OUTPUT(foo/out:bar/in), where
3758 # there is no Makefile in bar/.
3759 if ($relative_dir eq '.')
3763 $dist_dirs{dirname ($_)} = 1;
3767 # We skip any automake input files, as they are handled
3768 # elsewhere. We also skip files that aren't in this
3769 # directory. However, if the file's directory does not have a
3770 # Makefile, and we are currently doing `.', then we create a
3771 # rule to rebuild the file in the subdir.
3772 next if -f $file . '.am';
3773 my $fd = dirname ($file);
3774 if ($fd ne $relative_dir)
3776 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
3786 # Some users have been tempted to put `stamp-h' in the
3787 # AC_OUTPUT line. This won't do the right thing, so we
3788 # explicitly fail here.
3789 if ($local eq 'stamp-h')
3791 # FIXME: allow real filename.
3792 &am_conf_error ($configure_ac, $ac_output_line,
3793 'stamp-h should not appear in AC_OUTPUT');
3797 $output_rules .= ($local . ': '
3798 . '$(top_builddir)/config.status '
3799 . join (' ', @rewritten_inputs) . "\n"
3801 . 'cd $(top_builddir) && CONFIG_FILES='
3802 . ($relative_dir eq '.' ? '' : '$(subdir)/')
3803 . '$@' . ($need_rewritten
3804 ? (':' . join (':', @inputs))
3806 . ' CONFIG_HEADERS= CONFIG_LINKS= $(SHELL) ./config.status'
3808 push (@actual_other_files, $local);
3810 # Require all input files.
3811 &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3812 &rewrite_inputs_into_dependencies (0, @inputs));
3815 # These files get removed by "make clean".
3816 &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3822 my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3823 'oldinclude', 'pkginclude',
3827 next unless /\.(.*)$/;
3828 &saw_extension ($1);
3834 return if ! $seen_gettext || $relative_dir ne '.';
3836 if (! &variable_defined ('SUBDIRS'))
3839 ("AM_GNU_GETTEXT used but SUBDIRS not defined");
3843 my @subdirs = &variable_value_as_list ('SUBDIRS', 'all');
3844 &am_line_error ('SUBDIRS',
3845 "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
3846 if ! grep ('po', @subdirs);
3847 &am_line_error ('SUBDIRS',
3848 "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
3849 if ! grep ('intl', @subdirs);
3851 &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3854 # Handle footer elements.
3857 # NOTE don't use define_pretty_variable here, because
3858 # $contents{...} is already defined.
3859 $output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n\n"
3860 if variable_value ('SOURCES');
3863 &am_line_error ('.SUFFIXES',
3864 "use variable `SUFFIXES', not target `.SUFFIXES'")
3865 if target_defined ('.SUFFIXES');
3867 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3868 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
3869 # anything else, by sticking it right after the default: target.
3870 $output_header .= ".SUFFIXES:\n";
3871 if (@suffixes || &variable_defined ('SUFFIXES'))
3873 # Make sure suffixes has unique elements. Sort them to ensure
3874 # the output remains consistent. However, $(SUFFIXES) is
3875 # always at the start of the list, unsorted. This is done
3876 # because make will choose rules depending on the ordering of
3877 # suffixes, and this lets the user have some control. Push
3878 # actual suffixes, and not $(SUFFIXES). Some versions of make
3879 # do not like variable substitutions on the .SUFFIXES line.
3880 my @user_suffixes = (&variable_defined ('SUFFIXES')
3881 ? &variable_value_as_list ('SUFFIXES', '')
3884 my %suffixes = map { $_ => 1 } @suffixes;
3885 delete @suffixes{@user_suffixes};
3887 $output_header .= (".SUFFIXES: "
3888 . join (' ', @user_suffixes, sort keys %suffixes)
3892 $output_trailer .= file_contents ('footer');
3895 # Deal with installdirs target.
3896 sub handle_installdirs ()
3899 &file_contents ('install',
3901 => variable_value ('_am_installdirs') || ''));
3905 # Deal with all and all-am.
3908 my ($makefile) = @_;
3912 # Put this at the beginning for the sake of non-GNU makes. This
3913 # is still wrong if these makes can run parallel jobs. But it is
3915 unshift (@all, basename ($makefile));
3917 foreach my $one_name (@config_names)
3919 push (@all, basename ($one_name))
3920 if dirname ($one_name) eq $relative_dir;
3923 # Install `all' hooks.
3924 if (&target_defined ("all-local"))
3926 push (@all, "all-local");
3927 &depend ('.PHONY', "all-local");
3930 &pretty_print_rule ("all-am:", "\t\t", @all);
3931 &depend ('.PHONY', 'all-am', 'all');
3936 my @local_headers = ();
3937 push @local_headers, '$(BUILT_SOURCES)'
3938 if &variable_defined ('BUILT_SOURCES');
3939 foreach my $one_name (@config_names)
3941 push @local_headers, basename ($one_name)
3942 if dirname ($one_name) eq $relative_dir;
3947 # We need to make sure config.h is built before we recurse.
3948 # We also want to make sure that built sources are built
3949 # before any ordinary `all' targets are run. We can't do this
3950 # by changing the order of dependencies to the "all" because
3951 # that breaks when using parallel makes. Instead we handle
3952 # things explicitly.
3953 $output_all .= ("all: " . join (' ', @local_headers)
3955 . '$(MAKE) $(AM_MAKEFLAGS) '
3956 . (&variable_defined ('SUBDIRS')
3957 ? 'all-recursive' : 'all-am')
3962 $output_all .= "all: " . (&variable_defined ('SUBDIRS')
3963 ? 'all-recursive' : 'all-am') . "\n\n";
3968 # Handle check merge target specially.
3969 sub do_check_merge_target
3971 if (&target_defined ('check-local'))
3973 # User defined local form of target. So include it.
3974 push (@check_tests, 'check-local');
3975 &depend ('.PHONY', 'check-local');
3978 # In --cygnus mode, check doesn't depend on all.
3981 # Just run the local check rules.
3982 &pretty_print_rule ('check-am:', "\t\t", @check);
3986 # The check target must depend on the local equivalent of
3987 # `all', to ensure all the primary targets are built. Then it
3988 # must build the local check rules.
3989 $output_rules .= "check-am: all-am\n";
3990 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
3994 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
3998 &depend ('.PHONY', 'check', 'check-am');
3999 $output_rules .= ("check: "
4000 . (&variable_defined ('SUBDIRS')
4001 ? 'check-recursive' : 'check-am')
4005 # Handle all 'clean' targets.
4010 # Don't include `MAINTAINER'; it is handled specially below.
4011 foreach my $name ('MOSTLY', '', 'DIST')
4013 $transform{"${name}CLEAN"} = &variable_defined ("${name}CLEANFILES");
4016 # Built sources are automatically removed by maintainer-clean.
4017 push (@maintainer_clean_files, '$(BUILT_SOURCES)')
4018 if &variable_defined ('BUILT_SOURCES');
4019 push (@maintainer_clean_files, '$(MAINTAINERCLEANFILES)')
4020 if &variable_defined ('MAINTAINERCLEANFILES');
4022 $output_rules .= &file_contents ('clean',
4025 # Join with no space to avoid
4026 # spurious `test -z' success at
4028 => join ('', @maintainer_clean_files),
4030 # A space is required in the join here.
4031 => join (' ', @maintainer_clean_files)));
4035 # &depend ($CATEGORY, @DEPENDENDEES)
4036 # ----------------------------------
4037 # The target $CATEGORY depends on @DEPENDENDEES.
4040 my ($category, @dependendees) = @_;
4042 push (@{$dependencies{$category}}, @dependendees);
4047 # &target_cmp ($A, $B)
4048 # --------------------
4049 # Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
4062 # &handle_factored_dependencies ()
4063 # --------------------------------
4064 # Handle everything related to gathered targets.
4065 sub handle_factored_dependencies
4068 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4069 'uninstall-exec-local', 'uninstall-exec-hook')
4071 if (&target_defined ($utarg))
4074 $x =~ s/(data|exec)-//;
4075 &am_line_error ($utarg, "use `$x', not `$utarg'");
4079 if (&target_defined ('install-local'))
4081 &am_line_error ('install-local',
4082 "use `install-data-local' or `install-exec-local', "
4083 . "not `install-local'");
4086 if (!defined $options{'no-installinfo'}
4087 && &target_defined ('install-info-local'))
4089 &am_line_error ('install-info-local',
4090 "`install-info-local' target defined but "
4091 . "`no-installinfo' option not in use");
4094 # Install the -local hooks.
4095 foreach (keys %dependencies)
4097 # Hooks are installed on the -am targets.
4099 if (&target_defined ("$_-local"))
4101 depend ("$_-am", "$_-local");
4102 &depend ('.PHONY', "$_-local");
4106 # Install the -hook hooks.
4107 # FIXME: Why not be as liberal as we are with -local hooks?
4108 foreach ('install-exec', 'install-data')
4110 if (&target_defined ("$_-hook"))
4112 $actions{"$_-am"} .=
4113 ("\t\@\$(NORMAL_INSTALL)\n"
4114 . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
4118 # All the required targets are phony.
4119 depend ('.PHONY', keys %required_targets);
4121 # Actually output gathered targets.
4122 foreach (sort target_cmp keys %dependencies)
4124 # If there is nothing about this guy, skip it.
4126 unless (@{$dependencies{$_}}
4128 || $required_targets{$_});
4129 &pretty_print_rule ("$_:", "\t",
4130 uniq (sort @{$dependencies{$_}}));
4131 $output_rules .= $actions{$_}
4132 if defined $actions{$_};
4133 $output_rules .= "\n";
4138 # &handle_tests_dejagnu ()
4139 # ------------------------
4140 sub handle_tests_dejagnu
4142 push (@check_tests, 'check-DEJAGNU');
4143 $output_rules .= file_contents ('dejagnu');
4147 # Handle TESTS variable and other checks.
4150 if (defined $options{'dejagnu'})
4152 &handle_tests_dejagnu;
4156 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4159 "`$c' defined but `dejagnu' not in `AUTOMAKE_OPTIONS'")
4160 if &variable_defined ($c);
4164 if (&variable_defined ('TESTS'))
4166 push (@check_tests, 'check-TESTS');
4167 $output_rules .= &file_contents ('check');
4171 # Handle Emacs Lisp.
4172 sub handle_emacs_lisp
4174 my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4177 return if ! @elfiles;
4179 # Generate .elc files.
4180 my @elcfiles = map { $_ . 'c' } @elfiles;
4181 &define_pretty_variable ('ELCFILES', '', @elcfiles);
4183 push (@all, '$(ELCFILES)');
4185 &am_error ("`lisp_LISP' defined but `AM_PATH_LISPDIR' not in `$configure_ac'")
4186 if ! $seen_lispdir && &variable_defined ('lisp_LISP');
4188 &require_file_with_conf_line ('AM_PATH_LISPDIR', $FOREIGN, 'elisp-comp');
4194 my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4195 'python', 'noinst');
4196 return if ! @pyfiles;
4198 # Found some python.
4199 &am_error ("`python_PYTHON' defined but `AM_PATH_PYTHON' not in `$configure_ac'")
4200 if ! $seen_pythondir && &variable_defined ('python_PYTHON');
4202 &require_file_with_conf_line ('AM_PATH_PYTHON', $FOREIGN, 'py-compile');
4203 &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4209 my @sourcelist = &am_install_var ('-candist',
4211 'java', 'noinst', 'check');
4212 return if ! @sourcelist;
4214 my %valid = &am_primary_prefixes ('JAVA', 1,
4215 'java', 'noinst', 'check');
4218 foreach my $curs (keys %valid)
4220 if (! &variable_defined ($curs . '_JAVA') || $curs eq 'EXTRA')
4227 &am_line_error ($curs . '_JAVA',
4228 "multiple _JAVA primaries in use");
4233 push (@all, 'class' . $dir . '.stamp');
4237 # Handle some of the minor options.
4238 sub handle_minor_options
4240 if (defined $options{'readme-alpha'})
4242 if ($relative_dir eq '.')
4244 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4246 # FIXME: allow real filename.
4247 &am_conf_line_error ($configure_ac,
4248 $package_version_line,
4249 "version `$package_version' doesn't follow Gnits standards");
4251 elsif (defined $1 && -f 'README-alpha')
4253 # This means we have an alpha release. See
4254 # GNITS_VERSION_PATTERN for details.
4255 &require_file ($FOREIGN, 'README-alpha');
4261 ################################################################
4265 # &scan_autoconf_config_files ($CONFIG-FILES)
4266 # -------------------------------------------
4267 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4269 sub scan_autoconf_config_files
4271 my ($config_files) = @_;
4272 # Look at potential Makefile.am's.
4273 foreach (split ' ', $config_files)
4275 # Must skip empty string for Perl 4.
4276 next if $_ eq "\\" || $_ eq '';
4278 # Handle $local:$input syntax. Note that we ignore
4279 # every input file past the first, though we keep
4280 # those around for later.
4281 my ($local, $input, @rest) = split (/:/);
4288 # FIXME: should be error if .in is missing.
4289 $input =~ s/\.in$//;
4292 if (-f $input . '.am')
4294 # We have a file that automake should generate.
4295 $make_list{$input} = join (':', ($local, @rest));
4299 # We have a file that automake should cause to be
4300 # rebuilt, but shouldn't generate itself.
4301 push (@other_input_files, $_);
4307 # &scan_autoconf_traces ($FILENAME)
4308 # ---------------------------------
4309 # FIXME: For the time being, we don't care about the FILENAME.
4310 sub scan_autoconf_traces
4312 my ($filename) = @_;
4314 my $traces = "$ENV{amtraces} ";
4316 $traces .= ' -t AC_CONFIG_FILES';
4317 $traces .= ' -t AC_LIBSOURCE';
4318 $traces .= ' -t AC_SUBST';
4320 my $tracefh = new IO::File ("$traces |");
4323 die "$me: couldn't open `$traces': $!\n";
4325 print "$me: reading $traces\n" if $verbose;
4327 while ($_ = $tracefh->getline)
4330 my ($file, $line, $macro, @args) = split /:/;
4331 my $here = "$file:$line";
4333 # Alphabetical ordering please.
4334 if ($macro eq 'AC_CONFIG_FILES')
4336 # Look at potential Makefile.am's.
4337 &scan_autoconf_config_files ($args[0]);
4339 elsif ($macro eq 'AC_LIBSOURCE')
4341 my $source = "$args[0].c";
4342 # We should actually also `close' the sources: getopt.c
4343 # wants getopt.h etc. But actually it should be done in the
4344 # macro itself, i.e., we have to first fix Autoconf to extend
4345 # _AC_LIBOBJ_DECL and use it the in various macros.
4346 if (!defined $libsources{$source})
4348 print STDERR "traces: discovered $source\n";
4349 $libsources{$source} = $here;
4352 elsif ($macro eq 'AC_SUBST')
4354 if (!defined $configure_vars{$args[0]})
4356 print STDERR "traces: discovered AC_SUBST($args[0])\n";
4357 $configure_vars{$args[0]} = $here;
4363 || die "$me: close: $traces: $!\n";
4367 # &scan_one_autoconf_file ($FILENAME)
4368 # -----------------------------------
4369 # Scan one file for interesting things. Subroutine of
4370 # &scan_autoconf_files.
4371 sub scan_one_autoconf_file
4373 my ($filename) = @_;
4375 my $configfh = new IO::File ("< $filename");
4378 die "$me: couldn't open `$filename': $!\n";
4380 print "$me: reading $filename\n" if $verbose;
4382 my ($in_ac_output, $in_ac_replace) = (0, 0);
4383 while ($_ = $configfh->getline)
4385 # Remove comments from current line.
4389 # Skip macro definitions. Otherwise we might be confused into
4390 # thinking that a macro that was only defined was actually
4394 # Follow includes. This is a weirdness commonly in use at
4395 # Cygnus and hopefully nowhere else.
4396 if (/sinclude\((.*)\)/ && -f $1)
4398 # $_ being local, if we don't preserve it, when coming
4399 # back we will have $_ undefined, which is bad for the
4400 # the rest of this routine.
4401 my $underscore = $_;
4402 &scan_one_autoconf_file ($1);
4406 # Populate libobjs array.
4407 if (/AC_FUNC_ALLOCA/)
4409 $libsources{'alloca.c'} = 1;
4411 elsif (/AC_FUNC_GETLOADAVG/)
4413 $libsources{'getloadavg.c'} = 1;
4415 elsif (/AC_FUNC_MEMCMP/)
4417 $libsources{'memcmp.c'} = 1;
4419 elsif (/AC_STRUCT_ST_BLOCKS/)
4421 $libsources{'fileblocks.c'} = 1;
4423 elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4425 $libsources{'getopt.c'} = 1;
4426 $libsources{'getopt1.c'} = 1;
4428 elsif (/AM_FUNC_STRTOD/)
4430 $libsources{'strtod.c'} = 1;
4432 elsif (/AM_WITH_REGEX/)
4434 $libsources{'rx.c'} = 1;
4435 $libsources{'rx.h'} = 1;
4436 $libsources{'regex.c'} = 1;
4437 $libsources{'regex.h'} = 1;
4439 elsif (/AC_FUNC_MKTIME/)
4441 $libsources{'mktime.c'} = 1;
4443 elsif (/AM_FUNC_ERROR_AT_LINE/)
4445 $libsources{'error.c'} = 1;
4446 $libsources{'error.h'} = 1;
4448 elsif (/AM_FUNC_OBSTACK/)
4450 $libsources{'obstack.c'} = 1;
4451 $libsources{'obstack.h'} = 1;
4453 elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4454 || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4456 foreach my $libobj_iter (split (' ', $1))
4458 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4459 || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4460 || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4462 $libsources{$1 . '.c'} = 1;
4466 elsif (/AC_LIBOBJ\(([^)]+)\)/)
4468 $libsources{"$1.c"} = 1;
4470 elsif (/AC_LIBSOURCE\(([^)]+)\)/)
4472 $libsources{&unquote_m4_arg ($1)} = 1;
4474 elsif (/AC_LIBSOURCES\(([^)]+)\)/)
4476 foreach my $lc_iter (split (/[, ]+/, &unquote_m4_arg ($1)))
4478 $libsources{$lc_iter} = 1;
4482 if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4488 $in_ac_replace = 0 if s/[\]\)].*$//;
4489 # Remove trailing backslash.
4493 # Need to skip empty elements for Perl 4.
4495 $libsources{$_ . '.c'} = 1;
4499 if (/$obsolete_rx/o)
4502 if ($obsolete_macros{$1} ne '')
4504 $hint = '; ' . $obsolete_macros{$1};
4506 &am_conf_line_error ($filename, $., "`$1' is obsolete$hint");
4509 # Process the AC_OUTPUT and AC_CONFIG_FILES macros.
4510 if (! $in_ac_output && s/AC_(OUTPUT|CONFIG_FILES)\s*\(\[?//)
4513 $ac_output_line = $.;
4524 # Look at potential Makefile.am's.
4525 &scan_autoconf_config_files ($_);
4528 && scalar keys %make_list == 0
4529 && @other_input_files == 0)
4531 &am_conf_line_error ($filename, $ac_output_line,
4532 "No files mentioned in `AC_OUTPUT'");
4537 if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4539 @config_aux_path = &unquote_m4_arg ($1);
4540 $config_aux_dir_set_in_configure_in = 1;
4543 # Check for ansi2knr.
4544 $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4549 $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4552 # Check for `-c -o' code.
4553 $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4555 # Check for NLS support.
4556 if (/AM_GNU_GETTEXT/)
4559 $ac_gettext_line = $.;
4562 # Handle configuration headers. A config header of `[$1]'
4563 # means we are actually scanning AM_CONFIG_HEADER from
4565 if (/A([CM])_CONFIG_HEADERS?\s*\((.*)\)/
4569 ($filename, $., "`automake requires `AM_CONFIG_HEADER', not `AC_CONFIG_HEADER'")
4572 $config_header_line = $.;
4573 foreach my $one_hdr (split (' ', &unquote_m4_arg ($2)))
4575 push (@config_fullnames, $one_hdr);
4576 if ($one_hdr =~ /^([^:]+):(.+)$/)
4578 push (@config_names, $1);
4579 push (@config_headers, $2);
4583 push (@config_names, $one_hdr);
4584 push (@config_headers, $one_hdr . '.in');
4589 # Handle AC_CANONICAL_*. Always allow upgrading to
4590 # AC_CANONICAL_SYSTEM, but never downgrading.
4591 $seen_canonical = $AC_CANONICAL_HOST
4592 if ! $seen_canonical
4593 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4594 $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4596 # If using X, include some extra variable definitions. NOTE
4597 # we don't want to force these into CFLAGS or anything,
4598 # because not all programs will necessarily use X.
4601 foreach my $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS',
4604 $configure_vars{$var} = $filename . ':' . $.
4608 # This macro handles several different things.
4609 if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4611 ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4612 $package_version_line = $.;
4613 $seen_init_automake = 1;
4618 $configure_vars{'LEX'} = $filename . ':' . $.;
4619 $seen_decl_yytext = 1;
4621 if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.(ac|in)$/)
4623 &am_conf_line_warning ($filename, $., "`AC_DECL_YYTEXT' is covered by `AM_PROG_LEX'");
4625 if (/AC_PROG_LEX/ && $filename =~ /configure\.(ac|in)$/)
4627 &am_conf_line_warning ($filename, $., "automake requires `AM_PROG_LEX', not `AC_PROG_LEX'");
4630 if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4632 $configure_vars{$1} = $filename . ':' . $.;
4634 if (/$AC_CHECK_PATTERN/o)
4636 $configure_vars{$3} = $filename . ':' . $.;
4638 if (/$AM_MISSING_PATTERN/o
4642 && $1 ne 'AUTOHEADER'
4643 # AM_INIT_AUTOMAKE is AM_MISSING_PROG'ing MAKEINFO. But
4644 # we handle it elsewhere.
4645 && $1 ne 'MAKEINFO')
4647 $configure_vars{$1} = $filename . ':' . $.;
4650 # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4651 # but later define it elsewhere. This is pretty hacky. We
4652 # also explicitly avoid INSTALL_SCRIPT and some other
4653 # variables because they are defined in header-vars.am.
4655 if (/$AC_SUBST_PATTERN/o
4657 && $1 ne 'INSTALL_SCRIPT'
4658 && $1 ne 'INSTALL_DATA')
4660 $configure_vars{$1} = $filename . ':' . $.;
4663 $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4664 if (/AM_MAINTAINER_MODE/)
4666 $seen_maint_mode = 1;
4667 $configure_cond{'MAINTAINER_MODE'} = 1;
4670 $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4672 if (/AM_PATH_PYTHON/)
4674 $seen_pythondir = 1;
4675 $configure_vars{'pythondir'} = $filename . ':' . $.;
4676 $configure_vars{'PYTHON'} = $filename . ':' . $.;
4679 if (/A(C|M)_PROG_LIBTOOL/)
4681 # We're not ready for this yet. People still use a
4682 # libtool with no AC_PROG_LIBTOOL. Once that is the
4683 # dominant version we can reenable this code -- but next
4684 # time by mentioning the macro in %obsolete_macros, both
4685 # here and in aclocal.in.
4687 # if (/AM_PROG_LIBTOOL/)
4689 # &am_conf_line_warning ($filename, $., "`AM_PROG_LIBTOOL' is obsolete, use `AC_PROG_LIBTOOL' instead");
4693 $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4694 $configure_vars{'RANLIB'} = $filename . ':' . $.;
4695 $configure_vars{'CC'} = $filename . ':' . $.;
4696 # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST. Make sure we
4697 # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4698 $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4701 $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4703 if (/$AM_CONDITIONAL_PATTERN/o)
4705 $configure_cond{$1} = 1;
4708 # Check for Fortran 77 intrinsic and run-time libraries.
4709 if (/AC_F77_LIBRARY_LDFLAGS/)
4711 $configure_vars{'FLIBS'} = $filename . ':' . $.;
4719 # &scan_autoconf_files ()
4720 # -----------------------
4721 # Check whether we use `configure.ac' or `configure.in'.
4722 # Scan it (and possibly `aclocal.m4') for interesting things.
4723 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
4724 sub scan_autoconf_files
4726 # Reinitialize libsources here. This isn't really necessary,
4727 # since we currently assume there is only one configure.ac. But
4728 # that won't always be the case.
4731 warn "$me: both `configure.ac' and `configure.in' present:"
4732 . " ignoring `configure.in'\n"
4733 if -f 'configure.ac' && -f 'configure.in';
4734 $configure_ac = 'configure.in'
4735 if -f 'configure.in';
4736 $configure_ac = 'configure.ac'
4737 if -f 'configure.ac';
4738 die "$me: `configure.ac' or `configure.in' is required\n"
4741 &scan_one_autoconf_file ($configure_ac);
4742 &scan_one_autoconf_file ('aclocal.m4')
4745 if (defined $ENV{'amtraces'})
4747 warn '$me: Autoconf traces is an experimental feature';
4748 warn '$me: use at your own risks';
4750 &scan_autoconf_traces ($configure_ac);
4753 # Set input and output files if not specified by user.
4756 @input_files = sort keys %make_list;
4757 %output_files = %make_list;
4760 @configure_input_files = sort keys %make_list;
4762 &am_conf_error ("`AM_INIT_AUTOMAKE' must be used")
4763 if ! $seen_init_automake;
4765 # Look for some files we need. Always check for these. This
4766 # check must be done for every run, even those where we are only
4767 # looking at a subdir Makefile. We must set relative_dir so that
4768 # the file-finding machinery works.
4769 # FIXME: Is this broken because it needs dynamic scopes.
4770 # My tests seems to show it's not the case.
4771 $relative_dir = '.';
4772 &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4773 &am_error ("`install.sh' is an anachronism; use `install-sh' instead")
4774 if -f $config_aux_path[0] . '/install.sh';
4776 &require_config_file ($FOREIGN, 'py-compile')
4779 # Preserve dist_common for later.
4780 $configure_dist_common = variable_value ('DIST_COMMON', 'TRUE') || '';
4783 ################################################################
4785 # Set up for Cygnus mode.
4788 return unless $cygnus_mode;
4790 &set_strictness ('foreign');
4791 $options{'no-installinfo'} = 1;
4792 $options{'no-dependencies'} = 1;
4793 $use_dependencies = 0;
4795 if (! $seen_maint_mode)
4797 &am_conf_error ("`AM_MAINTAINER_MODE' required when --cygnus specified");
4801 # Do any extra checking for GNU standards.
4802 sub check_gnu_standards
4804 if ($relative_dir eq '.')
4806 # In top level (or only) directory.
4807 &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4808 'AUTHORS', 'ChangeLog');
4811 if ($strictness >= $GNU
4812 && defined $options{'no-installman'})
4814 &am_line_error ('AUTOMAKE_OPTIONS',
4815 "option `no-installman' disallowed by GNU standards");
4818 if ($strictness >= $GNU
4819 && defined $options{'no-installinfo'})
4821 &am_line_error ('AUTOMAKE_OPTIONS',
4822 "option `no-installinfo' disallowed by GNU standards");
4826 # Do any extra checking for GNITS standards.
4827 sub check_gnits_standards
4829 if ($relative_dir eq '.')
4831 # In top level (or only) directory.
4832 &require_file ($GNITS, 'THANKS');
4836 ################################################################
4838 # Functions to handle files of each language.
4840 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
4841 # simple formula: Return value is $LANG_SUBDIR if the resulting object
4842 # file should be in a subdir if the source file is, $LANG_PROCESS if
4843 # file is to be dealt with, $LANG_IGNORE otherwise.
4845 # Much of the actual processing is handled in
4846 # handle_single_transform_list. These functions exist so that
4847 # auxiliary information can be recorded for a later cleanup pass.
4848 # Note that the calls to these functions are computed, so don't bother
4849 # searching for their precise names in the source.
4851 # This is just a convenience function that can be used to determine
4852 # when a subdir object should be used.
4855 return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4858 # Rewrite a single C source file.
4861 my ($directory, $base, $ext) = @_;
4863 if (defined $options{'ansi2knr'} && $base =~ /_$/)
4865 # FIXME: include line number in error.
4866 &am_error ("C source file `$base.c' would be deleted by ansi2knr rules");
4869 my $r = $LANG_PROCESS;
4870 if (defined $options{'subdir-objects'})
4873 $base = $directory . '/' . $base;
4877 # Only give error once.
4879 # FIXME: line number.
4880 &am_error ("C objects in subdir but `AM_PROG_CC_C_O' not in `$configure_ac'");
4883 &require_config_file ($FOREIGN, 'compile');
4886 $de_ansi_files{$base} = 1;
4890 # Rewrite a single C++ source file.
4891 sub lang_cxx_rewrite
4893 return &lang_sub_obj;
4896 # Rewrite a single header file.
4897 sub lang_header_rewrite
4899 # Header files are simply ignored.
4900 return $LANG_IGNORE;
4903 # Rewrite a single yacc file.
4904 sub lang_yacc_rewrite
4906 my ($directory, $base, $ext) = @_;
4908 my $r = &lang_sub_obj;
4909 (my $newext = $ext) =~ tr/y/c/;
4910 return ($r, $newext);
4913 # Rewrite a single yacc++ file.
4914 sub lang_yaccxx_rewrite
4916 my ($directory, $base, $ext) = @_;
4918 my $r = &lang_sub_obj;
4919 (my $newext = $ext) =~ tr/y/c/;
4920 return ($r, $newext);
4923 # Rewrite a single lex file.
4924 sub lang_lex_rewrite
4926 my ($directory, $base, $ext) = @_;
4928 my $r = &lang_sub_obj;
4929 (my $newext = $ext) =~ tr/l/c/;
4930 return ($r, $newext);
4933 # Rewrite a single lex++ file.
4934 sub lang_lexxx_rewrite
4936 my ($directory, $base, $ext) = @_;
4938 my $r = &lang_sub_obj;
4939 (my $newext = $ext) =~ tr/l/c/;
4940 return ($r, $newext);
4943 # Rewrite a single assembly file.
4944 sub lang_asm_rewrite
4946 return &lang_sub_obj;
4949 # Rewrite a single Fortran 77 file.
4950 sub lang_f77_rewrite
4952 return $LANG_PROCESS;
4955 # Rewrite a single preprocessed Fortran 77 file.
4956 sub lang_ppf77_rewrite
4958 return $LANG_PROCESS;
4961 # Rewrite a single ratfor file.
4962 sub lang_ratfor_rewrite
4964 return $LANG_PROCESS;
4967 # Rewrite a single Objective C file.
4968 sub lang_objc_rewrite
4970 return &lang_sub_obj;
4973 # Rewrite a single Java file.
4974 sub lang_java_rewrite
4976 return $LANG_SUBDIR;
4979 # The lang_X_finish functions are called after all source file
4980 # processing is done. Each should handle defining rules for the
4981 # language, etc. A finish function is only called if a source file of
4982 # the appropriate type has been seen.
4986 # Push all libobjs files onto de_ansi_files. We actually only
4987 # push files which exist in the current directory, and which are
4988 # genuine source files.
4989 foreach my $file (keys %libsources)
4991 if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
4993 $de_ansi_files{$1} = 1;
4997 if (defined $options{'ansi2knr'} && keys %de_ansi_files)
4999 # Make all _.c files depend on their corresponding .c files.
5001 foreach my $base (sort keys %de_ansi_files)
5003 # Each _.c file must depend on ansi2knr; otherwise it
5004 # might be used in a parallel build before it is built.
5005 # We need to support files in the srcdir and in the build
5006 # dir (because these files might be auto-generated. But
5007 # we can't use $< -- some makes only define $< during a
5009 $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
5010 . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5011 . '`if test -f $(srcdir)/' . $base . '.c'
5012 . '; then echo $(srcdir)/' . $base . '.c'
5013 . '; else echo ' . $base . '.c; fi` '
5014 . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5015 . '| $(ANSI2KNR) > ' . $base . "_.c"
5016 # If ansi2knr fails then we shouldn't
5017 # create the _.c file
5018 . " || rm -f ${base}_.c\n");
5019 push (@objects, $base . '_.$(OBJEXT)');
5020 push (@objects, $base . '_.lo')
5024 # Make all _.o (and _.lo) files depend on ansi2knr.
5025 # Use a sneaky little hack to make it print nicely.
5026 &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5030 # This is a yacc helper which is called whenever we have decided to
5031 # compile a yacc file.
5032 sub lang_yacc_target_hook
5034 my ($self, $aggregate, $output, $input) = @_;
5036 my $flag = $aggregate . "_YFLAGS";
5037 if ((&variable_defined ($flag)
5038 && &variable_value ($flag) =~ /$DASH_D_PATTERN/o)
5039 || (&variable_defined ('YFLAGS')
5040 && &variable_value ('YFLAGS') =~ /$DASH_D_PATTERN/o))
5042 (my $output_base = $output) =~ s/\..*$//;
5043 my $header = $output_base . '.h';
5045 # Found a `-d' that applies to the compilation of this file.
5046 # Add a dependency for the generated header file, and arrange
5047 # for that file to be included in the distribution.
5048 # FIXME: this fails for `nodist_*_SOURCES'.
5049 $output_rules .= "${header}: $input\n";
5050 &push_dist_common ($header);
5051 # If the files are built in the build directory, then we want
5052 # to remove them with `make clean'. If they are in srcdir
5053 # they shouldn't be touched. However, we can't determine this
5054 # statically, and the GNU rules say that yacc/lex output files
5055 # should be removed by maintainer-clean. So that's what we
5057 push (@maintainer_clean_files, $header);
5061 # This is a helper for both lex and yacc.
5062 sub yacc_lex_finish_helper
5064 return if defined $language_scratch{'lex-yacc-done'};
5065 $language_scratch{'lex-yacc-done'} = 1;
5067 # If there is more than one distinct yacc (resp lex) source file
5068 # in a given directory, then the `ylwrap' program is required to
5069 # allow parallel builds to work correctly. FIXME: for now, no
5071 &require_config_file ($FOREIGN, 'ylwrap');
5072 if ($config_aux_dir_set_in_configure_in)
5074 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5078 &define_variable ('YLWRAP', '$(top_srcdir)/ylwrap');
5082 sub lang_yacc_finish
5084 return if defined $language_scratch{'yacc-done'};
5085 $language_scratch{'yacc-done'} = 1;
5087 if (&variable_defined ('YACCFLAGS'))
5089 &am_line_error ('YACCFLAGS',
5090 "`YACCFLAGS' obsolete; use `YFLAGS' instead");
5093 if (count_files_for_language ('yacc') > 1)
5095 &yacc_lex_finish_helper;
5102 return if defined $language_scratch{'lex-done'};
5103 $language_scratch{'lex-done'} = 1;
5105 if (! $seen_decl_yytext)
5107 &am_error ("lex source seen but `AC_DECL_YYTEXT' not in `$configure_ac'");
5110 if (count_files_for_language ('lex') > 1)
5112 &yacc_lex_finish_helper;
5117 # Given a hash table of linker names, pick the name that has the most
5118 # precedence. This is lame, but something has to have global
5119 # knowledge in order to eliminate the conflict. Add more linkers as
5126 if defined $linkers{'GCJLINK'};
5128 if defined $linkers{'CXXLINK'};
5130 if defined $linkers{'F77LINK'};
5132 if defined $linkers{'OBJCLINK'};
5136 # Called to indicate that an extension was used.
5140 if (! defined $extension_seen{$ext})
5142 $extension_seen{$ext} = 1;
5146 ++$extension_seen{$ext};
5150 # Return the number of files seen for a given language. Knows about
5151 # special cases we care about. FIXME: this is hideous. We need
5152 # something that involves real language objects. For instance yacc
5153 # and yaccxx could both derive from a common yacc class which would
5154 # know about the strange ylwrap requirement. (Or better yet we could
5155 # just not support legacy yacc!)
5156 sub count_files_for_language
5161 if ($name eq 'yacc' || $name eq 'yaccxx')
5163 @names = ('yacc', 'yaccxx');
5165 elsif ($name eq 'lex' || $name eq 'lexxx')
5167 @names = ('lex', 'lexxx');
5175 foreach $name (@names)
5177 my $lang = $languages{$name};
5178 foreach my $ext (@{$lang->extensions})
5180 $r += $extension_seen{$ext}
5181 if defined $extension_seen{$ext};
5188 # Called to ask whether source files have been seen . If HEADERS is 1,
5189 # headers can be included.
5194 # count all the sources
5196 foreach my $val (values %extension_seen)
5203 $count -= count_files_for_language ('header');
5210 # register_language (%ATTRIBUTE)
5211 # ------------------------------
5212 # Register a single language.
5213 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5214 sub register_language (%)
5220 unless defined $option{'ansi'};
5221 $option{'autodep'} = 'no'
5222 unless defined $option{'autodep'};
5223 $option{'linker'} = ''
5224 unless defined $option{'linker'};
5225 $option{'define_flag'} = 1
5226 unless defined $option{'define_flag'};
5228 my $lang = new Language (%option);
5231 grep ($extension_map{$_} = $lang->name, @{$lang->extensions});
5232 $languages{$lang->name} = $lang;
5235 # This function is used to find a path from a user-specified suffix to
5236 # `o' or to some other suffix we recognize internally, eg `cc'.
5239 my ($source_ext) = @_;
5241 # FIXME: hard-coding `o' is a mistake. Doing something
5242 # intelligent is harder.
5243 while (! $extension_map{$source_ext}
5244 && $source_ext ne 'o'
5245 && defined $suffix_rules{$source_ext})
5247 $source_ext = $suffix_rules{$source_ext};
5254 ################################################################
5256 # Pretty-print something. HEAD is what should be printed at the
5257 # beginning of the first line, FILL is what should be printed at the
5258 # beginning of every subsequent line.
5259 sub pretty_print_internal
5261 my ($head, $fill, @values) = @_;
5263 my $column = length ($head);
5266 # Fill length is number of characters. However, each Tab
5267 # character counts for eight. So we count the number of Tabs and
5269 my $fill_length = length ($fill);
5270 $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5274 # "71" because we also print a space.
5275 if ($column + length ($_) > 71)
5277 $result .= " \\\n" . $fill;
5278 $column = $fill_length;
5280 $result .= ' ' if $result =~ /\S\z/;
5282 $column += length ($_) + 1;
5289 # Pretty-print something and append to output_vars.
5292 $output_vars .= &pretty_print_internal (@_);
5295 # Pretty-print something and append to output_rules.
5296 sub pretty_print_rule
5298 $output_rules .= &pretty_print_internal (@_);
5302 ################################################################
5306 # &conditional_string(@COND-STACK)
5307 # --------------------------------
5308 # Build a string which denotes the conditional in @COND-STACK. Some
5309 # simplifications are done: `TRUE' entries are elided, and any `FALSE'
5310 # entry results in a return of `FALSE'.
5311 sub conditional_string
5315 if (grep (/^FALSE$/, @stack))
5321 return join (' ', uniq sort grep (!/^TRUE$/, @stack));
5327 # &conditional_true_when ($COND, $WHEN)
5328 # -------------------------------------
5329 # See if a conditional is true. Both arguments are conditional
5330 # strings. This returns true if the first conditional is true when
5331 # the second conditional is true.
5332 # For instance with $COND = `BAR FOO', and $WHEN = `BAR BAZ FOO',
5333 # obviously return 1, and 0 when, for instance, $WHEN = `FOO'.
5334 sub conditional_true_when ($$)
5336 my ($cond, $when) = @_;
5338 # Make a hash holding all the values from $WHEN.
5339 my %cond_vals = map { $_ => 1 } split (' ', $when);
5341 # Check each component of $cond, which looks `COND1 COND2'.
5342 foreach my $comp (split (' ', $cond))
5344 # TRUE is always true.
5345 next if $comp eq 'TRUE';
5346 return 0 if ! defined $cond_vals{$comp};
5354 # &conditional_is_redundant ($COND, @WHENS)
5355 # ----------------------------------------
5356 # Determine whether $COND is redundant with respect to @WHENS.
5358 # Returns true if $COND is true for any of the conditions in @WHENS.
5360 # If there are no @WHENS, then behave as if @WHENS contained a single empty
5362 sub conditional_is_redundant ($@)
5364 my ($cond, @whens) = @_;
5368 return 1 if conditional_true_when ($cond, "");
5372 foreach my $when (@whens)
5374 return 1 if conditional_true_when ($cond, $when);
5383 # condition_negate ($COND)
5384 # ------------------------
5385 sub condition_negate ($)
5389 $cond =~ s/TRUE$/TRUEO/;
5390 $cond =~ s/FALSE$/TRUE/;
5391 $cond =~ s/TRUEO$/FALSE/;
5397 # Compare condition names.
5398 # Issue them in alphabetical order, foo_TRUE before foo_FALSE.
5401 # Be careful we might be comparing `' or `#'.
5402 $a =~ /^(.*)_(TRUE|FALSE)$/;
5403 my ($aname, $abool) = ($1 || '', $2 || '');
5404 $b =~ /^(.*)_(TRUE|FALSE)$/;
5405 my ($bname, $bbool) = ($1 || '', $2 || '');
5406 return ($aname cmp $bname
5407 # Don't bother with IFs, given that TRUE is after FALSE
5408 # just cmp in the reverse order.
5409 || $bbool cmp $abool
5415 # &make_condition (@CONDITIONS)
5416 # -----------------------------
5417 # Transform a list of conditions (themselves can be an internal list
5418 # of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
5419 # Make conditional (a pattern for AC_SUBST).
5420 # Correctly returns the empty string when there are no conditions.
5423 my $res = conditional_string (@_);
5425 # There are no conditions.
5431 elsif ($res eq 'FALSE')
5438 $res = '@' . $res . '@';
5447 ## ------------------------------ ##
5448 ## Handling the condition stack. ##
5449 ## ------------------------------ ##
5453 # cond_stack_if ($NEGATE, $COND, $WHERE)
5454 # --------------------------------------
5455 sub cond_stack_if ($$$)
5457 my ($negate, $cond, $where) = @_;
5459 &am_file_error ($where, "$cond does not appear in AM_CONDITIONAL")
5460 if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
5462 $cond = "${cond}_TRUE"
5463 unless $cond =~ /^TRUE|FALSE$/;
5464 $cond = condition_negate ($cond)
5467 push (@cond_stack, $cond);
5469 return conditional_string (@cond_stack);
5474 # cond_stack_else ($NEGATE, $COND, $WHERE)
5475 # ----------------------------------------
5476 sub cond_stack_else ($$$)
5478 my ($negate, $cond, $where) = @_;
5482 &am_file_error ($where, "else without if");
5486 $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);
5488 # If $COND is given, check against it.
5491 $cond = "${cond}_TRUE"
5492 unless $cond =~ /^TRUE|FALSE$/;
5493 $cond = condition_negate ($cond)
5496 &am_file_error ($where,
5497 "else reminder ($negate$cond) incompatible with "
5498 . "current conditional: $cond_stack[$#cond_stack]")
5499 if $cond_stack[$#cond_stack] ne $cond;
5502 return conditional_string (@cond_stack);
5507 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5508 # -----------------------------------------
5509 sub cond_stack_endif ($$$)
5511 my ($negate, $cond, $where) = @_;
5516 &am_file_error ($where, "endif without if: $negate$cond");
5521 # If $COND is given, check against it.
5524 $cond = "${cond}_TRUE"
5525 unless $cond =~ /^TRUE|FALSE$/;
5526 $cond = condition_negate ($cond)
5529 &am_file_error ($where,
5530 "endif reminder ($negate$cond) incompatible with "
5531 . "current conditional: $cond_stack[$#cond_stack]")
5532 if $cond_stack[$#cond_stack] ne $cond;
5537 return conditional_string (@cond_stack);
5544 ## ------------------------ ##
5545 ## Handling the variables. ##
5546 ## ------------------------ ##
5549 # check_ambiguous_conditional ($VAR, $COND)
5550 # -----------------------------------------
5551 # Check for an ambiguous conditional. This is called when a variable
5552 # is being defined conditionally. If we already know about a
5553 # definition that is true under the same conditions, then we have an
5555 sub check_ambiguous_conditional ($$)
5557 my ($var, $cond) = @_;
5558 foreach my $vcond (keys %{$var_value{$var}})
5561 if ($vcond eq $cond)
5563 $message = "$var multiply defined in condition $cond";
5565 elsif (&conditional_true_when ($vcond, $cond))
5567 $message = ("$var was already defined in condition $vcond, "
5568 . "which implies condition $cond");
5570 elsif (&conditional_true_when ($cond, $vcond))
5572 $message = ("$var was already defined in condition $vcond, "
5573 . "which is implied by condition $cond");
5577 &am_line_error ($var, $message);
5584 # ¯o_define($VAR, $VAR_IS_AM, $TYPE, $COND, $VALUE, $WHERE)
5585 # -------------------------------------------------------------
5586 # The $VAR can go from Automake to user, but not the converse.
5587 sub macro_define ($$$$$$)
5589 my ($var, $var_is_am, $type, $cond, $value, $where) = @_;
5591 am_file_error ($where, "bad macro name `$var'")
5592 if $var !~ /$MACRO_PATTERN/o;
5596 # An Automake variable must be consistently defined with the same
5597 # sign by Automake. A user variable must be set by either `=' or
5598 # `:=', and later promoted to `+='.
5601 if (defined $var_type{$var} && $var_type{$var} ne $type)
5603 am_line_error ($var,
5604 ("$var was set with `$var_type{$var}=' "
5605 . "and is now set with `$type='"));
5610 if (!defined $var_type{$var} && $type eq '+')
5612 am_line_error ($var, "$var must be set with `=' before using `+='");
5615 $var_type{$var} = $type;
5617 # When adding, since we rewrite, don't try to preserve the
5618 # Automake continuation backslashes.
5620 if $type eq '+' && $var_is_am;
5622 # Differentiate the first assignment (including with `+=').
5623 if ($type eq '+' && defined $var_value{$var}{$cond})
5625 if (substr ($var_value{$var}{$cond}, -1) eq "\n")
5627 # Insert a backslash before a trailing newline.
5628 $var_value{$var}{$cond} =
5629 substr ($var_value{$var}{$cond}, 0, -1) . "\\\n";
5631 elsif ($var_value{$var}{$cond})
5633 # Insert a separator.
5634 $var_value{$var}{$cond} .= ' ';
5636 $var_value{$var}{$cond} .= $value;
5640 # The first assignment to a macro sets the line number. Ideally I
5641 # suppose we would associate line numbers with random bits of text.
5642 # FIXME: We sometimes redefine some variables, but we want to keep
5643 # the original location. More subs are needed to handle
5644 # properly variables. Once this done, remove this hack.
5645 $var_line{$var} = $where
5646 unless defined $var_line{$var};
5648 # If Automake tries to override a value specified by the user,
5649 # just don't let it do.
5650 if (defined $var_value{$var}{$cond} && !$var_is_am{$var} && $var_is_am)
5654 print STDERR "$me: refusing to override the user definition of:\n";
5656 print STDERR "$me: with `$cond' => `$value'\n";
5661 # There must be no previous value unless the user is redefining
5662 # an Automake variable or an AC_SUBST variable.
5663 check_ambiguous_conditional ($var, $cond)
5664 unless ($var_is_am{$var} && !$var_is_am
5665 || exists $configure_vars{$var});
5667 $var_value{$var}{$cond} = $value;
5671 # An Automake variable can be given to the user, but not the converse.
5672 if (! defined $var_is_am{$var} || !$var_is_am)
5674 $var_is_am{$var} = $var_is_am;
5679 # &variable_delete ($VAR, [@CONDS])
5680 # ---------------------------------
5681 # Forget about $VAR under the conditions @CONDS, or completely if
5683 sub variable_delete ($@)
5685 my ($var, @conds) = @_;
5689 delete $var_value{$var};
5690 delete $var_line{$var};
5691 delete $var_is_am{$var};
5692 delete $var_comment{$var};
5693 delete $var_type{$var};
5697 foreach my $cond (@conds)
5699 delete $var_value{$var}{$cond};
5705 # ¯o_dump ($VAR)
5706 # ------------------
5711 if (!exists $var_value{$var})
5713 print STDERR " $var does not exist\n";
5717 my $var_is_am = $var_is_am{$var} ? "Automake" : "User";
5718 my $where = (defined $var_line{$var}
5719 ? $var_line{$var} : "undefined");
5720 print STDERR "$var_comment{$var}"
5721 if defined $var_comment{$var};
5722 print STDERR " $var ($var_is_am, where = $where) $var_type{$var}=\n";
5723 print STDERR " {\n";
5724 foreach my $vcond (sort by_condition keys %{$var_value{$var}})
5726 print STDERR " $vcond => $var_value{$var}{$vcond}\n";
5728 print STDERR " }\n";
5739 print STDERR "%var_value =\n";
5741 foreach my $var (sort (keys %var_value))
5750 # &variable_defined ($VAR, [$COND])
5751 # ---------------------------------
5752 # See if a variable exists. $VAR is the variable name, and $COND is
5753 # the condition which we should check. If no condition is given, we
5754 # currently return true if the variable is defined under any
5756 sub variable_defined ($$)
5758 my ($var, $cond) = @_;
5760 # Unfortunately we can't just check for $var_value{VAR}{COND}
5761 # as this would make perl create $condition{VAR}, which we
5763 if (!exists $var_value{$var})
5765 if (defined $targets{$var})
5767 &am_line_error ($var, "`$var' is a target; expected a variable")
5769 # The variable is not defined
5773 if ($cond && !exists $var_value{$var}{$cond})
5775 # The variable is not defined for the given condition.
5779 # Even a var_value examination is good enough for us. FIXME:
5780 # really should maintain examined status on a per-condition basis.
5781 $content_seen{$var} = 1;
5785 # Mark a variable as examined.
5786 sub examine_variable
5789 &variable_defined ($var);
5792 # Return the set of conditions for which a variable is defined.
5794 # If the variable is not defined conditionally, and is not defined in
5795 # terms of any variables which are defined conditionally, then this
5796 # returns the empty list.
5798 # If the variable is defined conditionally, but is not defined in
5799 # terms of any variables which are defined conditionally, then this
5800 # returns the list of conditions for which the variable is defined.
5802 # If the variable is defined in terms of any variables which are
5803 # defined conditionally, then this returns a full set of permutations
5804 # of the subvariable conditions. For example, if the variable is
5805 # defined in terms of a variable which is defined for COND_TRUE,
5806 # then this returns both COND_TRUE and COND_FALSE. This is
5807 # because we will need to define the variable under both conditions.
5809 sub variable_conditions ($)
5817 my @new_conds = &variable_conditions_sub ($var, '');
5818 # Now we want to return all permutations of the subvariable
5821 foreach my $item (@new_conds)
5823 foreach (split (' ', $item))
5825 s/^(.*)_(TRUE|FALSE)$/$1_TRUE/;
5829 @new_conds = &variable_conditions_permutations (sort keys %allconds);
5831 foreach my $cond (@new_conds)
5833 my $reduce = &variable_conditions_reduce (split (' ', $cond));
5835 if $reduce eq 'FALSE';
5836 $uniqify{$cond} = 1;
5839 @uniq_list = sort by_condition keys %uniqify;
5840 # Note we cannot just do `return sort keys %uniqify', because this
5841 # function is sometimes used in a scalar context.
5847 # &variable_conditionally_defined ($VAR)
5848 # --------------------------------------
5849 sub variable_conditionally_defined ($)
5852 foreach my $cond (variable_conditions ($var))
5855 unless $cond =~ /^TRUE|FALSE$/;
5862 # &variable_conditions_sub ($VAR, $PARENT)
5863 # -------------------------------------------------------
5864 # A subroutine of variable_conditions. This returns all the
5865 # conditions of $VAR, including those of any sub-variables.
5866 sub variable_conditions_sub
5868 my ($var, $parent) = @_;
5871 if (defined $vars_scanned{$var})
5873 &am_line_error ($parent, "variable `$var' recursively defined");
5876 $vars_scanned{$var} = 1;
5878 my @this_conds = ();
5879 # Examine every condition under which $VAR is defined.
5880 foreach my $vcond (keys %{$var_value{$var}})
5882 push (@this_conds, $vcond);
5884 # If $VAR references some other variable, then compute the
5885 # conditions for that subvariable.
5886 my @subvar_conds = ();
5887 foreach (split (' ', $var_value{$var}{$vcond}))
5889 # If a comment seen, just leave.
5892 # Handle variable substitutions.
5893 if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5896 if ($varname =~ /$SUBST_REF_PATTERN/o)
5902 # Here we compute all the conditions under which the
5903 # subvariable is defined. Then we go through and add
5905 my @svc = &variable_conditions_sub ($varname, $var);
5906 foreach my $item (@svc)
5908 my $val = conditional_string ($vcond, split (' ', $item));
5910 push (@subvar_conds, $val);
5915 # If there are no conditional subvariables, then we want to
5916 # return this condition. Otherwise, we want to return the
5917 # permutations of the subvariables, taking into account the
5918 # conditions of $VAR.
5919 if (! @subvar_conds)
5921 push (@new_conds, $vcond);
5925 push (@new_conds, &variable_conditions_reduce (@subvar_conds));
5929 # Unset our entry in vars_scanned. We only care about recursive
5931 delete $vars_scanned{$var};
5933 # If we are being called on behalf of another variable, we need to
5934 # return all possible permutations of the conditions. We have
5935 # already handled everything in @this_conds along with their
5936 # subvariables. We now need to add any permutations that are not
5938 foreach my $this_cond (@this_conds)
5941 &variable_conditions_permutations (split(' ', $this_cond));
5942 foreach my $perm (@perms)
5945 foreach my $scan (@this_conds)
5947 if (&conditional_true_when ($perm, $scan)
5948 || &conditional_true_when ($scan, $perm))
5956 # This permutation was not already handled, and is valid
5958 push (@new_conds, $perm);
5966 # Filter a list of conditionals so that only the exclusive ones are
5967 # retained. For example, if both `COND1_TRUE COND2_TRUE' and
5968 # `COND1_TRUE' are in the list, discard the latter.
5969 # If the list is empty, return TRUE
5970 sub variable_conditions_reduce
5977 $cond = shift(@conds);
5979 # FALSE is absorbent.
5980 if ($cond eq 'FALSE')
5984 elsif (!conditional_is_redundant ($cond, @ret, @conds))
5990 return "TRUE" if @ret == 0;
5995 # invert_conditions (@CONDS)
5996 # --------------------------
5997 # Invert a list of conditionals. Returns a set of conditionals which
5998 # are never true for any of the input conditionals, and when taken
5999 # together with the input conditionals cover all possible cases.
6001 # For example: invert_conditions("A_TRUE B_TRUE", "A_FALSE B_FALSE") will
6002 # return ("A_FALSE B_TRUE", "A_TRUE B_FALSE")
6003 sub invert_conditions
6008 foreach my $cond (@conds)
6010 foreach my $perm (variable_conditions_permutations (split(' ', $cond)))
6012 push @notconds, $perm
6013 if ! conditional_is_redundant ($perm, @conds);
6016 return variable_conditions_reduce (@notconds);
6019 # Return a list of permutations of a conditional string.
6020 sub variable_conditions_permutations
6025 my $comp = shift (@comps);
6026 return &variable_conditions_permutations (@comps)
6028 my $neg = condition_negate ($comp);
6031 foreach my $sub (&variable_conditions_permutations (@comps))
6033 push (@ret, "$comp $sub");
6034 push (@ret, "$neg $sub");
6046 # &check_variable_defined_unconditionally($VAR, $PARENT)
6047 # ------------------------------------------------------
6048 # Warn if a variable is conditionally defined. This is called if we
6049 # are using the value of a variable.
6050 sub check_variable_defined_unconditionally ($$)
6052 my ($var, $parent) = @_;
6053 foreach my $cond (keys %{$var_value{$var}})
6056 if $cond =~ /^TRUE|FALSE$/;
6060 &am_line_error ($parent,
6061 "warning: automake does not support conditional definition of $var in $parent");
6065 &am_line_error ($parent,
6066 "warning: automake does not support $var being defined conditionally");
6072 # Get the TRUE value of a variable, warn if the variable is
6073 # conditionally defined.
6077 &check_variable_defined_unconditionally ($var);
6078 return $var_value{$var}{'TRUE'};
6083 # &value_to_list ($VAR, $VAL, $COND)
6084 # ----------------------------------
6085 # Convert a variable value to a list, split as whitespace. This will
6086 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6089 # If COND is 'all', then all values under all conditions should be
6090 # returned; if COND is a particular condition (all conditions are
6091 # surrounded by @...@) then only the value for that condition should
6092 # be returned; otherwise, warn if VAR is conditionally defined.
6093 # SCANNED is a global hash listing whose keys are all the variables
6094 # already scanned; it is an error to rescan a variable.
6097 my ($var, $val, $cond) = @_;
6101 $val =~ s/\\(\n|$)/ /g;
6103 foreach (split (' ', $val))
6105 # If a comment seen, just leave.
6108 # Handle variable substitutions.
6109 if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
6113 # If the user uses a losing variable name, just ignore it.
6114 # This isn't ideal, but people have requested it.
6115 next if ($varname =~ /\@.*\@/);
6119 if ($varname =~ /$SUBST_REF_PATTERN/o)
6123 ($from = $2) =~ s/(\W)/\\$1/g;
6127 @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
6129 # Now rewrite the value if appropriate.
6132 grep (s/$from$/$to/, @temp_list);
6135 push (@result, @temp_list);
6146 # Return contents of variable as list, split as whitespace. This will
6147 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6148 # substitutions. If COND is 'all', then all values under all
6149 # conditions should be returned; if COND is a particular condition
6150 # (all conditions are surrounded by @...@) then only the value for
6151 # that condition should be returned; otherwise, warn if VAR is
6152 # conditionally defined. If PARENT is specified, it is the name of
6153 # the including variable; this is only used for error reports.
6154 sub variable_value_as_list_worker
6156 my ($var, $cond, $parent) = @_;
6159 if (! defined $var_value{$var})
6161 if (defined $targets{$var})
6163 &am_line_error ($var, "`$var' is a target; expected a variable");
6167 &am_line_error ($parent, "variable `$var' not defined");
6170 elsif (defined $vars_scanned{$var})
6172 # `vars_scanned' is a global we use to keep track of which
6173 # variables we've already examined.
6174 &am_line_error ($parent, "variable `$var' recursively defined");
6176 elsif ($cond eq 'all')
6178 $vars_scanned{$var} = 1;
6179 foreach my $vcond (keys %{$var_value{$var}})
6181 my $val = $var_value{$var}{$vcond};
6182 push (@result, &value_to_list ($var, $val, $cond));
6188 $vars_scanned{$var} = 1;
6190 foreach my $vcond (keys %{$var_value{$var}})
6192 my $val = $var_value{$var}{$vcond};
6193 if (&conditional_true_when ($vcond, $cond))
6195 # Warn if we have an ambiguity. It's hard to know how
6196 # to handle this case correctly.
6197 &check_variable_defined_unconditionally ($var, $parent)
6200 push (@result, &value_to_list ($var, $val, $cond));
6205 # Unset our entry in vars_scanned. We only care about recursive
6207 delete $vars_scanned{$var};
6213 # &variable_output ($VAR, [@CONDS])
6214 # ---------------------------------
6215 # Output all the values of $VAR is @COND is not specified, else only
6216 # that corresponding to @COND.
6217 sub variable_output ($@)
6219 my ($var, @conds) = @_;
6221 @conds = sort by_condition keys %{$var_value{$var}}
6224 $output_vars .= $var_comment{$var}
6225 if defined $var_comment{$var};
6227 foreach my $cond (@conds)
6229 my $val = $var_value{$var}{$cond};
6230 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6231 my $output_var = "$var $equals $val";
6232 $output_var =~ s/^/make_condition ($cond)/meg;
6233 $output_vars .= $output_var . "\n";
6238 # &variable_pretty_output ($VAR, [@CONDS])
6239 # ----------------------------------------
6240 # Likewise, but pretty, i.e., we *split* the values at spaces. Use only
6241 # with variables holding filenames.
6242 sub variable_pretty_output ($@)
6244 my ($var, @conds) = @_;
6246 @conds = sort by_condition keys %{$var_value{$var}}
6249 $output_vars .= $var_comment{$var}
6250 if defined $var_comment{$var};
6252 foreach my $cond (@conds)
6254 my $val = $var_value{$var}{$cond};
6255 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6256 my $make_condition = make_condition ($cond);
6257 $output_vars .= pretty_print_internal ("$make_condition$var $equals",
6258 "$make_condition\t",
6259 split (' ' , $val));
6264 # This is just a wrapper for variable_value_as_list_worker that
6265 # initializes the global hash `vars_scanned'. This hash is used to
6266 # avoid infinite recursion.
6267 sub variable_value_as_list
6269 my ($var, $cond, $parent) = @_;
6271 return &variable_value_as_list_worker ($var, $cond, $parent);
6275 # Like define_variable, but the value is a list, and the variable may
6276 # be defined conditionally. The second argument is the conditional
6277 # under which the value should be defined; this should be the empty
6278 # string to define the variable unconditionally. The third argument
6279 # is a list holding the values to use for the variable. The value is
6280 # pretty printed in the output file.
6281 sub define_pretty_variable
6283 my ($var, $cond, @value) = @_;
6285 # Beware that an empty $cond has a different semantics for
6286 # macro_define and variable_pretty_output.
6289 if (! &variable_defined ($var, $cond))
6291 macro_define ($var, 1, '', $cond, join (' ', @value), undef);
6292 variable_pretty_output ($var, $cond || 'TRUE');
6293 $content_seen{$var} = 1;
6298 # define_variable ($VAR, $VALUE)
6299 # ------------------------------
6300 # Define a new user variable VAR to VALUE, but only if not already defined.
6303 my ($var, $value) = @_;
6305 define_pretty_variable ($var, 'TRUE', $value);
6309 # Like define_variable, but define a variable to be the configure
6310 # substitution by the same name.
6311 sub define_configure_variable
6314 my $value = '@' . $var . '@';
6315 &define_variable ($var, $value);
6319 # define_compiler_variable ($LANG)
6320 # --------------------------------
6321 # Define a compiler variable. We also handle defining the `LT'
6322 # version of the command when using libtool.
6323 sub define_compiler_variable ($)
6327 my ($var, $value) = ($lang->compiler, $lang->compile);
6328 &define_variable ($var, $value);
6329 &define_variable ("LT$var", "\$(LIBTOOL) --mode=compile $value")
6334 # define_linker_variable ($LANG)
6335 # ------------------------------
6336 # Define linker variables.
6337 sub define_linker_variable ($)
6341 my ($var, $value) = ($lang->lder, $lang->ld);
6343 &define_variable ($lang->lder, $lang->ld);
6344 # CCLINK = $(CCLD) blah blah...
6345 &define_variable ($lang->linker,
6346 (($seen_libtool ? '$(LIBTOOL) --mode=link ' : '')
6350 ################################################################
6352 ## ---------------- ##
6353 ## Handling rules. ##
6354 ## ---------------- ##
6357 # rule_define ($TARGET, $IS_AM, $COND, $WHERE)
6358 # --------------------------------------------
6359 # Define a new rule. $TARGET is the rule name. $IS_AM is a boolean
6360 # which is true if the new rule is defined by the user. $COND is the
6361 # condition under which the rule is defined. $WHERE is where the rule
6362 # is defined (file name or line number). Returns true if it is ok to
6363 # define the rule, false otherwise.
6364 sub rule_define ($$$$)
6366 my ($target, $rule_is_am, $cond, $where) = @_;
6368 # For now `foo:' will override `foo$(EXEEXT):'. This is temporary,
6369 # though, so we emit a warning.
6370 (my $noexe = $target) =~ s,\$\(EXEEXT\)$,,;
6371 if ($noexe ne $target && defined $targets{$noexe})
6373 # The no-exeext option enables this feature.
6374 if (! defined $options{'no-exeext'})
6376 &am_line_error ($noexe,
6377 "deprecated feature: `$noexe' overrides `$noexe\$(EXEEXT)'\nchange your target to read `$noexe\$(EXEEXT)'");
6383 if (defined $targets{$target}
6385 ? ! defined $target_conditional{$target}
6386 : defined $target_conditional{$target}))
6388 &am_line_error ($target,
6389 "$target defined both conditionally and unconditionally");
6392 # Value here doesn't matter; for targets we only note existence.
6393 $targets{$target} = $where;
6396 if ($target_conditional{$target})
6398 &check_ambiguous_conditional ($target, $cond);
6400 $target_conditional{$target}{$cond} = $where;
6404 # Check the rule for being a suffix rule. If so, store in a hash.
6406 if ((my ($source_suffix, $object_suffix)) = ($target =~ $SUFFIX_RULE_PATTERN))
6408 $suffix_rules{$source_suffix} = $object_suffix;
6409 print "Sources ending in .$source_suffix become .$object_suffix\n"
6411 # Set SUFFIXES from suffix_rules.
6412 push @suffixes, ".$source_suffix", ".$object_suffix";
6419 # See if a target exists.
6423 return defined $targets{$target};
6427 ################################################################
6429 # Read Makefile.am and set up %contents. Simultaneously copy lines
6430 # from Makefile.am into $output_trailer or $output_vars as
6431 # appropriate. NOTE we put rules in the trailer section. We want
6432 # user rules to come after our generated stuff.
6437 my $am_file = new IO::File ("< $amfile");
6440 die "$me: couldn't open `$amfile': $!\n";
6442 print "$me: reading $amfile\n" if $verbose;
6448 while ($_ = $am_file->getline)
6450 if (/$IGNORE_PATTERN/o)
6452 # Merely delete comments beginning with two hashes.
6454 elsif (/$WHITE_PATTERN/o)
6456 # Stick a single white line before the incoming macro or rule.
6460 elsif (/$COMMENT_PATTERN/o)
6462 # Stick comments before the incoming macro or rule. Make
6463 # sure a blank line preceeds first block of comments.
6464 $spacing = "\n" unless $blank;
6466 $comment .= $spacing . $_;
6475 $output_vars .= $comment . "\n";
6479 # We save the conditional stack on entry, and then check to make
6480 # sure it is the same on exit. This lets us conditonally include
6482 my @saved_cond_stack = @cond_stack;
6483 my $cond = conditional_string (@cond_stack);
6487 my $last_var_name = '';
6488 my $last_var_type = '';
6489 my $last_var_value = '';
6490 # FIXME: shouldn't use $_ in this loop; it is too big.
6494 unless substr ($_, -1, 1) eq "\n";
6496 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
6497 # used by users. @MAINT@ is an anachronism now.
6498 $_ =~ s/\@MAINT\@//g
6499 unless $seen_maint_mode;
6501 my $new_saw_bk = /\\$/ && ! /$COMMENT_PATTERN/o;
6503 if (/$IGNORE_PATTERN/o)
6505 # Merely delete comments beginning with two hashes.
6507 elsif (/$WHITE_PATTERN/o)
6509 # Stick a single white line before the incoming macro or rule.
6511 &am_line_error ($., "blank line following trailing backslash")
6514 elsif (/$COMMENT_PATTERN/o)
6516 # Stick comments before the incoming macro or rule.
6517 $comment .= $spacing . $_;
6519 &am_line_error ($., "comment following trailing backslash")
6526 $output_trailer .= &make_condition (@cond_stack);
6527 $output_trailer .= $_;
6531 $last_var_value .= ' '
6532 unless $last_var_value =~ /\s$/;
6533 $last_var_value .= $_;
6537 $var_comment{$last_var_name} .= "$spacing"
6538 if (!defined $var_comment{$last_var_name}
6539 || substr ($var_comment{$last_var_name}, -1) ne "\n");
6540 $var_comment{$last_var_name} .= "$comment";
6541 $comment = $spacing = '';
6542 macro_define ($last_var_name, 0,
6543 $last_var_type, $cond,
6544 $last_var_value, $.)
6545 if $cond ne 'FALSE';
6546 push (@var_list, $last_var_name);
6551 elsif (/$IF_PATTERN/o)
6553 $cond = cond_stack_if ($1, $2, "$amfile:$.");
6555 elsif (/$ELSE_PATTERN/o)
6557 $cond = cond_stack_else ($1, $2, "$amfile:$.");
6559 elsif (/$ENDIF_PATTERN/o)
6561 $cond = cond_stack_endif ($1, $2, "$amfile:$.");
6564 elsif (/$RULE_PATTERN/o)
6569 rule_define ($1, 0, $cond, $.);
6572 $output_trailer .= $comment . $spacing;
6573 $output_trailer .= &make_condition (@cond_stack);
6574 $output_trailer .= $_;
6575 $comment = $spacing = '';
6577 elsif (/$ASSIGNMENT_PATTERN/o)
6579 # Found a macro definition.
6581 $last_var_name = $1;
6582 $last_var_type = $2;
6583 $last_var_value = $3;
6584 if ($3 ne '' && substr ($3, -1) eq "\\")
6586 # We preserve the `\' because otherwise the long lines
6587 # that are generated will be truncated by broken
6589 $last_var_value = $3 . "\n";
6594 # FIXME: this doesn't always work correctly; it will
6595 # group all comments for a given variable, no matter
6597 # Accumulating variables must not be output.
6598 $var_comment{$last_var_name} .= "$spacing"
6599 if (!defined $var_comment{$last_var_name}
6600 || substr ($var_comment{$last_var_name}, -1) ne "\n");
6601 $var_comment{$last_var_name} .= "$comment";
6602 $comment = $spacing = '';
6604 macro_define ($last_var_name, 0,
6605 $last_var_type, $cond,
6606 $last_var_value, $.)
6607 if $cond ne 'FALSE';
6608 push (@var_list, $last_var_name);
6611 elsif (/$INCLUDE_PATTERN/o)
6615 if ($path =~ s/^\$\(top_srcdir\)\///)
6617 push (@include_stack, "\$\(top_srcdir\)/$path");
6621 $path =~ s/\$\(srcdir\)\///;
6622 push (@include_stack, "\$\(srcdir\)/$path");
6623 $path = $relative_dir . "/" . $path;
6625 &read_am_file ($path);
6629 # This isn't an error; it is probably a continued rule.
6630 # In fact, this is what we assume.
6632 $output_trailer .= $comment . $spacing;
6633 $output_trailer .= &make_condition (@cond_stack);
6634 $output_trailer .= $_;
6635 $comment = $spacing = '';
6636 &am_line_error ($., "`#' comment at start of rule is unportable")
6637 if $_ =~ /^\t\s*\#/;
6640 $saw_bk = $new_saw_bk;
6641 $_ = $am_file->getline;
6644 $output_trailer .= $comment;
6646 if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
6650 &am_error ("unterminated conditionals: @cond_stack");
6654 # FIXME: better error message here.
6655 &am_error ("conditionals not nested in include file");
6661 # define_standard_variables ()
6662 # ----------------------------
6663 # A helper for read_main_am_file which initializes configure variables
6664 # and variables from header-vars.am. This is a subr so we can call it
6666 sub define_standard_variables
6668 my $saved_output_vars = $output_vars;
6669 my ($comments, undef, $rules) =
6670 file_contents_internal (1, "$libdir/am/header-vars.am");
6672 # This will output the definitions in $output_vars, which we don't
6674 foreach my $var (sort keys %configure_vars)
6676 &define_configure_variable ($var);
6677 push (@var_list, $var);
6680 # ... hence, we restore $output_vars.
6681 $output_vars = $saved_output_vars . $comments . $rules;
6684 # Read main am file.
6685 sub read_main_am_file
6689 # This supports the strange variable tricks we are about to play.
6690 if (scalar keys %var_value > 0)
6693 &prog_error ("variable defined before read_main_am_file");
6696 # Generate copyright header for generated Makefile.in.
6697 # We do discard the output of predefined variables, handled below.
6698 $output_vars = ("# $in_file_name generated automatically by automake "
6699 . $VERSION . " from $am_file_name.\n");
6700 $output_vars .= $gen_copyright;
6702 # We want to predefine as many variables as possible. This lets
6703 # the user set them with `+=' in Makefile.am. However, we don't
6704 # want these initial definitions to end up in the output quite
6705 # yet. So we just load them, but output them later.
6706 &define_standard_variables;
6708 # Read user file, which might override some of our values.
6709 &read_am_file ($amfile);
6711 # Ouput all the Automake variables. If the user changed one, then
6712 # it is now marked as owned by the user.
6713 foreach my $var (uniq @var_list)
6715 # Don't process user variables.
6716 variable_output ($var)
6717 unless !$var_is_am{$var};
6720 # Now dump the user variables that were defined. We do it in the same
6721 # order in which they were defined (skipping duplicates).
6722 foreach my $var (uniq @var_list)
6724 # Don't process Automake variables.
6725 variable_output ($var)
6726 unless $var_is_am{$var};
6730 ################################################################
6733 # &flatten ($STRING)
6734 # ------------------
6735 # Flatten the $STRING and return the result.
6750 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
6751 # ------------------------------------------
6752 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6754 sub make_paragraphs ($%)
6756 my ($file, %transform) = @_;
6758 # Complete %transform with global options and make it a Perl
6761 "s/$IGNORE_PATTERN//gm;"
6762 . transform (%transform,
6764 'CYGNUS' => $cygnus_mode,
6766 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
6768 'SHAR' => $options{'dist-shar'} || 0,
6769 'BZIP2' => $options{'dist-bzip2'} || 0,
6770 'ZIP' => $options{'dist-zip'} || 0,
6771 'COMPRESS' => $options{'dist-tarZ'} || 0,
6773 'INSTALL-INFO' => !$options{'no-installinfo'},
6774 'INSTALL-MAN' => !$options{'no-installman'},
6775 'CK-NEWS' => $options{'check-news'} || 0,
6777 'SUBDIRS' => &variable_defined ('SUBDIRS'),
6778 'TOPDIR' => backname ($relative_dir),
6779 'TOPDIR_P' => $relative_dir eq '.',
6780 'CONFIGURE-AC' => $configure_ac,
6782 'BUILD' => $seen_canonical == $AC_CANONICAL_SYSTEM,
6783 'HOST' => $seen_canonical,
6784 'TARGET' => $seen_canonical == $AC_CANONICAL_SYSTEM,
6786 'LIBTOOL' => defined $configure_vars{'LIBTOOL'})
6787 # We don't need more than two consecutive new-lines.
6788 . 's/\n{3,}/\n\n/g';
6790 # Swallow the file and apply the COMMAND.
6791 my $fc_file = new IO::File ("< $file");
6794 die "$me: installation error: cannot open `$file'\n";
6797 print "$me: reading $file\n"
6799 my $saved_dollar_slash = $/;
6801 $_ = $fc_file->getline;
6802 $/ = $saved_dollar_slash;
6807 # Split at unescaped new lines.
6808 my @lines = split (/(?<!\\)\n/, $content);
6811 while (defined ($_ = shift @lines))
6813 my $paragraph = "$_";
6814 # If we are a rule, eat as long as we start with a tab.
6815 if (/$RULE_PATTERN/smo)
6817 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
6819 $paragraph .= "\n$_";
6821 unshift (@lines, $_);
6824 # If we are a comments, eat as much comments as you can.
6825 elsif (/$COMMENT_PATTERN/smo)
6827 while (defined ($_ = shift @lines)
6828 && $_ =~ /$COMMENT_PATTERN/smo)
6830 $paragraph .= "\n$_";
6832 unshift (@lines, $_);
6835 push @res, $paragraph;
6844 # ($COMMENT, $VARIABLES, $RULES)
6845 # &file_contents_internal ($IS_AM, $FILE, [%TRANSFORM])
6846 # -----------------------------------------------------
6847 # Return contents of a file from $libdir/am, automatically skipping
6848 # macros or rules which are already known. $IS_AM iff the caller is
6849 # reading an Automake file (as opposed to the user's Makefile.am).
6850 sub file_contents_internal ($$%)
6852 my ($is_am, $file, %transform) = @_;
6854 my $result_vars = '';
6855 my $result_rules = '';
6859 # We save the conditional stack on entry, and then check to make
6860 # sure it is the same on exit. This lets us conditonally include
6862 my @saved_cond_stack = @cond_stack;
6863 my $cond = conditional_string (@cond_stack);
6865 foreach (make_paragraphs ($file, %transform))
6868 &am_file_error ($file, "blank line following trailing backslash:\n$_")
6870 &am_file_error ($file, "comment following trailing backslash:\n$_")
6875 # Stick empty line before the incoming macro or rule.
6878 elsif (/$COMMENT_PATTERN/mso)
6880 # Stick comments before the incoming macro or rule.
6884 # Handle inclusion of other files.
6885 elsif (/$INCLUDE_PATTERN/o)
6887 if ($cond ne 'FALSE')
6889 my $file = ($is_am ? "$libdir/am/" : '') . $1;
6891 my ($com, $vars, $rules)
6892 = file_contents_internal ($is_am, $file, %transform);
6894 $result_vars .= $vars;
6895 $result_rules .= $rules;
6899 # Handling the conditionals.
6900 elsif (/$IF_PATTERN/o)
6902 $cond = cond_stack_if ($1, $2, $file);
6904 elsif (/$ELSE_PATTERN/o)
6906 $cond = cond_stack_else ($1, $2, $file);
6908 elsif (/$ENDIF_PATTERN/o)
6910 $cond = cond_stack_endif ($1, $2, $file);
6914 elsif (/$RULE_PATTERN/mso)
6916 # Separate relationship from optional actions: the first
6917 # `new-line tab" not preceded by backslash (continuation
6919 # I'm quite shoked! It seems that (\\\n|[^\n]) is not the
6920 # same as `([^\n]|\\\n)!!! Don't swap it, it breaks.
6922 /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
6923 my ($relationship, $actions) = ($1, $2 || '');
6925 # Separate targets from dependencies: the first colon.
6926 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
6927 my ($targets, $dependencies) = ($1, $2);
6928 # Remove the escaped new lines.
6929 # I don't know why, but I have to use a tmp $flat_deps.
6930 my $flat_deps = &flatten ($dependencies);
6931 my @deps = split (' ', $flat_deps);
6933 foreach (split (' ' , $targets))
6935 # FIXME: We are not robust to people defining several targets
6936 # at once, only some of them being in %dependencies.
6938 # Output only if not in FALSE.
6939 if (defined $dependencies{$_}
6940 && $cond ne 'FALSE')
6942 &depend ($_, @deps);
6943 $actions{$_} .= $actions;
6947 # Free-lance dependency. Output the rule for all the
6948 # targets instead of one by one.
6950 # Work out all the conditions for which the target hasn't
6952 my @undefined_conds;
6953 if (defined $target_conditional{$targets})
6955 my @defined_conds = keys %{$target_conditional{$targets}};
6956 @undefined_conds = invert_conditions(@defined_conds);
6960 if (defined $targets{$targets})
6962 # No conditions for which target hasn't been defined
6963 @undefined_conds = ();
6967 # Target hasn't been defined for any conditions
6968 @undefined_conds = ("");
6972 if ($cond ne 'FALSE')
6975 for $undefined_cond (@undefined_conds)
6977 my $condparagraph = $paragraph;
6978 $condparagraph =~ s/^/make_condition (@cond_stack, $undefined_cond)/gme;
6979 $result_rules .= "$spacing$comment$condparagraph\n"
6980 if rule_define ($targets, $is_am,
6981 "$cond $undefined_cond", $file);
6984 $comment = $spacing = '';
6990 elsif (/$ASSIGNMENT_PATTERN/mso)
6992 my ($var, $type, $val) = ($1, $2, $3);
6993 &am_file_error ($file, "macro `$var' with trailing backslash")
6996 # Accumulating variables must not be output.
6997 $var_comment{$var} .= "$spacing"
6998 if (!defined $var_comment{$var}
6999 || substr ($var_comment{$var}, -1) ne "\n");
7000 $var_comment{$var} .= "$comment";
7001 macro_define ($var, $is_am, $type, $cond, $val, $file)
7002 if $cond ne 'FALSE';
7003 push (@var_list, $var);
7005 # If the user has set some variables we were in charge
7006 # of (which is detected by the first reading of
7007 # `header-vars.am'), we must not output them.
7008 $result_vars .= "$spacing$comment$_\n"
7009 if $type ne '+' && $var_is_am{$var} && $cond ne 'FALSE';
7011 $comment = $spacing = '';
7015 # This isn't an error; it is probably some tokens which
7016 # configure is supposed to replace, such as `@SET-MAKE@',
7017 # or some part of a rule cut by an if/endif.
7018 if ($cond ne 'FALSE')
7020 s/^/make_condition (@cond_stack)/gme;
7021 $result_rules .= "$spacing$comment$_\n";
7023 $comment = $spacing = '';
7027 if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
7031 &am_error ("unterminated conditionals: @cond_stack");
7035 # FIXME: better error message here.
7036 &am_error ("conditionals not nested in include file");
7040 return ($comment, $result_vars, $result_rules);
7045 # &file_contents ($BASENAME, [%TRANSFORM])
7046 # ----------------------------------------
7047 # Return contents of a file from $libdir/am, automatically skipping
7048 # macros or rules which are already known.
7049 sub file_contents ($%)
7051 my ($basename, %transform) = @_;
7052 my ($comments, $variables, $rules) =
7053 file_contents_internal (1, "$libdir/am/$basename.am", %transform);
7054 return "$comments$variables$rules";
7059 # &transform (%PAIRS)
7060 # -------------------
7061 # Foreach ($TOKEN, $VAL) in %PAIRS produce a replacement expression suitable
7062 # for file_contents which:
7063 # - replaces @$TOKEN@ with $VALUE,
7064 # - enables/disables ?$TOKEN?.
7070 while (my ($token, $val) = each %pairs)
7072 $result .= "s/\Q%$token%\E/\Q$val\E/gm;";
7075 $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
7076 $result .= "s/\Q%?$token%\E/TRUE/gm;";
7080 $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
7081 $result .= "s/\Q%?$token%\E/FALSE/gm;";
7089 # Find all variable prefixes that are used for install directories. A
7090 # prefix `zar' qualifies iff:
7091 # * `zardir' is a variable.
7092 # * `zar_PRIMARY' is a variable.
7093 sub am_primary_prefixes
7095 my ($primary, $can_dist, @prefixes) = @_;
7097 my %valid = map { $_ => 0 } @prefixes;
7098 $valid{'EXTRA'} = 0;
7099 foreach my $varname (keys %var_value)
7101 # Automake is allowed to define variables that look like they
7102 # are magic variables, such as INSTALL_DATA.
7104 if $var_is_am{$varname};
7106 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
7108 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
7109 if ($dist ne '' && ! $can_dist)
7111 # Note that a configure variable is always legitimate.
7112 # It is natural to name such variables after the
7113 # primary, so we explicitly allow it.
7114 if (! defined $configure_vars{$varname})
7116 &am_line_error ($varname,
7117 "invalid variable `$varname': `dist' is forbidden");
7120 elsif (! defined $valid{$X} && ! &variable_defined ("${X}dir"))
7122 # Note that a configure variable is always legitimate.
7123 # It is natural to name such variables after the
7124 # primary, so we explicitly allow it.
7125 if (! defined $configure_vars{$varname})
7127 &am_line_error ($varname,
7128 "invalid variable `$varname'");
7133 # Ensure all extended prefixes are actually used.
7134 $valid{"$base$dist$X"} = 1;
7142 # Handle `where_HOW' variable magic. Does all lookups, generates
7143 # install code, and possibly generates code to define the primary
7144 # variable. The first argument is the name of the .am file to munge,
7145 # the second argument is the primary variable (eg HEADERS), and all
7146 # subsequent arguments are possible installation locations. Returns
7147 # list of all values of all _HOW targets.
7149 # FIXME: this should be rewritten to be cleaner. It should be broken
7150 # up into multiple functions.
7152 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7159 my $default_dist = 0;
7162 if ($args[0] eq '-noextra')
7166 elsif ($args[0] eq '-candist')
7170 elsif ($args[0] eq '-defaultdist')
7175 elsif ($args[0] !~ /^-/)
7182 my ($file, $primary, @prefixes) = @args;
7184 # Now that configure substitutions are allowed in where_HOW
7185 # variables, it is an error to actually define the primary. We
7186 # allow `JAVA', as it is customarily used to mean the Java
7187 # interpreter. This is but one of several Java hacks. Similarly,
7188 # `PYTHON' is customarily used to mean the Python interpreter.
7189 &am_line_error ($primary, "`$primary' is an anachronism")
7190 if &variable_defined ($primary)
7191 && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7194 # Look for misspellings. It is an error to have a variable ending
7195 # in a "reserved" suffix whose prefix is unknown, eg
7196 # "bni_PROGRAMS". However, unusual prefixes are allowed if a
7197 # variable of the same name (with "dir" appended) exists. For
7198 # instance, if the variable "zardir" is defined, then
7199 # "zar_PROGRAMS" becomes valid. This is to provide a little extra
7200 # flexibility in those cases which need it.
7201 my %valid = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7203 # If a primary includes a configure substitution, then the EXTRA_
7204 # form is required. Otherwise we can't properly do our job.
7206 my $warned_about_extra = 0;
7211 # True if the iteration is the first one. Used for instance to
7212 # output parts of the associated file only once.
7214 foreach my $X (sort keys %valid)
7216 my $one_name = $X . '_' . $primary;
7218 unless (&variable_defined ($one_name));
7220 my $strip_subdir = 1;
7221 # If subdir prefix should be preserved, do so.
7222 if ($X =~ /^nobase_/)
7228 my $nodir_name = $X;
7229 # If files should be distributed, do so.
7233 $dist_p = (($default_dist && $one_name !~ /^nodist_/)
7234 || (! $default_dist && $one_name =~ /^dist_/));
7235 $nodir_name =~ s/^(dist|nodist)_//;
7238 # Append actual contents of where_PRIMARY variable to
7240 foreach my $rcurs (&variable_value_as_list ($one_name, 'all'))
7242 # Skip configure substitutions. Possibly bogus.
7243 if ($rcurs =~ /^\@.*\@$/)
7247 if (! $warned_about_extra)
7249 $warned_about_extra = 1;
7250 &am_line_error ($one_name,
7251 "`$one_name' contains configure substitution, but shouldn't");
7254 # Check here to make sure variables defined in
7255 # configure.ac do not imply that EXTRA_PRIMARY
7257 elsif (! defined $configure_vars{$one_name})
7259 $require_extra = $one_name
7266 push (@result, $rcurs);
7269 # A blatant hack: we rewrite each _PROGRAMS primary to include
7271 if ($primary eq 'PROGRAMS')
7273 my @conds = &variable_conditions ($one_name);
7276 foreach my $cond (@conds)
7278 my @one_binlist = ();
7279 my @condval = &variable_value_as_list ($one_name,
7281 foreach my $rcurs (@condval)
7283 # Skip autoconf substs. Also skip if the user
7284 # already applied $(EXEEXT).
7285 if ($rcurs =~ /^\@.*\@$/ || $rcurs =~ /\$\(EXEEXT\)$/)
7287 push (@one_binlist, $rcurs);
7291 push (@one_binlist, $rcurs . '$(EXEEXT)');
7295 push (@condvals, $cond);
7296 push (@condvals, join (' ', @one_binlist));
7299 variable_delete ($one_name);
7302 my $cond = shift (@condvals);
7303 my @val = split (' ', shift (@condvals));
7304 &define_pretty_variable ($one_name, $cond, @val);
7308 # "EXTRA" shouldn't be used when generating clean targets,
7309 # all, or install targets.
7312 # We used to warn if EXTRA_FOO was defined uselessly,
7313 # but this was annoying.
7319 push (@check, '$(' . $one_name . ')');
7323 push (@used, '$(' . $one_name . ')');
7326 # Is this to be installed?
7327 my $install_p = $X ne 'noinst' && $X ne 'check';
7329 # If so, with install-exec? (or install-data?).
7330 my $exec_p = (defined $exec_dir_p {$X}
7334 # Singular form of $PRIMARY.
7335 (my $one_primary = $primary) =~ s/S$//;
7336 $output_rules .= &file_contents ($file,
7339 'PRIMARY' => $primary,
7340 'ONE_PRIMARY' => $one_primary,
7342 'NDIR' => $nodir_name,
7343 'BASE' => $strip_subdir,
7346 'INSTALL' => $install_p,
7347 'DIST' => $dist_p));
7352 # The JAVA variable is used as the name of the Java interpreter.
7353 # The PYTHON variable is used as the name of the Python interpreter.
7354 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7357 &define_pretty_variable ($primary, '', @used);
7358 $output_vars .= "\n";
7361 if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7363 &am_line_error ($require_extra,
7364 "`$require_extra' contains configure substitution, but `EXTRA_$primary' not defined");
7367 # Push here because PRIMARY might be configure time determined.
7368 push (@all, '$(' . $primary . ')')
7369 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7371 # Make the result unique. This lets the user use conditionals in
7372 # a natural way, but still lets us program lazily -- we don't have
7373 # to worry about handling a particular object more than once.
7374 return uniq (sort @result);
7378 ################################################################
7380 # Each key in this hash is the name of a directory holding a
7381 # Makefile.in. These variables are local to `is_make_dir'.
7383 my $make_dirs_set = 0;
7388 if (! $make_dirs_set)
7390 foreach my $iter (@configure_input_files)
7392 $make_dirs{dirname ($iter)} = 1;
7394 # We also want to notice Makefile.in's.
7395 foreach my $iter (@other_input_files)
7397 if ($iter =~ /Makefile\.in$/)
7399 $make_dirs{dirname ($iter)} = 1;
7404 return defined $make_dirs{$dir};
7407 ################################################################
7409 # This variable is local to the "require file" set of functions.
7410 my @require_file_paths = ();
7412 # If a file name appears as a key in this hash, then it has already
7413 # been checked for. This variable is local to the "require file"
7415 %require_file_found = ();
7417 # See if we want to push this file onto dist_common. This function
7418 # encodes the rules for deciding when to do so.
7419 sub maybe_push_required_file
7421 my ($dir, $file, $fullfile) = @_;
7423 if ($dir eq $relative_dir)
7425 &push_dist_common ($file);
7427 elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7429 # If we are doing the topmost directory, and the file is in a
7430 # subdir which does not have a Makefile, then we distribute it
7432 &push_dist_common ($fullfile);
7437 # &require_file_internal ($IS_CONFIGURE, $LINE, $MYSTRICT, @FILES)
7438 # ----------------------------------------------------------------
7439 # Verify that the file must exist in the current directory.
7440 # $MYSTRICT is the strictness level at which this file becomes required.
7442 # Must set require_file_paths before calling this function.
7443 # require_file_paths is set to hold a single directory (the one in
7444 # which the first file was found) before return.
7445 sub require_file_internal
7447 my ($is_configure, $line, $mystrict, @files) = @_;
7449 foreach my $file (@files)
7457 my $dangling_sym = 0;
7458 foreach my $dir (@require_file_paths)
7460 $fullfile = $dir . "/" . $file;
7461 $errdir = $dir unless $errdir;
7463 # Use different name for "error filename". Otherwise on
7464 # an error the bad file will be reported as eg
7465 # `../../install-sh' when using the default
7467 $errfile = $errdir . '/' . $file;
7469 if (-l $fullfile && ! -f $fullfile)
7474 elsif (-f $fullfile)
7477 &maybe_push_required_file ($dir, $file, $fullfile);
7483 # `--force-missing' only has an effect if `--add-missing' is
7485 if ($found_it && (! $add_missing || ! $force_missing))
7487 # Prune the path list.
7488 @require_file_paths = $save_dir;
7492 # If we've already looked for it, we're done. You might
7493 # wonder why we don't do this before searching for the
7494 # file. If we do that, then something like
7495 # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
7499 next if defined $require_file_found{$file};
7500 $require_file_found{$file} = 1;
7503 if ($strictness >= $mystrict)
7505 if ($dangling_sym && $add_missing)
7513 # Only install missing files according to our desired
7515 my $message = "required file `$errfile' not found";
7520 # Maybe run libtoolize.
7521 my @syslist = ('libtoolize', '--automake');
7522 push @syslist, '--copy'
7525 && grep ($_ eq $file, @libtoolize_files)
7526 && system (@syslist))
7528 $message = "installing `$errfile'";
7530 $trailer = "; cannot run `libtoolize': $!";
7532 elsif (-f ("$libdir/$file"))
7534 # Install the missing file. Symlink if we
7535 # can, copy if we must. Note: delete the file
7536 # first, in case it is a dangling symlink.
7537 $message = "installing `$errfile'";
7538 # Windows Perl will hang if we try to delete a
7539 # file that doesn't exist.
7540 unlink ($errfile) if -f $errfile;
7541 if ($symlink_exists && ! $copy_missing)
7543 if (! symlink ("$libdir/$file", $errfile))
7546 $trailer = "; error while making link: $!";
7549 elsif (system ('cp', "$libdir/$file", $errfile))
7552 $trailer = "\n error while copying";
7556 &maybe_push_required_file (dirname ($errfile),
7559 # Prune the path list.
7560 @require_file_paths = &dirname ($errfile);
7563 # If --force-missing was specified, and we have
7564 # actually found the file, then do nothing.
7566 if $found_it && $force_missing;
7572 # FIXME: allow actual file to be specified.
7573 &am_conf_line_warning ($configure_ac, $line,
7574 "$message$trailer");
7578 &am_line_warning ($line, "$message$trailer");
7585 # FIXME: allow actual file to be specified.
7586 &am_conf_line_error ($configure_ac, $line,
7587 "$message$trailer");
7591 &am_line_error ($line, "$message$trailer");
7599 # Like require_file_with_line, but error messages refer to
7600 # configure.ac, not the current Makefile.am.
7601 sub require_file_with_conf_line
7603 @require_file_paths = $relative_dir;
7604 &require_file_internal (1, @_);
7607 sub require_file_with_line
7609 @require_file_paths = $relative_dir;
7610 &require_file_internal (0, @_);
7615 @require_file_paths = $relative_dir;
7616 &require_file_internal (0, '', @_);
7619 # Require a file that is also required by Autoconf. Looks in
7620 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7621 sub require_config_file
7623 @require_file_paths = @config_aux_path;
7624 &require_file_internal (1, '', @_);
7625 my $dir = $require_file_paths[0];
7626 @config_aux_path = @require_file_paths;
7627 # Avoid unsightly '/.'s.
7628 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7631 # Assumes that the line number is in Makefile.am.
7632 sub require_conf_file_with_line
7634 @require_file_paths = @config_aux_path;
7635 &require_file_internal (0, @_);
7636 my $dir = $require_file_paths[0];
7637 @config_aux_path = @require_file_paths;
7638 # Avoid unsightly '/.'s.
7639 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7642 # Assumes that the line number is in configure.ac.
7643 sub require_conf_file_with_conf_line
7645 @require_file_paths = @config_aux_path;
7646 &require_file_internal (1, @_);
7647 my $dir = $require_file_paths[0];
7648 @config_aux_path = @require_file_paths;
7649 # avoid unsightly '/.'s.
7650 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7653 ################################################################
7655 # &require_build_directory ($DIRECTORY)
7656 # ------------------------------------
7657 # Emit rules to create $DIRECTORY if needed, and return
7658 # the file that any target requiring this directory should be made
7660 sub require_build_directory ($)
7662 my $directory = shift;
7663 my $dirstamp = "$directory/.dirstamp";
7665 # Don't emit the rule twice.
7666 if (! defined $directory_map{$directory})
7668 $directory_map{$directory} = 1;
7670 # Directory must be removed by `make distclean'.
7671 $compile_clean_files{$dirstamp} = $DIST_CLEAN;
7673 $output_rules .= ("$dirstamp:\n"
7674 . "\t\@\$(mkinstalldirs) $directory\n"
7675 . "\t\@: > $dirstamp\n");
7681 # &require_build_directory_maybe ($FILE)
7682 # --------------------------------------
7683 # If $FILE lies in a subdirectory, emit a rule to create this
7684 # directory and return the file that $FILE should be made
7685 # dependent upon. Otherwise, just return the empty string.
7686 sub require_build_directory_maybe ($)
7689 my $directory = dirname ($file);
7691 if ($directory ne '.')
7693 return &require_build_directory ($directory);
7701 ################################################################
7703 # Push a list of files onto dist_common.
7704 sub push_dist_common
7706 &prog_error ("push_dist_common run after handle_dist")
7707 if $handle_dist_run;
7708 macro_define ('DIST_COMMON', 1, '+', '', join (' ', @_), '');
7715 $strictness_name = $_[0];
7716 if ($strictness_name eq 'gnu')
7720 elsif ($strictness_name eq 'gnits')
7722 $strictness = $GNITS;
7724 elsif ($strictness_name eq 'foreign')
7726 $strictness = $FOREIGN;
7730 die "$me: level `$strictness_name' not recognized\n";
7735 ################################################################
7737 # Ensure a file exists.
7742 my $touch = new IO::File (">> $file");
7746 # Glob something. Do this to avoid indentation screwups everywhere we
7747 # want to glob. Gross!
7754 # Remove one level of brackets and strip leading spaces,
7755 # as does m4 to function arguments.
7761 my @letters = split //;
7770 next if $depth == 1;
7775 next if $depth == 0;
7776 # don't count orphan right brackets
7777 $depth = 0 if $depth < 0;
7781 return join '', @result;
7784 ################################################################
7786 # am_print_error ($LEADER, @ARGS)
7787 # -------------------------------
7788 # Do the work of printing the error message. Join @ARGS with spaces,
7789 # then split at newlines and add $LEADER to each line. Uses `warn' to
7793 my ($leader, @args) = @_;
7794 my $text = join (' ', @args);
7795 @args = split ("\n", $text);
7796 $text = $leader . join ("\n" . $leader, @args) . "\n";
7800 # Print an error message and set exit status.
7803 am_print_error ("$me: ${am_file}.am: ", @_);
7807 # am_file_error ($FILE, @ARGS)
7808 # ----------------------------
7811 my ($file, @args) = @_;
7813 am_print_error ("$file: ", @args);
7819 my ($symbol, @args) = @_;
7821 if ($symbol && "$symbol" ne '-1')
7823 my $file = "${am_file}.am";
7825 if ($symbol =~ /^\d+$/)
7827 # SYMBOL is a line number, so just add the colon.
7828 $file .= ':' . $symbol;
7830 elsif (defined $var_line{$symbol})
7832 # SYMBOL is a variable defined in Makefile.am, so add the
7833 # line number we saved from there.
7834 $file .= ':' . $var_line{$symbol};
7836 elsif (defined $configure_vars{$symbol})
7838 # SYMBOL is a variable defined in configure.ac, so add the
7839 # appropriate line number.
7840 $file = $configure_vars{$symbol};
7844 # Couldn't find the line number.
7847 am_print_error ("$file: ", @args);
7856 # Like am_error, but while scanning configure.ac.
7859 # FIXME: can run in subdirs.
7860 am_print_error ("$me: $configure_ac: ", @_);
7864 # Error message with line number referring to configure.ac.
7865 sub am_conf_line_error
7867 my ($file, $line, @args) = @_;
7871 am_print_error ("$file: $line: ", @args);
7876 &am_conf_error (@args);
7880 # Warning message with line number referring to configure.ac.
7881 # Does not affect exit_status
7882 sub am_conf_line_warning
7884 my $saved_exit_status = $exit_status;
7885 my $sig = $SIG{'__WARN__'};
7886 $SIG{'__WARN__'} = 'DEFAULT';
7887 am_conf_line_error (@_);
7888 $exit_status = $saved_exit_status;
7889 $SIG{'__WARN__'} = $sig;
7892 # Like am_line_error, but doesn't affect exit status.
7895 my $saved_exit_status = $exit_status;
7896 my $sig = $SIG{'__WARN__'};
7897 $SIG{'__WARN__'} = 'DEFAULT';
7899 $exit_status = $saved_exit_status;
7900 $SIG{'__WARN__'} = $sig;
7903 # Tell user where our aclocal.m4 is, but only once.
7904 sub keyed_aclocal_warning
7907 warn "$me: macro `$key' can be generated by `aclocal'\n";
7910 # Print usage information.
7914 Usage: $0 [OPTION] ... [Makefile]...
7916 Generate Makefile.in for configure from Makefile.am.
7919 --help print this help, then exit
7920 --version print version number, then exit
7921 -v, --verbose verbosely list files processed
7922 -o, --output-dir=DIR put generated Makefile.in's into DIR
7923 --no-force only update Makefile.in's that are out of date
7925 Dependency tracking:
7926 -i, --ignore-deps disable dependency tracking code
7927 --include-deps enable dependency tracking code
7930 --cygnus assume program is part of Cygnus-style tree
7931 --foreign set strictness to foreign
7932 --gnits set strictness to gnits
7933 --gnu set strictness to gnu
7936 -a, --add-missing add missing standard files to package
7937 --libdir=DIR directory storing library files
7938 -c, --copy with -a, copy missing files (default is symlink)
7939 -f, --force-missing force update of standard files
7944 foreach my $iter (sort ((@common_files, @common_sometimes)))
7946 push (@lcomm, $iter) unless $iter eq $last;
7951 print "\nFiles which are automatically distributed, if found:\n";
7952 format USAGE_FORMAT =
7953 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
7954 $four[0], $four[1], $four[2], $four[3]
7956 $~ = "USAGE_FORMAT";
7959 my $rows = int(@lcomm / $cols);
7960 my $rest = @lcomm % $cols;
7971 for (my $y = 0; $y < $rows; $y++)
7973 @four = ("", "", "", "");
7974 for (my $x = 0; $x < $cols; $x++)
7976 last if $y + 1 == $rows && $x == $rest;
7978 my $idx = (($x > $rest)
7979 ? ($rows * $rest + ($rows - 1) * ($x - $rest))
7983 $four[$x] = $lcomm[$idx];
7988 print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7995 # Print version information
7999 automake (GNU $PACKAGE) $VERSION
8000 Written by Tom Tromey <tromey\@cygnus.com>.
8002 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
8003 Free Software Foundation, Inc.
8004 This is free software; see the source for copying conditions. There is NO
8005 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.