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' => '$',
62 'derived_autodep' => '$',
66 # Name of the linking variable (LINK).
68 # Content of the linking variable.
71 # Name of the linker variable (LD).
73 # Content of the linker variable ($(CC)).
76 # Flag to specify the output file (-o).
84 if (defined $self->_finish)
94 use strict 'vars', 'subs';
98 my $me = basename ($0);
105 # Parameters set by configure. Not to be changed. NOTE: assign
106 # VERSION as string so that eg version 0.30 will print correctly.
107 my $VERSION = "@VERSION@";
108 my $PACKAGE = "@PACKAGE@";
109 my $prefix = "@prefix@";
110 my $libdir = "@datadir@/@PACKAGE@";
113 my $IGNORE_PATTERN = '^\s*##([^#\n].*)?\n';
114 my $WHITE_PATTERN = '^\s*$';
115 my $COMMENT_PATTERN = '^#';
116 my $TARGET_PATTERN='[$a-zA-Z_.][-.a-zA-Z0-9_(){}/$]*';
117 # A rule has three parts: a list of targets, a list of dependencies,
118 # and optionally actions.
120 "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
122 my $SUFFIX_RULE_PATTERN = '^\.([a-zA-Z0-9]+)\.([a-zA-Z0-9]+)$';
123 # Only recognize leading spaces, not leading tabs. If we recognize
124 # leading tabs here then we need to make the reader smarter, because
125 # otherwise it will think rules like `foo=bar; \' are errors.
126 my $MACRO_PATTERN = '^[A-Za-z0-9_@]+$';
127 my $ASSIGNMENT_PATTERN = '^ *([^ \t=:+]*)\s*([:+]?)=\s*(.*)$';
128 # This pattern recognizes a Gnits version id and sets $1 if the
129 # release is an alpha release. We also allow a suffix which can be
130 # used to extend the version number with a "fork" identifier.
131 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
132 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?$';
133 my $ELSE_PATTERN = '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
134 my $ENDIF_PATTERN = '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
135 my $PATH_PATTERN='(\w|[/.-])+';
136 # This will pass through anything not of the prescribed form.
137 my $INCLUDE_PATTERN = ('^include\s+'
138 . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
139 . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
140 . '|([^/\$]' . $PATH_PATTERN. '))\s*(#.*)?$');
142 # Some regular expressions. One reason to put them here is that it
143 # makes indentation work better in Emacs.
144 my $AC_CONFIG_AUX_DIR_PATTERN = 'AC_CONFIG_AUX_DIR\(([^)]+)\)';
145 my $AM_INIT_AUTOMAKE_PATTERN = 'AM_INIT_AUTOMAKE\([^,]*,([^,)]+)[,)]';
146 my $AM_PACKAGE_VERSION_PATTERN = '^\s*\[?([^]\s]+)\]?\s*$';
147 # Note that there is no AC_PATH_TOOL. But we don't really care.
148 my $AC_CHECK_PATTERN = 'AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\(\[?(\w+)';
149 my $AM_MISSING_PATTERN = 'AM_MISSING_PROG\(\[?(\w+)';
150 # Just check for alphanumeric in AC_SUBST. If you do AC_SUBST(5),
152 my $AC_SUBST_PATTERN = 'AC_SUBST\(\[?(\w+)';
153 my $AM_CONDITIONAL_PATTERN = 'AM_CONDITIONAL\(\[?(\w+)';
155 # Constants to define the "strictness" level.
160 # Values for AC_CANONICAL_*
161 my $AC_CANONICAL_HOST = 1;
162 my $AC_CANONICAL_SYSTEM = 2;
164 # Values indicating when something should be cleaned. Right now we
165 # only need to handle `mostly'- and `dist'-clean; add more as
167 my $MOSTLY_CLEAN = 0;
170 # Files installed by libtoolize.
171 my @libtoolize_files = ('ltmain.sh', 'config.guess', 'config.sub');
172 # ltconfig appears here for compatibility with old versions of libtool.
173 my @libtoolize_sometimes = ('ltconfig', 'ltcf-c.sh', 'ltcf-cxx.sh',
176 # Commonly found files we look for and automatically include in
180 'README', 'THANKS', 'TODO', 'NEWS', 'COPYING', 'COPYING.LIB',
181 'INSTALL', 'ABOUT-NLS', 'ChangeLog', 'configure.ac',
182 'configure.in', 'configure', 'config.guess', 'config.sub',
183 'AUTHORS', 'BACKLOG', 'ABOUT-GNU', 'libversion.in',
184 'mdate-sh', 'mkinstalldirs', 'install-sh', 'texinfo.tex',
185 'ansi2knr.c', 'ansi2knr.1', 'elisp-comp',
186 # ltconfig appears here for compatibility with old versions
188 'ylwrap', 'acinclude.m4', @libtoolize_files, @libtoolize_sometimes,
189 'missing', 'depcomp', 'compile', 'py-compile'
192 # Commonly used files we auto-include, but only sometimes.
193 my @common_sometimes =
195 'aclocal.m4', 'acconfig.h', 'config.h.top',
196 'config.h.bot', 'stamp-h.in', 'stamp-vti'
199 # Copyright on generated Makefile.ins.
200 my $gen_copyright = "\
201 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
202 # Free Software Foundation, Inc.
203 # This Makefile.in is free software; the Free Software Foundation
204 # gives unlimited permission to copy and/or distribute it,
205 # with or without modifications, as long as this notice is preserved.
207 # This program is distributed in the hope that it will be useful,
208 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
209 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
210 # PARTICULAR PURPOSE.
213 # These constants are returned by lang_*_rewrite functions.
214 # LANG_SUBDIR means that the resulting object file should be in a
215 # subdir if the source file is. In this case the file name cannot
216 # have `..' components.
218 my $LANG_PROCESS = 1;
221 # Directories installed during 'install-exec' phase.
240 # Map from obsolete macros to hints for new macros.
241 # If you change this, change the corresponding list in aclocal.in.
242 # FIXME: should just put this into a single file.
243 my %obsolete_macros =
245 'AC_FEATURE_CTYPE' => "use `AC_HEADER_STDC'",
246 'AC_FEATURE_ERRNO' => "add `strerror' to `AC_REPLACE_FUNCS(...)'",
247 'AC_FEATURE_EXIT' => '',
248 'AC_SYSTEM_HEADER' => '',
250 # Note that we do not handle this one, because it is still run
251 # from AM_CONFIG_HEADER. So we deal with it specially in
252 # &scan_autoconf_files.
253 # 'AC_CONFIG_HEADER' => "use `AM_CONFIG_HEADER'",
255 'fp_C_PROTOTYPES' => "use `AM_C_PROTOTYPES'",
256 'fp_PROG_CC_STDC' => "use `AM_PROG_CC_STDC'",
257 'fp_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
258 'fp_WITH_DMALLOC' => "use `AM_WITH_DMALLOC'",
259 'fp_WITH_REGEX' => "use `AM_WITH_REGEX'",
260 'gm_PROG_LIBTOOL' => "use `AM_PROG_LIBTOOL'",
261 'jm_MAINTAINER_MODE' => "use `AM_MAINTAINER_MODE'",
262 'md_TYPE_PTRDIFF_T' => "use `AM_TYPE_PTRDIFF_T'",
263 'ud_PATH_LISPDIR' => "use `AM_PATH_LISPDIR'",
264 'ud_GNU_GETTEXT' => "use `AM_GNU_GETTEXT'",
266 # Now part of autoconf proper, under a different name.
267 'AM_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
268 'fp_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
269 'AM_SANITY_CHECK_CC' => "automatically done by `AC_PROG_CC'",
270 'AM_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
271 'AM_EXEEXT' => "use `AC_EXEEXT'",
272 'AM_CYGWIN32' => "use `AC_CYGWIN'",
273 'AM_MINGW32' => "use `AC_MINGW32'",
274 'AM_FUNC_MKTIME' => "use `AC_FUNC_MKTIME'",
276 # These aren't quite obsolete.
280 # Regexp to match the above macros.
281 my $obsolete_rx = '(\b' . join ('\b|\b', keys %obsolete_macros) . '\b)';
285 ## ---------------------------------- ##
286 ## Variables related to the options. ##
287 ## ---------------------------------- ##
289 # TRUE if we should always generate Makefile.in.
290 my $force_generation = 1;
292 # Strictness level as set on command line.
293 my $default_strictness = $GNU;
295 # Name of strictness level, as set on command line.
296 my $default_strictness_name = 'gnu';
298 # This is TRUE if automatic dependency generation code should be
299 # included in generated Makefile.in.
300 my $cmdline_use_dependencies = 1;
302 # TRUE if in verbose mode.
305 # This holds our (eventual) exit status. We don't actually exit until
306 # we have processed all input files.
309 # From the Perl manual.
310 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
312 # TRUE if missing standard files should be installed.
315 # TRUE if we should copy missing files; otherwise symlink if possible.
316 my $copy_missing = 0;
318 # TRUE if we should always update files that we know about.
319 my $force_missing = 0;
322 ## ---------------------------------------- ##
323 ## Variables filled during files scanning. ##
324 ## ---------------------------------------- ##
326 # Name of the top autoconf input: `configure.ac' or `configure.in'.
327 my $configure_ac = '';
329 # Files found by scanning configure.ac for LIBOBJS.
332 # True if AM_C_PROTOTYPES appears in configure.ac.
333 my $am_c_prototypes = 0;
335 # Names used in AC_CONFIG_HEADER call. @config_fullnames holds the
336 # name which appears in AC_CONFIG_HEADER, colon and all.
337 # @config_names holds the file names. @config_headers holds the '.in'
338 # files. Ordinarily these are similar, but they can be different if
339 # the weird "NAME:FILE" syntax is used.
340 my @config_fullnames = ();
341 my @config_names = ();
342 my @config_headers = ();
343 # Line number at which AC_CONFIG_HEADER appears in configure.ac.
344 my $config_header_line = 0;
346 # Directory where output files go. Actually, output files are
347 # relative to this directory.
348 my $output_directory = '.';
350 # List of Makefile.am's to process, and their corresponding outputs.
351 my @input_files = ();
352 my %output_files = ();
354 # Complete list of Makefile.am's that exist.
355 my @configure_input_files = ();
357 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
358 my @other_input_files = ();
359 # Line number at which AC_OUTPUT seen.
360 my $ac_output_line = 0;
362 # List of directories to search for configure-required files. This
363 # can be set by AC_CONFIG_AUX_DIR.
364 my @config_aux_path = ('.', '..', '../..');
365 my $config_aux_dir = '';
366 my $config_aux_dir_set_in_configure_in = 0;
368 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
369 my $seen_gettext = 0;
370 # Line number at which AM_GNU_GETTEXT seen.
371 my $ac_gettext_line = 0;
373 # Whether ALL_LINGUAS has been seen.
374 my $seen_linguas = '';
376 my $all_linguas = '';
377 # Line number at which it appears.
378 my $all_linguas_line = 0;
380 # TRUE if AC_DECL_YYTEXT was seen.
381 my $seen_decl_yytext = 0;
383 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM). The presence of
384 # AC_CHECK_TOOL also sets this.
385 my $seen_canonical = 0;
387 # TRUE if we've seen AC_PROG_LIBTOOL.
388 my $seen_libtool = 0;
389 my $libtool_line = 0;
391 # TRUE if we've seen AM_MAINTAINER_MODE.
392 my $seen_maint_mode = 0;
394 # Actual version we've seen.
395 my $package_version = '';
397 # Line number where we saw version definition.
398 my $package_version_line = 0;
400 # TRUE if we've seen AM_PATH_LISPDIR.
401 my $seen_lispdir = 0;
403 # TRUE if we've seen AM_PATH_PYTHON.
404 my $seen_pythondir = 0;
406 # TRUE if we've seen AC_EXEEXT.
409 # TRUE if we've seen AC_OBJEXT.
412 # TRUE if we've seen AC_ENABLE_MULTILIB.
413 my $seen_multilib = 0;
415 # TRUE if we've seen AM_PROG_CC_C_O
418 # TRUE if we've seen AM_INIT_AUTOMAKE.
419 my $seen_init_automake = 0;
421 # Hash table of discovered configure substitutions. Keys are names,
422 # values are `FILE:LINE' strings which are used by error message
424 my %configure_vars = ();
426 # This is used to keep track of which variable definitions we are
427 # scanning. It is only used in certain limited ways, but it has to be
428 # global. It is declared just for documentation purposes.
429 my %vars_scanned = ();
431 # TRUE if --cygnus seen.
434 # Hash table of AM_CONDITIONAL variables seen in configure.
435 my %configure_cond = ();
437 # This maps extensions onto language names.
438 my %extension_map = ();
440 # List of the DIST_COMMON files we discovered while reading
442 my $configure_dist_common = '';
444 # This maps languages names onto objects.
447 # List of targets we must always output.
448 # FIXME: Complete, and remove falsely required targets.
449 my %required_targets =
460 # FIXME: Not required, temporary hacks.
461 # Well, actually they are sort of required: the -recursive
462 # targets will run them anyway...
465 'install-data-am' => 1,
466 'install-exec-am' => 1,
467 'installcheck-am' => 1,
475 ################################################################
477 ## ------------------------------------------ ##
478 ## Variables reset by &initialize_per_input. ##
479 ## ------------------------------------------ ##
481 # Basename and relative dir of the input file.
485 # Same but wrt Makefile.in.
489 # These two variables are used when generating each Makefile.in.
490 # They hold the Makefile.in until it is ready to be printed.
497 # Suffixes found during a run.
500 # Handling the variables.
503 # - $var_value{$VAR}{$COND} is its value associated to $COND,
504 # - $var_line{$VAR} is where it has been defined,
505 # - $var_comment{$VAR} are the comments associated to it.
506 # - $var_type{$VAR} is how it has been defined (`', `+', or `:'),
507 # - $var_is_am{$VAR} is true if the variable is owned by Automake.
514 # This holds a 1 if a particular variable was examined.
517 # This holds the names which are targets. These also appear in
521 # Same as %VAR_VALUE, but for targets.
522 my %target_conditional;
524 # This is the conditional stack.
527 # This holds the set of included files.
530 # This holds a list of directories which we must create at `dist'
531 # time. This is used in some strange scenarios involving weird
532 # AC_OUTPUT commands.
535 # List of dependencies for the obvious targets.
540 # Holds the dependencies of targets which dependencies are factored.
541 # Typically, `.PHONY' will appear in plenty of *.am files, but must
542 # be output once. Arguably all pure dependencies could be subject
543 # to this factorization, but it is not unpleasant to have paragraphs
544 # in Makefile: keeping related stuff altogether.
547 # Holds the factored actions. Tied to %DEPENDENCIES, i.e., filled
548 # only when keys exists in %DEPENDENCIES.
551 # A list of files deleted by `maintainer-clean'.
552 my @maintainer_clean_files;
554 # Keys in this hash table are object files or other files in
555 # subdirectories which need to be removed. This only holds files
556 # which are created by compilations. The value in the hash indicates
557 # when the file should be removed.
558 my %compile_clean_files;
560 # Value of `$(SOURCES)', used by tags.am.
562 # Sources which go in the distribution.
565 # This hash maps object file names onto their corresponding source
566 # file names. This is used to ensure that each object is created
567 # by a single source file.
570 # This keeps track of the directories for which we've already
571 # created `.dirstamp' code.
581 # Options from AUTOMAKE_OPTIONS.
584 # Whether or not dependencies are handled. Can be further changed
586 my $use_dependencies;
588 # All yacc and lex source filenames for this directory. Use
589 # filenames instead of raw count so that multiple instances are
590 # counted correctly (eg one yacc file can appear in multiple
591 # programs without harm).
595 # This is a list of all targets to run during "make dist".
598 # Keys in this hash are the basenames of files which must depend
602 # This maps the source extension of a suffix rule to its
603 # corresponding output extension.
606 # This is the name of the redirect `all' target to use.
609 # This keeps track of which extensions we've seen (that we care
613 # This is random scratch space for the language finish functions.
614 # Don't randomly overwrite it; examine other uses of keys first.
615 my %language_scratch;
617 # We keep track of which objects need special (per-executable)
618 # handling on a per-language basis.
619 my %lang_specific_files;
621 # This is set when `handle_dist' has finished. Once this happens,
622 # we should no longer push on dist_common.
625 # True if we need `LINK' defined. This is a hack.
628 # This is the list of such variables to output.
629 # FIXME: Might be useless actually.
632 # Was get_object_extension run?
633 # FIXME: This is a hack. a better switch should be found.
634 my $get_object_extension_was_run;
637 ## --------------------------------- ##
638 ## Forward subroutine declarations. ##
639 ## --------------------------------- ##
640 sub register_language (%);
641 sub file_contents_internal ($$%);
644 # &initialize_per_input ()
645 # ------------------------
646 # (Re)-Initialize per-Makefile.am variables.
647 sub initialize_per_input ()
650 $am_relative_dir = '';
657 $output_trailer = '';
673 %target_conditional = ();
681 $am_relative_dir = '';
697 # Installing/uninstalling.
698 'install-data-am' => [],
699 'install-exec-am' => [],
700 'uninstall-am' => [],
703 'uninstall-man' => [],
705 'install-info' => [],
706 'install-info-am' => [],
707 'uninstall-info' => [],
709 'installcheck-am' => [],
713 'mostlyclean-am' => [],
714 'maintainer-clean-am' => [],
715 'distclean-am' => [],
718 'maintainer-clean' => [],
729 @maintainer_clean_files = ();
740 $strictness = $default_strictness;
741 $strictness_name = $default_strictness_name;
745 $use_dependencies = $cmdline_use_dependencies;
758 %extension_seen = ();
760 %language_scratch = ();
762 %lang_specific_files = ();
764 $handle_dist_run = 0;
770 $get_object_extension_was_run = 0;
772 %compile_clean_files = ();
776 ################################################################
778 # Initialize our list of languages that are internally supported.
781 register_language ('name' => 'c',
783 'config_vars' => ['CC'],
787 'compiler' => 'COMPILE',
788 'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
792 'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
793 'compile_flag' => '-c',
794 'extensions' => ['c'],
795 '_finish' => \&lang_c_finish);
798 register_language ('name' => 'cxx',
800 'config_vars' => ['CXX'],
801 'linker' => 'CXXLINK',
802 'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
804 'flags' => 'CXXFLAGS',
805 'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
806 'compiler' => 'CXXCOMPILE',
807 'compile_flag' => '-c',
808 'output_flag' => '-o',
812 'extensions' => ['c++', 'cc', 'cpp', 'cxx', 'C']);
815 register_language ('name' => 'objc',
816 'Name' => 'Objective C',
817 'config_vars' => ['OBJC'],
818 'linker' => 'OBJCLINK',,
819 'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
821 'flags' => 'OBJCFLAGS',
822 'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
823 'compiler' => 'OBJCCOMPILE',
824 'compile_flag' => '-c',
825 'output_flag' => '-o',
829 'extensions' => ['m']);
832 register_language ('name' => 'header',
834 'extensions' => ['h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc'],
836 '_finish' => sub { });
838 # For now, yacc and lex can't be handled on a per-exe basis.
841 register_language ('name' => 'yacc',
844 'config_vars' => ['YACC'],
845 'derived_autodep' => 'yes',
846 'extensions' => ['y'],
847 '_finish' => \&lang_yacc_finish);
848 register_language ('name' => 'yaccxx',
849 'Name' => 'Yacc (C++)',
850 'config_vars' => ['YACC'],
851 'linker' => 'CXXLINK',
852 'derived_autodep' => 'yes',
853 'extensions' => ['y++', 'yy', 'yxx', 'ypp'],
854 '_finish' => \&lang_yacc_finish);
857 register_language ('name' => 'lex',
860 'config_vars' => ['LEX'],
861 'derived_autodep' => 'yes',
862 'extensions' => ['l'],
863 '_finish' => \&lang_lex_finish);
864 register_language ('name' => 'lexxx',
865 'Name' => 'Lex (C++)',
866 'config_vars' => ['LEX'],
867 'linker' => 'CXXLINK',
868 'derived_autodep' => 'yes',
869 'extensions' => ['l++', 'll', 'lxx', 'lpp'],
870 '_finish' => \&lang_lex_finish);
873 register_language ('name' => 'asm',
874 'Name' => 'Assembler',
875 'config_vars' => ['AS', 'ASFLAGS'],
877 'flags' => 'ASFLAGS',
878 # Users can set AM_ASFLAGS to includes DEFS, INCLUDES,
879 # or anything else required. They can also set AS.
880 'compile' => '$(AS) $(AM_ASFLAGS) $(ASFLAGS)',
881 'compiler' => 'ASCOMPILE',
882 'compile_flag' => '-c',
883 'extensions' => ['s', 'S'],
885 # With assembly we still use the C linker.
886 '_finish' => \&lang_c_finish);
889 register_language ('name' => 'f77',
890 'Name' => 'Fortran 77',
891 'linker' => 'F77LINK',
892 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
894 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
895 'compiler' => 'F77COMPILE',
896 'compile_flag' => '-c',
897 'output_flag' => '-o',
901 'extensions' => ['f', 'for', 'f90']);
903 # Preprocessed Fortran 77
905 # The current support for preprocessing Fortran 77 just involves
906 # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
907 # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
908 # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
909 # for `make' Version 3.76 Beta' (specifically, from info file
910 # `(make)Catalogue of Rules').
912 # A better approach would be to write an Autoconf test
913 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
914 # Fortran 77 compilers know how to do preprocessing. The Autoconf
915 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
916 # preprocessing capabilities, and then fall back on cpp (if cpp were
918 register_language ('name' => 'ppf77',
919 'Name' => 'Preprocessed Fortran 77',
920 'config_vars' => ['F77'],
921 'linker' => 'F77LINK',
922 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
926 'compiler' => 'PPF77COMPILE',
927 'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
928 'compile_flag' => '-c',
929 'output_flag' => '-o',
931 'extensions' => ['F']);
934 register_language ('name' => 'ratfor',
936 'config_vars' => ['F77'],
937 'linker' => 'F77LINK',
938 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
943 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
944 'compiler' => 'RCOMPILE',
945 'compile_flag' => '-c',
946 'output_flag' => '-o',
948 'extensions' => ['r']);
951 register_language ('name' => 'java',
953 'config_vars' => ['GCJ'],
954 'linker' => 'GCJLINK',
955 'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
957 'flags' => 'GCJFLAGS',
958 'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
959 'compiler' => 'GCJCOMPILE',
960 'compile_flag' => '-c',
961 'output_flag' => '-o',
965 'extensions' => ['java', 'class', 'zip', 'jar']);
967 ################################################################
969 # Parse command line.
972 # Do configure.ac scan only once.
973 &scan_autoconf_files;
975 die "$me: no `Makefile.am' found or specified\n"
978 # Now do all the work on each file.
979 # This guy must be local otherwise it's private to the loop.
982 foreach $am_file (@input_files)
984 if (! -f ($am_file . '.am'))
986 &am_error ("`" . $am_file . ".am' does not exist");
990 &generate_makefile ($output_files{$am_file}, $am_file);
996 # FIXME: This should be `my'ed next to its subs.
997 use vars '%require_file_found';
999 ################################################################
1001 # prog_error (@PRINT-ME)
1002 # ----------------------
1003 # Signal a programming error, display PRINT-ME, and exit 1.
1006 print STDERR "$me: programming error: @_\n";
1014 # Return LIST with no duplicates.
1019 foreach my $item (@_)
1021 if (! defined $seen{$item})
1032 # Return a configure-style substitution using the indicated text.
1033 # We do this to avoid having the substitutions directly in automake.in;
1034 # when we do that they are sometimes removed and this causes confusion
1039 return '@' . $text . '@';
1042 ################################################################
1046 # &backname ($REL-DIR)
1047 # --------------------
1048 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
1049 # For instance `src/foo' => `../..'.
1050 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
1055 foreach (split (/\//, $file))
1057 next if $_ eq '.' || $_ eq '';
1067 return join ('/', @res) || '.';
1070 ################################################################
1072 # Parse command line.
1073 sub parse_arguments ()
1076 &set_strictness ('gnu');
1079 Getopt::Long::config ("bundling");
1080 Getopt::Long::GetOptions
1082 'version' => \&version,
1084 'libdir:s' => \$libdir,
1085 'gnu' => sub { &set_strictness ('gnu'); },
1086 'gnits' => sub { &set_strictness ('gnits'); },
1087 'cygnus' => \$cygnus_mode,
1088 'foreign' => sub { &set_strictness ('foreign'); },
1089 'include-deps' => sub { $cmdline_use_dependencies = 1; },
1090 'i|ignore-deps' => sub { $cmdline_use_dependencies = 0; },
1091 'no-force' => sub { $force_generation = 0; },
1092 'f|force-missing'=> \$force_missing,
1093 'o|output-dir:s' => \$output_directory,
1094 'a|add-missing' => \$add_missing,
1095 'c|copy' => \$copy_missing,
1096 'v|verbose' => \$verbose,
1097 'Werror' => sub { $SIG{"__WARN__"} = sub { die $_[0] } },
1098 'Wno-error' => sub { $SIG{"__WARN__"} = 'DEFAULT' }
1102 foreach my $arg (@ARGV)
1104 # Handle $local:$input syntax. Note that we only examine the
1105 # first ":" file to see if it is automake input; the rest are
1106 # just taken verbatim. We still keep all the files around for
1107 # dependency checking, however.
1108 my ($local, $input, @rest) = split (/:/, $arg);
1115 # Strip .in; later on .am is tacked on. That is how the
1116 # automake input file is found. Maybe not the best way, but
1117 # it is easy to explain.
1119 or die "$me: invalid input file name `$arg'\n.";
1121 push (@input_files, $input);
1122 $output_files{$input} = join (':', ($local, @rest));
1125 # Take global strictness from whatever we currently have set.
1126 $default_strictness = $strictness;
1127 $default_strictness_name = $strictness_name;
1130 ################################################################
1132 # Generate a Makefile.in given the name of the corresponding Makefile and
1133 # the name of the file output by config.status.
1134 sub generate_makefile
1136 my ($output, $makefile) = @_;
1138 # Reset all the Makefile.am related variables.
1139 &initialize_per_input;
1141 # Name of input file ("Makefile.am") and output file
1142 # ("Makefile.in"). These have no directory components.
1143 $am_file_name = basename ($makefile) . '.am';
1144 $in_file_name = basename ($makefile) . '.in';
1146 # $OUTPUT is encoded. If it contains a ":" then the first element
1147 # is the real output file, and all remaining elements are input
1148 # files. We don't scan or otherwise deal with these input file,
1149 # other than to mark them as dependencies. See
1150 # &scan_autoconf_files for details.
1151 my (@secondary_inputs);
1152 ($output, @secondary_inputs) = split (/:/, $output);
1154 $relative_dir = dirname ($output);
1155 $am_relative_dir = dirname ($makefile);
1157 &read_main_am_file ($makefile . '.am');
1158 if (&handle_options)
1160 # Fatal error. Just return, so we can continue with next file.
1164 # There are a few install-related variables that you should not define.
1165 foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
1167 if (&variable_defined ($var) && !$var_is_am{$var})
1169 &am_line_error ($var, "`$var' should not be defined");
1173 # At the toplevel directory, we might need config.guess, config.sub
1174 # or libtool scripts (ltconfig and ltmain.sh).
1175 if ($relative_dir eq '.')
1179 # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1181 &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
1185 # We still need Makefile.in here, because sometimes the `dist'
1186 # target doesn't re-run automake.
1187 if ($am_relative_dir eq $relative_dir)
1189 # Only distribute the files if they are in the same subdir as
1190 # the generated makefile.
1191 &push_dist_common ($in_file_name, $am_file_name);
1194 push (@sources, '$(SOURCES)')
1195 if &variable_defined ('SOURCES');
1197 # If OBJEXT/EXEEXT were not set in configure.in, do it, it
1198 # simplifies our task, and anyway starting with Autoconf 2.50, it
1199 # will always be defined, and this code will be dead.
1200 $output_vars .= "EXEEXT =\n"
1201 unless $seen_exeext;
1202 $output_vars .= "OBJEXT = o\n"
1203 unless $seen_objext;
1205 # Must do this after reading .am file. See read_main_am_file to
1206 # understand weird tricks we play there with variables.
1207 &define_variable ('subdir', $relative_dir);
1209 # Check first, because we might modify some state.
1211 &check_gnu_standards;
1212 &check_gnits_standards;
1214 &handle_configure ($output, $makefile, @secondary_inputs);
1217 &handle_ltlibraries;
1221 # This must run first so that the ANSI2KNR definition is generated
1222 # before it is used by the _.c rules. We have to do this because
1223 # a variable which is used in a dependency must be defined before
1224 # the target, or else make won't properly see it.
1226 # This must be run after all the sources are scanned.
1229 # Re-init SOURCES. FIXME: other code shouldn't depend on this
1230 # (but currently does).
1231 macro_define ('SOURCES', 1, '', 'TRUE',
1232 join (' ', @sources), 'internal');
1233 &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
1245 &handle_minor_options;
1248 # This must come after most other rules.
1249 &handle_dist ($makefile);
1252 &do_check_merge_target;
1253 &handle_all ($output);
1256 if (&variable_defined('lib_LTLIBRARIES') &&
1257 &variable_defined('bin_PROGRAMS'))
1259 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
1262 &handle_installdirs;
1264 &handle_factored_dependencies;
1268 if (! -d ($output_directory . '/' . $am_relative_dir))
1270 mkdir ($output_directory . '/' . $am_relative_dir, 0755);
1273 my ($out_file) = $output_directory . '/' . $makefile . ".in";
1274 if (! $force_generation && -e $out_file)
1276 my ($am_time) = (stat ($makefile . '.am'))[9];
1277 my ($in_time) = (stat ($out_file))[9];
1278 # FIXME: should cache these times.
1279 my ($conf_time) = (stat ($configure_ac))[9];
1280 # FIXME: how to do unsigned comparison?
1281 if ($am_time < $in_time || $am_time < $conf_time)
1283 # No need to update.
1286 if (-f 'aclocal.m4')
1288 my ($acl_time) = (stat _)[9];
1289 return if ($am_time < $acl_time);
1293 my $gm_file = new IO::File "> $out_file";
1296 warn "$me: ${am_file}.in: cannot write: $!\n";
1300 print "$me: creating ", $makefile, ".in\n" if $verbose;
1302 # In case we're running under MSWindows, don't write with CRLF
1303 # (as it causes problems for the dependency-file extraction in
1304 # AM_OUTPUT_DEPENDENCY_COMMANDS).
1307 print $gm_file $output_vars;
1308 # We make sure that `all:' is the first target.
1309 print $gm_file $output_all;
1310 print $gm_file $output_header;
1311 print $gm_file $output_rules;
1312 print $gm_file $output_trailer;
1314 if (! $gm_file->close)
1316 warn "$me: $am_file.in: cannot close: $!\n";
1322 ################################################################
1324 # A helper which handles the logic of requiring a version number in
1325 # AUTOMAKE_OPTIONS. Return 1 on error, 0 on success.
1326 sub version_check ($$$$)
1328 my ($rmajor, $rminor, $ralpha, $rfork) = ($1, $2, $3, $4);
1330 &prog_error ("version is incorrect: $VERSION")
1331 if $VERSION !~ /(\d+)\.(\d+)([a-z]?)-?([A-Za-z0-9]+)?/;
1333 my ($tmajor, $tminor, $talpha, $tfork) = ($1, $2, $3, $4);
1338 my $rminorminor = 0;
1339 my $tminorminor = 0;
1341 # Some versions were labelled like `1.4-p3a'. This is the same as
1342 # an alpha release labelled `1.4.3a'. However, a version like
1343 # `1.4g' is the same as `1.4.99g'. Yes, this sucks. Moral:
1344 # always listen to the users.
1345 if ($rfork =~ /p([0-9]+)([a-z]?)/)
1348 # `1.4a-p3b' never existed. But we'll accept it anyway.
1349 $ralpha = $ralpha || $2 || '';
1352 if ($tfork =~ /p([0-9]+)([a-z]?)/)
1355 # `1.4a-p3b' never existed. But we'll accept it anyway.
1356 $talpha = $talpha || $2 || '';
1360 $rminorminor = 99 if $ralpha ne '' && $rminorminor == 0;
1361 $tminorminor = 99 if $talpha ne '' && $tminorminor == 0;
1363 # 2.0 is better than 1.0.
1364 # 1.2 is better than 1.1.
1365 # 1.2a is better than 1.2.
1366 # If we require 3.4n-foo then we require something
1367 # >= 3.4n, with the `foo' fork identifier.
1368 # The $r* variables are what the user specified.
1369 # The $t* variables denote automake itself.
1370 if ($rmajor > $tmajor
1371 || ($rmajor == $tmajor && $rminor > $tminor)
1372 || ($rminor == $tminor && $rminor == $tminor
1373 && $rminorminor > $tminorminor)
1374 || ($rminor == $tminor && $rminor == $tminor
1375 && $rminorminor == $tminorminor
1376 && $ralpha gt $talpha)
1377 || ($rfork ne '' && $rfork ne $tfork))
1379 &am_line_error ('AUTOMAKE_OPTIONS',
1380 "require version $_, but have $VERSION");
1387 # Handle AUTOMAKE_OPTIONS variable. Return 1 on error, 0 otherwise.
1390 if (&variable_defined ('AUTOMAKE_OPTIONS'))
1392 foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
1395 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
1397 &set_strictness ($_);
1399 elsif ($_ eq 'cygnus')
1405 # An option like "../lib/ansi2knr" is allowed. With
1406 # no path prefix, we assume the required programs are
1407 # in this directory. We save the actual option for
1409 $options{'ansi2knr'} = $_;
1411 elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
1412 || $_ eq 'dist-shar' || $_ eq 'dist-zip'
1413 || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
1414 || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
1415 || $_ eq 'readme-alpha' || $_ eq 'check-news'
1416 || $_ eq 'subdir-objects' || $_ eq 'nostdinc')
1418 # Explicitly recognize these.
1420 elsif ($_ eq 'no-dependencies')
1422 $use_dependencies = 0;
1424 elsif (/(\d+)\.(\d+)([a-z]?)(-[A-Za-z0-9]+)?/)
1426 # Got a version number.
1427 if (version_check ($1, $2, $3, $4))
1434 &am_line_error ('AUTOMAKE_OPTIONS',
1435 "option `" . $_ . "\' not recognized");
1440 if ($strictness == $GNITS)
1442 $options{'readme-alpha'} = 1;
1443 $options{'check-news'} = 1;
1450 # get_object_extension ($OUT)
1451 # ---------------------------
1452 # Return object extension. Just once, put some code into the output.
1453 # OUT is the name of the output file
1454 sub get_object_extension
1458 # Maybe require libtool library object files.
1459 my $extension = '.$(OBJEXT)';
1460 $extension = '.lo' if ($out =~ /\.la$/);
1462 # Check for automatic de-ANSI-fication.
1463 $extension = '$U' . $extension
1464 if defined $options{'ansi2knr'};
1466 $get_object_extension_was_run = 1;
1472 # Call finish function for each language that was used.
1473 sub handle_languages
1475 if ($use_dependencies)
1477 # Include auto-dep code. Don't include it if DEP_FILES would
1479 if (&saw_sources_p (0) && keys %dep_files)
1481 # Set location of depcomp.
1482 &define_variable ('depcomp', "\$(SHELL) $config_aux_dir/depcomp");
1484 &require_config_file ($FOREIGN, 'depcomp');
1486 my @deplist = sort keys %dep_files;
1488 # We define this as a conditional variable because BSD
1489 # make can't handle backslashes for continuing comments on
1490 # the following line.
1491 &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
1493 # Generate each `include' individually. Irix 6 make will
1494 # not properly include several files resulting from a
1495 # variable expansion; generating many separate includes
1497 $output_rules .= "\n";
1498 foreach my $iter (@deplist)
1500 $output_rules .= (subst ('AMDEP_TRUE')
1501 . subst ('_am_include')
1503 . subst ('_am_quote')
1505 . subst ('_am_quote')
1509 $output_rules .= &file_contents ('depend');
1514 &define_variable ('depcomp', '');
1519 # Is the c linker needed?
1521 foreach my $ext (sort keys %extension_seen)
1523 next unless $extension_map{$ext};
1525 my $lang = $languages{$extension_map{$ext}};
1527 # Get information on $LANG.
1528 my $pfx = $lang->autodep;
1529 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1531 my $AMDEP = (($use_dependencies && $lang->autodep ne 'no')
1532 ? 'AMDEP' : 'FALSE');
1534 my %transform = ('EXT' => $ext,
1537 'LIBTOOL' => $seen_libtool,
1539 '-c' => $lang->compile_flag || '');
1541 # Generate the appropriate rules for this extension.
1542 if ($use_dependencies && $lang->autodep ne 'no'
1543 || defined $lang->compile)
1545 # Some C compilers don't support -c -o. Use it only if really
1547 my $output_flag = $lang->output_flag || '';
1550 && $lang->flags eq 'CFLAGS'
1551 && defined $options{'subdir-objects'});
1554 file_contents ('depend2',
1564 'COMPILE' => '$(' . $lang->compiler . ')',
1565 'LTCOMPILE' => '$(LT' . $lang->compiler . ')',
1566 '-o' => $output_flag);
1569 # Now include code for each specially handled object with this
1571 my %seen_files = ();
1572 foreach my $file (@{$lang_specific_files{$lang->name}})
1574 my ($derived, $source, $obj) = split (' ', $file);
1576 # We might see a given object twice, for instance if it is
1577 # used under different conditions.
1578 next if defined $seen_files{$obj};
1579 $seen_files{$obj} = 1;
1581 my $flags = $lang->flags || '';
1582 my $val = "${derived}_${flags}";
1584 (my $obj_compile = $lang->compile) =~ s/\(AM_$flags/\($val/;
1585 my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
1587 # We _need_ `-o' for per object rules.
1588 my $output_flag = $lang->output_flag || '-o';
1590 # Generate a transform which will turn suffix targets in
1591 # depend2.am into real targets for the particular objects we
1594 file_contents ('depend2',
1599 'SOURCE' => $source,
1601 'OBJOBJ' => "$obj.obj",
1602 'LTOBJ' => "$obj.lo",
1604 'COMPILE' => $obj_compile,
1605 'LTCOMPILE' => $obj_ltcompile,
1606 '-o' => $output_flag));
1609 # The rest of the loop is done once per language.
1610 next if defined $done{$lang};
1613 # Load the language dependent Makefile chunks.
1614 my %lang = map { uc ($_) => 0 } keys %languages;
1615 $lang{uc ($lang->name)} = 1;
1616 $output_rules .= file_contents ('lang-compile', %transform, %lang);
1618 # If the source to a program consists entirely of code from a
1619 # `pure' language, for instance C++ for Fortran 77, then we
1620 # don't need the C compiler code. However if we run into
1621 # something unusual then we do generate the C code. There are
1622 # probably corner cases here that do not work properly.
1623 # People linking Java code to Fortran code deserve pain.
1624 $needs_c ||= ! $lang->pure;
1626 define_compiler_variable ($lang)
1627 if ($lang->compile);
1629 define_linker_variable ($lang)
1632 foreach my $var (@{$lang->config_vars})
1634 am_error ($lang->Name
1635 . " source seen but `$var' not defined in"
1636 . " `$configure_ac'")
1637 if !exists $configure_vars{$var};
1640 # The compiler's flag must be a configure variable.
1641 define_configure_variable ($lang->flags)
1642 if (defined $lang->flags);
1644 # Call the finisher.
1648 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1649 # suffix rule was learned), don't bother with the C stuff. But if
1650 # anything else creeps in, then use it.
1652 if $need_link || scalar keys %suffix_rules > 1;
1656 if (! defined $done{$languages{'c'}})
1658 &define_configure_variable ($languages{'c'}->flags);
1659 &define_compiler_variable ($languages{'c'});
1661 define_linker_variable ($languages{'c'});
1665 # Output a rule to build from a YACC source. The output from YACC is
1666 # compiled with C or C++, depending on the extension of the YACC file.
1667 sub output_yacc_build_rule
1669 my ($yacc_suffix, $use_ylwrap) = @_;
1671 (my $c_suffix = $yacc_suffix) =~ tr/y/c/;
1673 # Generate rule for c/c++.
1674 $output_rules .= &file_contents ('yacc',
1675 ('YLWRAP' => $use_ylwrap,
1676 'YACC_SUFFIX' => $yacc_suffix,
1677 'C_SUFFIX' => $c_suffix));
1680 sub output_lex_build_rule
1682 my ($lex_suffix, $use_ylwrap) = @_;
1684 (my $c_suffix = $lex_suffix) =~ tr/l/c/;
1686 $output_rules .= &file_contents ('lex',
1687 ('YLWRAP' => $use_ylwrap,
1688 'LEX_SUFFIX' => $lex_suffix,
1689 'C_SUFFIX' => $c_suffix));
1692 # Check to make sure a source defined in LIBOBJS is not explicitly
1693 # mentioned. This is a separate function (as opposed to being inlined
1694 # in handle_source_transform) because it isn't always appropriate to
1696 sub check_libobjs_sources
1698 my ($one_file, $unxformed) = @_;
1700 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1701 'dist_EXTRA_', 'nodist_EXTRA_')
1704 if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1706 @files = &variable_value_as_list (($prefix
1707 . $one_file . '_SOURCES'),
1710 elsif ($prefix eq '')
1712 @files = ($unxformed . '.c');
1719 foreach my $file (@files)
1721 if (defined $libsources{$file})
1723 &am_line_error ($prefix . $one_file . '_SOURCES',
1724 "automatically discovered file `$file' should not be explicitly mentioned");
1731 # ($LINKER, @OBJECTS)
1732 # handle_single_transform_list ($VAR, $DERIVED, $OBJ, @FILES)
1733 # -----------------------------------------------------------
1734 # Does much of the actual work for handle_source_transform.
1736 # $DERIVED is the name of resulting executable or library
1737 # $OBJ is the object extension (e.g., `$U.lo')
1738 # @FILES is the list of source files to transform
1740 # $LINKER is name of linker to use (empty string for default linker)
1741 # @OBJECTS are names of objects
1742 sub handle_single_transform_list ($$$@)
1744 my ($var, $derived, $obj, @files) = @_;
1746 my $nonansi_obj = $obj;
1747 $nonansi_obj =~ s/\$U//g;
1748 my %linkers_used = ();
1750 # Turn sources into objects.
1753 # Configure substitutions in _SOURCES variables are errors.
1756 &am_line_error ($var, "$var includes configure substitution `$_'");
1760 # If the source file is in a subdirectory then the `.o' is
1761 # put into the current directory.
1763 # Split file name into base and extension.
1764 next if ! /^(?:(.*)\/)?([^\/]*)\.(.*)$/;
1766 my $directory = $1 || '';
1770 # We must generate a rule for the object if it requires its own flags.
1772 my ($linker, $object);
1774 $extension = &derive_suffix ($extension);
1776 if ($extension_map{$extension} &&
1777 ($lang = $languages{$extension_map{$extension}}))
1779 &saw_extension ($extension);
1780 # Found the language, so see what it says.
1781 my $subr = 'lang_' . $lang->name . '_rewrite';
1782 # Note: computed subr call.
1783 my $r = & $subr ($directory, $base, $extension);
1784 # Skip this entry if we were asked not to process it.
1785 next if $r == $LANG_IGNORE;
1787 # Now extract linker and other info.
1788 $linker = $lang->linker;
1790 my $this_obj_ext = $lang->ansi ? $obj : $nonansi_obj;
1791 $object = $base . $this_obj_ext;
1793 if (defined $lang->flags
1794 && &variable_defined ($derived . '_' . $lang->flags))
1796 # We have a per-executable flag in effect for this
1797 # object. In this case we rewrite the object's
1798 # name to ensure it is unique. We also require
1799 # the `compile' program to deal with compilers
1800 # where `-c -o' does not work.
1802 # We choose the name `DERIVED_OBJECT' to ensure
1803 # (1) uniqueness, and (2) continuity between
1804 # invocations. However, this will result in a
1805 # name that is too long for losing systems, in
1806 # some situations. So we provide _SHORTNAME to
1809 my $dname = $derived;
1810 if (&variable_defined ($derived . '_SHORTNAME'))
1812 # FIXME: should use the same conditional as
1813 # the _SOURCES variable. But this is really
1814 # silly overkill -- nobody should have
1815 # conditional shortnames.
1816 $dname = &variable_value ($derived . '_SHORTNAME');
1818 $object = $dname . '-' . $object;
1820 &require_file ($FOREIGN, 'compile')
1821 if $lang->name eq 'c';
1823 &prog_error ("$lang->name flags defined without compiler")
1824 if ! defined $lang->compile;
1829 # If rewrite said it was ok, put the object into a
1831 if ($r == $LANG_SUBDIR && $directory ne '')
1833 $object = $directory . '/' . $object;
1836 # If doing dependency tracking, then we can't print
1837 # the rule. If we have a subdir object, we need to
1838 # generate an explicit rule. Actually, in any case
1839 # where the object is not in `.' we need a special
1840 # rule. The per-object rules in this case are
1841 # generated later, by handle_languages.
1842 if ($renamed || $directory ne '')
1844 my $obj_sans_ext = substr ($object, 0,
1845 - length ($this_obj_ext));
1846 my $val = "$full $obj_sans_ext";
1848 # If we renamed the object then we want to use the
1849 # per-executable flag name. But if this is simply a
1850 # subdir build then we still want to use the AM_ flag
1854 $val = "$derived $val";
1861 push (@{$lang_specific_files{$lang->name}}, $val);
1864 elsif ($extension eq 'o')
1866 # This is probably the result of a direct suffix rule.
1867 # In this case we just accept the rewrite. FIXME:
1868 # this fails if we want libtool objects.
1869 $object = $base . '.' . $extension;
1874 # No error message here. Used to have one, but it was
1879 $linkers_used{$linker} = 1;
1881 push (@result, $object);
1883 if (defined $object_map{$object})
1885 if ($object_map{$object} ne $full)
1887 &am_error ("object `$object' created by `$full' and `$object_map{$object}'");
1893 $object_map{$object} = $full;
1895 # If file is in subdirectory, we need explicit
1897 if ($directory ne '' || $renamed)
1899 push (@dep_list, $full);
1902 # If resulting object is in subdir, we need to make
1903 # sure the subdir exists at build time.
1904 if ($object =~ /\//)
1906 # FIXME: check that $DIRECTORY is somewhere in the
1909 # We don't allow `..' in object file names for
1910 # *any* source, not just Java. For Java it just
1911 # doesn't make sense, but in general it is
1912 # a problem because we can't pick a good name for
1914 if ($object =~ /(\/|^)\.\.\//)
1916 &am_error ("`$full' contains `..' component but should not");
1919 # Make sure object is removed by `make mostlyclean'.
1920 $compile_clean_files{$object} = $MOSTLY_CLEAN;
1922 push (@dep_list, $directory . '/.dirstamp');
1924 # If we're generating dependencies, we also want
1925 # to make sure that the appropriate subdir of the
1926 # .deps directory is created.
1927 if ($use_dependencies)
1929 push (@dep_list, '.deps/' . $directory . '/.dirstamp');
1932 if (! defined $directory_map{$directory})
1934 $directory_map{$directory} = 1;
1936 # Directory must be removed by `make distclean'.
1937 $compile_clean_files{$directory . "/.dirstamp"} =
1939 $output_rules .= ($directory . "/.dirstamp:\n"
1940 . "\t\@\$(mkinstalldirs) $directory\n"
1941 . "\t\@: > $directory/.dirstamp\n");
1942 if ($use_dependencies)
1944 $output_rules .= ('.deps/' . $directory
1946 . "\t\@\$(mkinstalldirs) .deps/$directory\n"
1947 . "\t\@: > .deps/$directory/.dirstamp\n");
1952 &pretty_print_rule ($object . ':', "\t", @dep_list)
1953 if scalar @dep_list > 0;
1956 # Transform .o or $o file into .P file (for automatic
1959 && ($lang->autodep ne 'no'
1960 || $lang->derived_autodep eq 'yes'))
1962 my $depfile = $object;
1963 $depfile =~ s/\.([^.]*)$/.P$1/;
1964 $depfile =~ s/\$\(OBJEXT\)$/o/;
1965 $dep_files{'$(DEPDIR)/' . $depfile} = 1;
1969 return (&resolve_linker (%linkers_used), @result);
1974 # Handle SOURCE->OBJECT transform for one program or library.
1976 # canonical (transformed) name of object to build
1977 # actual name of object to build
1978 # object extension (ie either `.o' or `$o'.
1979 # Return result is name of linker variable that must be used.
1980 # Empty return means just use `LINK'.
1981 sub handle_source_transform
1983 # one_file is canonical name. unxformed is given name. obj is
1985 my ($one_file, $unxformed, $obj) = @_;
1989 if (&variable_defined ($one_file . "_OBJECTS"))
1991 &am_line_error ($one_file . '_OBJECTS',
1992 $one_file . '_OBJECTS', 'should not be defined');
1993 # No point in continuing.
1998 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1999 'dist_EXTRA_', 'nodist_EXTRA_')
2001 my $var = $prefix . $one_file . "_SOURCES";
2003 if !variable_defined ($var);
2005 # We are going to define _OBJECTS variables using the prefix.
2006 # Then we glom them all together. So we can't use the null
2007 # prefix here as we need it later.
2008 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2010 # Keep track of which prefixes we saw.
2011 $used_pfx{$xpfx} = 1
2012 unless $prefix =~ /EXTRA_/;
2014 push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
2015 push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
2016 unless $prefix =~ /^nodist_/;
2017 foreach my $cond (variable_conditions ($var))
2019 my @files = &variable_value_as_list ($var, $cond);
2020 my ($temp, @result) =
2021 &handle_single_transform_list ($var, $one_file, $obj,
2023 # If there are no files to compile, don't require a linker (yet).
2027 # Define _OBJECTS conditionally.
2028 &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
2030 unless $prefix =~ /EXTRA_/;
2034 my @keys = sort keys %used_pfx;
2035 if (scalar @keys == 0)
2037 &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
2038 push (@sources, $unxformed . '.c');
2039 push (@dist_sources, $unxformed . '.c');
2041 my ($temp, @result) =
2042 &handle_single_transform_list ($one_file . '_SOURCES',
2045 $linker = $temp if $linker eq '';
2046 &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
2050 grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
2051 &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
2054 # If we want to use `LINK' we must make sure it is defined.
2064 # handle_lib_objects ($XNAME, $VAR)
2065 # ---------------------------------
2066 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
2067 # Also, generate _DEPENDENCIES variable if appropriate.
2069 # transformed name of object being built, or empty string if no object
2070 # name of _LDADD/_LIBADD-type variable to examine
2071 # Returns 1 if LIBOBJS seen, 0 otherwise.
2072 sub handle_lib_objects
2074 my ($xname, $var) = @_;
2076 &prog_error ("handle_lib_objects: $var undefined")
2077 if ! &variable_defined ($var);
2080 foreach my $cond (&variable_conditions ($var))
2082 if (&handle_lib_objects_cond ($xname, $var, $cond))
2090 # Subroutine of handle_lib_objects: handle a particular condition.
2091 sub handle_lib_objects_cond
2093 my ($xname, $var, $cond) = @_;
2095 # We recognize certain things that are commonly put in LIBADD or
2099 my $seen_libobjs = 0;
2102 foreach my $lsearch (&variable_value_as_list ($var, $cond))
2104 # Skip -lfoo and -Ldir; these are explicitly allowed.
2105 next if $lsearch =~ /^-[lL]/;
2106 if (! $flagvar && $lsearch =~ /^-/)
2108 if ($var =~ /^(.*)LDADD$/)
2110 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
2111 next if $lsearch =~ /^-dl(pre)?open$/;
2112 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2116 # Only get this error once.
2118 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2122 # Assume we have a file of some sort, and push it onto the
2123 # dependency list. Autoconf substitutions are not pushed;
2124 # rarely is a new dependency substituted into (eg) foo_LDADD
2125 # -- but "bad things (eg -lX11) are routinely substituted.
2126 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2127 # and handled specially below.
2128 push (@dep_list, $lsearch)
2129 unless $lsearch =~ /^\@.*\@$/;
2131 # Automatically handle @LIBOBJS@ and @ALLOCA@. Basically this
2132 # means adding entries to dep_files.
2133 if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
2135 my $myobjext = ($1 ? 'l' : '') . 'o';
2137 push (@dep_list, $lsearch);
2139 if (! keys %libsources
2140 && ! &variable_defined ($1 . 'LIBOBJS'))
2142 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in `$configure_ac'");
2145 foreach my $iter (keys %libsources)
2147 if ($iter =~ /\.([cly])$/)
2149 &saw_extension ($1);
2150 &saw_extension ('c');
2153 if ($iter =~ /\.h$/)
2155 &require_file_with_line ($var, $FOREIGN, $iter);
2157 elsif ($iter ne 'alloca.c')
2159 my $rewrite = $iter;
2160 $rewrite =~ s/\.c$/.P$myobjext/;
2161 $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
2162 ($rewrite = $iter) =~ s/(\W)/\\$1/g;
2163 $rewrite = "^" . $rewrite . "\$";
2164 # Only require the file if it is not a built source.
2165 if (! &variable_defined ('BUILT_SOURCES')
2166 || ! grep (/$rewrite/,
2167 &variable_value_as_list ('BUILT_SOURCES',
2170 &require_file_with_line ($var, $FOREIGN, $iter);
2175 elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
2177 my $myobjext = ($1 ? 'l' : '') . 'o';
2179 push (@dep_list, $lsearch);
2180 &am_line_error ($var,
2181 "\@$1" . "ALLOCA\@ seen but `AC_FUNC_ALLOCA' not in `$configure_ac'")
2182 if ! defined $libsources{'alloca.c'};
2183 $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
2184 &require_file_with_line ($var, $FOREIGN, 'alloca.c');
2185 &saw_extension ('c');
2189 if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
2191 &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
2194 return $seen_libobjs;
2197 # Canonicalize the input parameter
2201 $string =~ tr/A-Za-z0-9_\@/_/c;
2205 # Canonicalize a name, and check to make sure the non-canonical name
2206 # is never used. Returns canonical name. Arguments are name and a
2207 # list of suffixes to check for.
2208 sub check_canonical_spelling
2210 my ($name, @suffixes) = @_;
2212 my $xname = &canonicalize ($name);
2213 if ($xname ne $name)
2215 foreach my $xt (@suffixes)
2217 &am_line_error ("$name$xt",
2218 "invalid variable `$name$xt'; "
2219 . "should be `$xname$xt'")
2220 if &variable_defined ("$name$xt");
2230 # Set up the compile suite.
2231 sub handle_compile ()
2234 unless $get_object_extension_was_run;
2237 my $default_includes = '';
2238 if (! defined $options{'nostdinc'})
2240 $default_includes = ' -I. -I$(srcdir)';
2242 if (&variable_defined ('CONFIG_HEADER'))
2244 foreach my $hdr (split (' ', &variable_value ('CONFIG_HEADER')))
2246 $default_includes .= ' -I' . dirname ($hdr);
2251 my (@mostly_rms, @dist_rms);
2252 foreach my $item (sort keys %compile_clean_files)
2254 if ($compile_clean_files{$item} == $MOSTLY_CLEAN)
2256 push (@mostly_rms, "\t-rm -f $item");
2258 elsif ($compile_clean_files{$item} == $DIST_CLEAN)
2260 push (@dist_rms, "\t-rm -f $item");
2264 &prog_error ("invalid entry in \%compile_clean_files");
2268 my ($coms, $vars, $rules) =
2269 &file_contents_internal (1, "$libdir/am/compile.am",
2270 ('DEFAULT_INCLUDES' => $default_includes,
2271 'MOSTLYRMS' => join ("\n", @mostly_rms),
2272 'DISTRMS' => join ("\n", @dist_rms)));
2273 $output_vars .= $vars;
2274 $output_rules .= "$coms$rules";
2276 # Check for automatic de-ANSI-fication.
2277 if (defined $options{'ansi2knr'})
2279 if (! $am_c_prototypes)
2281 &am_line_error ('AUTOMAKE_OPTIONS',
2282 "option `ansi2knr' in use but `AM_C_PROTOTYPES' not in `$configure_ac'");
2283 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
2284 # Only give this error once.
2285 $am_c_prototypes = 1;
2288 # topdir is where ansi2knr should be.
2289 if ($options{'ansi2knr'} eq 'ansi2knr')
2291 # Only require ansi2knr files if they should appear in
2293 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
2294 'ansi2knr.c', 'ansi2knr.1');
2296 # ansi2knr needs to be built before subdirs, so unshift it.
2297 unshift (@all, '$(ANSI2KNR)');
2300 my $ansi2knr_dir = '';
2301 $ansi2knr_dir = dirname ($options{'ansi2knr'})
2302 if $options{'ansi2knr'} ne 'ansi2knr';
2304 $output_rules .= &file_contents ('ansi2knr',
2305 ('ANSI2KNR-DIR' => $ansi2knr_dir));
2312 # Handle libtool rules. Only called when RELATIVE_DIR is `.'.
2315 return unless $seen_libtool;
2317 # libtool requires some files.
2318 &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
2320 # Output the libtool compilation rules.
2321 $output_rules .= &file_contents ('libtool');
2324 # handle_programs ()
2325 # ------------------
2326 # Handle C programs.
2329 my @proglist = &am_install_var ('progs', 'PROGRAMS',
2330 'bin', 'sbin', 'libexec', 'pkglib',
2332 return if ! @proglist;
2334 my $seen_libobjs = 0;
2335 foreach my $one_file (@proglist)
2337 my $obj = &get_object_extension ($one_file);
2339 # Canonicalize names and check for misspellings.
2340 my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2341 '_SOURCES', '_OBJECTS',
2344 my $linker = &handle_source_transform ($xname, $one_file, $obj);
2347 if (&variable_defined ($xname . "_LDADD"))
2349 if (&handle_lib_objects ($xname, $xname . '_LDADD'))
2357 # User didn't define prog_LDADD override. So do it.
2358 &define_variable ($xname . '_LDADD', '$(LDADD)');
2360 # This does a bit too much work. But we need it to
2361 # generate _DEPENDENCIES when appropriate.
2362 if (&variable_defined ('LDADD'))
2364 if (&handle_lib_objects ($xname, 'LDADD'))
2369 elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
2371 &define_variable ($xname . '_DEPENDENCIES', '');
2376 if (&variable_defined ($xname . '_LIBADD'))
2378 &am_line_error ($xname . '_LIBADD',
2379 "use `" . $xname . "_LDADD', not `"
2380 . $xname . "_LIBADD'");
2383 if (! &variable_defined ($xname . '_LDFLAGS'))
2385 # Define the prog_LDFLAGS variable.
2386 &define_variable ($xname . '_LDFLAGS', '');
2389 # Determine program to use for link.
2391 if (&variable_defined ($xname . '_LINK'))
2393 $xlink = $xname . '_LINK';
2397 $xlink = $linker ? $linker : 'LINK';
2400 $output_rules .= &file_contents ('program',
2401 ('PROGRAM' => $one_file,
2402 'XPROGRAM' => $xname,
2403 'XLINK' => $xlink));
2406 if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD'))
2413 foreach my $one_file (@proglist)
2415 my $xname = &canonicalize ($one_file);
2417 if (&variable_defined ($xname . '_LDADD'))
2419 &check_libobjs_sources ($xname, $xname . '_LDADD');
2421 elsif (&variable_defined ('LDADD'))
2423 &check_libobjs_sources ($xname, 'LDADD');
2430 # handle_libraries ()
2431 # -------------------
2433 sub handle_libraries
2435 my @liblist = &am_install_var ('libs', 'LIBRARIES',
2436 'lib', 'pkglib', 'noinst', 'check');
2437 return if ! @liblist;
2439 my %valid = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2441 if (! defined $configure_vars{'RANLIB'})
2443 foreach my $key (keys %valid)
2445 if (&variable_defined ($key . '_LIBRARIES'))
2447 &am_line_error ($key . '_LIBRARIES', "library used but `RANLIB' not defined in `$configure_ac'");
2448 # Only get this error once. If this is ever printed,
2450 $configure_vars{'RANLIB'} = 'BUG';
2456 my $seen_libobjs = 0;
2457 foreach my $onelib (@liblist)
2459 # Check that the library fits the standard naming convention.
2460 if ($onelib !~ /^lib.*\.a$/)
2462 # FIXME should put line number here. That means mapping
2463 # from library name back to variable name.
2464 &am_error ("`$onelib' is not a standard library name");
2467 my $obj = &get_object_extension ($onelib);
2469 # Canonicalize names and check for misspellings.
2470 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2471 '_OBJECTS', '_DEPENDENCIES',
2474 if (! &variable_defined ($xlib . '_AR'))
2476 &define_variable ($xlib . '_AR', '$(AR) cru');
2479 if (&variable_defined ($xlib . '_LIBADD'))
2481 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2488 # Generate support for conditional object inclusion in
2490 &define_variable ($xlib . "_LIBADD", '');
2493 if (&variable_defined ($xlib . '_LDADD'))
2495 &am_line_error ($xlib . '_LDADD',
2496 "use `" . $xlib . "_LIBADD', not `"
2497 . $xlib . "_LDADD'");
2500 # Make sure we at look at this.
2501 &examine_variable ($xlib . '_DEPENDENCIES');
2503 &handle_source_transform ($xlib, $onelib, $obj);
2505 $output_rules .= &file_contents ('library',
2506 ('LIBRARY' => $onelib,
2507 'XLIBRARY' => $xlib));
2512 foreach my $onelib (@liblist)
2514 my $xlib = &canonicalize ($onelib);
2515 if (&variable_defined ($xlib . '_LIBADD'))
2517 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2524 # handle_ltlibraries ()
2525 # ---------------------
2526 # Handle shared libraries.
2527 sub handle_ltlibraries
2529 my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2530 'noinst', 'lib', 'pkglib', 'check');
2531 return if ! @liblist;
2534 my %valid = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2537 foreach my $key (keys %valid)
2539 if (&variable_defined ($key . '_LTLIBRARIES'))
2543 &am_line_error ($key . '_LTLIBRARIES', "library used but `LIBTOOL' not defined in `$configure_ac'");
2544 # Only get this error once. If this is ever printed,
2546 $configure_vars{'LIBTOOL'} = 'BUG';
2550 # Get the installation directory of each library.
2551 for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
2555 &am_error ("`$_' is already going to be installed in `$instdirs{$_}'");
2559 $instdirs{$_} = $key;
2565 my $seen_libobjs = 0;
2566 foreach my $onelib (@liblist)
2568 my $obj = &get_object_extension ($onelib);
2570 # Canonicalize names and check for misspellings.
2571 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2572 '_SOURCES', '_OBJECTS',
2575 if (! &variable_defined ($xlib . '_LDFLAGS'))
2577 # Define the lib_LDFLAGS variable.
2578 &define_variable ($xlib . '_LDFLAGS', '');
2581 # Check that the library fits the standard naming convention.
2582 my $libname_rx = "^lib.*\.la";
2583 if ((&variable_defined ($xlib . '_LDFLAGS')
2584 && grep (/-module/, &variable_value_as_list ($xlib . '_LDFLAGS',
2586 || (&variable_defined ('LDFLAGS')
2587 && grep (/-module/, &variable_value_as_list ('LDFLAGS',
2590 # Relax name checking for libtool modules.
2591 $libname_rx = "\.la";
2593 if ($onelib !~ /$libname_rx$/)
2595 # FIXME this should only be a warning for foreign packages
2596 # FIXME should put line number here. That means mapping
2597 # from library name back to variable name.
2598 &am_error ("`$onelib' is not a standard libtool library name");
2601 if (&variable_defined ($xlib . '_LIBADD'))
2603 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2610 # Generate support for conditional object inclusion in
2612 &define_variable ($xlib . "_LIBADD", '');
2615 if (&variable_defined ($xlib . '_LDADD'))
2617 &am_line_error ($xlib . '_LDADD',
2618 "use `" . $xlib . "_LIBADD', not `"
2619 . $xlib . "_LDADD'");
2622 # Make sure we at look at this.
2623 &examine_variable ($xlib . '_DEPENDENCIES');
2625 my $linker = &handle_source_transform ($xlib, $onelib, $obj);
2627 # Determine program to use for link.
2629 if (&variable_defined ($xlib . '_LINK'))
2631 $xlink = $xlib . '_LINK';
2635 $xlink = $linker ? $linker : 'LINK';
2639 if ($instdirs{$onelib} eq 'EXTRA'
2640 || $instdirs{$onelib} eq 'noinst'
2641 || $instdirs{$onelib} eq 'check')
2643 # It's an EXTRA_ library, so we can't specify -rpath,
2644 # because we don't know where the library will end up.
2645 # The user probably knows, but generally speaking automake
2646 # doesn't -- and in fact configure could decide
2647 # dynamically between two different locations.
2652 $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
2655 $output_rules .= &file_contents ('ltlibrary',
2656 ('LTLIBRARY' => $onelib,
2657 'XLTLIBRARY' => $xlib,
2659 'XLINK' => $xlink));
2664 foreach my $onelib (@liblist)
2666 my $xlib = &canonicalize ($onelib);
2667 if (&variable_defined ($xlib . '_LIBADD'))
2669 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2675 # See if any _SOURCES variable were misspelled. Also, make sure that
2676 # EXTRA_ variables don't contain configure substitutions.
2679 foreach my $varname (keys %var_value)
2681 foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
2684 if ($varname =~ /$primary$/ && ! $content_seen{$varname})
2686 &am_line_error ($varname,
2687 "invalid unused variable name: `$varname'");
2696 # NOTE we no longer automatically clean SCRIPTS, because it is
2697 # useful to sometimes distribute scripts verbatim. This happens
2698 # eg in Automake itself.
2699 &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2700 'bin', 'sbin', 'libexec', 'pkgdata',
2703 my $scripts_installed = 0;
2704 # Set $scripts_installed if appropriate. Make sure we only find
2705 # scripts which are actually installed -- this is why we can't
2706 # simply use the return value of am_install_var.
2707 my %valid = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
2708 'libexec', 'pkgdata',
2710 foreach my $key (keys %valid)
2712 if ($key ne 'noinst'
2714 && &variable_defined ($key . '_SCRIPTS'))
2716 $scripts_installed = 1;
2717 # push (@check_tests, 'check-' . $key . 'SCRIPTS');
2723 # ($OUTFILE, $VFILE, @CLEAN_FILES)
2724 # &scan_texinfo_file ($FILENAME)
2725 # ------------------------------
2726 # $OUTFILE is the name of the info file produced by $FILENAME.
2727 # $VFILE is the name of the version.texi file used (empty if none).
2728 # @CLEAN_FILES is the list of by products (indexes etc.)
2729 sub scan_texinfo_file
2731 my ($filename) = @_;
2733 # These are always created, no matter whether indexes are used or not.
2734 my @clean_suffixes = ('aux', 'dvi', 'log', 'ps', 'toc',
2735 # grep new.*index texinfo.tex
2736 'cp', 'fn', 'ky', 'vr', 'tp', 'pg');
2738 # There are predefined indexes which don't follow the regular rules.
2739 my %predefined_index =
2742 'c' => 'cps', 'f' => 'fns', 'k' => 'kys',
2743 'v' => 'vrs', 't' => 'tps', 'p' => 'pgs'
2746 # There are commands which include a hidden index command.
2750 'fn' => 'fns', 'un' => 'fns',
2751 'typefn' => 'fns', 'typefun' => 'fns',
2752 'mac' => 'fns', 'spec' => 'fns',
2753 'op' => 'fns', 'typeop' => 'fns',
2754 'method' => 'fns', 'typemethod' => 'fns',
2756 'vr' => 'vrs', 'var' => 'vrs',
2757 'typevr' => 'vrs', 'typevar' => 'vrs',
2760 'ivar' => 'vrs', 'typeivar' => 'vrs',
2765 # Indexes stored into another one. In this case, the *.??s file
2767 my @syncodeindexes = ();
2769 my $texi = new IO::File ("< $filename");
2772 &am_error ("couldn't open `$filename': $!");
2775 print "$me: reading $filename\n" if $verbose;
2777 my ($outfile, $vfile);
2778 while ($_ = $texi->getline)
2780 if (/^\@setfilename +(\S+)/)
2783 if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
2785 &am_file_error ($filename, "$.: ",
2786 "output `$outfile' has unrecognized extension");
2790 # A "version.texi" file is actually any file whose name
2791 # matches "vers*.texi".
2792 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2797 # Try to find what are the indexes which are used.
2799 # Creating a new category of index.
2800 elsif (/^\@def(code)?index (\w+)/)
2802 push @clean_suffixes, $2;
2805 # Storing in a predefined index.
2806 elsif (/^\@([cfkvtp])index /)
2808 push @clean_suffixes, $predefined_index{$1};
2810 elsif (/^\@def(\w+) /)
2812 push @clean_suffixes, $hidden_index{$1}
2813 if defined $hidden_index{$1};
2816 # Merging an index into an another.
2817 elsif (/^\@syn(code)?index (\w+) \w+/)
2819 push @syncodeindexes, "$2s";
2827 &am_error ("`$filename' missing \@setfilename");
2831 my $infobase = basename ($filename);
2832 $infobase =~ s/\.te?xi(nfo)?$//;
2833 # FIXME: I don't understand why, but I can't use "$infobase.$_" => 1.
2834 my %clean_files = map { "$infobase" . ".$_" => 1 } @clean_suffixes;
2835 grep { delete $clean_files{"$infobase.$_"} } @syncodeindexes;
2836 return ($outfile, $vfile, (sort keys %clean_files));
2840 # ($DO-SOMETHING, $TEXICLEANS)
2841 # handle_texinfo_helper ()
2843 # Handle all Texinfo source; helper for handle_texinfo
2844 sub handle_texinfo_helper
2846 &am_line_error ('TEXINFOS',
2847 "`TEXINFOS' is an anachronism; use `info_TEXINFOS'")
2848 if &variable_defined ('TEXINFOS');
2849 return (0, '') if (! &variable_defined ('info_TEXINFOS')
2850 && ! &variable_defined ('html_TEXINFOS'));
2852 if (&variable_defined ('html_TEXINFOS'))
2854 &am_line_error ('html_TEXINFOS',
2855 "HTML generation not yet supported");
2859 my @texis = &variable_value_as_list ('info_TEXINFOS', 'all');
2861 my (@info_deps_list, @dvis_list, @texi_deps);
2868 foreach my $info_cursor (@texis)
2870 my $infobase = $info_cursor;
2871 $infobase =~ s/\.(txi|texinfo|texi)$//;
2873 if ($infobase eq $info_cursor)
2875 # FIXME: report line number.
2876 &am_error ("texinfo file `$info_cursor' has unrecognized extension");
2879 $texi_suffixes{$1} = 1;
2881 # If 'version.texi' is referenced by input file, then include
2882 # automatic versioning capability.
2883 my ($out_file, $vtexi, @clean_files) =
2884 &scan_texinfo_file ("$relative_dir/$info_cursor")
2886 push (@texi_cleans, @clean_files);
2890 &am_error ("`$vtexi', included in `$info_cursor', also included in `$versions{$vtexi}'")
2891 if (defined $versions{$vtexi});
2892 $versions{$vtexi} = $info_cursor;
2894 # We number the stamp-vti files. This is doable since the
2895 # actual names don't matter much. We only number starting
2896 # with the second one, so that the common case looks nice.
2897 my $vti = ($done ? $done : 'vti');
2900 # This is ugly, but it is our historical practice.
2901 if ($config_aux_dir_set_in_configure_in)
2903 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2908 &require_file_with_line ('info_TEXINFOS', $FOREIGN,
2913 if ($config_aux_dir_set_in_configure_in)
2915 $conf_dir = $config_aux_dir;
2916 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
2920 $conf_dir = '$(srcdir)/';
2922 $output_rules .= &file_contents ('texi-vers',
2923 ('TEXI' => $info_cursor,
2926 'MDDIR' => $conf_dir));
2929 # If user specified file_TEXINFOS, then use that as explicit
2932 push (@texi_deps, $info_cursor);
2933 # Prefix with $(srcdir) because some version of make won't
2934 # work if the target has it and the dependency doesn't.
2935 push (@texi_deps, '$(srcdir)/' . $vtexi) if $vtexi;
2937 my $canonical = &canonicalize ($infobase);
2938 if (&variable_defined ($canonical . "_TEXINFOS"))
2940 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
2941 &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
2944 $output_rules .= ("\n" . $out_file . ": "
2945 . join (' ', @texi_deps)
2946 . "\n" . $infobase . ".dvi: "
2947 . join (' ', @texi_deps)
2950 push (@info_deps_list, $out_file);
2951 push (@dvis_list, $infobase . '.dvi');
2954 # Handle location of texinfo.tex.
2955 my $need_texi_file = 0;
2959 $texinfodir = '$(top_srcdir)/../texinfo';
2960 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
2962 elsif ($config_aux_dir_set_in_configure_in)
2964 $texinfodir = $config_aux_dir;
2965 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
2966 $need_texi_file = 2; # so that we require_conf_file later
2968 elsif (&variable_defined ('TEXINFO_TEX'))
2970 # The user defined TEXINFO_TEX so assume he knows what he is
2972 $texinfodir = ('$(srcdir)/'
2973 . dirname (&variable_value ('TEXINFO_TEX')));
2977 $texinfodir = '$(srcdir)';
2978 $need_texi_file = 1;
2981 foreach my $txsfx (sort keys %texi_suffixes)
2983 $output_rules .= &file_contents ('texibuild',
2984 ('TEXINFODIR' => $texinfodir,
2985 'SUFFIX' => $txsfx));
2989 my $texiclean = &pretty_print_internal ("", "\t ", @texi_cleans);
2991 push (@dist_targets, 'dist-info');
2993 if (! defined $options{'no-installinfo'})
2995 # Make sure documentation is made and installed first. Use
2996 # $(INFO_DEPS), not 'info', because otherwise recursive makes
2997 # get run twice during "make all".
2998 unshift (@all, '$(INFO_DEPS)');
3001 &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
3002 &define_variable ("DVIS", join (' ', @dvis_list));
3003 # This next isn't strictly needed now -- the places that look here
3004 # could easily be changed to look in info_TEXINFOS. But this is
3005 # probably better, in case noinst_TEXINFOS is ever supported.
3006 &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
3008 # Do some error checking. Note that this file is not required
3009 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3011 if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
3013 if ($need_texi_file > 1)
3015 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
3020 &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
3024 return (1, $texiclean);
3029 # Handle all Texinfo source.
3032 my ($do_something, $texiclean) = handle_texinfo_helper ();
3033 $output_rules .= &file_contents ('texinfos',
3034 ('TEXICLEAN' => $texiclean,
3035 'LOCAL-TEXIS' => $do_something));
3038 # Handle any man pages.
3039 sub handle_man_pages
3041 &am_line_error ('MANS', "`MANS' is an anachronism; use `man_MANS'")
3042 if &variable_defined ('MANS');
3044 # Find all the sections in use. We do this by first looking for
3045 # "standard" sections, and then looking for any additional
3046 # sections used in man_MANS.
3047 my (%sections, %vlist);
3048 # We handle nodist_ for uniformity. man pages aren't distributed
3049 # by default so it isn't actually very important.
3050 foreach my $pfx ('', 'dist_', 'nodist_')
3052 # Add more sections as needed.
3053 foreach my $section ('0'..'9', 'n', 'l')
3055 if (&variable_defined ($pfx . 'man' . $section . '_MANS'))
3057 $sections{$section} = 1;
3058 $vlist{'$(' . $pfx . 'man' . $section . '_MANS)'} = 1;
3060 &push_dist_common ('$(' . $pfx . 'man' . $section . '_MANS)')
3065 if (&variable_defined ($pfx . 'man_MANS'))
3067 $vlist{'$(' . $pfx . 'man_MANS)'} = 1;
3068 foreach (&variable_value_as_list ($pfx . 'man_MANS', 'all'))
3070 # A page like `foo.1c' goes into man1dir.
3071 if (/\.([0-9a-z])([a-z]*)$/)
3077 &push_dist_common ('$(' . $pfx . 'man_MANS)')
3082 return unless %sections;
3084 # Now for each section, generate an install and unintall rule.
3085 # Sort sections so output is deterministic.
3086 foreach my $section (sort keys %sections)
3088 $output_rules .= &file_contents ('mans', ('SECTION' => $section));
3091 $output_vars .= &file_contents ('mans-vars',
3092 ('MANS' => join (' ', sort keys %vlist)));
3094 if (! defined $options{'no-installman'})
3096 push (@all, '$(MANS)');
3100 # Handle DATA variables.
3103 &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3104 'data', 'sysconf', 'sharedstate', 'localstate',
3105 'pkgdata', 'noinst', 'check');
3112 if (&variable_defined ('SUBDIRS'))
3114 $output_rules .= ("tags-recursive:\n"
3115 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3116 # Never fail here if a subdir fails; it
3118 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3119 . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3121 push (@tag_deps, 'tags-recursive');
3122 &depend ('.PHONY', 'tags-recursive');
3125 if (&saw_sources_p (1)
3126 || &variable_defined ('ETAGS_ARGS')
3130 foreach my $one_hdr (@config_headers)
3132 if ($relative_dir eq dirname ($one_hdr))
3134 # The config header is in this directory. So require it.
3135 $config .= ' ' if $config;
3136 $config .= basename ($one_hdr);
3139 $output_rules .= &file_contents ('tags',
3140 ('CONFIG' => $config,
3141 'DIRS' => join (' ', @tag_deps)));
3142 &examine_variable ('TAGS_DEPENDENCIES');
3144 elsif (&variable_defined ('TAGS_DEPENDENCIES'))
3146 &am_line_error ('TAGS_DEPENDENCIES',
3147 "doesn't make sense to define `TAGS_DEPENDENCIES' without sources or `ETAGS_ARGS'");
3151 # Every Makefile must define some sort of TAGS rule.
3152 # Otherwise, it would be possible for a top-level "make TAGS"
3153 # to fail because some subdirectory failed.
3154 $output_rules .= "tags: TAGS\nTAGS:\n\n";
3158 # Handle multilib support.
3161 if ($seen_multilib && $relative_dir eq '.')
3163 $output_rules .= &file_contents ('multilib');
3169 # &for_dist_common ($A, $B)
3170 # -------------------------
3171 # Subroutine for &handle_dist: sort files to dist.
3173 # We put README first because it then becomes easier to make a
3174 # Usenet-compliant shar file (in these, README must be first).
3176 # FIXME: do more ordering of files here.
3189 # handle_dist ($MAKEFILE)
3190 # -----------------------
3191 # Handle 'dist' target.
3194 my ($makefile) = @_;
3196 # `make dist' isn't used in a Cygnus-style tree.
3197 # Omit the rules so that people don't try to use them.
3198 return if $cygnus_mode;
3200 # Look for common files that should be included in distribution.
3201 foreach my $cfile (@common_files)
3203 if (-f ($relative_dir . "/" . $cfile))
3205 &push_dist_common ($cfile);
3209 # We might copy elements from $configure_dist_common to
3210 # %dist_common if we think we need to. If the file appears in our
3211 # directory, we would have discovered it already, so we don't
3212 # check that. But if the file is in a subdir without a Makefile,
3213 # we want to distribute it here if we are doing `.'. Ugly!
3214 if ($relative_dir eq '.')
3216 foreach my $file (split (' ' , $configure_dist_common))
3218 if (! &is_make_dir (dirname ($file)))
3220 &push_dist_common ($file);
3227 # Files to distributed. Don't use &variable_value_as_list
3228 # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3229 check_variable_defined_unconditionally ('DIST_COMMON');
3230 my @dist_common = split (' ', variable_value ('DIST_COMMON', 'TRUE'));
3231 @dist_common = uniq (sort for_dist_common (@dist_common));
3232 pretty_print ('DIST_COMMON = ', "\t", @dist_common);
3234 # Now that we've processed DIST_COMMON, disallow further attempts
3236 $handle_dist_run = 1;
3238 # Scan EXTRA_DIST to see if we need to distribute anything from a
3239 # subdir. If so, add it to the list. I didn't want to do this
3240 # originally, but there were so many requests that I finally
3242 if (&variable_defined ('EXTRA_DIST'))
3244 # FIXME: This should be fixed to work with conditionals. That
3245 # will require only making the entries in %dist_dirs under the
3246 # appropriate condition. This is meaningful if the nature of
3247 # the distribution should depend upon the configure options
3249 foreach (&variable_value_as_list ('EXTRA_DIST', ''))
3252 next unless s,/+[^/]+$,,;
3258 # We have to check DIST_COMMON for extra directories in case the
3259 # user put a source used in AC_OUTPUT into a subdir.
3260 foreach (&variable_value_as_list ('DIST_COMMON', 'all'))
3263 next unless s,/+[^/]+$,,;
3268 # Rule to check whether a distribution is viable.
3269 my %transform = ('DISTCHECK-HOOK' => &target_defined ('distcheck-hook'),
3270 'GETTEXT' => $seen_gettext);
3272 # Prepend $(distdir) to each directory given.
3273 my %rewritten = map { '$(distdir)/' . "$_" => 1 } keys %dist_dirs;
3274 $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);
3276 # If we have SUBDIRS, create all dist subdirectories and do
3278 if (&variable_defined ('SUBDIRS'))
3280 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3281 # to all possible directories, and use it. If DIST_SUBDIRS is
3282 # defined, just use it.
3283 my $dist_subdir_name;
3284 # Note that we check DIST_SUBDIRS first on purpose. At least
3285 # one project uses so many conditional subdirectories that
3286 # calling variable_conditionally_defined on SUBDIRS will cause
3287 # automake to grow to 150Mb. Sigh.
3288 if (&variable_defined ('DIST_SUBDIRS')
3289 || variable_conditionally_defined ('SUBDIRS'))
3291 $dist_subdir_name = 'DIST_SUBDIRS';
3292 if (! &variable_defined ('DIST_SUBDIRS'))
3294 &define_pretty_variable
3295 ('DIST_SUBDIRS', '',
3296 uniq (&variable_value_as_list ('SUBDIRS', 'all')));
3301 $dist_subdir_name = 'SUBDIRS';
3302 # We always define this because that is what `distclean'
3304 &define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
3307 $transform{'DIST_SUBDIR_NAME'} = $dist_subdir_name;
3310 # If the target `dist-hook' exists, make sure it is run. This
3311 # allows users to do random weird things to the distribution
3312 # before it is packaged up.
3313 push (@dist_targets, 'dist-hook')
3314 if &target_defined ('dist-hook');
3315 $transform{'DIST-TARGETS'} = join(' ', @dist_targets);
3317 # Defining $(DISTDIR).
3318 $transform{'DISTDIR'} = !&variable_defined('distdir');
3319 $transform{'TOP_DISTDIR'} = backname ($relative_dir);
3321 $output_rules .= &file_contents ('distdir', %transform);
3325 # Handle subdirectories.
3329 unless &variable_defined ('SUBDIRS');
3331 # Make sure each directory mentioned in SUBDIRS actually exists.
3332 foreach my $dir (&variable_value_as_list ('SUBDIRS', 'all'))
3334 # Skip directories substituted by configure.
3335 next if $dir =~ /^\@.*\@$/;
3337 if (! -d $am_relative_dir . '/' . $dir)
3339 &am_line_error ('SUBDIRS',
3340 "required directory $am_relative_dir/$dir does not exist");
3344 &am_line_error ('SUBDIRS', "directory should not contain `/'")
3348 $output_rules .= &file_contents ('subdirs');
3349 variable_pretty_output ('RECURSIVE_TARGETS', 'TRUE');
3353 # ($REGEN, @DEPENDENCIES)
3356 # If aclocal.m4 creation is automated, return the list of its dependencies.
3359 my $regen_aclocal = 0;
3362 unless $relative_dir eq '.';
3364 &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3365 &examine_variable ('CONFIGURE_DEPENDENCIES');
3367 if (-f 'aclocal.m4')
3369 &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3370 &push_dist_common ('aclocal.m4');
3372 my $aclocal = new IO::File ("< aclocal.m4");
3375 my $line = $aclocal->getline;
3378 if ($line =~ 'generated automatically by aclocal')
3387 if (-f 'acinclude.m4')
3390 push @ac_deps, 'acinclude.m4';
3393 if (&variable_defined ('ACLOCAL_M4_SOURCES'))
3395 push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3397 elsif (&variable_defined ('ACLOCAL_AMFLAGS'))
3399 # Scan all -I directories for m4 files. These are our
3401 my $examine_next = 0;
3402 foreach my $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
3407 if ($amdir !~ /^\// && -d $amdir)
3409 foreach my $ac_dep (&my_glob ($amdir . '/*.m4'))
3411 $ac_dep =~ s/^\.\/+//;
3412 push (@ac_deps, $ac_dep)
3413 unless $ac_dep eq "aclocal.m4"
3414 || $ac_dep eq "acinclude.m4";
3418 elsif ($amdir eq '-I')
3425 # Note that it might be possible that aclocal.m4 doesn't exist but
3426 # should be auto-generated. This case probably isn't very
3429 return ($regen_aclocal, @ac_deps);
3432 # Rewrite a list of input files into a form suitable to put on a
3433 # dependency list. The idea is that if an input file has a directory
3434 # part the same as the current directory, then the directory part is
3435 # simply removed. But if the directory part is different, then
3436 # $(top_srcdir) is prepended. Among other things, this is used to
3437 # generate the dependency list for the output files generated by
3438 # AC_OUTPUT. Consider what the dependencies should look like in this
3440 # AC_OUTPUT(src/out:src/in1:lib/in2)
3441 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3442 # If 0 then files that require this addition will simply be ignored.
3443 sub rewrite_inputs_into_dependencies
3445 my ($add_srcdir, @inputs) = @_;
3448 foreach my $single (@inputs)
3450 if (dirname ($single) eq $relative_dir)
3452 push (@newinputs, basename ($single));
3456 push (@newinputs, '$(top_srcdir)/' . $single);
3463 # Handle remaking and configure stuff.
3464 # We need the name of the input file, to do proper remaking rules.
3465 sub handle_configure
3467 my ($local, $input, @secondary_inputs) = @_;
3469 my $input_base = basename ($input);
3470 my $local_base = basename ($local);
3472 my $amfile = $input_base . '.am';
3473 # We know we can always add '.in' because it really should be an
3474 # error if the .in was missing originally.
3475 my $infile = '$(srcdir)/' . $input_base . '.in';
3476 my $colon_infile = '';
3477 if ($local ne $input || @secondary_inputs)
3479 $colon_infile = ':' . $input . '.in';
3481 $colon_infile .= ':' . join (':', @secondary_inputs)
3482 if @secondary_inputs;
3484 my @rewritten = &rewrite_inputs_into_dependencies (1, @secondary_inputs);
3486 my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4 ();
3489 &file_contents ('configure',
3493 => join (' ', @rewritten),
3495 => ((($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3500 => join (' ', @include_stack),
3504 => $cygnus_mode ? 'cygnus' : $strictness_name,
3506 => $cmdline_use_dependencies ? '' : ' --ignore-deps',
3507 'MAKEFILE-AM-SOURCES'
3508 => "$input$colon_infile",
3510 => $regen_aclocal_m4,
3512 => join (' ', @aclocal_m4_deps)));
3514 if ($relative_dir eq '.')
3516 &push_dist_common ('acconfig.h')
3520 # If we have a configure header, require it.
3521 my @local_fullnames = @config_fullnames;
3522 my @local_names = @config_names;
3524 my $distclean_config = '';
3525 foreach my $one_hdr (@config_headers)
3527 my $one_fullname = shift (@local_fullnames);
3528 my $one_name = shift (@local_names);
3530 my $header_dir = dirname ($one_name);
3532 # If the header is in the current directory we want to build
3533 # the header here. Otherwise, if we're at the topmost
3534 # directory and the header's directory doesn't have a
3535 # Makefile, then we also want to build the header.
3536 if ($relative_dir eq $header_dir
3537 || ($relative_dir eq '.' && ! &is_make_dir ($header_dir)))
3539 my ($cn_sans_dir, $stamp_dir);
3540 if ($relative_dir eq $header_dir)
3542 $cn_sans_dir = basename ($one_name);
3547 $cn_sans_dir = $one_name;
3548 if ($header_dir eq '.')
3554 $stamp_dir = $header_dir . '/';
3558 # Compute relative path from directory holding output
3559 # header to directory holding input header. FIXME:
3560 # doesn't handle case where we have multiple inputs.
3562 if (dirname ($one_hdr) eq $relative_dir)
3564 $ch_sans_dir = basename ($one_hdr);
3568 $ch_sans_dir = backname ($relative_dir) . '/' . $one_hdr;
3571 &require_file_with_conf_line ($config_header_line,
3572 $FOREIGN, $ch_sans_dir);
3574 # Header defined and in this directory.
3576 if (-f $one_name . '.top')
3578 push (@files, "${cn_sans_dir}.top");
3580 if (-f $one_name . '.bot')
3582 push (@files, "${cn_sans_dir}.bot");
3585 &push_dist_common (@files);
3587 # For now, acconfig.h can only appear in the top srcdir.
3588 if (-f 'acconfig.h')
3590 push (@files, '$(top_srcdir)/acconfig.h');
3593 my $stamp_name = 'stamp-h';
3594 $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3596 my $out_dir = dirname ($ch_sans_dir);
3599 &file_contents ('remake-hdr',
3600 ('FILES' => join (' ', @files),
3601 'CONFIG_HEADER' => $cn_sans_dir,
3602 'CONFIG_HEADER_IN' => $ch_sans_dir,
3603 'CONFIG_HEADER_FULL' => $one_fullname,
3604 'STAMP' => "$stamp_dir$stamp_name",
3605 'SRC_STAMP' => "$out_dir/$stamp_name"));
3607 &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3608 &require_file_with_conf_line ($config_header_line, $FOREIGN,
3609 "${out_dir}/${stamp_name}.in");
3611 $distclean_config .= ' ' if $distclean_config;
3612 $distclean_config .= $cn_sans_dir;
3616 if ($distclean_config)
3618 $output_rules .= &file_contents ('clean-hdr',
3619 ('FILES' => $distclean_config));
3622 # Set location of mkinstalldirs.
3623 &define_variable ('mkinstalldirs',
3624 ('$(SHELL) ' . $config_aux_dir . '/mkinstalldirs'));
3626 &am_line_error ('CONFIG_HEADER',
3627 "`CONFIG_HEADER' is an anachronism; now determined from `$configure_ac'")
3628 if &variable_defined ('CONFIG_HEADER');
3630 my $config_header = '';
3631 foreach my $one_name (@config_names)
3633 # Generate CONFIG_HEADER define.
3635 if ($relative_dir eq dirname ($one_name))
3637 $one_hdr = basename ($one_name);
3641 $one_hdr = "\$(top_builddir)/${one_name}";
3644 $config_header .= ' ' if $config_header;
3645 $config_header .= $one_hdr;
3649 &define_variable ("CONFIG_HEADER", $config_header);
3652 # Now look for other files in this directory which must be remade
3653 # by config.status, and generate rules for them.
3654 my @actual_other_files = ();
3655 foreach my $lfile (@other_input_files)
3658 my (@inputs, @rewritten_inputs);
3659 my ($need_rewritten);
3660 if ($lfile =~ /^([^:]*):(.*)$/)
3662 # This is the ":" syntax of AC_OUTPUT.
3664 $local = basename ($file);
3665 @inputs = split (':', $2);
3666 @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3667 $need_rewritten = 1;
3673 $local = basename ($file);
3674 @inputs = ($file . '.in');
3676 &rewrite_inputs_into_dependencies (1, @inputs);
3677 $need_rewritten = 0;
3680 # Make sure the dist directory for each input file is created.
3681 # We only have to do this at the topmost level though. This
3682 # is a bit ugly but it easier than spreading out the logic,
3683 # especially in cases like AC_OUTPUT(foo/out:bar/in), where
3684 # there is no Makefile in bar/.
3685 if ($relative_dir eq '.')
3689 $dist_dirs{dirname ($_)} = 1;
3693 # We skip any automake input files, as they are handled
3694 # elsewhere. We also skip files that aren't in this
3695 # directory. However, if the file's directory does not have a
3696 # Makefile, and we are currently doing `.', then we create a
3697 # rule to rebuild the file in the subdir.
3698 next if -f $file . '.am';
3699 my $fd = dirname ($file);
3700 if ($fd ne $relative_dir)
3702 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
3712 # Some users have been tempted to put `stamp-h' in the
3713 # AC_OUTPUT line. This won't do the right thing, so we
3714 # explicitly fail here.
3715 if ($local eq 'stamp-h')
3717 # FIXME: allow real filename.
3718 &am_conf_error ($configure_ac, $ac_output_line,
3719 'stamp-h should not appear in AC_OUTPUT');
3723 $output_rules .= ($local . ': '
3724 . '$(top_builddir)/config.status '
3725 . join (' ', @rewritten_inputs) . "\n"
3727 . 'cd $(top_builddir) && CONFIG_FILES='
3728 . ($relative_dir eq '.' ? '' : '$(subdir)/')
3729 . '$@' . ($need_rewritten
3730 ? (':' . join (':', @inputs))
3732 . ' CONFIG_HEADERS= CONFIG_LINKS= $(SHELL) ./config.status'
3734 push (@actual_other_files, $local);
3736 # Require all input files.
3737 &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3738 &rewrite_inputs_into_dependencies (0, @inputs));
3741 # These files get removed by "make clean".
3742 &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3748 my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3749 'oldinclude', 'pkginclude',
3753 next unless /\.(.*)$/;
3754 &saw_extension ($1);
3760 return if ! $seen_gettext || $relative_dir ne '.';
3762 if (! &variable_defined ('SUBDIRS'))
3765 ("AM_GNU_GETTEXT used but SUBDIRS not defined");
3769 my @subdirs = &variable_value_as_list ('SUBDIRS', 'all');
3770 &am_line_error ('SUBDIRS',
3771 "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
3772 if ! grep ('po', @subdirs);
3773 &am_line_error ('SUBDIRS',
3774 "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
3775 if ! grep ('intl', @subdirs);
3777 &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3779 # Ensure that each language in ALL_LINGUAS has a .po file, and
3780 # each po file is mentioned in ALL_LINGUAS.
3783 my %linguas = map { $_ => 1 } split (' ', $all_linguas);
3790 &am_line_error ($all_linguas_line,
3791 ("po/$_.po exists but `$_' not in `ALL_LINGUAS'"))
3795 foreach (keys %linguas)
3797 &am_line_error ($all_linguas_line,
3798 "$_ in `ALL_LINGUAS' but po/$_.po does not exist")
3804 &am_error ("AM_GNU_GETTEXT in `$configure_ac' but `ALL_LINGUAS' not defined");
3808 # Handle footer elements.
3811 # NOTE don't use define_pretty_variable here, because
3812 # $contents{...} is already defined.
3813 $output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n\n"
3814 if variable_value ('SOURCES');
3817 &am_line_error ('.SUFFIXES',
3818 "use variable `SUFFIXES', not target `.SUFFIXES'")
3819 if target_defined ('.SUFFIXES');
3821 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3822 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
3823 # anything else, by sticking it right after the default: target.
3824 $output_header .= ".SUFFIXES:\n";
3825 if (@suffixes || &variable_defined ('SUFFIXES'))
3827 # Make sure suffixes has unique elements. Sort them to ensure
3828 # the output remains consistent. However, $(SUFFIXES) is
3829 # always at the start of the list, unsorted. This is done
3830 # because make will choose rules depending on the ordering of
3831 # suffixes, and this lets the user have some control. Push
3832 # actual suffixes, and not $(SUFFIXES). Some versions of make
3833 # do not like variable substitutions on the .SUFFIXES line.
3834 my @user_suffixes = (&variable_defined ('SUFFIXES')
3835 ? &variable_value_as_list ('SUFFIXES', '')
3838 my %suffixes = map { $_ => 1 } @suffixes;
3839 delete @suffixes{@user_suffixes};
3841 $output_header .= (".SUFFIXES: "
3842 . join (' ', @user_suffixes, sort keys %suffixes)
3846 $output_trailer .= file_contents ('footer');
3849 # Deal with installdirs target.
3850 sub handle_installdirs ()
3853 &file_contents ('install',
3855 => variable_value ('_am_installdirs') || ''));
3859 # Deal with all and all-am.
3862 my ($makefile) = @_;
3866 # Put this at the beginning for the sake of non-GNU makes. This
3867 # is still wrong if these makes can run parallel jobs. But it is
3869 unshift (@all, basename ($makefile));
3871 foreach my $one_name (@config_names)
3873 push (@all, basename ($one_name))
3874 if dirname ($one_name) eq $relative_dir;
3877 # Install `all' hooks.
3878 if (&target_defined ("all-local"))
3880 push (@all, "all-local");
3881 &depend ('.PHONY', "all-local");
3884 &pretty_print_rule ("all-am:", "\t\t", @all);
3885 &depend ('.PHONY', 'all-am', 'all');
3890 my @local_headers = ();
3891 push @local_headers, '$(BUILT_SOURCES)'
3892 if &variable_defined ('BUILT_SOURCES');
3893 foreach my $one_name (@config_names)
3895 push @local_headers, basename ($one_name)
3896 if dirname ($one_name) eq $relative_dir;
3901 # We need to make sure config.h is built before we recurse.
3902 # We also want to make sure that built sources are built
3903 # before any ordinary `all' targets are run. We can't do this
3904 # by changing the order of dependencies to the "all" because
3905 # that breaks when using parallel makes. Instead we handle
3906 # things explicitly.
3907 $output_all .= ("all: " . join (' ', @local_headers)
3909 . '$(MAKE) $(AM_MAKEFLAGS) '
3910 . (&variable_defined ('SUBDIRS')
3911 ? 'all-recursive' : 'all-am')
3916 $output_all .= "all: " . (&variable_defined ('SUBDIRS')
3917 ? 'all-recursive' : 'all-am') . "\n\n";
3922 # Handle check merge target specially.
3923 sub do_check_merge_target
3925 if (&target_defined ('check-local'))
3927 # User defined local form of target. So include it.
3928 push (@check_tests, 'check-local');
3929 &depend ('.PHONY', 'check-local');
3932 # In --cygnus mode, check doesn't depend on all.
3935 # Just run the local check rules.
3936 &pretty_print_rule ('check-am:', "\t\t", @check);
3940 # The check target must depend on the local equivalent of
3941 # `all', to ensure all the primary targets are built. Then it
3942 # must build the local check rules.
3943 $output_rules .= "check-am: all-am\n";
3944 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
3948 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
3952 &depend ('.PHONY', 'check', 'check-am');
3953 $output_rules .= ("check: "
3954 . (&variable_defined ('SUBDIRS')
3955 ? 'check-recursive' : 'check-am')
3959 # Handle all 'clean' targets.
3964 # Don't include `MAINTAINER'; it is handled specially below.
3965 foreach my $name ('MOSTLY', '', 'DIST')
3967 $transform{"${name}CLEAN"} = &variable_defined ("${name}CLEANFILES");
3970 # Built sources are automatically removed by maintainer-clean.
3971 push (@maintainer_clean_files, '$(BUILT_SOURCES)')
3972 if &variable_defined ('BUILT_SOURCES');
3973 push (@maintainer_clean_files, '$(MAINTAINERCLEANFILES)')
3974 if &variable_defined ('MAINTAINERCLEANFILES');
3976 $output_rules .= &file_contents ('clean',
3979 # Join with no space to avoid
3980 # spurious `test -z' success at
3982 => join ('', @maintainer_clean_files),
3984 # A space is required in the join here.
3985 => join (' ', @maintainer_clean_files)));
3989 # &depend ($CATEGORY, @DEPENDENDEES)
3990 # ----------------------------------
3991 # The target $CATEGORY depends on @DEPENDENDEES.
3994 my ($category, @dependendees) = @_;
3996 push (@{$dependencies{$category}}, @dependendees);
4001 # &target_cmp ($A, $B)
4002 # --------------------
4003 # Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
4016 # &handle_factored_dependencies ()
4017 # --------------------------------
4018 # Handle everything related to gathered targets.
4019 sub handle_factored_dependencies
4022 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4023 'uninstall-exec-local', 'uninstall-exec-hook')
4025 if (&target_defined ($utarg))
4028 $x =~ s/(data|exec)-//;
4029 &am_line_error ($utarg, "use `$x', not `$utarg'");
4033 if (&target_defined ('install-local'))
4035 &am_line_error ('install-local',
4036 "use `install-data-local' or `install-exec-local', "
4037 . "not `install-local'");
4040 if (!defined $options{'no-installinfo'}
4041 && &target_defined ('install-info-local'))
4043 &am_line_error ('install-info-local',
4044 "`install-info-local' target defined but "
4045 . "`no-installinfo' option not in use");
4048 # Install the -local hooks.
4049 foreach (keys %dependencies)
4051 # Hooks are installed on the -am targets.
4053 if (&target_defined ("$_-local"))
4055 depend ("$_-am", "$_-local");
4056 &depend ('.PHONY', "$_-local");
4060 # Install the -hook hooks.
4061 # FIXME: Why not be as liberal as we are with -local hooks?
4062 foreach ('install-exec', 'install-data')
4064 if (&target_defined ("$_-hook"))
4066 $actions{"$_-am"} .=
4067 ("\t\@\$(NORMAL_INSTALL)\n"
4068 . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
4072 # All the required targets are phony.
4073 depend ('.PHONY', keys %required_targets);
4075 # Actually output gathered targets.
4076 foreach (sort target_cmp keys %dependencies)
4078 # If there is nothing about this guy, skip it.
4080 unless (@{$dependencies{$_}}
4082 || $required_targets{$_});
4083 &pretty_print_rule ("$_:", "\t",
4084 uniq (sort @{$dependencies{$_}}));
4085 $output_rules .= $actions{$_}
4086 if defined $actions{$_};
4087 $output_rules .= "\n";
4092 # &handle_tests_dejagnu ()
4093 # ------------------------
4094 sub handle_tests_dejagnu
4096 push (@check_tests, 'check-DEJAGNU');
4098 # Only create site.exp rule if user hasn't already written one.
4100 file_contents ('dejagnu', ('SITE-EXP' => ! target_defined ('site.exp')));
4104 # Handle TESTS variable and other checks.
4107 if (defined $options{'dejagnu'})
4109 &handle_tests_dejagnu;
4113 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4116 "`$c' defined but `dejagnu' not in `AUTOMAKE_OPTIONS'")
4117 if &variable_defined ($c);
4121 if (&variable_defined ('TESTS'))
4123 push (@check_tests, 'check-TESTS');
4124 $output_rules .= &file_contents ('check');
4128 # Handle Emacs Lisp.
4129 sub handle_emacs_lisp
4131 my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4134 return if ! @elfiles;
4136 # Generate .elc files.
4137 my @elcfiles = map { $_ . 'c' } @elfiles;
4138 &define_pretty_variable ('ELCFILES', '', @elcfiles);
4140 push (@all, '$(ELCFILES)');
4142 &am_error ("`lisp_LISP' defined but `AM_PATH_LISPDIR' not in `$configure_ac'")
4143 if ! $seen_lispdir && &variable_defined ('lisp_LISP');
4145 &require_file_with_conf_line ('AM_PATH_LISPDIR', $FOREIGN, 'elisp-comp');
4151 my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4152 'python', 'noinst');
4153 return if ! @pyfiles;
4155 # Found some python.
4156 &am_error ("`python_PYTHON' defined but `AM_PATH_PYTHON' not in `$configure_ac'")
4157 if ! $seen_pythondir && &variable_defined ('python_PYTHON');
4159 &require_file_with_conf_line ('AM_PATH_PYTHON', $FOREIGN, 'py-compile');
4160 &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4166 my @sourcelist = &am_install_var ('-candist',
4168 'java', 'noinst', 'check');
4169 return if ! @sourcelist;
4171 my %valid = &am_primary_prefixes ('JAVA', 1,
4172 'java', 'noinst', 'check');
4175 foreach my $curs (keys %valid)
4177 if (! &variable_defined ($curs . '_JAVA') || $curs eq 'EXTRA')
4184 &am_line_error ($curs . '_JAVA',
4185 "multiple _JAVA primaries in use");
4190 push (@all, 'class' . $dir . '.stamp');
4194 # Handle some of the minor options.
4195 sub handle_minor_options
4197 if (defined $options{'readme-alpha'})
4199 if ($relative_dir eq '.')
4201 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4203 # FIXME: allow real filename.
4204 &am_conf_line_error ($configure_ac,
4205 $package_version_line,
4206 "version `$package_version' doesn't follow Gnits standards");
4208 elsif (defined $1 && -f 'README-alpha')
4210 # This means we have an alpha release. See
4211 # GNITS_VERSION_PATTERN for details.
4212 &require_file ($FOREIGN, 'README-alpha');
4218 ################################################################
4221 my @make_input_list;
4222 # &scan_autoconf_config_files ($CONFIG-FILES)
4223 # -------------------------------------------
4224 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4226 sub scan_autoconf_config_files
4228 my ($config_files) = @_;
4229 # Look at potential Makefile.am's.
4230 foreach (split ' ', $config_files)
4232 # Must skip empty string for Perl 4.
4233 next if $_ eq "\\" || $_ eq '';
4235 # Handle $local:$input syntax. Note that we ignore
4236 # every input file past the first, though we keep
4237 # those around for later.
4238 my ($local, $input, @rest) = split (/:/);
4245 # FIXME: should be error if .in is missing.
4246 $input =~ s/\.in$//;
4249 if (-f $input . '.am')
4251 # We have a file that automake should generate.
4252 push (@make_input_list, $input);
4253 $make_list{$input} = join (':', ($local, @rest));
4257 # We have a file that automake should cause to be
4258 # rebuilt, but shouldn't generate itself.
4259 push (@other_input_files, $_);
4265 # &scan_autoconf_traces ($FILENAME)
4266 # ---------------------------------
4267 # FIXME: For the time being, we don't care about the FILENAME.
4268 sub scan_autoconf_traces
4270 my ($filename) = @_;
4272 my $traces = "$ENV{amtraces} ";
4274 $traces .= ' -t AC_CONFIG_FILES';
4275 $traces .= ' -t AC_LIBSOURCE';
4276 $traces .= ' -t AC_SUBST';
4278 my $tracefh = new IO::File ("$traces |");
4281 die "$me: couldn't open `$traces': $!\n";
4283 print "$me: reading $traces\n" if $verbose;
4285 while ($_ = $tracefh->getline)
4288 my ($file, $line, $macro, @args) = split /:/;
4289 my $here = "$file:$line";
4291 # Alphabetical ordering please.
4292 if ($macro eq 'AC_CONFIG_FILES')
4294 # Look at potential Makefile.am's.
4295 &scan_autoconf_config_files ($args[0]);
4297 elsif ($macro eq 'AC_LIBSOURCE')
4299 my $source = "$args[0].c";
4300 # We should actually also `close' the sources: getopt.c
4301 # wants getopt.h etc. But actually it should be done in the
4302 # macro itself, i.e., we have to first fix Autoconf to extend
4303 # _AC_LIBOBJ_DECL and use it the in various macros.
4304 if (!defined $libsources{$source})
4306 print STDERR "traces: discovered $source\n";
4307 $libsources{$source} = $here;
4310 elsif ($macro eq 'AC_SUBST')
4312 if (!defined $configure_vars{$args[0]})
4314 print STDERR "traces: discovered AC_SUBST($args[0])\n";
4315 $configure_vars{$args[0]} = $here;
4321 || die "$me: close: $traces: $!\n";
4325 # &scan_one_autoconf_file ($FILENAME)
4326 # -----------------------------------
4327 # Scan one file for interesting things. Subroutine of
4328 # &scan_autoconf_files.
4329 sub scan_one_autoconf_file
4331 my ($filename) = @_;
4333 my $configfh = new IO::File ("< $filename");
4336 die "$me: couldn't open `$filename': $!\n";
4338 print "$me: reading $filename\n" if $verbose;
4340 my ($in_ac_output, $in_ac_replace) = (0, 0);
4341 while ($_ = $configfh->getline)
4343 # Remove comments from current line.
4347 # Skip macro definitions. Otherwise we might be confused into
4348 # thinking that a macro that was only defined was actually
4352 # Follow includes. This is a weirdness commonly in use at
4353 # Cygnus and hopefully nowhere else.
4354 if (/sinclude\((.*)\)/ && -f $1)
4356 # $_ being local, if we don't preserve it, when coming
4357 # back we will have $_ undefined, which is bad for the
4358 # the rest of this routine.
4359 my $underscore = $_;
4360 &scan_one_autoconf_file ($1);
4364 # Populate libobjs array.
4365 if (/AC_FUNC_ALLOCA/)
4367 $libsources{'alloca.c'} = 1;
4369 elsif (/AC_FUNC_GETLOADAVG/)
4371 $libsources{'getloadavg.c'} = 1;
4373 elsif (/AC_FUNC_MEMCMP/)
4375 $libsources{'memcmp.c'} = 1;
4377 elsif (/AC_STRUCT_ST_BLOCKS/)
4379 $libsources{'fileblocks.c'} = 1;
4381 elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4383 $libsources{'getopt.c'} = 1;
4384 $libsources{'getopt1.c'} = 1;
4386 elsif (/AM_FUNC_STRTOD/)
4388 $libsources{'strtod.c'} = 1;
4390 elsif (/AM_WITH_REGEX/)
4392 $libsources{'rx.c'} = 1;
4393 $libsources{'rx.h'} = 1;
4394 $libsources{'regex.c'} = 1;
4395 $libsources{'regex.h'} = 1;
4397 elsif (/AC_FUNC_MKTIME/)
4399 $libsources{'mktime.c'} = 1;
4401 elsif (/AM_FUNC_ERROR_AT_LINE/)
4403 $libsources{'error.c'} = 1;
4404 $libsources{'error.h'} = 1;
4406 elsif (/AM_FUNC_OBSTACK/)
4408 $libsources{'obstack.c'} = 1;
4409 $libsources{'obstack.h'} = 1;
4411 elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4412 || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4414 foreach my $libobj_iter (split (' ', $1))
4416 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4417 || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4418 || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4420 $libsources{$1 . '.c'} = 1;
4424 elsif (/AC_LIBOBJ\(([^)]+)\)/)
4426 $libsources{"$1.c"} = 1;
4429 if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4435 $in_ac_replace = 0 if s/[\]\)].*$//;
4436 # Remove trailing backslash.
4440 # Need to skip empty elements for Perl 4.
4442 $libsources{$_ . '.c'} = 1;
4446 if (/$obsolete_rx/o)
4449 if ($obsolete_macros{$1} ne '')
4451 $hint = '; ' . $obsolete_macros{$1};
4453 &am_conf_line_error ($filename, $., "`$1' is obsolete$hint");
4456 # Process the AC_OUTPUT and AC_CONFIG_FILES macros.
4457 if (! $in_ac_output && s/AC_(OUTPUT|CONFIG_FILES)\s*\(\[?//)
4460 $ac_output_line = $.;
4471 # Look at potential Makefile.am's.
4472 &scan_autoconf_config_files ($_);
4474 if ($closing && @make_input_list == 0 && @other_input_files == 0)
4476 &am_conf_line_error ($filename, $ac_output_line,
4477 "No files mentioned in `AC_OUTPUT'");
4482 if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4484 @config_aux_path = &unquote_m4_arg ($1);
4485 $config_aux_dir_set_in_configure_in = 1;
4488 # Check for ansi2knr.
4489 $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4491 # Check for exe extension stuff.
4495 $configure_vars{'EXEEXT'} = $filename . ':' . $.;
4501 $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4504 # Check for `-c -o' code.
4505 $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4507 # Check for NLS support.
4508 if (/AM_GNU_GETTEXT/)
4511 $ac_gettext_line = $.;
4514 # Look for ALL_LINGUAS.
4515 if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4519 $all_linguas_line = $.;
4522 # Handle configuration headers. A config header of `[$1]'
4523 # means we are actually scanning AM_CONFIG_HEADER from
4525 if (/A([CM])_CONFIG_HEADERS?\s*\((.*)\)/
4529 ($filename, $., "`automake requires `AM_CONFIG_HEADER', not `AC_CONFIG_HEADER'")
4532 $config_header_line = $.;
4533 foreach my $one_hdr (split (' ', &unquote_m4_arg ($2)))
4535 push (@config_fullnames, $one_hdr);
4536 if ($one_hdr =~ /^([^:]+):(.+)$/)
4538 push (@config_names, $1);
4539 push (@config_headers, $2);
4543 push (@config_names, $one_hdr);
4544 push (@config_headers, $one_hdr . '.in');
4549 # Handle AC_CANONICAL_*. Always allow upgrading to
4550 # AC_CANONICAL_SYSTEM, but never downgrading.
4551 $seen_canonical = $AC_CANONICAL_HOST
4552 if ! $seen_canonical
4553 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4554 $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4556 # If using X, include some extra variable definitions. NOTE
4557 # we don't want to force these into CFLAGS or anything,
4558 # because not all programs will necessarily use X.
4561 foreach my $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS',
4564 $configure_vars{$var} = $filename . ':' . $.
4568 # This macro handles several different things.
4569 if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4571 ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4572 $package_version_line = $.;
4573 $seen_init_automake = 1;
4578 $configure_vars{'LEX'} = $filename . ':' . $.;
4579 $seen_decl_yytext = 1;
4581 if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.(ac|in)$/)
4583 &am_conf_line_warning ($filename, $., "`AC_DECL_YYTEXT' is covered by `AM_PROG_LEX'");
4585 if (/AC_PROG_LEX/ && $filename =~ /configure\.(ac|in)$/)
4587 &am_conf_line_warning ($filename, $., "automake requires `AM_PROG_LEX', not `AC_PROG_LEX'");
4590 if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4592 $configure_vars{$1} = $filename . ':' . $.;
4594 if (/$AC_CHECK_PATTERN/o)
4596 $configure_vars{$3} = $filename . ':' . $.;
4598 if (/$AM_MISSING_PATTERN/o
4602 && $1 ne 'AUTOHEADER'
4603 # AM_INIT_AUTOMAKE is AM_MISSING_PROG'ing MAKEINFO. But
4604 # we handle it elsewhere.
4605 && $1 ne 'MAKEINFO')
4607 $configure_vars{$1} = $filename . ':' . $.;
4610 # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4611 # but later define it elsewhere. This is pretty hacky. We
4612 # also explicitly avoid INSTALL_SCRIPT and some other
4613 # variables because they are defined in header-vars.am.
4615 if (/$AC_SUBST_PATTERN/o
4617 && $1 ne 'INSTALL_SCRIPT'
4618 && $1 ne 'INSTALL_DATA')
4620 $configure_vars{$1} = $filename . ':' . $.;
4623 $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4624 if (/AM_MAINTAINER_MODE/)
4626 $seen_maint_mode = 1;
4627 $configure_cond{'MAINTAINER_MODE'} = 1;
4630 $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4632 if (/AM_PATH_PYTHON/)
4634 $seen_pythondir = 1;
4635 $configure_vars{'pythondir'} = $filename . ':' . $.;
4636 $configure_vars{'PYTHON'} = $filename . ':' . $.;
4639 if (/A(C|M)_PROG_LIBTOOL/)
4641 # We're not ready for this yet. People still use a
4642 # libtool with no AC_PROG_LIBTOOL. Once that is the
4643 # dominant version we can reenable this code -- but next
4644 # time by mentioning the macro in %obsolete_macros, both
4645 # here and in aclocal.in.
4647 # if (/AM_PROG_LIBTOOL/)
4649 # &am_conf_line_warning ($filename, $., "`AM_PROG_LIBTOOL' is obsolete, use `AC_PROG_LIBTOOL' instead");
4653 $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4654 $configure_vars{'RANLIB'} = $filename . ':' . $.;
4655 $configure_vars{'CC'} = $filename . ':' . $.;
4656 # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST. Make sure we
4657 # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4658 $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4661 $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4663 if (/$AM_CONDITIONAL_PATTERN/o)
4665 $configure_cond{$1} = 1;
4668 # Check for Fortran 77 intrinsic and run-time libraries.
4669 if (/AC_F77_LIBRARY_LDFLAGS/)
4671 $configure_vars{'FLIBS'} = $filename . ':' . $.;
4679 # &scan_autoconf_files ()
4680 # -----------------------
4681 # Check whether we use `configure.ac' or `configure.in'.
4682 # Scan it (and possibly `aclocal.m4') for interesting things.
4683 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
4684 sub scan_autoconf_files
4686 # Reinitialize libsources here. This isn't really necessary,
4687 # since we currently assume there is only one configure.ac. But
4688 # that won't always be the case.
4691 warn "$me: both `configure.ac' and `configure.in' present:"
4692 . " ignoring `configure.in'\n"
4693 if -f 'configure.ac' && -f 'configure.in';
4694 $configure_ac = 'configure.in'
4695 if -f 'configure.in';
4696 $configure_ac = 'configure.ac'
4697 if -f 'configure.ac';
4698 die "$me: `configure.ac' or `configure.in' is required\n"
4701 &scan_one_autoconf_file ($configure_ac);
4702 &scan_one_autoconf_file ('aclocal.m4')
4705 if (defined $ENV{'amtraces'})
4707 warn '$me: Autoconf traces is an experimental feature';
4708 warn '$me: use at your own risks';
4710 &scan_autoconf_traces ($configure_ac);
4713 # Set input and output files if not specified by user.
4716 @input_files = @make_input_list;
4717 %output_files = %make_list;
4720 @configure_input_files = @make_input_list;
4722 &am_conf_error ("`AM_INIT_AUTOMAKE' must be used")
4723 if ! $seen_init_automake;
4725 # Look for some files we need. Always check for these. This
4726 # check must be done for every run, even those where we are only
4727 # looking at a subdir Makefile. We must set relative_dir so that
4728 # the file-finding machinery works.
4729 # FIXME: Is this broken because it needs dynamic scopes.
4730 # My tests seems to show it's not the case.
4731 $relative_dir = '.';
4732 &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4733 &am_error ("`install.sh' is an anachronism; use `install-sh' instead")
4734 if -f $config_aux_path[0] . '/install.sh';
4736 &require_config_file ($FOREIGN, 'py-compile')
4739 # Preserve dist_common for later.
4740 $configure_dist_common = variable_value ('DIST_COMMON', 'TRUE') || '';
4743 ################################################################
4745 # Set up for Cygnus mode.
4748 return unless $cygnus_mode;
4750 &set_strictness ('foreign');
4751 $options{'no-installinfo'} = 1;
4752 $options{'no-dependencies'} = 1;
4753 $use_dependencies = 0;
4755 if (! $seen_maint_mode)
4757 &am_conf_error ("`AM_MAINTAINER_MODE' required when --cygnus specified");
4761 # Do any extra checking for GNU standards.
4762 sub check_gnu_standards
4764 if ($relative_dir eq '.')
4766 # In top level (or only) directory.
4767 &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4768 'AUTHORS', 'ChangeLog');
4771 if ($strictness >= $GNU
4772 && defined $options{'no-installman'})
4774 &am_line_error ('AUTOMAKE_OPTIONS',
4775 "option `no-installman' disallowed by GNU standards");
4778 if ($strictness >= $GNU
4779 && defined $options{'no-installinfo'})
4781 &am_line_error ('AUTOMAKE_OPTIONS',
4782 "option `no-installinfo' disallowed by GNU standards");
4786 # Do any extra checking for GNITS standards.
4787 sub check_gnits_standards
4789 if ($relative_dir eq '.')
4791 # In top level (or only) directory.
4792 &require_file ($GNITS, 'THANKS');
4796 ################################################################
4798 # Functions to handle files of each language.
4800 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
4801 # simple formula: Return value is $LANG_SUBDIR if the resulting object
4802 # file should be in a subdir if the source file is, $LANG_PROCESS if
4803 # file is to be dealt with, $LANG_IGNORE otherwise.
4805 # Much of the actual processing is handled in
4806 # handle_single_transform_list. These functions exist so that
4807 # auxiliary information can be recorded for a later cleanup pass.
4808 # Note that the calls to these functions are computed, so don't bother
4809 # searching for their precise names in the source.
4811 # This is just a convenience function that can be used to determine
4812 # when a subdir object should be used.
4815 return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4818 # Rewrite a single C source file.
4821 my ($directory, $base, $ext) = @_;
4823 if (defined $options{'ansi2knr'} && $base =~ /_$/)
4825 # FIXME: include line number in error.
4826 &am_error ("C source file `$base.c' would be deleted by ansi2knr rules");
4829 my $r = $LANG_PROCESS;
4830 if (defined $options{'subdir-objects'})
4833 $base = $directory . '/' . $base;
4837 # Only give error once.
4839 # FIXME: line number.
4840 &am_error ("C objects in subdir but `AM_PROG_CC_C_O' not in `$configure_ac'");
4843 &require_file ($FOREIGN, 'compile')
4844 if $relative_dir eq '.';
4847 $de_ansi_files{$base} = 1;
4851 # Rewrite a single C++ source file.
4852 sub lang_cxx_rewrite
4854 return &lang_sub_obj;
4857 # Rewrite a single header file.
4858 sub lang_header_rewrite
4860 # Header files are simply ignored.
4861 return $LANG_IGNORE;
4864 # Rewrite a single yacc file.
4865 sub lang_yacc_rewrite
4867 my ($directory, $base, $ext) = @_;
4869 my $r = &lang_c_rewrite ($directory, $base, $ext);
4871 if ($r == $LANG_SUBDIR)
4873 $pfx = $directory . '/';
4875 $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4877 &saw_extension ('c');
4879 &push_dist_common ($pfx . $base . '.' . $ext);
4883 # Rewrite a single yacc++ file.
4884 sub lang_yaccxx_rewrite
4886 my ($directory, $base, $ext) = @_;
4888 my $r = $LANG_PROCESS;
4890 if (defined $options{'subdir-objects'})
4892 $pfx = $directory . '/';
4895 $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4897 &saw_extension ($ext);
4899 &push_dist_common ($pfx . $base . '.' . $ext);
4903 # Rewrite a single lex file.
4904 sub lang_lex_rewrite
4906 my ($directory, $base, $ext) = @_;
4908 my $r = &lang_c_rewrite ($directory, $base, $ext);
4910 if ($r == $LANG_SUBDIR)
4912 $pfx = $directory . '/';
4914 $lex_sources{$pfx . $base . '.' . $ext} = 1;
4916 &saw_extension ('c');
4918 &push_dist_common ($pfx . $base . '.' . $ext);
4922 # Rewrite a single lex++ file.
4923 sub lang_lexxx_rewrite
4925 my ($directory, $base, $ext) = @_;
4927 my $r = $LANG_PROCESS;
4929 if (defined $options{'subdir-objects'})
4931 $pfx = $directory . '/';
4934 $lex_sources{$pfx . $base . '.' . $ext} = 1;
4936 &saw_extension ($ext);
4938 &push_dist_common ($pfx . $base . '.' . $ext);
4942 # Rewrite a single assembly file.
4943 sub lang_asm_rewrite
4945 return &lang_sub_obj;
4948 # Rewrite a single Fortran 77 file.
4949 sub lang_f77_rewrite
4951 return $LANG_PROCESS;
4954 # Rewrite a single preprocessed Fortran 77 file.
4955 sub lang_ppf77_rewrite
4957 return $LANG_PROCESS;
4960 # Rewrite a single ratfor file.
4961 sub lang_ratfor_rewrite
4963 return $LANG_PROCESS;
4966 # Rewrite a single Objective C file.
4967 sub lang_objc_rewrite
4969 return &lang_sub_obj;
4972 # Rewrite a single Java file.
4973 sub lang_java_rewrite
4975 return $LANG_SUBDIR;
4978 # The lang_X_finish functions are called after all source file
4979 # processing is done. Each should handle defining rules for the
4980 # language, etc. A finish function is only called if a source file of
4981 # the appropriate type has been seen.
4985 # Push all libobjs files onto de_ansi_files. We actually only
4986 # push files which exist in the current directory, and which are
4987 # genuine source files.
4988 foreach my $file (keys %libsources)
4990 if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
4992 $de_ansi_files{$1} = 1;
4996 if (defined $options{'ansi2knr'} && keys %de_ansi_files)
4998 # Make all _.c files depend on their corresponding .c files.
5000 foreach my $base (sort keys %de_ansi_files)
5002 # Each _.c file must depend on ansi2knr; otherwise it
5003 # might be used in a parallel build before it is built.
5004 # We need to support files in the srcdir and in the build
5005 # dir (because these files might be auto-generated. But
5006 # we can't use $< -- some makes only define $< during a
5008 $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
5009 . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5010 . '`if test -f $(srcdir)/' . $base . '.c'
5011 . '; then echo $(srcdir)/' . $base . '.c'
5012 . '; else echo ' . $base . '.c; fi` '
5013 . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5014 . '| $(ANSI2KNR) > ' . $base . "_.c"
5015 # If ansi2knr fails then we shouldn't
5016 # create the _.c file
5017 . " || rm -f ${base}_.c\n");
5018 push (@objects, $base . '_.$(OBJEXT)');
5019 push (@objects, $base . '_.lo')
5023 # Make all _.o (and _.lo) files depend on ansi2knr.
5024 # Use a sneaky little hack to make it print nicely.
5025 &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5030 # This is a helper for both lex and yacc.
5031 sub yacc_lex_finish_helper
5033 return if defined $language_scratch{'lex-yacc-done'};
5034 $language_scratch{'lex-yacc-done'} = 1;
5036 # If there is more than one distinct yacc (resp lex) source file
5037 # in a given directory, then the `ylwrap' program is required to
5038 # allow parallel builds to work correctly. FIXME: for now, no
5040 &require_config_file ($FOREIGN, 'ylwrap');
5041 if ($config_aux_dir_set_in_configure_in)
5043 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5047 &define_variable ('YLWRAP', '$(top_srcdir)/ylwrap');
5051 sub lang_yacc_finish
5053 return if defined $language_scratch{'yacc-done'};
5054 $language_scratch{'yacc-done'} = 1;
5056 my %seen_suffix = ();
5057 my @yacc_files = sort keys %yacc_sources;
5058 my $yacc_count = scalar (@yacc_files);
5059 foreach my $file (@yacc_files)
5062 &output_yacc_build_rule ($1, $yacc_count > 1)
5063 if ! defined $seen_suffix{$1};
5064 $seen_suffix{$1} = 1;
5066 $file =~ /^(.*)\.(y|yy|y\+\+|yxx|ypp)$/;
5068 my $hname = 'h'; # Always use `.h' for header file.
5072 if ((&variable_defined ('AM_YFLAGS')
5073 && &variable_value ('AM_YFLAGS') =~ /(^|\s)-d(\s|$)/)
5074 || (&variable_defined ('YFLAGS')
5075 && &variable_value ('YFLAGS') =~ /(^|\s)-d(\s|$)/)) {
5076 # Now generate rule to make the header file. This should only
5077 # be generated if `yacc -d' specified.
5078 $output_rules .= "${base}.${hname}: ${base}.${cname}\n";
5080 # If the files are built in the build directory, then we want
5081 # to remove them with `make clean'. If they are in srcdir
5082 # they shouldn't be touched. However, we can't determine this
5083 # statically, and the GNU rules say that yacc/lex output files
5084 # should be removed by maintainer-clean. So that's what we
5086 push (@maintainer_clean_files, "${base}.${hname}");
5088 &push_dist_common ("${base}.${hname}");
5090 push (@maintainer_clean_files, "${base}.${cname}");
5092 $output_rules .= "\n";
5094 if (&variable_defined ('YACCFLAGS'))
5096 &am_line_error ('YACCFLAGS',
5097 "`YACCFLAGS' obsolete; use `YFLAGS' instead");
5100 if ($yacc_count > 1)
5102 &yacc_lex_finish_helper;
5109 return if defined $language_scratch{'lex-done'};
5110 $language_scratch{'lex-done'} = 1;
5112 my %seen_suffix = ();
5113 my $lex_count = scalar (keys %lex_sources);
5114 foreach my $file (sort keys %lex_sources)
5117 &output_lex_build_rule ($1, $lex_count > 1)
5118 if (! defined $seen_suffix{$1});
5119 $seen_suffix{$1} = 1;
5121 # If the files are built in the build directory, then we want
5122 # to remove them with `make clean'. If they are in srcdir
5123 # they shouldn't be touched. However, we can't determine this
5124 # statically, and the GNU rules say that yacc/lex output files
5125 # should be removed by maintainer-clean. So that's what we
5127 $file =~ /^(.*)\.(l|ll|l\+\+|lxx|lpp)$/;
5129 ($cname = $2) =~ tr/l/c/;
5130 push (@maintainer_clean_files, "${1}.${cname}");
5133 if (! $seen_decl_yytext)
5135 &am_error ("lex source seen but `AC_DECL_YYTEXT' not in `$configure_ac'");
5140 &yacc_lex_finish_helper;
5145 # Given a hash table of linker names, pick the name that has the most
5146 # precedence. This is lame, but something has to have global
5147 # knowledge in order to eliminate the conflict. Add more linkers as
5154 if defined $linkers{'GCJLINK'};
5156 if defined $linkers{'CXXLINK'};
5158 if defined $linkers{'F77LINK'};
5160 if defined $linkers{'OBJCLINK'};
5164 # Called to indicate that an extension was used.
5168 $extension_seen{$ext} = 1;
5171 # Called to ask whether source files have been seen . If HEADERS is 1,
5172 # headers can be included.
5183 $headers = grep ($extension_seen{$_},
5184 @{$languages{'header'}->extensions});
5187 return scalar keys %extension_seen > $headers;
5191 # register_language (%ATTRIBUTE)
5192 # ------------------------------
5193 # Register a single language.
5194 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5195 sub register_language (%)
5201 unless defined $option{'ansi'};
5202 $option{'autodep'} = 'no'
5203 unless defined $option{'autodep'};
5204 $option{'derived_autodep'} = 'no'
5205 unless defined $option{'derived_autodep'};
5206 $option{'linker'} = ''
5207 unless defined $option{'linker'};
5209 my $lang = new Language (%option);
5212 grep ($extension_map{$_} = $lang->name, @{$lang->extensions});
5213 $languages{$lang->name} = $lang;
5216 # This function is used to find a path from a user-specified suffix to
5217 # `o' or to some other suffix we recognize internally, eg `cc'.
5220 my ($source_ext) = @_;
5222 # FIXME: hard-coding `o' is a mistake. Doing something
5223 # intelligent is harder.
5224 while (! $extension_map{$source_ext}
5225 && $source_ext ne 'o'
5226 && defined $suffix_rules{$source_ext})
5228 $source_ext = $suffix_rules{$source_ext};
5235 ################################################################
5237 # Pretty-print something. HEAD is what should be printed at the
5238 # beginning of the first line, FILL is what should be printed at the
5239 # beginning of every subsequent line.
5240 sub pretty_print_internal
5242 my ($head, $fill, @values) = @_;
5244 my $column = length ($head);
5247 # Fill length is number of characters. However, each Tab
5248 # character counts for eight. So we count the number of Tabs and
5250 my $fill_length = length ($fill);
5251 $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5255 # "71" because we also print a space.
5256 if ($column + length ($_) > 71)
5258 $result .= " \\\n" . $fill;
5259 $column = $fill_length;
5261 $result .= ' ' if $result =~ /\S\z/;
5263 $column += length ($_) + 1;
5270 # Pretty-print something and append to output_vars.
5273 $output_vars .= &pretty_print_internal (@_);
5276 # Pretty-print something and append to output_rules.
5277 sub pretty_print_rule
5279 $output_rules .= &pretty_print_internal (@_);
5283 ################################################################
5287 # &conditional_string(@COND-STACK)
5288 # --------------------------------
5289 # Build a string which denotes the conditional in @COND-STACK. Some
5290 # simplifications are done: `TRUE' entries are elided, and any `FALSE'
5291 # entry results in a return of `FALSE'.
5292 sub conditional_string
5296 if (grep (/^FALSE$/, @stack))
5302 return join (' ', uniq sort grep (!/^TRUE$/, @stack));
5308 # &conditional_true_when ($COND, $WHEN)
5309 # -------------------------------------
5310 # See if a conditional is true. Both arguments are conditional
5311 # strings. This returns true if the first conditional is true when
5312 # the second conditional is true.
5313 # For instance with $COND = `BAR FOO', and $WHEN = `BAR BAZ FOO',
5314 # obviously return 1, and 0 when, for instance, $WHEN = `FOO'.
5315 sub conditional_true_when ($$)
5317 my ($cond, $when) = @_;
5319 # Make a hash holding all the values from $WHEN.
5320 my %cond_vals = map { $_ => 1 } split (' ', $when);
5322 # Check each component of $cond, which looks `COND1 COND2'.
5323 foreach my $comp (split (' ', $cond))
5325 # TRUE is always true.
5326 next if $comp eq 'TRUE';
5327 return 0 if ! defined $cond_vals{$comp};
5335 # &conditionals_true_when (@CONDS, @WHENS)
5336 # ----------------------------------------
5337 # Same as above, but true if all the @CONDS are true when *ALL*
5338 # the @WHENS are sufficient.
5340 # If there are no @CONDS, then return true, of course. *BUT*, even if there
5341 # are @CONDS but @WHENS is empty, return true. This is counter intuitive,
5342 # and against all the rules of logic, but is needed by the current code.
5343 # FIXME: Do something saner when the logic of conditionals is understood.
5344 sub conditionals_true_when (@@)
5346 my (@conds, @whens) = @_;
5348 foreach my $cond (@conds)
5350 foreach my $when (@whens)
5353 unless conditional_true_when ($cond, $when);
5362 # condition_negate ($COND)
5363 # ------------------------
5364 sub condition_negate ($)
5368 $cond =~ s/TRUE$/TRUEO/;
5369 $cond =~ s/FALSE$/TRUE/;
5370 $cond =~ s/TRUEO$/FALSE/;
5376 # Compare condition names.
5377 # Issue them in alphabetical order, foo_TRUE before foo_FALSE.
5380 # Be careful we might be comparing `' or `#'.
5381 $a =~ /^(.*)_(TRUE|FALSE)$/;
5382 my ($aname, $abool) = ($1 || '', $2 || '');
5383 $b =~ /^(.*)_(TRUE|FALSE)$/;
5384 my ($bname, $bbool) = ($1 || '', $2 || '');
5385 return ($aname cmp $bname
5386 # Don't bother with IFs, given that TRUE is after FALSE
5387 # just cmp in the reverse order.
5388 || $bbool cmp $abool
5394 # &make_condition (@CONDITIONS)
5395 # -----------------------------
5396 # Transform a list of conditions (themselves can be an internal list
5397 # of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
5398 # Make conditional (a pattern for AC_SUBST).
5399 # Correctly returns the empty string when there are no conditions.
5402 my $res = conditional_string (@_);
5404 # There are no conditions.
5410 elsif ($res eq 'FALSE')
5417 $res = '@' . $res . '@';
5426 ## ------------------------------ ##
5427 ## Handling the condition stack. ##
5428 ## ------------------------------ ##
5432 # cond_stack_if ($NEGATE, $COND, $WHERE)
5433 # --------------------------------------
5434 sub cond_stack_if ($$$)
5436 my ($negate, $cond, $where) = @_;
5438 &am_file_error ($where, "$cond does not appear in AM_CONDITIONAL")
5439 if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
5441 $cond = "${cond}_TRUE"
5442 unless $cond =~ /^TRUE|FALSE$/;
5443 $cond = condition_negate ($cond)
5446 push (@cond_stack, $cond);
5448 return conditional_string (@cond_stack);
5453 # cond_stack_else ($NEGATE, $COND, $WHERE)
5454 # ----------------------------------------
5455 sub cond_stack_else ($$$)
5457 my ($negate, $cond, $where) = @_;
5461 &am_file_error ($where, "else without if");
5465 $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);
5467 # If $COND is given, check against it.
5470 $cond = "${cond}_TRUE"
5471 unless $cond =~ /^TRUE|FALSE$/;
5472 $cond = condition_negate ($cond)
5475 &am_file_error ($where,
5476 "else reminder ($negate$cond) incompatible with "
5477 . "current conditional: $cond_stack[$#cond_stack]")
5478 if $cond_stack[$#cond_stack] ne $cond;
5481 return conditional_string (@cond_stack);
5486 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5487 # -----------------------------------------
5488 sub cond_stack_endif ($$$)
5490 my ($negate, $cond, $where) = @_;
5495 &am_file_error ($where, "endif without if: $negate$cond");
5500 # If $COND is given, check against it.
5503 $cond = "${cond}_TRUE"
5504 unless $cond =~ /^TRUE|FALSE$/;
5505 $cond = condition_negate ($cond)
5508 &am_file_error ($where,
5509 "endif reminder ($negate$cond) incompatible with "
5510 . "current conditional: $cond_stack[$#cond_stack]")
5511 if $cond_stack[$#cond_stack] ne $cond;
5516 return conditional_string (@cond_stack);
5523 ## ------------------------ ##
5524 ## Handling the variables. ##
5525 ## ------------------------ ##
5528 # check_ambiguous_conditional ($VAR, $COND)
5529 # -----------------------------------------
5530 # Check for an ambiguous conditional. This is called when a variable
5531 # is being defined conditionally. If we already know about a
5532 # definition that is true under the same conditions, then we have an
5534 sub check_ambiguous_conditional ($$)
5536 my ($var, $cond) = @_;
5537 foreach my $vcond (keys %{$var_value{$var}})
5540 if ($vcond eq $cond)
5542 $message = "$var multiply defined in condition $cond";
5544 elsif (&conditional_true_when ($vcond, $cond))
5546 $message = ("$var was already defined in condition $vcond, "
5547 . "which implies condition $cond");
5549 elsif (&conditional_true_when ($cond, $vcond))
5551 $message = ("$var was already defined in condition $vcond, "
5552 . "which is implied by condition $cond");
5556 &am_line_error ($var, $message);
5563 # ¯o_define($VAR, $VAR_IS_AM, $TYPE, $COND, $VALUE, $WHERE)
5564 # -------------------------------------------------------------
5565 # The $VAR can go from Automake to user, but not the converse.
5566 sub macro_define ($$$$$$)
5568 my ($var, $var_is_am, $type, $cond, $value, $where) = @_;
5570 am_file_error ($where, "bad macro name `$var'")
5571 if $var !~ /$MACRO_PATTERN/o;
5575 # An Automake variable must be consistently defined with the same
5576 # sign by Automake. A user variable must be set by either `=' or
5577 # `:=', and later promoted to `+='.
5580 if (defined $var_type{$var} && $var_type{$var} ne $type)
5582 am_line_error ($var,
5583 ("$var was set with `$var_type{$var}=' "
5584 . "and is now set with `$type='"));
5589 if (!defined $var_type{$var} && $type eq '+')
5591 am_line_error ($var, "$var must be set with `=' before using `+='");
5594 $var_type{$var} = $type;
5596 # When adding, since we rewrite, don't try to preserve the
5597 # Automake continuation backslashes.
5599 if $type eq '+' && $var_is_am;
5601 # Differentiate the first assignment (including with `+=').
5602 if ($type eq '+' && defined $var_value{$var}{$cond})
5604 if (substr ($var_value{$var}{$cond}, -1) eq "\n")
5606 # Insert a backslash before a trailing newline.
5607 $var_value{$var}{$cond} =
5608 substr ($var_value{$var}{$cond}, 0, -1) . "\\\n";
5610 elsif ($var_value{$var}{$cond})
5612 # Insert a separator.
5613 $var_value{$var}{$cond} .= ' ';
5615 $var_value{$var}{$cond} .= $value;
5619 # The first assignment to a macro sets the line number. Ideally I
5620 # suppose we would associate line numbers with random bits of text.
5621 # FIXME: We sometimes redefine some variables, but we want to keep
5622 # the original location. More subs are needed to handle
5623 # properly variables. Once this done, remove this hack.
5624 $var_line{$var} = $where
5625 unless defined $var_line{$var};
5627 # If Automake tries to override a value specified by the user,
5628 # just don't let it do.
5629 if (defined $var_value{$var}{$cond} && !$var_is_am{$var} && $var_is_am)
5633 print STDERR "$me: refusing to override the user definition of:\n";
5635 print STDERR "$me: with `$cond' => `$value'\n";
5640 # There must be no previous value unless the user is redefining
5641 # an Automake variable or an AC_SUBST variable.
5642 check_ambiguous_conditional ($var, $cond)
5643 unless ($var_is_am{$var} && !$var_is_am
5644 || exists $configure_vars{$var});
5646 $var_value{$var}{$cond} = $value;
5650 # An Automake variable can be given to the user, but not the converse.
5651 if (! defined $var_is_am{$var} || !$var_is_am)
5653 $var_is_am{$var} = $var_is_am;
5658 # &variable_delete ($VAR, [@CONDS])
5659 # ---------------------------------
5660 # Forget about $VAR under the conditions @CONDS, or completely if
5662 sub variable_delete ($@)
5664 my ($var, @conds) = @_;
5668 delete $var_value{$var};
5669 delete $var_line{$var};
5670 delete $var_is_am{$var};
5671 delete $var_comment{$var};
5672 delete $var_type{$var};
5676 foreach my $cond (@conds)
5678 delete $var_value{$var}{$cond};
5684 # ¯o_dump ($VAR)
5685 # ------------------
5690 if (!exists $var_value{$var})
5692 print STDERR " $var does not exist\n";
5696 my $var_is_am = $var_is_am{$var} ? "Automake" : "User";
5697 my $where = (defined $var_line{$var}
5698 ? $var_line{$var} : "undefined");
5699 print STDERR "$var_comment{$var}"
5700 if defined $var_comment{$var};
5701 print STDERR " $var ($var_is_am, where = $where) $var_type{$var}=\n";
5702 print STDERR " {\n";
5703 foreach my $vcond (sort by_condition keys %{$var_value{$var}})
5705 print STDERR " $vcond => $var_value{$var}{$vcond}\n";
5707 print STDERR " }\n";
5718 print STDERR "%var_value =\n";
5720 foreach my $var (sort (keys %var_value))
5729 # &variable_defined ($VAR, [$COND])
5730 # ---------------------------------
5731 # See if a variable exists. $VAR is the variable name, and $COND is
5732 # the condition which we should check. If no condition is given, we
5733 # currently return true if the variable is defined under any
5735 sub variable_defined ($$)
5737 my ($var, $cond) = @_;
5739 # Unfortunately we can't just check for $var_value{VAR}{COND}
5740 # as this would make perl create $condition{VAR}, which we
5742 if (!exists $var_value{$var})
5744 if (defined $targets{$var})
5746 &am_line_error ($var, "`$var' is a target; expected a variable")
5748 # The variable is not defined
5752 if ($cond && !exists $var_value{$var}{$cond})
5754 # The variable is not defined for the given condition.
5758 # Even a var_value examination is good enough for us. FIXME:
5759 # really should maintain examined status on a per-condition basis.
5760 $content_seen{$var} = 1;
5764 # Mark a variable as examined.
5765 sub examine_variable
5768 &variable_defined ($var);
5771 # Return the set of conditions for which a variable is defined.
5773 # If the variable is not defined conditionally, and is not defined in
5774 # terms of any variables which are defined conditionally, then this
5775 # returns the empty list.
5777 # If the variable is defined conditionally, but is not defined in
5778 # terms of any variables which are defined conditionally, then this
5779 # returns the list of conditions for which the variable is defined.
5781 # If the variable is defined in terms of any variables which are
5782 # defined conditionally, then this returns a full set of permutations
5783 # of the subvariable conditions. For example, if the variable is
5784 # defined in terms of a variable which is defined for COND_TRUE,
5785 # then this returns both COND_TRUE and COND_FALSE. This is
5786 # because we will need to define the variable under both conditions.
5788 sub variable_conditions ($)
5796 my @new_conds = &variable_conditions_sub ($var, '', ());
5797 # Now we want to return all permutations of the subvariable
5800 foreach my $item (@new_conds)
5802 foreach (split (' ', $item))
5804 s/^(.*)_(TRUE|FALSE)$/$1_TRUE/;
5808 @new_conds = &variable_conditions_permutations (sort keys %allconds);
5810 foreach my $cond (@new_conds)
5812 my $reduce = &variable_conditions_reduce (split (' ', $cond));
5814 if $reduce eq 'FALSE';
5815 $uniqify{$cond} = 1;
5818 @uniq_list = sort by_condition keys %uniqify;
5819 # Note we cannot just do `return sort keys %uniqify', because this
5820 # function is sometimes used in a scalar context.
5826 # &variable_conditionally_defined ($VAR)
5827 # --------------------------------------
5828 sub variable_conditionally_defined ($)
5831 foreach my $cond (variable_conditions ($var))
5834 unless $cond =~ /^TRUE|FALSE$/;
5841 # &variable_conditions_sub ($VAR, $PARENT, @PARENT_CONDS)
5842 # -------------------------------------------------------
5843 # A subroutine of variable_conditions. This returns all the
5844 # conditions of $VAR which are satisfiable when all of @PARENT_CONDS
5846 sub variable_conditions_sub
5848 my ($var, $parent, @parent_conds) = @_;
5851 if (defined $vars_scanned{$var})
5853 &am_line_error ($parent, "variable `$var' recursively defined");
5856 $vars_scanned{$var} = 1;
5858 my @this_conds = ();
5859 # Examine every condition under which $VAR is defined.
5860 foreach my $vcond (keys %{$var_value{$var}})
5862 # If this condition cannot be true when the parent conditions
5863 # are true, then skip it.
5865 if ! conditionals_true_when ((@parent_conds), ($vcond));
5867 push (@this_conds, $vcond);
5869 # If $VAR references some other variable, then compute the
5870 # conditions for that subvariable.
5871 push (@parent_conds, $vcond);
5872 my @subvar_conds = ();
5873 foreach (split (' ', $var_value{$var}{$vcond}))
5875 # If a comment seen, just leave.
5878 # Handle variable substitutions.
5879 if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5882 # Here we compute all the conditions under which the
5883 # subvariable is defined. Then we go through and add
5885 my @svc = &variable_conditions_sub ($1, $var, @parent_conds);
5886 foreach my $item (@svc)
5888 my $val = conditional_string ($vcond, split (' ', $item));
5890 push (@subvar_conds, $val);
5894 pop (@parent_conds);
5896 # If there are no conditional subvariables, then we want to
5897 # return this condition. Otherwise, we want to return the
5898 # permutations of the subvariables, taking into account the
5899 # conditions of $VAR.
5900 if (! @subvar_conds)
5902 push (@new_conds, $vcond);
5906 push (@new_conds, &variable_conditions_reduce (@subvar_conds));
5910 # Unset our entry in vars_scanned. We only care about recursive
5912 delete $vars_scanned{$var};
5914 # If we are being called on behalf of another variable, we need to
5915 # return all possible permutations of the conditions. We have
5916 # already handled everything in @this_conds along with their
5917 # subvariables. We now need to add any permutations that are not
5919 foreach my $this_cond (@this_conds)
5922 &variable_conditions_permutations (split(' ', $this_cond));
5923 foreach my $perm (@perms)
5926 foreach my $scan (@this_conds)
5928 if (&conditional_true_when ($perm, $scan)
5929 || &conditional_true_when ($scan, $perm))
5938 if ! conditionals_true_when ((@parent_conds), ($perm));
5940 # This permutation was not already handled, and is valid
5942 push (@new_conds, $perm);
5950 # Filter a list of conditionals so that only the exclusive ones are
5951 # retained. For example, if both `COND1_TRUE COND2_TRUE' and
5952 # `COND1_TRUE' are in the list, discard the latter.
5953 sub variable_conditions_reduce
5957 foreach my $cond (@conds)
5959 # FALSE is absorbent.
5960 if ($cond eq 'FALSE')
5964 elsif (conditionals_true_when (($cond), (@ret)))
5973 # Return a list of permutations of a conditional string.
5974 sub variable_conditions_permutations
5979 my $comp = shift (@comps);
5980 return &variable_conditions_permutations (@comps)
5982 my $neg = condition_negate ($comp);
5985 foreach my $sub (&variable_conditions_permutations (@comps))
5987 push (@ret, "$comp $sub");
5988 push (@ret, "$neg $sub");
6000 # &check_variable_defined_unconditionally($VAR, $PARENT)
6001 # ------------------------------------------------------
6002 # Warn if a variable is conditionally defined. This is called if we
6003 # are using the value of a variable.
6004 sub check_variable_defined_unconditionally ($$)
6006 my ($var, $parent) = @_;
6007 foreach my $cond (keys %{$var_value{$var}})
6010 if $cond =~ /^TRUE|FALSE$/;
6014 &am_line_error ($parent,
6015 "warning: automake does not support conditional definition of $var in $parent");
6019 &am_line_error ($parent,
6020 "warning: automake does not support $var being defined conditionally");
6028 # Get the TRUE value of a variable, warn if the variable is
6029 # conditionally defined.
6033 &check_variable_defined_unconditionally ($var);
6034 return $var_value{$var}{'TRUE'};
6039 # &value_to_list ($VAR, $VAL, $COND)
6040 # ----------------------------------
6041 # Convert a variable value to a list, split as whitespace. This will
6042 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6045 # If COND is 'all', then all values under all conditions should be
6046 # returned; if COND is a particular condition (all conditions are
6047 # surrounded by @...@) then only the value for that condition should
6048 # be returned; otherwise, warn if VAR is conditionally defined.
6049 # SCANNED is a global hash listing whose keys are all the variables
6050 # already scanned; it is an error to rescan a variable.
6053 my ($var, $val, $cond) = @_;
6057 $val =~ s/\\(\n|$)/ /g;
6059 foreach (split (' ', $val))
6061 # If a comment seen, just leave.
6064 # Handle variable substitutions.
6065 if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
6069 # If the user uses a losing variable name, just ignore it.
6070 # This isn't ideal, but people have requested it.
6071 next if ($varname =~ /\@.*\@/);
6075 if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
6079 ($from = $2) =~ s/(\W)/\\$1/g;
6083 @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
6085 # Now rewrite the value if appropriate.
6088 grep (s/$from$/$to/, @temp_list);
6091 push (@result, @temp_list);
6102 # Return contents of variable as list, split as whitespace. This will
6103 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6104 # substitutions. If COND is 'all', then all values under all
6105 # conditions should be returned; if COND is a particular condition
6106 # (all conditions are surrounded by @...@) then only the value for
6107 # that condition should be returned; otherwise, warn if VAR is
6108 # conditionally defined. If PARENT is specified, it is the name of
6109 # the including variable; this is only used for error reports.
6110 sub variable_value_as_list_worker
6112 my ($var, $cond, $parent) = @_;
6115 if (! defined $var_value{$var})
6117 if (defined $targets{$var})
6119 &am_line_error ($var, "`$var' is a target; expected a variable");
6123 &am_line_error ($parent, "variable `$var' not defined");
6126 elsif (defined $vars_scanned{$var})
6128 # `vars_scanned' is a global we use to keep track of which
6129 # variables we've already examined.
6130 &am_line_error ($parent, "variable `$var' recursively defined");
6132 elsif ($cond eq 'all')
6134 $vars_scanned{$var} = 1;
6135 foreach my $vcond (keys %{$var_value{$var}})
6137 my $val = $var_value{$var}{$vcond};
6138 push (@result, &value_to_list ($var, $val, $cond));
6144 $vars_scanned{$var} = 1;
6146 foreach my $vcond (keys %{$var_value{$var}})
6148 my $val = $var_value{$var}{$vcond};
6149 if (&conditional_true_when ($vcond, $cond))
6151 # Warn if we have an ambiguity. It's hard to know how
6152 # to handle this case correctly.
6153 &check_variable_defined_unconditionally ($var, $parent)
6156 push (@result, &value_to_list ($var, $val, $cond));
6161 # Unset our entry in vars_scanned. We only care about recursive
6163 delete $vars_scanned{$var};
6169 # &variable_output ($VAR, [@CONDS])
6170 # ---------------------------------
6171 # Output all the values of $VAR is @COND is not specified, else only
6172 # that corresponding to @COND.
6173 sub variable_output ($@)
6175 my ($var, @conds) = @_;
6177 @conds = sort by_condition keys %{$var_value{$var}}
6180 $output_vars .= $var_comment{$var}
6181 if defined $var_comment{$var};
6183 foreach my $cond (@conds)
6185 my $val = $var_value{$var}{$cond};
6186 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6187 my $output_var = "$var $equals $val";
6188 $output_var =~ s/^/make_condition ($cond)/meg;
6189 $output_vars .= $output_var . "\n";
6194 # &variable_pretty_output ($VAR, [@CONDS])
6195 # ----------------------------------------
6196 # Likewise, but pretty, i.e., we *split* the values at spaces. Use only
6197 # with variables holding filenames.
6198 sub variable_pretty_output ($@)
6200 my ($var, @conds) = @_;
6202 @conds = sort by_condition keys %{$var_value{$var}}
6205 $output_vars .= $var_comment{$var}
6206 if defined $var_comment{$var};
6208 foreach my $cond (@conds)
6210 my $val = $var_value{$var}{$cond};
6211 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6212 my $make_condition = make_condition ($cond);
6213 $output_vars .= pretty_print_internal ("$make_condition$var $equals",
6214 "$make_condition\t",
6215 split (' ' , $val));
6220 # This is just a wrapper for variable_value_as_list_worker that
6221 # initializes the global hash `vars_scanned'. This hash is used to
6222 # avoid infinite recursion.
6223 sub variable_value_as_list
6225 my ($var, $cond, $parent) = @_;
6227 return &variable_value_as_list_worker ($var, $cond, $parent);
6231 # Like define_variable, but the value is a list, and the variable may
6232 # be defined conditionally. The second argument is the conditional
6233 # under which the value should be defined; this should be the empty
6234 # string to define the variable unconditionally. The third argument
6235 # is a list holding the values to use for the variable. The value is
6236 # pretty printed in the output file.
6237 sub define_pretty_variable
6239 my ($var, $cond, @value) = @_;
6241 # Beware that an empty $cond has a different semantics for
6242 # macro_define and variable_pretty_output.
6245 if (! &variable_defined ($var, $cond))
6247 macro_define ($var, 1, '', $cond, join (' ', @value), undef);
6248 variable_pretty_output ($var, $cond || 'TRUE');
6249 $content_seen{$var} = 1;
6254 # define_variable ($VAR, $VALUE)
6255 # ------------------------------
6256 # Define a new user variable VAR to VALUE, but only if not already defined.
6259 my ($var, $value) = @_;
6261 define_pretty_variable ($var, 'TRUE', $value);
6265 # Like define_variable, but define a variable to be the configure
6266 # substitution by the same name.
6267 sub define_configure_variable
6270 my $value = '@' . $var . '@';
6271 &define_variable ($var, $value);
6275 # define_compiler_variable ($LANG)
6276 # --------------------------------
6277 # Define a compiler variable. We also handle defining the `LT'
6278 # version of the command when using libtool.
6279 sub define_compiler_variable ($)
6283 my ($var, $value) = ($lang->compiler, $lang->compile);
6284 &define_variable ($var, $value);
6285 &define_variable ("LT$var", "\$(LIBTOOL) --mode=compile $value")
6290 # define_linker_variable ($LANG)
6291 # ------------------------------
6292 # Define linker variables.
6293 sub define_linker_variable ($)
6297 my ($var, $value) = ($lang->lder, $lang->ld);
6299 &define_variable ($lang->lder, $lang->ld);
6300 # CCLINK = $(CCLD) blah blah...
6301 &define_variable ($lang->linker,
6302 (($seen_libtool ? '$(LIBTOOL) --mode=link ' : '')
6306 ################################################################
6308 ## ---------------- ##
6309 ## Handling rules. ##
6310 ## ---------------- ##
6312 sub rule_define ($$$$)
6314 my ($target, $rule_is_am, $cond, $where) = @_;
6316 if (defined $targets{$target}
6318 ? ! defined $target_conditional{$target}
6319 : defined $target_conditional{$target}))
6321 &am_line_error ($target,
6322 "$target defined both conditionally and unconditionally");
6325 # Value here doesn't matter; for targets we only note existence.
6326 $targets{$target} = $where;
6329 if ($target_conditional{$target})
6331 &check_ambiguous_conditional ($target, $cond);
6333 $target_conditional{$target}{$cond} = $where;
6337 # Check the rule for being a suffix rule. If so, store in a hash.
6339 if ((my ($source_suffix, $object_suffix)) = ($target =~ $SUFFIX_RULE_PATTERN))
6341 $suffix_rules{$source_suffix} = $object_suffix;
6342 print "Sources ending in .$source_suffix become .$object_suffix\n"
6344 # Set SUFFIXES from suffix_rules.
6345 push @suffixes, ".$source_suffix", ".$object_suffix";
6350 # See if a target exists.
6354 return defined $targets{$target};
6358 ################################################################
6360 # Read Makefile.am and set up %contents. Simultaneously copy lines
6361 # from Makefile.am into $output_trailer or $output_vars as
6362 # appropriate. NOTE we put rules in the trailer section. We want
6363 # user rules to come after our generated stuff.
6368 my $am_file = new IO::File ("< $amfile");
6371 die "$me: couldn't open `$amfile': $!\n";
6373 print "$me: reading $amfile\n" if $verbose;
6379 while ($_ = $am_file->getline)
6381 if (/$IGNORE_PATTERN/o)
6383 # Merely delete comments beginning with two hashes.
6385 elsif (/$WHITE_PATTERN/o)
6387 # Stick a single white line before the incoming macro or rule.
6391 elsif (/$COMMENT_PATTERN/o)
6393 # Stick comments before the incoming macro or rule. Make
6394 # sure a blank line preceeds first block of comments.
6395 $spacing = "\n" unless $blank;
6397 $comment .= $spacing . $_;
6406 $output_vars .= $comment . "\n";
6410 # We save the conditional stack on entry, and then check to make
6411 # sure it is the same on exit. This lets us conditonally include
6413 my @saved_cond_stack = @cond_stack;
6414 my $cond = conditional_string (@cond_stack);
6418 my $last_var_name = '';
6419 my $last_var_type = '';
6420 my $last_var_value = '';
6421 # FIXME: shouldn't use $_ in this loop; it is too big.
6425 unless substr ($_, -1, 1) eq "\n";
6427 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
6428 # used by users. @MAINT@ is an anachronism now.
6429 $_ =~ s/\@MAINT\@//g
6430 unless $seen_maint_mode;
6432 my $new_saw_bk = /\\$/ && ! /$COMMENT_PATTERN/o;
6434 if (/$IGNORE_PATTERN/o)
6436 # Merely delete comments beginning with two hashes.
6438 elsif (/$WHITE_PATTERN/o)
6440 # Stick a single white line before the incoming macro or rule.
6442 &am_line_error ($., "blank line following trailing backslash")
6445 elsif (/$COMMENT_PATTERN/o)
6447 # Stick comments before the incoming macro or rule.
6448 $comment .= $spacing . $_;
6450 &am_line_error ($., "comment following trailing backslash")
6457 $output_trailer .= &make_condition (@cond_stack);
6458 $output_trailer .= $_;
6462 $last_var_value .= ' '
6463 unless $last_var_value =~ /\s$/;
6464 $last_var_value .= $_;
6468 $var_comment{$last_var_name} .= "$spacing"
6469 if (!defined $var_comment{$last_var_name}
6470 || substr ($var_comment{$last_var_name}, -1) ne "\n");
6471 $var_comment{$last_var_name} .= "$comment";
6472 $comment = $spacing = '';
6473 macro_define ($last_var_name, 0,
6474 $last_var_type, $cond,
6475 $last_var_value, $.)
6476 if $cond ne 'FALSE';
6477 push (@var_list, $last_var_name);
6482 elsif (/$IF_PATTERN/o)
6484 $cond = cond_stack_if ($1, $2, "$amfile:$.");
6486 elsif (/$ELSE_PATTERN/o)
6488 $cond = cond_stack_else ($1, $2, "$amfile:$.");
6490 elsif (/$ENDIF_PATTERN/o)
6492 $cond = cond_stack_endif ($1, $2, "$amfile:$.");
6495 elsif (/$RULE_PATTERN/o)
6500 rule_define ($1, 0, $cond, $.);
6503 $output_trailer .= $comment . $spacing;
6504 $output_trailer .= &make_condition (@cond_stack);
6505 $output_trailer .= $_;
6506 $comment = $spacing = '';
6508 elsif (/$ASSIGNMENT_PATTERN/o)
6510 # Found a macro definition.
6512 $last_var_name = $1;
6513 $last_var_type = $2;
6514 $last_var_value = $3;
6515 if ($3 ne '' && substr ($3, -1) eq "\\")
6517 # We preserve the `\' because otherwise the long lines
6518 # that are generated will be truncated by broken
6520 $last_var_value = $3 . "\n";
6525 # FIXME: this doesn't always work correctly; it will
6526 # group all comments for a given variable, no matter
6528 # Accumulating variables must not be output.
6529 $var_comment{$last_var_name} .= "$spacing"
6530 if (!defined $var_comment{$last_var_name}
6531 || substr ($var_comment{$last_var_name}, -1) ne "\n");
6532 $var_comment{$last_var_name} .= "$comment";
6533 $comment = $spacing = '';
6535 macro_define ($last_var_name, 0,
6536 $last_var_type, $cond,
6537 $last_var_value, $.)
6538 if $cond ne 'FALSE';
6539 push (@var_list, $last_var_name);
6542 elsif (/$INCLUDE_PATTERN/o)
6546 if ($path =~ s/^\$\(top_srcdir\)\///)
6548 push (@include_stack, "\$\(top_srcdir\)/$path");
6552 $path =~ s/\$\(srcdir\)\///;
6553 push (@include_stack, "\$\(srcdir\)/$path");
6554 $path = $relative_dir . "/" . $path;
6556 &read_am_file ($path);
6560 # This isn't an error; it is probably a continued rule.
6561 # In fact, this is what we assume.
6563 $output_trailer .= $comment . $spacing;
6564 $output_trailer .= &make_condition (@cond_stack);
6565 $output_trailer .= $_;
6566 $comment = $spacing = '';
6567 &am_line_error ($., "`#' comment at start of rule is unportable")
6568 if $_ =~ /^\t\s*\#/;
6571 $saw_bk = $new_saw_bk;
6572 $_ = $am_file->getline;
6575 $output_trailer .= $comment;
6577 if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
6581 &am_error ("unterminated conditionals: @cond_stack");
6585 # FIXME: better error message here.
6586 &am_error ("conditionals not nested in include file");
6592 # define_standard_variables ()
6593 # ----------------------------
6594 # A helper for read_main_am_file which initializes configure variables
6595 # and variables from header-vars.am. This is a subr so we can call it
6597 sub define_standard_variables
6599 my $saved_output_vars = $output_vars;
6600 my ($comments, undef, $rules) =
6601 file_contents_internal (1, "$libdir/am/header-vars.am");
6603 # This will output the definitions in $output_vars, which we don't
6605 foreach my $var (sort keys %configure_vars)
6607 &define_configure_variable ($var);
6608 push (@var_list, $var);
6611 # ... hence, we restore $output_vars.
6612 $output_vars = $saved_output_vars . $comments . $rules;
6615 # Read main am file.
6616 sub read_main_am_file
6620 # This supports the strange variable tricks we are about to play.
6621 if (scalar keys %var_value > 0)
6624 &prog_error ("variable defined before read_main_am_file");
6627 # Generate copyright header for generated Makefile.in.
6628 # We do discard the output of predefined variables, handled below.
6629 $output_vars = ("# $in_file_name generated automatically by automake "
6630 . $VERSION . " from $am_file_name.\n");
6631 $output_vars .= $gen_copyright;
6633 # We want to predefine as many variables as possible. This lets
6634 # the user set them with `+=' in Makefile.am. However, we don't
6635 # want these initial definitions to end up in the output quite
6636 # yet. So we just load them, but output them later.
6637 &define_standard_variables;
6639 # Read user file, which might override some of our values.
6640 &read_am_file ($amfile);
6642 # Ouput all the Automake variables. If the user changed one, then
6643 # it is now marked as owned by the user.
6644 foreach my $var (uniq @var_list)
6646 # Don't process user variables.
6647 variable_output ($var)
6648 unless !$var_is_am{$var};
6651 # Now dump the user variables that were defined. We do it in the same
6652 # order in which they were defined (skipping duplicates).
6653 foreach my $var (uniq @var_list)
6655 # Don't process Automake variables.
6656 variable_output ($var)
6657 unless $var_is_am{$var};
6661 ################################################################
6664 # &flatten ($STRING)
6665 # ------------------
6666 # Flatten the $STRING and return the result.
6681 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
6682 # ------------------------------------------
6683 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6685 sub make_paragraphs ($%)
6687 my ($file, %transform) = @_;
6689 # Complete %transform with global options and make it a Perl
6692 "s/$IGNORE_PATTERN//gm;"
6693 . transform (%transform,
6695 'CYGNUS' => $cygnus_mode,
6697 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
6699 'SHAR' => $options{'dist-shar'} || 0,
6700 'BZIP2' => $options{'dist-bzip2'} || 0,
6701 'ZIP' => $options{'dist-zip'} || 0,
6702 'COMPRESS' => $options{'dist-tarZ'} || 0,
6704 'INSTALL-INFO' => !$options{'no-installinfo'},
6705 'INSTALL-MAN' => !$options{'no-installman'},
6706 'CK-NEWS' => $options{'check-news'} || 0,
6708 'SUBDIRS' => &variable_defined ('SUBDIRS'),
6709 'TOPDIR' => backname ($relative_dir),
6710 'TOPDIR_P' => $relative_dir eq '.',
6711 'CONFIGURE-AC' => $configure_ac,
6713 'BUILD' => $seen_canonical == $AC_CANONICAL_SYSTEM,
6714 'HOST' => $seen_canonical,
6715 'TARGET' => $seen_canonical == $AC_CANONICAL_SYSTEM,
6717 'LIBTOOL' => defined $configure_vars{'LIBTOOL'})
6718 # We don't need more than two consecutive new-lines.
6719 . 's/\n{3,}/\n\n/g';
6721 # Swallow the file and apply the COMMAND.
6722 my $fc_file = new IO::File ("< $file");
6725 die "$me: installation error: cannot open `$file'\n";
6728 print "$me: reading $file\n"
6730 my $saved_dollar_slash = $/;
6732 $_ = $fc_file->getline;
6733 $/ = $saved_dollar_slash;
6738 # Split at unescaped new lines.
6739 my @lines = split (/(?<!\\)\n/, $content);
6742 while (defined ($_ = shift @lines))
6744 my $paragraph = "$_";
6745 # If we are a rule, eat as long as we start with a tab.
6746 if (/$RULE_PATTERN/smo)
6748 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
6750 $paragraph .= "\n$_";
6752 unshift (@lines, $_);
6755 # If we are a comments, eat as much comments as you can.
6756 elsif (/$COMMENT_PATTERN/smo)
6758 while (defined ($_ = shift @lines)
6759 && $_ =~ /$COMMENT_PATTERN/smo)
6761 $paragraph .= "\n$_";
6763 unshift (@lines, $_);
6766 push @res, $paragraph;
6775 # ($COMMENT, $VARIABLES, $RULES)
6776 # &file_contents_internal ($IS_AM, $FILE, [%TRANSFORM])
6777 # -----------------------------------------------------
6778 # Return contents of a file from $libdir/am, automatically skipping
6779 # macros or rules which are already known. $IS_AM iff the caller is
6780 # reading an Automake file (as opposed to the user's Makefile.am).
6781 sub file_contents_internal ($$%)
6783 my ($is_am, $file, %transform) = @_;
6785 my $result_vars = '';
6786 my $result_rules = '';
6790 # We save the conditional stack on entry, and then check to make
6791 # sure it is the same on exit. This lets us conditonally include
6793 my @saved_cond_stack = @cond_stack;
6794 my $cond = conditional_string (@cond_stack);
6796 foreach (make_paragraphs ($file, %transform))
6799 &am_file_error ($file, "blank line following trailing backslash:\n$_")
6801 &am_file_error ($file, "comment following trailing backslash:\n$_")
6806 # Stick empty line before the incoming macro or rule.
6809 elsif (/$COMMENT_PATTERN/mso)
6811 # Stick comments before the incoming macro or rule.
6815 # Handle inclusion of other files.
6816 elsif (/$INCLUDE_PATTERN/o)
6818 if ($cond ne 'FALSE')
6820 my $file = ($is_am ? "$libdir/am/" : '') . $1;
6822 my ($com, $vars, $rules)
6823 = file_contents_internal ($is_am, $file, %transform);
6825 $result_vars .= $vars;
6826 $result_rules .= $rules;
6830 # Handling the conditionals.
6831 elsif (/$IF_PATTERN/o)
6833 $cond = cond_stack_if ($1, $2, $file);
6835 elsif (/$ELSE_PATTERN/o)
6837 $cond = cond_stack_else ($1, $2, $file);
6839 elsif (/$ENDIF_PATTERN/o)
6841 $cond = cond_stack_endif ($1, $2, $file);
6845 elsif (/$RULE_PATTERN/mso)
6847 # Separate relationship from optional actions: the first
6848 # `new-line tab" not preceded by backslash (continuation
6850 # I'm quite shoked! It seems that (\\\n|[^\n]) is not the
6851 # same as `([^\n]|\\\n)!!! Don't swap it, it breaks.
6853 /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
6854 my ($relationship, $actions) = ($1, $2 || '');
6856 # Separate targets from dependencies: the first colon.
6857 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
6858 my ($targets, $dependencies) = ($1, $2);
6859 # Remove the escaped new lines.
6860 # I don't know why, but I have to use a tmp $flat_deps.
6861 my $flat_deps = &flatten ($dependencies);
6862 my @deps = split (' ', $flat_deps);
6864 foreach (split (' ' , $targets))
6866 # FIXME: We are not robust to people defining several targets
6867 # at once, only some of them being in %dependencies.
6869 # Output only if not in FALSE.
6870 if (defined $dependencies{$_}
6871 && $cond ne 'FALSE')
6873 &depend ($_, @deps);
6874 $actions{$_} .= $actions;
6878 # Free lance dependency. Output the rule for all the
6879 # targets instead of one by one.
6880 if (!defined $targets{$targets}
6881 && $cond ne 'FALSE')
6883 $paragraph =~ s/^/make_condition (@cond_stack)/gme;
6884 $result_rules .= "$spacing$comment$paragraph\n";
6885 rule_define ($targets, $is_am, $cond, $file);
6887 $comment = $spacing = '';
6893 elsif (/$ASSIGNMENT_PATTERN/mso)
6895 my ($var, $type, $val) = ($1, $2, $3);
6896 &am_file_error ($file, "macro `$var' with trailing backslash")
6899 # Accumulating variables must not be output.
6900 $var_comment{$var} .= "$spacing"
6901 if (!defined $var_comment{$var}
6902 || substr ($var_comment{$var}, -1) ne "\n");
6903 $var_comment{$var} .= "$comment";
6904 macro_define ($var, $is_am, $type, $cond, $val, $file)
6905 if $cond ne 'FALSE';
6906 push (@var_list, $var);
6908 # If the user has set some variables we were in charge
6909 # of (which is detected by the first reading of
6910 # `header-vars.am'), we must not output them.
6911 $result_vars .= "$spacing$comment$_\n"
6912 if $type ne '+' && $var_is_am{$var} && $cond ne 'FALSE';
6914 $comment = $spacing = '';
6918 # This isn't an error; it is probably some tokens which
6919 # configure is supposed to replace, such as `@SET-MAKE@',
6920 # or some part of a rule cut by an if/endif.
6921 if ($cond ne 'FALSE')
6923 s/^/make_condition (@cond_stack)/gme;
6924 $result_rules .= "$spacing$comment$_\n";
6926 $comment = $spacing = '';
6930 if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
6934 &am_error ("unterminated conditionals: @cond_stack");
6938 # FIXME: better error message here.
6939 &am_error ("conditionals not nested in include file");
6943 return ($comment, $result_vars, $result_rules);
6948 # &file_contents ($BASENAME, [%TRANSFORM])
6949 # ----------------------------------------
6950 # Return contents of a file from $libdir/am, automatically skipping
6951 # macros or rules which are already known.
6952 sub file_contents ($%)
6954 my ($basename, %transform) = @_;
6955 my ($comments, $variables, $rules) =
6956 file_contents_internal (1, "$libdir/am/$basename.am", %transform);
6957 return "$comments$variables$rules";
6962 # &transform (%PAIRS)
6963 # -------------------
6964 # Foreach ($TOKEN, $VAL) in %PAIRS produce a replacement expression suitable
6965 # for file_contents which:
6966 # - replaces @$TOKEN@ with $VALUE,
6967 # - enables/disables ?$TOKEN?.
6973 while (my ($token, $val) = each %pairs)
6975 $result .= "s/\Q%$token%\E/\Q$val\E/gm;";
6978 $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
6979 $result .= "s/\Q%?$token%\E/TRUE/gm;";
6983 $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
6984 $result .= "s/\Q%?$token%\E/FALSE/gm;";
6992 # Find all variable prefixes that are used for install directories. A
6993 # prefix `zar' qualifies iff:
6994 # * `zardir' is a variable.
6995 # * `zar_PRIMARY' is a variable.
6996 sub am_primary_prefixes
6998 my ($primary, $can_dist, @prefixes) = @_;
7000 my %valid = map { $_ => 0 } @prefixes;
7001 $valid{'EXTRA'} = 0;
7002 foreach my $varname (keys %var_value)
7004 # Automake is allowed to define variables that look like they
7005 # are magic variables, such as INSTALL_DATA.
7007 if $var_is_am{$varname};
7009 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
7011 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
7012 if ($dist ne '' && ! $can_dist)
7014 # Note that a configure variable is always legitimate.
7015 # It is natural to name such variables after the
7016 # primary, so we explicitly allow it.
7017 if (! defined $configure_vars{$varname})
7019 &am_line_error ($varname,
7020 "invalid variable `$varname': `dist' is forbidden");
7023 elsif (! defined $valid{$X} && ! &variable_defined ("${X}dir"))
7025 # Note that a configure variable is always legitimate.
7026 # It is natural to name such variables after the
7027 # primary, so we explicitly allow it.
7028 if (! defined $configure_vars{$varname})
7030 &am_line_error ($varname,
7031 "invalid variable `$varname'");
7036 # Ensure all extended prefixes are actually used.
7037 $valid{"$base$dist$X"} = 1;
7045 # Handle `where_HOW' variable magic. Does all lookups, generates
7046 # install code, and possibly generates code to define the primary
7047 # variable. The first argument is the name of the .am file to munge,
7048 # the second argument is the primary variable (eg HEADERS), and all
7049 # subsequent arguments are possible installation locations. Returns
7050 # list of all values of all _HOW targets.
7052 # FIXME: this should be rewritten to be cleaner. It should be broken
7053 # up into multiple functions.
7055 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7062 my $default_dist = 0;
7065 if ($args[0] eq '-noextra')
7069 elsif ($args[0] eq '-candist')
7073 elsif ($args[0] eq '-defaultdist')
7078 elsif ($args[0] !~ /^-/)
7085 my ($file, $primary, @prefixes) = @args;
7087 # Now that configure substitutions are allowed in where_HOW
7088 # variables, it is an error to actually define the primary. We
7089 # allow `JAVA', as it is customarily used to mean the Java
7090 # interpreter. This is but one of several Java hacks. Similarly,
7091 # `PYTHON' is customarily used to mean the Python interpreter.
7092 &am_line_error ($primary, "`$primary' is an anachronism")
7093 if &variable_defined ($primary)
7094 && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7097 # Look for misspellings. It is an error to have a variable ending
7098 # in a "reserved" suffix whose prefix is unknown, eg
7099 # "bni_PROGRAMS". However, unusual prefixes are allowed if a
7100 # variable of the same name (with "dir" appended) exists. For
7101 # instance, if the variable "zardir" is defined, then
7102 # "zar_PROGRAMS" becomes valid. This is to provide a little extra
7103 # flexibility in those cases which need it.
7104 my %valid = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7106 # If a primary includes a configure substitution, then the EXTRA_
7107 # form is required. Otherwise we can't properly do our job.
7109 my $warned_about_extra = 0;
7114 # True if the iteration is the first one. Used for instance to
7115 # output parts of the associated file only once.
7117 foreach my $X (sort keys %valid)
7119 my $one_name = $X . '_' . $primary;
7121 unless (&variable_defined ($one_name));
7123 my $strip_subdir = 1;
7124 # If subdir prefix should be preserved, do so.
7125 if ($X =~ /^nobase_/)
7131 my $nodir_name = $X;
7132 # If files should be distributed, do so.
7136 $dist_p = (($default_dist && $one_name !~ /^nodist_/)
7137 || (! $default_dist && $one_name =~ /^dist_/));
7138 $nodir_name =~ s/^(dist|nodist)_//;
7141 # Append actual contents of where_PRIMARY variable to
7143 foreach my $rcurs (&variable_value_as_list ($one_name, 'all'))
7145 # Skip configure substitutions. Possibly bogus.
7146 if ($rcurs =~ /^\@.*\@$/)
7150 if (! $warned_about_extra)
7152 $warned_about_extra = 1;
7153 &am_line_error ($one_name,
7154 "`$one_name' contains configure substitution, but shouldn't");
7157 # Check here to make sure variables defined in
7158 # configure.ac do not imply that EXTRA_PRIMARY
7160 elsif (! defined $configure_vars{$one_name})
7162 $require_extra = $one_name
7169 push (@result, $rcurs);
7172 # A blatant hack: we rewrite each _PROGRAMS primary to
7173 # include EXEEXT when in Cygwin32 mode.
7174 if ($primary eq 'PROGRAMS')
7176 my @conds = &variable_conditions ($one_name);
7179 foreach my $cond (@conds)
7181 my @one_binlist = ();
7182 my @condval = &variable_value_as_list ($one_name,
7184 foreach my $rcurs (@condval)
7186 if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7188 push (@one_binlist, $rcurs);
7192 push (@one_binlist, $rcurs . '$(EXEEXT)');
7196 push (@condvals, $cond);
7197 push (@condvals, join (' ', @one_binlist));
7200 variable_delete ($one_name);
7203 my $cond = shift (@condvals);
7204 my @val = split (' ', shift (@condvals));
7205 &define_pretty_variable ($one_name, $cond, @val);
7209 # "EXTRA" shouldn't be used when generating clean targets,
7210 # all, or install targets.
7213 # We used to warn if EXTRA_FOO was defined uselessly,
7214 # but this was annoying.
7220 push (@check, '$(' . $one_name . ')');
7224 push (@used, '$(' . $one_name . ')');
7227 # Is this to be installed?
7228 my $install_p = $X ne 'noinst' && $X ne 'check';
7230 # If so, with install-exec? (or install-data?).
7231 my $exec_p = (defined $exec_dir_p {$X}
7235 # Singular form of $PRIMARY.
7236 (my $one_primary = $primary) =~ s/S$//;
7237 $output_rules .= &file_contents ($file,
7240 'PRIMARY' => $primary,
7241 'ONE_PRIMARY' => $one_primary,
7243 'NDIR' => $nodir_name,
7244 'BASE' => $strip_subdir,
7247 'INSTALL' => $install_p,
7248 'DIST' => $dist_p));
7253 # The JAVA variable is used as the name of the Java interpreter.
7254 # The PYTHON variable is used as the name of the Python interpreter.
7255 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7258 &define_pretty_variable ($primary, '', @used);
7259 $output_vars .= "\n";
7262 if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7264 &am_line_error ($require_extra,
7265 "`$require_extra' contains configure substitution, but `EXTRA_$primary' not defined");
7268 # Push here because PRIMARY might be configure time determined.
7269 push (@all, '$(' . $primary . ')')
7270 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7272 # Make the result unique. This lets the user use conditionals in
7273 # a natural way, but still lets us program lazily -- we don't have
7274 # to worry about handling a particular object more than once.
7275 return uniq (sort @result);
7279 ################################################################
7281 # Each key in this hash is the name of a directory holding a
7282 # Makefile.in. These variables are local to `is_make_dir'.
7284 my $make_dirs_set = 0;
7289 if (! $make_dirs_set)
7291 foreach my $iter (@configure_input_files)
7293 $make_dirs{dirname ($iter)} = 1;
7295 # We also want to notice Makefile.in's.
7296 foreach my $iter (@other_input_files)
7298 if ($iter =~ /Makefile\.in$/)
7300 $make_dirs{dirname ($iter)} = 1;
7305 return defined $make_dirs{$dir};
7308 ################################################################
7310 # This variable is local to the "require file" set of functions.
7311 my @require_file_paths = ();
7313 # If a file name appears as a key in this hash, then it has already
7314 # been checked for. This variable is local to the "require file"
7316 %require_file_found = ();
7318 # See if we want to push this file onto dist_common. This function
7319 # encodes the rules for deciding when to do so.
7320 sub maybe_push_required_file
7322 my ($dir, $file, $fullfile) = @_;
7324 if ($dir eq $relative_dir)
7326 &push_dist_common ($file);
7328 elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7330 # If we are doing the topmost directory, and the file is in a
7331 # subdir which does not have a Makefile, then we distribute it
7333 &push_dist_common ($fullfile);
7338 # &require_file_internal ($IS_CONFIGURE, $LINE, $MYSTRICT, @FILES)
7339 # ----------------------------------------------------------------
7340 # Verify that the file must exist in the current directory.
7341 # $MYSTRICT is the strictness level at which this file becomes required.
7343 # Must set require_file_paths before calling this function.
7344 # require_file_paths is set to hold a single directory (the one in
7345 # which the first file was found) before return.
7346 sub require_file_internal
7348 my ($is_configure, $line, $mystrict, @files) = @_;
7350 foreach my $file (@files)
7358 my $dangling_sym = 0;
7359 foreach my $dir (@require_file_paths)
7361 $fullfile = $dir . "/" . $file;
7362 $errdir = $dir unless $errdir;
7364 # Use different name for "error filename". Otherwise on
7365 # an error the bad file will be reported as eg
7366 # `../../install-sh' when using the default
7368 $errfile = $errdir . '/' . $file;
7370 if (-l $fullfile && ! -f $fullfile)
7375 elsif (-f $fullfile)
7378 &maybe_push_required_file ($dir, $file, $fullfile);
7384 # `--force-missing' only has an effect if `--add-missing' is
7386 if ($found_it && (! $add_missing || ! $force_missing))
7388 # Prune the path list.
7389 @require_file_paths = $save_dir;
7393 # If we've already looked for it, we're done. You might
7394 # wonder why we don't do this before searching for the
7395 # file. If we do that, then something like
7396 # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
7400 next if defined $require_file_found{$file};
7401 $require_file_found{$file} = 1;
7404 if ($strictness >= $mystrict)
7406 if ($dangling_sym && $add_missing)
7414 # Only install missing files according to our desired
7416 my $message = "required file `$errfile' not found";
7421 # Maybe run libtoolize.
7422 my @syslist = ('libtoolize', '--automake');
7423 push @syslist, '--copy'
7426 && grep ($_ eq $file, @libtoolize_files)
7427 && system (@syslist))
7429 $message = "installing `$errfile'";
7431 $trailer = "; cannot run `libtoolize': $!";
7433 elsif (-f ("$libdir/$file"))
7435 # Install the missing file. Symlink if we
7436 # can, copy if we must. Note: delete the file
7437 # first, in case it is a dangling symlink.
7438 $message = "installing `$errfile'";
7439 # Windows Perl will hang if we try to delete a
7440 # file that doesn't exist.
7441 unlink ($errfile) if -f $errfile;
7442 if ($symlink_exists && ! $copy_missing)
7444 if (! symlink ("$libdir/$file", $errfile))
7447 $trailer = "; error while making link: $!";
7450 elsif (system ('cp', "$libdir/$file", $errfile))
7453 $trailer = "\n error while copying";
7457 &maybe_push_required_file (dirname ($errfile),
7460 # Prune the path list.
7461 @require_file_paths = &dirname ($errfile);
7464 # If --force-missing was specified, and we have
7465 # actually found the file, then do nothing.
7467 if $found_it && $force_missing;
7473 # FIXME: allow actual file to be specified.
7474 &am_conf_line_warning ($configure_ac, $line,
7475 "$message$trailer");
7479 &am_line_warning ($line, "$message$trailer");
7486 # FIXME: allow actual file to be specified.
7487 &am_conf_line_error ($configure_ac, $line,
7488 "$message$trailer");
7492 &am_line_error ($line, "$message$trailer");
7500 # Like require_file_with_line, but error messages refer to
7501 # configure.ac, not the current Makefile.am.
7502 sub require_file_with_conf_line
7504 @require_file_paths = $relative_dir;
7505 &require_file_internal (1, @_);
7508 sub require_file_with_line
7510 @require_file_paths = $relative_dir;
7511 &require_file_internal (0, @_);
7516 @require_file_paths = $relative_dir;
7517 &require_file_internal (0, '', @_);
7520 # Require a file that is also required by Autoconf. Looks in
7521 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7522 sub require_config_file
7524 @require_file_paths = @config_aux_path;
7525 &require_file_internal (1, '', @_);
7526 my $dir = $require_file_paths[0];
7527 @config_aux_path = @require_file_paths;
7528 # Avoid unsightly '/.'s.
7529 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7532 # Assumes that the line number is in Makefile.am.
7533 sub require_conf_file_with_line
7535 @require_file_paths = @config_aux_path;
7536 &require_file_internal (0, @_);
7537 my $dir = $require_file_paths[0];
7538 @config_aux_path = @require_file_paths;
7539 # Avoid unsightly '/.'s.
7540 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7543 # Assumes that the line number is in configure.ac.
7544 sub require_conf_file_with_conf_line
7546 @require_file_paths = @config_aux_path;
7547 &require_file_internal (1, @_);
7548 my $dir = $require_file_paths[0];
7549 @config_aux_path = @require_file_paths;
7550 # avoid unsightly '/.'s.
7551 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7554 ################################################################
7556 # Push a list of files onto dist_common.
7557 sub push_dist_common
7559 &prog_error ("push_dist_common run after handle_dist")
7560 if $handle_dist_run;
7561 macro_define ('DIST_COMMON', 1, '+', '', join (' ', @_), '');
7568 $strictness_name = $_[0];
7569 if ($strictness_name eq 'gnu')
7573 elsif ($strictness_name eq 'gnits')
7575 $strictness = $GNITS;
7577 elsif ($strictness_name eq 'foreign')
7579 $strictness = $FOREIGN;
7583 die "$me: level `$strictness_name' not recognized\n";
7588 ################################################################
7590 # Ensure a file exists.
7595 my $touch = new IO::File (">> $file");
7599 # Glob something. Do this to avoid indentation screwups everywhere we
7600 # want to glob. Gross!
7607 # Remove one level of brackets and strip leading spaces,
7608 # as does m4 to function arguments.
7614 my @letters = split //;
7623 next if $depth == 1;
7628 next if $depth == 0;
7629 # don't count orphan right brackets
7630 $depth = 0 if $depth < 0;
7634 return join '', @result;
7637 ################################################################
7639 # Print an error message and set exit status.
7642 warn "$me: ${am_file}.am: @_\n";
7646 # am_file_error ($FILE, @ARGS)
7647 # ----------------------------
7650 my ($file, @args) = @_;
7652 warn "$file: @args\n";
7658 my ($symbol, @args) = @_;
7660 if ($symbol && "$symbol" ne '-1')
7662 my $file = "${am_file}.am";
7664 if ($symbol =~ /^\d+$/)
7666 # SYMBOL is a line number, so just add the colon.
7667 $file .= ':' . $symbol;
7669 elsif (defined $var_line{$symbol})
7671 # SYMBOL is a variable defined in Makefile.am, so add the
7672 # line number we saved from there.
7673 $file .= ':' . $var_line{$symbol};
7675 elsif (defined $configure_vars{$symbol})
7677 # SYMBOL is a variable defined in configure.ac, so add the
7678 # appropriate line number.
7679 $file = $configure_vars{$symbol};
7683 # Couldn't find the line number.
7685 warn $file, ": @args\n";
7694 # Like am_error, but while scanning configure.ac.
7697 # FIXME: can run in subdirs.
7698 warn "$me: $configure_ac: @_\n";
7702 # Error message with line number referring to configure.ac.
7703 sub am_conf_line_error
7705 my ($file, $line, @args) = @_;
7709 warn "$file: $line: @args\n";
7714 &am_conf_error (@args);
7718 # Warning message with line number referring to configure.ac.
7719 # Does not affect exit_status
7720 sub am_conf_line_warning
7722 my $saved_exit_status = $exit_status;
7723 my $sig = $SIG{'__WARN__'};
7724 $SIG{'__WARN__'} = 'DEFAULT';
7725 am_conf_line_error (@_);
7726 $exit_status = $saved_exit_status;
7727 $SIG{'__WARN__'} = $sig;
7730 # Like am_line_error, but doesn't affect exit status.
7733 my $saved_exit_status = $exit_status;
7734 my $sig = $SIG{'__WARN__'};
7735 $SIG{'__WARN__'} = 'DEFAULT';
7737 $exit_status = $saved_exit_status;
7738 $SIG{'__WARN__'} = $sig;
7741 # Tell user where our aclocal.m4 is, but only once.
7742 sub keyed_aclocal_warning
7745 warn "$me: macro `$key' can be generated by `aclocal'\n";
7748 # Print usage information.
7752 Usage: $0 [OPTION] ... [Makefile]...
7754 Generate Makefile.in for configure from Makefile.am.
7757 --help print this help, then exit
7758 --version print version number, then exit
7759 -v, --verbose verbosely list files processed
7760 -o, --output-dir=DIR put generated Makefile.in's into DIR
7761 --no-force only update Makefile.in's that are out of date
7763 Dependency tracking:
7764 -i, --ignore-deps disable dependency tracking code
7765 --include-deps enable dependency tracking code
7768 --cygnus assume program is part of Cygnus-style tree
7769 --foreign set strictness to foreign
7770 --gnits set strictness to gnits
7771 --gnu set strictness to gnu
7774 -a, --add-missing add missing standard files to package
7775 --libdir=DIR directory storing library files
7776 -c, --copy with -a, copy missing files (default is symlink)
7777 -f, --force-missing force update of standard files
7782 foreach my $iter (sort ((@common_files, @common_sometimes)))
7784 push (@lcomm, $iter) unless $iter eq $last;
7788 my ($one, $two, $three, $four, $max);
7789 print "\nFiles which are automatically distributed, if found:\n";
7790 format USAGE_FORMAT =
7791 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
7792 $one, $two, $three, $four
7794 $~ = "USAGE_FORMAT";
7795 $max = int (($#lcomm + 1) / 4);
7797 for (my $i = 0; $i < $max; ++$i)
7800 $two = $lcomm[$max + $i];
7801 $three = $lcomm[2 * $max + $i];
7802 $four = $lcomm[3 * $max + $i];
7806 my $mod = ($#lcomm + 1) % 4;
7809 $one = $lcomm[$max];
7810 $two = ($mod > 1) ? $lcomm[2 * $max] : '';
7811 $three = ($mod > 2) ? $lcomm[3 * $max] : '';
7812 $four = ($mod > 3) ? $lcomm[4 * $max] : '';
7816 print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7823 # Print version information
7827 automake (GNU $PACKAGE) $VERSION
7828 Written by Tom Tromey <tromey\@cygnus.com>.
7830 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
7831 Free Software Foundation, Inc.
7832 This is free software; see the source for copying conditions. There is NO
7833 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.