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 '.')
1177 # libtool requires some files.
1178 &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
1182 # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1184 &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
1188 # We still need Makefile.in here, because sometimes the `dist'
1189 # target doesn't re-run automake.
1190 if ($am_relative_dir eq $relative_dir)
1192 # Only distribute the files if they are in the same subdir as
1193 # the generated makefile.
1194 &push_dist_common ($in_file_name, $am_file_name);
1197 push (@sources, '$(SOURCES)')
1198 if &variable_defined ('SOURCES');
1200 # If OBJEXT/EXEEXT were not set in configure.in, do it, it
1201 # simplifies our task, and anyway starting with Autoconf 2.50, it
1202 # will always be defined, and this code will be dead.
1203 $output_vars .= "EXEEXT =\n"
1204 unless $seen_exeext;
1205 $output_vars .= "OBJEXT = o\n"
1206 unless $seen_objext;
1208 # Must do this after reading .am file. See read_main_am_file to
1209 # understand weird tricks we play there with variables.
1210 &define_variable ('subdir', $relative_dir);
1212 # Check first, because we might modify some state.
1214 &check_gnu_standards;
1215 &check_gnits_standards;
1217 &handle_configure ($output, $makefile, @secondary_inputs);
1220 &handle_ltlibraries;
1224 # This must run first so that the ANSI2KNR definition is generated
1225 # before it is used by the _.c rules. We have to do this because
1226 # a variable which is used in a dependency must be defined before
1227 # the target, or else make won't properly see it.
1229 # This must be run after all the sources are scanned.
1232 # Re-init SOURCES. FIXME: other code shouldn't depend on this
1233 # (but currently does).
1234 macro_define ('SOURCES', 1, '', 'TRUE',
1235 join (' ', @sources), 'internal');
1236 &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
1248 &handle_minor_options;
1251 # This must come after most other rules.
1252 &handle_dist ($makefile);
1255 &do_check_merge_target;
1256 &handle_all ($output);
1259 if (&variable_defined('lib_LTLIBRARIES') &&
1260 &variable_defined('bin_PROGRAMS'))
1262 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
1265 &handle_installdirs;
1267 &handle_factored_dependencies;
1271 if (! -d ($output_directory . '/' . $am_relative_dir))
1273 mkdir ($output_directory . '/' . $am_relative_dir, 0755);
1276 my ($out_file) = $output_directory . '/' . $makefile . ".in";
1277 if (! $force_generation && -e $out_file)
1279 my ($am_time) = (stat ($makefile . '.am'))[9];
1280 my ($in_time) = (stat ($out_file))[9];
1281 # FIXME: should cache these times.
1282 my ($conf_time) = (stat ($configure_ac))[9];
1283 # FIXME: how to do unsigned comparison?
1284 if ($am_time < $in_time || $am_time < $conf_time)
1286 # No need to update.
1289 if (-f 'aclocal.m4')
1291 my ($acl_time) = (stat _)[9];
1292 return if ($am_time < $acl_time);
1296 my $gm_file = new IO::File "> $out_file";
1299 warn "$me: ${am_file}.in: cannot write: $!\n";
1303 print "$me: creating ", $makefile, ".in\n" if $verbose;
1305 # In case we're running under MSWindows, don't write with CRLF
1306 # (as it causes problems for the dependency-file extraction in
1307 # AM_OUTPUT_DEPENDENCY_COMMANDS).
1310 print $gm_file $output_vars;
1311 # We make sure that `all:' is the first target.
1312 print $gm_file $output_all;
1313 print $gm_file $output_header;
1314 print $gm_file $output_rules;
1315 print $gm_file $output_trailer;
1317 if (! $gm_file->close)
1319 warn "$me: $am_file.in: cannot close: $!\n";
1325 ################################################################
1327 # A helper which handles the logic of requiring a version number in
1328 # AUTOMAKE_OPTIONS. Return 1 on error, 0 on success.
1329 sub version_check ($$$$)
1331 my ($rmajor, $rminor, $ralpha, $rfork) = ($1, $2, $3, $4);
1333 &prog_error ("version is incorrect: $VERSION")
1334 if $VERSION !~ /(\d+)\.(\d+)([a-z]?)-?([A-Za-z0-9]+)?/;
1336 my ($tmajor, $tminor, $talpha, $tfork) = ($1, $2, $3, $4);
1341 my $rminorminor = 0;
1342 my $tminorminor = 0;
1344 # Some versions were labelled like `1.4-p3a'. This is the same as
1345 # an alpha release labelled `1.4.3a'. However, a version like
1346 # `1.4g' is the same as `1.4.99g'. Yes, this sucks. Moral:
1347 # always listen to the users.
1348 if ($rfork =~ /p([0-9]+)([a-z]?)/)
1351 # `1.4a-p3b' never existed. But we'll accept it anyway.
1352 $ralpha = $ralpha || $2 || '';
1355 if ($tfork =~ /p([0-9]+)([a-z]?)/)
1358 # `1.4a-p3b' never existed. But we'll accept it anyway.
1359 $talpha = $talpha || $2 || '';
1363 $rminorminor = 99 if $ralpha ne '' && $rminorminor == 0;
1364 $tminorminor = 99 if $talpha ne '' && $tminorminor == 0;
1366 # 2.0 is better than 1.0.
1367 # 1.2 is better than 1.1.
1368 # 1.2a is better than 1.2.
1369 # If we require 3.4n-foo then we require something
1370 # >= 3.4n, with the `foo' fork identifier.
1371 # The $r* variables are what the user specified.
1372 # The $t* variables denote automake itself.
1373 if ($rmajor > $tmajor
1374 || ($rmajor == $tmajor && $rminor > $tminor)
1375 || ($rminor == $tminor && $rminor == $tminor
1376 && $rminorminor > $tminorminor)
1377 || ($rminor == $tminor && $rminor == $tminor
1378 && $rminorminor == $tminorminor
1379 && $ralpha gt $talpha)
1380 || ($rfork ne '' && $rfork ne $tfork))
1382 &am_line_error ('AUTOMAKE_OPTIONS',
1383 "require version $_, but have $VERSION");
1390 # Handle AUTOMAKE_OPTIONS variable. Return 1 on error, 0 otherwise.
1393 if (&variable_defined ('AUTOMAKE_OPTIONS'))
1395 foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
1398 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
1400 &set_strictness ($_);
1402 elsif ($_ eq 'cygnus')
1408 # An option like "../lib/ansi2knr" is allowed. With
1409 # no path prefix, we assume the required programs are
1410 # in this directory. We save the actual option for
1412 $options{'ansi2knr'} = $_;
1414 elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
1415 || $_ eq 'dist-shar' || $_ eq 'dist-zip'
1416 || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
1417 || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
1418 || $_ eq 'readme-alpha' || $_ eq 'check-news'
1419 || $_ eq 'subdir-objects' || $_ eq 'nostdinc')
1421 # Explicitly recognize these.
1423 elsif ($_ eq 'no-dependencies')
1425 $use_dependencies = 0;
1427 elsif (/(\d+)\.(\d+)([a-z]?)(-[A-Za-z0-9]+)?/)
1429 # Got a version number.
1430 if (version_check ($1, $2, $3, $4))
1437 &am_line_error ('AUTOMAKE_OPTIONS',
1438 "option `" . $_ . "\' not recognized");
1443 if ($strictness == $GNITS)
1445 $options{'readme-alpha'} = 1;
1446 $options{'check-news'} = 1;
1453 # get_object_extension ($OUT)
1454 # ---------------------------
1455 # Return object extension. Just once, put some code into the output.
1456 # OUT is the name of the output file
1457 sub get_object_extension
1461 # Maybe require libtool library object files.
1462 my $extension = '.$(OBJEXT)';
1463 $extension = '.lo' if ($out =~ /\.la$/);
1465 # Check for automatic de-ANSI-fication.
1466 $extension = '$U' . $extension
1467 if defined $options{'ansi2knr'};
1469 $get_object_extension_was_run = 1;
1475 # Call finish function for each language that was used.
1476 sub handle_languages
1478 if ($use_dependencies)
1480 # Include auto-dep code. Don't include it if DEP_FILES would
1482 if (&saw_sources_p (0) && keys %dep_files)
1484 # Set location of depcomp.
1485 &define_variable ('depcomp', "\$(SHELL) $config_aux_dir/depcomp");
1487 &require_config_file ($FOREIGN, 'depcomp');
1489 my @deplist = sort keys %dep_files;
1491 # We define this as a conditional variable because BSD
1492 # make can't handle backslashes for continuing comments on
1493 # the following line.
1494 &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
1496 # Generate each `include' individually. Irix 6 make will
1497 # not properly include several files resulting from a
1498 # variable expansion; generating many separate includes
1500 $output_rules .= "\n";
1501 foreach my $iter (@deplist)
1503 $output_rules .= (subst ('AMDEP_TRUE')
1504 . subst ('_am_include')
1506 . subst ('_am_quote')
1508 . subst ('_am_quote')
1512 $output_rules .= &file_contents ('depend');
1517 &define_variable ('depcomp', '');
1522 # Is the c linker needed?
1524 foreach my $ext (sort keys %extension_seen)
1526 next unless $extension_map{$ext};
1528 my $lang = $languages{$extension_map{$ext}};
1530 # Get information on $LANG.
1531 my $pfx = $lang->autodep;
1532 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1534 my $AMDEP = (($use_dependencies && $lang->autodep ne 'no')
1535 ? 'AMDEP' : 'FALSE');
1537 my %transform = ('EXT' => $ext,
1540 'LIBTOOL' => $seen_libtool,
1542 '-c' => $lang->compile_flag || '');
1544 # Generate the appropriate rules for this extension.
1545 if ($use_dependencies && $lang->autodep ne 'no'
1546 || defined $lang->compile)
1548 # Some C compilers don't support -c -o. Use it only if really
1550 my $output_flag = $lang->output_flag || '';
1553 && $lang->flags eq 'CFLAGS'
1554 && defined $options{'subdir-objects'});
1557 file_contents ('depend2',
1567 'COMPILE' => '$(' . $lang->compiler . ')',
1568 'LTCOMPILE' => '$(LT' . $lang->compiler . ')',
1569 '-o' => $output_flag);
1572 # Now include code for each specially handled object with this
1574 my %seen_files = ();
1575 foreach my $file (@{$lang_specific_files{$lang->name}})
1577 my ($derived, $source, $obj) = split (' ', $file);
1579 # We might see a given object twice, for instance if it is
1580 # used under different conditions.
1581 next if defined $seen_files{$obj};
1582 $seen_files{$obj} = 1;
1584 my $flags = $lang->flags || '';
1585 my $val = "${derived}_${flags}";
1587 (my $obj_compile = $lang->compile) =~ s/\(AM_$flags/\($val/;
1588 my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
1590 # We _need_ `-o' for per object rules.
1591 my $output_flag = $lang->output_flag || '-o';
1593 # Generate a transform which will turn suffix targets in
1594 # depend2.am into real targets for the particular objects we
1597 file_contents ('depend2',
1602 'SOURCE' => $source,
1604 'OBJOBJ' => "$obj.obj",
1605 'LTOBJ' => "$obj.lo",
1607 'COMPILE' => $obj_compile,
1608 'LTCOMPILE' => $obj_ltcompile,
1609 '-o' => $output_flag));
1612 # The rest of the loop is done once per language.
1613 next if defined $done{$lang};
1616 # Load the language dependent Makefile chunks.
1617 my %lang = map { uc ($_) => 0 } keys %languages;
1618 $lang{uc ($lang->name)} = 1;
1619 $output_rules .= file_contents ('lang-compile', %transform, %lang);
1621 # If the source to a program consists entirely of code from a
1622 # `pure' language, for instance C++ for Fortran 77, then we
1623 # don't need the C compiler code. However if we run into
1624 # something unusual then we do generate the C code. There are
1625 # probably corner cases here that do not work properly.
1626 # People linking Java code to Fortran code deserve pain.
1627 $needs_c ||= ! $lang->pure;
1629 define_compiler_variable ($lang)
1630 if ($lang->compile);
1632 define_linker_variable ($lang)
1635 foreach my $var (@{$lang->config_vars})
1637 am_error ($lang->Name
1638 . " source seen but `$var' not defined in"
1639 . " `$configure_ac'")
1640 if !exists $configure_vars{$var};
1643 # The compiler's flag must be a configure variable.
1644 define_configure_variable ($lang->flags)
1645 if (defined $lang->flags);
1647 # Call the finisher.
1651 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1652 # suffix rule was learned), don't bother with the C stuff. But if
1653 # anything else creeps in, then use it.
1655 if $need_link || scalar keys %suffix_rules > 1;
1659 if (! defined $done{$languages{'c'}})
1661 &define_configure_variable ($languages{'c'}->flags);
1662 &define_compiler_variable ($languages{'c'});
1664 define_linker_variable ($languages{'c'});
1668 # Output a rule to build from a YACC source. The output from YACC is
1669 # compiled with C or C++, depending on the extension of the YACC file.
1670 sub output_yacc_build_rule
1672 my ($yacc_suffix, $use_ylwrap) = @_;
1674 (my $c_suffix = $yacc_suffix) =~ tr/y/c/;
1676 # Generate rule for c/c++.
1677 $output_rules .= &file_contents ('yacc',
1678 ('YLWRAP' => $use_ylwrap,
1679 'YACC_SUFFIX' => $yacc_suffix,
1680 'C_SUFFIX' => $c_suffix));
1683 sub output_lex_build_rule
1685 my ($lex_suffix, $use_ylwrap) = @_;
1687 (my $c_suffix = $lex_suffix) =~ tr/l/c/;
1689 $output_rules .= &file_contents ('lex',
1690 ('YLWRAP' => $use_ylwrap,
1691 'LEX_SUFFIX' => $lex_suffix,
1692 'C_SUFFIX' => $c_suffix));
1695 # Check to make sure a source defined in LIBOBJS is not explicitly
1696 # mentioned. This is a separate function (as opposed to being inlined
1697 # in handle_source_transform) because it isn't always appropriate to
1699 sub check_libobjs_sources
1701 my ($one_file, $unxformed) = @_;
1703 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1704 'dist_EXTRA_', 'nodist_EXTRA_')
1707 if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1709 @files = &variable_value_as_list (($prefix
1710 . $one_file . '_SOURCES'),
1713 elsif ($prefix eq '')
1715 @files = ($unxformed . '.c');
1722 foreach my $file (@files)
1724 if (defined $libsources{$file})
1726 &am_line_error ($prefix . $one_file . '_SOURCES',
1727 "automatically discovered file `$file' should not be explicitly mentioned");
1734 # ($LINKER, @OBJECTS)
1735 # handle_single_transform_list ($VAR, $DERIVED, $OBJ, @FILES)
1736 # -----------------------------------------------------------
1737 # Does much of the actual work for handle_source_transform.
1739 # $DERIVED is the name of resulting executable or library
1740 # $OBJ is the object extension (e.g., `$U.lo')
1741 # @FILES is the list of source files to transform
1743 # $LINKER is name of linker to use (empty string for default linker)
1744 # @OBJECTS are names of objects
1745 sub handle_single_transform_list ($$$@)
1747 my ($var, $derived, $obj, @files) = @_;
1749 my $nonansi_obj = $obj;
1750 $nonansi_obj =~ s/\$U//g;
1751 my %linkers_used = ();
1753 # Turn sources into objects.
1756 # Configure substitutions in _SOURCES variables are errors.
1759 &am_line_error ($var, "$var includes configure substitution `$_'");
1763 # If the source file is in a subdirectory then the `.o' is
1764 # put into the current directory.
1766 # Split file name into base and extension.
1767 next if ! /^(?:(.*)\/)?([^\/]*)\.(.*)$/;
1769 my $directory = $1 || '';
1773 # We must generate a rule for the object if it requires its own flags.
1775 my ($linker, $object);
1777 $extension = &derive_suffix ($extension);
1779 if ($extension_map{$extension} &&
1780 ($lang = $languages{$extension_map{$extension}}))
1782 &saw_extension ($extension);
1783 # Found the language, so see what it says.
1784 my $subr = 'lang_' . $lang->name . '_rewrite';
1785 # Note: computed subr call.
1786 my $r = & $subr ($directory, $base, $extension);
1787 # Skip this entry if we were asked not to process it.
1788 next if $r == $LANG_IGNORE;
1790 # Now extract linker and other info.
1791 $linker = $lang->linker;
1793 my $this_obj_ext = $lang->ansi ? $obj : $nonansi_obj;
1794 $object = $base . $this_obj_ext;
1796 if (defined $lang->flags
1797 && &variable_defined ($derived . '_' . $lang->flags))
1799 # We have a per-executable flag in effect for this
1800 # object. In this case we rewrite the object's
1801 # name to ensure it is unique. We also require
1802 # the `compile' program to deal with compilers
1803 # where `-c -o' does not work.
1805 # We choose the name `DERIVED_OBJECT' to ensure
1806 # (1) uniqueness, and (2) continuity between
1807 # invocations. However, this will result in a
1808 # name that is too long for losing systems, in
1809 # some situations. So we provide _SHORTNAME to
1812 my $dname = $derived;
1813 if (&variable_defined ($derived . '_SHORTNAME'))
1815 # FIXME: should use the same conditional as
1816 # the _SOURCES variable. But this is really
1817 # silly overkill -- nobody should have
1818 # conditional shortnames.
1819 $dname = &variable_value ($derived . '_SHORTNAME');
1821 $object = $dname . '-' . $object;
1823 &require_file ($FOREIGN, 'compile')
1824 if $lang->name eq 'c';
1826 &prog_error ("$lang->name flags defined without compiler")
1827 if ! defined $lang->compile;
1832 # If rewrite said it was ok, put the object into a
1834 if ($r == $LANG_SUBDIR && $directory ne '')
1836 $object = $directory . '/' . $object;
1839 # If doing dependency tracking, then we can't print
1840 # the rule. If we have a subdir object, we need to
1841 # generate an explicit rule. Actually, in any case
1842 # where the object is not in `.' we need a special
1843 # rule. The per-object rules in this case are
1844 # generated later, by handle_languages.
1845 if ($renamed || $directory ne '')
1847 my $obj_sans_ext = substr ($object, 0,
1848 - length ($this_obj_ext));
1849 my $val = "$full $obj_sans_ext";
1851 # If we renamed the object then we want to use the
1852 # per-executable flag name. But if this is simply a
1853 # subdir build then we still want to use the AM_ flag
1857 $val = "$derived $val";
1864 push (@{$lang_specific_files{$lang->name}}, $val);
1867 elsif ($extension eq 'o')
1869 # This is probably the result of a direct suffix rule.
1870 # In this case we just accept the rewrite. FIXME:
1871 # this fails if we want libtool objects.
1872 $object = $base . '.' . $extension;
1877 # No error message here. Used to have one, but it was
1882 $linkers_used{$linker} = 1;
1884 push (@result, $object);
1886 if (defined $object_map{$object})
1888 if ($object_map{$object} ne $full)
1890 &am_error ("object `$object' created by `$full' and `$object_map{$object}'");
1896 $object_map{$object} = $full;
1898 # If file is in subdirectory, we need explicit
1900 if ($directory ne '' || $renamed)
1902 push (@dep_list, $full);
1905 # If resulting object is in subdir, we need to make
1906 # sure the subdir exists at build time.
1907 if ($object =~ /\//)
1909 # FIXME: check that $DIRECTORY is somewhere in the
1912 # We don't allow `..' in object file names for
1913 # *any* source, not just Java. For Java it just
1914 # doesn't make sense, but in general it is
1915 # a problem because we can't pick a good name for
1917 if ($object =~ /(\/|^)\.\.\//)
1919 &am_error ("`$full' contains `..' component but should not");
1922 # Make sure object is removed by `make mostlyclean'.
1923 $compile_clean_files{$object} = $MOSTLY_CLEAN;
1925 push (@dep_list, $directory . '/.dirstamp');
1927 # If we're generating dependencies, we also want
1928 # to make sure that the appropriate subdir of the
1929 # .deps directory is created.
1930 if ($use_dependencies)
1932 push (@dep_list, '.deps/' . $directory . '/.dirstamp');
1935 if (! defined $directory_map{$directory})
1937 $directory_map{$directory} = 1;
1939 # Directory must be removed by `make distclean'.
1940 $compile_clean_files{$directory . "/.dirstamp"} =
1942 $output_rules .= ($directory . "/.dirstamp:\n"
1943 . "\t\@\$(mkinstalldirs) $directory\n"
1944 . "\t\@: > $directory/.dirstamp\n");
1945 if ($use_dependencies)
1947 $output_rules .= ('.deps/' . $directory
1949 . "\t\@\$(mkinstalldirs) .deps/$directory\n"
1950 . "\t\@: > .deps/$directory/.dirstamp\n");
1955 &pretty_print_rule ($object . ':', "\t", @dep_list)
1956 if scalar @dep_list > 0;
1959 # Transform .o or $o file into .P file (for automatic
1962 && ($lang->autodep ne 'no'
1963 || $lang->derived_autodep eq 'yes'))
1965 my $depfile = $object;
1966 $depfile =~ s/\.([^.]*)$/.P$1/;
1967 $depfile =~ s/\$\(OBJEXT\)$/o/;
1968 $dep_files{'$(DEPDIR)/' . $depfile} = 1;
1972 return (&resolve_linker (%linkers_used), @result);
1977 # Handle SOURCE->OBJECT transform for one program or library.
1979 # canonical (transformed) name of object to build
1980 # actual name of object to build
1981 # object extension (ie either `.o' or `$o'.
1982 # Return result is name of linker variable that must be used.
1983 # Empty return means just use `LINK'.
1984 sub handle_source_transform
1986 # one_file is canonical name. unxformed is given name. obj is
1988 my ($one_file, $unxformed, $obj) = @_;
1992 if (&variable_defined ($one_file . "_OBJECTS"))
1994 &am_line_error ($one_file . '_OBJECTS',
1995 $one_file . '_OBJECTS', 'should not be defined');
1996 # No point in continuing.
2001 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
2002 'dist_EXTRA_', 'nodist_EXTRA_')
2004 my $var = $prefix . $one_file . "_SOURCES";
2006 if !variable_defined ($var);
2008 # We are going to define _OBJECTS variables using the prefix.
2009 # Then we glom them all together. So we can't use the null
2010 # prefix here as we need it later.
2011 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2013 # Keep track of which prefixes we saw.
2014 $used_pfx{$xpfx} = 1
2015 unless $prefix =~ /EXTRA_/;
2017 push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
2018 push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
2019 unless $prefix =~ /^nodist_/;
2020 foreach my $cond (variable_conditions ($var))
2022 my @files = &variable_value_as_list ($var, $cond);
2023 my ($temp, @result) =
2024 &handle_single_transform_list ($var, $one_file, $obj,
2026 # If there are no files to compile, don't require a linker (yet).
2030 # Define _OBJECTS conditionally.
2031 &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
2033 unless $prefix =~ /EXTRA_/;
2037 my @keys = sort keys %used_pfx;
2038 if (scalar @keys == 0)
2040 &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
2041 push (@sources, $unxformed . '.c');
2042 push (@dist_sources, $unxformed . '.c');
2044 my ($temp, @result) =
2045 &handle_single_transform_list ($one_file . '_SOURCES',
2048 $linker = $temp if $linker eq '';
2049 &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
2053 grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
2054 &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
2057 # If we want to use `LINK' we must make sure it is defined.
2067 # handle_lib_objects ($XNAME, $VAR)
2068 # ---------------------------------
2069 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
2070 # Also, generate _DEPENDENCIES variable if appropriate.
2072 # transformed name of object being built, or empty string if no object
2073 # name of _LDADD/_LIBADD-type variable to examine
2074 # Returns 1 if LIBOBJS seen, 0 otherwise.
2075 sub handle_lib_objects
2077 my ($xname, $var) = @_;
2079 &prog_error ("handle_lib_objects: $var undefined")
2080 if ! &variable_defined ($var);
2083 foreach my $cond (&variable_conditions ($var))
2085 if (&handle_lib_objects_cond ($xname, $var, $cond))
2093 # Subroutine of handle_lib_objects: handle a particular condition.
2094 sub handle_lib_objects_cond
2096 my ($xname, $var, $cond) = @_;
2098 # We recognize certain things that are commonly put in LIBADD or
2102 my $seen_libobjs = 0;
2105 foreach my $lsearch (&variable_value_as_list ($var, $cond))
2107 # Skip -lfoo and -Ldir; these are explicitly allowed.
2108 next if $lsearch =~ /^-[lL]/;
2109 if (! $flagvar && $lsearch =~ /^-/)
2111 if ($var =~ /^(.*)LDADD$/)
2113 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
2114 next if $lsearch =~ /^-dl(pre)?open$/;
2115 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2119 # Only get this error once.
2121 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2125 # Assume we have a file of some sort, and push it onto the
2126 # dependency list. Autoconf substitutions are not pushed;
2127 # rarely is a new dependency substituted into (eg) foo_LDADD
2128 # -- but "bad things (eg -lX11) are routinely substituted.
2129 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2130 # and handled specially below.
2131 push (@dep_list, $lsearch)
2132 unless $lsearch =~ /^\@.*\@$/;
2134 # Automatically handle @LIBOBJS@ and @ALLOCA@. Basically this
2135 # means adding entries to dep_files.
2136 if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
2138 my $myobjext = ($1 ? 'l' : '') . 'o';
2140 push (@dep_list, $lsearch);
2142 if (! keys %libsources
2143 && ! &variable_defined ($1 . 'LIBOBJS'))
2145 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in `$configure_ac'");
2148 foreach my $iter (keys %libsources)
2150 if ($iter =~ /\.([cly])$/)
2152 &saw_extension ($1);
2153 &saw_extension ('c');
2156 if ($iter =~ /\.h$/)
2158 &require_file_with_line ($var, $FOREIGN, $iter);
2160 elsif ($iter ne 'alloca.c')
2162 my $rewrite = $iter;
2163 $rewrite =~ s/\.c$/.P$myobjext/;
2164 $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
2165 ($rewrite = $iter) =~ s/(\W)/\\$1/g;
2166 $rewrite = "^" . $rewrite . "\$";
2167 # Only require the file if it is not a built source.
2168 if (! &variable_defined ('BUILT_SOURCES')
2169 || ! grep (/$rewrite/,
2170 &variable_value_as_list ('BUILT_SOURCES',
2173 &require_file_with_line ($var, $FOREIGN, $iter);
2178 elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
2180 my $myobjext = ($1 ? 'l' : '') . 'o';
2182 push (@dep_list, $lsearch);
2183 &am_line_error ($var,
2184 "\@$1" . "ALLOCA\@ seen but `AC_FUNC_ALLOCA' not in `$configure_ac'")
2185 if ! defined $libsources{'alloca.c'};
2186 $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
2187 &require_file_with_line ($var, $FOREIGN, 'alloca.c');
2188 &saw_extension ('c');
2192 if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
2194 &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
2197 return $seen_libobjs;
2200 # Canonicalize the input parameter
2204 $string =~ tr/A-Za-z0-9_\@/_/c;
2208 # Canonicalize a name, and check to make sure the non-canonical name
2209 # is never used. Returns canonical name. Arguments are name and a
2210 # list of suffixes to check for.
2211 sub check_canonical_spelling
2213 my ($name, @suffixes) = @_;
2215 my $xname = &canonicalize ($name);
2216 if ($xname ne $name)
2218 foreach my $xt (@suffixes)
2220 &am_line_error ("$name$xt",
2221 "invalid variable `$name$xt'; "
2222 . "should be `$xname$xt'")
2223 if &variable_defined ("$name$xt");
2233 # Set up the compile suite.
2234 sub handle_compile ()
2237 unless $get_object_extension_was_run;
2240 my $default_includes = '';
2241 if (! defined $options{'nostdinc'})
2243 $default_includes = ' -I. -I$(srcdir)';
2245 if (&variable_defined ('CONFIG_HEADER'))
2247 foreach my $hdr (split (' ', &variable_value ('CONFIG_HEADER')))
2249 $default_includes .= ' -I' . dirname ($hdr);
2254 my (@mostly_rms, @dist_rms);
2255 foreach my $item (sort keys %compile_clean_files)
2257 if ($compile_clean_files{$item} == $MOSTLY_CLEAN)
2259 push (@mostly_rms, "\t-rm -f $item");
2261 elsif ($compile_clean_files{$item} == $DIST_CLEAN)
2263 push (@dist_rms, "\t-rm -f $item");
2267 &prog_error ("invalid entry in \%compile_clean_files");
2271 my ($coms, $vars, $rules) =
2272 &file_contents_internal (1, "$libdir/am/compile.am",
2273 ('DEFAULT_INCLUDES' => $default_includes,
2274 'MOSTLYRMS' => join ("\n", @mostly_rms),
2275 'DISTRMS' => join ("\n", @dist_rms)));
2276 $output_vars .= $vars;
2277 $output_rules .= "$coms$rules";
2281 # Output the libtool compilation rules.
2282 $output_rules .= &file_contents ('libtool');
2285 # Check for automatic de-ANSI-fication.
2286 if (defined $options{'ansi2knr'})
2288 if (! $am_c_prototypes)
2290 &am_line_error ('AUTOMAKE_OPTIONS',
2291 "option `ansi2knr' in use but `AM_C_PROTOTYPES' not in `$configure_ac'");
2292 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
2293 # Only give this error once.
2294 $am_c_prototypes = 1;
2297 # topdir is where ansi2knr should be.
2298 if ($options{'ansi2knr'} eq 'ansi2knr')
2300 # Only require ansi2knr files if they should appear in
2302 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
2303 'ansi2knr.c', 'ansi2knr.1');
2305 # ansi2knr needs to be built before subdirs, so unshift it.
2306 unshift (@all, '$(ANSI2KNR)');
2309 my $ansi2knr_dir = '';
2310 $ansi2knr_dir = dirname ($options{'ansi2knr'})
2311 if $options{'ansi2knr'} ne 'ansi2knr';
2313 $output_rules .= &file_contents ('ansi2knr',
2314 ('ANSI2KNR-DIR' => $ansi2knr_dir));
2321 # handle_programs ()
2322 # ------------------
2323 # Handle C programs.
2326 my @proglist = &am_install_var ('progs', 'PROGRAMS',
2327 'bin', 'sbin', 'libexec', 'pkglib',
2329 return if ! @proglist;
2331 my $seen_libobjs = 0;
2332 foreach my $one_file (@proglist)
2334 my $obj = &get_object_extension ($one_file);
2336 # Canonicalize names and check for misspellings.
2337 my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2338 '_SOURCES', '_OBJECTS',
2341 my $linker = &handle_source_transform ($xname, $one_file, $obj);
2344 if (&variable_defined ($xname . "_LDADD"))
2346 if (&handle_lib_objects ($xname, $xname . '_LDADD'))
2354 # User didn't define prog_LDADD override. So do it.
2355 &define_variable ($xname . '_LDADD', '$(LDADD)');
2357 # This does a bit too much work. But we need it to
2358 # generate _DEPENDENCIES when appropriate.
2359 if (&variable_defined ('LDADD'))
2361 if (&handle_lib_objects ($xname, 'LDADD'))
2366 elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
2368 &define_variable ($xname . '_DEPENDENCIES', '');
2373 if (&variable_defined ($xname . '_LIBADD'))
2375 &am_line_error ($xname . '_LIBADD',
2376 "use `" . $xname . "_LDADD', not `"
2377 . $xname . "_LIBADD'");
2380 if (! &variable_defined ($xname . '_LDFLAGS'))
2382 # Define the prog_LDFLAGS variable.
2383 &define_variable ($xname . '_LDFLAGS', '');
2386 # Determine program to use for link.
2388 if (&variable_defined ($xname . '_LINK'))
2390 $xlink = $xname . '_LINK';
2394 $xlink = $linker ? $linker : 'LINK';
2397 $output_rules .= &file_contents ('program',
2398 ('PROGRAM' => $one_file,
2399 'XPROGRAM' => $xname,
2400 'XLINK' => $xlink));
2403 if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD'))
2410 foreach my $one_file (@proglist)
2412 my $xname = &canonicalize ($one_file);
2414 if (&variable_defined ($xname . '_LDADD'))
2416 &check_libobjs_sources ($xname, $xname . '_LDADD');
2418 elsif (&variable_defined ('LDADD'))
2420 &check_libobjs_sources ($xname, 'LDADD');
2427 # handle_libraries ()
2428 # -------------------
2430 sub handle_libraries
2432 my @liblist = &am_install_var ('libs', 'LIBRARIES',
2433 'lib', 'pkglib', 'noinst', 'check');
2434 return if ! @liblist;
2436 my %valid = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2438 if (! defined $configure_vars{'RANLIB'})
2440 foreach my $key (keys %valid)
2442 if (&variable_defined ($key . '_LIBRARIES'))
2444 &am_line_error ($key . '_LIBRARIES', "library used but `RANLIB' not defined in `$configure_ac'");
2445 # Only get this error once. If this is ever printed,
2447 $configure_vars{'RANLIB'} = 'BUG';
2453 my $seen_libobjs = 0;
2454 foreach my $onelib (@liblist)
2456 # Check that the library fits the standard naming convention.
2457 if ($onelib !~ /^lib.*\.a$/)
2459 # FIXME should put line number here. That means mapping
2460 # from library name back to variable name.
2461 &am_error ("`$onelib' is not a standard library name");
2464 my $obj = &get_object_extension ($onelib);
2466 # Canonicalize names and check for misspellings.
2467 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2468 '_OBJECTS', '_DEPENDENCIES',
2471 if (! &variable_defined ($xlib . '_AR'))
2473 &define_variable ($xlib . '_AR', '$(AR) cru');
2476 if (&variable_defined ($xlib . '_LIBADD'))
2478 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2485 # Generate support for conditional object inclusion in
2487 &define_variable ($xlib . "_LIBADD", '');
2490 if (&variable_defined ($xlib . '_LDADD'))
2492 &am_line_error ($xlib . '_LDADD',
2493 "use `" . $xlib . "_LIBADD', not `"
2494 . $xlib . "_LDADD'");
2497 # Make sure we at look at this.
2498 &examine_variable ($xlib . '_DEPENDENCIES');
2500 &handle_source_transform ($xlib, $onelib, $obj);
2502 $output_rules .= &file_contents ('library',
2503 ('LIBRARY' => $onelib,
2504 'XLIBRARY' => $xlib));
2509 foreach my $onelib (@liblist)
2511 my $xlib = &canonicalize ($onelib);
2512 if (&variable_defined ($xlib . '_LIBADD'))
2514 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2521 # handle_ltlibraries ()
2522 # ---------------------
2523 # Handle shared libraries.
2524 sub handle_ltlibraries
2526 my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2527 'noinst', 'lib', 'pkglib', 'check');
2528 return if ! @liblist;
2531 my %valid = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2534 foreach my $key (keys %valid)
2536 if (&variable_defined ($key . '_LTLIBRARIES'))
2540 &am_line_error ($key . '_LTLIBRARIES', "library used but `LIBTOOL' not defined in `$configure_ac'");
2541 # Only get this error once. If this is ever printed,
2543 $configure_vars{'LIBTOOL'} = 'BUG';
2547 # Get the installation directory of each library.
2548 for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
2552 &am_error ("`$_' is already going to be installed in `$instdirs{$_}'");
2556 $instdirs{$_} = $key;
2562 my $seen_libobjs = 0;
2563 foreach my $onelib (@liblist)
2565 my $obj = &get_object_extension ($onelib);
2567 # Canonicalize names and check for misspellings.
2568 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2569 '_SOURCES', '_OBJECTS',
2572 if (! &variable_defined ($xlib . '_LDFLAGS'))
2574 # Define the lib_LDFLAGS variable.
2575 &define_variable ($xlib . '_LDFLAGS', '');
2578 # Check that the library fits the standard naming convention.
2579 my $libname_rx = "^lib.*\.la";
2580 if ((&variable_defined ($xlib . '_LDFLAGS')
2581 && grep (/-module/, &variable_value_as_list ($xlib . '_LDFLAGS',
2583 || (&variable_defined ('LDFLAGS')
2584 && grep (/-module/, &variable_value_as_list ('LDFLAGS',
2587 # Relax name checking for libtool modules.
2588 $libname_rx = "\.la";
2590 if ($onelib !~ /$libname_rx$/)
2592 # FIXME this should only be a warning for foreign packages
2593 # FIXME should put line number here. That means mapping
2594 # from library name back to variable name.
2595 &am_error ("`$onelib' is not a standard libtool library name");
2598 if (&variable_defined ($xlib . '_LIBADD'))
2600 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2607 # Generate support for conditional object inclusion in
2609 &define_variable ($xlib . "_LIBADD", '');
2612 if (&variable_defined ($xlib . '_LDADD'))
2614 &am_line_error ($xlib . '_LDADD',
2615 "use `" . $xlib . "_LIBADD', not `"
2616 . $xlib . "_LDADD'");
2619 # Make sure we at look at this.
2620 &examine_variable ($xlib . '_DEPENDENCIES');
2622 my $linker = &handle_source_transform ($xlib, $onelib, $obj);
2624 # Determine program to use for link.
2626 if (&variable_defined ($xlib . '_LINK'))
2628 $xlink = $xlib . '_LINK';
2632 $xlink = $linker ? $linker : 'LINK';
2636 if ($instdirs{$onelib} eq 'EXTRA'
2637 || $instdirs{$onelib} eq 'noinst'
2638 || $instdirs{$onelib} eq 'check')
2640 # It's an EXTRA_ library, so we can't specify -rpath,
2641 # because we don't know where the library will end up.
2642 # The user probably knows, but generally speaking automake
2643 # doesn't -- and in fact configure could decide
2644 # dynamically between two different locations.
2649 $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
2652 $output_rules .= &file_contents ('ltlibrary',
2653 ('LTLIBRARY' => $onelib,
2654 'XLTLIBRARY' => $xlib,
2656 'XLINK' => $xlink));
2661 foreach my $onelib (@liblist)
2663 my $xlib = &canonicalize ($onelib);
2664 if (&variable_defined ($xlib . '_LIBADD'))
2666 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2672 # See if any _SOURCES variable were misspelled. Also, make sure that
2673 # EXTRA_ variables don't contain configure substitutions.
2676 foreach my $varname (keys %var_value)
2678 foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
2681 if ($varname =~ /$primary$/ && ! $content_seen{$varname})
2683 &am_line_error ($varname,
2684 "invalid unused variable name: `$varname'");
2693 # NOTE we no longer automatically clean SCRIPTS, because it is
2694 # useful to sometimes distribute scripts verbatim. This happens
2695 # eg in Automake itself.
2696 &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2697 'bin', 'sbin', 'libexec', 'pkgdata',
2700 my $scripts_installed = 0;
2701 # Set $scripts_installed if appropriate. Make sure we only find
2702 # scripts which are actually installed -- this is why we can't
2703 # simply use the return value of am_install_var.
2704 my %valid = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
2705 'libexec', 'pkgdata',
2707 foreach my $key (keys %valid)
2709 if ($key ne 'noinst'
2711 && &variable_defined ($key . '_SCRIPTS'))
2713 $scripts_installed = 1;
2714 # push (@check_tests, 'check-' . $key . 'SCRIPTS');
2720 # ($OUTFILE, $VFILE, @CLEAN_FILES)
2721 # &scan_texinfo_file ($FILENAME)
2722 # ------------------------------
2723 # $OUTFILE is the name of the info file produced by $FILENAME.
2724 # $VFILE is the name of the version.texi file used (empty if none).
2725 # @CLEAN_FILES is the list of by products (indexes etc.)
2726 sub scan_texinfo_file
2728 my ($filename) = @_;
2730 # These are always created, no matter whether indexes are used or not.
2731 my @clean_suffixes = ('aux', 'dvi', 'log', 'ps', 'toc',
2732 # grep new.*index texinfo.tex
2733 'cp', 'fn', 'ky', 'vr', 'tp', 'pg');
2735 # There are predefined indexes which don't follow the regular rules.
2736 my %predefined_index =
2739 'c' => 'cps', 'f' => 'fns', 'k' => 'kys',
2740 'v' => 'vrs', 't' => 'tps', 'p' => 'pgs'
2743 # There are commands which include a hidden index command.
2747 'fn' => 'fns', 'un' => 'fns',
2748 'typefn' => 'fns', 'typefun' => 'fns',
2749 'mac' => 'fns', 'spec' => 'fns',
2750 'op' => 'fns', 'typeop' => 'fns',
2751 'method' => 'fns', 'typemethod' => 'fns',
2753 'vr' => 'vrs', 'var' => 'vrs',
2754 'typevr' => 'vrs', 'typevar' => 'vrs',
2757 'ivar' => 'vrs', 'typeivar' => 'vrs',
2762 # Indexes stored into another one. In this case, the *.??s file
2764 my @syncodeindexes = ();
2766 my $texi = new IO::File ("< $filename");
2769 &am_error ("couldn't open `$filename': $!");
2772 print "$me: reading $filename\n" if $verbose;
2774 my ($outfile, $vfile);
2775 while ($_ = $texi->getline)
2777 if (/^\@setfilename +(\S+)/)
2780 if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
2782 &am_file_error ($filename, "$.: ",
2783 "output `$outfile' has unrecognized extension");
2787 # A "version.texi" file is actually any file whose name
2788 # matches "vers*.texi".
2789 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2794 # Try to find what are the indexes which are used.
2796 # Creating a new category of index.
2797 elsif (/^\@def(code)?index (\w+)/)
2799 push @clean_suffixes, $2;
2802 # Storing in a predefined index.
2803 elsif (/^\@([cfkvtp])index /)
2805 push @clean_suffixes, $predefined_index{$1};
2807 elsif (/^\@def(\w+) /)
2809 push @clean_suffixes, $hidden_index{$1}
2810 if defined $hidden_index{$1};
2813 # Merging an index into an another.
2814 elsif (/^\@syn(code)?index (\w+) \w+/)
2816 push @syncodeindexes, "$2s";
2824 &am_error ("`$filename' missing \@setfilename");
2828 my $infobase = basename ($filename);
2829 $infobase =~ s/\.te?xi(nfo)?$//;
2830 # FIXME: I don't understand why, but I can't use "$infobase.$_" => 1.
2831 my %clean_files = map { "$infobase" . ".$_" => 1 } @clean_suffixes;
2832 grep { delete $clean_files{"$infobase.$_"} } @syncodeindexes;
2833 return ($outfile, $vfile, (sort keys %clean_files));
2837 # ($DO-SOMETHING, $TEXICLEANS)
2838 # handle_texinfo_helper ()
2840 # Handle all Texinfo source; helper for handle_texinfo
2841 sub handle_texinfo_helper
2843 &am_line_error ('TEXINFOS',
2844 "`TEXINFOS' is an anachronism; use `info_TEXINFOS'")
2845 if &variable_defined ('TEXINFOS');
2846 return (0, '') if (! &variable_defined ('info_TEXINFOS')
2847 && ! &variable_defined ('html_TEXINFOS'));
2849 if (&variable_defined ('html_TEXINFOS'))
2851 &am_line_error ('html_TEXINFOS',
2852 "HTML generation not yet supported");
2856 my @texis = &variable_value_as_list ('info_TEXINFOS', 'all');
2858 my (@info_deps_list, @dvis_list, @texi_deps);
2865 foreach my $info_cursor (@texis)
2867 my $infobase = $info_cursor;
2868 $infobase =~ s/\.(txi|texinfo|texi)$//;
2870 if ($infobase eq $info_cursor)
2872 # FIXME: report line number.
2873 &am_error ("texinfo file `$info_cursor' has unrecognized extension");
2876 $texi_suffixes{$1} = 1;
2878 # If 'version.texi' is referenced by input file, then include
2879 # automatic versioning capability.
2880 my ($out_file, $vtexi, @clean_files) =
2881 &scan_texinfo_file ("$relative_dir/$info_cursor")
2883 push (@texi_cleans, @clean_files);
2887 &am_error ("`$vtexi', included in `$info_cursor', also included in `$versions{$vtexi}'")
2888 if (defined $versions{$vtexi});
2889 $versions{$vtexi} = $info_cursor;
2891 # We number the stamp-vti files. This is doable since the
2892 # actual names don't matter much. We only number starting
2893 # with the second one, so that the common case looks nice.
2894 my $vti = ($done ? $done : 'vti');
2897 # This is ugly, but it is our historical practice.
2898 if ($config_aux_dir_set_in_configure_in)
2900 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2905 &require_file_with_line ('info_TEXINFOS', $FOREIGN,
2910 if ($config_aux_dir_set_in_configure_in)
2912 $conf_dir = $config_aux_dir;
2913 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
2917 $conf_dir = '$(srcdir)/';
2919 $output_rules .= &file_contents ('texi-vers',
2920 ('TEXI' => $info_cursor,
2923 'MDDIR' => $conf_dir));
2926 # If user specified file_TEXINFOS, then use that as explicit
2929 push (@texi_deps, $info_cursor);
2930 # Prefix with $(srcdir) because some version of make won't
2931 # work if the target has it and the dependency doesn't.
2932 push (@texi_deps, '$(srcdir)/' . $vtexi) if $vtexi;
2934 my $canonical = &canonicalize ($infobase);
2935 if (&variable_defined ($canonical . "_TEXINFOS"))
2937 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
2938 &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
2941 $output_rules .= ("\n" . $out_file . ": "
2942 . join (' ', @texi_deps)
2943 . "\n" . $infobase . ".dvi: "
2944 . join (' ', @texi_deps)
2947 push (@info_deps_list, $out_file);
2948 push (@dvis_list, $infobase . '.dvi');
2951 # Handle location of texinfo.tex.
2952 my $need_texi_file = 0;
2956 $texinfodir = '$(top_srcdir)/../texinfo';
2957 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
2959 elsif ($config_aux_dir_set_in_configure_in)
2961 $texinfodir = $config_aux_dir;
2962 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
2963 $need_texi_file = 2; # so that we require_conf_file later
2965 elsif (&variable_defined ('TEXINFO_TEX'))
2967 # The user defined TEXINFO_TEX so assume he knows what he is
2969 $texinfodir = ('$(srcdir)/'
2970 . dirname (&variable_value ('TEXINFO_TEX')));
2974 $texinfodir = '$(srcdir)';
2975 $need_texi_file = 1;
2978 foreach my $txsfx (sort keys %texi_suffixes)
2980 $output_rules .= &file_contents ('texibuild',
2981 ('TEXINFODIR' => $texinfodir,
2982 'SUFFIX' => $txsfx));
2986 my $texiclean = &pretty_print_internal ("", "\t ", @texi_cleans);
2988 push (@dist_targets, 'dist-info');
2990 if (! defined $options{'no-installinfo'})
2992 # Make sure documentation is made and installed first. Use
2993 # $(INFO_DEPS), not 'info', because otherwise recursive makes
2994 # get run twice during "make all".
2995 unshift (@all, '$(INFO_DEPS)');
2998 &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2999 &define_variable ("DVIS", join (' ', @dvis_list));
3000 # This next isn't strictly needed now -- the places that look here
3001 # could easily be changed to look in info_TEXINFOS. But this is
3002 # probably better, in case noinst_TEXINFOS is ever supported.
3003 &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
3005 # Do some error checking. Note that this file is not required
3006 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
3008 if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
3010 if ($need_texi_file > 1)
3012 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
3017 &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
3021 return (1, $texiclean);
3026 # Handle all Texinfo source.
3029 my ($do_something, $texiclean) = handle_texinfo_helper ();
3030 $output_rules .= &file_contents ('texinfos',
3031 ('TEXICLEAN' => $texiclean,
3032 'LOCAL-TEXIS' => $do_something));
3035 # Handle any man pages.
3036 sub handle_man_pages
3038 &am_line_error ('MANS', "`MANS' is an anachronism; use `man_MANS'")
3039 if &variable_defined ('MANS');
3041 # Find all the sections in use. We do this by first looking for
3042 # "standard" sections, and then looking for any additional
3043 # sections used in man_MANS.
3044 my (%sections, %vlist);
3045 # We handle nodist_ for uniformity. man pages aren't distributed
3046 # by default so it isn't actually very important.
3047 foreach my $pfx ('', 'dist_', 'nodist_')
3049 # Add more sections as needed.
3050 foreach my $section ('0'..'9', 'n', 'l')
3052 if (&variable_defined ($pfx . 'man' . $section . '_MANS'))
3054 $sections{$section} = 1;
3055 $vlist{'$(' . $pfx . 'man' . $section . '_MANS)'} = 1;
3057 &push_dist_common ('$(' . $pfx . 'man' . $section . '_MANS)')
3062 if (&variable_defined ($pfx . 'man_MANS'))
3064 $vlist{'$(' . $pfx . 'man_MANS)'} = 1;
3065 foreach (&variable_value_as_list ($pfx . 'man_MANS', 'all'))
3067 # A page like `foo.1c' goes into man1dir.
3068 if (/\.([0-9a-z])([a-z]*)$/)
3074 &push_dist_common ('$(' . $pfx . 'man_MANS)')
3079 return unless %sections;
3081 # Now for each section, generate an install and unintall rule.
3082 # Sort sections so output is deterministic.
3083 foreach my $section (sort keys %sections)
3085 $output_rules .= &file_contents ('mans', ('SECTION' => $section));
3088 $output_vars .= &file_contents ('mans-vars',
3089 ('MANS' => join (' ', sort keys %vlist)));
3091 if (! defined $options{'no-installman'})
3093 push (@all, '$(MANS)');
3097 # Handle DATA variables.
3100 &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3101 'data', 'sysconf', 'sharedstate', 'localstate',
3102 'pkgdata', 'noinst', 'check');
3109 if (&variable_defined ('SUBDIRS'))
3111 $output_rules .= ("tags-recursive:\n"
3112 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3113 # Never fail here if a subdir fails; it
3115 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3116 . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3118 push (@tag_deps, 'tags-recursive');
3119 &depend ('.PHONY', 'tags-recursive');
3122 if (&saw_sources_p (1)
3123 || &variable_defined ('ETAGS_ARGS')
3127 foreach my $one_hdr (@config_headers)
3129 if ($relative_dir eq dirname ($one_hdr))
3131 # The config header is in this directory. So require it.
3132 $config .= ' ' if $config;
3133 $config .= basename ($one_hdr);
3136 $output_rules .= &file_contents ('tags',
3137 ('CONFIG' => $config,
3138 'DIRS' => join (' ', @tag_deps)));
3139 &examine_variable ('TAGS_DEPENDENCIES');
3141 elsif (&variable_defined ('TAGS_DEPENDENCIES'))
3143 &am_line_error ('TAGS_DEPENDENCIES',
3144 "doesn't make sense to define `TAGS_DEPENDENCIES' without sources or `ETAGS_ARGS'");
3148 # Every Makefile must define some sort of TAGS rule.
3149 # Otherwise, it would be possible for a top-level "make TAGS"
3150 # to fail because some subdirectory failed.
3151 $output_rules .= "tags: TAGS\nTAGS:\n\n";
3155 # Handle multilib support.
3158 if ($seen_multilib && $relative_dir eq '.')
3160 $output_rules .= &file_contents ('multilib');
3166 # &for_dist_common ($A, $B)
3167 # -------------------------
3168 # Subroutine for &handle_dist: sort files to dist.
3170 # We put README first because it then becomes easier to make a
3171 # Usenet-compliant shar file (in these, README must be first).
3173 # FIXME: do more ordering of files here.
3186 # handle_dist ($MAKEFILE)
3187 # -----------------------
3188 # Handle 'dist' target.
3191 my ($makefile) = @_;
3193 # `make dist' isn't used in a Cygnus-style tree.
3194 # Omit the rules so that people don't try to use them.
3195 return if $cygnus_mode;
3197 # Look for common files that should be included in distribution.
3198 foreach my $cfile (@common_files)
3200 if (-f ($relative_dir . "/" . $cfile))
3202 &push_dist_common ($cfile);
3206 # We might copy elements from $configure_dist_common to
3207 # %dist_common if we think we need to. If the file appears in our
3208 # directory, we would have discovered it already, so we don't
3209 # check that. But if the file is in a subdir without a Makefile,
3210 # we want to distribute it here if we are doing `.'. Ugly!
3211 if ($relative_dir eq '.')
3213 foreach my $file (split (' ' , $configure_dist_common))
3215 if (! &is_make_dir (dirname ($file)))
3217 &push_dist_common ($file);
3224 # Files to distributed. Don't use &variable_value_as_list
3225 # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3226 check_variable_defined_unconditionally ('DIST_COMMON');
3227 my @dist_common = split (' ', variable_value ('DIST_COMMON', 'TRUE'));
3228 @dist_common = uniq (sort for_dist_common (@dist_common));
3229 pretty_print ('DIST_COMMON = ', "\t", @dist_common);
3231 # Now that we've processed DIST_COMMON, disallow further attempts
3233 $handle_dist_run = 1;
3235 # Scan EXTRA_DIST to see if we need to distribute anything from a
3236 # subdir. If so, add it to the list. I didn't want to do this
3237 # originally, but there were so many requests that I finally
3239 if (&variable_defined ('EXTRA_DIST'))
3241 # FIXME: This should be fixed to work with conditionals. That
3242 # will require only making the entries in %dist_dirs under the
3243 # appropriate condition. This is meaningful if the nature of
3244 # the distribution should depend upon the configure options
3246 foreach (&variable_value_as_list ('EXTRA_DIST', ''))
3249 next unless s,/+[^/]+$,,;
3255 # We have to check DIST_COMMON for extra directories in case the
3256 # user put a source used in AC_OUTPUT into a subdir.
3257 foreach (&variable_value_as_list ('DIST_COMMON', 'all'))
3260 next unless s,/+[^/]+$,,;
3265 # Rule to check whether a distribution is viable.
3266 my %transform = ('DISTCHECK-HOOK' => &target_defined ('distcheck-hook'),
3267 'GETTEXT' => $seen_gettext);
3269 # Prepend $(distdir) to each directory given.
3270 my %rewritten = map { '$(distdir)/' . "$_" => 1 } keys %dist_dirs;
3271 $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);
3273 # If we have SUBDIRS, create all dist subdirectories and do
3275 if (&variable_defined ('SUBDIRS'))
3277 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3278 # to all possible directories, and use it. If DIST_SUBDIRS is
3279 # defined, just use it.
3280 my $dist_subdir_name;
3281 # Note that we check DIST_SUBDIRS first on purpose. At least
3282 # one project uses so many conditional subdirectories that
3283 # calling variable_conditionally_defined on SUBDIRS will cause
3284 # automake to grow to 150Mb. Sigh.
3285 if (&variable_defined ('DIST_SUBDIRS')
3286 || variable_conditionally_defined ('SUBDIRS'))
3288 $dist_subdir_name = 'DIST_SUBDIRS';
3289 if (! &variable_defined ('DIST_SUBDIRS'))
3291 &define_pretty_variable
3292 ('DIST_SUBDIRS', '',
3293 uniq (&variable_value_as_list ('SUBDIRS', 'all')));
3298 $dist_subdir_name = 'SUBDIRS';
3299 # We always define this because that is what `distclean'
3301 &define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
3304 $transform{'DIST_SUBDIR_NAME'} = $dist_subdir_name;
3307 # If the target `dist-hook' exists, make sure it is run. This
3308 # allows users to do random weird things to the distribution
3309 # before it is packaged up.
3310 push (@dist_targets, 'dist-hook')
3311 if &target_defined ('dist-hook');
3312 $transform{'DIST-TARGETS'} = join(' ', @dist_targets);
3314 # Defining $(DISTDIR).
3315 $transform{'DISTDIR'} = !&variable_defined('distdir');
3316 $transform{'TOP_DISTDIR'} = backname ($relative_dir);
3318 $output_rules .= &file_contents ('distdir', %transform);
3322 # Handle subdirectories.
3326 unless &variable_defined ('SUBDIRS');
3328 # Make sure each directory mentioned in SUBDIRS actually exists.
3329 foreach my $dir (&variable_value_as_list ('SUBDIRS', 'all'))
3331 # Skip directories substituted by configure.
3332 next if $dir =~ /^\@.*\@$/;
3334 if (! -d $am_relative_dir . '/' . $dir)
3336 &am_line_error ('SUBDIRS',
3337 "required directory $am_relative_dir/$dir does not exist");
3341 &am_line_error ('SUBDIRS', "directory should not contain `/'")
3345 $output_rules .= &file_contents ('subdirs');
3346 variable_pretty_output ('RECURSIVE_TARGETS', 'TRUE');
3350 # ($REGEN, @DEPENDENCIES)
3353 # If aclocal.m4 creation is automated, return the list of its dependencies.
3356 my $regen_aclocal = 0;
3359 unless $relative_dir eq '.';
3361 &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3362 &examine_variable ('CONFIGURE_DEPENDENCIES');
3364 if (-f 'aclocal.m4')
3366 &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3367 &push_dist_common ('aclocal.m4');
3369 my $aclocal = new IO::File ("< aclocal.m4");
3372 my $line = $aclocal->getline;
3375 if ($line =~ 'generated automatically by aclocal')
3384 if (-f 'acinclude.m4')
3387 push @ac_deps, 'acinclude.m4';
3390 if (&variable_defined ('ACLOCAL_M4_SOURCES'))
3392 push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3394 elsif (&variable_defined ('ACLOCAL_AMFLAGS'))
3396 # Scan all -I directories for m4 files. These are our
3398 my $examine_next = 0;
3399 foreach my $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
3404 if ($amdir !~ /^\// && -d $amdir)
3406 foreach my $ac_dep (&my_glob ($amdir . '/*.m4'))
3408 $ac_dep =~ s/^\.\/+//;
3409 push (@ac_deps, $ac_dep)
3410 unless $ac_dep eq "aclocal.m4"
3411 || $ac_dep eq "acinclude.m4";
3415 elsif ($amdir eq '-I')
3422 # Note that it might be possible that aclocal.m4 doesn't exist but
3423 # should be auto-generated. This case probably isn't very
3426 return ($regen_aclocal, @ac_deps);
3429 # Rewrite a list of input files into a form suitable to put on a
3430 # dependency list. The idea is that if an input file has a directory
3431 # part the same as the current directory, then the directory part is
3432 # simply removed. But if the directory part is different, then
3433 # $(top_srcdir) is prepended. Among other things, this is used to
3434 # generate the dependency list for the output files generated by
3435 # AC_OUTPUT. Consider what the dependencies should look like in this
3437 # AC_OUTPUT(src/out:src/in1:lib/in2)
3438 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3439 # If 0 then files that require this addition will simply be ignored.
3440 sub rewrite_inputs_into_dependencies
3442 my ($add_srcdir, @inputs) = @_;
3445 foreach my $single (@inputs)
3447 if (dirname ($single) eq $relative_dir)
3449 push (@newinputs, basename ($single));
3453 push (@newinputs, '$(top_srcdir)/' . $single);
3460 # Handle remaking and configure stuff.
3461 # We need the name of the input file, to do proper remaking rules.
3462 sub handle_configure
3464 my ($local, $input, @secondary_inputs) = @_;
3466 my $input_base = basename ($input);
3467 my $local_base = basename ($local);
3469 my $amfile = $input_base . '.am';
3470 # We know we can always add '.in' because it really should be an
3471 # error if the .in was missing originally.
3472 my $infile = '$(srcdir)/' . $input_base . '.in';
3473 my $colon_infile = '';
3474 if ($local ne $input || @secondary_inputs)
3476 $colon_infile = ':' . $input . '.in';
3478 $colon_infile .= ':' . join (':', @secondary_inputs)
3479 if @secondary_inputs;
3481 my @rewritten = &rewrite_inputs_into_dependencies (1, @secondary_inputs);
3483 my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4 ();
3486 &file_contents ('configure',
3490 => join (' ', @rewritten),
3492 => ((($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3497 => join (' ', @include_stack),
3501 => $cygnus_mode ? 'cygnus' : $strictness_name,
3503 => $cmdline_use_dependencies ? '' : ' --ignore-deps',
3504 'MAKEFILE-AM-SOURCES'
3505 => "$input$colon_infile",
3507 => $regen_aclocal_m4,
3509 => join (' ', @aclocal_m4_deps)));
3511 if ($relative_dir eq '.')
3513 &push_dist_common ('acconfig.h')
3517 # If we have a configure header, require it.
3518 my @local_fullnames = @config_fullnames;
3519 my @local_names = @config_names;
3521 my $distclean_config = '';
3522 foreach my $one_hdr (@config_headers)
3524 my $one_fullname = shift (@local_fullnames);
3525 my $one_name = shift (@local_names);
3527 my $header_dir = dirname ($one_name);
3529 # If the header is in the current directory we want to build
3530 # the header here. Otherwise, if we're at the topmost
3531 # directory and the header's directory doesn't have a
3532 # Makefile, then we also want to build the header.
3533 if ($relative_dir eq $header_dir
3534 || ($relative_dir eq '.' && ! &is_make_dir ($header_dir)))
3536 my ($cn_sans_dir, $stamp_dir);
3537 if ($relative_dir eq $header_dir)
3539 $cn_sans_dir = basename ($one_name);
3544 $cn_sans_dir = $one_name;
3545 if ($header_dir eq '.')
3551 $stamp_dir = $header_dir . '/';
3555 # Compute relative path from directory holding output
3556 # header to directory holding input header. FIXME:
3557 # doesn't handle case where we have multiple inputs.
3559 if (dirname ($one_hdr) eq $relative_dir)
3561 $ch_sans_dir = basename ($one_hdr);
3565 $ch_sans_dir = backname ($relative_dir) . '/' . $one_hdr;
3568 &require_file_with_conf_line ($config_header_line,
3569 $FOREIGN, $ch_sans_dir);
3571 # Header defined and in this directory.
3573 if (-f $one_name . '.top')
3575 push (@files, "${cn_sans_dir}.top");
3577 if (-f $one_name . '.bot')
3579 push (@files, "${cn_sans_dir}.bot");
3582 &push_dist_common (@files);
3584 # For now, acconfig.h can only appear in the top srcdir.
3585 if (-f 'acconfig.h')
3587 push (@files, '$(top_srcdir)/acconfig.h');
3590 my $stamp_name = 'stamp-h';
3591 $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3593 my $out_dir = dirname ($ch_sans_dir);
3596 &file_contents ('remake-hdr',
3597 ('FILES' => join (' ', @files),
3598 'CONFIG_HEADER' => $cn_sans_dir,
3599 'CONFIG_HEADER_IN' => $ch_sans_dir,
3600 'CONFIG_HEADER_FULL' => $one_fullname,
3601 'STAMP' => "$stamp_dir$stamp_name",
3602 'SRC_STAMP' => "$out_dir/$stamp_name"));
3604 &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3605 &require_file_with_conf_line ($config_header_line, $FOREIGN,
3606 "${out_dir}/${stamp_name}.in");
3608 $distclean_config .= ' ' if $distclean_config;
3609 $distclean_config .= $cn_sans_dir;
3613 if ($distclean_config)
3615 $output_rules .= &file_contents ('clean-hdr',
3616 ('FILES' => $distclean_config));
3619 # Set location of mkinstalldirs.
3620 &define_variable ('mkinstalldirs',
3621 ('$(SHELL) ' . $config_aux_dir . '/mkinstalldirs'));
3623 &am_line_error ('CONFIG_HEADER',
3624 "`CONFIG_HEADER' is an anachronism; now determined from `$configure_ac'")
3625 if &variable_defined ('CONFIG_HEADER');
3627 my $config_header = '';
3628 foreach my $one_name (@config_names)
3630 # Generate CONFIG_HEADER define.
3632 if ($relative_dir eq dirname ($one_name))
3634 $one_hdr = basename ($one_name);
3638 $one_hdr = "\$(top_builddir)/${one_name}";
3641 $config_header .= ' ' if $config_header;
3642 $config_header .= $one_hdr;
3646 &define_variable ("CONFIG_HEADER", $config_header);
3649 # Now look for other files in this directory which must be remade
3650 # by config.status, and generate rules for them.
3651 my @actual_other_files = ();
3652 foreach my $lfile (@other_input_files)
3655 my (@inputs, @rewritten_inputs);
3656 my ($need_rewritten);
3657 if ($lfile =~ /^([^:]*):(.*)$/)
3659 # This is the ":" syntax of AC_OUTPUT.
3661 $local = basename ($file);
3662 @inputs = split (':', $2);
3663 @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3664 $need_rewritten = 1;
3670 $local = basename ($file);
3671 @inputs = ($file . '.in');
3673 &rewrite_inputs_into_dependencies (1, @inputs);
3674 $need_rewritten = 0;
3677 # Make sure the dist directory for each input file is created.
3678 # We only have to do this at the topmost level though. This
3679 # is a bit ugly but it easier than spreading out the logic,
3680 # especially in cases like AC_OUTPUT(foo/out:bar/in), where
3681 # there is no Makefile in bar/.
3682 if ($relative_dir eq '.')
3686 $dist_dirs{dirname ($_)} = 1;
3690 # We skip any automake input files, as they are handled
3691 # elsewhere. We also skip files that aren't in this
3692 # directory. However, if the file's directory does not have a
3693 # Makefile, and we are currently doing `.', then we create a
3694 # rule to rebuild the file in the subdir.
3695 next if -f $file . '.am';
3696 my $fd = dirname ($file);
3697 if ($fd ne $relative_dir)
3699 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
3709 # Some users have been tempted to put `stamp-h' in the
3710 # AC_OUTPUT line. This won't do the right thing, so we
3711 # explicitly fail here.
3712 if ($local eq 'stamp-h')
3714 # FIXME: allow real filename.
3715 &am_conf_error ($configure_ac, $ac_output_line,
3716 'stamp-h should not appear in AC_OUTPUT');
3720 $output_rules .= ($local . ': '
3721 . '$(top_builddir)/config.status '
3722 . join (' ', @rewritten_inputs) . "\n"
3724 . 'cd $(top_builddir) && CONFIG_FILES='
3725 . ($relative_dir eq '.' ? '' : '$(subdir)/')
3726 . '$@' . ($need_rewritten
3727 ? (':' . join (':', @inputs))
3729 . ' CONFIG_HEADERS= CONFIG_LINKS= $(SHELL) ./config.status'
3731 push (@actual_other_files, $local);
3733 # Require all input files.
3734 &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3735 &rewrite_inputs_into_dependencies (0, @inputs));
3738 # These files get removed by "make clean".
3739 &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3745 my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3746 'oldinclude', 'pkginclude',
3750 next unless /\.(.*)$/;
3751 &saw_extension ($1);
3757 return if ! $seen_gettext || $relative_dir ne '.';
3759 if (! &variable_defined ('SUBDIRS'))
3762 ("AM_GNU_GETTEXT used but SUBDIRS not defined");
3766 my @subdirs = &variable_value_as_list ('SUBDIRS', 'all');
3767 &am_line_error ('SUBDIRS',
3768 "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
3769 if ! grep ('po', @subdirs);
3770 &am_line_error ('SUBDIRS',
3771 "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
3772 if ! grep ('intl', @subdirs);
3774 &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3776 # Ensure that each language in ALL_LINGUAS has a .po file, and
3777 # each po file is mentioned in ALL_LINGUAS.
3780 my %linguas = map { $_ => 1 } split (' ', $all_linguas);
3787 &am_line_error ($all_linguas_line,
3788 ("po/$_.po exists but `$_' not in `ALL_LINGUAS'"))
3792 foreach (keys %linguas)
3794 &am_line_error ($all_linguas_line,
3795 "$_ in `ALL_LINGUAS' but po/$_.po does not exist")
3801 &am_error ("AM_GNU_GETTEXT in `$configure_ac' but `ALL_LINGUAS' not defined");
3805 # Handle footer elements.
3808 # NOTE don't use define_pretty_variable here, because
3809 # $contents{...} is already defined.
3810 $output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n\n"
3811 if variable_value ('SOURCES');
3814 &am_line_error ('.SUFFIXES',
3815 "use variable `SUFFIXES', not target `.SUFFIXES'")
3816 if target_defined ('.SUFFIXES');
3818 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3819 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
3820 # anything else, by sticking it right after the default: target.
3821 $output_header .= ".SUFFIXES:\n";
3822 if (@suffixes || &variable_defined ('SUFFIXES'))
3824 # Make sure suffixes has unique elements. Sort them to ensure
3825 # the output remains consistent. However, $(SUFFIXES) is
3826 # always at the start of the list, unsorted. This is done
3827 # because make will choose rules depending on the ordering of
3828 # suffixes, and this lets the user have some control. Push
3829 # actual suffixes, and not $(SUFFIXES). Some versions of make
3830 # do not like variable substitutions on the .SUFFIXES line.
3831 my @user_suffixes = (&variable_defined ('SUFFIXES')
3832 ? &variable_value_as_list ('SUFFIXES', '')
3835 my %suffixes = map { $_ => 1 } @suffixes;
3836 delete @suffixes{@user_suffixes};
3838 $output_header .= (".SUFFIXES: "
3839 . join (' ', @user_suffixes, sort keys %suffixes)
3843 $output_trailer .= file_contents ('footer');
3846 # Deal with installdirs target.
3847 sub handle_installdirs ()
3850 &file_contents ('install',
3852 => variable_value ('_am_installdirs') || ''));
3856 # Deal with all and all-am.
3859 my ($makefile) = @_;
3863 # Put this at the beginning for the sake of non-GNU makes. This
3864 # is still wrong if these makes can run parallel jobs. But it is
3866 unshift (@all, basename ($makefile));
3868 foreach my $one_name (@config_names)
3870 push (@all, basename ($one_name))
3871 if dirname ($one_name) eq $relative_dir;
3874 # Install `all' hooks.
3875 if (&target_defined ("all-local"))
3877 push (@all, "all-local");
3878 &depend ('.PHONY', "all-local");
3881 &pretty_print_rule ("all-am:", "\t\t", @all);
3882 &depend ('.PHONY', 'all-am', 'all');
3887 my @local_headers = ();
3888 push @local_headers, '$(BUILT_SOURCES)'
3889 if &variable_defined ('BUILT_SOURCES');
3890 foreach my $one_name (@config_names)
3892 push @local_headers, basename ($one_name)
3893 if dirname ($one_name) eq $relative_dir;
3898 # We need to make sure config.h is built before we recurse.
3899 # We also want to make sure that built sources are built
3900 # before any ordinary `all' targets are run. We can't do this
3901 # by changing the order of dependencies to the "all" because
3902 # that breaks when using parallel makes. Instead we handle
3903 # things explicitly.
3904 $output_all .= ("all: " . join (' ', @local_headers)
3906 . '$(MAKE) $(AM_MAKEFLAGS) '
3907 . (&variable_defined ('SUBDIRS')
3908 ? 'all-recursive' : 'all-am')
3913 $output_all .= "all: " . (&variable_defined ('SUBDIRS')
3914 ? 'all-recursive' : 'all-am') . "\n\n";
3919 # Handle check merge target specially.
3920 sub do_check_merge_target
3922 if (&target_defined ('check-local'))
3924 # User defined local form of target. So include it.
3925 push (@check_tests, 'check-local');
3926 &depend ('.PHONY', 'check-local');
3929 # In --cygnus mode, check doesn't depend on all.
3932 # Just run the local check rules.
3933 &pretty_print_rule ('check-am:', "\t\t", @check);
3937 # The check target must depend on the local equivalent of
3938 # `all', to ensure all the primary targets are built. Then it
3939 # must build the local check rules.
3940 $output_rules .= "check-am: all-am\n";
3941 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
3945 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
3949 &depend ('.PHONY', 'check', 'check-am');
3950 $output_rules .= ("check: "
3951 . (&variable_defined ('SUBDIRS')
3952 ? 'check-recursive' : 'check-am')
3956 # Handle all 'clean' targets.
3961 # Don't include `MAINTAINER'; it is handled specially below.
3962 foreach my $name ('MOSTLY', '', 'DIST')
3964 $transform{"${name}CLEAN"} = &variable_defined ("${name}CLEANFILES");
3967 # Built sources are automatically removed by maintainer-clean.
3968 push (@maintainer_clean_files, '$(BUILT_SOURCES)')
3969 if &variable_defined ('BUILT_SOURCES');
3970 push (@maintainer_clean_files, '$(MAINTAINERCLEANFILES)')
3971 if &variable_defined ('MAINTAINERCLEANFILES');
3973 $output_rules .= &file_contents ('clean',
3976 # Join with no space to avoid
3977 # spurious `test -z' success at
3979 => join ('', @maintainer_clean_files),
3981 # A space is required in the join here.
3982 => join (' ', @maintainer_clean_files)));
3986 # &depend ($CATEGORY, @DEPENDENDEES)
3987 # ----------------------------------
3988 # The target $CATEGORY depends on @DEPENDENDEES.
3991 my ($category, @dependendees) = @_;
3993 push (@{$dependencies{$category}}, @dependendees);
3998 # &target_cmp ($A, $B)
3999 # --------------------
4000 # Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
4013 # &handle_factored_dependencies ()
4014 # --------------------------------
4015 # Handle everything related to gathered targets.
4016 sub handle_factored_dependencies
4019 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4020 'uninstall-exec-local', 'uninstall-exec-hook')
4022 if (&target_defined ($utarg))
4025 $x =~ s/(data|exec)-//;
4026 &am_line_error ($utarg, "use `$x', not `$utarg'");
4030 if (&target_defined ('install-local'))
4032 &am_line_error ('install-local',
4033 "use `install-data-local' or `install-exec-local', "
4034 . "not `install-local'");
4037 if (!defined $options{'no-installinfo'}
4038 && &target_defined ('install-info-local'))
4040 &am_line_error ('install-info-local',
4041 "`install-info-local' target defined but "
4042 . "`no-installinfo' option not in use");
4045 # Install the -local hooks.
4046 foreach (keys %dependencies)
4048 # Hooks are installed on the -am targets.
4050 if (&target_defined ("$_-local"))
4052 depend ("$_-am", "$_-local");
4053 &depend ('.PHONY', "$_-local");
4057 # Install the -hook hooks.
4058 # FIXME: Why not be as liberal as we are with -local hooks?
4059 foreach ('install-exec', 'install-data')
4061 if (&target_defined ("$_-hook"))
4063 $actions{"$_-am"} .=
4064 ("\t\@\$(NORMAL_INSTALL)\n"
4065 . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
4069 # All the required targets are phony.
4070 depend ('.PHONY', keys %required_targets);
4072 # Actually output gathered targets.
4073 foreach (sort target_cmp keys %dependencies)
4075 # If there is nothing about this guy, skip it.
4077 unless (@{$dependencies{$_}}
4079 || $required_targets{$_});
4080 &pretty_print_rule ("$_:", "\t",
4081 uniq (sort @{$dependencies{$_}}));
4082 $output_rules .= $actions{$_}
4083 if defined $actions{$_};
4084 $output_rules .= "\n";
4089 # &handle_tests_dejagnu ()
4090 # ------------------------
4091 sub handle_tests_dejagnu
4093 push (@check_tests, 'check-DEJAGNU');
4095 # Only create site.exp rule if user hasn't already written one.
4097 file_contents ('dejagnu', ('SITE-EXP' => ! target_defined ('site.exp')));
4101 # Handle TESTS variable and other checks.
4104 if (defined $options{'dejagnu'})
4106 &handle_tests_dejagnu;
4110 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4113 "`$c' defined but `dejagnu' not in `AUTOMAKE_OPTIONS'")
4114 if &variable_defined ($c);
4118 if (&variable_defined ('TESTS'))
4120 push (@check_tests, 'check-TESTS');
4121 $output_rules .= &file_contents ('check');
4125 # Handle Emacs Lisp.
4126 sub handle_emacs_lisp
4128 my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4131 return if ! @elfiles;
4133 # Generate .elc files.
4134 my @elcfiles = map { $_ . 'c' } @elfiles;
4135 &define_pretty_variable ('ELCFILES', '', @elcfiles);
4137 push (@all, '$(ELCFILES)');
4139 &am_error ("`lisp_LISP' defined but `AM_PATH_LISPDIR' not in `$configure_ac'")
4140 if ! $seen_lispdir && &variable_defined ('lisp_LISP');
4142 &require_file_with_conf_line ('AM_PATH_LISPDIR', $FOREIGN, 'elisp-comp');
4148 my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4149 'python', 'noinst');
4150 return if ! @pyfiles;
4152 # Found some python.
4153 &am_error ("`python_PYTHON' defined but `AM_PATH_PYTHON' not in `$configure_ac'")
4154 if ! $seen_pythondir && &variable_defined ('python_PYTHON');
4156 &require_file_with_conf_line ('AM_PATH_PYTHON', $FOREIGN, 'py-compile');
4157 &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4163 my @sourcelist = &am_install_var ('-candist',
4165 'java', 'noinst', 'check');
4166 return if ! @sourcelist;
4168 my %valid = &am_primary_prefixes ('JAVA', 1,
4169 'java', 'noinst', 'check');
4172 foreach my $curs (keys %valid)
4174 if (! &variable_defined ($curs . '_JAVA') || $curs eq 'EXTRA')
4181 &am_line_error ($curs . '_JAVA',
4182 "multiple _JAVA primaries in use");
4187 push (@all, 'class' . $dir . '.stamp');
4191 # Handle some of the minor options.
4192 sub handle_minor_options
4194 if (defined $options{'readme-alpha'})
4196 if ($relative_dir eq '.')
4198 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4200 # FIXME: allow real filename.
4201 &am_conf_line_error ($configure_ac,
4202 $package_version_line,
4203 "version `$package_version' doesn't follow Gnits standards");
4205 elsif (defined $1 && -f 'README-alpha')
4207 # This means we have an alpha release. See
4208 # GNITS_VERSION_PATTERN for details.
4209 &require_file ($FOREIGN, 'README-alpha');
4215 ################################################################
4218 my @make_input_list;
4219 # &scan_autoconf_config_files ($CONFIG-FILES)
4220 # -------------------------------------------
4221 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4223 sub scan_autoconf_config_files
4225 my ($config_files) = @_;
4226 # Look at potential Makefile.am's.
4227 foreach (split ' ', $config_files)
4229 # Must skip empty string for Perl 4.
4230 next if $_ eq "\\" || $_ eq '';
4232 # Handle $local:$input syntax. Note that we ignore
4233 # every input file past the first, though we keep
4234 # those around for later.
4235 my ($local, $input, @rest) = split (/:/);
4242 # FIXME: should be error if .in is missing.
4243 $input =~ s/\.in$//;
4246 if (-f $input . '.am')
4248 # We have a file that automake should generate.
4249 push (@make_input_list, $input);
4250 $make_list{$input} = join (':', ($local, @rest));
4254 # We have a file that automake should cause to be
4255 # rebuilt, but shouldn't generate itself.
4256 push (@other_input_files, $_);
4262 # &scan_autoconf_traces ($FILENAME)
4263 # ---------------------------------
4264 # FIXME: For the time being, we don't care about the FILENAME.
4265 sub scan_autoconf_traces
4267 my ($filename) = @_;
4269 my $traces = "$ENV{amtraces} ";
4271 $traces .= ' -t AC_CONFIG_FILES';
4272 $traces .= ' -t AC_LIBSOURCE';
4273 $traces .= ' -t AC_SUBST';
4275 my $tracefh = new IO::File ("$traces |");
4278 die "$me: couldn't open `$traces': $!\n";
4280 print "$me: reading $traces\n" if $verbose;
4282 while ($_ = $tracefh->getline)
4285 my ($file, $line, $macro, @args) = split /:/;
4286 my $here = "$file:$line";
4288 # Alphabetical ordering please.
4289 if ($macro eq 'AC_CONFIG_FILES')
4291 # Look at potential Makefile.am's.
4292 &scan_autoconf_config_files ($args[0]);
4294 elsif ($macro eq 'AC_LIBSOURCE')
4296 my $source = "$args[0].c";
4297 # We should actually also `close' the sources: getopt.c
4298 # wants getopt.h etc. But actually it should be done in the
4299 # macro itself, i.e., we have to first fix Autoconf to extend
4300 # _AC_LIBOBJ_DECL and use it the in various macros.
4301 if (!defined $libsources{$source})
4303 print STDERR "traces: discovered $source\n";
4304 $libsources{$source} = $here;
4307 elsif ($macro eq 'AC_SUBST')
4309 if (!defined $configure_vars{$args[0]})
4311 print STDERR "traces: discovered AC_SUBST($args[0])\n";
4312 $configure_vars{$args[0]} = $here;
4318 || die "$me: close: $traces: $!\n";
4322 # &scan_one_autoconf_file ($FILENAME)
4323 # -----------------------------------
4324 # Scan one file for interesting things. Subroutine of
4325 # &scan_autoconf_files.
4326 sub scan_one_autoconf_file
4328 my ($filename) = @_;
4330 my $configfh = new IO::File ("< $filename");
4333 die "$me: couldn't open `$filename': $!\n";
4335 print "$me: reading $filename\n" if $verbose;
4337 my ($in_ac_output, $in_ac_replace) = (0, 0);
4338 while ($_ = $configfh->getline)
4340 # Remove comments from current line.
4344 # Skip macro definitions. Otherwise we might be confused into
4345 # thinking that a macro that was only defined was actually
4349 # Follow includes. This is a weirdness commonly in use at
4350 # Cygnus and hopefully nowhere else.
4351 if (/sinclude\((.*)\)/ && -f $1)
4353 # $_ being local, if we don't preserve it, when coming
4354 # back we will have $_ undefined, which is bad for the
4355 # the rest of this routine.
4356 my $underscore = $_;
4357 &scan_one_autoconf_file ($1);
4361 # Populate libobjs array.
4362 if (/AC_FUNC_ALLOCA/)
4364 $libsources{'alloca.c'} = 1;
4366 elsif (/AC_FUNC_GETLOADAVG/)
4368 $libsources{'getloadavg.c'} = 1;
4370 elsif (/AC_FUNC_MEMCMP/)
4372 $libsources{'memcmp.c'} = 1;
4374 elsif (/AC_STRUCT_ST_BLOCKS/)
4376 $libsources{'fileblocks.c'} = 1;
4378 elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4380 $libsources{'getopt.c'} = 1;
4381 $libsources{'getopt1.c'} = 1;
4383 elsif (/AM_FUNC_STRTOD/)
4385 $libsources{'strtod.c'} = 1;
4387 elsif (/AM_WITH_REGEX/)
4389 $libsources{'rx.c'} = 1;
4390 $libsources{'rx.h'} = 1;
4391 $libsources{'regex.c'} = 1;
4392 $libsources{'regex.h'} = 1;
4394 elsif (/AC_FUNC_MKTIME/)
4396 $libsources{'mktime.c'} = 1;
4398 elsif (/AM_FUNC_ERROR_AT_LINE/)
4400 $libsources{'error.c'} = 1;
4401 $libsources{'error.h'} = 1;
4403 elsif (/AM_FUNC_OBSTACK/)
4405 $libsources{'obstack.c'} = 1;
4406 $libsources{'obstack.h'} = 1;
4408 elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4409 || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4411 foreach my $libobj_iter (split (' ', $1))
4413 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4414 || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4415 || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4417 $libsources{$1 . '.c'} = 1;
4421 elsif (/AC_LIBOBJ\(([^)]+)\)/)
4423 $libsources{"$1.c"} = 1;
4426 if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4432 $in_ac_replace = 0 if s/[\]\)].*$//;
4433 # Remove trailing backslash.
4437 # Need to skip empty elements for Perl 4.
4439 $libsources{$_ . '.c'} = 1;
4443 if (/$obsolete_rx/o)
4446 if ($obsolete_macros{$1} ne '')
4448 $hint = '; ' . $obsolete_macros{$1};
4450 &am_conf_line_error ($filename, $., "`$1' is obsolete$hint");
4453 # Process the AC_OUTPUT and AC_CONFIG_FILES macros.
4454 if (! $in_ac_output && s/AC_(OUTPUT|CONFIG_FILES)\s*\(\[?//)
4457 $ac_output_line = $.;
4468 # Look at potential Makefile.am's.
4469 &scan_autoconf_config_files ($_);
4471 if ($closing && @make_input_list == 0 && @other_input_files == 0)
4473 &am_conf_line_error ($filename, $ac_output_line,
4474 "No files mentioned in `AC_OUTPUT'");
4479 if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4481 @config_aux_path = &unquote_m4_arg ($1);
4482 $config_aux_dir_set_in_configure_in = 1;
4485 # Check for ansi2knr.
4486 $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4488 # Check for exe extension stuff.
4492 $configure_vars{'EXEEXT'} = $filename . ':' . $.;
4498 $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4501 # Check for `-c -o' code.
4502 $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4504 # Check for NLS support.
4505 if (/AM_GNU_GETTEXT/)
4508 $ac_gettext_line = $.;
4511 # Look for ALL_LINGUAS.
4512 if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4516 $all_linguas_line = $.;
4519 # Handle configuration headers. A config header of `[$1]'
4520 # means we are actually scanning AM_CONFIG_HEADER from
4522 if (/A([CM])_CONFIG_HEADERS?\s*\((.*)\)/
4526 ($filename, $., "`automake requires `AM_CONFIG_HEADER', not `AC_CONFIG_HEADER'")
4529 $config_header_line = $.;
4530 foreach my $one_hdr (split (' ', &unquote_m4_arg ($2)))
4532 push (@config_fullnames, $one_hdr);
4533 if ($one_hdr =~ /^([^:]+):(.+)$/)
4535 push (@config_names, $1);
4536 push (@config_headers, $2);
4540 push (@config_names, $one_hdr);
4541 push (@config_headers, $one_hdr . '.in');
4546 # Handle AC_CANONICAL_*. Always allow upgrading to
4547 # AC_CANONICAL_SYSTEM, but never downgrading.
4548 $seen_canonical = $AC_CANONICAL_HOST
4549 if ! $seen_canonical
4550 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4551 $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4553 # If using X, include some extra variable definitions. NOTE
4554 # we don't want to force these into CFLAGS or anything,
4555 # because not all programs will necessarily use X.
4558 foreach my $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS',
4561 $configure_vars{$var} = $filename . ':' . $.
4565 # This macro handles several different things.
4566 if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4568 ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4569 $package_version_line = $.;
4570 $seen_init_automake = 1;
4575 $configure_vars{'LEX'} = $filename . ':' . $.;
4576 $seen_decl_yytext = 1;
4578 if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.(ac|in)$/)
4580 &am_conf_line_warning ($filename, $., "`AC_DECL_YYTEXT' is covered by `AM_PROG_LEX'");
4582 if (/AC_PROG_LEX/ && $filename =~ /configure\.(ac|in)$/)
4584 &am_conf_line_warning ($filename, $., "automake requires `AM_PROG_LEX', not `AC_PROG_LEX'");
4587 if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4589 $configure_vars{$1} = $filename . ':' . $.;
4591 if (/$AC_CHECK_PATTERN/o)
4593 $configure_vars{$3} = $filename . ':' . $.;
4595 if (/$AM_MISSING_PATTERN/o
4599 && $1 ne 'AUTOHEADER'
4600 # AM_INIT_AUTOMAKE is AM_MISSING_PROG'ing MAKEINFO. But
4601 # we handle it elsewhere.
4602 && $1 ne 'MAKEINFO')
4604 $configure_vars{$1} = $filename . ':' . $.;
4607 # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4608 # but later define it elsewhere. This is pretty hacky. We
4609 # also explicitly avoid INSTALL_SCRIPT and some other
4610 # variables because they are defined in header-vars.am.
4612 if (/$AC_SUBST_PATTERN/o
4614 && $1 ne 'INSTALL_SCRIPT'
4615 && $1 ne 'INSTALL_DATA')
4617 $configure_vars{$1} = $filename . ':' . $.;
4620 $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4621 if (/AM_MAINTAINER_MODE/)
4623 $seen_maint_mode = 1;
4624 $configure_cond{'MAINTAINER_MODE'} = 1;
4627 $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4629 if (/AM_PATH_PYTHON/)
4631 $seen_pythondir = 1;
4632 $configure_vars{'pythondir'} = $filename . ':' . $.;
4633 $configure_vars{'PYTHON'} = $filename . ':' . $.;
4636 if (/A(C|M)_PROG_LIBTOOL/)
4638 # We're not ready for this yet. People still use a
4639 # libtool with no AC_PROG_LIBTOOL. Once that is the
4640 # dominant version we can reenable this code -- but next
4641 # time by mentioning the macro in %obsolete_macros, both
4642 # here and in aclocal.in.
4644 # if (/AM_PROG_LIBTOOL/)
4646 # &am_conf_line_warning ($filename, $., "`AM_PROG_LIBTOOL' is obsolete, use `AC_PROG_LIBTOOL' instead");
4650 $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4651 $configure_vars{'RANLIB'} = $filename . ':' . $.;
4652 $configure_vars{'CC'} = $filename . ':' . $.;
4653 # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST. Make sure we
4654 # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4655 $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4658 $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4660 if (/$AM_CONDITIONAL_PATTERN/o)
4662 $configure_cond{$1} = 1;
4665 # Check for Fortran 77 intrinsic and run-time libraries.
4666 if (/AC_F77_LIBRARY_LDFLAGS/)
4668 $configure_vars{'FLIBS'} = $filename . ':' . $.;
4676 # &scan_autoconf_files ()
4677 # -----------------------
4678 # Check whether we use `configure.ac' or `configure.in'.
4679 # Scan it (and possibly `aclocal.m4') for interesting things.
4680 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
4681 sub scan_autoconf_files
4683 # Reinitialize libsources here. This isn't really necessary,
4684 # since we currently assume there is only one configure.ac. But
4685 # that won't always be the case.
4688 warn "$me: both `configure.ac' and `configure.in' present:"
4689 . " ignoring `configure.in'\n"
4690 if -f 'configure.ac' && -f 'configure.in';
4691 $configure_ac = 'configure.in'
4692 if -f 'configure.in';
4693 $configure_ac = 'configure.ac'
4694 if -f 'configure.ac';
4695 die "$me: `configure.ac' or `configure.in' is required\n"
4698 &scan_one_autoconf_file ($configure_ac);
4699 &scan_one_autoconf_file ('aclocal.m4')
4702 if (defined $ENV{'amtraces'})
4704 warn '$me: Autoconf traces is an experimental feature';
4705 warn '$me: use at your own risks';
4707 &scan_autoconf_traces ($configure_ac);
4710 # Set input and output files if not specified by user.
4713 @input_files = @make_input_list;
4714 %output_files = %make_list;
4717 @configure_input_files = @make_input_list;
4719 &am_conf_error ("`AM_INIT_AUTOMAKE' must be used")
4720 if ! $seen_init_automake;
4722 # Look for some files we need. Always check for these. This
4723 # check must be done for every run, even those where we are only
4724 # looking at a subdir Makefile. We must set relative_dir so that
4725 # the file-finding machinery works.
4726 # FIXME: Is this broken because it needs dynamic scopes.
4727 # My tests seems to show it's not the case.
4728 $relative_dir = '.';
4729 &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4730 &am_error ("`install.sh' is an anachronism; use `install-sh' instead")
4731 if -f $config_aux_path[0] . '/install.sh';
4733 &require_config_file ($FOREIGN, 'py-compile')
4736 # Preserve dist_common for later.
4737 $configure_dist_common = variable_value ('DIST_COMMON', 'TRUE') || '';
4740 ################################################################
4742 # Set up for Cygnus mode.
4745 return unless $cygnus_mode;
4747 &set_strictness ('foreign');
4748 $options{'no-installinfo'} = 1;
4749 $options{'no-dependencies'} = 1;
4750 $use_dependencies = 0;
4752 if (! $seen_maint_mode)
4754 &am_conf_error ("`AM_MAINTAINER_MODE' required when --cygnus specified");
4758 # Do any extra checking for GNU standards.
4759 sub check_gnu_standards
4761 if ($relative_dir eq '.')
4763 # In top level (or only) directory.
4764 &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4765 'AUTHORS', 'ChangeLog');
4768 if ($strictness >= $GNU
4769 && defined $options{'no-installman'})
4771 &am_line_error ('AUTOMAKE_OPTIONS',
4772 "option `no-installman' disallowed by GNU standards");
4775 if ($strictness >= $GNU
4776 && defined $options{'no-installinfo'})
4778 &am_line_error ('AUTOMAKE_OPTIONS',
4779 "option `no-installinfo' disallowed by GNU standards");
4783 # Do any extra checking for GNITS standards.
4784 sub check_gnits_standards
4786 if ($relative_dir eq '.')
4788 # In top level (or only) directory.
4789 &require_file ($GNITS, 'THANKS');
4793 ################################################################
4795 # Functions to handle files of each language.
4797 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
4798 # simple formula: Return value is $LANG_SUBDIR if the resulting object
4799 # file should be in a subdir if the source file is, $LANG_PROCESS if
4800 # file is to be dealt with, $LANG_IGNORE otherwise.
4802 # Much of the actual processing is handled in
4803 # handle_single_transform_list. These functions exist so that
4804 # auxiliary information can be recorded for a later cleanup pass.
4805 # Note that the calls to these functions are computed, so don't bother
4806 # searching for their precise names in the source.
4808 # This is just a convenience function that can be used to determine
4809 # when a subdir object should be used.
4812 return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4815 # Rewrite a single C source file.
4818 my ($directory, $base, $ext) = @_;
4820 if (defined $options{'ansi2knr'} && $base =~ /_$/)
4822 # FIXME: include line number in error.
4823 &am_error ("C source file `$base.c' would be deleted by ansi2knr rules");
4826 my $r = $LANG_PROCESS;
4827 if (defined $options{'subdir-objects'})
4830 $base = $directory . '/' . $base;
4834 # Only give error once.
4836 # FIXME: line number.
4837 &am_error ("C objects in subdir but `AM_PROG_CC_C_O' not in `$configure_ac'");
4840 &require_file ($FOREIGN, 'compile')
4841 if $relative_dir eq '.';
4844 $de_ansi_files{$base} = 1;
4848 # Rewrite a single C++ source file.
4849 sub lang_cxx_rewrite
4851 return &lang_sub_obj;
4854 # Rewrite a single header file.
4855 sub lang_header_rewrite
4857 # Header files are simply ignored.
4858 return $LANG_IGNORE;
4861 # Rewrite a single yacc file.
4862 sub lang_yacc_rewrite
4864 my ($directory, $base, $ext) = @_;
4866 my $r = &lang_c_rewrite ($directory, $base, $ext);
4868 if ($r == $LANG_SUBDIR)
4870 $pfx = $directory . '/';
4872 $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4874 &saw_extension ('c');
4876 &push_dist_common ($pfx . $base . '.' . $ext);
4880 # Rewrite a single yacc++ file.
4881 sub lang_yaccxx_rewrite
4883 my ($directory, $base, $ext) = @_;
4885 my $r = $LANG_PROCESS;
4887 if (defined $options{'subdir-objects'})
4889 $pfx = $directory . '/';
4892 $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4894 &saw_extension ($ext);
4896 &push_dist_common ($pfx . $base . '.' . $ext);
4900 # Rewrite a single lex file.
4901 sub lang_lex_rewrite
4903 my ($directory, $base, $ext) = @_;
4905 my $r = &lang_c_rewrite ($directory, $base, $ext);
4907 if ($r == $LANG_SUBDIR)
4909 $pfx = $directory . '/';
4911 $lex_sources{$pfx . $base . '.' . $ext} = 1;
4913 &saw_extension ('c');
4915 &push_dist_common ($pfx . $base . '.' . $ext);
4919 # Rewrite a single lex++ file.
4920 sub lang_lexxx_rewrite
4922 my ($directory, $base, $ext) = @_;
4924 my $r = $LANG_PROCESS;
4926 if (defined $options{'subdir-objects'})
4928 $pfx = $directory . '/';
4931 $lex_sources{$pfx . $base . '.' . $ext} = 1;
4933 &saw_extension ($ext);
4935 &push_dist_common ($pfx . $base . '.' . $ext);
4939 # Rewrite a single assembly file.
4940 sub lang_asm_rewrite
4942 return &lang_sub_obj;
4945 # Rewrite a single Fortran 77 file.
4946 sub lang_f77_rewrite
4948 return $LANG_PROCESS;
4951 # Rewrite a single preprocessed Fortran 77 file.
4952 sub lang_ppf77_rewrite
4954 return $LANG_PROCESS;
4957 # Rewrite a single ratfor file.
4958 sub lang_ratfor_rewrite
4960 return $LANG_PROCESS;
4963 # Rewrite a single Objective C file.
4964 sub lang_objc_rewrite
4966 return &lang_sub_obj;
4969 # Rewrite a single Java file.
4970 sub lang_java_rewrite
4972 return $LANG_SUBDIR;
4975 # The lang_X_finish functions are called after all source file
4976 # processing is done. Each should handle defining rules for the
4977 # language, etc. A finish function is only called if a source file of
4978 # the appropriate type has been seen.
4982 # Push all libobjs files onto de_ansi_files. We actually only
4983 # push files which exist in the current directory, and which are
4984 # genuine source files.
4985 foreach my $file (keys %libsources)
4987 if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
4989 $de_ansi_files{$1} = 1;
4993 if (defined $options{'ansi2knr'} && keys %de_ansi_files)
4995 # Make all _.c files depend on their corresponding .c files.
4997 foreach my $base (sort keys %de_ansi_files)
4999 # Each _.c file must depend on ansi2knr; otherwise it
5000 # might be used in a parallel build before it is built.
5001 # We need to support files in the srcdir and in the build
5002 # dir (because these files might be auto-generated. But
5003 # we can't use $< -- some makes only define $< during a
5005 $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
5006 . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5007 . '`if test -f $(srcdir)/' . $base . '.c'
5008 . '; then echo $(srcdir)/' . $base . '.c'
5009 . '; else echo ' . $base . '.c; fi` '
5010 . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5011 . '| $(ANSI2KNR) > ' . $base . "_.c"
5012 # If ansi2knr fails then we shouldn't
5013 # create the _.c file
5014 . " || rm -f ${base}_.c\n");
5015 push (@objects, $base . '_.$(OBJEXT)');
5016 push (@objects, $base . '_.lo')
5020 # Make all _.o (and _.lo) files depend on ansi2knr.
5021 # Use a sneaky little hack to make it print nicely.
5022 &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5027 # This is a helper for both lex and yacc.
5028 sub yacc_lex_finish_helper
5030 return if defined $language_scratch{'lex-yacc-done'};
5031 $language_scratch{'lex-yacc-done'} = 1;
5033 # If there is more than one distinct yacc (resp lex) source file
5034 # in a given directory, then the `ylwrap' program is required to
5035 # allow parallel builds to work correctly. FIXME: for now, no
5037 &require_config_file ($FOREIGN, 'ylwrap');
5038 if ($config_aux_dir_set_in_configure_in)
5040 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5044 &define_variable ('YLWRAP', '$(top_srcdir)/ylwrap');
5048 sub lang_yacc_finish
5050 return if defined $language_scratch{'yacc-done'};
5051 $language_scratch{'yacc-done'} = 1;
5053 my %seen_suffix = ();
5054 my @yacc_files = sort keys %yacc_sources;
5055 my $yacc_count = scalar (@yacc_files);
5056 foreach my $file (@yacc_files)
5059 &output_yacc_build_rule ($1, $yacc_count > 1)
5060 if ! defined $seen_suffix{$1};
5061 $seen_suffix{$1} = 1;
5063 $file =~ /^(.*)\.(y|yy|y\+\+|yxx|ypp)$/;
5065 my $hname = 'h'; # Always use `.h' for header file.
5069 if ((&variable_defined ('AM_YFLAGS')
5070 && &variable_value ('AM_YFLAGS') =~ /(^|\s)-d(\s|$)/)
5071 || (&variable_defined ('YFLAGS')
5072 && &variable_value ('YFLAGS') =~ /(^|\s)-d(\s|$)/)) {
5073 # Now generate rule to make the header file. This should only
5074 # be generated if `yacc -d' specified.
5075 $output_rules .= "${base}.${hname}: ${base}.${cname}\n";
5077 # If the files are built in the build directory, then we want
5078 # to remove them with `make clean'. If they are in srcdir
5079 # they shouldn't be touched. However, we can't determine this
5080 # statically, and the GNU rules say that yacc/lex output files
5081 # should be removed by maintainer-clean. So that's what we
5083 push (@maintainer_clean_files, "${base}.${hname}");
5085 &push_dist_common ("${base}.${hname}");
5087 push (@maintainer_clean_files, "${base}.${cname}");
5089 $output_rules .= "\n";
5091 if (&variable_defined ('YACCFLAGS'))
5093 &am_line_error ('YACCFLAGS',
5094 "`YACCFLAGS' obsolete; use `YFLAGS' instead");
5097 if ($yacc_count > 1)
5099 &yacc_lex_finish_helper;
5106 return if defined $language_scratch{'lex-done'};
5107 $language_scratch{'lex-done'} = 1;
5109 my %seen_suffix = ();
5110 my $lex_count = scalar (keys %lex_sources);
5111 foreach my $file (sort keys %lex_sources)
5114 &output_lex_build_rule ($1, $lex_count > 1)
5115 if (! defined $seen_suffix{$1});
5116 $seen_suffix{$1} = 1;
5118 # If the files are built in the build directory, then we want
5119 # to remove them with `make clean'. If they are in srcdir
5120 # they shouldn't be touched. However, we can't determine this
5121 # statically, and the GNU rules say that yacc/lex output files
5122 # should be removed by maintainer-clean. So that's what we
5124 $file =~ /^(.*)\.(l|ll|l\+\+|lxx|lpp)$/;
5126 ($cname = $2) =~ tr/l/c/;
5127 push (@maintainer_clean_files, "${1}.${cname}");
5130 if (! $seen_decl_yytext)
5132 &am_error ("lex source seen but `AC_DECL_YYTEXT' not in `$configure_ac'");
5137 &yacc_lex_finish_helper;
5142 # Given a hash table of linker names, pick the name that has the most
5143 # precedence. This is lame, but something has to have global
5144 # knowledge in order to eliminate the conflict. Add more linkers as
5151 if defined $linkers{'GCJLINK'};
5153 if defined $linkers{'CXXLINK'};
5155 if defined $linkers{'F77LINK'};
5157 if defined $linkers{'OBJCLINK'};
5161 # Called to indicate that an extension was used.
5165 $extension_seen{$ext} = 1;
5168 # Called to ask whether source files have been seen . If HEADERS is 1,
5169 # headers can be included.
5180 $headers = grep ($extension_seen{$_},
5181 @{$languages{'header'}->extensions});
5184 return scalar keys %extension_seen > $headers;
5188 # register_language (%ATTRIBUTE)
5189 # ------------------------------
5190 # Register a single language.
5191 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5192 sub register_language (%)
5198 unless defined $option{'ansi'};
5199 $option{'autodep'} = 'no'
5200 unless defined $option{'autodep'};
5201 $option{'derived_autodep'} = 'no'
5202 unless defined $option{'derived_autodep'};
5203 $option{'linker'} = ''
5204 unless defined $option{'linker'};
5206 my $lang = new Language (%option);
5209 grep ($extension_map{$_} = $lang->name, @{$lang->extensions});
5210 $languages{$lang->name} = $lang;
5213 # This function is used to find a path from a user-specified suffix to
5214 # `o' or to some other suffix we recognize internally, eg `cc'.
5217 my ($source_ext) = @_;
5219 # FIXME: hard-coding `o' is a mistake. Doing something
5220 # intelligent is harder.
5221 while (! $extension_map{$source_ext}
5222 && $source_ext ne 'o'
5223 && defined $suffix_rules{$source_ext})
5225 $source_ext = $suffix_rules{$source_ext};
5232 ################################################################
5234 # Pretty-print something. HEAD is what should be printed at the
5235 # beginning of the first line, FILL is what should be printed at the
5236 # beginning of every subsequent line.
5237 sub pretty_print_internal
5239 my ($head, $fill, @values) = @_;
5241 my $column = length ($head);
5244 # Fill length is number of characters. However, each Tab
5245 # character counts for eight. So we count the number of Tabs and
5247 my $fill_length = length ($fill);
5248 $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5252 # "71" because we also print a space.
5253 if ($column + length ($_) > 71)
5255 $result .= " \\\n" . $fill;
5256 $column = $fill_length;
5258 $result .= ' ' if $result =~ /\S\z/;
5260 $column += length ($_) + 1;
5267 # Pretty-print something and append to output_vars.
5270 $output_vars .= &pretty_print_internal (@_);
5273 # Pretty-print something and append to output_rules.
5274 sub pretty_print_rule
5276 $output_rules .= &pretty_print_internal (@_);
5280 ################################################################
5284 # &conditional_string(@COND-STACK)
5285 # --------------------------------
5286 # Build a string which denotes the conditional in @COND-STACK. Some
5287 # simplifications are done: `TRUE' entries are elided, and any `FALSE'
5288 # entry results in a return of `FALSE'.
5289 sub conditional_string
5293 if (grep (/^FALSE$/, @stack))
5299 return join (' ', uniq sort grep (!/^TRUE$/, @stack));
5305 # &conditional_true_when ($COND, $WHEN)
5306 # -------------------------------------
5307 # See if a conditional is true. Both arguments are conditional
5308 # strings. This returns true if the first conditional is true when
5309 # the second conditional is true.
5310 # For instance with $COND = `BAR FOO', and $WHEN = `BAR BAZ FOO',
5311 # obviously return 1, and 0 when, for instance, $WHEN = `FOO'.
5312 sub conditional_true_when ($$)
5314 my ($cond, $when) = @_;
5316 # Make a hash holding all the values from $WHEN.
5317 my %cond_vals = map { $_ => 1 } split (' ', $when);
5319 # Check each component of $cond, which looks `COND1 COND2'.
5320 foreach my $comp (split (' ', $cond))
5322 # TRUE is always true.
5323 next if $comp eq 'TRUE';
5324 return 0 if ! defined $cond_vals{$comp};
5332 # &conditionals_true_when (@CONDS, @WHENS)
5333 # ----------------------------------------
5334 # Same as above, but true if all the @CONDS are true when *ALL*
5335 # the @WHENS are sufficient.
5337 # If there are no @CONDS, then return true, of course. *BUT*, even if there
5338 # are @CONDS but @WHENS is empty, return true. This is counter intuitive,
5339 # and against all the rules of logic, but is needed by the current code.
5340 # FIXME: Do something saner when the logic of conditionals is understood.
5341 sub conditionals_true_when (@@)
5343 my (@conds, @whens) = @_;
5345 foreach my $cond (@conds)
5347 foreach my $when (@whens)
5350 unless conditional_true_when ($cond, $when);
5359 # condition_negate ($COND)
5360 # ------------------------
5361 sub condition_negate ($)
5365 $cond =~ s/TRUE$/TRUEO/;
5366 $cond =~ s/FALSE$/TRUE/;
5367 $cond =~ s/TRUEO$/FALSE/;
5373 # Compare condition names.
5374 # Issue them in alphabetical order, foo_TRUE before foo_FALSE.
5377 # Be careful we might be comparing `' or `#'.
5378 $a =~ /^(.*)_(TRUE|FALSE)$/;
5379 my ($aname, $abool) = ($1 || '', $2 || '');
5380 $b =~ /^(.*)_(TRUE|FALSE)$/;
5381 my ($bname, $bbool) = ($1 || '', $2 || '');
5382 return ($aname cmp $bname
5383 # Don't bother with IFs, given that TRUE is after FALSE
5384 # just cmp in the reverse order.
5385 || $bbool cmp $abool
5391 # &make_condition (@CONDITIONS)
5392 # -----------------------------
5393 # Transform a list of conditions (themselves can be an internal list
5394 # of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
5395 # Make conditional (a pattern for AC_SUBST).
5396 # Correctly returns the empty string when there are no conditions.
5399 my $res = conditional_string (@_);
5401 # There are no conditions.
5407 elsif ($res eq 'FALSE')
5414 $res = '@' . $res . '@';
5423 ## ------------------------------ ##
5424 ## Handling the condition stack. ##
5425 ## ------------------------------ ##
5429 # cond_stack_if ($NEGATE, $COND, $WHERE)
5430 # --------------------------------------
5431 sub cond_stack_if ($$$)
5433 my ($negate, $cond, $where) = @_;
5435 &am_file_error ($where, "$cond does not appear in AM_CONDITIONAL")
5436 if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
5438 $cond = "${cond}_TRUE"
5439 unless $cond =~ /^TRUE|FALSE$/;
5440 $cond = condition_negate ($cond)
5443 push (@cond_stack, $cond);
5445 return conditional_string (@cond_stack);
5450 # cond_stack_else ($NEGATE, $COND, $WHERE)
5451 # ----------------------------------------
5452 sub cond_stack_else ($$$)
5454 my ($negate, $cond, $where) = @_;
5458 &am_file_error ($where, "else without if");
5462 $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);
5464 # If $COND is given, check against it.
5467 $cond = "${cond}_TRUE"
5468 unless $cond =~ /^TRUE|FALSE$/;
5469 $cond = condition_negate ($cond)
5472 &am_file_error ($where,
5473 "else reminder ($negate$cond) incompatible with "
5474 . "current conditional: $cond_stack[$#cond_stack]")
5475 if $cond_stack[$#cond_stack] ne $cond;
5478 return conditional_string (@cond_stack);
5483 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5484 # -----------------------------------------
5485 sub cond_stack_endif ($$$)
5487 my ($negate, $cond, $where) = @_;
5492 &am_file_error ($where, "endif without if: $negate$cond");
5497 # If $COND is given, check against it.
5500 $cond = "${cond}_TRUE"
5501 unless $cond =~ /^TRUE|FALSE$/;
5502 $cond = condition_negate ($cond)
5505 &am_file_error ($where,
5506 "endif reminder ($negate$cond) incompatible with "
5507 . "current conditional: $cond_stack[$#cond_stack]")
5508 if $cond_stack[$#cond_stack] ne $cond;
5513 return conditional_string (@cond_stack);
5520 ## ------------------------ ##
5521 ## Handling the variables. ##
5522 ## ------------------------ ##
5525 # check_ambiguous_conditional ($VAR, $COND)
5526 # -----------------------------------------
5527 # Check for an ambiguous conditional. This is called when a variable
5528 # is being defined conditionally. If we already know about a
5529 # definition that is true under the same conditions, then we have an
5531 sub check_ambiguous_conditional ($$)
5533 my ($var, $cond) = @_;
5534 foreach my $vcond (keys %{$var_value{$var}})
5537 if ($vcond eq $cond)
5539 $message = "$var multiply defined in condition $cond";
5541 elsif (&conditional_true_when ($vcond, $cond))
5543 $message = ("$var was already defined in condition $vcond, "
5544 . "which implies condition $cond");
5546 elsif (&conditional_true_when ($cond, $vcond))
5548 $message = ("$var was already defined in condition $vcond, "
5549 . "which is implied by condition $cond");
5553 &am_line_error ($var, $message);
5560 # ¯o_define($VAR, $VAR_IS_AM, $TYPE, $COND, $VALUE, $WHERE)
5561 # -------------------------------------------------------------
5562 # The $VAR can go from Automake to user, but not the converse.
5563 sub macro_define ($$$$$$)
5565 my ($var, $var_is_am, $type, $cond, $value, $where) = @_;
5567 am_file_error ($where, "bad macro name `$var'")
5568 if $var !~ /$MACRO_PATTERN/o;
5572 # An Automake variable must be consistently defined with the same
5573 # sign by Automake. A user variable must be set by either `=' or
5574 # `:=', and later promoted to `+='.
5577 if (defined $var_type{$var} && $var_type{$var} ne $type)
5579 am_line_error ($var,
5580 ("$var was set with `$var_type{$var}=' "
5581 . "and is now set with `$type='"));
5586 if (!defined $var_type{$var} && $type eq '+')
5588 am_line_error ($var, "$var must be set with `=' before using `+='");
5591 $var_type{$var} = $type;
5593 # When adding, since we rewrite, don't try to preserve the
5594 # Automake continuation backslashes.
5596 if $type eq '+' && $var_is_am;
5598 # Differentiate the first assignment (including with `+=').
5599 if ($type eq '+' && defined $var_value{$var}{$cond})
5601 if (substr ($var_value{$var}{$cond}, -1) eq "\n")
5603 # Insert a backslash before a trailing newline.
5604 $var_value{$var}{$cond} =
5605 substr ($var_value{$var}{$cond}, 0, -1) . "\\\n";
5607 elsif ($var_value{$var}{$cond})
5609 # Insert a separator.
5610 $var_value{$var}{$cond} .= ' ';
5612 $var_value{$var}{$cond} .= $value;
5616 # The first assignment to a macro sets the line number. Ideally I
5617 # suppose we would associate line numbers with random bits of text.
5618 # FIXME: We sometimes redefine some variables, but we want to keep
5619 # the original location. More subs are needed to handle
5620 # properly variables. Once this done, remove this hack.
5621 $var_line{$var} = $where
5622 unless defined $var_line{$var};
5624 # If Automake tries to override a value specified by the user,
5625 # just don't let it do.
5626 if (defined $var_value{$var}{$cond} && !$var_is_am{$var} && $var_is_am)
5630 print STDERR "$me: refusing to override the user definition of:\n";
5632 print STDERR "$me: with `$cond' => `$value'\n";
5637 # There must be no previous value unless the user is redefining
5638 # an Automake variable or an AC_SUBST variable.
5639 check_ambiguous_conditional ($var, $cond)
5640 unless ($var_is_am{$var} && !$var_is_am
5641 || exists $configure_vars{$var});
5643 $var_value{$var}{$cond} = $value;
5647 # An Automake variable can be given to the user, but not the converse.
5648 if (! defined $var_is_am{$var} || !$var_is_am)
5650 $var_is_am{$var} = $var_is_am;
5655 # &variable_delete ($VAR, [@CONDS])
5656 # ---------------------------------
5657 # Forget about $VAR under the conditions @CONDS, or completely if
5659 sub variable_delete ($@)
5661 my ($var, @conds) = @_;
5665 delete $var_value{$var};
5666 delete $var_line{$var};
5667 delete $var_is_am{$var};
5668 delete $var_comment{$var};
5669 delete $var_type{$var};
5673 foreach my $cond (@conds)
5675 delete $var_value{$var}{$cond};
5681 # ¯o_dump ($VAR)
5682 # ------------------
5687 if (!exists $var_value{$var})
5689 print STDERR " $var does not exist\n";
5693 my $var_is_am = $var_is_am{$var} ? "Automake" : "User";
5694 my $where = (defined $var_line{$var}
5695 ? $var_line{$var} : "undefined");
5696 print STDERR "$var_comment{$var}"
5697 if defined $var_comment{$var};
5698 print STDERR " $var ($var_is_am, where = $where) $var_type{$var}=\n";
5699 print STDERR " {\n";
5700 foreach my $vcond (sort by_condition keys %{$var_value{$var}})
5702 print STDERR " $vcond => $var_value{$var}{$vcond}\n";
5704 print STDERR " }\n";
5715 print STDERR "%var_value =\n";
5717 foreach my $var (sort (keys %var_value))
5726 # &variable_defined ($VAR, [$COND])
5727 # ---------------------------------
5728 # See if a variable exists. $VAR is the variable name, and $COND is
5729 # the condition which we should check. If no condition is given, we
5730 # currently return true if the variable is defined under any
5732 sub variable_defined ($$)
5734 my ($var, $cond) = @_;
5736 # Unfortunately we can't just check for $var_value{VAR}{COND}
5737 # as this would make perl create $condition{VAR}, which we
5739 if (!exists $var_value{$var})
5741 if (defined $targets{$var})
5743 &am_line_error ($var, "`$var' is a target; expected a variable")
5745 # The variable is not defined
5749 if ($cond && !exists $var_value{$var}{$cond})
5751 # The variable is not defined for the given condition.
5755 # Even a var_value examination is good enough for us. FIXME:
5756 # really should maintain examined status on a per-condition basis.
5757 $content_seen{$var} = 1;
5761 # Mark a variable as examined.
5762 sub examine_variable
5765 &variable_defined ($var);
5768 # Return the set of conditions for which a variable is defined.
5770 # If the variable is not defined conditionally, and is not defined in
5771 # terms of any variables which are defined conditionally, then this
5772 # returns the empty list.
5774 # If the variable is defined conditionally, but is not defined in
5775 # terms of any variables which are defined conditionally, then this
5776 # returns the list of conditions for which the variable is defined.
5778 # If the variable is defined in terms of any variables which are
5779 # defined conditionally, then this returns a full set of permutations
5780 # of the subvariable conditions. For example, if the variable is
5781 # defined in terms of a variable which is defined for COND_TRUE,
5782 # then this returns both COND_TRUE and COND_FALSE. This is
5783 # because we will need to define the variable under both conditions.
5785 sub variable_conditions ($)
5793 my @new_conds = &variable_conditions_sub ($var, '', ());
5794 # Now we want to return all permutations of the subvariable
5797 foreach my $item (@new_conds)
5799 foreach (split (' ', $item))
5801 s/^(.*)_(TRUE|FALSE)$/$1_TRUE/;
5805 @new_conds = &variable_conditions_permutations (sort keys %allconds);
5807 foreach my $cond (@new_conds)
5809 my $reduce = &variable_conditions_reduce (split (' ', $cond));
5811 if $reduce eq 'FALSE';
5812 $uniqify{$cond} = 1;
5815 @uniq_list = sort by_condition keys %uniqify;
5816 # Note we cannot just do `return sort keys %uniqify', because this
5817 # function is sometimes used in a scalar context.
5823 # &variable_conditionally_defined ($VAR)
5824 # --------------------------------------
5825 sub variable_conditionally_defined ($)
5828 foreach my $cond (variable_conditions ($var))
5831 unless $cond =~ /^TRUE|FALSE$/;
5838 # &variable_conditions_sub ($VAR, $PARENT, @PARENT_CONDS)
5839 # -------------------------------------------------------
5840 # A subroutine of variable_conditions. This returns all the
5841 # conditions of $VAR which are satisfiable when all of @PARENT_CONDS
5843 sub variable_conditions_sub
5845 my ($var, $parent, @parent_conds) = @_;
5848 if (defined $vars_scanned{$var})
5850 &am_line_error ($parent, "variable `$var' recursively defined");
5853 $vars_scanned{$var} = 1;
5855 my @this_conds = ();
5856 # Examine every condition under which $VAR is defined.
5857 foreach my $vcond (keys %{$var_value{$var}})
5859 # If this condition cannot be true when the parent conditions
5860 # are true, then skip it.
5862 if ! conditionals_true_when ((@parent_conds), ($vcond));
5864 push (@this_conds, $vcond);
5866 # If $VAR references some other variable, then compute the
5867 # conditions for that subvariable.
5868 push (@parent_conds, $vcond);
5869 my @subvar_conds = ();
5870 foreach (split (' ', $var_value{$var}{$vcond}))
5872 # If a comment seen, just leave.
5875 # Handle variable substitutions.
5876 if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5879 # Here we compute all the conditions under which the
5880 # subvariable is defined. Then we go through and add
5882 my @svc = &variable_conditions_sub ($1, $var, @parent_conds);
5883 foreach my $item (@svc)
5885 my $val = conditional_string ($vcond, split (' ', $item));
5887 push (@subvar_conds, $val);
5891 pop (@parent_conds);
5893 # If there are no conditional subvariables, then we want to
5894 # return this condition. Otherwise, we want to return the
5895 # permutations of the subvariables, taking into account the
5896 # conditions of $VAR.
5897 if (! @subvar_conds)
5899 push (@new_conds, $vcond);
5903 push (@new_conds, &variable_conditions_reduce (@subvar_conds));
5907 # Unset our entry in vars_scanned. We only care about recursive
5909 delete $vars_scanned{$var};
5911 # If we are being called on behalf of another variable, we need to
5912 # return all possible permutations of the conditions. We have
5913 # already handled everything in @this_conds along with their
5914 # subvariables. We now need to add any permutations that are not
5916 foreach my $this_cond (@this_conds)
5919 &variable_conditions_permutations (split(' ', $this_cond));
5920 foreach my $perm (@perms)
5923 foreach my $scan (@this_conds)
5925 if (&conditional_true_when ($perm, $scan)
5926 || &conditional_true_when ($scan, $perm))
5935 if ! conditionals_true_when ((@parent_conds), ($perm));
5937 # This permutation was not already handled, and is valid
5939 push (@new_conds, $perm);
5947 # Filter a list of conditionals so that only the exclusive ones are
5948 # retained. For example, if both `COND1_TRUE COND2_TRUE' and
5949 # `COND1_TRUE' are in the list, discard the latter.
5950 sub variable_conditions_reduce
5954 foreach my $cond (@conds)
5956 # FALSE is absorbent.
5957 if ($cond eq 'FALSE')
5961 elsif (conditionals_true_when (($cond), (@ret)))
5970 # Return a list of permutations of a conditional string.
5971 sub variable_conditions_permutations
5976 my $comp = shift (@comps);
5977 return &variable_conditions_permutations (@comps)
5979 my $neg = condition_negate ($comp);
5982 foreach my $sub (&variable_conditions_permutations (@comps))
5984 push (@ret, "$comp $sub");
5985 push (@ret, "$neg $sub");
5997 # &check_variable_defined_unconditionally($VAR, $PARENT)
5998 # ------------------------------------------------------
5999 # Warn if a variable is conditionally defined. This is called if we
6000 # are using the value of a variable.
6001 sub check_variable_defined_unconditionally ($$)
6003 my ($var, $parent) = @_;
6004 foreach my $cond (keys %{$var_value{$var}})
6007 if $cond =~ /^TRUE|FALSE$/;
6011 &am_line_error ($parent,
6012 "warning: automake does not support conditional definition of $var in $parent");
6016 &am_line_error ($parent,
6017 "warning: automake does not support $var being defined conditionally");
6025 # Get the TRUE value of a variable, warn if the variable is
6026 # conditionally defined.
6030 &check_variable_defined_unconditionally ($var);
6031 return $var_value{$var}{'TRUE'};
6036 # &value_to_list ($VAR, $VAL, $COND)
6037 # ----------------------------------
6038 # Convert a variable value to a list, split as whitespace. This will
6039 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6042 # If COND is 'all', then all values under all conditions should be
6043 # returned; if COND is a particular condition (all conditions are
6044 # surrounded by @...@) then only the value for that condition should
6045 # be returned; otherwise, warn if VAR is conditionally defined.
6046 # SCANNED is a global hash listing whose keys are all the variables
6047 # already scanned; it is an error to rescan a variable.
6050 my ($var, $val, $cond) = @_;
6054 $val =~ s/\\(\n|$)/ /g;
6056 foreach (split (' ', $val))
6058 # If a comment seen, just leave.
6061 # Handle variable substitutions.
6062 if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
6066 # If the user uses a losing variable name, just ignore it.
6067 # This isn't ideal, but people have requested it.
6068 next if ($varname =~ /\@.*\@/);
6072 if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
6076 ($from = $2) =~ s/(\W)/\\$1/g;
6080 @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
6082 # Now rewrite the value if appropriate.
6085 grep (s/$from$/$to/, @temp_list);
6088 push (@result, @temp_list);
6099 # Return contents of variable as list, split as whitespace. This will
6100 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6101 # substitutions. If COND is 'all', then all values under all
6102 # conditions should be returned; if COND is a particular condition
6103 # (all conditions are surrounded by @...@) then only the value for
6104 # that condition should be returned; otherwise, warn if VAR is
6105 # conditionally defined. If PARENT is specified, it is the name of
6106 # the including variable; this is only used for error reports.
6107 sub variable_value_as_list_worker
6109 my ($var, $cond, $parent) = @_;
6112 if (! defined $var_value{$var})
6114 if (defined $targets{$var})
6116 &am_line_error ($var, "`$var' is a target; expected a variable");
6120 &am_line_error ($parent, "variable `$var' not defined");
6123 elsif (defined $vars_scanned{$var})
6125 # `vars_scanned' is a global we use to keep track of which
6126 # variables we've already examined.
6127 &am_line_error ($parent, "variable `$var' recursively defined");
6129 elsif ($cond eq 'all')
6131 $vars_scanned{$var} = 1;
6132 foreach my $vcond (keys %{$var_value{$var}})
6134 my $val = $var_value{$var}{$vcond};
6135 push (@result, &value_to_list ($var, $val, $cond));
6141 $vars_scanned{$var} = 1;
6143 foreach my $vcond (keys %{$var_value{$var}})
6145 my $val = $var_value{$var}{$vcond};
6146 if (&conditional_true_when ($vcond, $cond))
6148 # Warn if we have an ambiguity. It's hard to know how
6149 # to handle this case correctly.
6150 &check_variable_defined_unconditionally ($var, $parent)
6153 push (@result, &value_to_list ($var, $val, $cond));
6158 # Unset our entry in vars_scanned. We only care about recursive
6160 delete $vars_scanned{$var};
6166 # &variable_output ($VAR, [@CONDS])
6167 # ---------------------------------
6168 # Output all the values of $VAR is @COND is not specified, else only
6169 # that corresponding to @COND.
6170 sub variable_output ($@)
6172 my ($var, @conds) = @_;
6174 @conds = sort by_condition keys %{$var_value{$var}}
6177 $output_vars .= $var_comment{$var}
6178 if defined $var_comment{$var};
6180 foreach my $cond (@conds)
6182 my $val = $var_value{$var}{$cond};
6183 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6184 my $output_var = "$var $equals $val";
6185 $output_var =~ s/^/make_condition ($cond)/meg;
6186 $output_vars .= $output_var . "\n";
6191 # &variable_pretty_output ($VAR, [@CONDS])
6192 # ----------------------------------------
6193 # Likewise, but pretty, i.e., we *split* the values at spaces. Use only
6194 # with variables holding filenames.
6195 sub variable_pretty_output ($@)
6197 my ($var, @conds) = @_;
6199 @conds = sort by_condition keys %{$var_value{$var}}
6202 $output_vars .= $var_comment{$var}
6203 if defined $var_comment{$var};
6205 foreach my $cond (@conds)
6207 my $val = $var_value{$var}{$cond};
6208 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6209 my $make_condition = make_condition ($cond);
6210 $output_vars .= pretty_print_internal ("$make_condition$var $equals",
6211 "$make_condition\t",
6212 split (' ' , $val));
6217 # This is just a wrapper for variable_value_as_list_worker that
6218 # initializes the global hash `vars_scanned'. This hash is used to
6219 # avoid infinite recursion.
6220 sub variable_value_as_list
6222 my ($var, $cond, $parent) = @_;
6224 return &variable_value_as_list_worker ($var, $cond, $parent);
6228 # Like define_variable, but the value is a list, and the variable may
6229 # be defined conditionally. The second argument is the conditional
6230 # under which the value should be defined; this should be the empty
6231 # string to define the variable unconditionally. The third argument
6232 # is a list holding the values to use for the variable. The value is
6233 # pretty printed in the output file.
6234 sub define_pretty_variable
6236 my ($var, $cond, @value) = @_;
6238 # Beware that an empty $cond has a different semantics for
6239 # macro_define and variable_pretty_output.
6242 if (! &variable_defined ($var, $cond))
6244 macro_define ($var, 1, '', $cond, join (' ', @value), undef);
6245 variable_pretty_output ($var, $cond || 'TRUE');
6246 $content_seen{$var} = 1;
6251 # define_variable ($VAR, $VALUE)
6252 # ------------------------------
6253 # Define a new user variable VAR to VALUE, but only if not already defined.
6256 my ($var, $value) = @_;
6258 define_pretty_variable ($var, 'TRUE', $value);
6262 # Like define_variable, but define a variable to be the configure
6263 # substitution by the same name.
6264 sub define_configure_variable
6267 my $value = '@' . $var . '@';
6268 &define_variable ($var, $value);
6272 # define_compiler_variable ($LANG)
6273 # --------------------------------
6274 # Define a compiler variable. We also handle defining the `LT'
6275 # version of the command when using libtool.
6276 sub define_compiler_variable ($)
6280 my ($var, $value) = ($lang->compiler, $lang->compile);
6281 &define_variable ($var, $value);
6282 &define_variable ("LT$var", "\$(LIBTOOL) --mode=compile $value")
6287 # define_linker_variable ($LANG)
6288 # ------------------------------
6289 # Define linker variables.
6290 sub define_linker_variable ($)
6294 my ($var, $value) = ($lang->lder, $lang->ld);
6296 &define_variable ($lang->lder, $lang->ld);
6297 # CCLINK = $(CCLD) blah blah...
6298 &define_variable ($lang->linker,
6299 (($seen_libtool ? '$(LIBTOOL) --mode=link ' : '')
6303 ################################################################
6305 ## ---------------- ##
6306 ## Handling rules. ##
6307 ## ---------------- ##
6309 sub rule_define ($$$$)
6311 my ($target, $rule_is_am, $cond, $where) = @_;
6313 if (defined $targets{$target}
6315 ? ! defined $target_conditional{$target}
6316 : defined $target_conditional{$target}))
6318 &am_line_error ($target,
6319 "$target defined both conditionally and unconditionally");
6322 # Value here doesn't matter; for targets we only note existence.
6323 $targets{$target} = $where;
6326 if ($target_conditional{$target})
6328 &check_ambiguous_conditional ($target, $cond);
6330 $target_conditional{$target}{$cond} = $where;
6334 # Check the rule for being a suffix rule. If so, store in a hash.
6336 if ((my ($source_suffix, $object_suffix)) = ($target =~ $SUFFIX_RULE_PATTERN))
6338 $suffix_rules{$source_suffix} = $object_suffix;
6339 print "Sources ending in .$source_suffix become .$object_suffix\n"
6341 # Set SUFFIXES from suffix_rules.
6342 push @suffixes, ".$source_suffix", ".$object_suffix";
6347 # See if a target exists.
6351 return defined $targets{$target};
6355 ################################################################
6357 # Read Makefile.am and set up %contents. Simultaneously copy lines
6358 # from Makefile.am into $output_trailer or $output_vars as
6359 # appropriate. NOTE we put rules in the trailer section. We want
6360 # user rules to come after our generated stuff.
6365 my $am_file = new IO::File ("< $amfile");
6368 die "$me: couldn't open `$amfile': $!\n";
6370 print "$me: reading $amfile\n" if $verbose;
6376 while ($_ = $am_file->getline)
6378 if (/$IGNORE_PATTERN/o)
6380 # Merely delete comments beginning with two hashes.
6382 elsif (/$WHITE_PATTERN/o)
6384 # Stick a single white line before the incoming macro or rule.
6388 elsif (/$COMMENT_PATTERN/o)
6390 # Stick comments before the incoming macro or rule. Make
6391 # sure a blank line preceeds first block of comments.
6392 $spacing = "\n" unless $blank;
6394 $comment .= $spacing . $_;
6403 $output_vars .= $comment . "\n";
6407 # We save the conditional stack on entry, and then check to make
6408 # sure it is the same on exit. This lets us conditonally include
6410 my @saved_cond_stack = @cond_stack;
6411 my $cond = conditional_string (@cond_stack);
6415 my $last_var_name = '';
6416 my $last_var_type = '';
6417 my $last_var_value = '';
6418 # FIXME: shouldn't use $_ in this loop; it is too big.
6422 unless substr ($_, -1, 1) eq "\n";
6424 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
6425 # used by users. @MAINT@ is an anachronism now.
6426 $_ =~ s/\@MAINT\@//g
6427 unless $seen_maint_mode;
6429 my $new_saw_bk = /\\$/ && ! /$COMMENT_PATTERN/o;
6431 if (/$IGNORE_PATTERN/o)
6433 # Merely delete comments beginning with two hashes.
6435 elsif (/$WHITE_PATTERN/o)
6437 # Stick a single white line before the incoming macro or rule.
6439 &am_line_error ($., "blank line following trailing backslash")
6442 elsif (/$COMMENT_PATTERN/o)
6444 # Stick comments before the incoming macro or rule.
6445 $comment .= $spacing . $_;
6447 &am_line_error ($., "comment following trailing backslash")
6454 $output_trailer .= &make_condition (@cond_stack);
6455 $output_trailer .= $_;
6459 $last_var_value .= ' '
6460 unless $last_var_value =~ /\s$/;
6461 $last_var_value .= $_;
6465 $var_comment{$last_var_name} .= "$spacing"
6466 if (!defined $var_comment{$last_var_name}
6467 || substr ($var_comment{$last_var_name}, -1) ne "\n");
6468 $var_comment{$last_var_name} .= "$comment";
6469 $comment = $spacing = '';
6470 macro_define ($last_var_name, 0,
6471 $last_var_type, $cond,
6472 $last_var_value, $.)
6473 if $cond ne 'FALSE';
6474 push (@var_list, $last_var_name);
6479 elsif (/$IF_PATTERN/o)
6481 $cond = cond_stack_if ($1, $2, "$amfile:$.");
6483 elsif (/$ELSE_PATTERN/o)
6485 $cond = cond_stack_else ($1, $2, "$amfile:$.");
6487 elsif (/$ENDIF_PATTERN/o)
6489 $cond = cond_stack_endif ($1, $2, "$amfile:$.");
6492 elsif (/$RULE_PATTERN/o)
6497 rule_define ($1, 0, $cond, $.);
6500 $output_trailer .= $comment . $spacing;
6501 $output_trailer .= &make_condition (@cond_stack);
6502 $output_trailer .= $_;
6503 $comment = $spacing = '';
6505 elsif (/$ASSIGNMENT_PATTERN/o)
6507 # Found a macro definition.
6509 $last_var_name = $1;
6510 $last_var_type = $2;
6511 $last_var_value = $3;
6512 if ($3 ne '' && substr ($3, -1) eq "\\")
6514 # We preserve the `\' because otherwise the long lines
6515 # that are generated will be truncated by broken
6517 $last_var_value = $3 . "\n";
6522 # FIXME: this doesn't always work correctly; it will
6523 # group all comments for a given variable, no matter
6525 # Accumulating variables must not be output.
6526 $var_comment{$last_var_name} .= "$spacing"
6527 if (!defined $var_comment{$last_var_name}
6528 || substr ($var_comment{$last_var_name}, -1) ne "\n");
6529 $var_comment{$last_var_name} .= "$comment";
6530 $comment = $spacing = '';
6532 macro_define ($last_var_name, 0,
6533 $last_var_type, $cond,
6534 $last_var_value, $.)
6535 if $cond ne 'FALSE';
6536 push (@var_list, $last_var_name);
6539 elsif (/$INCLUDE_PATTERN/o)
6543 if ($path =~ s/^\$\(top_srcdir\)\///)
6545 push (@include_stack, "\$\(top_srcdir\)/$path");
6549 $path =~ s/\$\(srcdir\)\///;
6550 push (@include_stack, "\$\(srcdir\)/$path");
6551 $path = $relative_dir . "/" . $path;
6553 &read_am_file ($path);
6557 # This isn't an error; it is probably a continued rule.
6558 # In fact, this is what we assume.
6560 $output_trailer .= $comment . $spacing;
6561 $output_trailer .= &make_condition (@cond_stack);
6562 $output_trailer .= $_;
6563 $comment = $spacing = '';
6564 &am_line_error ($., "`#' comment at start of rule is unportable")
6565 if $_ =~ /^\t\s*\#/;
6568 $saw_bk = $new_saw_bk;
6569 $_ = $am_file->getline;
6572 $output_trailer .= $comment;
6574 if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
6578 &am_error ("unterminated conditionals: @cond_stack");
6582 # FIXME: better error message here.
6583 &am_error ("conditionals not nested in include file");
6589 # define_standard_variables ()
6590 # ----------------------------
6591 # A helper for read_main_am_file which initializes configure variables
6592 # and variables from header-vars.am. This is a subr so we can call it
6594 sub define_standard_variables
6596 my $saved_output_vars = $output_vars;
6597 my ($comments, undef, $rules) =
6598 file_contents_internal (1, "$libdir/am/header-vars.am");
6600 # This will output the definitions in $output_vars, which we don't
6602 foreach my $var (sort keys %configure_vars)
6604 &define_configure_variable ($var);
6605 push (@var_list, $var);
6608 # ... hence, we restore $output_vars.
6609 $output_vars = $saved_output_vars . $comments . $rules;
6612 # Read main am file.
6613 sub read_main_am_file
6617 # This supports the strange variable tricks we are about to play.
6618 if (scalar keys %var_value > 0)
6621 &prog_error ("variable defined before read_main_am_file");
6624 # Generate copyright header for generated Makefile.in.
6625 # We do discard the output of predefined variables, handled below.
6626 $output_vars = ("# $in_file_name generated automatically by automake "
6627 . $VERSION . " from $am_file_name.\n");
6628 $output_vars .= $gen_copyright;
6630 # We want to predefine as many variables as possible. This lets
6631 # the user set them with `+=' in Makefile.am. However, we don't
6632 # want these initial definitions to end up in the output quite
6633 # yet. So we just load them, but output them later.
6634 &define_standard_variables;
6636 # Read user file, which might override some of our values.
6637 &read_am_file ($amfile);
6639 # Ouput all the Automake variables. If the user changed one, then
6640 # it is now marked as owned by the user.
6641 foreach my $var (uniq @var_list)
6643 # Don't process user variables.
6644 variable_output ($var)
6645 unless !$var_is_am{$var};
6648 # Now dump the user variables that were defined. We do it in the same
6649 # order in which they were defined (skipping duplicates).
6650 foreach my $var (uniq @var_list)
6652 # Don't process Automake variables.
6653 variable_output ($var)
6654 unless $var_is_am{$var};
6658 ################################################################
6661 # &flatten ($STRING)
6662 # ------------------
6663 # Flatten the $STRING and return the result.
6678 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
6679 # ------------------------------------------
6680 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6682 sub make_paragraphs ($%)
6684 my ($file, %transform) = @_;
6686 # Complete %transform with global options and make it a Perl
6689 "s/$IGNORE_PATTERN//gm;"
6690 . transform (%transform,
6692 'CYGNUS' => $cygnus_mode,
6694 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
6696 'SHAR' => $options{'dist-shar'} || 0,
6697 'BZIP2' => $options{'dist-bzip2'} || 0,
6698 'ZIP' => $options{'dist-zip'} || 0,
6699 'COMPRESS' => $options{'dist-tarZ'} || 0,
6701 'INSTALL-INFO' => !$options{'no-installinfo'},
6702 'INSTALL-MAN' => !$options{'no-installman'},
6703 'CK-NEWS' => $options{'check-news'} || 0,
6705 'SUBDIRS' => &variable_defined ('SUBDIRS'),
6706 'TOPDIR' => backname ($relative_dir),
6707 'TOPDIR_P' => $relative_dir eq '.',
6708 'CONFIGURE-AC' => $configure_ac,
6710 'BUILD' => $seen_canonical == $AC_CANONICAL_SYSTEM,
6711 'HOST' => $seen_canonical,
6712 'TARGET' => $seen_canonical == $AC_CANONICAL_SYSTEM,
6714 'LIBTOOL' => defined $configure_vars{'LIBTOOL'})
6715 # We don't need more than two consecutive new-lines.
6716 . 's/\n{3,}/\n\n/g';
6718 # Swallow the file and apply the COMMAND.
6719 my $fc_file = new IO::File ("< $file");
6722 die "$me: installation error: cannot open `$file'\n";
6725 print "$me: reading $file\n"
6727 my $saved_dollar_slash = $/;
6729 $_ = $fc_file->getline;
6730 $/ = $saved_dollar_slash;
6735 # Split at unescaped new lines.
6736 my @lines = split (/(?<!\\)\n/, $content);
6739 while (defined ($_ = shift @lines))
6741 my $paragraph = "$_";
6742 # If we are a rule, eat as long as we start with a tab.
6743 if (/$RULE_PATTERN/smo)
6745 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
6747 $paragraph .= "\n$_";
6749 unshift (@lines, $_);
6752 # If we are a comments, eat as much comments as you can.
6753 elsif (/$COMMENT_PATTERN/smo)
6755 while (defined ($_ = shift @lines)
6756 && $_ =~ /$COMMENT_PATTERN/smo)
6758 $paragraph .= "\n$_";
6760 unshift (@lines, $_);
6763 push @res, $paragraph;
6772 # ($COMMENT, $VARIABLES, $RULES)
6773 # &file_contents_internal ($IS_AM, $FILE, [%TRANSFORM])
6774 # -----------------------------------------------------
6775 # Return contents of a file from $libdir/am, automatically skipping
6776 # macros or rules which are already known. $IS_AM iff the caller is
6777 # reading an Automake file (as opposed to the user's Makefile.am).
6778 sub file_contents_internal ($$%)
6780 my ($is_am, $file, %transform) = @_;
6782 my $result_vars = '';
6783 my $result_rules = '';
6787 # We save the conditional stack on entry, and then check to make
6788 # sure it is the same on exit. This lets us conditonally include
6790 my @saved_cond_stack = @cond_stack;
6791 my $cond = conditional_string (@cond_stack);
6793 foreach (make_paragraphs ($file, %transform))
6796 &am_file_error ($file, "blank line following trailing backslash:\n$_")
6798 &am_file_error ($file, "comment following trailing backslash:\n$_")
6803 # Stick empty line before the incoming macro or rule.
6806 elsif (/$COMMENT_PATTERN/mso)
6808 # Stick comments before the incoming macro or rule.
6812 # Handle inclusion of other files.
6813 elsif (/$INCLUDE_PATTERN/o)
6815 if ($cond ne 'FALSE')
6817 my $file = ($is_am ? "$libdir/am/" : '') . $1;
6819 my ($com, $vars, $rules)
6820 = file_contents_internal ($is_am, $file, %transform);
6822 $result_vars .= $vars;
6823 $result_rules .= $rules;
6827 # Handling the conditionals.
6828 elsif (/$IF_PATTERN/o)
6830 $cond = cond_stack_if ($1, $2, $file);
6832 elsif (/$ELSE_PATTERN/o)
6834 $cond = cond_stack_else ($1, $2, $file);
6836 elsif (/$ENDIF_PATTERN/o)
6838 $cond = cond_stack_endif ($1, $2, $file);
6842 elsif (/$RULE_PATTERN/mso)
6844 # Separate relationship from optional actions: the first
6845 # `new-line tab" not preceded by backslash (continuation
6847 # I'm quite shoked! It seems that (\\\n|[^\n]) is not the
6848 # same as `([^\n]|\\\n)!!! Don't swap it, it breaks.
6850 /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
6851 my ($relationship, $actions) = ($1, $2 || '');
6853 # Separate targets from dependencies: the first colon.
6854 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
6855 my ($targets, $dependencies) = ($1, $2);
6856 # Remove the escaped new lines.
6857 # I don't know why, but I have to use a tmp $flat_deps.
6858 my $flat_deps = &flatten ($dependencies);
6859 my @deps = split (' ', $flat_deps);
6861 foreach (split (' ' , $targets))
6863 # FIXME: We are not robust to people defining several targets
6864 # at once, only some of them being in %dependencies.
6866 # Output only if not in FALSE.
6867 if (defined $dependencies{$_}
6868 && $cond ne 'FALSE')
6870 &depend ($_, @deps);
6871 $actions{$_} .= $actions;
6875 # Free lance dependency. Output the rule for all the
6876 # targets instead of one by one.
6877 if (!defined $targets{$targets}
6878 && $cond ne 'FALSE')
6880 $paragraph =~ s/^/make_condition (@cond_stack)/gme;
6881 $result_rules .= "$spacing$comment$paragraph\n";
6882 rule_define ($targets, $is_am, $cond, $file);
6884 $comment = $spacing = '';
6890 elsif (/$ASSIGNMENT_PATTERN/mso)
6892 my ($var, $type, $val) = ($1, $2, $3);
6893 &am_file_error ($file, "macro `$var' with trailing backslash")
6896 # Accumulating variables must not be output.
6897 $var_comment{$var} .= "$spacing"
6898 if (!defined $var_comment{$var}
6899 || substr ($var_comment{$var}, -1) ne "\n");
6900 $var_comment{$var} .= "$comment";
6901 macro_define ($var, $is_am, $type, $cond, $val, $file)
6902 if $cond ne 'FALSE';
6903 push (@var_list, $var);
6905 # If the user has set some variables we were in charge
6906 # of (which is detected by the first reading of
6907 # `header-vars.am'), we must not output them.
6908 $result_vars .= "$spacing$comment$_\n"
6909 if $type ne '+' && $var_is_am{$var} && $cond ne 'FALSE';
6911 $comment = $spacing = '';
6915 # This isn't an error; it is probably some tokens which
6916 # configure is supposed to replace, such as `@SET-MAKE@',
6917 # or some part of a rule cut by an if/endif.
6918 if ($cond ne 'FALSE')
6920 s/^/make_condition (@cond_stack)/gme;
6921 $result_rules .= "$spacing$comment$_\n";
6923 $comment = $spacing = '';
6927 if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
6931 &am_error ("unterminated conditionals: @cond_stack");
6935 # FIXME: better error message here.
6936 &am_error ("conditionals not nested in include file");
6940 return ($comment, $result_vars, $result_rules);
6945 # &file_contents ($BASENAME, [%TRANSFORM])
6946 # ----------------------------------------
6947 # Return contents of a file from $libdir/am, automatically skipping
6948 # macros or rules which are already known.
6949 sub file_contents ($%)
6951 my ($basename, %transform) = @_;
6952 my ($comments, $variables, $rules) =
6953 file_contents_internal (1, "$libdir/am/$basename.am", %transform);
6954 return "$comments$variables$rules";
6959 # &transform (%PAIRS)
6960 # -------------------
6961 # Foreach ($TOKEN, $VAL) in %PAIRS produce a replacement expression suitable
6962 # for file_contents which:
6963 # - replaces @$TOKEN@ with $VALUE,
6964 # - enables/disables ?$TOKEN?.
6970 while (my ($token, $val) = each %pairs)
6972 $result .= "s/\Q%$token%\E/\Q$val\E/gm;";
6975 $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
6976 $result .= "s/\Q%?$token%\E/TRUE/gm;";
6980 $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
6981 $result .= "s/\Q%?$token%\E/FALSE/gm;";
6989 # Find all variable prefixes that are used for install directories. A
6990 # prefix `zar' qualifies iff:
6991 # * `zardir' is a variable.
6992 # * `zar_PRIMARY' is a variable.
6993 sub am_primary_prefixes
6995 my ($primary, $can_dist, @prefixes) = @_;
6997 my %valid = map { $_ => 0 } @prefixes;
6998 $valid{'EXTRA'} = 0;
6999 foreach my $varname (keys %var_value)
7001 # Automake is allowed to define variables that look like they
7002 # are magic variables, such as INSTALL_DATA.
7004 if $var_is_am{$varname};
7006 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
7008 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
7009 if ($dist ne '' && ! $can_dist)
7011 # Note that a configure variable is always legitimate.
7012 # It is natural to name such variables after the
7013 # primary, so we explicitly allow it.
7014 if (! defined $configure_vars{$varname})
7016 &am_line_error ($varname,
7017 "invalid variable `$varname': `dist' is forbidden");
7020 elsif (! defined $valid{$X} && ! &variable_defined ("${X}dir"))
7022 # Note that a configure variable is always legitimate.
7023 # It is natural to name such variables after the
7024 # primary, so we explicitly allow it.
7025 if (! defined $configure_vars{$varname})
7027 &am_line_error ($varname,
7028 "invalid variable `$varname'");
7033 # Ensure all extended prefixes are actually used.
7034 $valid{"$base$dist$X"} = 1;
7042 # Handle `where_HOW' variable magic. Does all lookups, generates
7043 # install code, and possibly generates code to define the primary
7044 # variable. The first argument is the name of the .am file to munge,
7045 # the second argument is the primary variable (eg HEADERS), and all
7046 # subsequent arguments are possible installation locations. Returns
7047 # list of all values of all _HOW targets.
7049 # FIXME: this should be rewritten to be cleaner. It should be broken
7050 # up into multiple functions.
7052 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7059 my $default_dist = 0;
7062 if ($args[0] eq '-noextra')
7066 elsif ($args[0] eq '-candist')
7070 elsif ($args[0] eq '-defaultdist')
7075 elsif ($args[0] !~ /^-/)
7082 my ($file, $primary, @prefixes) = @args;
7084 # Now that configure substitutions are allowed in where_HOW
7085 # variables, it is an error to actually define the primary. We
7086 # allow `JAVA', as it is customarily used to mean the Java
7087 # interpreter. This is but one of several Java hacks. Similarly,
7088 # `PYTHON' is customarily used to mean the Python interpreter.
7089 &am_line_error ($primary, "`$primary' is an anachronism")
7090 if &variable_defined ($primary)
7091 && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7094 # Look for misspellings. It is an error to have a variable ending
7095 # in a "reserved" suffix whose prefix is unknown, eg
7096 # "bni_PROGRAMS". However, unusual prefixes are allowed if a
7097 # variable of the same name (with "dir" appended) exists. For
7098 # instance, if the variable "zardir" is defined, then
7099 # "zar_PROGRAMS" becomes valid. This is to provide a little extra
7100 # flexibility in those cases which need it.
7101 my %valid = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7103 # If a primary includes a configure substitution, then the EXTRA_
7104 # form is required. Otherwise we can't properly do our job.
7106 my $warned_about_extra = 0;
7111 # True if the iteration is the first one. Used for instance to
7112 # output parts of the associated file only once.
7114 foreach my $X (sort keys %valid)
7116 my $one_name = $X . '_' . $primary;
7118 unless (&variable_defined ($one_name));
7120 my $strip_subdir = 1;
7121 # If subdir prefix should be preserved, do so.
7122 if ($X =~ /^nobase_/)
7128 my $nodir_name = $X;
7129 # If files should be distributed, do so.
7133 $dist_p = (($default_dist && $one_name !~ /^nodist_/)
7134 || (! $default_dist && $one_name =~ /^dist_/));
7135 $nodir_name =~ s/^(dist|nodist)_//;
7138 # Append actual contents of where_PRIMARY variable to
7140 foreach my $rcurs (&variable_value_as_list ($one_name, 'all'))
7142 # Skip configure substitutions. Possibly bogus.
7143 if ($rcurs =~ /^\@.*\@$/)
7147 if (! $warned_about_extra)
7149 $warned_about_extra = 1;
7150 &am_line_error ($one_name,
7151 "`$one_name' contains configure substitution, but shouldn't");
7154 # Check here to make sure variables defined in
7155 # configure.ac do not imply that EXTRA_PRIMARY
7157 elsif (! defined $configure_vars{$one_name})
7159 $require_extra = $one_name
7166 push (@result, $rcurs);
7169 # A blatant hack: we rewrite each _PROGRAMS primary to
7170 # include EXEEXT when in Cygwin32 mode.
7171 if ($primary eq 'PROGRAMS')
7173 my @conds = &variable_conditions ($one_name);
7176 foreach my $cond (@conds)
7178 my @one_binlist = ();
7179 my @condval = &variable_value_as_list ($one_name,
7181 foreach my $rcurs (@condval)
7183 if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7185 push (@one_binlist, $rcurs);
7189 push (@one_binlist, $rcurs . '$(EXEEXT)');
7193 push (@condvals, $cond);
7194 push (@condvals, join (' ', @one_binlist));
7197 variable_delete ($one_name);
7200 my $cond = shift (@condvals);
7201 my @val = split (' ', shift (@condvals));
7202 &define_pretty_variable ($one_name, $cond, @val);
7206 # "EXTRA" shouldn't be used when generating clean targets,
7207 # all, or install targets.
7210 # We used to warn if EXTRA_FOO was defined uselessly,
7211 # but this was annoying.
7217 push (@check, '$(' . $one_name . ')');
7221 push (@used, '$(' . $one_name . ')');
7224 # Is this to be installed?
7225 my $install_p = $X ne 'noinst' && $X ne 'check';
7227 # If so, with install-exec? (or install-data?).
7228 my $exec_p = (defined $exec_dir_p {$X}
7232 # Singular form of $PRIMARY.
7233 (my $one_primary = $primary) =~ s/S$//;
7234 $output_rules .= &file_contents ($file,
7237 'PRIMARY' => $primary,
7238 'ONE_PRIMARY' => $one_primary,
7240 'NDIR' => $nodir_name,
7241 'BASE' => $strip_subdir,
7244 'INSTALL' => $install_p,
7245 'DIST' => $dist_p));
7250 # The JAVA variable is used as the name of the Java interpreter.
7251 # The PYTHON variable is used as the name of the Python interpreter.
7252 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7255 &define_pretty_variable ($primary, '', @used);
7256 $output_vars .= "\n";
7259 if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7261 &am_line_error ($require_extra,
7262 "`$require_extra' contains configure substitution, but `EXTRA_$primary' not defined");
7265 # Push here because PRIMARY might be configure time determined.
7266 push (@all, '$(' . $primary . ')')
7267 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7269 # Make the result unique. This lets the user use conditionals in
7270 # a natural way, but still lets us program lazily -- we don't have
7271 # to worry about handling a particular object more than once.
7272 return uniq (sort @result);
7276 ################################################################
7278 # Each key in this hash is the name of a directory holding a
7279 # Makefile.in. These variables are local to `is_make_dir'.
7281 my $make_dirs_set = 0;
7286 if (! $make_dirs_set)
7288 foreach my $iter (@configure_input_files)
7290 $make_dirs{dirname ($iter)} = 1;
7292 # We also want to notice Makefile.in's.
7293 foreach my $iter (@other_input_files)
7295 if ($iter =~ /Makefile\.in$/)
7297 $make_dirs{dirname ($iter)} = 1;
7302 return defined $make_dirs{$dir};
7305 ################################################################
7307 # This variable is local to the "require file" set of functions.
7308 my @require_file_paths = ();
7310 # If a file name appears as a key in this hash, then it has already
7311 # been checked for. This variable is local to the "require file"
7313 %require_file_found = ();
7315 # See if we want to push this file onto dist_common. This function
7316 # encodes the rules for deciding when to do so.
7317 sub maybe_push_required_file
7319 my ($dir, $file, $fullfile) = @_;
7321 if ($dir eq $relative_dir)
7323 &push_dist_common ($file);
7325 elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7327 # If we are doing the topmost directory, and the file is in a
7328 # subdir which does not have a Makefile, then we distribute it
7330 &push_dist_common ($fullfile);
7335 # &require_file_internal ($IS_CONFIGURE, $LINE, $MYSTRICT, @FILES)
7336 # ----------------------------------------------------------------
7337 # Verify that the file must exist in the current directory.
7338 # $MYSTRICT is the strictness level at which this file becomes required.
7340 # Must set require_file_paths before calling this function.
7341 # require_file_paths is set to hold a single directory (the one in
7342 # which the first file was found) before return.
7343 sub require_file_internal
7345 my ($is_configure, $line, $mystrict, @files) = @_;
7347 foreach my $file (@files)
7354 # If we've already looked for it, we're done.
7355 next if defined $require_file_found{$file};
7356 $require_file_found{$file} = 1;
7359 my $dangling_sym = 0;
7360 foreach my $dir (@require_file_paths)
7362 $fullfile = $dir . "/" . $file;
7363 $errdir = $dir unless $errdir;
7365 # Use different name for "error filename". Otherwise on
7366 # an error the bad file will be reported as eg
7367 # `../../install-sh' when using the default
7369 $errfile = $errdir . '/' . $file;
7371 if (-l $fullfile && ! -f readlink ($fullfile))
7376 elsif (-f $fullfile)
7379 &maybe_push_required_file ($dir, $file, $fullfile);
7385 if ($found_it && ! $force_missing)
7387 # Prune the path list.
7388 @require_file_paths = $save_dir;
7392 if ($strictness >= $mystrict)
7394 if ($dangling_sym && $add_missing)
7402 # Only install missing files according to our desired
7404 my $message = "required file `$errfile' not found";
7409 # Maybe run libtoolize.
7410 my @syslist = ('libtoolize', '--automake');
7411 push @syslist, '--copy'
7414 && grep ($_ eq $file, @libtoolize_files)
7415 && system (@syslist))
7417 $message = "installing `$errfile'";
7419 $trailer = "; cannot run `libtoolize': $!";
7421 elsif (-f ("$libdir/$file"))
7423 # Install the missing file. Symlink if we
7424 # can, copy if we must. Note: delete the file
7425 # first, in case it is a dangling symlink.
7426 $message = "installing `$errfile'";
7427 # Windows Perl will hang if we try to delete a
7428 # file that doesn't exist.
7429 unlink ($errfile) if -f $errfile;
7430 if ($symlink_exists && ! $copy_missing)
7432 if (! symlink ("$libdir/$file", $errfile))
7435 $trailer = "; error while making link: $!";
7438 elsif (system ('cp', "$libdir/$file", $errfile))
7441 $trailer = "\n error while copying";
7445 &maybe_push_required_file (dirname ($errfile),
7448 # Prune the path list.
7449 @require_file_paths = &dirname ($errfile);
7456 # FIXME: allow actual file to be specified.
7457 &am_conf_line_warning ($configure_ac, $line,
7458 "$message$trailer");
7462 &am_line_warning ($line, "$message$trailer");
7469 # FIXME: allow actual file to be specified.
7470 &am_conf_line_error ($configure_ac, $line,
7471 "$message$trailer");
7475 &am_line_error ($line, "$message$trailer");
7483 # Like require_file_with_line, but error messages refer to
7484 # configure.ac, not the current Makefile.am.
7485 sub require_file_with_conf_line
7487 @require_file_paths = $relative_dir;
7488 &require_file_internal (1, @_);
7491 sub require_file_with_line
7493 @require_file_paths = $relative_dir;
7494 &require_file_internal (0, @_);
7499 @require_file_paths = $relative_dir;
7500 &require_file_internal (0, '', @_);
7503 # Require a file that is also required by Autoconf. Looks in
7504 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7505 sub require_config_file
7507 @require_file_paths = @config_aux_path;
7508 &require_file_internal (1, '', @_);
7509 my $dir = $require_file_paths[0];
7510 @config_aux_path = @require_file_paths;
7511 # Avoid unsightly '/.'s.
7512 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7515 # Assumes that the line number is in Makefile.am.
7516 sub require_conf_file_with_line
7518 @require_file_paths = @config_aux_path;
7519 &require_file_internal (0, @_);
7520 my $dir = $require_file_paths[0];
7521 @config_aux_path = @require_file_paths;
7522 # Avoid unsightly '/.'s.
7523 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7526 # Assumes that the line number is in configure.ac.
7527 sub require_conf_file_with_conf_line
7529 @require_file_paths = @config_aux_path;
7530 &require_file_internal (1, @_);
7531 my $dir = $require_file_paths[0];
7532 @config_aux_path = @require_file_paths;
7533 # avoid unsightly '/.'s.
7534 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7537 ################################################################
7539 # Push a list of files onto dist_common.
7540 sub push_dist_common
7542 &prog_error ("push_dist_common run after handle_dist")
7543 if $handle_dist_run;
7544 macro_define ('DIST_COMMON', 1, '+', '', join (' ', @_), '');
7551 $strictness_name = $_[0];
7552 if ($strictness_name eq 'gnu')
7556 elsif ($strictness_name eq 'gnits')
7558 $strictness = $GNITS;
7560 elsif ($strictness_name eq 'foreign')
7562 $strictness = $FOREIGN;
7566 die "$me: level `$strictness_name' not recognized\n";
7571 ################################################################
7573 # Ensure a file exists.
7578 my $touch = new IO::File (">> $file");
7582 # Glob something. Do this to avoid indentation screwups everywhere we
7583 # want to glob. Gross!
7590 # Remove one level of brackets and strip leading spaces,
7591 # as does m4 to function arguments.
7597 my @letters = split //;
7606 next if $depth == 1;
7611 next if $depth == 0;
7612 # don't count orphan right brackets
7613 $depth = 0 if $depth < 0;
7617 return join '', @result;
7620 ################################################################
7622 # Print an error message and set exit status.
7625 warn "$me: ${am_file}.am: @_\n";
7629 # am_file_error ($FILE, @ARGS)
7630 # ----------------------------
7633 my ($file, @args) = @_;
7635 warn "$file: @args\n";
7641 my ($symbol, @args) = @_;
7643 if ($symbol && "$symbol" ne '-1')
7645 my $file = "${am_file}.am";
7647 if ($symbol =~ /^\d+$/)
7649 # SYMBOL is a line number, so just add the colon.
7650 $file .= ':' . $symbol;
7652 elsif (defined $var_line{$symbol})
7654 # SYMBOL is a variable defined in Makefile.am, so add the
7655 # line number we saved from there.
7656 $file .= ':' . $var_line{$symbol};
7658 elsif (defined $configure_vars{$symbol})
7660 # SYMBOL is a variable defined in configure.ac, so add the
7661 # appropriate line number.
7662 $file = $configure_vars{$symbol};
7666 # Couldn't find the line number.
7668 warn $file, ": @args\n";
7677 # Like am_error, but while scanning configure.ac.
7680 # FIXME: can run in subdirs.
7681 warn "$me: $configure_ac: @_\n";
7685 # Error message with line number referring to configure.ac.
7686 sub am_conf_line_error
7688 my ($file, $line, @args) = @_;
7692 warn "$file: $line: @args\n";
7697 &am_conf_error (@args);
7701 # Warning message with line number referring to configure.ac.
7702 # Does not affect exit_status
7703 sub am_conf_line_warning
7705 my $saved_exit_status = $exit_status;
7706 my $sig = $SIG{'__WARN__'};
7707 $SIG{'__WARN__'} = 'DEFAULT';
7708 am_conf_line_error (@_);
7709 $exit_status = $saved_exit_status;
7710 $SIG{'__WARN__'} = $sig;
7713 # Like am_line_error, but doesn't affect exit status.
7716 my $saved_exit_status = $exit_status;
7717 my $sig = $SIG{'__WARN__'};
7718 $SIG{'__WARN__'} = 'DEFAULT';
7720 $exit_status = $saved_exit_status;
7721 $SIG{'__WARN__'} = $sig;
7724 # Tell user where our aclocal.m4 is, but only once.
7725 sub keyed_aclocal_warning
7728 warn "$me: macro `$key' can be generated by `aclocal'\n";
7731 # Print usage information.
7735 Usage: $0 [OPTION] ... [Makefile]...
7737 Generate Makefile.in for configure from Makefile.am.
7740 --help print this help, then exit
7741 --version print version number, then exit
7742 -v, --verbose verbosely list files processed
7743 -o, --output-dir=DIR put generated Makefile.in's into DIR
7744 --no-force only update Makefile.in's that are out of date
7746 Dependency tracking:
7747 -i, --ignore-deps disable dependency tracking code
7748 --include-deps enable dependency tracking code
7751 --cygnus assume program is part of Cygnus-style tree
7752 --foreign set strictness to foreign
7753 --gnits set strictness to gnits
7754 --gnu set strictness to gnu
7757 -a, --add-missing add missing standard files to package
7758 --libdir=DIR directory storing library files
7759 -c, --copy with -a, copy missing files (default is symlink)
7760 -f, --force-missing force update of standard files
7765 foreach my $iter (sort ((@common_files, @common_sometimes)))
7767 push (@lcomm, $iter) unless $iter eq $last;
7771 my ($one, $two, $three, $four, $max);
7772 print "\nFiles which are automatically distributed, if found:\n";
7773 format USAGE_FORMAT =
7774 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
7775 $one, $two, $three, $four
7777 $~ = "USAGE_FORMAT";
7778 $max = int (($#lcomm + 1) / 4);
7780 for (my $i = 0; $i < $max; ++$i)
7783 $two = $lcomm[$max + $i];
7784 $three = $lcomm[2 * $max + $i];
7785 $four = $lcomm[3 * $max + $i];
7789 my $mod = ($#lcomm + 1) % 4;
7792 $one = $lcomm[$max];
7793 $two = ($mod > 1) ? $lcomm[2 * $max] : '';
7794 $three = ($mod > 2) ? $lcomm[3 * $max] : '';
7795 $four = ($mod > 3) ? $lcomm[4 * $max] : '';
7799 print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7806 # Print version information
7810 automake (GNU $PACKAGE) $VERSION
7811 Written by Tom Tromey <tromey\@cygnus.com>.
7813 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
7814 Free Software Foundation, Inc.
7815 This is free software; see the source for copying conditions. There is NO
7816 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.