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...).
46 # Name of the compiling variable (COMPILE).
48 # Content of the compiling variable.
50 # Flag to require compilation without linking (-c).
51 'compile_flag' => '$',
52 'derived_autodep' => '$',
56 # Name of the linking variable (LINK).
58 # Content of the linking variable.
61 # Name of the linker variable (LD).
63 # Content of the linker variable ($(CC)).
66 # Flag to specify the output file (-o).
68 # `pure' is `1' or `'. A `pure' language is one where, if
69 # all the files in a directory are of that language, then we
70 # do not require the C compiler or any code to call it.
85 use strict 'vars', 'subs';
89 my $me = basename ($0);
96 # Parameters set by configure. Not to be changed. NOTE: assign
97 # VERSION as string so that eg version 0.30 will print correctly.
98 my $VERSION = "@VERSION@";
99 my $PACKAGE = "@PACKAGE@";
100 my $prefix = "@prefix@";
101 my $am_dir = "@datadir@/@PACKAGE@/am";
102 my $pkgdata_dir = "@datadir@/@PACKAGE@";
105 my $IGNORE_PATTERN = '^##([^#].*)?$';
106 my $WHITE_PATTERN = '^\s*$';
107 my $COMMENT_PATTERN = '^#';
108 my $TARGET_PATTERN='[$a-zA-Z_.][-.a-zA-Z0-9_(){}/$]*';
109 my $RULE_PATTERN = "^($TARGET_PATTERN) *:([^=].*|)\$";
110 my $SUFFIX_RULE_PATTERN = '^\.([a-zA-Z0-9]+)\.([a-zA-Z0-9]+)$';
111 # Only recognize leading spaces, not leading tabs. If we recognize
112 # leading tabs here then we need to make the reader smarter, because
113 # otherwise it will think rules like `foo=bar; \' are errors.
114 my $MACRO_PATTERN = '^ *([A-Za-z0-9_@]+)\s*([:+]?)=\s*(.*)$';
115 my $BOGUS_MACRO_PATTERN = '^ *([^ \t]*)\s*([:+]?)=\s*(.*)$';
116 # This pattern recognizes a Gnits version id and sets $1 if the
117 # release is an alpha release. We also allow a suffix which can be
118 # used to extend the version number with a "fork" identifier.
119 my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
120 my $IF_PATTERN = '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?$';
121 my $ELSE_PATTERN = '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
122 my $ENDIF_PATTERN = '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
123 my $PATH_PATTERN='(\w|[/.-])+';
124 # This will pass through anything not of the prescribed form.
125 my $INCLUDE_PATTERN = ('^include\s+'
126 . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
127 . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
128 . '|([^/\$]' . $PATH_PATTERN. '))\s*(#.*)?$');
130 # Some regular expressions. One reason to put them here is that it
131 # makes indentation work better in Emacs.
132 my $AC_CONFIG_AUX_DIR_PATTERN = 'AC_CONFIG_AUX_DIR\(([^)]+)\)';
133 my $AM_INIT_AUTOMAKE_PATTERN = 'AM_INIT_AUTOMAKE\([^,]*,([^,)]+)[,)]';
134 my $AM_PACKAGE_VERSION_PATTERN = '^\s*\[?([^]\s]+)\]?\s*$';
135 # Note that there is no AC_PATH_TOOL. But we don't really care.
136 my $AC_CHECK_PATTERN = 'AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\(\[?(\w+)';
137 my $AM_MISSING_PATTERN = 'AM_MISSING_PROG\(\[?(\w+)';
138 # Just check for alphanumeric in AC_SUBST. If you do AC_SUBST(5),
140 my $AC_SUBST_PATTERN = 'AC_SUBST\(\[?(\w+)';
141 my $AM_CONDITIONAL_PATTERN = 'AM_CONDITIONAL\(\[?(\w+)';
143 # Constants to define the "strictness" level.
148 # Values for AC_CANONICAL_*
149 my $AC_CANONICAL_HOST = 1;
150 my $AC_CANONICAL_SYSTEM = 2;
152 # Files installed by libtoolize.
153 my @libtoolize_files = ('ltmain.sh', 'config.guess', 'config.sub');
154 # ltconfig appears here for compatibility with old versions of libtool.
155 my @libtoolize_sometimes = ('ltconfig', 'ltcf-c.sh', 'ltcf-cxx.sh',
158 # Commonly found files we look for and automatically include in
162 'README', 'THANKS', 'TODO', 'NEWS', 'COPYING', 'COPYING.LIB',
163 'INSTALL', 'ABOUT-NLS', 'ChangeLog', 'configure.ac',
164 'configure.in', 'configure', 'config.guess', 'config.sub',
165 'AUTHORS', 'BACKLOG', 'ABOUT-GNU', 'libversion.in',
166 'mdate-sh', 'mkinstalldirs', 'install-sh', 'texinfo.tex',
167 'ansi2knr.c', 'ansi2knr.1', 'elisp-comp',
168 # ltconfig appears here for compatibility with old versions
170 'ylwrap', 'acinclude.m4', @libtoolize_files, @libtoolize_sometimes,
171 'missing', 'depcomp', 'compile', 'py-compile'
174 # Commonly used files we auto-include, but only sometimes.
175 my @common_sometimes =
177 'aclocal.m4', 'acconfig.h', 'config.h.top',
178 'config.h.bot', 'stamp-h.in', 'stamp-vti'
181 # Copyright on generated Makefile.ins.
182 my $gen_copyright = "\
183 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
184 # Free Software Foundation, Inc.
185 # This Makefile.in is free software; the Free Software Foundation
186 # gives unlimited permission to copy and/or distribute it,
187 # with or without modifications, as long as this notice is preserved.
189 # This program is distributed in the hope that it will be useful,
190 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
191 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
192 # PARTICULAR PURPOSE.
195 # These constants are returned by lang_*_rewrite functions.
196 # LANG_SUBDIR means that the resulting object file should be in a
197 # subdir if the source file is. In this case the file name cannot
198 # have `..' components.
200 my $LANG_PROCESS = 1;
203 # Directories installed during 'install-exec' phase.
222 # Map from obsolete macros to hints for new macros.
223 # If you change this, change the corresponding list in aclocal.in.
224 # FIXME: should just put this into a single file.
225 my %obsolete_macros =
227 'AC_FEATURE_CTYPE' => "use `AC_HEADER_STDC'",
228 'AC_FEATURE_ERRNO' => "add `strerror' to `AC_REPLACE_FUNCS(...)'",
229 'AC_FEATURE_EXIT' => '',
230 'AC_SYSTEM_HEADER' => '',
232 # Note that we do not handle this one, because it is still run
233 # from AM_CONFIG_HEADER. So we deal with it specially in
234 # &scan_autoconf_files.
235 # 'AC_CONFIG_HEADER' => "use `AM_CONFIG_HEADER'",
237 'fp_C_PROTOTYPES' => "use `AM_C_PROTOTYPES'",
238 'fp_PROG_CC_STDC' => "use `AM_PROG_CC_STDC'",
239 'fp_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
240 'fp_WITH_DMALLOC' => "use `AM_WITH_DMALLOC'",
241 'fp_WITH_REGEX' => "use `AM_WITH_REGEX'",
242 'gm_PROG_LIBTOOL' => "use `AM_PROG_LIBTOOL'",
243 'jm_MAINTAINER_MODE' => "use `AM_MAINTAINER_MODE'",
244 'md_TYPE_PTRDIFF_T' => "use `AM_TYPE_PTRDIFF_T'",
245 'ud_PATH_LISPDIR' => "use `AM_PATH_LISPDIR'",
246 'ud_GNU_GETTEXT' => "use `AM_GNU_GETTEXT'",
248 # Now part of autoconf proper, under a different name.
249 'AM_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
250 'fp_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
251 'AM_SANITY_CHECK_CC' => "automatically done by `AC_PROG_CC'",
252 'AM_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
253 'AM_EXEEXT' => "use `AC_EXEEXT'",
254 'AM_CYGWIN32' => "use `AC_CYGWIN'",
255 'AM_MINGW32' => "use `AC_MINGW32'",
256 'AM_FUNC_MKTIME' => "use `AC_FUNC_MKTIME'",
258 # These aren't quite obsolete.
262 # Regexp to match the above macros.
263 my $obsolete_rx = '(\b' . join ('\b|\b', keys %obsolete_macros) . '\b)';
267 ## ---------------------------------- ##
268 ## Variables related to the options. ##
269 ## ---------------------------------- ##
271 # TRUE if we should always generate Makefile.in.
272 my $force_generation = 1;
274 # Strictness level as set on command line.
275 my $default_strictness = $GNU;
277 # Name of strictness level, as set on command line.
278 my $default_strictness_name = 'gnu';
280 # This is TRUE if automatic dependency generation code should be
281 # included in generated Makefile.in.
282 my $cmdline_use_dependencies = 1;
284 # TRUE if in verbose mode.
287 # This holds our (eventual) exit status. We don't actually exit until
288 # we have processed all input files.
291 # From the Perl manual.
292 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
294 # TRUE if missing standard files should be installed.
297 # TRUE if we should copy missing files; otherwise symlink if possible.
298 my $copy_missing = 0;
300 # TRUE if we should always update files that we know about.
301 my $force_missing = 0;
304 ## ---------------------------------------- ##
305 ## Variables filled during files scanning. ##
306 ## ---------------------------------------- ##
308 # Name of the top autoconf input: `configure.ac' or `configure.in'.
309 my $configure_ac = '';
311 # Files found by scanning configure.ac for LIBOBJS.
314 # True if AM_C_PROTOTYPES appears in configure.ac.
315 my $am_c_prototypes = 0;
317 # Names used in AC_CONFIG_HEADER call. @config_fullnames holds the
318 # name which appears in AC_CONFIG_HEADER, colon and all.
319 # @config_names holds the file names. @config_headers holds the '.in'
320 # files. Ordinarily these are similar, but they can be different if
321 # the weird "NAME:FILE" syntax is used.
322 my @config_fullnames = ();
323 my @config_names = ();
324 my @config_headers = ();
325 # Line number at which AC_CONFIG_HEADER appears in configure.ac.
326 my $config_header_line = 0;
328 # Directory where output files go. Actually, output files are
329 # relative to this directory.
330 my $output_directory = '.';
332 # List of Makefile.am's to process, and their corresponding outputs.
333 my @input_files = ();
334 my %output_files = ();
336 # Complete list of Makefile.am's that exist.
337 my @configure_input_files = ();
339 # List of files in AC_OUTPUT without Makefile.am, and their outputs.
340 my @other_input_files = ();
341 # Line number at which AC_OUTPUT seen.
342 my $ac_output_line = 0;
344 # List of directories to search for configure-required files. This
345 # can be set by AC_CONFIG_AUX_DIR.
346 my @config_aux_path = ('.', '..', '../..');
347 my $config_aux_dir = '';
349 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
350 my $seen_gettext = 0;
351 # Line number at which AM_GNU_GETTEXT seen.
352 my $ac_gettext_line = 0;
354 # Whether ALL_LINGUAS has been seen.
355 my $seen_linguas = '';
357 my $all_linguas = '';
358 # Line number at which it appears.
359 my $all_linguas_line = 0;
361 # TRUE if AC_DECL_YYTEXT was seen.
362 my $seen_decl_yytext = 0;
364 # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM). The presence of
365 # AC_CHECK_TOOL also sets this.
366 my $seen_canonical = 0;
368 # TRUE if we've seen AC_PROG_LIBTOOL.
369 my $seen_libtool = 0;
370 my $libtool_line = 0;
372 # TRUE if we've seen AM_MAINTAINER_MODE.
373 my $seen_maint_mode = 0;
375 # Actual version we've seen.
376 my $package_version = '';
378 # Line number where we saw version definition.
379 my $package_version_line = 0;
381 # TRUE if we've seen AM_PATH_LISPDIR.
382 my $seen_lispdir = 0;
384 # TRUE if we've seen AM_CHECK_PYTHON.
385 my $seen_pythondir = 0;
387 # TRUE if we've seen AC_EXEEXT.
390 # TRUE if we've seen AC_OBJEXT.
393 # TRUE if we've seen AC_ENABLE_MULTILIB.
394 my $seen_multilib = 0;
396 # TRUE if we've seen AM_PROG_CC_C_O
399 # TRUE if we've seen AM_INIT_AUTOMAKE.
400 my $seen_init_automake = 0;
402 # Hash table of discovered configure substitutions. Keys are names,
403 # values are `FILE:LINE' strings which are used by error message
405 my %configure_vars = ();
407 # This is used to keep track of which variable definitions we are
408 # scanning. It is only used in certain limited ways, but it has to be
409 # global. It is declared just for documentation purposes.
410 my %vars_scanned = ();
412 # Charsets used by maintainer and in distribution. MAINT_CHARSET is
413 # handled in a funny way: if seen in the top-level Makefile.am, it is
414 # used for every directory which does not specify a different value.
415 # The rationale here is that some directories (eg gettext) might be
416 # distributions of other packages, and thus require their own charset
417 # info. However, the DIST_CHARSET must be the same for the entire
418 # package; it can only be set at top-level.
419 # FIXME: this yields bugs when rebuilding. What to do? Always
420 # read (and sometimes discard) top-level Makefile.am?
421 my $maint_charset = '';
422 my $dist_charset = 'utf8'; # recode doesn't support this yet.
424 # TRUE if --cygnus seen.
427 # Hash table of AM_CONDITIONAL variables seen in configure.
428 my %configure_cond = ();
430 # This maps extensions onto language names.
431 my %extension_map = ();
433 # List of the DIST_COMMON files we discovered while reading
435 my $configure_dist_common = '';
437 # This maps languages names onto objects.
440 # List of targets we must always output.
441 # FIXME: Complete, and remove falsely required targets.
442 my %required_targets =
453 # FIXME: Not required, temporary hacks.
454 # Well, actually they are sort of required: the -recursive
455 # targets will run them anyway...
458 'install-data-am' => 1,
459 'install-exec-am' => 1,
460 'installcheck-am' => 1,
468 ################################################################
470 ## ------------------------------------------ ##
471 ## Variables reset by &initialize_per_input. ##
472 ## ------------------------------------------ ##
474 # Basename and relative dir of the input file.
478 # Same but wrt Makefile.in.
482 # These two variables are used when generating each Makefile.in.
483 # They hold the Makefile.in until it is ready to be printed.
490 # Suffixes found during a run.
493 # Handling the variables.
496 # - $var_value{$VAR}{$COND} is its value associated to $COND,
497 # - $var_line{$VAR} is where it has been defined,
498 # - $var_comment{$VAR} are the comments associated to it.
499 # - $var_type{$VAR} is how it has been defined (`', `+', or `:'),
500 # - $var_is_am{$VAR} is true if the variable is owned by Automake.
507 # This holds a 1 if a particular variable was examined.
510 # This holds the names which are targets. These also appear in
514 # Same as %VAR_VALUE, but for targets.
515 my %target_conditional;
517 # This is the conditional stack.
520 # This holds the set of included files.
523 # This holds a list of directories which we must create at `dist'
524 # time. This is used in some strange scenarios involving weird
525 # AC_OUTPUT commands.
528 # List of dependencies for the obvious targets.
533 # Holds the dependencies of targets which dependencies are factored.
534 # Typically, `.PHONY' will appear in plenty of *.am files, but must
535 # be output once. Arguably all pure dependencies could be subject
536 # to this factorization, but it is not unpleasant to have paragraphs
537 # in Makefile: keeping related stuff altogether.
540 # Holds the factored actions. Tied to %DEPENDENCIES, i.e., filled
541 # only when keys exists in %DEPENDENCIES.
544 # A list of files deleted by `maintainer-clean'.
545 my @maintainer_clean_files;
547 # These are pretty obvious, too. They are used to define the
548 # SOURCES and OBJECTS variables.
551 # Sources which go in the distribution.
554 # This hash maps object file names onto their corresponding source
555 # file names. This is used to ensure that each object is created
556 # by a single source file.
559 # This keeps track of the directories for which we've already
560 # created `.dirstamp' code.
570 # Options from AUTOMAKE_OPTIONS.
573 # Whether or not dependencies are handled. Can be further changed
575 my $use_dependencies;
578 my $local_maint_charset;
580 # All yacc and lex source filenames for this directory. Use
581 # filenames instead of raw count so that multiple instances are
582 # counted correctly (eg one yacc file can appear in multiple
583 # programs without harm).
587 # This is a list of all targets to run during "make dist".
590 # Keys in this hash are the basenames of files which must depend
594 # This maps the source extension of a suffix rule to its
595 # corresponding output extension.
598 # This is the name of the redirect `all' target to use.
601 # This keeps track of which extensions we've seen (that we care
605 # This is random scratch space for the language finish functions.
606 # Don't randomly overwrite it; examine other uses of keys first.
607 my %language_scratch;
609 # We keep track of which objects need special (per-executable)
610 # handling on a per-language basis.
611 my %lang_specific_files;
613 # This is set when `handle_dist' has finished. Once this happens,
614 # we should no longer push on dist_common.
617 # True if we need `LINK' defined. This is a hack.
620 # This is the list of such variables to output.
621 # FIXME: Might be useless actually.
624 # Was get_object_extension run?
625 # FIXME: This is a hack. a better switch should be found.
626 my $get_object_extension_was_run;
629 ## --------------------------------- ##
630 ## Forward subroutine declarations. ##
631 ## --------------------------------- ##
632 sub register_language ($%);
633 sub file_contents_internal ($%);
636 # &initialize_per_input ()
637 # ------------------------
638 # (Re)-Initialize per-Makefile.am variables.
639 sub initialize_per_input ()
642 $am_relative_dir = '';
649 $output_trailer = '';
665 %target_conditional = ();
673 $am_relative_dir = '';
689 # Installing/uninstalling.
690 'install-data-am' => [],
691 'install-exec-am' => [],
692 'uninstall-am' => [],
695 'uninstall-man' => [],
697 'install-info' => [],
698 'install-info-am' => [],
699 'uninstall-info' => [],
701 'installcheck-am' => [],
705 'mostlyclean-am' => [],
706 'maintainer-clean-am' => [],
707 'distclean-am' => [],
710 'maintainer-clean' => [],
721 @maintainer_clean_files = ();
733 $strictness = $default_strictness;
734 $strictness_name = $default_strictness_name;
738 $use_dependencies = $cmdline_use_dependencies;
740 $local_maint_charset = $maint_charset;
753 %extension_seen = ();
755 %language_scratch = ();
757 %lang_specific_files = ();
759 $handle_dist_run = 0;
765 $get_object_extension_was_run = 0;
769 ################################################################
771 # Initialize our list of languages that are internally supported.
774 register_language ('name' => 'c',
778 'compiler' => 'COMPILE',
779 'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
783 'link' => '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
784 'compile_flag' => '-c',
785 'extensions' => ['c'],
786 '_finish' => \&lang_c_finish);
789 register_language ('name' => 'cxx',
790 'linker' => 'CXXLINK',
791 'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
793 'flags' => 'CXXFLAGS',
794 'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
795 'compiler' => 'CXXCOMPILE',
796 'compile_flag' => '-c',
797 'output_flag' => '-o',
801 'extensions' => ['c++', 'cc', 'cpp', 'cxx', 'C'],
802 '_finish' => \&lang_cxx_finish);
805 register_language ('name' => 'objc',
806 'linker' => 'OBJCLINK',,
807 'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
809 'flags' => 'OBJCFLAGS',
810 'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
811 'compiler' => 'OBJCCOMPILE',
812 'compile_flag' => '-c',
813 'output_flag' => '-o',
817 'extensions' => ['m'],
818 '_finish' => \&lang_objc_finish);
821 register_language ('name' => 'header',
822 'extensions' => ['h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc'],
824 '_finish' => sub { });
826 # For now, yacc and lex can't be handled on a per-exe basis.
829 register_language ('name' => 'yacc',
831 'derived_autodep' => 'yes',
832 'extensions' => ['y'],
833 '_finish' => \&lang_yacc_finish);
834 register_language ('name' => 'yaccxx',
835 'linker' => 'CXXLINK',
836 'derived_autodep' => 'yes',
837 'extensions' => ['y++', 'yy', 'yxx', 'ypp'],
838 '_finish' => \&lang_yacc_finish);
841 register_language ('name' => 'lex',
843 'derived_autodep' => 'yes',
844 'extensions' => ['l'],
845 '_finish' => \&lang_lex_finish);
846 register_language ('name' => 'lexxx',
847 'linker' => 'CXXLINK',
848 'derived_autodep' => 'yes',
849 'extensions' => ['l++', 'll', 'lxx', 'lpp'],
850 '_finish' => \&lang_lex_finish);
853 register_language ('name' => 'asm',
856 'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
857 # FIXME: a different compiler?
858 'compiler' => 'COMPILE',
859 'compile_flag' => '-c',
860 'extensions' => ['s', 'S'],
861 # We need the C code for assembly.
862 '_finish' => \&lang_c_finish);
865 register_language ('name' => 'f77',
866 'linker' => 'F77LINK',
867 'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
869 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
870 'compiler' => 'F77COMPILE',
871 'compile_flag' => '-c',
872 'output_flag' => '-o',
876 'extensions' => ['f', 'for', 'f90'],
877 '_finish' => \&lang_f77_finish);
879 # Preprocessed Fortran 77.
880 register_language ('name' => 'ppf77',
881 'linker' => 'F77LINK',
883 'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
884 'compiler' => 'PPF77COMPILE',
885 'compile_flag' => '-c',
886 'output_flag' => '-o',
888 'extensions' => ['F'],
889 '_finish' => \&lang_ppf77_finish);
892 register_language ('name' => 'ratfor',
893 'linker' => 'F77LINK',
896 'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
897 'compiler' => 'RCOMPILE',
898 'compile_flag' => '-c',
899 'output_flag' => '-o',
901 'extensions' => ['r'],
902 '_finish' => \&lang_ratfor_finish);
905 # FIXME: for now we can't do dependency tracking for Java.
907 register_language ('name' => 'java',
908 'linker' => 'GCJLINK',
909 'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
910 'flags' => 'GCJFLAGS',
911 'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
912 'compiler' => 'GCJCOMPILE',
913 'compile_flag' => '-c',
914 'output_flag' => '-o',
918 'extensions' => ['java', 'class', 'zip', 'jar'],
919 '_finish' => \&lang_java_finish);
921 ################################################################
923 # Parse command line.
926 # Do configure.ac scan only once.
927 &scan_autoconf_files;
929 die "$me: no `Makefile.am' found or specified\n"
932 # Now do all the work on each file.
933 # This guy must be local otherwise it's private to the loop.
936 foreach $am_file (@input_files)
938 if (! -f ($am_file . '.am'))
940 &am_error ("`" . $am_file . ".am' does not exist");
944 &generate_makefile ($output_files{$am_file}, $am_file);
950 # FIXME: This should be `my'ed next to its subs.
951 use vars '%require_file_found';
953 ################################################################
955 # prog_error (@PRINT-ME)
956 # ----------------------
957 # Signal a programming error, display PRINT-ME, and exit 1.
960 print STDERR "$me: programming error: @_\n";
968 # Return LIST with no duplicates.
973 foreach my $item (@_)
975 if (! defined $seen{$item})
985 ################################################################
989 # &backname ($REL-DIR)
990 # --------------------
991 # If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
992 # For instance `src/foo' => `../..'.
993 # Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
998 foreach (split (/\//, $file))
1000 next if $_ eq '.' || $_ eq '';
1010 return join ('/', @res) || '.';
1013 ################################################################
1015 # Parse command line.
1016 sub parse_arguments ()
1019 &set_strictness ('gnu');
1022 Getopt::Long::config ("bundling");
1023 Getopt::Long::GetOptions
1025 'version' => \&version,
1027 'amdir:s' => \$am_dir,
1028 'gnu' => sub { &set_strictness ('gnu'); },
1029 'gnits' => sub { &set_strictness ('gnits'); },
1030 'cygnus' => \$cygnus_mode,
1031 'foreign' => sub { &set_strictness ('foreign'); },
1032 'include-deps' => sub { $cmdline_use_dependencies = 1; },
1033 'i|ignore-deps' => sub { $cmdline_use_dependencies = 0; },
1034 'no-force' => sub { $force_generation = 0; },
1035 'f|force-missing'=> \$force_missing,
1036 'o|output-dir:s' => \$output_directory,
1037 'a|add-missing' => \$add_missing,
1038 'c|copy' => \$copy_missing,
1039 'v|verbose' => \$verbose,
1040 'Werror' => sub { $SIG{"__WARN__"} = sub { die $_[0] } },
1041 'Wno-error' => sub { $SIG{"__WARN__"} = 'DEFAULT' }
1045 foreach my $arg (@ARGV)
1047 # Handle $local:$input syntax. Note that we only examine the
1048 # first ":" file to see if it is automake input; the rest are
1049 # just taken verbatim. We still keep all the files around for
1050 # dependency checking, however.
1051 my ($local, $input, @rest) = split (/:/, $arg);
1058 # Strip .in; later on .am is tacked on. That is how the
1059 # automake input file is found. Maybe not the best way, but
1060 # it is easy to explain.
1062 or die "$me: invalid input file name `$arg'\n.";
1064 push (@input_files, $input);
1065 $output_files{$input} = join (':', ($local, @rest));
1068 # Take global strictness from whatever we currently have set.
1069 $default_strictness = $strictness;
1070 $default_strictness_name = $strictness_name;
1073 ################################################################
1075 # Generate a Makefile.in given the name of the corresponding Makefile and
1076 # the name of the file output by config.status.
1077 sub generate_makefile
1079 my ($output, $makefile) = @_;
1081 # Reset all the Makefile.am related variables.
1082 &initialize_per_input;
1084 # Name of input file ("Makefile.am") and output file
1085 # ("Makefile.in"). These have no directory components.
1086 $am_file_name = basename ($makefile) . '.am';
1087 $in_file_name = basename ($makefile) . '.in';
1089 # $OUTPUT is encoded. If it contains a ":" then the first element
1090 # is the real output file, and all remaining elements are input
1091 # files. We don't scan or otherwise deal with these input file,
1092 # other than to mark them as dependencies. See
1093 # &scan_autoconf_files for details.
1094 my (@secondary_inputs);
1095 ($output, @secondary_inputs) = split (/:/, $output);
1097 $relative_dir = dirname ($output);
1098 $am_relative_dir = dirname ($makefile);
1100 &read_main_am_file ($makefile . '.am');
1101 if (&handle_options)
1103 # Fatal error. Just return, so we can continue with next file.
1107 # There are a few install-related variables that you should not define.
1108 foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
1110 if (&variable_defined ($var) && !$var_is_am{$var})
1112 &am_line_error ($var, "`$var' should not be defined");
1116 # At the toplevel directory, we might need config.guess, config.sub
1117 # or libtool scripts (ltconfig and ltmain.sh).
1118 if ($relative_dir eq '.')
1120 # libtool requires some files.
1121 &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
1125 # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
1127 &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
1131 # We still need Makefile.in here, because sometimes the `dist'
1132 # target doesn't re-run automake.
1133 if ($am_relative_dir eq $relative_dir)
1135 # Only distribute the files if they are in the same subdir as
1136 # the generated makefile.
1137 &push_dist_common ($in_file_name, $am_file_name);
1140 push (@sources, '$(SOURCES)')
1141 if &variable_defined ('SOURCES');
1142 push (@objects, '$(OBJECTS)')
1143 if &variable_defined ('OBJECTS');
1145 # If OBJEXT/EXEEXT were not set in configure.in, do it, it
1146 # simplifies our task, and anyway starting with Autoconf 2.50, it
1147 # will always be defined, and this code will be dead.
1148 $output_vars .= "EXEEXT =\n"
1149 unless $seen_exeext;
1150 $output_vars .= "OBJEXT = o\n"
1151 unless $seen_objext;
1153 # Must do this after reading .am file. See read_main_am_file to
1154 # understand weird tricks we play there with variables.
1155 &define_variable ('subdir', $relative_dir);
1157 # Check first, because we might modify some state.
1159 &check_gnu_standards;
1160 &check_gnits_standards;
1162 &handle_configure ($output, $makefile, @secondary_inputs);
1165 &handle_ltlibraries;
1169 # This must be run after all the sources are scanned.
1173 # Re-init SOURCES and OBJECTS. FIXME: other code shouldn't depend
1174 # on this (but currently does).
1175 macro_define ('SOURCES', 1, '', 'TRUE',
1176 join (' ', @sources), 'internal');
1177 macro_define ('OBJECTS', 1, '', 'TRUE',
1178 join (' ', @objects), 'internal');
1179 &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);
1191 &handle_minor_options;
1194 # This must come after most other rules.
1195 &handle_dist ($makefile);
1198 &do_check_merge_target;
1199 &handle_all ($output);
1202 if (&variable_defined('lib_LTLIBRARIES') &&
1203 &variable_defined('bin_PROGRAMS'))
1205 $output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
1208 &handle_installdirs;
1210 &handle_factored_dependencies;
1214 if (! -d ($output_directory . '/' . $am_relative_dir))
1216 mkdir ($output_directory . '/' . $am_relative_dir, 0755);
1219 my ($out_file) = $output_directory . '/' . $makefile . ".in";
1220 if (! $force_generation && -e $out_file)
1222 my ($am_time) = (stat ($makefile . '.am'))[9];
1223 my ($in_time) = (stat ($out_file))[9];
1224 # FIXME: should cache these times.
1225 my ($conf_time) = (stat ($configure_ac))[9];
1226 # FIXME: how to do unsigned comparison?
1227 if ($am_time < $in_time || $am_time < $conf_time)
1229 # No need to update.
1232 if (-f 'aclocal.m4')
1234 my ($acl_time) = (stat _)[9];
1235 return if ($am_time < $acl_time);
1239 my $gm_file = new IO::File "> $out_file";
1242 warn "$me: ${am_file}.in: cannot write: $!\n";
1246 print "$me: creating ", $makefile, ".in\n" if $verbose;
1248 # In case we're running under MSWindows, don't write with CRLF
1249 # (as it causes problems for the dependency-file extraction in
1250 # AM_OUTPUT_DEPENDENCY_COMMANDS).
1253 print $gm_file $output_vars;
1254 # We make sure that `all:' is the first target.
1255 print $gm_file $output_all;
1256 print $gm_file $output_header;
1257 print $gm_file $output_rules;
1258 print $gm_file $output_trailer;
1260 if (! $gm_file->close)
1262 warn "$me: $am_file.in: cannot close: $!\n";
1268 ################################################################
1270 # Handle AUTOMAKE_OPTIONS variable. Return 1 on error, 0 otherwise.
1273 if (&variable_defined ('AUTOMAKE_OPTIONS'))
1275 foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
1278 if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
1280 &set_strictness ($_);
1282 elsif ($_ eq 'cygnus')
1288 # An option like "../lib/ansi2knr" is allowed. With
1289 # no path prefix, we assume the required programs are
1290 # in this directory. We save the actual option for
1292 $options{'ansi2knr'} = $_;
1294 elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
1295 || $_ eq 'dist-shar' || $_ eq 'dist-zip'
1296 || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
1297 || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
1298 || $_ eq 'readme-alpha' || $_ eq 'check-news'
1299 || $_ eq 'subdir-objects' || $_ eq 'nostdinc')
1301 # Explicitly recognize these.
1303 elsif ($_ eq 'no-dependencies')
1305 $use_dependencies = 0;
1307 elsif (/(\d+)\.(\d+)([a-z]?)(-[A-Za-z0-9]+)?/)
1309 # Got a version number.
1311 my ($rmajor, $rminor, $ralpha, $rfork) = ($1, $2, $3, $4);
1313 &prog_error ("version is incorrect: $VERSION")
1314 if $VERSION !~ /(\d+)\.(\d+)([a-z]?)(-[A-Za-z0-9]+)?/;
1316 my ($tmajor, $tminor, $talpha, $tfork) = ($1, $2, $3, $4);
1321 # 2.0 is better than 1.0.
1322 # 1.2 is better than 1.1.
1323 # 1.2a is better than 1.2.
1324 # If we require 3.4n-foo then we require something
1325 # >= 3.4n, with the `foo' fork identifier.
1326 if ($rmajor > $tmajor
1327 || ($rmajor == $tmajor && $rminor > $tminor)
1328 || ($rminor == $tminor && $rminor == $tminor
1329 && $ralpha gt $talpha)
1330 || ($rfork ne '' && $rfork ne $tfork))
1332 &am_line_error ('AUTOMAKE_OPTIONS',
1333 "require version $_, but have $VERSION");
1339 &am_line_error ('AUTOMAKE_OPTIONS',
1340 "option `" . $_ . "\' not recognized");
1345 if ($strictness == $GNITS)
1347 $options{'readme-alpha'} = 1;
1348 $options{'check-news'} = 1;
1355 # get_object_extension ($OUT)
1356 # ---------------------------
1357 # Return object extension. Just once, put some code into the output.
1358 # OUT is the name of the output file
1359 sub get_object_extension
1363 # Maybe require libtool library object files.
1364 my $extension = '.$(OBJEXT)';
1365 $extension = '.lo' if ($out =~ /\.la$/);
1367 # Check for automatic de-ANSI-fication.
1368 $extension = '$U' . $extension
1369 if defined $options{'ansi2knr'};
1371 $get_object_extension_was_run = 1;
1377 # Call finish function for each language that was used.
1378 sub handle_languages
1380 if ($use_dependencies)
1382 # Include auto-dep code. Don't include it if DEP_FILES would
1384 if (&saw_sources_p (0) && keys %dep_files)
1386 my $config_aux_dir_specified = ($config_aux_dir ne '.'
1387 && $config_aux_dir ne '');
1389 # Set $require_file_found{'depcomp'} if the depcomp file exists,
1390 # before calling require_config_file on `depcomp'. This makes
1391 # require_file_internal skip its buggy existence test that would
1392 # make automake fail (with `required file `lib/depcomp' not found')
1393 # when AC_CONFIG_AUX_DIR is not set. See tests/subdir4.test.
1394 my $depcomp_dir = ($config_aux_dir_specified ? $config_aux_dir
1396 $require_file_found{'depcomp'} = 1 if -f "$depcomp_dir/depcomp";
1398 # Set location of depcomp.
1399 my $prefix = ($config_aux_dir_specified ? $config_aux_dir
1402 &define_variable ('depcomp', "\$(SHELL) $prefix/depcomp");
1404 &require_config_file ($FOREIGN, 'depcomp');
1406 my @deplist = sort keys %dep_files;
1408 # We define this as a conditional variable because BSD
1409 # make can't handle backslashes for continuing comments on
1410 # the following line.
1411 &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
1413 # Generate each `include' individually. Irix 6 make will
1414 # not properly include several files resulting from a
1415 # variable expansion; generating many separate includes
1417 $output_rules .= "\n";
1418 foreach my $iter (@deplist)
1420 # The strange concatentation is used to avoid
1421 # substitutions from our own configure.
1422 $output_rules .= ('@AMDEP' . '_TRUE@@_am_include@ @_am_quote@'
1423 . $iter . '@_am_quote@' . "\n");
1426 $output_rules .= &file_contents ('depend');
1431 &define_variable ('depcomp', '');
1436 # Is the c linker needed?
1438 foreach my $ext (sort keys %extension_seen)
1440 my $lang = $languages{$extension_map{$ext}};
1442 # Get information on $LANG.
1443 my $pfx = $lang->autodep;
1444 my $fpfx = ($pfx eq '') ? 'CC' : $pfx;
1446 my $AMDEP = (($use_dependencies && $lang->autodep ne 'no')
1447 ? 'AMDEP' : 'FALSE');
1449 my %transform = ('EXT' => $ext,
1452 'LIBTOOL' => $seen_libtool,
1454 '-c' => $lang->compile_flag || '');
1456 # Generate the appropriate rules for this extension.
1457 if ($use_dependencies && $lang->autodep ne 'no'
1458 || defined $lang->compile)
1460 # Some C compilers don't support -c -o. Use it only if really
1462 my $output_flag = $lang->output_flag || '';
1465 && $lang->flags eq 'CFLAGS'
1466 && defined $options{'subdir-objects'});
1469 file_contents ('depend2',
1479 'COMPILE' => '$(' . $lang->compiler . ')',
1480 'LTCOMPILE' => '$(LT' . $lang->compiler . ')',
1481 '-o' => $output_flag);
1484 # Now include code for each specially handled object with this
1486 my %seen_files = ();
1487 foreach my $file (@{$lang_specific_files{$lang->name}})
1489 my ($derived, $source, $obj) = split (' ', $file);
1491 # We might see a given object twice, for instance if it is
1492 # used under different conditions.
1493 next if defined $seen_files{$obj};
1494 $seen_files{$obj} = 1;
1496 my $flags = $lang->flags || '';
1497 my $val = "${derived}_${flags}";
1499 (my $obj_compile = $lang->compile) =~ s/\(AM_$flags/\($val/;
1500 my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
1502 # We _need_ `-o' for per object rules.
1503 my $output_flag = $lang->output_flag || '-o';
1505 # Generate a transform which will turn suffix targets in
1506 # depend2.am into real targets for the particular objects we
1509 file_contents ('depend2',
1514 'SOURCE' => $source,
1516 'OBJOBJ' => "$obj.obj",
1517 'LTOBJ' => "$obj.lo",
1519 'COMPILE' => $obj_compile,
1520 'LTCOMPILE' => $obj_ltcompile,
1521 '-o' => $output_flag));
1524 # The rest of the loop is done once per language.
1525 next if defined $done{$lang};
1529 # If the source to a program consists entirely of code from a
1530 # `pure' language, for instance C++ for Fortran 77, then we
1531 # don't need the C compiler code. However if we run into
1532 # something unusual then we do generate the C code. There are
1533 # probably corner cases here that do not work properly.
1534 # People linking Java code to Fortran code deserve pain.
1535 $needs_c ||= ! $lang->pure;
1537 define_compiler_variable ($lang)
1538 if ($lang->compile);
1540 # The compiler's flag must be a configure variable.
1541 define_configure_variable ($lang->flags)
1542 if (defined $lang->flags);
1544 # Call the finisher.
1548 # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
1549 # suffix rule was learned), don't bother with the C stuff. But if
1550 # anything else creeps in, then use it.
1552 if $need_link || scalar keys %suffix_rules > 1;
1556 if (! defined $done{$languages{'c'}})
1558 &define_configure_variable ($languages{'c'}->flags);
1559 &define_compiler_variable ($languages{'c'});
1561 define_linker_variable ($languages{'c'});
1565 # Output a rule to build from a YACC source. The output from YACC is
1566 # compiled with C or C++, depending on the extension of the YACC file.
1567 sub output_yacc_build_rule
1569 my ($yacc_suffix, $use_ylwrap) = @_;
1571 (my $c_suffix = $yacc_suffix) =~ tr/y/c/;
1573 # Generate rule for c/c++.
1574 $output_rules .= &file_contents ('yacc',
1575 ('YLWRAP' => $use_ylwrap,
1576 'YACC_SUFFIX' => $yacc_suffix,
1577 'C_SUFFIX' => $c_suffix));
1580 sub output_lex_build_rule
1582 my ($lex_suffix, $use_ylwrap) = @_;
1584 (my $c_suffix = $lex_suffix) =~ tr/l/c/;
1586 $output_rules .= &file_contents ('lex',
1587 ('YLWRAP' => $use_ylwrap,
1588 'LEX_SUFFIX' => $lex_suffix,
1589 'C_SUFFIX' => $c_suffix));
1592 if ($use_dependencies)
1594 # Include auto-dep code. Don't include it if DEP_FILES would
1596 if (&saw_sources_p (0) && keys %dep_files)
1598 my $config_aux_dir_specified = ($config_aux_dir ne '.'
1599 && $config_aux_dir ne '');
1601 # Set $require_file_found{'depcomp'} if the depcomp file exists,
1602 # before calling require_config_file on `depcomp'. This makes
1603 # require_file_internal skip its buggy existence test that would
1604 # make automake fail (with `required file `lib/depcomp' not found')
1605 # when AC_CONFIG_AUX_DIR is not set. See tests/subdir4.test.
1606 my $depcomp_dir = ($config_aux_dir_specified ? $config_aux_dir
1608 $require_file_found{'depcomp'} = 1 if -f "$depcomp_dir/depcomp";
1610 # Set location of depcomp.
1611 my $prefix = ($config_aux_dir_specified ? $config_aux_dir
1614 &define_variable ('depcomp', "\$(SHELL) $prefix/depcomp");
1616 &require_config_file ($FOREIGN, 'depcomp');
1618 my @deplist = sort keys %dep_files;
1620 # We define this as a conditional variable because BSD
1621 # make can't handle backslashes for continuing comments on
1622 # the following line.
1623 &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
1625 # Generate each `include' individually. Irix 6 make will
1626 # not properly include several files resulting from a
1627 # variable expansion; generating many separate includes
1629 $output_rules .= "\n";
1630 foreach my $iter (@deplist)
1632 # The strange concatentation is used to avoid
1633 # substitutions from our own configure.
1634 $output_rules .= ('@AMDEP' . '_TRUE@@_am_include@ '
1638 $output_rules .= &file_contents ('depend');
1643 &define_variable ('depcomp', '');
1646 # Check to make sure a source defined in LIBOBJS is not explicitly
1647 # mentioned. This is a separate function (as opposed to being inlined
1648 # in handle_source_transform) because it isn't always appropriate to
1650 sub check_libobjs_sources
1652 my ($one_file, $unxformed) = @_;
1654 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1655 'dist_EXTRA_', 'nodist_EXTRA_')
1658 if (&variable_defined ($prefix . $one_file . '_SOURCES'))
1660 @files = &variable_value_as_list (($prefix
1661 . $one_file . '_SOURCES'),
1664 elsif ($prefix eq '')
1666 @files = ($unxformed . '.c');
1673 foreach my $file (@files)
1675 if (defined $libsources{$file})
1677 &am_line_error ($prefix . $one_file . '_SOURCES',
1678 "automatically discovered file `$file' should not be explicitly mentioned");
1684 if ($use_dependencies)
1686 # Include auto-dep code. Don't include it if DEP_FILES would
1688 if (&saw_sources_p (0) && keys %dep_files)
1690 my $config_aux_dir_specified = ($config_aux_dir ne '.'
1691 && $config_aux_dir ne '');
1693 # Set $require_file_found{'depcomp'} if the depcomp file exists,
1694 # before calling require_config_file on `depcomp'. This makes
1695 # require_file_internal skip its buggy existence test that would
1696 # make automake fail (with `required file `lib/depcomp' not found')
1697 # when AC_CONFIG_AUX_DIR is not set. See tests/subdir4.test.
1698 my $depcomp_dir = ($config_aux_dir_specified ? $config_aux_dir
1700 $require_file_found{'depcomp'} = 1 if -f "$depcomp_dir/depcomp";
1702 # Set location of depcomp.
1703 my $prefix = ($config_aux_dir_specified ? $config_aux_dir
1706 &define_variable ('depcomp', "\$(SHELL) $prefix/depcomp");
1708 &require_config_file ($FOREIGN, 'depcomp');
1710 my @deplist = sort keys %dep_files;
1712 # We define this as a conditional variable because BSD
1713 # make can't handle backslashes for continuing comments on
1714 # the following line.
1715 &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
1717 # Generate each `include' individually. Irix 6 make will
1718 # not properly include several files resulting from a
1719 # variable expansion; generating many separate includes
1721 $output_rules .= "\n";
1722 foreach my $iter (@deplist)
1724 $output_rules .= '@AMDEP_TRUE@@_am_include@ ' . $iter . "\n";
1727 $output_rules .= &file_contents ('depend');
1732 &define_variable ('depcomp', '');
1735 # ($LINKER, @OBJECTS)
1736 # handle_single_transform_list ($VAR, $DERIVED, $OBJ, @FILES)
1737 # -----------------------------------------------------------
1738 # Does much of the actual work for handle_source_transform.
1740 # $DERIVED is the name of resulting executable or library
1741 # $OBJ is the object extension (e.g., `$U.lo')
1742 # @FILES is the list of source files to transform
1744 # $LINKER is name of linker to use (empty string for default linker)
1745 # @OBJECTS are names of objects
1746 sub handle_single_transform_list ($$$@)
1748 my ($var, $derived, $obj, @files) = @_;
1750 my $nonansi_obj = $obj;
1751 $nonansi_obj =~ s/\$U//g;
1752 my %linkers_used = ();
1754 # Turn sources into objects.
1757 # Configure substitutions in _SOURCES variables are errors.
1760 &am_line_error ($var, "$var includes configure substitution `$_'");
1764 # If the source file is in a subdirectory then the `.o' is
1765 # put into the current directory.
1767 # Split file name into base and extension.
1768 next if ! /^(?:(.*)\/)?([^\/]*)\.(.*)$/;
1770 my $directory = $1 || '';
1774 # We must generate a rule for the object if it requires its own flags.
1776 my ($linker, $object);
1778 $extension = &derive_suffix ($extension);
1779 my $lang = $languages{$extension_map{$extension}};
1782 &saw_extension ($extension);
1783 # Found the language, so see what it says.
1784 my $subr = 'lang_' . $lang->name . '_rewrite';
1785 # Note: computed subr call.
1786 my $r = & $subr ($directory, $base, $extension);
1787 # Skip this entry if we were asked not to process it.
1788 next if $r == $LANG_IGNORE;
1790 # Now extract linker and other info.
1791 $linker = $lang->linker;
1796 $object = $base . $obj;
1797 $this_obj_ext = $obj;
1801 $object = $base . $nonansi_obj;
1802 $this_obj_ext = $nonansi_obj;
1805 if (defined $lang->flags
1806 && &variable_defined ($derived . '_' . $lang->flags))
1808 # We have a per-executable flag in effect for this
1809 # object. In this case we rewrite the object's
1810 # name to ensure it is unique. We also require
1811 # the `compile' program to deal with compilers
1812 # where `-c -o' does not work.
1814 # We choose the name `DERIVED_OBJECT' to ensure
1815 # (1) uniqueness, and (2) continuity between
1816 # invocations. However, this will result in a
1817 # name that is too long for losing systems, in
1818 # some situations. So we provide _SHORTNAME to
1821 my $dname = $derived;
1822 if (&variable_defined ($derived . '_SHORTNAME'))
1824 # FIXME: should use the same conditional as
1825 # the _SOURCES variable. But this is really
1826 # silly overkill -- nobody should have
1827 # conditional shortnames.
1828 $dname = &variable_value ($derived . '_SHORTNAME');
1830 $object = $dname . '-' . $object;
1832 &require_file ($FOREIGN, 'compile')
1833 if $lang->name eq 'c';
1835 &prog_error ("$lang->name flags defined without compiler")
1836 if ! defined $lang->compile;
1841 # If rewrite said it was ok, put the object into a
1843 if ($r == $LANG_SUBDIR && $directory ne '')
1845 $object = $directory . '/' . $object;
1848 # If doing dependency tracking, then we can't print
1849 # the rule. If we have a subdir object, we need to
1850 # generate an explicit rule. Actually, in any case
1851 # where the object is not in `.' we need a special
1852 # rule. The per-object rules in this case are
1853 # generated later, by handle_languages.
1854 if ($renamed || $directory ne '')
1856 my $obj_sans_ext = substr ($object, 0,
1857 - length ($this_obj_ext));
1858 push (@{$lang_specific_files{$lang->name}},
1859 "$derived $full $obj_sans_ext");
1862 elsif ($extension eq 'o')
1864 # This is probably the result of a direct suffix rule.
1865 # In this case we just accept the rewrite. FIXME:
1866 # this fails if we want libtool objects.
1867 $object = $base . '.' . $extension;
1872 # No error message here. Used to have one, but it was
1877 $linkers_used{$linker} = 1;
1879 push (@result, $object);
1881 if (defined $object_map{$object})
1883 if ($object_map{$object} ne $full)
1885 &am_error ("object `$object' created by `$full' and `$object_map{$object}'");
1891 $object_map{$object} = $full;
1893 # If file is in subdirectory, we need explicit
1895 if ($directory ne '' || $renamed)
1897 push (@dep_list, $full);
1900 # If resulting object is in subdir, we need to make
1901 # sure the subdir exists at build time.
1902 if ($object =~ /\//)
1904 # FIXME: check that $DIRECTORY is somewhere in the
1907 # We don't allow `..' in object file names for
1908 # *any* source, not just Java. For Java it just
1909 # doesn't make sense, but in general it is
1910 # a problem because we can't pick a good name for
1912 if ($object =~ /(\/|^)\.\.\//)
1914 &am_error ("`$full' contains `..' component but should not");
1917 push (@dep_list, $directory . '/.dirstamp');
1919 # If we're generating dependencies, we also want
1920 # to make sure that the appropriate subdir of the
1921 # .deps directory is created.
1922 if ($use_dependencies)
1924 push (@dep_list, '.deps/' . $directory . '/.dirstamp');
1927 if (! defined $directory_map{$directory})
1929 $directory_map{$directory} = 1;
1930 $output_rules .= ($directory . "/.dirstamp:\n"
1931 . "\t\@\$(mkinstalldirs) $directory\n"
1932 . "\t\@: > $directory/.dirstamp\n");
1933 if ($use_dependencies)
1935 $output_rules .= ('.deps/' . $directory
1937 . "\t\@\$(mkinstalldirs) .deps/$directory\n"
1938 . "\t\@: > .deps/$directory/.dirstamp\n");
1943 &pretty_print_rule ($object . ':', "\t", @dep_list)
1944 if scalar @dep_list > 0;
1947 # Transform .o or $o file into .P file (for automatic
1950 && ($lang->autodep ne 'no'
1951 || $lang->derived_autodep eq 'yes'))
1953 my $depfile = $object;
1954 $depfile =~ s/\.([^.]*)$/.P$1/;
1955 $depfile =~ s/\$\(OBJEXT\)$/o/;
1956 $dep_files{'$(DEPDIR)/' . $depfile} = 1;
1960 return (&resolve_linker (%linkers_used), @result);
1965 # Handle SOURCE->OBJECT transform for one program or library.
1967 # canonical (transformed) name of object to build
1968 # actual name of object to build
1969 # object extension (ie either `.o' or `$o'.
1970 # Return result is name of linker variable that must be used.
1971 # Empty return means just use `LINK'.
1972 sub handle_source_transform
1974 # one_file is canonical name. unxformed is given name. obj is
1976 my ($one_file, $unxformed, $obj) = @_;
1980 if (&variable_defined ($one_file . "_OBJECTS"))
1982 &am_line_error ($one_file . '_OBJECTS',
1983 $one_file . '_OBJECTS', 'should not be defined');
1984 # No point in continuing.
1989 foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
1990 'dist_EXTRA_', 'nodist_EXTRA_')
1992 my $var = $prefix . $one_file . "_SOURCES";
1994 if !variable_defined ($var);
1996 # We are going to define _OBJECTS variables using the prefix.
1997 # Then we glom them all together. So we can't use the null
1998 # prefix here as we need it later.
1999 my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
2001 # Keep track of which prefixes we saw.
2002 $used_pfx{$xpfx} = 1
2003 unless $prefix =~ /EXTRA_/;
2005 push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
2006 push (@objects, '$(' . $xpfx . $one_file . "_OBJECTS)")
2007 unless $prefix =~ /EXTRA_/;
2008 push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
2009 unless $prefix =~ /^nodist_/;
2010 foreach my $cond (variable_conditions ($var))
2012 my @files = &variable_value_as_list ($var, $cond);
2013 my ($temp, @result) =
2014 &handle_single_transform_list ($var, $one_file, $obj,
2016 # If there are no files to compile, don't require a linker (yet).
2020 # Define _OBJECTS conditionally.
2021 &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
2023 unless $prefix =~ /EXTRA_/;
2027 my @keys = sort keys %used_pfx;
2028 if (scalar @keys == 0)
2030 &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
2031 push (@sources, $unxformed . '.c');
2032 push (@dist_sources, $unxformed . '.c');
2033 push (@objects, $unxformed . $obj);
2035 my ($temp, @result) =
2036 &handle_single_transform_list ($one_file . '_SOURCES',
2039 $linker = $temp if $linker eq '';
2040 &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
2044 grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
2045 &define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
2048 # If we want to use `LINK' we must make sure it is defined.
2058 # handle_lib_objects ($XNAME, $VAR)
2059 # ---------------------------------
2060 # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
2061 # Also, generate _DEPENDENCIES variable if appropriate.
2063 # transformed name of object being built, or empty string if no object
2064 # name of _LDADD/_LIBADD-type variable to examine
2065 # Returns 1 if LIBOBJS seen, 0 otherwise.
2066 sub handle_lib_objects
2068 my ($xname, $var) = @_;
2070 &prog_error ("handle_lib_objects: $var undefined")
2071 if ! &variable_defined ($var);
2074 foreach my $cond (&variable_conditions ($var))
2076 if (&handle_lib_objects_cond ($xname, $var, $cond))
2084 # Subroutine of handle_lib_objects: handle a particular condition.
2085 sub handle_lib_objects_cond
2087 my ($xname, $var, $cond) = @_;
2089 # We recognize certain things that are commonly put in LIBADD or
2093 my $seen_libobjs = 0;
2096 foreach my $lsearch (&variable_value_as_list ($var, $cond))
2098 # Skip -lfoo and -Ldir; these are explicitly allowed.
2099 next if $lsearch =~ /^-[lL]/;
2100 if (! $flagvar && $lsearch =~ /^-/)
2102 if ($var =~ /^(.*)LDADD$/)
2104 # Skip -dlopen and -dlpreopen; these are explicitly allowed.
2105 next if $lsearch =~ /^-dl(pre)?open$/;
2106 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2110 # Only get this error once.
2112 &am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
2116 # Assume we have a file of some sort, and push it onto the
2117 # dependency list. Autoconf substitutions are not pushed;
2118 # rarely is a new dependency substituted into (eg) foo_LDADD
2119 # -- but "bad things (eg -lX11) are routinely substituted.
2120 # Note that LIBOBJS and ALLOCA are exceptions to this rule,
2121 # and handled specially below.
2122 push (@dep_list, $lsearch)
2123 unless $lsearch =~ /^\@.*\@$/;
2125 # Automatically handle @LIBOBJS@ and @ALLOCA@. Basically this
2126 # means adding entries to dep_files.
2127 if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
2129 my $myobjext = ($1 ? 'l' : '') . 'o';
2131 push (@dep_list, $lsearch);
2133 if (! keys %libsources
2134 && ! &variable_defined ($1 . 'LIBOBJS'))
2136 &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in `$configure_ac'");
2139 foreach my $iter (keys %libsources)
2141 if ($iter =~ /\.([cly])$/)
2143 &saw_extension ($1);
2144 &saw_extension ('c');
2147 if ($iter =~ /\.h$/)
2149 &require_file_with_line ($var, $FOREIGN, $iter);
2151 elsif ($iter ne 'alloca.c')
2153 my $rewrite = $iter;
2154 $rewrite =~ s/\.c$/.P$myobjext/;
2155 $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
2156 ($rewrite = $iter) =~ s/(\W)/\\$1/g;
2157 $rewrite = "^" . $rewrite . "\$";
2158 # Only require the file if it is not a built source.
2159 if (! &variable_defined ('BUILT_SOURCES')
2160 || ! grep (/$rewrite/,
2161 &variable_value_as_list ('BUILT_SOURCES',
2164 &require_file_with_line ($var, $FOREIGN, $iter);
2169 elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
2171 my $myobjext = ($1 ? 'l' : '') . 'o';
2173 push (@dep_list, $lsearch);
2174 &am_line_error ($var,
2175 "\@$1" . "ALLOCA\@ seen but `AC_FUNC_ALLOCA' not in `$configure_ac'")
2176 if ! defined $libsources{'alloca.c'};
2177 $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
2178 &require_file_with_line ($var, $FOREIGN, 'alloca.c');
2179 &saw_extension ('c');
2183 if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
2185 &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
2188 return $seen_libobjs;
2191 # Canonicalize the input parameter
2195 $string =~ tr/A-Za-z0-9_\@/_/c;
2199 # Canonicalize a name, and check to make sure the non-canonical name
2200 # is never used. Returns canonical name. Arguments are name and a
2201 # list of suffixes to check for.
2202 sub check_canonical_spelling
2204 my ($name, @suffixes) = @_;
2206 my $xname = &canonicalize ($name);
2207 if ($xname ne $name)
2209 foreach my $xt (@suffixes)
2211 &am_line_error ($name . $xt,
2212 "invalid variable `" . $name . $xt
2213 . "'; should be `" . $xname . $xt . "'")
2214 if &variable_defined ($name . $xt);
2224 # Set up the compile suite.
2225 sub handle_compile ()
2228 unless $get_object_extension_was_run;
2231 my $default_includes = '';
2232 if (! defined $options{'nostdinc'})
2234 $default_includes = ' -I. -I$(srcdir)';
2236 if (&variable_defined ('CONFIG_HEADER'))
2238 foreach my $hdr (split (' ', &variable_value ('CONFIG_HEADER')))
2240 $default_includes .= ' -I' . dirname ($hdr);
2245 my ($coms, $vars, $rules) =
2246 &file_contents_internal (1, "$am_dir/compile.am",
2247 ('DEFAULT_INCLUDES' => $default_includes));
2248 $output_vars .= $vars;
2249 $output_rules .= "$coms$rules";
2253 # Output the libtool compilation rules.
2254 $output_rules .= &file_contents ('libtool');
2257 # Check for automatic de-ANSI-fication.
2258 if (defined $options{'ansi2knr'})
2260 if (! $am_c_prototypes)
2262 &am_line_error ('AUTOMAKE_OPTIONS',
2263 "option `ansi2knr' in use but `AM_C_PROTOTYPES' not in `$configure_ac'");
2264 &keyed_aclocal_warning ('AM_C_PROTOTYPES');
2265 # Only give this error once.
2266 $am_c_prototypes = 1;
2269 # topdir is where ansi2knr should be.
2270 if ($options{'ansi2knr'} eq 'ansi2knr')
2272 # Only require ansi2knr files if they should appear in
2274 &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
2275 'ansi2knr.c', 'ansi2knr.1');
2277 # ansi2knr needs to be built before subdirs, so unshift it.
2278 unshift (@all, '$(ANSI2KNR)');
2281 my $ansi2knr_dir = '';
2282 $ansi2knr_dir = dirname ($options{'ansi2knr'})
2283 if $options{'ansi2knr'} ne 'ansi2knr';
2285 $output_rules .= &file_contents ('ansi2knr',
2286 ('ANSI2KNR-DIR' => $ansi2knr_dir));
2293 # handle_programs ()
2294 # ------------------
2295 # Handle C programs.
2298 my @proglist = &am_install_var ('progs', 'PROGRAMS',
2299 'bin', 'sbin', 'libexec', 'pkglib',
2301 return if ! @proglist;
2303 my $seen_libobjs = 0;
2304 foreach my $one_file (@proglist)
2306 my $obj = &get_object_extension ($one_file);
2308 # Canonicalize names and check for misspellings.
2309 my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
2310 '_SOURCES', '_OBJECTS',
2313 my $linker = &handle_source_transform ($xname, $one_file, $obj);
2316 if (&variable_defined ($xname . "_LDADD"))
2318 if (&handle_lib_objects ($xname, $xname . '_LDADD'))
2326 # User didn't define prog_LDADD override. So do it.
2327 &define_variable ($xname . '_LDADD', '$(LDADD)');
2329 # This does a bit too much work. But we need it to
2330 # generate _DEPENDENCIES when appropriate.
2331 if (&variable_defined ('LDADD'))
2333 if (&handle_lib_objects ($xname, 'LDADD'))
2338 elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
2340 &define_variable ($xname . '_DEPENDENCIES', '');
2345 if (&variable_defined ($xname . '_LIBADD'))
2347 &am_line_error ($xname . '_LIBADD',
2348 "use `" . $xname . "_LDADD', not `"
2349 . $xname . "_LIBADD'");
2352 if (! &variable_defined ($xname . '_LDFLAGS'))
2354 # Define the prog_LDFLAGS variable.
2355 &define_variable ($xname . '_LDFLAGS', '');
2358 # Determine program to use for link.
2360 if (&variable_defined ($xname . '_LINK'))
2362 $xlink = $xname . '_LINK';
2366 $xlink = $linker ? $linker : 'LINK';
2369 $output_rules .= &file_contents ('program',
2370 ('PROGRAM' => $one_file,
2371 'XPROGRAM' => $xname,
2372 'XLINK' => $xlink));
2375 if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD'))
2382 foreach my $one_file (@proglist)
2384 my $xname = &canonicalize ($one_file);
2386 if (&variable_defined ($xname . '_LDADD'))
2388 &check_libobjs_sources ($xname, $xname . '_LDADD');
2390 elsif (&variable_defined ('LDADD'))
2392 &check_libobjs_sources ($xname, 'LDADD');
2399 # handle_libraries ()
2400 # -------------------
2402 sub handle_libraries
2404 my @liblist = &am_install_var ('libs', 'LIBRARIES',
2405 'lib', 'pkglib', 'noinst', 'check');
2406 return if ! @liblist;
2408 my %valid = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
2410 if (! defined $configure_vars{'RANLIB'})
2412 foreach my $key (keys %valid)
2414 if (&variable_defined ($key . '_LIBRARIES'))
2416 &am_line_error ($key . '_LIBRARIES', "library used but `RANLIB' not defined in `$configure_ac'");
2417 # Only get this error once. If this is ever printed,
2419 $configure_vars{'RANLIB'} = 'BUG';
2425 my $seen_libobjs = 0;
2426 foreach my $onelib (@liblist)
2428 # Check that the library fits the standard naming convention.
2429 if ($onelib !~ /^lib.*\.a$/)
2431 # FIXME should put line number here. That means mapping
2432 # from library name back to variable name.
2433 &am_error ("`$onelib' is not a standard library name");
2436 my $obj = &get_object_extension ($onelib);
2438 # Canonicalize names and check for misspellings.
2439 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
2440 '_OBJECTS', '_DEPENDENCIES',
2443 if (! &variable_defined ($xlib . '_AR'))
2445 &define_variable ($xlib . '_AR', '$(AR) cru');
2448 if (&variable_defined ($xlib . '_LIBADD'))
2450 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2457 # Generate support for conditional object inclusion in
2459 &define_variable ($xlib . "_LIBADD", '');
2462 if (&variable_defined ($xlib . '_LDADD'))
2464 &am_line_error ($xlib . '_LDADD',
2465 "use `" . $xlib . "_LIBADD', not `"
2466 . $xlib . "_LDADD'");
2469 # Make sure we at look at this.
2470 &examine_variable ($xlib . '_DEPENDENCIES');
2472 &handle_source_transform ($xlib, $onelib, $obj);
2474 $output_rules .= &file_contents ('library',
2475 ('LIBRARY' => $onelib,
2476 'XLIBRARY' => $xlib));
2481 foreach my $onelib (@liblist)
2483 my $xlib = &canonicalize ($onelib);
2484 if (&variable_defined ($xlib . '_LIBADD'))
2486 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2493 # handle_ltlibraries ()
2494 # ---------------------
2495 # Handle shared libraries.
2496 sub handle_ltlibraries
2498 my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
2499 'noinst', 'lib', 'pkglib', 'check');
2500 return if ! @liblist;
2503 my %valid = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
2506 foreach my $key (keys %valid)
2508 if (&variable_defined ($key . '_LTLIBRARIES'))
2512 &am_line_error ($key . '_LTLIBRARIES', "library used but `LIBTOOL' not defined in `$configure_ac'");
2513 # Only get this error once. If this is ever printed,
2515 $configure_vars{'LIBTOOL'} = 'BUG';
2519 # Get the installation directory of each library.
2520 for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
2524 &am_error ("`$_' is already going to be installed in `$instdirs{$_}'");
2528 $instdirs{$_} = $key;
2534 my $seen_libobjs = 0;
2535 foreach my $onelib (@liblist)
2537 my $obj = &get_object_extension ($onelib);
2539 # Canonicalize names and check for misspellings.
2540 my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
2541 '_SOURCES', '_OBJECTS',
2544 if (! &variable_defined ($xlib . '_LDFLAGS'))
2546 # Define the lib_LDFLAGS variable.
2547 &define_variable ($xlib . '_LDFLAGS', '');
2550 # Check that the library fits the standard naming convention.
2551 my $libname_rx = "^lib.*\.la";
2552 if ((&variable_defined ($xlib . '_LDFLAGS')
2553 && grep (/-module/, &variable_value_as_list ($xlib . '_LDFLAGS',
2555 || (&variable_defined ('LDFLAGS')
2556 && grep (/-module/, &variable_value_as_list ('LDFLAGS',
2559 # Relax name checking for libtool modules.
2560 $libname_rx = "\.la";
2562 if ($onelib !~ /$libname_rx$/)
2564 # FIXME this should only be a warning for foreign packages
2565 # FIXME should put line number here. That means mapping
2566 # from library name back to variable name.
2567 &am_error ("`$onelib' is not a standard libtool library name");
2570 if (&variable_defined ($xlib . '_LIBADD'))
2572 if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
2579 # Generate support for conditional object inclusion in
2581 &define_variable ($xlib . "_LIBADD", '');
2584 if (&variable_defined ($xlib . '_LDADD'))
2586 &am_line_error ($xlib . '_LDADD',
2587 "use `" . $xlib . "_LIBADD', not `"
2588 . $xlib . "_LDADD'");
2591 # Make sure we at look at this.
2592 &examine_variable ($xlib . '_DEPENDENCIES');
2594 my $linker = &handle_source_transform ($xlib, $onelib, $obj);
2596 # Determine program to use for link.
2598 if (&variable_defined ($xlib . '_LINK'))
2600 $xlink = $xlib . '_LINK';
2604 $xlink = $linker ? $linker : 'LINK';
2608 if ($instdirs{$onelib} eq 'EXTRA'
2609 || $instdirs{$onelib} eq 'noinst'
2610 || $instdirs{$onelib} eq 'check')
2612 # It's an EXTRA_ library, so we can't specify -rpath,
2613 # because we don't know where the library will end up.
2614 # The user probably knows, but generally speaking automake
2615 # doesn't -- and in fact configure could decide
2616 # dynamically between two different locations.
2621 $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
2624 $output_rules .= &file_contents ('ltlibrary',
2625 ('LTLIBRARY' => $onelib,
2626 'XLTLIBRARY' => $xlib,
2628 'XLINK' => $xlink));
2633 foreach my $onelib (@liblist)
2635 my $xlib = &canonicalize ($onelib);
2636 if (&variable_defined ($xlib . '_LIBADD'))
2638 &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
2644 # See if any _SOURCES variable were misspelled. Also, make sure that
2645 # EXTRA_ variables don't contain configure substitutions.
2648 foreach my $varname (keys %var_value)
2650 foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
2653 if ($varname =~ /$primary$/ && ! $content_seen{$varname})
2655 &am_line_error ($varname,
2656 "invalid unused variable name: `$varname'");
2665 # NOTE we no longer automatically clean SCRIPTS, because it is
2666 # useful to sometimes distribute scripts verbatim. This happens
2667 # eg in Automake itself.
2668 &am_install_var ('-candist', 'scripts', 'SCRIPTS',
2669 'bin', 'sbin', 'libexec', 'pkgdata',
2672 my $scripts_installed = 0;
2673 # Set $scripts_installed if appropriate. Make sure we only find
2674 # scripts which are actually installed -- this is why we can't
2675 # simply use the return value of am_install_var.
2676 my %valid = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
2677 'libexec', 'pkgdata',
2679 foreach my $key (keys %valid)
2681 if ($key ne 'noinst'
2683 && &variable_defined ($key . '_SCRIPTS'))
2685 $scripts_installed = 1;
2686 # push (@check_tests, 'check-' . $key . 'SCRIPTS');
2692 # ($OUTFILE, $VFILE, @CLEAN_FILES)
2693 # &scan_texinfo_file ($FILENAME)
2694 # ------------------------------
2695 # $OUTFILE is the name of the info file produced by $FILENAME.
2696 # $VFILE is the name of the version.texi file used (empty if none).
2697 # @CLEAN_FILES is the list of by products (indexes etc.)
2698 sub scan_texinfo_file
2700 my ($filename) = @_;
2702 # These are always created, no matter whether indexes are used or not.
2703 my @clean_suffixes = ('aux', 'dvi', 'log', 'ps', 'toc',
2704 # grep new.*index texinfo.tex
2705 'cp', 'fn', 'ky', 'vr', 'tp', 'pg');
2707 # There are predefined indexes which don't follow the regular rules.
2708 my %predefined_index =
2711 'c' => 'cps', 'f' => 'fns', 'k' => 'kys',
2712 'v' => 'vrs', 't' => 'tps', 'p' => 'pgs'
2715 # There are commands which include a hidden index command.
2719 'fn' => 'fns', 'un' => 'fns',
2720 'typefn' => 'fns', 'typefun' => 'fns',
2721 'mac' => 'fns', 'spec' => 'fns',
2722 'op' => 'fns', 'typeop' => 'fns',
2723 'method' => 'fns', 'typemethod' => 'fns',
2725 'vr' => 'vrs', 'var' => 'vrs',
2726 'typevr' => 'vrs', 'typevar' => 'vrs',
2729 'ivar' => 'vrs', 'typeivar' => 'vrs',
2734 # Indexes stored into another one. In this case, the *.??s file
2736 my @syncodeindexes = ();
2738 my $texi = new IO::File ("< $filename");
2741 &am_error ("couldn't open `$filename': $!");
2744 print "$me: reading $filename\n" if $verbose;
2746 my ($outfile, $vfile);
2747 while ($_ = $texi->getline)
2749 if (/^\@setfilename +(\S+)/)
2752 if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
2754 &am_file_error ($filename, "$.: ",
2755 "output `$outfile' has unrecognized extension");
2759 # A "version.texi" file is actually any file whose name
2760 # matches "vers*.texi".
2761 elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
2766 # Try to find what are the indexes which are used.
2768 # Creating a new category of index.
2769 elsif (/^\@def(code)?index (\w+)/)
2771 push @clean_suffixes, $2;
2774 # Storing in a predefined index.
2775 elsif (/^\@([cfkvtp])index /)
2777 push @clean_suffixes, $predefined_index{$1};
2779 elsif (/^\@def(\w+) /)
2781 push @clean_suffixes, $hidden_index{$1}
2782 if defined $hidden_index{$1};
2785 # Merging an index into an another.
2786 elsif (/^\@syn(code)?index (\w+) \w+/)
2788 push @syncodeindexes, "$2s";
2796 &am_error ("`$filename' missing \@setfilename");
2800 my $infobase = basename ($filename);
2801 $infobase =~ s/\.te?xi(nfo)?$//;
2803 grep { $clean_files{"$infobase.$_"} = 1 } @clean_suffixes;
2804 grep { delete $clean_files{"$infobase.$_"} } @syncodeindexes;
2805 return ($outfile, $vfile, (sort keys %clean_files));
2811 # Handle all Texinfo source.
2814 &am_line_error ('TEXINFOS',
2815 "`TEXINFOS' is an anachronism; use `info_TEXINFOS'")
2816 if &variable_defined ('TEXINFOS');
2817 return if (! &variable_defined ('info_TEXINFOS')
2818 && ! &variable_defined ('html_TEXINFOS'));
2820 if (&variable_defined ('html_TEXINFOS'))
2822 &am_line_error ('html_TEXINFOS',
2823 "HTML generation not yet supported");
2827 my @texis = &variable_value_as_list ('info_TEXINFOS', 'all');
2829 my (@info_deps_list, @dvis_list, @texi_deps);
2836 foreach my $info_cursor (@texis)
2838 my $infobase = $info_cursor;
2839 $infobase =~ s/\.(txi|texinfo|texi)$//;
2841 if ($infobase eq $info_cursor)
2843 # FIXME: report line number.
2844 &am_error ("texinfo file `$info_cursor' has unrecognized extension");
2847 $texi_suffixes{$1} = 1;
2849 # If 'version.texi' is referenced by input file, then include
2850 # automatic versioning capability.
2851 my ($out_file, $vtexi, @clean_files) =
2852 &scan_texinfo_file ("$relative_dir/$info_cursor")
2854 push (@texi_cleans, @clean_files);
2858 &am_error ("`$vtexi', included in `$info_cursor', also included in `$versions{$vtexi}'")
2859 if (defined $versions{$vtexi});
2860 $versions{$vtexi} = $info_cursor;
2862 # We number the stamp-vti files. This is doable since the
2863 # actual names don't matter much. We only number starting
2864 # with the second one, so that the common case looks nice.
2865 my $vti = ($done ? $done : 'vti');
2868 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2872 if ($config_aux_dir eq '.' || $config_aux_dir eq '')
2874 $conf_dir = '$(srcdir)/';
2878 $conf_dir = $config_aux_dir;
2879 $conf_dir .= '/' unless $conf_dir =~ /\/$/;
2881 $output_rules .= &file_contents ('texi-vers',
2882 ('TEXI' => $info_cursor,
2885 'MDDIR' => $conf_dir));
2888 # If user specified file_TEXINFOS, then use that as explicit
2891 push (@texi_deps, $info_cursor);
2892 # Prefix with $(srcdir) because some version of make won't
2893 # work if the target has it and the dependency doesn't.
2894 push (@texi_deps, '$(srcdir)/' . $vtexi) if $vtexi;
2896 my $canonical = &canonicalize ($infobase);
2897 if (&variable_defined ($canonical . "_TEXINFOS"))
2899 push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
2900 &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
2903 $output_rules .= ("\n" . $out_file . ": "
2904 . join (' ', @texi_deps)
2905 . "\n" . $infobase . ".dvi: "
2906 . join (' ', @texi_deps)
2909 push (@info_deps_list, $out_file);
2910 push (@dvis_list, $infobase . '.dvi');
2913 # Handle location of texinfo.tex.
2914 my $need_texi_file = 0;
2918 $texinfodir = '$(top_srcdir)/../texinfo';
2919 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
2922 elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
2924 $texinfodir = $config_aux_dir;
2925 &define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
2926 $need_texi_file = 2; # so that we require_conf_file later
2928 elsif (&variable_defined ('TEXINFO_TEX'))
2930 # The user defined TEXINFO_TEX so assume he knows what he is
2932 $texinfodir = ('$(srcdir)/'
2933 . dirname (&variable_value ('TEXINFO_TEX')));
2937 $texinfodir = '$(srcdir)';
2938 $need_texi_file = 1;
2941 foreach my $txsfx (sort keys %texi_suffixes)
2943 $output_rules .= &file_contents ('texibuild',
2944 ('TEXINFODIR' => $texinfodir,
2945 'SUFFIX' => $txsfx));
2948 my $texiclean = &pretty_print_internal ("", "\t ", @texi_cleans);
2949 $output_rules .= &file_contents ('texinfos',
2950 ('TEXICLEAN' => $texiclean));
2952 push (@dist_targets, 'dist-info');
2954 if (! defined $options{'no-installinfo'})
2956 # Make sure documentation is made and installed first. Use
2957 # $(INFO_DEPS), not 'info', because otherwise recursive makes
2958 # get run twice during "make all".
2959 unshift (@all, '$(INFO_DEPS)');
2962 &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
2963 &define_variable ("DVIS", join (' ', @dvis_list));
2964 # This next isn't strictly needed now -- the places that look here
2965 # could easily be changed to look in info_TEXINFOS. But this is
2966 # probably better, in case noinst_TEXINFOS is ever supported.
2967 &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
2969 # Do some error checking. Note that this file is not required
2970 # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
2972 if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
2974 if ($need_texi_file > 1)
2976 &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
2981 &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
2986 # Handle any man pages.
2987 sub handle_man_pages
2989 &am_line_error ('MANS', "`MANS' is an anachronism; use `man_MANS'")
2990 if &variable_defined ('MANS');
2992 # Find all the sections in use. We do this by first looking for
2993 # "standard" sections, and then looking for any additional
2994 # sections used in man_MANS.
2995 my (%sections, %vlist);
2996 # We handle nodist_ for uniformity. man pages aren't distributed
2997 # by default so it isn't actually very important.
2998 foreach my $pfx ('', 'dist_', 'nodist_')
3000 # Add more sections as needed.
3001 foreach my $section ('0'..'9', 'n', 'l')
3003 if (&variable_defined ($pfx . 'man' . $section . '_MANS'))
3005 $sections{$section} = 1;
3006 $vlist{'$(' . $pfx . 'man' . $section . '_MANS)'} = 1;
3008 &push_dist_common ('$(' . $pfx . 'man' . $section . '_MANS)')
3013 if (&variable_defined ($pfx . 'man_MANS'))
3015 $vlist{'$(' . $pfx . 'man_MANS)'} = 1;
3016 foreach (&variable_value_as_list ($pfx . 'man_MANS', 'all'))
3018 # A page like `foo.1c' goes into man1dir.
3019 if (/\.([0-9a-z])([a-z]*)$/)
3025 &push_dist_common ('$(' . $pfx . 'man_MANS)')
3030 return unless %sections;
3032 # Now for each section, generate an install and unintall rule.
3033 # Sort sections so output is deterministic.
3034 foreach my $section (sort keys %sections)
3036 $output_rules .= &file_contents ('mans', ('SECTION' => $section));
3039 $output_vars .= &file_contents ('mans-vars',
3040 ('MANS' => join (' ', sort keys %vlist)));
3042 if (! defined $options{'no-installman'})
3044 push (@all, '$(MANS)');
3048 # Handle DATA variables.
3051 &am_install_var ('-noextra', '-candist', 'data', 'DATA',
3052 'data', 'sysconf', 'sharedstate', 'localstate',
3053 'pkgdata', 'noinst', 'check');
3060 if (&variable_defined ('SUBDIRS'))
3062 $output_rules .= ("tags-recursive:\n"
3063 . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
3064 # Never fail here if a subdir fails; it
3066 . "\t test \"\$\$subdir\" = . || (cd \$\$subdir"
3067 . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
3069 push (@tag_deps, 'tags-recursive');
3070 &depend ('.PHONY', 'tags-recursive');
3073 if (&saw_sources_p (1)
3074 || &variable_defined ('ETAGS_ARGS')
3078 foreach my $one_hdr (@config_headers)
3080 if ($relative_dir eq dirname ($one_hdr))
3082 # The config header is in this directory. So require it.
3083 $config .= ' ' if $config;
3084 $config .= basename ($one_hdr);
3087 $output_rules .= &file_contents ('tags',
3088 ('CONFIG' => $config,
3089 'DIRS' => join (' ', @tag_deps)));
3090 &examine_variable ('TAGS_DEPENDENCIES');
3092 elsif (&variable_defined ('TAGS_DEPENDENCIES'))
3094 &am_line_error ('TAGS_DEPENDENCIES',
3095 "doesn't make sense to define `TAGS_DEPENDENCIES' without sources or `ETAGS_ARGS'");
3099 # Every Makefile must define some sort of TAGS rule.
3100 # Otherwise, it would be possible for a top-level "make TAGS"
3101 # to fail because some subdirectory failed.
3102 $output_rules .= "tags: TAGS\nTAGS:\n\n";
3106 # Handle multilib support.
3109 return unless $seen_multilib;
3111 $output_rules .= &file_contents ('multilib');
3116 # &for_dist_common ($A, $B)
3117 # -------------------------
3118 # Subroutine for &handle_dist: sort files to dist.
3120 # We put README first because it then becomes easier to make a
3121 # Usenet-compliant shar file (in these, README must be first).
3123 # FIXME: do more ordering of files here.
3136 # handle_dist ($MAKEFILE)
3137 # -----------------------
3138 # Handle 'dist' target.
3141 my ($makefile) = @_;
3143 # `make dist' isn't used in a Cygnus-style tree.
3144 # Omit the rules so that people don't try to use them.
3145 return if $cygnus_mode;
3147 # Set up maint_charset.
3148 $local_maint_charset = &variable_value ('MAINT_CHARSET')
3149 if &variable_defined ('MAINT_CHARSET');
3150 $maint_charset = $local_maint_charset
3151 if $relative_dir eq '.';
3153 if (&variable_defined ('DIST_CHARSET'))
3155 &am_line_error ('DIST_CHARSET',
3156 "DIST_CHARSET defined but no MAINT_CHARSET defined")
3157 if ! $local_maint_charset;
3158 if ($relative_dir eq '.')
3160 $dist_charset = &variable_value ('DIST_CHARSET')
3164 &am_line_error ('DIST_CHARSET',
3165 "DIST_CHARSET can only be defined at top level");
3169 # Look for common files that should be included in distribution.
3170 foreach my $cfile (@common_files)
3172 if (-f ($relative_dir . "/" . $cfile))
3174 &push_dist_common ($cfile);
3178 # We might copy elements from $configure_dist_common to
3179 # %dist_common if we think we need to. If the file appears in our
3180 # directory, we would have discovered it already, so we don't
3181 # check that. But if the file is in a subdir without a Makefile,
3182 # we want to distribute it here if we are doing `.'. Ugly!
3183 if ($relative_dir eq '.')
3185 foreach my $file (split (' ' , $configure_dist_common))
3187 if (! &is_make_dir (dirname ($file)))
3189 &push_dist_common ($file);
3196 # Files to distributed. Don't use &variable_value_as_list
3197 # as it recursively expands `$(dist_pkgdata_DATA)' etc.
3198 check_variable_defined_unconditionally ('DIST_COMMON');
3199 my @dist_common = split (' ', variable_value ('DIST_COMMON', 'TRUE'));
3200 @dist_common = uniq (sort for_dist_common (@dist_common));
3201 pretty_print ('DIST_COMMON = ', "\t", @dist_common);
3203 # Now that we've processed DIST_COMMON, disallow further attempts
3205 $handle_dist_run = 1;
3207 # Scan EXTRA_DIST to see if we need to distribute anything from a
3208 # subdir. If so, add it to the list. I didn't want to do this
3209 # originally, but there were so many requests that I finally
3211 if (&variable_defined ('EXTRA_DIST'))
3213 # FIXME: This should be fixed to work with conditionals. That
3214 # will require only making the entries in %dist_dirs under the
3215 # appropriate condition. This is meaningful if the nature of
3216 # the distribution should depend upon the configure options
3218 foreach (&variable_value_as_list ('EXTRA_DIST', ''))
3221 next unless s,/+[^/]+$,,;
3227 # We have to check DIST_COMMON for extra directories in case the
3228 # user put a source used in AC_OUTPUT into a subdir.
3229 foreach (&variable_value_as_list ('DIST_COMMON', 'all'))
3232 next unless s,/+[^/]+$,,;
3237 # Rule to check whether a distribution is viable.
3238 my %transform = ('DISTCHECK-HOOK' => &target_defined ('distcheck-hook'),
3239 'GETTEXT' => $seen_gettext);
3241 # Prepend $(distdir) to each directory given.
3243 grep ($rewritten{'$(distdir)/' . $_} = 1, keys %dist_dirs);
3244 $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);
3246 # If we have SUBDIRS, create all dist subdirectories and do
3248 if (&variable_defined ('SUBDIRS'))
3250 # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
3251 # to all possible directories, and use it. If DIST_SUBDIRS is
3252 # defined, just use it.
3253 my $dist_subdir_name;
3254 # Note that we check DIST_SUBDIRS first on purpose. At least
3255 # one project uses so many conditional subdirectories that
3256 # calling variable_conditionally_defined on SUBDIRS will cause
3257 # automake to grow to 150Mb. Sigh.
3258 if (&variable_defined ('DIST_SUBDIRS')
3259 || variable_conditionally_defined ('SUBDIRS'))
3261 $dist_subdir_name = 'DIST_SUBDIRS';
3262 if (! &variable_defined ('DIST_SUBDIRS'))
3264 &define_pretty_variable
3265 ('DIST_SUBDIRS', '',
3266 uniq (&variable_value_as_list ('SUBDIRS', 'all')));
3271 $dist_subdir_name = 'SUBDIRS';
3272 # We always define this because that is what `distclean'
3274 &define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
3277 $transform{'DIST_SUBDIR_NAME'} = $dist_subdir_name;
3280 # If the target `dist-hook' exists, make sure it is run. This
3281 # allows users to do random weird things to the distribution
3282 # before it is packaged up.
3283 push (@dist_targets, 'dist-hook')
3284 if &target_defined ('dist-hook');
3285 $transform{'DIST-TARGETS'} = join(' ', @dist_targets);
3287 # Defining $(DISTDIR).
3288 $transform{'DISTDIR'} = !&variable_defined('distdir');
3289 $transform{'TOP_DISTDIR'} = backname ($relative_dir);
3291 $output_rules .= &file_contents ('distdir', %transform);
3295 # Handle auto-dependency code.
3296 sub handle_dependencies
3298 if ($use_dependencies)
3300 # Include auto-dep code. Don't include it if DEP_FILES would
3302 if (&saw_sources_p (0) && keys %dep_files)
3304 my $config_aux_dir_specified = ($config_aux_dir ne '.'
3305 && $config_aux_dir ne '');
3307 # Set $require_file_found{'depcomp'} if the depcomp file exists,
3308 # before calling require_config_file on `depcomp'. This makes
3309 # require_file_internal skip its buggy existence test that would
3310 # make automake fail (with `required file `lib/depcomp' not found')
3311 # when AC_CONFIG_AUX_DIR is not set. See tests/subdir4.test.
3312 my $depcomp_dir = ($config_aux_dir_specified ? $config_aux_dir
3314 $require_file_found{'depcomp'} = 1 if -f "$depcomp_dir/depcomp";
3316 # Set location of depcomp.
3317 my $prefix = ($config_aux_dir_specified ? $config_aux_dir
3320 &define_variable ('depcomp', "\$(SHELL) $prefix/depcomp");
3322 &require_config_file ($FOREIGN, 'depcomp');
3324 my @deplist = sort keys %dep_files;
3326 # We define this as a conditional variable because BSD
3327 # make can't handle backslashes for continuing comments on
3328 # the following line.
3329 &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);
3331 # Generate each `include' individually. Irix 6 make will
3332 # not properly include several files resulting from a
3333 # variable expansion; generating many separate includes
3335 $output_rules .= "\n";
3336 foreach my $iter (@deplist)
3338 # The strange concatentation is used to avoid
3339 # substitutions from our own configure.
3340 $output_rules .= ('@AMDEP' . '_TRUE@@_am_include@ @_am_quote@'
3341 . $iter . '@_am_quote@' . "\n");
3344 $output_rules .= &file_contents ('depend');
3349 &define_variable ('depcomp', '');
3352 foreach my $lang (values %languages)
3354 if ($lang->autodep ne 'no')
3356 add_depend2 ($lang);
3361 # Handle subdirectories.
3365 unless &variable_defined ('SUBDIRS');
3367 # Make sure each directory mentioned in SUBDIRS actually exists.
3368 foreach my $dir (&variable_value_as_list ('SUBDIRS', 'all'))
3370 # Skip directories substituted by configure.
3371 next if $dir =~ /^\@.*\@$/;
3373 if (! -d $am_relative_dir . '/' . $dir)
3375 &am_line_error ('SUBDIRS',
3376 "required directory $am_relative_dir/$dir does not exist");
3380 &am_line_error ('SUBDIRS', "directory should not contain `/'")
3384 $output_rules .= &file_contents ('subdirs');
3385 variable_pretty_output ('RECURSIVE_TARGETS', 'TRUE');
3389 # ($REGEN, @DEPENDENCIES)
3392 # If aclocal.m4 creation is automated, return the list of its dependencies.
3395 my $regen_aclocal = 0;
3398 unless $relative_dir eq '.';
3400 &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
3401 &examine_variable ('CONFIGURE_DEPENDENCIES');
3403 if (-f 'aclocal.m4')
3405 &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
3406 &push_dist_common ('aclocal.m4');
3408 my $aclocal = new IO::File ("< aclocal.m4");
3411 my $line = $aclocal->getline;
3414 if ($line =~ 'generated automatically by aclocal')
3423 if (-f 'acinclude.m4')
3426 push @ac_deps, 'acinclude.m4';
3429 if (&variable_defined ('ACLOCAL_M4_SOURCES'))
3431 push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
3433 elsif (&variable_defined ('ACLOCAL_AMFLAGS'))
3435 # Scan all -I directories for m4 files. These are our
3437 my $examine_next = 0;
3438 foreach my $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
3443 if ($amdir !~ /^\// && -d $amdir)
3445 foreach my $ac_dep (&my_glob ($amdir . '/*.m4'))
3447 $ac_dep =~ s/^\.\/+//;
3448 push (@ac_deps, $ac_dep)
3449 unless $ac_dep eq "aclocal.m4"
3450 || $ac_dep eq "acinclude.m4";
3454 elsif ($amdir eq '-I')
3461 # Note that it might be possible that aclocal.m4 doesn't exist but
3462 # should be auto-generated. This case probably isn't very
3465 return ($regen_aclocal, @ac_deps);
3468 # Rewrite a list of input files into a form suitable to put on a
3469 # dependency list. The idea is that if an input file has a directory
3470 # part the same as the current directory, then the directory part is
3471 # simply removed. But if the directory part is different, then
3472 # $(top_srcdir) is prepended. Among other things, this is used to
3473 # generate the dependency list for the output files generated by
3474 # AC_OUTPUT. Consider what the dependencies should look like in this
3476 # AC_OUTPUT(src/out:src/in1:lib/in2)
3477 # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
3478 # If 0 then files that require this addition will simply be ignored.
3479 sub rewrite_inputs_into_dependencies
3481 my ($add_srcdir, @inputs) = @_;
3484 foreach my $single (@inputs)
3486 if (dirname ($single) eq $relative_dir)
3488 push (@newinputs, basename ($single));
3492 push (@newinputs, '$(top_srcdir)/' . $single);
3499 # Handle remaking and configure stuff.
3500 # We need the name of the input file, to do proper remaking rules.
3501 sub handle_configure
3503 my ($local, $input, @secondary_inputs) = @_;
3505 my $input_base = basename ($input);
3506 my $local_base = basename ($local);
3508 my $amfile = $input_base . '.am';
3509 # We know we can always add '.in' because it really should be an
3510 # error if the .in was missing originally.
3511 my $infile = '$(srcdir)/' . $input_base . '.in';
3512 my $colon_infile = '';
3513 if ($local ne $input || @secondary_inputs)
3515 $colon_infile = ':' . $input . '.in';
3517 $colon_infile .= ':' . join (':', @secondary_inputs)
3518 if @secondary_inputs;
3520 my @rewritten = &rewrite_inputs_into_dependencies (1, @secondary_inputs);
3522 my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4 ();
3525 &file_contents ('configure',
3529 => join (' ', @rewritten),
3531 => ((($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
3536 => join (' ', @include_stack),
3540 => $cygnus_mode ? 'cygnus' : $strictness_name,
3542 => $cmdline_use_dependencies ? '' : ' --ignore-deps',
3543 'MAKEFILE-AM-SOURCES'
3544 => "$input$colon_infile",
3546 => $regen_aclocal_m4,
3548 => join (' ', @aclocal_m4_deps)));
3550 if ($relative_dir eq '.')
3552 &push_dist_common ('acconfig.h')
3556 # If we have a configure header, require it.
3557 my @local_fullnames = @config_fullnames;
3558 my @local_names = @config_names;
3560 my $distclean_config = '';
3561 foreach my $one_hdr (@config_headers)
3563 my $one_fullname = shift (@local_fullnames);
3564 my $one_name = shift (@local_names);
3566 my $header_dir = dirname ($one_name);
3568 # If the header is in the current directory we want to build
3569 # the header here. Otherwise, if we're at the topmost
3570 # directory and the header's directory doesn't have a
3571 # Makefile, then we also want to build the header.
3572 if ($relative_dir eq $header_dir
3573 || ($relative_dir eq '.' && ! &is_make_dir ($header_dir)))
3575 my ($cn_sans_dir, $stamp_dir);
3576 if ($relative_dir eq $header_dir)
3578 $cn_sans_dir = basename ($one_name);
3583 $cn_sans_dir = $one_name;
3584 if ($header_dir eq '.')
3590 $stamp_dir = $header_dir . '/';
3594 # Compute relative path from directory holding output
3595 # header to directory holding input header. FIXME:
3596 # doesn't handle case where we have multiple inputs.
3598 if (dirname ($one_hdr) eq $relative_dir)
3600 $ch_sans_dir = basename ($one_hdr);
3604 $ch_sans_dir = backname ($relative_dir) . '/' . $one_hdr;
3607 &require_file_with_conf_line ($config_header_line,
3608 $FOREIGN, $ch_sans_dir);
3610 # Header defined and in this directory.
3612 if (-f $one_name . '.top')
3614 push (@files, "${cn_sans_dir}.top");
3616 if (-f $one_name . '.bot')
3618 push (@files, "${cn_sans_dir}.bot");
3621 &push_dist_common (@files);
3623 # For now, acconfig.h can only appear in the top srcdir.
3624 if (-f 'acconfig.h')
3626 push (@files, '$(top_srcdir)/acconfig.h');
3629 my $stamp_name = 'stamp-h';
3630 $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
3632 my $out_dir = dirname ($ch_sans_dir);
3635 &file_contents ('remake-hdr',
3636 ('FILES' => join (' ', @files),
3637 'CONFIG_HEADER' => $cn_sans_dir,
3638 'CONFIG_HEADER_IN' => $ch_sans_dir,
3639 'CONFIG_HEADER_FULL' => $one_fullname,
3640 'STAMP' => "$stamp_dir$stamp_name",
3641 'SRC_STAMP' => "$out_dir/$stamp_name"));
3643 &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
3644 &require_file_with_conf_line ($config_header_line, $FOREIGN,
3645 "${out_dir}/${stamp_name}.in");
3647 $distclean_config .= ' ' if $distclean_config;
3648 $distclean_config .= $cn_sans_dir;
3652 if ($distclean_config)
3654 $output_rules .= &file_contents ('clean-hdr',
3655 ('FILES' => $distclean_config));
3658 # Set location of mkinstalldirs.
3659 if ($config_aux_dir ne '.' && $config_aux_dir ne '')
3661 &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
3662 . '/mkinstalldirs'));
3666 &define_variable ('mkinstalldirs',
3667 '$(SHELL) $(top_srcdir)/mkinstalldirs');
3670 &am_line_error ('CONFIG_HEADER',
3671 "`CONFIG_HEADER' is an anachronism; now determined from `$configure_ac'")
3672 if &variable_defined ('CONFIG_HEADER');
3674 my $config_header = '';
3675 foreach my $one_name (@config_names)
3677 # Generate CONFIG_HEADER define.
3679 if ($relative_dir eq dirname ($one_name))
3681 $one_hdr = basename ($one_name);
3685 $one_hdr = "\$(top_builddir)/${one_name}";
3688 $config_header .= ' ' if $config_header;
3689 $config_header .= $one_hdr;
3693 &define_variable ("CONFIG_HEADER", $config_header);
3696 # Now look for other files in this directory which must be remade
3697 # by config.status, and generate rules for them.
3698 my @actual_other_files = ();
3699 foreach my $lfile (@other_input_files)
3702 my (@inputs, @rewritten_inputs);
3703 my ($need_rewritten);
3704 if ($lfile =~ /^([^:]*):(.*)$/)
3706 # This is the ":" syntax of AC_OUTPUT.
3708 $local = basename ($file);
3709 @inputs = split (':', $2);
3710 @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
3711 $need_rewritten = 1;
3717 $local = basename ($file);
3718 @inputs = ($file . '.in');
3720 &rewrite_inputs_into_dependencies (1, @inputs);
3721 $need_rewritten = 0;
3724 # Make sure the dist directory for each input file is created.
3725 # We only have to do this at the topmost level though. This
3726 # is a bit ugly but it easier than spreading out the logic,
3727 # especially in cases like AC_OUTPUT(foo/out:bar/in), where
3728 # there is no Makefile in bar/.
3729 if ($relative_dir eq '.')
3733 $dist_dirs{dirname ($_)} = 1;
3737 # We skip any automake input files, as they are handled
3738 # elsewhere. We also skip files that aren't in this
3739 # directory. However, if the file's directory does not have a
3740 # Makefile, and we are currently doing `.', then we create a
3741 # rule to rebuild the file in the subdir.
3742 next if -f $file . '.am';
3743 my $fd = dirname ($file);
3744 if ($fd ne $relative_dir)
3746 if ($relative_dir eq '.' && ! &is_make_dir ($fd))
3756 # Some users have been tempted to put `stamp-h' in the
3757 # AC_OUTPUT line. This won't do the right thing, so we
3758 # explicitly fail here.
3759 if ($local eq 'stamp-h')
3761 # FIXME: allow real filename.
3762 &am_conf_error ($configure_ac, $ac_output_line,
3763 'stamp-h should not appear in AC_OUTPUT');
3767 $output_rules .= ($local . ': '
3768 . '$(top_builddir)/config.status '
3769 . join (' ', @rewritten_inputs) . "\n"
3771 . 'cd $(top_builddir) && CONFIG_FILES='
3772 . ($relative_dir eq '.' ? '' : '$(subdir)/')
3773 . '$@' . ($need_rewritten
3774 ? (':' . join (':', @inputs))
3776 . ' CONFIG_HEADERS= CONFIG_LINKS= $(SHELL) ./config.status'
3778 push (@actual_other_files, $local);
3780 # Require all input files.
3781 &require_file_with_conf_line ($ac_output_line, $FOREIGN,
3782 &rewrite_inputs_into_dependencies (0, @inputs));
3785 # These files get removed by "make clean".
3786 &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
3792 my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
3793 'oldinclude', 'pkginclude',
3797 next unless /\.(.*)$/;
3798 &saw_extension ($1);
3804 return if ! $seen_gettext || $relative_dir ne '.';
3806 if (! &variable_defined ('SUBDIRS'))
3809 ("AM_GNU_GETTEXT used but SUBDIRS not defined");
3813 my @subdirs = &variable_value_as_list ('SUBDIRS', 'all');
3814 &am_line_error ('SUBDIRS',
3815 "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
3816 if ! grep ('po', @subdirs);
3817 &am_line_error ('SUBDIRS',
3818 "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
3819 if ! grep ('intl', @subdirs);
3821 &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
3823 # Ensure that each language in ALL_LINGUAS has a .po file, and
3824 # each po file is mentioned in ALL_LINGUAS.
3828 grep ($linguas{$_} = 1, split (' ', $all_linguas));
3835 &am_line_error ($all_linguas_line,
3836 ("po/$_.po exists but `$_' not in `ALL_LINGUAS'"))
3840 foreach (keys %linguas)
3842 &am_line_error ($all_linguas_line,
3843 "$_ in `ALL_LINGUAS' but po/$_.po does not exist")
3849 &am_error ("AM_GNU_GETTEXT in `$configure_ac' but `ALL_LINGUAS' not defined");
3853 # Handle footer elements.
3856 if (variable_value ('SOURCES'))
3858 # NOTE don't use define_pretty_variable here, because
3859 # $contents{...} is already defined.
3860 $output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n";
3862 if (variable_value ('OBJECTS'))
3864 # NOTE don't use define_pretty_variable here, because
3865 # $contents{...} is already defined.
3866 $output_vars .= 'OBJECTS = ' . variable_value ('OBJECTS') . "\n";
3868 if (variable_value ('SOURCES') || variable_value ('OBJECTS'))
3870 $output_vars .= "\n";
3873 if (&target_defined ('.SUFFIXES'))
3875 &am_line_error ('.SUFFIXES',
3876 "use variable `SUFFIXES', not target `.SUFFIXES'");
3879 # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
3880 # before .SUFFIXES. So we make sure that .SUFFIXES appears before
3881 # anything else, by sticking it right after the default: target.
3882 $output_header .= ".SUFFIXES:\n";
3883 if (@suffixes || &variable_defined ('SUFFIXES'))
3885 # Make sure suffixes has unique elements. Sort them to ensure
3886 # the output remains consistent. However, $(SUFFIXES) is
3887 # always at the start of the list, unsorted. This is done
3888 # because make will choose rules depending on the ordering of
3889 # suffixes, and this lets the user have some control. Push
3890 # actual suffixes, and not $(SUFFIXES). Some versions of make
3891 # do not like variable substitutions on the .SUFFIXES line.
3892 my @user_suffixes = (&variable_defined ('SUFFIXES')
3893 ? &variable_value_as_list ('SUFFIXES', '')
3897 grep ($suffixes{$_} = 1, @suffixes);
3898 delete @suffixes{@user_suffixes};
3900 $output_header .= (".SUFFIXES: "
3901 . join (' ', @user_suffixes, sort keys %suffixes)
3904 $output_trailer .= &file_contents ('footer');
3907 # Deal with installdirs target.
3908 sub handle_installdirs ()
3911 &file_contents ('install',
3913 => variable_value ('_am_installdirs') || ''));
3917 # Deal with all and all-am.
3920 my ($makefile) = @_;
3924 # Put this at the beginning for the sake of non-GNU makes. This
3925 # is still wrong if these makes can run parallel jobs. But it is
3927 unshift (@all, basename ($makefile));
3929 foreach my $one_name (@config_names)
3931 push (@all, basename ($one_name))
3932 if dirname ($one_name) eq $relative_dir;
3935 # Install `all' hooks.
3936 if (&target_defined ("all-local"))
3938 push (@all, "all-local");
3939 &depend ('.PHONY', "all-local");
3942 &pretty_print_rule ("all-am:", "\t\t", @all);
3943 &depend ('.PHONY', 'all-am', 'all');
3948 my @local_headers = ();
3949 push @local_headers, '$(BUILT_SOURCES)'
3950 if &variable_defined ('BUILT_SOURCES');
3951 foreach my $one_name (@config_names)
3953 push @local_headers, basename ($one_name)
3954 if dirname ($one_name) eq $relative_dir;
3959 # We need to make sure config.h is built before we recurse.
3960 # We also want to make sure that built sources are built
3961 # before any ordinary `all' targets are run. We can't do this
3962 # by changing the order of dependencies to the "all" because
3963 # that breaks when using parallel makes. Instead we handle
3964 # things explicitly.
3965 $output_all .= ("all: " . join (' ', @local_headers)
3967 . '$(MAKE) $(AM_MAKEFLAGS) '
3968 . (&variable_defined ('SUBDIRS')
3969 ? 'all-recursive' : 'all-am')
3974 $output_all .= "all: " . (&variable_defined ('SUBDIRS')
3975 ? 'all-recursive' : 'all-am') . "\n\n";
3980 # Handle check merge target specially.
3981 sub do_check_merge_target
3983 if (&target_defined ('check-local'))
3985 # User defined local form of target. So include it.
3986 push (@check_tests, 'check-local');
3987 &depend ('.PHONY', 'check-local');
3990 # In --cygnus mode, check doesn't depend on all.
3993 # Just run the local check rules.
3994 &pretty_print_rule ('check-am:', "\t\t", @check);
3998 # The check target must depend on the local equivalent of
3999 # `all', to ensure all the primary targets are built. Then it
4000 # must build the local check rules.
4001 $output_rules .= "check-am: all-am\n";
4002 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4006 &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ",
4010 &depend ('.PHONY', 'check', 'check-am');
4011 $output_rules .= ("check: "
4012 . (&variable_defined ('SUBDIRS')
4013 ? 'check-recursive' : 'check-am')
4017 # Handle all 'clean' targets.
4022 # Don't include `MAINTAINER'; it is handled specially below.
4023 foreach my $name ('MOSTLY', '', 'DIST')
4025 $transform{"${name}CLEAN"} = &variable_defined ("${name}CLEANFILES");
4028 # Built sources are automatically removed by maintainer-clean.
4029 push (@maintainer_clean_files, '$(BUILT_SOURCES)')
4030 if &variable_defined ('BUILT_SOURCES');
4031 push (@maintainer_clean_files, '$(MAINTAINERCLEANFILES)')
4032 if &variable_defined ('MAINTAINERCLEANFILES');
4034 $output_rules .= &file_contents ('clean',
4037 # Join with no space to avoid
4038 # spurious `test -z' success at
4040 => join ('', @maintainer_clean_files),
4042 # A space is required in the join here.
4043 => join (' ', @maintainer_clean_files)));
4047 # &depend ($CATEGORY, @DEPENDENDEES)
4048 # ----------------------------------
4049 # The target $CATEGORY depends on @DEPENDENDEES.
4052 my ($category, @dependendees) = @_;
4054 push (@{$dependencies{$category}}, @dependendees);
4059 # &target_cmp ($A, $B)
4060 # --------------------
4061 # Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
4074 # &handle_factored_dependencies ()
4075 # --------------------------------
4076 # Handle everything related to gathered targets.
4077 sub handle_factored_dependencies
4080 foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
4081 'uninstall-exec-local', 'uninstall-exec-hook')
4083 if (&target_defined ($utarg))
4086 $x =~ s/(data|exec)-//;
4087 &am_line_error ($utarg, "use `$x', not `$utarg'");
4091 if (&target_defined ('install-local'))
4093 &am_line_error ('install-local',
4094 "use `install-data-local' or `install-exec-local', "
4095 . "not `install-local'");
4098 if (!defined $options{'no-installinfo'}
4099 && &target_defined ('install-info-local'))
4101 &am_line_error ('install-info-local',
4102 "`install-info-local' target defined but "
4103 . "`no-installinfo' option not in use");
4106 # Install the -local hooks.
4107 foreach (keys %dependencies)
4109 # Hooks are installed on the -am targets.
4111 if (&target_defined ("$_-local"))
4113 depend ("$_-am", "$_-local");
4114 &depend ('.PHONY', "$_-local");
4118 # Install the -hook hooks.
4119 # FIXME: Why not be as liberal as we are with -local hooks?
4120 foreach ('install-exec', 'install-data')
4122 if (&target_defined ("$_-hook"))
4124 $actions{"$_-am"} .=
4125 ("\t\@\$(NORMAL_INSTALL)\n"
4126 . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
4130 # All the required targets are phony.
4131 grep { &depend ('.PHONY', $_) } keys %required_targets;
4133 # Actually output gathered targets.
4134 foreach (sort target_cmp keys %dependencies)
4136 # If there is nothing about this guy, skip it.
4138 unless (@{$dependencies{$_}}
4140 || $required_targets{$_});
4141 &pretty_print_rule ("$_:", "\t",
4142 uniq (sort @{$dependencies{$_}}));
4143 $output_rules .= $actions{$_}
4144 if defined $actions{$_};
4145 $output_rules .= "\n";
4150 # &handle_tests_dejagnu ()
4151 # ------------------------
4152 sub handle_tests_dejagnu
4154 push (@check_tests, 'check-DEJAGNU');
4156 # Only create site.exp rule if user hasn't already written one.
4158 &file_contents ('dejagnu',
4159 ('SITE-EXP' => ! &target_defined ('site.exp'),
4160 'BUILD' => $seen_canonical == $AC_CANONICAL_SYSTEM,
4161 'HOST' => $seen_canonical,
4162 'TARGET' => $seen_canonical == $AC_CANONICAL_SYSTEM));
4166 # Handle TESTS variable and other checks.
4169 if (defined $options{'dejagnu'})
4171 &handle_tests_dejagnu;
4175 foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
4178 "`$c' defined but `dejagnu' not in `AUTOMAKE_OPTIONS'")
4179 if &variable_defined ($c);
4183 if (&variable_defined ('TESTS'))
4185 push (@check_tests, 'check-TESTS');
4186 $output_rules .= &file_contents ('check');
4190 # Handle Emacs Lisp.
4191 sub handle_emacs_lisp
4193 my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
4196 return if ! @elfiles;
4198 # Generate .elc files.
4199 grep ($_ .= 'c', @elfiles);
4200 &define_pretty_variable ('ELCFILES', '', @elfiles);
4202 push (@all, '$(ELCFILES)');
4204 &am_error ("`lisp_LISP' defined but `AM_PATH_LISPDIR' not in `$configure_ac'")
4205 if ! $seen_lispdir && &variable_defined ('lisp_LISP');
4207 &require_file_with_conf_line ('AM_PATH_LISPDIR', $FOREIGN, 'elisp-comp');
4213 my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
4214 'python', 'noinst');
4215 return if ! @pyfiles;
4217 # Found some python.
4218 &am_error ("`python_PYTHON' defined but `AM_CHECK_PYTHON' not in `$configure_ac'")
4219 if ! $seen_pythondir && &variable_defined ('python_PYTHON');
4221 &require_file_with_conf_line ('AM_CHECK_PYTHON', $FOREIGN, 'py_comp');
4227 my @sourcelist = &am_install_var ('-candist',
4229 'java', 'noinst', 'check');
4230 return if ! @sourcelist;
4232 my %valid = &am_primary_prefixes ('JAVA', 1,
4233 'java', 'noinst', 'check');
4236 foreach my $curs (keys %valid)
4238 if (! &variable_defined ($curs . '_JAVA') || $curs eq 'EXTRA')
4245 &am_line_error ($curs . '_JAVA',
4246 "multiple _JAVA primaries in use");
4251 push (@all, 'class' . $dir . '.stamp');
4255 # Handle some of the minor options.
4256 sub handle_minor_options
4258 if (defined $options{'readme-alpha'})
4260 if ($relative_dir eq '.')
4262 if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
4264 # FIXME: allow real filename.
4265 &am_conf_line_error ($configure_ac,
4266 $package_version_line,
4267 "version `$package_version' doesn't follow Gnits standards");
4269 elsif (defined $1 && -f 'README-alpha')
4271 # This means we have an alpha release. See
4272 # GNITS_VERSION_PATTERN for details.
4273 &require_file ($FOREIGN, 'README-alpha');
4279 ################################################################
4282 my @make_input_list;
4283 # &scan_autoconf_config_files ($CONFIG-FILES)
4284 # -------------------------------------------
4285 # Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
4287 sub scan_autoconf_config_files
4289 my ($config_files) = @_;
4290 # Look at potential Makefile.am's.
4291 foreach (split ' ', $config_files)
4293 # Must skip empty string for Perl 4.
4294 next if $_ eq "\\" || $_ eq '';
4296 # Handle $local:$input syntax. Note that we ignore
4297 # every input file past the first, though we keep
4298 # those around for later.
4299 my ($local, $input, @rest) = split (/:/);
4306 # FIXME: should be error if .in is missing.
4307 $input =~ s/\.in$//;
4310 if (-f $input . '.am')
4312 # We have a file that automake should generate.
4313 push (@make_input_list, $input);
4314 $make_list{$input} = join (':', ($local, @rest));
4318 # We have a file that automake should cause to be
4319 # rebuilt, but shouldn't generate itself.
4320 push (@other_input_files, $_);
4326 # &scan_autoconf_traces ($FILENAME)
4327 # ---------------------------------
4328 # FIXME: For the time being, we don't care about the FILENAME.
4329 sub scan_autoconf_traces
4331 my ($filename) = @_;
4333 my $traces = "$ENV{amtraces} ";
4335 $traces .= ' -t AC_CONFIG_FILES';
4336 $traces .= ' -t AC_LIBSOURCE';
4337 $traces .= ' -t AC_SUBST';
4339 my $tracefh = new IO::File ("$traces |");
4342 die "$me: couldn't open `$traces': $!\n";
4344 print "$me: reading $traces\n" if $verbose;
4346 while ($_ = $tracefh->getline)
4349 my ($file, $line, $macro, @args) = split /:/;
4350 my $here = "$file:$line";
4352 # Alphabetical ordering please.
4353 if ($macro eq 'AC_CONFIG_FILES')
4355 # Look at potential Makefile.am's.
4356 &scan_autoconf_config_files ($args[0]);
4358 elsif ($macro eq 'AC_LIBSOURCE')
4360 my $source = "$args[0].c";
4361 # We should actually also `close' the sources: getopt.c
4362 # wants getopt.h etc. But actually it should be done in the
4363 # macro itself, i.e., we have to first fix Autoconf to extend
4364 # _AC_LIBOBJ_DECL and use it the in various macros.
4365 if (!defined $libsources{$source})
4367 print STDERR "traces: discovered $source\n";
4368 $libsources{$source} = $here;
4371 elsif ($macro eq 'AC_SUBST')
4373 if (!defined $configure_vars{$args[0]})
4375 print STDERR "traces: discovered AC_SUBST($args[0])\n";
4376 $configure_vars{$args[0]} = $here;
4382 || die "$me: close: $traces: $!\n";
4386 # &scan_one_autoconf_file ($FILENAME)
4387 # -----------------------------------
4388 # Scan one file for interesting things. Subroutine of
4389 # &scan_autoconf_files.
4390 sub scan_one_autoconf_file
4392 my ($filename) = @_;
4394 my $configfh = new IO::File ("< $filename");
4397 die "$me: couldn't open `$filename': $!\n";
4399 print "$me: reading $filename\n" if $verbose;
4401 my ($in_ac_output, $in_ac_replace) = (0, 0);
4402 while ($_ = $configfh->getline)
4404 # Remove comments from current line.
4408 # Skip macro definitions. Otherwise we might be confused into
4409 # thinking that a macro that was only defined was actually
4413 # Follow includes. This is a weirdness commonly in use at
4414 # Cygnus and hopefully nowhere else.
4415 if (/sinclude\((.*)\)/ && -f $1)
4417 # $_ being local, if we don't preserve it, when coming
4418 # back we will have $_ undefined, which is bad for the
4419 # the rest of this routine.
4420 my $underscore = $_;
4421 &scan_one_autoconf_file ($1);
4425 # Populate libobjs array.
4426 if (/AC_FUNC_ALLOCA/)
4428 $libsources{'alloca.c'} = 1;
4430 elsif (/AC_FUNC_GETLOADAVG/)
4432 $libsources{'getloadavg.c'} = 1;
4434 elsif (/AC_FUNC_MEMCMP/)
4436 $libsources{'memcmp.c'} = 1;
4438 elsif (/AC_STRUCT_ST_BLOCKS/)
4440 $libsources{'fileblocks.c'} = 1;
4442 elsif (/A[CM]_REPLACE_GNU_GETOPT/)
4444 $libsources{'getopt.c'} = 1;
4445 $libsources{'getopt1.c'} = 1;
4447 elsif (/AM_FUNC_STRTOD/)
4449 $libsources{'strtod.c'} = 1;
4451 elsif (/AM_WITH_REGEX/)
4453 $libsources{'rx.c'} = 1;
4454 $libsources{'rx.h'} = 1;
4455 $libsources{'regex.c'} = 1;
4456 $libsources{'regex.h'} = 1;
4458 elsif (/AC_FUNC_MKTIME/)
4460 $libsources{'mktime.c'} = 1;
4462 elsif (/AM_FUNC_ERROR_AT_LINE/)
4464 $libsources{'error.c'} = 1;
4465 $libsources{'error.h'} = 1;
4467 elsif (/AM_FUNC_OBSTACK/)
4469 $libsources{'obstack.c'} = 1;
4470 $libsources{'obstack.h'} = 1;
4472 elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
4473 || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
4475 foreach my $libobj_iter (split (' ', $1))
4477 if ($libobj_iter =~ /^(.*)\.o(bj)?$/
4478 || $libobj_iter =~ /^(.*)\.\$ac_objext$/
4479 || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
4481 $libsources{$1 . '.c'} = 1;
4485 elsif (/AC_LIBOBJ\(([^)]+)\)/)
4487 $libsources{"$1.c"} = 1;
4490 if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
4496 $in_ac_replace = 0 if s/[\]\)].*$//;
4497 # Remove trailing backslash.
4501 # Need to skip empty elements for Perl 4.
4503 $libsources{$_ . '.c'} = 1;
4507 if (/$obsolete_rx/o)
4510 if ($obsolete_macros{$1} ne '')
4512 $hint = '; ' . $obsolete_macros{$1};
4514 &am_conf_line_error ($filename, $., "`$1' is obsolete$hint");
4517 # Process the AC_OUTPUT and AC_CONFIG_FILES macros.
4518 if (! $in_ac_output && s/AC_(OUTPUT|CONFIG_FILES)\s*\(\[?//)
4521 $ac_output_line = $.;
4532 # Look at potential Makefile.am's.
4533 &scan_autoconf_config_files ($_);
4535 if ($closing && @make_input_list == 0 && @other_input_files == 0)
4537 &am_conf_line_error ($filename, $ac_output_line,
4538 "No files mentioned in `AC_OUTPUT'");
4543 if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
4545 @config_aux_path = &unquote_m4_arg ($1);
4548 # Check for ansi2knr.
4549 $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
4551 # Check for exe extension stuff.
4555 $configure_vars{'EXEEXT'} = $filename . ':' . $.;
4561 $configure_vars{'OBJEXT'} = $filename . ':' . $.;
4564 # Check for `-c -o' code.
4565 $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
4567 # Check for NLS support.
4568 if (/AM_GNU_GETTEXT/)
4571 $ac_gettext_line = $.;
4574 # Look for ALL_LINGUAS.
4575 if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
4579 $all_linguas_line = $.;
4582 # Handle configuration headers. A config header of `[$1]'
4583 # means we are actually scanning AM_CONFIG_HEADER from
4585 if (/A([CM])_CONFIG_HEADERS?\s*\((.*)\)/
4589 ($filename, $., "`automake requires `AM_CONFIG_HEADER', not `AC_CONFIG_HEADER'")
4592 $config_header_line = $.;
4593 foreach my $one_hdr (split (' ', &unquote_m4_arg ($2)))
4595 push (@config_fullnames, $one_hdr);
4596 if ($one_hdr =~ /^([^:]+):(.+)$/)
4598 push (@config_names, $1);
4599 push (@config_headers, $2);
4603 push (@config_names, $one_hdr);
4604 push (@config_headers, $one_hdr . '.in');
4609 # Handle AC_CANONICAL_*. Always allow upgrading to
4610 # AC_CANONICAL_SYSTEM, but never downgrading.
4611 $seen_canonical = $AC_CANONICAL_HOST
4612 if ! $seen_canonical
4613 && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
4614 $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
4616 # If using X, include some extra variable definitions. NOTE
4617 # we don't want to force these into CFLAGS or anything,
4618 # because not all programs will necessarily use X.
4621 foreach my $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS',
4624 $configure_vars{$var} = $filename . ':' . $.
4628 # This macro handles several different things.
4629 if (/$AM_INIT_AUTOMAKE_PATTERN/o)
4631 ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
4632 $package_version_line = $.;
4633 $seen_init_automake = 1;
4638 $configure_vars{'LEX'} = $filename . ':' . $.;
4639 $seen_decl_yytext = 1;
4641 if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.(ac|in)$/)
4643 &am_conf_line_warning ($filename, $., "`AC_DECL_YYTEXT' is covered by `AM_PROG_LEX'");
4645 if (/AC_PROG_LEX/ && $filename =~ /configure\.(ac|in)$/)
4647 &am_conf_line_warning ($filename, $., "automake requires `AM_PROG_LEX', not `AC_PROG_LEX'");
4650 if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
4652 $configure_vars{$1} = $filename . ':' . $.;
4654 if (/$AC_CHECK_PATTERN/o)
4656 $configure_vars{$3} = $filename . ':' . $.;
4658 if (/$AM_MISSING_PATTERN/o
4662 && $1 ne 'AUTOHEADER'
4663 # AM_INIT_AUTOMAKE is AM_MISSING_PROG'ing MAKEINFO. But
4664 # we handle it elsewhere.
4665 && $1 ne 'MAKEINFO')
4667 $configure_vars{$1} = $filename . ':' . $.;
4670 # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
4671 # but later define it elsewhere. This is pretty hacky. We
4672 # also explicitly avoid INSTALL_SCRIPT and some other
4673 # variables because they are defined in header-vars.am.
4675 if (/$AC_SUBST_PATTERN/o
4677 && $1 ne 'INSTALL_SCRIPT'
4678 && $1 ne 'INSTALL_DATA')
4680 $configure_vars{$1} = $filename . ':' . $.;
4683 $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
4684 if (/AM_MAINTAINER_MODE/)
4686 $seen_maint_mode = 1;
4687 $configure_cond{'MAINTAINER_MODE'} = 1;
4690 $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
4692 if (/AM_PATH_PYTHON/)
4694 $seen_pythondir = 1;
4695 $configure_vars{'pythondir'} = $filename . ':' . $.;
4696 $configure_vars{'PYTHON'} = $filename . ':' . $.;
4699 if (/A(C|M)_PROG_LIBTOOL/)
4701 # We're not ready for this yet. People still use a
4702 # libtool with no AC_PROG_LIBTOOL. Once that is the
4703 # dominant version we can reenable this code -- but next
4704 # time by mentioning the macro in %obsolete_macros, both
4705 # here and in aclocal.in.
4707 # if (/AM_PROG_LIBTOOL/)
4709 # &am_conf_line_warning ($filename, $., "`AM_PROG_LIBTOOL' is obsolete, use `AC_PROG_LIBTOOL' instead");
4713 $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
4714 $configure_vars{'RANLIB'} = $filename . ':' . $.;
4715 $configure_vars{'CC'} = $filename . ':' . $.;
4716 # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST. Make sure we
4717 # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
4718 $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
4721 $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
4723 if (/$AM_CONDITIONAL_PATTERN/o)
4725 $configure_cond{$1} = 1;
4728 # Check for Fortran 77 intrinsic and run-time libraries.
4729 if (/AC_F77_LIBRARY_LDFLAGS/)
4731 $configure_vars{'FLIBS'} = $filename . ':' . $.;
4739 # &scan_autoconf_files ()
4740 # -----------------------
4741 # Check whether we use `configure.ac' or `configure.in'.
4742 # Scan it (and possibly `aclocal.m4') for interesting things.
4743 # We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
4744 sub scan_autoconf_files
4746 # Reinitialize libsources here. This isn't really necessary,
4747 # since we currently assume there is only one configure.ac. But
4748 # that won't always be the case.
4751 warn "$me: both `configure.ac' and `configure.in' present:"
4752 . " ignoring `configure.in'\n"
4753 if -f 'configure.ac' && -f 'configure.in';
4754 $configure_ac = 'configure.in'
4755 if -f 'configure.in';
4756 $configure_ac = 'configure.ac'
4757 if -f 'configure.ac';
4758 die "$me: `configure.ac' or `configure.in' is required\n"
4761 &scan_one_autoconf_file ($configure_ac);
4762 &scan_one_autoconf_file ('aclocal.m4')
4765 if (defined $ENV{'amtraces'})
4767 warn '$me: Autoconf traces is an experimental feature';
4768 warn '$me: use at your own risks';
4770 &scan_autoconf_traces ($configure_ac);
4773 # Set input and output files if not specified by user.
4776 @input_files = @make_input_list;
4777 %output_files = %make_list;
4780 @configure_input_files = @make_input_list;
4782 &am_conf_error ("`AM_INIT_AUTOMAKE' must be used")
4783 if ! $seen_init_automake;
4785 # Look for some files we need. Always check for these. This
4786 # check must be done for every run, even those where we are only
4787 # looking at a subdir Makefile. We must set relative_dir so that
4788 # the file-finding machinery works.
4789 # FIXME: Is this broken because it needs dynamic scopes.
4790 # My tests seems to show it's not the case.
4791 $relative_dir = '.';
4792 &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
4793 &am_error ("`install.sh' is an anachronism; use `install-sh' instead")
4794 if -f $config_aux_path[0] . '/install.sh';
4796 &require_config_file ($FOREIGN, 'py-compile')
4799 # Preserve dist_common for later.
4800 $configure_dist_common = variable_value ('DIST_COMMON', 'TRUE');
4803 ################################################################
4805 # Set up for Cygnus mode.
4808 return unless $cygnus_mode;
4810 &set_strictness ('foreign');
4811 $options{'no-installinfo'} = 1;
4812 $options{'no-dependencies'} = 1;
4813 $use_dependencies = 0;
4815 if (! $seen_maint_mode)
4817 &am_conf_error ("`AM_MAINTAINER_MODE' required when --cygnus specified");
4821 # Do any extra checking for GNU standards.
4822 sub check_gnu_standards
4824 if ($relative_dir eq '.')
4826 # In top level (or only) directory.
4827 &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
4828 'AUTHORS', 'ChangeLog');
4831 if ($strictness >= $GNU
4832 && defined $options{'no-installman'})
4834 &am_line_error ('AUTOMAKE_OPTIONS',
4835 "option `no-installman' disallowed by GNU standards");
4838 if ($strictness >= $GNU
4839 && defined $options{'no-installinfo'})
4841 &am_line_error ('AUTOMAKE_OPTIONS',
4842 "option `no-installinfo' disallowed by GNU standards");
4846 # Do any extra checking for GNITS standards.
4847 sub check_gnits_standards
4849 if ($relative_dir eq '.')
4851 # In top level (or only) directory.
4852 &require_file ($GNITS, 'THANKS');
4856 ################################################################
4858 # Functions to handle files of each language.
4860 # Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
4861 # simple formula: Return value is $LANG_SUBDIR if the resulting object
4862 # file should be in a subdir if the source file is, $LANG_PROCESS if
4863 # file is to be dealt with, $LANG_IGNORE otherwise.
4865 # Much of the actual processing is handled in
4866 # handle_single_transform_list. These functions exist so that
4867 # auxiliary information can be recorded for a later cleanup pass.
4868 # Note that the calls to these functions are computed, so don't bother
4869 # searching for their precise names in the source.
4871 # This is just a convenience function that can be used to determine
4872 # when a subdir object should be used.
4875 return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
4878 # Rewrite a single C source file.
4881 my ($directory, $base, $ext) = @_;
4883 if (defined $options{'ansi2knr'} && $base =~ /_$/)
4885 # FIXME: include line number in error.
4886 &am_error ("C source file `$base.c' would be deleted by ansi2knr rules");
4889 my $r = $LANG_PROCESS;
4890 if (defined $options{'subdir-objects'})
4893 $base = $directory . '/' . $base;
4897 # Only give error once.
4899 # FIXME: line number.
4900 &am_error ("C objects in subdir but `AM_PROG_CC_C_O' not in `$configure_ac'");
4903 &require_file ($FOREIGN, 'compile')
4904 if $relative_dir eq '.';
4907 $de_ansi_files{$base} = 1;
4911 # Rewrite a single C++ source file.
4912 sub lang_cxx_rewrite
4914 return &lang_sub_obj;
4917 # Rewrite a single header file.
4918 sub lang_header_rewrite
4920 # Header files are simply ignored.
4921 return $LANG_IGNORE;
4924 # Rewrite a single yacc file.
4925 sub lang_yacc_rewrite
4927 my ($directory, $base, $ext) = @_;
4929 my $r = &lang_c_rewrite ($directory, $base, $ext);
4931 if ($r == $LANG_SUBDIR)
4933 $pfx = $directory . '/';
4935 $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4937 &saw_extension ('c');
4939 &push_dist_common ($pfx . $base . '.' . $ext);
4943 # Rewrite a single yacc++ file.
4944 sub lang_yaccxx_rewrite
4946 my ($directory, $base, $ext) = @_;
4948 my $r = $LANG_PROCESS;
4950 if (defined $options{'subdir-objects'})
4952 $pfx = $directory . '/';
4955 $yacc_sources{$pfx . $base . '.' . $ext} = 1;
4957 &saw_extension ($ext);
4959 &push_dist_common ($pfx . $base . '.' . $ext);
4963 # Rewrite a single lex file.
4964 sub lang_lex_rewrite
4966 my ($directory, $base, $ext) = @_;
4968 my $r = &lang_c_rewrite ($directory, $base, $ext);
4970 if ($r == $LANG_SUBDIR)
4972 $pfx = $directory . '/';
4974 $lex_sources{$pfx . $base . '.' . $ext} = 1;
4976 &saw_extension ('c');
4978 &push_dist_common ($pfx . $base . '.' . $ext);
4982 # Rewrite a single lex++ file.
4983 sub lang_lexxx_rewrite
4985 my ($directory, $base, $ext) = @_;
4987 my $r = $LANG_PROCESS;
4989 if (defined $options{'subdir-objects'})
4991 $pfx = $directory . '/';
4994 $lex_sources{$pfx . $base . '.' . $ext} = 1;
4996 &saw_extension ($ext);
4998 &push_dist_common ($pfx . $base . '.' . $ext);
5002 # Rewrite a single assembly file.
5003 sub lang_asm_rewrite
5005 return &lang_sub_obj;
5008 # Rewrite a single Fortran 77 file.
5009 sub lang_f77_rewrite
5011 return $LANG_PROCESS;
5014 # Rewrite a single preprocessed Fortran 77 file.
5015 sub lang_ppf77_rewrite
5017 return $LANG_PROCESS;
5020 # Rewrite a single ratfor file.
5021 sub lang_ratfor_rewrite
5023 return $LANG_PROCESS;
5026 # Rewrite a single Objective C file.
5027 sub lang_objc_rewrite
5029 return &lang_sub_obj;
5032 # Rewrite a single Java file.
5033 sub lang_java_rewrite
5035 return $LANG_SUBDIR;
5038 # The lang_X_finish functions are called after all source file
5039 # processing is done. Each should handle defining rules for the
5040 # language, etc. A finish function is only called if a source file of
5041 # the appropriate type has been seen.
5045 # Push all libobjs files onto de_ansi_files. We actually only
5046 # push files which exist in the current directory, and which are
5047 # genuine source files.
5048 foreach my $file (keys %libsources)
5050 if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
5052 $de_ansi_files{$1} = 1;
5056 if (defined $options{'ansi2knr'} && keys %de_ansi_files)
5058 # Make all _.c files depend on their corresponding .c files.
5060 foreach my $base (sort keys %de_ansi_files)
5062 # Each _.c file must depend on ansi2knr; otherwise it
5063 # might be used in a parallel build before it is built.
5064 # We need to support files in the srcdir and in the build
5065 # dir (because these files might be auto-generated. But
5066 # we can't use $< -- some makes only define $< during a
5068 $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
5069 . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
5070 . '`if test -f $(srcdir)/' . $base . '.c'
5071 . '; then echo $(srcdir)/' . $base . '.c'
5072 . '; else echo ' . $base . '.c; fi` '
5073 . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
5074 . '| $(ANSI2KNR) > ' . $base . "_.c\n");
5075 push (@objects, $base . '_.$(OBJEXT)');
5076 push (@objects, $base . '_.lo')
5080 # Make all _.o (and _.lo) files depend on ansi2knr.
5081 # Use a sneaky little hack to make it print nicely.
5082 &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
5085 if (! defined $configure_vars{'CC'})
5087 # FIXME: line number.
5088 &am_error ("C source seen but `CC' not defined in `$configure_ac'");
5094 define_linker_variable ($languages{'cxx'});
5096 if (! defined $configure_vars{'CXX'})
5098 &am_error ("C++ source seen but `CXX' not defined in `$configure_ac'");
5102 # This is a helper for both lex and yacc.
5103 sub yacc_lex_finish_helper
5105 return if defined $language_scratch{'lex-yacc-done'};
5106 $language_scratch{'lex-yacc-done'} = 1;
5108 # If there is more than one distinct yacc (resp lex) source file
5109 # in a given directory, then the `ylwrap' program is required to
5110 # allow parallel builds to work correctly. FIXME: for now, no
5112 &require_config_file ($FOREIGN, 'ylwrap');
5113 if ($config_aux_dir ne '.' && $config_aux_dir ne '')
5115 &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
5119 &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
5123 sub lang_yacc_finish
5125 return if defined $language_scratch{'yacc-done'};
5126 $language_scratch{'yacc-done'} = 1;
5128 my %seen_suffix = ();
5129 my @yacc_files = sort keys %yacc_sources;
5130 my $yacc_count = scalar (@yacc_files);
5131 foreach my $file (@yacc_files)
5134 &output_yacc_build_rule ($1, $yacc_count > 1)
5135 if ! defined $seen_suffix{$1};
5136 $seen_suffix{$1} = 1;
5138 $file =~ /^(.*)\.(y|yy|y\+\+|yxx|ypp)$/;
5140 my $hname = 'h'; # Always use `.h' for header file.
5144 if ((&variable_defined ('AM_YFLAGS')
5145 && &variable_value ('AM_YFLAGS') =~ /(^|\s)-d(\s|$)/)
5146 || (&variable_defined ('YFLAGS')
5147 && &variable_value ('YFLAGS') =~ /(^|\s)-d(\s|$)/)) {
5148 # Now generate rule to make the header file. This should only
5149 # be generated if `yacc -d' specified.
5150 $output_rules .= "${base}.${hname}: ${base}.${cname}\n";
5152 # If the files are built in the build directory, then we want
5153 # to remove them with `make clean'. If they are in srcdir
5154 # they shouldn't be touched. However, we can't determine this
5155 # statically, and the GNU rules say that yacc/lex output files
5156 # should be removed by maintainer-clean. So that's what we
5158 push (@maintainer_clean_files, "${base}.${hname}");
5160 &push_dist_common ("${base}.${hname}");
5162 push (@maintainer_clean_files, "${base}.${cname}");
5164 $output_rules .= "\n";
5166 if (! defined $configure_vars{'YACC'})
5168 &am_error ("yacc source seen but `YACC' not defined in `$configure_ac'");
5170 if (&variable_defined ('YACCFLAGS'))
5172 &am_line_error ('YACCFLAGS',
5173 "`YACCFLAGS' obsolete; use `YFLAGS' instead");
5176 if ($yacc_count > 1)
5178 &yacc_lex_finish_helper;
5185 return if defined $language_scratch{'lex-done'};
5186 $language_scratch{'lex-done'} = 1;
5188 my %seen_suffix = ();
5189 my $lex_count = scalar (keys %lex_sources);
5190 foreach my $file (sort keys %lex_sources)
5193 &output_lex_build_rule ($1, $lex_count > 1)
5194 if (! defined $seen_suffix{$1});
5195 $seen_suffix{$1} = 1;
5197 # If the files are built in the build directory, then we want
5198 # to remove them with `make clean'. If they are in srcdir
5199 # they shouldn't be touched. However, we can't determine this
5200 # statically, and the GNU rules say that yacc/lex output files
5201 # should be removed by maintainer-clean. So that's what we
5203 $file =~ /^(.*)\.(l|ll|l\+\+|lxx|lpp)$/;
5205 ($cname = $2) =~ tr/l/c/;
5206 push (@maintainer_clean_files, "${1}.${cname}");
5209 if (! defined $configure_vars{'LEX'})
5211 &am_error ("lex source seen but `LEX' not defined in `$configure_ac'");
5213 if (! $seen_decl_yytext)
5215 &am_error ("lex source seen but `AC_DECL_YYTEXT' not in `$configure_ac'");
5220 &yacc_lex_finish_helper;
5227 # FIXME: this function can be called more than once. We should
5228 # arrange for it to only do anything the first time through.
5230 define_linker_variable ($languages{'f77'});
5232 if (! defined $configure_vars{'F77'})
5234 &am_error ("Fortran 77 source seen but `F77' not defined in `$configure_ac'");
5238 # Preprocessed Fortran 77
5240 # The current support for preprocessing Fortran 77 just involves passing
5241 # `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)' as additional flags
5242 # to the Fortran 77 compiler, since this is how GNU Make does it; see
5243 # the `GNU Make Manual, Edition 0.51 for `make' Version 3.76 Beta'
5244 # (specifically, from info file `(make)Catalogue of Rules').
5246 # A better approach would be to write an Autoconf test
5247 # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
5248 # Fortran 77 compilers know how to do preprocessing. The Autoconf macro
5249 # AC_PROG_FPP should test the Fortran 77 compiler first for
5250 # preprocessing capabilities, and then fall back on cpp (if cpp were
5252 sub lang_ppf77_finish
5256 # We also handle the case of preprocessing `.F' files into `.f'
5258 $output_rules .= (".F.f:\n"
5259 . "\t\$(F77COMPILE) -F \$<\n");
5262 sub lang_ratfor_finish
5266 # We also handle the case of preprocessing `.r' files into `.f'
5268 $output_rules .= (".r.f:\n"
5269 . "\t\$(RCOMPILE) -F \$<\n");
5272 sub lang_objc_finish
5274 define_linker_variable ($languages{'objc'});
5276 if (! defined $configure_vars{'OBJC'})
5278 &am_error ("Objective C source seen but `OBJC' not defined in `$configure_ac'");
5282 sub lang_java_finish
5284 define_linker_variable ($languages{'java'});
5286 if (! defined $configure_vars{'GCJ'})
5288 &am_error ("Java source seen but `GCJ' not defined in `$configure_ac'");
5293 # Given a hash table of linker names, pick the name that has the most
5294 # precedence. This is lame, but something has to have global
5295 # knowledge in order to eliminate the conflict. Add more linkers as
5302 if defined $linkers{'GCJLINK'};
5304 if defined $linkers{'CXXLINK'};
5306 if defined $linkers{'F77LINK'};
5308 if defined $linkers{'OBJCLINK'};
5312 # Called to indicate that an extension was used.
5316 $extension_seen{$ext} = 1;
5319 # Called to ask whether source files have been seen . If HEADERS is 1,
5320 # headers can be included.
5331 $headers = grep ($extension_seen{$_},
5332 @{$languages{'header'}->extensions});
5335 return scalar keys %extension_seen > $headers;
5339 # register_language (%ATTRIBUTE)
5340 # ------------------------------
5341 # Register a single language. LANGUAGE is the name of the language.
5342 # Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
5343 sub register_language ($%)
5349 unless defined $option{'ansi'};
5350 $option{'autodep'} = 'no'
5351 unless defined $option{'autodep'};
5352 $option{'derived_autodep'} = 'no'
5353 unless defined $option{'derived_autodep'};
5354 $option{'linker'} = ''
5355 unless defined $option{'linker'};
5357 my $lang = new Language (%option);
5360 grep ($extension_map{$_} = $lang->name, @{$lang->extensions});
5361 $languages{$lang->name} = $lang;
5364 # This function is used to find a path from a user-specified suffix to
5365 # `o' or to some other suffix we recognize internally, eg `cc'.
5368 my ($source_ext) = @_;
5370 # FIXME: hard-coding `o' is a mistake. Doing something
5371 # intelligent is harder.
5372 while ($extension_map{$source_ext} eq ''
5373 && $source_ext ne 'o'
5374 && defined $suffix_rules{$source_ext})
5376 $source_ext = $suffix_rules{$source_ext};
5383 ################################################################
5385 # Pretty-print something. HEAD is what should be printed at the
5386 # beginning of the first line, FILL is what should be printed at the
5387 # beginning of every subsequent line.
5388 sub pretty_print_internal
5390 my ($head, $fill, @values) = @_;
5392 my $column = length ($head);
5395 # Fill length is number of characters. However, each Tab
5396 # character counts for eight. So we count the number of Tabs and
5398 my $fill_length = length ($fill);
5399 $fill_length += 7 * ($fill =~ tr/\t/\t/d);
5403 # "71" because we also print a space.
5404 if ($column + length ($_) > 71)
5406 $result .= " \\\n" . $fill;
5407 $column = $fill_length;
5409 $result .= ' ' if $result =~ /\S\z/;
5411 $column += length ($_) + 1;
5418 # Pretty-print something and append to output_vars.
5421 $output_vars .= &pretty_print_internal (@_);
5424 # Pretty-print something and append to output_rules.
5425 sub pretty_print_rule
5427 $output_rules .= &pretty_print_internal (@_);
5431 ################################################################
5435 # &conditional_string(@COND-STACK)
5436 # --------------------------------
5438 sub conditional_string
5442 if (grep (/^FALSE$/, @stack))
5448 return join (' ', uniq sort grep (!/^TRUE$/, @stack));
5454 # &conditional_true_when ($COND, $WHEN)
5455 # -------------------------------------
5456 # See if a conditional is true. Both arguments are conditional
5457 # strings. This returns true if the first conditional is true when
5458 # the second conditional is true.
5459 # For instance with $COND = `BAR FOO', and $WHEN = `BAR BAZ FOO',
5460 # obviously return 1, and 0 when, for instance, $WHEN = `FOO'.
5461 sub conditional_true_when ($$)
5463 my ($cond, $when) = @_;
5465 # Make a hash holding all the values from $WHEN.
5466 my %cond_vals = map { $_ => 1 } split (' ', $when);
5468 # Check each component of $cond, which looks `COND1 COND2'.
5469 foreach my $comp (split (' ', $cond))
5471 # TRUE is always true.
5472 return 1 if $comp eq 'TRUE';
5473 return 0 if ! defined $cond_vals{$comp};
5481 # &conditionals_true_when (@CONDS, @WHENS)
5482 # ----------------------------------------
5483 # Same as above, but true if all the @CONDS are true when *ALL*
5484 # the @WHENS are sufficient.
5486 # If there are no @CONDS, then return true, of course. *BUT*, even if there
5487 # are @CONDS but @WHENS is empty, return true. This is counter intuitive,
5488 # and against all the rules of logic, but is needed by the current code.
5489 # FIXME: Do something saner when the logic of conditionals is understood.
5490 sub conditionals_true_when (@@)
5492 my (@conds, @whens) = @_;
5494 foreach my $cond (@conds)
5496 foreach my $when (@whens)
5499 unless conditional_true_when ($cond, $when);
5508 # condition_negate ($COND)
5509 # ------------------------
5510 sub condition_negate ($)
5514 $cond =~ s/TRUE$/TRUEO/;
5515 $cond =~ s/FALSE$/TRUE/;
5516 $cond =~ s/TRUEO$/FALSE/;
5522 # Compare condition names.
5523 # Issue them in alphabetical order, foo_TRUE before foo_FALSE.
5526 # Be careful we might be comparing `' or `#'.
5527 $a =~ /^(.*)_(TRUE|FALSE)$/;
5528 my ($aname, $abool) = ($1 || '', $2 || '');
5529 $b =~ /^(.*)_(TRUE|FALSE)$/;
5530 my ($bname, $bbool) = ($1 || '', $2 || '');
5531 return ($aname cmp $bname
5532 # Don't bother with IFs, given that TRUE is after FALSE
5533 # just cmp in the reverse order.
5534 || $bbool cmp $abool
5540 # &make_condition (@CONDITIONS)
5541 # -----------------------------
5542 # Transform a list of conditions (themselves can be an internal list
5543 # of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
5544 # Make conditional (a pattern for AC_SUBST).
5545 # Correctly returns the empty string when there are no conditions.
5548 my $res = conditional_string (@_);
5550 # There are no conditions.
5556 elsif ($res eq 'FALSE')
5563 $res = '@' . $res . '@';
5572 ## ------------------------------ ##
5573 ## Handling the condition stack. ##
5574 ## ------------------------------ ##
5578 # cond_stack_if ($NEGATE, $COND, $WHERE)
5579 # --------------------------------------
5580 sub cond_stack_if ($$$)
5582 my ($negate, $cond, $where) = @_;
5584 &am_file_error ($where, "$cond does not appear in AM_CONDITIONAL")
5585 if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
5587 $cond = "${cond}_TRUE"
5588 unless $cond =~ /^TRUE|FALSE$/;
5589 $cond = condition_negate ($cond)
5592 push (@cond_stack, $cond);
5594 return conditional_string (@cond_stack);
5599 # cond_stack_else ($NEGATE, $COND, $WHERE)
5600 # ----------------------------------------
5601 sub cond_stack_else ($$$)
5603 my ($negate, $cond, $where) = @_;
5607 &am_file_error ($where, "else without if");
5611 $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);
5613 # If $COND is given, check against it.
5616 $cond = "${cond}_TRUE"
5617 unless $cond =~ /^TRUE|FALSE$/;
5618 $cond = condition_negate ($cond)
5621 &am_file_error ($where,
5622 "else reminder ($negate$cond) incompatible with "
5623 . "current conditional: $cond_stack[$#cond_stack]")
5624 if $cond_stack[$#cond_stack] ne $cond;
5627 return conditional_string (@cond_stack);
5632 # cond_stack_endif ($NEGATE, $COND, $WHERE)
5633 # -----------------------------------------
5634 sub cond_stack_endif ($$$)
5636 my ($negate, $cond, $where) = @_;
5641 &am_file_error ($where, "endif without if");
5646 # If $COND is given, check against it.
5649 $cond = "${cond}_TRUE"
5650 unless $cond =~ /^TRUE|FALSE$/;
5651 $cond = condition_negate ($cond)
5654 &am_file_error ($where,
5655 "endif reminder ($negate$cond) incompatible with "
5656 . "current conditional: $cond_stack[$#cond_stack]")
5657 if $cond_stack[$#cond_stack] ne $cond;
5662 return conditional_string (@cond_stack);
5669 ## ------------------------ ##
5670 ## Handling the variables. ##
5671 ## ------------------------ ##
5674 # check_ambiguous_conditional ($VAR, $COND)
5675 # -----------------------------------------
5676 # Check for an ambiguous conditional. This is called when a variable
5677 # is being defined conditionally. If we already know about a
5678 # definition that is true under the same conditions, then we have an
5680 sub check_ambiguous_conditional ($$)
5682 my ($var, $cond) = @_;
5683 foreach my $vcond (keys %{$var_value{$var}})
5686 if ($vcond eq $cond)
5688 $message = "$var multiply defined in condition $cond";
5690 elsif (&conditional_true_when ($vcond, $cond))
5692 $message = ("$var was already defined in condition $vcond, "
5693 . "which implies condition $cond");
5695 elsif (&conditional_true_when ($cond, $vcond))
5697 $message = ("$var was already defined in condition $vcond, "
5698 . "which is implied by condition $cond");
5702 &am_line_error ($var, $message);
5709 # ¯o_define($VAR, $VAR_IS_AM, $TYPE, $COND, $VALUE, $WHERE)
5710 # -------------------------------------------------------------
5711 # The $VAR can go from Automake to user, but not the converse.
5712 sub macro_define ($$$$$$)
5714 my ($var, $var_is_am, $type, $cond, $value, $where) = @_;
5718 # An Automake variable must be consistently defined with the same
5719 # sign by Automake. A user variable must be set by either `=' or
5720 # `:=', and later promoted to `+='.
5723 if (defined $var_type{$var} && $var_type{$var} ne $type)
5725 am_line_error ($var,
5726 ("$var was set with `$var_type{$var}=' "
5727 . "and is now set with `$type='"));
5732 if (!defined $var_type{$var} && $type eq '+')
5734 am_line_error ($var, "$var must be set with `=' before using `+='");
5737 $var_type{$var} = $type;
5739 # Differentiate the first assignment (including with `+=').
5740 if ($type eq '+' && defined $var_value{$var}{$cond})
5742 if (substr ($var_value{$var}{$cond}, -1) eq "\n")
5744 # Insert a backslash before a trailing newline.
5745 $var_value{$var}{$cond} =
5746 substr ($var_value{$var}{$cond}, 0, -1) . "\\\n";
5748 elsif ($var_value{$var}{$cond})
5750 # Insert a separator.
5751 $var_value{$var}{$cond} .= ' ';
5753 $var_value{$var}{$cond} .= $value;
5757 # The first assignment to a macro sets the line number. Ideally I
5758 # suppose we would associate line numbers with random bits of text.
5759 # FIXME: We sometimes redefine some variables, but we want to keep
5760 # the original location. More subs are needed to handle
5761 # properly variables. Once this done, remove this hack.
5762 $var_line{$var} = $where
5763 unless defined $var_line{$var};
5765 # If Automake tries to override a value specified by the user,
5766 # just don't let it do.
5767 if (defined $var_value{$var}{$cond} && !$var_is_am{$var} && $var_is_am)
5771 print STDERR "$me: refusing to override the user definition of:\n";
5772 variable_dump ($var);
5773 print STDERR "$me: with `$cond' => `$value'\n";
5778 # There must be no previous value unless the user is redefining
5779 # an Automake variable or an AC_SUBST variable.
5780 check_ambiguous_conditional ($var, $cond)
5781 unless ($var_is_am{$var} && !$var_is_am
5782 || exists $configure_vars{$var});
5784 $var_value{$var}{$cond} = $value;
5788 # An Automake variable can be given to the user, but not the converse.
5789 if (! defined $var_is_am{$var} || !$var_is_am)
5791 $var_is_am{$var} = $var_is_am;
5796 # &variable_delete ($VAR, [@CONDS])
5797 # ---------------------------------
5798 # Forget about $VAR under the conditions @CONDS, or completely if
5800 sub variable_delete ($@)
5802 my ($var, @conds) = @_;
5806 delete $var_value{$var};
5807 delete $var_line{$var};
5808 delete $var_is_am{$var};
5809 delete $var_comment{$var};
5810 delete $var_type{$var};
5814 foreach my $cond (@conds)
5816 delete $var_value{$var}{$cond};
5822 # ¯o_dump ($VAR)
5823 # ------------------
5828 if (!exists $var_value{$var})
5830 print STDERR " $var does not exist\n";
5834 my $var_is_am = $var_is_am{$var} ? "Automake" : "User";
5835 my $where = (defined $var_line{$var}
5836 ? $var_line{$var} : "undefined");
5837 print STDERR "$var_comment{$var}"
5838 if defined $var_comment{$var};
5839 print STDERR " $var ($var_is_am, where = $where) $var_type{$var}=\n";
5840 print STDERR " {\n";
5841 foreach my $vcond (sort by_condition keys %{$var_value{$var}})
5843 print STDERR " $vcond => $var_value{$var}{$vcond}\n";
5845 print STDERR " }\n";
5856 print STDERR "%var_value =\n";
5858 foreach my $var (sort (keys %var_value))
5867 # &variable_defined ($VAR, [$COND])
5868 # ---------------------------------
5869 # See if a variable exists. $VAR is the variable name, and $COND is
5870 # the condition which we should check. If no condition is given, we
5871 # currently return true if the variable is defined under any
5873 sub variable_defined ($$)
5875 my ($var, $cond) = @_;
5877 # Unfortunately we can't just check for $var_value{VAR}{COND}
5878 # as this would make perl create $condition{VAR}, which we
5880 if (!exists $var_value{$var})
5882 if (defined $targets{$var})
5884 &am_line_error ($var, "`$var' is a target; expected a variable")
5886 # The variable is not defined
5890 if ($cond && !exists $var_value{$var}{$cond})
5892 # The variable is not defined for the given condition.
5896 # Even a var_value examination is good enough for us. FIXME:
5897 # really should maintain examined status on a per-condition basis.
5898 $content_seen{$var} = 1;
5902 # Mark a variable as examined.
5903 sub examine_variable
5906 &variable_defined ($var);
5909 # Return the set of conditions for which a variable is defined.
5911 # If the variable is not defined conditionally, and is not defined in
5912 # terms of any variables which are defined conditionally, then this
5913 # returns the empty list.
5915 # If the variable is defined conditionally, but is not defined in
5916 # terms of any variables which are defined conditionally, then this
5917 # returns the list of conditions for which the variable is defined.
5919 # If the variable is defined in terms of any variables which are
5920 # defined conditionally, then this returns a full set of permutations
5921 # of the subvariable conditions. For example, if the variable is
5922 # defined in terms of a variable which is defined for COND_TRUE,
5923 # then this returns both COND_TRUE and COND_FALSE. This is
5924 # because we will need to define the variable under both conditions.
5926 sub variable_conditions ($)
5933 foreach my $cond (&variable_conditions_sub ($var, '', ()))
5936 if $cond eq 'FALSE';
5937 $uniqify{$cond} = 1;
5940 @uniq_list = sort by_condition keys %uniqify;
5941 # Note we cannot just do `return sort keys %uniqify', because this
5942 # function is sometimes used in a scalar context.
5948 # &variable_conditionally_defined ($VAR)
5949 # --------------------------------------
5950 sub variable_conditionally_defined ($)
5953 foreach my $cond (variable_conditions ($var))
5956 unless $cond =~ /^TRUE|FALSE$/;
5963 # &variable_conditions_sub ($VAR, $PARENT, @PARENT_CONDS)
5964 # -------------------------------------------------------
5965 # A subroutine of variable_conditions. We only return conditions
5966 # which are true for all the conditions in @PARENT_CONDS.
5967 sub variable_conditions_sub
5969 my ($var, $parent, @parent_conds) = @_;
5972 if (defined $vars_scanned{$var})
5974 &am_line_error ($parent, "variable `$var' recursively defined");
5977 $vars_scanned{$var} = 1;
5979 my @this_conds = ();
5980 foreach my $vcond (keys %{$var_value{$var}})
5983 if ! conditionals_true_when ((@parent_conds), ($vcond));
5985 push (@this_conds, $vcond);
5987 push (@parent_conds, $vcond);
5988 my @subvar_conds = ();
5989 foreach (split (' ', $var_value{$var}{$vcond}))
5991 # If a comment seen, just leave.
5994 # Handle variable substitutions.
5995 if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
5997 push (@subvar_conds,
5998 &variable_conditions_sub ($1, $var, @parent_conds));
6001 pop (@parent_conds);
6003 # If there are no conditional subvariables, then we want to
6004 # return this condition. Otherwise, we want to return the
6005 # permutations of the subvariables.
6006 if (! @subvar_conds)
6008 push (@new_conds, $vcond);
6012 push (@new_conds, &variable_conditions_reduce (@subvar_conds));
6016 # Unset our entry in vars_scanned. We only care about recursive
6018 delete $vars_scanned{$var};
6020 # If there are no parents, then this call is the top level call.
6023 # Now we want to return all permutations of the subvariable
6026 foreach my $item (@new_conds)
6028 foreach (split (' ', $item))
6030 s/^(.*)_(TRUE|FALSE)$/$1_TRUE/;
6034 return &variable_conditions_permutations (sort keys %allconds);
6037 # If we are being called on behalf of another variable, we need to
6038 # return all possible permutations of the conditions. We have
6039 # already handled everything in @this_conds along with their
6040 # subvariables. We now need to add any permutations that are not
6042 foreach my $this_cond (@this_conds)
6045 &variable_conditions_permutations (split(' ', $this_cond));
6046 foreach my $perm (@perms)
6049 foreach my $scan (@this_conds)
6051 if (&conditional_true_when ($perm, $scan)
6052 || &conditional_true_when ($scan, $perm))
6061 if ! conditionals_true_when ((@parent_conds), ($perm));
6063 # This permutation was not already handled, and is valid
6065 push (@new_conds, $perm);
6073 # Filter a list of conditionals so that only the exclusive ones are
6074 # retained. For example, if both `COND1_TRUE COND2_TRUE' and
6075 # `COND1_TRUE' are in the list, discard the latter.
6076 sub variable_conditions_reduce
6080 foreach my $cond (@conds)
6082 # FALSE is absorbent.
6083 if ($cond eq 'FALSE')
6087 elsif (conditionals_true_when (($cond), (@ret)))
6096 # Return a list of permutations of a conditional string.
6097 sub variable_conditions_permutations
6102 my $comp = shift (@comps);
6103 return &variable_conditions_permutations (@comps)
6105 my $neg = condition_negate ($comp);
6108 foreach my $sub (&variable_conditions_permutations (@comps))
6110 push (@ret, "$comp $sub");
6111 push (@ret, "$neg $sub");
6123 # &check_variable_defined_unconditionally($VAR, $PARENT)
6124 # ------------------------------------------------------
6125 # Warn if a variable is conditionally defined. This is called if we
6126 # are using the value of a variable.
6127 sub check_variable_defined_unconditionally ($$)
6129 my ($var, $parent) = @_;
6130 foreach my $cond (keys %{$var_value{$var}})
6133 if $cond =~ /^TRUE|FALSE$/;
6137 &am_line_error ($parent,
6138 "warning: automake does not support conditional definition of $var in $parent");
6142 &am_line_error ($parent,
6143 "warning: automake does not support $var being defined conditionally");
6151 # Get the TRUE value of a variable, warn if the variable is
6152 # conditionally defined.
6156 &check_variable_defined_unconditionally ($var);
6157 return $var_value{$var}{'TRUE'};
6162 # &value_to_list ($VAR, $VAL, $COND)
6163 # ----------------------------------
6164 # Convert a variable value to a list, split as whitespace. This will
6165 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6168 # If COND is 'all', then all values under all conditions should be
6169 # returned; if COND is a particular condition (all conditions are
6170 # surrounded by @...@) then only the value for that condition should
6171 # be returned; otherwise, warn if VAR is conditionally defined.
6172 # SCANNED is a global hash listing whose keys are all the variables
6173 # already scanned; it is an error to rescan a variable.
6176 my ($var, $val, $cond) = @_;
6180 $val =~ s/\\(\n|$)/ /g;
6182 foreach (split (' ', $val))
6184 # If a comment seen, just leave.
6187 # Handle variable substitutions.
6188 if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
6192 # If the user uses a losing variable name, just ignore it.
6193 # This isn't ideal, but people have requested it.
6194 next if ($varname =~ /\@.*\@/);
6198 if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
6202 ($from = $2) =~ s/(\W)/\\$1/g;
6206 @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
6208 # Now rewrite the value if appropriate.
6211 grep (s/$from$/$to/, @temp_list);
6214 push (@result, @temp_list);
6225 # Return contents of variable as list, split as whitespace. This will
6226 # recursively follow $(...) and ${...} inclusions. It preserves @...@
6227 # substitutions. If COND is 'all', then all values under all
6228 # conditions should be returned; if COND is a particular condition
6229 # (all conditions are surrounded by @...@) then only the value for
6230 # that condition should be returned; otherwise, warn if VAR is
6231 # conditionally defined. If PARENT is specified, it is the name of
6232 # the including variable; this is only used for error reports.
6233 sub variable_value_as_list_worker
6235 my ($var, $cond, $parent) = @_;
6238 if (! defined $var_value{$var})
6240 if (defined $targets{$var})
6242 &am_line_error ($var, "`$var' is a target; expected a variable");
6246 &am_line_error ($parent, "variable `$var' not defined");
6249 elsif (defined $vars_scanned{$var})
6251 # `vars_scanned' is a global we use to keep track of which
6252 # variables we've already examined.
6253 &am_line_error ($parent, "variable `$var' recursively defined");
6255 elsif ($cond eq 'all')
6257 $vars_scanned{$var} = 1;
6258 foreach my $vcond (keys %{$var_value{$var}})
6260 my $val = $var_value{$var}{$vcond};
6261 push (@result, &value_to_list ($var, $val, $cond));
6267 $vars_scanned{$var} = 1;
6269 foreach my $vcond (keys %{$var_value{$var}})
6271 my $val = $var_value{$var}{$vcond};
6272 if (&conditional_true_when ($vcond, $cond))
6274 # Warn if we have an ambiguity. It's hard to know how
6275 # to handle this case correctly.
6276 &check_variable_defined_unconditionally ($var, $parent)
6279 push (@result, &value_to_list ($var, $val, $cond));
6284 # Unset our entry in vars_scanned. We only care about recursive
6286 delete $vars_scanned{$var};
6292 # &variable_output ($VAR, [@CONDS])
6293 # ---------------------------------
6294 # Output all the values of $VAR is @COND is not specified, else only
6295 # that corresponding to @COND.
6296 sub variable_output ($@)
6298 my ($var, @conds) = @_;
6300 @conds = sort by_condition keys %{$var_value{$var}}
6303 $output_vars .= $var_comment{$var}
6304 if defined $var_comment{$var};
6306 foreach my $cond (@conds)
6308 my $val = $var_value{$var}{$cond};
6309 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6310 my $output_var = "$var $equals $val";
6311 $output_var =~ s/^/&make_condition ($cond)/meg;
6312 $output_vars .= $output_var . "\n";
6317 # &variable_pretty_output ($VAR, [@CONDS])
6318 # ----------------------------------------
6319 # Likewise, but pretty, i.e., we *split* the values at spaces. Use only
6320 # with variables holding filenames.
6321 sub variable_pretty_output ($@)
6323 my ($var, @conds) = @_;
6325 @conds = sort by_condition keys %{$var_value{$var}}
6328 $output_vars .= $var_comment{$var}
6329 if defined $var_comment{$var};
6331 foreach my $cond (@conds)
6333 my $val = $var_value{$var}{$cond};
6334 my $equals = $var_type{$var} eq ':' ? ':=' : '=';
6335 my $make_condition = make_condition ($cond);
6336 $output_vars .= pretty_print_internal ("$make_condition$var $equals",
6337 "$make_condition\t",
6338 split (' ' , $val));
6343 # This is just a wrapper for variable_value_as_list_worker that
6344 # initializes the global hash `vars_scanned'. This hash is used to
6345 # avoid infinite recursion.
6346 sub variable_value_as_list
6348 my ($var, $cond, $parent) = @_;
6350 return &variable_value_as_list_worker ($var, $cond, $parent);
6354 # Like define_variable, but the value is a list, and the variable may
6355 # be defined conditionally. The second argument is the conditional
6356 # under which the value should be defined; this should be the empty
6357 # string to define the variable unconditionally. The third argument
6358 # is a list holding the values to use for the variable. The value is
6359 # pretty printed in the output file.
6360 sub define_pretty_variable
6362 my ($var, $cond, @value) = @_;
6364 # Beware that an empty $cond has a different semantics for
6365 # macro_define and variable_pretty_output.
6368 if (! &variable_defined ($var, $cond))
6370 macro_define ($var, 1, '', $cond, join (' ', @value), undef);
6371 variable_pretty_output ($var, $cond || 'TRUE');
6372 $content_seen{$var} = 1;
6377 # define_variable ($VAR, $VALUE)
6378 # ------------------------------
6379 # Define a new user variable VAR to VALUE, but only if not already defined.
6382 my ($var, $value) = @_;
6384 define_pretty_variable ($var, 'TRUE', $value);
6388 # Like define_variable, but define a variable to be the configure
6389 # substitution by the same name.
6390 sub define_configure_variable
6393 my $value = '@' . $var . '@';
6394 &define_variable ($var, $value);
6398 # define_compiler_variable ($LANG)
6399 # --------------------------------
6400 # Define a compiler variable. We also handle defining the `LT'
6401 # version of the command when using libtool.
6402 sub define_compiler_variable ($)
6406 my ($var, $value) = ($lang->compiler, $lang->compile);
6407 &define_variable ($var, $value);
6408 &define_variable ("LT$var", "$(LIBTOOL) --mode=compile $value")
6413 # define_linker_variable ($LANG)
6414 # ------------------------------
6415 # Define linker variables.
6416 sub define_linker_variable ($)
6420 my ($var, $value) = ($lang->lder, $lang->ld);
6422 &define_variable ($lang->lder, $lang->ld);
6423 # CCLINK = $(CCLD) blah blah...
6424 &define_variable ($lang->linker,
6425 (($seen_libtool ? '$(LIBTOOL) --mode=link ' : '')
6429 ################################################################
6431 ## ---------------- ##
6432 ## Handling rules. ##
6433 ## ---------------- ##
6435 sub rule_define ($$$$)
6437 my ($target, $rule_is_am, $cond, $where) = @_;
6439 if (defined $targets{$target}
6441 ? ! defined $target_conditional{$target}
6442 : defined $target_conditional{$target}))
6444 &am_line_error ($target,
6445 "$target defined both conditionally and unconditionally");
6448 # Value here doesn't matter; for targets we only note existence.
6449 $targets{$target} = $where;
6452 if ($target_conditional{$target})
6454 &check_ambiguous_conditional ($target, $cond);
6456 $target_conditional{$target}{$cond} = $where;
6460 # Check the rule for being a suffix rule. If so, store in a hash.
6462 if ((my ($source_suffix, $object_suffix)) = ($1 =~ $SUFFIX_RULE_PATTERN))
6464 $suffix_rules{$source_suffix} = $object_suffix;
6465 print "Sources ending in .$source_suffix become .$object_suffix\n"
6467 # Set SUFFIXES from suffix_rules.
6468 push @suffixes, ".$source_suffix", ".$object_suffix";
6473 # See if a target exists.
6477 return defined $targets{$target};
6481 ################################################################
6483 # Read Makefile.am and set up %contents. Simultaneously copy lines
6484 # from Makefile.am into $output_trailer or $output_vars as
6485 # appropriate. NOTE we put rules in the trailer section. We want
6486 # user rules to come after our generated stuff.
6491 my $am_file = new IO::File ("< $amfile");
6494 die "$me: couldn't open `$amfile': $!\n";
6496 print "$me: reading $amfile\n" if $verbose;
6502 while ($_ = $am_file->getline)
6504 if (/$IGNORE_PATTERN/o)
6506 # Merely delete comments beginning with two hashes.
6508 elsif (/$WHITE_PATTERN/o)
6510 # Stick a single white line before the incoming macro or rule.
6514 elsif (/$COMMENT_PATTERN/o)
6516 # Stick comments before the incoming macro or rule. Make
6517 # sure a blank line preceeds first block of comments.
6518 $spacing = "\n" unless $blank;
6520 $comment .= $spacing . $_;
6529 $output_vars .= $comment . "\n";
6533 # We save the conditional stack on entry, and then check to make
6534 # sure it is the same on exit. This lets us conditonally include
6536 my @saved_cond_stack = @cond_stack;
6537 my $cond = conditional_string (@cond_stack);
6542 my $last_var_name = '';
6543 my $last_var_type = '';
6544 my $last_var_value = '';
6548 unless substr ($_, -1, 1) eq "\n";
6550 # Don't look at MAINTAINER_MODE_TRUE here. That shouldn't be
6551 # used by users. @MAINT@ is an anachronism now.
6552 $_ =~ s/\@MAINT\@//g
6553 unless $seen_maint_mode;
6555 if (/$IGNORE_PATTERN/o)
6557 # Merely delete comments beginning with two hashes.
6559 elsif (/$WHITE_PATTERN/o)
6561 # Stick a single white line before the incoming macro or rule.
6563 &am_line_error ($., "blank line following trailing backslash")
6566 elsif (/$COMMENT_PATTERN/o)
6568 # Stick comments before the incoming macro or rule.
6569 $comment .= $spacing . $_;
6571 &am_line_error ($., "comment following trailing backslash")
6578 $output_trailer .= &make_condition (@cond_stack);
6579 $output_trailer .= $_;
6583 $last_var_value .= ' '
6584 unless $last_var_value =~ /\s$/;
6585 $last_var_value .= $_;
6589 $var_comment{$last_var_name} .= "$spacing"
6590 if (!defined $var_comment{$last_var_name}
6591 || substr ($var_comment{$last_var_name}, -1) ne "\n");
6592 $var_comment{$last_var_name} .= "$comment";
6593 $comment = $spacing = '';
6594 macro_define ($last_var_name, 0,
6595 $last_var_type, $cond,
6596 $last_var_value, $.)
6597 if $cond ne 'FALSE';
6598 push (@var_list, $last_var_name);
6603 elsif (/$IF_PATTERN/o)
6605 $cond = cond_stack_if ($1, $2, "$amfile:$.");
6607 elsif (/$ELSE_PATTERN/o)
6609 $cond = cond_stack_else ($1, $2, "$amfile:$.");
6611 elsif (/$ENDIF_PATTERN/o)
6613 $cond = cond_stack_endif ($1, $2, "$amfile:$.");
6616 elsif (/$RULE_PATTERN/o)
6621 rule_define ($1, 0, $cond, $.);
6624 $output_trailer .= $comment . $spacing;
6625 $output_trailer .= &make_condition (@cond_stack);
6626 $output_trailer .= $_;
6627 $comment = $spacing = '';
6629 elsif (($is_ok_macro = /$MACRO_PATTERN/o)
6630 || /$BOGUS_MACRO_PATTERN/o)
6633 &am_line_error ($., "bad macro name `$last_var_name'")
6636 # Found a macro definition.
6638 $last_var_name = $1;
6639 $last_var_type = $2;
6640 $last_var_value = $3;
6641 if ($3 ne '' && substr ($3, -1) eq "\\")
6643 # We preserve the `\' because otherwise the long lines
6644 # that are generated will be truncated by broken
6646 $last_var_value = $3 . "\n";
6651 # FIXME: this doesn't always work correctly; it will
6652 # group all comments for a given variable, no matter
6654 # Accumulating variables must not be output.
6655 $var_comment{$last_var_name} .= "$spacing"
6656 if (!defined $var_comment{$last_var_name}
6657 || substr ($var_comment{$last_var_name}, -1) ne "\n");
6658 $var_comment{$last_var_name} .= "$comment";
6659 $comment = $spacing = '';
6661 macro_define ($last_var_name, 0,
6662 $last_var_type, $cond,
6663 $last_var_value, $.)
6664 if $cond ne 'FALSE';
6665 push (@var_list, $last_var_name);
6668 elsif (/$INCLUDE_PATTERN/o)
6672 if ($path =~ s/^\$\(top_srcdir\)\///)
6674 push (@include_stack, "\$\(top_srcdir\)/$path");
6678 $path =~ s/\$\(srcdir\)\///;
6679 push (@include_stack, "\$\(srcdir\)/$path");
6680 $path = $relative_dir . "/" . $path;
6682 &read_am_file ($path);
6686 # This isn't an error; it is probably a continued rule.
6687 # In fact, this is what we assume.
6689 $output_trailer .= $comment . $spacing;
6690 $output_trailer .= &make_condition (@cond_stack);
6691 $output_trailer .= $_;
6692 $comment = $spacing = '';
6696 $_ = $am_file->getline;
6699 $output_trailer .= $comment;
6701 if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
6705 &am_error ("unterminated conditionals: @cond_stack");
6709 # FIXME: better error message here.
6710 &am_error ("conditionals not nested in include file");
6716 # define_standard_variables ()
6717 # ----------------------------
6718 # A helper for read_main_am_file which initializes configure variables
6719 # and variables from header-vars.am. This is a subr so we can call it
6721 sub define_standard_variables
6723 my $saved_output_vars = $output_vars;
6724 my ($comments, $variables, $rules) =
6725 &file_contents_internal (1, "$am_dir/header-vars.am",
6726 ('BUILD' => $seen_canonical == $AC_CANONICAL_SYSTEM,
6727 'HOST' => $seen_canonical,
6728 'TARGET' => $seen_canonical == $AC_CANONICAL_SYSTEM,
6729 'top_builddir' => backname ($relative_dir)));
6731 # This will output the definitions in $output_vars, which we don't
6733 foreach my $var (sort keys %configure_vars)
6735 &define_configure_variable ($var);
6736 push (@var_list, $var);
6739 # ... hence, we restore $output_vars.
6740 $output_vars = $saved_output_vars . $comments . $rules;
6743 # Read main am file.
6744 sub read_main_am_file
6748 # This supports the strange variable tricks we are about to play.
6749 if (scalar keys %var_value > 0)
6752 &prog_error ("variable defined before read_main_am_file");
6755 # Generate copyright header for generated Makefile.in.
6756 # We do discard the output of predefined variables, handled below.
6757 $output_vars = ("# $in_file_name generated automatically by automake "
6758 . $VERSION . " from $am_file_name.\n");
6759 $output_vars .= $gen_copyright;
6761 # We want to predefine as many variables as possible. This lets
6762 # the user set them with `+=' in Makefile.am. However, we don't
6763 # want these initial definitions to end up in the output quite
6764 # yet. So we just load them, but output them later.
6765 &define_standard_variables;
6767 # Read user file, which might override some of our values.
6768 &read_am_file ($amfile);
6770 # Ouput all the Automake variables. If the user changed one, then
6771 # it is now marked as owned by the user.
6772 foreach my $var (uniq @var_list)
6774 # Don't process user variables.
6775 variable_output ($var)
6776 unless !$var_is_am{$var};
6779 # Now dump the user variables that were defined. We do it in the same
6780 # order in which they were defined (skipping duplicates).
6781 foreach my $var (uniq @var_list)
6783 # Don't process Automake variables.
6784 variable_output ($var)
6785 unless $var_is_am{$var};
6789 ################################################################
6792 # &flatten ($STRING)
6793 # ------------------
6794 # Flatten the $STRING and return the result.
6809 # &make_paragraphs ($MAKEFILE, [%TRANSFORM])
6810 # ------------------------------------------
6811 # Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
6813 sub make_paragraphs ($%)
6815 my ($file, %transform) = @_;
6817 # Complete %transform with global options and make it a Perl
6820 # We don't use IGNORE_PATTERN because it contains $ which
6821 # prevents us from matching the end of line.
6822 "s/##([^#\n].*)?\\n//gmo;"
6823 . &transform (%transform,
6825 'CYGNUS' => $cygnus_mode,
6827 => $seen_maint_mode ? '@MAINTAINER_MODE_TRUE@' : '',
6829 'SHAR' => $options{'dist-shar'} || 0,
6830 'BZIP2' => $options{'dist-bzip2'} || 0,
6831 'ZIP' => $options{'dist-zip'} || 0,
6832 'COMPRESS' => $options{'dist-tarZ'} || 0,
6834 'INSTALL-INFO' => !$options{'no-installinfo'},
6835 'INSTALL-MAN' => !$options{'no-installman'},
6836 'CK-NEWS' => $options{'check-news'} || 0,
6838 'SUBDIRS' => &variable_defined ('SUBDIRS'),
6839 'TOPDIR' => backname ($relative_dir),
6840 'TOPDIR_P' => $relative_dir eq '.',
6841 'CONFIGURE-AC' => $configure_ac,
6843 'LIBTOOL' => defined $configure_vars{'LIBTOOL'})
6844 # We don't need more than two consecutive new-lines.
6845 . 's/\n{3,}/\n\n/g';
6847 # Swallow the file and apply the COMMAND.
6848 my $fc_file = new IO::File ("< $file");
6851 die "$me: installation error: cannot open `$file'\n";
6854 print "$me: reading $file\n"
6856 my $saved_dollar_slash = $/;
6858 $_ = $fc_file->getline;
6859 $/ = $saved_dollar_slash;
6864 # A rule has three parts: a list of targets, a list of dependencies,
6865 # and optionally actions.
6867 "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
6870 # Split at unescaped new lines.
6871 my @lines = split (/(?<!\\)\n/, $content);
6874 while (defined ($_ = shift @lines))
6876 my $paragraph = "$_";
6877 # If we are a rule, eat as long as we start with a tab.
6878 if (/$RULE_PATTERN/smo)
6880 while (defined ($_ = shift @lines) && $_ =~ /^\t/)
6882 $paragraph .= "\n$_";
6884 unshift (@lines, $_);
6887 # If we are a comments, eat as much comments as you can.
6888 elsif (/$COMMENT_PATTERN/smo)
6890 while (defined ($_ = shift @lines)
6891 && $_ =~ /$COMMENT_PATTERN/smo)
6893 $paragraph .= "\n$_";
6895 unshift (@lines, $_);
6898 push @res, $paragraph;
6907 # ($COMMENT, $VARIABLES, $RULES)
6908 # &file_contents_internal ($IS_AM, $FILE, [%TRANSFORM])
6909 # -----------------------------------------------------
6910 # Return contents of a file from $am_dir, automatically skipping
6911 # macros or rules which are already known. $IS_AM iff the caller is
6912 # reading an Automake file (as opposed to the user's Makefile.am).
6913 sub file_contents_internal ($%)
6915 my ($is_am, $file, %transform) = @_;
6917 # A rule has three parts: a list of targets, a list of dependencies,
6918 # and optionally actions.
6920 "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";
6922 my $result_vars = '';
6923 my $result_rules = '';
6927 # We save the conditional stack on entry, and then check to make
6928 # sure it is the same on exit. This lets us conditonally include
6930 my @saved_cond_stack = @cond_stack;
6931 my $cond = conditional_string (@cond_stack);
6933 foreach (make_paragraphs ($file, %transform))
6936 &am_file_error ($file, "blank line following trailing backslash:\n$_")
6938 &am_file_error ($file, "comment following trailing backslash:\n$_")
6943 # Stick empty line before the incoming macro or rule.
6946 elsif (/$COMMENT_PATTERN/mso)
6948 # Stick comments before the incoming macro or rule.
6952 # Handle inclusion of other files.
6953 elsif (/$INCLUDE_PATTERN/o)
6955 if ($cond ne 'FALSE')
6957 my $file = ($is_am ? "$am_dir/" : '') . $1;
6959 my ($com, $vars, $rules)
6960 = file_contents_internal ($is_am, $file, %transform);
6962 $result_vars .= $vars;
6963 $result_rules .= $rules;
6967 # Handling the conditionals.
6968 elsif (/$IF_PATTERN/o)
6970 $cond = cond_stack_if ($1, $2, $file);
6972 elsif (/$ELSE_PATTERN/o)
6974 $cond = cond_stack_else ($1, $2, $file);
6976 elsif (/$ENDIF_PATTERN/o)
6978 $cond = cond_stack_endif ($1, $2, $file);
6982 elsif (/$RULE_PATTERN/mso)
6984 # Separate relationship from optional actions: the first
6985 # `new-line tab" not preceded by backslash (continuation
6987 # I'm quite shoked! It seems that (\\\n|[^\n]) is not the
6988 # same as `([^\n]|\\\n)!!! Don't swap it, it breaks.
6990 /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
6991 my ($relationship, $actions) = ($1, $2 || '');
6993 # Separate targets from dependencies: the first colon.
6994 $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
6995 my ($targets, $dependencies) = ($1, $2);
6996 # Remove the escaped new lines.
6997 # I don't know why, but I have to use a tmp $flat_deps.
6998 my $flat_deps = &flatten ($dependencies);
6999 my @deps = split (' ', $flat_deps);
7001 foreach (split (' ' , $targets))
7003 # FIXME: We are not robust to people defining several targets
7004 # at once, only some of them being in %dependencies.
7006 # Output only if not in FALSE.
7007 if (defined $dependencies{$_}
7008 && $cond ne 'FALSE')
7010 &depend ($_, @deps);
7011 $actions{$_} .= $actions;
7015 # Free lance dependency. Output the rule for all the
7016 # targets instead of one by one.
7017 if (!defined $targets{$targets}
7018 && $cond ne 'FALSE')
7020 $result_rules .= "$spacing$comment$paragraph\n";
7021 rule_define ($targets, $is_am, $cond, $.);
7023 $comment = $spacing = '';
7028 elsif (/$MACRO_PATTERN/mso)
7030 my ($var, $type, $val) = ($1, $2, $3);
7031 &prog_error ("$file:$.: macro `$var' with trailing backslash")
7034 # Accumulating variables must not be output.
7035 $var_comment{$var} .= "$spacing"
7036 if (!defined $var_comment{$var}
7037 || substr ($var_comment{$var}, -1) ne "\n");
7038 $var_comment{$var} .= "$comment";
7039 # Strip the continuation backslashes.
7041 macro_define ($var, $is_am, $type, $cond, $val, $.)
7042 if $cond ne 'FALSE';
7043 push (@var_list, $var);
7045 # If the user has set some variables we were in charge
7046 # of (which is detected by the first reading of
7047 # `header-vars.am'), we must not output them.
7048 $result_vars .= "$spacing$comment$_\n"
7049 if $type ne '+' && $var_is_am{$var} && $cond ne 'FALSE';
7051 $comment = $spacing = '';
7055 # This isn't an error; it is probably some tokens which
7056 # configure is supposed to replace, such as `@SET-MAKE@',
7057 # or some part of a rule cut by an if/endif.
7058 if ($cond ne 'FALSE')
7060 $result_rules .= "$spacing$comment$_\n";
7062 $comment = $spacing = '';
7066 if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
7070 &am_error ("unterminated conditionals: @cond_stack");
7074 # FIXME: better error message here.
7075 &am_error ("conditionals not nested in include file");
7079 return ($comment, $result_vars, $result_rules);
7084 # &file_contents ($BASENAME, [%TRANSFORM])
7085 # ----------------------------------------
7086 # Return contents of a file from $am_dir, automatically skipping
7087 # macros or rules which are already known.
7088 sub file_contents ($%)
7090 my ($basename, %transform) = @_;
7091 my ($comments, $variables, $rules) =
7092 file_contents_internal (1, "$am_dir/$basename.am", %transform);
7093 return "$comments$variables$rules";
7098 # &transform (%PAIRS)
7099 # -------------------
7100 # Foreach ($TOKEN, $VAL) in %PAIRS produce a replacement expression suitable
7101 # for file_contents which:
7102 # - replaces @$TOKEN@ with $VALUE,
7103 # - enables/disables ?$TOKEN?.
7109 while (my ($token, $val) = each %pairs)
7111 $result .= "s/\Q%$token%\E/\Q$val\E/gm;";
7114 $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
7115 $result .= "s/\Q%?$token%\E/TRUE/gm;";
7119 $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
7120 $result .= "s/\Q%?$token%\E/FALSE/gm;";
7128 # Find all variable prefixes that are used for install directories. A
7129 # prefix `zar' qualifies iff:
7130 # * `zardir' is a variable.
7131 # * `zar_PRIMARY' is a variable.
7132 sub am_primary_prefixes
7134 my ($primary, $can_dist, @prefixes) = @_;
7137 grep ($valid{$_} = 0, @prefixes);
7138 $valid{'EXTRA'} = 0;
7139 foreach my $varname (keys %var_value)
7141 # Automake is allowed to define variables that look like they
7142 # are magic variables, such as INSTALL_DATA.
7144 if $var_is_am{$varname};
7146 if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
7148 my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
7149 if ($dist ne '' && ! $can_dist)
7151 # Note that a configure variable is always legitimate.
7152 # It is natural to name such variables after the
7153 # primary, so we explicitly allow it.
7154 if (! defined $configure_vars{$varname})
7156 &am_line_error ($varname,
7157 "invalid variable `$varname': `dist' is forbidden");
7160 elsif (! defined $valid{$X} && ! &variable_defined ("${X}dir"))
7162 # Note that a configure variable is always legitimate.
7163 # It is natural to name such variables after the
7164 # primary, so we explicitly allow it.
7165 if (! defined $configure_vars{$varname})
7167 &am_line_error ($varname,
7168 "invalid variable `$varname'");
7173 # Ensure all extended prefixes are actually used.
7174 $valid{"$base$dist$X"} = 1;
7182 # Handle `where_HOW' variable magic. Does all lookups, generates
7183 # install code, and possibly generates code to define the primary
7184 # variable. The first argument is the name of the .am file to munge,
7185 # the second argument is the primary variable (eg HEADERS), and all
7186 # subsequent arguments are possible installation locations. Returns
7187 # list of all values of all _HOW targets.
7189 # FIXME: this should be rewritten to be cleaner. It should be broken
7190 # up into multiple functions.
7192 # Usage is: am_install_var (OPTION..., file, HOW, where...)
7199 my $default_dist = 0;
7202 if ($args[0] eq '-noextra')
7206 elsif ($args[0] eq '-candist')
7210 elsif ($args[0] eq '-defaultdist')
7215 elsif ($args[0] !~ /^-/)
7222 my ($file, $primary, @prefixes) = @args;
7224 # Now that configure substitutions are allowed in where_HOW
7225 # variables, it is an error to actually define the primary. We
7226 # allow `JAVA', as it is customarily used to mean the Java
7227 # interpreter. This is but one of several Java hacks. Similarly,
7228 # `PYTHON' is customarily used to mean the Python interpreter.
7229 &am_line_error ($primary, "`$primary' is an anachronism")
7230 if &variable_defined ($primary)
7231 && ($primary ne 'JAVA' && $primary ne 'PYTHON');
7234 # Look for misspellings. It is an error to have a variable ending
7235 # in a "reserved" suffix whose prefix is unknown, eg
7236 # "bni_PROGRAMS". However, unusual prefixes are allowed if a
7237 # variable of the same name (with "dir" appended) exists. For
7238 # instance, if the variable "zardir" is defined, then
7239 # "zar_PROGRAMS" becomes valid. This is to provide a little extra
7240 # flexibility in those cases which need it.
7241 my %valid = &am_primary_prefixes ($primary, $can_dist, @prefixes);
7243 # If a primary includes a configure substitution, then the EXTRA_
7244 # form is required. Otherwise we can't properly do our job.
7246 my $warned_about_extra = 0;
7251 # True if the iteration is the first one. Used for instance to
7252 # output parts of the associated file only once.
7254 foreach my $X (sort keys %valid)
7256 my $one_name = $X . '_' . $primary;
7258 unless (&variable_defined ($one_name));
7260 my $strip_subdir = 1;
7261 # If subdir prefix should be preserved, do so.
7262 if ($X =~ /^nobase_/)
7268 my $nodir_name = $X;
7269 # If files should be distributed, do so.
7273 $dist_p = (($default_dist && $one_name !~ /^nodist_/)
7274 || (! $default_dist && $one_name =~ /^dist_/));
7275 $nodir_name =~ s/^(dist|nodist)_//;
7278 # Append actual contents of where_PRIMARY variable to
7280 foreach my $rcurs (&variable_value_as_list ($one_name, 'all'))
7282 # Skip configure substitutions. Possibly bogus.
7283 if ($rcurs =~ /^\@.*\@$/)
7287 if (! $warned_about_extra)
7289 $warned_about_extra = 1;
7290 &am_line_error ($one_name,
7291 "`$one_name' contains configure substitution, but shouldn't");
7294 # Check here to make sure variables defined in
7295 # configure.ac do not imply that EXTRA_PRIMARY
7297 elsif (! defined $configure_vars{$one_name})
7299 $require_extra = $one_name
7306 push (@result, $rcurs);
7309 # A blatant hack: we rewrite each _PROGRAMS primary to
7310 # include EXEEXT when in Cygwin32 mode.
7311 if ($primary eq 'PROGRAMS')
7313 my @conds = &variable_conditions ($one_name);
7316 foreach my $cond (@conds)
7318 my @one_binlist = ();
7319 my @condval = &variable_value_as_list ($one_name,
7321 foreach my $rcurs (@condval)
7323 if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
7325 push (@one_binlist, $rcurs);
7329 push (@one_binlist, $rcurs . '$(EXEEXT)');
7333 push (@condvals, $cond);
7334 push (@condvals, join (' ', @one_binlist));
7337 variable_delete ($one_name);
7340 my $cond = shift (@condvals);
7341 my @val = split (' ', shift (@condvals));
7342 &define_pretty_variable ($one_name, $cond, @val);
7346 # "EXTRA" shouldn't be used when generating clean targets,
7347 # all, or install targets.
7350 # We used to warn if EXTRA_FOO was defined uselessly,
7351 # but this was annoying.
7357 push (@check, '$(' . $one_name . ')');
7361 push (@used, '$(' . $one_name . ')');
7364 # Is this to be installed?
7365 my $install_p = $X ne 'noinst' && $X ne 'check';
7367 # If so, with install-exec? (or install-data?).
7368 my $exec_p = (defined $exec_dir_p {$X}
7372 # Singular form of $PRIMARY.
7373 (my $one_primary = $primary) =~ s/S$//;
7374 $output_rules .= &file_contents ($file,
7377 'PRIMARY' => $primary,
7378 'ONE_PRIMARY' => $one_primary,
7380 'NDIR' => $nodir_name,
7381 'BASE' => $strip_subdir,
7384 'INSTALL' => $install_p,
7385 'DIST' => $dist_p));
7390 # The JAVA variable is used as the name of the Java interpreter.
7391 # The PYTHON variable is used as the name of the Python interpreter.
7392 if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
7395 &define_pretty_variable ($primary, '', @used);
7396 $output_vars .= "\n";
7399 if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
7401 &am_line_error ($require_extra,
7402 "`$require_extra' contains configure substitution, but `EXTRA_$primary' not defined");
7405 # Push here because PRIMARY might be configure time determined.
7406 push (@all, '$(' . $primary . ')')
7407 if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';
7409 # Make the result unique. This lets the user use conditionals in
7410 # a natural way, but still lets us program lazily -- we don't have
7411 # to worry about handling a particular object more than once.
7412 return uniq (sort @result);
7416 ################################################################
7418 # Each key in this hash is the name of a directory holding a
7419 # Makefile.in. These variables are local to `is_make_dir'.
7421 my $make_dirs_set = 0;
7426 if (! $make_dirs_set)
7428 foreach my $iter (@configure_input_files)
7430 $make_dirs{dirname ($iter)} = 1;
7432 # We also want to notice Makefile.in's.
7433 foreach my $iter (@other_input_files)
7435 if ($iter =~ /Makefile\.in$/)
7437 $make_dirs{dirname ($iter)} = 1;
7442 return defined $make_dirs{$dir};
7445 ################################################################
7447 # This variable is local to the "require file" set of functions.
7448 my @require_file_paths = ();
7450 # If a file name appears as a key in this hash, then it has already
7451 # been checked for. This variable is local to the "require file"
7453 %require_file_found = ();
7455 # See if we want to push this file onto dist_common. This function
7456 # encodes the rules for deciding when to do so.
7457 sub maybe_push_required_file
7459 my ($dir, $file, $fullfile) = @_;
7461 # FIXME: Once again, special-case `.'.
7462 if ($dir eq $relative_dir || $dir eq '.')
7464 &push_dist_common ($file);
7466 elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
7468 # If we are doing the topmost directory, and the file is in a
7469 # subdir which does not have a Makefile, then we distribute it
7471 &push_dist_common ($fullfile);
7476 # &require_file_internal ($IS_CONFIGURE, $LINE, $MYSTRICT, @FILES)
7477 # ----------------------------------------------------------------
7478 # Verify that the file must exist in the current directory.
7479 # $MYSTRICT is the strictness level at which this file becomes required.
7481 # Must set require_file_paths before calling this function.
7482 # require_file_paths is set to hold a single directory (the one in
7483 # which the first file was found) before return.
7484 sub require_file_internal
7486 my ($is_configure, $line, $mystrict, @files) = @_;
7488 foreach my $file (@files)
7495 # If we've already looked for it, we're done.
7496 next if defined $require_file_found{$file};
7497 $require_file_found{$file} = 1;
7500 my $dangling_sym = 0;
7501 foreach my $dir (@require_file_paths)
7505 $fullfile = $relative_dir . "/" . $file;
7506 $errdir = $relative_dir unless $errdir;
7510 $fullfile = $dir . "/" . $file;
7511 $errdir = $dir unless $errdir;
7514 # Use different name for "error filename". Otherwise on
7515 # an error the bad file will be reported as eg
7516 # `../../install-sh' when using the default
7518 $errfile = $errdir . '/' . $file;
7520 if (-l $fullfile && ! -f readlink ($fullfile))
7525 elsif (-f $fullfile)
7528 &maybe_push_required_file ($dir, $file, $fullfile);
7534 if ($found_it && ! $force_missing)
7536 # Prune the path list.
7537 @require_file_paths = $save_dir;
7541 if ($strictness >= $mystrict)
7543 if ($dangling_sym && ($force_missing || $add_missing))
7551 # Only install missing files according to our desired
7553 my $message = "required file `$errfile' not found";
7558 # Maybe run libtoolize.
7559 my @syslist = ('libtoolize', '--automake');
7560 push @syslist, '--copy'
7563 && grep ($_ eq $file, @libtoolize_files)
7564 && system (@syslist))
7566 $message = "installing `$errfile'";
7568 $trailer = "; cannot run `libtoolize': $!";
7570 elsif (-f ("$pkgdata_dir/$file"))
7572 # Install the missing file. Symlink if we
7573 # can, copy if we must. Note: delete the file
7574 # first, in case it is a dangling symlink.
7575 $message = "installing `$errfile'";
7576 # Windows Perl will hang if we try to delete a
7577 # file that doesn't exist.
7578 unlink ($errfile) if -f $errfile;
7579 if ($symlink_exists && ! $copy_missing)
7581 if (! symlink ("$pkgdata_dir/$file", $errfile))
7584 $trailer = "; error while making link: $!";
7587 elsif (system ('cp', "$pkgdata_dir/$file", $errfile))
7590 $trailer = "\n error while copying";
7594 &maybe_push_required_file (dirname ($errfile),
7598 my $save = $exit_status;
7601 # FIXME: allow actual file to be specified.
7602 &am_conf_line_error ($configure_ac, $line,
7603 "$message$trailer");
7607 &am_line_error ($line, "$message$trailer");
7609 $exit_status = $save if $suppress;
7615 # Like require_file_with_line, but error messages refer to
7616 # configure.ac, not the current Makefile.am.
7617 sub require_file_with_conf_line
7619 @require_file_paths = '.';
7620 &require_file_internal (1, @_);
7623 sub require_file_with_line
7625 @require_file_paths = '.';
7626 &require_file_internal (0, @_);
7631 @require_file_paths = '.';
7632 &require_file_internal (0, '', @_);
7635 # Require a file that is also required by Autoconf. Looks in
7636 # configuration path, as specified by AC_CONFIG_AUX_DIR.
7637 sub require_config_file
7639 @require_file_paths = @config_aux_path;
7640 &require_file_internal (1, '', @_);
7641 my $dir = $require_file_paths[0];
7642 @config_aux_path = @require_file_paths;
7645 $config_aux_dir = '.';
7649 $config_aux_dir = '$(top_srcdir)/' . $dir;
7653 # Assumes that the line number is in Makefile.am.
7654 sub require_conf_file_with_line
7656 @require_file_paths = @config_aux_path;
7657 &require_file_internal (0, @_);
7658 my $dir = $require_file_paths[0];
7659 @config_aux_path = @require_file_paths;
7662 $config_aux_dir = '.';
7666 $config_aux_dir = '$(top_srcdir)/' . $dir;
7670 # Assumes that the line number is in configure.ac.
7671 sub require_conf_file_with_conf_line
7673 @require_file_paths = @config_aux_path;
7674 &require_file_internal (1, @_);
7675 my $dir = $require_file_paths[0];
7676 @config_aux_path = @require_file_paths;
7679 $config_aux_dir = '.';
7683 $config_aux_dir = '$(top_srcdir)/' . $dir;
7687 ################################################################
7689 # Push a list of files onto dist_common.
7690 sub push_dist_common
7692 &prog_error ("push_dist_common run after handle_dist")
7693 if $handle_dist_run;
7694 macro_define ('DIST_COMMON', 1, '+', '', join (' ', @_), '');
7701 $strictness_name = $_[0];
7702 if ($strictness_name eq 'gnu')
7706 elsif ($strictness_name eq 'gnits')
7708 $strictness = $GNITS;
7710 elsif ($strictness_name eq 'foreign')
7712 $strictness = $FOREIGN;
7716 die "$me: level `$strictness_name' not recognized\n";
7721 ################################################################
7723 # Ensure a file exists.
7728 my $touch = new IO::File (">> $file");
7732 # Glob something. Do this to avoid indentation screwups everywhere we
7733 # want to glob. Gross!
7740 # Remove one level of brackets and strip leading spaces,
7741 # as does m4 to function arguments.
7747 my @letters = split //;
7756 next if $depth == 1;
7761 next if $depth == 0;
7762 # don't count orphan right brackets
7763 $depth = 0 if $depth < 0;
7767 return join '', @result;
7770 ################################################################
7772 # Print an error message and set exit status.
7775 warn "$me: ${am_file}.am: @_\n";
7780 # am_file_error ($FILE, @ARGS)
7781 # ----------------------------
7784 my ($file, @args) = @_;
7786 warn "$file: @args\n";
7792 my ($symbol, @args) = @_;
7794 if ($symbol && "$symbol" ne '-1')
7796 my $file = "${am_file}.am";
7798 if ($symbol =~ /^\d+$/)
7800 # SYMBOL is a line number, so just add the colon.
7801 $file .= ':' . $symbol;
7803 elsif (defined $var_line{$symbol})
7805 # SYMBOL is a variable defined in Makefile.am, so add the
7806 # line number we saved from there.
7807 $file .= ':' . $var_line{$symbol};
7809 elsif (defined $configure_vars{$symbol})
7811 # SYMBOL is a variable defined in configure.ac, so add the
7812 # appropriate line number.
7813 $file = $configure_vars{$symbol};
7817 # Couldn't find the line number.
7819 warn $file, ": @args\n";
7828 # Like am_error, but while scanning configure.ac.
7831 # FIXME: can run in subdirs.
7832 warn "$me: $configure_ac: @_\n";
7836 # Error message with line number referring to configure.ac.
7837 sub am_conf_line_error
7839 my ($file, $line, @args) = @_;
7843 warn "$file: $line: @args\n";
7848 &am_conf_error (@args);
7852 # Warning message with line number referring to configure.ac.
7853 # Does not affect exit_status
7854 sub am_conf_line_warning
7856 my $saved_exit_status = $exit_status;
7857 &am_conf_line_error (@_);
7858 $exit_status = $saved_exit_status;
7861 # Tell user where our aclocal.m4 is, but only once.
7862 sub keyed_aclocal_warning
7865 warn "$me: macro `$key' can be generated by `aclocal'\n";
7868 # Print usage information.
7872 Usage: $0 [OPTION] ... [Makefile]...
7874 Generate Makefile.in for configure from Makefile.am.
7877 --help print this help, then exit
7878 --version print version number, then exit
7879 -v, --verbose verbosely list files processed
7880 -o, --output-dir=DIR put generated Makefile.in's into DIR
7881 --no-force only update Makefile.in's that are out of date
7883 Dependency tracking:
7884 -i, --ignore-deps disable dependency tracking code
7885 --include-deps enable dependency tracking code
7888 --cygnus assume program is part of Cygnus-style tree
7889 --foreign set strictness to foreign
7890 --gnits set strictness to gnits
7891 --gnu set strictness to gnu
7894 -a, --add-missing add missing standard files to package
7895 --amdir=DIR directory storing config files
7896 -c, --copy with -a, copy missing files (default is symlink)
7897 -f, --force-missing force update of standard files
7902 foreach my $iter (sort ((@common_files, @common_sometimes)))
7904 push (@lcomm, $iter) unless $iter eq $last;
7908 my ($one, $two, $three, $four, $max);
7909 print "\nFiles which are automatically distributed, if found:\n";
7910 format USAGE_FORMAT =
7911 @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
7912 $one, $two, $three, $four
7914 $~ = "USAGE_FORMAT";
7915 $max = int (($#lcomm + 1) / 4);
7917 for (my $i = 0; $i < $max; ++$i)
7920 $two = $lcomm[$max + $i];
7921 $three = $lcomm[2 * $max + $i];
7922 $four = $lcomm[3 * $max + $i];
7926 my $mod = ($#lcomm + 1) % 4;
7929 $one = $lcomm[$max];
7930 $two = ($mod > 1) ? $lcomm[2 * $max] : '';
7931 $three = ($mod > 2) ? $lcomm[3 * $max] : '';
7932 $four = ($mod > 3) ? $lcomm[4 * $max] : '';
7936 print "\nReport bugs to <bug-automake\@gnu.org>.\n";
7943 # Print version information
7947 automake (GNU $PACKAGE) $VERSION
7948 Written by Tom Tromey <tromey\@cygnus.com>.
7950 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
7951 Free Software Foundation, Inc.
7952 This is free software; see the source for copying conditions. There is NO
7953 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.