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 $am_dir = "@datadir@/@PACKAGE@/am";
111 my $pkgdata_dir = "@datadir@/@PACKAGE@";
114 my $IGNORE_PATTERN = '^##([^#\n].*)?\n';
115 my $WHITE_PATTERN = '^\s*$';
116 my $COMMENT_PATTERN = '^#';
117 my $TARGET_PATTERN='[$a-zA-Z_.][-.a-zA-Z0-9_(){}/$]*';
118 # A rule has three parts: a list of targets, a list of dependencies,
119 # and optionally actions.
121 "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
123 my $SUFFIX_RULE_PATTERN = '^\.([a-zA-Z0-9]+)\.([a-zA-Z0-9]+)$';
124 # Only recognize leading spaces, not leading tabs. If we recognize
125 # leading tabs here then we need to make the reader smarter, because
126 # otherwise it will think rules like `foo=bar; \' are errors.
127 my $MACRO_PATTERN = '^[A-Za-z0-9_@]+$';
128 my $ASSIGNMENT_PATTERN = '^ *([^ \t=]*)\s*([:+]?)=\s*(.*)$';
129 # This pattern recognizes a Gnits version id and sets $1 if the
130 # release is an alpha release. We also allow a suffix which can be
131 # used to extend the version number with a "fork" identifier.
132 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
133 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?$';
134 my $ELSE_PATTERN = '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
135 my $ENDIF_PATTERN = '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
136 my $PATH_PATTERN='(\w|[/.-])+';
137 # This will pass through anything not of the prescribed form.
138 my $INCLUDE_PATTERN = ('^include\s+'
139 . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
140 . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
141 . '|([^/\$]' . $PATH_PATTERN. '))\s*(#.*)?$');
143 # Some regular expressions. One reason to put them here is that it
144 # makes indentation work better in Emacs.
145 my $AC_CONFIG_AUX_DIR_PATTERN = 'AC_CONFIG_AUX_DIR\(([^)]+)\)';
146 my $AM_INIT_AUTOMAKE_PATTERN = 'AM_INIT_AUTOMAKE\([^,]*,([^,)]+)[,)]';
147 my $AM_PACKAGE_VERSION_PATTERN = '^\s*\[?([^]\s]+)\]?\s*$';
148 # Note that there is no AC_PATH_TOOL. But we don't really care.
149 my $AC_CHECK_PATTERN = 'AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\(\[?(\w+)';
150 my $AM_MISSING_PATTERN = 'AM_MISSING_PROG\(\[?(\w+)';
151 # Just check for alphanumeric in AC_SUBST. If you do AC_SUBST(5),
153 my $AC_SUBST_PATTERN = 'AC_SUBST\(\[?(\w+)';
154 my $AM_CONDITIONAL_PATTERN = 'AM_CONDITIONAL\(\[?(\w+)';
156 # Constants to define the "strictness" level.
161 # Values for AC_CANONICAL_*
162 my $AC_CANONICAL_HOST = 1;
163 my $AC_CANONICAL_SYSTEM = 2;
165 # Values indicating when something should be cleaned. Right now we
166 # only need to handle `mostly'- and `dist'-clean; add more as
168 my $MOSTLY_CLEAN = 0;
171 # Files installed by libtoolize.
172 my @libtoolize_files = ('ltmain.sh', 'config.guess', 'config.sub');
173 # ltconfig appears here for compatibility with old versions of libtool.
174 my @libtoolize_sometimes = ('ltconfig', 'ltcf-c.sh', 'ltcf-cxx.sh',
177 # Commonly found files we look for and automatically include in
181 'README', 'THANKS', 'TODO', 'NEWS', 'COPYING', 'COPYING.LIB',
182 'INSTALL', 'ABOUT-NLS', 'ChangeLog', 'configure.ac',
183 'configure.in', 'configure', 'config.guess', 'config.sub',
184 'AUTHORS', 'BACKLOG', 'ABOUT-GNU', 'libversion.in',
185 'mdate-sh', 'mkinstalldirs', 'install-sh', 'texinfo.tex',
186 'ansi2knr.c', 'ansi2knr.1', 'elisp-comp',
187 # ltconfig appears here for compatibility with old versions
189 'ylwrap', 'acinclude.m4', @libtoolize_files, @libtoolize_sometimes,
190 'missing', 'depcomp', 'compile', 'py-compile'
193 # Commonly used files we auto-include, but only sometimes.
194 my @common_sometimes =
196 'aclocal.m4', 'acconfig.h', 'config.h.top',
197 'config.h.bot', 'stamp-h.in', 'stamp-vti'
200 # Copyright on generated Makefile.ins.
201 my $gen_copyright = "\
202 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
203 # Free Software Foundation, Inc.
204 # This Makefile.in is free software; the Free Software Foundation
205 # gives unlimited permission to copy and/or distribute it,
206 # with or without modifications, as long as this notice is preserved.
208 # This program is distributed in the hope that it will be useful,
209 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
210 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
211 # PARTICULAR PURPOSE.
214 # These constants are returned by lang_*_rewrite functions.
215 # LANG_SUBDIR means that the resulting object file should be in a
216 # subdir if the source file is. In this case the file name cannot
217 # have `..' components.
219 my $LANG_PROCESS = 1;
222 # Directories installed during 'install-exec' phase.
241 # Map from obsolete macros to hints for new macros.
242 # If you change this, change the corresponding list in aclocal.in.
243 # FIXME: should just put this into a single file.
244 my %obsolete_macros =
246 'AC_FEATURE_CTYPE' => "use `AC_HEADER_STDC'",
247 'AC_FEATURE_ERRNO' => "add `strerror' to `AC_REPLACE_FUNCS(...)'",
248 'AC_FEATURE_EXIT' => '',
249 'AC_SYSTEM_HEADER' => '',
251 # Note that we do not handle this one, because it is still run
252 # from AM_CONFIG_HEADER. So we deal with it specially in
253 # &scan_autoconf_files.
254 # 'AC_CONFIG_HEADER' => "use `AM_CONFIG_HEADER'",
256 'fp_C_PROTOTYPES' => "use `AM_C_PROTOTYPES'",
257 'fp_PROG_CC_STDC' => "use `AM_PROG_CC_STDC'",
258 'fp_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
259 'fp_WITH_DMALLOC' => "use `AM_WITH_DMALLOC'",
260 'fp_WITH_REGEX' => "use `AM_WITH_REGEX'",
261 'gm_PROG_LIBTOOL' => "use `AM_PROG_LIBTOOL'",
262 'jm_MAINTAINER_MODE' => "use `AM_MAINTAINER_MODE'",
263 'md_TYPE_PTRDIFF_T' => "use `AM_TYPE_PTRDIFF_T'",
264 'ud_PATH_LISPDIR' => "use `AM_PATH_LISPDIR'",
265 'ud_GNU_GETTEXT' => "use `AM_GNU_GETTEXT'",
267 # Now part of autoconf proper, under a different name.
268 'AM_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
269 'fp_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
270 'AM_SANITY_CHECK_CC' => "automatically done by `AC_PROG_CC'",
271 'AM_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
272 'AM_EXEEXT' => "use `AC_EXEEXT'",
273 'AM_CYGWIN32' => "use `AC_CYGWIN'",
274 'AM_MINGW32' => "use `AC_MINGW32'",
275 'AM_FUNC_MKTIME' => "use `AC_FUNC_MKTIME'",
277 # These aren't quite obsolete.
281 # Regexp to match the above macros.
282 my $obsolete_rx = '(\b' . join ('\b|\b', keys %obsolete_macros) . '\b)';
286 ## ---------------------------------- ##
287 ## Variables related to the options. ##
288 ## ---------------------------------- ##
290 # TRUE if we should always generate Makefile.in.
291 my $force_generation = 1;
293 # Strictness level as set on command line.
294 my $default_strictness = $GNU;
296 # Name of strictness level, as set on command line.
297 my $default_strictness_name = 'gnu';
299 # This is TRUE if automatic dependency generation code should be
300 # included in generated Makefile.in.
301 my $cmdline_use_dependencies = 1;
303 # TRUE if in verbose mode.
306 # This holds our (eventual) exit status. We don't actually exit until
307 # we have processed all input files.
310 # From the Perl manual.
311 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
313 # TRUE if missing standard files should be installed.
316 # TRUE if we should copy missing files; otherwise symlink if possible.
317 my $copy_missing = 0;
319 # TRUE if we should always update files that we know about.
320 my $force_missing = 0;
323 ## ---------------------------------------- ##
324 ## Variables filled during files scanning. ##
325 ## ---------------------------------------- ##
327 # Name of the top autoconf input: `configure.ac' or `configure.in'.
328 my $configure_ac = '';
330 # Files found by scanning configure.ac for LIBOBJS.
333 # True if AM_C_PROTOTYPES appears in configure.ac.
334 my $am_c_prototypes = 0;
336 # Names used in AC_CONFIG_HEADER call. @config_fullnames holds the
337 # name which appears in AC_CONFIG_HEADER, colon and all.
338 # @config_names holds the file names. @config_headers holds the '.in'
339 # files. Ordinarily these are similar, but they can be different if
340 # the weird "NAME:FILE" syntax is used.
341 my @config_fullnames = ();
342 my @config_names = ();
343 my @config_headers = ();
344 # Line number at which AC_CONFIG_HEADER appears in configure.ac.
345 my $config_header_line = 0;
347 # Directory where output files go. Actually, output files are
348 # relative to this directory.
349 my $output_directory = '.';
351 # List of Makefile.am's to process, and their corresponding outputs.
352 my @input_files = ();
353 my %output_files = ();
355 # Complete list of Makefile.am's that exist.
356 my @configure_input_files = ();
358 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
359 my @other_input_files = ();
360 # Line number at which AC_OUTPUT seen.
361 my $ac_output_line = 0;
363 # List of directories to search for configure-required files. This
364 # can be set by AC_CONFIG_AUX_DIR.
365 my @config_aux_path = ('.', '..', '../..');
366 my $config_aux_dir = '';
367 my $config_aux_dir_set_in_configure_in = 0;
369 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
370 my $seen_gettext = 0;
371 # Line number at which AM_GNU_GETTEXT seen.
372 my $ac_gettext_line = 0;
374 # Whether ALL_LINGUAS has been seen.
375 my $seen_linguas = '';
377 my $all_linguas = '';
378 # Line number at which it appears.
379 my $all_linguas_line = 0;
381 # TRUE if AC_DECL_YYTEXT was seen.
382 my $seen_decl_yytext = 0;
384 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM). The presence of
385 # AC_CHECK_TOOL also sets this.
386 my $seen_canonical = 0;
388 # TRUE if we've seen AC_PROG_LIBTOOL.
389 my $seen_libtool = 0;
390 my $libtool_line = 0;
392 # TRUE if we've seen AM_MAINTAINER_MODE.
393 my $seen_maint_mode = 0;
395 # Actual version we've seen.
396 my $package_version = '';
398 # Line number where we saw version definition.
399 my $package_version_line = 0;
401 # TRUE if we've seen AM_PATH_LISPDIR.
402 my $seen_lispdir = 0;
404 # TRUE if we've seen AM_PATH_PYTHON.
405 my $seen_pythondir = 0;
407 # TRUE if we've seen AC_EXEEXT.
410 # TRUE if we've seen AC_OBJEXT.
413 # TRUE if we've seen AC_ENABLE_MULTILIB.
414 my $seen_multilib = 0;
416 # TRUE if we've seen AM_PROG_CC_C_O
419 # TRUE if we've seen AM_INIT_AUTOMAKE.
420 my $seen_init_automake = 0;
422 # Hash table of discovered configure substitutions. Keys are names,
423 # values are `FILE:LINE' strings which are used by error message
425 my %configure_vars = ();
427 # This is used to keep track of which variable definitions we are
428 # scanning. It is only used in certain limited ways, but it has to be
429 # global. It is declared just for documentation purposes.
430 my %vars_scanned = ();
432 # Charsets used by maintainer and in distribution. MAINT_CHARSET is
433 # handled in a funny way: if seen in the top-level Makefile.am, it is
434 # used for every directory which does not specify a different value.
435 # The rationale here is that some directories (eg gettext) might be
436 # distributions of other packages, and thus require their own charset
437 # info. However, the DIST_CHARSET must be the same for the entire
438 # package; it can only be set at top-level.
439 # FIXME: this yields bugs when rebuilding. What to do? Always
440 # read (and sometimes discard) top-level Makefile.am?
441 my $maint_charset = '';
442 my $dist_charset = 'utf8'; # recode doesn't support this yet.
444 # TRUE if --cygnus seen.
447 # Hash table of AM_CONDITIONAL variables seen in configure.
448 my %configure_cond = ();
450 # This maps extensions onto language names.
451 my %extension_map = ();
453 # List of the DIST_COMMON files we discovered while reading
455 my $configure_dist_common = '';
457 # This maps languages names onto objects.
460 # List of targets we must always output.
461 # FIXME: Complete, and remove falsely required targets.
462 my %required_targets =
473 # FIXME: Not required, temporary hacks.
474 # Well, actually they are sort of required: the -recursive
475 # targets will run them anyway...
478 'install-data-am' => 1,
479 'install-exec-am' => 1,
480 'installcheck-am' => 1,
488 ################################################################
490 ## ------------------------------------------ ##
491 ## Variables reset by &initialize_per_input. ##
492 ## ------------------------------------------ ##
494 # Basename and relative dir of the input file.
498 # Same but wrt Makefile.in.
502 # These two variables are used when generating each Makefile.in.
503 # They hold the Makefile.in until it is ready to be printed.
510 # Suffixes found during a run.
513 # Handling the variables.
516 # - $var_value{$VAR}{$COND} is its value associated to $COND,
517 # - $var_line{$VAR} is where it has been defined,
518 # - $var_comment{$VAR} are the comments associated to it.
519 # - $var_type{$VAR} is how it has been defined (`', `+', or `:'),
520 # - $var_is_am{$VAR} is true if the variable is owned by Automake.
527 # This holds a 1 if a particular variable was examined.
530 # This holds the names which are targets. These also appear in
534 # Same as %VAR_VALUE, but for targets.
535 my %target_conditional;
537 # This is the conditional stack.
540 # This holds the set of included files.
543 # This holds a list of directories which we must create at `dist'
544 # time. This is used in some strange scenarios involving weird
545 # AC_OUTPUT commands.
548 # List of dependencies for the obvious targets.
553 # Holds the dependencies of targets which dependencies are factored.
554 # Typically, `.PHONY' will appear in plenty of *.am files, but must
555 # be output once. Arguably all pure dependencies could be subject
556 # to this factorization, but it is not unpleasant to have paragraphs
557 # in Makefile: keeping related stuff altogether.
560 # Holds the factored actions. Tied to %DEPENDENCIES, i.e., filled
561 # only when keys exists in %DEPENDENCIES.
564 # A list of files deleted by `maintainer-clean'.
565 my @maintainer_clean_files;
567 # Keys in this hash table are object files or other files in
568 # subdirectories which need to be removed. This only holds files
569 # which are created by compilations. The value in the hash indicates
570 # when the file should be removed.
571 my %compile_clean_files;
573 # Value of `$(SOURCES)', used by tags.am.
575 # Sources which go in the distribution.
578 # This hash maps object file names onto their corresponding source
579 # file names. This is used to ensure that each object is created
580 # by a single source file.
583 # This keeps track of the directories for which we've already
584 # created `.dirstamp' code.
594 # Options from AUTOMAKE_OPTIONS.
597 # Whether or not dependencies are handled. Can be further changed
599 my $use_dependencies;
602 my $local_maint_charset;
604 # All yacc and lex source filenames for this directory. Use
605 # filenames instead of raw count so that multiple instances are
606 # counted correctly (eg one yacc file can appear in multiple
607 # programs without harm).
611 # This is a list of all targets to run during "make dist".
614 # Keys in this hash are the basenames of files which must depend
618 # This maps the source extension of a suffix rule to its
619 # corresponding output extension.
622 # This is the name of the redirect `all' target to use.
625 # This keeps track of which extensions we've seen (that we care
629 # This is random scratch space for the language finish functions.
630 # Don't randomly overwrite it; examine other uses of keys first.
631 my %language_scratch;
633 # We keep track of which objects need special (per-executable)
634 # handling on a per-language basis.
635 my %lang_specific_files;
637 # This is set when `handle_dist' has finished. Once this happens,
638 # we should no longer push on dist_common.
641 # True if we need `LINK' defined. This is a hack.
644 # This is the list of such variables to output.
645 # FIXME: Might be useless actually.
648 # Was get_object_extension run?
649 # FIXME: This is a hack. a better switch should be found.
650 my $get_object_extension_was_run;
653 ## --------------------------------- ##
654 ## Forward subroutine declarations. ##
655 ## --------------------------------- ##
656 sub register_language (%);
657 sub file_contents_internal ($$%);
660 # &initialize_per_input ()
661 # ------------------------
662 # (Re)-Initialize per-Makefile.am variables.
663 sub initialize_per_input ()
666 $am_relative_dir = '';
673 $output_trailer = '';
689 %target_conditional = ();
697 $am_relative_dir = '';
713 # Installing/uninstalling.
714 'install-data-am' => [],
715 'install-exec-am' => [],
716 'uninstall-am' => [],
719 'uninstall-man' => [],
721 'install-info' => [],
722 'install-info-am' => [],
723 'uninstall-info' => [],
725 'installcheck-am' => [],
729 'mostlyclean-am' => [],
730 'maintainer-clean-am' => [],
731 'distclean-am' => [],
734 'maintainer-clean' => [],
745 @maintainer_clean_files = ();
756 $strictness = $default_strictness;
757 $strictness_name = $default_strictness_name;
761 $use_dependencies = $cmdline_use_dependencies;
763 $local_maint_charset = $maint_charset;
776 %extension_seen = ();
778 %language_scratch = ();
780 %lang_specific_files = ();
782 $handle_dist_run = 0;
788 $get_object_extension_was_run = 0;
790 %compile_clean_files = ();
794 ################################################################
796 # Initialize our list of languages that are internally supported.
799 register_language ('name' => 'c',
801 'config_vars' => ['CC'],
805 'compiler' => 'COMPILE',
806 'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
810 'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
811 'compile_flag' => '-c',
812 'extensions' => ['c'],
813 '_finish' => \&lang_c_finish);
816 register_language ('name' => 'cxx',
818 'config_vars' => ['CXX'],
819 'linker' => 'CXXLINK',
820 'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
822 'flags' => 'CXXFLAGS',
823 'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
824 'compiler' => 'CXXCOMPILE',
825 'compile_flag' => '-c',
826 'output_flag' => '-o',
830 'extensions' => ['c++', 'cc', 'cpp', 'cxx', 'C']);
833 register_language ('name' => 'objc',
834 'Name' => 'Objective C',
835 'config_vars' => ['OBJC'],
836 'linker' => 'OBJCLINK',,
837 'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
839 'flags' => 'OBJCFLAGS',
840 'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
841 'compiler' => 'OBJCCOMPILE',
842 'compile_flag' => '-c',
843 'output_flag' => '-o',
847 'extensions' => ['m']);
850 register_language ('name' => 'header',
852 'extensions' => ['h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc'],
854 '_finish' => sub { });
856 # For now, yacc and lex can't be handled on a per-exe basis.
859 register_language ('name' => 'yacc',
862 'config_vars' => ['YACC'],
863 'derived_autodep' => 'yes',
864 'extensions' => ['y'],
865 '_finish' => \&lang_yacc_finish);
866 register_language ('name' => 'yaccxx',
867 'Name' => 'Yacc (C++)',
868 'config_vars' => ['YACC'],
869 'linker' => 'CXXLINK',
870 'derived_autodep' => 'yes',
871 'extensions' => ['y++', 'yy', 'yxx', 'ypp'],
872 '_finish' => \&lang_yacc_finish);
875 register_language ('name' => 'lex',
878 'config_vars' => ['LEX'],
879 'derived_autodep' => 'yes',
880 'extensions' => ['l'],
881 '_finish' => \&lang_lex_finish);
882 register_language ('name' => 'lexxx',
883 'Name' => 'Lex (C++)',
884 'config_vars' => ['LEX'],
885 'linker' => 'CXXLINK',
886 'derived_autodep' => 'yes',
887 'extensions' => ['l++', 'll', 'lxx', 'lpp'],
888 '_finish' => \&lang_lex_finish);
891 register_language ('name' => 'asm',
892 'Name' => 'Assembler',
893 'config_vars' => ['AS', 'ASFLAGS'],
895 'flags' => 'ASFLAGS',
896 # Users can set AM_ASFLAGS to includes DEFS, INCLUDES,
897 # or anything else required. They can also set AS.
898 'compile' => '$(AS) $(AM_ASFLAGS) $(ASFLAGS)',
899 'compiler' => 'ASCOMPILE',
900 'compile_flag' => '-c',
901 'extensions' => ['s', 'S'],
903 # With assembly we still use the C linker.
904 '_finish' => \&lang_c_finish);
907 register_language ('name' => 'f77',
908 'Name' => 'Fortran 77',
909 'linker' => 'F77LINK',
910 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
912 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
913 'compiler' => 'F77COMPILE',
914 'compile_flag' => '-c',
915 'output_flag' => '-o',
919 'extensions' => ['f', 'for', 'f90']);
921 # Preprocessed Fortran 77
923 # The current support for preprocessing Fortran 77 just involves
924 # passing `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
925 # $(CPPFLAGS)' as additional flags to the Fortran 77 compiler, since
926 # this is how GNU Make does it; see the `GNU Make Manual, Edition 0.51
927 # for `make' Version 3.76 Beta' (specifically, from info file
928 # `(make)Catalogue of Rules').
930 # A better approach would be to write an Autoconf test
931 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
932 # Fortran 77 compilers know how to do preprocessing. The Autoconf
933 # macro AC_PROG_FPP should test the Fortran 77 compiler first for
934 # preprocessing capabilities, and then fall back on cpp (if cpp were
936 register_language ('name' => 'ppf77',
937 'Name' => 'Preprocessed Fortran 77',
938 'config_vars' => ['F77'],
939 'linker' => 'F77LINK',
940 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
944 'compiler' => 'PPF77COMPILE',
945 'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
946 'compile_flag' => '-c',
947 'output_flag' => '-o',
949 'extensions' => ['F']);
952 register_language ('name' => 'ratfor',
954 'config_vars' => ['F77'],
955 'linker' => 'F77LINK',
956 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
961 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
962 'compiler' => 'RCOMPILE',
963 'compile_flag' => '-c',
964 'output_flag' => '-o',
966 'extensions' => ['r']);
969 register_language ('name' => 'java',
971 'config_vars' => ['GCJ'],
972 'linker' => 'GCJLINK',
973 'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
975 'flags' => 'GCJFLAGS',
976 'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
977 'compiler' => 'GCJCOMPILE',
978 'compile_flag' => '-c',
979 'output_flag' => '-o',
983 'extensions' => ['java', 'class', 'zip', 'jar']);
985 ################################################################
987 # Parse command line.
990 # Do configure.ac scan only once.
991 &scan_autoconf_files;
993 die "$me: no `Makefile.am' found or specified\n"
996 # Now do all the work on each file.
997 # This guy must be local otherwise it's private to the loop.
1000 foreach $am_file (@input_files)
1002 if (! -f ($am_file . '.am'))
1004 &am_error ("`" . $am_file . ".am' does not exist");
1008 &generate_makefile ($output_files{$am_file}, $am_file);
1014 # FIXME: This should be `my'ed next to its subs.
1015 use vars '%require_file_found';
1017 ################################################################
1019 # prog_error (@PRINT-ME)
1020 # ----------------------
1021 # Signal a programming error, display PRINT-ME, and exit 1.
1024 print STDERR "$me: programming error: @_\n";
1032 # Return LIST with no duplicates.
1037 foreach my $item (@_)
1039 if (! defined $seen{$item})
1050 # Return a configure-style substitution using the indicated text.
1051 # We do this to avoid having the substitutions directly in automake.in;
1052 # when we do that they are sometimes removed and this causes confusion
1057 return '@' . $text . '@';
1060 ################################################################
1064 # &backname ($REL-DIR)
1065 # --------------------
1066 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
1067 # For instance `src/foo' => `../..'.
1068 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
1073 foreach (split (/\//, $file))
1075 next if $_ eq '.' || $_ eq '';
1085 return join ('/', @res) || '.';
1088 ################################################################
1090 # Parse command line.
1091 sub parse_arguments ()
1094 &set_strictness ('gnu');
1097 Getopt::Long::config ("bundling");
1098 Getopt::Long::GetOptions
1100 'version' => \&version,
1102 'amdir:s' => \$am_dir,
1103 'gnu' => sub { &set_strictness ('gnu'); },
1104 'gnits' => sub { &set_strictness ('gnits'); },
1105 'cygnus' => \$cygnus_mode,
1106 'foreign' => sub { &set_strictness ('foreign'); },
1107 'include-deps' => sub { $cmdline_use_dependencies = 1; },
1108 'i|ignore-deps' => sub { $cmdline_use_dependencies = 0; },
1109 'no-force' => sub { $force_generation = 0; },
1110 'f|force-missing'=> \$force_missing,
1111 'o|output-dir:s' => \$output_directory,
1112 'a|add-missing' => \$add_missing,
1113 'c|copy' => \$copy_missing,
1114 'v|verbose' => \$verbose,
1115 'Werror' => sub { $SIG{"__WARN__"} = sub { die $_[0] } },
1116 'Wno-error' => sub { $SIG{"__WARN__"} = 'DEFAULT' }
1120 foreach my $arg (@ARGV)
1122 # Handle $local:$input syntax. Note that we only examine the
1123 # first ":" file to see if it is automake input; the rest are
1124 # just taken verbatim. We still keep all the files around for
1125 # dependency checking, however.
1126 my ($local, $input, @rest) = split (/:/, $arg);
1133 # Strip .in; later on .am is tacked on. That is how the
1134 # automake input file is found. Maybe not the best way, but
1135 # it is easy to explain.
1137 or die "$me: invalid input file name `$arg'\n.";
1139 push (@input_files, $input);
1140 $output_files{$input} = join (':', ($local, @rest));
1143 # Take global strictness from whatever we currently have set.
1144 $default_strictness = $strictness;
1145 $default_strictness_name = $strictness_name;
1148 ################################################################
1150 # Generate a Makefile.in given the name of the corresponding Makefile and
1151 # the name of the file output by config.status.
1152 sub generate_makefile
1154 my ($output, $makefile) = @_;
1156 # Reset all the Makefile.am related variables.
1157 &initialize_per_input;
1159 # Name of input file ("Makefile.am") and output file
1160 # ("Makefile.in"). These have no directory components.
1161 $am_file_name = basename ($makefile) . '.am';
1162 $in_file_name = basename ($makefile) . '.in';
1164 # $OUTPUT is encoded. If it contains a ":" then the first element
1165 # is the real output file, and all remaining elements are input
1166 # files. We don't scan or otherwise deal with these input file,
1167 # other than to mark them as dependencies. See
1168 # &scan_autoconf_files for details.
1169 my (@secondary_inputs);
1170 ($output, @secondary_inputs) = split (/:/, $output);
1172 $relative_dir = dirname ($output);
1173 $am_relative_dir = dirname ($makefile);
1175 &read_main_am_file ($makefile . '.am');
1176 if (&handle_options)
1178 # Fatal error. Just return, so we can continue with next file.
1182 # There are a few install-related variables that you should not define.
1183 foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
1185 if (&variable_defined ($var) && !$var_is_am{$var})
1187 &am_line_error ($var, "`$var' should not be defined");
1191 # At the toplevel directory, we might need config.guess, config.sub
1192 # or libtool scripts (ltconfig and ltmain.sh).
1193 if ($relative_dir eq '.')
1195 # libtool requires some files.
1196 &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
1200 # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1202 &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
1206 # We still need Makefile.in here, because sometimes the `dist'
1207 # target doesn't re-run automake.
1208 if ($am_relative_dir eq $relative_dir)
1210 # Only distribute the files if they are in the same subdir as
1211 # the generated makefile.
1212 &push_dist_common ($in_file_name, $am_file_name);
1215 push (@sources, '$(SOURCES)')
1216 if &variable_defined ('SOURCES');
1218 # If OBJEXT/EXEEXT were not set in configure.in, do it, it
1219 # simplifies our task, and anyway starting with Autoconf 2.50, it
1220 # will always be defined, and this code will be dead.
1221 $output_vars .= "EXEEXT =\n"
1222 unless $seen_exeext;
1223 $output_vars .= "OBJEXT = o\n"
1224 unless $seen_objext;
1226 # Must do this after reading .am file. See read_main_am_file to
1227 # understand weird tricks we play there with variables.
1228 &define_variable ('subdir', $relative_dir);
1230 # Check first, because we might modify some state.
1232 &check_gnu_standards;
1233 &check_gnits_standards;
1235 &handle_configure ($output, $makefile, @secondary_inputs);
1238 &handle_ltlibraries;
1242 # This must be run after all the sources are scanned.
1246 # Re-init SOURCES. FIXME: other code shouldn't depend on this
1247 # (but currently does).
1248 macro_define ('SOURCES', 1, '', 'TRUE',
1249 join (' ', @sources), 'internal');
1250 &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
1262 &handle_minor_options;
1265 # This must come after most other rules.
1266 &handle_dist ($makefile);
1269 &do_check_merge_target;
1270 &handle_all ($output);
1273 if (&variable_defined('lib_LTLIBRARIES') &&
1274 &variable_defined('bin_PROGRAMS'))
1276 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
1279 &handle_installdirs;
1281 &handle_factored_dependencies;
1285 if (! -d ($output_directory . '/' . $am_relative_dir))
1287 mkdir ($output_directory . '/' . $am_relative_dir, 0755);
1290 my ($out_file) = $output_directory . '/' . $makefile . ".in";
1291 if (! $force_generation && -e $out_file)
1293 my ($am_time) = (stat ($makefile . '.am'))[9];
1294 my ($in_time) = (stat ($out_file))[9];
1295 # FIXME: should cache these times.
1296 my ($conf_time) = (stat ($configure_ac))[9];
1297 # FIXME: how to do unsigned comparison?
1298 if ($am_time < $in_time || $am_time < $conf_time)
1300 # No need to update.
1303 if (-f 'aclocal.m4')
1305 my ($acl_time) = (stat _)[9];
1306 return if ($am_time < $acl_time);
1310 my $gm_file = new IO::File "> $out_file";
1313 warn "$me: ${am_file}.in: cannot write: $!\n";
1317 print "$me: creating ", $makefile, ".in\n" if $verbose;
1319 # In case we're running under MSWindows, don't write with CRLF
1320 # (as it causes problems for the dependency-file extraction in
1321 # AM_OUTPUT_DEPENDENCY_COMMANDS).
1324 print $gm_file $output_vars;
1325 # We make sure that `all:' is the first target.
1326 print $gm_file $output_all;
1327 print $gm_file $output_header;
1328 print $gm_file $output_rules;
1329 print $gm_file $output_trailer;
1331 if (! $gm_file->close)
1333 warn "$me: $am_file.in: cannot close: $!\n";
1339 ################################################################
1341 # Handle AUTOMAKE_OPTIONS variable. Return 1 on error, 0 otherwise.
1344 if (&variable_defined ('AUTOMAKE_OPTIONS'))
1346 foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
1349 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
1351 &set_strictness ($_);
1353 elsif ($_ eq 'cygnus')
1359 # An option like "../lib/ansi2knr" is allowed. With
1360 # no path prefix, we assume the required programs are
1361 # in this directory. We save the actual option for
1363 $options{'ansi2knr'} = $_;
1365 elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
1366 || $_ eq 'dist-shar' || $_ eq 'dist-zip'
1367 || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
1368 || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
1369 || $_ eq 'readme-alpha' || $_ eq 'check-news'
1370 || $_ eq 'subdir-objects' || $_ eq 'nostdinc')
1372 # Explicitly recognize these.
1374 elsif ($_ eq 'no-dependencies')
1376 $use_dependencies = 0;
1378 elsif (/(\d+)\.(\d+)([a-z]?)(-[A-Za-z0-9]+)?/)
1380 # Got a version number.
1382 my ($rmajor, $rminor, $ralpha, $rfork) = ($1, $2, $3, $4);
1384 &prog_error ("version is incorrect: $VERSION")
1385 if $VERSION !~ /(\d+)\.(\d+)([a-z]?)(-[A-Za-z0-9]+)?/;
1387 my ($tmajor, $tminor, $talpha, $tfork) = ($1, $2, $3, $4);
1392 # 2.0 is better than 1.0.
1393 # 1.2 is better than 1.1.
1394 # 1.2a is better than 1.2.
1395 # If we require 3.4n-foo then we require something
1396 # >= 3.4n, with the `foo' fork identifier.
1397 if ($rmajor > $tmajor
1398 || ($rmajor == $tmajor && $rminor > $tminor)
1399 || ($rminor == $tminor && $rminor == $tminor
1400 && $ralpha gt $talpha)
1401 || ($rfork ne '' && $rfork ne $tfork))
1403 &am_line_error ('AUTOMAKE_OPTIONS',
1404 "require version $_, but have $VERSION");
1410 &am_line_error ('AUTOMAKE_OPTIONS',
1411 "option `" . $_ . "\' not recognized");
1416 if ($strictness == $GNITS)
1418 $options{'readme-alpha'} = 1;
1419 $options{'check-news'} = 1;
1426 # get_object_extension ($OUT)
1427 # ---------------------------
1428 # Return object extension. Just once, put some code into the output.
1429 # OUT is the name of the output file
1430 sub get_object_extension
1434 # Maybe require libtool library object files.
1435 my $extension = '.$(OBJEXT)';
1436 $extension = '.lo' if ($out =~ /\.la$/);
1438 # Check for automatic de-ANSI-fication.
1439 $extension = '$U' . $extension
1440 if defined $options{'ansi2knr'};
1442 $get_object_extension_was_run = 1;
1448 # Call finish function for each language that was used.
1449 sub handle_languages
1451 if ($use_dependencies)
1453 # Include auto-dep code. Don't include it if DEP_FILES would
1455 if (&saw_sources_p (0) && keys %dep_files)
1457 # Set location of depcomp.
1458 &define_variable ('depcomp', "\$(SHELL) $config_aux_dir/depcomp");
1460 &require_config_file ($FOREIGN, 'depcomp');
1462 my @deplist = sort keys %dep_files;
1464 # We define this as a conditional variable because BSD
1465 # make can't handle backslashes for continuing comments on
1466 # the following line.
1467 &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
1469 # Generate each `include' individually. Irix 6 make will
1470 # not properly include several files resulting from a
1471 # variable expansion; generating many separate includes
1473 $output_rules .= "\n";
1474 foreach my $iter (@deplist)
1476 $output_rules .= (subst ('AMDEP_TRUE')
1477 . subst ('_am_include')
1479 . subst ('_am_quote')
1481 . subst ('_am_quote')
1485 $output_rules .= &file_contents ('depend');
1490 &define_variable ('depcomp', '');
1495 # Is the c linker needed?
1497 foreach my $ext (sort keys %extension_seen)
1499 my $lang = $languages{$extension_map{$ext}};
1501 # Get information on $LANG.
1502 my $pfx = $lang->autodep;
1503 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1505 my $AMDEP = (($use_dependencies && $lang->autodep ne 'no')
1506 ? 'AMDEP' : 'FALSE');
1508 my %transform = ('EXT' => $ext,
1511 'LIBTOOL' => $seen_libtool,
1513 '-c' => $lang->compile_flag || '');
1515 # Generate the appropriate rules for this extension.
1516 if ($use_dependencies && $lang->autodep ne 'no'
1517 || defined $lang->compile)
1519 # Some C compilers don't support -c -o. Use it only if really
1521 my $output_flag = $lang->output_flag || '';
1524 && $lang->flags eq 'CFLAGS'
1525 && defined $options{'subdir-objects'});
1528 file_contents ('depend2',
1538 'COMPILE' => '$(' . $lang->compiler . ')',
1539 'LTCOMPILE' => '$(LT' . $lang->compiler . ')',
1540 '-o' => $output_flag);
1543 # Now include code for each specially handled object with this
1545 my %seen_files = ();
1546 foreach my $file (@{$lang_specific_files{$lang->name}})
1548 my ($derived, $source, $obj) = split (' ', $file);
1550 # We might see a given object twice, for instance if it is
1551 # used under different conditions.
1552 next if defined $seen_files{$obj};
1553 $seen_files{$obj} = 1;
1555 my $flags = $lang->flags || '';
1556 my $val = "${derived}_${flags}";
1558 (my $obj_compile = $lang->compile) =~ s/\(AM_$flags/\($val/;
1559 my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
1561 # We _need_ `-o' for per object rules.
1562 my $output_flag = $lang->output_flag || '-o';
1564 # Generate a transform which will turn suffix targets in
1565 # depend2.am into real targets for the particular objects we
1568 file_contents ('depend2',
1573 'SOURCE' => $source,
1575 'OBJOBJ' => "$obj.obj",
1576 'LTOBJ' => "$obj.lo",
1578 'COMPILE' => $obj_compile,
1579 'LTCOMPILE' => $obj_ltcompile,
1580 '-o' => $output_flag));
1583 # The rest of the loop is done once per language.
1584 next if defined $done{$lang};
1587 # Load the language dependent Makefile chunks.
1588 my %lang = map { uc ($_) => 0 } keys %languages;
1589 $lang{uc ($lang->name)} = 1;
1590 $output_rules .= file_contents ('lang-compile', %transform, %lang);
1592 # If the source to a program consists entirely of code from a
1593 # `pure' language, for instance C++ for Fortran 77, then we
1594 # don't need the C compiler code. However if we run into
1595 # something unusual then we do generate the C code. There are
1596 # probably corner cases here that do not work properly.
1597 # People linking Java code to Fortran code deserve pain.
1598 $needs_c ||= ! $lang->pure;
1600 define_compiler_variable ($lang)
1601 if ($lang->compile);
1603 define_linker_variable ($lang)
1606 foreach my $var (@{$lang->config_vars})
1608 am_error ($lang->Name
1609 . " source seen but `$var' not defined in"
1610 . " `$configure_ac'")
1611 if !exists $configure_vars{$var};
1614 # The compiler's flag must be a configure variable.
1615 define_configure_variable ($lang->flags)
1616 if (defined $lang->flags);
1618 # Call the finisher.
1622 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1623 # suffix rule was learned), don't bother with the C stuff. But if
1624 # anything else creeps in, then use it.
1626 if $need_link || scalar keys %suffix_rules > 1;
1630 if (! defined $done{$languages{'c'}})
1632 &define_configure_variable ($languages{'c'}->flags);
1633 &define_compiler_variable ($languages{'c'});
1635 define_linker_variable ($languages{'c'});
1639 # Output a rule to build from a YACC source. The output from YACC is
1640 # compiled with C or C++, depending on the extension of the YACC file.
1641 sub output_yacc_build_rule
1643 my ($yacc_suffix, $use_ylwrap) = @_;
1645 (my $c_suffix = $yacc_suffix) =~ tr/y/c/;
1647 # Generate rule for c/c++.
1648 $output_rules .= &file_contents ('yacc',
1649 ('YLWRAP' => $use_ylwrap,
1650 'YACC_SUFFIX' => $yacc_suffix,
1651 'C_SUFFIX' => $c_suffix));
1654 sub output_lex_build_rule
1656 my ($lex_suffix, $use_ylwrap) = @_;
1658 (my $c_suffix = $lex_suffix) =~ tr/l/c/;
1660 $output_rules .= &file_contents ('lex',
1661 ('YLWRAP' => $use_ylwrap,
1662 'LEX_SUFFIX' => $lex_suffix,
1663 'C_SUFFIX' => $c_suffix));
1666 # Check to make sure a source defined in LIBOBJS is not explicitly
1667 # mentioned. This is a separate function (as opposed to being inlined
1668 # in handle_source_transform) because it isn't always appropriate to
1670 sub check_libobjs_sources
1672 my ($one_file, $unxformed) = @_;
1674 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1675 'dist_EXTRA_', 'nodist_EXTRA_')
1678 if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1680 @files = &variable_value_as_list (($prefix
1681 . $one_file . '_SOURCES'),
1684 elsif ($prefix eq '')
1686 @files = ($unxformed . '.c');
1693 foreach my $file (@files)
1695 if (defined $libsources{$file})
1697 &am_line_error ($prefix . $one_file . '_SOURCES',
1698 "automatically discovered file `$file' should not be explicitly mentioned");
1705 # ($LINKER, @OBJECTS)
1706 # handle_single_transform_list ($VAR, $DERIVED, $OBJ, @FILES)
1707 # -----------------------------------------------------------
1708 # Does much of the actual work for handle_source_transform.
1710 # $DERIVED is the name of resulting executable or library
1711 # $OBJ is the object extension (e.g., `$U.lo')
1712 # @FILES is the list of source files to transform
1714 # $LINKER is name of linker to use (empty string for default linker)
1715 # @OBJECTS are names of objects
1716 sub handle_single_transform_list ($$$@)
1718 my ($var, $derived, $obj, @files) = @_;
1720 my $nonansi_obj = $obj;
1721 $nonansi_obj =~ s/\$U//g;
1722 my %linkers_used = ();
1724 # Turn sources into objects.
1727 # Configure substitutions in _SOURCES variables are errors.
1730 &am_line_error ($var, "$var includes configure substitution `$_'");
1734 # If the source file is in a subdirectory then the `.o' is
1735 # put into the current directory.
1737 # Split file name into base and extension.
1738 next if ! /^(?:(.*)\/)?([^\/]*)\.(.*)$/;
1740 my $directory = $1 || '';
1744 # We must generate a rule for the object if it requires its own flags.
1746 my ($linker, $object);
1748 $extension = &derive_suffix ($extension);
1749 my $lang = $languages{$extension_map{$extension}};
1752 &saw_extension ($extension);
1753 # Found the language, so see what it says.
1754 my $subr = 'lang_' . $lang->name . '_rewrite';
1755 # Note: computed subr call.
1756 my $r = & $subr ($directory, $base, $extension);
1757 # Skip this entry if we were asked not to process it.
1758 next if $r == $LANG_IGNORE;
1760 # Now extract linker and other info.
1761 $linker = $lang->linker;
1763 my $this_obj_ext = $lang->ansi ? $obj : $nonansi_obj;
1764 $object = $base . $this_obj_ext;
1766 if (defined $lang->flags
1767 && &variable_defined ($derived . '_' . $lang->flags))
1769 # We have a per-executable flag in effect for this
1770 # object. In this case we rewrite the object's
1771 # name to ensure it is unique. We also require
1772 # the `compile' program to deal with compilers
1773 # where `-c -o' does not work.
1775 # We choose the name `DERIVED_OBJECT' to ensure
1776 # (1) uniqueness, and (2) continuity between
1777 # invocations. However, this will result in a
1778 # name that is too long for losing systems, in
1779 # some situations. So we provide _SHORTNAME to
1782 my $dname = $derived;
1783 if (&variable_defined ($derived . '_SHORTNAME'))
1785 # FIXME: should use the same conditional as
1786 # the _SOURCES variable. But this is really
1787 # silly overkill -- nobody should have
1788 # conditional shortnames.
1789 $dname = &variable_value ($derived . '_SHORTNAME');
1791 $object = $dname . '-' . $object;
1793 &require_file ($FOREIGN, 'compile')
1794 if $lang->name eq 'c';
1796 &prog_error ("$lang->name flags defined without compiler")
1797 if ! defined $lang->compile;
1802 # If rewrite said it was ok, put the object into a
1804 if ($r == $LANG_SUBDIR && $directory ne '')
1806 $object = $directory . '/' . $object;
1809 # If doing dependency tracking, then we can't print
1810 # the rule. If we have a subdir object, we need to
1811 # generate an explicit rule. Actually, in any case
1812 # where the object is not in `.' we need a special
1813 # rule. The per-object rules in this case are
1814 # generated later, by handle_languages.
1815 if ($renamed || $directory ne '')
1817 my $obj_sans_ext = substr ($object, 0,
1818 - length ($this_obj_ext));
1819 push (@{$lang_specific_files{$lang->name}},
1820 "$derived $full $obj_sans_ext");
1823 elsif ($extension eq 'o')
1825 # This is probably the result of a direct suffix rule.
1826 # In this case we just accept the rewrite. FIXME:
1827 # this fails if we want libtool objects.
1828 $object = $base . '.' . $extension;
1833 # No error message here. Used to have one, but it was
1838 $linkers_used{$linker} = 1;
1840 push (@result, $object);
1842 if (defined $object_map{$object})
1844 if ($object_map{$object} ne $full)
1846 &am_error ("object `$object' created by `$full' and `$object_map{$object}'");
1852 $object_map{$object} = $full;
1854 # If file is in subdirectory, we need explicit
1856 if ($directory ne '' || $renamed)
1858 push (@dep_list, $full);
1861 # If resulting object is in subdir, we need to make
1862 # sure the subdir exists at build time.
1863 if ($object =~ /\//)
1865 # FIXME: check that $DIRECTORY is somewhere in the
1868 # We don't allow `..' in object file names for
1869 # *any* source, not just Java. For Java it just
1870 # doesn't make sense, but in general it is
1871 # a problem because we can't pick a good name for
1873 if ($object =~ /(\/|^)\.\.\//)
1875 &am_error ("`$full' contains `..' component but should not");
1878 # Make sure object is removed by `make mostlyclean'.
1879 $compile_clean_files{$object} = $MOSTLY_CLEAN;
1881 push (@dep_list, $directory . '/.dirstamp');
1883 # If we're generating dependencies, we also want
1884 # to make sure that the appropriate subdir of the
1885 # .deps directory is created.
1886 if ($use_dependencies)
1888 push (@dep_list, '.deps/' . $directory . '/.dirstamp');
1891 if (! defined $directory_map{$directory})
1893 $directory_map{$directory} = 1;
1895 # Directory must be removed by `make distclean'.
1896 $compile_clean_files{$directory . "/.dirstamp"} =
1898 $output_rules .= ($directory . "/.dirstamp:\n"
1899 . "\t\@\$(mkinstalldirs) $directory\n"
1900 . "\t\@: > $directory/.dirstamp\n");
1901 if ($use_dependencies)
1903 $output_rules .= ('.deps/' . $directory
1905 . "\t\@\$(mkinstalldirs) .deps/$directory\n"
1906 . "\t\@: > .deps/$directory/.dirstamp\n");
1911 &pretty_print_rule ($object . ':', "\t", @dep_list)
1912 if scalar @dep_list > 0;
1915 # Transform .o or $o file into .P file (for automatic
1918 && ($lang->autodep ne 'no'
1919 || $lang->derived_autodep eq 'yes'))
1921 my $depfile = $object;
1922 $depfile =~ s/\.([^.]*)$/.P$1/;
1923 $depfile =~ s/\$\(OBJEXT\)$/o/;
1924 $dep_files{'$(DEPDIR)/' . $depfile} = 1;
1928 return (&resolve_linker (%linkers_used), @result);
1933 # Handle SOURCE->OBJECT transform for one program or library.
1935 # canonical (transformed) name of object to build
1936 # actual name of object to build
1937 # object extension (ie either `.o' or `$o'.
1938 # Return result is name of linker variable that must be used.
1939 # Empty return means just use `LINK'.
1940 sub handle_source_transform
1942 # one_file is canonical name. unxformed is given name. obj is
1944 my ($one_file, $unxformed, $obj) = @_;
1948 if (&variable_defined ($one_file . "_OBJECTS"))
1950 &am_line_error ($one_file . '_OBJECTS',
1951 $one_file . '_OBJECTS', 'should not be defined');
1952 # No point in continuing.
1957 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1958 'dist_EXTRA_', 'nodist_EXTRA_')
1960 my $var = $prefix . $one_file . "_SOURCES";
1962 if !variable_defined ($var);
1964 # We are going to define _OBJECTS variables using the prefix.
1965 # Then we glom them all together. So we can't use the null
1966 # prefix here as we need it later.
1967 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
1969 # Keep track of which prefixes we saw.
1970 $used_pfx{$xpfx} = 1
1971 unless $prefix =~ /EXTRA_/;
1973 push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
1974 push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
1975 unless $prefix =~ /^nodist_/;
1976 foreach my $cond (variable_conditions ($var))
1978 my @files = &variable_value_as_list ($var, $cond);
1979 my ($temp, @result) =
1980 &handle_single_transform_list ($var, $one_file, $obj,
1982 # If there are no files to compile, don't require a linker (yet).
1986 # Define _OBJECTS conditionally.
1987 &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
1989 unless $prefix =~ /EXTRA_/;
1993 my @keys = sort keys %used_pfx;
1994 if (scalar @keys == 0)
1996 &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
1997 push (@sources, $unxformed . '.c');
1998 push (@dist_sources, $unxformed . '.c');
2000 my ($temp, @result) =
2001 &handle_single_transform_list ($one_file . '_SOURCES',
2004 $linker = $temp if $linker eq '';
2005 &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
2009 grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
2010 &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
2013 # If we want to use `LINK' we must make sure it is defined.
2023 # handle_lib_objects ($XNAME, $VAR)
2024 # ---------------------------------
2025 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
2026 # Also, generate _DEPENDENCIES variable if appropriate.
2028 # transformed name of object being built, or empty string if no object
2029 # name of _LDADD/_LIBADD-type variable to examine
2030 # Returns 1 if LIBOBJS seen, 0 otherwise.
2031 sub handle_lib_objects
2033 my ($xname, $var) = @_;
2035 &prog_error ("handle_lib_objects: $var undefined")
2036 if ! &variable_defined ($var);
2039 foreach my $cond (&variable_conditions ($var))
2041 if (&handle_lib_objects_cond ($xname, $var, $cond))
2049 # Subroutine of handle_lib_objects: handle a particular condition.
2050 sub handle_lib_objects_cond
2052 my ($xname, $var, $cond) = @_;
2054 # We recognize certain things that are commonly put in LIBADD or
2058 my $seen_libobjs = 0;
2061 foreach my $lsearch (&variable_value_as_list ($var, $cond))
2063 # Skip -lfoo and -Ldir; these are explicitly allowed.
2064 next if $lsearch =~ /^-[lL]/;
2065 if (! $flagvar && $lsearch =~ /^-/)
2067 if ($var =~ /^(.*)LDADD$/)
2069 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
2070 next if $lsearch =~ /^-dl(pre)?open$/;
2071 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2075 # Only get this error once.
2077 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2081 # Assume we have a file of some sort, and push it onto the
2082 # dependency list. Autoconf substitutions are not pushed;
2083 # rarely is a new dependency substituted into (eg) foo_LDADD
2084 # -- but "bad things (eg -lX11) are routinely substituted.
2085 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2086 # and handled specially below.
2087 push (@dep_list, $lsearch)
2088 unless $lsearch =~ /^\@.*\@$/;
2090 # Automatically handle @LIBOBJS@ and @ALLOCA@. Basically this
2091 # means adding entries to dep_files.
2092 if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
2094 my $myobjext = ($1 ? 'l' : '') . 'o';
2096 push (@dep_list, $lsearch);
2098 if (! keys %libsources
2099 && ! &variable_defined ($1 . 'LIBOBJS'))
2101 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in `$configure_ac'");
2104 foreach my $iter (keys %libsources)
2106 if ($iter =~ /\.([cly])$/)
2108 &saw_extension ($1);
2109 &saw_extension ('c');
2112 if ($iter =~ /\.h$/)
2114 &require_file_with_line ($var, $FOREIGN, $iter);
2116 elsif ($iter ne 'alloca.c')
2118 my $rewrite = $iter;
2119 $rewrite =~ s/\.c$/.P$myobjext/;
2120 $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
2121 ($rewrite = $iter) =~ s/(\W)/\\$1/g;
2122 $rewrite = "^" . $rewrite . "\$";
2123 # Only require the file if it is not a built source.
2124 if (! &variable_defined ('BUILT_SOURCES')
2125 || ! grep (/$rewrite/,
2126 &variable_value_as_list ('BUILT_SOURCES',
2129 &require_file_with_line ($var, $FOREIGN, $iter);
2134 elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
2136 my $myobjext = ($1 ? 'l' : '') . 'o';
2138 push (@dep_list, $lsearch);
2139 &am_line_error ($var,
2140 "\@$1" . "ALLOCA\@ seen but `AC_FUNC_ALLOCA' not in `$configure_ac'")
2141 if ! defined $libsources{'alloca.c'};
2142 $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
2143 &require_file_with_line ($var, $FOREIGN, 'alloca.c');
2144 &saw_extension ('c');
2148 if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
2150 &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
2153 return $seen_libobjs;
2156 # Canonicalize the input parameter
2160 $string =~ tr/A-Za-z0-9_\@/_/c;
2164 # Canonicalize a name, and check to make sure the non-canonical name
2165 # is never used. Returns canonical name. Arguments are name and a
2166 # list of suffixes to check for.
2167 sub check_canonical_spelling
2169 my ($name, @suffixes) = @_;
2171 my $xname = &canonicalize ($name);
2172 if ($xname ne $name)
2174 foreach my $xt (@suffixes)
2176 &am_line_error ("$name$xt",
2177 "invalid variable `$name$xt'; "
2178 . "should be `$xname$xt'")
2179 if &variable_defined ("$name$xt");
2189 # Set up the compile suite.
2190 sub handle_compile ()
2193 unless $get_object_extension_was_run;
2196 my $default_includes = '';
2197 if (! defined $options{'nostdinc'})
2199 $default_includes = ' -I. -I$(srcdir)';
2201 if (&variable_defined ('CONFIG_HEADER'))
2203 foreach my $hdr (split (' ', &variable_value ('CONFIG_HEADER')))
2205 $default_includes .= ' -I' . dirname ($hdr);
2210 my (@mostly_rms, @dist_rms);
2211 foreach my $item (sort keys %compile_clean_files)
2213 if ($compile_clean_files{$item} == $MOSTLY_CLEAN)
2215 push (@mostly_rms, "\t-rm -f $item");
2217 elsif ($compile_clean_files{$item} == $DIST_CLEAN)
2219 push (@dist_rms, "\t-rm -f $item");
2223 &prog_error ("invalid entry in \%compile_clean_files");
2227 my ($coms, $vars, $rules) =
2228 &file_contents_internal (1, "$am_dir/compile.am",
2229 ('DEFAULT_INCLUDES' => $default_includes,
2230 'MOSTLYRMS' => join ("\n", @mostly_rms),
2231 'DISTRMS' => join ("\n", @dist_rms)));
2232 $output_vars .= $vars;
2233 $output_rules .= "$coms$rules";
2237 # Output the libtool compilation rules.
2238 $output_rules .= &file_contents ('libtool');
2241 # Check for automatic de-ANSI-fication.
2242 if (defined $options{'ansi2knr'})
2244 if (! $am_c_prototypes)
2246 &am_line_error ('AUTOMAKE_OPTIONS',
2247 "option `ansi2knr' in use but `AM_C_PROTOTYPES' not in `$configure_ac'");
2248 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
2249 # Only give this error once.
2250 $am_c_prototypes = 1;
2253 # topdir is where ansi2knr should be.
2254 if ($options{'ansi2knr'} eq 'ansi2knr')
2256 # Only require ansi2knr files if they should appear in
2258 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
2259 'ansi2knr.c', 'ansi2knr.1');
2261 # ansi2knr needs to be built before subdirs, so unshift it.
2262 unshift (@all, '$(ANSI2KNR)');
2265 my $ansi2knr_dir = '';
2266 $ansi2knr_dir = dirname ($options{'ansi2knr'})
2267 if $options{'ansi2knr'} ne 'ansi2knr';
2269 $output_rules .= &file_contents ('ansi2knr',
2270 ('ANSI2KNR-DIR' => $ansi2knr_dir));
2277 # handle_programs ()
2278 # ------------------
2279 # Handle C programs.
2282 my @proglist = &am_install_var ('progs', 'PROGRAMS',
2283 'bin', 'sbin', 'libexec', 'pkglib',
2285 return if ! @proglist;
2287 my $seen_libobjs = 0;
2288 foreach my $one_file (@proglist)
2290 my $obj = &get_object_extension ($one_file);
2292 # Canonicalize names and check for misspellings.
2293 my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2294 '_SOURCES', '_OBJECTS',
2297 my $linker = &handle_source_transform ($xname, $one_file, $obj);
2300 if (&variable_defined ($xname . "_LDADD"))
2302 if (&handle_lib_objects ($xname, $xname . '_LDADD'))
2310 # User didn't define prog_LDADD override. So do it.
2311 &define_variable ($xname . '_LDADD', '$(LDADD)');
2313 # This does a bit too much work. But we need it to
2314 # generate _DEPENDENCIES when appropriate.
2315 if (&variable_defined ('LDADD'))
2317 if (&handle_lib_objects ($xname, 'LDADD'))
2322 elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
2324 &define_variable ($xname . '_DEPENDENCIES', '');
2329 if (&variable_defined ($xname . '_LIBADD'))
2331 &am_line_error ($xname . '_LIBADD',
2332 "use `" . $xname . "_LDADD', not `"
2333 . $xname . "_LIBADD'");
2336 if (! &variable_defined ($xname . '_LDFLAGS'))
2338 # Define the prog_LDFLAGS variable.
2339 &define_variable ($xname . '_LDFLAGS', '');
2342 # Determine program to use for link.
2344 if (&variable_defined ($xname . '_LINK'))
2346 $xlink = $xname . '_LINK';
2350 $xlink = $linker ? $linker : 'LINK';
2353 $output_rules .= &file_contents ('program',
2354 ('PROGRAM' => $one_file,
2355 'XPROGRAM' => $xname,
2356 'XLINK' => $xlink));
2359 if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD'))
2366 foreach my $one_file (@proglist)
2368 my $xname = &canonicalize ($one_file);
2370 if (&variable_defined ($xname . '_LDADD'))
2372 &check_libobjs_sources ($xname, $xname . '_LDADD');
2374 elsif (&variable_defined ('LDADD'))
2376 &check_libobjs_sources ($xname, 'LDADD');
2383 # handle_libraries ()
2384 # -------------------
2386 sub handle_libraries
2388 my @liblist = &am_install_var ('libs', 'LIBRARIES',
2389 'lib', 'pkglib', 'noinst', 'check');
2390 return if ! @liblist;
2392 my %valid = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2394 if (! defined $configure_vars{'RANLIB'})
2396 foreach my $key (keys %valid)
2398 if (&variable_defined ($key . '_LIBRARIES'))
2400 &am_line_error ($key . '_LIBRARIES', "library used but `RANLIB' not defined in `$configure_ac'");
2401 # Only get this error once. If this is ever printed,
2403 $configure_vars{'RANLIB'} = 'BUG';
2409 my $seen_libobjs = 0;
2410 foreach my $onelib (@liblist)
2412 # Check that the library fits the standard naming convention.
2413 if ($onelib !~ /^lib.*\.a$/)
2415 # FIXME should put line number here. That means mapping
2416 # from library name back to variable name.
2417 &am_error ("`$onelib' is not a standard library name");
2420 my $obj = &get_object_extension ($onelib);
2422 # Canonicalize names and check for misspellings.
2423 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2424 '_OBJECTS', '_DEPENDENCIES',
2427 if (! &variable_defined ($xlib . '_AR'))
2429 &define_variable ($xlib . '_AR', '$(AR) cru');
2432 if (&variable_defined ($xlib . '_LIBADD'))
2434 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2441 # Generate support for conditional object inclusion in
2443 &define_variable ($xlib . "_LIBADD", '');
2446 if (&variable_defined ($xlib . '_LDADD'))
2448 &am_line_error ($xlib . '_LDADD',
2449 "use `" . $xlib . "_LIBADD', not `"
2450 . $xlib . "_LDADD'");
2453 # Make sure we at look at this.
2454 &examine_variable ($xlib . '_DEPENDENCIES');
2456 &handle_source_transform ($xlib, $onelib, $obj);
2458 $output_rules .= &file_contents ('library',
2459 ('LIBRARY' => $onelib,
2460 'XLIBRARY' => $xlib));
2465 foreach my $onelib (@liblist)
2467 my $xlib = &canonicalize ($onelib);
2468 if (&variable_defined ($xlib . '_LIBADD'))
2470 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2477 # handle_ltlibraries ()
2478 # ---------------------
2479 # Handle shared libraries.
2480 sub handle_ltlibraries
2482 my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2483 'noinst', 'lib', 'pkglib', 'check');
2484 return if ! @liblist;
2487 my %valid = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2490 foreach my $key (keys %valid)
2492 if (&variable_defined ($key . '_LTLIBRARIES'))
2496 &am_line_error ($key . '_LTLIBRARIES', "library used but `LIBTOOL' not defined in `$configure_ac'");
2497 # Only get this error once. If this is ever printed,
2499 $configure_vars{'LIBTOOL'} = 'BUG';
2503 # Get the installation directory of each library.
2504 for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
2508 &am_error ("`$_' is already going to be installed in `$instdirs{$_}'");
2512 $instdirs{$_} = $key;
2518 my $seen_libobjs = 0;
2519 foreach my $onelib (@liblist)
2521 my $obj = &get_object_extension ($onelib);
2523 # Canonicalize names and check for misspellings.
2524 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2525 '_SOURCES', '_OBJECTS',
2528 if (! &variable_defined ($xlib . '_LDFLAGS'))
2530 # Define the lib_LDFLAGS variable.
2531 &define_variable ($xlib . '_LDFLAGS', '');
2534 # Check that the library fits the standard naming convention.
2535 my $libname_rx = "^lib.*\.la";
2536 if ((&variable_defined ($xlib . '_LDFLAGS')
2537 && grep (/-module/, &variable_value_as_list ($xlib . '_LDFLAGS',
2539 || (&variable_defined ('LDFLAGS')
2540 && grep (/-module/, &variable_value_as_list ('LDFLAGS',
2543 # Relax name checking for libtool modules.
2544 $libname_rx = "\.la";
2546 if ($onelib !~ /$libname_rx$/)
2548 # FIXME this should only be a warning for foreign packages
2549 # FIXME should put line number here. That means mapping
2550 # from library name back to variable name.
2551 &am_error ("`$onelib' is not a standard libtool library name");
2554 if (&variable_defined ($xlib . '_LIBADD'))
2556 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2563 # Generate support for conditional object inclusion in
2565 &define_variable ($xlib . "_LIBADD", '');
2568 if (&variable_defined ($xlib . '_LDADD'))
2570 &am_line_error ($xlib . '_LDADD',
2571 "use `" . $xlib . "_LIBADD', not `"
2572 . $xlib . "_LDADD'");
2575 # Make sure we at look at this.
2576 &examine_variable ($xlib . '_DEPENDENCIES');
2578 my $linker = &handle_source_transform ($xlib, $onelib, $obj);
2580 # Determine program to use for link.
2582 if (&variable_defined ($xlib . '_LINK'))
2584 $xlink = $xlib . '_LINK';
2588 $xlink = $linker ? $linker : 'LINK';
2592 if ($instdirs{$onelib} eq 'EXTRA'
2593 || $instdirs{$onelib} eq 'noinst'
2594 || $instdirs{$onelib} eq 'check')
2596 # It's an EXTRA_ library, so we can't specify -rpath,
2597 # because we don't know where the library will end up.
2598 # The user probably knows, but generally speaking automake
2599 # doesn't -- and in fact configure could decide
2600 # dynamically between two different locations.
2605 $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
2608 $output_rules .= &file_contents ('ltlibrary',
2609 ('LTLIBRARY' => $onelib,
2610 'XLTLIBRARY' => $xlib,
2612 'XLINK' => $xlink));
2617 foreach my $onelib (@liblist)
2619 my $xlib = &canonicalize ($onelib);
2620 if (&variable_defined ($xlib . '_LIBADD'))
2622 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2628 # See if any _SOURCES variable were misspelled. Also, make sure that
2629 # EXTRA_ variables don't contain configure substitutions.
2632 foreach my $varname (keys %var_value)
2634 foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
2637 if ($varname =~ /$primary$/ && ! $content_seen{$varname})
2639 &am_line_error ($varname,
2640 "invalid unused variable name: `$varname'");
2649 # NOTE we no longer automatically clean SCRIPTS, because it is
2650 # useful to sometimes distribute scripts verbatim. This happens
2651 # eg in Automake itself.
2652 &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2653 'bin', 'sbin', 'libexec', 'pkgdata',
2656 my $scripts_installed = 0;
2657 # Set $scripts_installed if appropriate. Make sure we only find
2658 # scripts which are actually installed -- this is why we can't
2659 # simply use the return value of am_install_var.
2660 my %valid = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
2661 'libexec', 'pkgdata',
2663 foreach my $key (keys %valid)
2665 if ($key ne 'noinst'
2667 && &variable_defined ($key . '_SCRIPTS'))
2669 $scripts_installed = 1;
2670 # push (@check_tests, 'check-' . $key . 'SCRIPTS');
2676 # ($OUTFILE, $VFILE, @CLEAN_FILES)
2677 # &scan_texinfo_file ($FILENAME)
2678 # ------------------------------
2679 # $OUTFILE is the name of the info file produced by $FILENAME.
2680 # $VFILE is the name of the version.texi file used (empty if none).
2681 # @CLEAN_FILES is the list of by products (indexes etc.)
2682 sub scan_texinfo_file
2684 my ($filename) = @_;
2686 # These are always created, no matter whether indexes are used or not.
2687 my @clean_suffixes = ('aux', 'dvi', 'log', 'ps', 'toc',
2688 # grep new.*index texinfo.tex
2689 'cp', 'fn', 'ky', 'vr', 'tp', 'pg');
2691 # There are predefined indexes which don't follow the regular rules.
2692 my %predefined_index =
2695 'c' => 'cps', 'f' => 'fns', 'k' => 'kys',
2696 'v' => 'vrs', 't' => 'tps', 'p' => 'pgs'
2699 # There are commands which include a hidden index command.
2703 'fn' => 'fns', 'un' => 'fns',
2704 'typefn' => 'fns', 'typefun' => 'fns',
2705 'mac' => 'fns', 'spec' => 'fns',
2706 'op' => 'fns', 'typeop' => 'fns',
2707 'method' => 'fns', 'typemethod' => 'fns',
2709 'vr' => 'vrs', 'var' => 'vrs',
2710 'typevr' => 'vrs', 'typevar' => 'vrs',
2713 'ivar' => 'vrs', 'typeivar' => 'vrs',
2718 # Indexes stored into another one. In this case, the *.??s file
2720 my @syncodeindexes = ();
2722 my $texi = new IO::File ("< $filename");
2725 &am_error ("couldn't open `$filename': $!");
2728 print "$me: reading $filename\n" if $verbose;
2730 my ($outfile, $vfile);
2731 while ($_ = $texi->getline)
2733 if (/^\@setfilename +(\S+)/)
2736 if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
2738 &am_file_error ($filename, "$.: ",
2739 "output `$outfile' has unrecognized extension");
2743 # A "version.texi" file is actually any file whose name
2744 # matches "vers*.texi".
2745 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2750 # Try to find what are the indexes which are used.
2752 # Creating a new category of index.
2753 elsif (/^\@def(code)?index (\w+)/)
2755 push @clean_suffixes, $2;
2758 # Storing in a predefined index.
2759 elsif (/^\@([cfkvtp])index /)
2761 push @clean_suffixes, $predefined_index{$1};
2763 elsif (/^\@def(\w+) /)
2765 push @clean_suffixes, $hidden_index{$1}
2766 if defined $hidden_index{$1};
2769 # Merging an index into an another.
2770 elsif (/^\@syn(code)?index (\w+) \w+/)
2772 push @syncodeindexes, "$2s";
2780 &am_error ("`$filename' missing \@setfilename");
2784 my $infobase = basename ($filename);
2785 $infobase =~ s/\.te?xi(nfo)?$//;
2787 grep { $clean_files{"$infobase.$_"} = 1 } @clean_suffixes;
2788 grep { delete $clean_files{"$infobase.$_"} } @syncodeindexes;
2789 return ($outfile, $vfile, (sort keys %clean_files));
2795 # Handle all Texinfo source.
2798 &am_line_error ('TEXINFOS',
2799 "`TEXINFOS' is an anachronism; use `info_TEXINFOS'")
2800 if &variable_defined ('TEXINFOS');
2801 return if (! &variable_defined ('info_TEXINFOS')
2802 && ! &variable_defined ('html_TEXINFOS'));
2804 if (&variable_defined ('html_TEXINFOS'))
2806 &am_line_error ('html_TEXINFOS',
2807 "HTML generation not yet supported");
2811 my @texis = &variable_value_as_list ('info_TEXINFOS', 'all');
2813 my (@info_deps_list, @dvis_list, @texi_deps);
2820 foreach my $info_cursor (@texis)
2822 my $infobase = $info_cursor;
2823 $infobase =~ s/\.(txi|texinfo|texi)$//;
2825 if ($infobase eq $info_cursor)
2827 # FIXME: report line number.
2828 &am_error ("texinfo file `$info_cursor' has unrecognized extension");
2831 $texi_suffixes{$1} = 1;
2833 # If 'version.texi' is referenced by input file, then include
2834 # automatic versioning capability.
2835 my ($out_file, $vtexi, @clean_files) =
2836 &scan_texinfo_file ("$relative_dir/$info_cursor")
2838 push (@texi_cleans, @clean_files);
2842 &am_error ("`$vtexi', included in `$info_cursor', also included in `$versions{$vtexi}'")
2843 if (defined $versions{$vtexi});
2844 $versions{$vtexi} = $info_cursor;
2846 # We number the stamp-vti files. This is doable since the
2847 # actual names don't matter much. We only number starting
2848 # with the second one, so that the common case looks nice.
2849 my $vti = ($done ? $done : 'vti');
2852 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2856 if ($config_aux_dir_set_in_configure_in)
2858 $conf_dir = $config_aux_dir;
2859 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
2863 $conf_dir = '$(srcdir)/';
2865 $output_rules .= &file_contents ('texi-vers',
2866 ('TEXI' => $info_cursor,
2869 'MDDIR' => $conf_dir));
2872 # If user specified file_TEXINFOS, then use that as explicit
2875 push (@texi_deps, $info_cursor);
2876 # Prefix with $(srcdir) because some version of make won't
2877 # work if the target has it and the dependency doesn't.
2878 push (@texi_deps, '$(srcdir)/' . $vtexi) if $vtexi;
2880 my $canonical = &canonicalize ($infobase);
2881 if (&variable_defined ($canonical . "_TEXINFOS"))
2883 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
2884 &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
2887 $output_rules .= ("\n" . $out_file . ": "
2888 . join (' ', @texi_deps)
2889 . "\n" . $infobase . ".dvi: "
2890 . join (' ', @texi_deps)
2893 push (@info_deps_list, $out_file);
2894 push (@dvis_list, $infobase . '.dvi');
2897 # Handle location of texinfo.tex.
2898 my $need_texi_file = 0;
2902 $texinfodir = '$(top_srcdir)/../texinfo';
2903 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
2906 elsif ($config_aux_dir_set_in_configure_in)
2908 $texinfodir = $config_aux_dir;
2909 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
2910 $need_texi_file = 2; # so that we require_conf_file later
2912 elsif (&variable_defined ('TEXINFO_TEX'))
2914 # The user defined TEXINFO_TEX so assume he knows what he is
2916 $texinfodir = ('$(srcdir)/'
2917 . dirname (&variable_value ('TEXINFO_TEX')));
2921 $texinfodir = '$(srcdir)';
2922 $need_texi_file = 1;
2925 foreach my $txsfx (sort keys %texi_suffixes)
2927 $output_rules .= &file_contents ('texibuild',
2928 ('TEXINFODIR' => $texinfodir,
2929 'SUFFIX' => $txsfx));
2932 my $texiclean = &pretty_print_internal ("", "\t ", @texi_cleans);
2933 $output_rules .= &file_contents ('texinfos',
2934 ('TEXICLEAN' => $texiclean));
2936 push (@dist_targets, 'dist-info');
2938 if (! defined $options{'no-installinfo'})
2940 # Make sure documentation is made and installed first. Use
2941 # $(INFO_DEPS), not 'info', because otherwise recursive makes
2942 # get run twice during "make all".
2943 unshift (@all, '$(INFO_DEPS)');
2946 &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2947 &define_variable ("DVIS", join (' ', @dvis_list));
2948 # This next isn't strictly needed now -- the places that look here
2949 # could easily be changed to look in info_TEXINFOS. But this is
2950 # probably better, in case noinst_TEXINFOS is ever supported.
2951 &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
2953 # Do some error checking. Note that this file is not required
2954 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2956 if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
2958 if ($need_texi_file > 1)
2960 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2965 &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
2970 # Handle any man pages.
2971 sub handle_man_pages
2973 &am_line_error ('MANS', "`MANS' is an anachronism; use `man_MANS'")
2974 if &variable_defined ('MANS');
2976 # Find all the sections in use. We do this by first looking for
2977 # "standard" sections, and then looking for any additional
2978 # sections used in man_MANS.
2979 my (%sections, %vlist);
2980 # We handle nodist_ for uniformity. man pages aren't distributed
2981 # by default so it isn't actually very important.
2982 foreach my $pfx ('', 'dist_', 'nodist_')
2984 # Add more sections as needed.
2985 foreach my $section ('0'..'9', 'n', 'l')
2987 if (&variable_defined ($pfx . 'man' . $section . '_MANS'))
2989 $sections{$section} = 1;
2990 $vlist{'$(' . $pfx . 'man' . $section . '_MANS)'} = 1;
2992 &push_dist_common ('$(' . $pfx . 'man' . $section . '_MANS)')
2997 if (&variable_defined ($pfx . 'man_MANS'))
2999 $vlist{'$(' . $pfx . 'man_MANS)'} = 1;
3000 foreach (&variable_value_as_list ($pfx . 'man_MANS', 'all'))
3002 # A page like `foo.1c' goes into man1dir.
3003 if (/\.([0-9a-z])([a-z]*)$/)
3009 &push_dist_common ('$(' . $pfx . 'man_MANS)')
3014 return unless %sections;
3016 # Now for each section, generate an install and unintall rule.
3017 # Sort sections so output is deterministic.
3018 foreach my $section (sort keys %sections)
3020 $output_rules .= &file_contents ('mans', ('SECTION' => $section));
3023 $output_vars .= &file_contents ('mans-vars',
3024 ('MANS' => join (' ', sort keys %vlist)));
3026 if (! defined $options{'no-installman'})
3028 push (@all, '$(MANS)');
3032 # Handle DATA variables.
3035 &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3036 'data', 'sysconf', 'sharedstate', 'localstate',
3037 'pkgdata', 'noinst', 'check');
3044 if (&variable_defined ('SUBDIRS'))
3046 $output_rules .= ("tags-recursive:\n"
3047 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3048 # Never fail here if a subdir fails; it
3050 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3051 . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3053 push (@tag_deps, 'tags-recursive');
3054 &depend ('.PHONY', 'tags-recursive');
3057 if (&saw_sources_p (1)
3058 || &variable_defined ('ETAGS_ARGS')
3062 foreach my $one_hdr (@config_headers)
3064 if ($relative_dir eq dirname ($one_hdr))
3066 # The config header is in this directory. So require it.
3067 $config .= ' ' if $config;
3068 $config .= basename ($one_hdr);
3071 $output_rules .= &file_contents ('tags',
3072 ('CONFIG' => $config,
3073 'DIRS' => join (' ', @tag_deps)));
3074 &examine_variable ('TAGS_DEPENDENCIES');
3076 elsif (&variable_defined ('TAGS_DEPENDENCIES'))
3078 &am_line_error ('TAGS_DEPENDENCIES',
3079 "doesn't make sense to define `TAGS_DEPENDENCIES' without sources or `ETAGS_ARGS'");
3083 # Every Makefile must define some sort of TAGS rule.
3084 # Otherwise, it would be possible for a top-level "make TAGS"
3085 # to fail because some subdirectory failed.
3086 $output_rules .= "tags: TAGS\nTAGS:\n\n";
3090 # Handle multilib support.
3093 return unless $seen_multilib;
3095 $output_rules .= &file_contents ('multilib');
3100 # &for_dist_common ($A, $B)
3101 # -------------------------
3102 # Subroutine for &handle_dist: sort files to dist.
3104 # We put README first because it then becomes easier to make a
3105 # Usenet-compliant shar file (in these, README must be first).
3107 # FIXME: do more ordering of files here.
3120 # handle_dist ($MAKEFILE)
3121 # -----------------------
3122 # Handle 'dist' target.
3125 my ($makefile) = @_;
3127 # `make dist' isn't used in a Cygnus-style tree.
3128 # Omit the rules so that people don't try to use them.
3129 return if $cygnus_mode;
3131 # Set up maint_charset.
3132 $local_maint_charset = &variable_value ('MAINT_CHARSET')
3133 if &variable_defined ('MAINT_CHARSET');
3134 $maint_charset = $local_maint_charset
3135 if $relative_dir eq '.';
3137 if (&variable_defined ('DIST_CHARSET'))
3139 &am_line_error ('DIST_CHARSET',
3140 "DIST_CHARSET defined but no MAINT_CHARSET defined")
3141 if ! $local_maint_charset;
3142 if ($relative_dir eq '.')
3144 $dist_charset = &variable_value ('DIST_CHARSET')
3148 &am_line_error ('DIST_CHARSET',
3149 "DIST_CHARSET can only be defined at top level");
3153 # Look for common files that should be included in distribution.
3154 foreach my $cfile (@common_files)
3156 if (-f ($relative_dir . "/" . $cfile))
3158 &push_dist_common ($cfile);
3162 # We might copy elements from $configure_dist_common to
3163 # %dist_common if we think we need to. If the file appears in our
3164 # directory, we would have discovered it already, so we don't
3165 # check that. But if the file is in a subdir without a Makefile,
3166 # we want to distribute it here if we are doing `.'. Ugly!
3167 if ($relative_dir eq '.')
3169 foreach my $file (split (' ' , $configure_dist_common))
3171 if (! &is_make_dir (dirname ($file)))
3173 &push_dist_common ($file);
3180 # Files to distributed. Don't use &variable_value_as_list
3181 # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3182 check_variable_defined_unconditionally ('DIST_COMMON');
3183 my @dist_common = split (' ', variable_value ('DIST_COMMON', 'TRUE'));
3184 @dist_common = uniq (sort for_dist_common (@dist_common));
3185 pretty_print ('DIST_COMMON = ', "\t", @dist_common);
3187 # Now that we've processed DIST_COMMON, disallow further attempts
3189 $handle_dist_run = 1;
3191 # Scan EXTRA_DIST to see if we need to distribute anything from a
3192 # subdir. If so, add it to the list. I didn't want to do this
3193 # originally, but there were so many requests that I finally
3195 if (&variable_defined ('EXTRA_DIST'))
3197 # FIXME: This should be fixed to work with conditionals. That
3198 # will require only making the entries in %dist_dirs under the
3199 # appropriate condition. This is meaningful if the nature of
3200 # the distribution should depend upon the configure options
3202 foreach (&variable_value_as_list ('EXTRA_DIST', ''))
3205 next unless s,/+[^/]+$,,;
3211 # We have to check DIST_COMMON for extra directories in case the
3212 # user put a source used in AC_OUTPUT into a subdir.
3213 foreach (&variable_value_as_list ('DIST_COMMON', 'all'))
3216 next unless s,/+[^/]+$,,;
3221 # Rule to check whether a distribution is viable.
3222 my %transform = ('DISTCHECK-HOOK' => &target_defined ('distcheck-hook'),
3223 'GETTEXT' => $seen_gettext);
3225 # Prepend $(distdir) to each directory given.
3227 grep ($rewritten{'$(distdir)/' . $_} = 1, keys %dist_dirs);
3228 $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);
3230 # If we have SUBDIRS, create all dist subdirectories and do
3232 if (&variable_defined ('SUBDIRS'))
3234 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3235 # to all possible directories, and use it. If DIST_SUBDIRS is
3236 # defined, just use it.
3237 my $dist_subdir_name;
3238 # Note that we check DIST_SUBDIRS first on purpose. At least
3239 # one project uses so many conditional subdirectories that
3240 # calling variable_conditionally_defined on SUBDIRS will cause
3241 # automake to grow to 150Mb. Sigh.
3242 if (&variable_defined ('DIST_SUBDIRS')
3243 || variable_conditionally_defined ('SUBDIRS'))
3245 $dist_subdir_name = 'DIST_SUBDIRS';
3246 if (! &variable_defined ('DIST_SUBDIRS'))
3248 &define_pretty_variable
3249 ('DIST_SUBDIRS', '',
3250 uniq (&variable_value_as_list ('SUBDIRS', 'all')));
3255 $dist_subdir_name = 'SUBDIRS';
3256 # We always define this because that is what `distclean'
3258 &define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
3261 $transform{'DIST_SUBDIR_NAME'} = $dist_subdir_name;
3264 # If the target `dist-hook' exists, make sure it is run. This
3265 # allows users to do random weird things to the distribution
3266 # before it is packaged up.
3267 push (@dist_targets, 'dist-hook')
3268 if &target_defined ('dist-hook');
3269 $transform{'DIST-TARGETS'} = join(' ', @dist_targets);
3271 # Defining $(DISTDIR).
3272 $transform{'DISTDIR'} = !&variable_defined('distdir');
3273 $transform{'TOP_DISTDIR'} = backname ($relative_dir);
3275 $output_rules .= &file_contents ('distdir', %transform);
3279 # Handle subdirectories.
3283 unless &variable_defined ('SUBDIRS');
3285 # Make sure each directory mentioned in SUBDIRS actually exists.
3286 foreach my $dir (&variable_value_as_list ('SUBDIRS', 'all'))
3288 # Skip directories substituted by configure.
3289 next if $dir =~ /^\@.*\@$/;
3291 if (! -d $am_relative_dir . '/' . $dir)
3293 &am_line_error ('SUBDIRS',
3294 "required directory $am_relative_dir/$dir does not exist");
3298 &am_line_error ('SUBDIRS', "directory should not contain `/'")
3302 $output_rules .= &file_contents ('subdirs');
3303 variable_pretty_output ('RECURSIVE_TARGETS', 'TRUE');
3307 # ($REGEN, @DEPENDENCIES)
3310 # If aclocal.m4 creation is automated, return the list of its dependencies.
3313 my $regen_aclocal = 0;
3316 unless $relative_dir eq '.';
3318 &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3319 &examine_variable ('CONFIGURE_DEPENDENCIES');
3321 if (-f 'aclocal.m4')
3323 &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3324 &push_dist_common ('aclocal.m4');
3326 my $aclocal = new IO::File ("< aclocal.m4");
3329 my $line = $aclocal->getline;
3332 if ($line =~ 'generated automatically by aclocal')
3341 if (-f 'acinclude.m4')
3344 push @ac_deps, 'acinclude.m4';
3347 if (&variable_defined ('ACLOCAL_M4_SOURCES'))
3349 push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3351 elsif (&variable_defined ('ACLOCAL_AMFLAGS'))
3353 # Scan all -I directories for m4 files. These are our
3355 my $examine_next = 0;
3356 foreach my $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
3361 if ($amdir !~ /^\// && -d $amdir)
3363 foreach my $ac_dep (&my_glob ($amdir . '/*.m4'))
3365 $ac_dep =~ s/^\.\/+//;
3366 push (@ac_deps, $ac_dep)
3367 unless $ac_dep eq "aclocal.m4"
3368 || $ac_dep eq "acinclude.m4";
3372 elsif ($amdir eq '-I')
3379 # Note that it might be possible that aclocal.m4 doesn't exist but
3380 # should be auto-generated. This case probably isn't very
3383 return ($regen_aclocal, @ac_deps);
3386 # Rewrite a list of input files into a form suitable to put on a
3387 # dependency list. The idea is that if an input file has a directory
3388 # part the same as the current directory, then the directory part is
3389 # simply removed. But if the directory part is different, then
3390 # $(top_srcdir) is prepended. Among other things, this is used to
3391 # generate the dependency list for the output files generated by
3392 # AC_OUTPUT. Consider what the dependencies should look like in this
3394 # AC_OUTPUT(src/out:src/in1:lib/in2)
3395 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3396 # If 0 then files that require this addition will simply be ignored.
3397 sub rewrite_inputs_into_dependencies
3399 my ($add_srcdir, @inputs) = @_;
3402 foreach my $single (@inputs)
3404 if (dirname ($single) eq $relative_dir)
3406 push (@newinputs, basename ($single));
3410 push (@newinputs, '$(top_srcdir)/' . $single);
3417 # Handle remaking and configure stuff.
3418 # We need the name of the input file, to do proper remaking rules.
3419 sub handle_configure
3421 my ($local, $input, @secondary_inputs) = @_;
3423 my $input_base = basename ($input);
3424 my $local_base = basename ($local);
3426 my $amfile = $input_base . '.am';
3427 # We know we can always add '.in' because it really should be an
3428 # error if the .in was missing originally.
3429 my $infile = '$(srcdir)/' . $input_base . '.in';
3430 my $colon_infile = '';
3431 if ($local ne $input || @secondary_inputs)
3433 $colon_infile = ':' . $input . '.in';
3435 $colon_infile .= ':' . join (':', @secondary_inputs)
3436 if @secondary_inputs;
3438 my @rewritten = &rewrite_inputs_into_dependencies (1, @secondary_inputs);
3440 my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4 ();
3443 &file_contents ('configure',
3447 => join (' ', @rewritten),
3449 => ((($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3454 => join (' ', @include_stack),
3458 => $cygnus_mode ? 'cygnus' : $strictness_name,
3460 => $cmdline_use_dependencies ? '' : ' --ignore-deps',
3461 'MAKEFILE-AM-SOURCES'
3462 => "$input$colon_infile",
3464 => $regen_aclocal_m4,
3466 => join (' ', @aclocal_m4_deps)));
3468 if ($relative_dir eq '.')
3470 &push_dist_common ('acconfig.h')
3474 # If we have a configure header, require it.
3475 my @local_fullnames = @config_fullnames;
3476 my @local_names = @config_names;
3478 my $distclean_config = '';
3479 foreach my $one_hdr (@config_headers)
3481 my $one_fullname = shift (@local_fullnames);
3482 my $one_name = shift (@local_names);
3484 my $header_dir = dirname ($one_name);
3486 # If the header is in the current directory we want to build
3487 # the header here. Otherwise, if we're at the topmost
3488 # directory and the header's directory doesn't have a
3489 # Makefile, then we also want to build the header.
3490 if ($relative_dir eq $header_dir
3491 || ($relative_dir eq '.' && ! &is_make_dir ($header_dir)))
3493 my ($cn_sans_dir, $stamp_dir);
3494 if ($relative_dir eq $header_dir)
3496 $cn_sans_dir = basename ($one_name);
3501 $cn_sans_dir = $one_name;
3502 if ($header_dir eq '.')
3508 $stamp_dir = $header_dir . '/';
3512 # Compute relative path from directory holding output
3513 # header to directory holding input header. FIXME:
3514 # doesn't handle case where we have multiple inputs.
3516 if (dirname ($one_hdr) eq $relative_dir)
3518 $ch_sans_dir = basename ($one_hdr);
3522 $ch_sans_dir = backname ($relative_dir) . '/' . $one_hdr;
3525 &require_file_with_conf_line ($config_header_line,
3526 $FOREIGN, $ch_sans_dir);
3528 # Header defined and in this directory.
3530 if (-f $one_name . '.top')
3532 push (@files, "${cn_sans_dir}.top");
3534 if (-f $one_name . '.bot')
3536 push (@files, "${cn_sans_dir}.bot");
3539 &push_dist_common (@files);
3541 # For now, acconfig.h can only appear in the top srcdir.
3542 if (-f 'acconfig.h')
3544 push (@files, '$(top_srcdir)/acconfig.h');
3547 my $stamp_name = 'stamp-h';
3548 $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3550 my $out_dir = dirname ($ch_sans_dir);
3553 &file_contents ('remake-hdr',
3554 ('FILES' => join (' ', @files),
3555 'CONFIG_HEADER' => $cn_sans_dir,
3556 'CONFIG_HEADER_IN' => $ch_sans_dir,
3557 'CONFIG_HEADER_FULL' => $one_fullname,
3558 'STAMP' => "$stamp_dir$stamp_name",
3559 'SRC_STAMP' => "$out_dir/$stamp_name"));
3561 &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3562 &require_file_with_conf_line ($config_header_line, $FOREIGN,
3563 "${out_dir}/${stamp_name}.in");
3565 $distclean_config .= ' ' if $distclean_config;
3566 $distclean_config .= $cn_sans_dir;
3570 if ($distclean_config)
3572 $output_rules .= &file_contents ('clean-hdr',
3573 ('FILES' => $distclean_config));
3576 # Set location of mkinstalldirs.
3577 &define_variable ('mkinstalldirs',
3578 ('$(SHELL) ' . $config_aux_dir . '/mkinstalldirs'));
3580 &am_line_error ('CONFIG_HEADER',
3581 "`CONFIG_HEADER' is an anachronism; now determined from `$configure_ac'")
3582 if &variable_defined ('CONFIG_HEADER');
3584 my $config_header = '';
3585 foreach my $one_name (@config_names)
3587 # Generate CONFIG_HEADER define.
3589 if ($relative_dir eq dirname ($one_name))
3591 $one_hdr = basename ($one_name);
3595 $one_hdr = "\$(top_builddir)/${one_name}";
3598 $config_header .= ' ' if $config_header;
3599 $config_header .= $one_hdr;
3603 &define_variable ("CONFIG_HEADER", $config_header);
3606 # Now look for other files in this directory which must be remade
3607 # by config.status, and generate rules for them.
3608 my @actual_other_files = ();
3609 foreach my $lfile (@other_input_files)
3612 my (@inputs, @rewritten_inputs);
3613 my ($need_rewritten);
3614 if ($lfile =~ /^([^:]*):(.*)$/)
3616 # This is the ":" syntax of AC_OUTPUT.
3618 $local = basename ($file);
3619 @inputs = split (':', $2);
3620 @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3621 $need_rewritten = 1;
3627 $local = basename ($file);
3628 @inputs = ($file . '.in');
3630 &rewrite_inputs_into_dependencies (1, @inputs);
3631 $need_rewritten = 0;
3634 # Make sure the dist directory for each input file is created.
3635 # We only have to do this at the topmost level though. This
3636 # is a bit ugly but it easier than spreading out the logic,
3637 # especially in cases like AC_OUTPUT(foo/out:bar/in), where
3638 # there is no Makefile in bar/.
3639 if ($relative_dir eq '.')
3643 $dist_dirs{dirname ($_)} = 1;
3647 # We skip any automake input files, as they are handled
3648 # elsewhere. We also skip files that aren't in this
3649 # directory. However, if the file's directory does not have a
3650 # Makefile, and we are currently doing `.', then we create a
3651 # rule to rebuild the file in the subdir.
3652 next if -f $file . '.am';
3653 my $fd = dirname ($file);
3654 if ($fd ne $relative_dir)
3656 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
3666 # Some users have been tempted to put `stamp-h' in the
3667 # AC_OUTPUT line. This won't do the right thing, so we
3668 # explicitly fail here.
3669 if ($local eq 'stamp-h')
3671 # FIXME: allow real filename.
3672 &am_conf_error ($configure_ac, $ac_output_line,
3673 'stamp-h should not appear in AC_OUTPUT');
3677 $output_rules .= ($local . ': '
3678 . '$(top_builddir)/config.status '
3679 . join (' ', @rewritten_inputs) . "\n"
3681 . 'cd $(top_builddir) && CONFIG_FILES='
3682 . ($relative_dir eq '.' ? '' : '$(subdir)/')
3683 . '$@' . ($need_rewritten
3684 ? (':' . join (':', @inputs))
3686 . ' CONFIG_HEADERS= CONFIG_LINKS= $(SHELL) ./config.status'
3688 push (@actual_other_files, $local);
3690 # Require all input files.
3691 &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3692 &rewrite_inputs_into_dependencies (0, @inputs));
3695 # These files get removed by "make clean".
3696 &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3702 my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3703 'oldinclude', 'pkginclude',
3707 next unless /\.(.*)$/;
3708 &saw_extension ($1);
3714 return if ! $seen_gettext || $relative_dir ne '.';
3716 if (! &variable_defined ('SUBDIRS'))
3719 ("AM_GNU_GETTEXT used but SUBDIRS not defined");
3723 my @subdirs = &variable_value_as_list ('SUBDIRS', 'all');
3724 &am_line_error ('SUBDIRS',
3725 "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
3726 if ! grep ('po', @subdirs);
3727 &am_line_error ('SUBDIRS',
3728 "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
3729 if ! grep ('intl', @subdirs);
3731 &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3733 # Ensure that each language in ALL_LINGUAS has a .po file, and
3734 # each po file is mentioned in ALL_LINGUAS.
3738 grep ($linguas{$_} = 1, split (' ', $all_linguas));
3745 &am_line_error ($all_linguas_line,
3746 ("po/$_.po exists but `$_' not in `ALL_LINGUAS'"))
3750 foreach (keys %linguas)
3752 &am_line_error ($all_linguas_line,
3753 "$_ in `ALL_LINGUAS' but po/$_.po does not exist")
3759 &am_error ("AM_GNU_GETTEXT in `$configure_ac' but `ALL_LINGUAS' not defined");
3763 # Handle footer elements.
3766 # NOTE don't use define_pretty_variable here, because
3767 # $contents{...} is already defined.
3768 $output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n\n"
3769 if variable_value ('SOURCES');
3772 &am_line_error ('.SUFFIXES',
3773 "use variable `SUFFIXES', not target `.SUFFIXES'")
3774 if target_defined ('.SUFFIXES');
3776 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3777 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
3778 # anything else, by sticking it right after the default: target.
3779 $output_header .= ".SUFFIXES:\n";
3780 if (@suffixes || &variable_defined ('SUFFIXES'))
3782 # Make sure suffixes has unique elements. Sort them to ensure
3783 # the output remains consistent. However, $(SUFFIXES) is
3784 # always at the start of the list, unsorted. This is done
3785 # because make will choose rules depending on the ordering of
3786 # suffixes, and this lets the user have some control. Push
3787 # actual suffixes, and not $(SUFFIXES). Some versions of make
3788 # do not like variable substitutions on the .SUFFIXES line.
3789 my @user_suffixes = (&variable_defined ('SUFFIXES')
3790 ? &variable_value_as_list ('SUFFIXES', '')
3794 grep ($suffixes{$_} = 1, @suffixes);
3795 delete @suffixes{@user_suffixes};
3797 $output_header .= (".SUFFIXES: "
3798 . join (' ', @user_suffixes, sort keys %suffixes)
3802 $output_trailer .= file_contents ('footer');
3805 # Deal with installdirs target.
3806 sub handle_installdirs ()
3809 &file_contents ('install',
3811 => variable_value ('_am_installdirs') || ''));
3815 # Deal with all and all-am.
3818 my ($makefile) = @_;
3822 # Put this at the beginning for the sake of non-GNU makes. This
3823 # is still wrong if these makes can run parallel jobs. But it is
3825 unshift (@all, basename ($makefile));
3827 foreach my $one_name (@config_names)
3829 push (@all, basename ($one_name))
3830 if dirname ($one_name) eq $relative_dir;
3833 # Install `all' hooks.
3834 if (&target_defined ("all-local"))
3836 push (@all, "all-local");
3837 &depend ('.PHONY', "all-local");
3840 &pretty_print_rule ("all-am:", "\t\t", @all);
3841 &depend ('.PHONY', 'all-am', 'all');
3846 my @local_headers = ();
3847 push @local_headers, '$(BUILT_SOURCES)'
3848 if &variable_defined ('BUILT_SOURCES');
3849 foreach my $one_name (@config_names)
3851 push @local_headers, basename ($one_name)
3852 if dirname ($one_name) eq $relative_dir;
3857 # We need to make sure config.h is built before we recurse.
3858 # We also want to make sure that built sources are built
3859 # before any ordinary `all' targets are run. We can't do this
3860 # by changing the order of dependencies to the "all" because
3861 # that breaks when using parallel makes. Instead we handle
3862 # things explicitly.
3863 $output_all .= ("all: " . join (' ', @local_headers)
3865 . '$(MAKE) $(AM_MAKEFLAGS) '
3866 . (&variable_defined ('SUBDIRS')
3867 ? 'all-recursive' : 'all-am')
3872 $output_all .= "all: " . (&variable_defined ('SUBDIRS')
3873 ? 'all-recursive' : 'all-am') . "\n\n";
3878 # Handle check merge target specially.
3879 sub do_check_merge_target
3881 if (&target_defined ('check-local'))
3883 # User defined local form of target. So include it.
3884 push (@check_tests, 'check-local');
3885 &depend ('.PHONY', 'check-local');
3888 # In --cygnus mode, check doesn't depend on all.
3891 # Just run the local check rules.
3892 &pretty_print_rule ('check-am:', "\t\t", @check);
3896 # The check target must depend on the local equivalent of
3897 # `all', to ensure all the primary targets are built. Then it
3898 # must build the local check rules.
3899 $output_rules .= "check-am: all-am\n";
3900 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
3904 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
3908 &depend ('.PHONY', 'check', 'check-am');
3909 $output_rules .= ("check: "
3910 . (&variable_defined ('SUBDIRS')
3911 ? 'check-recursive' : 'check-am')
3915 # Handle all 'clean' targets.
3920 # Don't include `MAINTAINER'; it is handled specially below.
3921 foreach my $name ('MOSTLY', '', 'DIST')
3923 $transform{"${name}CLEAN"} = &variable_defined ("${name}CLEANFILES");
3926 # Built sources are automatically removed by maintainer-clean.
3927 push (@maintainer_clean_files, '$(BUILT_SOURCES)')
3928 if &variable_defined ('BUILT_SOURCES');
3929 push (@maintainer_clean_files, '$(MAINTAINERCLEANFILES)')
3930 if &variable_defined ('MAINTAINERCLEANFILES');
3932 $output_rules .= &file_contents ('clean',
3935 # Join with no space to avoid
3936 # spurious `test -z' success at
3938 => join ('', @maintainer_clean_files),
3940 # A space is required in the join here.
3941 => join (' ', @maintainer_clean_files)));
3945 # &depend ($CATEGORY, @DEPENDENDEES)
3946 # ----------------------------------
3947 # The target $CATEGORY depends on @DEPENDENDEES.
3950 my ($category, @dependendees) = @_;
3952 push (@{$dependencies{$category}}, @dependendees);
3957 # &target_cmp ($A, $B)
3958 # --------------------
3959 # Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
3972 # &handle_factored_dependencies ()
3973 # --------------------------------
3974 # Handle everything related to gathered targets.
3975 sub handle_factored_dependencies
3978 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
3979 'uninstall-exec-local', 'uninstall-exec-hook')
3981 if (&target_defined ($utarg))
3984 $x =~ s/(data|exec)-//;
3985 &am_line_error ($utarg, "use `$x', not `$utarg'");
3989 if (&target_defined ('install-local'))
3991 &am_line_error ('install-local',
3992 "use `install-data-local' or `install-exec-local', "
3993 . "not `install-local'");
3996 if (!defined $options{'no-installinfo'}
3997 && &target_defined ('install-info-local'))
3999 &am_line_error ('install-info-local',
4000 "`install-info-local' target defined but "
4001 . "`no-installinfo' option not in use");
4004 # Install the -local hooks.
4005 foreach (keys %dependencies)
4007 # Hooks are installed on the -am targets.
4009 if (&target_defined ("$_-local"))
4011 depend ("$_-am", "$_-local");
4012 &depend ('.PHONY', "$_-local");
4016 # Install the -hook hooks.
4017 # FIXME: Why not be as liberal as we are with -local hooks?
4018 foreach ('install-exec', 'install-data')
4020 if (&target_defined ("$_-hook"))
4022 $actions{"$_-am"} .=
4023 ("\t\@\$(NORMAL_INSTALL)\n"
4024 . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
4028 # All the required targets are phony.
4029 grep { &depend ('.PHONY', $_) } keys %required_targets;
4031 # Actually output gathered targets.
4032 foreach (sort target_cmp keys %dependencies)
4034 # If there is nothing about this guy, skip it.
4036 unless (@{$dependencies{$_}}
4038 || $required_targets{$_});
4039 &pretty_print_rule ("$_:", "\t",
4040 uniq (sort @{$dependencies{$_}}));
4041 $output_rules .= $actions{$_}
4042 if defined $actions{$_};
4043 $output_rules .= "\n";
4048 # &handle_tests_dejagnu ()
4049 # ------------------------
4050 sub handle_tests_dejagnu
4052 push (@check_tests, 'check-DEJAGNU');
4054 # Only create site.exp rule if user hasn't already written one.
4056 file_contents ('dejagnu', ('SITE-EXP' => ! target_defined ('site.exp')));
4060 # Handle TESTS variable and other checks.
4063 if (defined $options{'dejagnu'})
4065 &handle_tests_dejagnu;
4069 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4072 "`$c' defined but `dejagnu' not in `AUTOMAKE_OPTIONS'")
4073 if &variable_defined ($c);
4077 if (&variable_defined ('TESTS'))
4079 push (@check_tests, 'check-TESTS');
4080 $output_rules .= &file_contents ('check');
4084 # Handle Emacs Lisp.
4085 sub handle_emacs_lisp
4087 my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4090 return if ! @elfiles;
4092 # Generate .elc files.
4093 grep ($_ .= 'c', @elfiles);
4094 &define_pretty_variable ('ELCFILES', '', @elfiles);
4096 push (@all, '$(ELCFILES)');
4098 &am_error ("`lisp_LISP' defined but `AM_PATH_LISPDIR' not in `$configure_ac'")
4099 if ! $seen_lispdir && &variable_defined ('lisp_LISP');
4101 &require_file_with_conf_line ('AM_PATH_LISPDIR', $FOREIGN, 'elisp-comp');
4107 my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4108 'python', 'noinst');
4109 return if ! @pyfiles;
4111 # Found some python.
4112 &am_error ("`python_PYTHON' defined but `AM_PATH_PYTHON' not in `$configure_ac'")
4113 if ! $seen_pythondir && &variable_defined ('python_PYTHON');
4115 &require_file_with_conf_line ('AM_PATH_PYTHON', $FOREIGN, 'py-compile');
4116 &define_variable ('py_compile', $config_aux_dir . '/py-compile');
4122 my @sourcelist = &am_install_var ('-candist',
4124 'java', 'noinst', 'check');
4125 return if ! @sourcelist;
4127 my %valid = &am_primary_prefixes ('JAVA', 1,
4128 'java', 'noinst', 'check');
4131 foreach my $curs (keys %valid)
4133 if (! &variable_defined ($curs . '_JAVA') || $curs eq 'EXTRA')
4140 &am_line_error ($curs . '_JAVA',
4141 "multiple _JAVA primaries in use");
4146 push (@all, 'class' . $dir . '.stamp');
4150 # Handle some of the minor options.
4151 sub handle_minor_options
4153 if (defined $options{'readme-alpha'})
4155 if ($relative_dir eq '.')
4157 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4159 # FIXME: allow real filename.
4160 &am_conf_line_error ($configure_ac,
4161 $package_version_line,
4162 "version `$package_version' doesn't follow Gnits standards");
4164 elsif (defined $1 && -f 'README-alpha')
4166 # This means we have an alpha release. See
4167 # GNITS_VERSION_PATTERN for details.
4168 &require_file ($FOREIGN, 'README-alpha');
4174 ################################################################
4177 my @make_input_list;
4178 # &scan_autoconf_config_files ($CONFIG-FILES)
4179 # -------------------------------------------
4180 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4182 sub scan_autoconf_config_files
4184 my ($config_files) = @_;
4185 # Look at potential Makefile.am's.
4186 foreach (split ' ', $config_files)
4188 # Must skip empty string for Perl 4.
4189 next if $_ eq "\\" || $_ eq '';
4191 # Handle $local:$input syntax. Note that we ignore
4192 # every input file past the first, though we keep
4193 # those around for later.
4194 my ($local, $input, @rest) = split (/:/);
4201 # FIXME: should be error if .in is missing.
4202 $input =~ s/\.in$//;
4205 if (-f $input . '.am')
4207 # We have a file that automake should generate.
4208 push (@make_input_list, $input);
4209 $make_list{$input} = join (':', ($local, @rest));
4213 # We have a file that automake should cause to be
4214 # rebuilt, but shouldn't generate itself.
4215 push (@other_input_files, $_);
4221 # &scan_autoconf_traces ($FILENAME)
4222 # ---------------------------------
4223 # FIXME: For the time being, we don't care about the FILENAME.
4224 sub scan_autoconf_traces
4226 my ($filename) = @_;
4228 my $traces = "$ENV{amtraces} ";
4230 $traces .= ' -t AC_CONFIG_FILES';
4231 $traces .= ' -t AC_LIBSOURCE';
4232 $traces .= ' -t AC_SUBST';
4234 my $tracefh = new IO::File ("$traces |");
4237 die "$me: couldn't open `$traces': $!\n";
4239 print "$me: reading $traces\n" if $verbose;
4241 while ($_ = $tracefh->getline)
4244 my ($file, $line, $macro, @args) = split /:/;
4245 my $here = "$file:$line";
4247 # Alphabetical ordering please.
4248 if ($macro eq 'AC_CONFIG_FILES')
4250 # Look at potential Makefile.am's.
4251 &scan_autoconf_config_files ($args[0]);
4253 elsif ($macro eq 'AC_LIBSOURCE')
4255 my $source = "$args[0].c";
4256 # We should actually also `close' the sources: getopt.c
4257 # wants getopt.h etc. But actually it should be done in the
4258 # macro itself, i.e., we have to first fix Autoconf to extend
4259 # _AC_LIBOBJ_DECL and use it the in various macros.
4260 if (!defined $libsources{$source})
4262 print STDERR "traces: discovered $source\n";
4263 $libsources{$source} = $here;
4266 elsif ($macro eq 'AC_SUBST')
4268 if (!defined $configure_vars{$args[0]})
4270 print STDERR "traces: discovered AC_SUBST($args[0])\n";
4271 $configure_vars{$args[0]} = $here;
4277 || die "$me: close: $traces: $!\n";
4281 # &scan_one_autoconf_file ($FILENAME)
4282 # -----------------------------------
4283 # Scan one file for interesting things. Subroutine of
4284 # &scan_autoconf_files.
4285 sub scan_one_autoconf_file
4287 my ($filename) = @_;
4289 my $configfh = new IO::File ("< $filename");
4292 die "$me: couldn't open `$filename': $!\n";
4294 print "$me: reading $filename\n" if $verbose;
4296 my ($in_ac_output, $in_ac_replace) = (0, 0);
4297 while ($_ = $configfh->getline)
4299 # Remove comments from current line.
4303 # Skip macro definitions. Otherwise we might be confused into
4304 # thinking that a macro that was only defined was actually
4308 # Follow includes. This is a weirdness commonly in use at
4309 # Cygnus and hopefully nowhere else.
4310 if (/sinclude\((.*)\)/ && -f $1)
4312 # $_ being local, if we don't preserve it, when coming
4313 # back we will have $_ undefined, which is bad for the
4314 # the rest of this routine.
4315 my $underscore = $_;
4316 &scan_one_autoconf_file ($1);
4320 # Populate libobjs array.
4321 if (/AC_FUNC_ALLOCA/)
4323 $libsources{'alloca.c'} = 1;
4325 elsif (/AC_FUNC_GETLOADAVG/)
4327 $libsources{'getloadavg.c'} = 1;
4329 elsif (/AC_FUNC_MEMCMP/)
4331 $libsources{'memcmp.c'} = 1;
4333 elsif (/AC_STRUCT_ST_BLOCKS/)
4335 $libsources{'fileblocks.c'} = 1;
4337 elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4339 $libsources{'getopt.c'} = 1;
4340 $libsources{'getopt1.c'} = 1;
4342 elsif (/AM_FUNC_STRTOD/)
4344 $libsources{'strtod.c'} = 1;
4346 elsif (/AM_WITH_REGEX/)
4348 $libsources{'rx.c'} = 1;
4349 $libsources{'rx.h'} = 1;
4350 $libsources{'regex.c'} = 1;
4351 $libsources{'regex.h'} = 1;
4353 elsif (/AC_FUNC_MKTIME/)
4355 $libsources{'mktime.c'} = 1;
4357 elsif (/AM_FUNC_ERROR_AT_LINE/)
4359 $libsources{'error.c'} = 1;
4360 $libsources{'error.h'} = 1;
4362 elsif (/AM_FUNC_OBSTACK/)
4364 $libsources{'obstack.c'} = 1;
4365 $libsources{'obstack.h'} = 1;
4367 elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4368 || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4370 foreach my $libobj_iter (split (' ', $1))
4372 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4373 || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4374 || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4376 $libsources{$1 . '.c'} = 1;
4380 elsif (/AC_LIBOBJ\(([^)]+)\)/)
4382 $libsources{"$1.c"} = 1;
4385 if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4391 $in_ac_replace = 0 if s/[\]\)].*$//;
4392 # Remove trailing backslash.
4396 # Need to skip empty elements for Perl 4.
4398 $libsources{$_ . '.c'} = 1;
4402 if (/$obsolete_rx/o)
4405 if ($obsolete_macros{$1} ne '')
4407 $hint = '; ' . $obsolete_macros{$1};
4409 &am_conf_line_error ($filename, $., "`$1' is obsolete$hint");
4412 # Process the AC_OUTPUT and AC_CONFIG_FILES macros.
4413 if (! $in_ac_output && s/AC_(OUTPUT|CONFIG_FILES)\s*\(\[?//)
4416 $ac_output_line = $.;
4427 # Look at potential Makefile.am's.
4428 &scan_autoconf_config_files ($_);
4430 if ($closing && @make_input_list == 0 && @other_input_files == 0)
4432 &am_conf_line_error ($filename, $ac_output_line,
4433 "No files mentioned in `AC_OUTPUT'");
4438 if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4440 @config_aux_path = &unquote_m4_arg ($1);
4441 $config_aux_dir_set_in_configure_in = 1;
4444 # Check for ansi2knr.
4445 $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4447 # Check for exe extension stuff.
4451 $configure_vars{'EXEEXT'} = $filename . ':' . $.;
4457 $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4460 # Check for `-c -o' code.
4461 $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4463 # Check for NLS support.
4464 if (/AM_GNU_GETTEXT/)
4467 $ac_gettext_line = $.;
4470 # Look for ALL_LINGUAS.
4471 if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4475 $all_linguas_line = $.;
4478 # Handle configuration headers. A config header of `[$1]'
4479 # means we are actually scanning AM_CONFIG_HEADER from
4481 if (/A([CM])_CONFIG_HEADERS?\s*\((.*)\)/
4485 ($filename, $., "`automake requires `AM_CONFIG_HEADER', not `AC_CONFIG_HEADER'")
4488 $config_header_line = $.;
4489 foreach my $one_hdr (split (' ', &unquote_m4_arg ($2)))
4491 push (@config_fullnames, $one_hdr);
4492 if ($one_hdr =~ /^([^:]+):(.+)$/)
4494 push (@config_names, $1);
4495 push (@config_headers, $2);
4499 push (@config_names, $one_hdr);
4500 push (@config_headers, $one_hdr . '.in');
4505 # Handle AC_CANONICAL_*. Always allow upgrading to
4506 # AC_CANONICAL_SYSTEM, but never downgrading.
4507 $seen_canonical = $AC_CANONICAL_HOST
4508 if ! $seen_canonical
4509 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4510 $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4512 # If using X, include some extra variable definitions. NOTE
4513 # we don't want to force these into CFLAGS or anything,
4514 # because not all programs will necessarily use X.
4517 foreach my $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS',
4520 $configure_vars{$var} = $filename . ':' . $.
4524 # This macro handles several different things.
4525 if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4527 ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4528 $package_version_line = $.;
4529 $seen_init_automake = 1;
4534 $configure_vars{'LEX'} = $filename . ':' . $.;
4535 $seen_decl_yytext = 1;
4537 if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.(ac|in)$/)
4539 &am_conf_line_warning ($filename, $., "`AC_DECL_YYTEXT' is covered by `AM_PROG_LEX'");
4541 if (/AC_PROG_LEX/ && $filename =~ /configure\.(ac|in)$/)
4543 &am_conf_line_warning ($filename, $., "automake requires `AM_PROG_LEX', not `AC_PROG_LEX'");
4546 if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4548 $configure_vars{$1} = $filename . ':' . $.;
4550 if (/$AC_CHECK_PATTERN/o)
4552 $configure_vars{$3} = $filename . ':' . $.;
4554 if (/$AM_MISSING_PATTERN/o
4558 && $1 ne 'AUTOHEADER'
4559 # AM_INIT_AUTOMAKE is AM_MISSING_PROG'ing MAKEINFO. But
4560 # we handle it elsewhere.
4561 && $1 ne 'MAKEINFO')
4563 $configure_vars{$1} = $filename . ':' . $.;
4566 # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4567 # but later define it elsewhere. This is pretty hacky. We
4568 # also explicitly avoid INSTALL_SCRIPT and some other
4569 # variables because they are defined in header-vars.am.
4571 if (/$AC_SUBST_PATTERN/o
4573 && $1 ne 'INSTALL_SCRIPT'
4574 && $1 ne 'INSTALL_DATA')
4576 $configure_vars{$1} = $filename . ':' . $.;
4579 $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4580 if (/AM_MAINTAINER_MODE/)
4582 $seen_maint_mode = 1;
4583 $configure_cond{'MAINTAINER_MODE'} = 1;
4586 $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4588 if (/AM_PATH_PYTHON/)
4590 $seen_pythondir = 1;
4591 $configure_vars{'pythondir'} = $filename . ':' . $.;
4592 $configure_vars{'PYTHON'} = $filename . ':' . $.;
4595 if (/A(C|M)_PROG_LIBTOOL/)
4597 # We're not ready for this yet. People still use a
4598 # libtool with no AC_PROG_LIBTOOL. Once that is the
4599 # dominant version we can reenable this code -- but next
4600 # time by mentioning the macro in %obsolete_macros, both
4601 # here and in aclocal.in.
4603 # if (/AM_PROG_LIBTOOL/)
4605 # &am_conf_line_warning ($filename, $., "`AM_PROG_LIBTOOL' is obsolete, use `AC_PROG_LIBTOOL' instead");
4609 $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4610 $configure_vars{'RANLIB'} = $filename . ':' . $.;
4611 $configure_vars{'CC'} = $filename . ':' . $.;
4612 # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST. Make sure we
4613 # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4614 $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4617 $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4619 if (/$AM_CONDITIONAL_PATTERN/o)
4621 $configure_cond{$1} = 1;
4624 # Check for Fortran 77 intrinsic and run-time libraries.
4625 if (/AC_F77_LIBRARY_LDFLAGS/)
4627 $configure_vars{'FLIBS'} = $filename . ':' . $.;
4635 # &scan_autoconf_files ()
4636 # -----------------------
4637 # Check whether we use `configure.ac' or `configure.in'.
4638 # Scan it (and possibly `aclocal.m4') for interesting things.
4639 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
4640 sub scan_autoconf_files
4642 # Reinitialize libsources here. This isn't really necessary,
4643 # since we currently assume there is only one configure.ac. But
4644 # that won't always be the case.
4647 warn "$me: both `configure.ac' and `configure.in' present:"
4648 . " ignoring `configure.in'\n"
4649 if -f 'configure.ac' && -f 'configure.in';
4650 $configure_ac = 'configure.in'
4651 if -f 'configure.in';
4652 $configure_ac = 'configure.ac'
4653 if -f 'configure.ac';
4654 die "$me: `configure.ac' or `configure.in' is required\n"
4657 &scan_one_autoconf_file ($configure_ac);
4658 &scan_one_autoconf_file ('aclocal.m4')
4661 if (defined $ENV{'amtraces'})
4663 warn '$me: Autoconf traces is an experimental feature';
4664 warn '$me: use at your own risks';
4666 &scan_autoconf_traces ($configure_ac);
4669 # Set input and output files if not specified by user.
4672 @input_files = @make_input_list;
4673 %output_files = %make_list;
4676 @configure_input_files = @make_input_list;
4678 &am_conf_error ("`AM_INIT_AUTOMAKE' must be used")
4679 if ! $seen_init_automake;
4681 # Look for some files we need. Always check for these. This
4682 # check must be done for every run, even those where we are only
4683 # looking at a subdir Makefile. We must set relative_dir so that
4684 # the file-finding machinery works.
4685 # FIXME: Is this broken because it needs dynamic scopes.
4686 # My tests seems to show it's not the case.
4687 $relative_dir = '.';
4688 &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4689 &am_error ("`install.sh' is an anachronism; use `install-sh' instead")
4690 if -f $config_aux_path[0] . '/install.sh';
4692 &require_config_file ($FOREIGN, 'py-compile')
4695 # Preserve dist_common for later.
4696 $configure_dist_common = variable_value ('DIST_COMMON', 'TRUE') || '';
4699 ################################################################
4701 # Set up for Cygnus mode.
4704 return unless $cygnus_mode;
4706 &set_strictness ('foreign');
4707 $options{'no-installinfo'} = 1;
4708 $options{'no-dependencies'} = 1;
4709 $use_dependencies = 0;
4711 if (! $seen_maint_mode)
4713 &am_conf_error ("`AM_MAINTAINER_MODE' required when --cygnus specified");
4717 # Do any extra checking for GNU standards.
4718 sub check_gnu_standards
4720 if ($relative_dir eq '.')
4722 # In top level (or only) directory.
4723 &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4724 'AUTHORS', 'ChangeLog');
4727 if ($strictness >= $GNU
4728 && defined $options{'no-installman'})
4730 &am_line_error ('AUTOMAKE_OPTIONS',
4731 "option `no-installman' disallowed by GNU standards");
4734 if ($strictness >= $GNU
4735 && defined $options{'no-installinfo'})
4737 &am_line_error ('AUTOMAKE_OPTIONS',
4738 "option `no-installinfo' disallowed by GNU standards");
4742 # Do any extra checking for GNITS standards.
4743 sub check_gnits_standards
4745 if ($relative_dir eq '.')
4747 # In top level (or only) directory.
4748 &require_file ($GNITS, 'THANKS');
4752 ################################################################
4754 # Functions to handle files of each language.
4756 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
4757 # simple formula: Return value is $LANG_SUBDIR if the resulting object
4758 # file should be in a subdir if the source file is, $LANG_PROCESS if
4759 # file is to be dealt with, $LANG_IGNORE otherwise.
4761 # Much of the actual processing is handled in
4762 # handle_single_transform_list. These functions exist so that
4763 # auxiliary information can be recorded for a later cleanup pass.
4764 # Note that the calls to these functions are computed, so don't bother
4765 # searching for their precise names in the source.
4767 # This is just a convenience function that can be used to determine
4768 # when a subdir object should be used.
4771 return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4774 # Rewrite a single C source file.
4777 my ($directory, $base, $ext) = @_;
4779 if (defined $options{'ansi2knr'} && $base =~ /_$/)
4781 # FIXME: include line number in error.
4782 &am_error ("C source file `$base.c' would be deleted by ansi2knr rules");
4785 my $r = $LANG_PROCESS;
4786 if (defined $options{'subdir-objects'})
4789 $base = $directory . '/' . $base;
4793 # Only give error once.
4795 # FIXME: line number.
4796 &am_error ("C objects in subdir but `AM_PROG_CC_C_O' not in `$configure_ac'");
4799 &require_file ($FOREIGN, 'compile')
4800 if $relative_dir eq '.';
4803 $de_ansi_files{$base} = 1;
4807 # Rewrite a single C++ source file.
4808 sub lang_cxx_rewrite
4810 return &lang_sub_obj;
4813 # Rewrite a single header file.
4814 sub lang_header_rewrite
4816 # Header files are simply ignored.
4817 return $LANG_IGNORE;
4820 # Rewrite a single yacc file.
4821 sub lang_yacc_rewrite
4823 my ($directory, $base, $ext) = @_;
4825 my $r = &lang_c_rewrite ($directory, $base, $ext);
4827 if ($r == $LANG_SUBDIR)
4829 $pfx = $directory . '/';
4831 $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4833 &saw_extension ('c');
4835 &push_dist_common ($pfx . $base . '.' . $ext);
4839 # Rewrite a single yacc++ file.
4840 sub lang_yaccxx_rewrite
4842 my ($directory, $base, $ext) = @_;
4844 my $r = $LANG_PROCESS;
4846 if (defined $options{'subdir-objects'})
4848 $pfx = $directory . '/';
4851 $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4853 &saw_extension ($ext);
4855 &push_dist_common ($pfx . $base . '.' . $ext);
4859 # Rewrite a single lex file.
4860 sub lang_lex_rewrite
4862 my ($directory, $base, $ext) = @_;
4864 my $r = &lang_c_rewrite ($directory, $base, $ext);
4866 if ($r == $LANG_SUBDIR)
4868 $pfx = $directory . '/';
4870 $lex_sources{$pfx . $base . '.' . $ext} = 1;
4872 &saw_extension ('c');
4874 &push_dist_common ($pfx . $base . '.' . $ext);
4878 # Rewrite a single lex++ file.
4879 sub lang_lexxx_rewrite
4881 my ($directory, $base, $ext) = @_;
4883 my $r = $LANG_PROCESS;
4885 if (defined $options{'subdir-objects'})
4887 $pfx = $directory . '/';
4890 $lex_sources{$pfx . $base . '.' . $ext} = 1;
4892 &saw_extension ($ext);
4894 &push_dist_common ($pfx . $base . '.' . $ext);
4898 # Rewrite a single assembly file.
4899 sub lang_asm_rewrite
4901 return &lang_sub_obj;
4904 # Rewrite a single Fortran 77 file.
4905 sub lang_f77_rewrite
4907 return $LANG_PROCESS;
4910 # Rewrite a single preprocessed Fortran 77 file.
4911 sub lang_ppf77_rewrite
4913 return $LANG_PROCESS;
4916 # Rewrite a single ratfor file.
4917 sub lang_ratfor_rewrite
4919 return $LANG_PROCESS;
4922 # Rewrite a single Objective C file.
4923 sub lang_objc_rewrite
4925 return &lang_sub_obj;
4928 # Rewrite a single Java file.
4929 sub lang_java_rewrite
4931 return $LANG_SUBDIR;
4934 # The lang_X_finish functions are called after all source file
4935 # processing is done. Each should handle defining rules for the
4936 # language, etc. A finish function is only called if a source file of
4937 # the appropriate type has been seen.
4941 # Push all libobjs files onto de_ansi_files. We actually only
4942 # push files which exist in the current directory, and which are
4943 # genuine source files.
4944 foreach my $file (keys %libsources)
4946 if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
4948 $de_ansi_files{$1} = 1;
4952 if (defined $options{'ansi2knr'} && keys %de_ansi_files)
4954 # Make all _.c files depend on their corresponding .c files.
4956 foreach my $base (sort keys %de_ansi_files)
4958 # Each _.c file must depend on ansi2knr; otherwise it
4959 # might be used in a parallel build before it is built.
4960 # We need to support files in the srcdir and in the build
4961 # dir (because these files might be auto-generated. But
4962 # we can't use $< -- some makes only define $< during a
4964 $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
4965 . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
4966 . '`if test -f $(srcdir)/' . $base . '.c'
4967 . '; then echo $(srcdir)/' . $base . '.c'
4968 . '; else echo ' . $base . '.c; fi` '
4969 . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
4970 . '| $(ANSI2KNR) > ' . $base . "_.c\n");
4971 push (@objects, $base . '_.$(OBJEXT)');
4972 push (@objects, $base . '_.lo')
4976 # Make all _.o (and _.lo) files depend on ansi2knr.
4977 # Use a sneaky little hack to make it print nicely.
4978 &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
4983 # This is a helper for both lex and yacc.
4984 sub yacc_lex_finish_helper
4986 return if defined $language_scratch{'lex-yacc-done'};
4987 $language_scratch{'lex-yacc-done'} = 1;
4989 # If there is more than one distinct yacc (resp lex) source file
4990 # in a given directory, then the `ylwrap' program is required to
4991 # allow parallel builds to work correctly. FIXME: for now, no
4993 &require_config_file ($FOREIGN, 'ylwrap');
4994 if ($config_aux_dir_set_in_configure_in)
4996 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5000 &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
5004 sub lang_yacc_finish
5006 return if defined $language_scratch{'yacc-done'};
5007 $language_scratch{'yacc-done'} = 1;
5009 my %seen_suffix = ();
5010 my @yacc_files = sort keys %yacc_sources;
5011 my $yacc_count = scalar (@yacc_files);
5012 foreach my $file (@yacc_files)
5015 &output_yacc_build_rule ($1, $yacc_count > 1)
5016 if ! defined $seen_suffix{$1};
5017 $seen_suffix{$1} = 1;
5019 $file =~ /^(.*)\.(y|yy|y\+\+|yxx|ypp)$/;
5021 my $hname = 'h'; # Always use `.h' for header file.
5025 if ((&variable_defined ('AM_YFLAGS')
5026 && &variable_value ('AM_YFLAGS') =~ /(^|\s)-d(\s|$)/)
5027 || (&variable_defined ('YFLAGS')
5028 && &variable_value ('YFLAGS') =~ /(^|\s)-d(\s|$)/)) {
5029 # Now generate rule to make the header file. This should only
5030 # be generated if `yacc -d' specified.
5031 $output_rules .= "${base}.${hname}: ${base}.${cname}\n";
5033 # If the files are built in the build directory, then we want
5034 # to remove them with `make clean'. If they are in srcdir
5035 # they shouldn't be touched. However, we can't determine this
5036 # statically, and the GNU rules say that yacc/lex output files
5037 # should be removed by maintainer-clean. So that's what we
5039 push (@maintainer_clean_files, "${base}.${hname}");
5041 &push_dist_common ("${base}.${hname}");
5043 push (@maintainer_clean_files, "${base}.${cname}");
5045 $output_rules .= "\n";
5047 if (&variable_defined ('YACCFLAGS'))
5049 &am_line_error ('YACCFLAGS',
5050 "`YACCFLAGS' obsolete; use `YFLAGS' instead");
5053 if ($yacc_count > 1)
5055 &yacc_lex_finish_helper;
5062 return if defined $language_scratch{'lex-done'};
5063 $language_scratch{'lex-done'} = 1;
5065 my %seen_suffix = ();
5066 my $lex_count = scalar (keys %lex_sources);
5067 foreach my $file (sort keys %lex_sources)
5070 &output_lex_build_rule ($1, $lex_count > 1)
5071 if (! defined $seen_suffix{$1});
5072 $seen_suffix{$1} = 1;
5074 # If the files are built in the build directory, then we want
5075 # to remove them with `make clean'. If they are in srcdir
5076 # they shouldn't be touched. However, we can't determine this
5077 # statically, and the GNU rules say that yacc/lex output files
5078 # should be removed by maintainer-clean. So that's what we
5080 $file =~ /^(.*)\.(l|ll|l\+\+|lxx|lpp)$/;
5082 ($cname = $2) =~ tr/l/c/;
5083 push (@maintainer_clean_files, "${1}.${cname}");
5086 if (! $seen_decl_yytext)
5088 &am_error ("lex source seen but `AC_DECL_YYTEXT' not in `$configure_ac'");
5093 &yacc_lex_finish_helper;
5098 # Given a hash table of linker names, pick the name that has the most
5099 # precedence. This is lame, but something has to have global
5100 # knowledge in order to eliminate the conflict. Add more linkers as
5107 if defined $linkers{'GCJLINK'};
5109 if defined $linkers{'CXXLINK'};
5111 if defined $linkers{'F77LINK'};
5113 if defined $linkers{'OBJCLINK'};
5117 # Called to indicate that an extension was used.
5121 $extension_seen{$ext} = 1;
5124 # Called to ask whether source files have been seen . If HEADERS is 1,
5125 # headers can be included.
5136 $headers = grep ($extension_seen{$_},
5137 @{$languages{'header'}->extensions});
5140 return scalar keys %extension_seen > $headers;
5144 # register_language (%ATTRIBUTE)
5145 # ------------------------------
5146 # Register a single language.
5147 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5148 sub register_language (%)
5154 unless defined $option{'ansi'};
5155 $option{'autodep'} = 'no'
5156 unless defined $option{'autodep'};
5157 $option{'derived_autodep'} = 'no'
5158 unless defined $option{'derived_autodep'};
5159 $option{'linker'} = ''
5160 unless defined $option{'linker'};
5162 my $lang = new Language (%option);
5165 grep ($extension_map{$_} = $lang->name, @{$lang->extensions});
5166 $languages{$lang->name} = $lang;
5169 # This function is used to find a path from a user-specified suffix to
5170 # `o' or to some other suffix we recognize internally, eg `cc'.
5173 my ($source_ext) = @_;
5175 # FIXME: hard-coding `o' is a mistake. Doing something
5176 # intelligent is harder.
5177 while ($extension_map{$source_ext} eq ''
5178 && $source_ext ne 'o'
5179 && defined $suffix_rules{$source_ext})
5181 $source_ext = $suffix_rules{$source_ext};
5188 ################################################################
5190 # Pretty-print something. HEAD is what should be printed at the
5191 # beginning of the first line, FILL is what should be printed at the
5192 # beginning of every subsequent line.
5193 sub pretty_print_internal
5195 my ($head, $fill, @values) = @_;
5197 my $column = length ($head);
5200 # Fill length is number of characters. However, each Tab
5201 # character counts for eight. So we count the number of Tabs and
5203 my $fill_length = length ($fill);
5204 $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5208 # "71" because we also print a space.
5209 if ($column + length ($_) > 71)
5211 $result .= " \\\n" . $fill;
5212 $column = $fill_length;
5214 $result .= ' ' if $result =~ /\S\z/;
5216 $column += length ($_) + 1;
5223 # Pretty-print something and append to output_vars.
5226 $output_vars .= &pretty_print_internal (@_);
5229 # Pretty-print something and append to output_rules.
5230 sub pretty_print_rule
5232 $output_rules .= &pretty_print_internal (@_);
5236 ################################################################
5240 # &conditional_string(@COND-STACK)
5241 # --------------------------------
5243 sub conditional_string
5247 if (grep (/^FALSE$/, @stack))
5253 return join (' ', uniq sort grep (!/^TRUE$/, @stack));
5259 # &conditional_true_when ($COND, $WHEN)
5260 # -------------------------------------
5261 # See if a conditional is true. Both arguments are conditional
5262 # strings. This returns true if the first conditional is true when
5263 # the second conditional is true.
5264 # For instance with $COND = `BAR FOO', and $WHEN = `BAR BAZ FOO',
5265 # obviously return 1, and 0 when, for instance, $WHEN = `FOO'.
5266 sub conditional_true_when ($$)
5268 my ($cond, $when) = @_;
5270 # Make a hash holding all the values from $WHEN.
5271 my %cond_vals = map { $_ => 1 } split (' ', $when);
5273 # Check each component of $cond, which looks `COND1 COND2'.
5274 foreach my $comp (split (' ', $cond))
5276 # TRUE is always true.
5277 next if $comp eq 'TRUE';
5278 return 0 if ! defined $cond_vals{$comp};
5286 # &conditionals_true_when (@CONDS, @WHENS)
5287 # ----------------------------------------
5288 # Same as above, but true if all the @CONDS are true when *ALL*
5289 # the @WHENS are sufficient.
5291 # If there are no @CONDS, then return true, of course. *BUT*, even if there
5292 # are @CONDS but @WHENS is empty, return true. This is counter intuitive,
5293 # and against all the rules of logic, but is needed by the current code.
5294 # FIXME: Do something saner when the logic of conditionals is understood.
5295 sub conditionals_true_when (@@)
5297 my (@conds, @whens) = @_;
5299 foreach my $cond (@conds)
5301 foreach my $when (@whens)
5304 unless conditional_true_when ($cond, $when);
5313 # condition_negate ($COND)
5314 # ------------------------
5315 sub condition_negate ($)
5319 $cond =~ s/TRUE$/TRUEO/;
5320 $cond =~ s/FALSE$/TRUE/;
5321 $cond =~ s/TRUEO$/FALSE/;
5327 # Compare condition names.
5328 # Issue them in alphabetical order, foo_TRUE before foo_FALSE.
5331 # Be careful we might be comparing `' or `#'.
5332 $a =~ /^(.*)_(TRUE|FALSE)$/;
5333 my ($aname, $abool) = ($1 || '', $2 || '');
5334 $b =~ /^(.*)_(TRUE|FALSE)$/;
5335 my ($bname, $bbool) = ($1 || '', $2 || '');
5336 return ($aname cmp $bname
5337 # Don't bother with IFs, given that TRUE is after FALSE
5338 # just cmp in the reverse order.
5339 || $bbool cmp $abool
5345 # &make_condition (@CONDITIONS)
5346 # -----------------------------
5347 # Transform a list of conditions (themselves can be an internal list
5348 # of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
5349 # Make conditional (a pattern for AC_SUBST).
5350 # Correctly returns the empty string when there are no conditions.
5353 my $res = conditional_string (@_);
5355 # There are no conditions.
5361 elsif ($res eq 'FALSE')
5368 $res = '@' . $res . '@';
5377 ## ------------------------------ ##
5378 ## Handling the condition stack. ##
5379 ## ------------------------------ ##
5383 # cond_stack_if ($NEGATE, $COND, $WHERE)
5384 # --------------------------------------
5385 sub cond_stack_if ($$$)
5387 my ($negate, $cond, $where) = @_;
5389 &am_file_error ($where, "$cond does not appear in AM_CONDITIONAL")
5390 if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
5392 $cond = "${cond}_TRUE"
5393 unless $cond =~ /^TRUE|FALSE$/;
5394 $cond = condition_negate ($cond)
5397 push (@cond_stack, $cond);
5399 return conditional_string (@cond_stack);
5404 # cond_stack_else ($NEGATE, $COND, $WHERE)
5405 # ----------------------------------------
5406 sub cond_stack_else ($$$)
5408 my ($negate, $cond, $where) = @_;
5412 &am_file_error ($where, "else without if");
5416 $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);
5418 # If $COND is given, check against it.
5421 $cond = "${cond}_TRUE"
5422 unless $cond =~ /^TRUE|FALSE$/;
5423 $cond = condition_negate ($cond)
5426 &am_file_error ($where,
5427 "else reminder ($negate$cond) incompatible with "
5428 . "current conditional: $cond_stack[$#cond_stack]")
5429 if $cond_stack[$#cond_stack] ne $cond;
5432 return conditional_string (@cond_stack);
5437 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5438 # -----------------------------------------
5439 sub cond_stack_endif ($$$)
5441 my ($negate, $cond, $where) = @_;
5446 &am_file_error ($where, "endif without if: $negate$cond");
5451 # If $COND is given, check against it.
5454 $cond = "${cond}_TRUE"
5455 unless $cond =~ /^TRUE|FALSE$/;
5456 $cond = condition_negate ($cond)
5459 &am_file_error ($where,
5460 "endif reminder ($negate$cond) incompatible with "
5461 . "current conditional: $cond_stack[$#cond_stack]")
5462 if $cond_stack[$#cond_stack] ne $cond;
5467 return conditional_string (@cond_stack);
5474 ## ------------------------ ##
5475 ## Handling the variables. ##
5476 ## ------------------------ ##
5479 # check_ambiguous_conditional ($VAR, $COND)
5480 # -----------------------------------------
5481 # Check for an ambiguous conditional. This is called when a variable
5482 # is being defined conditionally. If we already know about a
5483 # definition that is true under the same conditions, then we have an
5485 sub check_ambiguous_conditional ($$)
5487 my ($var, $cond) = @_;
5488 foreach my $vcond (keys %{$var_value{$var}})
5491 if ($vcond eq $cond)
5493 $message = "$var multiply defined in condition $cond";
5495 elsif (&conditional_true_when ($vcond, $cond))
5497 $message = ("$var was already defined in condition $vcond, "
5498 . "which implies condition $cond");
5500 elsif (&conditional_true_when ($cond, $vcond))
5502 $message = ("$var was already defined in condition $vcond, "
5503 . "which is implied by condition $cond");
5507 &am_line_error ($var, $message);
5514 # ¯o_define($VAR, $VAR_IS_AM, $TYPE, $COND, $VALUE, $WHERE)
5515 # -------------------------------------------------------------
5516 # The $VAR can go from Automake to user, but not the converse.
5517 sub macro_define ($$$$$$)
5519 my ($var, $var_is_am, $type, $cond, $value, $where) = @_;
5521 am_file_error ($where, "bad macro name `$var'")
5522 if $var !~ /$MACRO_PATTERN/o;
5526 # An Automake variable must be consistently defined with the same
5527 # sign by Automake. A user variable must be set by either `=' or
5528 # `:=', and later promoted to `+='.
5531 if (defined $var_type{$var} && $var_type{$var} ne $type)
5533 am_line_error ($var,
5534 ("$var was set with `$var_type{$var}=' "
5535 . "and is now set with `$type='"));
5540 if (!defined $var_type{$var} && $type eq '+')
5542 am_line_error ($var, "$var must be set with `=' before using `+='");
5545 $var_type{$var} = $type;
5547 # When adding, since we rewrite, don't try to preserve the
5548 # Automake continuation backslashes.
5550 if $type eq '+' && $var_is_am;
5552 # Differentiate the first assignment (including with `+=').
5553 if ($type eq '+' && defined $var_value{$var}{$cond})
5555 if (substr ($var_value{$var}{$cond}, -1) eq "\n")
5557 # Insert a backslash before a trailing newline.
5558 $var_value{$var}{$cond} =
5559 substr ($var_value{$var}{$cond}, 0, -1) . "\\\n";
5561 elsif ($var_value{$var}{$cond})
5563 # Insert a separator.
5564 $var_value{$var}{$cond} .= ' ';
5566 $var_value{$var}{$cond} .= $value;
5570 # The first assignment to a macro sets the line number. Ideally I
5571 # suppose we would associate line numbers with random bits of text.
5572 # FIXME: We sometimes redefine some variables, but we want to keep
5573 # the original location. More subs are needed to handle
5574 # properly variables. Once this done, remove this hack.
5575 $var_line{$var} = $where
5576 unless defined $var_line{$var};
5578 # If Automake tries to override a value specified by the user,
5579 # just don't let it do.
5580 if (defined $var_value{$var}{$cond} && !$var_is_am{$var} && $var_is_am)
5584 print STDERR "$me: refusing to override the user definition of:\n";
5585 variable_dump ($var);
5586 print STDERR "$me: with `$cond' => `$value'\n";
5591 # There must be no previous value unless the user is redefining
5592 # an Automake variable or an AC_SUBST variable.
5593 check_ambiguous_conditional ($var, $cond)
5594 unless ($var_is_am{$var} && !$var_is_am
5595 || exists $configure_vars{$var});
5597 $var_value{$var}{$cond} = $value;
5601 # An Automake variable can be given to the user, but not the converse.
5602 if (! defined $var_is_am{$var} || !$var_is_am)
5604 $var_is_am{$var} = $var_is_am;
5609 # &variable_delete ($VAR, [@CONDS])
5610 # ---------------------------------
5611 # Forget about $VAR under the conditions @CONDS, or completely if
5613 sub variable_delete ($@)
5615 my ($var, @conds) = @_;
5619 delete $var_value{$var};
5620 delete $var_line{$var};
5621 delete $var_is_am{$var};
5622 delete $var_comment{$var};
5623 delete $var_type{$var};
5627 foreach my $cond (@conds)
5629 delete $var_value{$var}{$cond};
5635 # ¯o_dump ($VAR)
5636 # ------------------
5641 if (!exists $var_value{$var})
5643 print STDERR " $var does not exist\n";
5647 my $var_is_am = $var_is_am{$var} ? "Automake" : "User";
5648 my $where = (defined $var_line{$var}
5649 ? $var_line{$var} : "undefined");
5650 print STDERR "$var_comment{$var}"
5651 if defined $var_comment{$var};
5652 print STDERR " $var ($var_is_am, where = $where) $var_type{$var}=\n";
5653 print STDERR " {\n";
5654 foreach my $vcond (sort by_condition keys %{$var_value{$var}})
5656 print STDERR " $vcond => $var_value{$var}{$vcond}\n";
5658 print STDERR " }\n";
5669 print STDERR "%var_value =\n";
5671 foreach my $var (sort (keys %var_value))
5680 # &variable_defined ($VAR, [$COND])
5681 # ---------------------------------
5682 # See if a variable exists. $VAR is the variable name, and $COND is
5683 # the condition which we should check. If no condition is given, we
5684 # currently return true if the variable is defined under any
5686 sub variable_defined ($$)
5688 my ($var, $cond) = @_;
5690 # Unfortunately we can't just check for $var_value{VAR}{COND}
5691 # as this would make perl create $condition{VAR}, which we
5693 if (!exists $var_value{$var})
5695 if (defined $targets{$var})
5697 &am_line_error ($var, "`$var' is a target; expected a variable")
5699 # The variable is not defined
5703 if ($cond && !exists $var_value{$var}{$cond})
5705 # The variable is not defined for the given condition.
5709 # Even a var_value examination is good enough for us. FIXME:
5710 # really should maintain examined status on a per-condition basis.
5711 $content_seen{$var} = 1;
5715 # Mark a variable as examined.
5716 sub examine_variable
5719 &variable_defined ($var);
5722 # Return the set of conditions for which a variable is defined.
5724 # If the variable is not defined conditionally, and is not defined in
5725 # terms of any variables which are defined conditionally, then this
5726 # returns the empty list.
5728 # If the variable is defined conditionally, but is not defined in
5729 # terms of any variables which are defined conditionally, then this
5730 # returns the list of conditions for which the variable is defined.
5732 # If the variable is defined in terms of any variables which are
5733 # defined conditionally, then this returns a full set of permutations
5734 # of the subvariable conditions. For example, if the variable is
5735 # defined in terms of a variable which is defined for COND_TRUE,
5736 # then this returns both COND_TRUE and COND_FALSE. This is
5737 # because we will need to define the variable under both conditions.
5739 sub variable_conditions ($)
5746 foreach my $cond (&variable_conditions_sub ($var, '', ()))
5749 if $cond eq 'FALSE';
5750 $uniqify{$cond} = 1;
5753 @uniq_list = sort by_condition keys %uniqify;
5754 # Note we cannot just do `return sort keys %uniqify', because this
5755 # function is sometimes used in a scalar context.
5761 # &variable_conditionally_defined ($VAR)
5762 # --------------------------------------
5763 sub variable_conditionally_defined ($)
5766 foreach my $cond (variable_conditions ($var))
5769 unless $cond =~ /^TRUE|FALSE$/;
5776 # &variable_conditions_sub ($VAR, $PARENT, @PARENT_CONDS)
5777 # -------------------------------------------------------
5778 # A subroutine of variable_conditions. We only return conditions
5779 # which are true for all the conditions in @PARENT_CONDS.
5780 sub variable_conditions_sub
5782 my ($var, $parent, @parent_conds) = @_;
5785 if (defined $vars_scanned{$var})
5787 &am_line_error ($parent, "variable `$var' recursively defined");
5790 $vars_scanned{$var} = 1;
5792 my @this_conds = ();
5793 foreach my $vcond (keys %{$var_value{$var}})
5796 if ! conditionals_true_when ((@parent_conds), ($vcond));
5798 push (@this_conds, $vcond);
5800 push (@parent_conds, $vcond);
5801 my @subvar_conds = ();
5802 foreach (split (' ', $var_value{$var}{$vcond}))
5804 # If a comment seen, just leave.
5807 # Handle variable substitutions.
5808 if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5810 push (@subvar_conds,
5811 &variable_conditions_sub ($1, $var, @parent_conds));
5814 pop (@parent_conds);
5816 # If there are no conditional subvariables, then we want to
5817 # return this condition. Otherwise, we want to return the
5818 # permutations of the subvariables.
5819 if (! @subvar_conds)
5821 push (@new_conds, $vcond);
5825 push (@new_conds, &variable_conditions_reduce (@subvar_conds));
5829 # Unset our entry in vars_scanned. We only care about recursive
5831 delete $vars_scanned{$var};
5833 # If there are no parents, then this call is the top level call.
5836 # Now we want to return all permutations of the subvariable
5839 foreach my $item (@new_conds)
5841 foreach (split (' ', $item))
5843 s/^(.*)_(TRUE|FALSE)$/$1_TRUE/;
5847 return &variable_conditions_permutations (sort keys %allconds);
5850 # If we are being called on behalf of another variable, we need to
5851 # return all possible permutations of the conditions. We have
5852 # already handled everything in @this_conds along with their
5853 # subvariables. We now need to add any permutations that are not
5855 foreach my $this_cond (@this_conds)
5858 &variable_conditions_permutations (split(' ', $this_cond));
5859 foreach my $perm (@perms)
5862 foreach my $scan (@this_conds)
5864 if (&conditional_true_when ($perm, $scan)
5865 || &conditional_true_when ($scan, $perm))
5874 if ! conditionals_true_when ((@parent_conds), ($perm));
5876 # This permutation was not already handled, and is valid
5878 push (@new_conds, $perm);
5886 # Filter a list of conditionals so that only the exclusive ones are
5887 # retained. For example, if both `COND1_TRUE COND2_TRUE' and
5888 # `COND1_TRUE' are in the list, discard the latter.
5889 sub variable_conditions_reduce
5893 foreach my $cond (@conds)
5895 # FALSE is absorbent.
5896 if ($cond eq 'FALSE')
5900 elsif (conditionals_true_when (($cond), (@ret)))
5909 # Return a list of permutations of a conditional string.
5910 sub variable_conditions_permutations
5915 my $comp = shift (@comps);
5916 return &variable_conditions_permutations (@comps)
5918 my $neg = condition_negate ($comp);
5921 foreach my $sub (&variable_conditions_permutations (@comps))
5923 push (@ret, "$comp $sub");
5924 push (@ret, "$neg $sub");
5936 # &check_variable_defined_unconditionally($VAR, $PARENT)
5937 # ------------------------------------------------------
5938 # Warn if a variable is conditionally defined. This is called if we
5939 # are using the value of a variable.
5940 sub check_variable_defined_unconditionally ($$)
5942 my ($var, $parent) = @_;
5943 foreach my $cond (keys %{$var_value{$var}})
5946 if $cond =~ /^TRUE|FALSE$/;
5950 &am_line_error ($parent,
5951 "warning: automake does not support conditional definition of $var in $parent");
5955 &am_line_error ($parent,
5956 "warning: automake does not support $var being defined conditionally");
5964 # Get the TRUE value of a variable, warn if the variable is
5965 # conditionally defined.
5969 &check_variable_defined_unconditionally ($var);
5970 return $var_value{$var}{'TRUE'};
5975 # &value_to_list ($VAR, $VAL, $COND)
5976 # ----------------------------------
5977 # Convert a variable value to a list, split as whitespace. This will
5978 # recursively follow $(...) and ${...} inclusions. It preserves @...@
5981 # If COND is 'all', then all values under all conditions should be
5982 # returned; if COND is a particular condition (all conditions are
5983 # surrounded by @...@) then only the value for that condition should
5984 # be returned; otherwise, warn if VAR is conditionally defined.
5985 # SCANNED is a global hash listing whose keys are all the variables
5986 # already scanned; it is an error to rescan a variable.
5989 my ($var, $val, $cond) = @_;
5993 $val =~ s/\\(\n|$)/ /g;
5995 foreach (split (' ', $val))
5997 # If a comment seen, just leave.
6000 # Handle variable substitutions.
6001 if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
6005 # If the user uses a losing variable name, just ignore it.
6006 # This isn't ideal, but people have requested it.
6007 next if ($varname =~ /\@.*\@/);
6011 if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
6015 ($from = $2) =~ s/(\W)/\\$1/g;
6019 @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
6021 # Now rewrite the value if appropriate.
6024 grep (s/$from$/$to/, @temp_list);
6027 push (@result, @temp_list);
6038 # Return contents of variable as list, split as whitespace. This will
6039 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6040 # substitutions. If COND is 'all', then all values under all
6041 # conditions should be returned; if COND is a particular condition
6042 # (all conditions are surrounded by @...@) then only the value for
6043 # that condition should be returned; otherwise, warn if VAR is
6044 # conditionally defined. If PARENT is specified, it is the name of
6045 # the including variable; this is only used for error reports.
6046 sub variable_value_as_list_worker
6048 my ($var, $cond, $parent) = @_;
6051 if (! defined $var_value{$var})
6053 if (defined $targets{$var})
6055 &am_line_error ($var, "`$var' is a target; expected a variable");
6059 &am_line_error ($parent, "variable `$var' not defined");
6062 elsif (defined $vars_scanned{$var})
6064 # `vars_scanned' is a global we use to keep track of which
6065 # variables we've already examined.
6066 &am_line_error ($parent, "variable `$var' recursively defined");
6068 elsif ($cond eq 'all')
6070 $vars_scanned{$var} = 1;
6071 foreach my $vcond (keys %{$var_value{$var}})
6073 my $val = $var_value{$var}{$vcond};
6074 push (@result, &value_to_list ($var, $val, $cond));
6080 $vars_scanned{$var} = 1;
6082 foreach my $vcond (keys %{$var_value{$var}})
6084 my $val = $var_value{$var}{$vcond};
6085 if (&conditional_true_when ($vcond, $cond))
6087 # Warn if we have an ambiguity. It's hard to know how
6088 # to handle this case correctly.
6089 &check_variable_defined_unconditionally ($var, $parent)
6092 push (@result, &value_to_list ($var, $val, $cond));
6097 # Unset our entry in vars_scanned. We only care about recursive
6099 delete $vars_scanned{$var};
6105 # &variable_output ($VAR, [@CONDS])
6106 # ---------------------------------
6107 # Output all the values of $VAR is @COND is not specified, else only
6108 # that corresponding to @COND.
6109 sub variable_output ($@)
6111 my ($var, @conds) = @_;
6113 @conds = sort by_condition keys %{$var_value{$var}}
6116 $output_vars .= $var_comment{$var}
6117 if defined $var_comment{$var};
6119 foreach my $cond (@conds)
6121 my $val = $var_value{$var}{$cond};
6122 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6123 my $output_var = "$var $equals $val";
6124 $output_var =~ s/^/make_condition ($cond)/meg;
6125 $output_vars .= $output_var . "\n";
6130 # &variable_pretty_output ($VAR, [@CONDS])
6131 # ----------------------------------------
6132 # Likewise, but pretty, i.e., we *split* the values at spaces. Use only
6133 # with variables holding filenames.
6134 sub variable_pretty_output ($@)
6136 my ($var, @conds) = @_;
6138 @conds = sort by_condition keys %{$var_value{$var}}
6141 $output_vars .= $var_comment{$var}
6142 if defined $var_comment{$var};
6144 foreach my $cond (@conds)
6146 my $val = $var_value{$var}{$cond};
6147 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6148 my $make_condition = make_condition ($cond);
6149 $output_vars .= pretty_print_internal ("$make_condition$var $equals",
6150 "$make_condition\t",
6151 split (' ' , $val));
6156 # This is just a wrapper for variable_value_as_list_worker that
6157 # initializes the global hash `vars_scanned'. This hash is used to
6158 # avoid infinite recursion.
6159 sub variable_value_as_list
6161 my ($var, $cond, $parent) = @_;
6163 return &variable_value_as_list_worker ($var, $cond, $parent);
6167 # Like define_variable, but the value is a list, and the variable may
6168 # be defined conditionally. The second argument is the conditional
6169 # under which the value should be defined; this should be the empty
6170 # string to define the variable unconditionally. The third argument
6171 # is a list holding the values to use for the variable. The value is
6172 # pretty printed in the output file.
6173 sub define_pretty_variable
6175 my ($var, $cond, @value) = @_;
6177 # Beware that an empty $cond has a different semantics for
6178 # macro_define and variable_pretty_output.
6181 if (! &variable_defined ($var, $cond))
6183 macro_define ($var, 1, '', $cond, join (' ', @value), undef);
6184 variable_pretty_output ($var, $cond || 'TRUE');
6185 $content_seen{$var} = 1;
6190 # define_variable ($VAR, $VALUE)
6191 # ------------------------------
6192 # Define a new user variable VAR to VALUE, but only if not already defined.
6195 my ($var, $value) = @_;
6197 define_pretty_variable ($var, 'TRUE', $value);
6201 # Like define_variable, but define a variable to be the configure
6202 # substitution by the same name.
6203 sub define_configure_variable
6206 my $value = '@' . $var . '@';
6207 &define_variable ($var, $value);
6211 # define_compiler_variable ($LANG)
6212 # --------------------------------
6213 # Define a compiler variable. We also handle defining the `LT'
6214 # version of the command when using libtool.
6215 sub define_compiler_variable ($)
6219 my ($var, $value) = ($lang->compiler, $lang->compile);
6220 &define_variable ($var, $value);
6221 &define_variable ("LT$var", "\$(LIBTOOL) --mode=compile $value")
6226 # define_linker_variable ($LANG)
6227 # ------------------------------
6228 # Define linker variables.
6229 sub define_linker_variable ($)
6233 my ($var, $value) = ($lang->lder, $lang->ld);
6235 &define_variable ($lang->lder, $lang->ld);
6236 # CCLINK = $(CCLD) blah blah...
6237 &define_variable ($lang->linker,
6238 (($seen_libtool ? '$(LIBTOOL) --mode=link ' : '')
6242 ################################################################
6244 ## ---------------- ##
6245 ## Handling rules. ##
6246 ## ---------------- ##
6248 sub rule_define ($$$$)
6250 my ($target, $rule_is_am, $cond, $where) = @_;
6252 if (defined $targets{$target}
6254 ? ! defined $target_conditional{$target}
6255 : defined $target_conditional{$target}))
6257 &am_line_error ($target,
6258 "$target defined both conditionally and unconditionally");
6261 # Value here doesn't matter; for targets we only note existence.
6262 $targets{$target} = $where;
6265 if ($target_conditional{$target})
6267 &check_ambiguous_conditional ($target, $cond);
6269 $target_conditional{$target}{$cond} = $where;
6273 # Check the rule for being a suffix rule. If so, store in a hash.
6275 if ((my ($source_suffix, $object_suffix)) = ($target =~ $SUFFIX_RULE_PATTERN))
6277 $suffix_rules{$source_suffix} = $object_suffix;
6278 print "Sources ending in .$source_suffix become .$object_suffix\n"
6280 # Set SUFFIXES from suffix_rules.
6281 push @suffixes, ".$source_suffix", ".$object_suffix";
6286 # See if a target exists.
6290 return defined $targets{$target};
6294 ################################################################
6296 # Read Makefile.am and set up %contents. Simultaneously copy lines
6297 # from Makefile.am into $output_trailer or $output_vars as
6298 # appropriate. NOTE we put rules in the trailer section. We want
6299 # user rules to come after our generated stuff.
6304 my $am_file = new IO::File ("< $amfile");
6307 die "$me: couldn't open `$amfile': $!\n";
6309 print "$me: reading $amfile\n" if $verbose;
6315 while ($_ = $am_file->getline)
6317 if (/$IGNORE_PATTERN/o)
6319 # Merely delete comments beginning with two hashes.
6321 elsif (/$WHITE_PATTERN/o)
6323 # Stick a single white line before the incoming macro or rule.
6327 elsif (/$COMMENT_PATTERN/o)
6329 # Stick comments before the incoming macro or rule. Make
6330 # sure a blank line preceeds first block of comments.
6331 $spacing = "\n" unless $blank;
6333 $comment .= $spacing . $_;
6342 $output_vars .= $comment . "\n";
6346 # We save the conditional stack on entry, and then check to make
6347 # sure it is the same on exit. This lets us conditonally include
6349 my @saved_cond_stack = @cond_stack;
6350 my $cond = conditional_string (@cond_stack);
6354 my $last_var_name = '';
6355 my $last_var_type = '';
6356 my $last_var_value = '';
6357 # FIXME: shouldn't use $_ in this loop; it is too big.
6361 unless substr ($_, -1, 1) eq "\n";
6363 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
6364 # used by users. @MAINT@ is an anachronism now.
6365 $_ =~ s/\@MAINT\@//g
6366 unless $seen_maint_mode;
6368 my $new_saw_bk = /\\$/;
6370 if (/$IGNORE_PATTERN/o)
6372 # Merely delete comments beginning with two hashes.
6374 elsif (/$WHITE_PATTERN/o)
6376 # Stick a single white line before the incoming macro or rule.
6378 &am_line_error ($., "blank line following trailing backslash")
6381 elsif (/$COMMENT_PATTERN/o)
6383 # Stick comments before the incoming macro or rule.
6384 $comment .= $spacing . $_;
6386 &am_line_error ($., "comment following trailing backslash")
6393 $output_trailer .= &make_condition (@cond_stack);
6394 $output_trailer .= $_;
6398 $last_var_value .= ' '
6399 unless $last_var_value =~ /\s$/;
6400 $last_var_value .= $_;
6404 $var_comment{$last_var_name} .= "$spacing"
6405 if (!defined $var_comment{$last_var_name}
6406 || substr ($var_comment{$last_var_name}, -1) ne "\n");
6407 $var_comment{$last_var_name} .= "$comment";
6408 $comment = $spacing = '';
6409 macro_define ($last_var_name, 0,
6410 $last_var_type, $cond,
6411 $last_var_value, $.)
6412 if $cond ne 'FALSE';
6413 push (@var_list, $last_var_name);
6418 elsif (/$IF_PATTERN/o)
6420 $cond = cond_stack_if ($1, $2, "$amfile:$.");
6422 elsif (/$ELSE_PATTERN/o)
6424 $cond = cond_stack_else ($1, $2, "$amfile:$.");
6426 elsif (/$ENDIF_PATTERN/o)
6428 $cond = cond_stack_endif ($1, $2, "$amfile:$.");
6431 elsif (/$RULE_PATTERN/o)
6436 rule_define ($1, 0, $cond, $.);
6439 $output_trailer .= $comment . $spacing;
6440 $output_trailer .= &make_condition (@cond_stack);
6441 $output_trailer .= $_;
6442 $comment = $spacing = '';
6444 elsif (/$ASSIGNMENT_PATTERN/o)
6446 # Found a macro definition.
6448 $last_var_name = $1;
6449 $last_var_type = $2;
6450 $last_var_value = $3;
6451 if ($3 ne '' && substr ($3, -1) eq "\\")
6453 # We preserve the `\' because otherwise the long lines
6454 # that are generated will be truncated by broken
6456 $last_var_value = $3 . "\n";
6461 # FIXME: this doesn't always work correctly; it will
6462 # group all comments for a given variable, no matter
6464 # Accumulating variables must not be output.
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 = '';
6471 macro_define ($last_var_name, 0,
6472 $last_var_type, $cond,
6473 $last_var_value, $.)
6474 if $cond ne 'FALSE';
6475 push (@var_list, $last_var_name);
6478 elsif (/$INCLUDE_PATTERN/o)
6482 if ($path =~ s/^\$\(top_srcdir\)\///)
6484 push (@include_stack, "\$\(top_srcdir\)/$path");
6488 $path =~ s/\$\(srcdir\)\///;
6489 push (@include_stack, "\$\(srcdir\)/$path");
6490 $path = $relative_dir . "/" . $path;
6492 &read_am_file ($path);
6496 # This isn't an error; it is probably a continued rule.
6497 # In fact, this is what we assume.
6499 $output_trailer .= $comment . $spacing;
6500 $output_trailer .= &make_condition (@cond_stack);
6501 $output_trailer .= $_;
6502 $comment = $spacing = '';
6505 $saw_bk = $new_saw_bk;
6506 $_ = $am_file->getline;
6509 $output_trailer .= $comment;
6511 if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
6515 &am_error ("unterminated conditionals: @cond_stack");
6519 # FIXME: better error message here.
6520 &am_error ("conditionals not nested in include file");
6526 # define_standard_variables ()
6527 # ----------------------------
6528 # A helper for read_main_am_file which initializes configure variables
6529 # and variables from header-vars.am. This is a subr so we can call it
6531 sub define_standard_variables
6533 my $saved_output_vars = $output_vars;
6534 my ($comments, undef, $rules) =
6535 file_contents_internal (1, "$am_dir/header-vars.am");
6537 # This will output the definitions in $output_vars, which we don't
6539 foreach my $var (sort keys %configure_vars)
6541 &define_configure_variable ($var);
6542 push (@var_list, $var);
6545 # ... hence, we restore $output_vars.
6546 $output_vars = $saved_output_vars . $comments . $rules;
6549 # Read main am file.
6550 sub read_main_am_file
6554 # This supports the strange variable tricks we are about to play.
6555 if (scalar keys %var_value > 0)
6558 &prog_error ("variable defined before read_main_am_file");
6561 # Generate copyright header for generated Makefile.in.
6562 # We do discard the output of predefined variables, handled below.
6563 $output_vars = ("# $in_file_name generated automatically by automake "
6564 . $VERSION . " from $am_file_name.\n");
6565 $output_vars .= $gen_copyright;
6567 # We want to predefine as many variables as possible. This lets
6568 # the user set them with `+=' in Makefile.am. However, we don't
6569 # want these initial definitions to end up in the output quite
6570 # yet. So we just load them, but output them later.
6571 &define_standard_variables;
6573 # Read user file, which might override some of our values.
6574 &read_am_file ($amfile);
6576 # Ouput all the Automake variables. If the user changed one, then
6577 # it is now marked as owned by the user.
6578 foreach my $var (uniq @var_list)
6580 # Don't process user variables.
6581 variable_output ($var)
6582 unless !$var_is_am{$var};
6585 # Now dump the user variables that were defined. We do it in the same
6586 # order in which they were defined (skipping duplicates).
6587 foreach my $var (uniq @var_list)
6589 # Don't process Automake variables.
6590 variable_output ($var)
6591 unless $var_is_am{$var};
6595 ################################################################
6598 # &flatten ($STRING)
6599 # ------------------
6600 # Flatten the $STRING and return the result.
6615 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
6616 # ------------------------------------------
6617 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6619 sub make_paragraphs ($%)
6621 my ($file, %transform) = @_;
6623 # Complete %transform with global options and make it a Perl
6626 "s/$IGNORE_PATTERN//gm;"
6627 . transform (%transform,
6629 'CYGNUS' => $cygnus_mode,
6631 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
6633 'SHAR' => $options{'dist-shar'} || 0,
6634 'BZIP2' => $options{'dist-bzip2'} || 0,
6635 'ZIP' => $options{'dist-zip'} || 0,
6636 'COMPRESS' => $options{'dist-tarZ'} || 0,
6638 'INSTALL-INFO' => !$options{'no-installinfo'},
6639 'INSTALL-MAN' => !$options{'no-installman'},
6640 'CK-NEWS' => $options{'check-news'} || 0,
6642 'SUBDIRS' => &variable_defined ('SUBDIRS'),
6643 'TOPDIR' => backname ($relative_dir),
6644 'TOPDIR_P' => $relative_dir eq '.',
6645 'CONFIGURE-AC' => $configure_ac,
6647 'BUILD' => $seen_canonical == $AC_CANONICAL_SYSTEM,
6648 'HOST' => $seen_canonical,
6649 'TARGET' => $seen_canonical == $AC_CANONICAL_SYSTEM,
6651 'LIBTOOL' => defined $configure_vars{'LIBTOOL'})
6652 # We don't need more than two consecutive new-lines.
6653 . 's/\n{3,}/\n\n/g';
6655 # Swallow the file and apply the COMMAND.
6656 my $fc_file = new IO::File ("< $file");
6659 die "$me: installation error: cannot open `$file'\n";
6662 print "$me: reading $file\n"
6664 my $saved_dollar_slash = $/;
6666 $_ = $fc_file->getline;
6667 $/ = $saved_dollar_slash;
6672 # Split at unescaped new lines.
6673 my @lines = split (/(?<!\\)\n/, $content);
6676 while (defined ($_ = shift @lines))
6678 my $paragraph = "$_";
6679 # If we are a rule, eat as long as we start with a tab.
6680 if (/$RULE_PATTERN/smo)
6682 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
6684 $paragraph .= "\n$_";
6686 unshift (@lines, $_);
6689 # If we are a comments, eat as much comments as you can.
6690 elsif (/$COMMENT_PATTERN/smo)
6692 while (defined ($_ = shift @lines)
6693 && $_ =~ /$COMMENT_PATTERN/smo)
6695 $paragraph .= "\n$_";
6697 unshift (@lines, $_);
6700 push @res, $paragraph;
6709 # ($COMMENT, $VARIABLES, $RULES)
6710 # &file_contents_internal ($IS_AM, $FILE, [%TRANSFORM])
6711 # -----------------------------------------------------
6712 # Return contents of a file from $am_dir, automatically skipping
6713 # macros or rules which are already known. $IS_AM iff the caller is
6714 # reading an Automake file (as opposed to the user's Makefile.am).
6715 sub file_contents_internal ($$%)
6717 my ($is_am, $file, %transform) = @_;
6719 my $result_vars = '';
6720 my $result_rules = '';
6724 # We save the conditional stack on entry, and then check to make
6725 # sure it is the same on exit. This lets us conditonally include
6727 my @saved_cond_stack = @cond_stack;
6728 my $cond = conditional_string (@cond_stack);
6730 foreach (make_paragraphs ($file, %transform))
6733 &am_file_error ($file, "blank line following trailing backslash:\n$_")
6735 &am_file_error ($file, "comment following trailing backslash:\n$_")
6740 # Stick empty line before the incoming macro or rule.
6743 elsif (/$COMMENT_PATTERN/mso)
6745 # Stick comments before the incoming macro or rule.
6749 # Handle inclusion of other files.
6750 elsif (/$INCLUDE_PATTERN/o)
6752 if ($cond ne 'FALSE')
6754 my $file = ($is_am ? "$am_dir/" : '') . $1;
6756 my ($com, $vars, $rules)
6757 = file_contents_internal ($is_am, $file, %transform);
6759 $result_vars .= $vars;
6760 $result_rules .= $rules;
6764 # Handling the conditionals.
6765 elsif (/$IF_PATTERN/o)
6767 $cond = cond_stack_if ($1, $2, $file);
6769 elsif (/$ELSE_PATTERN/o)
6771 $cond = cond_stack_else ($1, $2, $file);
6773 elsif (/$ENDIF_PATTERN/o)
6775 $cond = cond_stack_endif ($1, $2, $file);
6779 elsif (/$RULE_PATTERN/mso)
6781 # Separate relationship from optional actions: the first
6782 # `new-line tab" not preceded by backslash (continuation
6784 # I'm quite shoked! It seems that (\\\n|[^\n]) is not the
6785 # same as `([^\n]|\\\n)!!! Don't swap it, it breaks.
6787 /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
6788 my ($relationship, $actions) = ($1, $2 || '');
6790 # Separate targets from dependencies: the first colon.
6791 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
6792 my ($targets, $dependencies) = ($1, $2);
6793 # Remove the escaped new lines.
6794 # I don't know why, but I have to use a tmp $flat_deps.
6795 my $flat_deps = &flatten ($dependencies);
6796 my @deps = split (' ', $flat_deps);
6798 foreach (split (' ' , $targets))
6800 # FIXME: We are not robust to people defining several targets
6801 # at once, only some of them being in %dependencies.
6803 # Output only if not in FALSE.
6804 if (defined $dependencies{$_}
6805 && $cond ne 'FALSE')
6807 &depend ($_, @deps);
6808 $actions{$_} .= $actions;
6812 # Free lance dependency. Output the rule for all the
6813 # targets instead of one by one.
6814 if (!defined $targets{$targets}
6815 && $cond ne 'FALSE')
6817 $paragraph =~ s/^/make_condition (@cond_stack)/gme;
6818 $result_rules .= "$spacing$comment$paragraph\n";
6819 rule_define ($targets, $is_am, $cond, $file);
6821 $comment = $spacing = '';
6827 elsif (/$ASSIGNMENT_PATTERN/mso)
6829 my ($var, $type, $val) = ($1, $2, $3);
6830 &am_file_error ($file, "macro `$var' with trailing backslash")
6833 # Accumulating variables must not be output.
6834 $var_comment{$var} .= "$spacing"
6835 if (!defined $var_comment{$var}
6836 || substr ($var_comment{$var}, -1) ne "\n");
6837 $var_comment{$var} .= "$comment";
6838 macro_define ($var, $is_am, $type, $cond, $val, $file)
6839 if $cond ne 'FALSE';
6840 push (@var_list, $var);
6842 # If the user has set some variables we were in charge
6843 # of (which is detected by the first reading of
6844 # `header-vars.am'), we must not output them.
6845 $result_vars .= "$spacing$comment$_\n"
6846 if $type ne '+' && $var_is_am{$var} && $cond ne 'FALSE';
6848 $comment = $spacing = '';
6852 # This isn't an error; it is probably some tokens which
6853 # configure is supposed to replace, such as `@SET-MAKE@',
6854 # or some part of a rule cut by an if/endif.
6855 if ($cond ne 'FALSE')
6857 s/^/make_condition (@cond_stack)/gme;
6858 $result_rules .= "$spacing$comment$_\n";
6860 $comment = $spacing = '';
6864 if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
6868 &am_error ("unterminated conditionals: @cond_stack");
6872 # FIXME: better error message here.
6873 &am_error ("conditionals not nested in include file");
6877 return ($comment, $result_vars, $result_rules);
6882 # &file_contents ($BASENAME, [%TRANSFORM])
6883 # ----------------------------------------
6884 # Return contents of a file from $am_dir, automatically skipping
6885 # macros or rules which are already known.
6886 sub file_contents ($%)
6888 my ($basename, %transform) = @_;
6889 my ($comments, $variables, $rules) =
6890 file_contents_internal (1, "$am_dir/$basename.am", %transform);
6891 return "$comments$variables$rules";
6896 # &transform (%PAIRS)
6897 # -------------------
6898 # Foreach ($TOKEN, $VAL) in %PAIRS produce a replacement expression suitable
6899 # for file_contents which:
6900 # - replaces @$TOKEN@ with $VALUE,
6901 # - enables/disables ?$TOKEN?.
6907 while (my ($token, $val) = each %pairs)
6909 $result .= "s/\Q%$token%\E/\Q$val\E/gm;";
6912 $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
6913 $result .= "s/\Q%?$token%\E/TRUE/gm;";
6917 $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
6918 $result .= "s/\Q%?$token%\E/FALSE/gm;";
6926 # Find all variable prefixes that are used for install directories. A
6927 # prefix `zar' qualifies iff:
6928 # * `zardir' is a variable.
6929 # * `zar_PRIMARY' is a variable.
6930 sub am_primary_prefixes
6932 my ($primary, $can_dist, @prefixes) = @_;
6935 grep ($valid{$_} = 0, @prefixes);
6936 $valid{'EXTRA'} = 0;
6937 foreach my $varname (keys %var_value)
6939 # Automake is allowed to define variables that look like they
6940 # are magic variables, such as INSTALL_DATA.
6942 if $var_is_am{$varname};
6944 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
6946 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
6947 if ($dist ne '' && ! $can_dist)
6949 # Note that a configure variable is always legitimate.
6950 # It is natural to name such variables after the
6951 # primary, so we explicitly allow it.
6952 if (! defined $configure_vars{$varname})
6954 &am_line_error ($varname,
6955 "invalid variable `$varname': `dist' is forbidden");
6958 elsif (! defined $valid{$X} && ! &variable_defined ("${X}dir"))
6960 # Note that a configure variable is always legitimate.
6961 # It is natural to name such variables after the
6962 # primary, so we explicitly allow it.
6963 if (! defined $configure_vars{$varname})
6965 &am_line_error ($varname,
6966 "invalid variable `$varname'");
6971 # Ensure all extended prefixes are actually used.
6972 $valid{"$base$dist$X"} = 1;
6980 # Handle `where_HOW' variable magic. Does all lookups, generates
6981 # install code, and possibly generates code to define the primary
6982 # variable. The first argument is the name of the .am file to munge,
6983 # the second argument is the primary variable (eg HEADERS), and all
6984 # subsequent arguments are possible installation locations. Returns
6985 # list of all values of all _HOW targets.
6987 # FIXME: this should be rewritten to be cleaner. It should be broken
6988 # up into multiple functions.
6990 # Usage is: am_install_var (OPTION..., file, HOW, where...)
6997 my $default_dist = 0;
7000 if ($args[0] eq '-noextra')
7004 elsif ($args[0] eq '-candist')
7008 elsif ($args[0] eq '-defaultdist')
7013 elsif ($args[0] !~ /^-/)
7020 my ($file, $primary, @prefixes) = @args;
7022 # Now that configure substitutions are allowed in where_HOW
7023 # variables, it is an error to actually define the primary. We
7024 # allow `JAVA', as it is customarily used to mean the Java
7025 # interpreter. This is but one of several Java hacks. Similarly,
7026 # `PYTHON' is customarily used to mean the Python interpreter.
7027 &am_line_error ($primary, "`$primary' is an anachronism")
7028 if &variable_defined ($primary)
7029 && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7032 # Look for misspellings. It is an error to have a variable ending
7033 # in a "reserved" suffix whose prefix is unknown, eg
7034 # "bni_PROGRAMS". However, unusual prefixes are allowed if a
7035 # variable of the same name (with "dir" appended) exists. For
7036 # instance, if the variable "zardir" is defined, then
7037 # "zar_PROGRAMS" becomes valid. This is to provide a little extra
7038 # flexibility in those cases which need it.
7039 my %valid = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7041 # If a primary includes a configure substitution, then the EXTRA_
7042 # form is required. Otherwise we can't properly do our job.
7044 my $warned_about_extra = 0;
7049 # True if the iteration is the first one. Used for instance to
7050 # output parts of the associated file only once.
7052 foreach my $X (sort keys %valid)
7054 my $one_name = $X . '_' . $primary;
7056 unless (&variable_defined ($one_name));
7058 my $strip_subdir = 1;
7059 # If subdir prefix should be preserved, do so.
7060 if ($X =~ /^nobase_/)
7066 my $nodir_name = $X;
7067 # If files should be distributed, do so.
7071 $dist_p = (($default_dist && $one_name !~ /^nodist_/)
7072 || (! $default_dist && $one_name =~ /^dist_/));
7073 $nodir_name =~ s/^(dist|nodist)_//;
7076 # Append actual contents of where_PRIMARY variable to
7078 foreach my $rcurs (&variable_value_as_list ($one_name, 'all'))
7080 # Skip configure substitutions. Possibly bogus.
7081 if ($rcurs =~ /^\@.*\@$/)
7085 if (! $warned_about_extra)
7087 $warned_about_extra = 1;
7088 &am_line_error ($one_name,
7089 "`$one_name' contains configure substitution, but shouldn't");
7092 # Check here to make sure variables defined in
7093 # configure.ac do not imply that EXTRA_PRIMARY
7095 elsif (! defined $configure_vars{$one_name})
7097 $require_extra = $one_name
7104 push (@result, $rcurs);
7107 # A blatant hack: we rewrite each _PROGRAMS primary to
7108 # include EXEEXT when in Cygwin32 mode.
7109 if ($primary eq 'PROGRAMS')
7111 my @conds = &variable_conditions ($one_name);
7114 foreach my $cond (@conds)
7116 my @one_binlist = ();
7117 my @condval = &variable_value_as_list ($one_name,
7119 foreach my $rcurs (@condval)
7121 if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7123 push (@one_binlist, $rcurs);
7127 push (@one_binlist, $rcurs . '$(EXEEXT)');
7131 push (@condvals, $cond);
7132 push (@condvals, join (' ', @one_binlist));
7135 variable_delete ($one_name);
7138 my $cond = shift (@condvals);
7139 my @val = split (' ', shift (@condvals));
7140 &define_pretty_variable ($one_name, $cond, @val);
7144 # "EXTRA" shouldn't be used when generating clean targets,
7145 # all, or install targets.
7148 # We used to warn if EXTRA_FOO was defined uselessly,
7149 # but this was annoying.
7155 push (@check, '$(' . $one_name . ')');
7159 push (@used, '$(' . $one_name . ')');
7162 # Is this to be installed?
7163 my $install_p = $X ne 'noinst' && $X ne 'check';
7165 # If so, with install-exec? (or install-data?).
7166 my $exec_p = (defined $exec_dir_p {$X}
7170 # Singular form of $PRIMARY.
7171 (my $one_primary = $primary) =~ s/S$//;
7172 $output_rules .= &file_contents ($file,
7175 'PRIMARY' => $primary,
7176 'ONE_PRIMARY' => $one_primary,
7178 'NDIR' => $nodir_name,
7179 'BASE' => $strip_subdir,
7182 'INSTALL' => $install_p,
7183 'DIST' => $dist_p));
7188 # The JAVA variable is used as the name of the Java interpreter.
7189 # The PYTHON variable is used as the name of the Python interpreter.
7190 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7193 &define_pretty_variable ($primary, '', @used);
7194 $output_vars .= "\n";
7197 if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7199 &am_line_error ($require_extra,
7200 "`$require_extra' contains configure substitution, but `EXTRA_$primary' not defined");
7203 # Push here because PRIMARY might be configure time determined.
7204 push (@all, '$(' . $primary . ')')
7205 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7207 # Make the result unique. This lets the user use conditionals in
7208 # a natural way, but still lets us program lazily -- we don't have
7209 # to worry about handling a particular object more than once.
7210 return uniq (sort @result);
7214 ################################################################
7216 # Each key in this hash is the name of a directory holding a
7217 # Makefile.in. These variables are local to `is_make_dir'.
7219 my $make_dirs_set = 0;
7224 if (! $make_dirs_set)
7226 foreach my $iter (@configure_input_files)
7228 $make_dirs{dirname ($iter)} = 1;
7230 # We also want to notice Makefile.in's.
7231 foreach my $iter (@other_input_files)
7233 if ($iter =~ /Makefile\.in$/)
7235 $make_dirs{dirname ($iter)} = 1;
7240 return defined $make_dirs{$dir};
7243 ################################################################
7245 # This variable is local to the "require file" set of functions.
7246 my @require_file_paths = ();
7248 # If a file name appears as a key in this hash, then it has already
7249 # been checked for. This variable is local to the "require file"
7251 %require_file_found = ();
7253 # See if we want to push this file onto dist_common. This function
7254 # encodes the rules for deciding when to do so.
7255 sub maybe_push_required_file
7257 my ($dir, $file, $fullfile) = @_;
7259 if ($dir eq $relative_dir)
7261 &push_dist_common ($file);
7263 elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7265 # If we are doing the topmost directory, and the file is in a
7266 # subdir which does not have a Makefile, then we distribute it
7268 &push_dist_common ($fullfile);
7273 # &require_file_internal ($IS_CONFIGURE, $LINE, $MYSTRICT, @FILES)
7274 # ----------------------------------------------------------------
7275 # Verify that the file must exist in the current directory.
7276 # $MYSTRICT is the strictness level at which this file becomes required.
7278 # Must set require_file_paths before calling this function.
7279 # require_file_paths is set to hold a single directory (the one in
7280 # which the first file was found) before return.
7281 sub require_file_internal
7283 my ($is_configure, $line, $mystrict, @files) = @_;
7285 foreach my $file (@files)
7292 # If we've already looked for it, we're done.
7293 next if defined $require_file_found{$file};
7294 $require_file_found{$file} = 1;
7297 my $dangling_sym = 0;
7298 foreach my $dir (@require_file_paths)
7300 $fullfile = $dir . "/" . $file;
7301 $errdir = $dir unless $errdir;
7303 # Use different name for "error filename". Otherwise on
7304 # an error the bad file will be reported as eg
7305 # `../../install-sh' when using the default
7307 $errfile = $errdir . '/' . $file;
7309 if (-l $fullfile && ! -f readlink ($fullfile))
7314 elsif (-f $fullfile)
7317 &maybe_push_required_file ($dir, $file, $fullfile);
7323 if ($found_it && ! $force_missing)
7325 # Prune the path list.
7326 @require_file_paths = $save_dir;
7330 if ($strictness >= $mystrict)
7332 if ($dangling_sym && $add_missing)
7340 # Only install missing files according to our desired
7342 my $message = "required file `$errfile' not found";
7347 # Maybe run libtoolize.
7348 my @syslist = ('libtoolize', '--automake');
7349 push @syslist, '--copy'
7352 && grep ($_ eq $file, @libtoolize_files)
7353 && system (@syslist))
7355 $message = "installing `$errfile'";
7357 $trailer = "; cannot run `libtoolize': $!";
7359 elsif (-f ("$pkgdata_dir/$file"))
7361 # Install the missing file. Symlink if we
7362 # can, copy if we must. Note: delete the file
7363 # first, in case it is a dangling symlink.
7364 $message = "installing `$errfile'";
7365 # Windows Perl will hang if we try to delete a
7366 # file that doesn't exist.
7367 unlink ($errfile) if -f $errfile;
7368 if ($symlink_exists && ! $copy_missing)
7370 if (! symlink ("$pkgdata_dir/$file", $errfile))
7373 $trailer = "; error while making link: $!";
7376 elsif (system ('cp', "$pkgdata_dir/$file", $errfile))
7379 $trailer = "\n error while copying";
7383 &maybe_push_required_file (dirname ($errfile),
7386 # Prune the path list.
7387 @require_file_paths = &dirname ($errfile);
7394 # FIXME: allow actual file to be specified.
7395 &am_conf_line_warning ($configure_ac, $line,
7396 "$message$trailer");
7400 &am_line_warning ($line, "$message$trailer");
7407 # FIXME: allow actual file to be specified.
7408 &am_conf_line_error ($configure_ac, $line,
7409 "$message$trailer");
7413 &am_line_error ($line, "$message$trailer");
7421 # Like require_file_with_line, but error messages refer to
7422 # configure.ac, not the current Makefile.am.
7423 sub require_file_with_conf_line
7425 @require_file_paths = $relative_dir;
7426 &require_file_internal (1, @_);
7429 sub require_file_with_line
7431 @require_file_paths = $relative_dir;
7432 &require_file_internal (0, @_);
7437 @require_file_paths = $relative_dir;
7438 &require_file_internal (0, '', @_);
7441 # Require a file that is also required by Autoconf. Looks in
7442 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7443 sub require_config_file
7445 @require_file_paths = @config_aux_path;
7446 &require_file_internal (1, '', @_);
7447 my $dir = $require_file_paths[0];
7448 @config_aux_path = @require_file_paths;
7449 # Avoid unsightly '/.'s.
7450 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7453 # Assumes that the line number is in Makefile.am.
7454 sub require_conf_file_with_line
7456 @require_file_paths = @config_aux_path;
7457 &require_file_internal (0, @_);
7458 my $dir = $require_file_paths[0];
7459 @config_aux_path = @require_file_paths;
7460 # Avoid unsightly '/.'s.
7461 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7464 # Assumes that the line number is in configure.ac.
7465 sub require_conf_file_with_conf_line
7467 @require_file_paths = @config_aux_path;
7468 &require_file_internal (1, @_);
7469 my $dir = $require_file_paths[0];
7470 @config_aux_path = @require_file_paths;
7471 # avoid unsightly '/.'s.
7472 $config_aux_dir = '$(top_srcdir)' . ($dir eq '.' ? "" : "/$dir");
7475 ################################################################
7477 # Push a list of files onto dist_common.
7478 sub push_dist_common
7480 &prog_error ("push_dist_common run after handle_dist")
7481 if $handle_dist_run;
7482 macro_define ('DIST_COMMON', 1, '+', '', join (' ', @_), '');
7489 $strictness_name = $_[0];
7490 if ($strictness_name eq 'gnu')
7494 elsif ($strictness_name eq 'gnits')
7496 $strictness = $GNITS;
7498 elsif ($strictness_name eq 'foreign')
7500 $strictness = $FOREIGN;
7504 die "$me: level `$strictness_name' not recognized\n";
7509 ################################################################
7511 # Ensure a file exists.
7516 my $touch = new IO::File (">> $file");
7520 # Glob something. Do this to avoid indentation screwups everywhere we
7521 # want to glob. Gross!
7528 # Remove one level of brackets and strip leading spaces,
7529 # as does m4 to function arguments.
7535 my @letters = split //;
7544 next if $depth == 1;
7549 next if $depth == 0;
7550 # don't count orphan right brackets
7551 $depth = 0 if $depth < 0;
7555 return join '', @result;
7558 ################################################################
7560 # Print an error message and set exit status.
7563 warn "$me: ${am_file}.am: @_\n";
7567 # am_file_error ($FILE, @ARGS)
7568 # ----------------------------
7571 my ($file, @args) = @_;
7573 warn "$file: @args\n";
7579 my ($symbol, @args) = @_;
7581 if ($symbol && "$symbol" ne '-1')
7583 my $file = "${am_file}.am";
7585 if ($symbol =~ /^\d+$/)
7587 # SYMBOL is a line number, so just add the colon.
7588 $file .= ':' . $symbol;
7590 elsif (defined $var_line{$symbol})
7592 # SYMBOL is a variable defined in Makefile.am, so add the
7593 # line number we saved from there.
7594 $file .= ':' . $var_line{$symbol};
7596 elsif (defined $configure_vars{$symbol})
7598 # SYMBOL is a variable defined in configure.ac, so add the
7599 # appropriate line number.
7600 $file = $configure_vars{$symbol};
7604 # Couldn't find the line number.
7606 warn $file, ": @args\n";
7615 # Like am_error, but while scanning configure.ac.
7618 # FIXME: can run in subdirs.
7619 warn "$me: $configure_ac: @_\n";
7623 # Error message with line number referring to configure.ac.
7624 sub am_conf_line_error
7626 my ($file, $line, @args) = @_;
7630 warn "$file: $line: @args\n";
7635 &am_conf_error (@args);
7639 # Warning message with line number referring to configure.ac.
7640 # Does not affect exit_status
7641 sub am_conf_line_warning
7643 my $saved_exit_status = $exit_status;
7644 my $sig = $SIG{'__WARN__'};
7645 $SIG{'__WARN__'} = 'DEFAULT';
7646 am_conf_line_error (@_);
7647 $exit_status = $saved_exit_status;
7648 $SIG{'__WARN__'} = $sig;
7651 # Like am_line_error, but doesn't affect exit status.
7654 my $saved_exit_status = $exit_status;
7655 my $sig = $SIG{'__WARN__'};
7656 $SIG{'__WARN__'} = 'DEFAULT';
7658 $exit_status = $saved_exit_status;
7659 $SIG{'__WARN__'} = $sig;
7662 # Tell user where our aclocal.m4 is, but only once.
7663 sub keyed_aclocal_warning
7666 warn "$me: macro `$key' can be generated by `aclocal'\n";
7669 # Print usage information.
7673 Usage: $0 [OPTION] ... [Makefile]...
7675 Generate Makefile.in for configure from Makefile.am.
7678 --help print this help, then exit
7679 --version print version number, then exit
7680 -v, --verbose verbosely list files processed
7681 -o, --output-dir=DIR put generated Makefile.in's into DIR
7682 --no-force only update Makefile.in's that are out of date
7684 Dependency tracking:
7685 -i, --ignore-deps disable dependency tracking code
7686 --include-deps enable dependency tracking code
7689 --cygnus assume program is part of Cygnus-style tree
7690 --foreign set strictness to foreign
7691 --gnits set strictness to gnits
7692 --gnu set strictness to gnu
7695 -a, --add-missing add missing standard files to package
7696 --amdir=DIR directory storing config files
7697 -c, --copy with -a, copy missing files (default is symlink)
7698 -f, --force-missing force update of standard files
7703 foreach my $iter (sort ((@common_files, @common_sometimes)))
7705 push (@lcomm, $iter) unless $iter eq $last;
7709 my ($one, $two, $three, $four, $max);
7710 print "\nFiles which are automatically distributed, if found:\n";
7711 format USAGE_FORMAT =
7712 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
7713 $one, $two, $three, $four
7715 $~ = "USAGE_FORMAT";
7716 $max = int (($#lcomm + 1) / 4);
7718 for (my $i = 0; $i < $max; ++$i)
7721 $two = $lcomm[$max + $i];
7722 $three = $lcomm[2 * $max + $i];
7723 $four = $lcomm[3 * $max + $i];
7727 my $mod = ($#lcomm + 1) % 4;
7730 $one = $lcomm[$max];
7731 $two = ($mod > 1) ? $lcomm[2 * $max] : '';
7732 $three = ($mod > 2) ? $lcomm[3 * $max] : '';
7733 $four = ($mod > 3) ? $lcomm[4 * $max] : '';
7737 print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7744 # Print version information
7748 automake (GNU $PACKAGE) $VERSION
7749 Written by Tom Tromey <tromey\@cygnus.com>.
7751 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
7752 Free Software Foundation, Inc.
7753 This is free software; see the source for copying conditions. There is NO
7754 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.